authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-02-05 10:50:09+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-04-04 06:08:09+02:00
log156ab8750056c3ff440af0937806d8cdb2623816
tree26956c58e4d169279885ab94d479f8b9f4285872
parent7ab01c9a42fa0262d67d9ff1a0ecde24fb7031e7
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

libcxx: Update to Clang 20.

See: * https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc/77319 * https://discourse.llvm.org/t/rfc-project-hand-in-hand-llvm-libc-libc-code-sharing/77701 We're dropping support for C++03 for Zig due to the first change; it would be insane to ship 1018 duplicate header files just for this outdated use case. As a result of the second change, I had to bring in a subset of the headers from llvm-libc since libc++ now depends on these. Hopefully we can continue to get away with not copying the entirety of llvm-libc.

1001 files changed, 36835 insertions(+), 19964 deletions(-)

lib/libcxx/include/__algorithm/adjacent_find.h+11-9
......@@ -11,9 +11,9 @@
1111#define _LIBCPP___ALGORITHM_ADJACENT_FIND_H
1212
1313#include <__algorithm/comp.h>
14#include <__algorithm/iterator_operations.h>
1514#include <__config>
16#include <__iterator/iterator_traits.h>
15#include <__functional/identity.h>
16#include <__type_traits/invoke.h>
1717#include <__utility/move.h>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -25,14 +25,15 @@ _LIBCPP_PUSH_MACROS
2525
2626_LIBCPP_BEGIN_NAMESPACE_STD
2727
28template <class _Iter, class _Sent, class _BinaryPredicate>
29_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter
30__adjacent_find(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) {
28template <class _Iter, class _Sent, class _Pred, class _Proj>
29[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter
30__adjacent_find(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
3131 if (__first == __last)
3232 return __first;
33
3334 _Iter __i = __first;
3435 while (++__i != __last) {
35 if (__pred(*__first, *__i))
36 if (std::__invoke(__pred, std::__invoke(__proj, *__first), std::__invoke(__proj, *__i)))
3637 return __first;
3738 __first = __i;
3839 }
......@@ -40,13 +41,14 @@ __adjacent_find(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) {
4041}
4142
4243template <class _ForwardIterator, class _BinaryPredicate>
43_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
44[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
4445adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) {
45 return std::__adjacent_find(std::move(__first), std::move(__last), __pred);
46 __identity __proj;
47 return std::__adjacent_find(std::move(__first), std::move(__last), __pred, __proj);
4648}
4749
4850template <class _ForwardIterator>
49_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
51[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
5052adjacent_find(_ForwardIterator __first, _ForwardIterator __last) {
5153 return std::adjacent_find(std::move(__first), std::move(__last), __equal_to());
5254}
lib/libcxx/include/__algorithm/all_of.h+15-5
......@@ -11,6 +11,8 @@
1111#define _LIBCPP___ALGORITHM_ALL_OF_H
1212
1313#include <__config>
14#include <__functional/identity.h>
15#include <__type_traits/invoke.h>
1416
1517#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1618# pragma GCC system_header
......@@ -18,15 +20,23 @@
1820
1921_LIBCPP_BEGIN_NAMESPACE_STD
2022
21template <class _InputIterator, class _Predicate>
22_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
23all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
24 for (; __first != __last; ++__first)
25 if (!__pred(*__first))
23template <class _Iter, class _Sent, class _Proj, class _Pred>
24_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
25__all_of(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
26 for (; __first != __last; ++__first) {
27 if (!std::__invoke(__pred, std::__invoke(__proj, *__first)))
2628 return false;
29 }
2730 return true;
2831}
2932
33template <class _InputIterator, class _Predicate>
34[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
35all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
36 __identity __proj;
37 return std::__all_of(__first, __last, __pred, __proj);
38}
39
3040_LIBCPP_END_NAMESPACE_STD
3141
3242#endif // _LIBCPP___ALGORITHM_ALL_OF_H
lib/libcxx/include/__algorithm/any_of.h+15-5
......@@ -11,6 +11,8 @@
1111#define _LIBCPP___ALGORITHM_ANY_OF_H
1212
1313#include <__config>
14#include <__functional/identity.h>
15#include <__type_traits/invoke.h>
1416
1517#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1618# pragma GCC system_header
......@@ -18,15 +20,23 @@
1820
1921_LIBCPP_BEGIN_NAMESPACE_STD
2022
21template <class _InputIterator, class _Predicate>
22_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
23any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
24 for (; __first != __last; ++__first)
25 if (__pred(*__first))
23template <class _Iter, class _Sent, class _Proj, class _Pred>
24_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
25__any_of(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
26 for (; __first != __last; ++__first) {
27 if (std::__invoke(__pred, std::__invoke(__proj, *__first)))
2628 return true;
29 }
2730 return false;
2831}
2932
33template <class _InputIterator, class _Predicate>
34[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
35any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
36 __identity __proj;
37 return std::__any_of(__first, __last, __pred, __proj);
38}
39
3040_LIBCPP_END_NAMESPACE_STD
3141
3242#endif // _LIBCPP___ALGORITHM_ANY_OF_H
lib/libcxx/include/__algorithm/binary_search.h+2-3
......@@ -13,7 +13,6 @@
1313#include <__algorithm/comp_ref_type.h>
1414#include <__algorithm/lower_bound.h>
1515#include <__config>
16#include <__iterator/iterator_traits.h>
1716
1817#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1918# pragma GCC system_header
......@@ -22,14 +21,14 @@
2221_LIBCPP_BEGIN_NAMESPACE_STD
2322
2423template <class _ForwardIterator, class _Tp, class _Compare>
25_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
24[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
2625binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
2726 __first = std::lower_bound<_ForwardIterator, _Tp, __comp_ref_type<_Compare> >(__first, __last, __value, __comp);
2827 return __first != __last && !__comp(__value, *__first);
2928}
3029
3130template <class _ForwardIterator, class _Tp>
32_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
31[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
3332binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
3433 return std::binary_search(__first, __last, __value, __less<>());
3534}
lib/libcxx/include/__algorithm/comp.h+4
......@@ -11,6 +11,7 @@
1111
1212#include <__config>
1313#include <__type_traits/desugars_to.h>
14#include <__type_traits/is_integral.h>
1415
1516#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1617# pragma GCC system_header
......@@ -44,6 +45,9 @@ struct __less<void, void> {
4445template <class _Tp>
4546inline const bool __desugars_to_v<__less_tag, __less<>, _Tp, _Tp> = true;
4647
48template <class _Tp>
49inline const bool __desugars_to_v<__totally_ordered_less_tag, __less<>, _Tp, _Tp> = is_integral<_Tp>::value;
50
4751_LIBCPP_END_NAMESPACE_STD
4852
4953#endif // _LIBCPP___ALGORITHM_COMP_H
lib/libcxx/include/__algorithm/comp_ref_type.h+2-2
......@@ -56,10 +56,10 @@ struct __debug_less {
5656// Pass the comparator by lvalue reference. Or in the debug mode, using a debugging wrapper that stores a reference.
5757#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
5858template <class _Comp>
59using __comp_ref_type = __debug_less<_Comp>;
59using __comp_ref_type _LIBCPP_NODEBUG = __debug_less<_Comp>;
6060#else
6161template <class _Comp>
62using __comp_ref_type = _Comp&;
62using __comp_ref_type _LIBCPP_NODEBUG = _Comp&;
6363#endif
6464
6565_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/copy.h+9-10
......@@ -11,11 +11,12 @@
1111
1212#include <__algorithm/copy_move_common.h>
1313#include <__algorithm/for_each_segment.h>
14#include <__algorithm/iterator_operations.h>
1514#include <__algorithm/min.h>
1615#include <__config>
16#include <__iterator/iterator_traits.h>
1717#include <__iterator/segmented_iterator.h>
1818#include <__type_traits/common_type.h>
19#include <__type_traits/enable_if.h>
1920#include <__utility/move.h>
2021#include <__utility/pair.h>
2122
......@@ -28,10 +29,9 @@ _LIBCPP_PUSH_MACROS
2829
2930_LIBCPP_BEGIN_NAMESPACE_STD
3031
31template <class, class _InIter, class _Sent, class _OutIter>
32template <class _InIter, class _Sent, class _OutIter>
3233inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> __copy(_InIter, _Sent, _OutIter);
3334
34template <class _AlgPolicy>
3535struct __copy_impl {
3636 template <class _InIter, class _Sent, class _OutIter>
3737 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
......@@ -47,7 +47,7 @@ struct __copy_impl {
4747
4848 template <class _InIter, class _OutIter>
4949 struct _CopySegment {
50 using _Traits = __segmented_iterator_traits<_InIter>;
50 using _Traits _LIBCPP_NODEBUG = __segmented_iterator_traits<_InIter>;
5151
5252 _OutIter& __result_;
5353
......@@ -56,7 +56,7 @@ struct __copy_impl {
5656
5757 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
5858 operator()(typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) {
59 __result_ = std::__copy<_AlgPolicy>(__lfirst, __llast, std::move(__result_)).second;
59 __result_ = std::__copy(__lfirst, __llast, std::move(__result_)).second;
6060 }
6161 };
6262
......@@ -85,7 +85,7 @@ struct __copy_impl {
8585 while (true) {
8686 auto __local_last = _Traits::__end(__segment_iterator);
8787 auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first);
88 auto __iters = std::__copy<_AlgPolicy>(__first, __first + __size, __local_first);
88 auto __iters = std::__copy(__first, __first + __size, __local_first);
8989 __first = std::move(__iters.first);
9090
9191 if (__first == __last)
......@@ -103,17 +103,16 @@ struct __copy_impl {
103103 }
104104};
105105
106template <class _AlgPolicy, class _InIter, class _Sent, class _OutIter>
106template <class _InIter, class _Sent, class _OutIter>
107107pair<_InIter, _OutIter> inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
108108__copy(_InIter __first, _Sent __last, _OutIter __result) {
109 return std::__copy_move_unwrap_iters<__copy_impl<_AlgPolicy> >(
110 std::move(__first), std::move(__last), std::move(__result));
109 return std::__copy_move_unwrap_iters<__copy_impl>(std::move(__first), std::move(__last), std::move(__result));
111110}
112111
113112template <class _InputIterator, class _OutputIterator>
114113inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
115114copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
116 return std::__copy<_ClassicAlgPolicy>(__first, __last, __result).second;
115 return std::__copy(__first, __last, __result).second;
117116}
118117
119118_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/copy_backward.h+2
......@@ -13,8 +13,10 @@
1313#include <__algorithm/iterator_operations.h>
1414#include <__algorithm/min.h>
1515#include <__config>
16#include <__iterator/iterator_traits.h>
1617#include <__iterator/segmented_iterator.h>
1718#include <__type_traits/common_type.h>
19#include <__type_traits/enable_if.h>
1820#include <__type_traits/is_constructible.h>
1921#include <__utility/move.h>
2022#include <__utility/pair.h>
lib/libcxx/include/__algorithm/copy_if.h+21-5
......@@ -10,25 +10,41 @@
1010#define _LIBCPP___ALGORITHM_COPY_IF_H
1111
1212#include <__config>
13#include <__functional/identity.h>
14#include <__type_traits/invoke.h>
15#include <__utility/move.h>
16#include <__utility/pair.h>
1317
1418#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1519# pragma GCC system_header
1620#endif
1721
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
1825_LIBCPP_BEGIN_NAMESPACE_STD
1926
20template <class _InputIterator, class _OutputIterator, class _Predicate>
21inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
22copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) {
27template <class _InIter, class _Sent, class _OutIter, class _Proj, class _Pred>
28_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
29__copy_if(_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj& __proj) {
2330 for (; __first != __last; ++__first) {
24 if (__pred(*__first)) {
31 if (std::__invoke(__pred, std::__invoke(__proj, *__first))) {
2532 *__result = *__first;
2633 ++__result;
2734 }
2835 }
29 return __result;
36 return std::make_pair(std::move(__first), std::move(__result));
37}
38
39template <class _InputIterator, class _OutputIterator, class _Predicate>
40inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
41copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) {
42 __identity __proj;
43 return std::__copy_if(__first, __last, __result, __pred, __proj).second;
3044}
3145
3246_LIBCPP_END_NAMESPACE_STD
3347
48_LIBCPP_POP_MACROS
49
3450#endif // _LIBCPP___ALGORITHM_COPY_IF_H
lib/libcxx/include/__algorithm/copy_move_common.h+1-2
......@@ -9,10 +9,10 @@
99#ifndef _LIBCPP___ALGORITHM_COPY_MOVE_COMMON_H
1010#define _LIBCPP___ALGORITHM_COPY_MOVE_COMMON_H
1111
12#include <__algorithm/iterator_operations.h>
1312#include <__algorithm/unwrap_iter.h>
1413#include <__algorithm/unwrap_range.h>
1514#include <__config>
15#include <__cstddef/size_t.h>
1616#include <__iterator/iterator_traits.h>
1717#include <__memory/pointer_traits.h>
1818#include <__string/constexpr_c_functions.h>
......@@ -24,7 +24,6 @@
2424#include <__type_traits/is_volatile.h>
2525#include <__utility/move.h>
2626#include <__utility/pair.h>
27#include <cstddef>
2827
2928#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3029# pragma GCC system_header
lib/libcxx/include/__algorithm/count.h+8-5
......@@ -16,9 +16,10 @@
1616#include <__bit/popcount.h>
1717#include <__config>
1818#include <__functional/identity.h>
19#include <__functional/invoke.h>
2019#include <__fwd/bit_reference.h>
2120#include <__iterator/iterator_traits.h>
21#include <__type_traits/enable_if.h>
22#include <__type_traits/invoke.h>
2223
2324#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2425# pragma GCC system_header
......@@ -43,7 +44,7 @@ __count(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) {
4344// __bit_iterator implementation
4445template <bool _ToCount, class _Cp, bool _IsConst>
4546_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __bit_iterator<_Cp, _IsConst>::difference_type
46__count_bool(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) {
47__count_bool(__bit_iterator<_Cp, _IsConst> __first, typename __size_difference_type_traits<_Cp>::size_type __n) {
4748 using _It = __bit_iterator<_Cp, _IsConst>;
4849 using __storage_type = typename _It::__storage_type;
4950 using difference_type = typename _It::difference_type;
......@@ -74,12 +75,14 @@ template <class, class _Cp, bool _IsConst, class _Tp, class _Proj, __enable_if_t
7475_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_diff_t<__bit_iterator<_Cp, _IsConst> >
7576__count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value, _Proj&) {
7677 if (__value)
77 return std::__count_bool<true>(__first, static_cast<typename _Cp::size_type>(__last - __first));
78 return std::__count_bool<false>(__first, static_cast<typename _Cp::size_type>(__last - __first));
78 return std::__count_bool<true>(
79 __first, static_cast<typename __size_difference_type_traits<_Cp>::size_type>(__last - __first));
80 return std::__count_bool<false>(
81 __first, static_cast<typename __size_difference_type_traits<_Cp>::size_type>(__last - __first));
7982}
8083
8184template <class _InputIterator, class _Tp>
82_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_diff_t<_InputIterator>
85[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_diff_t<_InputIterator>
8386count(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
8487 __identity __proj;
8588 return std::__count<_ClassicAlgPolicy>(__first, __last, __value, __proj);
lib/libcxx/include/__algorithm/count_if.h+17-6
......@@ -10,8 +10,11 @@
1010#ifndef _LIBCPP___ALGORITHM_COUNT_IF_H
1111#define _LIBCPP___ALGORITHM_COUNT_IF_H
1212
13#include <__algorithm/iterator_operations.h>
1314#include <__config>
15#include <__functional/identity.h>
1416#include <__iterator/iterator_traits.h>
17#include <__type_traits/invoke.h>
1518
1619#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1720# pragma GCC system_header
......@@ -19,15 +22,23 @@
1922
2023_LIBCPP_BEGIN_NAMESPACE_STD
2124
25template <class _AlgPolicy, class _Iter, class _Sent, class _Proj, class _Pred>
26_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __policy_iter_diff_t<_AlgPolicy, _Iter>
27__count_if(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
28 __policy_iter_diff_t<_AlgPolicy, _Iter> __counter(0);
29 for (; __first != __last; ++__first) {
30 if (std::__invoke(__pred, std::__invoke(__proj, *__first)))
31 ++__counter;
32 }
33 return __counter;
34}
35
2236template <class _InputIterator, class _Predicate>
23_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
37[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
2438typename iterator_traits<_InputIterator>::difference_type
2539count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
26 typename iterator_traits<_InputIterator>::difference_type __r(0);
27 for (; __first != __last; ++__first)
28 if (__pred(*__first))
29 ++__r;
30 return __r;
40 __identity __proj;
41 return std::__count_if<_ClassicAlgPolicy>(__first, __last, __pred, __proj);
3142}
3243
3344_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/equal.h+9-10
......@@ -14,13 +14,12 @@
1414#include <__algorithm/unwrap_iter.h>
1515#include <__config>
1616#include <__functional/identity.h>
17#include <__functional/invoke.h>
1817#include <__iterator/distance.h>
1918#include <__iterator/iterator_traits.h>
2019#include <__string/constexpr_c_functions.h>
2120#include <__type_traits/desugars_to.h>
2221#include <__type_traits/enable_if.h>
23#include <__type_traits/is_constant_evaluated.h>
22#include <__type_traits/invoke.h>
2423#include <__type_traits/is_equality_comparable.h>
2524#include <__type_traits/is_volatile.h>
2625#include <__utility/move.h>
......@@ -35,7 +34,7 @@ _LIBCPP_PUSH_MACROS
3534_LIBCPP_BEGIN_NAMESPACE_STD
3635
3736template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
38_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_iter_impl(
37[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_iter_impl(
3938 _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate& __pred) {
4039 for (; __first1 != __last1; ++__first1, (void)++__first2)
4140 if (!__pred(*__first1, *__first2))
......@@ -49,20 +48,20 @@ template <class _Tp,
4948 __enable_if_t<__desugars_to_v<__equal_tag, _BinaryPredicate, _Tp, _Up> && !is_volatile<_Tp>::value &&
5049 !is_volatile<_Up>::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
5150 int> = 0>
52_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
51[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
5352__equal_iter_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, _BinaryPredicate&) {
5453 return std::__constexpr_memcmp_equal(__first1, __first2, __element_count(__last1 - __first1));
5554}
5655
5756template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
58_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
57[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
5958equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) {
6059 return std::__equal_iter_impl(
6160 std::__unwrap_iter(__first1), std::__unwrap_iter(__last1), std::__unwrap_iter(__first2), __pred);
6261}
6362
6463template <class _InputIterator1, class _InputIterator2>
65_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
64[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
6665equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) {
6766 return std::equal(__first1, __last1, __first2, __equal_to());
6867}
......@@ -70,7 +69,7 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first
7069#if _LIBCPP_STD_VER >= 14
7170
7271template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
73_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_impl(
72[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_impl(
7473 _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __comp, _Proj1& __proj1, _Proj2& __proj2) {
7574 while (__first1 != __last1 && __first2 != __last2) {
7675 if (!std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
......@@ -90,13 +89,13 @@ template <class _Tp,
9089 __is_identity<_Proj2>::value && !is_volatile<_Tp>::value && !is_volatile<_Up>::value &&
9190 __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
9291 int> = 0>
93_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
92[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
9493__equal_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, _Up*, _Pred&, _Proj1&, _Proj2&) {
9594 return std::__constexpr_memcmp_equal(__first1, __first2, __element_count(__last1 - __first1));
9695}
9796
9897template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
99_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
98[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
10099equal(_InputIterator1 __first1,
101100 _InputIterator1 __last1,
102101 _InputIterator2 __first2,
......@@ -119,7 +118,7 @@ equal(_InputIterator1 __first1,
119118}
120119
121120template <class _InputIterator1, class _InputIterator2>
122_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
121[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
123122equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
124123 return std::equal(__first1, __last1, __first2, __last2, __equal_to());
125124}
lib/libcxx/include/__algorithm/equal_range.h+4-8
......@@ -17,11 +17,7 @@
1717#include <__algorithm/upper_bound.h>
1818#include <__config>
1919#include <__functional/identity.h>
20#include <__functional/invoke.h>
21#include <__iterator/advance.h>
22#include <__iterator/distance.h>
23#include <__iterator/iterator_traits.h>
24#include <__iterator/next.h>
20#include <__type_traits/invoke.h>
2521#include <__type_traits/is_callable.h>
2622#include <__type_traits/is_constructible.h>
2723#include <__utility/move.h>
......@@ -60,9 +56,9 @@ __equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp
6056}
6157
6258template <class _ForwardIterator, class _Tp, class _Compare>
63_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
59[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
6460equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
65 static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
61 static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
6662 static_assert(is_copy_constructible<_ForwardIterator>::value, "Iterator has to be copy constructible");
6763 return std::__equal_range<_ClassicAlgPolicy>(
6864 std::move(__first),
......@@ -73,7 +69,7 @@ equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __valu
7369}
7470
7571template <class _ForwardIterator, class _Tp>
76_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
72[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
7773equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
7874 return std::equal_range(std::move(__first), std::move(__last), __value, __less<>());
7975}
lib/libcxx/include/__algorithm/fill_n.h+1-2
......@@ -12,7 +12,6 @@
1212#include <__algorithm/min.h>
1313#include <__config>
1414#include <__fwd/bit_reference.h>
15#include <__iterator/iterator_traits.h>
1615#include <__memory/pointer_traits.h>
1716#include <__utility/convert_to_integral.h>
1817
......@@ -33,7 +32,7 @@ __fill_n(_OutputIterator __first, _Size __n, const _Tp& __value);
3332
3433template <bool _FillVal, class _Cp>
3534_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
36__fill_n_bool(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) {
35__fill_n_bool(__bit_iterator<_Cp, false> __first, typename __size_difference_type_traits<_Cp>::size_type __n) {
3736 using _It = __bit_iterator<_Cp, false>;
3837 using __storage_type = typename _It::__storage_type;
3938
lib/libcxx/include/__algorithm/find.h+12-9
......@@ -17,17 +17,18 @@
1717#include <__bit/invert_if.h>
1818#include <__config>
1919#include <__functional/identity.h>
20#include <__functional/invoke.h>
2120#include <__fwd/bit_reference.h>
2221#include <__iterator/segmented_iterator.h>
2322#include <__string/constexpr_c_functions.h>
23#include <__type_traits/enable_if.h>
24#include <__type_traits/invoke.h>
25#include <__type_traits/is_equality_comparable.h>
2426#include <__type_traits/is_integral.h>
25#include <__type_traits/is_same.h>
2627#include <__type_traits/is_signed.h>
2728#include <__utility/move.h>
2829#include <limits>
2930
30#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
31#if _LIBCPP_HAS_WIDE_CHARACTERS
3132# include <cwchar>
3233#endif
3334
......@@ -63,7 +64,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __find(_Tp* __first, _T
6364 return __last;
6465}
6566
66#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
67#if _LIBCPP_HAS_WIDE_CHARACTERS
6768template <class _Tp,
6869 class _Up,
6970 class _Proj,
......@@ -75,7 +76,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __find(_Tp* __first, _T
7576 return __ret;
7677 return __last;
7778}
78#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
79#endif // _LIBCPP_HAS_WIDE_CHARACTERS
7980
8081// TODO: This should also be possible to get right with different signedness
8182// cast integral types to allow vectorization
......@@ -96,7 +97,7 @@ __find(_Tp* __first, _Tp* __last, const _Up& __value, _Proj& __proj) {
9697// __bit_iterator implementation
9798template <bool _ToFind, class _Cp, bool _IsConst>
9899_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, _IsConst>
99__find_bool(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) {
100__find_bool(__bit_iterator<_Cp, _IsConst> __first, typename __size_difference_type_traits<_Cp>::size_type __n) {
100101 using _It = __bit_iterator<_Cp, _IsConst>;
101102 using __storage_type = typename _It::__storage_type;
102103
......@@ -134,8 +135,10 @@ template <class _Cp, bool _IsConst, class _Tp, class _Proj, __enable_if_t<__is_i
134135inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, _IsConst>
135136__find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value, _Proj&) {
136137 if (static_cast<bool>(__value))
137 return std::__find_bool<true>(__first, static_cast<typename _Cp::size_type>(__last - __first));
138 return std::__find_bool<false>(__first, static_cast<typename _Cp::size_type>(__last - __first));
138 return std::__find_bool<true>(
139 __first, static_cast<typename __size_difference_type_traits<_Cp>::size_type>(__last - __first));
140 return std::__find_bool<false>(
141 __first, static_cast<typename __size_difference_type_traits<_Cp>::size_type>(__last - __first));
139142}
140143
141144// segmented iterator implementation
......@@ -167,7 +170,7 @@ struct __find_segment {
167170
168171// public API
169172template <class _InputIterator, class _Tp>
170_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
173[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
171174find(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
172175 __identity __proj;
173176 return std::__rewrap_iter(
lib/libcxx/include/__algorithm/find_end.h+4-111
......@@ -12,14 +12,10 @@
1212
1313#include <__algorithm/comp.h>
1414#include <__algorithm/iterator_operations.h>
15#include <__algorithm/search.h>
1615#include <__config>
1716#include <__functional/identity.h>
18#include <__functional/invoke.h>
19#include <__iterator/advance.h>
2017#include <__iterator/iterator_traits.h>
21#include <__iterator/next.h>
22#include <__iterator/reverse_iterator.h>
18#include <__type_traits/invoke.h>
2319#include <__utility/pair.h>
2420
2521#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -80,111 +76,8 @@ _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1>
8076 }
8177}
8278
83template < class _IterOps,
84 class _Pred,
85 class _Iter1,
86 class _Sent1,
87 class _Iter2,
88 class _Sent2,
89 class _Proj1,
90 class _Proj2>
91_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter1 __find_end(
92 _Iter1 __first1,
93 _Sent1 __sent1,
94 _Iter2 __first2,
95 _Sent2 __sent2,
96 _Pred& __pred,
97 _Proj1& __proj1,
98 _Proj2& __proj2,
99 bidirectional_iterator_tag,
100 bidirectional_iterator_tag) {
101 auto __last1 = _IterOps::next(__first1, __sent1);
102 auto __last2 = _IterOps::next(__first2, __sent2);
103 // modeled after search algorithm (in reverse)
104 if (__first2 == __last2)
105 return __last1; // Everything matches an empty sequence
106 _Iter1 __l1 = __last1;
107 _Iter2 __l2 = __last2;
108 --__l2;
109 while (true) {
110 // Find last element in sequence 1 that matchs *(__last2-1), with a mininum of loop checks
111 while (true) {
112 if (__first1 == __l1) // return __last1 if no element matches *__first2
113 return __last1;
114 if (std::__invoke(__pred, std::__invoke(__proj1, *--__l1), std::__invoke(__proj2, *__l2)))
115 break;
116 }
117 // *__l1 matches *__l2, now match elements before here
118 _Iter1 __m1 = __l1;
119 _Iter2 __m2 = __l2;
120 while (true) {
121 if (__m2 == __first2) // If pattern exhausted, __m1 is the answer (works for 1 element pattern)
122 return __m1;
123 if (__m1 == __first1) // Otherwise if source exhaused, pattern not found
124 return __last1;
125
126 // if there is a mismatch, restart with a new __l1
127 if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(__proj2, *--__m2))) {
128 break;
129 } // else there is a match, check next elements
130 }
131 }
132}
133
134template < class _AlgPolicy,
135 class _Pred,
136 class _Iter1,
137 class _Sent1,
138 class _Iter2,
139 class _Sent2,
140 class _Proj1,
141 class _Proj2>
142_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter1 __find_end(
143 _Iter1 __first1,
144 _Sent1 __sent1,
145 _Iter2 __first2,
146 _Sent2 __sent2,
147 _Pred& __pred,
148 _Proj1& __proj1,
149 _Proj2& __proj2,
150 random_access_iterator_tag,
151 random_access_iterator_tag) {
152 typedef typename iterator_traits<_Iter1>::difference_type _D1;
153 auto __last1 = _IterOps<_AlgPolicy>::next(__first1, __sent1);
154 auto __last2 = _IterOps<_AlgPolicy>::next(__first2, __sent2);
155 // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern
156 auto __len2 = __last2 - __first2;
157 if (__len2 == 0)
158 return __last1;
159 auto __len1 = __last1 - __first1;
160 if (__len1 < __len2)
161 return __last1;
162 const _Iter1 __s = __first1 + _D1(__len2 - 1); // End of pattern match can't go before here
163 _Iter1 __l1 = __last1;
164 _Iter2 __l2 = __last2;
165 --__l2;
166 while (true) {
167 while (true) {
168 if (__s == __l1)
169 return __last1;
170 if (std::__invoke(__pred, std::__invoke(__proj1, *--__l1), std::__invoke(__proj2, *__l2)))
171 break;
172 }
173 _Iter1 __m1 = __l1;
174 _Iter2 __m2 = __l2;
175 while (true) {
176 if (__m2 == __first2)
177 return __m1;
178 // no need to check range on __m1 because __s guarantees we have enough source
179 if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(*--__m2))) {
180 break;
181 }
182 }
183 }
184}
185
18679template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
187_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_end_classic(
80[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_end_classic(
18881 _ForwardIterator1 __first1,
18982 _ForwardIterator1 __last1,
19083 _ForwardIterator2 __first2,
......@@ -205,7 +98,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Fo
20598}
20699
207100template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
208_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_end(
101[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_end(
209102 _ForwardIterator1 __first1,
210103 _ForwardIterator1 __last1,
211104 _ForwardIterator2 __first2,
......@@ -215,7 +108,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Fo
215108}
216109
217110template <class _ForwardIterator1, class _ForwardIterator2>
218_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1
111[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1
219112find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
220113 return std::find_end(__first1, __last1, __first2, __last2, __equal_to());
221114}
lib/libcxx/include/__algorithm/find_first_of.h+2-3
......@@ -12,7 +12,6 @@
1212
1313#include <__algorithm/comp.h>
1414#include <__config>
15#include <__iterator/iterator_traits.h>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1817# pragma GCC system_header
......@@ -35,7 +34,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_fir
3534}
3635
3736template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
38_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of(
37[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of(
3938 _ForwardIterator1 __first1,
4039 _ForwardIterator1 __last1,
4140 _ForwardIterator2 __first2,
......@@ -45,7 +44,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Fo
4544}
4645
4746template <class _ForwardIterator1, class _ForwardIterator2>
48_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of(
47[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of(
4948 _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
5049 return std::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to());
5150}
lib/libcxx/include/__algorithm/find_if.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _InputIterator, class _Predicate>
22_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
22[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
2323find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
2424 for (; __first != __last; ++__first)
2525 if (__pred(*__first))
lib/libcxx/include/__algorithm/find_if_not.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _InputIterator, class _Predicate>
22_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
22[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
2323find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
2424 for (; __first != __last; ++__first)
2525 if (!__pred(*__first))
lib/libcxx/include/__algorithm/fold.h deleted-128
......@@ -1,128 +0,0 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___ALGORITHM_FOLD_H
11#define _LIBCPP___ALGORITHM_FOLD_H
12
13#include <__concepts/assignable.h>
14#include <__concepts/convertible_to.h>
15#include <__concepts/invocable.h>
16#include <__concepts/movable.h>
17#include <__config>
18#include <__functional/invoke.h>
19#include <__functional/reference_wrapper.h>
20#include <__iterator/concepts.h>
21#include <__iterator/iterator_traits.h>
22#include <__iterator/next.h>
23#include <__ranges/access.h>
24#include <__ranges/concepts.h>
25#include <__ranges/dangling.h>
26#include <__type_traits/decay.h>
27#include <__type_traits/invoke.h>
28#include <__utility/forward.h>
29#include <__utility/move.h>
30
31#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
32# pragma GCC system_header
33#endif
34
35_LIBCPP_PUSH_MACROS
36#include <__undef_macros>
37
38_LIBCPP_BEGIN_NAMESPACE_STD
39
40#if _LIBCPP_STD_VER >= 23
41
42namespace ranges {
43template <class _Ip, class _Tp>
44struct in_value_result {
45 _LIBCPP_NO_UNIQUE_ADDRESS _Ip in;
46 _LIBCPP_NO_UNIQUE_ADDRESS _Tp value;
47
48 template <class _I2, class _T2>
49 requires convertible_to<const _Ip&, _I2> && convertible_to<const _Tp&, _T2>
50 _LIBCPP_HIDE_FROM_ABI constexpr operator in_value_result<_I2, _T2>() const& {
51 return {in, value};
52 }
53
54 template <class _I2, class _T2>
55 requires convertible_to<_Ip, _I2> && convertible_to<_Tp, _T2>
56 _LIBCPP_HIDE_FROM_ABI constexpr operator in_value_result<_I2, _T2>() && {
57 return {std::move(in), std::move(value)};
58 }
59};
60
61template <class _Ip, class _Tp>
62using fold_left_with_iter_result = in_value_result<_Ip, _Tp>;
63
64template <class _Fp, class _Tp, class _Ip, class _Rp, class _Up = decay_t<_Rp>>
65concept __indirectly_binary_left_foldable_impl =
66 convertible_to<_Rp, _Up> && //
67 movable<_Tp> && //
68 movable<_Up> && //
69 convertible_to<_Tp, _Up> && //
70 invocable<_Fp&, _Up, iter_reference_t<_Ip>> && //
71 assignable_from<_Up&, invoke_result_t<_Fp&, _Up, iter_reference_t<_Ip>>>;
72
73template <class _Fp, class _Tp, class _Ip>
74concept __indirectly_binary_left_foldable =
75 copy_constructible<_Fp> && //
76 invocable<_Fp&, _Tp, iter_reference_t<_Ip>> && //
77 __indirectly_binary_left_foldable_impl<_Fp, _Tp, _Ip, invoke_result_t<_Fp&, _Tp, iter_reference_t<_Ip>>>;
78
79struct __fold_left_with_iter {
80 template <input_iterator _Ip, sentinel_for<_Ip> _Sp, class _Tp, __indirectly_binary_left_foldable<_Tp, _Ip> _Fp>
81 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Ip __first, _Sp __last, _Tp __init, _Fp __f) {
82 using _Up = decay_t<invoke_result_t<_Fp&, _Tp, iter_reference_t<_Ip>>>;
83
84 if (__first == __last) {
85 return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), _Up(std::move(__init))};
86 }
87
88 _Up __result = std::invoke(__f, std::move(__init), *__first);
89 for (++__first; __first != __last; ++__first) {
90 __result = std::invoke(__f, std::move(__result), *__first);
91 }
92
93 return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), std::move(__result)};
94 }
95
96 template <input_range _Rp, class _Tp, __indirectly_binary_left_foldable<_Tp, iterator_t<_Rp>> _Fp>
97 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Rp&& __r, _Tp __init, _Fp __f) {
98 auto __result = operator()(ranges::begin(__r), ranges::end(__r), std::move(__init), std::ref(__f));
99
100 using _Up = decay_t<invoke_result_t<_Fp&, _Tp, range_reference_t<_Rp>>>;
101 return fold_left_with_iter_result<borrowed_iterator_t<_Rp>, _Up>{std::move(__result.in), std::move(__result.value)};
102 }
103};
104
105inline constexpr auto fold_left_with_iter = __fold_left_with_iter();
106
107struct __fold_left {
108 template <input_iterator _Ip, sentinel_for<_Ip> _Sp, class _Tp, __indirectly_binary_left_foldable<_Tp, _Ip> _Fp>
109 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Ip __first, _Sp __last, _Tp __init, _Fp __f) {
110 return fold_left_with_iter(std::move(__first), std::move(__last), std::move(__init), std::ref(__f)).value;
111 }
112
113 template <input_range _Rp, class _Tp, __indirectly_binary_left_foldable<_Tp, iterator_t<_Rp>> _Fp>
114 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Rp&& __r, _Tp __init, _Fp __f) {
115 return fold_left_with_iter(ranges::begin(__r), ranges::end(__r), std::move(__init), std::ref(__f)).value;
116 }
117};
118
119inline constexpr auto fold_left = __fold_left();
120} // namespace ranges
121
122#endif // _LIBCPP_STD_VER >= 23
123
124_LIBCPP_END_NAMESPACE_STD
125
126_LIBCPP_POP_MACROS
127
128#endif // _LIBCPP___ALGORITHM_FOLD_H
lib/libcxx/include/__algorithm/for_each.h-1
......@@ -14,7 +14,6 @@
1414#include <__config>
1515#include <__iterator/segmented_iterator.h>
1616#include <__ranges/movable_box.h>
17#include <__type_traits/enable_if.h>
1817#include <__utility/in_place.h>
1918#include <__utility/move.h>
2019
lib/libcxx/include/__algorithm/includes.h+4-5
......@@ -13,8 +13,7 @@
1313#include <__algorithm/comp_ref_type.h>
1414#include <__config>
1515#include <__functional/identity.h>
16#include <__functional/invoke.h>
17#include <__iterator/iterator_traits.h>
16#include <__type_traits/invoke.h>
1817#include <__type_traits/is_callable.h>
1918#include <__utility/move.h>
2019
......@@ -47,14 +46,14 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __includes(
4746}
4847
4948template <class _InputIterator1, class _InputIterator2, class _Compare>
50_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
49[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
5150includes(_InputIterator1 __first1,
5251 _InputIterator1 __last1,
5352 _InputIterator2 __first2,
5453 _InputIterator2 __last2,
5554 _Compare __comp) {
5655 static_assert(
57 __is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value, "Comparator has to be callable");
56 __is_callable<_Compare&, decltype(*__first1), decltype(*__first2)>::value, "The comparator has to be callable");
5857
5958 return std::__includes(
6059 std::move(__first1),
......@@ -67,7 +66,7 @@ includes(_InputIterator1 __first1,
6766}
6867
6968template <class _InputIterator1, class _InputIterator2>
70_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
69[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
7170includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
7271 return std::includes(std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __less<>());
7372}
lib/libcxx/include/__algorithm/inplace_merge.h+22-20
......@@ -18,16 +18,15 @@
1818#include <__algorithm/rotate.h>
1919#include <__algorithm/upper_bound.h>
2020#include <__config>
21#include <__cstddef/ptrdiff_t.h>
2122#include <__functional/identity.h>
22#include <__iterator/advance.h>
23#include <__iterator/distance.h>
2423#include <__iterator/iterator_traits.h>
2524#include <__iterator/reverse_iterator.h>
2625#include <__memory/destruct_n.h>
27#include <__memory/temporary_buffer.h>
2826#include <__memory/unique_ptr.h>
27#include <__memory/unique_temporary_buffer.h>
28#include <__utility/move.h>
2929#include <__utility/pair.h>
30#include <new>
3130
3231#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3332# pragma GCC system_header
......@@ -45,17 +44,17 @@ private:
4544 _Predicate __p_;
4645
4746public:
48 _LIBCPP_HIDE_FROM_ABI __invert() {}
47 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __invert() {}
4948
50 _LIBCPP_HIDE_FROM_ABI explicit __invert(_Predicate __p) : __p_(__p) {}
49 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __invert(_Predicate __p) : __p_(__p) {}
5150
5251 template <class _T1>
53 _LIBCPP_HIDE_FROM_ABI bool operator()(const _T1& __x) {
52 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator()(const _T1& __x) {
5453 return !__p_(__x);
5554 }
5655
5756 template <class _T1, class _T2>
58 _LIBCPP_HIDE_FROM_ABI bool operator()(const _T1& __x, const _T2& __y) {
57 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator()(const _T1& __x, const _T2& __y) {
5958 return __p_(__y, __x);
6059 }
6160};
......@@ -67,7 +66,7 @@ template <class _AlgPolicy,
6766 class _InputIterator2,
6867 class _Sent2,
6968 class _OutputIterator>
70_LIBCPP_HIDE_FROM_ABI void __half_inplace_merge(
69_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __half_inplace_merge(
7170 _InputIterator1 __first1,
7271 _Sent1 __last1,
7372 _InputIterator2 __first2,
......@@ -92,7 +91,7 @@ _LIBCPP_HIDE_FROM_ABI void __half_inplace_merge(
9291}
9392
9493template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
95_LIBCPP_HIDE_FROM_ABI void __buffered_inplace_merge(
94_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __buffered_inplace_merge(
9695 _BidirectionalIterator __first,
9796 _BidirectionalIterator __middle,
9897 _BidirectionalIterator __last,
......@@ -123,7 +122,7 @@ _LIBCPP_HIDE_FROM_ABI void __buffered_inplace_merge(
123122}
124123
125124template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
126void __inplace_merge(
125_LIBCPP_CONSTEXPR_SINCE_CXX26 void __inplace_merge(
127126 _BidirectionalIterator __first,
128127 _BidirectionalIterator __middle,
129128 _BidirectionalIterator __last,
......@@ -208,16 +207,19 @@ _LIBCPP_HIDE_FROM_ABI void __inplace_merge(
208207 _BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare&& __comp) {
209208 typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
210209 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
211 difference_type __len1 = _IterOps<_AlgPolicy>::distance(__first, __middle);
212 difference_type __len2 = _IterOps<_AlgPolicy>::distance(__middle, __last);
213 difference_type __buf_size = std::min(__len1, __len2);
214 // TODO: Remove the use of std::get_temporary_buffer
215 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
216 pair<value_type*, ptrdiff_t> __buf = std::get_temporary_buffer<value_type>(__buf_size);
217 _LIBCPP_SUPPRESS_DEPRECATED_POP
218 unique_ptr<value_type, __return_temporary_buffer> __h(__buf.first);
210 difference_type __len1 = _IterOps<_AlgPolicy>::distance(__first, __middle);
211 difference_type __len2 = _IterOps<_AlgPolicy>::distance(__middle, __last);
212 difference_type __buf_size = std::min(__len1, __len2);
213 __unique_temporary_buffer<value_type> __unique_buf = std::__allocate_unique_temporary_buffer<value_type>(__buf_size);
219214 return std::__inplace_merge<_AlgPolicy>(
220 std::move(__first), std::move(__middle), std::move(__last), __comp, __len1, __len2, __buf.first, __buf.second);
215 std::move(__first),
216 std::move(__middle),
217 std::move(__last),
218 __comp,
219 __len1,
220 __len2,
221 __unique_buf.get(),
222 __unique_buf.get_deleter().__count_);
221223}
222224
223225template <class _BidirectionalIterator, class _Compare>
lib/libcxx/include/__algorithm/is_heap.h+2-3
......@@ -13,7 +13,6 @@
1313#include <__algorithm/comp_ref_type.h>
1414#include <__algorithm/is_heap_until.h>
1515#include <__config>
16#include <__iterator/iterator_traits.h>
1716
1817#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1918# pragma GCC system_header
......@@ -22,13 +21,13 @@
2221_LIBCPP_BEGIN_NAMESPACE_STD
2322
2423template <class _RandomAccessIterator, class _Compare>
25_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
24[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
2625is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
2726 return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp)) == __last;
2827}
2928
3029template <class _RandomAccessIterator>
31_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
30[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
3231is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
3332 return std::is_heap(__first, __last, __less<>());
3433}
lib/libcxx/include/__algorithm/is_heap_until.h+2-2
......@@ -46,13 +46,13 @@ __is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Co
4646}
4747
4848template <class _RandomAccessIterator, class _Compare>
49_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
49[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
5050is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
5151 return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp));
5252}
5353
5454template <class _RandomAccessIterator>
55_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
55[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
5656is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last) {
5757 return std::__is_heap_until(__first, __last, __less<>());
5858}
lib/libcxx/include/__algorithm/is_partitioned.h+1-1
......@@ -18,7 +18,7 @@
1818_LIBCPP_BEGIN_NAMESPACE_STD
1919
2020template <class _InputIterator, class _Predicate>
21_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
21[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
2222is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
2323 for (; __first != __last; ++__first)
2424 if (!__pred(*__first))
lib/libcxx/include/__algorithm/is_permutation.h+12-11
......@@ -14,12 +14,13 @@
1414#include <__algorithm/iterator_operations.h>
1515#include <__config>
1616#include <__functional/identity.h>
17#include <__functional/invoke.h>
1817#include <__iterator/concepts.h>
1918#include <__iterator/distance.h>
2019#include <__iterator/iterator_traits.h>
21#include <__iterator/next.h>
20#include <__type_traits/enable_if.h>
21#include <__type_traits/invoke.h>
2222#include <__type_traits/is_callable.h>
23#include <__type_traits/is_same.h>
2324#include <__utility/move.h>
2425
2526#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -113,7 +114,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation_impl(
113114
114115// 2+1 iterators, predicate. Not used by range algorithms.
115116template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2, class _BinaryPredicate>
116_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(
117[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(
117118 _ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2, _BinaryPredicate&& __pred) {
118119 // Shorten sequences as much as possible by lopping of any equal prefix.
119120 for (; __first1 != __last1; ++__first1, (void)++__first2) {
......@@ -247,17 +248,17 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation(
247248
248249// 2+1 iterators, predicate
249250template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
250_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(
251[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(
251252 _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _BinaryPredicate __pred) {
252 static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
253 "The predicate has to be callable");
253 static_assert(__is_callable<_BinaryPredicate&, decltype(*__first1), decltype(*__first2)>::value,
254 "The comparator has to be callable");
254255
255256 return std::__is_permutation<_ClassicAlgPolicy>(std::move(__first1), std::move(__last1), std::move(__first2), __pred);
256257}
257258
258259// 2+1 iterators
259260template <class _ForwardIterator1, class _ForwardIterator2>
260_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
261[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
261262is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) {
262263 return std::is_permutation(__first1, __last1, __first2, __equal_to());
263264}
......@@ -266,7 +267,7 @@ is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIt
266267
267268// 2+2 iterators
268269template <class _ForwardIterator1, class _ForwardIterator2>
269_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(
270[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(
270271 _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
271272 return std::__is_permutation<_ClassicAlgPolicy>(
272273 std::move(__first1),
......@@ -280,14 +281,14 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 boo
280281
281282// 2+2 iterators, predicate
282283template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
283_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(
284[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(
284285 _ForwardIterator1 __first1,
285286 _ForwardIterator1 __last1,
286287 _ForwardIterator2 __first2,
287288 _ForwardIterator2 __last2,
288289 _BinaryPredicate __pred) {
289 static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
290 "The predicate has to be callable");
290 static_assert(__is_callable<_BinaryPredicate&, decltype(*__first1), decltype(*__first2)>::value,
291 "The comparator has to be callable");
291292
292293 return std::__is_permutation<_ClassicAlgPolicy>(
293294 std::move(__first1),
lib/libcxx/include/__algorithm/is_sorted.h+2-3
......@@ -13,7 +13,6 @@
1313#include <__algorithm/comp_ref_type.h>
1414#include <__algorithm/is_sorted_until.h>
1515#include <__config>
16#include <__iterator/iterator_traits.h>
1716
1817#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1918# pragma GCC system_header
......@@ -22,13 +21,13 @@
2221_LIBCPP_BEGIN_NAMESPACE_STD
2322
2423template <class _ForwardIterator, class _Compare>
25_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
24[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
2625is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
2726 return std::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp) == __last;
2827}
2928
3029template <class _ForwardIterator>
31_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
30[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
3231is_sorted(_ForwardIterator __first, _ForwardIterator __last) {
3332 return std::is_sorted(__first, __last, __less<>());
3433}
lib/libcxx/include/__algorithm/is_sorted_until.h+2-3
......@@ -12,7 +12,6 @@
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
1414#include <__config>
15#include <__iterator/iterator_traits.h>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1817# pragma GCC system_header
......@@ -35,13 +34,13 @@ __is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __
3534}
3635
3736template <class _ForwardIterator, class _Compare>
38_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
37[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
3938is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
4039 return std::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp);
4140}
4241
4342template <class _ForwardIterator>
44_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
43[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
4544is_sorted_until(_ForwardIterator __first, _ForwardIterator __last) {
4645 return std::is_sorted_until(__first, __last, __less<>());
4746}
lib/libcxx/include/__algorithm/iterator_operations.h+11-8
......@@ -48,13 +48,13 @@ struct _RangeAlgPolicy {};
4848template <>
4949struct _IterOps<_RangeAlgPolicy> {
5050 template <class _Iter>
51 using __value_type = iter_value_t<_Iter>;
51 using __value_type _LIBCPP_NODEBUG = iter_value_t<_Iter>;
5252
5353 template <class _Iter>
54 using __iterator_category = ranges::__iterator_concept<_Iter>;
54 using __iterator_category _LIBCPP_NODEBUG = ranges::__iterator_concept<_Iter>;
5555
5656 template <class _Iter>
57 using __difference_type = iter_difference_t<_Iter>;
57 using __difference_type _LIBCPP_NODEBUG = iter_difference_t<_Iter>;
5858
5959 static constexpr auto advance = ranges::advance;
6060 static constexpr auto distance = ranges::distance;
......@@ -72,13 +72,13 @@ struct _ClassicAlgPolicy {};
7272template <>
7373struct _IterOps<_ClassicAlgPolicy> {
7474 template <class _Iter>
75 using __value_type = typename iterator_traits<_Iter>::value_type;
75 using __value_type _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::value_type;
7676
7777 template <class _Iter>
78 using __iterator_category = typename iterator_traits<_Iter>::iterator_category;
78 using __iterator_category _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::iterator_category;
7979
8080 template <class _Iter>
81 using __difference_type = typename iterator_traits<_Iter>::difference_type;
81 using __difference_type _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::difference_type;
8282
8383 // advance
8484 template <class _Iter, class _Distance>
......@@ -94,10 +94,10 @@ struct _IterOps<_ClassicAlgPolicy> {
9494 }
9595
9696 template <class _Iter>
97 using __deref_t = decltype(*std::declval<_Iter&>());
97 using __deref_t _LIBCPP_NODEBUG = decltype(*std::declval<_Iter&>());
9898
9999 template <class _Iter>
100 using __move_t = decltype(std::move(*std::declval<_Iter&>()));
100 using __move_t _LIBCPP_NODEBUG = decltype(std::move(*std::declval<_Iter&>()));
101101
102102 template <class _Iter>
103103 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static void __validate_iter_reference() {
......@@ -216,6 +216,9 @@ private:
216216 }
217217};
218218
219template <class _AlgPolicy, class _Iter>
220using __policy_iter_diff_t _LIBCPP_NODEBUG = typename _IterOps<_AlgPolicy>::template __difference_type<_Iter>;
221
219222_LIBCPP_END_NAMESPACE_STD
220223
221224_LIBCPP_POP_MACROS
lib/libcxx/include/__algorithm/lexicographical_compare.h+85-13
......@@ -10,48 +10,120 @@
1010#define _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H
1111
1212#include <__algorithm/comp.h>
13#include <__algorithm/comp_ref_type.h>
13#include <__algorithm/min.h>
14#include <__algorithm/mismatch.h>
15#include <__algorithm/simd_utils.h>
16#include <__algorithm/unwrap_iter.h>
1417#include <__config>
18#include <__functional/identity.h>
1519#include <__iterator/iterator_traits.h>
20#include <__string/constexpr_c_functions.h>
21#include <__type_traits/desugars_to.h>
22#include <__type_traits/enable_if.h>
23#include <__type_traits/invoke.h>
24#include <__type_traits/is_equality_comparable.h>
25#include <__type_traits/is_integral.h>
26#include <__type_traits/is_trivially_lexicographically_comparable.h>
27#include <__type_traits/is_volatile.h>
28
29#if _LIBCPP_HAS_WIDE_CHARACTERS
30# include <cwchar>
31#endif
1632
1733#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1834# pragma GCC system_header
1935#endif
2036
37_LIBCPP_PUSH_MACROS
38#include <__undef_macros>
39
2140_LIBCPP_BEGIN_NAMESPACE_STD
2241
23template <class _Compare, class _InputIterator1, class _InputIterator2>
42template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Proj1, class _Proj2, class _Comp>
2443_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __lexicographical_compare(
25 _InputIterator1 __first1,
26 _InputIterator1 __last1,
27 _InputIterator2 __first2,
28 _InputIterator2 __last2,
29 _Compare __comp) {
30 for (; __first2 != __last2; ++__first1, (void)++__first2) {
31 if (__first1 == __last1 || __comp(*__first1, *__first2))
44 _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Comp& __comp, _Proj1& __proj1, _Proj2& __proj2) {
45 while (__first2 != __last2) {
46 if (__first1 == __last1 ||
47 std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
3248 return true;
33 if (__comp(*__first2, *__first1))
49 if (std::__invoke(__comp, std::__invoke(__proj2, *__first2), std::__invoke(__proj1, *__first1)))
3450 return false;
51 ++__first1;
52 ++__first2;
3553 }
3654 return false;
3755}
3856
57#if _LIBCPP_STD_VER >= 14
58
59// If the comparison operation is equivalent to < and that is a total order, we know that we can use equality comparison
60// on that type instead to extract some information. Furthermore, if equality comparison on that type is trivial, the
61// user can't observe that we're calling it. So instead of using the user-provided total order, we use std::mismatch,
62// which uses equality comparison (and is vertorized). Additionally, if the type is trivially lexicographically
63// comparable, we can go one step further and use std::memcmp directly instead of calling std::mismatch.
64template <class _Tp,
65 class _Proj1,
66 class _Proj2,
67 class _Comp,
68 __enable_if_t<__desugars_to_v<__totally_ordered_less_tag, _Comp, _Tp, _Tp> && !is_volatile<_Tp>::value &&
69 __libcpp_is_trivially_equality_comparable<_Tp, _Tp>::value &&
70 __is_identity<_Proj1>::value && __is_identity<_Proj2>::value,
71 int> = 0>
72_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
73__lexicographical_compare(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Tp* __last2, _Comp&, _Proj1&, _Proj2&) {
74 if constexpr (__is_trivially_lexicographically_comparable_v<_Tp, _Tp>) {
75 auto __res =
76 std::__constexpr_memcmp(__first1, __first2, __element_count(std::min(__last1 - __first1, __last2 - __first2)));
77 if (__res == 0)
78 return __last1 - __first1 < __last2 - __first2;
79 return __res < 0;
80 }
81# if _LIBCPP_HAS_WIDE_CHARACTERS
82 else if constexpr (is_same<__remove_cv_t<_Tp>, wchar_t>::value) {
83 auto __res = std::__constexpr_wmemcmp(__first1, __first2, std::min(__last1 - __first1, __last2 - __first2));
84 if (__res == 0)
85 return __last1 - __first1 < __last2 - __first2;
86 return __res < 0;
87 }
88# endif // _LIBCPP_HAS_WIDE_CHARACTERS
89 else {
90 auto __res = std::mismatch(__first1, __last1, __first2, __last2);
91 if (__res.second == __last2)
92 return false;
93 if (__res.first == __last1)
94 return true;
95 return *__res.first < *__res.second;
96 }
97}
98
99#endif // _LIBCPP_STD_VER >= 14
100
39101template <class _InputIterator1, class _InputIterator2, class _Compare>
40_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare(
102[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare(
41103 _InputIterator1 __first1,
42104 _InputIterator1 __last1,
43105 _InputIterator2 __first2,
44106 _InputIterator2 __last2,
45107 _Compare __comp) {
46 return std::__lexicographical_compare<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __comp);
108 __identity __proj;
109 return std::__lexicographical_compare(
110 std::__unwrap_iter(__first1),
111 std::__unwrap_iter(__last1),
112 std::__unwrap_iter(__first2),
113 std::__unwrap_iter(__last2),
114 __comp,
115 __proj,
116 __proj);
47117}
48118
49119template <class _InputIterator1, class _InputIterator2>
50_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare(
120[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare(
51121 _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
52122 return std::lexicographical_compare(__first1, __last1, __first2, __last2, __less<>());
53123}
54124
55125_LIBCPP_END_NAMESPACE_STD
56126
127_LIBCPP_POP_MACROS
128
57129#endif // _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H
lib/libcxx/include/__algorithm/lower_bound.h+7-8
......@@ -14,12 +14,11 @@
1414#include <__algorithm/iterator_operations.h>
1515#include <__config>
1616#include <__functional/identity.h>
17#include <__functional/invoke.h>
1817#include <__iterator/advance.h>
1918#include <__iterator/distance.h>
2019#include <__iterator/iterator_traits.h>
20#include <__type_traits/invoke.h>
2121#include <__type_traits/is_callable.h>
22#include <__type_traits/remove_reference.h>
2322
2423#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2524# pragma GCC system_header
......@@ -28,7 +27,7 @@
2827_LIBCPP_BEGIN_NAMESPACE_STD
2928
3029template <class _AlgPolicy, class _Iter, class _Type, class _Proj, class _Comp>
31_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter __lower_bound_bisecting(
30[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter __lower_bound_bisecting(
3231 _Iter __first,
3332 const _Type& __value,
3433 typename iterator_traits<_Iter>::difference_type __len,
......@@ -58,7 +57,7 @@ _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter __lo
5857// whereas the one-sided version will yield O(n) operations on both counts, with a \Omega(log(n)) bound on the number of
5958// comparisons.
6059template <class _AlgPolicy, class _ForwardIterator, class _Sent, class _Type, class _Proj, class _Comp>
61_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
60[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
6261__lower_bound_onesided(_ForwardIterator __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) {
6362 // step = 0, ensuring we can always short-circuit when distance is 1 later on
6463 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
8483}
8584
8685template <class _AlgPolicy, class _ForwardIterator, class _Sent, class _Type, class _Proj, class _Comp>
87_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
86[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
8887__lower_bound(_ForwardIterator __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) {
8988 const auto __dist = _IterOps<_AlgPolicy>::distance(__first, __last);
9089 return std::__lower_bound_bisecting<_AlgPolicy>(__first, __value, __dist, __comp, __proj);
9190}
9291
9392template <class _ForwardIterator, class _Tp, class _Compare>
94_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
93[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
9594lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
96 static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
95 static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
9796 auto __proj = std::__identity();
9897 return std::__lower_bound<_ClassicAlgPolicy>(__first, __last, __value, __comp, __proj);
9998}
10099
101100template <class _ForwardIterator, class _Tp>
102_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
101[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
103102lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
104103 return std::lower_bound(__first, __last, __value, __less<>());
105104}
lib/libcxx/include/__algorithm/make_projected.h+7-9
......@@ -9,15 +9,13 @@
99#ifndef _LIBCPP___ALGORITHM_MAKE_PROJECTED_H
1010#define _LIBCPP___ALGORITHM_MAKE_PROJECTED_H
1111
12#include <__concepts/same_as.h>
1312#include <__config>
1413#include <__functional/identity.h>
1514#include <__functional/invoke.h>
1615#include <__type_traits/decay.h>
1716#include <__type_traits/enable_if.h>
18#include <__type_traits/integral_constant.h>
17#include <__type_traits/invoke.h>
1918#include <__type_traits/is_member_pointer.h>
20#include <__type_traits/is_same.h>
2119#include <__utility/declval.h>
2220#include <__utility/forward.h>
2321
......@@ -36,16 +34,16 @@ struct _ProjectedPred {
3634 : __pred(__pred_arg), __proj(__proj_arg) {}
3735
3836 template <class _Tp>
39 typename __invoke_of<_Pred&, decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_Tp>()))>::type
40 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
41 operator()(_Tp&& __v) const {
37 __invoke_result_t<_Pred&, decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_Tp>()))> _LIBCPP_CONSTEXPR
38 _LIBCPP_HIDE_FROM_ABI
39 operator()(_Tp&& __v) const {
4240 return std::__invoke(__pred, std::__invoke(__proj, std::forward<_Tp>(__v)));
4341 }
4442
4543 template <class _T1, class _T2>
46 typename __invoke_of<_Pred&,
47 decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T1>())),
48 decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T2>()))>::type _LIBCPP_CONSTEXPR
44 __invoke_result_t<_Pred&,
45 decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T1>())),
46 decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T2>()))> _LIBCPP_CONSTEXPR
4947 _LIBCPP_HIDE_FROM_ABI
5048 operator()(_T1&& __lhs, _T2&& __rhs) const {
5149 return std::__invoke(
lib/libcxx/include/__algorithm/max.h+4-4
......@@ -25,13 +25,13 @@ _LIBCPP_PUSH_MACROS
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
2727template <class _Tp, class _Compare>
28_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
28[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
2929max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) {
3030 return __comp(__a, __b) ? __b : __a;
3131}
3232
3333template <class _Tp>
34_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
34[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
3535max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) {
3636 return std::max(__a, __b, __less<>());
3737}
......@@ -39,13 +39,13 @@ max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b)
3939#ifndef _LIBCPP_CXX03_LANG
4040
4141template <class _Tp, class _Compare>
42_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp
42[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp
4343max(initializer_list<_Tp> __t, _Compare __comp) {
4444 return *std::__max_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp);
4545}
4646
4747template <class _Tp>
48_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp max(initializer_list<_Tp> __t) {
48[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp max(initializer_list<_Tp> __t) {
4949 return *std::max_element(__t.begin(), __t.end(), __less<>());
5050}
5151
lib/libcxx/include/__algorithm/max_element.h+5-2
......@@ -13,6 +13,7 @@
1313#include <__algorithm/comp_ref_type.h>
1414#include <__config>
1515#include <__iterator/iterator_traits.h>
16#include <__type_traits/is_callable.h>
1617
1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1819# pragma GCC system_header
......@@ -35,13 +36,15 @@ __max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp
3536}
3637
3738template <class _ForwardIterator, class _Compare>
38_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
39[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
3940max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
41 static_assert(
42 __is_callable<_Compare&, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
4043 return std::__max_element<__comp_ref_type<_Compare> >(__first, __last, __comp);
4144}
4245
4346template <class _ForwardIterator>
44_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
47[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
4548max_element(_ForwardIterator __first, _ForwardIterator __last) {
4649 return std::max_element(__first, __last, __less<>());
4750}
lib/libcxx/include/__algorithm/merge.h-1
......@@ -13,7 +13,6 @@
1313#include <__algorithm/comp_ref_type.h>
1414#include <__algorithm/copy.h>
1515#include <__config>
16#include <__iterator/iterator_traits.h>
1716
1817#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1918# pragma GCC system_header
lib/libcxx/include/__algorithm/min.h+4-4
......@@ -25,13 +25,13 @@ _LIBCPP_PUSH_MACROS
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
2727template <class _Tp, class _Compare>
28_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
28[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
2929min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) {
3030 return __comp(__b, __a) ? __b : __a;
3131}
3232
3333template <class _Tp>
34_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
34[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&
3535min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) {
3636 return std::min(__a, __b, __less<>());
3737}
......@@ -39,13 +39,13 @@ min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b)
3939#ifndef _LIBCPP_CXX03_LANG
4040
4141template <class _Tp, class _Compare>
42_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp
42[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp
4343min(initializer_list<_Tp> __t, _Compare __comp) {
4444 return *std::__min_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp);
4545}
4646
4747template <class _Tp>
48_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp min(initializer_list<_Tp> __t) {
48[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp min(initializer_list<_Tp> __t) {
4949 return *std::min_element(__t.begin(), __t.end(), __less<>());
5050}
5151
lib/libcxx/include/__algorithm/min_element.h+4-4
......@@ -13,8 +13,8 @@
1313#include <__algorithm/comp_ref_type.h>
1414#include <__config>
1515#include <__functional/identity.h>
16#include <__functional/invoke.h>
1716#include <__iterator/iterator_traits.h>
17#include <__type_traits/invoke.h>
1818#include <__type_traits/is_callable.h>
1919#include <__utility/move.h>
2020
......@@ -48,18 +48,18 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter __min_element(_Iter __
4848}
4949
5050template <class _ForwardIterator, class _Compare>
51_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
51[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
5252min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
5353 static_assert(
5454 __has_forward_iterator_category<_ForwardIterator>::value, "std::min_element requires a ForwardIterator");
5555 static_assert(
56 __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
56 __is_callable<_Compare&, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
5757
5858 return std::__min_element<__comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp);
5959}
6060
6161template <class _ForwardIterator>
62_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
62[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
6363min_element(_ForwardIterator __first, _ForwardIterator __last) {
6464 return std::min_element(__first, __last, __less<>());
6565}
lib/libcxx/include/__algorithm/minmax.h+5-5
......@@ -24,13 +24,13 @@
2424_LIBCPP_BEGIN_NAMESPACE_STD
2525
2626template <class _Tp, class _Compare>
27_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<const _Tp&, const _Tp&>
27[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<const _Tp&, const _Tp&>
2828minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) {
2929 return __comp(__b, __a) ? pair<const _Tp&, const _Tp&>(__b, __a) : pair<const _Tp&, const _Tp&>(__a, __b);
3030}
3131
3232template <class _Tp>
33_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<const _Tp&, const _Tp&>
33[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<const _Tp&, const _Tp&>
3434minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) {
3535 return std::minmax(__a, __b, __less<>());
3636}
......@@ -38,16 +38,16 @@ minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __
3838#ifndef _LIBCPP_CXX03_LANG
3939
4040template <class _Tp, class _Compare>
41_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp>
41[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp>
4242minmax(initializer_list<_Tp> __t, _Compare __comp) {
43 static_assert(__is_callable<_Compare, _Tp, _Tp>::value, "The comparator has to be callable");
43 static_assert(__is_callable<_Compare&, _Tp, _Tp>::value, "The comparator has to be callable");
4444 __identity __proj;
4545 auto __ret = std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj);
4646 return pair<_Tp, _Tp>(*__ret.first, *__ret.second);
4747}
4848
4949template <class _Tp>
50_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp>
50[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp>
5151minmax(initializer_list<_Tp> __t) {
5252 return std::minmax(__t, __less<>());
5353}
lib/libcxx/include/__algorithm/minmax_element.h+4-4
......@@ -12,8 +12,8 @@
1212#include <__algorithm/comp.h>
1313#include <__config>
1414#include <__functional/identity.h>
15#include <__functional/invoke.h>
1615#include <__iterator/iterator_traits.h>
16#include <__type_traits/invoke.h>
1717#include <__type_traits/is_callable.h>
1818#include <__utility/pair.h>
1919
......@@ -79,18 +79,18 @@ __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj)
7979}
8080
8181template <class _ForwardIterator, class _Compare>
82_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_ForwardIterator, _ForwardIterator>
82[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_ForwardIterator, _ForwardIterator>
8383minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
8484 static_assert(
8585 __has_forward_iterator_category<_ForwardIterator>::value, "std::minmax_element requires a ForwardIterator");
8686 static_assert(
87 __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
87 __is_callable<_Compare&, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
8888 auto __proj = __identity();
8989 return std::__minmax_element_impl(__first, __last, __comp, __proj);
9090}
9191
9292template <class _ForwardIterator>
93_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_ForwardIterator, _ForwardIterator>
93[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_ForwardIterator, _ForwardIterator>
9494minmax_element(_ForwardIterator __first, _ForwardIterator __last) {
9595 return std::minmax_element(__first, __last, __less<>());
9696}
lib/libcxx/include/__algorithm/mismatch.h+14-13
......@@ -15,17 +15,18 @@
1515#include <__algorithm/simd_utils.h>
1616#include <__algorithm/unwrap_iter.h>
1717#include <__config>
18#include <__cstddef/size_t.h>
1819#include <__functional/identity.h>
1920#include <__iterator/aliasing_iterator.h>
21#include <__iterator/iterator_traits.h>
2022#include <__type_traits/desugars_to.h>
23#include <__type_traits/enable_if.h>
2124#include <__type_traits/invoke.h>
2225#include <__type_traits/is_constant_evaluated.h>
2326#include <__type_traits/is_equality_comparable.h>
2427#include <__type_traits/is_integral.h>
2528#include <__utility/move.h>
2629#include <__utility/pair.h>
27#include <__utility/unreachable.h>
28#include <cstddef>
2930
3031#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3132# pragma GCC system_header
......@@ -37,7 +38,7 @@ _LIBCPP_PUSH_MACROS
3738_LIBCPP_BEGIN_NAMESPACE_STD
3839
3940template <class _Iter1, class _Sent1, class _Iter2, class _Pred, class _Proj1, class _Proj2>
40_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2>
41[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2>
4142__mismatch_loop(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) {
4243 while (__first1 != __last1) {
4344 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,
4950}
5051
5152template <class _Iter1, class _Sent1, class _Iter2, class _Pred, class _Proj1, class _Proj2>
52_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2>
53[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2>
5354__mismatch(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) {
5455 return std::__mismatch_loop(__first1, __last1, __first2, __pred, __proj1, __proj2);
5556}
......@@ -57,7 +58,7 @@ __mismatch(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Pred& __pred, _Pro
5758#if _LIBCPP_VECTORIZE_ALGORITHMS
5859
5960template <class _Iter>
60_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter, _Iter>
61[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter, _Iter>
6162__mismatch_vectorized(_Iter __first1, _Iter __last1, _Iter __first2) {
6263 using __value_type = __iter_value_type<_Iter>;
6364 constexpr size_t __unroll_count = 4;
......@@ -124,7 +125,7 @@ template <class _Tp,
124125 __enable_if_t<is_integral<_Tp>::value && __desugars_to_v<__equal_tag, _Pred, _Tp, _Tp> &&
125126 __is_identity<_Proj1>::value && __is_identity<_Proj2>::value,
126127 int> = 0>
127_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*>
128[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*>
128129__mismatch(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Pred&, _Proj1&, _Proj2&) {
129130 return std::__mismatch_vectorized(__first1, __last1, __first2);
130131}
......@@ -137,7 +138,7 @@ template <class _Tp,
137138 __is_identity<_Proj1>::value && __is_identity<_Proj2>::value &&
138139 __can_map_to_integer_v<_Tp> && __libcpp_is_trivially_equality_comparable<_Tp, _Tp>::value,
139140 int> = 0>
140_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*>
141[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*>
141142__mismatch(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) {
142143 if (__libcpp_is_constant_evaluated()) {
143144 return std::__mismatch_loop(__first1, __last1, __first2, __pred, __proj1, __proj2);
......@@ -150,7 +151,7 @@ __mismatch(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Pred& __pred, _Proj1& __
150151#endif // _LIBCPP_VECTORIZE_ALGORITHMS
151152
152153template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
153_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
154[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
154155mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) {
155156 __identity __proj;
156157 auto __res = std::__mismatch(
......@@ -159,14 +160,14 @@ mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __fi
159160}
160161
161162template <class _InputIterator1, class _InputIterator2>
162_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
163[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
163164mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) {
164165 return std::mismatch(__first1, __last1, __first2, __equal_to());
165166}
166167
167168#if _LIBCPP_STD_VER >= 14
168169template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
169_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> __mismatch(
170[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> __mismatch(
170171 _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) {
171172 while (__first1 != __last1 && __first2 != __last2) {
172173 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
178179}
179180
180181template <class _Tp, class _Pred, class _Proj1, class _Proj2>
181_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*>
182[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*>
182183__mismatch(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Tp* __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) {
183184 auto __len = std::min(__last1 - __first1, __last2 - __first2);
184185 return std::__mismatch(__first1, __first1 + __len, __first2, __pred, __proj1, __proj2);
185186}
186187
187188template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
188_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
189[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
189190mismatch(_InputIterator1 __first1,
190191 _InputIterator1 __last1,
191192 _InputIterator2 __first2,
......@@ -204,7 +205,7 @@ mismatch(_InputIterator1 __first1,
204205}
205206
206207template <class _InputIterator1, class _InputIterator2>
207_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
208[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2>
208209mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
209210 return std::mismatch(__first1, __last1, __first2, __last2, __equal_to());
210211}
lib/libcxx/include/__algorithm/move.h+3-1
......@@ -14,8 +14,10 @@
1414#include <__algorithm/iterator_operations.h>
1515#include <__algorithm/min.h>
1616#include <__config>
17#include <__iterator/iterator_traits.h>
1718#include <__iterator/segmented_iterator.h>
1819#include <__type_traits/common_type.h>
20#include <__type_traits/enable_if.h>
1921#include <__type_traits/is_constructible.h>
2022#include <__utility/move.h>
2123#include <__utility/pair.h>
......@@ -48,7 +50,7 @@ struct __move_impl {
4850
4951 template <class _InIter, class _OutIter>
5052 struct _MoveSegment {
51 using _Traits = __segmented_iterator_traits<_InIter>;
53 using _Traits _LIBCPP_NODEBUG = __segmented_iterator_traits<_InIter>;
5254
5355 _OutIter& __result_;
5456
lib/libcxx/include/__algorithm/move_backward.h+2
......@@ -13,8 +13,10 @@
1313#include <__algorithm/iterator_operations.h>
1414#include <__algorithm/min.h>
1515#include <__config>
16#include <__iterator/iterator_traits.h>
1617#include <__iterator/segmented_iterator.h>
1718#include <__type_traits/common_type.h>
19#include <__type_traits/enable_if.h>
1820#include <__type_traits/is_constructible.h>
1921#include <__utility/move.h>
2022#include <__utility/pair.h>
lib/libcxx/include/__algorithm/none_of.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _InputIterator, class _Predicate>
22_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
22[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
2323none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
2424 for (; __first != __last; ++__first)
2525 if (__pred(*__first))
lib/libcxx/include/__algorithm/partial_sort_copy.h+3-3
......@@ -18,8 +18,8 @@
1818#include <__algorithm/sort_heap.h>
1919#include <__config>
2020#include <__functional/identity.h>
21#include <__functional/invoke.h>
2221#include <__iterator/iterator_traits.h>
22#include <__type_traits/invoke.h>
2323#include <__type_traits/is_callable.h>
2424#include <__utility/move.h>
2525#include <__utility/pair.h>
......@@ -76,8 +76,8 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
7676 _RandomAccessIterator __result_first,
7777 _RandomAccessIterator __result_last,
7878 _Compare __comp) {
79 static_assert(
80 __is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value, "Comparator has to be callable");
79 static_assert(__is_callable<_Compare&, decltype(*__first), decltype(*__result_first)>::value,
80 "The comparator has to be callable");
8181
8282 auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>(
8383 __first,
lib/libcxx/include/__algorithm/partition.h+2-1
......@@ -12,6 +12,7 @@
1212#include <__algorithm/iterator_operations.h>
1313#include <__config>
1414#include <__iterator/iterator_traits.h>
15#include <__type_traits/remove_cvref.h>
1516#include <__utility/move.h>
1617#include <__utility/pair.h>
1718
......@@ -29,7 +30,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _Forw
2930__partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred, forward_iterator_tag) {
3031 while (true) {
3132 if (__first == __last)
32 return std::make_pair(std::move(__first), std::move(__first));
33 return std::make_pair(__first, __first);
3334 if (!__pred(*__first))
3435 break;
3536 ++__first;
lib/libcxx/include/__algorithm/pstl.h+3-3
......@@ -18,7 +18,7 @@
1818_LIBCPP_PUSH_MACROS
1919#include <__undef_macros>
2020
21#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
21#if _LIBCPP_HAS_EXPERIMENTAL_PSTL && _LIBCPP_STD_VER >= 17
2222
2323# include <__functional/operations.h>
2424# include <__iterator/cpp17_iterator_concepts.h>
......@@ -352,7 +352,7 @@ template <class _ExecutionPolicy,
352352 class _Predicate,
353353 class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
354354 enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
355_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool
355[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool
356356is_partitioned(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
357357 _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "is_partitioned requires ForwardIterators");
358358 using _Implementation = __pstl::__dispatch<__pstl::__is_partitioned, __pstl::__current_configuration, _RawPolicy>;
......@@ -656,7 +656,7 @@ _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator transform(
656656
657657_LIBCPP_END_NAMESPACE_STD
658658
659#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
659#endif // _LIBCPP_HAS_EXPERIMENTAL_PSTL && _LIBCPP_STD_VER >= 17
660660
661661_LIBCPP_POP_MACROS
662662
lib/libcxx/include/__algorithm/radix_sort.h created+332
......@@ -0,0 +1,332 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___ALGORITHM_RADIX_SORT_H
11#define _LIBCPP___ALGORITHM_RADIX_SORT_H
12
13// This is an implementation of classic LSD radix sort algorithm, running in linear time and using `O(max(N, M))`
14// additional memory, where `N` is size of an input range, `M` - maximum value of
15// a radix of the sorted integer type. Type of the radix and its maximum value are determined at compile time
16// based on type returned by function `__radix`. The default radix is uint8.
17
18// The algorithm is equivalent to several consecutive calls of counting sort for each
19// radix of the sorted numbers from low to high byte.
20// The algorithm uses a temporary buffer of size equal to size of the input range. Each `i`-th pass
21// of the algorithm sorts values by `i`-th radix and moves values to the temporary buffer (for each even `i`, counted
22// from zero), or moves them back to the initial range (for each odd `i`). If there is only one radix in sorted integers
23// (e.g. int8), the sorted values are placed to the buffer, and then moved back to the initial range.
24
25// The implementation also has several optimizations:
26// - the counters for the counting sort are calculated in one pass for all radices;
27// - if all values of a radix are the same, we do not sort that radix, and just move items to the buffer;
28// - if two consecutive radices satisfies condition above, we do nothing for these two radices.
29
30#include <__algorithm/for_each.h>
31#include <__algorithm/move.h>
32#include <__bit/bit_log2.h>
33#include <__bit/countl.h>
34#include <__config>
35#include <__functional/identity.h>
36#include <__iterator/distance.h>
37#include <__iterator/iterator_traits.h>
38#include <__iterator/move_iterator.h>
39#include <__iterator/next.h>
40#include <__iterator/reverse_iterator.h>
41#include <__numeric/partial_sum.h>
42#include <__type_traits/decay.h>
43#include <__type_traits/enable_if.h>
44#include <__type_traits/invoke.h>
45#include <__type_traits/is_assignable.h>
46#include <__type_traits/is_integral.h>
47#include <__type_traits/is_unsigned.h>
48#include <__type_traits/make_unsigned.h>
49#include <__utility/forward.h>
50#include <__utility/integer_sequence.h>
51#include <__utility/move.h>
52#include <__utility/pair.h>
53#include <climits>
54#include <cstdint>
55#include <initializer_list>
56#include <limits>
57
58#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
59# pragma GCC system_header
60#endif
61
62_LIBCPP_PUSH_MACROS
63#include <__undef_macros>
64
65_LIBCPP_BEGIN_NAMESPACE_STD
66
67#if _LIBCPP_STD_VER >= 14
68
69template <class _InputIterator, class _OutputIterator>
70_LIBCPP_HIDE_FROM_ABI pair<_OutputIterator, __iter_value_type<_InputIterator>>
71__partial_sum_max(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
72 if (__first == __last)
73 return {__result, 0};
74
75 auto __max = *__first;
76 __iter_value_type<_InputIterator> __sum = *__first;
77 *__result = __sum;
78
79 while (++__first != __last) {
80 if (__max < *__first) {
81 __max = *__first;
82 }
83 __sum = std::move(__sum) + *__first;
84 *++__result = __sum;
85 }
86 return {++__result, __max};
87}
88
89template <class _Value, class _Map, class _Radix>
90struct __radix_sort_traits {
91 using __image_type _LIBCPP_NODEBUG = decay_t<__invoke_result_t<_Map, _Value>>;
92 static_assert(is_unsigned<__image_type>::value);
93
94 using __radix_type _LIBCPP_NODEBUG = decay_t<__invoke_result_t<_Radix, __image_type>>;
95 static_assert(is_integral<__radix_type>::value);
96
97 static constexpr auto __radix_value_range = numeric_limits<__radix_type>::max() + 1;
98 static constexpr auto __radix_size = std::__bit_log2<uint64_t>(__radix_value_range);
99 static constexpr auto __radix_count = sizeof(__image_type) * CHAR_BIT / __radix_size;
100};
101
102template <class _Value, class _Map>
103struct __counting_sort_traits {
104 using __image_type _LIBCPP_NODEBUG = decay_t<__invoke_result_t<_Map, _Value>>;
105 static_assert(is_unsigned<__image_type>::value);
106
107 static constexpr const auto __value_range = numeric_limits<__image_type>::max() + 1;
108 static constexpr auto __radix_size = std::__bit_log2<uint64_t>(__value_range);
109};
110
111template <class _Radix, class _Integer>
112_LIBCPP_HIDE_FROM_ABI auto __nth_radix(size_t __radix_number, _Radix __radix, _Integer __n) {
113 static_assert(is_unsigned<_Integer>::value);
114 using __traits = __counting_sort_traits<_Integer, _Radix>;
115
116 return __radix(static_cast<_Integer>(__n >> __traits::__radix_size * __radix_number));
117}
118
119template <class _ForwardIterator, class _Map, class _RandomAccessIterator>
120_LIBCPP_HIDE_FROM_ABI void
121__collect(_ForwardIterator __first, _ForwardIterator __last, _Map __map, _RandomAccessIterator __counters) {
122 using __value_type = __iter_value_type<_ForwardIterator>;
123 using __traits = __counting_sort_traits<__value_type, _Map>;
124
125 std::for_each(__first, __last, [&__counters, &__map](const auto& __preimage) { ++__counters[__map(__preimage)]; });
126
127 const auto __counters_end = __counters + __traits::__value_range;
128 std::partial_sum(__counters, __counters_end, __counters);
129}
130
131template <class _ForwardIterator, class _RandomAccessIterator1, class _Map, class _RandomAccessIterator2>
132_LIBCPP_HIDE_FROM_ABI void
133__dispose(_ForwardIterator __first,
134 _ForwardIterator __last,
135 _RandomAccessIterator1 __result,
136 _Map __map,
137 _RandomAccessIterator2 __counters) {
138 std::for_each(__first, __last, [&__result, &__counters, &__map](auto&& __preimage) {
139 auto __index = __counters[__map(__preimage)]++;
140 __result[__index] = std::move(__preimage);
141 });
142}
143
144template <class _ForwardIterator,
145 class _Map,
146 class _Radix,
147 class _RandomAccessIterator1,
148 class _RandomAccessIterator2,
149 size_t... _Radices>
150_LIBCPP_HIDE_FROM_ABI bool __collect_impl(
151 _ForwardIterator __first,
152 _ForwardIterator __last,
153 _Map __map,
154 _Radix __radix,
155 _RandomAccessIterator1 __counters,
156 _RandomAccessIterator2 __maximums,
157 index_sequence<_Radices...>) {
158 using __value_type = __iter_value_type<_ForwardIterator>;
159 constexpr auto __radix_value_range = __radix_sort_traits<__value_type, _Map, _Radix>::__radix_value_range;
160
161 auto __previous = numeric_limits<__invoke_result_t<_Map, __value_type>>::min();
162 auto __is_sorted = true;
163 std::for_each(__first, __last, [&__counters, &__map, &__radix, &__previous, &__is_sorted](const auto& __value) {
164 auto __current = __map(__value);
165 __is_sorted &= (__current >= __previous);
166 __previous = __current;
167
168 (++__counters[_Radices][std::__nth_radix(_Radices, __radix, __current)], ...);
169 });
170
171 ((__maximums[_Radices] =
172 std::__partial_sum_max(__counters[_Radices], __counters[_Radices] + __radix_value_range, __counters[_Radices])
173 .second),
174 ...);
175
176 return __is_sorted;
177}
178
179template <class _ForwardIterator, class _Map, class _Radix, class _RandomAccessIterator1, class _RandomAccessIterator2>
180_LIBCPP_HIDE_FROM_ABI bool
181__collect(_ForwardIterator __first,
182 _ForwardIterator __last,
183 _Map __map,
184 _Radix __radix,
185 _RandomAccessIterator1 __counters,
186 _RandomAccessIterator2 __maximums) {
187 using __value_type = __iter_value_type<_ForwardIterator>;
188 constexpr auto __radix_count = __radix_sort_traits<__value_type, _Map, _Radix>::__radix_count;
189 return std::__collect_impl(
190 __first, __last, __map, __radix, __counters, __maximums, make_index_sequence<__radix_count>());
191}
192
193template <class _BidirectionalIterator, class _RandomAccessIterator1, class _Map, class _RandomAccessIterator2>
194_LIBCPP_HIDE_FROM_ABI void __dispose_backward(
195 _BidirectionalIterator __first,
196 _BidirectionalIterator __last,
197 _RandomAccessIterator1 __result,
198 _Map __map,
199 _RandomAccessIterator2 __counters) {
200 std::for_each(std::make_reverse_iterator(__last),
201 std::make_reverse_iterator(__first),
202 [&__result, &__counters, &__map](auto&& __preimage) {
203 auto __index = --__counters[__map(__preimage)];
204 __result[__index] = std::move(__preimage);
205 });
206}
207
208template <class _ForwardIterator, class _RandomAccessIterator, class _Map>
209_LIBCPP_HIDE_FROM_ABI _RandomAccessIterator
210__counting_sort_impl(_ForwardIterator __first, _ForwardIterator __last, _RandomAccessIterator __result, _Map __map) {
211 using __value_type = __iter_value_type<_ForwardIterator>;
212 using __traits = __counting_sort_traits<__value_type, _Map>;
213
214 __iter_diff_t<_RandomAccessIterator> __counters[__traits::__value_range + 1] = {0};
215
216 std::__collect(__first, __last, __map, std::next(std::begin(__counters)));
217 std::__dispose(__first, __last, __result, __map, std::begin(__counters));
218
219 return __result + __counters[__traits::__value_range];
220}
221
222template <class _RandomAccessIterator1,
223 class _RandomAccessIterator2,
224 class _Map,
225 class _Radix,
226 enable_if_t< __radix_sort_traits<__iter_value_type<_RandomAccessIterator1>, _Map, _Radix>::__radix_count == 1,
227 int> = 0>
228_LIBCPP_HIDE_FROM_ABI void __radix_sort_impl(
229 _RandomAccessIterator1 __first,
230 _RandomAccessIterator1 __last,
231 _RandomAccessIterator2 __buffer,
232 _Map __map,
233 _Radix __radix) {
234 auto __buffer_end = std::__counting_sort_impl(__first, __last, __buffer, [&__map, &__radix](const auto& __value) {
235 return __radix(__map(__value));
236 });
237
238 std::move(__buffer, __buffer_end, __first);
239}
240
241template <
242 class _RandomAccessIterator1,
243 class _RandomAccessIterator2,
244 class _Map,
245 class _Radix,
246 enable_if_t< __radix_sort_traits<__iter_value_type<_RandomAccessIterator1>, _Map, _Radix>::__radix_count % 2 == 0,
247 int> = 0 >
248_LIBCPP_HIDE_FROM_ABI void __radix_sort_impl(
249 _RandomAccessIterator1 __first,
250 _RandomAccessIterator1 __last,
251 _RandomAccessIterator2 __buffer_begin,
252 _Map __map,
253 _Radix __radix) {
254 using __value_type = __iter_value_type<_RandomAccessIterator1>;
255 using __traits = __radix_sort_traits<__value_type, _Map, _Radix>;
256
257 __iter_diff_t<_RandomAccessIterator1> __counters[__traits::__radix_count][__traits::__radix_value_range] = {{0}};
258 __iter_diff_t<_RandomAccessIterator1> __maximums[__traits::__radix_count] = {0};
259 const auto __is_sorted = std::__collect(__first, __last, __map, __radix, __counters, __maximums);
260 if (!__is_sorted) {
261 const auto __range_size = std::distance(__first, __last);
262 auto __buffer_end = __buffer_begin + __range_size;
263 for (size_t __radix_number = 0; __radix_number < __traits::__radix_count; __radix_number += 2) {
264 const auto __n0th_is_single = __maximums[__radix_number] == __range_size;
265 const auto __n1th_is_single = __maximums[__radix_number + 1] == __range_size;
266
267 if (__n0th_is_single && __n1th_is_single) {
268 continue;
269 }
270
271 if (__n0th_is_single) {
272 std::move(__first, __last, __buffer_begin);
273 } else {
274 auto __n0th = [__radix_number, &__map, &__radix](const auto& __v) {
275 return std::__nth_radix(__radix_number, __radix, __map(__v));
276 };
277 std::__dispose_backward(__first, __last, __buffer_begin, __n0th, __counters[__radix_number]);
278 }
279
280 if (__n1th_is_single) {
281 std::move(__buffer_begin, __buffer_end, __first);
282 } else {
283 auto __n1th = [__radix_number, &__map, &__radix](const auto& __v) {
284 return std::__nth_radix(__radix_number + 1, __radix, __map(__v));
285 };
286 std::__dispose_backward(__buffer_begin, __buffer_end, __first, __n1th, __counters[__radix_number + 1]);
287 }
288 }
289 }
290}
291
292_LIBCPP_HIDE_FROM_ABI constexpr auto __shift_to_unsigned(bool __b) { return __b; }
293
294template <class _Ip>
295_LIBCPP_HIDE_FROM_ABI constexpr auto __shift_to_unsigned(_Ip __n) {
296 constexpr const auto __min_value = numeric_limits<_Ip>::min();
297 return static_cast<make_unsigned_t<_Ip> >(__n ^ __min_value);
298}
299
300struct __low_byte_fn {
301 template <class _Ip>
302 _LIBCPP_HIDE_FROM_ABI constexpr uint8_t operator()(_Ip __integer) const {
303 static_assert(is_unsigned<_Ip>::value);
304
305 return static_cast<uint8_t>(__integer & 0xff);
306 }
307};
308
309template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _Map, class _Radix>
310_LIBCPP_HIDE_FROM_ABI void
311__radix_sort(_RandomAccessIterator1 __first,
312 _RandomAccessIterator1 __last,
313 _RandomAccessIterator2 __buffer,
314 _Map __map,
315 _Radix __radix) {
316 auto __map_to_unsigned = [__map = std::move(__map)](const auto& __x) { return std::__shift_to_unsigned(__map(__x)); };
317 std::__radix_sort_impl(__first, __last, __buffer, __map_to_unsigned, __radix);
318}
319
320template <class _RandomAccessIterator1, class _RandomAccessIterator2>
321_LIBCPP_HIDE_FROM_ABI void
322__radix_sort(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __buffer) {
323 std::__radix_sort(__first, __last, __buffer, __identity{}, __low_byte_fn{});
324}
325
326#endif // _LIBCPP_STD_VER >= 14
327
328_LIBCPP_END_NAMESPACE_STD
329
330_LIBCPP_POP_MACROS
331
332#endif // _LIBCPP___ALGORITHM_RADIX_SORT_H
lib/libcxx/include/__algorithm/ranges_adjacent_find.h+5-22
......@@ -9,9 +9,9 @@
99#ifndef _LIBCPP___ALGORITHM_RANGES_ADJACENT_FIND_H
1010#define _LIBCPP___ALGORITHM_RANGES_ADJACENT_FIND_H
1111
12#include <__algorithm/adjacent_find.h>
1213#include <__config>
1314#include <__functional/identity.h>
14#include <__functional/invoke.h>
1515#include <__functional/ranges_operations.h>
1616#include <__iterator/concepts.h>
1717#include <__iterator/projected.h>
......@@ -32,30 +32,14 @@ _LIBCPP_PUSH_MACROS
3232_LIBCPP_BEGIN_NAMESPACE_STD
3333
3434namespace ranges {
35namespace __adjacent_find {
36struct __fn {
37 template <class _Iter, class _Sent, class _Proj, class _Pred>
38 _LIBCPP_HIDE_FROM_ABI constexpr static _Iter
39 __adjacent_find_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
40 if (__first == __last)
41 return __first;
42
43 auto __i = __first;
44 while (++__i != __last) {
45 if (std::invoke(__pred, std::invoke(__proj, *__first), std::invoke(__proj, *__i)))
46 return __first;
47 __first = __i;
48 }
49 return __i;
50 }
51
35struct __adjacent_find {
5236 template <forward_iterator _Iter,
5337 sentinel_for<_Iter> _Sent,
5438 class _Proj = identity,
5539 indirect_binary_predicate<projected<_Iter, _Proj>, projected<_Iter, _Proj>> _Pred = ranges::equal_to>
5640 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Iter
5741 operator()(_Iter __first, _Sent __last, _Pred __pred = {}, _Proj __proj = {}) const {
58 return __adjacent_find_impl(std::move(__first), std::move(__last), __pred, __proj);
42 return std::__adjacent_find(std::move(__first), std::move(__last), __pred, __proj);
5943 }
6044
6145 template <forward_range _Range,
......@@ -64,13 +48,12 @@ struct __fn {
6448 _Pred = ranges::equal_to>
6549 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range>
6650 operator()(_Range&& __range, _Pred __pred = {}, _Proj __proj = {}) const {
67 return __adjacent_find_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
51 return std::__adjacent_find(ranges::begin(__range), ranges::end(__range), __pred, __proj);
6852 }
6953};
70} // namespace __adjacent_find
7154
7255inline namespace __cpo {
73inline constexpr auto adjacent_find = __adjacent_find::__fn{};
56inline constexpr auto adjacent_find = __adjacent_find{};
7457} // namespace __cpo
7558} // namespace ranges
7659
lib/libcxx/include/__algorithm/ranges_all_of.h+5-15
......@@ -9,6 +9,7 @@
99#ifndef _LIBCPP___ALGORITHM_RANGES_ALL_OF_H
1010#define _LIBCPP___ALGORITHM_RANGES_ALL_OF_H
1111
12#include <__algorithm/all_of.h>
1213#include <__config>
1314#include <__functional/identity.h>
1415#include <__functional/invoke.h>
......@@ -30,24 +31,14 @@ _LIBCPP_PUSH_MACROS
3031_LIBCPP_BEGIN_NAMESPACE_STD
3132
3233namespace ranges {
33namespace __all_of {
34struct __fn {
35 template <class _Iter, class _Sent, class _Proj, class _Pred>
36 _LIBCPP_HIDE_FROM_ABI constexpr static bool __all_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
37 for (; __first != __last; ++__first) {
38 if (!std::invoke(__pred, std::invoke(__proj, *__first)))
39 return false;
40 }
41 return true;
42 }
43
34struct __all_of {
4435 template <input_iterator _Iter,
4536 sentinel_for<_Iter> _Sent,
4637 class _Proj = identity,
4738 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
4839 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool
4940 operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const {
50 return __all_of_impl(std::move(__first), std::move(__last), __pred, __proj);
41 return std::__all_of(std::move(__first), std::move(__last), __pred, __proj);
5142 }
5243
5344 template <input_range _Range,
......@@ -55,13 +46,12 @@ struct __fn {
5546 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
5647 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool
5748 operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
58 return __all_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
49 return std::__all_of(ranges::begin(__range), ranges::end(__range), __pred, __proj);
5950 }
6051};
61} // namespace __all_of
6252
6353inline namespace __cpo {
64inline constexpr auto all_of = __all_of::__fn{};
54inline constexpr auto all_of = __all_of{};
6555} // namespace __cpo
6656} // namespace ranges
6757
lib/libcxx/include/__algorithm/ranges_any_of.h+5-16
......@@ -9,9 +9,9 @@
99#ifndef _LIBCPP___ALGORITHM_RANGES_ANY_OF_H
1010#define _LIBCPP___ALGORITHM_RANGES_ANY_OF_H
1111
12#include <__algorithm/any_of.h>
1213#include <__config>
1314#include <__functional/identity.h>
14#include <__functional/invoke.h>
1515#include <__iterator/concepts.h>
1616#include <__iterator/projected.h>
1717#include <__ranges/access.h>
......@@ -30,24 +30,14 @@ _LIBCPP_PUSH_MACROS
3030_LIBCPP_BEGIN_NAMESPACE_STD
3131
3232namespace ranges {
33namespace __any_of {
34struct __fn {
35 template <class _Iter, class _Sent, class _Proj, class _Pred>
36 _LIBCPP_HIDE_FROM_ABI constexpr static bool __any_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
37 for (; __first != __last; ++__first) {
38 if (std::invoke(__pred, std::invoke(__proj, *__first)))
39 return true;
40 }
41 return false;
42 }
43
33struct __any_of {
4434 template <input_iterator _Iter,
4535 sentinel_for<_Iter> _Sent,
4636 class _Proj = identity,
4737 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
4838 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool
4939 operator()(_Iter __first, _Sent __last, _Pred __pred = {}, _Proj __proj = {}) const {
50 return __any_of_impl(std::move(__first), std::move(__last), __pred, __proj);
40 return std::__any_of(std::move(__first), std::move(__last), __pred, __proj);
5141 }
5242
5343 template <input_range _Range,
......@@ -55,13 +45,12 @@ struct __fn {
5545 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
5646 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool
5747 operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
58 return __any_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
48 return std::__any_of(ranges::begin(__range), ranges::end(__range), __pred, __proj);
5949 }
6050};
61} // namespace __any_of
6251
6352inline namespace __cpo {
64inline constexpr auto any_of = __any_of::__fn{};
53inline constexpr auto any_of = __any_of{};
6554} // namespace __cpo
6655} // namespace ranges
6756
lib/libcxx/include/__algorithm/ranges_binary_search.h+2-4
......@@ -32,8 +32,7 @@ _LIBCPP_PUSH_MACROS
3232_LIBCPP_BEGIN_NAMESPACE_STD
3333
3434namespace ranges {
35namespace __binary_search {
36struct __fn {
35struct __binary_search {
3736 template <forward_iterator _Iter,
3837 sentinel_for<_Iter> _Sent,
3938 class _Type,
......@@ -57,10 +56,9 @@ struct __fn {
5756 return __ret != __last && !std::invoke(__comp, __value, std::invoke(__proj, *__ret));
5857 }
5958};
60} // namespace __binary_search
6159
6260inline namespace __cpo {
63inline constexpr auto binary_search = __binary_search::__fn{};
61inline constexpr auto binary_search = __binary_search{};
6462} // namespace __cpo
6563} // namespace ranges
6664
lib/libcxx/include/__algorithm/ranges_clamp.h+2-4
......@@ -30,8 +30,7 @@ _LIBCPP_PUSH_MACROS
3030_LIBCPP_BEGIN_NAMESPACE_STD
3131
3232namespace ranges {
33namespace __clamp {
34struct __fn {
33struct __clamp {
3534 template <class _Type,
3635 class _Proj = identity,
3736 indirect_strict_weak_order<projected<const _Type*, _Proj>> _Comp = ranges::less>
......@@ -50,10 +49,9 @@ struct __fn {
5049 return __value;
5150 }
5251};
53} // namespace __clamp
5452
5553inline namespace __cpo {
56inline constexpr auto clamp = __clamp::__fn{};
54inline constexpr auto clamp = __clamp{};
5755} // namespace __cpo
5856} // namespace ranges
5957
lib/libcxx/include/__algorithm/ranges_contains.h+2-4
......@@ -33,8 +33,7 @@ _LIBCPP_PUSH_MACROS
3333_LIBCPP_BEGIN_NAMESPACE_STD
3434
3535namespace ranges {
36namespace __contains {
37struct __fn {
36struct __contains {
3837 template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity>
3938 requires indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type*>
4039 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool static
......@@ -50,10 +49,9 @@ struct __fn {
5049 ranges::end(__range);
5150 }
5251};
53} // namespace __contains
5452
5553inline namespace __cpo {
56inline constexpr auto contains = __contains::__fn{};
54inline constexpr auto contains = __contains{};
5755} // namespace __cpo
5856} // namespace ranges
5957
lib/libcxx/include/__algorithm/ranges_contains_subrange.h+2-4
......@@ -35,8 +35,7 @@ _LIBCPP_PUSH_MACROS
3535_LIBCPP_BEGIN_NAMESPACE_STD
3636
3737namespace ranges {
38namespace __contains_subrange {
39struct __fn {
38struct __contains_subrange {
4039 template <forward_iterator _Iter1,
4140 sentinel_for<_Iter1> _Sent1,
4241 forward_iterator _Iter2,
......@@ -81,10 +80,9 @@ struct __fn {
8180 return __ret.empty() == false;
8281 }
8382};
84} // namespace __contains_subrange
8583
8684inline namespace __cpo {
87inline constexpr auto contains_subrange = __contains_subrange::__fn{};
85inline constexpr auto contains_subrange = __contains_subrange{};
8886} // namespace __cpo
8987} // namespace ranges
9088
lib/libcxx/include/__algorithm/ranges_copy.h+4-7
......@@ -11,7 +11,6 @@
1111
1212#include <__algorithm/copy.h>
1313#include <__algorithm/in_out_result.h>
14#include <__algorithm/iterator_operations.h>
1514#include <__config>
1615#include <__functional/identity.h>
1716#include <__iterator/concepts.h>
......@@ -37,13 +36,12 @@ namespace ranges {
3736template <class _InIter, class _OutIter>
3837using copy_result = in_out_result<_InIter, _OutIter>;
3938
40namespace __copy {
41struct __fn {
39struct __copy {
4240 template <input_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter>
4341 requires indirectly_copyable<_InIter, _OutIter>
4442 _LIBCPP_HIDE_FROM_ABI constexpr copy_result<_InIter, _OutIter>
4543 operator()(_InIter __first, _Sent __last, _OutIter __result) const {
46 auto __ret = std::__copy<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__result));
44 auto __ret = std::__copy(std::move(__first), std::move(__last), std::move(__result));
4745 return {std::move(__ret.first), std::move(__ret.second)};
4846 }
4947
......@@ -51,14 +49,13 @@ struct __fn {
5149 requires indirectly_copyable<iterator_t<_Range>, _OutIter>
5250 _LIBCPP_HIDE_FROM_ABI constexpr copy_result<borrowed_iterator_t<_Range>, _OutIter>
5351 operator()(_Range&& __r, _OutIter __result) const {
54 auto __ret = std::__copy<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), std::move(__result));
52 auto __ret = std::__copy(ranges::begin(__r), ranges::end(__r), std::move(__result));
5553 return {std::move(__ret.first), std::move(__ret.second)};
5654 }
5755};
58} // namespace __copy
5956
6057inline namespace __cpo {
61inline constexpr auto copy = __copy::__fn{};
58inline constexpr auto copy = __copy{};
6259} // namespace __cpo
6360} // namespace ranges
6461
lib/libcxx/include/__algorithm/ranges_copy_backward.h+2-4
......@@ -35,8 +35,7 @@ namespace ranges {
3535template <class _Ip, class _Op>
3636using copy_backward_result = in_out_result<_Ip, _Op>;
3737
38namespace __copy_backward {
39struct __fn {
38struct __copy_backward {
4039 template <bidirectional_iterator _InIter1, sentinel_for<_InIter1> _Sent1, bidirectional_iterator _InIter2>
4140 requires indirectly_copyable<_InIter1, _InIter2>
4241 _LIBCPP_HIDE_FROM_ABI constexpr copy_backward_result<_InIter1, _InIter2>
......@@ -53,10 +52,9 @@ struct __fn {
5352 return {std::move(__ret.first), std::move(__ret.second)};
5453 }
5554};
56} // namespace __copy_backward
5755
5856inline namespace __cpo {
59inline constexpr auto copy_backward = __copy_backward::__fn{};
57inline constexpr auto copy_backward = __copy_backward{};
6058} // namespace __cpo
6159} // namespace ranges
6260
lib/libcxx/include/__algorithm/ranges_copy_if.h+7-18
......@@ -9,6 +9,7 @@
99#ifndef _LIBCPP___ALGORITHM_RANGES_COPY_IF_H
1010#define _LIBCPP___ALGORITHM_RANGES_COPY_IF_H
1111
12#include <__algorithm/copy_if.h>
1213#include <__algorithm/in_out_result.h>
1314#include <__config>
1415#include <__functional/identity.h>
......@@ -36,20 +37,7 @@ namespace ranges {
3637template <class _Ip, class _Op>
3738using copy_if_result = in_out_result<_Ip, _Op>;
3839
39namespace __copy_if {
40struct __fn {
41 template <class _InIter, class _Sent, class _OutIter, class _Proj, class _Pred>
42 _LIBCPP_HIDE_FROM_ABI static constexpr copy_if_result<_InIter, _OutIter>
43 __copy_if_impl(_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj& __proj) {
44 for (; __first != __last; ++__first) {
45 if (std::invoke(__pred, std::invoke(__proj, *__first))) {
46 *__result = *__first;
47 ++__result;
48 }
49 }
50 return {std::move(__first), std::move(__result)};
51 }
52
40struct __copy_if {
5341 template <input_iterator _Iter,
5442 sentinel_for<_Iter> _Sent,
5543 weakly_incrementable _OutIter,
......@@ -58,7 +46,8 @@ struct __fn {
5846 requires indirectly_copyable<_Iter, _OutIter>
5947 _LIBCPP_HIDE_FROM_ABI constexpr copy_if_result<_Iter, _OutIter>
6048 operator()(_Iter __first, _Sent __last, _OutIter __result, _Pred __pred, _Proj __proj = {}) const {
61 return __copy_if_impl(std::move(__first), std::move(__last), std::move(__result), __pred, __proj);
49 auto __res = std::__copy_if(std::move(__first), std::move(__last), std::move(__result), __pred, __proj);
50 return {std::move(__res.first), std::move(__res.second)};
6251 }
6352
6453 template <input_range _Range,
......@@ -68,13 +57,13 @@ struct __fn {
6857 requires indirectly_copyable<iterator_t<_Range>, _OutIter>
6958 _LIBCPP_HIDE_FROM_ABI constexpr copy_if_result<borrowed_iterator_t<_Range>, _OutIter>
7059 operator()(_Range&& __r, _OutIter __result, _Pred __pred, _Proj __proj = {}) const {
71 return __copy_if_impl(ranges::begin(__r), ranges::end(__r), std::move(__result), __pred, __proj);
60 auto __res = std::__copy_if(ranges::begin(__r), ranges::end(__r), std::move(__result), __pred, __proj);
61 return {std::move(__res.first), std::move(__res.second)};
7262 }
7363};
74} // namespace __copy_if
7564
7665inline namespace __cpo {
77inline constexpr auto copy_if = __copy_if::__fn{};
66inline constexpr auto copy_if = __copy_if{};
7867} // namespace __cpo
7968} // namespace ranges
8069
lib/libcxx/include/__algorithm/ranges_copy_n.h+4-5
......@@ -37,8 +37,8 @@ namespace ranges {
3737template <class _Ip, class _Op>
3838using copy_n_result = in_out_result<_Ip, _Op>;
3939
40namespace __copy_n {
41struct __fn {
40// TODO: Merge this with copy_n
41struct __copy_n {
4242 template <class _InIter, class _DiffType, class _OutIter>
4343 _LIBCPP_HIDE_FROM_ABI constexpr static copy_n_result<_InIter, _OutIter>
4444 __go(_InIter __first, _DiffType __n, _OutIter __result) {
......@@ -54,7 +54,7 @@ struct __fn {
5454 template <random_access_iterator _InIter, class _DiffType, random_access_iterator _OutIter>
5555 _LIBCPP_HIDE_FROM_ABI constexpr static copy_n_result<_InIter, _OutIter>
5656 __go(_InIter __first, _DiffType __n, _OutIter __result) {
57 auto __ret = std::__copy<_RangeAlgPolicy>(__first, __first + __n, __result);
57 auto __ret = std::__copy(__first, __first + __n, __result);
5858 return {__ret.first, __ret.second};
5959 }
6060
......@@ -65,10 +65,9 @@ struct __fn {
6565 return __go(std::move(__first), __n, std::move(__result));
6666 }
6767};
68} // namespace __copy_n
6968
7069inline namespace __cpo {
71inline constexpr auto copy_n = __copy_n::__fn{};
70inline constexpr auto copy_n = __copy_n{};
7271} // namespace __cpo
7372} // namespace ranges
7473
lib/libcxx/include/__algorithm/ranges_count.h+2-4
......@@ -34,8 +34,7 @@ _LIBCPP_PUSH_MACROS
3434_LIBCPP_BEGIN_NAMESPACE_STD
3535
3636namespace ranges {
37namespace __count {
38struct __fn {
37struct __count {
3938 template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity>
4039 requires indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type*>
4140 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter>
......@@ -50,10 +49,9 @@ struct __fn {
5049 return std::__count<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), __value, __proj);
5150 }
5251};
53} // namespace __count
5452
5553inline namespace __cpo {
56inline constexpr auto count = __count::__fn{};
54inline constexpr auto count = __count{};
5755} // namespace __cpo
5856} // namespace ranges
5957
lib/libcxx/include/__algorithm/ranges_count_if.h+6-18
......@@ -9,9 +9,10 @@
99#ifndef _LIBCPP___ALGORITHM_RANGES_COUNT_IF_H
1010#define _LIBCPP___ALGORITHM_RANGES_COUNT_IF_H
1111
12#include <__algorithm/count_if.h>
13#include <__algorithm/iterator_operations.h>
1214#include <__config>
1315#include <__functional/identity.h>
14#include <__functional/invoke.h>
1516#include <__functional/ranges_operations.h>
1617#include <__iterator/concepts.h>
1718#include <__iterator/incrementable_traits.h>
......@@ -33,26 +34,14 @@ _LIBCPP_PUSH_MACROS
3334_LIBCPP_BEGIN_NAMESPACE_STD
3435
3536namespace ranges {
36template <class _Iter, class _Sent, class _Proj, class _Pred>
37_LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter>
38__count_if_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
39 iter_difference_t<_Iter> __counter(0);
40 for (; __first != __last; ++__first) {
41 if (std::invoke(__pred, std::invoke(__proj, *__first)))
42 ++__counter;
43 }
44 return __counter;
45}
46
47namespace __count_if {
48struct __fn {
37struct __count_if {
4938 template <input_iterator _Iter,
5039 sentinel_for<_Iter> _Sent,
5140 class _Proj = identity,
5241 indirect_unary_predicate<projected<_Iter, _Proj>> _Predicate>
5342 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter>
5443 operator()(_Iter __first, _Sent __last, _Predicate __pred, _Proj __proj = {}) const {
55 return ranges::__count_if_impl(std::move(__first), std::move(__last), __pred, __proj);
44 return std::__count_if<_RangeAlgPolicy>(std::move(__first), std::move(__last), __pred, __proj);
5645 }
5746
5847 template <input_range _Range,
......@@ -60,13 +49,12 @@ struct __fn {
6049 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Predicate>
6150 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr range_difference_t<_Range>
6251 operator()(_Range&& __r, _Predicate __pred, _Proj __proj = {}) const {
63 return ranges::__count_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj);
52 return std::__count_if<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), __pred, __proj);
6453 }
6554};
66} // namespace __count_if
6755
6856inline namespace __cpo {
69inline constexpr auto count_if = __count_if::__fn{};
57inline constexpr auto count_if = __count_if{};
7058} // namespace __cpo
7159} // namespace ranges
7260
lib/libcxx/include/__algorithm/ranges_ends_with.h+3-4
......@@ -22,6 +22,7 @@
2222#include <__iterator/reverse_iterator.h>
2323#include <__ranges/access.h>
2424#include <__ranges/concepts.h>
25#include <__ranges/size.h>
2526#include <__utility/move.h>
2627
2728#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -36,8 +37,7 @@ _LIBCPP_PUSH_MACROS
3637_LIBCPP_BEGIN_NAMESPACE_STD
3738
3839namespace ranges {
39namespace __ends_with {
40struct __fn {
40struct __ends_with {
4141 template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
4242 _LIBCPP_HIDE_FROM_ABI static constexpr bool __ends_with_fn_impl_bidirectional(
4343 _Iter1 __first1,
......@@ -185,10 +185,9 @@ struct __fn {
185185 }
186186 }
187187};
188} // namespace __ends_with
189188
190189inline namespace __cpo {
191inline constexpr auto ends_with = __ends_with::__fn{};
190inline constexpr auto ends_with = __ends_with{};
192191} // namespace __cpo
193192} // namespace ranges
194193
lib/libcxx/include/__algorithm/ranges_equal.h+2-4
......@@ -34,8 +34,7 @@ _LIBCPP_PUSH_MACROS
3434_LIBCPP_BEGIN_NAMESPACE_STD
3535
3636namespace ranges {
37namespace __equal {
38struct __fn {
37struct __equal {
3938 template <input_iterator _Iter1,
4039 sentinel_for<_Iter1> _Sent1,
4140 input_iterator _Iter2,
......@@ -93,10 +92,9 @@ struct __fn {
9392 return false;
9493 }
9594};
96} // namespace __equal
9795
9896inline namespace __cpo {
99inline constexpr auto equal = __equal::__fn{};
97inline constexpr auto equal = __equal{};
10098} // namespace __cpo
10199} // namespace ranges
102100
lib/libcxx/include/__algorithm/ranges_equal_range.h+2-6
......@@ -38,9 +38,7 @@ _LIBCPP_PUSH_MACROS
3838_LIBCPP_BEGIN_NAMESPACE_STD
3939
4040namespace ranges {
41namespace __equal_range {
42
43struct __fn {
41struct __equal_range {
4442 template <forward_iterator _Iter,
4543 sentinel_for<_Iter> _Sent,
4644 class _Tp,
......@@ -64,10 +62,8 @@ struct __fn {
6462 }
6563};
6664
67} // namespace __equal_range
68
6965inline namespace __cpo {
70inline constexpr auto equal_range = __equal_range::__fn{};
66inline constexpr auto equal_range = __equal_range{};
7167} // namespace __cpo
7268} // namespace ranges
7369
lib/libcxx/include/__algorithm/ranges_fill.h+2-4
......@@ -28,8 +28,7 @@ _LIBCPP_PUSH_MACROS
2828_LIBCPP_BEGIN_NAMESPACE_STD
2929
3030namespace ranges {
31namespace __fill {
32struct __fn {
31struct __fill {
3332 template <class _Type, output_iterator<const _Type&> _Iter, sentinel_for<_Iter> _Sent>
3433 _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last, const _Type& __value) const {
3534 if constexpr (random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>) {
......@@ -46,10 +45,9 @@ struct __fn {
4645 return (*this)(ranges::begin(__range), ranges::end(__range), __value);
4746 }
4847};
49} // namespace __fill
5048
5149inline namespace __cpo {
52inline constexpr auto fill = __fill::__fn{};
50inline constexpr auto fill = __fill{};
5351} // namespace __cpo
5452} // namespace ranges
5553
lib/libcxx/include/__algorithm/ranges_fill_n.h+5-9
......@@ -9,9 +9,11 @@
99#ifndef _LIBCPP___ALGORITHM_RANGES_FILL_N_H
1010#define _LIBCPP___ALGORITHM_RANGES_FILL_N_H
1111
12#include <__algorithm/fill_n.h>
1213#include <__config>
1314#include <__iterator/concepts.h>
1415#include <__iterator/incrementable_traits.h>
16#include <__utility/move.h>
1517
1618#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1719# pragma GCC system_header
......@@ -25,22 +27,16 @@ _LIBCPP_PUSH_MACROS
2527_LIBCPP_BEGIN_NAMESPACE_STD
2628
2729namespace ranges {
28namespace __fill_n {
29struct __fn {
30struct __fill_n {
3031 template <class _Type, output_iterator<const _Type&> _Iter>
3132 _LIBCPP_HIDE_FROM_ABI constexpr _Iter
3233 operator()(_Iter __first, iter_difference_t<_Iter> __n, const _Type& __value) const {
33 for (; __n != 0; --__n) {
34 *__first = __value;
35 ++__first;
36 }
37 return __first;
34 return std::__fill_n(std::move(__first), __n, __value);
3835 }
3936};
40} // namespace __fill_n
4137
4238inline namespace __cpo {
43inline constexpr auto fill_n = __fill_n::__fn{};
39inline constexpr auto fill_n = __fill_n{};
4440} // namespace __cpo
4541} // namespace ranges
4642
lib/libcxx/include/__algorithm/ranges_find.h+2-4
......@@ -36,8 +36,7 @@ _LIBCPP_PUSH_MACROS
3636_LIBCPP_BEGIN_NAMESPACE_STD
3737
3838namespace ranges {
39namespace __find {
40struct __fn {
39struct __find {
4140 template <class _Iter, class _Sent, class _Tp, class _Proj>
4241 _LIBCPP_HIDE_FROM_ABI static constexpr _Iter
4342 __find_unwrap(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) {
......@@ -64,10 +63,9 @@ struct __fn {
6463 return __find_unwrap(ranges::begin(__r), ranges::end(__r), __value, __proj);
6564 }
6665};
67} // namespace __find
6866
6967inline namespace __cpo {
70inline constexpr auto find = __find::__fn{};
68inline constexpr auto find = __find{};
7169} // namespace __cpo
7270} // namespace ranges
7371
lib/libcxx/include/__algorithm/ranges_find_end.h+2-4
......@@ -35,8 +35,7 @@ _LIBCPP_PUSH_MACROS
3535_LIBCPP_BEGIN_NAMESPACE_STD
3636
3737namespace ranges {
38namespace __find_end {
39struct __fn {
38struct __find_end {
4039 template <forward_iterator _Iter1,
4140 sentinel_for<_Iter1> _Sent1,
4241 forward_iterator _Iter2,
......@@ -87,10 +86,9 @@ struct __fn {
8786 return {__ret.first, __ret.second};
8887 }
8988};
90} // namespace __find_end
9189
9290inline namespace __cpo {
93inline constexpr auto find_end = __find_end::__fn{};
91inline constexpr auto find_end = __find_end{};
9492} // namespace __cpo
9593} // namespace ranges
9694
lib/libcxx/include/__algorithm/ranges_find_first_of.h+2-4
......@@ -32,8 +32,7 @@ _LIBCPP_PUSH_MACROS
3232_LIBCPP_BEGIN_NAMESPACE_STD
3333
3434namespace ranges {
35namespace __find_first_of {
36struct __fn {
35struct __find_first_of {
3736 template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
3837 _LIBCPP_HIDE_FROM_ABI constexpr static _Iter1 __find_first_of_impl(
3938 _Iter1 __first1,
......@@ -90,10 +89,9 @@ struct __fn {
9089 __proj2);
9190 }
9291};
93} // namespace __find_first_of
9492
9593inline namespace __cpo {
96inline constexpr auto find_first_of = __find_first_of::__fn{};
94inline constexpr auto find_first_of = __find_first_of{};
9795} // namespace __cpo
9896} // namespace ranges
9997
lib/libcxx/include/__algorithm/ranges_find_if.h+2-4
......@@ -42,8 +42,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Ip __find_if_impl(_Ip __first, _Sp __last, _Pre
4242 return __first;
4343}
4444
45namespace __find_if {
46struct __fn {
45struct __find_if {
4746 template <input_iterator _Ip,
4847 sentinel_for<_Ip> _Sp,
4948 class _Proj = identity,
......@@ -59,10 +58,9 @@ struct __fn {
5958 return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj);
6059 }
6160};
62} // namespace __find_if
6361
6462inline namespace __cpo {
65inline constexpr auto find_if = __find_if::__fn{};
63inline constexpr auto find_if = __find_if{};
6664} // namespace __cpo
6765} // namespace ranges
6866
lib/libcxx/include/__algorithm/ranges_find_if_not.h+2-4
......@@ -34,8 +34,7 @@ _LIBCPP_PUSH_MACROS
3434_LIBCPP_BEGIN_NAMESPACE_STD
3535
3636namespace ranges {
37namespace __find_if_not {
38struct __fn {
37struct __find_if_not {
3938 template <input_iterator _Ip,
4039 sentinel_for<_Ip> _Sp,
4140 class _Proj = identity,
......@@ -53,10 +52,9 @@ struct __fn {
5352 return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred2, __proj);
5453 }
5554};
56} // namespace __find_if_not
5755
5856inline namespace __cpo {
59inline constexpr auto find_if_not = __find_if_not::__fn{};
57inline constexpr auto find_if_not = __find_if_not{};
6058} // namespace __cpo
6159} // namespace ranges
6260
lib/libcxx/include/__algorithm/ranges_find_last.h+7-12
......@@ -21,6 +21,7 @@
2121#include <__ranges/access.h>
2222#include <__ranges/concepts.h>
2323#include <__ranges/subrange.h>
24#include <__utility/forward.h>
2425#include <__utility/move.h>
2526
2627#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -72,8 +73,7 @@ __find_last_impl(_Iter __first, _Sent __last, _Pred __pred, _Proj& __proj) {
7273 }
7374}
7475
75namespace __find_last {
76struct __fn {
76struct __find_last {
7777 template <class _Type>
7878 struct __op {
7979 const _Type& __value;
......@@ -97,10 +97,8 @@ struct __fn {
9797 return ranges::__find_last_impl(ranges::begin(__range), ranges::end(__range), __op<_Type>{__value}, __proj);
9898 }
9999};
100} // namespace __find_last
101100
102namespace __find_last_if {
103struct __fn {
101struct __find_last_if {
104102 template <class _Pred>
105103 struct __op {
106104 _Pred& __pred;
......@@ -127,10 +125,8 @@ struct __fn {
127125 return ranges::__find_last_impl(ranges::begin(__range), ranges::end(__range), __op<_Pred>{__pred}, __proj);
128126 }
129127};
130} // namespace __find_last_if
131128
132namespace __find_last_if_not {
133struct __fn {
129struct __find_last_if_not {
134130 template <class _Pred>
135131 struct __op {
136132 _Pred& __pred;
......@@ -157,12 +153,11 @@ struct __fn {
157153 return ranges::__find_last_impl(ranges::begin(__range), ranges::end(__range), __op<_Pred>{__pred}, __proj);
158154 }
159155};
160} // namespace __find_last_if_not
161156
162157inline namespace __cpo {
163inline constexpr auto find_last = __find_last::__fn{};
164inline constexpr auto find_last_if = __find_last_if::__fn{};
165inline constexpr auto find_last_if_not = __find_last_if_not::__fn{};
158inline constexpr auto find_last = __find_last{};
159inline constexpr auto find_last_if = __find_last_if{};
160inline constexpr auto find_last_if_not = __find_last_if_not{};
166161} // namespace __cpo
167162} // namespace ranges
168163
lib/libcxx/include/__algorithm/ranges_fold.h created+129
......@@ -0,0 +1,129 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___ALGORITHM_RANGES_FOLD_H
11#define _LIBCPP___ALGORITHM_RANGES_FOLD_H
12
13#include <__concepts/assignable.h>
14#include <__concepts/constructible.h>
15#include <__concepts/convertible_to.h>
16#include <__concepts/invocable.h>
17#include <__concepts/movable.h>
18#include <__config>
19#include <__functional/invoke.h>
20#include <__functional/reference_wrapper.h>
21#include <__iterator/concepts.h>
22#include <__iterator/iterator_traits.h>
23#include <__iterator/next.h>
24#include <__ranges/access.h>
25#include <__ranges/concepts.h>
26#include <__ranges/dangling.h>
27#include <__type_traits/decay.h>
28#include <__type_traits/invoke.h>
29#include <__utility/forward.h>
30#include <__utility/move.h>
31
32#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
33# pragma GCC system_header
34#endif
35
36_LIBCPP_PUSH_MACROS
37#include <__undef_macros>
38
39_LIBCPP_BEGIN_NAMESPACE_STD
40
41#if _LIBCPP_STD_VER >= 23
42
43namespace ranges {
44template <class _Ip, class _Tp>
45struct in_value_result {
46 _LIBCPP_NO_UNIQUE_ADDRESS _Ip in;
47 _LIBCPP_NO_UNIQUE_ADDRESS _Tp value;
48
49 template <class _I2, class _T2>
50 requires convertible_to<const _Ip&, _I2> && convertible_to<const _Tp&, _T2>
51 _LIBCPP_HIDE_FROM_ABI constexpr operator in_value_result<_I2, _T2>() const& {
52 return {in, value};
53 }
54
55 template <class _I2, class _T2>
56 requires convertible_to<_Ip, _I2> && convertible_to<_Tp, _T2>
57 _LIBCPP_HIDE_FROM_ABI constexpr operator in_value_result<_I2, _T2>() && {
58 return {std::move(in), std::move(value)};
59 }
60};
61
62template <class _Ip, class _Tp>
63using fold_left_with_iter_result = in_value_result<_Ip, _Tp>;
64
65template <class _Fp, class _Tp, class _Ip, class _Rp, class _Up = decay_t<_Rp>>
66concept __indirectly_binary_left_foldable_impl =
67 convertible_to<_Rp, _Up> && //
68 movable<_Tp> && //
69 movable<_Up> && //
70 convertible_to<_Tp, _Up> && //
71 invocable<_Fp&, _Up, iter_reference_t<_Ip>> && //
72 assignable_from<_Up&, invoke_result_t<_Fp&, _Up, iter_reference_t<_Ip>>>;
73
74template <class _Fp, class _Tp, class _Ip>
75concept __indirectly_binary_left_foldable =
76 copy_constructible<_Fp> && //
77 invocable<_Fp&, _Tp, iter_reference_t<_Ip>> && //
78 __indirectly_binary_left_foldable_impl<_Fp, _Tp, _Ip, invoke_result_t<_Fp&, _Tp, iter_reference_t<_Ip>>>;
79
80struct __fold_left_with_iter {
81 template <input_iterator _Ip, sentinel_for<_Ip> _Sp, class _Tp, __indirectly_binary_left_foldable<_Tp, _Ip> _Fp>
82 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Ip __first, _Sp __last, _Tp __init, _Fp __f) {
83 using _Up = decay_t<invoke_result_t<_Fp&, _Tp, iter_reference_t<_Ip>>>;
84
85 if (__first == __last) {
86 return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), _Up(std::move(__init))};
87 }
88
89 _Up __result = std::invoke(__f, std::move(__init), *__first);
90 for (++__first; __first != __last; ++__first) {
91 __result = std::invoke(__f, std::move(__result), *__first);
92 }
93
94 return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), std::move(__result)};
95 }
96
97 template <input_range _Rp, class _Tp, __indirectly_binary_left_foldable<_Tp, iterator_t<_Rp>> _Fp>
98 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Rp&& __r, _Tp __init, _Fp __f) {
99 auto __result = operator()(ranges::begin(__r), ranges::end(__r), std::move(__init), std::ref(__f));
100
101 using _Up = decay_t<invoke_result_t<_Fp&, _Tp, range_reference_t<_Rp>>>;
102 return fold_left_with_iter_result<borrowed_iterator_t<_Rp>, _Up>{std::move(__result.in), std::move(__result.value)};
103 }
104};
105
106inline constexpr auto fold_left_with_iter = __fold_left_with_iter();
107
108struct __fold_left {
109 template <input_iterator _Ip, sentinel_for<_Ip> _Sp, class _Tp, __indirectly_binary_left_foldable<_Tp, _Ip> _Fp>
110 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Ip __first, _Sp __last, _Tp __init, _Fp __f) {
111 return fold_left_with_iter(std::move(__first), std::move(__last), std::move(__init), std::ref(__f)).value;
112 }
113
114 template <input_range _Rp, class _Tp, __indirectly_binary_left_foldable<_Tp, iterator_t<_Rp>> _Fp>
115 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Rp&& __r, _Tp __init, _Fp __f) {
116 return fold_left_with_iter(ranges::begin(__r), ranges::end(__r), std::move(__init), std::ref(__f)).value;
117 }
118};
119
120inline constexpr auto fold_left = __fold_left();
121} // namespace ranges
122
123#endif // _LIBCPP_STD_VER >= 23
124
125_LIBCPP_END_NAMESPACE_STD
126
127_LIBCPP_POP_MACROS
128
129#endif // _LIBCPP___ALGORITHM_RANGES_FOLD_H
lib/libcxx/include/__algorithm/ranges_for_each.h+2-4
......@@ -36,8 +36,7 @@ namespace ranges {
3636template <class _Iter, class _Func>
3737using for_each_result = in_fun_result<_Iter, _Func>;
3838
39namespace __for_each {
40struct __fn {
39struct __for_each {
4140private:
4241 template <class _Iter, class _Sent, class _Proj, class _Func>
4342 _LIBCPP_HIDE_FROM_ABI constexpr static for_each_result<_Iter, _Func>
......@@ -65,10 +64,9 @@ public:
6564 return __for_each_impl(ranges::begin(__range), ranges::end(__range), __func, __proj);
6665 }
6766};
68} // namespace __for_each
6967
7068inline namespace __cpo {
71inline constexpr auto for_each = __for_each::__fn{};
69inline constexpr auto for_each = __for_each{};
7270} // namespace __cpo
7371} // namespace ranges
7472
lib/libcxx/include/__algorithm/ranges_for_each_n.h+2-4
......@@ -36,8 +36,7 @@ namespace ranges {
3636template <class _Iter, class _Func>
3737using for_each_n_result = in_fun_result<_Iter, _Func>;
3838
39namespace __for_each_n {
40struct __fn {
39struct __for_each_n {
4140 template <input_iterator _Iter, class _Proj = identity, indirectly_unary_invocable<projected<_Iter, _Proj>> _Func>
4241 _LIBCPP_HIDE_FROM_ABI constexpr for_each_n_result<_Iter, _Func>
4342 operator()(_Iter __first, iter_difference_t<_Iter> __count, _Func __func, _Proj __proj = {}) const {
......@@ -48,10 +47,9 @@ struct __fn {
4847 return {std::move(__first), std::move(__func)};
4948 }
5049};
51} // namespace __for_each_n
5250
5351inline namespace __cpo {
54inline constexpr auto for_each_n = __for_each_n::__fn{};
52inline constexpr auto for_each_n = __for_each_n{};
5553} // namespace __cpo
5654} // namespace ranges
5755
lib/libcxx/include/__algorithm/ranges_generate.h+3-7
......@@ -12,12 +12,12 @@
1212#include <__concepts/constructible.h>
1313#include <__concepts/invocable.h>
1414#include <__config>
15#include <__functional/invoke.h>
1615#include <__iterator/concepts.h>
1716#include <__iterator/iterator_traits.h>
1817#include <__ranges/access.h>
1918#include <__ranges/concepts.h>
2019#include <__ranges/dangling.h>
20#include <__type_traits/invoke.h>
2121#include <__utility/move.h>
2222
2323#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -32,9 +32,7 @@ _LIBCPP_PUSH_MACROS
3232_LIBCPP_BEGIN_NAMESPACE_STD
3333
3434namespace ranges {
35namespace __generate {
36
37struct __fn {
35struct __generate {
3836 template <class _OutIter, class _Sent, class _Func>
3937 _LIBCPP_HIDE_FROM_ABI constexpr static _OutIter __generate_fn_impl(_OutIter __first, _Sent __last, _Func& __gen) {
4038 for (; __first != __last; ++__first) {
......@@ -57,10 +55,8 @@ struct __fn {
5755 }
5856};
5957
60} // namespace __generate
61
6258inline namespace __cpo {
63inline constexpr auto generate = __generate::__fn{};
59inline constexpr auto generate = __generate{};
6460} // namespace __cpo
6561} // namespace ranges
6662
lib/libcxx/include/__algorithm/ranges_generate_n.h+3-7
......@@ -13,12 +13,12 @@
1313#include <__concepts/invocable.h>
1414#include <__config>
1515#include <__functional/identity.h>
16#include <__functional/invoke.h>
1716#include <__iterator/concepts.h>
1817#include <__iterator/incrementable_traits.h>
1918#include <__iterator/iterator_traits.h>
2019#include <__ranges/access.h>
2120#include <__ranges/concepts.h>
21#include <__type_traits/invoke.h>
2222#include <__utility/move.h>
2323
2424#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -33,9 +33,7 @@ _LIBCPP_PUSH_MACROS
3333_LIBCPP_BEGIN_NAMESPACE_STD
3434
3535namespace ranges {
36namespace __generate_n {
37
38struct __fn {
36struct __generate_n {
3937 template <input_or_output_iterator _OutIter, copy_constructible _Func>
4038 requires invocable<_Func&> && indirectly_writable<_OutIter, invoke_result_t<_Func&>>
4139 _LIBCPP_HIDE_FROM_ABI constexpr _OutIter
......@@ -49,10 +47,8 @@ struct __fn {
4947 }
5048};
5149
52} // namespace __generate_n
53
5450inline namespace __cpo {
55inline constexpr auto generate_n = __generate_n::__fn{};
51inline constexpr auto generate_n = __generate_n{};
5652} // namespace __cpo
5753} // namespace ranges
5854
lib/libcxx/include/__algorithm/ranges_includes.h+2-6
......@@ -35,9 +35,7 @@ _LIBCPP_PUSH_MACROS
3535_LIBCPP_BEGIN_NAMESPACE_STD
3636
3737namespace ranges {
38namespace __includes {
39
40struct __fn {
38struct __includes {
4139 template <input_iterator _Iter1,
4240 sentinel_for<_Iter1> _Sent1,
4341 input_iterator _Iter2,
......@@ -82,10 +80,8 @@ struct __fn {
8280 }
8381};
8482
85} // namespace __includes
86
8783inline namespace __cpo {
88inline constexpr auto includes = __includes::__fn{};
84inline constexpr auto includes = __includes{};
8985} // namespace __cpo
9086} // namespace ranges
9187
lib/libcxx/include/__algorithm/ranges_inplace_merge.h+2-6
......@@ -39,9 +39,7 @@ _LIBCPP_PUSH_MACROS
3939_LIBCPP_BEGIN_NAMESPACE_STD
4040
4141namespace ranges {
42namespace __inplace_merge {
43
44struct __fn {
42struct __inplace_merge {
4543 template <class _Iter, class _Sent, class _Comp, class _Proj>
4644 _LIBCPP_HIDE_FROM_ABI static constexpr auto
4745 __inplace_merge_impl(_Iter __first, _Iter __middle, _Sent __last, _Comp&& __comp, _Proj&& __proj) {
......@@ -68,10 +66,8 @@ struct __fn {
6866 }
6967};
7068
71} // namespace __inplace_merge
72
7369inline namespace __cpo {
74inline constexpr auto inplace_merge = __inplace_merge::__fn{};
70inline constexpr auto inplace_merge = __inplace_merge{};
7571} // namespace __cpo
7672} // namespace ranges
7773
lib/libcxx/include/__algorithm/ranges_is_heap.h+2-6
......@@ -34,9 +34,7 @@ _LIBCPP_PUSH_MACROS
3434_LIBCPP_BEGIN_NAMESPACE_STD
3535
3636namespace ranges {
37namespace __is_heap {
38
39struct __fn {
37struct __is_heap {
4038 template <class _Iter, class _Sent, class _Proj, class _Comp>
4139 _LIBCPP_HIDE_FROM_ABI constexpr static bool
4240 __is_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
......@@ -65,10 +63,8 @@ struct __fn {
6563 }
6664};
6765
68} // namespace __is_heap
69
7066inline namespace __cpo {
71inline constexpr auto is_heap = __is_heap::__fn{};
67inline constexpr auto is_heap = __is_heap{};
7268} // namespace __cpo
7369} // namespace ranges
7470
lib/libcxx/include/__algorithm/ranges_is_heap_until.h+2-6
......@@ -35,9 +35,7 @@ _LIBCPP_PUSH_MACROS
3535_LIBCPP_BEGIN_NAMESPACE_STD
3636
3737namespace ranges {
38namespace __is_heap_until {
39
40struct __fn {
38struct __is_heap_until {
4139 template <class _Iter, class _Sent, class _Proj, class _Comp>
4240 _LIBCPP_HIDE_FROM_ABI constexpr static _Iter
4341 __is_heap_until_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
......@@ -65,10 +63,8 @@ struct __fn {
6563 }
6664};
6765
68} // namespace __is_heap_until
69
7066inline namespace __cpo {
71inline constexpr auto is_heap_until = __is_heap_until::__fn{};
67inline constexpr auto is_heap_until = __is_heap_until{};
7268} // namespace __cpo
7369} // namespace ranges
7470
lib/libcxx/include/__algorithm/ranges_is_partitioned.h+2-4
......@@ -31,8 +31,7 @@ _LIBCPP_PUSH_MACROS
3131_LIBCPP_BEGIN_NAMESPACE_STD
3232
3333namespace ranges {
34namespace __is_partitioned {
35struct __fn {
34struct __is_partitioned {
3635 template <class _Iter, class _Sent, class _Proj, class _Pred>
3736 _LIBCPP_HIDE_FROM_ABI constexpr static bool
3837 __is_partitioned_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
......@@ -70,10 +69,9 @@ struct __fn {
7069 return __is_partitioned_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
7170 }
7271};
73} // namespace __is_partitioned
7472
7573inline namespace __cpo {
76inline constexpr auto is_partitioned = __is_partitioned::__fn{};
74inline constexpr auto is_partitioned = __is_partitioned{};
7775} // namespace __cpo
7876} // namespace ranges
7977
lib/libcxx/include/__algorithm/ranges_is_permutation.h+2-4
......@@ -33,8 +33,7 @@ _LIBCPP_PUSH_MACROS
3333_LIBCPP_BEGIN_NAMESPACE_STD
3434
3535namespace ranges {
36namespace __is_permutation {
37struct __fn {
36struct __is_permutation {
3837 template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Proj1, class _Proj2, class _Pred>
3938 _LIBCPP_HIDE_FROM_ABI constexpr static bool __is_permutation_func_impl(
4039 _Iter1 __first1,
......@@ -91,10 +90,9 @@ struct __fn {
9190 __proj2);
9291 }
9392};
94} // namespace __is_permutation
9593
9694inline namespace __cpo {
97inline constexpr auto is_permutation = __is_permutation::__fn{};
95inline constexpr auto is_permutation = __is_permutation{};
9896} // namespace __cpo
9997} // namespace ranges
10098
lib/libcxx/include/__algorithm/ranges_is_sorted.h+2-4
......@@ -31,8 +31,7 @@ _LIBCPP_PUSH_MACROS
3131_LIBCPP_BEGIN_NAMESPACE_STD
3232
3333namespace ranges {
34namespace __is_sorted {
35struct __fn {
34struct __is_sorted {
3635 template <forward_iterator _Iter,
3736 sentinel_for<_Iter> _Sent,
3837 class _Proj = identity,
......@@ -51,10 +50,9 @@ struct __fn {
5150 return ranges::__is_sorted_until_impl(ranges::begin(__range), __last, __comp, __proj) == __last;
5251 }
5352};
54} // namespace __is_sorted
5553
5654inline namespace __cpo {
57inline constexpr auto is_sorted = __is_sorted::__fn{};
55inline constexpr auto is_sorted = __is_sorted{};
5856} // namespace __cpo
5957} // namespace ranges
6058
lib/libcxx/include/__algorithm/ranges_is_sorted_until.h+2-4
......@@ -47,8 +47,7 @@ __is_sorted_until_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj
4747 return __i;
4848}
4949
50namespace __is_sorted_until {
51struct __fn {
50struct __is_sorted_until {
5251 template <forward_iterator _Iter,
5352 sentinel_for<_Iter> _Sent,
5453 class _Proj = identity,
......@@ -66,10 +65,9 @@ struct __fn {
6665 return ranges::__is_sorted_until_impl(ranges::begin(__range), ranges::end(__range), __comp, __proj);
6766 }
6867};
69} // namespace __is_sorted_until
7068
7169inline namespace __cpo {
72inline constexpr auto is_sorted_until = __is_sorted_until::__fn{};
70inline constexpr auto is_sorted_until = __is_sorted_until{};
7371} // namespace __cpo
7472} // namespace ranges
7573
lib/libcxx/include/__algorithm/ranges_iterator_concept.h+1-1
......@@ -44,7 +44,7 @@ consteval auto __get_iterator_concept() {
4444}
4545
4646template <class _Iter>
47using __iterator_concept = decltype(__get_iterator_concept<_Iter>());
47using __iterator_concept _LIBCPP_NODEBUG = decltype(__get_iterator_concept<_Iter>());
4848
4949} // namespace ranges
5050_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/ranges_lexicographical_compare.h+17-16
......@@ -9,6 +9,8 @@
99#ifndef _LIBCPP___ALGORITHM_RANGES_LEXICOGRAPHICAL_COMPARE_H
1010#define _LIBCPP___ALGORITHM_RANGES_LEXICOGRAPHICAL_COMPARE_H
1111
12#include <__algorithm/lexicographical_compare.h>
13#include <__algorithm/unwrap_range.h>
1214#include <__config>
1315#include <__functional/identity.h>
1416#include <__functional/invoke.h>
......@@ -31,10 +33,9 @@ _LIBCPP_PUSH_MACROS
3133_LIBCPP_BEGIN_NAMESPACE_STD
3234
3335namespace ranges {
34namespace __lexicographical_compare {
35struct __fn {
36struct __lexicographical_compare {
3637 template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Proj1, class _Proj2, class _Comp>
37 _LIBCPP_HIDE_FROM_ABI constexpr static bool __lexicographical_compare_impl(
38 static _LIBCPP_HIDE_FROM_ABI constexpr bool __lexicographical_compare_unwrap(
3839 _Iter1 __first1,
3940 _Sent1 __last1,
4041 _Iter2 __first2,
......@@ -42,15 +43,16 @@ struct __fn {
4243 _Comp& __comp,
4344 _Proj1& __proj1,
4445 _Proj2& __proj2) {
45 while (__first2 != __last2) {
46 if (__first1 == __last1 || std::invoke(__comp, std::invoke(__proj1, *__first1), std::invoke(__proj2, *__first2)))
47 return true;
48 if (std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1)))
49 return false;
50 ++__first1;
51 ++__first2;
52 }
53 return false;
46 auto [__first1_un, __last1_un] = std::__unwrap_range(std::move(__first1), std::move(__last1));
47 auto [__first2_un, __last2_un] = std::__unwrap_range(std::move(__first2), std::move(__last2));
48 return std::__lexicographical_compare(
49 std::move(__first1_un),
50 std::move(__last1_un),
51 std::move(__first2_un),
52 std::move(__last2_un),
53 __comp,
54 __proj1,
55 __proj2);
5456 }
5557
5658 template <input_iterator _Iter1,
......@@ -68,7 +70,7 @@ struct __fn {
6870 _Comp __comp = {},
6971 _Proj1 __proj1 = {},
7072 _Proj2 __proj2 = {}) const {
71 return __lexicographical_compare_impl(
73 return __lexicographical_compare_unwrap(
7274 std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __comp, __proj1, __proj2);
7375 }
7476
......@@ -80,7 +82,7 @@ struct __fn {
8082 _Comp = ranges::less>
8183 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
8284 _Range1&& __range1, _Range2&& __range2, _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const {
83 return __lexicographical_compare_impl(
85 return __lexicographical_compare_unwrap(
8486 ranges::begin(__range1),
8587 ranges::end(__range1),
8688 ranges::begin(__range2),
......@@ -90,10 +92,9 @@ struct __fn {
9092 __proj2);
9193 }
9294};
93} // namespace __lexicographical_compare
9495
9596inline namespace __cpo {
96inline constexpr auto lexicographical_compare = __lexicographical_compare::__fn{};
97inline constexpr auto lexicographical_compare = __lexicographical_compare{};
9798} // namespace __cpo
9899} // namespace ranges
99100
lib/libcxx/include/__algorithm/ranges_lower_bound.h+2-4
......@@ -36,8 +36,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3636
3737namespace ranges {
3838
39namespace __lower_bound {
40struct __fn {
39struct __lower_bound {
4140 template <forward_iterator _Iter,
4241 sentinel_for<_Iter> _Sent,
4342 class _Type,
......@@ -57,10 +56,9 @@ struct __fn {
5756 return std::__lower_bound<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), __value, __comp, __proj);
5857 }
5958};
60} // namespace __lower_bound
6159
6260inline namespace __cpo {
63inline constexpr auto lower_bound = __lower_bound::__fn{};
61inline constexpr auto lower_bound = __lower_bound{};
6462} // namespace __cpo
6563} // namespace ranges
6664
lib/libcxx/include/__algorithm/ranges_make_heap.h+2-6
......@@ -40,9 +40,7 @@ _LIBCPP_PUSH_MACROS
4040_LIBCPP_BEGIN_NAMESPACE_STD
4141
4242namespace ranges {
43namespace __make_heap {
44
45struct __fn {
43struct __make_heap {
4644 template <class _Iter, class _Sent, class _Comp, class _Proj>
4745 _LIBCPP_HIDE_FROM_ABI constexpr static _Iter
4846 __make_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
......@@ -69,10 +67,8 @@ struct __fn {
6967 }
7068};
7169
72} // namespace __make_heap
73
7470inline namespace __cpo {
75inline constexpr auto make_heap = __make_heap::__fn{};
71inline constexpr auto make_heap = __make_heap{};
7672} // namespace __cpo
7773} // namespace ranges
7874
lib/libcxx/include/__algorithm/ranges_max.h+2-4
......@@ -36,8 +36,7 @@ _LIBCPP_PUSH_MACROS
3636_LIBCPP_BEGIN_NAMESPACE_STD
3737
3838namespace ranges {
39namespace __max {
40struct __fn {
39struct __max {
4140 template <class _Tp,
4241 class _Proj = identity,
4342 indirect_strict_weak_order<projected<const _Tp*, _Proj>> _Comp = ranges::less>
......@@ -87,10 +86,9 @@ struct __fn {
8786 }
8887 }
8988};
90} // namespace __max
9189
9290inline namespace __cpo {
93inline constexpr auto max = __max::__fn{};
91inline constexpr auto max = __max{};
9492} // namespace __cpo
9593} // namespace ranges
9694
lib/libcxx/include/__algorithm/ranges_max_element.h+2-4
......@@ -32,8 +32,7 @@ _LIBCPP_PUSH_MACROS
3232_LIBCPP_BEGIN_NAMESPACE_STD
3333
3434namespace ranges {
35namespace __max_element {
36struct __fn {
35struct __max_element {
3736 template <forward_iterator _Ip,
3837 sentinel_for<_Ip> _Sp,
3938 class _Proj = identity,
......@@ -53,10 +52,9 @@ struct __fn {
5352 return ranges::__min_element_impl(ranges::begin(__r), ranges::end(__r), __comp_lhs_rhs_swapped, __proj);
5453 }
5554};
56} // namespace __max_element
5755
5856inline namespace __cpo {
59inline constexpr auto max_element = __max_element::__fn{};
57inline constexpr auto max_element = __max_element{};
6058} // namespace __cpo
6159} // namespace ranges
6260
lib/libcxx/include/__algorithm/ranges_merge.h+35-39
......@@ -39,42 +39,7 @@ namespace ranges {
3939template <class _InIter1, class _InIter2, class _OutIter>
4040using merge_result = in_in_out_result<_InIter1, _InIter2, _OutIter>;
4141
42namespace __merge {
43
44template < class _InIter1,
45 class _Sent1,
46 class _InIter2,
47 class _Sent2,
48 class _OutIter,
49 class _Comp,
50 class _Proj1,
51 class _Proj2>
52_LIBCPP_HIDE_FROM_ABI constexpr merge_result<__remove_cvref_t<_InIter1>,
53 __remove_cvref_t<_InIter2>,
54 __remove_cvref_t<_OutIter>>
55__merge_impl(_InIter1&& __first1,
56 _Sent1&& __last1,
57 _InIter2&& __first2,
58 _Sent2&& __last2,
59 _OutIter&& __result,
60 _Comp&& __comp,
61 _Proj1&& __proj1,
62 _Proj2&& __proj2) {
63 for (; __first1 != __last1 && __first2 != __last2; ++__result) {
64 if (std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1))) {
65 *__result = *__first2;
66 ++__first2;
67 } else {
68 *__result = *__first1;
69 ++__first1;
70 }
71 }
72 auto __ret1 = ranges::copy(std::move(__first1), std::move(__last1), std::move(__result));
73 auto __ret2 = ranges::copy(std::move(__first2), std::move(__last2), std::move(__ret1.out));
74 return {std::move(__ret1.in), std::move(__ret2.in), std::move(__ret2.out)};
75}
76
77struct __fn {
42struct __merge {
7843 template <input_iterator _InIter1,
7944 sentinel_for<_InIter1> _Sent1,
8045 input_iterator _InIter2,
......@@ -120,12 +85,43 @@ struct __fn {
12085 __proj1,
12186 __proj2);
12287 }
123};
12488
125} // namespace __merge
89 template < class _InIter1,
90 class _Sent1,
91 class _InIter2,
92 class _Sent2,
93 class _OutIter,
94 class _Comp,
95 class _Proj1,
96 class _Proj2>
97 _LIBCPP_HIDE_FROM_ABI static constexpr merge_result<__remove_cvref_t<_InIter1>,
98 __remove_cvref_t<_InIter2>,
99 __remove_cvref_t<_OutIter>>
100 __merge_impl(_InIter1&& __first1,
101 _Sent1&& __last1,
102 _InIter2&& __first2,
103 _Sent2&& __last2,
104 _OutIter&& __result,
105 _Comp&& __comp,
106 _Proj1&& __proj1,
107 _Proj2&& __proj2) {
108 for (; __first1 != __last1 && __first2 != __last2; ++__result) {
109 if (std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1))) {
110 *__result = *__first2;
111 ++__first2;
112 } else {
113 *__result = *__first1;
114 ++__first1;
115 }
116 }
117 auto __ret1 = ranges::copy(std::move(__first1), std::move(__last1), std::move(__result));
118 auto __ret2 = ranges::copy(std::move(__first2), std::move(__last2), std::move(__ret1.out));
119 return {std::move(__ret1.in), std::move(__ret2.in), std::move(__ret2.out)};
120 }
121};
126122
127123inline namespace __cpo {
128inline constexpr auto merge = __merge::__fn{};
124inline constexpr auto merge = __merge{};
129125} // namespace __cpo
130126} // namespace ranges
131127
lib/libcxx/include/__algorithm/ranges_min.h+2-4
......@@ -35,8 +35,7 @@ _LIBCPP_PUSH_MACROS
3535_LIBCPP_BEGIN_NAMESPACE_STD
3636
3737namespace ranges {
38namespace __min {
39struct __fn {
38struct __min {
4039 template <class _Tp,
4140 class _Proj = identity,
4241 indirect_strict_weak_order<projected<const _Tp*, _Proj>> _Comp = ranges::less>
......@@ -79,10 +78,9 @@ struct __fn {
7978 }
8079 }
8180};
82} // namespace __min
8381
8482inline namespace __cpo {
85inline constexpr auto min = __min::__fn{};
83inline constexpr auto min = __min{};
8684} // namespace __cpo
8785} // namespace ranges
8886
lib/libcxx/include/__algorithm/ranges_min_element.h+2-4
......@@ -46,8 +46,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Ip __min_element_impl(_Ip __first, _Sp __last,
4646 return __first;
4747}
4848
49namespace __min_element {
50struct __fn {
49struct __min_element {
5150 template <forward_iterator _Ip,
5251 sentinel_for<_Ip> _Sp,
5352 class _Proj = identity,
......@@ -65,10 +64,9 @@ struct __fn {
6564 return ranges::__min_element_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj);
6665 }
6766};
68} // namespace __min_element
6967
7068inline namespace __cpo {
71inline constexpr auto min_element = __min_element::__fn{};
69inline constexpr auto min_element = __min_element{};
7270} // namespace __cpo
7371} // namespace ranges
7472
lib/libcxx/include/__algorithm/ranges_minmax.h+3-4
......@@ -24,6 +24,7 @@
2424#include <__ranges/access.h>
2525#include <__ranges/concepts.h>
2626#include <__type_traits/desugars_to.h>
27#include <__type_traits/is_integral.h>
2728#include <__type_traits/is_reference.h>
2829#include <__type_traits/is_trivially_copyable.h>
2930#include <__type_traits/remove_cvref.h>
......@@ -47,8 +48,7 @@ namespace ranges {
4748template <class _T1>
4849using minmax_result = min_max_result<_T1>;
4950
50namespace __minmax {
51struct __fn {
51struct __minmax {
5252 template <class _Type,
5353 class _Proj = identity,
5454 indirect_strict_weak_order<projected<const _Type*, _Proj>> _Comp = ranges::less>
......@@ -159,10 +159,9 @@ struct __fn {
159159 }
160160 }
161161};
162} // namespace __minmax
163162
164163inline namespace __cpo {
165inline constexpr auto minmax = __minmax::__fn{};
164inline constexpr auto minmax = __minmax{};
166165} // namespace __cpo
167166} // namespace ranges
168167
lib/libcxx/include/__algorithm/ranges_minmax_element.h+2-4
......@@ -40,8 +40,7 @@ namespace ranges {
4040template <class _T1>
4141using minmax_element_result = min_max_result<_T1>;
4242
43namespace __minmax_element {
44struct __fn {
43struct __minmax_element {
4544 template <forward_iterator _Ip,
4645 sentinel_for<_Ip> _Sp,
4746 class _Proj = identity,
......@@ -61,10 +60,9 @@ struct __fn {
6160 return {__ret.first, __ret.second};
6261 }
6362};
64} // namespace __minmax_element
6563
6664inline namespace __cpo {
67inline constexpr auto minmax_element = __minmax_element::__fn{};
65inline constexpr auto minmax_element = __minmax_element{};
6866} // namespace __cpo
6967
7068} // namespace ranges
lib/libcxx/include/__algorithm/ranges_mismatch.h+2-4
......@@ -39,8 +39,7 @@ namespace ranges {
3939template <class _I1, class _I2>
4040using mismatch_result = in_in_result<_I1, _I2>;
4141
42namespace __mismatch {
43struct __fn {
42struct __mismatch {
4443 template <class _I1, class _S1, class _I2, class _S2, class _Pred, class _Proj1, class _Proj2>
4544 static _LIBCPP_HIDE_FROM_ABI constexpr mismatch_result<_I1, _I2>
4645 __go(_I1 __first1, _S1 __last1, _I2 __first2, _S2 __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) {
......@@ -84,10 +83,9 @@ struct __fn {
8483 ranges::begin(__r1), ranges::end(__r1), ranges::begin(__r2), ranges::end(__r2), __pred, __proj1, __proj2);
8584 }
8685};
87} // namespace __mismatch
8886
8987inline namespace __cpo {
90constexpr inline auto mismatch = __mismatch::__fn{};
88constexpr inline auto mismatch = __mismatch{};
9189} // namespace __cpo
9290} // namespace ranges
9391
lib/libcxx/include/__algorithm/ranges_move.h+2-4
......@@ -35,8 +35,7 @@ namespace ranges {
3535template <class _InIter, class _OutIter>
3636using move_result = in_out_result<_InIter, _OutIter>;
3737
38namespace __move {
39struct __fn {
38struct __move {
4039 template <class _InIter, class _Sent, class _OutIter>
4140 _LIBCPP_HIDE_FROM_ABI constexpr static move_result<_InIter, _OutIter>
4241 __move_impl(_InIter __first, _Sent __last, _OutIter __result) {
......@@ -58,10 +57,9 @@ struct __fn {
5857 return __move_impl(ranges::begin(__range), ranges::end(__range), std::move(__result));
5958 }
6059};
61} // namespace __move
6260
6361inline namespace __cpo {
64inline constexpr auto move = __move::__fn{};
62inline constexpr auto move = __move{};
6563} // namespace __cpo
6664} // namespace ranges
6765
lib/libcxx/include/__algorithm/ranges_move_backward.h+2-4
......@@ -37,8 +37,7 @@ namespace ranges {
3737template <class _InIter, class _OutIter>
3838using move_backward_result = in_out_result<_InIter, _OutIter>;
3939
40namespace __move_backward {
41struct __fn {
40struct __move_backward {
4241 template <class _InIter, class _Sent, class _OutIter>
4342 _LIBCPP_HIDE_FROM_ABI constexpr static move_backward_result<_InIter, _OutIter>
4443 __move_backward_impl(_InIter __first, _Sent __last, _OutIter __result) {
......@@ -60,10 +59,9 @@ struct __fn {
6059 return __move_backward_impl(ranges::begin(__range), ranges::end(__range), std::move(__result));
6160 }
6261};
63} // namespace __move_backward
6462
6563inline namespace __cpo {
66inline constexpr auto move_backward = __move_backward::__fn{};
64inline constexpr auto move_backward = __move_backward{};
6765} // namespace __cpo
6866} // namespace ranges
6967
lib/libcxx/include/__algorithm/ranges_next_permutation.h+2-6
......@@ -40,9 +40,7 @@ namespace ranges {
4040template <class _InIter>
4141using next_permutation_result = in_found_result<_InIter>;
4242
43namespace __next_permutation {
44
45struct __fn {
43struct __next_permutation {
4644 template <bidirectional_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
4745 requires sortable<_Iter, _Comp, _Proj>
4846 _LIBCPP_HIDE_FROM_ABI constexpr next_permutation_result<_Iter>
......@@ -62,10 +60,8 @@ struct __fn {
6260 }
6361};
6462
65} // namespace __next_permutation
66
6763inline namespace __cpo {
68constexpr inline auto next_permutation = __next_permutation::__fn{};
64constexpr inline auto next_permutation = __next_permutation{};
6965} // namespace __cpo
7066} // namespace ranges
7167
lib/libcxx/include/__algorithm/ranges_none_of.h+2-4
......@@ -30,8 +30,7 @@ _LIBCPP_PUSH_MACROS
3030_LIBCPP_BEGIN_NAMESPACE_STD
3131
3232namespace ranges {
33namespace __none_of {
34struct __fn {
33struct __none_of {
3534 template <class _Iter, class _Sent, class _Proj, class _Pred>
3635 _LIBCPP_HIDE_FROM_ABI constexpr static bool
3736 __none_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
......@@ -59,10 +58,9 @@ struct __fn {
5958 return __none_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
6059 }
6160};
62} // namespace __none_of
6361
6462inline namespace __cpo {
65inline constexpr auto none_of = __none_of::__fn{};
63inline constexpr auto none_of = __none_of{};
6664} // namespace __cpo
6765} // namespace ranges
6866
lib/libcxx/include/__algorithm/ranges_nth_element.h+2-6
......@@ -39,9 +39,7 @@ _LIBCPP_PUSH_MACROS
3939_LIBCPP_BEGIN_NAMESPACE_STD
4040
4141namespace ranges {
42namespace __nth_element {
43
44struct __fn {
42struct __nth_element {
4543 template <class _Iter, class _Sent, class _Comp, class _Proj>
4644 _LIBCPP_HIDE_FROM_ABI constexpr static _Iter
4745 __nth_element_fn_impl(_Iter __first, _Iter __nth, _Sent __last, _Comp& __comp, _Proj& __proj) {
......@@ -68,10 +66,8 @@ struct __fn {
6866 }
6967};
7068
71} // namespace __nth_element
72
7369inline namespace __cpo {
74inline constexpr auto nth_element = __nth_element::__fn{};
70inline constexpr auto nth_element = __nth_element{};
7571} // namespace __cpo
7672} // namespace ranges
7773
lib/libcxx/include/__algorithm/ranges_partial_sort.h+2-6
......@@ -41,9 +41,7 @@ _LIBCPP_PUSH_MACROS
4141_LIBCPP_BEGIN_NAMESPACE_STD
4242
4343namespace ranges {
44namespace __partial_sort {
45
46struct __fn {
44struct __partial_sort {
4745 template <class _Iter, class _Sent, class _Comp, class _Proj>
4846 _LIBCPP_HIDE_FROM_ABI constexpr static _Iter
4947 __partial_sort_fn_impl(_Iter __first, _Iter __middle, _Sent __last, _Comp& __comp, _Proj& __proj) {
......@@ -66,10 +64,8 @@ struct __fn {
6664 }
6765};
6866
69} // namespace __partial_sort
70
7167inline namespace __cpo {
72inline constexpr auto partial_sort = __partial_sort::__fn{};
68inline constexpr auto partial_sort = __partial_sort{};
7369} // namespace __cpo
7470} // namespace ranges
7571
lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h+2-6
......@@ -42,9 +42,7 @@ namespace ranges {
4242template <class _InIter, class _OutIter>
4343using partial_sort_copy_result = in_out_result<_InIter, _OutIter>;
4444
45namespace __partial_sort_copy {
46
47struct __fn {
45struct __partial_sort_copy {
4846 template <input_iterator _Iter1,
4947 sentinel_for<_Iter1> _Sent1,
5048 random_access_iterator _Iter2,
......@@ -98,10 +96,8 @@ struct __fn {
9896 }
9997};
10098
101} // namespace __partial_sort_copy
102
10399inline namespace __cpo {
104inline constexpr auto partial_sort_copy = __partial_sort_copy::__fn{};
100inline constexpr auto partial_sort_copy = __partial_sort_copy{};
105101} // namespace __cpo
106102} // namespace ranges
107103
lib/libcxx/include/__algorithm/ranges_partition.h+3-6
......@@ -24,6 +24,7 @@
2424#include <__ranges/access.h>
2525#include <__ranges/concepts.h>
2626#include <__ranges/subrange.h>
27#include <__type_traits/remove_cvref.h>
2728#include <__utility/forward.h>
2829#include <__utility/move.h>
2930#include <__utility/pair.h>
......@@ -40,9 +41,7 @@ _LIBCPP_PUSH_MACROS
4041_LIBCPP_BEGIN_NAMESPACE_STD
4142
4243namespace ranges {
43namespace __partition {
44
45struct __fn {
44struct __partition {
4645 template <class _Iter, class _Sent, class _Proj, class _Pred>
4746 _LIBCPP_HIDE_FROM_ABI static constexpr subrange<__remove_cvref_t<_Iter>>
4847 __partition_fn_impl(_Iter&& __first, _Sent&& __last, _Pred&& __pred, _Proj&& __proj) {
......@@ -72,10 +71,8 @@ struct __fn {
7271 }
7372};
7473
75} // namespace __partition
76
7774inline namespace __cpo {
78inline constexpr auto partition = __partition::__fn{};
75inline constexpr auto partition = __partition{};
7976} // namespace __cpo
8077} // namespace ranges
8178
lib/libcxx/include/__algorithm/ranges_partition_copy.h+2-6
......@@ -38,9 +38,7 @@ namespace ranges {
3838template <class _InIter, class _OutIter1, class _OutIter2>
3939using partition_copy_result = in_out_out_result<_InIter, _OutIter1, _OutIter2>;
4040
41namespace __partition_copy {
42
43struct __fn {
41struct __partition_copy {
4442 // TODO(ranges): delegate to the classic algorithm.
4543 template <class _InIter, class _Sent, class _OutIter1, class _OutIter2, class _Proj, class _Pred>
4644 _LIBCPP_HIDE_FROM_ABI constexpr static partition_copy_result<__remove_cvref_t<_InIter>,
......@@ -94,10 +92,8 @@ struct __fn {
9492 }
9593};
9694
97} // namespace __partition_copy
98
9995inline namespace __cpo {
100inline constexpr auto partition_copy = __partition_copy::__fn{};
96inline constexpr auto partition_copy = __partition_copy{};
10197} // namespace __cpo
10298} // namespace ranges
10399
lib/libcxx/include/__algorithm/ranges_partition_point.h+2-6
......@@ -35,9 +35,7 @@ _LIBCPP_PUSH_MACROS
3535_LIBCPP_BEGIN_NAMESPACE_STD
3636
3737namespace ranges {
38namespace __partition_point {
39
40struct __fn {
38struct __partition_point {
4139 // TODO(ranges): delegate to the classic algorithm.
4240 template <class _Iter, class _Sent, class _Proj, class _Pred>
4341 _LIBCPP_HIDE_FROM_ABI constexpr static _Iter
......@@ -77,10 +75,8 @@ struct __fn {
7775 }
7876};
7977
80} // namespace __partition_point
81
8278inline namespace __cpo {
83inline constexpr auto partition_point = __partition_point::__fn{};
79inline constexpr auto partition_point = __partition_point{};
8480} // namespace __cpo
8581} // namespace ranges
8682
lib/libcxx/include/__algorithm/ranges_pop_heap.h+2-6
......@@ -40,9 +40,7 @@ _LIBCPP_PUSH_MACROS
4040_LIBCPP_BEGIN_NAMESPACE_STD
4141
4242namespace ranges {
43namespace __pop_heap {
44
45struct __fn {
43struct __pop_heap {
4644 template <class _Iter, class _Sent, class _Comp, class _Proj>
4745 _LIBCPP_HIDE_FROM_ABI constexpr static _Iter
4846 __pop_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
......@@ -70,10 +68,8 @@ struct __fn {
7068 }
7169};
7270
73} // namespace __pop_heap
74
7571inline namespace __cpo {
76inline constexpr auto pop_heap = __pop_heap::__fn{};
72inline constexpr auto pop_heap = __pop_heap{};
7773} // namespace __cpo
7874} // namespace ranges
7975
lib/libcxx/include/__algorithm/ranges_prev_permutation.h+2-6
......@@ -40,9 +40,7 @@ namespace ranges {
4040template <class _InIter>
4141using prev_permutation_result = in_found_result<_InIter>;
4242
43namespace __prev_permutation {
44
45struct __fn {
43struct __prev_permutation {
4644 template <bidirectional_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
4745 requires sortable<_Iter, _Comp, _Proj>
4846 _LIBCPP_HIDE_FROM_ABI constexpr prev_permutation_result<_Iter>
......@@ -62,10 +60,8 @@ struct __fn {
6260 }
6361};
6462
65} // namespace __prev_permutation
66
6763inline namespace __cpo {
68constexpr inline auto prev_permutation = __prev_permutation::__fn{};
64constexpr inline auto prev_permutation = __prev_permutation{};
6965} // namespace __cpo
7066} // namespace ranges
7167
lib/libcxx/include/__algorithm/ranges_push_heap.h+2-6
......@@ -40,9 +40,7 @@ _LIBCPP_PUSH_MACROS
4040_LIBCPP_BEGIN_NAMESPACE_STD
4141
4242namespace ranges {
43namespace __push_heap {
44
45struct __fn {
43struct __push_heap {
4644 template <class _Iter, class _Sent, class _Comp, class _Proj>
4745 _LIBCPP_HIDE_FROM_ABI constexpr static _Iter
4846 __push_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
......@@ -69,10 +67,8 @@ struct __fn {
6967 }
7068};
7169
72} // namespace __push_heap
73
7470inline namespace __cpo {
75inline constexpr auto push_heap = __push_heap::__fn{};
71inline constexpr auto push_heap = __push_heap{};
7672} // namespace __cpo
7773} // namespace ranges
7874
lib/libcxx/include/__algorithm/ranges_remove.h+2-4
......@@ -33,8 +33,7 @@ _LIBCPP_PUSH_MACROS
3333_LIBCPP_BEGIN_NAMESPACE_STD
3434
3535namespace ranges {
36namespace __remove {
37struct __fn {
36struct __remove {
3837 template <permutable _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity>
3938 requires indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type*>
4039 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter>
......@@ -52,10 +51,9 @@ struct __fn {
5251 return ranges::__remove_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
5352 }
5453};
55} // namespace __remove
5654
5755inline namespace __cpo {
58inline constexpr auto remove = __remove::__fn{};
56inline constexpr auto remove = __remove{};
5957} // namespace __cpo
6058} // namespace ranges
6159
lib/libcxx/include/__algorithm/ranges_remove_copy.h+2-6
......@@ -38,9 +38,7 @@ namespace ranges {
3838template <class _InIter, class _OutIter>
3939using remove_copy_result = in_out_result<_InIter, _OutIter>;
4040
41namespace __remove_copy {
42
43struct __fn {
41struct __remove_copy {
4442 template <input_iterator _InIter,
4543 sentinel_for<_InIter> _Sent,
4644 weakly_incrementable _OutIter,
......@@ -65,10 +63,8 @@ struct __fn {
6563 }
6664};
6765
68} // namespace __remove_copy
69
7066inline namespace __cpo {
71inline constexpr auto remove_copy = __remove_copy::__fn{};
67inline constexpr auto remove_copy = __remove_copy{};
7268} // namespace __cpo
7369} // namespace ranges
7470
lib/libcxx/include/__algorithm/ranges_remove_copy_if.h+2-6
......@@ -53,9 +53,7 @@ __remove_copy_if_impl(_InIter __first, _Sent __last, _OutIter __result, _Pred& _
5353 return {std::move(__first), std::move(__result)};
5454}
5555
56namespace __remove_copy_if {
57
58struct __fn {
56struct __remove_copy_if {
5957 template <input_iterator _InIter,
6058 sentinel_for<_InIter> _Sent,
6159 weakly_incrementable _OutIter,
......@@ -79,10 +77,8 @@ struct __fn {
7977 }
8078};
8179
82} // namespace __remove_copy_if
83
8480inline namespace __cpo {
85inline constexpr auto remove_copy_if = __remove_copy_if::__fn{};
81inline constexpr auto remove_copy_if = __remove_copy_if{};
8682} // namespace __cpo
8783} // namespace ranges
8884
lib/libcxx/include/__algorithm/ranges_remove_if.h+2-4
......@@ -53,8 +53,7 @@ __remove_if_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
5353 return {__new_end, __i};
5454}
5555
56namespace __remove_if {
57struct __fn {
56struct __remove_if {
5857 template <permutable _Iter,
5958 sentinel_for<_Iter> _Sent,
6059 class _Proj = identity,
......@@ -73,10 +72,9 @@ struct __fn {
7372 return ranges::__remove_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
7473 }
7574};
76} // namespace __remove_if
7775
7876inline namespace __cpo {
79inline constexpr auto remove_if = __remove_if::__fn{};
77inline constexpr auto remove_if = __remove_if{};
8078} // namespace __cpo
8179} // namespace ranges
8280
lib/libcxx/include/__algorithm/ranges_replace.h+2-4
......@@ -32,8 +32,7 @@ _LIBCPP_PUSH_MACROS
3232_LIBCPP_BEGIN_NAMESPACE_STD
3333
3434namespace ranges {
35namespace __replace {
36struct __fn {
35struct __replace {
3736 template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Type1, class _Type2, class _Proj = identity>
3837 requires indirectly_writable<_Iter, const _Type2&> &&
3938 indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type1*>
......@@ -52,10 +51,9 @@ struct __fn {
5251 return ranges::__replace_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __new_value, __proj);
5352 }
5453};
55} // namespace __replace
5654
5755inline namespace __cpo {
58inline constexpr auto replace = __replace::__fn{};
56inline constexpr auto replace = __replace{};
5957} // namespace __cpo
6058} // namespace ranges
6159
lib/libcxx/include/__algorithm/ranges_replace_copy.h+2-6
......@@ -38,9 +38,7 @@ namespace ranges {
3838template <class _InIter, class _OutIter>
3939using replace_copy_result = in_out_result<_InIter, _OutIter>;
4040
41namespace __replace_copy {
42
43struct __fn {
41struct __replace_copy {
4442 template <input_iterator _InIter,
4543 sentinel_for<_InIter> _Sent,
4644 class _OldType,
......@@ -77,10 +75,8 @@ struct __fn {
7775 }
7876};
7977
80} // namespace __replace_copy
81
8278inline namespace __cpo {
83inline constexpr auto replace_copy = __replace_copy::__fn{};
79inline constexpr auto replace_copy = __replace_copy{};
8480} // namespace __cpo
8581} // namespace ranges
8682
lib/libcxx/include/__algorithm/ranges_replace_copy_if.h+2-6
......@@ -52,9 +52,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr replace_copy_if_result<_InIter, _OutIter> __repl
5252 return {std::move(__first), std::move(__result)};
5353}
5454
55namespace __replace_copy_if {
56
57struct __fn {
55struct __replace_copy_if {
5856 template <input_iterator _InIter,
5957 sentinel_for<_InIter> _Sent,
6058 class _Type,
......@@ -82,10 +80,8 @@ struct __fn {
8280 }
8381};
8482
85} // namespace __replace_copy_if
86
8783inline namespace __cpo {
88inline constexpr auto replace_copy_if = __replace_copy_if::__fn{};
84inline constexpr auto replace_copy_if = __replace_copy_if{};
8985} // namespace __cpo
9086} // namespace ranges
9187
lib/libcxx/include/__algorithm/ranges_replace_if.h+2-4
......@@ -42,8 +42,7 @@ __replace_if_impl(_Iter __first, _Sent __last, _Pred& __pred, const _Type& __new
4242 return __first;
4343}
4444
45namespace __replace_if {
46struct __fn {
45struct __replace_if {
4746 template <input_iterator _Iter,
4847 sentinel_for<_Iter> _Sent,
4948 class _Type,
......@@ -65,10 +64,9 @@ struct __fn {
6564 return ranges::__replace_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __new_value, __proj);
6665 }
6766};
68} // namespace __replace_if
6967
7068inline namespace __cpo {
71inline constexpr auto replace_if = __replace_if::__fn{};
69inline constexpr auto replace_if = __replace_if{};
7270} // namespace __cpo
7371} // namespace ranges
7472
lib/libcxx/include/__algorithm/ranges_reverse.h+2-4
......@@ -27,8 +27,7 @@
2727_LIBCPP_BEGIN_NAMESPACE_STD
2828
2929namespace ranges {
30namespace __reverse {
31struct __fn {
30struct __reverse {
3231 template <bidirectional_iterator _Iter, sentinel_for<_Iter> _Sent>
3332 requires permutable<_Iter>
3433 _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last) const {
......@@ -65,10 +64,9 @@ struct __fn {
6564 return (*this)(ranges::begin(__range), ranges::end(__range));
6665 }
6766};
68} // namespace __reverse
6967
7068inline namespace __cpo {
71inline constexpr auto reverse = __reverse::__fn{};
69inline constexpr auto reverse = __reverse{};
7270} // namespace __cpo
7371} // namespace ranges
7472
lib/libcxx/include/__algorithm/ranges_reverse_copy.h+2-4
......@@ -37,8 +37,7 @@ namespace ranges {
3737template <class _InIter, class _OutIter>
3838using reverse_copy_result = in_out_result<_InIter, _OutIter>;
3939
40namespace __reverse_copy {
41struct __fn {
40struct __reverse_copy {
4241 template <bidirectional_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter>
4342 requires indirectly_copyable<_InIter, _OutIter>
4443 _LIBCPP_HIDE_FROM_ABI constexpr reverse_copy_result<_InIter, _OutIter>
......@@ -54,10 +53,9 @@ struct __fn {
5453 return {ranges::next(ranges::begin(__range), ranges::end(__range)), std::move(__ret.out)};
5554 }
5655};
57} // namespace __reverse_copy
5856
5957inline namespace __cpo {
60inline constexpr auto reverse_copy = __reverse_copy::__fn{};
58inline constexpr auto reverse_copy = __reverse_copy{};
6159} // namespace __cpo
6260} // namespace ranges
6361
lib/libcxx/include/__algorithm/ranges_rotate.h+2-6
......@@ -33,9 +33,7 @@ _LIBCPP_PUSH_MACROS
3333_LIBCPP_BEGIN_NAMESPACE_STD
3434
3535namespace ranges {
36namespace __rotate {
37
38struct __fn {
36struct __rotate {
3937 template <class _Iter, class _Sent>
4038 _LIBCPP_HIDE_FROM_ABI constexpr static subrange<_Iter> __rotate_fn_impl(_Iter __first, _Iter __middle, _Sent __last) {
4139 auto __ret = std::__rotate<_RangeAlgPolicy>(std::move(__first), std::move(__middle), std::move(__last));
......@@ -55,10 +53,8 @@ struct __fn {
5553 }
5654};
5755
58} // namespace __rotate
59
6056inline namespace __cpo {
61inline constexpr auto rotate = __rotate::__fn{};
57inline constexpr auto rotate = __rotate{};
6258} // namespace __cpo
6359} // namespace ranges
6460
lib/libcxx/include/__algorithm/ranges_rotate_copy.h+2-4
......@@ -34,8 +34,7 @@ namespace ranges {
3434template <class _InIter, class _OutIter>
3535using rotate_copy_result = in_out_result<_InIter, _OutIter>;
3636
37namespace __rotate_copy {
38struct __fn {
37struct __rotate_copy {
3938 template <forward_iterator _InIter, sentinel_for<_InIter> _Sent, weakly_incrementable _OutIter>
4039 requires indirectly_copyable<_InIter, _OutIter>
4140 _LIBCPP_HIDE_FROM_ABI constexpr rotate_copy_result<_InIter, _OutIter>
......@@ -52,10 +51,9 @@ struct __fn {
5251 return (*this)(ranges::begin(__range), std::move(__middle), ranges::end(__range), std::move(__result));
5352 }
5453};
55} // namespace __rotate_copy
5654
5755inline namespace __cpo {
58inline constexpr auto rotate_copy = __rotate_copy::__fn{};
56inline constexpr auto rotate_copy = __rotate_copy{};
5957} // namespace __cpo
6058} // namespace ranges
6159
lib/libcxx/include/__algorithm/ranges_sample.h+2-6
......@@ -35,9 +35,7 @@ _LIBCPP_PUSH_MACROS
3535_LIBCPP_BEGIN_NAMESPACE_STD
3636
3737namespace ranges {
38namespace __sample {
39
40struct __fn {
38struct __sample {
4139 template <input_iterator _Iter, sentinel_for<_Iter> _Sent, weakly_incrementable _OutIter, class _Gen>
4240 requires(forward_iterator<_Iter> || random_access_iterator<_OutIter>) && indirectly_copyable<_Iter, _OutIter> &&
4341 uniform_random_bit_generator<remove_reference_t<_Gen>>
......@@ -58,10 +56,8 @@ struct __fn {
5856 }
5957};
6058
61} // namespace __sample
62
6359inline namespace __cpo {
64inline constexpr auto sample = __sample::__fn{};
60inline constexpr auto sample = __sample{};
6561} // namespace __cpo
6662} // namespace ranges
6763
lib/libcxx/include/__algorithm/ranges_search.h+2-4
......@@ -33,8 +33,7 @@
3333_LIBCPP_BEGIN_NAMESPACE_STD
3434
3535namespace ranges {
36namespace __search {
37struct __fn {
36struct __search {
3837 template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
3938 _LIBCPP_HIDE_FROM_ABI static constexpr subrange<_Iter1> __ranges_search_impl(
4039 _Iter1 __first1,
......@@ -120,10 +119,9 @@ struct __fn {
120119 __proj2);
121120 }
122121};
123} // namespace __search
124122
125123inline namespace __cpo {
126inline constexpr auto search = __search::__fn{};
124inline constexpr auto search = __search{};
127125} // namespace __cpo
128126} // namespace ranges
129127
lib/libcxx/include/__algorithm/ranges_search_n.h+2-4
......@@ -39,8 +39,7 @@ _LIBCPP_PUSH_MACROS
3939_LIBCPP_BEGIN_NAMESPACE_STD
4040
4141namespace ranges {
42namespace __search_n {
43struct __fn {
42struct __search_n {
4443 template <class _Iter1, class _Sent1, class _SizeT, class _Type, class _Pred, class _Proj>
4544 _LIBCPP_HIDE_FROM_ABI static constexpr subrange<_Iter1> __ranges_search_n_impl(
4645 _Iter1 __first, _Sent1 __last, _SizeT __count, const _Type& __value, _Pred& __pred, _Proj& __proj) {
......@@ -100,10 +99,9 @@ struct __fn {
10099 return __ranges_search_n_impl(ranges::begin(__range), ranges::end(__range), __count, __value, __pred, __proj);
101100 }
102101};
103} // namespace __search_n
104102
105103inline namespace __cpo {
106inline constexpr auto search_n = __search_n::__fn{};
104inline constexpr auto search_n = __search_n{};
107105} // namespace __cpo
108106} // namespace ranges
109107
lib/libcxx/include/__algorithm/ranges_set_difference.h+4-9
......@@ -10,7 +10,6 @@
1010#define _LIBCPP___ALGORITHM_RANGES_SET_DIFFERENCE_H
1111
1212#include <__algorithm/in_out_result.h>
13#include <__algorithm/iterator_operations.h>
1413#include <__algorithm/make_projected.h>
1514#include <__algorithm/set_difference.h>
1615#include <__config>
......@@ -42,9 +41,7 @@ namespace ranges {
4241template <class _InIter, class _OutIter>
4342using set_difference_result = in_out_result<_InIter, _OutIter>;
4443
45namespace __set_difference {
46
47struct __fn {
44struct __set_difference {
4845 template <input_iterator _InIter1,
4946 sentinel_for<_InIter1> _Sent1,
5047 input_iterator _InIter2,
......@@ -63,7 +60,7 @@ struct __fn {
6360 _Comp __comp = {},
6461 _Proj1 __proj1 = {},
6562 _Proj2 __proj2 = {}) const {
66 auto __ret = std::__set_difference<_RangeAlgPolicy>(
63 auto __ret = std::__set_difference(
6764 __first1, __last1, __first2, __last2, __result, ranges::__make_projected_comp(__comp, __proj1, __proj2));
6865 return {std::move(__ret.first), std::move(__ret.second)};
6966 }
......@@ -82,7 +79,7 @@ struct __fn {
8279 _Comp __comp = {},
8380 _Proj1 __proj1 = {},
8481 _Proj2 __proj2 = {}) const {
85 auto __ret = std::__set_difference<_RangeAlgPolicy>(
82 auto __ret = std::__set_difference(
8683 ranges::begin(__range1),
8784 ranges::end(__range1),
8885 ranges::begin(__range2),
......@@ -93,10 +90,8 @@ struct __fn {
9390 }
9491};
9592
96} // namespace __set_difference
97
9893inline namespace __cpo {
99inline constexpr auto set_difference = __set_difference::__fn{};
94inline constexpr auto set_difference = __set_difference{};
10095} // namespace __cpo
10196} // namespace ranges
10297
lib/libcxx/include/__algorithm/ranges_set_intersection.h+2-6
......@@ -40,9 +40,7 @@ namespace ranges {
4040template <class _InIter1, class _InIter2, class _OutIter>
4141using set_intersection_result = in_in_out_result<_InIter1, _InIter2, _OutIter>;
4242
43namespace __set_intersection {
44
45struct __fn {
43struct __set_intersection {
4644 template <input_iterator _InIter1,
4745 sentinel_for<_InIter1> _Sent1,
4846 input_iterator _InIter2,
......@@ -98,10 +96,8 @@ struct __fn {
9896 }
9997};
10098
101} // namespace __set_intersection
102
10399inline namespace __cpo {
104inline constexpr auto set_intersection = __set_intersection::__fn{};
100inline constexpr auto set_intersection = __set_intersection{};
105101} // namespace __cpo
106102} // namespace ranges
107103
lib/libcxx/include/__algorithm/ranges_set_symmetric_difference.h+4-9
......@@ -10,7 +10,6 @@
1010#define _LIBCPP___ALGORITHM_RANGES_SET_SYMMETRIC_DIFFERENCE_H
1111
1212#include <__algorithm/in_in_out_result.h>
13#include <__algorithm/iterator_operations.h>
1413#include <__algorithm/make_projected.h>
1514#include <__algorithm/set_symmetric_difference.h>
1615#include <__config>
......@@ -40,9 +39,7 @@ namespace ranges {
4039template <class _InIter1, class _InIter2, class _OutIter>
4140using set_symmetric_difference_result = in_in_out_result<_InIter1, _InIter2, _OutIter>;
4241
43namespace __set_symmetric_difference {
44
45struct __fn {
42struct __set_symmetric_difference {
4643 template <input_iterator _InIter1,
4744 sentinel_for<_InIter1> _Sent1,
4845 input_iterator _InIter2,
......@@ -61,7 +58,7 @@ struct __fn {
6158 _Comp __comp = {},
6259 _Proj1 __proj1 = {},
6360 _Proj2 __proj2 = {}) const {
64 auto __ret = std::__set_symmetric_difference<_RangeAlgPolicy>(
61 auto __ret = std::__set_symmetric_difference(
6562 std::move(__first1),
6663 std::move(__last1),
6764 std::move(__first2),
......@@ -87,7 +84,7 @@ struct __fn {
8784 _Comp __comp = {},
8885 _Proj1 __proj1 = {},
8986 _Proj2 __proj2 = {}) const {
90 auto __ret = std::__set_symmetric_difference<_RangeAlgPolicy>(
87 auto __ret = std::__set_symmetric_difference(
9188 ranges::begin(__range1),
9289 ranges::end(__range1),
9390 ranges::begin(__range2),
......@@ -98,10 +95,8 @@ struct __fn {
9895 }
9996};
10097
101} // namespace __set_symmetric_difference
102
10398inline namespace __cpo {
104inline constexpr auto set_symmetric_difference = __set_symmetric_difference::__fn{};
99inline constexpr auto set_symmetric_difference = __set_symmetric_difference{};
105100} // namespace __cpo
106101} // namespace ranges
107102
lib/libcxx/include/__algorithm/ranges_set_union.h+4-9
......@@ -10,7 +10,6 @@
1010#define _LIBCPP___ALGORITHM_RANGES_SET_UNION_H
1111
1212#include <__algorithm/in_in_out_result.h>
13#include <__algorithm/iterator_operations.h>
1413#include <__algorithm/make_projected.h>
1514#include <__algorithm/set_union.h>
1615#include <__config>
......@@ -43,9 +42,7 @@ namespace ranges {
4342template <class _InIter1, class _InIter2, class _OutIter>
4443using set_union_result = in_in_out_result<_InIter1, _InIter2, _OutIter>;
4544
46namespace __set_union {
47
48struct __fn {
45struct __set_union {
4946 template <input_iterator _InIter1,
5047 sentinel_for<_InIter1> _Sent1,
5148 input_iterator _InIter2,
......@@ -64,7 +61,7 @@ struct __fn {
6461 _Comp __comp = {},
6562 _Proj1 __proj1 = {},
6663 _Proj2 __proj2 = {}) const {
67 auto __ret = std::__set_union<_RangeAlgPolicy>(
64 auto __ret = std::__set_union(
6865 std::move(__first1),
6966 std::move(__last1),
7067 std::move(__first2),
......@@ -88,7 +85,7 @@ struct __fn {
8885 _Comp __comp = {},
8986 _Proj1 __proj1 = {},
9087 _Proj2 __proj2 = {}) const {
91 auto __ret = std::__set_union<_RangeAlgPolicy>(
88 auto __ret = std::__set_union(
9289 ranges::begin(__range1),
9390 ranges::end(__range1),
9491 ranges::begin(__range2),
......@@ -99,10 +96,8 @@ struct __fn {
9996 }
10097};
10198
102} // namespace __set_union
103
10499inline namespace __cpo {
105inline constexpr auto set_union = __set_union::__fn{};
100inline constexpr auto set_union = __set_union{};
106101} // namespace __cpo
107102} // namespace ranges
108103
lib/libcxx/include/__algorithm/ranges_shuffle.h+2-6
......@@ -39,9 +39,7 @@ _LIBCPP_PUSH_MACROS
3939_LIBCPP_BEGIN_NAMESPACE_STD
4040
4141namespace ranges {
42namespace __shuffle {
43
44struct __fn {
42struct __shuffle {
4543 template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Gen>
4644 requires permutable<_Iter> && uniform_random_bit_generator<remove_reference_t<_Gen>>
4745 _LIBCPP_HIDE_FROM_ABI _Iter operator()(_Iter __first, _Sent __last, _Gen&& __gen) const {
......@@ -56,10 +54,8 @@ struct __fn {
5654 }
5755};
5856
59} // namespace __shuffle
60
6157inline namespace __cpo {
62inline constexpr auto shuffle = __shuffle::__fn{};
58inline constexpr auto shuffle = __shuffle{};
6359} // namespace __cpo
6460} // namespace ranges
6561
lib/libcxx/include/__algorithm/ranges_sort.h+2-6
......@@ -39,9 +39,7 @@ _LIBCPP_PUSH_MACROS
3939_LIBCPP_BEGIN_NAMESPACE_STD
4040
4141namespace ranges {
42namespace __sort {
43
44struct __fn {
42struct __sort {
4543 template <class _Iter, class _Sent, class _Comp, class _Proj>
4644 _LIBCPP_HIDE_FROM_ABI constexpr static _Iter
4745 __sort_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
......@@ -68,10 +66,8 @@ struct __fn {
6866 }
6967};
7068
71} // namespace __sort
72
7369inline namespace __cpo {
74inline constexpr auto sort = __sort::__fn{};
70inline constexpr auto sort = __sort{};
7571} // namespace __cpo
7672} // namespace ranges
7773
lib/libcxx/include/__algorithm/ranges_sort_heap.h+2-6
......@@ -40,9 +40,7 @@ _LIBCPP_PUSH_MACROS
4040_LIBCPP_BEGIN_NAMESPACE_STD
4141
4242namespace ranges {
43namespace __sort_heap {
44
45struct __fn {
43struct __sort_heap {
4644 template <class _Iter, class _Sent, class _Comp, class _Proj>
4745 _LIBCPP_HIDE_FROM_ABI constexpr static _Iter
4846 __sort_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
......@@ -69,10 +67,8 @@ struct __fn {
6967 }
7068};
7169
72} // namespace __sort_heap
73
7470inline namespace __cpo {
75inline constexpr auto sort_heap = __sort_heap::__fn{};
71inline constexpr auto sort_heap = __sort_heap{};
7672} // namespace __cpo
7773} // namespace ranges
7874
lib/libcxx/include/__algorithm/ranges_stable_partition.h+2-6
......@@ -42,9 +42,7 @@ _LIBCPP_PUSH_MACROS
4242_LIBCPP_BEGIN_NAMESPACE_STD
4343
4444namespace ranges {
45namespace __stable_partition {
46
47struct __fn {
45struct __stable_partition {
4846 template <class _Iter, class _Sent, class _Proj, class _Pred>
4947 _LIBCPP_HIDE_FROM_ABI static subrange<__remove_cvref_t<_Iter>>
5048 __stable_partition_fn_impl(_Iter&& __first, _Sent&& __last, _Pred&& __pred, _Proj&& __proj) {
......@@ -76,10 +74,8 @@ struct __fn {
7674 }
7775};
7876
79} // namespace __stable_partition
80
8177inline namespace __cpo {
82inline constexpr auto stable_partition = __stable_partition::__fn{};
78inline constexpr auto stable_partition = __stable_partition{};
8379} // namespace __cpo
8480} // namespace ranges
8581
lib/libcxx/include/__algorithm/ranges_stable_sort.h+2-6
......@@ -39,9 +39,7 @@ _LIBCPP_PUSH_MACROS
3939_LIBCPP_BEGIN_NAMESPACE_STD
4040
4141namespace ranges {
42namespace __stable_sort {
43
44struct __fn {
42struct __stable_sort {
4543 template <class _Iter, class _Sent, class _Comp, class _Proj>
4644 _LIBCPP_HIDE_FROM_ABI static _Iter __stable_sort_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
4745 auto __last_iter = ranges::next(__first, __last);
......@@ -66,10 +64,8 @@ struct __fn {
6664 }
6765};
6866
69} // namespace __stable_sort
70
7167inline namespace __cpo {
72inline constexpr auto stable_sort = __stable_sort::__fn{};
68inline constexpr auto stable_sort = __stable_sort{};
7369} // namespace __cpo
7470} // namespace ranges
7571
lib/libcxx/include/__algorithm/ranges_starts_with.h+4-6
......@@ -32,8 +32,7 @@ _LIBCPP_PUSH_MACROS
3232_LIBCPP_BEGIN_NAMESPACE_STD
3333
3434namespace ranges {
35namespace __starts_with {
36struct __fn {
35struct __starts_with {
3736 template <input_iterator _Iter1,
3837 sentinel_for<_Iter1> _Sent1,
3938 input_iterator _Iter2,
......@@ -50,7 +49,7 @@ struct __fn {
5049 _Pred __pred = {},
5150 _Proj1 __proj1 = {},
5251 _Proj2 __proj2 = {}) {
53 return __mismatch::__fn::__go(
52 return __mismatch::__go(
5453 std::move(__first1),
5554 std::move(__last1),
5655 std::move(__first2),
......@@ -69,7 +68,7 @@ struct __fn {
6968 requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>, _Pred, _Proj1, _Proj2>
7069 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr bool
7170 operator()(_Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) {
72 return __mismatch::__fn::__go(
71 return __mismatch::__go(
7372 ranges::begin(__range1),
7473 ranges::end(__range1),
7574 ranges::begin(__range2),
......@@ -80,9 +79,8 @@ struct __fn {
8079 .in2 == ranges::end(__range2);
8180 }
8281};
83} // namespace __starts_with
8482inline namespace __cpo {
85inline constexpr auto starts_with = __starts_with::__fn{};
83inline constexpr auto starts_with = __starts_with{};
8684} // namespace __cpo
8785} // namespace ranges
8886
lib/libcxx/include/__algorithm/ranges_swap_ranges.h+2-4
......@@ -36,8 +36,7 @@ namespace ranges {
3636template <class _I1, class _I2>
3737using swap_ranges_result = in_in_result<_I1, _I2>;
3838
39namespace __swap_ranges {
40struct __fn {
39struct __swap_ranges {
4140 template <input_iterator _I1, sentinel_for<_I1> _S1, input_iterator _I2, sentinel_for<_I2> _S2>
4241 requires indirectly_swappable<_I1, _I2>
4342 _LIBCPP_HIDE_FROM_ABI constexpr swap_ranges_result<_I1, _I2>
......@@ -54,10 +53,9 @@ struct __fn {
5453 return operator()(ranges::begin(__r1), ranges::end(__r1), ranges::begin(__r2), ranges::end(__r2));
5554 }
5655};
57} // namespace __swap_ranges
5856
5957inline namespace __cpo {
60inline constexpr auto swap_ranges = __swap_ranges::__fn{};
58inline constexpr auto swap_ranges = __swap_ranges{};
6159} // namespace __cpo
6260} // namespace ranges
6361
lib/libcxx/include/__algorithm/ranges_transform.h+2-4
......@@ -41,8 +41,7 @@ using unary_transform_result = in_out_result<_Ip, _Op>;
4141template <class _I1, class _I2, class _O1>
4242using binary_transform_result = in_in_out_result<_I1, _I2, _O1>;
4343
44namespace __transform {
45struct __fn {
44struct __transform {
4645private:
4746 template <class _InIter, class _Sent, class _OutIter, class _Func, class _Proj>
4847 _LIBCPP_HIDE_FROM_ABI static constexpr unary_transform_result<_InIter, _OutIter>
......@@ -161,10 +160,9 @@ public:
161160 __projection2);
162161 }
163162};
164} // namespace __transform
165163
166164inline namespace __cpo {
167inline constexpr auto transform = __transform::__fn{};
165inline constexpr auto transform = __transform{};
168166} // namespace __cpo
169167} // namespace ranges
170168
lib/libcxx/include/__algorithm/ranges_unique.h+2-6
......@@ -40,9 +40,7 @@ _LIBCPP_PUSH_MACROS
4040_LIBCPP_BEGIN_NAMESPACE_STD
4141
4242namespace ranges {
43namespace __unique {
44
45struct __fn {
43struct __unique {
4644 template <permutable _Iter,
4745 sentinel_for<_Iter> _Sent,
4846 class _Proj = identity,
......@@ -66,10 +64,8 @@ struct __fn {
6664 }
6765};
6866
69} // namespace __unique
70
7167inline namespace __cpo {
72inline constexpr auto unique = __unique::__fn{};
68inline constexpr auto unique = __unique{};
7369} // namespace __cpo
7470} // namespace ranges
7571
lib/libcxx/include/__algorithm/ranges_unique_copy.h+3-7
......@@ -44,12 +44,10 @@ namespace ranges {
4444template <class _InIter, class _OutIter>
4545using unique_copy_result = in_out_result<_InIter, _OutIter>;
4646
47namespace __unique_copy {
48
4947template <class _InIter, class _OutIter>
5048concept __can_reread_from_output = (input_iterator<_OutIter> && same_as<iter_value_t<_InIter>, iter_value_t<_OutIter>>);
5149
52struct __fn {
50struct __unique_copy {
5351 template <class _InIter, class _OutIter>
5452 static consteval auto __get_algo_tag() {
5553 if constexpr (forward_iterator<_InIter>) {
......@@ -62,7 +60,7 @@ struct __fn {
6260 }
6361
6462 template <class _InIter, class _OutIter>
65 using __algo_tag_t = decltype(__get_algo_tag<_InIter, _OutIter>());
63 using __algo_tag_t _LIBCPP_NODEBUG = decltype(__get_algo_tag<_InIter, _OutIter>());
6664
6765 template <input_iterator _InIter,
6866 sentinel_for<_InIter> _Sent,
......@@ -104,10 +102,8 @@ struct __fn {
104102 }
105103};
106104
107} // namespace __unique_copy
108
109105inline namespace __cpo {
110inline constexpr auto unique_copy = __unique_copy::__fn{};
106inline constexpr auto unique_copy = __unique_copy{};
111107} // namespace __cpo
112108} // namespace ranges
113109
lib/libcxx/include/__algorithm/ranges_upper_bound.h+2-4
......@@ -30,8 +30,7 @@
3030_LIBCPP_BEGIN_NAMESPACE_STD
3131
3232namespace ranges {
33namespace __upper_bound {
34struct __fn {
33struct __upper_bound {
3534 template <forward_iterator _Iter,
3635 sentinel_for<_Iter> _Sent,
3736 class _Type,
......@@ -60,10 +59,9 @@ struct __fn {
6059 ranges::begin(__r), ranges::end(__r), __value, __comp_lhs_rhs_swapped, __proj);
6160 }
6261};
63} // namespace __upper_bound
6462
6563inline namespace __cpo {
66inline constexpr auto upper_bound = __upper_bound::__fn{};
64inline constexpr auto upper_bound = __upper_bound{};
6765} // namespace __cpo
6866} // namespace ranges
6967
lib/libcxx/include/__algorithm/remove.h+1-1
......@@ -24,7 +24,7 @@ _LIBCPP_PUSH_MACROS
2424_LIBCPP_BEGIN_NAMESPACE_STD
2525
2626template <class _ForwardIterator, class _Tp>
27_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
27[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
2828remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
2929 __first = std::find(__first, __last, __value);
3030 if (__first != __last) {
lib/libcxx/include/__algorithm/remove_if.h+1-1
......@@ -23,7 +23,7 @@ _LIBCPP_PUSH_MACROS
2323_LIBCPP_BEGIN_NAMESPACE_STD
2424
2525template <class _ForwardIterator, class _Predicate>
26_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
26[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
2727remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
2828 __first = std::find_if<_ForwardIterator, _Predicate&>(__first, __last, __pred);
2929 if (__first != __last) {
lib/libcxx/include/__algorithm/search.h+5-5
......@@ -14,11 +14,11 @@
1414#include <__algorithm/iterator_operations.h>
1515#include <__config>
1616#include <__functional/identity.h>
17#include <__functional/invoke.h>
1817#include <__iterator/advance.h>
1918#include <__iterator/concepts.h>
2019#include <__iterator/iterator_traits.h>
2120#include <__type_traits/enable_if.h>
21#include <__type_traits/invoke.h>
2222#include <__type_traits/is_callable.h>
2323#include <__utility/pair.h>
2424
......@@ -160,20 +160,20 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __searc
160160}
161161
162162template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
163_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1
163[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1
164164search(_ForwardIterator1 __first1,
165165 _ForwardIterator1 __last1,
166166 _ForwardIterator2 __first2,
167167 _ForwardIterator2 __last2,
168168 _BinaryPredicate __pred) {
169 static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value,
170 "BinaryPredicate has to be callable");
169 static_assert(__is_callable<_BinaryPredicate&, decltype(*__first1), decltype(*__first2)>::value,
170 "The comparator has to be callable");
171171 auto __proj = __identity();
172172 return std::__search_impl(__first1, __last1, __first2, __last2, __pred, __proj, __proj).first;
173173}
174174
175175template <class _ForwardIterator1, class _ForwardIterator2>
176_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1
176[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1
177177search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) {
178178 return std::search(__first1, __last1, __first2, __last2, __equal_to());
179179}
lib/libcxx/include/__algorithm/search_n.h+5-4
......@@ -14,12 +14,13 @@
1414#include <__algorithm/iterator_operations.h>
1515#include <__config>
1616#include <__functional/identity.h>
17#include <__functional/invoke.h>
1817#include <__iterator/advance.h>
1918#include <__iterator/concepts.h>
2019#include <__iterator/distance.h>
2120#include <__iterator/iterator_traits.h>
2221#include <__ranges/concepts.h>
22#include <__type_traits/enable_if.h>
23#include <__type_traits/invoke.h>
2324#include <__type_traits/is_callable.h>
2425#include <__utility/convert_to_integral.h>
2526#include <__utility/pair.h>
......@@ -136,16 +137,16 @@ __search_n_impl(_Iter1 __first, _Sent1 __last, _DiffT __count, const _Type& __va
136137}
137138
138139template <class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
139_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator search_n(
140[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator search_n(
140141 _ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value, _BinaryPredicate __pred) {
141142 static_assert(
142 __is_callable<_BinaryPredicate, decltype(*__first), const _Tp&>::value, "BinaryPredicate has to be callable");
143 __is_callable<_BinaryPredicate&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
143144 auto __proj = __identity();
144145 return std::__search_n_impl(__first, __last, std::__convert_to_integral(__count), __value, __pred, __proj).first;
145146}
146147
147148template <class _ForwardIterator, class _Size, class _Tp>
148_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
149[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
149150search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value) {
150151 return std::search_n(__first, __last, std::__convert_to_integral(__count), __value, __equal_to());
151152}
lib/libcxx/include/__algorithm/set_difference.h+4-7
......@@ -12,10 +12,8 @@
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
1414#include <__algorithm/copy.h>
15#include <__algorithm/iterator_operations.h>
1615#include <__config>
1716#include <__functional/identity.h>
18#include <__functional/invoke.h>
1917#include <__iterator/iterator_traits.h>
2018#include <__type_traits/remove_cvref.h>
2119#include <__utility/move.h>
......@@ -30,7 +28,7 @@ _LIBCPP_PUSH_MACROS
3028
3129_LIBCPP_BEGIN_NAMESPACE_STD
3230
33template <class _AlgPolicy, class _Comp, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
31template <class _Comp, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
3432_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__remove_cvref_t<_InIter1>, __remove_cvref_t<_OutIter> >
3533__set_difference(
3634 _InIter1&& __first1, _Sent1&& __last1, _InIter2&& __first2, _Sent2&& __last2, _OutIter&& __result, _Comp&& __comp) {
......@@ -46,7 +44,7 @@ __set_difference(
4644 ++__first2;
4745 }
4846 }
49 return std::__copy<_AlgPolicy>(std::move(__first1), std::move(__last1), std::move(__result));
47 return std::__copy(std::move(__first1), std::move(__last1), std::move(__result));
5048}
5149
5250template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
......@@ -57,8 +55,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_d
5755 _InputIterator2 __last2,
5856 _OutputIterator __result,
5957 _Compare __comp) {
60 return std::__set_difference<_ClassicAlgPolicy, __comp_ref_type<_Compare> >(
61 __first1, __last1, __first2, __last2, __result, __comp)
58 return std::__set_difference<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __result, __comp)
6259 .second;
6360}
6461
......@@ -69,7 +66,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_d
6966 _InputIterator2 __first2,
7067 _InputIterator2 __last2,
7168 _OutputIterator __result) {
72 return std::__set_difference<_ClassicAlgPolicy>(__first1, __last1, __first2, __last2, __result, __less<>()).second;
69 return std::__set_difference(__first1, __last1, __first2, __last2, __result, __less<>()).second;
7370}
7471
7572_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/set_intersection.h+4-3
......@@ -19,6 +19,7 @@
1919#include <__iterator/next.h>
2020#include <__type_traits/is_same.h>
2121#include <__utility/exchange.h>
22#include <__utility/forward.h>
2223#include <__utility/move.h>
2324#include <__utility/swap.h>
2425
......@@ -84,7 +85,7 @@ template <class _AlgPolicy,
8485 class _InForwardIter2,
8586 class _Sent2,
8687 class _OutIter>
87_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI
88[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI
8889_LIBCPP_CONSTEXPR_SINCE_CXX20 __set_intersection_result<_InForwardIter1, _InForwardIter2, _OutIter>
8990__set_intersection(
9091 _InForwardIter1 __first1,
......@@ -129,7 +130,7 @@ template <class _AlgPolicy,
129130 class _InInputIter2,
130131 class _Sent2,
131132 class _OutIter>
132_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI
133[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI
133134_LIBCPP_CONSTEXPR_SINCE_CXX20 __set_intersection_result<_InInputIter1, _InInputIter2, _OutIter>
134135__set_intersection(
135136 _InInputIter1 __first1,
......@@ -160,7 +161,7 @@ __set_intersection(
160161}
161162
162163template <class _AlgPolicy, class _Compare, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
163_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI
164[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI
164165_LIBCPP_CONSTEXPR_SINCE_CXX20 __set_intersection_result<_InIter1, _InIter2, _OutIter>
165166__set_intersection(
166167 _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) {
lib/libcxx/include/__algorithm/set_symmetric_difference.h+4-5
......@@ -12,7 +12,6 @@
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
1414#include <__algorithm/copy.h>
15#include <__algorithm/iterator_operations.h>
1615#include <__config>
1716#include <__iterator/iterator_traits.h>
1817#include <__utility/move.h>
......@@ -39,13 +38,13 @@ struct __set_symmetric_difference_result {
3938 : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {}
4039};
4140
42template <class _AlgPolicy, class _Compare, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
41template <class _Compare, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
4342_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>
4443__set_symmetric_difference(
4544 _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) {
4645 while (__first1 != __last1) {
4746 if (__first2 == __last2) {
48 auto __ret1 = std::__copy<_AlgPolicy>(std::move(__first1), std::move(__last1), std::move(__result));
47 auto __ret1 = std::__copy(std::move(__first1), std::move(__last1), std::move(__result));
4948 return __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>(
5049 std::move(__ret1.first), std::move(__first2), std::move((__ret1.second)));
5150 }
......@@ -63,7 +62,7 @@ __set_symmetric_difference(
6362 ++__first2;
6463 }
6564 }
66 auto __ret2 = std::__copy<_AlgPolicy>(std::move(__first2), std::move(__last2), std::move(__result));
65 auto __ret2 = std::__copy(std::move(__first2), std::move(__last2), std::move(__result));
6766 return __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>(
6867 std::move(__first1), std::move(__ret2.first), std::move((__ret2.second)));
6968}
......@@ -76,7 +75,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_symmetri
7675 _InputIterator2 __last2,
7776 _OutputIterator __result,
7877 _Compare __comp) {
79 return std::__set_symmetric_difference<_ClassicAlgPolicy, __comp_ref_type<_Compare> >(
78 return std::__set_symmetric_difference<__comp_ref_type<_Compare> >(
8079 std::move(__first1),
8180 std::move(__last1),
8281 std::move(__first2),
lib/libcxx/include/__algorithm/set_union.h+4-5
......@@ -12,7 +12,6 @@
1212#include <__algorithm/comp.h>
1313#include <__algorithm/comp_ref_type.h>
1414#include <__algorithm/copy.h>
15#include <__algorithm/iterator_operations.h>
1615#include <__config>
1716#include <__iterator/iterator_traits.h>
1817#include <__utility/move.h>
......@@ -39,12 +38,12 @@ struct __set_union_result {
3938 : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {}
4039};
4140
42template <class _AlgPolicy, class _Compare, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
41template <class _Compare, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
4342_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_union_result<_InIter1, _InIter2, _OutIter> __set_union(
4443 _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) {
4544 for (; __first1 != __last1; ++__result) {
4645 if (__first2 == __last2) {
47 auto __ret1 = std::__copy<_AlgPolicy>(std::move(__first1), std::move(__last1), std::move(__result));
46 auto __ret1 = std::__copy(std::move(__first1), std::move(__last1), std::move(__result));
4847 return __set_union_result<_InIter1, _InIter2, _OutIter>(
4948 std::move(__ret1.first), std::move(__first2), std::move((__ret1.second)));
5049 }
......@@ -59,7 +58,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_union_result<_InIter1,
5958 ++__first1;
6059 }
6160 }
62 auto __ret2 = std::__copy<_AlgPolicy>(std::move(__first2), std::move(__last2), std::move(__result));
61 auto __ret2 = std::__copy(std::move(__first2), std::move(__last2), std::move(__result));
6362 return __set_union_result<_InIter1, _InIter2, _OutIter>(
6463 std::move(__first1), std::move(__ret2.first), std::move((__ret2.second)));
6564}
......@@ -72,7 +71,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_union(
7271 _InputIterator2 __last2,
7372 _OutputIterator __result,
7473 _Compare __comp) {
75 return std::__set_union<_ClassicAlgPolicy, __comp_ref_type<_Compare> >(
74 return std::__set_union<__comp_ref_type<_Compare> >(
7675 std::move(__first1),
7776 std::move(__last1),
7877 std::move(__first2),
lib/libcxx/include/__algorithm/shuffle.h+1-1
......@@ -11,12 +11,12 @@
1111
1212#include <__algorithm/iterator_operations.h>
1313#include <__config>
14#include <__cstddef/ptrdiff_t.h>
1415#include <__iterator/iterator_traits.h>
1516#include <__random/uniform_int_distribution.h>
1617#include <__utility/forward.h>
1718#include <__utility/move.h>
1819#include <__utility/swap.h>
19#include <cstddef>
2020#include <cstdint>
2121
2222#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__algorithm/simd_utils.h+8-8
......@@ -14,10 +14,10 @@
1414#include <__bit/countl.h>
1515#include <__bit/countr.h>
1616#include <__config>
17#include <__cstddef/size_t.h>
1718#include <__type_traits/is_arithmetic.h>
1819#include <__type_traits/is_same.h>
1920#include <__utility/integer_sequence.h>
20#include <cstddef>
2121#include <cstdint>
2222
2323#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -70,7 +70,7 @@ struct __get_as_integer_type_impl<8> {
7070};
7171
7272template <class _Tp>
73using __get_as_integer_type_t = typename __get_as_integer_type_impl<sizeof(_Tp)>::type;
73using __get_as_integer_type_t _LIBCPP_NODEBUG = typename __get_as_integer_type_impl<sizeof(_Tp)>::type;
7474
7575// This isn't specialized for 64 byte vectors on purpose. They have the potential to significantly reduce performance
7676// 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;
9090# endif
9191
9292template <class _ArithmeticT, size_t _Np>
93using __simd_vector __attribute__((__ext_vector_type__(_Np))) = _ArithmeticT;
93using __simd_vector __attribute__((__ext_vector_type__(_Np))) _LIBCPP_NODEBUG = _ArithmeticT;
9494
9595template <class _VecT>
9696inline constexpr size_t __simd_vector_size_v = []<bool _False = false>() -> size_t {
......@@ -106,23 +106,23 @@ _LIBCPP_HIDE_FROM_ABI _Tp __simd_vector_underlying_type_impl(__simd_vector<_Tp,
106106}
107107
108108template <class _VecT>
109using __simd_vector_underlying_type_t = decltype(std::__simd_vector_underlying_type_impl(_VecT{}));
109using __simd_vector_underlying_type_t _LIBCPP_NODEBUG = decltype(std::__simd_vector_underlying_type_impl(_VecT{}));
110110
111111// This isn't inlined without always_inline when loading chars.
112112template <class _VecT, class _Iter>
113_LIBCPP_NODISCARD _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _VecT __load_vector(_Iter __iter) noexcept {
113[[__nodiscard__]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _VecT __load_vector(_Iter __iter) noexcept {
114114 return [=]<size_t... _Indices>(index_sequence<_Indices...>) _LIBCPP_ALWAYS_INLINE noexcept {
115115 return _VecT{__iter[_Indices]...};
116116 }(make_index_sequence<__simd_vector_size_v<_VecT>>{});
117117}
118118
119119template <class _Tp, size_t _Np>
120_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool __all_of(__simd_vector<_Tp, _Np> __vec) noexcept {
120[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool __all_of(__simd_vector<_Tp, _Np> __vec) noexcept {
121121 return __builtin_reduce_and(__builtin_convertvector(__vec, __simd_vector<bool, _Np>));
122122}
123123
124124template <class _Tp, size_t _Np>
125_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI size_t __find_first_set(__simd_vector<_Tp, _Np> __vec) noexcept {
125[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t __find_first_set(__simd_vector<_Tp, _Np> __vec) noexcept {
126126 using __mask_vec = __simd_vector<bool, _Np>;
127127
128128 // 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
151151}
152152
153153template <class _Tp, size_t _Np>
154_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI size_t __find_first_not_set(__simd_vector<_Tp, _Np> __vec) noexcept {
154[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t __find_first_not_set(__simd_vector<_Tp, _Np> __vec) noexcept {
155155 return std::__find_first_set(~__vec);
156156}
157157
lib/libcxx/include/__algorithm/sort.h+128-170
......@@ -27,9 +27,14 @@
2727#include <__functional/ranges_operations.h>
2828#include <__iterator/iterator_traits.h>
2929#include <__type_traits/conditional.h>
30#include <__type_traits/desugars_to.h>
3031#include <__type_traits/disjunction.h>
32#include <__type_traits/enable_if.h>
3133#include <__type_traits/is_arithmetic.h>
3234#include <__type_traits/is_constant_evaluated.h>
35#include <__type_traits/is_same.h>
36#include <__type_traits/is_trivially_copyable.h>
37#include <__type_traits/remove_cvref.h>
3338#include <__utility/move.h>
3439#include <__utility/pair.h>
3540#include <climits>
......@@ -44,110 +49,11 @@ _LIBCPP_PUSH_MACROS
4449
4550_LIBCPP_BEGIN_NAMESPACE_STD
4651
47// stable, 2-3 compares, 0-2 swaps
48
49template <class _AlgPolicy, class _Compare, class _ForwardIterator>
50_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 unsigned
51__sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z, _Compare __c) {
52 using _Ops = _IterOps<_AlgPolicy>;
53
54 unsigned __r = 0;
55 if (!__c(*__y, *__x)) // if x <= y
56 {
57 if (!__c(*__z, *__y)) // if y <= z
58 return __r; // x <= y && y <= z
59 // x <= y && y > z
60 _Ops::iter_swap(__y, __z); // x <= z && y < z
61 __r = 1;
62 if (__c(*__y, *__x)) // if x > y
63 {
64 _Ops::iter_swap(__x, __y); // x < y && y <= z
65 __r = 2;
66 }
67 return __r; // x <= y && y < z
68 }
69 if (__c(*__z, *__y)) // x > y, if y > z
70 {
71 _Ops::iter_swap(__x, __z); // x < y && y < z
72 __r = 1;
73 return __r;
74 }
75 _Ops::iter_swap(__x, __y); // x > y && y <= z
76 __r = 1; // x < y && x <= z
77 if (__c(*__z, *__y)) // if y > z
78 {
79 _Ops::iter_swap(__y, __z); // x <= y && y < z
80 __r = 2;
81 }
82 return __r;
83} // x <= y && y <= z
84
85// stable, 3-6 compares, 0-5 swaps
86
87template <class _AlgPolicy, class _Compare, class _ForwardIterator>
88_LIBCPP_HIDE_FROM_ABI void
89__sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, _ForwardIterator __x4, _Compare __c) {
90 using _Ops = _IterOps<_AlgPolicy>;
91 std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c);
92 if (__c(*__x4, *__x3)) {
93 _Ops::iter_swap(__x3, __x4);
94 if (__c(*__x3, *__x2)) {
95 _Ops::iter_swap(__x2, __x3);
96 if (__c(*__x2, *__x1)) {
97 _Ops::iter_swap(__x1, __x2);
98 }
99 }
100 }
101}
102
103// stable, 4-10 compares, 0-9 swaps
104
105template <class _AlgPolicy, class _Comp, class _ForwardIterator>
106_LIBCPP_HIDE_FROM_ABI void
107__sort5(_ForwardIterator __x1,
108 _ForwardIterator __x2,
109 _ForwardIterator __x3,
110 _ForwardIterator __x4,
111 _ForwardIterator __x5,
112 _Comp __comp) {
113 using _Ops = _IterOps<_AlgPolicy>;
114
115 std::__sort4<_AlgPolicy, _Comp>(__x1, __x2, __x3, __x4, __comp);
116 if (__comp(*__x5, *__x4)) {
117 _Ops::iter_swap(__x4, __x5);
118 if (__comp(*__x4, *__x3)) {
119 _Ops::iter_swap(__x3, __x4);
120 if (__comp(*__x3, *__x2)) {
121 _Ops::iter_swap(__x2, __x3);
122 if (__comp(*__x2, *__x1)) {
123 _Ops::iter_swap(__x1, __x2);
124 }
125 }
126 }
127 }
128}
129
130// The comparator being simple is a prerequisite for using the branchless optimization.
131template <class _Tp>
132struct __is_simple_comparator : false_type {};
133template <>
134struct __is_simple_comparator<__less<>&> : true_type {};
135template <class _Tp>
136struct __is_simple_comparator<less<_Tp>&> : true_type {};
137template <class _Tp>
138struct __is_simple_comparator<greater<_Tp>&> : true_type {};
139#if _LIBCPP_STD_VER >= 20
140template <>
141struct __is_simple_comparator<ranges::less&> : true_type {};
142template <>
143struct __is_simple_comparator<ranges::greater&> : true_type {};
144#endif
145
14652template <class _Compare, class _Iter, class _Tp = typename iterator_traits<_Iter>::value_type>
147using __use_branchless_sort =
148 integral_constant<bool,
149 __libcpp_is_contiguous_iterator<_Iter>::value && sizeof(_Tp) <= sizeof(void*) &&
150 is_arithmetic<_Tp>::value && __is_simple_comparator<_Compare>::value>;
53inline const bool __use_branchless_sort =
54 __libcpp_is_contiguous_iterator<_Iter>::value && __is_cheap_to_copy<_Tp> && is_arithmetic<_Tp>::value &&
55 (__desugars_to_v<__less_tag, __remove_cvref_t<_Compare>, _Tp, _Tp> ||
56 __desugars_to_v<__greater_tag, __remove_cvref_t<_Compare>, _Tp, _Tp>);
15157
15258namespace __detail {
15359
......@@ -158,59 +64,88 @@ enum { __block_size = sizeof(uint64_t) * 8 };
15864
15965// Ensures that __c(*__x, *__y) is true by swapping *__x and *__y if necessary.
16066template <class _Compare, class _RandomAccessIterator>
161inline _LIBCPP_HIDE_FROM_ABI void __cond_swap(_RandomAccessIterator __x, _RandomAccessIterator __y, _Compare __c) {
67inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
68__cond_swap(_RandomAccessIterator __x, _RandomAccessIterator __y, _Compare __c) {
16269 // Note: this function behaves correctly even with proxy iterators (because it relies on `value_type`).
16370 using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
16471 bool __r = __c(*__x, *__y);
16572 value_type __tmp = __r ? *__x : *__y;
16673 *__y = __r ? *__y : *__x;
16774 *__x = __tmp;
75 return !__r;
16876}
16977
17078// Ensures that *__x, *__y and *__z are ordered according to the comparator __c,
17179// under the assumption that *__y and *__z are already ordered.
17280template <class _Compare, class _RandomAccessIterator>
173inline _LIBCPP_HIDE_FROM_ABI void
81inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
17482__partially_sorted_swap(_RandomAccessIterator __x, _RandomAccessIterator __y, _RandomAccessIterator __z, _Compare __c) {
17583 // Note: this function behaves correctly even with proxy iterators (because it relies on `value_type`).
17684 using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
177 bool __r = __c(*__z, *__x);
178 value_type __tmp = __r ? *__z : *__x;
179 *__z = __r ? *__x : *__z;
180 __r = __c(__tmp, *__y);
181 *__x = __r ? *__x : *__y;
182 *__y = __r ? *__y : __tmp;
85 bool __r1 = __c(*__z, *__x);
86 value_type __tmp = __r1 ? *__z : *__x;
87 *__z = __r1 ? *__x : *__z;
88 bool __r2 = __c(__tmp, *__y);
89 *__x = __r2 ? *__x : *__y;
90 *__y = __r2 ? *__y : __tmp;
91 return !__r1 || !__r2;
18392}
18493
94// stable, 2-3 compares, 0-2 swaps
95
18596template <class,
18697 class _Compare,
18798 class _RandomAccessIterator,
188 __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
189inline _LIBCPP_HIDE_FROM_ABI void __sort3_maybe_branchless(
190 _RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _Compare __c) {
191 std::__cond_swap<_Compare>(__x2, __x3, __c);
192 std::__partially_sorted_swap<_Compare>(__x1, __x2, __x3, __c);
99 __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>, int> = 0>
100inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
101__sort3(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _Compare __c) {
102 bool __swapped1 = std::__cond_swap<_Compare>(__x2, __x3, __c);
103 bool __swapped2 = std::__partially_sorted_swap<_Compare>(__x1, __x2, __x3, __c);
104 return __swapped1 || __swapped2;
193105}
194106
195107template <class _AlgPolicy,
196108 class _Compare,
197109 class _RandomAccessIterator,
198 __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
199inline _LIBCPP_HIDE_FROM_ABI void __sort3_maybe_branchless(
200 _RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _Compare __c) {
201 std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c);
202}
110 __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>, int> = 0>
111inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
112__sort3(_RandomAccessIterator __x, _RandomAccessIterator __y, _RandomAccessIterator __z, _Compare __c) {
113 using _Ops = _IterOps<_AlgPolicy>;
114
115 if (!__c(*__y, *__x)) // if x <= y
116 {
117 if (!__c(*__z, *__y)) // if y <= z
118 return false; // x <= y && y <= z
119 // x <= y && y > z
120 _Ops::iter_swap(__y, __z); // x <= z && y < z
121 if (__c(*__y, *__x)) // if x > y
122 _Ops::iter_swap(__x, __y); // x < y && y <= z
123 return true; // x <= y && y < z
124 }
125 if (__c(*__z, *__y)) // x > y, if y > z
126 {
127 _Ops::iter_swap(__x, __z); // x < y && y < z
128 return true;
129 }
130 _Ops::iter_swap(__x, __y); // x > y && y <= z
131 // x < y && x <= z
132 if (__c(*__z, *__y)) // if y > z
133 _Ops::iter_swap(__y, __z); // x <= y && y < z
134 return true;
135} // x <= y && y <= z
136
137// stable, 3-6 compares, 0-5 swaps
203138
204139template <class,
205140 class _Compare,
206141 class _RandomAccessIterator,
207 __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
208inline _LIBCPP_HIDE_FROM_ABI void __sort4_maybe_branchless(
209 _RandomAccessIterator __x1,
210 _RandomAccessIterator __x2,
211 _RandomAccessIterator __x3,
212 _RandomAccessIterator __x4,
213 _Compare __c) {
142 __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>, int> = 0>
143inline _LIBCPP_HIDE_FROM_ABI void
144__sort4(_RandomAccessIterator __x1,
145 _RandomAccessIterator __x2,
146 _RandomAccessIterator __x3,
147 _RandomAccessIterator __x4,
148 _Compare __c) {
214149 std::__cond_swap<_Compare>(__x1, __x3, __c);
215150 std::__cond_swap<_Compare>(__x2, __x4, __c);
216151 std::__cond_swap<_Compare>(__x1, __x2, __c);
......@@ -221,27 +156,39 @@ inline _LIBCPP_HIDE_FROM_ABI void __sort4_maybe_branchless(
221156template <class _AlgPolicy,
222157 class _Compare,
223158 class _RandomAccessIterator,
224 __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
225inline _LIBCPP_HIDE_FROM_ABI void __sort4_maybe_branchless(
226 _RandomAccessIterator __x1,
227 _RandomAccessIterator __x2,
228 _RandomAccessIterator __x3,
229 _RandomAccessIterator __x4,
230 _Compare __c) {
231 std::__sort4<_AlgPolicy, _Compare>(__x1, __x2, __x3, __x4, __c);
159 __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>, int> = 0>
160inline _LIBCPP_HIDE_FROM_ABI void
161__sort4(_RandomAccessIterator __x1,
162 _RandomAccessIterator __x2,
163 _RandomAccessIterator __x3,
164 _RandomAccessIterator __x4,
165 _Compare __c) {
166 using _Ops = _IterOps<_AlgPolicy>;
167 std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c);
168 if (__c(*__x4, *__x3)) {
169 _Ops::iter_swap(__x3, __x4);
170 if (__c(*__x3, *__x2)) {
171 _Ops::iter_swap(__x2, __x3);
172 if (__c(*__x2, *__x1)) {
173 _Ops::iter_swap(__x1, __x2);
174 }
175 }
176 }
232177}
233178
179// stable, 4-10 compares, 0-9 swaps
180
234181template <class _AlgPolicy,
235182 class _Compare,
236183 class _RandomAccessIterator,
237 __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
238inline _LIBCPP_HIDE_FROM_ABI void __sort5_maybe_branchless(
239 _RandomAccessIterator __x1,
240 _RandomAccessIterator __x2,
241 _RandomAccessIterator __x3,
242 _RandomAccessIterator __x4,
243 _RandomAccessIterator __x5,
244 _Compare __c) {
184 __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>, int> = 0>
185inline _LIBCPP_HIDE_FROM_ABI void
186__sort5(_RandomAccessIterator __x1,
187 _RandomAccessIterator __x2,
188 _RandomAccessIterator __x3,
189 _RandomAccessIterator __x4,
190 _RandomAccessIterator __x5,
191 _Compare __c) {
245192 std::__cond_swap<_Compare>(__x1, __x2, __c);
246193 std::__cond_swap<_Compare>(__x4, __x5, __c);
247194 std::__partially_sorted_swap<_Compare>(__x3, __x4, __x5, __c);
......@@ -253,16 +200,29 @@ inline _LIBCPP_HIDE_FROM_ABI void __sort5_maybe_branchless(
253200template <class _AlgPolicy,
254201 class _Compare,
255202 class _RandomAccessIterator,
256 __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>::value, int> = 0>
257inline _LIBCPP_HIDE_FROM_ABI void __sort5_maybe_branchless(
258 _RandomAccessIterator __x1,
259 _RandomAccessIterator __x2,
260 _RandomAccessIterator __x3,
261 _RandomAccessIterator __x4,
262 _RandomAccessIterator __x5,
263 _Compare __c) {
264 std::__sort5<_AlgPolicy, _Compare, _RandomAccessIterator>(
265 std::move(__x1), std::move(__x2), std::move(__x3), std::move(__x4), std::move(__x5), __c);
203 __enable_if_t<!__use_branchless_sort<_Compare, _RandomAccessIterator>, int> = 0>
204inline _LIBCPP_HIDE_FROM_ABI void
205__sort5(_RandomAccessIterator __x1,
206 _RandomAccessIterator __x2,
207 _RandomAccessIterator __x3,
208 _RandomAccessIterator __x4,
209 _RandomAccessIterator __x5,
210 _Compare __comp) {
211 using _Ops = _IterOps<_AlgPolicy>;
212
213 std::__sort4<_AlgPolicy, _Compare>(__x1, __x2, __x3, __x4, __comp);
214 if (__comp(*__x5, *__x4)) {
215 _Ops::iter_swap(__x4, __x5);
216 if (__comp(*__x4, *__x3)) {
217 _Ops::iter_swap(__x3, __x4);
218 if (__comp(*__x3, *__x2)) {
219 _Ops::iter_swap(__x2, __x3);
220 if (__comp(*__x2, *__x1)) {
221 _Ops::iter_swap(__x1, __x2);
222 }
223 }
224 }
225 }
266226}
267227
268228// Assumes size > 0
......@@ -280,7 +240,7 @@ __selection_sort(_BidirectionalIterator __first, _BidirectionalIterator __last,
280240// Sort the iterator range [__first, __last) using the comparator __comp using
281241// the insertion sort algorithm.
282242template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
283_LIBCPP_HIDE_FROM_ABI void
243_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
284244__insertion_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) {
285245 using _Ops = _IterOps<_AlgPolicy>;
286246
......@@ -352,14 +312,14 @@ __insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator
352312 _Ops::iter_swap(__first, __last);
353313 return true;
354314 case 3:
355 std::__sort3_maybe_branchless<_AlgPolicy, _Comp>(__first, __first + difference_type(1), --__last, __comp);
315 std::__sort3<_AlgPolicy, _Comp>(__first, __first + difference_type(1), --__last, __comp);
356316 return true;
357317 case 4:
358 std::__sort4_maybe_branchless<_AlgPolicy, _Comp>(
318 std::__sort4<_AlgPolicy, _Comp>(
359319 __first, __first + difference_type(1), __first + difference_type(2), --__last, __comp);
360320 return true;
361321 case 5:
362 std::__sort5_maybe_branchless<_AlgPolicy, _Comp>(
322 std::__sort5<_AlgPolicy, _Comp>(
363323 __first,
364324 __first + difference_type(1),
365325 __first + difference_type(2),
......@@ -370,7 +330,7 @@ __insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator
370330 }
371331 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
372332 _RandomAccessIterator __j = __first + difference_type(2);
373 std::__sort3_maybe_branchless<_AlgPolicy, _Comp>(__first, __first + difference_type(1), __j, __comp);
333 std::__sort3<_AlgPolicy, _Comp>(__first, __first + difference_type(1), __j, __comp);
374334 const unsigned __limit = 8;
375335 unsigned __count = 0;
376336 for (_RandomAccessIterator __i = __j + difference_type(1); __i != __last; ++__i) {
......@@ -777,14 +737,14 @@ void __introsort(_RandomAccessIterator __first,
777737 _Ops::iter_swap(__first, __last);
778738 return;
779739 case 3:
780 std::__sort3_maybe_branchless<_AlgPolicy, _Compare>(__first, __first + difference_type(1), --__last, __comp);
740 std::__sort3<_AlgPolicy, _Compare>(__first, __first + difference_type(1), --__last, __comp);
781741 return;
782742 case 4:
783 std::__sort4_maybe_branchless<_AlgPolicy, _Compare>(
743 std::__sort4<_AlgPolicy, _Compare>(
784744 __first, __first + difference_type(1), __first + difference_type(2), --__last, __comp);
785745 return;
786746 case 5:
787 std::__sort5_maybe_branchless<_AlgPolicy, _Compare>(
747 std::__sort5<_AlgPolicy, _Compare>(
788748 __first,
789749 __first + difference_type(1),
790750 __first + difference_type(2),
......@@ -891,7 +851,7 @@ template <class _Comp, class _RandomAccessIterator>
891851void __sort(_RandomAccessIterator, _RandomAccessIterator, _Comp);
892852
893853extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<char>&, char*>(char*, char*, __less<char>&);
894#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
854#if _LIBCPP_HAS_WIDE_CHARACTERS
895855extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
896856#endif
897857extern template _LIBCPP_EXPORTED_FROM_ABI void
......@@ -925,20 +885,18 @@ __sort_dispatch(_RandomAccessIterator __first, _RandomAccessIterator __last, _Co
925885 // Only use bitset partitioning for arithmetic types. We should also check
926886 // that the default comparator is in use so that we are sure that there are no
927887 // branches in the comparator.
928 std::__introsort<_AlgPolicy,
929 _Comp&,
930 _RandomAccessIterator,
931 __use_branchless_sort<_Comp, _RandomAccessIterator>::value>(__first, __last, __comp, __depth_limit);
888 std::__introsort<_AlgPolicy, _Comp&, _RandomAccessIterator, __use_branchless_sort<_Comp, _RandomAccessIterator> >(
889 __first, __last, __comp, __depth_limit);
932890}
933891
934892template <class _Type, class... _Options>
935using __is_any_of = _Or<is_same<_Type, _Options>...>;
893using __is_any_of _LIBCPP_NODEBUG = _Or<is_same<_Type, _Options>...>;
936894
937895template <class _Type>
938using __sort_is_specialized_in_library = __is_any_of<
896using __sort_is_specialized_in_library _LIBCPP_NODEBUG = __is_any_of<
939897 _Type,
940898 char,
941#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
899#if _LIBCPP_HAS_WIDE_CHARACTERS
942900 wchar_t,
943901#endif
944902 signed char,
lib/libcxx/include/__algorithm/stable_partition.h+11-14
......@@ -12,15 +12,16 @@
1212#include <__algorithm/iterator_operations.h>
1313#include <__algorithm/rotate.h>
1414#include <__config>
15#include <__cstddef/ptrdiff_t.h>
1516#include <__iterator/advance.h>
1617#include <__iterator/distance.h>
1718#include <__iterator/iterator_traits.h>
1819#include <__memory/destruct_n.h>
19#include <__memory/temporary_buffer.h>
2020#include <__memory/unique_ptr.h>
21#include <__memory/unique_temporary_buffer.h>
22#include <__type_traits/remove_cvref.h>
2123#include <__utility/move.h>
2224#include <__utility/pair.h>
23#include <new>
2425
2526#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2627# pragma GCC system_header
......@@ -132,14 +133,12 @@ __stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Pred
132133 // We now have a reduced range [__first, __last)
133134 // *__first is known to be false
134135 difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last);
136 __unique_temporary_buffer<value_type> __unique_buf;
135137 pair<value_type*, ptrdiff_t> __p(0, 0);
136 unique_ptr<value_type, __return_temporary_buffer> __h;
137138 if (__len >= __alloc_limit) {
138 // TODO: Remove the use of std::get_temporary_buffer
139 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
140 __p = std::get_temporary_buffer<value_type>(__len);
141 _LIBCPP_SUPPRESS_DEPRECATED_POP
142 __h.reset(__p.first);
139 __unique_buf = std::__allocate_unique_temporary_buffer<value_type>(__len);
140 __p.first = __unique_buf.get();
141 __p.second = __unique_buf.get_deleter().__count_;
143142 }
144143 return std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
145144 std::move(__first), std::move(__last), __pred, __len, __p, forward_iterator_tag());
......@@ -272,14 +271,12 @@ _LIBCPP_HIDE_FROM_ABI _BidirectionalIterator __stable_partition_impl(
272271 // *__last is known to be true
273272 // __len >= 2
274273 difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last) + 1;
274 __unique_temporary_buffer<value_type> __unique_buf;
275275 pair<value_type*, ptrdiff_t> __p(0, 0);
276 unique_ptr<value_type, __return_temporary_buffer> __h;
277276 if (__len >= __alloc_limit) {
278 // TODO: Remove the use of std::get_temporary_buffer
279 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
280 __p = std::get_temporary_buffer<value_type>(__len);
281 _LIBCPP_SUPPRESS_DEPRECATED_POP
282 __h.reset(__p.first);
277 __unique_buf = std::__allocate_unique_temporary_buffer<value_type>(__len);
278 __p.first = __unique_buf.get();
279 __p.second = __unique_buf.get_deleter().__count_;
283280 }
284281 return std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
285282 std::move(__first), std::move(__last), __pred, __len, __p, bidirectional_iterator_tag());
lib/libcxx/include/__algorithm/stable_sort.h+90-44
......@@ -13,17 +13,24 @@
1313#include <__algorithm/comp_ref_type.h>
1414#include <__algorithm/inplace_merge.h>
1515#include <__algorithm/iterator_operations.h>
16#include <__algorithm/radix_sort.h>
1617#include <__algorithm/sort.h>
1718#include <__config>
19#include <__cstddef/ptrdiff_t.h>
1820#include <__debug_utils/strict_weak_ordering_check.h>
1921#include <__iterator/iterator_traits.h>
22#include <__memory/construct_at.h>
2023#include <__memory/destruct_n.h>
21#include <__memory/temporary_buffer.h>
2224#include <__memory/unique_ptr.h>
25#include <__memory/unique_temporary_buffer.h>
26#include <__type_traits/desugars_to.h>
27#include <__type_traits/enable_if.h>
28#include <__type_traits/is_integral.h>
29#include <__type_traits/is_same.h>
2330#include <__type_traits/is_trivially_assignable.h>
31#include <__type_traits/remove_cvref.h>
2432#include <__utility/move.h>
2533#include <__utility/pair.h>
26#include <new>
2734
2835#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2936# pragma GCC system_header
......@@ -35,7 +42,7 @@ _LIBCPP_PUSH_MACROS
3542_LIBCPP_BEGIN_NAMESPACE_STD
3643
3744template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
38_LIBCPP_HIDE_FROM_ABI void __insertion_sort_move(
45_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __insertion_sort_move(
3946 _BidirectionalIterator __first1,
4047 _BidirectionalIterator __last1,
4148 typename iterator_traits<_BidirectionalIterator>::value_type* __first2,
......@@ -47,19 +54,19 @@ _LIBCPP_HIDE_FROM_ABI void __insertion_sort_move(
4754 __destruct_n __d(0);
4855 unique_ptr<value_type, __destruct_n&> __h(__first2, __d);
4956 value_type* __last2 = __first2;
50 ::new ((void*)__last2) value_type(_Ops::__iter_move(__first1));
57 std::__construct_at(__last2, _Ops::__iter_move(__first1));
5158 __d.template __incr<value_type>();
5259 for (++__last2; ++__first1 != __last1; ++__last2) {
5360 value_type* __j2 = __last2;
5461 value_type* __i2 = __j2;
5562 if (__comp(*__first1, *--__i2)) {
56 ::new ((void*)__j2) value_type(std::move(*__i2));
63 std::__construct_at(__j2, std::move(*__i2));
5764 __d.template __incr<value_type>();
5865 for (--__j2; __i2 != __first2 && __comp(*__first1, *--__i2); --__j2)
5966 *__j2 = std::move(*__i2);
6067 *__j2 = _Ops::__iter_move(__first1);
6168 } else {
62 ::new ((void*)__j2) value_type(_Ops::__iter_move(__first1));
69 std::__construct_at(__j2, _Ops::__iter_move(__first1));
6370 __d.template __incr<value_type>();
6471 }
6572 }
......@@ -68,7 +75,7 @@ _LIBCPP_HIDE_FROM_ABI void __insertion_sort_move(
6875}
6976
7077template <class _AlgPolicy, class _Compare, class _InputIterator1, class _InputIterator2>
71_LIBCPP_HIDE_FROM_ABI void __merge_move_construct(
78_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __merge_move_construct(
7279 _InputIterator1 __first1,
7380 _InputIterator1 __last1,
7481 _InputIterator2 __first2,
......@@ -83,22 +90,22 @@ _LIBCPP_HIDE_FROM_ABI void __merge_move_construct(
8390 for (; true; ++__result) {
8491 if (__first1 == __last1) {
8592 for (; __first2 != __last2; ++__first2, (void)++__result, __d.template __incr<value_type>())
86 ::new ((void*)__result) value_type(_Ops::__iter_move(__first2));
93 std::__construct_at(__result, _Ops::__iter_move(__first2));
8794 __h.release();
8895 return;
8996 }
9097 if (__first2 == __last2) {
9198 for (; __first1 != __last1; ++__first1, (void)++__result, __d.template __incr<value_type>())
92 ::new ((void*)__result) value_type(_Ops::__iter_move(__first1));
99 std::__construct_at(__result, _Ops::__iter_move(__first1));
93100 __h.release();
94101 return;
95102 }
96103 if (__comp(*__first2, *__first1)) {
97 ::new ((void*)__result) value_type(_Ops::__iter_move(__first2));
104 std::__construct_at(__result, _Ops::__iter_move(__first2));
98105 __d.template __incr<value_type>();
99106 ++__first2;
100107 } else {
101 ::new ((void*)__result) value_type(_Ops::__iter_move(__first1));
108 std::__construct_at(__result, _Ops::__iter_move(__first1));
102109 __d.template __incr<value_type>();
103110 ++__first1;
104111 }
......@@ -106,7 +113,7 @@ _LIBCPP_HIDE_FROM_ABI void __merge_move_construct(
106113}
107114
108115template <class _AlgPolicy, class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
109_LIBCPP_HIDE_FROM_ABI void __merge_move_assign(
116_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __merge_move_assign(
110117 _InputIterator1 __first1,
111118 _InputIterator1 __last1,
112119 _InputIterator2 __first2,
......@@ -134,19 +141,21 @@ _LIBCPP_HIDE_FROM_ABI void __merge_move_assign(
134141}
135142
136143template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
137void __stable_sort(_RandomAccessIterator __first,
138 _RandomAccessIterator __last,
139 _Compare __comp,
140 typename iterator_traits<_RandomAccessIterator>::difference_type __len,
141 typename iterator_traits<_RandomAccessIterator>::value_type* __buff,
142 ptrdiff_t __buff_size);
144_LIBCPP_CONSTEXPR_SINCE_CXX26 void __stable_sort(
145 _RandomAccessIterator __first,
146 _RandomAccessIterator __last,
147 _Compare __comp,
148 typename iterator_traits<_RandomAccessIterator>::difference_type __len,
149 typename iterator_traits<_RandomAccessIterator>::value_type* __buff,
150 ptrdiff_t __buff_size);
143151
144152template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
145void __stable_sort_move(_RandomAccessIterator __first1,
146 _RandomAccessIterator __last1,
147 _Compare __comp,
148 typename iterator_traits<_RandomAccessIterator>::difference_type __len,
149 typename iterator_traits<_RandomAccessIterator>::value_type* __first2) {
153_LIBCPP_CONSTEXPR_SINCE_CXX26 void __stable_sort_move(
154 _RandomAccessIterator __first1,
155 _RandomAccessIterator __last1,
156 _Compare __comp,
157 typename iterator_traits<_RandomAccessIterator>::difference_type __len,
158 typename iterator_traits<_RandomAccessIterator>::value_type* __first2) {
150159 using _Ops = _IterOps<_AlgPolicy>;
151160
152161 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
......@@ -154,21 +163,21 @@ void __stable_sort_move(_RandomAccessIterator __first1,
154163 case 0:
155164 return;
156165 case 1:
157 ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1));
166 std::__construct_at(__first2, _Ops::__iter_move(__first1));
158167 return;
159168 case 2:
160169 __destruct_n __d(0);
161170 unique_ptr<value_type, __destruct_n&> __h2(__first2, __d);
162171 if (__comp(*--__last1, *__first1)) {
163 ::new ((void*)__first2) value_type(_Ops::__iter_move(__last1));
172 std::__construct_at(__first2, _Ops::__iter_move(__last1));
164173 __d.template __incr<value_type>();
165174 ++__first2;
166 ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1));
175 std::__construct_at(__first2, _Ops::__iter_move(__first1));
167176 } else {
168 ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1));
177 std::__construct_at(__first2, _Ops::__iter_move(__first1));
169178 __d.template __incr<value_type>();
170179 ++__first2;
171 ::new ((void*)__first2) value_type(_Ops::__iter_move(__last1));
180 std::__construct_at(__first2, _Ops::__iter_move(__last1));
172181 }
173182 __h2.release();
174183 return;
......@@ -189,13 +198,36 @@ struct __stable_sort_switch {
189198 static const unsigned value = 128 * is_trivially_copy_assignable<_Tp>::value;
190199};
191200
201#if _LIBCPP_STD_VER >= 17
202template <class _Tp>
203_LIBCPP_HIDE_FROM_ABI constexpr unsigned __radix_sort_min_bound() {
204 static_assert(is_integral<_Tp>::value);
205 if constexpr (sizeof(_Tp) == 1) {
206 return 1 << 8;
207 }
208
209 return 1 << 10;
210}
211
212template <class _Tp>
213_LIBCPP_HIDE_FROM_ABI constexpr unsigned __radix_sort_max_bound() {
214 static_assert(is_integral<_Tp>::value);
215 if constexpr (sizeof(_Tp) >= 8) {
216 return 1 << 15;
217 }
218
219 return 1 << 16;
220}
221#endif // _LIBCPP_STD_VER >= 17
222
192223template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
193void __stable_sort(_RandomAccessIterator __first,
194 _RandomAccessIterator __last,
195 _Compare __comp,
196 typename iterator_traits<_RandomAccessIterator>::difference_type __len,
197 typename iterator_traits<_RandomAccessIterator>::value_type* __buff,
198 ptrdiff_t __buff_size) {
224_LIBCPP_CONSTEXPR_SINCE_CXX26 void __stable_sort(
225 _RandomAccessIterator __first,
226 _RandomAccessIterator __last,
227 _Compare __comp,
228 typename iterator_traits<_RandomAccessIterator>::difference_type __len,
229 typename iterator_traits<_RandomAccessIterator>::value_type* __buff,
230 ptrdiff_t __buff_size) {
199231 typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
200232 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
201233 switch (__len) {
......@@ -211,6 +243,22 @@ void __stable_sort(_RandomAccessIterator __first,
211243 std::__insertion_sort<_AlgPolicy, _Compare>(__first, __last, __comp);
212244 return;
213245 }
246
247#if _LIBCPP_STD_VER >= 17
248 constexpr auto __default_comp =
249 __desugars_to_v<__totally_ordered_less_tag, __remove_cvref_t<_Compare>, value_type, value_type >;
250 constexpr auto __integral_value =
251 is_integral_v<value_type > && is_same_v< value_type&, __iter_reference<_RandomAccessIterator>>;
252 constexpr auto __allowed_radix_sort = __default_comp && __integral_value;
253 if constexpr (__allowed_radix_sort) {
254 if (__len <= __buff_size && __len >= static_cast<difference_type>(__radix_sort_min_bound<value_type>()) &&
255 __len <= static_cast<difference_type>(__radix_sort_max_bound<value_type>())) {
256 std::__radix_sort(__first, __last, __buff);
257 return;
258 }
259 }
260#endif // _LIBCPP_STD_VER >= 17
261
214262 typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2;
215263 _RandomAccessIterator __m = __first + __l2;
216264 if (__len <= __buff_size) {
......@@ -235,20 +283,18 @@ void __stable_sort(_RandomAccessIterator __first,
235283}
236284
237285template <class _AlgPolicy, class _RandomAccessIterator, class _Compare>
238inline _LIBCPP_HIDE_FROM_ABI void
286_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
239287__stable_sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) {
240288 using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
241289 using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
242290
243291 difference_type __len = __last - __first;
292 __unique_temporary_buffer<value_type> __unique_buf;
244293 pair<value_type*, ptrdiff_t> __buf(0, 0);
245 unique_ptr<value_type, __return_temporary_buffer> __h;
246294 if (__len > static_cast<difference_type>(__stable_sort_switch<value_type>::value)) {
247 // TODO: Remove the use of std::get_temporary_buffer
248 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
249 __buf = std::get_temporary_buffer<value_type>(__len);
250 _LIBCPP_SUPPRESS_DEPRECATED_POP
251 __h.reset(__buf.first);
295 __unique_buf = std::__allocate_unique_temporary_buffer<value_type>(__len);
296 __buf.first = __unique_buf.get();
297 __buf.second = __unique_buf.get_deleter().__count_;
252298 }
253299
254300 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,
256302}
257303
258304template <class _RandomAccessIterator, class _Compare>
259inline _LIBCPP_HIDE_FROM_ABI void
305_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
260306stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
261307 std::__stable_sort_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp);
262308}
263309
264310template <class _RandomAccessIterator>
265inline _LIBCPP_HIDE_FROM_ABI void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) {
311_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
312stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) {
266313 std::stable_sort(__first, __last, __less<>());
267314}
268315
269316_LIBCPP_END_NAMESPACE_STD
270
271317_LIBCPP_POP_MACROS
272318
273319#endif // _LIBCPP___ALGORITHM_STABLE_SORT_H
lib/libcxx/include/__algorithm/three_way_comp_ref_type.h+2-2
......@@ -61,10 +61,10 @@ struct __debug_three_way_comp {
6161// Pass the comparator by lvalue reference. Or in the debug mode, using a debugging wrapper that stores a reference.
6262# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
6363template <class _Comp>
64using __three_way_comp_ref_type = __debug_three_way_comp<_Comp>;
64using __three_way_comp_ref_type _LIBCPP_NODEBUG = __debug_three_way_comp<_Comp>;
6565# else
6666template <class _Comp>
67using __three_way_comp_ref_type = _Comp&;
67using __three_way_comp_ref_type _LIBCPP_NODEBUG = _Comp&;
6868# endif
6969
7070#endif // _LIBCPP_STD_VER >= 20
lib/libcxx/include/__algorithm/uniform_random_bit_generator_adaptor.h+1-1
......@@ -10,7 +10,7 @@
1010#define _LIBCPP___ALGORITHM_RANGES_UNIFORM_RANDOM_BIT_GENERATOR_ADAPTOR_H
1111
1212#include <__config>
13#include <__functional/invoke.h>
13#include <__type_traits/invoke.h>
1414#include <__type_traits/remove_cvref.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__algorithm/unique.h+6-4
......@@ -13,6 +13,7 @@
1313#include <__algorithm/comp.h>
1414#include <__algorithm/iterator_operations.h>
1515#include <__config>
16#include <__functional/identity.h>
1617#include <__iterator/iterator_traits.h>
1718#include <__utility/move.h>
1819#include <__utility/pair.h>
......@@ -29,9 +30,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2930// unique
3031
3132template <class _AlgPolicy, class _Iter, class _Sent, class _BinaryPredicate>
32_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 std::pair<_Iter, _Iter>
33[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 std::pair<_Iter, _Iter>
3334__unique(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) {
34 __first = std::__adjacent_find(__first, __last, __pred);
35 __identity __proj;
36 __first = std::__adjacent_find(__first, __last, __pred, __proj);
3537 if (__first != __last) {
3638 // ... a a ? ...
3739 // f i
......@@ -46,13 +48,13 @@ __unique(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) {
4648}
4749
4850template <class _ForwardIterator, class _BinaryPredicate>
49_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
51[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
5052unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) {
5153 return std::__unique<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred).first;
5254}
5355
5456template <class _ForwardIterator>
55_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
57[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
5658unique(_ForwardIterator __first, _ForwardIterator __last) {
5759 return std::unique(__first, __last, __equal_to());
5860}
lib/libcxx/include/__algorithm/unwrap_iter.h+1-1
......@@ -46,7 +46,7 @@ struct __unwrap_iter_impl {
4646// It's a contiguous iterator, so we can use a raw pointer instead
4747template <class _Iter>
4848struct __unwrap_iter_impl<_Iter, true> {
49 using _ToAddressT = decltype(std::__to_address(std::declval<_Iter>()));
49 using _ToAddressT _LIBCPP_NODEBUG = decltype(std::__to_address(std::declval<_Iter>()));
5050
5151 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Iter __rewrap(_Iter __orig_iter, _ToAddressT __unwrapped_iter) {
5252 return __orig_iter + (__unwrapped_iter - std::__to_address(__orig_iter));
lib/libcxx/include/__algorithm/upper_bound.h+5-2
......@@ -18,6 +18,8 @@
1818#include <__iterator/advance.h>
1919#include <__iterator/distance.h>
2020#include <__iterator/iterator_traits.h>
21#include <__type_traits/invoke.h>
22#include <__type_traits/is_callable.h>
2123#include <__type_traits/is_constructible.h>
2224#include <__utility/move.h>
2325
......@@ -48,15 +50,16 @@ __upper_bound(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp
4850}
4951
5052template <class _ForwardIterator, class _Tp, class _Compare>
51_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
53[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
5254upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
55 static_assert(__is_callable<_Compare&, const _Tp&, decltype(*__first)>::value, "The comparator has to be callable");
5356 static_assert(is_copy_constructible<_ForwardIterator>::value, "Iterator has to be copy constructible");
5457 return std::__upper_bound<_ClassicAlgPolicy>(
5558 std::move(__first), std::move(__last), __value, std::move(__comp), std::__identity());
5659}
5760
5861template <class _ForwardIterator, class _Tp>
59_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
62[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
6063upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
6164 return std::upper_bound(std::move(__first), std::move(__last), __value, __less<>());
6265}
lib/libcxx/include/__assert+28-28
......@@ -23,10 +23,10 @@
2323 : _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING(__LINE__) ": assertion " _LIBCPP_TOSTRING( \
2424 expression) " failed: " message "\n"))
2525
26// TODO: __builtin_assume can currently inhibit optimizations. Until this has been fixed and we can add
27// assumptions without a clear optimization intent, disable that to avoid worsening the code generation.
28// See https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609 for a discussion.
29#if 0 && __has_builtin(__builtin_assume)
26// WARNING: __builtin_assume can currently inhibit optimizations. Only add assumptions with a clear
27// optimization intent. See https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609 for a
28// discussion.
29#if __has_builtin(__builtin_assume)
3030# define _LIBCPP_ASSUME(expression) \
3131 (_LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wassume") \
3232 __builtin_assume(static_cast<bool>(expression)) _LIBCPP_DIAGNOSTIC_POP)
......@@ -44,18 +44,18 @@
4444# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message)
4545// Disabled checks.
4646// On most modern platforms, dereferencing a null pointer does not lead to an actual memory access.
47# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSUME(expression)
47# define _LIBCPP_ASSERT_NON_NULL(expression, message) ((void)0)
4848// Overlapping ranges will make algorithms produce incorrect results but don't directly lead to a security
4949// vulnerability.
50# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression)
51# define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message) _LIBCPP_ASSUME(expression)
52# define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message) _LIBCPP_ASSUME(expression)
53# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression)
54# define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message) _LIBCPP_ASSUME(expression)
55# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSUME(expression)
56# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) _LIBCPP_ASSUME(expression)
57# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression)
58# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression)
50# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) ((void)0)
51# define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message) ((void)0)
52# define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message) ((void)0)
53# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) ((void)0)
54# define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message) ((void)0)
55# define _LIBCPP_ASSERT_PEDANTIC(expression, message) ((void)0)
56# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) ((void)0)
57# define _LIBCPP_ASSERT_INTERNAL(expression, message) ((void)0)
58# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) ((void)0)
5959
6060// Extensive hardening mode checks.
6161
......@@ -73,8 +73,8 @@
7373# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSERT(expression, message)
7474# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message)
7575// Disabled checks.
76# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) _LIBCPP_ASSUME(expression)
77# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression)
76# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) ((void)0)
77# define _LIBCPP_ASSERT_INTERNAL(expression, message) ((void)0)
7878
7979// Debug hardening mode checks.
8080
......@@ -99,18 +99,18 @@
9999#else
100100
101101// All checks disabled.
102# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSUME(expression)
103# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSUME(expression)
104# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSUME(expression)
105# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression)
106# define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message) _LIBCPP_ASSUME(expression)
107# define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message) _LIBCPP_ASSUME(expression)
108# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression)
109# define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message) _LIBCPP_ASSUME(expression)
110# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSUME(expression)
111# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) _LIBCPP_ASSUME(expression)
112# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression)
113# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression)
102# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) ((void)0)
103# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) ((void)0)
104# define _LIBCPP_ASSERT_NON_NULL(expression, message) ((void)0)
105# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) ((void)0)
106# define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message) ((void)0)
107# define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message) ((void)0)
108# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) ((void)0)
109# define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message) ((void)0)
110# define _LIBCPP_ASSERT_PEDANTIC(expression, message) ((void)0)
111# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) ((void)0)
112# define _LIBCPP_ASSERT_INTERNAL(expression, message) ((void)0)
113# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) ((void)0)
114114
115115#endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
116116// clang-format on
lib/libcxx/include/__assertion_handler+9-3
......@@ -10,8 +10,13 @@
1010#ifndef _LIBCPP___ASSERTION_HANDLER
1111#define _LIBCPP___ASSERTION_HANDLER
1212
13#include <__config>
14#include <__verbose_abort>
13#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
14# include <__cxx03/__config>
15# include <__cxx03/__verbose_abort>
16#else
17# include <__config>
18# include <__verbose_abort>
19#endif
1520
1621#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1722# pragma GCC system_header
......@@ -26,7 +31,8 @@
2631# if __has_builtin(__builtin_verbose_trap)
2732// AppleClang shipped a slightly different version of __builtin_verbose_trap from the upstream
2833// version before upstream Clang actually got the builtin.
29# if defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 17000
34// TODO: Remove once AppleClang supports the two-arguments version of the builtin.
35# if defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1700
3036# define _LIBCPP_ASSERTION_HANDLER(message) __builtin_verbose_trap(message)
3137# else
3238# define _LIBCPP_ASSERTION_HANDLER(message) __builtin_verbose_trap("libc++", message)
lib/libcxx/include/__atomic/aliases.h+9-8
......@@ -14,9 +14,10 @@
1414#include <__atomic/contention_t.h>
1515#include <__atomic/is_always_lock_free.h>
1616#include <__config>
17#include <__cstddef/ptrdiff_t.h>
18#include <__cstddef/size_t.h>
1719#include <__type_traits/conditional.h>
1820#include <__type_traits/make_unsigned.h>
19#include <cstddef>
2021#include <cstdint>
2122
2223#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -37,12 +38,12 @@ using atomic_long = atomic<long>;
3738using atomic_ulong = atomic<unsigned long>;
3839using atomic_llong = atomic<long long>;
3940using atomic_ullong = atomic<unsigned long long>;
40#ifndef _LIBCPP_HAS_NO_CHAR8_T
41#if _LIBCPP_HAS_CHAR8_T
4142using atomic_char8_t = atomic<char8_t>;
4243#endif
4344using atomic_char16_t = atomic<char16_t>;
4445using atomic_char32_t = atomic<char32_t>;
45#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
46#if _LIBCPP_HAS_WIDE_CHARACTERS
4647using atomic_wchar_t = atomic<wchar_t>;
4748#endif
4849
......@@ -83,19 +84,19 @@ using atomic_uintmax_t = atomic<uintmax_t>;
8384// C++20 atomic_{signed,unsigned}_lock_free: prefer the contention type most highly, then the largest lock-free type
8485#if _LIBCPP_STD_VER >= 20
8586# if ATOMIC_LLONG_LOCK_FREE == 2
86using __largest_lock_free_type = long long;
87using __largest_lock_free_type _LIBCPP_NODEBUG = long long;
8788# elif ATOMIC_INT_LOCK_FREE == 2
88using __largest_lock_free_type = int;
89using __largest_lock_free_type _LIBCPP_NODEBUG = int;
8990# elif ATOMIC_SHORT_LOCK_FREE == 2
90using __largest_lock_free_type = short;
91using __largest_lock_free_type _LIBCPP_NODEBUG = short;
9192# elif ATOMIC_CHAR_LOCK_FREE == 2
92using __largest_lock_free_type = char;
93using __largest_lock_free_type _LIBCPP_NODEBUG = char;
9394# else
9495# define _LIBCPP_NO_LOCK_FREE_TYPES // There are no lockfree types (this can happen on unusual platforms)
9596# endif
9697
9798# ifndef _LIBCPP_NO_LOCK_FREE_TYPES
98using __contention_t_or_largest =
99using __contention_t_or_largest _LIBCPP_NODEBUG =
99100 __conditional_t<__libcpp_is_always_lock_free<__cxx_contention_t>::__value,
100101 __cxx_contention_t,
101102 __largest_lock_free_type>;
lib/libcxx/include/__atomic/atomic.h+222-23
......@@ -9,21 +9,24 @@
99#ifndef _LIBCPP___ATOMIC_ATOMIC_H
1010#define _LIBCPP___ATOMIC_ATOMIC_H
1111
12#include <__atomic/atomic_base.h>
12#include <__atomic/atomic_sync.h>
1313#include <__atomic/check_memory_order.h>
14#include <__atomic/cxx_atomic_impl.h>
14#include <__atomic/is_always_lock_free.h>
1515#include <__atomic/memory_order.h>
16#include <__atomic/support.h>
1617#include <__config>
17#include <__functional/operations.h>
18#include <__cstddef/ptrdiff_t.h>
1819#include <__memory/addressof.h>
20#include <__type_traits/enable_if.h>
1921#include <__type_traits/is_floating_point.h>
2022#include <__type_traits/is_function.h>
23#include <__type_traits/is_integral.h>
24#include <__type_traits/is_nothrow_constructible.h>
2125#include <__type_traits/is_same.h>
2226#include <__type_traits/remove_const.h>
2327#include <__type_traits/remove_pointer.h>
2428#include <__type_traits/remove_volatile.h>
2529#include <__utility/forward.h>
26#include <cstddef>
2730#include <cstring>
2831
2932#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -32,11 +35,202 @@
3235
3336_LIBCPP_BEGIN_NAMESPACE_STD
3437
38template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
39struct __atomic_base // false
40{
41 mutable __cxx_atomic_impl<_Tp> __a_;
42
43#if _LIBCPP_STD_VER >= 17
44 static constexpr bool is_always_lock_free = __libcpp_is_always_lock_free<__cxx_atomic_impl<_Tp> >::__value;
45#endif
46
47 _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const volatile _NOEXCEPT {
48 return __cxx_atomic_is_lock_free(sizeof(__cxx_atomic_impl<_Tp>));
49 }
50 _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const _NOEXCEPT {
51 return static_cast<__atomic_base const volatile*>(this)->is_lock_free();
52 }
53 _LIBCPP_HIDE_FROM_ABI void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
54 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) {
55 std::__cxx_atomic_store(std::addressof(__a_), __d, __m);
56 }
57 _LIBCPP_HIDE_FROM_ABI void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
58 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) {
59 std::__cxx_atomic_store(std::addressof(__a_), __d, __m);
60 }
61 _LIBCPP_HIDE_FROM_ABI _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
62 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) {
63 return std::__cxx_atomic_load(std::addressof(__a_), __m);
64 }
65 _LIBCPP_HIDE_FROM_ABI _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
66 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) {
67 return std::__cxx_atomic_load(std::addressof(__a_), __m);
68 }
69 _LIBCPP_HIDE_FROM_ABI operator _Tp() const volatile _NOEXCEPT { return load(); }
70 _LIBCPP_HIDE_FROM_ABI operator _Tp() const _NOEXCEPT { return load(); }
71 _LIBCPP_HIDE_FROM_ABI _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
72 return std::__cxx_atomic_exchange(std::addressof(__a_), __d, __m);
73 }
74 _LIBCPP_HIDE_FROM_ABI _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
75 return std::__cxx_atomic_exchange(std::addressof(__a_), __d, __m);
76 }
77 _LIBCPP_HIDE_FROM_ABI bool
78 compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT
79 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) {
80 return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __s, __f);
81 }
82 _LIBCPP_HIDE_FROM_ABI bool compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT
83 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) {
84 return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __s, __f);
85 }
86 _LIBCPP_HIDE_FROM_ABI bool
87 compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT
88 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) {
89 return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __s, __f);
90 }
91 _LIBCPP_HIDE_FROM_ABI bool compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT
92 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) {
93 return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __s, __f);
94 }
95 _LIBCPP_HIDE_FROM_ABI bool
96 compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
97 return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __m, __m);
98 }
99 _LIBCPP_HIDE_FROM_ABI bool
100 compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
101 return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __m, __m);
102 }
103 _LIBCPP_HIDE_FROM_ABI bool
104 compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
105 return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __m, __m);
106 }
107 _LIBCPP_HIDE_FROM_ABI bool
108 compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
109 return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __m, __m);
110 }
111
112#if _LIBCPP_STD_VER >= 20
113 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void wait(_Tp __v, memory_order __m = memory_order_seq_cst) const
114 volatile _NOEXCEPT {
115 std::__atomic_wait(*this, __v, __m);
116 }
117 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void
118 wait(_Tp __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT {
119 std::__atomic_wait(*this, __v, __m);
120 }
121 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() volatile _NOEXCEPT {
122 std::__atomic_notify_one(*this);
123 }
124 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() _NOEXCEPT { std::__atomic_notify_one(*this); }
125 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() volatile _NOEXCEPT {
126 std::__atomic_notify_all(*this);
127 }
128 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() _NOEXCEPT { std::__atomic_notify_all(*this); }
129#endif // _LIBCPP_STD_VER >= 20
130
131#if _LIBCPP_STD_VER >= 20
132 _LIBCPP_HIDE_FROM_ABI constexpr __atomic_base() noexcept(is_nothrow_default_constructible_v<_Tp>) : __a_(_Tp()) {}
133#else
134 _LIBCPP_HIDE_FROM_ABI __atomic_base() _NOEXCEPT = default;
135#endif
136
137 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
138
139 __atomic_base(const __atomic_base&) = delete;
140};
141
142// atomic<Integral>
143
144template <class _Tp>
145struct __atomic_base<_Tp, true> : public __atomic_base<_Tp, false> {
146 using __base _LIBCPP_NODEBUG = __atomic_base<_Tp, false>;
147
148 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __atomic_base() _NOEXCEPT = default;
149
150 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
151
152 _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
153 return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m);
154 }
155 _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
156 return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m);
157 }
158 _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
159 return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m);
160 }
161 _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
162 return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m);
163 }
164 _LIBCPP_HIDE_FROM_ABI _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
165 return std::__cxx_atomic_fetch_and(std::addressof(this->__a_), __op, __m);
166 }
167 _LIBCPP_HIDE_FROM_ABI _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
168 return std::__cxx_atomic_fetch_and(std::addressof(this->__a_), __op, __m);
169 }
170 _LIBCPP_HIDE_FROM_ABI _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
171 return std::__cxx_atomic_fetch_or(std::addressof(this->__a_), __op, __m);
172 }
173 _LIBCPP_HIDE_FROM_ABI _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
174 return std::__cxx_atomic_fetch_or(std::addressof(this->__a_), __op, __m);
175 }
176 _LIBCPP_HIDE_FROM_ABI _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
177 return std::__cxx_atomic_fetch_xor(std::addressof(this->__a_), __op, __m);
178 }
179 _LIBCPP_HIDE_FROM_ABI _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
180 return std::__cxx_atomic_fetch_xor(std::addressof(this->__a_), __op, __m);
181 }
182
183 _LIBCPP_HIDE_FROM_ABI _Tp operator++(int) volatile _NOEXCEPT { return fetch_add(_Tp(1)); }
184 _LIBCPP_HIDE_FROM_ABI _Tp operator++(int) _NOEXCEPT { return fetch_add(_Tp(1)); }
185 _LIBCPP_HIDE_FROM_ABI _Tp operator--(int) volatile _NOEXCEPT { return fetch_sub(_Tp(1)); }
186 _LIBCPP_HIDE_FROM_ABI _Tp operator--(int) _NOEXCEPT { return fetch_sub(_Tp(1)); }
187 _LIBCPP_HIDE_FROM_ABI _Tp operator++() volatile _NOEXCEPT { return fetch_add(_Tp(1)) + _Tp(1); }
188 _LIBCPP_HIDE_FROM_ABI _Tp operator++() _NOEXCEPT { return fetch_add(_Tp(1)) + _Tp(1); }
189 _LIBCPP_HIDE_FROM_ABI _Tp operator--() volatile _NOEXCEPT { return fetch_sub(_Tp(1)) - _Tp(1); }
190 _LIBCPP_HIDE_FROM_ABI _Tp operator--() _NOEXCEPT { return fetch_sub(_Tp(1)) - _Tp(1); }
191 _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) volatile _NOEXCEPT { return fetch_add(__op) + __op; }
192 _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) _NOEXCEPT { return fetch_add(__op) + __op; }
193 _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) volatile _NOEXCEPT { return fetch_sub(__op) - __op; }
194 _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) _NOEXCEPT { return fetch_sub(__op) - __op; }
195 _LIBCPP_HIDE_FROM_ABI _Tp operator&=(_Tp __op) volatile _NOEXCEPT { return fetch_and(__op) & __op; }
196 _LIBCPP_HIDE_FROM_ABI _Tp operator&=(_Tp __op) _NOEXCEPT { return fetch_and(__op) & __op; }
197 _LIBCPP_HIDE_FROM_ABI _Tp operator|=(_Tp __op) volatile _NOEXCEPT { return fetch_or(__op) | __op; }
198 _LIBCPP_HIDE_FROM_ABI _Tp operator|=(_Tp __op) _NOEXCEPT { return fetch_or(__op) | __op; }
199 _LIBCPP_HIDE_FROM_ABI _Tp operator^=(_Tp __op) volatile _NOEXCEPT { return fetch_xor(__op) ^ __op; }
200 _LIBCPP_HIDE_FROM_ABI _Tp operator^=(_Tp __op) _NOEXCEPT { return fetch_xor(__op) ^ __op; }
201};
202
203// Here we need _IsIntegral because the default template argument is not enough
204// e.g __atomic_base<int> is __atomic_base<int, true>, which inherits from
205// __atomic_base<int, false> and the caller of the wait function is
206// __atomic_base<int, false>. So specializing __atomic_base<_Tp> does not work
207template <class _Tp, bool _IsIntegral>
208struct __atomic_waitable_traits<__atomic_base<_Tp, _IsIntegral> > {
209 static _LIBCPP_HIDE_FROM_ABI _Tp __atomic_load(const __atomic_base<_Tp, _IsIntegral>& __a, memory_order __order) {
210 return __a.load(__order);
211 }
212
213 static _LIBCPP_HIDE_FROM_ABI _Tp
214 __atomic_load(const volatile __atomic_base<_Tp, _IsIntegral>& __this, memory_order __order) {
215 return __this.load(__order);
216 }
217
218 static _LIBCPP_HIDE_FROM_ABI const __cxx_atomic_impl<_Tp>*
219 __atomic_contention_address(const __atomic_base<_Tp, _IsIntegral>& __a) {
220 return std::addressof(__a.__a_);
221 }
222
223 static _LIBCPP_HIDE_FROM_ABI const volatile __cxx_atomic_impl<_Tp>*
224 __atomic_contention_address(const volatile __atomic_base<_Tp, _IsIntegral>& __this) {
225 return std::addressof(__this.__a_);
226 }
227};
228
35229template <class _Tp>
36230struct atomic : public __atomic_base<_Tp> {
37 using __base = __atomic_base<_Tp>;
38 using value_type = _Tp;
39 using difference_type = value_type;
231 using __base _LIBCPP_NODEBUG = __atomic_base<_Tp>;
232 using value_type = _Tp;
233 using difference_type = value_type;
40234
41235#if _LIBCPP_STD_VER >= 20
42236 _LIBCPP_HIDE_FROM_ABI atomic() = default;
......@@ -63,9 +257,9 @@ struct atomic : public __atomic_base<_Tp> {
63257
64258template <class _Tp>
65259struct atomic<_Tp*> : public __atomic_base<_Tp*> {
66 using __base = __atomic_base<_Tp*>;
67 using value_type = _Tp*;
68 using difference_type = ptrdiff_t;
260 using __base _LIBCPP_NODEBUG = __atomic_base<_Tp*>;
261 using value_type = _Tp*;
262 using difference_type = ptrdiff_t;
69263
70264 _LIBCPP_HIDE_FROM_ABI atomic() _NOEXCEPT = default;
71265
......@@ -121,6 +315,9 @@ struct atomic<_Tp*> : public __atomic_base<_Tp*> {
121315 atomic& operator=(const atomic&) volatile = delete;
122316};
123317
318template <class _Tp>
319struct __atomic_waitable_traits<atomic<_Tp> > : __atomic_waitable_traits<__atomic_base<_Tp> > {};
320
124321#if _LIBCPP_STD_VER >= 20
125322template <class _Tp>
126323 requires is_floating_point_v<_Tp>
......@@ -178,7 +375,8 @@ private:
178375 auto __builtin_op = [](auto __a, auto __builtin_operand, auto __order) {
179376 return std::__cxx_atomic_fetch_add(__a, __builtin_operand, __order);
180377 };
181 return __rmw_op(std::forward<_This>(__self), __operand, __m, std::plus<>{}, __builtin_op);
378 auto __plus = [](auto __a, auto __b) { return __a + __b; };
379 return __rmw_op(std::forward<_This>(__self), __operand, __m, __plus, __builtin_op);
182380 }
183381
184382 template <class _This>
......@@ -186,13 +384,14 @@ private:
186384 auto __builtin_op = [](auto __a, auto __builtin_operand, auto __order) {
187385 return std::__cxx_atomic_fetch_sub(__a, __builtin_operand, __order);
188386 };
189 return __rmw_op(std::forward<_This>(__self), __operand, __m, std::minus<>{}, __builtin_op);
387 auto __minus = [](auto __a, auto __b) { return __a - __b; };
388 return __rmw_op(std::forward<_This>(__self), __operand, __m, __minus, __builtin_op);
190389 }
191390
192391public:
193 using __base = __atomic_base<_Tp>;
194 using value_type = _Tp;
195 using difference_type = value_type;
392 using __base _LIBCPP_NODEBUG = __atomic_base<_Tp>;
393 using value_type = _Tp;
394 using difference_type = value_type;
196395
197396 _LIBCPP_HIDE_FROM_ABI constexpr atomic() noexcept = default;
198397 _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(
429628 return __o->compare_exchange_strong(*__e, __d, __s, __f);
430629}
431630
631#if _LIBCPP_STD_VER >= 20
632
432633// atomic_wait
433634
434635template <class _Tp>
......@@ -462,29 +663,27 @@ atomic_wait_explicit(const atomic<_Tp>* __o, typename atomic<_Tp>::value_type __
462663// atomic_notify_one
463664
464665template <class _Tp>
465_LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void
466atomic_notify_one(volatile atomic<_Tp>* __o) _NOEXCEPT {
666_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void atomic_notify_one(volatile atomic<_Tp>* __o) _NOEXCEPT {
467667 __o->notify_one();
468668}
469669template <class _Tp>
470_LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void
471atomic_notify_one(atomic<_Tp>* __o) _NOEXCEPT {
670_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void atomic_notify_one(atomic<_Tp>* __o) _NOEXCEPT {
472671 __o->notify_one();
473672}
474673
475674// atomic_notify_all
476675
477676template <class _Tp>
478_LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void
479atomic_notify_all(volatile atomic<_Tp>* __o) _NOEXCEPT {
677_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void atomic_notify_all(volatile atomic<_Tp>* __o) _NOEXCEPT {
480678 __o->notify_all();
481679}
482680template <class _Tp>
483_LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void
484atomic_notify_all(atomic<_Tp>* __o) _NOEXCEPT {
681_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void atomic_notify_all(atomic<_Tp>* __o) _NOEXCEPT {
485682 __o->notify_all();
486683}
487684
685#endif // _LIBCPP_STD_VER >= 20
686
488687// atomic_fetch_add
489688
490689template <class _Tp>
lib/libcxx/include/__atomic/atomic_base.h deleted-221
......@@ -1,221 +0,0 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ATOMIC_ATOMIC_BASE_H
10#define _LIBCPP___ATOMIC_ATOMIC_BASE_H
11
12#include <__atomic/atomic_sync.h>
13#include <__atomic/check_memory_order.h>
14#include <__atomic/cxx_atomic_impl.h>
15#include <__atomic/is_always_lock_free.h>
16#include <__atomic/memory_order.h>
17#include <__config>
18#include <__memory/addressof.h>
19#include <__type_traits/is_integral.h>
20#include <__type_traits/is_nothrow_constructible.h>
21#include <__type_traits/is_same.h>
22#include <version>
23
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26#endif
27
28_LIBCPP_BEGIN_NAMESPACE_STD
29
30template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
31struct __atomic_base // false
32{
33 mutable __cxx_atomic_impl<_Tp> __a_;
34
35#if _LIBCPP_STD_VER >= 17
36 static constexpr bool is_always_lock_free = __libcpp_is_always_lock_free<__cxx_atomic_impl<_Tp> >::__value;
37#endif
38
39 _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const volatile _NOEXCEPT {
40 return __cxx_atomic_is_lock_free(sizeof(__cxx_atomic_impl<_Tp>));
41 }
42 _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const _NOEXCEPT {
43 return static_cast<__atomic_base const volatile*>(this)->is_lock_free();
44 }
45 _LIBCPP_HIDE_FROM_ABI void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
46 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) {
47 std::__cxx_atomic_store(std::addressof(__a_), __d, __m);
48 }
49 _LIBCPP_HIDE_FROM_ABI void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
50 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) {
51 std::__cxx_atomic_store(std::addressof(__a_), __d, __m);
52 }
53 _LIBCPP_HIDE_FROM_ABI _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
54 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) {
55 return std::__cxx_atomic_load(std::addressof(__a_), __m);
56 }
57 _LIBCPP_HIDE_FROM_ABI _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
58 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) {
59 return std::__cxx_atomic_load(std::addressof(__a_), __m);
60 }
61 _LIBCPP_HIDE_FROM_ABI operator _Tp() const volatile _NOEXCEPT { return load(); }
62 _LIBCPP_HIDE_FROM_ABI operator _Tp() const _NOEXCEPT { return load(); }
63 _LIBCPP_HIDE_FROM_ABI _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
64 return std::__cxx_atomic_exchange(std::addressof(__a_), __d, __m);
65 }
66 _LIBCPP_HIDE_FROM_ABI _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
67 return std::__cxx_atomic_exchange(std::addressof(__a_), __d, __m);
68 }
69 _LIBCPP_HIDE_FROM_ABI bool
70 compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT
71 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) {
72 return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __s, __f);
73 }
74 _LIBCPP_HIDE_FROM_ABI bool compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT
75 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) {
76 return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __s, __f);
77 }
78 _LIBCPP_HIDE_FROM_ABI bool
79 compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT
80 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) {
81 return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __s, __f);
82 }
83 _LIBCPP_HIDE_FROM_ABI bool compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT
84 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) {
85 return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __s, __f);
86 }
87 _LIBCPP_HIDE_FROM_ABI bool
88 compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
89 return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __m, __m);
90 }
91 _LIBCPP_HIDE_FROM_ABI bool
92 compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
93 return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __m, __m);
94 }
95 _LIBCPP_HIDE_FROM_ABI bool
96 compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
97 return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __m, __m);
98 }
99 _LIBCPP_HIDE_FROM_ABI bool
100 compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
101 return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __m, __m);
102 }
103
104 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void wait(_Tp __v, memory_order __m = memory_order_seq_cst) const
105 volatile _NOEXCEPT {
106 std::__atomic_wait(*this, __v, __m);
107 }
108 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void
109 wait(_Tp __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT {
110 std::__atomic_wait(*this, __v, __m);
111 }
112 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() volatile _NOEXCEPT {
113 std::__atomic_notify_one(*this);
114 }
115 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() _NOEXCEPT { std::__atomic_notify_one(*this); }
116 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() volatile _NOEXCEPT {
117 std::__atomic_notify_all(*this);
118 }
119 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() _NOEXCEPT { std::__atomic_notify_all(*this); }
120
121#if _LIBCPP_STD_VER >= 20
122 _LIBCPP_HIDE_FROM_ABI constexpr __atomic_base() noexcept(is_nothrow_default_constructible_v<_Tp>) : __a_(_Tp()) {}
123#else
124 _LIBCPP_HIDE_FROM_ABI __atomic_base() _NOEXCEPT = default;
125#endif
126
127 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
128
129 __atomic_base(const __atomic_base&) = delete;
130};
131
132// atomic<Integral>
133
134template <class _Tp>
135struct __atomic_base<_Tp, true> : public __atomic_base<_Tp, false> {
136 using __base = __atomic_base<_Tp, false>;
137
138 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __atomic_base() _NOEXCEPT = default;
139
140 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
141
142 _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
143 return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m);
144 }
145 _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
146 return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m);
147 }
148 _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
149 return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m);
150 }
151 _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
152 return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m);
153 }
154 _LIBCPP_HIDE_FROM_ABI _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
155 return std::__cxx_atomic_fetch_and(std::addressof(this->__a_), __op, __m);
156 }
157 _LIBCPP_HIDE_FROM_ABI _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
158 return std::__cxx_atomic_fetch_and(std::addressof(this->__a_), __op, __m);
159 }
160 _LIBCPP_HIDE_FROM_ABI _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
161 return std::__cxx_atomic_fetch_or(std::addressof(this->__a_), __op, __m);
162 }
163 _LIBCPP_HIDE_FROM_ABI _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
164 return std::__cxx_atomic_fetch_or(std::addressof(this->__a_), __op, __m);
165 }
166 _LIBCPP_HIDE_FROM_ABI _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
167 return std::__cxx_atomic_fetch_xor(std::addressof(this->__a_), __op, __m);
168 }
169 _LIBCPP_HIDE_FROM_ABI _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
170 return std::__cxx_atomic_fetch_xor(std::addressof(this->__a_), __op, __m);
171 }
172
173 _LIBCPP_HIDE_FROM_ABI _Tp operator++(int) volatile _NOEXCEPT { return fetch_add(_Tp(1)); }
174 _LIBCPP_HIDE_FROM_ABI _Tp operator++(int) _NOEXCEPT { return fetch_add(_Tp(1)); }
175 _LIBCPP_HIDE_FROM_ABI _Tp operator--(int) volatile _NOEXCEPT { return fetch_sub(_Tp(1)); }
176 _LIBCPP_HIDE_FROM_ABI _Tp operator--(int) _NOEXCEPT { return fetch_sub(_Tp(1)); }
177 _LIBCPP_HIDE_FROM_ABI _Tp operator++() volatile _NOEXCEPT { return fetch_add(_Tp(1)) + _Tp(1); }
178 _LIBCPP_HIDE_FROM_ABI _Tp operator++() _NOEXCEPT { return fetch_add(_Tp(1)) + _Tp(1); }
179 _LIBCPP_HIDE_FROM_ABI _Tp operator--() volatile _NOEXCEPT { return fetch_sub(_Tp(1)) - _Tp(1); }
180 _LIBCPP_HIDE_FROM_ABI _Tp operator--() _NOEXCEPT { return fetch_sub(_Tp(1)) - _Tp(1); }
181 _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) volatile _NOEXCEPT { return fetch_add(__op) + __op; }
182 _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) _NOEXCEPT { return fetch_add(__op) + __op; }
183 _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) volatile _NOEXCEPT { return fetch_sub(__op) - __op; }
184 _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) _NOEXCEPT { return fetch_sub(__op) - __op; }
185 _LIBCPP_HIDE_FROM_ABI _Tp operator&=(_Tp __op) volatile _NOEXCEPT { return fetch_and(__op) & __op; }
186 _LIBCPP_HIDE_FROM_ABI _Tp operator&=(_Tp __op) _NOEXCEPT { return fetch_and(__op) & __op; }
187 _LIBCPP_HIDE_FROM_ABI _Tp operator|=(_Tp __op) volatile _NOEXCEPT { return fetch_or(__op) | __op; }
188 _LIBCPP_HIDE_FROM_ABI _Tp operator|=(_Tp __op) _NOEXCEPT { return fetch_or(__op) | __op; }
189 _LIBCPP_HIDE_FROM_ABI _Tp operator^=(_Tp __op) volatile _NOEXCEPT { return fetch_xor(__op) ^ __op; }
190 _LIBCPP_HIDE_FROM_ABI _Tp operator^=(_Tp __op) _NOEXCEPT { return fetch_xor(__op) ^ __op; }
191};
192
193// Here we need _IsIntegral because the default template argument is not enough
194// e.g __atomic_base<int> is __atomic_base<int, true>, which inherits from
195// __atomic_base<int, false> and the caller of the wait function is
196// __atomic_base<int, false>. So specializing __atomic_base<_Tp> does not work
197template <class _Tp, bool _IsIntegral>
198struct __atomic_waitable_traits<__atomic_base<_Tp, _IsIntegral> > {
199 static _LIBCPP_HIDE_FROM_ABI _Tp __atomic_load(const __atomic_base<_Tp, _IsIntegral>& __a, memory_order __order) {
200 return __a.load(__order);
201 }
202
203 static _LIBCPP_HIDE_FROM_ABI _Tp
204 __atomic_load(const volatile __atomic_base<_Tp, _IsIntegral>& __this, memory_order __order) {
205 return __this.load(__order);
206 }
207
208 static _LIBCPP_HIDE_FROM_ABI const __cxx_atomic_impl<_Tp>*
209 __atomic_contention_address(const __atomic_base<_Tp, _IsIntegral>& __a) {
210 return std::addressof(__a.__a_);
211 }
212
213 static _LIBCPP_HIDE_FROM_ABI const volatile __cxx_atomic_impl<_Tp>*
214 __atomic_contention_address(const volatile __atomic_base<_Tp, _IsIntegral>& __this) {
215 return std::addressof(__this.__a_);
216 }
217};
218
219_LIBCPP_END_NAMESPACE_STD
220
221#endif // _LIBCPP___ATOMIC_ATOMIC_BASE_H
lib/libcxx/include/__atomic/atomic_flag.h+19-21
......@@ -11,8 +11,8 @@
1111
1212#include <__atomic/atomic_sync.h>
1313#include <__atomic/contention_t.h>
14#include <__atomic/cxx_atomic_impl.h>
1514#include <__atomic/memory_order.h>
15#include <__atomic/support.h>
1616#include <__chrono/duration.h>
1717#include <__config>
1818#include <__memory/addressof.h>
......@@ -48,26 +48,24 @@ struct atomic_flag {
4848 __cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);
4949 }
5050
51 _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void
52 wait(bool __v, memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT {
51#if _LIBCPP_STD_VER >= 20
52 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void wait(bool __v, memory_order __m = memory_order_seq_cst) const
53 volatile _NOEXCEPT {
5354 std::__atomic_wait(*this, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m);
5455 }
55 _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void
56 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void
5657 wait(bool __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT {
5758 std::__atomic_wait(*this, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m);
5859 }
59 _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() volatile _NOEXCEPT {
60 std::__atomic_notify_one(*this);
61 }
62 _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() _NOEXCEPT {
60 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() volatile _NOEXCEPT {
6361 std::__atomic_notify_one(*this);
6462 }
63 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() _NOEXCEPT { std::__atomic_notify_one(*this); }
6564 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() volatile _NOEXCEPT {
6665 std::__atomic_notify_all(*this);
6766 }
68 _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() _NOEXCEPT {
69 std::__atomic_notify_all(*this);
70 }
67 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() _NOEXCEPT { std::__atomic_notify_all(*this); }
68#endif
7169
7270#if _LIBCPP_STD_VER >= 20
7371 _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
144142 __o->clear(__m);
145143}
146144
147inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
145#if _LIBCPP_STD_VER >= 20
146inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
148147atomic_flag_wait(const volatile atomic_flag* __o, bool __v) _NOEXCEPT {
149148 __o->wait(__v);
150149}
151150
152inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
151inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
153152atomic_flag_wait(const atomic_flag* __o, bool __v) _NOEXCEPT {
154153 __o->wait(__v);
155154}
156155
157inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
156inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
158157atomic_flag_wait_explicit(const volatile atomic_flag* __o, bool __v, memory_order __m) _NOEXCEPT {
159158 __o->wait(__v, __m);
160159}
161160
162inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
161inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
163162atomic_flag_wait_explicit(const atomic_flag* __o, bool __v, memory_order __m) _NOEXCEPT {
164163 __o->wait(__v, __m);
165164}
166165
167inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
166inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
168167atomic_flag_notify_one(volatile atomic_flag* __o) _NOEXCEPT {
169168 __o->notify_one();
170169}
171170
172inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
173atomic_flag_notify_one(atomic_flag* __o) _NOEXCEPT {
171inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void atomic_flag_notify_one(atomic_flag* __o) _NOEXCEPT {
174172 __o->notify_one();
175173}
176174
177inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
175inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
178176atomic_flag_notify_all(volatile atomic_flag* __o) _NOEXCEPT {
179177 __o->notify_all();
180178}
181179
182inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void
183atomic_flag_notify_all(atomic_flag* __o) _NOEXCEPT {
180inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void atomic_flag_notify_all(atomic_flag* __o) _NOEXCEPT {
184181 __o->notify_all();
185182}
183#endif // _LIBCPP_STD_VER >= 20
186184
187185_LIBCPP_END_NAMESPACE_STD
188186
lib/libcxx/include/__atomic/atomic_lock_free.h+2-2
......@@ -18,7 +18,7 @@
1818#if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE)
1919# define ATOMIC_BOOL_LOCK_FREE __CLANG_ATOMIC_BOOL_LOCK_FREE
2020# define ATOMIC_CHAR_LOCK_FREE __CLANG_ATOMIC_CHAR_LOCK_FREE
21# ifndef _LIBCPP_HAS_NO_CHAR8_T
21# if _LIBCPP_HAS_CHAR8_T
2222# define ATOMIC_CHAR8_T_LOCK_FREE __CLANG_ATOMIC_CHAR8_T_LOCK_FREE
2323# endif
2424# define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
......@@ -32,7 +32,7 @@
3232#elif defined(__GCC_ATOMIC_BOOL_LOCK_FREE)
3333# define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE
3434# define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE
35# ifndef _LIBCPP_HAS_NO_CHAR8_T
35# if _LIBCPP_HAS_CHAR8_T
3636# define ATOMIC_CHAR8_T_LOCK_FREE __GCC_ATOMIC_CHAR8_T_LOCK_FREE
3737# endif
3838# define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
lib/libcxx/include/__atomic/atomic_ref.h+8-6
......@@ -20,14 +20,16 @@
2020#include <__assert>
2121#include <__atomic/atomic_sync.h>
2222#include <__atomic/check_memory_order.h>
23#include <__atomic/memory_order.h>
2324#include <__atomic/to_gcc_order.h>
2425#include <__concepts/arithmetic.h>
2526#include <__concepts/same_as.h>
2627#include <__config>
28#include <__cstddef/byte.h>
29#include <__cstddef/ptrdiff_t.h>
2730#include <__memory/addressof.h>
2831#include <__type_traits/has_unique_object_representation.h>
2932#include <__type_traits/is_trivially_copyable.h>
30#include <cstddef>
3133#include <cstdint>
3234#include <cstring>
3335
......@@ -219,7 +221,7 @@ public:
219221 _LIBCPP_HIDE_FROM_ABI void notify_all() const noexcept { std::__atomic_notify_all(*this); }
220222
221223protected:
222 typedef _Tp _Aligned_Tp __attribute__((aligned(required_alignment)));
224 using _Aligned_Tp [[__gnu__::__aligned__(required_alignment), __gnu__::__nodebug__]] = _Tp;
223225 _Aligned_Tp* __ptr_;
224226
225227 _LIBCPP_HIDE_FROM_ABI __atomic_ref_base(_Tp& __obj) : __ptr_(std::addressof(__obj)) {}
......@@ -239,7 +241,7 @@ template <class _Tp>
239241struct atomic_ref : public __atomic_ref_base<_Tp> {
240242 static_assert(is_trivially_copyable_v<_Tp>, "std::atomic_ref<T> requires that 'T' be a trivially copyable type");
241243
242 using __base = __atomic_ref_base<_Tp>;
244 using __base _LIBCPP_NODEBUG = __atomic_ref_base<_Tp>;
243245
244246 _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp& __obj) : __base(__obj) {
245247 _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
......@@ -257,7 +259,7 @@ struct atomic_ref : public __atomic_ref_base<_Tp> {
257259template <class _Tp>
258260 requires(std::integral<_Tp> && !std::same_as<bool, _Tp>)
259261struct atomic_ref<_Tp> : public __atomic_ref_base<_Tp> {
260 using __base = __atomic_ref_base<_Tp>;
262 using __base _LIBCPP_NODEBUG = __atomic_ref_base<_Tp>;
261263
262264 using difference_type = __base::value_type;
263265
......@@ -303,7 +305,7 @@ struct atomic_ref<_Tp> : public __atomic_ref_base<_Tp> {
303305template <class _Tp>
304306 requires std::floating_point<_Tp>
305307struct atomic_ref<_Tp> : public __atomic_ref_base<_Tp> {
306 using __base = __atomic_ref_base<_Tp>;
308 using __base _LIBCPP_NODEBUG = __atomic_ref_base<_Tp>;
307309
308310 using difference_type = __base::value_type;
309311
......@@ -342,7 +344,7 @@ struct atomic_ref<_Tp> : public __atomic_ref_base<_Tp> {
342344
343345template <class _Tp>
344346struct atomic_ref<_Tp*> : public __atomic_ref_base<_Tp*> {
345 using __base = __atomic_ref_base<_Tp*>;
347 using __base _LIBCPP_NODEBUG = __atomic_ref_base<_Tp*>;
346348
347349 using difference_type = ptrdiff_t;
348350
lib/libcxx/include/__atomic/atomic_sync.h+30-40
......@@ -10,14 +10,12 @@
1010#define _LIBCPP___ATOMIC_ATOMIC_SYNC_H
1111
1212#include <__atomic/contention_t.h>
13#include <__atomic/cxx_atomic_impl.h>
1413#include <__atomic/memory_order.h>
1514#include <__atomic/to_gcc_order.h>
1615#include <__chrono/duration.h>
1716#include <__config>
1817#include <__memory/addressof.h>
1918#include <__thread/poll_with_backoff.h>
20#include <__thread/support.h>
2119#include <__type_traits/conjunction.h>
2220#include <__type_traits/decay.h>
2321#include <__type_traits/invoke.h>
......@@ -57,19 +55,8 @@ struct __atomic_waitable< _Tp,
5755 decltype(__atomic_waitable_traits<__decay_t<_Tp> >::__atomic_contention_address(
5856 std::declval<const _Tp&>()))> > : true_type {};
5957
60template <class _AtomicWaitable, class _Poll>
61struct __atomic_wait_poll_impl {
62 const _AtomicWaitable& __a_;
63 _Poll __poll_;
64 memory_order __order_;
65
66 _LIBCPP_HIDE_FROM_ABI bool operator()() const {
67 auto __current_val = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_load(__a_, __order_);
68 return __poll_(__current_val);
69 }
70};
71
72#ifndef _LIBCPP_HAS_NO_THREADS
58#if _LIBCPP_STD_VER >= 20
59# if _LIBCPP_HAS_THREADS
7360
7461_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_one(void const volatile*) _NOEXCEPT;
7562_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 {
9380 _Poll __poll_;
9481 memory_order __order_;
9582
96 using __waitable_traits = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >;
83 using __waitable_traits _LIBCPP_NODEBUG = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >;
9784
9885 _LIBCPP_AVAILABILITY_SYNC
9986 _LIBCPP_HIDE_FROM_ABI bool
......@@ -120,15 +107,13 @@ struct __atomic_wait_backoff_impl {
120107
121108 _LIBCPP_AVAILABILITY_SYNC
122109 _LIBCPP_HIDE_FROM_ABI bool operator()(chrono::nanoseconds __elapsed) const {
123 if (__elapsed > chrono::microseconds(64)) {
110 if (__elapsed > chrono::microseconds(4)) {
124111 auto __contention_address = __waitable_traits::__atomic_contention_address(__a_);
125112 __cxx_contention_t __monitor_val;
126113 if (__update_monitor_val_and_poll(__contention_address, __monitor_val))
127114 return true;
128115 std::__libcpp_atomic_wait(__contention_address, __monitor_val);
129 } else if (__elapsed > chrono::microseconds(4))
130 __libcpp_thread_yield();
131 else {
116 } else {
132117 } // poll
133118 return false;
134119 }
......@@ -144,11 +129,16 @@ struct __atomic_wait_backoff_impl {
144129// value. The predicate function must not return `false` spuriously.
145130template <class _AtomicWaitable, class _Poll>
146131_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void
147__atomic_wait_unless(const _AtomicWaitable& __a, _Poll&& __poll, memory_order __order) {
132__atomic_wait_unless(const _AtomicWaitable& __a, memory_order __order, _Poll&& __poll) {
148133 static_assert(__atomic_waitable<_AtomicWaitable>::value, "");
149 __atomic_wait_poll_impl<_AtomicWaitable, __decay_t<_Poll> > __poll_impl = {__a, __poll, __order};
150134 __atomic_wait_backoff_impl<_AtomicWaitable, __decay_t<_Poll> > __backoff_fn = {__a, __poll, __order};
151 std::__libcpp_thread_poll_with_backoff(__poll_impl, __backoff_fn);
135 std::__libcpp_thread_poll_with_backoff(
136 /* poll */
137 [&]() {
138 auto __current_val = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_load(__a, __order);
139 return __poll(__current_val);
140 },
141 /* backoff */ __backoff_fn);
152142}
153143
154144template <class _AtomicWaitable>
......@@ -163,12 +153,17 @@ _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void __atomic_notify_all(const _
163153 std::__cxx_atomic_notify_all(__atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_contention_address(__a));
164154}
165155
166#else // _LIBCPP_HAS_NO_THREADS
156# else // _LIBCPP_HAS_THREADS
167157
168158template <class _AtomicWaitable, class _Poll>
169_LIBCPP_HIDE_FROM_ABI void __atomic_wait_unless(const _AtomicWaitable& __a, _Poll&& __poll, memory_order __order) {
170 __atomic_wait_poll_impl<_AtomicWaitable, __decay_t<_Poll> > __poll_fn = {__a, __poll, __order};
171 std::__libcpp_thread_poll_with_backoff(__poll_fn, __spinning_backoff_policy());
159_LIBCPP_HIDE_FROM_ABI void __atomic_wait_unless(const _AtomicWaitable& __a, memory_order __order, _Poll&& __poll) {
160 std::__libcpp_thread_poll_with_backoff(
161 /* poll */
162 [&]() {
163 auto __current_val = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_load(__a, __order);
164 return __poll(__current_val);
165 },
166 /* backoff */ __spinning_backoff_policy());
172167}
173168
174169template <class _AtomicWaitable>
......@@ -177,29 +172,24 @@ _LIBCPP_HIDE_FROM_ABI void __atomic_notify_one(const _AtomicWaitable&) {}
177172template <class _AtomicWaitable>
178173_LIBCPP_HIDE_FROM_ABI void __atomic_notify_all(const _AtomicWaitable&) {}
179174
180#endif // _LIBCPP_HAS_NO_THREADS
175# endif // _LIBCPP_HAS_THREADS
181176
182177template <typename _Tp>
183178_LIBCPP_HIDE_FROM_ABI bool __cxx_nonatomic_compare_equal(_Tp const& __lhs, _Tp const& __rhs) {
184179 return std::memcmp(std::addressof(__lhs), std::addressof(__rhs), sizeof(_Tp)) == 0;
185180}
186181
187template <class _Tp>
188struct __atomic_compare_unequal_to {
189 _Tp __val_;
190 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __arg) const {
191 return !std::__cxx_nonatomic_compare_equal(__arg, __val_);
192 }
193};
194
195template <class _AtomicWaitable, class _Up>
182template <class _AtomicWaitable, class _Tp>
196183_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void
197__atomic_wait(_AtomicWaitable& __a, _Up __val, memory_order __order) {
184__atomic_wait(_AtomicWaitable& __a, _Tp __val, memory_order __order) {
198185 static_assert(__atomic_waitable<_AtomicWaitable>::value, "");
199 __atomic_compare_unequal_to<_Up> __nonatomic_equal = {__val};
200 std::__atomic_wait_unless(__a, __nonatomic_equal, __order);
186 std::__atomic_wait_unless(__a, __order, [&](_Tp const& __current) {
187 return !std::__cxx_nonatomic_compare_equal(__current, __val);
188 });
201189}
202190
191#endif // C++20
192
203193_LIBCPP_END_NAMESPACE_STD
204194
205195#endif // _LIBCPP___ATOMIC_ATOMIC_SYNC_H
lib/libcxx/include/__atomic/contention_t.h+4-4
......@@ -9,7 +9,7 @@
99#ifndef _LIBCPP___ATOMIC_CONTENTION_T_H
1010#define _LIBCPP___ATOMIC_CONTENTION_T_H
1111
12#include <__atomic/cxx_atomic_impl.h>
12#include <__atomic/support.h>
1313#include <__config>
1414#include <cstdint>
1515
......@@ -20,12 +20,12 @@
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
2222#if defined(__linux__) || (defined(_AIX) && !defined(__64BIT__))
23using __cxx_contention_t = int32_t;
23using __cxx_contention_t _LIBCPP_NODEBUG = int32_t;
2424#else
25using __cxx_contention_t = int64_t;
25using __cxx_contention_t _LIBCPP_NODEBUG = int64_t;
2626#endif // __linux__ || (_AIX && !__64BIT__)
2727
28using __cxx_atomic_contention_t = __cxx_atomic_impl<__cxx_contention_t>;
28using __cxx_atomic_contention_t _LIBCPP_NODEBUG = __cxx_atomic_impl<__cxx_contention_t>;
2929
3030_LIBCPP_END_NAMESPACE_STD
3131
lib/libcxx/include/__atomic/cxx_atomic_impl.h deleted-510
......@@ -1,510 +0,0 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ATOMIC_CXX_ATOMIC_IMPL_H
10#define _LIBCPP___ATOMIC_CXX_ATOMIC_IMPL_H
11
12#include <__atomic/memory_order.h>
13#include <__atomic/to_gcc_order.h>
14#include <__config>
15#include <__memory/addressof.h>
16#include <__type_traits/is_assignable.h>
17#include <__type_traits/is_trivially_copyable.h>
18#include <__type_traits/remove_const.h>
19#include <cstddef>
20
21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22# pragma GCC system_header
23#endif
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
28
29// [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because
30// the default operator= in an object is not volatile, a byte-by-byte copy
31// is required.
32template <typename _Tp, typename _Tv, __enable_if_t<is_assignable<_Tp&, _Tv>::value, int> = 0>
33_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_assign_volatile(_Tp& __a_value, _Tv const& __val) {
34 __a_value = __val;
35}
36template <typename _Tp, typename _Tv, __enable_if_t<is_assignable<_Tp&, _Tv>::value, int> = 0>
37_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_assign_volatile(_Tp volatile& __a_value, _Tv volatile const& __val) {
38 volatile char* __to = reinterpret_cast<volatile char*>(std::addressof(__a_value));
39 volatile char* __end = __to + sizeof(_Tp);
40 volatile const char* __from = reinterpret_cast<volatile const char*>(std::addressof(__val));
41 while (__to != __end)
42 *__to++ = *__from++;
43}
44
45template <typename _Tp>
46struct __cxx_atomic_base_impl {
47 _LIBCPP_HIDE_FROM_ABI
48# ifndef _LIBCPP_CXX03_LANG
49 __cxx_atomic_base_impl() _NOEXCEPT = default;
50# else
51 __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {
52 }
53# endif // _LIBCPP_CXX03_LANG
54 _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT : __a_value(value) {}
55 _Tp __a_value;
56};
57
58template <typename _Tp>
59_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val) {
60 __cxx_atomic_assign_volatile(__a->__a_value, __val);
61}
62
63template <typename _Tp>
64_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) {
65 __a->__a_value = __val;
66}
67
68_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_thread_fence(memory_order __order) {
69 __atomic_thread_fence(__to_gcc_order(__order));
70}
71
72_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_signal_fence(memory_order __order) {
73 __atomic_signal_fence(__to_gcc_order(__order));
74}
75
76template <typename _Tp>
77_LIBCPP_HIDE_FROM_ABI void
78__cxx_atomic_store(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) {
79 __atomic_store(std::addressof(__a->__a_value), std::addressof(__val), __to_gcc_order(__order));
80}
81
82template <typename _Tp>
83_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) {
84 __atomic_store(std::addressof(__a->__a_value), std::addressof(__val), __to_gcc_order(__order));
85}
86
87template <typename _Tp>
88_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(const volatile __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) {
89 _Tp __ret;
90 __atomic_load(std::addressof(__a->__a_value), std::addressof(__ret), __to_gcc_order(__order));
91 return __ret;
92}
93
94template <typename _Tp>
95_LIBCPP_HIDE_FROM_ABI void
96__cxx_atomic_load_inplace(const volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __dst, memory_order __order) {
97 __atomic_load(std::addressof(__a->__a_value), __dst, __to_gcc_order(__order));
98}
99
100template <typename _Tp>
101_LIBCPP_HIDE_FROM_ABI void
102__cxx_atomic_load_inplace(const __cxx_atomic_base_impl<_Tp>* __a, _Tp* __dst, memory_order __order) {
103 __atomic_load(std::addressof(__a->__a_value), __dst, __to_gcc_order(__order));
104}
105
106template <typename _Tp>
107_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(const __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) {
108 _Tp __ret;
109 __atomic_load(std::addressof(__a->__a_value), std::addressof(__ret), __to_gcc_order(__order));
110 return __ret;
111}
112
113template <typename _Tp>
114_LIBCPP_HIDE_FROM_ABI _Tp
115__cxx_atomic_exchange(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) {
116 _Tp __ret;
117 __atomic_exchange(
118 std::addressof(__a->__a_value), std::addressof(__value), std::addressof(__ret), __to_gcc_order(__order));
119 return __ret;
120}
121
122template <typename _Tp>
123_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) {
124 _Tp __ret;
125 __atomic_exchange(
126 std::addressof(__a->__a_value), std::addressof(__value), std::addressof(__ret), __to_gcc_order(__order));
127 return __ret;
128}
129
130template <typename _Tp>
131_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong(
132 volatile __cxx_atomic_base_impl<_Tp>* __a,
133 _Tp* __expected,
134 _Tp __value,
135 memory_order __success,
136 memory_order __failure) {
137 return __atomic_compare_exchange(
138 std::addressof(__a->__a_value),
139 __expected,
140 std::addressof(__value),
141 false,
142 __to_gcc_order(__success),
143 __to_gcc_failure_order(__failure));
144}
145
146template <typename _Tp>
147_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong(
148 __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) {
149 return __atomic_compare_exchange(
150 std::addressof(__a->__a_value),
151 __expected,
152 std::addressof(__value),
153 false,
154 __to_gcc_order(__success),
155 __to_gcc_failure_order(__failure));
156}
157
158template <typename _Tp>
159_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak(
160 volatile __cxx_atomic_base_impl<_Tp>* __a,
161 _Tp* __expected,
162 _Tp __value,
163 memory_order __success,
164 memory_order __failure) {
165 return __atomic_compare_exchange(
166 std::addressof(__a->__a_value),
167 __expected,
168 std::addressof(__value),
169 true,
170 __to_gcc_order(__success),
171 __to_gcc_failure_order(__failure));
172}
173
174template <typename _Tp>
175_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak(
176 __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) {
177 return __atomic_compare_exchange(
178 std::addressof(__a->__a_value),
179 __expected,
180 std::addressof(__value),
181 true,
182 __to_gcc_order(__success),
183 __to_gcc_failure_order(__failure));
184}
185
186template <typename _Tp>
187struct __skip_amt {
188 enum { value = 1 };
189};
190
191template <typename _Tp>
192struct __skip_amt<_Tp*> {
193 enum { value = sizeof(_Tp) };
194};
195
196// FIXME: Haven't figured out what the spec says about using arrays with
197// atomic_fetch_add. Force a failure rather than creating bad behavior.
198template <typename _Tp>
199struct __skip_amt<_Tp[]> {};
200template <typename _Tp, int n>
201struct __skip_amt<_Tp[n]> {};
202
203template <typename _Tp, typename _Td>
204_LIBCPP_HIDE_FROM_ABI _Tp
205__cxx_atomic_fetch_add(volatile __cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) {
206 return __atomic_fetch_add(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order));
207}
208
209template <typename _Tp, typename _Td>
210_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) {
211 return __atomic_fetch_add(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order));
212}
213
214template <typename _Tp, typename _Td>
215_LIBCPP_HIDE_FROM_ABI _Tp
216__cxx_atomic_fetch_sub(volatile __cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) {
217 return __atomic_fetch_sub(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order));
218}
219
220template <typename _Tp, typename _Td>
221_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) {
222 return __atomic_fetch_sub(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order));
223}
224
225template <typename _Tp>
226_LIBCPP_HIDE_FROM_ABI _Tp
227__cxx_atomic_fetch_and(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
228 return __atomic_fetch_and(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
229}
230
231template <typename _Tp>
232_LIBCPP_HIDE_FROM_ABI _Tp
233__cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
234 return __atomic_fetch_and(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
235}
236
237template <typename _Tp>
238_LIBCPP_HIDE_FROM_ABI _Tp
239__cxx_atomic_fetch_or(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
240 return __atomic_fetch_or(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
241}
242
243template <typename _Tp>
244_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
245 return __atomic_fetch_or(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
246}
247
248template <typename _Tp>
249_LIBCPP_HIDE_FROM_ABI _Tp
250__cxx_atomic_fetch_xor(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
251 return __atomic_fetch_xor(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
252}
253
254template <typename _Tp>
255_LIBCPP_HIDE_FROM_ABI _Tp
256__cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
257 return __atomic_fetch_xor(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
258}
259
260# define __cxx_atomic_is_lock_free(__s) __atomic_is_lock_free(__s, 0)
261
262#elif defined(_LIBCPP_HAS_C_ATOMIC_IMP)
263
264template <typename _Tp>
265struct __cxx_atomic_base_impl {
266 _LIBCPP_HIDE_FROM_ABI
267# ifndef _LIBCPP_CXX03_LANG
268 __cxx_atomic_base_impl() _NOEXCEPT = default;
269# else
270 __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {
271 }
272# endif // _LIBCPP_CXX03_LANG
273 _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp __value) _NOEXCEPT : __a_value(__value) {}
274 _LIBCPP_DISABLE_EXTENSION_WARNING _Atomic(_Tp) __a_value;
275};
276
277# define __cxx_atomic_is_lock_free(__s) __c11_atomic_is_lock_free(__s)
278
279_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_thread_fence(memory_order __order) _NOEXCEPT {
280 __c11_atomic_thread_fence(static_cast<__memory_order_underlying_t>(__order));
281}
282
283_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_signal_fence(memory_order __order) _NOEXCEPT {
284 __c11_atomic_signal_fence(static_cast<__memory_order_underlying_t>(__order));
285}
286
287template <class _Tp>
288_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val) _NOEXCEPT {
289 __c11_atomic_init(std::addressof(__a->__a_value), __val);
290}
291template <class _Tp>
292_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) _NOEXCEPT {
293 __c11_atomic_init(std::addressof(__a->__a_value), __val);
294}
295
296template <class _Tp>
297_LIBCPP_HIDE_FROM_ABI void
298__cxx_atomic_store(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val, memory_order __order) _NOEXCEPT {
299 __c11_atomic_store(std::addressof(__a->__a_value), __val, static_cast<__memory_order_underlying_t>(__order));
300}
301template <class _Tp>
302_LIBCPP_HIDE_FROM_ABI void
303__cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) _NOEXCEPT {
304 __c11_atomic_store(std::addressof(__a->__a_value), __val, static_cast<__memory_order_underlying_t>(__order));
305}
306
307template <class _Tp>
308_LIBCPP_HIDE_FROM_ABI _Tp
309__cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const volatile* __a, memory_order __order) _NOEXCEPT {
310 using __ptr_type = __remove_const_t<decltype(__a->__a_value)>*;
311 return __c11_atomic_load(
312 const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order));
313}
314template <class _Tp>
315_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const* __a, memory_order __order) _NOEXCEPT {
316 using __ptr_type = __remove_const_t<decltype(__a->__a_value)>*;
317 return __c11_atomic_load(
318 const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order));
319}
320
321template <class _Tp>
322_LIBCPP_HIDE_FROM_ABI void
323__cxx_atomic_load_inplace(__cxx_atomic_base_impl<_Tp> const volatile* __a, _Tp* __dst, memory_order __order) _NOEXCEPT {
324 using __ptr_type = __remove_const_t<decltype(__a->__a_value)>*;
325 *__dst = __c11_atomic_load(
326 const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order));
327}
328template <class _Tp>
329_LIBCPP_HIDE_FROM_ABI void
330__cxx_atomic_load_inplace(__cxx_atomic_base_impl<_Tp> const* __a, _Tp* __dst, memory_order __order) _NOEXCEPT {
331 using __ptr_type = __remove_const_t<decltype(__a->__a_value)>*;
332 *__dst = __c11_atomic_load(
333 const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order));
334}
335
336template <class _Tp>
337_LIBCPP_HIDE_FROM_ABI _Tp
338__cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __value, memory_order __order) _NOEXCEPT {
339 return __c11_atomic_exchange(
340 std::addressof(__a->__a_value), __value, static_cast<__memory_order_underlying_t>(__order));
341}
342template <class _Tp>
343_LIBCPP_HIDE_FROM_ABI _Tp
344__cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) _NOEXCEPT {
345 return __c11_atomic_exchange(
346 std::addressof(__a->__a_value), __value, static_cast<__memory_order_underlying_t>(__order));
347}
348
349_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR memory_order __to_failure_order(memory_order __order) {
350 // Avoid switch statement to make this a constexpr.
351 return __order == memory_order_release
352 ? memory_order_relaxed
353 : (__order == memory_order_acq_rel ? memory_order_acquire : __order);
354}
355
356template <class _Tp>
357_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong(
358 __cxx_atomic_base_impl<_Tp> volatile* __a,
359 _Tp* __expected,
360 _Tp __value,
361 memory_order __success,
362 memory_order __failure) _NOEXCEPT {
363 return __c11_atomic_compare_exchange_strong(
364 std::addressof(__a->__a_value),
365 __expected,
366 __value,
367 static_cast<__memory_order_underlying_t>(__success),
368 static_cast<__memory_order_underlying_t>(__to_failure_order(__failure)));
369}
370template <class _Tp>
371_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong(
372 __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure)
373 _NOEXCEPT {
374 return __c11_atomic_compare_exchange_strong(
375 std::addressof(__a->__a_value),
376 __expected,
377 __value,
378 static_cast<__memory_order_underlying_t>(__success),
379 static_cast<__memory_order_underlying_t>(__to_failure_order(__failure)));
380}
381
382template <class _Tp>
383_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak(
384 __cxx_atomic_base_impl<_Tp> volatile* __a,
385 _Tp* __expected,
386 _Tp __value,
387 memory_order __success,
388 memory_order __failure) _NOEXCEPT {
389 return __c11_atomic_compare_exchange_weak(
390 std::addressof(__a->__a_value),
391 __expected,
392 __value,
393 static_cast<__memory_order_underlying_t>(__success),
394 static_cast<__memory_order_underlying_t>(__to_failure_order(__failure)));
395}
396template <class _Tp>
397_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak(
398 __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure)
399 _NOEXCEPT {
400 return __c11_atomic_compare_exchange_weak(
401 std::addressof(__a->__a_value),
402 __expected,
403 __value,
404 static_cast<__memory_order_underlying_t>(__success),
405 static_cast<__memory_order_underlying_t>(__to_failure_order(__failure)));
406}
407
408template <class _Tp>
409_LIBCPP_HIDE_FROM_ABI _Tp
410__cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
411 return __c11_atomic_fetch_add(
412 std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
413}
414template <class _Tp>
415_LIBCPP_HIDE_FROM_ABI _Tp
416__cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
417 return __c11_atomic_fetch_add(
418 std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
419}
420
421template <class _Tp>
422_LIBCPP_HIDE_FROM_ABI _Tp*
423__cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
424 return __c11_atomic_fetch_add(
425 std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
426}
427template <class _Tp>
428_LIBCPP_HIDE_FROM_ABI _Tp*
429__cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
430 return __c11_atomic_fetch_add(
431 std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
432}
433
434template <class _Tp>
435_LIBCPP_HIDE_FROM_ABI _Tp
436__cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
437 return __c11_atomic_fetch_sub(
438 std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
439}
440template <class _Tp>
441_LIBCPP_HIDE_FROM_ABI _Tp
442__cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
443 return __c11_atomic_fetch_sub(
444 std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
445}
446template <class _Tp>
447_LIBCPP_HIDE_FROM_ABI _Tp*
448__cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
449 return __c11_atomic_fetch_sub(
450 std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
451}
452template <class _Tp>
453_LIBCPP_HIDE_FROM_ABI _Tp*
454__cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
455 return __c11_atomic_fetch_sub(
456 std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
457}
458
459template <class _Tp>
460_LIBCPP_HIDE_FROM_ABI _Tp
461__cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
462 return __c11_atomic_fetch_and(
463 std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
464}
465template <class _Tp>
466_LIBCPP_HIDE_FROM_ABI _Tp
467__cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
468 return __c11_atomic_fetch_and(
469 std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
470}
471
472template <class _Tp>
473_LIBCPP_HIDE_FROM_ABI _Tp
474__cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
475 return __c11_atomic_fetch_or(
476 std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
477}
478template <class _Tp>
479_LIBCPP_HIDE_FROM_ABI _Tp
480__cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
481 return __c11_atomic_fetch_or(
482 std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
483}
484
485template <class _Tp>
486_LIBCPP_HIDE_FROM_ABI _Tp
487__cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
488 return __c11_atomic_fetch_xor(
489 std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
490}
491template <class _Tp>
492_LIBCPP_HIDE_FROM_ABI _Tp
493__cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
494 return __c11_atomic_fetch_xor(
495 std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
496}
497
498#endif // _LIBCPP_HAS_GCC_ATOMIC_IMP, _LIBCPP_HAS_C_ATOMIC_IMP
499
500template <typename _Tp, typename _Base = __cxx_atomic_base_impl<_Tp> >
501struct __cxx_atomic_impl : public _Base {
502 static_assert(is_trivially_copyable<_Tp>::value, "std::atomic<T> requires that 'T' be a trivially copyable type");
503
504 _LIBCPP_HIDE_FROM_ABI __cxx_atomic_impl() _NOEXCEPT = default;
505 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp __value) _NOEXCEPT : _Base(__value) {}
506};
507
508_LIBCPP_END_NAMESPACE_STD
509
510#endif // _LIBCPP___ATOMIC_CXX_ATOMIC_IMPL_H
lib/libcxx/include/__atomic/fence.h+1-1
......@@ -9,8 +9,8 @@
99#ifndef _LIBCPP___ATOMIC_FENCE_H
1010#define _LIBCPP___ATOMIC_FENCE_H
1111
12#include <__atomic/cxx_atomic_impl.h>
1312#include <__atomic/memory_order.h>
13#include <__atomic/support.h>
1414#include <__config>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__atomic/memory_order.h+1-1
......@@ -24,7 +24,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2424// to pin the underlying type in C++20.
2525enum __legacy_memory_order { __mo_relaxed, __mo_consume, __mo_acquire, __mo_release, __mo_acq_rel, __mo_seq_cst };
2626
27using __memory_order_underlying_t = underlying_type<__legacy_memory_order>::type;
27using __memory_order_underlying_t _LIBCPP_NODEBUG = underlying_type<__legacy_memory_order>::type;
2828
2929#if _LIBCPP_STD_VER >= 20
3030
lib/libcxx/include/__atomic/support.h created+124
......@@ -0,0 +1,124 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ATOMIC_SUPPORT_H
10#define _LIBCPP___ATOMIC_SUPPORT_H
11
12#include <__config>
13#include <__type_traits/is_trivially_copyable.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19//
20// This file implements base support for atomics on the platform.
21//
22// The following operations and types must be implemented (where _Atmc
23// is __cxx_atomic_base_impl for readability):
24//
25// clang-format off
26//
27// template <class _Tp>
28// struct __cxx_atomic_base_impl;
29//
30// #define __cxx_atomic_is_lock_free(__size)
31//
32// void __cxx_atomic_thread_fence(memory_order __order) noexcept;
33// void __cxx_atomic_signal_fence(memory_order __order) noexcept;
34//
35// template <class _Tp>
36// void __cxx_atomic_init(_Atmc<_Tp> volatile* __a, _Tp __val) noexcept;
37// template <class _Tp>
38// void __cxx_atomic_init(_Atmc<_Tp>* __a, _Tp __val) noexcept;
39//
40// template <class _Tp>
41// void __cxx_atomic_store(_Atmc<_Tp> volatile* __a, _Tp __val, memory_order __order) noexcept;
42// template <class _Tp>
43// void __cxx_atomic_store(_Atmc<_Tp>* __a, _Tp __val, memory_order __order) noexcept;
44//
45// template <class _Tp>
46// _Tp __cxx_atomic_load(_Atmc<_Tp> const volatile* __a, memory_order __order) noexcept;
47// template <class _Tp>
48// _Tp __cxx_atomic_load(_Atmc<_Tp> const* __a, memory_order __order) noexcept;
49//
50// template <class _Tp>
51// void __cxx_atomic_load_inplace(_Atmc<_Tp> const volatile* __a, _Tp* __dst, memory_order __order) noexcept;
52// template <class _Tp>
53// void __cxx_atomic_load_inplace(_Atmc<_Tp> const* __a, _Tp* __dst, memory_order __order) noexcept;
54//
55// template <class _Tp>
56// _Tp __cxx_atomic_exchange(_Atmc<_Tp> volatile* __a, _Tp __value, memory_order __order) noexcept;
57// template <class _Tp>
58// _Tp __cxx_atomic_exchange(_Atmc<_Tp>* __a, _Tp __value, memory_order __order) noexcept;
59//
60// template <class _Tp>
61// bool __cxx_atomic_compare_exchange_strong(_Atmc<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) noexcept;
62// template <class _Tp>
63// bool __cxx_atomic_compare_exchange_strong(_Atmc<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) noexcept;
64//
65// template <class _Tp>
66// bool __cxx_atomic_compare_exchange_weak(_Atmc<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) noexcept;
67// template <class _Tp>
68// bool __cxx_atomic_compare_exchange_weak(_Atmc<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) noexcept;
69//
70// template <class _Tp>
71// _Tp __cxx_atomic_fetch_add(_Atmc<_Tp> volatile* __a, _Tp __delta, memory_order __order) noexcept;
72// template <class _Tp>
73// _Tp __cxx_atomic_fetch_add(_Atmc<_Tp>* __a, _Tp __delta, memory_order __order) noexcept;
74//
75// template <class _Tp>
76// _Tp* __cxx_atomic_fetch_add(_Atmc<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) noexcept;
77// template <class _Tp>
78// _Tp* __cxx_atomic_fetch_add(_Atmc<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) noexcept;
79//
80// template <class _Tp>
81// _Tp __cxx_atomic_fetch_sub(_Atmc<_Tp> volatile* __a, _Tp __delta, memory_order __order) noexcept;
82// template <class _Tp>
83// _Tp __cxx_atomic_fetch_sub(_Atmc<_Tp>* __a, _Tp __delta, memory_order __order) noexcept;
84// template <class _Tp>
85// _Tp* __cxx_atomic_fetch_sub(_Atmc<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) noexcept;
86// template <class _Tp>
87// _Tp* __cxx_atomic_fetch_sub(_Atmc<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) noexcept;
88//
89// template <class _Tp>
90// _Tp __cxx_atomic_fetch_and(_Atmc<_Tp> volatile* __a, _Tp __pattern, memory_order __order) noexcept;
91// template <class _Tp>
92// _Tp __cxx_atomic_fetch_and(_Atmc<_Tp>* __a, _Tp __pattern, memory_order __order) noexcept;
93//
94// template <class _Tp>
95// _Tp __cxx_atomic_fetch_or(_Atmc<_Tp> volatile* __a, _Tp __pattern, memory_order __order) noexcept;
96// template <class _Tp>
97// _Tp __cxx_atomic_fetch_or(_Atmc<_Tp>* __a, _Tp __pattern, memory_order __order) noexcept;
98// template <class _Tp>
99// _Tp __cxx_atomic_fetch_xor(_Atmc<_Tp> volatile* __a, _Tp __pattern, memory_order __order) noexcept;
100// template <class _Tp>
101// _Tp __cxx_atomic_fetch_xor(_Atmc<_Tp>* __a, _Tp __pattern, memory_order __order) noexcept;
102//
103// clang-format on
104//
105
106#if _LIBCPP_HAS_GCC_ATOMIC_IMP
107# include <__atomic/support/gcc.h>
108#elif _LIBCPP_HAS_C_ATOMIC_IMP
109# include <__atomic/support/c11.h>
110#endif
111
112_LIBCPP_BEGIN_NAMESPACE_STD
113
114template <typename _Tp, typename _Base = __cxx_atomic_base_impl<_Tp> >
115struct __cxx_atomic_impl : public _Base {
116 static_assert(is_trivially_copyable<_Tp>::value, "std::atomic<T> requires that 'T' be a trivially copyable type");
117
118 _LIBCPP_HIDE_FROM_ABI __cxx_atomic_impl() _NOEXCEPT = default;
119 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp __value) _NOEXCEPT : _Base(__value) {}
120};
121
122_LIBCPP_END_NAMESPACE_STD
123
124#endif // _LIBCPP___ATOMIC_SUPPORT_H
lib/libcxx/include/__atomic/support/c11.h created+264
......@@ -0,0 +1,264 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ATOMIC_SUPPORT_C11_H
10#define _LIBCPP___ATOMIC_SUPPORT_C11_H
11
12#include <__atomic/memory_order.h>
13#include <__config>
14#include <__cstddef/ptrdiff_t.h>
15#include <__memory/addressof.h>
16#include <__type_traits/remove_const.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22//
23// This file implements support for C11-style atomics
24//
25
26_LIBCPP_BEGIN_NAMESPACE_STD
27
28template <typename _Tp>
29struct __cxx_atomic_base_impl {
30 _LIBCPP_HIDE_FROM_ABI
31#ifndef _LIBCPP_CXX03_LANG
32 __cxx_atomic_base_impl() _NOEXCEPT = default;
33#else
34 __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {
35 }
36#endif // _LIBCPP_CXX03_LANG
37 _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp __value) _NOEXCEPT : __a_value(__value) {}
38 _LIBCPP_DISABLE_EXTENSION_WARNING _Atomic(_Tp) __a_value;
39};
40
41#define __cxx_atomic_is_lock_free(__s) __c11_atomic_is_lock_free(__s)
42
43_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_thread_fence(memory_order __order) _NOEXCEPT {
44 __c11_atomic_thread_fence(static_cast<__memory_order_underlying_t>(__order));
45}
46
47_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_signal_fence(memory_order __order) _NOEXCEPT {
48 __c11_atomic_signal_fence(static_cast<__memory_order_underlying_t>(__order));
49}
50
51template <class _Tp>
52_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val) _NOEXCEPT {
53 __c11_atomic_init(std::addressof(__a->__a_value), __val);
54}
55template <class _Tp>
56_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) _NOEXCEPT {
57 __c11_atomic_init(std::addressof(__a->__a_value), __val);
58}
59
60template <class _Tp>
61_LIBCPP_HIDE_FROM_ABI void
62__cxx_atomic_store(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val, memory_order __order) _NOEXCEPT {
63 __c11_atomic_store(std::addressof(__a->__a_value), __val, static_cast<__memory_order_underlying_t>(__order));
64}
65template <class _Tp>
66_LIBCPP_HIDE_FROM_ABI void
67__cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) _NOEXCEPT {
68 __c11_atomic_store(std::addressof(__a->__a_value), __val, static_cast<__memory_order_underlying_t>(__order));
69}
70
71template <class _Tp>
72_LIBCPP_HIDE_FROM_ABI _Tp
73__cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const volatile* __a, memory_order __order) _NOEXCEPT {
74 using __ptr_type = __remove_const_t<decltype(__a->__a_value)>*;
75 return __c11_atomic_load(
76 const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order));
77}
78template <class _Tp>
79_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const* __a, memory_order __order) _NOEXCEPT {
80 using __ptr_type = __remove_const_t<decltype(__a->__a_value)>*;
81 return __c11_atomic_load(
82 const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order));
83}
84
85template <class _Tp>
86_LIBCPP_HIDE_FROM_ABI void
87__cxx_atomic_load_inplace(__cxx_atomic_base_impl<_Tp> const volatile* __a, _Tp* __dst, memory_order __order) _NOEXCEPT {
88 using __ptr_type = __remove_const_t<decltype(__a->__a_value)>*;
89 *__dst = __c11_atomic_load(
90 const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order));
91}
92template <class _Tp>
93_LIBCPP_HIDE_FROM_ABI void
94__cxx_atomic_load_inplace(__cxx_atomic_base_impl<_Tp> const* __a, _Tp* __dst, memory_order __order) _NOEXCEPT {
95 using __ptr_type = __remove_const_t<decltype(__a->__a_value)>*;
96 *__dst = __c11_atomic_load(
97 const_cast<__ptr_type>(std::addressof(__a->__a_value)), static_cast<__memory_order_underlying_t>(__order));
98}
99
100template <class _Tp>
101_LIBCPP_HIDE_FROM_ABI _Tp
102__cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __value, memory_order __order) _NOEXCEPT {
103 return __c11_atomic_exchange(
104 std::addressof(__a->__a_value), __value, static_cast<__memory_order_underlying_t>(__order));
105}
106template <class _Tp>
107_LIBCPP_HIDE_FROM_ABI _Tp
108__cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) _NOEXCEPT {
109 return __c11_atomic_exchange(
110 std::addressof(__a->__a_value), __value, static_cast<__memory_order_underlying_t>(__order));
111}
112
113_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR memory_order __to_failure_order(memory_order __order) {
114 // Avoid switch statement to make this a constexpr.
115 return __order == memory_order_release
116 ? memory_order_relaxed
117 : (__order == memory_order_acq_rel ? memory_order_acquire : __order);
118}
119
120template <class _Tp>
121_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong(
122 __cxx_atomic_base_impl<_Tp> volatile* __a,
123 _Tp* __expected,
124 _Tp __value,
125 memory_order __success,
126 memory_order __failure) _NOEXCEPT {
127 return __c11_atomic_compare_exchange_strong(
128 std::addressof(__a->__a_value),
129 __expected,
130 __value,
131 static_cast<__memory_order_underlying_t>(__success),
132 static_cast<__memory_order_underlying_t>(__to_failure_order(__failure)));
133}
134template <class _Tp>
135_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong(
136 __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure)
137 _NOEXCEPT {
138 return __c11_atomic_compare_exchange_strong(
139 std::addressof(__a->__a_value),
140 __expected,
141 __value,
142 static_cast<__memory_order_underlying_t>(__success),
143 static_cast<__memory_order_underlying_t>(__to_failure_order(__failure)));
144}
145
146template <class _Tp>
147_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak(
148 __cxx_atomic_base_impl<_Tp> volatile* __a,
149 _Tp* __expected,
150 _Tp __value,
151 memory_order __success,
152 memory_order __failure) _NOEXCEPT {
153 return __c11_atomic_compare_exchange_weak(
154 std::addressof(__a->__a_value),
155 __expected,
156 __value,
157 static_cast<__memory_order_underlying_t>(__success),
158 static_cast<__memory_order_underlying_t>(__to_failure_order(__failure)));
159}
160template <class _Tp>
161_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak(
162 __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure)
163 _NOEXCEPT {
164 return __c11_atomic_compare_exchange_weak(
165 std::addressof(__a->__a_value),
166 __expected,
167 __value,
168 static_cast<__memory_order_underlying_t>(__success),
169 static_cast<__memory_order_underlying_t>(__to_failure_order(__failure)));
170}
171
172template <class _Tp>
173_LIBCPP_HIDE_FROM_ABI _Tp
174__cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
175 return __c11_atomic_fetch_add(
176 std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
177}
178template <class _Tp>
179_LIBCPP_HIDE_FROM_ABI _Tp
180__cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
181 return __c11_atomic_fetch_add(
182 std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
183}
184
185template <class _Tp>
186_LIBCPP_HIDE_FROM_ABI _Tp*
187__cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
188 return __c11_atomic_fetch_add(
189 std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
190}
191template <class _Tp>
192_LIBCPP_HIDE_FROM_ABI _Tp*
193__cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
194 return __c11_atomic_fetch_add(
195 std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
196}
197
198template <class _Tp>
199_LIBCPP_HIDE_FROM_ABI _Tp
200__cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
201 return __c11_atomic_fetch_sub(
202 std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
203}
204template <class _Tp>
205_LIBCPP_HIDE_FROM_ABI _Tp
206__cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
207 return __c11_atomic_fetch_sub(
208 std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
209}
210template <class _Tp>
211_LIBCPP_HIDE_FROM_ABI _Tp*
212__cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
213 return __c11_atomic_fetch_sub(
214 std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
215}
216template <class _Tp>
217_LIBCPP_HIDE_FROM_ABI _Tp*
218__cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
219 return __c11_atomic_fetch_sub(
220 std::addressof(__a->__a_value), __delta, static_cast<__memory_order_underlying_t>(__order));
221}
222
223template <class _Tp>
224_LIBCPP_HIDE_FROM_ABI _Tp
225__cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
226 return __c11_atomic_fetch_and(
227 std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
228}
229template <class _Tp>
230_LIBCPP_HIDE_FROM_ABI _Tp
231__cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
232 return __c11_atomic_fetch_and(
233 std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
234}
235
236template <class _Tp>
237_LIBCPP_HIDE_FROM_ABI _Tp
238__cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
239 return __c11_atomic_fetch_or(
240 std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
241}
242template <class _Tp>
243_LIBCPP_HIDE_FROM_ABI _Tp
244__cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
245 return __c11_atomic_fetch_or(
246 std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
247}
248
249template <class _Tp>
250_LIBCPP_HIDE_FROM_ABI _Tp
251__cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
252 return __c11_atomic_fetch_xor(
253 std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
254}
255template <class _Tp>
256_LIBCPP_HIDE_FROM_ABI _Tp
257__cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
258 return __c11_atomic_fetch_xor(
259 std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order));
260}
261
262_LIBCPP_END_NAMESPACE_STD
263
264#endif // _LIBCPP___ATOMIC_SUPPORT_C11_H
lib/libcxx/include/__atomic/support/gcc.h created+265
......@@ -0,0 +1,265 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ATOMIC_SUPPORT_GCC_H
10#define _LIBCPP___ATOMIC_SUPPORT_GCC_H
11
12#include <__atomic/memory_order.h>
13#include <__atomic/to_gcc_order.h>
14#include <__config>
15#include <__memory/addressof.h>
16#include <__type_traits/enable_if.h>
17#include <__type_traits/is_assignable.h>
18#include <__type_traits/remove_const.h>
19
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21# pragma GCC system_header
22#endif
23
24//
25// This file implements support for GCC-style atomics
26//
27
28_LIBCPP_BEGIN_NAMESPACE_STD
29
30// [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because
31// the default operator= in an object is not volatile, a byte-by-byte copy
32// is required.
33template <typename _Tp, typename _Tv, __enable_if_t<is_assignable<_Tp&, _Tv>::value, int> = 0>
34_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_assign_volatile(_Tp& __a_value, _Tv const& __val) {
35 __a_value = __val;
36}
37template <typename _Tp, typename _Tv, __enable_if_t<is_assignable<_Tp&, _Tv>::value, int> = 0>
38_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_assign_volatile(_Tp volatile& __a_value, _Tv volatile const& __val) {
39 volatile char* __to = reinterpret_cast<volatile char*>(std::addressof(__a_value));
40 volatile char* __end = __to + sizeof(_Tp);
41 volatile const char* __from = reinterpret_cast<volatile const char*>(std::addressof(__val));
42 while (__to != __end)
43 *__to++ = *__from++;
44}
45
46template <typename _Tp>
47struct __cxx_atomic_base_impl {
48 _LIBCPP_HIDE_FROM_ABI
49#ifndef _LIBCPP_CXX03_LANG
50 __cxx_atomic_base_impl() _NOEXCEPT = default;
51#else
52 __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {
53 }
54#endif // _LIBCPP_CXX03_LANG
55 _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT : __a_value(value) {}
56 _Tp __a_value;
57};
58
59template <typename _Tp>
60_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val) {
61 __cxx_atomic_assign_volatile(__a->__a_value, __val);
62}
63
64template <typename _Tp>
65_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) {
66 __a->__a_value = __val;
67}
68
69_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_thread_fence(memory_order __order) {
70 __atomic_thread_fence(__to_gcc_order(__order));
71}
72
73_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_signal_fence(memory_order __order) {
74 __atomic_signal_fence(__to_gcc_order(__order));
75}
76
77template <typename _Tp>
78_LIBCPP_HIDE_FROM_ABI void
79__cxx_atomic_store(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) {
80 __atomic_store(std::addressof(__a->__a_value), std::addressof(__val), __to_gcc_order(__order));
81}
82
83template <typename _Tp>
84_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) {
85 __atomic_store(std::addressof(__a->__a_value), std::addressof(__val), __to_gcc_order(__order));
86}
87
88template <typename _Tp>
89_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(const volatile __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) {
90 _Tp __ret;
91 __atomic_load(std::addressof(__a->__a_value), std::addressof(__ret), __to_gcc_order(__order));
92 return __ret;
93}
94
95template <typename _Tp>
96_LIBCPP_HIDE_FROM_ABI void
97__cxx_atomic_load_inplace(const volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __dst, memory_order __order) {
98 __atomic_load(std::addressof(__a->__a_value), __dst, __to_gcc_order(__order));
99}
100
101template <typename _Tp>
102_LIBCPP_HIDE_FROM_ABI void
103__cxx_atomic_load_inplace(const __cxx_atomic_base_impl<_Tp>* __a, _Tp* __dst, memory_order __order) {
104 __atomic_load(std::addressof(__a->__a_value), __dst, __to_gcc_order(__order));
105}
106
107template <typename _Tp>
108_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(const __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) {
109 _Tp __ret;
110 __atomic_load(std::addressof(__a->__a_value), std::addressof(__ret), __to_gcc_order(__order));
111 return __ret;
112}
113
114template <typename _Tp>
115_LIBCPP_HIDE_FROM_ABI _Tp
116__cxx_atomic_exchange(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) {
117 _Tp __ret;
118 __atomic_exchange(
119 std::addressof(__a->__a_value), std::addressof(__value), std::addressof(__ret), __to_gcc_order(__order));
120 return __ret;
121}
122
123template <typename _Tp>
124_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) {
125 _Tp __ret;
126 __atomic_exchange(
127 std::addressof(__a->__a_value), std::addressof(__value), std::addressof(__ret), __to_gcc_order(__order));
128 return __ret;
129}
130
131template <typename _Tp>
132_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong(
133 volatile __cxx_atomic_base_impl<_Tp>* __a,
134 _Tp* __expected,
135 _Tp __value,
136 memory_order __success,
137 memory_order __failure) {
138 return __atomic_compare_exchange(
139 std::addressof(__a->__a_value),
140 __expected,
141 std::addressof(__value),
142 false,
143 __to_gcc_order(__success),
144 __to_gcc_failure_order(__failure));
145}
146
147template <typename _Tp>
148_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong(
149 __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) {
150 return __atomic_compare_exchange(
151 std::addressof(__a->__a_value),
152 __expected,
153 std::addressof(__value),
154 false,
155 __to_gcc_order(__success),
156 __to_gcc_failure_order(__failure));
157}
158
159template <typename _Tp>
160_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak(
161 volatile __cxx_atomic_base_impl<_Tp>* __a,
162 _Tp* __expected,
163 _Tp __value,
164 memory_order __success,
165 memory_order __failure) {
166 return __atomic_compare_exchange(
167 std::addressof(__a->__a_value),
168 __expected,
169 std::addressof(__value),
170 true,
171 __to_gcc_order(__success),
172 __to_gcc_failure_order(__failure));
173}
174
175template <typename _Tp>
176_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak(
177 __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) {
178 return __atomic_compare_exchange(
179 std::addressof(__a->__a_value),
180 __expected,
181 std::addressof(__value),
182 true,
183 __to_gcc_order(__success),
184 __to_gcc_failure_order(__failure));
185}
186
187template <typename _Tp>
188struct __skip_amt {
189 enum { value = 1 };
190};
191
192template <typename _Tp>
193struct __skip_amt<_Tp*> {
194 enum { value = sizeof(_Tp) };
195};
196
197// FIXME: Haven't figured out what the spec says about using arrays with
198// atomic_fetch_add. Force a failure rather than creating bad behavior.
199template <typename _Tp>
200struct __skip_amt<_Tp[]> {};
201template <typename _Tp, int n>
202struct __skip_amt<_Tp[n]> {};
203
204template <typename _Tp, typename _Td>
205_LIBCPP_HIDE_FROM_ABI _Tp
206__cxx_atomic_fetch_add(volatile __cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) {
207 return __atomic_fetch_add(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order));
208}
209
210template <typename _Tp, typename _Td>
211_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) {
212 return __atomic_fetch_add(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order));
213}
214
215template <typename _Tp, typename _Td>
216_LIBCPP_HIDE_FROM_ABI _Tp
217__cxx_atomic_fetch_sub(volatile __cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) {
218 return __atomic_fetch_sub(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order));
219}
220
221template <typename _Tp, typename _Td>
222_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) {
223 return __atomic_fetch_sub(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order));
224}
225
226template <typename _Tp>
227_LIBCPP_HIDE_FROM_ABI _Tp
228__cxx_atomic_fetch_and(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
229 return __atomic_fetch_and(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
230}
231
232template <typename _Tp>
233_LIBCPP_HIDE_FROM_ABI _Tp
234__cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
235 return __atomic_fetch_and(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
236}
237
238template <typename _Tp>
239_LIBCPP_HIDE_FROM_ABI _Tp
240__cxx_atomic_fetch_or(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
241 return __atomic_fetch_or(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
242}
243
244template <typename _Tp>
245_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
246 return __atomic_fetch_or(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
247}
248
249template <typename _Tp>
250_LIBCPP_HIDE_FROM_ABI _Tp
251__cxx_atomic_fetch_xor(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
252 return __atomic_fetch_xor(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
253}
254
255template <typename _Tp>
256_LIBCPP_HIDE_FROM_ABI _Tp
257__cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) {
258 return __atomic_fetch_xor(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order));
259}
260
261#define __cxx_atomic_is_lock_free(__s) __atomic_is_lock_free(__s, 0)
262
263_LIBCPP_END_NAMESPACE_STD
264
265#endif // _LIBCPP___ATOMIC_SUPPORT_GCC_H
lib/libcxx/include/__bit/bit_cast.h+1-1
......@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#ifndef _LIBCPP_CXX03_LANG
2323
2424template <class _ToType, class _FromType>
25_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI constexpr _ToType __bit_cast(const _FromType& __from) noexcept {
25[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr _ToType __bit_cast(const _FromType& __from) noexcept {
2626 return __builtin_bit_cast(_ToType, __from);
2727}
2828
lib/libcxx/include/__bit/bit_log2.h+6-5
......@@ -10,8 +10,8 @@
1010#define _LIBCPP___BIT_BIT_LOG2_H
1111
1212#include <__bit/countl.h>
13#include <__concepts/arithmetic.h>
1413#include <__config>
14#include <__type_traits/is_unsigned_integer.h>
1515#include <limits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -20,14 +20,15 @@
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if _LIBCPP_STD_VER >= 20
23#if _LIBCPP_STD_VER >= 14
2424
25template <__libcpp_unsigned_integer _Tp>
25template <class _Tp>
2626_LIBCPP_HIDE_FROM_ABI constexpr _Tp __bit_log2(_Tp __t) noexcept {
27 return numeric_limits<_Tp>::digits - 1 - std::countl_zero(__t);
27 static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__bit_log2 requires an unsigned integer type");
28 return numeric_limits<_Tp>::digits - 1 - std::__countl_zero(__t);
2829}
2930
30#endif // _LIBCPP_STD_VER >= 20
31#endif // _LIBCPP_STD_VER >= 14
3132
3233_LIBCPP_END_NAMESPACE_STD
3334
lib/libcxx/include/__bit/byteswap.h+2-2
......@@ -32,7 +32,7 @@ template <integral _Tp>
3232 return __builtin_bswap32(__val);
3333 } else if constexpr (sizeof(_Tp) == 8) {
3434 return __builtin_bswap64(__val);
35# ifndef _LIBCPP_HAS_NO_INT128
35# if _LIBCPP_HAS_INT128
3636 } else if constexpr (sizeof(_Tp) == 16) {
3737# if __has_builtin(__builtin_bswap128)
3838 return __builtin_bswap128(__val);
......@@ -40,7 +40,7 @@ template <integral _Tp>
4040 return static_cast<_Tp>(byteswap(static_cast<uint64_t>(__val))) << 64 |
4141 static_cast<_Tp>(byteswap(static_cast<uint64_t>(__val >> 64)));
4242# endif // __has_builtin(__builtin_bswap128)
43# endif // _LIBCPP_HAS_NO_INT128
43# endif // _LIBCPP_HAS_INT128
4444 } else {
4545 static_assert(sizeof(_Tp) == 0, "byteswap is unimplemented for integral types of this size");
4646 }
lib/libcxx/include/__bit/countl.h+5-5
......@@ -27,19 +27,19 @@ _LIBCPP_PUSH_MACROS
2727
2828_LIBCPP_BEGIN_NAMESPACE_STD
2929
30_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned __x) _NOEXCEPT {
30[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned __x) _NOEXCEPT {
3131 return __builtin_clz(__x);
3232}
3333
34_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned long __x) _NOEXCEPT {
34[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned long __x) _NOEXCEPT {
3535 return __builtin_clzl(__x);
3636}
3737
38_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned long long __x) _NOEXCEPT {
38[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned long long __x) _NOEXCEPT {
3939 return __builtin_clzll(__x);
4040}
4141
42#ifndef _LIBCPP_HAS_NO_INT128
42#if _LIBCPP_HAS_INT128
4343inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(__uint128_t __x) _NOEXCEPT {
4444# if __has_builtin(__builtin_clzg)
4545 return __builtin_clzg(__x);
......@@ -57,7 +57,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(__uint128_t __x)
5757 : __builtin_clzll(static_cast<unsigned long long>(__x >> 64));
5858# endif
5959}
60#endif // _LIBCPP_HAS_NO_INT128
60#endif // _LIBCPP_HAS_INT128
6161
6262template <class _Tp>
6363_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int __countl_zero(_Tp __t) _NOEXCEPT {
lib/libcxx/include/__bit/countr.h+4-4
......@@ -26,20 +26,20 @@ _LIBCPP_PUSH_MACROS
2626
2727_LIBCPP_BEGIN_NAMESPACE_STD
2828
29_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned __x) _NOEXCEPT {
29[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned __x) _NOEXCEPT {
3030 return __builtin_ctz(__x);
3131}
3232
33_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned long __x) _NOEXCEPT {
33[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned long __x) _NOEXCEPT {
3434 return __builtin_ctzl(__x);
3535}
3636
37_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned long long __x) _NOEXCEPT {
37[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned long long __x) _NOEXCEPT {
3838 return __builtin_ctzll(__x);
3939}
4040
4141template <class _Tp>
42_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int __countr_zero(_Tp __t) _NOEXCEPT {
42[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int __countr_zero(_Tp __t) _NOEXCEPT {
4343#if __has_builtin(__builtin_ctzg)
4444 return __builtin_ctzg(__t, numeric_limits<_Tp>::digits);
4545#else // __has_builtin(__builtin_ctzg)
lib/libcxx/include/__bit/rotate.h+8-8
......@@ -26,31 +26,31 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2626template <class _Tp>
2727_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __rotl(_Tp __x, int __s) _NOEXCEPT {
2828 static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotl requires an unsigned integer type");
29 const int __N = numeric_limits<_Tp>::digits;
30 int __r = __s % __N;
29 const int __n = numeric_limits<_Tp>::digits;
30 int __r = __s % __n;
3131
3232 if (__r == 0)
3333 return __x;
3434
3535 if (__r > 0)
36 return (__x << __r) | (__x >> (__N - __r));
36 return (__x << __r) | (__x >> (__n - __r));
3737
38 return (__x >> -__r) | (__x << (__N + __r));
38 return (__x >> -__r) | (__x << (__n + __r));
3939}
4040
4141template <class _Tp>
4242_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __rotr(_Tp __x, int __s) _NOEXCEPT {
4343 static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotr requires an unsigned integer type");
44 const int __N = numeric_limits<_Tp>::digits;
45 int __r = __s % __N;
44 const int __n = numeric_limits<_Tp>::digits;
45 int __r = __s % __n;
4646
4747 if (__r == 0)
4848 return __x;
4949
5050 if (__r > 0)
51 return (__x >> __r) | (__x << (__N - __r));
51 return (__x >> __r) | (__x << (__n - __r));
5252
53 return (__x << -__r) | (__x >> (__N + __r));
53 return (__x << -__r) | (__x >> (__n + __r));
5454}
5555
5656#if _LIBCPP_STD_VER >= 20
lib/libcxx/include/__bit_reference+33-21
......@@ -11,20 +11,20 @@
1111#define _LIBCPP___BIT_REFERENCE
1212
1313#include <__algorithm/copy_n.h>
14#include <__algorithm/fill_n.h>
1514#include <__algorithm/min.h>
1615#include <__bit/countr.h>
17#include <__bit/invert_if.h>
18#include <__bit/popcount.h>
1916#include <__compare/ordering.h>
2017#include <__config>
18#include <__cstddef/ptrdiff_t.h>
19#include <__cstddef/size_t.h>
2120#include <__fwd/bit_reference.h>
2221#include <__iterator/iterator_traits.h>
2322#include <__memory/construct_at.h>
2423#include <__memory/pointer_traits.h>
2524#include <__type_traits/conditional.h>
25#include <__type_traits/is_constant_evaluated.h>
26#include <__type_traits/void_t.h>
2627#include <__utility/swap.h>
27#include <cstring>
2828
2929#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3030# pragma GCC system_header
......@@ -43,10 +43,22 @@ struct __has_storage_type {
4343 static const bool value = false;
4444};
4545
46template <class, class>
47struct __size_difference_type_traits {
48 using difference_type = ptrdiff_t;
49 using size_type = size_t;
50};
51
52template <class _Cp>
53struct __size_difference_type_traits<_Cp, __void_t<typename _Cp::difference_type, typename _Cp::size_type> > {
54 using difference_type = typename _Cp::difference_type;
55 using size_type = typename _Cp::size_type;
56};
57
4658template <class _Cp, bool = __has_storage_type<_Cp>::value>
4759class __bit_reference {
48 using __storage_type = typename _Cp::__storage_type;
49 using __storage_pointer = typename _Cp::__storage_pointer;
60 using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type;
61 using __storage_pointer _LIBCPP_NODEBUG = typename _Cp::__storage_pointer;
5062
5163 __storage_pointer __seg_;
5264 __storage_type __mask_;
......@@ -57,7 +69,7 @@ class __bit_reference {
5769 friend class __bit_iterator<_Cp, false>;
5870
5971public:
60 using __container = typename _Cp::__self;
72 using __container _LIBCPP_NODEBUG = typename _Cp::__self;
6173
6274 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_reference(const __bit_reference&) = default;
6375
......@@ -137,8 +149,8 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(bool& __x,
137149
138150template <class _Cp>
139151class __bit_const_reference {
140 using __storage_type = typename _Cp::__storage_type;
141 using __storage_pointer = typename _Cp::__const_storage_pointer;
152 using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type;
153 using __storage_pointer _LIBCPP_NODEBUG = typename _Cp::__const_storage_pointer;
142154
143155 __storage_pointer __seg_;
144156 __storage_type __mask_;
......@@ -147,7 +159,7 @@ class __bit_const_reference {
147159 friend class __bit_iterator<_Cp, true>;
148160
149161public:
150 using __container = typename _Cp::__self;
162 using __container _LIBCPP_NODEBUG = typename _Cp::__self;
151163
152164 _LIBCPP_HIDE_FROM_ABI __bit_const_reference(const __bit_const_reference&) = default;
153165 __bit_const_reference& operator=(const __bit_const_reference&) = delete;
......@@ -589,10 +601,10 @@ inline _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cr, false> swap_ranges(
589601
590602template <class _Cp>
591603struct __bit_array {
592 using difference_type = typename _Cp::difference_type;
593 using __storage_type = typename _Cp::__storage_type;
594 using __storage_pointer = typename _Cp::__storage_pointer;
595 using iterator = typename _Cp::iterator;
604 using difference_type _LIBCPP_NODEBUG = typename __size_difference_type_traits<_Cp>::difference_type;
605 using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type;
606 using __storage_pointer _LIBCPP_NODEBUG = typename _Cp::__storage_pointer;
607 using iterator _LIBCPP_NODEBUG = typename _Cp::iterator;
596608
597609 static const unsigned __bits_per_word = _Cp::__bits_per_word;
598610 static const unsigned _Np = 4;
......@@ -781,7 +793,7 @@ equal(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __b
781793template <class _Cp, bool _IsConst, typename _Cp::__storage_type>
782794class __bit_iterator {
783795public:
784 using difference_type = typename _Cp::difference_type;
796 using difference_type = typename __size_difference_type_traits<_Cp>::difference_type;
785797 using value_type = bool;
786798 using pointer = __bit_iterator;
787799#ifndef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
......@@ -792,8 +804,8 @@ public:
792804 using iterator_category = random_access_iterator_tag;
793805
794806private:
795 using __storage_type = typename _Cp::__storage_type;
796 using __storage_pointer =
807 using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type;
808 using __storage_pointer _LIBCPP_NODEBUG =
797809 __conditional_t<_IsConst, typename _Cp::__const_storage_pointer, typename _Cp::__storage_pointer>;
798810
799811 static const unsigned __bits_per_word = _Cp::__bits_per_word;
......@@ -968,7 +980,7 @@ private:
968980
969981 template <bool _FillVal, class _Dp>
970982 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend void
971 __fill_n_bool(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n);
983 __fill_n_bool(__bit_iterator<_Dp, false> __first, typename __size_difference_type_traits<_Dp>::size_type __n);
972984
973985 template <class _Dp, bool _IC>
974986 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false> __copy_aligned(
......@@ -1011,10 +1023,10 @@ private:
10111023 equal(__bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC2>);
10121024 template <bool _ToFind, class _Dp, bool _IC>
10131025 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, _IC>
1014 __find_bool(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
1026 __find_bool(__bit_iterator<_Dp, _IC>, typename __size_difference_type_traits<_Dp>::size_type);
10151027 template <bool _ToCount, class _Dp, bool _IC>
1016 friend typename __bit_iterator<_Dp, _IC>::difference_type _LIBCPP_HIDE_FROM_ABI
1017 _LIBCPP_CONSTEXPR_SINCE_CXX20 __count_bool(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
1028 friend typename __bit_iterator<_Dp, _IC>::difference_type _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1029 __count_bool(__bit_iterator<_Dp, _IC>, typename __size_difference_type_traits<_Dp>::size_type);
10181030};
10191031
10201032_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__charconv/from_chars_floating_point.h created+73
......@@ -0,0 +1,73 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H
11#define _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H
12
13#include <__assert>
14#include <__charconv/chars_format.h>
15#include <__charconv/from_chars_result.h>
16#include <__config>
17#include <__cstddef/ptrdiff_t.h>
18#include <__system_error/errc.h>
19
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21# pragma GCC system_header
22#endif
23
24_LIBCPP_PUSH_MACROS
25#include <__undef_macros>
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29#if _LIBCPP_STD_VER >= 17
30
31template <class _Fp>
32struct __from_chars_result {
33 _Fp __value;
34 ptrdiff_t __n;
35 errc __ec;
36};
37
38template <class _Fp>
39_LIBCPP_EXPORTED_FROM_ABI __from_chars_result<_Fp> __from_chars_floating_point(
40 _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt);
41
42extern template __from_chars_result<float> __from_chars_floating_point(
43 _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt);
44
45extern template __from_chars_result<double> __from_chars_floating_point(
46 _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt);
47
48template <class _Fp>
49_LIBCPP_HIDE_FROM_ABI from_chars_result
50__from_chars(const char* __first, const char* __last, _Fp& __value, chars_format __fmt) {
51 __from_chars_result<_Fp> __r = std::__from_chars_floating_point<_Fp>(__first, __last, __fmt);
52 if (__r.__ec != errc::invalid_argument)
53 __value = __r.__value;
54 return {__first + __r.__n, __r.__ec};
55}
56
57_LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_HIDE_FROM_ABI inline from_chars_result
58from_chars(const char* __first, const char* __last, float& __value, chars_format __fmt = chars_format::general) {
59 return std::__from_chars<float>(__first, __last, __value, __fmt);
60}
61
62_LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_HIDE_FROM_ABI inline from_chars_result
63from_chars(const char* __first, const char* __last, double& __value, chars_format __fmt = chars_format::general) {
64 return std::__from_chars<double>(__first, __last, __value, __fmt);
65}
66
67#endif // _LIBCPP_STD_VER >= 17
68
69_LIBCPP_END_NAMESPACE_STD
70
71_LIBCPP_POP_MACROS
72
73#endif // _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H
lib/libcxx/include/__charconv/tables.h+1-1
......@@ -95,7 +95,7 @@ inline constexpr uint64_t __pow10_64[20] = {
9595 UINT64_C(1000000000000000000),
9696 UINT64_C(10000000000000000000)};
9797
98# ifndef _LIBCPP_HAS_NO_INT128
98# if _LIBCPP_HAS_INT128
9999inline constexpr int __pow10_128_offset = 0;
100100inline constexpr __uint128_t __pow10_128[40] = {
101101 UINT64_C(0),
lib/libcxx/include/__charconv/to_chars_base_10.h+1-1
......@@ -124,7 +124,7 @@ __base_10_u64(char* __buffer, uint64_t __value) noexcept {
124124 return __itoa::__append10(__buffer, __value);
125125}
126126
127# ifndef _LIBCPP_HAS_NO_INT128
127# if _LIBCPP_HAS_INT128
128128/// \returns 10^\a exp
129129///
130130/// \pre \a exp [19, 39]
lib/libcxx/include/__charconv/to_chars_integral.h+3-2
......@@ -18,14 +18,15 @@
1818#include <__charconv/to_chars_result.h>
1919#include <__charconv/traits.h>
2020#include <__config>
21#include <__cstddef/ptrdiff_t.h>
2122#include <__system_error/errc.h>
2223#include <__type_traits/enable_if.h>
2324#include <__type_traits/integral_constant.h>
25#include <__type_traits/is_integral.h>
2426#include <__type_traits/is_same.h>
2527#include <__type_traits/make_32_64_or_128_bit.h>
2628#include <__type_traits/make_unsigned.h>
2729#include <__utility/unreachable.h>
28#include <cstddef>
2930#include <cstdint>
3031#include <limits>
3132
......@@ -70,7 +71,7 @@ __to_chars_itoa(char* __first, char* __last, _Tp __value, false_type) {
7071 return {__last, errc::value_too_large};
7172}
7273
73# ifndef _LIBCPP_HAS_NO_INT128
74# if _LIBCPP_HAS_INT128
7475template <>
7576inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI to_chars_result
7677__to_chars_itoa(char* __first, char* __last, __uint128_t __value, false_type) {
lib/libcxx/include/__charconv/traits.h+1-1
......@@ -88,7 +88,7 @@ struct _LIBCPP_HIDDEN __traits_base<_Tp, __enable_if_t<sizeof(_Tp) == sizeof(uin
8888 }
8989};
9090
91# ifndef _LIBCPP_HAS_NO_INT128
91# if _LIBCPP_HAS_INT128
9292template <typename _Tp>
9393struct _LIBCPP_HIDDEN __traits_base<_Tp, __enable_if_t<sizeof(_Tp) == sizeof(__uint128_t)> > {
9494 using type = __uint128_t;
lib/libcxx/include/__chrono/convert_to_tm.h+27-5
......@@ -24,6 +24,7 @@
2424#include <__chrono/sys_info.h>
2525#include <__chrono/system_clock.h>
2626#include <__chrono/time_point.h>
27#include <__chrono/utc_clock.h>
2728#include <__chrono/weekday.h>
2829#include <__chrono/year.h>
2930#include <__chrono/year_month.h>
......@@ -98,6 +99,22 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const chrono::sys_time<_Duration> __tp
9899 return __result;
99100}
100101
102# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
103# if _LIBCPP_HAS_EXPERIMENTAL_TZDB
104
105template <class _Tm, class _Duration>
106_LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(chrono::utc_time<_Duration> __tp) {
107 _Tm __result = std::__convert_to_tm<_Tm>(chrono::utc_clock::to_sys(__tp));
108
109 if (chrono::get_leap_second_info(__tp).is_leap_second)
110 ++__result.tm_sec;
111
112 return __result;
113}
114
115# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
116# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
117
101118// Convert a chrono (calendar) time point, or dururation to the given _Tm type,
102119// which must have the same properties as std::tm.
103120template <class _Tm, class _ChronoT>
......@@ -110,13 +127,19 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& __value) {
110127 if constexpr (__is_time_point<_ChronoT>) {
111128 if constexpr (same_as<typename _ChronoT::clock, chrono::system_clock>)
112129 return std::__convert_to_tm<_Tm>(__value);
130# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
131# if _LIBCPP_HAS_EXPERIMENTAL_TZDB
132 else if constexpr (same_as<typename _ChronoT::clock, chrono::utc_clock>)
133 return std::__convert_to_tm<_Tm>(__value);
134# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
135# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
113136 else if constexpr (same_as<typename _ChronoT::clock, chrono::file_clock>)
114137 return std::__convert_to_tm<_Tm>(_ChronoT::clock::to_sys(__value));
115138 else if constexpr (same_as<typename _ChronoT::clock, chrono::local_t>)
116139 return std::__convert_to_tm<_Tm>(chrono::sys_time<typename _ChronoT::duration>{__value.time_since_epoch()});
117140 else
118141 static_assert(sizeof(_ChronoT) == 0, "TODO: Add the missing clock specialization");
119 } else if constexpr (chrono::__is_duration<_ChronoT>::value) {
142 } else if constexpr (chrono::__is_duration_v<_ChronoT>) {
120143 // [time.format]/6
121144 // ... However, if a flag refers to a "time of day" (e.g. %H, %I, %p,
122145 // 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) {
175198 if (__value.hours().count() > std::numeric_limits<decltype(__result.tm_hour)>::max())
176199 std::__throw_format_error("Formatting hh_mm_ss, encountered an hour overflow");
177200 __result.tm_hour = __value.hours().count();
178# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
201# if _LIBCPP_HAS_EXPERIMENTAL_TZDB
179202 } else if constexpr (same_as<_ChronoT, chrono::sys_info>) {
180203 // Has no time information.
181204 } else if constexpr (same_as<_ChronoT, chrono::local_info>) {
182205 // Has no time information.
183# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
184 !defined(_LIBCPP_HAS_NO_LOCALIZATION)
206# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
185207 } else if constexpr (__is_specialization_v<_ChronoT, chrono::zoned_time>) {
186208 return std::__convert_to_tm<_Tm>(
187209 chrono::sys_time<typename _ChronoT::duration>{__value.get_local_time().time_since_epoch()});
188210# endif
189# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
211# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
190212 } else
191213 static_assert(sizeof(_ChronoT) == 0, "Add the missing type specialization");
192214
lib/libcxx/include/__chrono/day.h+1-1
......@@ -11,8 +11,8 @@
1111#define _LIBCPP___CHRONO_DAY_H
1212
1313#include <__chrono/duration.h>
14#include <__compare/ordering.h>
1415#include <__config>
15#include <compare>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818# pragma GCC system_header
lib/libcxx/include/__chrono/duration.h+16-21
......@@ -35,26 +35,25 @@ template <class _Rep, class _Period = ratio<1> >
3535class _LIBCPP_TEMPLATE_VIS duration;
3636
3737template <class _Tp>
38struct __is_duration : false_type {};
38inline const bool __is_duration_v = false;
3939
4040template <class _Rep, class _Period>
41struct __is_duration<duration<_Rep, _Period> > : true_type {};
41inline const bool __is_duration_v<duration<_Rep, _Period> > = true;
4242
4343template <class _Rep, class _Period>
44struct __is_duration<const duration<_Rep, _Period> > : true_type {};
44inline const bool __is_duration_v<const duration<_Rep, _Period> > = true;
4545
4646template <class _Rep, class _Period>
47struct __is_duration<volatile duration<_Rep, _Period> > : true_type {};
47inline const bool __is_duration_v<volatile duration<_Rep, _Period> > = true;
4848
4949template <class _Rep, class _Period>
50struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
50inline const bool __is_duration_v<const volatile duration<_Rep, _Period> > = true;
5151
5252} // namespace chrono
5353
5454template <class _Rep1, class _Period1, class _Rep2, class _Period2>
5555struct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>, chrono::duration<_Rep2, _Period2> > {
56 typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, typename __ratio_gcd<_Period1, _Period2>::type>
57 type;
56 typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, __ratio_gcd<_Period1, _Period2> > type;
5857};
5958
6059namespace chrono {
......@@ -102,7 +101,7 @@ struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> {
102101 }
103102};
104103
105template <class _ToDuration, class _Rep, class _Period, __enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
104template <class _ToDuration, class _Rep, class _Period, __enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
106105inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration duration_cast(const duration<_Rep, _Period>& __fd) {
107106 return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
108107}
......@@ -124,7 +123,7 @@ public:
124123};
125124
126125#if _LIBCPP_STD_VER >= 17
127template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
126template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
128127inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration floor(const duration<_Rep, _Period>& __d) {
129128 _ToDuration __t = chrono::duration_cast<_ToDuration>(__d);
130129 if (__t > __d)
......@@ -132,7 +131,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration floor(const duration<
132131 return __t;
133132}
134133
135template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
134template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
136135inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration ceil(const duration<_Rep, _Period>& __d) {
137136 _ToDuration __t = chrono::duration_cast<_ToDuration>(__d);
138137 if (__t < __d)
......@@ -140,7 +139,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration ceil(const duration<_
140139 return __t;
141140}
142141
143template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
142template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
144143inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration round(const duration<_Rep, _Period>& __d) {
145144 _ToDuration __lower = chrono::floor<_ToDuration>(__d);
146145 _ToDuration __upper = __lower + _ToDuration{1};
......@@ -158,15 +157,15 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration round(const duration<
158157
159158template <class _Rep, class _Period>
160159class _LIBCPP_TEMPLATE_VIS duration {
161 static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
162 static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
160 static_assert(!__is_duration_v<_Rep>, "A duration representation can not be a duration");
161 static_assert(__is_ratio_v<_Period>, "Second template parameter of duration must be a std::ratio");
163162 static_assert(_Period::num > 0, "duration period must be positive");
164163
165164 template <class _R1, class _R2>
166165 struct __no_overflow {
167166 private:
168 static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
169 static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
167 static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>;
168 static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>;
170169 static const intmax_t __n1 = _R1::num / __gcd_n1_n2;
171170 static const intmax_t __d1 = _R1::den / __gcd_d1_d2;
172171 static const intmax_t __n2 = _R2::num / __gcd_n1_n2;
......@@ -434,7 +433,7 @@ operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) {
434433template <class _Rep1,
435434 class _Period,
436435 class _Rep2,
437 __enable_if_t<!__is_duration<_Rep2>::value &&
436 __enable_if_t<!__is_duration_v<_Rep2> &&
438437 is_convertible<const _Rep2&, typename common_type<_Rep1, _Rep2>::type>::value,
439438 int> = 0>
440439inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR duration<typename common_type<_Rep1, _Rep2>::type, _Period>
......@@ -456,7 +455,7 @@ operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2
456455template <class _Rep1,
457456 class _Period,
458457 class _Rep2,
459 __enable_if_t<!__is_duration<_Rep2>::value &&
458 __enable_if_t<!__is_duration_v<_Rep2> &&
460459 is_convertible<const _Rep2&, typename common_type<_Rep1, _Rep2>::type>::value,
461460 int> = 0>
462461inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR duration<typename common_type<_Rep1, _Rep2>::type, _Period>
......@@ -543,8 +542,4 @@ _LIBCPP_END_NAMESPACE_STD
543542
544543_LIBCPP_POP_MACROS
545544
546#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
547# include <type_traits>
548#endif
549
550545#endif // _LIBCPP___CHRONO_DURATION_H
lib/libcxx/include/__chrono/exception.h+6-6
......@@ -14,7 +14,7 @@
1414
1515#include <version>
1616// Enable the contents of the header only when libc++ was built with experimental features enabled.
17#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
17#if _LIBCPP_HAS_EXPERIMENTAL_TZDB
1818
1919# include <__chrono/calendar.h>
2020# include <__chrono/local_info.h>
......@@ -71,9 +71,9 @@ private:
7171};
7272
7373template <class _Duration>
74_LIBCPP_NORETURN _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_nonexistent_local_time(
74[[noreturn]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_nonexistent_local_time(
7575 [[maybe_unused]] const local_time<_Duration>& __time, [[maybe_unused]] const local_info& __info) {
76# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
76# if _LIBCPP_HAS_EXCEPTIONS
7777 throw nonexistent_local_time(__time, __info);
7878# else
7979 _LIBCPP_VERBOSE_ABORT("nonexistent_local_time was thrown in -fno-exceptions mode");
......@@ -115,9 +115,9 @@ private:
115115};
116116
117117template <class _Duration>
118_LIBCPP_NORETURN _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_ambiguous_local_time(
118[[noreturn]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_ambiguous_local_time(
119119 [[maybe_unused]] const local_time<_Duration>& __time, [[maybe_unused]] const local_info& __info) {
120# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
120# if _LIBCPP_HAS_EXCEPTIONS
121121 throw ambiguous_local_time(__time, __info);
122122# else
123123 _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
130130
131131_LIBCPP_END_NAMESPACE_STD
132132
133#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
133#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
134134
135135#endif // _LIBCPP___CHRONO_EXCEPTION_H
lib/libcxx/include/__chrono/file_clock.h+1-1
......@@ -47,7 +47,7 @@ _LIBCPP_END_NAMESPACE_STD
4747#ifndef _LIBCPP_CXX03_LANG
4848_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
4949struct _FilesystemClock {
50# if !defined(_LIBCPP_HAS_NO_INT128)
50# if _LIBCPP_HAS_INT128
5151 typedef __int128_t rep;
5252 typedef nano period;
5353# else
lib/libcxx/include/__chrono/formatter.h+129-114
......@@ -10,55 +10,60 @@
1010#ifndef _LIBCPP___CHRONO_FORMATTER_H
1111#define _LIBCPP___CHRONO_FORMATTER_H
1212
13#include <__algorithm/ranges_copy.h>
14#include <__chrono/calendar.h>
15#include <__chrono/concepts.h>
16#include <__chrono/convert_to_tm.h>
17#include <__chrono/day.h>
18#include <__chrono/duration.h>
19#include <__chrono/file_clock.h>
20#include <__chrono/hh_mm_ss.h>
21#include <__chrono/local_info.h>
22#include <__chrono/month.h>
23#include <__chrono/month_weekday.h>
24#include <__chrono/monthday.h>
25#include <__chrono/ostream.h>
26#include <__chrono/parser_std_format_spec.h>
27#include <__chrono/statically_widen.h>
28#include <__chrono/sys_info.h>
29#include <__chrono/system_clock.h>
30#include <__chrono/time_point.h>
31#include <__chrono/weekday.h>
32#include <__chrono/year.h>
33#include <__chrono/year_month.h>
34#include <__chrono/year_month_day.h>
35#include <__chrono/year_month_weekday.h>
36#include <__chrono/zoned_time.h>
37#include <__concepts/arithmetic.h>
38#include <__concepts/same_as.h>
3913#include <__config>
40#include <__format/concepts.h>
41#include <__format/format_error.h>
42#include <__format/format_functions.h>
43#include <__format/format_parse_context.h>
44#include <__format/formatter.h>
45#include <__format/parser_std_format_spec.h>
46#include <__format/write_escaped.h>
47#include <__memory/addressof.h>
48#include <__type_traits/is_specialization.h>
49#include <cmath>
50#include <ctime>
51#include <limits>
52#include <sstream>
53#include <string_view>
54
55#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
56# pragma GCC system_header
57#endif
14
15#if _LIBCPP_HAS_LOCALIZATION
16
17# include <__algorithm/ranges_copy.h>
18# include <__chrono/calendar.h>
19# include <__chrono/concepts.h>
20# include <__chrono/convert_to_tm.h>
21# include <__chrono/day.h>
22# include <__chrono/duration.h>
23# include <__chrono/file_clock.h>
24# include <__chrono/hh_mm_ss.h>
25# include <__chrono/local_info.h>
26# include <__chrono/month.h>
27# include <__chrono/month_weekday.h>
28# include <__chrono/monthday.h>
29# include <__chrono/ostream.h>
30# include <__chrono/parser_std_format_spec.h>
31# include <__chrono/statically_widen.h>
32# include <__chrono/sys_info.h>
33# include <__chrono/system_clock.h>
34# include <__chrono/time_point.h>
35# include <__chrono/utc_clock.h>
36# include <__chrono/weekday.h>
37# include <__chrono/year.h>
38# include <__chrono/year_month.h>
39# include <__chrono/year_month_day.h>
40# include <__chrono/year_month_weekday.h>
41# include <__chrono/zoned_time.h>
42# include <__concepts/arithmetic.h>
43# include <__concepts/same_as.h>
44# include <__format/concepts.h>
45# include <__format/format_error.h>
46# include <__format/format_functions.h>
47# include <__format/format_parse_context.h>
48# include <__format/formatter.h>
49# include <__format/parser_std_format_spec.h>
50# include <__format/write_escaped.h>
51# include <__memory/addressof.h>
52# include <__type_traits/is_specialization.h>
53# include <cmath>
54# include <ctime>
55# include <limits>
56# include <locale>
57# include <sstream>
58# include <string_view>
59
60# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
61# pragma GCC system_header
62# endif
5863
5964_LIBCPP_BEGIN_NAMESPACE_STD
6065
61#if _LIBCPP_STD_VER >= 20
66# if _LIBCPP_STD_VER >= 20
6267
6368namespace __formatter {
6469
......@@ -139,25 +144,23 @@ __format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::hh_mm_ss<
139144 __value.fractional_width);
140145}
141146
142# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && \
143 !defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
147# if _LIBCPP_HAS_EXPERIMENTAL_TZDB && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
144148template <class _CharT, class _Duration, class _TimeZonePtr>
145149_LIBCPP_HIDE_FROM_ABI void
146150__format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::zoned_time<_Duration, _TimeZonePtr>& __value) {
147151 __formatter::__format_sub_seconds(__sstr, __value.get_local_time().time_since_epoch());
148152}
149# endif
153# endif
150154
151155template <class _Tp>
152156consteval bool __use_fraction() {
153157 if constexpr (__is_time_point<_Tp>)
154158 return chrono::hh_mm_ss<typename _Tp::duration>::fractional_width;
155# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && \
156 !defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
159# if _LIBCPP_HAS_EXPERIMENTAL_TZDB && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
157160 else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
158161 return chrono::hh_mm_ss<typename _Tp::duration>::fractional_width;
159# endif
160 else if constexpr (chrono::__is_duration<_Tp>::value)
162# endif
163 else if constexpr (chrono::__is_duration_v<_Tp>)
161164 return chrono::hh_mm_ss<_Tp>::fractional_width;
162165 else if constexpr (__is_hh_mm_ss<_Tp>)
163166 return _Tp::fractional_width;
......@@ -225,16 +228,15 @@ struct _LIBCPP_HIDE_FROM_ABI __time_zone {
225228
226229template <class _Tp>
227230_LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] const _Tp& __value) {
228# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
231# if _LIBCPP_HAS_EXPERIMENTAL_TZDB
229232 if constexpr (same_as<_Tp, chrono::sys_info>)
230233 return {__value.abbrev, __value.offset};
231# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
232 !defined(_LIBCPP_HAS_NO_LOCALIZATION)
234# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
233235 else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
234236 return __formatter::__convert_to_time_zone(__value.get_info());
235# endif
237# endif
236238 else
237# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
239# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
238240 return {"UTC", chrono::seconds{0}};
239241}
240242
......@@ -272,7 +274,7 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
272274 } break;
273275
274276 case _CharT('j'):
275 if constexpr (chrono::__is_duration<_Tp>::value)
277 if constexpr (chrono::__is_duration_v<_Tp>)
276278 // Converting a duration where the period has a small ratio to days
277279 // may fail to compile. This due to loss of precision in the
278280 // 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(
284286 break;
285287
286288 case _CharT('q'):
287 if constexpr (chrono::__is_duration<_Tp>::value) {
289 if constexpr (chrono::__is_duration_v<_Tp>) {
288290 __sstr << chrono::__units_suffix<_CharT, typename _Tp::period>();
289291 break;
290292 }
......@@ -300,7 +302,7 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
300302 // MSVC STL ignores precision but uses separator
301303 // FMT honours precision and has a bug for separator
302304 // https://godbolt.org/z/78b7sMxns
303 if constexpr (chrono::__is_duration<_Tp>::value) {
305 if constexpr (chrono::__is_duration_v<_Tp>) {
304306 __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{}"), __value.count());
305307 break;
306308 }
......@@ -341,16 +343,16 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
341343 //
342344 // TODO FMT evaluate the comment above.
343345
344# if defined(__GLIBC__) || defined(_AIX) || defined(_WIN32)
346# if defined(__GLIBC__) || defined(_AIX) || defined(_WIN32)
345347 case _CharT('y'):
346348 // Glibc fails for negative values, AIX for positive values too.
347349 __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), (std::abs(__t.tm_year + 1900)) % 100);
348350 break;
349# endif // defined(__GLIBC__) || defined(_AIX) || defined(_WIN32)
351# endif // defined(__GLIBC__) || defined(_AIX) || defined(_WIN32)
350352
351353 case _CharT('Y'):
352354 // Depending on the platform's libc the range of supported years is
353 // limited. Intead of of testing all conditions use the internal
355 // limited. Instead of of testing all conditions use the internal
354356 // implementation unconditionally.
355357 __formatter::__format_year(__sstr, __t.tm_year + 1900);
356358 break;
......@@ -442,17 +444,16 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_ok(const _Tp& __value) {
442444 return __value.weekday().ok();
443445 else if constexpr (__is_hh_mm_ss<_Tp>)
444446 return true;
445# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
447# if _LIBCPP_HAS_EXPERIMENTAL_TZDB
446448 else if constexpr (same_as<_Tp, chrono::sys_info>)
447449 return true;
448450 else if constexpr (same_as<_Tp, chrono::local_info>)
449451 return true;
450# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
451 !defined(_LIBCPP_HAS_NO_LOCALIZATION)
452# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
452453 else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
453454 return true;
454# endif
455# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
455# endif
456# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
456457 else
457458 static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
458459}
......@@ -493,17 +494,16 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_name_ok(const _Tp& __value) {
493494 return __value.weekday().ok();
494495 else if constexpr (__is_hh_mm_ss<_Tp>)
495496 return true;
496# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
497# if _LIBCPP_HAS_EXPERIMENTAL_TZDB
497498 else if constexpr (same_as<_Tp, chrono::sys_info>)
498499 return true;
499500 else if constexpr (same_as<_Tp, chrono::local_info>)
500501 return true;
501# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
502 !defined(_LIBCPP_HAS_NO_LOCALIZATION)
502# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
503503 else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
504504 return true;
505# endif
506# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
505# endif
506# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
507507 else
508508 static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
509509}
......@@ -544,17 +544,16 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __date_ok(const _Tp& __value) {
544544 return __value.ok();
545545 else if constexpr (__is_hh_mm_ss<_Tp>)
546546 return true;
547# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
547# if _LIBCPP_HAS_EXPERIMENTAL_TZDB
548548 else if constexpr (same_as<_Tp, chrono::sys_info>)
549549 return true;
550550 else if constexpr (same_as<_Tp, chrono::local_info>)
551551 return true;
552# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
553 !defined(_LIBCPP_HAS_NO_LOCALIZATION)
552# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
554553 else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
555554 return true;
556# endif
557# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
555# endif
556# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
558557 else
559558 static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
560559}
......@@ -595,17 +594,16 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __month_name_ok(const _Tp& __value) {
595594 return __value.month().ok();
596595 else if constexpr (__is_hh_mm_ss<_Tp>)
597596 return true;
598# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
597# if _LIBCPP_HAS_EXPERIMENTAL_TZDB
599598 else if constexpr (same_as<_Tp, chrono::sys_info>)
600599 return true;
601600 else if constexpr (same_as<_Tp, chrono::local_info>)
602601 return true;
603# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
604 !defined(_LIBCPP_HAS_NO_LOCALIZATION)
602# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
605603 else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
606604 return true;
607# endif
608# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
605# endif
606# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
609607 else
610608 static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
611609}
......@@ -630,7 +628,7 @@ __format_chrono(const _Tp& __value,
630628 if (__chrono_specs.empty())
631629 __sstr << __value;
632630 else {
633 if constexpr (chrono::__is_duration<_Tp>::value) {
631 if constexpr (chrono::__is_duration_v<_Tp>) {
634632 // A duration can be a user defined arithmetic type. Users may specialize
635633 // numeric_limits, but they may not specialize is_signed.
636634 if constexpr (numeric_limits<typename _Tp::rep>::is_signed) {
......@@ -714,7 +712,7 @@ public:
714712template <class _Duration, __fmt_char_type _CharT>
715713struct _LIBCPP_TEMPLATE_VIS formatter<chrono::sys_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
716714public:
717 using _Base = __formatter_chrono<_CharT>;
715 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
718716
719717 template <class _ParseContext>
720718 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -722,10 +720,27 @@ public:
722720 }
723721};
724722
723# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
724# if _LIBCPP_HAS_EXPERIMENTAL_TZDB
725
726template <class _Duration, __fmt_char_type _CharT>
727struct _LIBCPP_TEMPLATE_VIS formatter<chrono::utc_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
728public:
729 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
730
731 template <class _ParseContext>
732 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
733 return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__clock);
734 }
735};
736
737# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
738# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
739
725740template <class _Duration, __fmt_char_type _CharT>
726741struct _LIBCPP_TEMPLATE_VIS formatter<chrono::file_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
727742public:
728 using _Base = __formatter_chrono<_CharT>;
743 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
729744
730745 template <class _ParseContext>
731746 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -736,7 +751,7 @@ public:
736751template <class _Duration, __fmt_char_type _CharT>
737752struct _LIBCPP_TEMPLATE_VIS formatter<chrono::local_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
738753public:
739 using _Base = __formatter_chrono<_CharT>;
754 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
740755
741756 template <class _ParseContext>
742757 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -748,7 +763,7 @@ public:
748763template <class _Rep, class _Period, __fmt_char_type _CharT>
749764struct formatter<chrono::duration<_Rep, _Period>, _CharT> : public __formatter_chrono<_CharT> {
750765public:
751 using _Base = __formatter_chrono<_CharT>;
766 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
752767
753768 template <class _ParseContext>
754769 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -770,7 +785,7 @@ public:
770785template <__fmt_char_type _CharT>
771786struct _LIBCPP_TEMPLATE_VIS formatter<chrono::day, _CharT> : public __formatter_chrono<_CharT> {
772787public:
773 using _Base = __formatter_chrono<_CharT>;
788 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
774789
775790 template <class _ParseContext>
776791 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -781,7 +796,7 @@ public:
781796template <__fmt_char_type _CharT>
782797struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month, _CharT> : public __formatter_chrono<_CharT> {
783798public:
784 using _Base = __formatter_chrono<_CharT>;
799 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
785800
786801 template <class _ParseContext>
787802 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -792,7 +807,7 @@ public:
792807template <__fmt_char_type _CharT>
793808struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year, _CharT> : public __formatter_chrono<_CharT> {
794809public:
795 using _Base = __formatter_chrono<_CharT>;
810 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
796811
797812 template <class _ParseContext>
798813 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -803,7 +818,7 @@ public:
803818template <__fmt_char_type _CharT>
804819struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday, _CharT> : public __formatter_chrono<_CharT> {
805820public:
806 using _Base = __formatter_chrono<_CharT>;
821 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
807822
808823 template <class _ParseContext>
809824 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -814,7 +829,7 @@ public:
814829template <__fmt_char_type _CharT>
815830struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday_indexed, _CharT> : public __formatter_chrono<_CharT> {
816831public:
817 using _Base = __formatter_chrono<_CharT>;
832 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
818833
819834 template <class _ParseContext>
820835 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -825,7 +840,7 @@ public:
825840template <__fmt_char_type _CharT>
826841struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday_last, _CharT> : public __formatter_chrono<_CharT> {
827842public:
828 using _Base = __formatter_chrono<_CharT>;
843 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
829844
830845 template <class _ParseContext>
831846 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -836,7 +851,7 @@ public:
836851template <__fmt_char_type _CharT>
837852struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_day, _CharT> : public __formatter_chrono<_CharT> {
838853public:
839 using _Base = __formatter_chrono<_CharT>;
854 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
840855
841856 template <class _ParseContext>
842857 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -847,7 +862,7 @@ public:
847862template <__fmt_char_type _CharT>
848863struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_day_last, _CharT> : public __formatter_chrono<_CharT> {
849864public:
850 using _Base = __formatter_chrono<_CharT>;
865 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
851866
852867 template <class _ParseContext>
853868 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -858,7 +873,7 @@ public:
858873template <__fmt_char_type _CharT>
859874struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_weekday, _CharT> : public __formatter_chrono<_CharT> {
860875public:
861 using _Base = __formatter_chrono<_CharT>;
876 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
862877
863878 template <class _ParseContext>
864879 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -869,7 +884,7 @@ public:
869884template <__fmt_char_type _CharT>
870885struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_weekday_last, _CharT> : public __formatter_chrono<_CharT> {
871886public:
872 using _Base = __formatter_chrono<_CharT>;
887 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
873888
874889 template <class _ParseContext>
875890 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -880,7 +895,7 @@ public:
880895template <__fmt_char_type _CharT>
881896struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month, _CharT> : public __formatter_chrono<_CharT> {
882897public:
883 using _Base = __formatter_chrono<_CharT>;
898 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
884899
885900 template <class _ParseContext>
886901 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -891,7 +906,7 @@ public:
891906template <__fmt_char_type _CharT>
892907struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_day, _CharT> : public __formatter_chrono<_CharT> {
893908public:
894 using _Base = __formatter_chrono<_CharT>;
909 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
895910
896911 template <class _ParseContext>
897912 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -902,7 +917,7 @@ public:
902917template <__fmt_char_type _CharT>
903918struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_day_last, _CharT> : public __formatter_chrono<_CharT> {
904919public:
905 using _Base = __formatter_chrono<_CharT>;
920 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
906921
907922 template <class _ParseContext>
908923 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -913,7 +928,7 @@ public:
913928template <__fmt_char_type _CharT>
914929struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_weekday, _CharT> : public __formatter_chrono<_CharT> {
915930public:
916 using _Base = __formatter_chrono<_CharT>;
931 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
917932
918933 template <class _ParseContext>
919934 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -924,7 +939,7 @@ public:
924939template <__fmt_char_type _CharT>
925940struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_weekday_last, _CharT> : public __formatter_chrono<_CharT> {
926941public:
927 using _Base = __formatter_chrono<_CharT>;
942 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
928943
929944 template <class _ParseContext>
930945 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -935,7 +950,7 @@ public:
935950template <class _Duration, __fmt_char_type _CharT>
936951struct formatter<chrono::hh_mm_ss<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
937952public:
938 using _Base = __formatter_chrono<_CharT>;
953 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
939954
940955 template <class _ParseContext>
941956 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -943,11 +958,11 @@ public:
943958 }
944959};
945960
946# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
961# if _LIBCPP_HAS_EXPERIMENTAL_TZDB
947962template <__fmt_char_type _CharT>
948963struct formatter<chrono::sys_info, _CharT> : public __formatter_chrono<_CharT> {
949964public:
950 using _Base = __formatter_chrono<_CharT>;
965 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
951966
952967 template <class _ParseContext>
953968 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -958,33 +973,33 @@ public:
958973template <__fmt_char_type _CharT>
959974struct formatter<chrono::local_info, _CharT> : public __formatter_chrono<_CharT> {
960975public:
961 using _Base = __formatter_chrono<_CharT>;
976 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
962977
963978 template <class _ParseContext>
964979 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
965980 return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags{});
966981 }
967982};
968# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
969 !defined(_LIBCPP_HAS_NO_LOCALIZATION)
983# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
970984// Note due to how libc++'s formatters are implemented there is no need to add
971985// the exposition only local-time-format-t abstraction.
972986template <class _Duration, class _TimeZonePtr, __fmt_char_type _CharT>
973987struct formatter<chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT> : public __formatter_chrono<_CharT> {
974988public:
975 using _Base = __formatter_chrono<_CharT>;
989 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
976990
977991 template <class _ParseContext>
978992 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
979993 return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__clock);
980994 }
981995};
982# endif // !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) &&
983 // !defined(_LIBCPP_HAS_NO_LOCALIZATION)
984# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
996# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
997# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
985998
986#endif // if _LIBCPP_STD_VER >= 20
999# endif // if _LIBCPP_STD_VER >= 20
9871000
9881001_LIBCPP_END_NAMESPACE_STD
9891002
1003#endif // _LIBCPP_HAS_LOCALIZATION
1004
9901005#endif // _LIBCPP___CHRONO_FORMATTER_H
lib/libcxx/include/__chrono/hh_mm_ss.h+2-2
......@@ -29,8 +29,8 @@ namespace chrono {
2929template <class _Duration>
3030class hh_mm_ss {
3131private:
32 static_assert(__is_duration<_Duration>::value, "template parameter of hh_mm_ss must be a std::chrono::duration");
33 using __CommonType = common_type_t<_Duration, chrono::seconds>;
32 static_assert(__is_duration_v<_Duration>, "template parameter of hh_mm_ss must be a std::chrono::duration");
33 using __CommonType _LIBCPP_NODEBUG = common_type_t<_Duration, chrono::seconds>;
3434
3535 _LIBCPP_HIDE_FROM_ABI static constexpr uint64_t __pow10(unsigned __exp) {
3636 uint64_t __ret = 1;
lib/libcxx/include/__chrono/high_resolution_clock.h+1-1
......@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222
2323namespace chrono {
2424
25#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
25#if _LIBCPP_HAS_MONOTONIC_CLOCK
2626typedef steady_clock high_resolution_clock;
2727#else
2828typedef system_clock high_resolution_clock;
lib/libcxx/include/__chrono/leap_second.h+73-68
......@@ -14,7 +14,7 @@
1414
1515#include <version>
1616// Enable the contents of the header only when libc++ was built with experimental features enabled.
17#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
17#if _LIBCPP_HAS_EXPERIMENTAL_TZDB
1818
1919# include <__chrono/duration.h>
2020# include <__chrono/system_clock.h>
......@@ -43,84 +43,89 @@ public:
4343 _LIBCPP_HIDE_FROM_ABI leap_second(const leap_second&) = default;
4444 _LIBCPP_HIDE_FROM_ABI leap_second& operator=(const leap_second&) = default;
4545
46 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI constexpr sys_seconds date() const noexcept { return __date_; }
46 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr sys_seconds date() const noexcept { return __date_; }
4747
48 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI constexpr seconds value() const noexcept { return __value_; }
48 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr seconds value() const noexcept { return __value_; }
4949
5050private:
5151 sys_seconds __date_;
5252 seconds __value_;
53};
5453
55_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const leap_second& __x, const leap_second& __y) {
56 return __x.date() == __y.date();
57}
58
59_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const leap_second& __x, const leap_second& __y) {
60 return __x.date() <=> __y.date();
61}
62
63template <class _Duration>
64_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const leap_second& __x, const sys_time<_Duration>& __y) {
65 return __x.date() == __y;
66}
67
68template <class _Duration>
69_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const leap_second& __x, const sys_time<_Duration>& __y) {
70 return __x.date() < __y;
71}
72
73template <class _Duration>
74_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const sys_time<_Duration>& __x, const leap_second& __y) {
75 return __x < __y.date();
76}
77
78template <class _Duration>
79_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const leap_second& __x, const sys_time<_Duration>& __y) {
80 return __y < __x;
81}
82
83template <class _Duration>
84_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const sys_time<_Duration>& __x, const leap_second& __y) {
85 return __y < __x;
86}
87
88template <class _Duration>
89_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const leap_second& __x, const sys_time<_Duration>& __y) {
90 return !(__y < __x);
91}
92
93template <class _Duration>
94_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const sys_time<_Duration>& __x, const leap_second& __y) {
95 return !(__y < __x);
96}
97
98template <class _Duration>
99_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const leap_second& __x, const sys_time<_Duration>& __y) {
100 return !(__x < __y);
101}
102
103template <class _Duration>
104_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const sys_time<_Duration>& __x, const leap_second& __y) {
105 return !(__x < __y);
106}
107
108# ifndef _LIBCPP_COMPILER_GCC
109// This requirement cause a compilation loop in GCC-13 and running out of memory.
110// TODO TZDB Test whether GCC-14 fixes this.
111template <class _Duration>
112 requires three_way_comparable_with<sys_seconds, sys_time<_Duration>>
113_LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(const leap_second& __x, const sys_time<_Duration>& __y) {
114 return __x.date() <=> __y;
115}
116# endif
54 // The function
55 // template<class Duration>
56 // requires three_way_comparable_with<sys_seconds, sys_time<Duration>>
57 // constexpr auto operator<=>(const leap_second& x, const sys_time<Duration>& y) noexcept;
58 //
59 // Has constraints that are recursive (LWG4139). The proposed resolution is
60 // to make the funcion a hidden friend. For consistency make this change for
61 // all comparison functions.
62
63 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const leap_second& __x, const leap_second& __y) {
64 return __x.date() == __y.date();
65 }
66
67 _LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering operator<=>(const leap_second& __x, const leap_second& __y) {
68 return __x.date() <=> __y.date();
69 }
70
71 template <class _Duration>
72 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const leap_second& __x, const sys_time<_Duration>& __y) {
73 return __x.date() == __y;
74 }
75
76 template <class _Duration>
77 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(const leap_second& __x, const sys_time<_Duration>& __y) {
78 return __x.date() < __y;
79 }
80
81 template <class _Duration>
82 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(const sys_time<_Duration>& __x, const leap_second& __y) {
83 return __x < __y.date();
84 }
85
86 template <class _Duration>
87 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(const leap_second& __x, const sys_time<_Duration>& __y) {
88 return __y < __x;
89 }
90
91 template <class _Duration>
92 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(const sys_time<_Duration>& __x, const leap_second& __y) {
93 return __y < __x;
94 }
95
96 template <class _Duration>
97 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(const leap_second& __x, const sys_time<_Duration>& __y) {
98 return !(__y < __x);
99 }
100
101 template <class _Duration>
102 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(const sys_time<_Duration>& __x, const leap_second& __y) {
103 return !(__y < __x);
104 }
105
106 template <class _Duration>
107 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(const leap_second& __x, const sys_time<_Duration>& __y) {
108 return !(__x < __y);
109 }
110
111 template <class _Duration>
112 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(const sys_time<_Duration>& __x, const leap_second& __y) {
113 return !(__x < __y);
114 }
115
116 template <class _Duration>
117 requires three_way_comparable_with<sys_seconds, sys_time<_Duration>>
118 _LIBCPP_HIDE_FROM_ABI friend constexpr auto operator<=>(const leap_second& __x, const sys_time<_Duration>& __y) {
119 return __x.date() <=> __y;
120 }
121};
117122
118123} // namespace chrono
119124
120# endif //_LIBCPP_STD_VER >= 20
125# endif // _LIBCPP_STD_VER >= 20
121126
122127_LIBCPP_END_NAMESPACE_STD
123128
124#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
129#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
125130
126131#endif // _LIBCPP___CHRONO_LEAP_SECOND_H
lib/libcxx/include/__chrono/local_info.h+2-2
......@@ -14,7 +14,7 @@
1414
1515#include <version>
1616// Enable the contents of the header only when libc++ was built with experimental features enabled.
17#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
17#if _LIBCPP_HAS_EXPERIMENTAL_TZDB
1818
1919# include <__chrono/sys_info.h>
2020# include <__config>
......@@ -45,6 +45,6 @@ struct local_info {
4545
4646_LIBCPP_END_NAMESPACE_STD
4747
48#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
48#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
4949
5050#endif // _LIBCPP___CHRONO_LOCAL_INFO_H
lib/libcxx/include/__chrono/month.h+1-1
......@@ -11,8 +11,8 @@
1111#define _LIBCPP___CHRONO_MONTH_H
1212
1313#include <__chrono/duration.h>
14#include <__compare/ordering.h>
1415#include <__config>
15#include <compare>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818# pragma GCC system_header
lib/libcxx/include/__chrono/monthday.h+1-1
......@@ -13,8 +13,8 @@
1313#include <__chrono/calendar.h>
1414#include <__chrono/day.h>
1515#include <__chrono/month.h>
16#include <__compare/ordering.h>
1617#include <__config>
17#include <compare>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2020# pragma GCC system_header
lib/libcxx/include/__chrono/ostream.h+53-35
......@@ -10,37 +10,42 @@
1010#ifndef _LIBCPP___CHRONO_OSTREAM_H
1111#define _LIBCPP___CHRONO_OSTREAM_H
1212
13#include <__chrono/calendar.h>
14#include <__chrono/day.h>
15#include <__chrono/duration.h>
16#include <__chrono/file_clock.h>
17#include <__chrono/hh_mm_ss.h>
18#include <__chrono/local_info.h>
19#include <__chrono/month.h>
20#include <__chrono/month_weekday.h>
21#include <__chrono/monthday.h>
22#include <__chrono/statically_widen.h>
23#include <__chrono/sys_info.h>
24#include <__chrono/system_clock.h>
25#include <__chrono/weekday.h>
26#include <__chrono/year.h>
27#include <__chrono/year_month.h>
28#include <__chrono/year_month_day.h>
29#include <__chrono/year_month_weekday.h>
30#include <__chrono/zoned_time.h>
31#include <__concepts/same_as.h>
3213#include <__config>
33#include <__format/format_functions.h>
34#include <__fwd/ostream.h>
35#include <ratio>
3614
37#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
38# pragma GCC system_header
39#endif
15#if _LIBCPP_HAS_LOCALIZATION
16
17# include <__chrono/calendar.h>
18# include <__chrono/day.h>
19# include <__chrono/duration.h>
20# include <__chrono/file_clock.h>
21# include <__chrono/hh_mm_ss.h>
22# include <__chrono/local_info.h>
23# include <__chrono/month.h>
24# include <__chrono/month_weekday.h>
25# include <__chrono/monthday.h>
26# include <__chrono/statically_widen.h>
27# include <__chrono/sys_info.h>
28# include <__chrono/system_clock.h>
29# include <__chrono/utc_clock.h>
30# include <__chrono/weekday.h>
31# include <__chrono/year.h>
32# include <__chrono/year_month.h>
33# include <__chrono/year_month_day.h>
34# include <__chrono/year_month_weekday.h>
35# include <__chrono/zoned_time.h>
36# include <__concepts/same_as.h>
37# include <__format/format_functions.h>
38# include <__fwd/ostream.h>
39# include <ratio>
40# include <sstream>
41
42# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
43# pragma GCC system_header
44# endif
4045
4146_LIBCPP_BEGIN_NAMESPACE_STD
4247
43#if _LIBCPP_STD_VER >= 20
48# if _LIBCPP_STD_VER >= 20
4449
4550namespace chrono {
4651
......@@ -57,6 +62,18 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const sys_days& __dp) {
5762 return __os << year_month_day{__dp};
5863}
5964
65# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
66# if _LIBCPP_HAS_EXPERIMENTAL_TZDB
67
68template <class _CharT, class _Traits, class _Duration>
69_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
70operator<<(basic_ostream<_CharT, _Traits>& __os, const utc_time<_Duration>& __tp) {
71 return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T}"), __tp);
72}
73
74# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
75# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
76
6077template <class _CharT, class _Traits, class _Duration>
6178_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
6279operator<<(basic_ostream<_CharT, _Traits>& __os, const file_time<_Duration> __tp) {
......@@ -82,11 +99,11 @@ _LIBCPP_HIDE_FROM_ABI auto __units_suffix() {
8299 else if constexpr (same_as<typename _Period::type, nano>)
83100 return _LIBCPP_STATICALLY_WIDEN(_CharT, "ns");
84101 else if constexpr (same_as<typename _Period::type, micro>)
85# ifndef _LIBCPP_HAS_NO_UNICODE
102# if _LIBCPP_HAS_UNICODE
86103 return _LIBCPP_STATICALLY_WIDEN(_CharT, "\u00b5s");
87# else
104# else
88105 return _LIBCPP_STATICALLY_WIDEN(_CharT, "us");
89# endif
106# endif
90107 else if constexpr (same_as<typename _Period::type, milli>)
91108 return _LIBCPP_STATICALLY_WIDEN(_CharT, "ms");
92109 else if constexpr (same_as<typename _Period::type, centi>)
......@@ -265,7 +282,7 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const hh_mm_ss<_Duration> __hms
265282 return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%T}"), __hms);
266283}
267284
268# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
285# if _LIBCPP_HAS_EXPERIMENTAL_TZDB
269286
270287template <class _CharT, class _Traits>
271288_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
......@@ -303,20 +320,21 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const local_info& __info) {
303320 _LIBCPP_STATICALLY_WIDEN(_CharT, "{}: {{{}, {}}}"), __result(), __info.first, __info.second);
304321}
305322
306# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
307 !defined(_LIBCPP_HAS_NO_LOCALIZATION)
323# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
308324template <class _CharT, class _Traits, class _Duration, class _TimeZonePtr>
309325_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
310326operator<<(basic_ostream<_CharT, _Traits>& __os, const zoned_time<_Duration, _TimeZonePtr>& __tp) {
311327 return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T %Z}"), __tp);
312328}
313# endif
314# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
329# endif
330# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
315331
316332} // namespace chrono
317333
318#endif // if _LIBCPP_STD_VER >= 20
334# endif // if _LIBCPP_STD_VER >= 20
319335
320336_LIBCPP_END_NAMESPACE_STD
321337
338#endif // _LIBCPP_HAS_LOCALIZATION
339
322340#endif // _LIBCPP___CHRONO_OSTREAM_H
lib/libcxx/include/__chrono/parser_std_format_spec.h+17-12
......@@ -11,20 +11,23 @@
1111#define _LIBCPP___CHRONO_PARSER_STD_FORMAT_SPEC_H
1212
1313#include <__config>
14#include <__format/concepts.h>
15#include <__format/format_error.h>
16#include <__format/format_parse_context.h>
17#include <__format/formatter_string.h>
18#include <__format/parser_std_format_spec.h>
19#include <string_view>
2014
21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22# pragma GCC system_header
23#endif
15#if _LIBCPP_HAS_LOCALIZATION
16
17# include <__format/concepts.h>
18# include <__format/format_error.h>
19# include <__format/format_parse_context.h>
20# include <__format/formatter_string.h>
21# include <__format/parser_std_format_spec.h>
22# include <string_view>
23
24# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26# endif
2427
2528_LIBCPP_BEGIN_NAMESPACE_STD
2629
27#if _LIBCPP_STD_VER >= 20
30# if _LIBCPP_STD_VER >= 20
2831
2932namespace __format_spec {
3033
......@@ -137,7 +140,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr void __validate_time_zone(__flags __flags) {
137140
138141template <class _CharT>
139142class _LIBCPP_TEMPLATE_VIS __parser_chrono {
140 using _ConstIterator = typename basic_format_parse_context<_CharT>::const_iterator;
143 using _ConstIterator _LIBCPP_NODEBUG = typename basic_format_parse_context<_CharT>::const_iterator;
141144
142145public:
143146 template <class _ParseContext>
......@@ -409,8 +412,10 @@ private:
409412
410413} // namespace __format_spec
411414
412#endif //_LIBCPP_STD_VER >= 20
415# endif // _LIBCPP_STD_VER >= 20
413416
414417_LIBCPP_END_NAMESPACE_STD
415418
419#endif // _LIBCPP_HAS_LOCALIZATION
420
416421#endif // _LIBCPP___CHRONO_PARSER_STD_FORMAT_SPEC_H
lib/libcxx/include/__chrono/statically_widen.h+4-4
......@@ -24,7 +24,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2424
2525#if _LIBCPP_STD_VER >= 20
2626
27# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
27# if _LIBCPP_HAS_WIDE_CHARACTERS
2828template <__fmt_char_type _CharT>
2929_LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __statically_widen(const char* __str, const wchar_t* __wstr) {
3030 if constexpr (same_as<_CharT, char>)
......@@ -33,7 +33,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __statically_widen(const char* __s
3333 return __wstr;
3434}
3535# define _LIBCPP_STATICALLY_WIDEN(_CharT, __str) ::std::__statically_widen<_CharT>(__str, L##__str)
36# else // _LIBCPP_HAS_NO_WIDE_CHARACTERS
36# else // _LIBCPP_HAS_WIDE_CHARACTERS
3737
3838// Without this indirection the unit test test/libcxx/modules_include.sh.cpp
3939// 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
4343 return __str;
4444}
4545# define _LIBCPP_STATICALLY_WIDEN(_CharT, __str) ::std::__statically_widen<_CharT>(__str)
46# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
46# endif // _LIBCPP_HAS_WIDE_CHARACTERS
4747
48#endif //_LIBCPP_STD_VER >= 20
48#endif // _LIBCPP_STD_VER >= 20
4949
5050_LIBCPP_END_NAMESPACE_STD
5151
lib/libcxx/include/__chrono/steady_clock.h+1-1
......@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222
2323namespace chrono {
2424
25#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
25#if _LIBCPP_HAS_MONOTONIC_CLOCK
2626class _LIBCPP_EXPORTED_FROM_ABI steady_clock {
2727public:
2828 typedef nanoseconds duration;
lib/libcxx/include/__chrono/sys_info.h+2-2
......@@ -14,7 +14,7 @@
1414
1515#include <version>
1616// Enable the contents of the header only when libc++ was built with experimental features enabled.
17#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
17#if _LIBCPP_HAS_EXPERIMENTAL_TZDB
1818
1919# include <__chrono/duration.h>
2020# include <__chrono/system_clock.h>
......@@ -46,6 +46,6 @@ struct sys_info {
4646
4747_LIBCPP_END_NAMESPACE_STD
4848
49#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
49#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
5050
5151#endif // _LIBCPP___CHRONO_SYS_INFO_H
lib/libcxx/include/__chrono/time_point.h+4-5
......@@ -32,8 +32,7 @@ namespace chrono {
3232
3333template <class _Clock, class _Duration = typename _Clock::duration>
3434class _LIBCPP_TEMPLATE_VIS time_point {
35 static_assert(__is_duration<_Duration>::value,
36 "Second template parameter of time_point must be a std::chrono::duration");
35 static_assert(__is_duration_v<_Duration>, "Second template parameter of time_point must be a std::chrono::duration");
3736
3837public:
3938 typedef _Clock clock;
......@@ -91,17 +90,17 @@ time_point_cast(const time_point<_Clock, _Duration>& __t) {
9190}
9291
9392#if _LIBCPP_STD_VER >= 17
94template <class _ToDuration, class _Clock, class _Duration, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
93template <class _ToDuration, class _Clock, class _Duration, enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
9594inline _LIBCPP_HIDE_FROM_ABI constexpr time_point<_Clock, _ToDuration> floor(const time_point<_Clock, _Duration>& __t) {
9695 return time_point<_Clock, _ToDuration>{chrono::floor<_ToDuration>(__t.time_since_epoch())};
9796}
9897
99template <class _ToDuration, class _Clock, class _Duration, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
98template <class _ToDuration, class _Clock, class _Duration, enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
10099inline _LIBCPP_HIDE_FROM_ABI constexpr time_point<_Clock, _ToDuration> ceil(const time_point<_Clock, _Duration>& __t) {
101100 return time_point<_Clock, _ToDuration>{chrono::ceil<_ToDuration>(__t.time_since_epoch())};
102101}
103102
104template <class _ToDuration, class _Clock, class _Duration, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
103template <class _ToDuration, class _Clock, class _Duration, enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
105104inline _LIBCPP_HIDE_FROM_ABI constexpr time_point<_Clock, _ToDuration> round(const time_point<_Clock, _Duration>& __t) {
106105 return time_point<_Clock, _ToDuration>{chrono::round<_ToDuration>(__t.time_since_epoch())};
107106}
lib/libcxx/include/__chrono/time_zone.h+11-8
......@@ -14,7 +14,7 @@
1414
1515#include <version>
1616// Enable the contents of the header only when libc++ was built with experimental features enabled.
17#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
17#if _LIBCPP_HAS_EXPERIMENTAL_TZDB
1818
1919# include <__chrono/calendar.h>
2020# include <__chrono/duration.h>
......@@ -37,8 +37,7 @@ _LIBCPP_PUSH_MACROS
3737
3838_LIBCPP_BEGIN_NAMESPACE_STD
3939
40# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
41 !defined(_LIBCPP_HAS_NO_LOCALIZATION)
40# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
4241
4342namespace chrono {
4443
......@@ -104,10 +103,14 @@ public:
104103 to_sys(const local_time<_Duration>& __time, choose __z) const {
105104 local_info __info = get_info(__time);
106105 switch (__info.result) {
107 case local_info::unique:
108 case local_info::nonexistent: // first and second are the same
106 case local_info::unique: // first and second are the same
109107 return sys_time<common_type_t<_Duration, seconds>>{__time.time_since_epoch() - __info.first.offset};
110108
109 case local_info::nonexistent:
110 // first and second are the same
111 // All non-existing values are converted to the same time.
112 return sys_time<common_type_t<_Duration, seconds>>{__info.first.end};
113
111114 case local_info::ambiguous:
112115 switch (__z) {
113116 case choose::earliest:
......@@ -170,13 +173,13 @@ operator<=>(const time_zone& __x, const time_zone& __y) noexcept {
170173
171174} // namespace chrono
172175
173# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
174 // && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
176# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM &&
177 // _LIBCPP_HAS_LOCALIZATION
175178
176179_LIBCPP_END_NAMESPACE_STD
177180
178181_LIBCPP_POP_MACROS
179182
180#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
183#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
181184
182185#endif // _LIBCPP___CHRONO_TIME_ZONE_H
lib/libcxx/include/__chrono/time_zone_link.h+5-5
......@@ -14,7 +14,7 @@
1414
1515#include <version>
1616// Enable the contents of the header only when libc++ was built with experimental features enabled.
17#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
17#if _LIBCPP_HAS_EXPERIMENTAL_TZDB
1818
1919# include <__compare/strong_order.h>
2020# include <__config>
......@@ -31,8 +31,7 @@ _LIBCPP_PUSH_MACROS
3131
3232_LIBCPP_BEGIN_NAMESPACE_STD
3333
34# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
35 !defined(_LIBCPP_HAS_NO_LOCALIZATION)
34# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
3635
3736namespace chrono {
3837
......@@ -68,12 +67,13 @@ operator<=>(const time_zone_link& __x, const time_zone_link& __y) noexcept {
6867
6968} // namespace chrono
7069
71# endif //_LIBCPP_STD_VER >= 20
70# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM &&
71 // _LIBCPP_HAS_LOCALIZATION
7272
7373_LIBCPP_END_NAMESPACE_STD
7474
7575_LIBCPP_POP_MACROS
7676
77#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
77#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
7878
7979#endif // _LIBCPP___CHRONO_TIME_ZONE_LINK_H
lib/libcxx/include/__chrono/tzdb.h+9-7
......@@ -14,15 +14,18 @@
1414
1515#include <version>
1616// Enable the contents of the header only when libc++ was built with experimental features enabled.
17#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
17#if _LIBCPP_HAS_EXPERIMENTAL_TZDB
1818
1919# include <__algorithm/ranges_lower_bound.h>
2020# include <__chrono/leap_second.h>
2121# include <__chrono/time_zone.h>
2222# include <__chrono/time_zone_link.h>
2323# include <__config>
24# include <__memory/addressof.h>
25# include <__vector/vector.h>
26# include <stdexcept>
2427# include <string>
25# include <vector>
28# include <string_view>
2629
2730# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2831# pragma GCC system_header
......@@ -33,8 +36,7 @@ _LIBCPP_PUSH_MACROS
3336
3437_LIBCPP_BEGIN_NAMESPACE_STD
3538
36# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
37 !defined(_LIBCPP_HAS_NO_LOCALIZATION)
39# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
3840
3941namespace chrono {
4042
......@@ -82,13 +84,13 @@ private:
8284
8385} // namespace chrono
8486
85# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
86 // && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
87# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM &&
88 // _LIBCPP_HAS_LOCALIZATION
8789
8890_LIBCPP_END_NAMESPACE_STD
8991
9092_LIBCPP_POP_MACROS
9193
92#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
94#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
9395
9496#endif // _LIBCPP___CHRONO_TZDB_H
lib/libcxx/include/__chrono/tzdb_list.h+6-6
......@@ -14,13 +14,14 @@
1414
1515#include <version>
1616// Enable the contents of the header only when libc++ was built with experimental features enabled.
17#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
17#if _LIBCPP_HAS_EXPERIMENTAL_TZDB
1818
1919# include <__chrono/time_zone.h>
2020# include <__chrono/tzdb.h>
2121# include <__config>
2222# include <__fwd/string.h>
2323# include <forward_list>
24# include <string_view>
2425
2526# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2627# pragma GCC system_header
......@@ -28,8 +29,7 @@
2829
2930_LIBCPP_BEGIN_NAMESPACE_STD
3031
31# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
32 !defined(_LIBCPP_HAS_NO_LOCALIZATION)
32# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
3333
3434namespace chrono {
3535
......@@ -98,11 +98,11 @@ _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI const tzdb& reload_tzdb();
9898
9999} // namespace chrono
100100
101# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
102 // && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
101# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM &&
102 // _LIBCPP_HAS_LOCALIZATION
103103
104104_LIBCPP_END_NAMESPACE_STD
105105
106#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
106#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
107107
108108#endif // _LIBCPP___CHRONO_TZDB_LIST_H
lib/libcxx/include/__chrono/utc_clock.h created+163
......@@ -0,0 +1,163 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CHRONO_UTC_CLOCK_H
11#define _LIBCPP___CHRONO_UTC_CLOCK_H
12
13#include <version>
14// Enable the contents of the header only when libc++ was built with experimental features enabled.
15#if _LIBCPP_HAS_EXPERIMENTAL_TZDB
16
17# include <__chrono/duration.h>
18# include <__chrono/leap_second.h>
19# include <__chrono/system_clock.h>
20# include <__chrono/time_point.h>
21# include <__chrono/tzdb.h>
22# include <__chrono/tzdb_list.h>
23# include <__config>
24# include <__type_traits/common_type.h>
25
26# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28# endif
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
33
34namespace chrono {
35
36class utc_clock;
37
38template <class _Duration>
39using utc_time = time_point<utc_clock, _Duration>;
40using utc_seconds = utc_time<seconds>;
41
42class utc_clock {
43public:
44 using rep = system_clock::rep;
45 using period = system_clock::period;
46 using duration = chrono::duration<rep, period>;
47 using time_point = chrono::time_point<utc_clock>;
48 static constexpr bool is_steady = false; // The system_clock is not steady.
49
50 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static time_point now() { return from_sys(system_clock::now()); }
51
52 template <class _Duration>
53 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static sys_time<common_type_t<_Duration, seconds>>
54 to_sys(const utc_time<_Duration>& __time);
55
56 template <class _Duration>
57 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static utc_time<common_type_t<_Duration, seconds>>
58 from_sys(const sys_time<_Duration>& __time) {
59 using _Rp = utc_time<common_type_t<_Duration, seconds>>;
60 // TODO TZDB investigate optimizations.
61 //
62 // The leap second database stores all transitions, this mean to calculate
63 // the current number of leap seconds the code needs to iterate over all
64 // leap seconds to accumulate the sum. Then the sum can be used to determine
65 // the sys_time. Accessing the database involves acquiring a mutex.
66 //
67 // The historic entries in the database are immutable. Hard-coding these
68 // values in a table would allow:
69 // - To store the sum, allowing a binary search on the data.
70 // - Avoid acquiring a mutex.
71 // The disadvantage are:
72 // - A slightly larger code size.
73 //
74 // There are two optimization directions
75 // - hard-code the database and do a linear search for future entries. This
76 // search can start at the back, and should probably contain very few
77 // entries. (Adding leap seconds is quite rare and new release of libc++
78 // can add the new entries; they are announced half a year before they are
79 // added.)
80 // - During parsing the leap seconds store an additional database in the
81 // dylib with the list of the sum of the leap seconds. In that case there
82 // can be a private function __get_utc_to_sys_table that returns the
83 // table.
84 //
85 // Note for to_sys there are no optimizations to be done; it uses
86 // get_leap_second_info. The function get_leap_second_info could benefit
87 // from optimizations as described above; again both options apply.
88
89 // Both UTC and the system clock use the same epoch. The Standard
90 // specifies from 1970-01-01 even when UTC starts at
91 // 1972-01-01 00:00:10 TAI. So when the sys_time is before epoch we can be
92 // sure there both clocks return the same value.
93
94 const tzdb& __tzdb = chrono::get_tzdb();
95 _Rp __result{__time.time_since_epoch()};
96 for (const auto& __leap_second : __tzdb.leap_seconds) {
97 if (__leap_second > __time)
98 return __result;
99
100 __result += __leap_second.value();
101 }
102 return __result;
103 }
104};
105
106struct leap_second_info {
107 bool is_leap_second;
108 seconds elapsed;
109};
110
111template <class _Duration>
112[[nodiscard]] _LIBCPP_HIDE_FROM_ABI leap_second_info get_leap_second_info(const utc_time<_Duration>& __time) {
113 const tzdb& __tzdb = chrono::get_tzdb();
114 if (__tzdb.leap_seconds.empty()) [[unlikely]]
115 return {false, chrono::seconds{0}};
116
117 sys_seconds __sys{chrono::floor<seconds>(__time).time_since_epoch()};
118 seconds __elapsed{0};
119 for (const auto& __leap_second : __tzdb.leap_seconds) {
120 if (__sys == __leap_second.date() + __elapsed)
121 // A time point may only be a leap second during a positive leap second
122 // insertion, since time points that occur during a (theoretical)
123 // negative leap second don't exist.
124 return {__leap_second.value() > 0s, __elapsed + __leap_second.value()};
125
126 if (__sys < __leap_second.date() + __elapsed)
127 return {false, __elapsed};
128
129 __elapsed += __leap_second.value();
130 }
131
132 return {false, __elapsed};
133}
134
135template <class _Duration>
136[[nodiscard]] _LIBCPP_HIDE_FROM_ABI sys_time<common_type_t<_Duration, seconds>>
137utc_clock::to_sys(const utc_time<_Duration>& __time) {
138 using _Dp = common_type_t<_Duration, seconds>;
139 leap_second_info __info = chrono::get_leap_second_info(__time);
140
141 // [time.clock.utc.members]/2
142 // Returns: A sys_time t, such that from_sys(t) == u if such a mapping
143 // exists. Otherwise u represents a time_point during a positive leap
144 // second insertion, the conversion counts that leap second as not
145 // inserted, and the last representable value of sys_time prior to the
146 // insertion of the leap second is returned.
147 sys_time<common_type_t<_Duration, seconds>> __result{__time.time_since_epoch() - __info.elapsed};
148 if (__info.is_leap_second)
149 return chrono::floor<seconds>(__result) + chrono::seconds{1} - _Dp{1};
150
151 return __result;
152}
153
154} // namespace chrono
155
156# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM &&
157 // _LIBCPP_HAS_LOCALIZATION
158
159_LIBCPP_END_NAMESPACE_STD
160
161#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
162
163#endif // _LIBCPP___CHRONO_UTC_CLOCK_H
lib/libcxx/include/__chrono/weekday.h-19
......@@ -79,25 +79,6 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const weekday& __lhs, con
7979 return __lhs.c_encoding() == __rhs.c_encoding();
8080}
8181
82// TODO(LLVM 20): Remove the escape hatch
83# ifdef _LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS
84_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator<(const weekday& __lhs, const weekday& __rhs) noexcept {
85 return __lhs.c_encoding() < __rhs.c_encoding();
86}
87
88_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator>(const weekday& __lhs, const weekday& __rhs) noexcept {
89 return __rhs < __lhs;
90}
91
92_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept {
93 return !(__rhs < __lhs);
94}
95
96_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept {
97 return !(__lhs < __rhs);
98}
99# endif // _LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS
100
10182_LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept {
10283 auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count();
10384 auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7;
lib/libcxx/include/__chrono/year.h+1-1
......@@ -11,8 +11,8 @@
1111#define _LIBCPP___CHRONO_YEAR_H
1212
1313#include <__chrono/duration.h>
14#include <__compare/ordering.h>
1415#include <__config>
15#include <compare>
1616#include <limits>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__chrono/year_month.h+1-1
......@@ -13,8 +13,8 @@
1313#include <__chrono/duration.h>
1414#include <__chrono/month.h>
1515#include <__chrono/year.h>
16#include <__compare/ordering.h>
1617#include <__config>
17#include <compare>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2020# pragma GCC system_header
lib/libcxx/include/__chrono/year_month_day.h+1-1
......@@ -19,8 +19,8 @@
1919#include <__chrono/time_point.h>
2020#include <__chrono/year.h>
2121#include <__chrono/year_month.h>
22#include <__compare/ordering.h>
2223#include <__config>
23#include <compare>
2424#include <limits>
2525
2626#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__chrono/zoned_time.h+13-12
......@@ -14,7 +14,7 @@
1414
1515#include <version>
1616// Enable the contents of the header only when libc++ was built with experimental features enabled.
17#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
17#if _LIBCPP_HAS_EXPERIMENTAL_TZDB
1818
1919# include <__chrono/calendar.h>
2020# include <__chrono/duration.h>
......@@ -22,12 +22,14 @@
2222# include <__chrono/system_clock.h>
2323# include <__chrono/time_zone.h>
2424# include <__chrono/tzdb_list.h>
25# include <__concepts/constructible.h>
2526# include <__config>
26# include <__fwd/string_view.h>
2727# include <__type_traits/common_type.h>
2828# include <__type_traits/conditional.h>
2929# include <__type_traits/remove_cvref.h>
30# include <__utility/declval.h>
3031# include <__utility/move.h>
32# include <string_view>
3133
3234# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3335# pragma GCC system_header
......@@ -38,8 +40,7 @@ _LIBCPP_PUSH_MACROS
3840
3941_LIBCPP_BEGIN_NAMESPACE_STD
4042
41# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
42 !defined(_LIBCPP_HAS_NO_LOCALIZATION)
43# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
4344
4445namespace chrono {
4546
......@@ -57,7 +58,7 @@ struct zoned_traits<const time_zone*> {
5758template <class _Duration, class _TimeZonePtr = const time_zone*>
5859class zoned_time {
5960 // [time.zone.zonedtime.ctor]/2
60 static_assert(__is_duration<_Duration>::value,
61 static_assert(__is_duration_v<_Duration>,
6162 "the program is ill-formed since _Duration is not a specialization of std::chrono::duration");
6263
6364 // The wording uses the constraints like
......@@ -65,7 +66,7 @@ class zoned_time {
6566 // Using these constraints in the code causes the compiler to give an
6667 // error that the constraint depends on itself. To avoid that issue use
6768 // the fact it is possible to create this object from a _TimeZonePtr.
68 using __traits = zoned_traits<_TimeZonePtr>;
69 using __traits _LIBCPP_NODEBUG = zoned_traits<_TimeZonePtr>;
6970
7071public:
7172 using duration = common_type_t<_Duration, seconds>;
......@@ -185,7 +186,7 @@ template <class _Duration>
185186zoned_time(sys_time<_Duration>) -> zoned_time<common_type_t<_Duration, seconds>>;
186187
187188template <class _TimeZonePtrOrName>
188using __time_zone_representation =
189using __time_zone_representation _LIBCPP_NODEBUG =
189190 conditional_t<is_convertible_v<_TimeZonePtrOrName, string_view>,
190191 const time_zone*,
191192 remove_cvref_t<_TimeZonePtrOrName>>;
......@@ -201,8 +202,8 @@ template <class _TimeZonePtrOrName, class _Duration>
201202zoned_time(_TimeZonePtrOrName&&, local_time<_Duration>, choose = choose::earliest)
202203 -> zoned_time<common_type_t<_Duration, seconds>, __time_zone_representation<_TimeZonePtrOrName>>;
203204
204template <class _Duration, class _TimeZonePtrOrName, class TimeZonePtr2>
205zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, TimeZonePtr2>, choose = choose::earliest)
205template <class _Duration, class _TimeZonePtrOrName, class _TimeZonePtr2>
206zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, _TimeZonePtr2>, choose = choose::earliest)
206207 -> zoned_time<common_type_t<_Duration, seconds>, __time_zone_representation<_TimeZonePtrOrName>>;
207208
208209using zoned_seconds = zoned_time<seconds>;
......@@ -215,13 +216,13 @@ operator==(const zoned_time<_Duration1, _TimeZonePtr>& __lhs, const zoned_time<_
215216
216217} // namespace chrono
217218
218# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
219 // && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
219# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM &&
220 // _LIBCPP_HAS_LOCALIZATION
220221
221222_LIBCPP_END_NAMESPACE_STD
222223
223224_LIBCPP_POP_MACROS
224225
225#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
226#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
226227
227228#endif // _LIBCPP___CHRONO_ZONED_TIME_H
lib/libcxx/include/__compare/common_comparison_category.h+1-1
......@@ -11,8 +11,8 @@
1111
1212#include <__compare/ordering.h>
1313#include <__config>
14#include <__cstddef/size_t.h>
1415#include <__type_traits/is_same.h>
15#include <cstddef>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818# pragma GCC system_header
lib/libcxx/include/__compare/compare_partial_order_fallback.h+11-12
......@@ -11,6 +11,7 @@
1111
1212#include <__compare/ordering.h>
1313#include <__compare/partial_order.h>
14#include <__concepts/boolean_testable.h>
1415#include <__config>
1516#include <__type_traits/decay.h>
1617#include <__type_traits/is_same.h>
......@@ -37,18 +38,16 @@ struct __fn {
3738 }
3839
3940 template <class _Tp, class _Up>
40 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
41 _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(noexcept(
42 std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? partial_ordering::equivalent
43 : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? partial_ordering::less
44 : std::forward<_Up>(__u) < std::forward<_Tp>(__t)
45 ? partial_ordering::greater
46 : partial_ordering::unordered))
47 -> decltype(std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? partial_ordering::equivalent
48 : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? partial_ordering::less
49 : std::forward<_Up>(__u) < std::forward<_Tp>(__t)
50 ? partial_ordering::greater
51 : partial_ordering::unordered) {
41 requires is_same_v<decay_t<_Tp>, decay_t<_Up>> && requires(_Tp&& __t, _Up&& __u) {
42 { std::forward<_Tp>(__t) == std::forward<_Up>(__u) } -> __boolean_testable;
43 { std::forward<_Tp>(__t) < std::forward<_Up>(__u) } -> __boolean_testable;
44 { std::forward<_Up>(__u) < std::forward<_Tp>(__t) } -> __boolean_testable;
45 }
46 _LIBCPP_HIDE_FROM_ABI static constexpr partial_ordering __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(
47 noexcept(std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? partial_ordering::equivalent
48 : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? partial_ordering::less
49 : std::forward<_Up>(__u) < std::forward<_Tp>(__t) ? partial_ordering::greater
50 : partial_ordering::unordered)) {
5251 return std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? partial_ordering::equivalent
5352 : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? partial_ordering::less
5453 : std::forward<_Up>(__u) < std::forward<_Tp>(__t)
lib/libcxx/include/__compare/compare_strong_order_fallback.h+9-10
......@@ -11,6 +11,7 @@
1111
1212#include <__compare/ordering.h>
1313#include <__compare/strong_order.h>
14#include <__concepts/boolean_testable.h>
1415#include <__config>
1516#include <__type_traits/decay.h>
1617#include <__type_traits/is_same.h>
......@@ -37,16 +38,14 @@ struct __fn {
3738 }
3839
3940 template <class _Tp, class _Up>
40 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
41 _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(noexcept(
42 std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? strong_ordering::equal
43 : std::forward<_Tp>(__t) < std::forward<_Up>(__u)
44 ? strong_ordering::less
45 : strong_ordering::greater))
46 -> decltype(std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? strong_ordering::equal
47 : std::forward<_Tp>(__t) < std::forward<_Up>(__u)
48 ? strong_ordering::less
49 : strong_ordering::greater) {
41 requires is_same_v<decay_t<_Tp>, decay_t<_Up>> && requires(_Tp&& __t, _Up&& __u) {
42 { std::forward<_Tp>(__t) == std::forward<_Up>(__u) } -> __boolean_testable;
43 { std::forward<_Tp>(__t) < std::forward<_Up>(__u) } -> __boolean_testable;
44 }
45 _LIBCPP_HIDE_FROM_ABI static constexpr strong_ordering __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(
46 noexcept(std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? strong_ordering::equal
47 : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? strong_ordering::less
48 : strong_ordering::greater)) {
5049 return std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? strong_ordering::equal
5150 : std::forward<_Tp>(__t) < std::forward<_Up>(__u)
5251 ? strong_ordering::less
lib/libcxx/include/__compare/compare_three_way_result.h+2-1
......@@ -33,7 +33,8 @@ struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result<
3333};
3434
3535template <class _Tp, class _Up = _Tp>
36struct _LIBCPP_TEMPLATE_VIS compare_three_way_result : __compare_three_way_result<_Tp, _Up, void> {};
36struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS compare_three_way_result
37 : __compare_three_way_result<_Tp, _Up, void> {};
3738
3839template <class _Tp, class _Up = _Tp>
3940using compare_three_way_result_t = typename compare_three_way_result<_Tp, _Up>::type;
lib/libcxx/include/__compare/compare_weak_order_fallback.h+7-7
......@@ -11,6 +11,7 @@
1111
1212#include <__compare/ordering.h>
1313#include <__compare/weak_order.h>
14#include <__concepts/boolean_testable.h>
1415#include <__config>
1516#include <__type_traits/decay.h>
1617#include <__type_traits/is_same.h>
......@@ -37,16 +38,15 @@ struct __fn {
3738 }
3839
3940 template <class _Tp, class _Up>
40 requires is_same_v<decay_t<_Tp>, decay_t<_Up>>
41 _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(noexcept(
41 requires is_same_v<decay_t<_Tp>, decay_t<_Up>> && requires(_Tp&& __t, _Up&& __u) {
42 { std::forward<_Tp>(__t) == std::forward<_Up>(__u) } -> __boolean_testable;
43 { std::forward<_Tp>(__t) < std::forward<_Up>(__u) } -> __boolean_testable;
44 }
45 _LIBCPP_HIDE_FROM_ABI static constexpr weak_ordering __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(noexcept(
4246 std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? weak_ordering::equivalent
4347 : std::forward<_Tp>(__t) < std::forward<_Up>(__u)
4448 ? weak_ordering::less
45 : weak_ordering::greater))
46 -> decltype(std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? weak_ordering::equivalent
47 : std::forward<_Tp>(__t) < std::forward<_Up>(__u)
48 ? weak_ordering::less
49 : weak_ordering::greater) {
49 : weak_ordering::greater)) {
5050 return std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? weak_ordering::equivalent
5151 : std::forward<_Tp>(__t) < std::forward<_Up>(__u)
5252 ? weak_ordering::less
lib/libcxx/include/__compare/ordering.h+38-34
......@@ -24,32 +24,35 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2424// exposition only
2525enum class _OrdResult : signed char { __less = -1, __equiv = 0, __greater = 1 };
2626
27enum class _NCmpResult : signed char { __unordered = -127 };
27enum class _PartialOrdResult : signed char {
28 __less = static_cast<signed char>(_OrdResult::__less),
29 __equiv = static_cast<signed char>(_OrdResult::__equiv),
30 __greater = static_cast<signed char>(_OrdResult::__greater),
31 __unordered = -127,
32};
2833
2934class partial_ordering;
3035class weak_ordering;
3136class strong_ordering;
3237
33template <class _Tp, class... _Args>
34inline constexpr bool __one_of_v = (is_same_v<_Tp, _Args> || ...);
35
3638struct _CmpUnspecifiedParam {
37 _LIBCPP_HIDE_FROM_ABI constexpr _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
38
39 template <class _Tp, class = enable_if_t<!__one_of_v<_Tp, int, partial_ordering, weak_ordering, strong_ordering>>>
40 _CmpUnspecifiedParam(_Tp) = delete;
39 // If anything other than a literal 0 is provided, the behavior is undefined by the Standard.
40 //
41 // The alternative to the `__enable_if__` attribute would be to use the fact that a pointer
42 // can be constructed from literal 0, but this conflicts with `-Wzero-as-null-pointer-constant`.
43 template <class _Tp, class = __enable_if_t<is_same_v<_Tp, int> > >
44 _LIBCPP_HIDE_FROM_ABI consteval _CmpUnspecifiedParam(_Tp __zero) noexcept
45# if __has_attribute(__enable_if__)
46 __attribute__((__enable_if__(
47 __zero == 0, "Only literal 0 is allowed as the operand of a comparison with one of the ordering types")))
48# endif
49 {
50 (void)__zero;
51 }
4152};
4253
4354class partial_ordering {
44 using _ValueT = signed char;
45
46 _LIBCPP_HIDE_FROM_ABI explicit constexpr partial_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
47
48 _LIBCPP_HIDE_FROM_ABI explicit constexpr partial_ordering(_NCmpResult __v) noexcept : __value_(_ValueT(__v)) {}
49
50 _LIBCPP_HIDE_FROM_ABI constexpr bool __is_ordered() const noexcept {
51 return __value_ != _ValueT(_NCmpResult::__unordered);
52 }
55 _LIBCPP_HIDE_FROM_ABI explicit constexpr partial_ordering(_PartialOrdResult __v) noexcept : __value_(__v) {}
5356
5457public:
5558 // valid values
......@@ -62,39 +65,39 @@ public:
6265 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default;
6366
6467 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
65 return __v.__is_ordered() && __v.__value_ == 0;
68 return __v.__value_ == _PartialOrdResult::__equiv;
6669 }
6770
6871 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
69 return __v.__is_ordered() && __v.__value_ < 0;
72 return __v.__value_ == _PartialOrdResult::__less;
7073 }
7174
7275 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
73 return __v.__is_ordered() && __v.__value_ <= 0;
76 return __v.__value_ == _PartialOrdResult::__equiv || __v.__value_ == _PartialOrdResult::__less;
7477 }
7578
7679 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
77 return __v.__is_ordered() && __v.__value_ > 0;
80 return __v.__value_ == _PartialOrdResult::__greater;
7881 }
7982
8083 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
81 return __v.__is_ordered() && __v.__value_ >= 0;
84 return __v.__value_ == _PartialOrdResult::__equiv || __v.__value_ == _PartialOrdResult::__greater;
8285 }
8386
8487 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
85 return __v.__is_ordered() && 0 < __v.__value_;
88 return __v.__value_ == _PartialOrdResult::__greater;
8689 }
8790
8891 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
89 return __v.__is_ordered() && 0 <= __v.__value_;
92 return __v.__value_ == _PartialOrdResult::__equiv || __v.__value_ == _PartialOrdResult::__greater;
9093 }
9194
9295 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
93 return __v.__is_ordered() && 0 > __v.__value_;
96 return __v.__value_ == _PartialOrdResult::__less;
9497 }
9598
9699 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
97 return __v.__is_ordered() && 0 >= __v.__value_;
100 return __v.__value_ == _PartialOrdResult::__equiv || __v.__value_ == _PartialOrdResult::__less;
98101 }
99102
100103 _LIBCPP_HIDE_FROM_ABI friend constexpr partial_ordering
......@@ -108,16 +111,16 @@ public:
108111 }
109112
110113private:
111 _ValueT __value_;
114 _PartialOrdResult __value_;
112115};
113116
114inline constexpr partial_ordering partial_ordering::less(_OrdResult::__less);
115inline constexpr partial_ordering partial_ordering::equivalent(_OrdResult::__equiv);
116inline constexpr partial_ordering partial_ordering::greater(_OrdResult::__greater);
117inline constexpr partial_ordering partial_ordering::unordered(_NCmpResult ::__unordered);
117inline constexpr partial_ordering partial_ordering::less(_PartialOrdResult::__less);
118inline constexpr partial_ordering partial_ordering::equivalent(_PartialOrdResult::__equiv);
119inline constexpr partial_ordering partial_ordering::greater(_PartialOrdResult::__greater);
120inline constexpr partial_ordering partial_ordering::unordered(_PartialOrdResult::__unordered);
118121
119122class weak_ordering {
120 using _ValueT = signed char;
123 using _ValueT _LIBCPP_NODEBUG = signed char;
121124
122125 _LIBCPP_HIDE_FROM_ABI explicit constexpr weak_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
123126
......@@ -187,7 +190,7 @@ inline constexpr weak_ordering weak_ordering::equivalent(_OrdResult::__equiv);
187190inline constexpr weak_ordering weak_ordering::greater(_OrdResult::__greater);
188191
189192class strong_ordering {
190 using _ValueT = signed char;
193 using _ValueT _LIBCPP_NODEBUG = signed char;
191194
192195 _LIBCPP_HIDE_FROM_ABI explicit constexpr strong_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
193196
......@@ -269,7 +272,8 @@ inline constexpr strong_ordering strong_ordering::greater(_OrdResult::__greater)
269272/// The types partial_ordering, weak_ordering, and strong_ordering are
270273/// collectively termed the comparison category types.
271274template <class _Tp>
272concept __comparison_category = __one_of_v<_Tp, partial_ordering, weak_ordering, strong_ordering>;
275concept __comparison_category =
276 is_same_v<_Tp, partial_ordering> || is_same_v<_Tp, weak_ordering> || is_same_v<_Tp, strong_ordering>;
273277
274278#endif // _LIBCPP_STD_VER >= 20
275279
lib/libcxx/include/__compare/synth_three_way.h+2-1
......@@ -43,7 +43,8 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way = []<class _Tp, cl
4343};
4444
4545template <class _Tp, class _Up = _Tp>
46using __synth_three_way_result = decltype(std::__synth_three_way(std::declval<_Tp&>(), std::declval<_Up&>()));
46using __synth_three_way_result _LIBCPP_NODEBUG =
47 decltype(std::__synth_three_way(std::declval<_Tp&>(), std::declval<_Up&>()));
4748
4849#endif // _LIBCPP_STD_VER >= 20
4950
lib/libcxx/include/__concepts/predicate.h+1-1
......@@ -12,7 +12,7 @@
1212#include <__concepts/boolean_testable.h>
1313#include <__concepts/invocable.h>
1414#include <__config>
15#include <__functional/invoke.h>
15#include <__type_traits/invoke.h>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818# pragma GCC system_header
lib/libcxx/include/__concepts/swappable.h+1-1
......@@ -14,6 +14,7 @@
1414#include <__concepts/common_reference_with.h>
1515#include <__concepts/constructible.h>
1616#include <__config>
17#include <__cstddef/size_t.h>
1718#include <__type_traits/extent.h>
1819#include <__type_traits/is_nothrow_assignable.h>
1920#include <__type_traits/is_nothrow_constructible.h>
......@@ -22,7 +23,6 @@
2223#include <__utility/forward.h>
2324#include <__utility/move.h>
2425#include <__utility/swap.h>
25#include <cstddef>
2626
2727#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2828# pragma GCC system_header
lib/libcxx/include/__condition_variable/condition_variable.h+9-9
......@@ -16,7 +16,7 @@
1616#include <__config>
1717#include <__mutex/mutex.h>
1818#include <__mutex/unique_lock.h>
19#include <__system_error/system_error.h>
19#include <__system_error/throw_system_error.h>
2020#include <__thread/support.h>
2121#include <__type_traits/enable_if.h>
2222#include <__type_traits/is_floating_point.h>
......@@ -33,7 +33,7 @@ _LIBCPP_PUSH_MACROS
3333
3434_LIBCPP_BEGIN_NAMESPACE_STD
3535
36#ifndef _LIBCPP_HAS_NO_THREADS
36#if _LIBCPP_HAS_THREADS
3737
3838// enum class cv_status
3939_LIBCPP_DECLARE_STRONG_ENUM(cv_status){no_timeout, timeout};
......@@ -45,7 +45,7 @@ class _LIBCPP_EXPORTED_FROM_ABI condition_variable {
4545public:
4646 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR condition_variable() _NOEXCEPT = default;
4747
48# ifdef _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
48# if _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
4949 ~condition_variable() = default;
5050# else
5151 ~condition_variable();
......@@ -83,7 +83,7 @@ public:
8383private:
8484 void
8585 __do_timed_wait(unique_lock<mutex>& __lk, chrono::time_point<chrono::system_clock, chrono::nanoseconds>) _NOEXCEPT;
86# if defined(_LIBCPP_HAS_COND_CLOCKWAIT)
86# if _LIBCPP_HAS_COND_CLOCKWAIT
8787 _LIBCPP_HIDE_FROM_ABI void
8888 __do_timed_wait(unique_lock<mutex>& __lk, chrono::time_point<chrono::steady_clock, chrono::nanoseconds>) _NOEXCEPT;
8989# endif
......@@ -91,7 +91,7 @@ private:
9191 _LIBCPP_HIDE_FROM_ABI void
9292 __do_timed_wait(unique_lock<mutex>& __lk, chrono::time_point<_Clock, chrono::nanoseconds>) _NOEXCEPT;
9393};
94#endif // !_LIBCPP_HAS_NO_THREADS
94#endif // _LIBCPP_HAS_THREADS
9595
9696template <class _Rep, class _Period, __enable_if_t<is_floating_point<_Rep>::value, int> = 0>
9797inline _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::
140140 return nanoseconds(__result);
141141}
142142
143#ifndef _LIBCPP_HAS_NO_THREADS
143#if _LIBCPP_HAS_THREADS
144144template <class _Predicate>
145145void condition_variable::wait(unique_lock<mutex>& __lk, _Predicate __pred) {
146146 while (!__pred())
......@@ -180,7 +180,7 @@ cv_status condition_variable::wait_for(unique_lock<mutex>& __lk, const chrono::d
180180 using __ns_rep = nanoseconds::rep;
181181 steady_clock::time_point __c_now = steady_clock::now();
182182
183# if defined(_LIBCPP_HAS_COND_CLOCKWAIT)
183# if _LIBCPP_HAS_COND_CLOCKWAIT
184184 using __clock_tp_ns = time_point<steady_clock, nanoseconds>;
185185 __ns_rep __now_count_ns = std::__safe_nanosecond_cast(__c_now.time_since_epoch()).count();
186186# else
......@@ -205,7 +205,7 @@ condition_variable::wait_for(unique_lock<mutex>& __lk, const chrono::duration<_R
205205 return wait_until(__lk, chrono::steady_clock::now() + __d, std::move(__pred));
206206}
207207
208# if defined(_LIBCPP_HAS_COND_CLOCKWAIT)
208# if _LIBCPP_HAS_COND_CLOCKWAIT
209209inline void condition_variable::__do_timed_wait(
210210 unique_lock<mutex>& __lk, chrono::time_point<chrono::steady_clock, chrono::nanoseconds> __tp) _NOEXCEPT {
211211 using namespace chrono;
......@@ -235,7 +235,7 @@ inline void condition_variable::__do_timed_wait(unique_lock<mutex>& __lk,
235235 wait_for(__lk, __tp - _Clock::now());
236236}
237237
238#endif // _LIBCPP_HAS_NO_THREADS
238#endif // _LIBCPP_HAS_THREADS
239239
240240_LIBCPP_END_NAMESPACE_STD
241241
lib/libcxx/include/__config+154-139
......@@ -14,6 +14,7 @@
1414#include <__configuration/abi.h>
1515#include <__configuration/availability.h>
1616#include <__configuration/compiler.h>
17#include <__configuration/language.h>
1718#include <__configuration/platform.h>
1819
1920#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
......@@ -27,10 +28,11 @@
2728// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM.
2829// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is
2930// defined to XXYYZZ.
30# define _LIBCPP_VERSION 190100
31# define _LIBCPP_VERSION 200100
3132
3233# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
3334# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
35# define _LIBCPP_CONCAT3(X, Y, Z) _LIBCPP_CONCAT(X, _LIBCPP_CONCAT(Y, Z))
3436
3537# if __STDC_HOSTED__ == 0
3638# define _LIBCPP_FREESTANDING
......@@ -38,16 +40,9 @@
3840
3941// HARDENING {
4042
41// This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes)
42// equivalent to setting the extensive mode. This is deprecated and will be removed in LLVM 20.
43// TODO: Remove in LLVM 21. We're making this an error to catch folks who might not have migrated.
4344# ifdef _LIBCPP_ENABLE_ASSERTIONS
44# warning "_LIBCPP_ENABLE_ASSERTIONS is deprecated, please use _LIBCPP_HARDENING_MODE instead"
45# if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1
46# error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1"
47# endif
48# if _LIBCPP_ENABLE_ASSERTIONS
49# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_EXTENSIVE
50# endif
45# error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE instead"
5146# endif
5247
5348// 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
191186# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
192187# endif
193188
194// FIXME: ABI detection should be done via compiler builtin macros. This
195// is just a placeholder until Clang implements such macros. For now assume
196// that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
197// and allow the user to explicitly specify the ABI to handle cases where this
198// heuristic falls short.
199# if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
200# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
201# elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
202# define _LIBCPP_ABI_ITANIUM
203# elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
204# define _LIBCPP_ABI_MICROSOFT
205# else
206# if defined(_WIN32) && defined(_MSC_VER)
207# define _LIBCPP_ABI_MICROSOFT
208# else
209# define _LIBCPP_ABI_ITANIUM
210# endif
211# endif
212
213189# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
214190# define _LIBCPP_ABI_VCRUNTIME
215191# endif
......@@ -222,13 +198,16 @@ _LIBCPP_HARDENING_MODE_DEBUG
222198
223199// Incomplete features get their own specific disabling flags. This makes it
224200// easier to grep for target specific flags once the feature is complete.
225# if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY)
226# define _LIBCPP_HAS_NO_INCOMPLETE_PSTL
227# define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN
228# define _LIBCPP_HAS_NO_EXPERIMENTAL_TZDB
229# define _LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM
201# if defined(_LIBCPP_ENABLE_EXPERIMENTAL) || defined(_LIBCPP_BUILDING_LIBRARY)
202# define _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 1
203# else
204# define _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 0
230205# endif
231206
207# define _LIBCPP_HAS_EXPERIMENTAL_PSTL _LIBCPP_HAS_EXPERIMENTAL_LIBRARY
208# define _LIBCPP_HAS_EXPERIMENTAL_TZDB _LIBCPP_HAS_EXPERIMENTAL_LIBRARY
209# define _LIBCPP_HAS_EXPERIMENTAL_SYNCSTREAM _LIBCPP_HAS_EXPERIMENTAL_LIBRARY
210
232211# if defined(__MVS__)
233212# include <features.h> // for __NATIVE_ASCII_F
234213# endif
......@@ -244,9 +223,14 @@ _LIBCPP_HARDENING_MODE_DEBUG
244223# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
245224# endif
246225# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
247# define _LIBCPP_HAS_BITSCAN64
226# define _LIBCPP_HAS_BITSCAN64 1
227# else
228# define _LIBCPP_HAS_BITSCAN64 0
248229# endif
249# define _LIBCPP_HAS_OPEN_WITH_WCHAR
230# define _LIBCPP_HAS_OPEN_WITH_WCHAR 1
231# else
232# define _LIBCPP_HAS_OPEN_WITH_WCHAR 0
233# define _LIBCPP_HAS_BITSCAN64 0
250234# endif // defined(_WIN32)
251235
252236# if defined(_AIX) && !defined(__64BIT__)
......@@ -312,7 +296,6 @@ _LIBCPP_HARDENING_MODE_DEBUG
312296# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
313297# define _ALIGNAS_TYPE(x) alignas(x)
314298# define _ALIGNAS(x) alignas(x)
315# define _LIBCPP_NORETURN [[noreturn]]
316299# define _NOEXCEPT noexcept
317300# define _NOEXCEPT_(...) noexcept(__VA_ARGS__)
318301# define _LIBCPP_CONSTEXPR constexpr
......@@ -322,8 +305,6 @@ _LIBCPP_HARDENING_MODE_DEBUG
322305# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
323306# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
324307# define _ALIGNAS(x) __attribute__((__aligned__(x)))
325# define _LIBCPP_NORETURN __attribute__((__noreturn__))
326# define _LIBCPP_HAS_NO_NOEXCEPT
327308# define nullptr __nullptr
328309# define _NOEXCEPT throw()
329310# define _NOEXCEPT_(...)
......@@ -340,23 +321,33 @@ typedef __char32_t char32_t;
340321
341322// Objective-C++ features (opt-in)
342323# if __has_feature(objc_arc)
343# define _LIBCPP_HAS_OBJC_ARC
324# define _LIBCPP_HAS_OBJC_ARC 1
325# else
326# define _LIBCPP_HAS_OBJC_ARC 0
344327# endif
345328
346329# if __has_feature(objc_arc_weak)
347# define _LIBCPP_HAS_OBJC_ARC_WEAK
330# define _LIBCPP_HAS_OBJC_ARC_WEAK 1
331# else
332# define _LIBCPP_HAS_OBJC_ARC_WEAK 0
348333# endif
349334
350335# if __has_extension(blocks)
351# define _LIBCPP_HAS_EXTENSION_BLOCKS
336# define _LIBCPP_HAS_EXTENSION_BLOCKS 1
337# else
338# define _LIBCPP_HAS_EXTENSION_BLOCKS 0
352339# endif
353340
354# if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
355# define _LIBCPP_HAS_BLOCKS_RUNTIME
341# if _LIBCPP_HAS_EXTENSION_BLOCKS && defined(__APPLE__)
342# define _LIBCPP_HAS_BLOCKS_RUNTIME 1
343# else
344# define _LIBCPP_HAS_BLOCKS_RUNTIME 0
356345# endif
357346
358# if !__has_feature(address_sanitizer)
359# define _LIBCPP_HAS_NO_ASAN
347# if __has_feature(address_sanitizer)
348# define _LIBCPP_HAS_ASAN 1
349# else
350# define _LIBCPP_HAS_ASAN 0
360351# endif
361352
362353# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
......@@ -479,7 +470,7 @@ typedef __char32_t char32_t;
479470# define _LIBCPP_HARDENING_SIG n // "none"
480471# endif
481472
482# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
473# if !_LIBCPP_HAS_EXCEPTIONS
483474# define _LIBCPP_EXCEPTIONS_SIG n
484475# else
485476# define _LIBCPP_EXCEPTIONS_SIG e
......@@ -593,6 +584,15 @@ typedef __char32_t char32_t;
593584 inline namespace _LIBCPP_ABI_NAMESPACE {
594585# define _LIBCPP_END_NAMESPACE_STD }} _LIBCPP_POP_EXTENSION_DIAGNOSTICS
595586
587#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace std { namespace experimental {
588#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL }}
589
590#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 {
591#define _LIBCPP_END_NAMESPACE_LFTS } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
592
593#define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 {
594#define _LIBCPP_END_NAMESPACE_LFTS_V2 } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
595
596596#ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE
597597# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem {
598598# define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD
......@@ -610,7 +610,9 @@ typedef __char32_t char32_t;
610610# endif
611611
612612# if !defined(__SIZEOF_INT128__) || defined(_MSC_VER)
613# define _LIBCPP_HAS_NO_INT128
613# define _LIBCPP_HAS_INT128 0
614# else
615# define _LIBCPP_HAS_INT128 1
614616# endif
615617
616618# ifdef _LIBCPP_CXX03_LANG
......@@ -631,10 +633,6 @@ typedef __char32_t char32_t;
631633# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
632634# endif // _LIBCPP_CXX03_LANG
633635
634# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__)
635# define _LIBCPP_LOCALE__L_EXTENSIONS 1
636# endif
637
638636# ifdef __FreeBSD__
639637# define _DECLARE_C99_LDBL_MATH 1
640638# endif
......@@ -642,29 +640,39 @@ typedef __char32_t char32_t;
642640// If we are getting operator new from the MSVC CRT, then allocation overloads
643641// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
644642# if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
645# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
643# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
646644# elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
647645// We're deferring to Microsoft's STL to provide aligned new et al. We don't
648646// have it unless the language feature test macro is defined.
649# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
647# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
650648# elif defined(__MVS__)
651# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
649# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
650# else
651# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 1
652652# endif
653653
654# if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
655# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
654# if !_LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
655# define _LIBCPP_HAS_ALIGNED_ALLOCATION 0
656# else
657# define _LIBCPP_HAS_ALIGNED_ALLOCATION 1
656658# endif
657659
658660// It is not yet possible to use aligned_alloc() on all Apple platforms since
659661// 10.15 was the first version to ship an implementation of aligned_alloc().
660662# if defined(__APPLE__)
661663# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
662 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500)
663# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
664 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \
665 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
666 __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000)
667# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0
668# else
669# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1
664670# endif
665671# elif defined(__ANDROID__) && __ANDROID_API__ < 28
666672// Android only provides aligned_alloc when targeting API 28 or higher.
667# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
673# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0
674# else
675# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1
668676# endif
669677
670678# if defined(__APPLE__) || defined(__FreeBSD__)
......@@ -676,7 +684,9 @@ typedef __char32_t char32_t;
676684# endif
677685
678686# if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
679# define _LIBCPP_HAS_NO_CHAR8_T
687# define _LIBCPP_HAS_CHAR8_T 0
688# else
689# define _LIBCPP_HAS_CHAR8_T 1
680690# endif
681691
682692// Deprecation macros.
......@@ -699,14 +709,6 @@ typedef __char32_t char32_t;
699709# define _LIBCPP_DEPRECATED_(m)
700710# endif
701711
702# if _LIBCPP_STD_VER < 20
703# define _LIBCPP_DEPRECATED_ATOMIC_SYNC \
704 _LIBCPP_DEPRECATED_("The C++20 synchronization library has been deprecated prior to C++20. Please update to " \
705 "using -std=c++20 if you need to use these facilities.")
706# else
707# define _LIBCPP_DEPRECATED_ATOMIC_SYNC /* nothing */
708# endif
709
710712# if !defined(_LIBCPP_CXX03_LANG)
711713# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
712714# else
......@@ -743,7 +745,7 @@ typedef __char32_t char32_t;
743745# define _LIBCPP_DEPRECATED_IN_CXX26
744746# endif
745747
746# if !defined(_LIBCPP_HAS_NO_CHAR8_T)
748# if _LIBCPP_HAS_CHAR8_T
747749# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
748750# else
749751# define _LIBCPP_DEPRECATED_WITH_CHAR8_T
......@@ -796,16 +798,22 @@ typedef __char32_t char32_t;
796798# define _LIBCPP_CONSTEXPR_SINCE_CXX23
797799# endif
798800
801# if _LIBCPP_STD_VER >= 26
802# define _LIBCPP_CONSTEXPR_SINCE_CXX26 constexpr
803# else
804# define _LIBCPP_CONSTEXPR_SINCE_CXX26
805# endif
806
799807# ifndef _LIBCPP_WEAK
800808# define _LIBCPP_WEAK __attribute__((__weak__))
801809# endif
802810
803811// Thread API
804812// clang-format off
805# if !defined(_LIBCPP_HAS_NO_THREADS) && \
806 !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
807 !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \
808 !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
813# if _LIBCPP_HAS_THREADS && \
814 !_LIBCPP_HAS_THREAD_API_PTHREAD && \
815 !_LIBCPP_HAS_THREAD_API_WIN32 && \
816 !_LIBCPP_HAS_THREAD_API_EXTERNAL
809817
810818# if defined(__FreeBSD__) || \
811819 defined(__wasi__) || \
......@@ -819,43 +827,49 @@ typedef __char32_t char32_t;
819827 defined(_AIX) || \
820828 defined(__EMSCRIPTEN__)
821829// clang-format on
822# define _LIBCPP_HAS_THREAD_API_PTHREAD
830# undef _LIBCPP_HAS_THREAD_API_PTHREAD
831# define _LIBCPP_HAS_THREAD_API_PTHREAD 1
823832# elif defined(__Fuchsia__)
824833// TODO(44575): Switch to C11 thread API when possible.
825# define _LIBCPP_HAS_THREAD_API_PTHREAD
834# undef _LIBCPP_HAS_THREAD_API_PTHREAD
835# define _LIBCPP_HAS_THREAD_API_PTHREAD 1
826836# elif defined(_LIBCPP_WIN32API)
827# define _LIBCPP_HAS_THREAD_API_WIN32
837# undef _LIBCPP_HAS_THREAD_API_WIN32
838# define _LIBCPP_HAS_THREAD_API_WIN32 1
828839# else
829840# error "No thread API"
830841# endif // _LIBCPP_HAS_THREAD_API
831# endif // _LIBCPP_HAS_NO_THREADS
842# endif // _LIBCPP_HAS_THREADS
832843
833# if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
844# if _LIBCPP_HAS_THREAD_API_PTHREAD
834845# if defined(__ANDROID__) && __ANDROID_API__ >= 30
835# define _LIBCPP_HAS_COND_CLOCKWAIT
846# define _LIBCPP_HAS_COND_CLOCKWAIT 1
836847# elif defined(_LIBCPP_GLIBC_PREREQ)
837848# if _LIBCPP_GLIBC_PREREQ(2, 30)
838# define _LIBCPP_HAS_COND_CLOCKWAIT
849# define _LIBCPP_HAS_COND_CLOCKWAIT 1
850# else
851# define _LIBCPP_HAS_COND_CLOCKWAIT 0
839852# endif
853# else
854# define _LIBCPP_HAS_COND_CLOCKWAIT 0
840855# endif
856# else
857# define _LIBCPP_HAS_COND_CLOCKWAIT 0
841858# endif
842859
843# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
844# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
845 _LIBCPP_HAS_NO_THREADS is not defined.
860# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_PTHREAD
861# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be true when _LIBCPP_HAS_THREADS is true.
846862# endif
847863
848# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
849# error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
850 _LIBCPP_HAS_NO_THREADS is defined.
864# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_EXTERNAL
865# error _LIBCPP_HAS_THREAD_API_EXTERNAL may only be true when _LIBCPP_HAS_THREADS is true.
851866# endif
852867
853# if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
854# error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
855 _LIBCPP_HAS_NO_THREADS is defined.
868# if !_LIBCPP_HAS_MONOTONIC_CLOCK && _LIBCPP_HAS_THREADS
869# error _LIBCPP_HAS_MONOTONIC_CLOCK may only be false when _LIBCPP_HAS_THREADS is false.
856870# endif
857871
858# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
872# if _LIBCPP_HAS_THREADS && !defined(__STDCPP_THREADS__)
859873# define __STDCPP_THREADS__ 1
860874# endif
861875
......@@ -870,11 +884,13 @@ typedef __char32_t char32_t;
870884// TODO(EricWF): Enable this optimization on Bionic after speaking to their
871885// respective stakeholders.
872886// clang-format off
873# if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \
874 (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \
875 defined(_LIBCPP_HAS_THREAD_API_WIN32)
887# if (_LIBCPP_HAS_THREAD_API_PTHREAD && defined(__GLIBC__)) || \
888 (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || \
889 _LIBCPP_HAS_THREAD_API_WIN32
876890// clang-format on
877# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
891# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 1
892# else
893# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 0
878894# endif
879895
880896// Destroying a condvar is a nop on Windows.
......@@ -885,25 +901,31 @@ typedef __char32_t char32_t;
885901//
886902// TODO(EricWF): This is potentially true for some pthread implementations
887903// as well.
888# if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32)
889# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
904# if (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || _LIBCPP_HAS_THREAD_API_WIN32
905# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 1
906# else
907# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 0
890908# endif
891909
892910# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \
893 defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
911 _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || defined(__LLVM_LIBC__)
894912# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
895913# endif
896914
897915# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
898# define _LIBCPP_HAS_C_ATOMIC_IMP
916# define _LIBCPP_HAS_C_ATOMIC_IMP 1
917# define _LIBCPP_HAS_GCC_ATOMIC_IMP 0
918# define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0
899919# elif defined(_LIBCPP_COMPILER_GCC)
900# define _LIBCPP_HAS_GCC_ATOMIC_IMP
920# define _LIBCPP_HAS_C_ATOMIC_IMP 0
921# define _LIBCPP_HAS_GCC_ATOMIC_IMP 1
922# define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0
901923# endif
902924
903# if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \
904 !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
905# define _LIBCPP_HAS_NO_ATOMIC_HEADER
925# if !_LIBCPP_HAS_C_ATOMIC_IMP && !_LIBCPP_HAS_GCC_ATOMIC_IMP && !_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP
926# define _LIBCPP_HAS_ATOMIC_HEADER 0
906927# else
928# define _LIBCPP_HAS_ATOMIC_HEADER 1
907929# ifndef _LIBCPP_ATOMIC_FLAG_TYPE
908930# define _LIBCPP_ATOMIC_FLAG_TYPE bool
909931# endif
......@@ -915,19 +937,18 @@ typedef __char32_t char32_t;
915937# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
916938# endif
917939
918# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
919# if defined(__clang__) && __has_attribute(acquire_capability)
920940// Work around the attribute handling in clang. When both __declspec and
921941// __attribute__ are present, the processing goes awry preventing the definition
922942// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
923943// combining the two does work.
924# if !defined(_MSC_VER)
925# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
926# endif
927# endif
944# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) && defined(__clang__) && \
945 __has_attribute(acquire_capability) && !defined(_MSC_VER)
946# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1
947# else
948# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 0
928949# endif
929950
930# ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
951# if _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
931952# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
932953# else
933954# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
......@@ -962,7 +983,7 @@ typedef __char32_t char32_t;
962983// When wide characters are disabled, it can be useful to have a quick way of
963984// disabling it without having to resort to #if-#endif, which has a larger
964985// impact on readability.
965# if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
986# if !_LIBCPP_HAS_WIDE_CHARACTERS
966987# define _LIBCPP_IF_WIDE_CHARACTERS(...)
967988# else
968989# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
......@@ -999,28 +1020,16 @@ typedef __char32_t char32_t;
9991020// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
10001021// However, MSVC implements [[msvc::no_unique_address]] which does what
10011022// [[no_unique_address]] is supposed to do, in general.
1002
1003// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or
1004// [[msvc::no_unique_address]] though. If/when it does implement
1005// [[msvc::no_unique_address]], this should be preferred though.
10061023# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
1007# elif __has_cpp_attribute(no_unique_address)
1008# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]]
10091024# else
1010# define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */
1011// Note that this can be replaced by #error as soon as clang-cl
1012// implements msvc::no_unique_address, since there should be no C++20
1013// compiler that doesn't support one of the two attributes at that point.
1014// We generally don't want to use this macro outside of C++20-only code,
1015// because using it conditionally in one language version only would make
1016// the ABI inconsistent.
1025# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]]
10171026# endif
10181027
10191028// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
10201029// functions is gradually being added to existing C libraries. The conditions
10211030// below check for known C library versions and conditions under which these
10221031// functions are declared by the C library.
1023# define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1032//
10241033// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if
10251034// __cpp_char8_t is defined or if C2X extensions are enabled. Determining
10261035// the latter depends on internal GNU libc details that are not appropriate
......@@ -1028,8 +1037,12 @@ typedef __char32_t char32_t;
10281037// defined are ignored.
10291038# if defined(_LIBCPP_GLIBC_PREREQ)
10301039# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
1031# undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1040# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
1041# else
1042# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
10321043# endif
1044# else
1045# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
10331046# endif
10341047
10351048// There are a handful of public standard library types that are intended to
......@@ -1124,15 +1137,6 @@ typedef __char32_t char32_t;
11241137# define _LIBCPP_USING_IF_EXISTS
11251138# endif
11261139
1127# if __has_cpp_attribute(__nodiscard__)
1128# define _LIBCPP_NODISCARD [[__nodiscard__]]
1129# else
1130// We can't use GCC's [[gnu::warn_unused_result]] and
1131// __attribute__((warn_unused_result)), because GCC does not silence them via
1132// (void) cast.
1133# define _LIBCPP_NODISCARD
1134# endif
1135
11361140# if __has_attribute(__no_destroy__)
11371141# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
11381142# else
......@@ -1160,10 +1164,19 @@ typedef __char32_t char32_t;
11601164# define _LIBCPP_LIFETIMEBOUND
11611165# endif
11621166
1163# if __has_attribute(__nodebug__)
1164# define _LIBCPP_NODEBUG __attribute__((__nodebug__))
1167# if __has_cpp_attribute(_Clang::__noescape__)
1168# define _LIBCPP_NOESCAPE [[_Clang::__noescape__]]
1169# else
1170# define _LIBCPP_NOESCAPE
1171# endif
1172
1173# define _LIBCPP_NODEBUG [[__gnu__::__nodebug__]]
1174
1175# if __has_cpp_attribute(_Clang::__no_specializations__)
1176# define _LIBCPP_NO_SPECIALIZATIONS \
1177 [[_Clang::__no_specializations__("Users are not allowed to specialize this standard library entity")]]
11651178# else
1166# define _LIBCPP_NODEBUG
1179# define _LIBCPP_NO_SPECIALIZATIONS
11671180# endif
11681181
11691182# if __has_attribute(__standalone_debug__)
......@@ -1220,7 +1233,9 @@ typedef __char32_t char32_t;
12201233
12211234// Clang-18 has support for deducing this, but it does not set the FTM.
12221235# if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800)
1223# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
1236# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 1
1237# else
1238# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 0
12241239# endif
12251240
12261241#endif // __cplusplus
lib/libcxx/include/__configuration/abi.h+46-4
......@@ -18,6 +18,25 @@
1818# pragma GCC system_header
1919#endif
2020
21// FIXME: ABI detection should be done via compiler builtin macros. This
22// is just a placeholder until Clang implements such macros. For now assume
23// that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
24// and allow the user to explicitly specify the ABI to handle cases where this
25// heuristic falls short.
26#if _LIBCPP_ABI_FORCE_ITANIUM && _LIBCPP_ABI_FORCE_MICROSOFT
27# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be true"
28#elif _LIBCPP_ABI_FORCE_ITANIUM
29# define _LIBCPP_ABI_ITANIUM
30#elif _LIBCPP_ABI_FORCE_MICROSOFT
31# define _LIBCPP_ABI_MICROSOFT
32#else
33# if defined(_WIN32) && defined(_MSC_VER)
34# define _LIBCPP_ABI_MICROSOFT
35# else
36# define _LIBCPP_ABI_ITANIUM
37# endif
38#endif
39
2140#if _LIBCPP_ABI_VERSION >= 2
2241// Change short string representation so that string data starts at offset 0,
2342// improving its alignment in some cases.
......@@ -98,10 +117,13 @@
98117// and WCHAR_MAX. This ABI setting determines whether we should instead track whether the fill
99118// value has been initialized using a separate boolean, which changes the ABI.
100119# define _LIBCPP_ABI_IOS_ALLOW_ARBITRARY_FILL_VALUE
101// Make a std::pair of trivially copyable types trivially copyable.
102// While this technically doesn't change the layout of pair itself, other types may decide to programatically change
103// their representation based on whether something is trivially copyable.
104# define _LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR
120// Historically, libc++ used a type called `__compressed_pair` to reduce storage needs in cases of empty types (e.g. an
121// empty allocator in std::vector). We switched to using `[[no_unique_address]]`. However, for ABI compatibility reasons
122// we had to add artificial padding in a few places.
123//
124// This setting disables the addition of such artificial padding, leading to a more optimal
125// representation for several types.
126# define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING
105127#elif _LIBCPP_ABI_VERSION == 1
106128# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
107129// Enable compiling copies of now inline methods into the dylib to support
......@@ -154,6 +176,26 @@
154176// ABI impact: changes the iterator type of `vector` (except `vector<bool>`).
155177// #define _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
156178
179// Changes the iterator type of `array` to a bounded iterator that keeps track of whether it's within the bounds of the
180// container and asserts it on every dereference and when performing iterator arithmetic.
181//
182// ABI impact: changes the iterator type of `array`, its size and its layout.
183// #define _LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY
184
185// [[msvc::no_unique_address]] seems to mostly affect empty classes, so the padding scheme for Itanium doesn't work.
186#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING)
187# define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING
188#endif
189
190// Tracks the bounds of the array owned by std::unique_ptr<T[]>, allowing it to trap when accessed out-of-bounds.
191// Note that limited bounds checking is also available outside of this ABI configuration, but only some categories
192// of types can be checked.
193//
194// ABI impact: This causes the layout of std::unique_ptr<T[]> to change and its size to increase.
195// This also affects the representation of a few library types that use std::unique_ptr
196// internally, such as the unordered containers.
197// #define _LIBCPP_ABI_BOUNDED_UNIQUE_PTR
198
157199#if defined(_LIBCPP_COMPILER_CLANG_BASED)
158200# if defined(__APPLE__)
159201# if defined(__i386__) || defined(__x86_64__)
lib/libcxx/include/__configuration/availability.h+53-69
......@@ -67,25 +67,19 @@
6767//
6868// [1]: https://clang.llvm.org/docs/AttributeReference.html#availability
6969
70// For backwards compatibility, allow users to define _LIBCPP_DISABLE_AVAILABILITY
71// for a while.
72#if defined(_LIBCPP_DISABLE_AVAILABILITY)
73# if !defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
74# define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS
75# endif
76#endif
77
7870// Availability markup is disabled when building the library, or when a non-Clang
7971// compiler is used because only Clang supports the necessary attributes.
8072#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCXXABI_BUILDING_LIBRARY) || !defined(_LIBCPP_COMPILER_CLANG_BASED)
81# if !defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
82# define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS
83# endif
73# undef _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS
74# define _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS 0
8475#endif
8576
8677// When availability annotations are disabled, we take for granted that features introduced
8778// in all versions of the library are available.
88#if defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
79#if !_LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS
80
81# define _LIBCPP_INTRODUCED_IN_LLVM_20 1
82# define _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE /* nothing */
8983
9084# define _LIBCPP_INTRODUCED_IN_LLVM_19 1
9185# define _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE /* nothing */
......@@ -93,9 +87,6 @@
9387# define _LIBCPP_INTRODUCED_IN_LLVM_18 1
9488# define _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE /* nothing */
9589
96# define _LIBCPP_INTRODUCED_IN_LLVM_17 1
97# define _LIBCPP_INTRODUCED_IN_LLVM_17_ATTRIBUTE /* nothing */
98
9990# define _LIBCPP_INTRODUCED_IN_LLVM_16 1
10091# define _LIBCPP_INTRODUCED_IN_LLVM_16_ATTRIBUTE /* nothing */
10192
......@@ -105,26 +96,17 @@
10596# define _LIBCPP_INTRODUCED_IN_LLVM_14 1
10697# define _LIBCPP_INTRODUCED_IN_LLVM_14_ATTRIBUTE /* nothing */
10798
108# define _LIBCPP_INTRODUCED_IN_LLVM_13 1
109# define _LIBCPP_INTRODUCED_IN_LLVM_13_ATTRIBUTE /* nothing */
110
11199# define _LIBCPP_INTRODUCED_IN_LLVM_12 1
112100# define _LIBCPP_INTRODUCED_IN_LLVM_12_ATTRIBUTE /* nothing */
113101
114102# define _LIBCPP_INTRODUCED_IN_LLVM_11 1
115103# define _LIBCPP_INTRODUCED_IN_LLVM_11_ATTRIBUTE /* nothing */
116104
117# define _LIBCPP_INTRODUCED_IN_LLVM_10 1
118# define _LIBCPP_INTRODUCED_IN_LLVM_10_ATTRIBUTE /* nothing */
119
120105# define _LIBCPP_INTRODUCED_IN_LLVM_9 1
121106# define _LIBCPP_INTRODUCED_IN_LLVM_9_ATTRIBUTE /* nothing */
122107# define _LIBCPP_INTRODUCED_IN_LLVM_9_ATTRIBUTE_PUSH /* nothing */
123108# define _LIBCPP_INTRODUCED_IN_LLVM_9_ATTRIBUTE_POP /* nothing */
124109
125# define _LIBCPP_INTRODUCED_IN_LLVM_8 1
126# define _LIBCPP_INTRODUCED_IN_LLVM_8_ATTRIBUTE /* nothing */
127
128110# define _LIBCPP_INTRODUCED_IN_LLVM_4 1
129111# define _LIBCPP_INTRODUCED_IN_LLVM_4_ATTRIBUTE /* nothing */
130112
......@@ -132,36 +114,42 @@
132114
133115// clang-format off
134116
117// LLVM 20
118// TODO: Fill this in
119# define _LIBCPP_INTRODUCED_IN_LLVM_20 0
120# define _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE __attribute__((unavailable))
121
135122// LLVM 19
136123// TODO: Fill this in
137124# define _LIBCPP_INTRODUCED_IN_LLVM_19 0
138125# define _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE __attribute__((unavailable))
139126
140127// LLVM 18
141// TODO: Fill this in
142# define _LIBCPP_INTRODUCED_IN_LLVM_18 0
143# define _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE __attribute__((unavailable))
144
145// LLVM 17
146# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 140400) || \
147 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 170400) || \
148 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 170400) || \
149 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 100400)
150# define _LIBCPP_INTRODUCED_IN_LLVM_17 0
128# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 150000) || \
129 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 180000) || \
130 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 180000) || \
131 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 110000) || \
132 (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 90000) || \
133 (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 240000)
134# define _LIBCPP_INTRODUCED_IN_LLVM_18 0
151135# else
152# define _LIBCPP_INTRODUCED_IN_LLVM_17 1
136# define _LIBCPP_INTRODUCED_IN_LLVM_18 1
153137# endif
154# define _LIBCPP_INTRODUCED_IN_LLVM_17_ATTRIBUTE \
155 __attribute__((availability(macos, strict, introduced = 14.4))) \
156 __attribute__((availability(ios, strict, introduced = 17.4))) \
157 __attribute__((availability(tvos, strict, introduced = 17.4))) \
158 __attribute__((availability(watchos, strict, introduced = 10.4)))
138# define _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE \
139 __attribute__((availability(macos, strict, introduced = 15.0))) \
140 __attribute__((availability(ios, strict, introduced = 18.0))) \
141 __attribute__((availability(tvos, strict, introduced = 18.0))) \
142 __attribute__((availability(watchos, strict, introduced = 11.0))) \
143 __attribute__((availability(bridgeos, strict, introduced = 9.0))) \
144 __attribute__((availability(driverkit, strict, introduced = 24.0)))
159145
160146// LLVM 16
161147# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 140000) || \
162148 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 170000) || \
163149 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 170000) || \
164 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 100000)
150 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 100000) || \
151 (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 80000) || \
152 (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 230000)
165153# define _LIBCPP_INTRODUCED_IN_LLVM_16 0
166154# else
167155# define _LIBCPP_INTRODUCED_IN_LLVM_16 1
......@@ -170,13 +158,17 @@
170158 __attribute__((availability(macos, strict, introduced = 14.0))) \
171159 __attribute__((availability(ios, strict, introduced = 17.0))) \
172160 __attribute__((availability(tvos, strict, introduced = 17.0))) \
173 __attribute__((availability(watchos, strict, introduced = 10.0)))
161 __attribute__((availability(watchos, strict, introduced = 10.0))) \
162 __attribute__((availability(bridgeos, strict, introduced = 8.0))) \
163 __attribute__((availability(driverkit, strict, introduced = 23.0)))
174164
175165// LLVM 15
176166# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 130400) || \
177167 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 160500) || \
178168 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 160500) || \
179 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 90500)
169 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 90500) || \
170 (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 70500) || \
171 (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 220400)
180172# define _LIBCPP_INTRODUCED_IN_LLVM_15 0
181173# else
182174# define _LIBCPP_INTRODUCED_IN_LLVM_15 1
......@@ -185,32 +177,21 @@
185177 __attribute__((availability(macos, strict, introduced = 13.4))) \
186178 __attribute__((availability(ios, strict, introduced = 16.5))) \
187179 __attribute__((availability(tvos, strict, introduced = 16.5))) \
188 __attribute__((availability(watchos, strict, introduced = 9.5)))
180 __attribute__((availability(watchos, strict, introduced = 9.5))) \
181 __attribute__((availability(bridgeos, strict, introduced = 7.5))) \
182 __attribute__((availability(driverkit, strict, introduced = 22.4)))
189183
190184// LLVM 14
191185# define _LIBCPP_INTRODUCED_IN_LLVM_14 _LIBCPP_INTRODUCED_IN_LLVM_15
192186# define _LIBCPP_INTRODUCED_IN_LLVM_14_ATTRIBUTE _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE
193187
194// LLVM 13
195# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 130000) || \
196 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 160000) || \
197 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 160000) || \
198 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 90000)
199# define _LIBCPP_INTRODUCED_IN_LLVM_13 0
200# else
201# define _LIBCPP_INTRODUCED_IN_LLVM_13 1
202# endif
203# define _LIBCPP_INTRODUCED_IN_LLVM_13_ATTRIBUTE \
204 __attribute__((availability(macos, strict, introduced = 13.0))) \
205 __attribute__((availability(ios, strict, introduced = 16.0))) \
206 __attribute__((availability(tvos, strict, introduced = 16.0))) \
207 __attribute__((availability(watchos, strict, introduced = 9.0)))
208
209188// LLVM 12
210189# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 120300) || \
211190 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 150300) || \
212191 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 150300) || \
213 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 80300)
192 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 80300) || \
193 (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 60000) || \
194 (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 210300)
214195# define _LIBCPP_INTRODUCED_IN_LLVM_12 0
215196# else
216197# define _LIBCPP_INTRODUCED_IN_LLVM_12 1
......@@ -219,7 +200,9 @@
219200 __attribute__((availability(macos, strict, introduced = 12.3))) \
220201 __attribute__((availability(ios, strict, introduced = 15.3))) \
221202 __attribute__((availability(tvos, strict, introduced = 15.3))) \
222 __attribute__((availability(watchos, strict, introduced = 8.3)))
203 __attribute__((availability(watchos, strict, introduced = 8.3))) \
204 __attribute__((availability(bridgeos, strict, introduced = 6.0))) \
205 __attribute__((availability(driverkit, strict, introduced = 21.3)))
223206
224207// LLVM 11
225208# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 110000) || \
......@@ -236,10 +219,6 @@
236219 __attribute__((availability(tvos, strict, introduced = 14.0))) \
237220 __attribute__((availability(watchos, strict, introduced = 7.0)))
238221
239// LLVM 10
240# define _LIBCPP_INTRODUCED_IN_LLVM_10 _LIBCPP_INTRODUCED_IN_LLVM_11
241# define _LIBCPP_INTRODUCED_IN_LLVM_10_ATTRIBUTE _LIBCPP_INTRODUCED_IN_LLVM_11_ATTRIBUTE
242
243222// LLVM 9
244223# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \
245224 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) || \
......@@ -375,10 +354,15 @@
375354#define _LIBCPP_AVAILABILITY_HAS_BAD_EXPECTED_ACCESS_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19
376355#define _LIBCPP_AVAILABILITY_BAD_EXPECTED_ACCESS_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE
377356
378// Define availability attributes that depend on _LIBCPP_HAS_NO_EXCEPTIONS.
357// This controls the availability of floating-point std::from_chars functions.
358// These overloads were added later than the integer overloads.
359#define _LIBCPP_AVAILABILITY_HAS_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20
360#define _LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE
361
362// Define availability attributes that depend on _LIBCPP_HAS_EXCEPTIONS.
379363// Those are defined in terms of the availability attributes above, and
380364// should not be vendor-specific.
381#if defined(_LIBCPP_HAS_NO_EXCEPTIONS)
365#if !_LIBCPP_HAS_EXCEPTIONS
382366# define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
383367# define _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS
384368# define _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
......@@ -389,8 +373,8 @@
389373#endif
390374
391375// Define availability attributes that depend on both
392// _LIBCPP_HAS_NO_EXCEPTIONS and _LIBCPP_HAS_NO_RTTI.
393#if defined(_LIBCPP_HAS_NO_EXCEPTIONS) || defined(_LIBCPP_HAS_NO_RTTI)
376// _LIBCPP_HAS_EXCEPTIONS and _LIBCPP_HAS_RTTI.
377#if !_LIBCPP_HAS_EXCEPTIONS || !_LIBCPP_HAS_RTTI
394378# undef _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION
395379# undef _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION
396380# define _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION 0
lib/libcxx/include/__configuration/compiler.h+2-2
......@@ -33,8 +33,8 @@
3333// Warn if a compiler version is used that is not supported anymore
3434// LLVM RELEASE Update the minimum compiler versions
3535# if defined(_LIBCPP_CLANG_VER)
36# if _LIBCPP_CLANG_VER < 1700
37# warning "Libc++ only supports Clang 17 and later"
36# if _LIBCPP_CLANG_VER < 1800
37# warning "Libc++ only supports Clang 18 and later"
3838# endif
3939# elif defined(_LIBCPP_APPLE_CLANG_VER)
4040# if _LIBCPP_APPLE_CLANG_VER < 1500
lib/libcxx/include/__configuration/language.h+8-4
......@@ -35,12 +35,16 @@
3535#endif // __cplusplus
3636// NOLINTEND(libcpp-cpp-version-check)
3737
38#if !defined(__cpp_rtti) || __cpp_rtti < 199711L
39# define _LIBCPP_HAS_NO_RTTI
38#if defined(__cpp_rtti) && __cpp_rtti >= 199711L
39# define _LIBCPP_HAS_RTTI 1
40#else
41# define _LIBCPP_HAS_RTTI 0
4042#endif
4143
42#if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L
43# define _LIBCPP_HAS_NO_EXCEPTIONS
44#if defined(__cpp_exceptions) && __cpp_exceptions >= 199711L
45# define _LIBCPP_HAS_EXCEPTIONS 1
46#else
47# define _LIBCPP_HAS_EXCEPTIONS 0
4448#endif
4549
4650#endif // _LIBCPP___CONFIGURATION_LANGUAGE_H
lib/libcxx/include/__configuration/platform.h+10-8
......@@ -31,14 +31,16 @@
3131#endif
3232
3333// Need to detect which libc we're using if we're on Linux.
34#if defined(__linux__)
35# include <features.h>
36# if defined(__GLIBC_PREREQ)
37# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
38# else
39# define _LIBCPP_GLIBC_PREREQ(a, b) 0
40# endif // defined(__GLIBC_PREREQ)
41#endif // defined(__linux__)
34#if defined(__linux__) || defined(__AMDGPU__) || defined(__NVPTX__)
35# if __has_include(<features.h>)
36# include <features.h>
37# if defined(__GLIBC_PREREQ)
38# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
39# else
40# define _LIBCPP_GLIBC_PREREQ(a, b) 0
41# endif // defined(__GLIBC_PREREQ)
42# endif
43#endif
4244
4345#ifndef __BYTE_ORDER__
4446# error \
lib/libcxx/include/__coroutine/coroutine_handle.h+2-1
......@@ -11,11 +11,12 @@
1111
1212#include <__assert>
1313#include <__config>
14#include <__cstddef/nullptr_t.h>
15#include <__cstddef/size_t.h>
1416#include <__functional/hash.h>
1517#include <__memory/addressof.h>
1618#include <__type_traits/remove_cv.h>
1719#include <compare>
18#include <cstddef>
1920
2021#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2122# pragma GCC system_header
lib/libcxx/include/__cstddef/byte.h created+85
......@@ -0,0 +1,85 @@
1//===---------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===---------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___CSTDDEF_BYTE_H
10#define _LIBCPP___CSTDDEF_BYTE_H
11
12#include <__config>
13#include <__fwd/byte.h>
14#include <__type_traits/enable_if.h>
15#include <__type_traits/is_integral.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21#if _LIBCPP_STD_VER >= 17
22namespace std { // purposefully not versioned
23
24enum class byte : unsigned char {};
25
26_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator|(byte __lhs, byte __rhs) noexcept {
27 return static_cast<byte>(
28 static_cast<unsigned char>(static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs)));
29}
30
31_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept {
32 return __lhs = __lhs | __rhs;
33}
34
35_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator&(byte __lhs, byte __rhs) noexcept {
36 return static_cast<byte>(
37 static_cast<unsigned char>(static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs)));
38}
39
40_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept {
41 return __lhs = __lhs & __rhs;
42}
43
44_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator^(byte __lhs, byte __rhs) noexcept {
45 return static_cast<byte>(
46 static_cast<unsigned char>(static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs)));
47}
48
49_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept {
50 return __lhs = __lhs ^ __rhs;
51}
52
53_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator~(byte __b) noexcept {
54 return static_cast<byte>(static_cast<unsigned char>(~static_cast<unsigned int>(__b)));
55}
56
57template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
58_LIBCPP_HIDE_FROM_ABI constexpr byte& operator<<=(byte& __lhs, _Integer __shift) noexcept {
59 return __lhs = __lhs << __shift;
60}
61
62template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
63_LIBCPP_HIDE_FROM_ABI constexpr byte operator<<(byte __lhs, _Integer __shift) noexcept {
64 return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift));
65}
66
67template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
68_LIBCPP_HIDE_FROM_ABI constexpr byte& operator>>=(byte& __lhs, _Integer __shift) noexcept {
69 return __lhs = __lhs >> __shift;
70}
71
72template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
73_LIBCPP_HIDE_FROM_ABI constexpr byte operator>>(byte __lhs, _Integer __shift) noexcept {
74 return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift));
75}
76
77template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
78[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Integer to_integer(byte __b) noexcept {
79 return static_cast<_Integer>(__b);
80}
81
82} // namespace std
83#endif // _LIBCPP_STD_VER >= 17
84
85#endif // _LIBCPP___CSTDDEF_BYTE_H
lib/libcxx/include/__cstddef/max_align_t.h created+27
......@@ -0,0 +1,27 @@
1//===---------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===---------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___CSTDDEF_MAX_ALIGN_T_H
10#define _LIBCPP___CSTDDEF_MAX_ALIGN_T_H
11
12#include <__config>
13#include <stddef.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21#if !defined(_LIBCPP_CXX03_LANG)
22using ::max_align_t _LIBCPP_USING_IF_EXISTS;
23#endif
24
25_LIBCPP_END_NAMESPACE_STD
26
27#endif // _LIBCPP___CSTDDEF_MAX_ALIGN_T_H
lib/libcxx/include/__cstddef/nullptr_t.h created+24
......@@ -0,0 +1,24 @@
1//===---------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===---------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___CSTDDEF_NULLPTR_T_H
10#define _LIBCPP___CSTDDEF_NULLPTR_T_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20using nullptr_t = decltype(nullptr);
21
22_LIBCPP_END_NAMESPACE_STD
23
24#endif // _LIBCPP___CSTDDEF_NULLPTR_T_H
lib/libcxx/include/__cstddef/ptrdiff_t.h created+24
......@@ -0,0 +1,24 @@
1//===---------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===---------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___CSTDDEF_PTRDIFF_T_H
10#define _LIBCPP___CSTDDEF_PTRDIFF_T_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20using ptrdiff_t = decltype(static_cast<int*>(nullptr) - static_cast<int*>(nullptr));
21
22_LIBCPP_END_NAMESPACE_STD
23
24#endif // _LIBCPP___CSTDDEF_PTRDIFF_T_H
lib/libcxx/include/__cstddef/size_t.h created+24
......@@ -0,0 +1,24 @@
1//===---------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===---------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___CSTDDEF_SIZE_T_H
10#define _LIBCPP___CSTDDEF_SIZE_T_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20using size_t = decltype(sizeof(int));
21
22_LIBCPP_END_NAMESPACE_STD
23
24#endif // _LIBCPP___CSTDDEF_SIZE_T_H
lib/libcxx/include/__debug_utils/sanitizers.h+5-5
......@@ -17,7 +17,7 @@
1717# pragma GCC system_header
1818#endif
1919
20#ifndef _LIBCPP_HAS_NO_ASAN
20#if _LIBCPP_HAS_ASAN
2121
2222extern "C" {
2323_LIBCPP_EXPORTED_FROM_ABI void
......@@ -28,12 +28,12 @@ _LIBCPP_EXPORTED_FROM_ABI int
2828__sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*);
2929}
3030
31#endif // _LIBCPP_HAS_NO_ASAN
31#endif // _LIBCPP_HAS_ASAN
3232
3333_LIBCPP_BEGIN_NAMESPACE_STD
3434
3535// ASan choices
36#ifndef _LIBCPP_HAS_NO_ASAN
36#if _LIBCPP_HAS_ASAN
3737# define _LIBCPP_HAS_ASAN_CONTAINER_ANNOTATIONS_FOR_ALL_ALLOCATORS 1
3838#endif
3939
......@@ -57,7 +57,7 @@ _LIBCPP_HIDE_FROM_ABI void __annotate_double_ended_contiguous_container(
5757 const void* __last_old_contained,
5858 const void* __first_new_contained,
5959 const void* __last_new_contained) {
60#ifdef _LIBCPP_HAS_NO_ASAN
60#if !_LIBCPP_HAS_ASAN
6161 (void)__first_storage;
6262 (void)__last_storage;
6363 (void)__first_old_contained;
......@@ -86,7 +86,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __annotate_contiguous_c
8686 const void* __last_storage,
8787 const void* __old_last_contained,
8888 const void* __new_last_contained) {
89#ifdef _LIBCPP_HAS_NO_ASAN
89#if !_LIBCPP_HAS_ASAN
9090 (void)__first_storage;
9191 (void)__last_storage;
9292 (void)__old_last_contained;
lib/libcxx/include/__exception/exception_ptr.h+4-5
......@@ -10,13 +10,12 @@
1010#define _LIBCPP___EXCEPTION_EXCEPTION_PTR_H
1111
1212#include <__config>
13#include <__cstddef/nullptr_t.h>
1314#include <__exception/operations.h>
1415#include <__memory/addressof.h>
1516#include <__memory/construct_at.h>
1617#include <__type_traits/decay.h>
17#include <cstddef>
1818#include <cstdlib>
19#include <new>
2019#include <typeinfo>
2120
2221#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -67,7 +66,7 @@ class _LIBCPP_EXPORTED_FROM_ABI exception_ptr {
6766
6867public:
6968 // exception_ptr is basically a COW string.
70 using __trivially_relocatable = exception_ptr;
69 using __trivially_relocatable _LIBCPP_NODEBUG = exception_ptr;
7170
7271 _LIBCPP_HIDE_FROM_ABI exception_ptr() _NOEXCEPT : __ptr_() {}
7372 _LIBCPP_HIDE_FROM_ABI exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {}
......@@ -92,7 +91,7 @@ public:
9291
9392template <class _Ep>
9493_LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
95# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
94# if _LIBCPP_HAS_EXCEPTIONS
9695# if _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION && __cplusplus >= 201103L
9796 using _Ep2 = __decay_t<_Ep>;
9897
......@@ -159,7 +158,7 @@ _LIBCPP_EXPORTED_FROM_ABI void swap(exception_ptr&, exception_ptr&) _NOEXCEPT;
159158
160159_LIBCPP_EXPORTED_FROM_ABI exception_ptr __copy_exception_ptr(void* __except, const void* __ptr);
161160_LIBCPP_EXPORTED_FROM_ABI exception_ptr current_exception() _NOEXCEPT;
162_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr);
161[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr);
163162
164163// This is a built-in template function which automagically extracts the required
165164// information.
lib/libcxx/include/__exception/nested_exception.h+8-7
......@@ -13,6 +13,8 @@
1313#include <__exception/exception_ptr.h>
1414#include <__memory/addressof.h>
1515#include <__type_traits/decay.h>
16#include <__type_traits/enable_if.h>
17#include <__type_traits/integral_constant.h>
1618#include <__type_traits/is_base_of.h>
1719#include <__type_traits/is_class.h>
1820#include <__type_traits/is_constructible.h>
......@@ -20,7 +22,6 @@
2022#include <__type_traits/is_final.h>
2123#include <__type_traits/is_polymorphic.h>
2224#include <__utility/forward.h>
23#include <cstddef>
2425
2526#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2627# pragma GCC system_header
......@@ -38,7 +39,7 @@ public:
3839 virtual ~nested_exception() _NOEXCEPT;
3940
4041 // access functions
41 _LIBCPP_NORETURN void rethrow_nested() const;
42 [[__noreturn__]] void rethrow_nested() const;
4243 _LIBCPP_HIDE_FROM_ABI exception_ptr nested_ptr() const _NOEXCEPT { return __ptr_; }
4344};
4445
......@@ -47,26 +48,26 @@ struct __nested : public _Tp, public nested_exception {
4748 _LIBCPP_HIDE_FROM_ABI explicit __nested(const _Tp& __t) : _Tp(__t) {}
4849};
4950
50#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
51#if _LIBCPP_HAS_EXCEPTIONS
5152template <class _Tp, class _Up, bool>
5253struct __throw_with_nested;
5354
5455template <class _Tp, class _Up>
5556struct __throw_with_nested<_Tp, _Up, true> {
56 _LIBCPP_NORETURN static inline _LIBCPP_HIDE_FROM_ABI void __do_throw(_Tp&& __t) {
57 [[__noreturn__]] static inline _LIBCPP_HIDE_FROM_ABI void __do_throw(_Tp&& __t) {
5758 throw __nested<_Up>(std::forward<_Tp>(__t));
5859 }
5960};
6061
6162template <class _Tp, class _Up>
6263struct __throw_with_nested<_Tp, _Up, false> {
63 _LIBCPP_NORETURN static inline _LIBCPP_HIDE_FROM_ABI void __do_throw(_Tp&& __t) { throw std::forward<_Tp>(__t); }
64 [[__noreturn__]] static inline _LIBCPP_HIDE_FROM_ABI void __do_throw(_Tp&& __t) { throw std::forward<_Tp>(__t); }
6465};
6566#endif
6667
6768template <class _Tp>
68_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void throw_with_nested(_Tp&& __t) {
69#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
69[[__noreturn__]] _LIBCPP_HIDE_FROM_ABI void throw_with_nested(_Tp&& __t) {
70#if _LIBCPP_HAS_EXCEPTIONS
7071 using _Up = __decay_t<_Tp>;
7172 static_assert(is_copy_constructible<_Up>::value, "type thrown must be CopyConstructible");
7273 __throw_with_nested<_Tp,
lib/libcxx/include/__exception/operations.h+5-4
......@@ -10,7 +10,6 @@
1010#define _LIBCPP___EXCEPTION_OPERATIONS_H
1111
1212#include <__config>
13#include <cstddef>
1413
1514#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1615# pragma GCC system_header
......@@ -22,20 +21,22 @@ namespace std { // purposefully not using versioning namespace
2221using unexpected_handler = void (*)();
2322_LIBCPP_EXPORTED_FROM_ABI unexpected_handler set_unexpected(unexpected_handler) _NOEXCEPT;
2423_LIBCPP_EXPORTED_FROM_ABI unexpected_handler get_unexpected() _NOEXCEPT;
25_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void unexpected();
24[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void unexpected();
2625#endif
2726
2827using terminate_handler = void (*)();
2928_LIBCPP_EXPORTED_FROM_ABI terminate_handler set_terminate(terminate_handler) _NOEXCEPT;
3029_LIBCPP_EXPORTED_FROM_ABI terminate_handler get_terminate() _NOEXCEPT;
3130
32_LIBCPP_EXPORTED_FROM_ABI bool uncaught_exception() _NOEXCEPT;
31#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_UNCAUGHT_EXCEPTION)
32_LIBCPP_EXPORTED_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 bool uncaught_exception() _NOEXCEPT;
33#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_UNCAUGHT_EXCEPTION)
3334_LIBCPP_EXPORTED_FROM_ABI int uncaught_exceptions() _NOEXCEPT;
3435
3536class _LIBCPP_EXPORTED_FROM_ABI exception_ptr;
3637
3738_LIBCPP_EXPORTED_FROM_ABI exception_ptr current_exception() _NOEXCEPT;
38_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr);
39[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr);
3940} // namespace std
4041
4142#endif // _LIBCPP___EXCEPTION_OPERATIONS_H
lib/libcxx/include/__exception/terminate.h+1-1
......@@ -16,7 +16,7 @@
1616#endif
1717
1818namespace std { // purposefully not using versioning namespace
19_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void terminate() _NOEXCEPT;
19[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void terminate() _NOEXCEPT;
2020} // namespace std
2121
2222#endif // _LIBCPP___EXCEPTION_TERMINATE_H
lib/libcxx/include/__expected/expected.h+33-34
......@@ -17,9 +17,11 @@
1717#include <__functional/invoke.h>
1818#include <__memory/addressof.h>
1919#include <__memory/construct_at.h>
20#include <__type_traits/conditional.h>
2021#include <__type_traits/conjunction.h>
2122#include <__type_traits/disjunction.h>
2223#include <__type_traits/integral_constant.h>
24#include <__type_traits/invoke.h>
2325#include <__type_traits/is_assignable.h>
2426#include <__type_traits/is_constructible.h>
2527#include <__type_traits/is_convertible.h>
......@@ -71,7 +73,7 @@ struct __expected_construct_unexpected_from_invoke_tag {};
7173
7274template <class _Err, class _Arg>
7375_LIBCPP_HIDE_FROM_ABI void __throw_bad_expected_access(_Arg&& __arg) {
74# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
76# if _LIBCPP_HAS_EXCEPTIONS
7577 throw bad_expected_access<_Err>(std::forward<_Arg>(__arg));
7678# else
7779 (void)__arg;
......@@ -457,14 +459,14 @@ class expected : private __expected_base<_Tp, _Err> {
457459 template <class _Up, class _OtherErr>
458460 friend class expected;
459461
460 using __base = __expected_base<_Tp, _Err>;
462 using __base _LIBCPP_NODEBUG = __expected_base<_Tp, _Err>;
461463
462464public:
463465 using value_type = _Tp;
464466 using error_type = _Err;
465467 using unexpected_type = unexpected<_Err>;
466468
467 using __trivially_relocatable =
469 using __trivially_relocatable _LIBCPP_NODEBUG =
468470 __conditional_t<__libcpp_is_trivially_relocatable<_Tp>::value && __libcpp_is_trivially_relocatable<_Err>::value,
469471 expected,
470472 void>;
......@@ -503,25 +505,24 @@ public:
503505
504506private:
505507 template <class _Up, class _OtherErr, class _UfQual, class _OtherErrQual>
506 using __can_convert =
507 _And< is_constructible<_Tp, _UfQual>,
508 is_constructible<_Err, _OtherErrQual>,
509 _If<_Not<is_same<remove_cv_t<_Tp>, bool>>::value,
510 _And<
511 _Not<_And<is_same<_Tp, _Up>, is_same<_Err, _OtherErr>>>, // use the copy constructor instead, see #92676
512 _Not<is_constructible<_Tp, expected<_Up, _OtherErr>&>>,
513 _Not<is_constructible<_Tp, expected<_Up, _OtherErr>>>,
514 _Not<is_constructible<_Tp, const expected<_Up, _OtherErr>&>>,
515 _Not<is_constructible<_Tp, const expected<_Up, _OtherErr>>>,
516 _Not<is_convertible<expected<_Up, _OtherErr>&, _Tp>>,
517 _Not<is_convertible<expected<_Up, _OtherErr>&&, _Tp>>,
518 _Not<is_convertible<const expected<_Up, _OtherErr>&, _Tp>>,
519 _Not<is_convertible<const expected<_Up, _OtherErr>&&, _Tp>>>,
520 true_type>,
521 _Not<is_constructible<unexpected<_Err>, expected<_Up, _OtherErr>&>>,
522 _Not<is_constructible<unexpected<_Err>, expected<_Up, _OtherErr>>>,
523 _Not<is_constructible<unexpected<_Err>, const expected<_Up, _OtherErr>&>>,
524 _Not<is_constructible<unexpected<_Err>, const expected<_Up, _OtherErr>>> >;
508 using __can_convert _LIBCPP_NODEBUG = _And<
509 is_constructible<_Tp, _UfQual>,
510 is_constructible<_Err, _OtherErrQual>,
511 _If<_Not<is_same<remove_cv_t<_Tp>, bool>>::value,
512 _And< _Not<_And<is_same<_Tp, _Up>, is_same<_Err, _OtherErr>>>, // use the copy constructor instead, see #92676
513 _Not<is_constructible<_Tp, expected<_Up, _OtherErr>&>>,
514 _Not<is_constructible<_Tp, expected<_Up, _OtherErr>>>,
515 _Not<is_constructible<_Tp, const expected<_Up, _OtherErr>&>>,
516 _Not<is_constructible<_Tp, const expected<_Up, _OtherErr>>>,
517 _Not<is_convertible<expected<_Up, _OtherErr>&, _Tp>>,
518 _Not<is_convertible<expected<_Up, _OtherErr>&&, _Tp>>,
519 _Not<is_convertible<const expected<_Up, _OtherErr>&, _Tp>>,
520 _Not<is_convertible<const expected<_Up, _OtherErr>&&, _Tp>>>,
521 true_type>,
522 _Not<is_constructible<unexpected<_Err>, expected<_Up, _OtherErr>&>>,
523 _Not<is_constructible<unexpected<_Err>, expected<_Up, _OtherErr>>>,
524 _Not<is_constructible<unexpected<_Err>, const expected<_Up, _OtherErr>&>>,
525 _Not<is_constructible<unexpected<_Err>, const expected<_Up, _OtherErr>>> >;
525526
526527 template <class _Func, class... _Args>
527528 _LIBCPP_HIDE_FROM_ABI constexpr explicit expected(
......@@ -918,9 +919,9 @@ public:
918919 requires is_constructible_v<_Err, _Err&>
919920 _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) & {
920921 using _Up = remove_cvref_t<invoke_result_t<_Func, _Tp&>>;
921 static_assert(__is_std_expected<_Up>::value, "The result of f(**this) must be a specialization of std::expected");
922 static_assert(__is_std_expected<_Up>::value, "The result of f(value()) must be a specialization of std::expected");
922923 static_assert(is_same_v<typename _Up::error_type, _Err>,
923 "The result of f(**this) must have the same error_type as this expected");
924 "The result of f(value()) must have the same error_type as this expected");
924925 if (has_value()) {
925926 return std::invoke(std::forward<_Func>(__f), this->__val());
926927 }
......@@ -931,9 +932,9 @@ public:
931932 requires is_constructible_v<_Err, const _Err&>
932933 _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) const& {
933934 using _Up = remove_cvref_t<invoke_result_t<_Func, const _Tp&>>;
934 static_assert(__is_std_expected<_Up>::value, "The result of f(**this) must be a specialization of std::expected");
935 static_assert(__is_std_expected<_Up>::value, "The result of f(value()) must be a specialization of std::expected");
935936 static_assert(is_same_v<typename _Up::error_type, _Err>,
936 "The result of f(**this) must have the same error_type as this expected");
937 "The result of f(value()) must have the same error_type as this expected");
937938 if (has_value()) {
938939 return std::invoke(std::forward<_Func>(__f), this->__val());
939940 }
......@@ -945,9 +946,9 @@ public:
945946 _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) && {
946947 using _Up = remove_cvref_t<invoke_result_t<_Func, _Tp&&>>;
947948 static_assert(
948 __is_std_expected<_Up>::value, "The result of f(std::move(**this)) must be a specialization of std::expected");
949 __is_std_expected<_Up>::value, "The result of f(std::move(value())) must be a specialization of std::expected");
949950 static_assert(is_same_v<typename _Up::error_type, _Err>,
950 "The result of f(std::move(**this)) must have the same error_type as this expected");
951 "The result of f(std::move(value())) must have the same error_type as this expected");
951952 if (has_value()) {
952953 return std::invoke(std::forward<_Func>(__f), std::move(this->__val()));
953954 }
......@@ -959,9 +960,9 @@ public:
959960 _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) const&& {
960961 using _Up = remove_cvref_t<invoke_result_t<_Func, const _Tp&&>>;
961962 static_assert(
962 __is_std_expected<_Up>::value, "The result of f(std::move(**this)) must be a specialization of std::expected");
963 __is_std_expected<_Up>::value, "The result of f(std::move(value())) must be a specialization of std::expected");
963964 static_assert(is_same_v<typename _Up::error_type, _Err>,
964 "The result of f(std::move(**this)) must have the same error_type as this expected");
965 "The result of f(std::move(value())) must have the same error_type as this expected");
965966 if (has_value()) {
966967 return std::invoke(std::forward<_Func>(__f), std::move(this->__val()));
967968 }
......@@ -1362,7 +1363,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
13621363 friend class expected;
13631364
13641365 template <class _Up, class _OtherErr, class _OtherErrQual>
1365 using __can_convert =
1366 using __can_convert _LIBCPP_NODEBUG =
13661367 _And< is_void<_Up>,
13671368 is_constructible<_Err, _OtherErrQual>,
13681369 _Not<is_constructible<unexpected<_Err>, expected<_Up, _OtherErr>&>>,
......@@ -1370,7 +1371,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
13701371 _Not<is_constructible<unexpected<_Err>, const expected<_Up, _OtherErr>&>>,
13711372 _Not<is_constructible<unexpected<_Err>, const expected<_Up, _OtherErr>>>>;
13721373
1373 using __base = __expected_void_base<_Err>;
1374 using __base _LIBCPP_NODEBUG = __expected_void_base<_Err>;
13741375
13751376public:
13761377 using value_type = _Tp;
......@@ -1492,8 +1493,6 @@ public:
14921493 return *this;
14931494 }
14941495
1495 _LIBCPP_HIDE_FROM_ABI constexpr expected& operator=(expected&&) = delete;
1496
14971496 _LIBCPP_HIDE_FROM_ABI constexpr expected&
14981497 operator=(expected&& __rhs) noexcept(is_nothrow_move_assignable_v<_Err> && is_nothrow_move_constructible_v<_Err>)
14991498 requires(is_move_assignable_v<_Err> && is_move_constructible_v<_Err>)
lib/libcxx/include/__expected/unexpected.h+7-7
......@@ -48,12 +48,12 @@ template <class _Err>
4848struct __is_std_unexpected<unexpected<_Err>> : true_type {};
4949
5050template <class _Tp>
51using __valid_std_unexpected = _BoolConstant< //
52 is_object_v<_Tp> && //
53 !is_array_v<_Tp> && //
54 !__is_std_unexpected<_Tp>::value && //
55 !is_const_v<_Tp> && //
56 !is_volatile_v<_Tp> //
51using __valid_std_unexpected _LIBCPP_NODEBUG = _BoolConstant< //
52 is_object_v<_Tp> && //
53 !is_array_v<_Tp> && //
54 !__is_std_unexpected<_Tp>::value && //
55 !is_const_v<_Tp> && //
56 !is_volatile_v<_Tp> //
5757 >;
5858
5959template <class _Err>
......@@ -108,7 +108,7 @@ public:
108108
109109 template <class _Err2>
110110 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const unexpected& __x, const unexpected<_Err2>& __y) {
111 return __x.__unex_ == __y.__unex_;
111 return __x.__unex_ == __y.error();
112112 }
113113
114114private:
lib/libcxx/include/__filesystem/directory_entry.h+48-13
......@@ -20,8 +20,11 @@
2020#include <__filesystem/operations.h>
2121#include <__filesystem/path.h>
2222#include <__filesystem/perms.h>
23#include <__fwd/ostream.h>
2324#include <__system_error/errc.h>
25#include <__system_error/error_category.h>
2426#include <__system_error/error_code.h>
27#include <__system_error/error_condition.h>
2528#include <__utility/move.h>
2629#include <__utility/unreachable.h>
2730#include <cstdint>
......@@ -33,7 +36,7 @@
3336_LIBCPP_PUSH_MACROS
3437#include <__undef_macros>
3538
36#if _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
39#if _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM
3740
3841_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
3942
......@@ -201,7 +204,9 @@ private:
201204 _IterNonSymlink,
202205 _RefreshSymlink,
203206 _RefreshSymlinkUnresolved,
204 _RefreshNonSymlink
207 _RefreshNonSymlink,
208 _IterCachedSymlink,
209 _IterCachedNonSymlink
205210 };
206211
207212 struct __cached_data {
......@@ -240,6 +245,29 @@ private:
240245 return __data;
241246 }
242247
248 _LIBCPP_HIDE_FROM_ABI static __cached_data
249 __create_iter_cached_result(file_type __ft, uintmax_t __size, perms __perm, file_time_type __write_time) {
250 __cached_data __data;
251 __data.__type_ = __ft;
252 __data.__size_ = __size;
253 __data.__write_time_ = __write_time;
254 if (__ft == file_type::symlink)
255 __data.__sym_perms_ = __perm;
256 else
257 __data.__non_sym_perms_ = __perm;
258 __data.__cache_type_ = [&]() {
259 switch (__ft) {
260 case file_type::none:
261 return _Empty;
262 case file_type::symlink:
263 return _IterCachedSymlink;
264 default:
265 return _IterCachedNonSymlink;
266 }
267 }();
268 return __data;
269 }
270
243271 _LIBCPP_HIDE_FROM_ABI void __assign_iter_entry(_Path&& __p, __cached_data __dt) {
244272 __p_ = std::move(__p);
245273 __data_ = __dt;
......@@ -248,15 +276,7 @@ private:
248276 _LIBCPP_EXPORTED_FROM_ABI error_code __do_refresh() noexcept;
249277
250278 _LIBCPP_HIDE_FROM_ABI static bool __is_dne_error(error_code const& __ec) {
251 if (!__ec)
252 return true;
253 switch (static_cast<errc>(__ec.value())) {
254 case errc::no_such_file_or_directory:
255 case errc::not_a_directory:
256 return true;
257 default:
258 return false;
259 }
279 return !__ec || __ec == errc::no_such_file_or_directory || __ec == errc::not_a_directory;
260280 }
261281
262282 _LIBCPP_HIDE_FROM_ABI void
......@@ -281,13 +301,15 @@ private:
281301 case _Empty:
282302 return __symlink_status(__p_, __ec).type();
283303 case _IterSymlink:
304 case _IterCachedSymlink:
284305 case _RefreshSymlink:
285306 case _RefreshSymlinkUnresolved:
286307 if (__ec)
287308 __ec->clear();
288309 return file_type::symlink;
310 case _IterCachedNonSymlink:
289311 case _IterNonSymlink:
290 case _RefreshNonSymlink:
312 case _RefreshNonSymlink: {
291313 file_status __st(__data_.__type_);
292314 if (__ec && !filesystem::exists(__st))
293315 *__ec = make_error_code(errc::no_such_file_or_directory);
......@@ -295,6 +317,7 @@ private:
295317 __ec->clear();
296318 return __data_.__type_;
297319 }
320 }
298321 __libcpp_unreachable();
299322 }
300323
......@@ -302,8 +325,10 @@ private:
302325 switch (__data_.__cache_type_) {
303326 case _Empty:
304327 case _IterSymlink:
328 case _IterCachedSymlink:
305329 case _RefreshSymlinkUnresolved:
306330 return __status(__p_, __ec).type();
331 case _IterCachedNonSymlink:
307332 case _IterNonSymlink:
308333 case _RefreshNonSymlink:
309334 case _RefreshSymlink: {
......@@ -323,8 +348,10 @@ private:
323348 case _Empty:
324349 case _IterNonSymlink:
325350 case _IterSymlink:
351 case _IterCachedSymlink:
326352 case _RefreshSymlinkUnresolved:
327353 return __status(__p_, __ec);
354 case _IterCachedNonSymlink:
328355 case _RefreshNonSymlink:
329356 case _RefreshSymlink:
330357 return file_status(__get_ft(__ec), __data_.__non_sym_perms_);
......@@ -338,8 +365,10 @@ private:
338365 case _IterNonSymlink:
339366 case _IterSymlink:
340367 return __symlink_status(__p_, __ec);
368 case _IterCachedNonSymlink:
341369 case _RefreshNonSymlink:
342370 return file_status(__get_sym_ft(__ec), __data_.__non_sym_perms_);
371 case _IterCachedSymlink:
343372 case _RefreshSymlink:
344373 case _RefreshSymlinkUnresolved:
345374 return file_status(__get_sym_ft(__ec), __data_.__sym_perms_);
......@@ -352,8 +381,10 @@ private:
352381 case _Empty:
353382 case _IterNonSymlink:
354383 case _IterSymlink:
384 case _IterCachedSymlink:
355385 case _RefreshSymlinkUnresolved:
356386 return filesystem::__file_size(__p_, __ec);
387 case _IterCachedNonSymlink:
357388 case _RefreshSymlink:
358389 case _RefreshNonSymlink: {
359390 error_code __m_ec;
......@@ -374,6 +405,8 @@ private:
374405 case _Empty:
375406 case _IterNonSymlink:
376407 case _IterSymlink:
408 case _IterCachedNonSymlink:
409 case _IterCachedSymlink:
377410 case _RefreshSymlinkUnresolved:
378411 return filesystem::__hard_link_count(__p_, __ec);
379412 case _RefreshSymlink:
......@@ -392,8 +425,10 @@ private:
392425 case _Empty:
393426 case _IterNonSymlink:
394427 case _IterSymlink:
428 case _IterCachedSymlink:
395429 case _RefreshSymlinkUnresolved:
396430 return filesystem::__last_write_time(__p_, __ec);
431 case _IterCachedNonSymlink:
397432 case _RefreshSymlink:
398433 case _RefreshNonSymlink: {
399434 error_code __m_ec;
......@@ -428,7 +463,7 @@ _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP
428463
429464_LIBCPP_END_NAMESPACE_FILESYSTEM
430465
431#endif // _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
466#endif // _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM
432467
433468_LIBCPP_POP_MACROS
434469
lib/libcxx/include/__filesystem/directory_iterator.h+2-3
......@@ -22,7 +22,6 @@
2222#include <__ranges/enable_view.h>
2323#include <__system_error/error_code.h>
2424#include <__utility/move.h>
25#include <cstddef>
2625
2726#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2827# pragma GCC system_header
......@@ -31,7 +30,7 @@
3130_LIBCPP_PUSH_MACROS
3231#include <__undef_macros>
3332
34#if _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
33#if _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM
3534
3635_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
3736
......@@ -144,7 +143,7 @@ _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY inline constexpr bool
144143
145144# endif // _LIBCPP_STD_VER >= 20
146145
147#endif // _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
146#endif // _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM
148147
149148_LIBCPP_POP_MACROS
150149
lib/libcxx/include/__filesystem/filesystem_error.h+3-3
......@@ -67,15 +67,15 @@ private:
6767 shared_ptr<_Storage> __storage_;
6868};
6969
70# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
70# if _LIBCPP_HAS_EXCEPTIONS
7171template <class... _Args>
72_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY void
72[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY void
7373__throw_filesystem_error(_Args&&... __args) {
7474 throw filesystem_error(std::forward<_Args>(__args)...);
7575}
7676# else
7777template <class... _Args>
78_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY void
78[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY void
7979__throw_filesystem_error(_Args&&...) {
8080 _LIBCPP_VERBOSE_ABORT("filesystem_error was thrown in -fno-exceptions mode");
8181}
lib/libcxx/include/__filesystem/operations.h+2-2
......@@ -27,7 +27,7 @@
2727# pragma GCC system_header
2828#endif
2929
30#if _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
30#if _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM
3131
3232_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
3333
......@@ -305,6 +305,6 @@ _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP
305305
306306_LIBCPP_END_NAMESPACE_FILESYSTEM
307307
308#endif // _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
308#endif // _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM
309309
310310#endif // _LIBCPP___FILESYSTEM_OPERATIONS_H
lib/libcxx/include/__filesystem/path.h+39-39
......@@ -21,11 +21,11 @@
2121#include <__type_traits/is_pointer.h>
2222#include <__type_traits/remove_const.h>
2323#include <__type_traits/remove_pointer.h>
24#include <cstddef>
24#include <__utility/move.h>
2525#include <string>
2626#include <string_view>
2727
28#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
28#if _LIBCPP_HAS_LOCALIZATION
2929# include <iomanip> // for quoted
3030# include <locale>
3131#endif
......@@ -51,30 +51,30 @@ template <class _Tp>
5151struct __can_convert_char<const _Tp> : public __can_convert_char<_Tp> {};
5252template <>
5353struct __can_convert_char<char> {
54 static const bool value = true;
55 using __char_type = char;
54 static const bool value = true;
55 using __char_type _LIBCPP_NODEBUG = char;
5656};
5757template <>
5858struct __can_convert_char<wchar_t> {
59 static const bool value = true;
60 using __char_type = wchar_t;
59 static const bool value = true;
60 using __char_type _LIBCPP_NODEBUG = wchar_t;
6161};
62# ifndef _LIBCPP_HAS_NO_CHAR8_T
62# if _LIBCPP_HAS_CHAR8_T
6363template <>
6464struct __can_convert_char<char8_t> {
65 static const bool value = true;
66 using __char_type = char8_t;
65 static const bool value = true;
66 using __char_type _LIBCPP_NODEBUG = char8_t;
6767};
6868# endif
6969template <>
7070struct __can_convert_char<char16_t> {
71 static const bool value = true;
72 using __char_type = char16_t;
71 static const bool value = true;
72 using __char_type _LIBCPP_NODEBUG = char16_t;
7373};
7474template <>
7575struct __can_convert_char<char32_t> {
76 static const bool value = true;
77 using __char_type = char32_t;
76 static const bool value = true;
77 using __char_type _LIBCPP_NODEBUG = char32_t;
7878};
7979
8080template <class _ECharT, __enable_if_t<__can_convert_char<_ECharT>::value, int> = 0>
......@@ -86,7 +86,7 @@ _LIBCPP_HIDE_FROM_ABI bool __is_separator(_ECharT __e) {
8686# endif
8787}
8888
89# ifndef _LIBCPP_HAS_NO_CHAR8_T
89# if _LIBCPP_HAS_CHAR8_T
9090typedef u8string __u8_string;
9191# else
9292typedef string __u8_string;
......@@ -95,7 +95,7 @@ typedef string __u8_string;
9595struct _NullSentinel {};
9696
9797template <class _Tp>
98using _Void = void;
98using _Void _LIBCPP_NODEBUG = void;
9999
100100template <class _Tp, class = void>
101101struct __is_pathable_string : public false_type {};
......@@ -104,7 +104,7 @@ template <class _ECharT, class _Traits, class _Alloc>
104104struct __is_pathable_string< basic_string<_ECharT, _Traits, _Alloc>,
105105 _Void<typename __can_convert_char<_ECharT>::__char_type> >
106106 : public __can_convert_char<_ECharT> {
107 using _Str = basic_string<_ECharT, _Traits, _Alloc>;
107 using _Str _LIBCPP_NODEBUG = basic_string<_ECharT, _Traits, _Alloc>;
108108
109109 _LIBCPP_HIDE_FROM_ABI static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
110110
......@@ -117,7 +117,7 @@ template <class _ECharT, class _Traits>
117117struct __is_pathable_string< basic_string_view<_ECharT, _Traits>,
118118 _Void<typename __can_convert_char<_ECharT>::__char_type> >
119119 : public __can_convert_char<_ECharT> {
120 using _Str = basic_string_view<_ECharT, _Traits>;
120 using _Str _LIBCPP_NODEBUG = basic_string_view<_ECharT, _Traits>;
121121
122122 _LIBCPP_HIDE_FROM_ABI static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); }
123123
......@@ -157,7 +157,7 @@ struct __is_pathable_iter<
157157 true,
158158 _Void<typename __can_convert_char< typename iterator_traits<_Iter>::value_type>::__char_type> >
159159 : __can_convert_char<typename iterator_traits<_Iter>::value_type> {
160 using _ECharT = typename iterator_traits<_Iter>::value_type;
160 using _ECharT _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::value_type;
161161
162162 _LIBCPP_HIDE_FROM_ABI static _Iter __range_begin(_Iter __b) { return __b; }
163163
......@@ -199,7 +199,7 @@ _LIBCPP_EXPORTED_FROM_ABI size_t __char_to_wide(const string&, wchar_t*, size_t)
199199template <class _ECharT>
200200struct _PathCVT;
201201
202# if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
202# if _LIBCPP_HAS_LOCALIZATION
203203template <class _ECharT>
204204struct _PathCVT {
205205 static_assert(__can_convert_char<_ECharT>::value, "Char type not convertible");
......@@ -258,7 +258,7 @@ struct _PathCVT {
258258 __append_range(__dest, _Traits::__range_begin(__s), _Traits::__range_end(__s));
259259 }
260260};
261# endif // !_LIBCPP_HAS_NO_LOCALIZATION
261# endif // _LIBCPP_HAS_LOCALIZATION
262262
263263template <>
264264struct _PathCVT<__path_value> {
......@@ -365,7 +365,7 @@ struct _PathExport<char16_t> {
365365 }
366366};
367367
368# ifndef _LIBCPP_HAS_NO_CHAR8_T
368# if _LIBCPP_HAS_CHAR8_T
369369template <>
370370struct _PathExport<char8_t> {
371371 typedef __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Narrower;
......@@ -375,18 +375,18 @@ struct _PathExport<char8_t> {
375375 _Narrower()(back_inserter(__dest), __src.data(), __src.data() + __src.size());
376376 }
377377};
378# endif /* !_LIBCPP_HAS_NO_CHAR8_T */
378# endif // _LIBCPP_HAS_CHAR8_T
379379# endif /* _LIBCPP_WIN32API */
380380
381381class _LIBCPP_EXPORTED_FROM_ABI path {
382382 template <class _SourceOrIter, class _Tp = path&>
383 using _EnableIfPathable = __enable_if_t<__is_pathable<_SourceOrIter>::value, _Tp>;
383 using _EnableIfPathable _LIBCPP_NODEBUG = __enable_if_t<__is_pathable<_SourceOrIter>::value, _Tp>;
384384
385385 template <class _Tp>
386 using _SourceChar = typename __is_pathable<_Tp>::__char_type;
386 using _SourceChar _LIBCPP_NODEBUG = typename __is_pathable<_Tp>::__char_type;
387387
388388 template <class _Tp>
389 using _SourceCVT = _PathCVT<_SourceChar<_Tp> >;
389 using _SourceCVT _LIBCPP_NODEBUG = _PathCVT<_SourceChar<_Tp> >;
390390
391391public:
392392# if defined(_LIBCPP_WIN32API)
......@@ -420,7 +420,7 @@ public:
420420 }
421421
422422 /*
423 #if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
423 #if _LIBCPP_HAS_LOCALIZATION
424424 // TODO Implement locale conversions.
425425 template <class _Source, class = _EnableIfPathable<_Source, void> >
426426 path(const _Source& __src, const locale& __loc, format = format::auto_format);
......@@ -682,7 +682,7 @@ public:
682682 return __s;
683683 }
684684
685# if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
685# if _LIBCPP_HAS_LOCALIZATION
686686 template <class _ECharT, class _Traits = char_traits<_ECharT>, class _Allocator = allocator<_ECharT> >
687687 _LIBCPP_HIDE_FROM_ABI basic_string<_ECharT, _Traits, _Allocator> string(const _Allocator& __a = _Allocator()) const {
688688 using _Str = basic_string<_ECharT, _Traits, _Allocator>;
......@@ -725,17 +725,17 @@ public:
725725 std::replace(__s.begin(), __s.end(), '\\', '/');
726726 return __s;
727727 }
728# endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
728# endif // _LIBCPP_HAS_LOCALIZATION
729729# else /* _LIBCPP_WIN32API */
730730
731731 _LIBCPP_HIDE_FROM_ABI std::string string() const { return __pn_; }
732# ifndef _LIBCPP_HAS_NO_CHAR8_T
732# if _LIBCPP_HAS_CHAR8_T
733733 _LIBCPP_HIDE_FROM_ABI std::u8string u8string() const { return std::u8string(__pn_.begin(), __pn_.end()); }
734734# else
735735 _LIBCPP_HIDE_FROM_ABI std::string u8string() const { return __pn_; }
736736# endif
737737
738# if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
738# if _LIBCPP_HAS_LOCALIZATION
739739 template <class _ECharT, class _Traits = char_traits<_ECharT>, class _Allocator = allocator<_ECharT> >
740740 _LIBCPP_HIDE_FROM_ABI basic_string<_ECharT, _Traits, _Allocator> string(const _Allocator& __a = _Allocator()) const {
741741 using _CVT = __widen_from_utf8<sizeof(_ECharT) * __CHAR_BIT__>;
......@@ -746,34 +746,34 @@ public:
746746 return __s;
747747 }
748748
749# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
749# if _LIBCPP_HAS_WIDE_CHARACTERS
750750 _LIBCPP_HIDE_FROM_ABI std::wstring wstring() const { return string<wchar_t>(); }
751751# endif
752752 _LIBCPP_HIDE_FROM_ABI std::u16string u16string() const { return string<char16_t>(); }
753753 _LIBCPP_HIDE_FROM_ABI std::u32string u32string() const { return string<char32_t>(); }
754# endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
754# endif // _LIBCPP_HAS_LOCALIZATION
755755
756756 // generic format observers
757757 _LIBCPP_HIDE_FROM_ABI std::string generic_string() const { return __pn_; }
758# ifndef _LIBCPP_HAS_NO_CHAR8_T
758# if _LIBCPP_HAS_CHAR8_T
759759 _LIBCPP_HIDE_FROM_ABI std::u8string generic_u8string() const { return std::u8string(__pn_.begin(), __pn_.end()); }
760760# else
761761 _LIBCPP_HIDE_FROM_ABI std::string generic_u8string() const { return __pn_; }
762762# endif
763763
764# if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
764# if _LIBCPP_HAS_LOCALIZATION
765765 template <class _ECharT, class _Traits = char_traits<_ECharT>, class _Allocator = allocator<_ECharT> >
766766 _LIBCPP_HIDE_FROM_ABI basic_string<_ECharT, _Traits, _Allocator>
767767 generic_string(const _Allocator& __a = _Allocator()) const {
768768 return string<_ECharT, _Traits, _Allocator>(__a);
769769 }
770770
771# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
771# if _LIBCPP_HAS_WIDE_CHARACTERS
772772 _LIBCPP_HIDE_FROM_ABI std::wstring generic_wstring() const { return string<wchar_t>(); }
773773# endif
774774 _LIBCPP_HIDE_FROM_ABI std::u16string generic_u16string() const { return string<char16_t>(); }
775775 _LIBCPP_HIDE_FROM_ABI std::u32string generic_u32string() const { return string<char32_t>(); }
776# endif /* !_LIBCPP_HAS_NO_LOCALIZATION */
776# endif // _LIBCPP_HAS_LOCALIZATION
777777# endif /* !_LIBCPP_WIN32API */
778778
779779private:
......@@ -811,7 +811,7 @@ public:
811811 _LIBCPP_HIDE_FROM_ABI path extension() const { return string_type(__extension()); }
812812
813813 // query
814 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const noexcept { return __pn_.empty(); }
814 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const noexcept { return __pn_.empty(); }
815815
816816 _LIBCPP_HIDE_FROM_ABI bool has_root_name() const { return !__root_name().empty(); }
817817 _LIBCPP_HIDE_FROM_ABI bool has_root_directory() const { return !__root_directory().empty(); }
......@@ -866,7 +866,7 @@ public:
866866 iterator begin() const;
867867 iterator end() const;
868868
869# if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
869# if _LIBCPP_HAS_LOCALIZATION
870870 template <
871871 class _CharT,
872872 class _Traits,
......@@ -895,7 +895,7 @@ public:
895895 __p = __tmp;
896896 return __is;
897897 }
898# endif // !_LIBCPP_HAS_NO_LOCALIZATION
898# endif // _LIBCPP_HAS_LOCALIZATION
899899
900900private:
901901 inline _LIBCPP_HIDE_FROM_ABI path& __assign_view(__string_view const& __s) {
lib/libcxx/include/__filesystem/path_iterator.h-3
......@@ -14,9 +14,6 @@
1414#include <__config>
1515#include <__filesystem/path.h>
1616#include <__iterator/iterator_traits.h>
17#include <cstddef>
18#include <string>
19#include <string_view>
2017
2118#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2219# pragma GCC system_header
lib/libcxx/include/__filesystem/recursive_directory_iterator.h+2-3
......@@ -21,7 +21,6 @@
2121#include <__ranges/enable_view.h>
2222#include <__system_error/error_code.h>
2323#include <__utility/move.h>
24#include <cstddef>
2524
2625#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2726# pragma GCC system_header
......@@ -30,7 +29,7 @@
3029_LIBCPP_PUSH_MACROS
3130#include <__undef_macros>
3231
33#if _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
32#if _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM
3433
3534_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
3635
......@@ -157,7 +156,7 @@ _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY inline constexpr bool
157156
158157# endif // _LIBCPP_STD_VER >= 20
159158
160#endif // _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
159#endif // _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM
161160
162161_LIBCPP_POP_MACROS
163162
lib/libcxx/include/__filesystem/u8path.h+3-3
......@@ -34,7 +34,7 @@ _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH
3434template <class _InputIt, __enable_if_t<__is_pathable<_InputIt>::value, int> = 0>
3535_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f, _InputIt __l) {
3636 static_assert(
37# ifndef _LIBCPP_HAS_NO_CHAR8_T
37# if _LIBCPP_HAS_CHAR8_T
3838 is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||
3939# endif
4040 is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
......@@ -56,7 +56,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f,
5656template <class _InputIt, __enable_if_t<__is_pathable<_InputIt>::value, int> = 0>
5757_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f, _NullSentinel) {
5858 static_assert(
59# ifndef _LIBCPP_HAS_NO_CHAR8_T
59# if _LIBCPP_HAS_CHAR8_T
6060 is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||
6161# endif
6262 is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
......@@ -77,7 +77,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f,
7777template <class _Source, __enable_if_t<__is_pathable<_Source>::value, int> = 0>
7878_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(const _Source& __s) {
7979 static_assert(
80# ifndef _LIBCPP_HAS_NO_CHAR8_T
80# if _LIBCPP_HAS_CHAR8_T
8181 is_same<typename __is_pathable<_Source>::__char_type, char8_t>::value ||
8282# endif
8383 is_same<typename __is_pathable<_Source>::__char_type, char>::value,
lib/libcxx/include/__flat_map/flat_map.h created+1199
......@@ -0,0 +1,1199 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___FLAT_MAP_FLAT_MAP_H
11#define _LIBCPP___FLAT_MAP_FLAT_MAP_H
12
13#include <__algorithm/lexicographical_compare_three_way.h>
14#include <__algorithm/min.h>
15#include <__algorithm/ranges_adjacent_find.h>
16#include <__algorithm/ranges_equal.h>
17#include <__algorithm/ranges_inplace_merge.h>
18#include <__algorithm/ranges_lower_bound.h>
19#include <__algorithm/ranges_partition_point.h>
20#include <__algorithm/ranges_sort.h>
21#include <__algorithm/ranges_unique.h>
22#include <__algorithm/ranges_upper_bound.h>
23#include <__algorithm/remove_if.h>
24#include <__assert>
25#include <__compare/synth_three_way.h>
26#include <__concepts/swappable.h>
27#include <__config>
28#include <__cstddef/byte.h>
29#include <__cstddef/ptrdiff_t.h>
30#include <__flat_map/key_value_iterator.h>
31#include <__flat_map/sorted_unique.h>
32#include <__flat_map/utils.h>
33#include <__functional/invoke.h>
34#include <__functional/is_transparent.h>
35#include <__functional/operations.h>
36#include <__fwd/vector.h>
37#include <__iterator/concepts.h>
38#include <__iterator/distance.h>
39#include <__iterator/iterator_traits.h>
40#include <__iterator/next.h>
41#include <__iterator/ranges_iterator_traits.h>
42#include <__iterator/reverse_iterator.h>
43#include <__memory/allocator_traits.h>
44#include <__memory/uses_allocator.h>
45#include <__memory/uses_allocator_construction.h>
46#include <__ranges/access.h>
47#include <__ranges/concepts.h>
48#include <__ranges/container_compatible_range.h>
49#include <__ranges/drop_view.h>
50#include <__ranges/from_range.h>
51#include <__ranges/ref_view.h>
52#include <__ranges/size.h>
53#include <__ranges/subrange.h>
54#include <__ranges/zip_view.h>
55#include <__type_traits/conjunction.h>
56#include <__type_traits/container_traits.h>
57#include <__type_traits/invoke.h>
58#include <__type_traits/is_allocator.h>
59#include <__type_traits/is_nothrow_constructible.h>
60#include <__type_traits/is_same.h>
61#include <__utility/exception_guard.h>
62#include <__utility/move.h>
63#include <__utility/pair.h>
64#include <__utility/scope_guard.h>
65#include <__vector/vector.h>
66#include <initializer_list>
67#include <stdexcept>
68
69#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
70# pragma GCC system_header
71#endif
72
73_LIBCPP_PUSH_MACROS
74#include <__undef_macros>
75
76#if _LIBCPP_STD_VER >= 23
77
78_LIBCPP_BEGIN_NAMESPACE_STD
79
80template <class _Key,
81 class _Tp,
82 class _Compare = less<_Key>,
83 class _KeyContainer = vector<_Key>,
84 class _MappedContainer = vector<_Tp>>
85class flat_map {
86 template <class, class, class, class, class>
87 friend class flat_map;
88
89 static_assert(is_same_v<_Key, typename _KeyContainer::value_type>);
90 static_assert(is_same_v<_Tp, typename _MappedContainer::value_type>);
91 static_assert(!is_same_v<_KeyContainer, std::vector<bool>>, "vector<bool> is not a sequence container");
92 static_assert(!is_same_v<_MappedContainer, std::vector<bool>>, "vector<bool> is not a sequence container");
93
94 template <bool _Const>
95 using __iterator _LIBCPP_NODEBUG = __key_value_iterator<flat_map, _KeyContainer, _MappedContainer, _Const>;
96
97public:
98 // types
99 using key_type = _Key;
100 using mapped_type = _Tp;
101 using value_type = pair<key_type, mapped_type>;
102 using key_compare = __type_identity_t<_Compare>;
103 using reference = pair<const key_type&, mapped_type&>;
104 using const_reference = pair<const key_type&, const mapped_type&>;
105 using size_type = size_t;
106 using difference_type = ptrdiff_t;
107 using iterator = __iterator<false>; // see [container.requirements]
108 using const_iterator = __iterator<true>; // see [container.requirements]
109 using reverse_iterator = std::reverse_iterator<iterator>;
110 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
111 using key_container_type = _KeyContainer;
112 using mapped_container_type = _MappedContainer;
113
114 class value_compare {
115 private:
116 key_compare __comp_;
117 _LIBCPP_HIDE_FROM_ABI value_compare(key_compare __c) : __comp_(__c) {}
118 friend flat_map;
119
120 public:
121 _LIBCPP_HIDE_FROM_ABI bool operator()(const_reference __x, const_reference __y) const {
122 return __comp_(__x.first, __y.first);
123 }
124 };
125
126 struct containers {
127 key_container_type keys;
128 mapped_container_type values;
129 };
130
131private:
132 template <class _Allocator>
133 _LIBCPP_HIDE_FROM_ABI static constexpr bool __allocator_ctor_constraint =
134 _And<uses_allocator<key_container_type, _Allocator>, uses_allocator<mapped_container_type, _Allocator>>::value;
135
136 _LIBCPP_HIDE_FROM_ABI static constexpr bool __is_compare_transparent = __is_transparent_v<_Compare>;
137
138public:
139 // [flat.map.cons], construct/copy/destroy
140 _LIBCPP_HIDE_FROM_ABI flat_map() noexcept(
141 is_nothrow_default_constructible_v<_KeyContainer> && is_nothrow_default_constructible_v<_MappedContainer> &&
142 is_nothrow_default_constructible_v<_Compare>)
143 : __containers_(), __compare_() {}
144
145 _LIBCPP_HIDE_FROM_ABI flat_map(const flat_map&) = default;
146
147 _LIBCPP_HIDE_FROM_ABI flat_map(flat_map&& __other) noexcept(
148 is_nothrow_move_constructible_v<_KeyContainer> && is_nothrow_move_constructible_v<_MappedContainer> &&
149 is_nothrow_move_constructible_v<_Compare>)
150# if _LIBCPP_HAS_EXCEPTIONS
151 try
152# endif // _LIBCPP_HAS_EXCEPTIONS
153 : __containers_(std::move(__other.__containers_)), __compare_(std::move(__other.__compare_)) {
154 __other.clear();
155# if _LIBCPP_HAS_EXCEPTIONS
156 } catch (...) {
157 __other.clear();
158 // gcc does not like the `throw` keyword in a conditionally noexcept function
159 if constexpr (!(is_nothrow_move_constructible_v<_KeyContainer> &&
160 is_nothrow_move_constructible_v<_MappedContainer> && is_nothrow_move_constructible_v<_Compare>)) {
161 throw;
162 }
163# endif // _LIBCPP_HAS_EXCEPTIONS
164 }
165
166 template <class _Allocator>
167 requires __allocator_ctor_constraint<_Allocator>
168 _LIBCPP_HIDE_FROM_ABI flat_map(const flat_map& __other, const _Allocator& __alloc)
169 : flat_map(__ctor_uses_allocator_tag{},
170 __alloc,
171 __other.__containers_.keys,
172 __other.__containers_.values,
173 __other.__compare_) {}
174
175 template <class _Allocator>
176 requires __allocator_ctor_constraint<_Allocator>
177 _LIBCPP_HIDE_FROM_ABI flat_map(flat_map&& __other, const _Allocator& __alloc)
178# if _LIBCPP_HAS_EXCEPTIONS
179 try
180# endif // _LIBCPP_HAS_EXCEPTIONS
181 : flat_map(__ctor_uses_allocator_tag{},
182 __alloc,
183 std::move(__other.__containers_.keys),
184 std::move(__other.__containers_.values),
185 std::move(__other.__compare_)) {
186 __other.clear();
187# if _LIBCPP_HAS_EXCEPTIONS
188 } catch (...) {
189 __other.clear();
190 throw;
191# endif // _LIBCPP_HAS_EXCEPTIONS
192 }
193
194 _LIBCPP_HIDE_FROM_ABI flat_map(
195 key_container_type __key_cont, mapped_container_type __mapped_cont, const key_compare& __comp = key_compare())
196 : __containers_{.keys = std::move(__key_cont), .values = std::move(__mapped_cont)}, __compare_(__comp) {
197 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
198 "flat_map keys and mapped containers have different size");
199 __sort_and_unique();
200 }
201
202 template <class _Allocator>
203 requires __allocator_ctor_constraint<_Allocator>
204 _LIBCPP_HIDE_FROM_ABI
205 flat_map(const key_container_type& __key_cont, const mapped_container_type& __mapped_cont, const _Allocator& __alloc)
206 : flat_map(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont) {
207 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
208 "flat_map keys and mapped containers have different size");
209 __sort_and_unique();
210 }
211
212 template <class _Allocator>
213 requires __allocator_ctor_constraint<_Allocator>
214 _LIBCPP_HIDE_FROM_ABI
215 flat_map(const key_container_type& __key_cont,
216 const mapped_container_type& __mapped_cont,
217 const key_compare& __comp,
218 const _Allocator& __alloc)
219 : flat_map(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont, __comp) {
220 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
221 "flat_map keys and mapped containers have different size");
222 __sort_and_unique();
223 }
224
225 _LIBCPP_HIDE_FROM_ABI
226 flat_map(sorted_unique_t,
227 key_container_type __key_cont,
228 mapped_container_type __mapped_cont,
229 const key_compare& __comp = key_compare())
230 : __containers_{.keys = std::move(__key_cont), .values = std::move(__mapped_cont)}, __compare_(__comp) {
231 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
232 "flat_map keys and mapped containers have different size");
233 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
234 __is_sorted_and_unique(__containers_.keys), "Either the key container is not sorted or it contains duplicates");
235 }
236
237 template <class _Allocator>
238 requires __allocator_ctor_constraint<_Allocator>
239 _LIBCPP_HIDE_FROM_ABI
240 flat_map(sorted_unique_t,
241 const key_container_type& __key_cont,
242 const mapped_container_type& __mapped_cont,
243 const _Allocator& __alloc)
244 : flat_map(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont) {
245 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
246 "flat_map keys and mapped containers have different size");
247 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
248 __is_sorted_and_unique(__containers_.keys), "Either the key container is not sorted or it contains duplicates");
249 }
250
251 template <class _Allocator>
252 requires __allocator_ctor_constraint<_Allocator>
253 _LIBCPP_HIDE_FROM_ABI
254 flat_map(sorted_unique_t,
255 const key_container_type& __key_cont,
256 const mapped_container_type& __mapped_cont,
257 const key_compare& __comp,
258 const _Allocator& __alloc)
259 : flat_map(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont, __comp) {
260 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
261 "flat_map keys and mapped containers have different size");
262 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
263 __is_sorted_and_unique(__containers_.keys), "Either the key container is not sorted or it contains duplicates");
264 }
265
266 _LIBCPP_HIDE_FROM_ABI explicit flat_map(const key_compare& __comp) : __containers_(), __compare_(__comp) {}
267
268 template <class _Allocator>
269 requires __allocator_ctor_constraint<_Allocator>
270 _LIBCPP_HIDE_FROM_ABI flat_map(const key_compare& __comp, const _Allocator& __alloc)
271 : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {}
272
273 template <class _Allocator>
274 requires __allocator_ctor_constraint<_Allocator>
275 _LIBCPP_HIDE_FROM_ABI explicit flat_map(const _Allocator& __alloc)
276 : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc) {}
277
278 template <class _InputIterator>
279 requires __has_input_iterator_category<_InputIterator>::value
280 _LIBCPP_HIDE_FROM_ABI
281 flat_map(_InputIterator __first, _InputIterator __last, const key_compare& __comp = key_compare())
282 : __containers_(), __compare_(__comp) {
283 insert(__first, __last);
284 }
285
286 template <class _InputIterator, class _Allocator>
287 requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>)
288 _LIBCPP_HIDE_FROM_ABI
289 flat_map(_InputIterator __first, _InputIterator __last, const key_compare& __comp, const _Allocator& __alloc)
290 : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {
291 insert(__first, __last);
292 }
293
294 template <class _InputIterator, class _Allocator>
295 requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>)
296 _LIBCPP_HIDE_FROM_ABI flat_map(_InputIterator __first, _InputIterator __last, const _Allocator& __alloc)
297 : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc) {
298 insert(__first, __last);
299 }
300
301 template <_ContainerCompatibleRange<value_type> _Range>
302 _LIBCPP_HIDE_FROM_ABI flat_map(from_range_t __fr, _Range&& __rg)
303 : flat_map(__fr, std::forward<_Range>(__rg), key_compare()) {}
304
305 template <_ContainerCompatibleRange<value_type> _Range, class _Allocator>
306 requires __allocator_ctor_constraint<_Allocator>
307 _LIBCPP_HIDE_FROM_ABI flat_map(from_range_t, _Range&& __rg, const _Allocator& __alloc)
308 : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc) {
309 insert_range(std::forward<_Range>(__rg));
310 }
311
312 template <_ContainerCompatibleRange<value_type> _Range>
313 _LIBCPP_HIDE_FROM_ABI flat_map(from_range_t, _Range&& __rg, const key_compare& __comp) : flat_map(__comp) {
314 insert_range(std::forward<_Range>(__rg));
315 }
316
317 template <_ContainerCompatibleRange<value_type> _Range, class _Allocator>
318 requires __allocator_ctor_constraint<_Allocator>
319 _LIBCPP_HIDE_FROM_ABI flat_map(from_range_t, _Range&& __rg, const key_compare& __comp, const _Allocator& __alloc)
320 : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {
321 insert_range(std::forward<_Range>(__rg));
322 }
323
324 template <class _InputIterator>
325 requires __has_input_iterator_category<_InputIterator>::value
326 _LIBCPP_HIDE_FROM_ABI
327 flat_map(sorted_unique_t, _InputIterator __first, _InputIterator __last, const key_compare& __comp = key_compare())
328 : __containers_(), __compare_(__comp) {
329 insert(sorted_unique, __first, __last);
330 }
331 template <class _InputIterator, class _Allocator>
332 requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>)
333 _LIBCPP_HIDE_FROM_ABI
334 flat_map(sorted_unique_t,
335 _InputIterator __first,
336 _InputIterator __last,
337 const key_compare& __comp,
338 const _Allocator& __alloc)
339 : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {
340 insert(sorted_unique, __first, __last);
341 }
342
343 template <class _InputIterator, class _Allocator>
344 requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>)
345 _LIBCPP_HIDE_FROM_ABI
346 flat_map(sorted_unique_t, _InputIterator __first, _InputIterator __last, const _Allocator& __alloc)
347 : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc) {
348 insert(sorted_unique, __first, __last);
349 }
350
351 _LIBCPP_HIDE_FROM_ABI flat_map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
352 : flat_map(__il.begin(), __il.end(), __comp) {}
353
354 template <class _Allocator>
355 requires __allocator_ctor_constraint<_Allocator>
356 _LIBCPP_HIDE_FROM_ABI
357 flat_map(initializer_list<value_type> __il, const key_compare& __comp, const _Allocator& __alloc)
358 : flat_map(__il.begin(), __il.end(), __comp, __alloc) {}
359
360 template <class _Allocator>
361 requires __allocator_ctor_constraint<_Allocator>
362 _LIBCPP_HIDE_FROM_ABI flat_map(initializer_list<value_type> __il, const _Allocator& __alloc)
363 : flat_map(__il.begin(), __il.end(), __alloc) {}
364
365 _LIBCPP_HIDE_FROM_ABI
366 flat_map(sorted_unique_t, initializer_list<value_type> __il, const key_compare& __comp = key_compare())
367 : flat_map(sorted_unique, __il.begin(), __il.end(), __comp) {}
368
369 template <class _Allocator>
370 requires __allocator_ctor_constraint<_Allocator>
371 _LIBCPP_HIDE_FROM_ABI
372 flat_map(sorted_unique_t, initializer_list<value_type> __il, const key_compare& __comp, const _Allocator& __alloc)
373 : flat_map(sorted_unique, __il.begin(), __il.end(), __comp, __alloc) {}
374
375 template <class _Allocator>
376 requires __allocator_ctor_constraint<_Allocator>
377 _LIBCPP_HIDE_FROM_ABI flat_map(sorted_unique_t, initializer_list<value_type> __il, const _Allocator& __alloc)
378 : flat_map(sorted_unique, __il.begin(), __il.end(), __alloc) {}
379
380 _LIBCPP_HIDE_FROM_ABI flat_map& operator=(initializer_list<value_type> __il) {
381 clear();
382 insert(__il);
383 return *this;
384 }
385
386 _LIBCPP_HIDE_FROM_ABI flat_map& operator=(const flat_map&) = default;
387
388 _LIBCPP_HIDE_FROM_ABI flat_map& operator=(flat_map&& __other) noexcept(
389 is_nothrow_move_assignable_v<_KeyContainer> && is_nothrow_move_assignable_v<_MappedContainer> &&
390 is_nothrow_move_assignable_v<_Compare>) {
391 // No matter what happens, we always want to clear the other container before returning
392 // since we moved from it
393 auto __clear_other_guard = std::__make_scope_guard([&]() noexcept { __other.clear() /* noexcept */; });
394 {
395 // If an exception is thrown, we have no choice but to clear *this to preserve invariants
396 auto __on_exception = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
397 __containers_ = std::move(__other.__containers_);
398 __compare_ = std::move(__other.__compare_);
399 __on_exception.__complete();
400 }
401 return *this;
402 }
403
404 // iterators
405 _LIBCPP_HIDE_FROM_ABI iterator begin() noexcept {
406 return iterator(__containers_.keys.begin(), __containers_.values.begin());
407 }
408
409 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const noexcept {
410 return const_iterator(__containers_.keys.begin(), __containers_.values.begin());
411 }
412
413 _LIBCPP_HIDE_FROM_ABI iterator end() noexcept {
414 return iterator(__containers_.keys.end(), __containers_.values.end());
415 }
416
417 _LIBCPP_HIDE_FROM_ABI const_iterator end() const noexcept {
418 return const_iterator(__containers_.keys.end(), __containers_.values.end());
419 }
420
421 _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() noexcept { return reverse_iterator(end()); }
422 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); }
423 _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() noexcept { return reverse_iterator(begin()); }
424 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); }
425
426 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const noexcept { return begin(); }
427 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const noexcept { return end(); }
428 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); }
429 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); }
430
431 // [flat.map.capacity], capacity
432 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool empty() const noexcept { return __containers_.keys.empty(); }
433
434 _LIBCPP_HIDE_FROM_ABI size_type size() const noexcept { return __containers_.keys.size(); }
435
436 _LIBCPP_HIDE_FROM_ABI size_type max_size() const noexcept {
437 return std::min<size_type>(__containers_.keys.max_size(), __containers_.values.max_size());
438 }
439
440 // [flat.map.access], element access
441 _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](const key_type& __x)
442 requires is_constructible_v<mapped_type>
443 {
444 return try_emplace(__x).first->second;
445 }
446
447 _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](key_type&& __x)
448 requires is_constructible_v<mapped_type>
449 {
450 return try_emplace(std::move(__x)).first->second;
451 }
452
453 template <class _Kp>
454 requires(__is_compare_transparent && is_constructible_v<key_type, _Kp> && is_constructible_v<mapped_type> &&
455 !is_convertible_v<_Kp &&, const_iterator> && !is_convertible_v<_Kp &&, iterator>)
456 _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](_Kp&& __x) {
457 return try_emplace(std::forward<_Kp>(__x)).first->second;
458 }
459
460 _LIBCPP_HIDE_FROM_ABI mapped_type& at(const key_type& __x) {
461 auto __it = find(__x);
462 if (__it == end()) {
463 std::__throw_out_of_range("flat_map::at(const key_type&): Key does not exist");
464 }
465 return __it->second;
466 }
467
468 _LIBCPP_HIDE_FROM_ABI const mapped_type& at(const key_type& __x) const {
469 auto __it = find(__x);
470 if (__it == end()) {
471 std::__throw_out_of_range("flat_map::at(const key_type&) const: Key does not exist");
472 }
473 return __it->second;
474 }
475
476 template <class _Kp>
477 requires __is_compare_transparent
478 _LIBCPP_HIDE_FROM_ABI mapped_type& at(const _Kp& __x) {
479 auto __it = find(__x);
480 if (__it == end()) {
481 std::__throw_out_of_range("flat_map::at(const K&): Key does not exist");
482 }
483 return __it->second;
484 }
485
486 template <class _Kp>
487 requires __is_compare_transparent
488 _LIBCPP_HIDE_FROM_ABI const mapped_type& at(const _Kp& __x) const {
489 auto __it = find(__x);
490 if (__it == end()) {
491 std::__throw_out_of_range("flat_map::at(const K&) const: Key does not exist");
492 }
493 return __it->second;
494 }
495
496 // [flat.map.modifiers], modifiers
497 template <class... _Args>
498 requires is_constructible_v<pair<key_type, mapped_type>, _Args...>
499 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> emplace(_Args&&... __args) {
500 std::pair<key_type, mapped_type> __pair(std::forward<_Args>(__args)...);
501 return __try_emplace(std::move(__pair.first), std::move(__pair.second));
502 }
503
504 template <class... _Args>
505 requires is_constructible_v<pair<key_type, mapped_type>, _Args...>
506 _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __hint, _Args&&... __args) {
507 std::pair<key_type, mapped_type> __pair(std::forward<_Args>(__args)...);
508 return __try_emplace_hint(__hint, std::move(__pair.first), std::move(__pair.second)).first;
509 }
510
511 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __x) { return emplace(__x); }
512
513 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __x) { return emplace(std::move(__x)); }
514
515 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, const value_type& __x) {
516 return emplace_hint(__hint, __x);
517 }
518
519 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, value_type&& __x) {
520 return emplace_hint(__hint, std::move(__x));
521 }
522
523 template <class _PairLike>
524 requires is_constructible_v<pair<key_type, mapped_type>, _PairLike>
525 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(_PairLike&& __x) {
526 return emplace(std::forward<_PairLike>(__x));
527 }
528
529 template <class _PairLike>
530 requires is_constructible_v<pair<key_type, mapped_type>, _PairLike>
531 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, _PairLike&& __x) {
532 return emplace_hint(__hint, std::forward<_PairLike>(__x));
533 }
534
535 template <class _InputIterator>
536 requires __has_input_iterator_category<_InputIterator>::value
537 _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last) {
538 if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>) {
539 __reserve(__last - __first);
540 }
541 __append_sort_merge_unique</*WasSorted = */ false>(std::move(__first), std::move(__last));
542 }
543
544 template <class _InputIterator>
545 requires __has_input_iterator_category<_InputIterator>::value
546 _LIBCPP_HIDE_FROM_ABI void insert(sorted_unique_t, _InputIterator __first, _InputIterator __last) {
547 if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>) {
548 __reserve(__last - __first);
549 }
550
551 __append_sort_merge_unique</*WasSorted = */ true>(std::move(__first), std::move(__last));
552 }
553
554 template <_ContainerCompatibleRange<value_type> _Range>
555 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
556 if constexpr (ranges::sized_range<_Range>) {
557 __reserve(ranges::size(__range));
558 }
559
560 __append_sort_merge_unique</*WasSorted = */ false>(ranges::begin(__range), ranges::end(__range));
561 }
562
563 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
564
565 _LIBCPP_HIDE_FROM_ABI void insert(sorted_unique_t, initializer_list<value_type> __il) {
566 insert(sorted_unique, __il.begin(), __il.end());
567 }
568
569 _LIBCPP_HIDE_FROM_ABI containers extract() && {
570 auto __guard = std::__make_scope_guard([&]() noexcept { clear() /* noexcept */; });
571 auto __ret = std::move(__containers_);
572 return __ret;
573 }
574
575 _LIBCPP_HIDE_FROM_ABI void replace(key_container_type&& __key_cont, mapped_container_type&& __mapped_cont) {
576 _LIBCPP_ASSERT_VALID_INPUT_RANGE(
577 __key_cont.size() == __mapped_cont.size(), "flat_map keys and mapped containers have different size");
578
579 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
580 __is_sorted_and_unique(__key_cont), "Either the key container is not sorted or it contains duplicates");
581 auto __guard = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
582 __containers_.keys = std::move(__key_cont);
583 __containers_.values = std::move(__mapped_cont);
584 __guard.__complete();
585 }
586
587 template <class... _Args>
588 requires is_constructible_v<mapped_type, _Args...>
589 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(const key_type& __key, _Args&&... __args) {
590 return __try_emplace(__key, std::forward<_Args>(__args)...);
591 }
592
593 template <class... _Args>
594 requires is_constructible_v<mapped_type, _Args...>
595 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(key_type&& __key, _Args&&... __args) {
596 return __try_emplace(std::move(__key), std::forward<_Args>(__args)...);
597 }
598
599 template <class _Kp, class... _Args>
600 requires(__is_compare_transparent && is_constructible_v<key_type, _Kp> &&
601 is_constructible_v<mapped_type, _Args...> && !is_convertible_v<_Kp &&, const_iterator> &&
602 !is_convertible_v<_Kp &&, iterator>)
603 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(_Kp&& __key, _Args&&... __args) {
604 return __try_emplace(std::forward<_Kp>(__key), std::forward<_Args>(__args)...);
605 }
606
607 template <class... _Args>
608 requires is_constructible_v<mapped_type, _Args...>
609 _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator __hint, const key_type& __key, _Args&&... __args) {
610 return __try_emplace_hint(__hint, __key, std::forward<_Args>(__args)...).first;
611 }
612
613 template <class... _Args>
614 requires is_constructible_v<mapped_type, _Args...>
615 _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator __hint, key_type&& __key, _Args&&... __args) {
616 return __try_emplace_hint(__hint, std::move(__key), std::forward<_Args>(__args)...).first;
617 }
618
619 template <class _Kp, class... _Args>
620 requires __is_compare_transparent && is_constructible_v<key_type, _Kp> && is_constructible_v<mapped_type, _Args...>
621 _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator __hint, _Kp&& __key, _Args&&... __args) {
622 return __try_emplace_hint(__hint, std::forward<_Kp>(__key), std::forward<_Args>(__args)...).first;
623 }
624
625 template <class _Mapped>
626 requires is_assignable_v<mapped_type&, _Mapped> && is_constructible_v<mapped_type, _Mapped>
627 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert_or_assign(const key_type& __key, _Mapped&& __obj) {
628 return __insert_or_assign(__key, std::forward<_Mapped>(__obj));
629 }
630
631 template <class _Mapped>
632 requires is_assignable_v<mapped_type&, _Mapped> && is_constructible_v<mapped_type, _Mapped>
633 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert_or_assign(key_type&& __key, _Mapped&& __obj) {
634 return __insert_or_assign(std::move(__key), std::forward<_Mapped>(__obj));
635 }
636
637 template <class _Kp, class _Mapped>
638 requires __is_compare_transparent && is_constructible_v<key_type, _Kp> && is_assignable_v<mapped_type&, _Mapped> &&
639 is_constructible_v<mapped_type, _Mapped>
640 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert_or_assign(_Kp&& __key, _Mapped&& __obj) {
641 return __insert_or_assign(std::forward<_Kp>(__key), std::forward<_Mapped>(__obj));
642 }
643
644 template <class _Mapped>
645 requires is_assignable_v<mapped_type&, _Mapped> && is_constructible_v<mapped_type, _Mapped>
646 _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __hint, const key_type& __key, _Mapped&& __obj) {
647 return __insert_or_assign(__hint, __key, std::forward<_Mapped>(__obj));
648 }
649
650 template <class _Mapped>
651 requires is_assignable_v<mapped_type&, _Mapped> && is_constructible_v<mapped_type, _Mapped>
652 _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __hint, key_type&& __key, _Mapped&& __obj) {
653 return __insert_or_assign(__hint, std::move(__key), std::forward<_Mapped>(__obj));
654 }
655
656 template <class _Kp, class _Mapped>
657 requires __is_compare_transparent && is_constructible_v<key_type, _Kp> && is_assignable_v<mapped_type&, _Mapped> &&
658 is_constructible_v<mapped_type, _Mapped>
659 _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __hint, _Kp&& __key, _Mapped&& __obj) {
660 return __insert_or_assign(__hint, std::forward<_Kp>(__key), std::forward<_Mapped>(__obj));
661 }
662
663 _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __position) {
664 return __erase(__position.__key_iter_, __position.__mapped_iter_);
665 }
666
667 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position) {
668 return __erase(__position.__key_iter_, __position.__mapped_iter_);
669 }
670
671 _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __x) {
672 auto __iter = find(__x);
673 if (__iter != end()) {
674 erase(__iter);
675 return 1;
676 }
677 return 0;
678 }
679
680 template <class _Kp>
681 requires(__is_compare_transparent && !is_convertible_v<_Kp &&, iterator> &&
682 !is_convertible_v<_Kp &&, const_iterator>)
683 _LIBCPP_HIDE_FROM_ABI size_type erase(_Kp&& __x) {
684 auto [__first, __last] = equal_range(__x);
685 auto __res = __last - __first;
686 erase(__first, __last);
687 return __res;
688 }
689
690 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last) {
691 auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
692 auto __key_it = __containers_.keys.erase(__first.__key_iter_, __last.__key_iter_);
693 auto __mapped_it = __containers_.values.erase(__first.__mapped_iter_, __last.__mapped_iter_);
694 __on_failure.__complete();
695 return iterator(std::move(__key_it), std::move(__mapped_it));
696 }
697
698 _LIBCPP_HIDE_FROM_ABI void swap(flat_map& __y) noexcept {
699 // warning: The spec has unconditional noexcept, which means that
700 // if any of the following functions throw an exception,
701 // std::terminate will be called.
702 // This is discussed in P2767, which hasn't been voted on yet.
703 ranges::swap(__compare_, __y.__compare_);
704 ranges::swap(__containers_.keys, __y.__containers_.keys);
705 ranges::swap(__containers_.values, __y.__containers_.values);
706 }
707
708 _LIBCPP_HIDE_FROM_ABI void clear() noexcept {
709 __containers_.keys.clear();
710 __containers_.values.clear();
711 }
712
713 // observers
714 _LIBCPP_HIDE_FROM_ABI key_compare key_comp() const { return __compare_; }
715 _LIBCPP_HIDE_FROM_ABI value_compare value_comp() const { return value_compare(__compare_); }
716
717 _LIBCPP_HIDE_FROM_ABI const key_container_type& keys() const noexcept { return __containers_.keys; }
718 _LIBCPP_HIDE_FROM_ABI const mapped_container_type& values() const noexcept { return __containers_.values; }
719
720 // map operations
721 _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __x) { return __find_impl(*this, __x); }
722
723 _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __x) const { return __find_impl(*this, __x); }
724
725 template <class _Kp>
726 requires __is_compare_transparent
727 _LIBCPP_HIDE_FROM_ABI iterator find(const _Kp& __x) {
728 return __find_impl(*this, __x);
729 }
730
731 template <class _Kp>
732 requires __is_compare_transparent
733 _LIBCPP_HIDE_FROM_ABI const_iterator find(const _Kp& __x) const {
734 return __find_impl(*this, __x);
735 }
736
737 _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __x) const { return contains(__x) ? 1 : 0; }
738
739 template <class _Kp>
740 requires __is_compare_transparent
741 _LIBCPP_HIDE_FROM_ABI size_type count(const _Kp& __x) const {
742 return contains(__x) ? 1 : 0;
743 }
744
745 _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __x) const { return find(__x) != end(); }
746
747 template <class _Kp>
748 requires __is_compare_transparent
749 _LIBCPP_HIDE_FROM_ABI bool contains(const _Kp& __x) const {
750 return find(__x) != end();
751 }
752
753 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __x) { return __lower_bound<iterator>(*this, __x); }
754
755 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __x) const {
756 return __lower_bound<const_iterator>(*this, __x);
757 }
758
759 template <class _Kp>
760 requires __is_compare_transparent
761 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _Kp& __x) {
762 return __lower_bound<iterator>(*this, __x);
763 }
764
765 template <class _Kp>
766 requires __is_compare_transparent
767 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _Kp& __x) const {
768 return __lower_bound<const_iterator>(*this, __x);
769 }
770
771 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __x) { return __upper_bound<iterator>(*this, __x); }
772
773 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __x) const {
774 return __upper_bound<const_iterator>(*this, __x);
775 }
776
777 template <class _Kp>
778 requires __is_compare_transparent
779 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _Kp& __x) {
780 return __upper_bound<iterator>(*this, __x);
781 }
782
783 template <class _Kp>
784 requires __is_compare_transparent
785 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _Kp& __x) const {
786 return __upper_bound<const_iterator>(*this, __x);
787 }
788
789 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __x) {
790 return __equal_range_impl(*this, __x);
791 }
792
793 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __x) const {
794 return __equal_range_impl(*this, __x);
795 }
796
797 template <class _Kp>
798 requires __is_compare_transparent
799 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _Kp& __x) {
800 return __equal_range_impl(*this, __x);
801 }
802 template <class _Kp>
803 requires __is_compare_transparent
804 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _Kp& __x) const {
805 return __equal_range_impl(*this, __x);
806 }
807
808 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const flat_map& __x, const flat_map& __y) {
809 return ranges::equal(__x, __y);
810 }
811
812 friend _LIBCPP_HIDE_FROM_ABI auto operator<=>(const flat_map& __x, const flat_map& __y) {
813 return std::lexicographical_compare_three_way(
814 __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
815 }
816
817 friend _LIBCPP_HIDE_FROM_ABI void swap(flat_map& __x, flat_map& __y) noexcept { __x.swap(__y); }
818
819private:
820 struct __ctor_uses_allocator_tag {
821 explicit _LIBCPP_HIDE_FROM_ABI __ctor_uses_allocator_tag() = default;
822 };
823 struct __ctor_uses_allocator_empty_tag {
824 explicit _LIBCPP_HIDE_FROM_ABI __ctor_uses_allocator_empty_tag() = default;
825 };
826
827 template <class _Allocator, class _KeyCont, class _MappedCont, class... _CompArg>
828 requires __allocator_ctor_constraint<_Allocator>
829 _LIBCPP_HIDE_FROM_ABI
830 flat_map(__ctor_uses_allocator_tag,
831 const _Allocator& __alloc,
832 _KeyCont&& __key_cont,
833 _MappedCont&& __mapped_cont,
834 _CompArg&&... __comp)
835 : __containers_{.keys = std::make_obj_using_allocator<key_container_type>(
836 __alloc, std::forward<_KeyCont>(__key_cont)),
837 .values = std::make_obj_using_allocator<mapped_container_type>(
838 __alloc, std::forward<_MappedCont>(__mapped_cont))},
839 __compare_(std::forward<_CompArg>(__comp)...) {}
840
841 template <class _Allocator, class... _CompArg>
842 requires __allocator_ctor_constraint<_Allocator>
843 _LIBCPP_HIDE_FROM_ABI flat_map(__ctor_uses_allocator_empty_tag, const _Allocator& __alloc, _CompArg&&... __comp)
844 : __containers_{.keys = std::make_obj_using_allocator<key_container_type>(__alloc),
845 .values = std::make_obj_using_allocator<mapped_container_type>(__alloc)},
846 __compare_(std::forward<_CompArg>(__comp)...) {}
847
848 _LIBCPP_HIDE_FROM_ABI bool __is_sorted_and_unique(auto&& __key_container) const {
849 auto __greater_or_equal_to = [this](const auto& __x, const auto& __y) { return !__compare_(__x, __y); };
850 return ranges::adjacent_find(__key_container, __greater_or_equal_to) == ranges::end(__key_container);
851 }
852
853 // This function is only used in constructors. So there is not exception handling in this function.
854 // If the function exits via an exception, there will be no flat_map object constructed, thus, there
855 // is no invariant state to preserve
856 _LIBCPP_HIDE_FROM_ABI void __sort_and_unique() {
857 auto __zv = ranges::views::zip(__containers_.keys, __containers_.values);
858 ranges::sort(__zv, __compare_, [](const auto& __p) -> decltype(auto) { return std::get<0>(__p); });
859 auto __dup_start = ranges::unique(__zv, __key_equiv(__compare_)).begin();
860 auto __dist = ranges::distance(__zv.begin(), __dup_start);
861 __containers_.keys.erase(__containers_.keys.begin() + __dist, __containers_.keys.end());
862 __containers_.values.erase(__containers_.values.begin() + __dist, __containers_.values.end());
863 }
864
865 template <bool _WasSorted, class _InputIterator, class _Sentinel>
866 _LIBCPP_HIDE_FROM_ABI void __append_sort_merge_unique(_InputIterator __first, _Sentinel __last) {
867 auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
868 size_t __num_of_appended = __flat_map_utils::__append(*this, std::move(__first), std::move(__last));
869 if (__num_of_appended != 0) {
870 auto __zv = ranges::views::zip(__containers_.keys, __containers_.values);
871 auto __append_start_offset = __containers_.keys.size() - __num_of_appended;
872 auto __end = __zv.end();
873 auto __compare_key = [this](const auto& __p1, const auto& __p2) {
874 return __compare_(std::get<0>(__p1), std::get<0>(__p2));
875 };
876 if constexpr (!_WasSorted) {
877 ranges::sort(__zv.begin() + __append_start_offset, __end, __compare_key);
878 } else {
879 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
880 __is_sorted_and_unique(__containers_.keys | ranges::views::drop(__append_start_offset)),
881 "Either the key container is not sorted or it contains duplicates");
882 }
883 ranges::inplace_merge(__zv.begin(), __zv.begin() + __append_start_offset, __end, __compare_key);
884
885 auto __dup_start = ranges::unique(__zv, __key_equiv(__compare_)).begin();
886 auto __dist = ranges::distance(__zv.begin(), __dup_start);
887 __containers_.keys.erase(__containers_.keys.begin() + __dist, __containers_.keys.end());
888 __containers_.values.erase(__containers_.values.begin() + __dist, __containers_.values.end());
889 }
890 __on_failure.__complete();
891 }
892
893 template <class _Self, class _Kp>
894 _LIBCPP_HIDE_FROM_ABI static auto __find_impl(_Self&& __self, const _Kp& __key) {
895 auto __it = __self.lower_bound(__key);
896 auto __last = __self.end();
897 if (__it == __last || __self.__compare_(__key, __it->first)) {
898 return __last;
899 }
900 return __it;
901 }
902
903 template <class _Self, class _Kp>
904 _LIBCPP_HIDE_FROM_ABI static auto __key_equal_range(_Self&& __self, const _Kp& __key) {
905 auto __it = ranges::lower_bound(__self.__containers_.keys, __key, __self.__compare_);
906 auto __last = __self.__containers_.keys.end();
907 if (__it == __last || __self.__compare_(__key, *__it)) {
908 return std::make_pair(__it, __it);
909 }
910 return std::make_pair(__it, std::next(__it));
911 }
912
913 template <class _Self, class _Kp>
914 _LIBCPP_HIDE_FROM_ABI static auto __equal_range_impl(_Self&& __self, const _Kp& __key) {
915 auto [__key_first, __key_last] = __key_equal_range(__self, __key);
916
917 const auto __make_mapped_iter = [&](const auto& __key_iter) {
918 return __self.__containers_.values.begin() +
919 static_cast<ranges::range_difference_t<mapped_container_type>>(
920 ranges::distance(__self.__containers_.keys.begin(), __key_iter));
921 };
922
923 using __iterator_type = ranges::iterator_t<decltype(__self)>;
924 return std::make_pair(__iterator_type(__key_first, __make_mapped_iter(__key_first)),
925 __iterator_type(__key_last, __make_mapped_iter(__key_last)));
926 }
927
928 template <class _Res, class _Self, class _Kp>
929 _LIBCPP_HIDE_FROM_ABI static _Res __lower_bound(_Self&& __self, _Kp& __x) {
930 return __binary_search<_Res>(__self, ranges::lower_bound, __x);
931 }
932
933 template <class _Res, class _Self, class _Kp>
934 _LIBCPP_HIDE_FROM_ABI static _Res __upper_bound(_Self&& __self, _Kp& __x) {
935 return __binary_search<_Res>(__self, ranges::upper_bound, __x);
936 }
937
938 template <class _Res, class _Self, class _Fn, class _Kp>
939 _LIBCPP_HIDE_FROM_ABI static _Res __binary_search(_Self&& __self, _Fn __search_fn, _Kp& __x) {
940 auto __key_iter = __search_fn(__self.__containers_.keys, __x, __self.__compare_);
941 auto __mapped_iter =
942 __self.__containers_.values.begin() +
943 static_cast<ranges::range_difference_t<mapped_container_type>>(
944 ranges::distance(__self.__containers_.keys.begin(), __key_iter));
945
946 return _Res(std::move(__key_iter), std::move(__mapped_iter));
947 }
948
949 template <class _KeyArg, class... _MArgs>
950 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __try_emplace(_KeyArg&& __key, _MArgs&&... __mapped_args) {
951 auto __key_it = ranges::lower_bound(__containers_.keys, __key, __compare_);
952 auto __mapped_it = __containers_.values.begin() + ranges::distance(__containers_.keys.begin(), __key_it);
953
954 if (__key_it == __containers_.keys.end() || __compare_(__key, *__key_it)) {
955 return pair<iterator, bool>(
956 __flat_map_utils::__emplace_exact_pos(
957 *this,
958 std::move(__key_it),
959 std::move(__mapped_it),
960 std::forward<_KeyArg>(__key),
961 std::forward<_MArgs>(__mapped_args)...),
962 true);
963 } else {
964 return pair<iterator, bool>(iterator(std::move(__key_it), std::move(__mapped_it)), false);
965 }
966 }
967
968 template <class _Kp>
969 _LIBCPP_HIDE_FROM_ABI bool __is_hint_correct(const_iterator __hint, _Kp&& __key) {
970 if (__hint != cbegin() && !__compare_((__hint - 1)->first, __key)) {
971 return false;
972 }
973 if (__hint != cend() && __compare_(__hint->first, __key)) {
974 return false;
975 }
976 return true;
977 }
978
979 template <class _Kp, class... _Args>
980 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __try_emplace_hint(const_iterator __hint, _Kp&& __key, _Args&&... __args) {
981 if (__is_hint_correct(__hint, __key)) {
982 if (__hint == cend() || __compare_(__key, __hint->first)) {
983 return {__flat_map_utils::__emplace_exact_pos(
984 *this,
985 __hint.__key_iter_,
986 __hint.__mapped_iter_,
987 std::forward<_Kp>(__key),
988 std::forward<_Args>(__args)...),
989 true};
990 } else {
991 // key equals
992 auto __dist = __hint - cbegin();
993 return {iterator(__containers_.keys.begin() + __dist, __containers_.values.begin() + __dist), false};
994 }
995 } else {
996 return __try_emplace(std::forward<_Kp>(__key), std::forward<_Args>(__args)...);
997 }
998 }
999
1000 template <class _Kp, class _Mapped>
1001 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_or_assign(_Kp&& __key, _Mapped&& __mapped) {
1002 auto __r = try_emplace(std::forward<_Kp>(__key), std::forward<_Mapped>(__mapped));
1003 if (!__r.second) {
1004 __r.first->second = std::forward<_Mapped>(__mapped);
1005 }
1006 return __r;
1007 }
1008
1009 template <class _Kp, class _Mapped>
1010 _LIBCPP_HIDE_FROM_ABI iterator __insert_or_assign(const_iterator __hint, _Kp&& __key, _Mapped&& __mapped) {
1011 auto __r = __try_emplace_hint(__hint, std::forward<_Kp>(__key), std::forward<_Mapped>(__mapped));
1012 if (!__r.second) {
1013 __r.first->second = std::forward<_Mapped>(__mapped);
1014 }
1015 return __r.first;
1016 }
1017
1018 _LIBCPP_HIDE_FROM_ABI void __reserve(size_t __size) {
1019 if constexpr (requires { __containers_.keys.reserve(__size); }) {
1020 __containers_.keys.reserve(__size);
1021 }
1022
1023 if constexpr (requires { __containers_.values.reserve(__size); }) {
1024 __containers_.values.reserve(__size);
1025 }
1026 }
1027
1028 template <class _KIter, class _MIter>
1029 _LIBCPP_HIDE_FROM_ABI iterator __erase(_KIter __key_iter_to_remove, _MIter __mapped_iter_to_remove) {
1030 auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
1031 auto __key_iter = __containers_.keys.erase(__key_iter_to_remove);
1032 auto __mapped_iter = __containers_.values.erase(__mapped_iter_to_remove);
1033 __on_failure.__complete();
1034 return iterator(std::move(__key_iter), std::move(__mapped_iter));
1035 }
1036
1037 template <class _Key2, class _Tp2, class _Compare2, class _KeyContainer2, class _MappedContainer2, class _Predicate>
1038 friend typename flat_map<_Key2, _Tp2, _Compare2, _KeyContainer2, _MappedContainer2>::size_type
1039 erase_if(flat_map<_Key2, _Tp2, _Compare2, _KeyContainer2, _MappedContainer2>&, _Predicate);
1040
1041 friend __flat_map_utils;
1042
1043 containers __containers_;
1044 _LIBCPP_NO_UNIQUE_ADDRESS key_compare __compare_;
1045
1046 struct __key_equiv {
1047 _LIBCPP_HIDE_FROM_ABI __key_equiv(key_compare __c) : __comp_(__c) {}
1048 _LIBCPP_HIDE_FROM_ABI bool operator()(const_reference __x, const_reference __y) const {
1049 return !__comp_(std::get<0>(__x), std::get<0>(__y)) && !__comp_(std::get<0>(__y), std::get<0>(__x));
1050 }
1051 key_compare __comp_;
1052 };
1053};
1054
1055template <class _KeyContainer, class _MappedContainer, class _Compare = less<typename _KeyContainer::value_type>>
1056 requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value &&
1057 !__is_allocator<_MappedContainer>::value &&
1058 is_invocable_v<const _Compare&,
1059 const typename _KeyContainer::value_type&,
1060 const typename _KeyContainer::value_type&>)
1061flat_map(_KeyContainer, _MappedContainer, _Compare = _Compare())
1062 -> flat_map<typename _KeyContainer::value_type,
1063 typename _MappedContainer::value_type,
1064 _Compare,
1065 _KeyContainer,
1066 _MappedContainer>;
1067
1068template <class _KeyContainer, class _MappedContainer, class _Allocator>
1069 requires(uses_allocator_v<_KeyContainer, _Allocator> && uses_allocator_v<_MappedContainer, _Allocator> &&
1070 !__is_allocator<_KeyContainer>::value && !__is_allocator<_MappedContainer>::value)
1071flat_map(_KeyContainer, _MappedContainer, _Allocator)
1072 -> flat_map<typename _KeyContainer::value_type,
1073 typename _MappedContainer::value_type,
1074 less<typename _KeyContainer::value_type>,
1075 _KeyContainer,
1076 _MappedContainer>;
1077
1078template <class _KeyContainer, class _MappedContainer, class _Compare, class _Allocator>
1079 requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value &&
1080 !__is_allocator<_MappedContainer>::value && uses_allocator_v<_KeyContainer, _Allocator> &&
1081 uses_allocator_v<_MappedContainer, _Allocator> &&
1082 is_invocable_v<const _Compare&,
1083 const typename _KeyContainer::value_type&,
1084 const typename _KeyContainer::value_type&>)
1085flat_map(_KeyContainer, _MappedContainer, _Compare, _Allocator)
1086 -> flat_map<typename _KeyContainer::value_type,
1087 typename _MappedContainer::value_type,
1088 _Compare,
1089 _KeyContainer,
1090 _MappedContainer>;
1091
1092template <class _KeyContainer, class _MappedContainer, class _Compare = less<typename _KeyContainer::value_type>>
1093 requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value &&
1094 !__is_allocator<_MappedContainer>::value &&
1095 is_invocable_v<const _Compare&,
1096 const typename _KeyContainer::value_type&,
1097 const typename _KeyContainer::value_type&>)
1098flat_map(sorted_unique_t, _KeyContainer, _MappedContainer, _Compare = _Compare())
1099 -> flat_map<typename _KeyContainer::value_type,
1100 typename _MappedContainer::value_type,
1101 _Compare,
1102 _KeyContainer,
1103 _MappedContainer>;
1104
1105template <class _KeyContainer, class _MappedContainer, class _Allocator>
1106 requires(uses_allocator_v<_KeyContainer, _Allocator> && uses_allocator_v<_MappedContainer, _Allocator> &&
1107 !__is_allocator<_KeyContainer>::value && !__is_allocator<_MappedContainer>::value)
1108flat_map(sorted_unique_t, _KeyContainer, _MappedContainer, _Allocator)
1109 -> flat_map<typename _KeyContainer::value_type,
1110 typename _MappedContainer::value_type,
1111 less<typename _KeyContainer::value_type>,
1112 _KeyContainer,
1113 _MappedContainer>;
1114
1115template <class _KeyContainer, class _MappedContainer, class _Compare, class _Allocator>
1116 requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value &&
1117 !__is_allocator<_MappedContainer>::value && uses_allocator_v<_KeyContainer, _Allocator> &&
1118 uses_allocator_v<_MappedContainer, _Allocator> &&
1119 is_invocable_v<const _Compare&,
1120 const typename _KeyContainer::value_type&,
1121 const typename _KeyContainer::value_type&>)
1122flat_map(sorted_unique_t, _KeyContainer, _MappedContainer, _Compare, _Allocator)
1123 -> flat_map<typename _KeyContainer::value_type,
1124 typename _MappedContainer::value_type,
1125 _Compare,
1126 _KeyContainer,
1127 _MappedContainer>;
1128
1129template <class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>>
1130 requires(__has_input_iterator_category<_InputIterator>::value && !__is_allocator<_Compare>::value)
1131flat_map(_InputIterator, _InputIterator, _Compare = _Compare())
1132 -> flat_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare>;
1133
1134template <class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>>
1135 requires(__has_input_iterator_category<_InputIterator>::value && !__is_allocator<_Compare>::value)
1136flat_map(sorted_unique_t, _InputIterator, _InputIterator, _Compare = _Compare())
1137 -> flat_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare>;
1138
1139template <ranges::input_range _Range,
1140 class _Compare = less<__range_key_type<_Range>>,
1141 class _Allocator = allocator<byte>,
1142 class = __enable_if_t<!__is_allocator<_Compare>::value && __is_allocator<_Allocator>::value>>
1143flat_map(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator()) -> flat_map<
1144 __range_key_type<_Range>,
1145 __range_mapped_type<_Range>,
1146 _Compare,
1147 vector<__range_key_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_key_type<_Range>>>,
1148 vector<__range_mapped_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_mapped_type<_Range>>>>;
1149
1150template <ranges::input_range _Range, class _Allocator, class = __enable_if_t<__is_allocator<_Allocator>::value>>
1151flat_map(from_range_t, _Range&&, _Allocator) -> flat_map<
1152 __range_key_type<_Range>,
1153 __range_mapped_type<_Range>,
1154 less<__range_key_type<_Range>>,
1155 vector<__range_key_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_key_type<_Range>>>,
1156 vector<__range_mapped_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_mapped_type<_Range>>>>;
1157
1158template <class _Key, class _Tp, class _Compare = less<_Key>>
1159 requires(!__is_allocator<_Compare>::value)
1160flat_map(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare()) -> flat_map<_Key, _Tp, _Compare>;
1161
1162template <class _Key, class _Tp, class _Compare = less<_Key>>
1163 requires(!__is_allocator<_Compare>::value)
1164flat_map(sorted_unique_t, initializer_list<pair<_Key, _Tp>>, _Compare = _Compare()) -> flat_map<_Key, _Tp, _Compare>;
1165
1166template <class _Key, class _Tp, class _Compare, class _KeyContainer, class _MappedContainer, class _Allocator>
1167struct uses_allocator<flat_map<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>, _Allocator>
1168 : bool_constant<uses_allocator_v<_KeyContainer, _Allocator> && uses_allocator_v<_MappedContainer, _Allocator>> {};
1169
1170template <class _Key, class _Tp, class _Compare, class _KeyContainer, class _MappedContainer, class _Predicate>
1171_LIBCPP_HIDE_FROM_ABI typename flat_map<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>::size_type
1172erase_if(flat_map<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>& __flat_map, _Predicate __pred) {
1173 auto __zv = ranges::views::zip(__flat_map.__containers_.keys, __flat_map.__containers_.values);
1174 auto __first = __zv.begin();
1175 auto __last = __zv.end();
1176 auto __guard = std::__make_exception_guard([&] { __flat_map.clear(); });
1177 auto __it = std::remove_if(__first, __last, [&](auto&& __zipped) -> bool {
1178 using _Ref = typename flat_map<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>::const_reference;
1179 return __pred(_Ref(std::get<0>(__zipped), std::get<1>(__zipped)));
1180 });
1181 auto __res = __last - __it;
1182 auto __offset = __it - __first;
1183
1184 const auto __erase_container = [&](auto& __cont) { __cont.erase(__cont.begin() + __offset, __cont.end()); };
1185
1186 __erase_container(__flat_map.__containers_.keys);
1187 __erase_container(__flat_map.__containers_.values);
1188
1189 __guard.__complete();
1190 return __res;
1191}
1192
1193_LIBCPP_END_NAMESPACE_STD
1194
1195#endif // _LIBCPP_STD_VER >= 23
1196
1197_LIBCPP_POP_MACROS
1198
1199#endif // _LIBCPP___FLAT_MAP_FLAT_MAP_H
lib/libcxx/include/__flat_map/flat_multimap.h created+1010
......@@ -0,0 +1,1010 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___FLAT_MAP_FLAT_MULTIMAP_H
11#define _LIBCPP___FLAT_MAP_FLAT_MULTIMAP_H
12
13#include <__algorithm/lexicographical_compare_three_way.h>
14#include <__algorithm/min.h>
15#include <__algorithm/ranges_equal.h>
16#include <__algorithm/ranges_equal_range.h>
17#include <__algorithm/ranges_inplace_merge.h>
18#include <__algorithm/ranges_is_sorted.h>
19#include <__algorithm/ranges_lower_bound.h>
20#include <__algorithm/ranges_partition_point.h>
21#include <__algorithm/ranges_sort.h>
22#include <__algorithm/ranges_unique.h>
23#include <__algorithm/ranges_upper_bound.h>
24#include <__algorithm/remove_if.h>
25#include <__assert>
26#include <__compare/synth_three_way.h>
27#include <__concepts/convertible_to.h>
28#include <__concepts/swappable.h>
29#include <__config>
30#include <__cstddef/byte.h>
31#include <__cstddef/ptrdiff_t.h>
32#include <__flat_map/key_value_iterator.h>
33#include <__flat_map/sorted_equivalent.h>
34#include <__flat_map/utils.h>
35#include <__functional/invoke.h>
36#include <__functional/is_transparent.h>
37#include <__functional/operations.h>
38#include <__fwd/vector.h>
39#include <__iterator/concepts.h>
40#include <__iterator/distance.h>
41#include <__iterator/iterator_traits.h>
42#include <__iterator/ranges_iterator_traits.h>
43#include <__iterator/reverse_iterator.h>
44#include <__memory/allocator_traits.h>
45#include <__memory/uses_allocator.h>
46#include <__memory/uses_allocator_construction.h>
47#include <__ranges/access.h>
48#include <__ranges/concepts.h>
49#include <__ranges/container_compatible_range.h>
50#include <__ranges/drop_view.h>
51#include <__ranges/from_range.h>
52#include <__ranges/ref_view.h>
53#include <__ranges/size.h>
54#include <__ranges/subrange.h>
55#include <__ranges/zip_view.h>
56#include <__type_traits/conjunction.h>
57#include <__type_traits/container_traits.h>
58#include <__type_traits/invoke.h>
59#include <__type_traits/is_allocator.h>
60#include <__type_traits/is_nothrow_constructible.h>
61#include <__type_traits/is_same.h>
62#include <__type_traits/maybe_const.h>
63#include <__utility/exception_guard.h>
64#include <__utility/move.h>
65#include <__utility/pair.h>
66#include <__utility/scope_guard.h>
67#include <__vector/vector.h>
68#include <initializer_list>
69#include <stdexcept>
70
71#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
72# pragma GCC system_header
73#endif
74
75_LIBCPP_PUSH_MACROS
76#include <__undef_macros>
77
78#if _LIBCPP_STD_VER >= 23
79
80_LIBCPP_BEGIN_NAMESPACE_STD
81
82template <class _Key,
83 class _Tp,
84 class _Compare = less<_Key>,
85 class _KeyContainer = vector<_Key>,
86 class _MappedContainer = vector<_Tp>>
87class flat_multimap {
88 template <class, class, class, class, class>
89 friend class flat_multimap;
90
91 static_assert(is_same_v<_Key, typename _KeyContainer::value_type>);
92 static_assert(is_same_v<_Tp, typename _MappedContainer::value_type>);
93 static_assert(!is_same_v<_KeyContainer, std::vector<bool>>, "vector<bool> is not a sequence container");
94 static_assert(!is_same_v<_MappedContainer, std::vector<bool>>, "vector<bool> is not a sequence container");
95
96 template <bool _Const>
97 using __iterator _LIBCPP_NODEBUG = __key_value_iterator<flat_multimap, _KeyContainer, _MappedContainer, _Const>;
98
99public:
100 // types
101 using key_type = _Key;
102 using mapped_type = _Tp;
103 using value_type = pair<key_type, mapped_type>;
104 using key_compare = __type_identity_t<_Compare>;
105 using reference = pair<const key_type&, mapped_type&>;
106 using const_reference = pair<const key_type&, const mapped_type&>;
107 using size_type = size_t;
108 using difference_type = ptrdiff_t;
109 using iterator = __iterator<false>; // see [container.requirements]
110 using const_iterator = __iterator<true>; // see [container.requirements]
111 using reverse_iterator = std::reverse_iterator<iterator>;
112 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
113 using key_container_type = _KeyContainer;
114 using mapped_container_type = _MappedContainer;
115
116 class value_compare {
117 private:
118 key_compare __comp_;
119 _LIBCPP_HIDE_FROM_ABI value_compare(key_compare __c) : __comp_(__c) {}
120 friend flat_multimap;
121
122 public:
123 _LIBCPP_HIDE_FROM_ABI bool operator()(const_reference __x, const_reference __y) const {
124 return __comp_(__x.first, __y.first);
125 }
126 };
127
128 struct containers {
129 key_container_type keys;
130 mapped_container_type values;
131 };
132
133private:
134 template <class _Allocator>
135 _LIBCPP_HIDE_FROM_ABI static constexpr bool __allocator_ctor_constraint =
136 _And<uses_allocator<key_container_type, _Allocator>, uses_allocator<mapped_container_type, _Allocator>>::value;
137
138 _LIBCPP_HIDE_FROM_ABI static constexpr bool __is_compare_transparent = __is_transparent_v<_Compare>;
139
140public:
141 // [flat.map.cons], construct/copy/destroy
142 _LIBCPP_HIDE_FROM_ABI flat_multimap() noexcept(
143 is_nothrow_default_constructible_v<_KeyContainer> && is_nothrow_default_constructible_v<_MappedContainer> &&
144 is_nothrow_default_constructible_v<_Compare>)
145 : __containers_(), __compare_() {}
146
147 _LIBCPP_HIDE_FROM_ABI flat_multimap(const flat_multimap&) = default;
148
149 // The copy/move constructors are not specified in the spec, which means they should be defaulted.
150 // However, the move constructor can potentially leave a moved-from object in an inconsistent
151 // state if an exception is thrown.
152 _LIBCPP_HIDE_FROM_ABI flat_multimap(flat_multimap&& __other) noexcept(
153 is_nothrow_move_constructible_v<_KeyContainer> && is_nothrow_move_constructible_v<_MappedContainer> &&
154 is_nothrow_move_constructible_v<_Compare>)
155# if _LIBCPP_HAS_EXCEPTIONS
156 try
157# endif // _LIBCPP_HAS_EXCEPTIONS
158 : __containers_(std::move(__other.__containers_)), __compare_(std::move(__other.__compare_)) {
159 __other.clear();
160# if _LIBCPP_HAS_EXCEPTIONS
161 } catch (...) {
162 __other.clear();
163 // gcc does not like the `throw` keyword in a conditionally noexcept function
164 if constexpr (!(is_nothrow_move_constructible_v<_KeyContainer> &&
165 is_nothrow_move_constructible_v<_MappedContainer> && is_nothrow_move_constructible_v<_Compare>)) {
166 throw;
167 }
168# endif // _LIBCPP_HAS_EXCEPTIONS
169 }
170
171 template <class _Allocator>
172 requires __allocator_ctor_constraint<_Allocator>
173 _LIBCPP_HIDE_FROM_ABI flat_multimap(const flat_multimap& __other, const _Allocator& __alloc)
174 : flat_multimap(__ctor_uses_allocator_tag{},
175 __alloc,
176 __other.__containers_.keys,
177 __other.__containers_.values,
178 __other.__compare_) {}
179
180 template <class _Allocator>
181 requires __allocator_ctor_constraint<_Allocator>
182 _LIBCPP_HIDE_FROM_ABI flat_multimap(flat_multimap&& __other, const _Allocator& __alloc)
183# if _LIBCPP_HAS_EXCEPTIONS
184 try
185# endif // _LIBCPP_HAS_EXCEPTIONS
186 : flat_multimap(__ctor_uses_allocator_tag{},
187 __alloc,
188 std::move(__other.__containers_.keys),
189 std::move(__other.__containers_.values),
190 std::move(__other.__compare_)) {
191 __other.clear();
192# if _LIBCPP_HAS_EXCEPTIONS
193 } catch (...) {
194 __other.clear();
195 throw;
196# endif // _LIBCPP_HAS_EXCEPTIONS
197 }
198
199 _LIBCPP_HIDE_FROM_ABI flat_multimap(
200 key_container_type __key_cont, mapped_container_type __mapped_cont, const key_compare& __comp = key_compare())
201 : __containers_{.keys = std::move(__key_cont), .values = std::move(__mapped_cont)}, __compare_(__comp) {
202 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
203 "flat_multimap keys and mapped containers have different size");
204 __sort();
205 }
206
207 template <class _Allocator>
208 requires __allocator_ctor_constraint<_Allocator>
209 _LIBCPP_HIDE_FROM_ABI flat_multimap(
210 const key_container_type& __key_cont, const mapped_container_type& __mapped_cont, const _Allocator& __alloc)
211 : flat_multimap(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont) {
212 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
213 "flat_multimap keys and mapped containers have different size");
214 __sort();
215 }
216
217 template <class _Allocator>
218 requires __allocator_ctor_constraint<_Allocator>
219 _LIBCPP_HIDE_FROM_ABI
220 flat_multimap(const key_container_type& __key_cont,
221 const mapped_container_type& __mapped_cont,
222 const key_compare& __comp,
223 const _Allocator& __alloc)
224 : flat_multimap(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont, __comp) {
225 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
226 "flat_multimap keys and mapped containers have different size");
227 __sort();
228 }
229
230 _LIBCPP_HIDE_FROM_ABI
231 flat_multimap(sorted_equivalent_t,
232 key_container_type __key_cont,
233 mapped_container_type __mapped_cont,
234 const key_compare& __comp = key_compare())
235 : __containers_{.keys = std::move(__key_cont), .values = std::move(__mapped_cont)}, __compare_(__comp) {
236 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
237 "flat_multimap keys and mapped containers have different size");
238 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__is_sorted(__containers_.keys), "Key container is not sorted");
239 }
240
241 template <class _Allocator>
242 requires __allocator_ctor_constraint<_Allocator>
243 _LIBCPP_HIDE_FROM_ABI
244 flat_multimap(sorted_equivalent_t,
245 const key_container_type& __key_cont,
246 const mapped_container_type& __mapped_cont,
247 const _Allocator& __alloc)
248 : flat_multimap(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont) {
249 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
250 "flat_multimap keys and mapped containers have different size");
251 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__is_sorted(__containers_.keys), "Key container is not sorted");
252 }
253
254 template <class _Allocator>
255 requires __allocator_ctor_constraint<_Allocator>
256 _LIBCPP_HIDE_FROM_ABI
257 flat_multimap(sorted_equivalent_t,
258 const key_container_type& __key_cont,
259 const mapped_container_type& __mapped_cont,
260 const key_compare& __comp,
261 const _Allocator& __alloc)
262 : flat_multimap(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont, __comp) {
263 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
264 "flat_multimap keys and mapped containers have different size");
265 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__is_sorted(__containers_.keys), "Key container is not sorted");
266 }
267
268 _LIBCPP_HIDE_FROM_ABI explicit flat_multimap(const key_compare& __comp) : __containers_(), __compare_(__comp) {}
269
270 template <class _Allocator>
271 requires __allocator_ctor_constraint<_Allocator>
272 _LIBCPP_HIDE_FROM_ABI flat_multimap(const key_compare& __comp, const _Allocator& __alloc)
273 : flat_multimap(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {}
274
275 template <class _Allocator>
276 requires __allocator_ctor_constraint<_Allocator>
277 _LIBCPP_HIDE_FROM_ABI explicit flat_multimap(const _Allocator& __alloc)
278 : flat_multimap(__ctor_uses_allocator_empty_tag{}, __alloc) {}
279
280 template <class _InputIterator>
281 requires __has_input_iterator_category<_InputIterator>::value
282 _LIBCPP_HIDE_FROM_ABI
283 flat_multimap(_InputIterator __first, _InputIterator __last, const key_compare& __comp = key_compare())
284 : __containers_(), __compare_(__comp) {
285 insert(__first, __last);
286 }
287
288 template <class _InputIterator, class _Allocator>
289 requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>)
290 _LIBCPP_HIDE_FROM_ABI
291 flat_multimap(_InputIterator __first, _InputIterator __last, const key_compare& __comp, const _Allocator& __alloc)
292 : flat_multimap(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {
293 insert(__first, __last);
294 }
295
296 template <class _InputIterator, class _Allocator>
297 requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>)
298 _LIBCPP_HIDE_FROM_ABI flat_multimap(_InputIterator __first, _InputIterator __last, const _Allocator& __alloc)
299 : flat_multimap(__ctor_uses_allocator_empty_tag{}, __alloc) {
300 insert(__first, __last);
301 }
302
303 template <_ContainerCompatibleRange<value_type> _Range>
304 _LIBCPP_HIDE_FROM_ABI flat_multimap(from_range_t __fr, _Range&& __rg)
305 : flat_multimap(__fr, std::forward<_Range>(__rg), key_compare()) {}
306
307 template <_ContainerCompatibleRange<value_type> _Range, class _Allocator>
308 requires __allocator_ctor_constraint<_Allocator>
309 _LIBCPP_HIDE_FROM_ABI flat_multimap(from_range_t, _Range&& __rg, const _Allocator& __alloc)
310 : flat_multimap(__ctor_uses_allocator_empty_tag{}, __alloc) {
311 insert_range(std::forward<_Range>(__rg));
312 }
313
314 template <_ContainerCompatibleRange<value_type> _Range>
315 _LIBCPP_HIDE_FROM_ABI flat_multimap(from_range_t, _Range&& __rg, const key_compare& __comp) : flat_multimap(__comp) {
316 insert_range(std::forward<_Range>(__rg));
317 }
318
319 template <_ContainerCompatibleRange<value_type> _Range, class _Allocator>
320 requires __allocator_ctor_constraint<_Allocator>
321 _LIBCPP_HIDE_FROM_ABI flat_multimap(from_range_t, _Range&& __rg, const key_compare& __comp, const _Allocator& __alloc)
322 : flat_multimap(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {
323 insert_range(std::forward<_Range>(__rg));
324 }
325
326 template <class _InputIterator>
327 requires __has_input_iterator_category<_InputIterator>::value
328 _LIBCPP_HIDE_FROM_ABI flat_multimap(
329 sorted_equivalent_t, _InputIterator __first, _InputIterator __last, const key_compare& __comp = key_compare())
330 : __containers_(), __compare_(__comp) {
331 insert(sorted_equivalent, __first, __last);
332 }
333 template <class _InputIterator, class _Allocator>
334 requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>)
335 _LIBCPP_HIDE_FROM_ABI
336 flat_multimap(sorted_equivalent_t,
337 _InputIterator __first,
338 _InputIterator __last,
339 const key_compare& __comp,
340 const _Allocator& __alloc)
341 : flat_multimap(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {
342 insert(sorted_equivalent, __first, __last);
343 }
344
345 template <class _InputIterator, class _Allocator>
346 requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>)
347 _LIBCPP_HIDE_FROM_ABI
348 flat_multimap(sorted_equivalent_t, _InputIterator __first, _InputIterator __last, const _Allocator& __alloc)
349 : flat_multimap(__ctor_uses_allocator_empty_tag{}, __alloc) {
350 insert(sorted_equivalent, __first, __last);
351 }
352
353 _LIBCPP_HIDE_FROM_ABI flat_multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
354 : flat_multimap(__il.begin(), __il.end(), __comp) {}
355
356 template <class _Allocator>
357 requires __allocator_ctor_constraint<_Allocator>
358 _LIBCPP_HIDE_FROM_ABI
359 flat_multimap(initializer_list<value_type> __il, const key_compare& __comp, const _Allocator& __alloc)
360 : flat_multimap(__il.begin(), __il.end(), __comp, __alloc) {}
361
362 template <class _Allocator>
363 requires __allocator_ctor_constraint<_Allocator>
364 _LIBCPP_HIDE_FROM_ABI flat_multimap(initializer_list<value_type> __il, const _Allocator& __alloc)
365 : flat_multimap(__il.begin(), __il.end(), __alloc) {}
366
367 _LIBCPP_HIDE_FROM_ABI
368 flat_multimap(sorted_equivalent_t, initializer_list<value_type> __il, const key_compare& __comp = key_compare())
369 : flat_multimap(sorted_equivalent, __il.begin(), __il.end(), __comp) {}
370
371 template <class _Allocator>
372 requires __allocator_ctor_constraint<_Allocator>
373 _LIBCPP_HIDE_FROM_ABI flat_multimap(
374 sorted_equivalent_t, initializer_list<value_type> __il, const key_compare& __comp, const _Allocator& __alloc)
375 : flat_multimap(sorted_equivalent, __il.begin(), __il.end(), __comp, __alloc) {}
376
377 template <class _Allocator>
378 requires __allocator_ctor_constraint<_Allocator>
379 _LIBCPP_HIDE_FROM_ABI flat_multimap(sorted_equivalent_t, initializer_list<value_type> __il, const _Allocator& __alloc)
380 : flat_multimap(sorted_equivalent, __il.begin(), __il.end(), __alloc) {}
381
382 _LIBCPP_HIDE_FROM_ABI flat_multimap& operator=(initializer_list<value_type> __il) {
383 clear();
384 insert(__il);
385 return *this;
386 }
387
388 // copy/move assignment are not specified in the spec (defaulted)
389 // but move assignment can potentially leave moved from object in an inconsistent
390 // state if an exception is thrown
391 _LIBCPP_HIDE_FROM_ABI flat_multimap& operator=(const flat_multimap&) = default;
392
393 _LIBCPP_HIDE_FROM_ABI flat_multimap& operator=(flat_multimap&& __other) noexcept(
394 is_nothrow_move_assignable_v<_KeyContainer> && is_nothrow_move_assignable_v<_MappedContainer> &&
395 is_nothrow_move_assignable_v<_Compare>) {
396 auto __clear_other_guard = std::__make_scope_guard([&]() noexcept { __other.clear() /* noexcept */; });
397 auto __clear_self_guard = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
398 __containers_ = std::move(__other.__containers_);
399 __compare_ = std::move(__other.__compare_);
400 __clear_self_guard.__complete();
401 return *this;
402 }
403
404 // iterators
405 _LIBCPP_HIDE_FROM_ABI iterator begin() noexcept {
406 return iterator(__containers_.keys.begin(), __containers_.values.begin());
407 }
408
409 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const noexcept {
410 return const_iterator(__containers_.keys.begin(), __containers_.values.begin());
411 }
412
413 _LIBCPP_HIDE_FROM_ABI iterator end() noexcept {
414 return iterator(__containers_.keys.end(), __containers_.values.end());
415 }
416
417 _LIBCPP_HIDE_FROM_ABI const_iterator end() const noexcept {
418 return const_iterator(__containers_.keys.end(), __containers_.values.end());
419 }
420
421 _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() noexcept { return reverse_iterator(end()); }
422 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); }
423 _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() noexcept { return reverse_iterator(begin()); }
424 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); }
425
426 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const noexcept { return begin(); }
427 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const noexcept { return end(); }
428 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); }
429 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); }
430
431 // [flat.map.capacity], capacity
432 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool empty() const noexcept { return __containers_.keys.empty(); }
433
434 _LIBCPP_HIDE_FROM_ABI size_type size() const noexcept { return __containers_.keys.size(); }
435
436 _LIBCPP_HIDE_FROM_ABI size_type max_size() const noexcept {
437 return std::min<size_type>(__containers_.keys.max_size(), __containers_.values.max_size());
438 }
439
440 // [flat.map.modifiers], modifiers
441 template <class... _Args>
442 requires is_constructible_v<pair<key_type, mapped_type>, _Args...> && is_move_constructible_v<key_type> &&
443 is_move_constructible_v<mapped_type>
444 _LIBCPP_HIDE_FROM_ABI iterator emplace(_Args&&... __args) {
445 std::pair<key_type, mapped_type> __pair(std::forward<_Args>(__args)...);
446 auto __key_it = ranges::upper_bound(__containers_.keys, __pair.first, __compare_);
447 auto __mapped_it = __corresponding_mapped_it(*this, __key_it);
448
449 return __flat_map_utils::__emplace_exact_pos(
450 *this, std::move(__key_it), std::move(__mapped_it), std::move(__pair.first), std::move(__pair.second));
451 }
452
453 template <class... _Args>
454 requires is_constructible_v<pair<key_type, mapped_type>, _Args...>
455 _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __hint, _Args&&... __args) {
456 std::pair<key_type, mapped_type> __pair(std::forward<_Args>(__args)...);
457
458 auto __prev_larger = __hint != cbegin() && __compare_(__pair.first, (__hint - 1)->first);
459 auto __next_smaller = __hint != cend() && __compare_(__hint->first, __pair.first);
460
461 auto __hint_distance = __hint.__key_iter_ - __containers_.keys.cbegin();
462 auto __key_iter = __containers_.keys.begin() + __hint_distance;
463 auto __mapped_iter = __containers_.values.begin() + __hint_distance;
464
465 if (!__prev_larger && !__next_smaller) [[likely]] {
466 // hint correct, just use exact hint iterators
467 } else if (__prev_larger && !__next_smaller) {
468 // the hint position is more to the right than the key should have been.
469 // we want to emplace the element to a position as right as possible
470 // e.g. Insert new element "2" in the following range
471 // 1, 1, 2, 2, 2, 3, 4, 6
472 // ^
473 // |
474 // hint
475 // We want to insert "2" after the last existing "2"
476 __key_iter = ranges::upper_bound(__containers_.keys.begin(), __key_iter, __pair.first, __compare_);
477 __mapped_iter = __corresponding_mapped_it(*this, __key_iter);
478 } else {
479 _LIBCPP_ASSERT_INTERNAL(!__prev_larger && __next_smaller, "this means that the multimap is not sorted");
480
481 // the hint position is more to the left than the key should have been.
482 // we want to emplace the element to a position as left as possible
483 // 1, 1, 2, 2, 2, 3, 4, 6
484 // ^
485 // |
486 // hint
487 // We want to insert "2" before the first existing "2"
488 __key_iter = ranges::lower_bound(__key_iter, __containers_.keys.end(), __pair.first, __compare_);
489 __mapped_iter = __corresponding_mapped_it(*this, __key_iter);
490 }
491 return __flat_map_utils::__emplace_exact_pos(
492 *this, __key_iter, __mapped_iter, std::move(__pair.first), std::move(__pair.second));
493 }
494
495 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return emplace(__x); }
496
497 _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __x) { return emplace(std::move(__x)); }
498
499 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, const value_type& __x) {
500 return emplace_hint(__hint, __x);
501 }
502
503 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, value_type&& __x) {
504 return emplace_hint(__hint, std::move(__x));
505 }
506
507 template <class _PairLike>
508 requires is_constructible_v<pair<key_type, mapped_type>, _PairLike>
509 _LIBCPP_HIDE_FROM_ABI iterator insert(_PairLike&& __x) {
510 return emplace(std::forward<_PairLike>(__x));
511 }
512
513 template <class _PairLike>
514 requires is_constructible_v<pair<key_type, mapped_type>, _PairLike>
515 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, _PairLike&& __x) {
516 return emplace_hint(__hint, std::forward<_PairLike>(__x));
517 }
518
519 template <class _InputIterator>
520 requires __has_input_iterator_category<_InputIterator>::value
521 _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last) {
522 if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>) {
523 __reserve(__last - __first);
524 }
525 __append_sort_merge</*WasSorted = */ false>(std::move(__first), std::move(__last));
526 }
527
528 template <class _InputIterator>
529 requires __has_input_iterator_category<_InputIterator>::value
530 _LIBCPP_HIDE_FROM_ABI void insert(sorted_equivalent_t, _InputIterator __first, _InputIterator __last) {
531 if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>) {
532 __reserve(__last - __first);
533 }
534
535 __append_sort_merge</*WasSorted = */ true>(std::move(__first), std::move(__last));
536 }
537
538 template <_ContainerCompatibleRange<value_type> _Range>
539 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
540 if constexpr (ranges::sized_range<_Range>) {
541 __reserve(ranges::size(__range));
542 }
543
544 __append_sort_merge</*WasSorted = */ false>(ranges::begin(__range), ranges::end(__range));
545 }
546
547 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
548
549 _LIBCPP_HIDE_FROM_ABI void insert(sorted_equivalent_t, initializer_list<value_type> __il) {
550 insert(sorted_equivalent, __il.begin(), __il.end());
551 }
552
553 _LIBCPP_HIDE_FROM_ABI containers extract() && {
554 auto __guard = std::__make_scope_guard([&]() noexcept { clear() /* noexcept */; });
555 auto __ret = std::move(__containers_);
556 return __ret;
557 }
558
559 _LIBCPP_HIDE_FROM_ABI void replace(key_container_type&& __key_cont, mapped_container_type&& __mapped_cont) {
560 _LIBCPP_ASSERT_VALID_INPUT_RANGE(
561 __key_cont.size() == __mapped_cont.size(), "flat_multimap keys and mapped containers have different size");
562
563 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__is_sorted(__key_cont), "Key container is not sorted");
564 auto __guard = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
565 __containers_.keys = std::move(__key_cont);
566 __containers_.values = std::move(__mapped_cont);
567 __guard.__complete();
568 }
569
570 _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __position) {
571 return __erase(__position.__key_iter_, __position.__mapped_iter_);
572 }
573
574 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position) {
575 return __erase(__position.__key_iter_, __position.__mapped_iter_);
576 }
577
578 _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __x) {
579 auto [__first, __last] = equal_range(__x);
580 auto __res = __last - __first;
581 erase(__first, __last);
582 return __res;
583 }
584
585 template <class _Kp>
586 requires(__is_compare_transparent && !is_convertible_v<_Kp &&, iterator> &&
587 !is_convertible_v<_Kp &&, const_iterator>)
588 _LIBCPP_HIDE_FROM_ABI size_type erase(_Kp&& __x) {
589 auto [__first, __last] = equal_range(__x);
590 auto __res = __last - __first;
591 erase(__first, __last);
592 return __res;
593 }
594
595 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last) {
596 auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
597 auto __key_it = __containers_.keys.erase(__first.__key_iter_, __last.__key_iter_);
598 auto __mapped_it = __containers_.values.erase(__first.__mapped_iter_, __last.__mapped_iter_);
599 __on_failure.__complete();
600 return iterator(std::move(__key_it), std::move(__mapped_it));
601 }
602
603 _LIBCPP_HIDE_FROM_ABI void swap(flat_multimap& __y) noexcept {
604 // warning: The spec has unconditional noexcept, which means that
605 // if any of the following functions throw an exception,
606 // std::terminate will be called
607 ranges::swap(__compare_, __y.__compare_);
608 ranges::swap(__containers_.keys, __y.__containers_.keys);
609 ranges::swap(__containers_.values, __y.__containers_.values);
610 }
611
612 _LIBCPP_HIDE_FROM_ABI void clear() noexcept {
613 __containers_.keys.clear();
614 __containers_.values.clear();
615 }
616
617 // observers
618 _LIBCPP_HIDE_FROM_ABI key_compare key_comp() const { return __compare_; }
619 _LIBCPP_HIDE_FROM_ABI value_compare value_comp() const { return value_compare(__compare_); }
620
621 _LIBCPP_HIDE_FROM_ABI const key_container_type& keys() const noexcept { return __containers_.keys; }
622 _LIBCPP_HIDE_FROM_ABI const mapped_container_type& values() const noexcept { return __containers_.values; }
623
624 // map operations
625 _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __x) { return __find_impl(*this, __x); }
626
627 _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __x) const { return __find_impl(*this, __x); }
628
629 template <class _Kp>
630 requires __is_compare_transparent
631 _LIBCPP_HIDE_FROM_ABI iterator find(const _Kp& __x) {
632 return __find_impl(*this, __x);
633 }
634
635 template <class _Kp>
636 requires __is_compare_transparent
637 _LIBCPP_HIDE_FROM_ABI const_iterator find(const _Kp& __x) const {
638 return __find_impl(*this, __x);
639 }
640
641 _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __x) const {
642 auto [__first, __last] = equal_range(__x);
643 return __last - __first;
644 }
645
646 template <class _Kp>
647 requires __is_compare_transparent
648 _LIBCPP_HIDE_FROM_ABI size_type count(const _Kp& __x) const {
649 auto [__first, __last] = equal_range(__x);
650 return __last - __first;
651 }
652
653 _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __x) const { return find(__x) != end(); }
654
655 template <class _Kp>
656 requires __is_compare_transparent
657 _LIBCPP_HIDE_FROM_ABI bool contains(const _Kp& __x) const {
658 return find(__x) != end();
659 }
660
661 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __x) { return __lower_bound<iterator>(*this, __x); }
662
663 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __x) const {
664 return __lower_bound<const_iterator>(*this, __x);
665 }
666
667 template <class _Kp>
668 requires __is_compare_transparent
669 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _Kp& __x) {
670 return __lower_bound<iterator>(*this, __x);
671 }
672
673 template <class _Kp>
674 requires __is_compare_transparent
675 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _Kp& __x) const {
676 return __lower_bound<const_iterator>(*this, __x);
677 }
678
679 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __x) { return __upper_bound<iterator>(*this, __x); }
680
681 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __x) const {
682 return __upper_bound<const_iterator>(*this, __x);
683 }
684
685 template <class _Kp>
686 requires __is_compare_transparent
687 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _Kp& __x) {
688 return __upper_bound<iterator>(*this, __x);
689 }
690
691 template <class _Kp>
692 requires __is_compare_transparent
693 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _Kp& __x) const {
694 return __upper_bound<const_iterator>(*this, __x);
695 }
696
697 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __x) {
698 return __equal_range_impl(*this, __x);
699 }
700
701 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __x) const {
702 return __equal_range_impl(*this, __x);
703 }
704
705 template <class _Kp>
706 requires __is_compare_transparent
707 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _Kp& __x) {
708 return __equal_range_impl(*this, __x);
709 }
710 template <class _Kp>
711 requires __is_compare_transparent
712 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _Kp& __x) const {
713 return __equal_range_impl(*this, __x);
714 }
715
716 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const flat_multimap& __x, const flat_multimap& __y) {
717 return ranges::equal(__x, __y);
718 }
719
720 friend _LIBCPP_HIDE_FROM_ABI auto operator<=>(const flat_multimap& __x, const flat_multimap& __y) {
721 return std::lexicographical_compare_three_way(
722 __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
723 }
724
725 friend _LIBCPP_HIDE_FROM_ABI void swap(flat_multimap& __x, flat_multimap& __y) noexcept { __x.swap(__y); }
726
727private:
728 struct __ctor_uses_allocator_tag {
729 explicit _LIBCPP_HIDE_FROM_ABI __ctor_uses_allocator_tag() = default;
730 };
731 struct __ctor_uses_allocator_empty_tag {
732 explicit _LIBCPP_HIDE_FROM_ABI __ctor_uses_allocator_empty_tag() = default;
733 };
734
735 template <class _Allocator, class _KeyCont, class _MappedCont, class... _CompArg>
736 requires __allocator_ctor_constraint<_Allocator>
737 _LIBCPP_HIDE_FROM_ABI
738 flat_multimap(__ctor_uses_allocator_tag,
739 const _Allocator& __alloc,
740 _KeyCont&& __key_cont,
741 _MappedCont&& __mapped_cont,
742 _CompArg&&... __comp)
743 : __containers_{.keys = std::make_obj_using_allocator<key_container_type>(
744 __alloc, std::forward<_KeyCont>(__key_cont)),
745 .values = std::make_obj_using_allocator<mapped_container_type>(
746 __alloc, std::forward<_MappedCont>(__mapped_cont))},
747 __compare_(std::forward<_CompArg>(__comp)...) {}
748
749 template <class _Allocator, class... _CompArg>
750 requires __allocator_ctor_constraint<_Allocator>
751 _LIBCPP_HIDE_FROM_ABI flat_multimap(__ctor_uses_allocator_empty_tag, const _Allocator& __alloc, _CompArg&&... __comp)
752 : __containers_{.keys = std::make_obj_using_allocator<key_container_type>(__alloc),
753 .values = std::make_obj_using_allocator<mapped_container_type>(__alloc)},
754 __compare_(std::forward<_CompArg>(__comp)...) {}
755
756 _LIBCPP_HIDE_FROM_ABI bool __is_sorted(auto&& __key_container) const {
757 return ranges::is_sorted(__key_container, __compare_);
758 }
759
760 _LIBCPP_HIDE_FROM_ABI void __sort() {
761 auto __zv = ranges::views::zip(__containers_.keys, __containers_.values);
762 ranges::sort(__zv, __compare_, [](const auto& __p) -> decltype(auto) { return std::get<0>(__p); });
763 }
764
765 template <class _Self, class _KeyIter>
766 _LIBCPP_HIDE_FROM_ABI static auto __corresponding_mapped_it(_Self&& __self, _KeyIter&& __key_iter) {
767 return __self.__containers_.values.begin() +
768 static_cast<ranges::range_difference_t<mapped_container_type>>(
769 ranges::distance(__self.__containers_.keys.begin(), __key_iter));
770 }
771
772 template <bool _WasSorted, class _InputIterator, class _Sentinel>
773 _LIBCPP_HIDE_FROM_ABI void __append_sort_merge(_InputIterator __first, _Sentinel __last) {
774 auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
775 size_t __num_appended = __flat_map_utils::__append(*this, std::move(__first), std::move(__last));
776 if (__num_appended != 0) {
777 auto __zv = ranges::views::zip(__containers_.keys, __containers_.values);
778 auto __append_start_offset = __containers_.keys.size() - __num_appended;
779 auto __end = __zv.end();
780 auto __compare_key = [this](const auto& __p1, const auto& __p2) {
781 return __compare_(std::get<0>(__p1), std::get<0>(__p2));
782 };
783 if constexpr (!_WasSorted) {
784 ranges::sort(__zv.begin() + __append_start_offset, __end, __compare_key);
785 } else {
786 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
787 __is_sorted(__containers_.keys | ranges::views::drop(__append_start_offset)),
788 "Key container is not sorted");
789 }
790 ranges::inplace_merge(__zv.begin(), __zv.begin() + __append_start_offset, __end, __compare_key);
791 }
792 __on_failure.__complete();
793 }
794
795 template <class _Self, class _Kp>
796 _LIBCPP_HIDE_FROM_ABI static auto __find_impl(_Self&& __self, const _Kp& __key) {
797 auto __it = __self.lower_bound(__key);
798 auto __last = __self.end();
799 if (__it == __last || __self.__compare_(__key, __it->first)) {
800 return __last;
801 }
802 return __it;
803 }
804
805 template <class _Self, class _Kp>
806 _LIBCPP_HIDE_FROM_ABI static auto __equal_range_impl(_Self&& __self, const _Kp& __key) {
807 auto [__key_first, __key_last] = ranges::equal_range(__self.__containers_.keys, __key, __self.__compare_);
808
809 using __iterator_type = ranges::iterator_t<decltype(__self)>;
810 return std::make_pair(__iterator_type(__key_first, __corresponding_mapped_it(__self, __key_first)),
811 __iterator_type(__key_last, __corresponding_mapped_it(__self, __key_last)));
812 }
813
814 template <class _Res, class _Self, class _Kp>
815 _LIBCPP_HIDE_FROM_ABI static _Res __lower_bound(_Self&& __self, _Kp& __x) {
816 auto __key_iter = ranges::lower_bound(__self.__containers_.keys, __x, __self.__compare_);
817 auto __mapped_iter = __corresponding_mapped_it(__self, __key_iter);
818 return _Res(std::move(__key_iter), std::move(__mapped_iter));
819 }
820
821 template <class _Res, class _Self, class _Kp>
822 _LIBCPP_HIDE_FROM_ABI static _Res __upper_bound(_Self&& __self, _Kp& __x) {
823 auto __key_iter = ranges::upper_bound(__self.__containers_.keys, __x, __self.__compare_);
824 auto __mapped_iter = __corresponding_mapped_it(__self, __key_iter);
825 return _Res(std::move(__key_iter), std::move(__mapped_iter));
826 }
827
828 _LIBCPP_HIDE_FROM_ABI void __reserve(size_t __size) {
829 if constexpr (requires { __containers_.keys.reserve(__size); }) {
830 __containers_.keys.reserve(__size);
831 }
832
833 if constexpr (requires { __containers_.values.reserve(__size); }) {
834 __containers_.values.reserve(__size);
835 }
836 }
837
838 template <class _KIter, class _MIter>
839 _LIBCPP_HIDE_FROM_ABI iterator __erase(_KIter __key_iter_to_remove, _MIter __mapped_iter_to_remove) {
840 auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
841 auto __key_iter = __containers_.keys.erase(__key_iter_to_remove);
842 auto __mapped_iter = __containers_.values.erase(__mapped_iter_to_remove);
843 __on_failure.__complete();
844 return iterator(std::move(__key_iter), std::move(__mapped_iter));
845 }
846
847 template <class _Key2, class _Tp2, class _Compare2, class _KeyContainer2, class _MappedContainer2, class _Predicate>
848 friend typename flat_multimap<_Key2, _Tp2, _Compare2, _KeyContainer2, _MappedContainer2>::size_type
849 erase_if(flat_multimap<_Key2, _Tp2, _Compare2, _KeyContainer2, _MappedContainer2>&, _Predicate);
850
851 friend __flat_map_utils;
852
853 containers __containers_;
854 _LIBCPP_NO_UNIQUE_ADDRESS key_compare __compare_;
855
856 struct __key_equiv {
857 _LIBCPP_HIDE_FROM_ABI __key_equiv(key_compare __c) : __comp_(__c) {}
858 _LIBCPP_HIDE_FROM_ABI bool operator()(const_reference __x, const_reference __y) const {
859 return !__comp_(std::get<0>(__x), std::get<0>(__y)) && !__comp_(std::get<0>(__y), std::get<0>(__x));
860 }
861 key_compare __comp_;
862 };
863};
864
865template <class _KeyContainer, class _MappedContainer, class _Compare = less<typename _KeyContainer::value_type>>
866 requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value &&
867 !__is_allocator<_MappedContainer>::value &&
868 is_invocable_v<const _Compare&,
869 const typename _KeyContainer::value_type&,
870 const typename _KeyContainer::value_type&>)
871flat_multimap(_KeyContainer, _MappedContainer, _Compare = _Compare())
872 -> flat_multimap<typename _KeyContainer::value_type,
873 typename _MappedContainer::value_type,
874 _Compare,
875 _KeyContainer,
876 _MappedContainer>;
877
878template <class _KeyContainer, class _MappedContainer, class _Allocator>
879 requires(uses_allocator_v<_KeyContainer, _Allocator> && uses_allocator_v<_MappedContainer, _Allocator> &&
880 !__is_allocator<_KeyContainer>::value && !__is_allocator<_MappedContainer>::value)
881flat_multimap(_KeyContainer, _MappedContainer, _Allocator)
882 -> flat_multimap<typename _KeyContainer::value_type,
883 typename _MappedContainer::value_type,
884 less<typename _KeyContainer::value_type>,
885 _KeyContainer,
886 _MappedContainer>;
887
888template <class _KeyContainer, class _MappedContainer, class _Compare, class _Allocator>
889 requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value &&
890 !__is_allocator<_MappedContainer>::value && uses_allocator_v<_KeyContainer, _Allocator> &&
891 uses_allocator_v<_MappedContainer, _Allocator> &&
892 is_invocable_v<const _Compare&,
893 const typename _KeyContainer::value_type&,
894 const typename _KeyContainer::value_type&>)
895flat_multimap(_KeyContainer, _MappedContainer, _Compare, _Allocator)
896 -> flat_multimap<typename _KeyContainer::value_type,
897 typename _MappedContainer::value_type,
898 _Compare,
899 _KeyContainer,
900 _MappedContainer>;
901
902template <class _KeyContainer, class _MappedContainer, class _Compare = less<typename _KeyContainer::value_type>>
903 requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value &&
904 !__is_allocator<_MappedContainer>::value &&
905 is_invocable_v<const _Compare&,
906 const typename _KeyContainer::value_type&,
907 const typename _KeyContainer::value_type&>)
908flat_multimap(sorted_equivalent_t, _KeyContainer, _MappedContainer, _Compare = _Compare())
909 -> flat_multimap<typename _KeyContainer::value_type,
910 typename _MappedContainer::value_type,
911 _Compare,
912 _KeyContainer,
913 _MappedContainer>;
914
915template <class _KeyContainer, class _MappedContainer, class _Allocator>
916 requires(uses_allocator_v<_KeyContainer, _Allocator> && uses_allocator_v<_MappedContainer, _Allocator> &&
917 !__is_allocator<_KeyContainer>::value && !__is_allocator<_MappedContainer>::value)
918flat_multimap(sorted_equivalent_t, _KeyContainer, _MappedContainer, _Allocator)
919 -> flat_multimap<typename _KeyContainer::value_type,
920 typename _MappedContainer::value_type,
921 less<typename _KeyContainer::value_type>,
922 _KeyContainer,
923 _MappedContainer>;
924
925template <class _KeyContainer, class _MappedContainer, class _Compare, class _Allocator>
926 requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value &&
927 !__is_allocator<_MappedContainer>::value && uses_allocator_v<_KeyContainer, _Allocator> &&
928 uses_allocator_v<_MappedContainer, _Allocator> &&
929 is_invocable_v<const _Compare&,
930 const typename _KeyContainer::value_type&,
931 const typename _KeyContainer::value_type&>)
932flat_multimap(sorted_equivalent_t, _KeyContainer, _MappedContainer, _Compare, _Allocator)
933 -> flat_multimap<typename _KeyContainer::value_type,
934 typename _MappedContainer::value_type,
935 _Compare,
936 _KeyContainer,
937 _MappedContainer>;
938
939template <class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>>
940 requires(__has_input_iterator_category<_InputIterator>::value && !__is_allocator<_Compare>::value)
941flat_multimap(_InputIterator, _InputIterator, _Compare = _Compare())
942 -> flat_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare>;
943
944template <class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>>
945 requires(__has_input_iterator_category<_InputIterator>::value && !__is_allocator<_Compare>::value)
946flat_multimap(sorted_equivalent_t, _InputIterator, _InputIterator, _Compare = _Compare())
947 -> flat_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare>;
948
949template <ranges::input_range _Range,
950 class _Compare = less<__range_key_type<_Range>>,
951 class _Allocator = allocator<byte>,
952 class = __enable_if_t<!__is_allocator<_Compare>::value && __is_allocator<_Allocator>::value>>
953flat_multimap(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator()) -> flat_multimap<
954 __range_key_type<_Range>,
955 __range_mapped_type<_Range>,
956 _Compare,
957 vector<__range_key_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_key_type<_Range>>>,
958 vector<__range_mapped_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_mapped_type<_Range>>>>;
959
960template <ranges::input_range _Range, class _Allocator, class = __enable_if_t<__is_allocator<_Allocator>::value>>
961flat_multimap(from_range_t, _Range&&, _Allocator) -> flat_multimap<
962 __range_key_type<_Range>,
963 __range_mapped_type<_Range>,
964 less<__range_key_type<_Range>>,
965 vector<__range_key_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_key_type<_Range>>>,
966 vector<__range_mapped_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_mapped_type<_Range>>>>;
967
968template <class _Key, class _Tp, class _Compare = less<_Key>>
969 requires(!__is_allocator<_Compare>::value)
970flat_multimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare()) -> flat_multimap<_Key, _Tp, _Compare>;
971
972template <class _Key, class _Tp, class _Compare = less<_Key>>
973 requires(!__is_allocator<_Compare>::value)
974flat_multimap(sorted_equivalent_t, initializer_list<pair<_Key, _Tp>>, _Compare = _Compare())
975 -> flat_multimap<_Key, _Tp, _Compare>;
976
977template <class _Key, class _Tp, class _Compare, class _KeyContainer, class _MappedContainer, class _Allocator>
978struct uses_allocator<flat_multimap<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>, _Allocator>
979 : bool_constant<uses_allocator_v<_KeyContainer, _Allocator> && uses_allocator_v<_MappedContainer, _Allocator>> {};
980
981template <class _Key, class _Tp, class _Compare, class _KeyContainer, class _MappedContainer, class _Predicate>
982_LIBCPP_HIDE_FROM_ABI typename flat_multimap<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>::size_type
983erase_if(flat_multimap<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>& __flat_multimap, _Predicate __pred) {
984 auto __zv = ranges::views::zip(__flat_multimap.__containers_.keys, __flat_multimap.__containers_.values);
985 auto __first = __zv.begin();
986 auto __last = __zv.end();
987 auto __guard = std::__make_exception_guard([&] { __flat_multimap.clear(); });
988 auto __it = std::remove_if(__first, __last, [&](auto&& __zipped) -> bool {
989 using _Ref = typename flat_multimap<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>::const_reference;
990 return __pred(_Ref(std::get<0>(__zipped), std::get<1>(__zipped)));
991 });
992 auto __res = __last - __it;
993 auto __offset = __it - __first;
994
995 const auto __erase_container = [&](auto& __cont) { __cont.erase(__cont.begin() + __offset, __cont.end()); };
996
997 __erase_container(__flat_multimap.__containers_.keys);
998 __erase_container(__flat_multimap.__containers_.values);
999
1000 __guard.__complete();
1001 return __res;
1002}
1003
1004_LIBCPP_END_NAMESPACE_STD
1005
1006#endif // _LIBCPP_STD_VER >= 23
1007
1008_LIBCPP_POP_MACROS
1009
1010#endif // _LIBCPP___FLAT_MAP_FLAT_MULTIMAP_H
lib/libcxx/include/__flat_map/key_value_iterator.h created+176
......@@ -0,0 +1,176 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___FLAT_MAP_KEY_VALUE_ITERATOR_H
11#define _LIBCPP___FLAT_MAP_KEY_VALUE_ITERATOR_H
12
13#include <__compare/three_way_comparable.h>
14#include <__concepts/convertible_to.h>
15#include <__config>
16#include <__iterator/iterator_traits.h>
17#include <__memory/addressof.h>
18#include <__type_traits/conditional.h>
19#include <__utility/move.h>
20#include <__utility/pair.h>
21
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24#endif
25
26_LIBCPP_PUSH_MACROS
27#include <__undef_macros>
28
29#if _LIBCPP_STD_VER >= 23
30
31_LIBCPP_BEGIN_NAMESPACE_STD
32
33/**
34 * __key_value_iterator is a proxy iterator which zips the underlying
35 * _KeyContainer::iterator and the underlying _MappedContainer::iterator.
36 * The two underlying iterators will be incremented/decremented together.
37 * And the reference is a pair of the const key reference and the value reference.
38 */
39template <class _Owner, class _KeyContainer, class _MappedContainer, bool _Const>
40struct __key_value_iterator {
41private:
42 using __key_iterator _LIBCPP_NODEBUG = typename _KeyContainer::const_iterator;
43 using __mapped_iterator _LIBCPP_NODEBUG =
44 _If<_Const, typename _MappedContainer::const_iterator, typename _MappedContainer::iterator>;
45 using __reference _LIBCPP_NODEBUG = _If<_Const, typename _Owner::const_reference, typename _Owner::reference>;
46
47 struct __arrow_proxy {
48 __reference __ref_;
49 _LIBCPP_HIDE_FROM_ABI __reference* operator->() { return std::addressof(__ref_); }
50 };
51
52 __key_iterator __key_iter_;
53 __mapped_iterator __mapped_iter_;
54
55 friend _Owner;
56
57 template <class, class, class, bool>
58 friend struct __key_value_iterator;
59
60public:
61 using iterator_concept = random_access_iterator_tag;
62 // `__key_value_iterator` only satisfy "Cpp17InputIterator" named requirements, because
63 // its `reference` is not a reference type.
64 // However, to avoid surprising runtime behaviour when it is used with the
65 // Cpp17 algorithms or operations, iterator_category is set to random_access_iterator_tag.
66 using iterator_category = random_access_iterator_tag;
67 using value_type = typename _Owner::value_type;
68 using difference_type = typename _Owner::difference_type;
69
70 _LIBCPP_HIDE_FROM_ABI __key_value_iterator() = default;
71
72 _LIBCPP_HIDE_FROM_ABI __key_value_iterator(__key_value_iterator<_Owner, _KeyContainer, _MappedContainer, !_Const> __i)
73 requires _Const && convertible_to<typename _KeyContainer::iterator, __key_iterator> &&
74 convertible_to<typename _MappedContainer::iterator, __mapped_iterator>
75 : __key_iter_(std::move(__i.__key_iter_)), __mapped_iter_(std::move(__i.__mapped_iter_)) {}
76
77 _LIBCPP_HIDE_FROM_ABI __key_value_iterator(__key_iterator __key_iter, __mapped_iterator __mapped_iter)
78 : __key_iter_(std::move(__key_iter)), __mapped_iter_(std::move(__mapped_iter)) {}
79
80 _LIBCPP_HIDE_FROM_ABI __reference operator*() const { return __reference(*__key_iter_, *__mapped_iter_); }
81 _LIBCPP_HIDE_FROM_ABI __arrow_proxy operator->() const { return __arrow_proxy{**this}; }
82
83 _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator++() {
84 ++__key_iter_;
85 ++__mapped_iter_;
86 return *this;
87 }
88
89 _LIBCPP_HIDE_FROM_ABI __key_value_iterator operator++(int) {
90 __key_value_iterator __tmp(*this);
91 ++*this;
92 return __tmp;
93 }
94
95 _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator--() {
96 --__key_iter_;
97 --__mapped_iter_;
98 return *this;
99 }
100
101 _LIBCPP_HIDE_FROM_ABI __key_value_iterator operator--(int) {
102 __key_value_iterator __tmp(*this);
103 --*this;
104 return __tmp;
105 }
106
107 _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator+=(difference_type __x) {
108 __key_iter_ += __x;
109 __mapped_iter_ += __x;
110 return *this;
111 }
112
113 _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator-=(difference_type __x) {
114 __key_iter_ -= __x;
115 __mapped_iter_ -= __x;
116 return *this;
117 }
118
119 _LIBCPP_HIDE_FROM_ABI __reference operator[](difference_type __n) const { return *(*this + __n); }
120
121 _LIBCPP_HIDE_FROM_ABI friend constexpr bool
122 operator==(const __key_value_iterator& __x, const __key_value_iterator& __y) {
123 return __x.__key_iter_ == __y.__key_iter_;
124 }
125
126 _LIBCPP_HIDE_FROM_ABI friend bool operator<(const __key_value_iterator& __x, const __key_value_iterator& __y) {
127 return __x.__key_iter_ < __y.__key_iter_;
128 }
129
130 _LIBCPP_HIDE_FROM_ABI friend bool operator>(const __key_value_iterator& __x, const __key_value_iterator& __y) {
131 return __y < __x;
132 }
133
134 _LIBCPP_HIDE_FROM_ABI friend bool operator<=(const __key_value_iterator& __x, const __key_value_iterator& __y) {
135 return !(__y < __x);
136 }
137
138 _LIBCPP_HIDE_FROM_ABI friend bool operator>=(const __key_value_iterator& __x, const __key_value_iterator& __y) {
139 return !(__x < __y);
140 }
141
142 _LIBCPP_HIDE_FROM_ABI friend auto operator<=>(const __key_value_iterator& __x, const __key_value_iterator& __y)
143 requires three_way_comparable<__key_iterator>
144 {
145 return __x.__key_iter_ <=> __y.__key_iter_;
146 }
147
148 _LIBCPP_HIDE_FROM_ABI friend __key_value_iterator operator+(const __key_value_iterator& __i, difference_type __n) {
149 auto __tmp = __i;
150 __tmp += __n;
151 return __tmp;
152 }
153
154 _LIBCPP_HIDE_FROM_ABI friend __key_value_iterator operator+(difference_type __n, const __key_value_iterator& __i) {
155 return __i + __n;
156 }
157
158 _LIBCPP_HIDE_FROM_ABI friend __key_value_iterator operator-(const __key_value_iterator& __i, difference_type __n) {
159 auto __tmp = __i;
160 __tmp -= __n;
161 return __tmp;
162 }
163
164 _LIBCPP_HIDE_FROM_ABI friend difference_type
165 operator-(const __key_value_iterator& __x, const __key_value_iterator& __y) {
166 return difference_type(__x.__key_iter_ - __y.__key_iter_);
167 }
168};
169
170_LIBCPP_END_NAMESPACE_STD
171
172#endif // _LIBCPP_STD_VER >= 23
173
174_LIBCPP_POP_MACROS
175
176#endif // _LIBCPP___FLAT_MAP_KEY_VALUE_ITERATOR_H
lib/libcxx/include/__flat_map/sorted_equivalent.h created+31
......@@ -0,0 +1,31 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9#ifndef _LIBCPP___FLAT_MAP_SORTED_EQUIVALENT_H
10#define _LIBCPP___FLAT_MAP_SORTED_EQUIVALENT_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18#if _LIBCPP_STD_VER >= 23
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22struct sorted_equivalent_t {
23 explicit sorted_equivalent_t() = default;
24};
25inline constexpr sorted_equivalent_t sorted_equivalent{};
26
27_LIBCPP_END_NAMESPACE_STD
28
29#endif // _LIBCPP_STD_VER >= 23
30
31#endif // _LIBCPP___FLAT_MAP_SORTED_EQUIVALENT_H
lib/libcxx/include/__flat_map/sorted_unique.h created+31
......@@ -0,0 +1,31 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9#ifndef _LIBCPP___FLAT_MAP_SORTED_UNIQUE_H
10#define _LIBCPP___FLAT_MAP_SORTED_UNIQUE_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18#if _LIBCPP_STD_VER >= 23
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22struct sorted_unique_t {
23 explicit sorted_unique_t() = default;
24};
25inline constexpr sorted_unique_t sorted_unique{};
26
27_LIBCPP_END_NAMESPACE_STD
28
29#endif // _LIBCPP_STD_VER >= 23
30
31#endif // _LIBCPP___FLAT_MAP_SORTED_UNIQUE_H
lib/libcxx/include/__flat_map/utils.h created+103
......@@ -0,0 +1,103 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___FLAT_MAP_UTILS_H
11#define _LIBCPP___FLAT_MAP_UTILS_H
12
13#include <__config>
14#include <__type_traits/container_traits.h>
15#include <__utility/exception_guard.h>
16#include <__utility/forward.h>
17#include <__utility/move.h>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
26#if _LIBCPP_STD_VER >= 23
27
28_LIBCPP_BEGIN_NAMESPACE_STD
29
30// These utilities are defined in a class instead of a namespace so that this class can be befriended more easily.
31struct __flat_map_utils {
32 // Emplace a {key: value} into a flat_{multi}map, at the exact position that
33 // __it_key and __it_mapped point to, assuming that the key is not already present in the map.
34 // When an exception is thrown during the emplacement, the function will try its best to
35 // roll back the changes it made to the map. If it cannot roll back the changes, it will
36 // clear the map.
37 template <class _Map, class _IterK, class _IterM, class _KeyArg, class... _MArgs>
38 _LIBCPP_HIDE_FROM_ABI static typename _Map::iterator __emplace_exact_pos(
39 _Map& __map, _IterK&& __it_key, _IterM&& __it_mapped, _KeyArg&& __key, _MArgs&&... __mapped_args) {
40 auto __on_key_failed = std::__make_exception_guard([&]() noexcept {
41 using _KeyContainer = typename _Map::key_container_type;
42 if constexpr (__container_traits<_KeyContainer>::__emplacement_has_strong_exception_safety_guarantee) {
43 // Nothing to roll back!
44 } else {
45 // we need to clear both because we don't know the state of our keys anymore
46 __map.clear() /* noexcept */;
47 }
48 });
49 auto __key_it = __map.__containers_.keys.emplace(__it_key, std::forward<_KeyArg>(__key));
50 __on_key_failed.__complete();
51
52 auto __on_value_failed = std::__make_exception_guard([&]() noexcept {
53 using _MappedContainer = typename _Map::mapped_container_type;
54 if constexpr (!__container_traits<_MappedContainer>::__emplacement_has_strong_exception_safety_guarantee) {
55 // we need to clear both because we don't know the state of our values anymore
56 __map.clear() /* noexcept */;
57 } else {
58 // In this case, we know the values are just like before we attempted emplacement,
59 // and we also know that the keys have been emplaced successfully. Just roll back the keys.
60# if _LIBCPP_HAS_EXCEPTIONS
61 try {
62# endif // _LIBCPP_HAS_EXCEPTIONS
63 __map.__containers_.keys.erase(__key_it);
64# if _LIBCPP_HAS_EXCEPTIONS
65 } catch (...) {
66 // Now things are funky for real. We're failing to rollback the keys.
67 // Just give up and clear the whole thing.
68 //
69 // Also, swallow the exception that happened during the rollback and let the
70 // original value-emplacement exception propagate normally.
71 __map.clear() /* noexcept */;
72 }
73# endif // _LIBCPP_HAS_EXCEPTIONS
74 }
75 });
76 auto __mapped_it = __map.__containers_.values.emplace(__it_mapped, std::forward<_MArgs>(__mapped_args)...);
77 __on_value_failed.__complete();
78
79 return typename _Map::iterator(std::move(__key_it), std::move(__mapped_it));
80 }
81
82 // TODO: We could optimize this, see
83 // https://github.com/llvm/llvm-project/issues/108624
84 template <class _Map, class _InputIterator, class _Sentinel>
85 _LIBCPP_HIDE_FROM_ABI static typename _Map::size_type
86 __append(_Map& __map, _InputIterator __first, _Sentinel __last) {
87 typename _Map::size_type __num_appended = 0;
88 for (; __first != __last; ++__first) {
89 typename _Map::value_type __kv = *__first;
90 __map.__containers_.keys.insert(__map.__containers_.keys.end(), std::move(__kv.first));
91 __map.__containers_.values.insert(__map.__containers_.values.end(), std::move(__kv.second));
92 ++__num_appended;
93 }
94 return __num_appended;
95 }
96};
97_LIBCPP_END_NAMESPACE_STD
98
99#endif // _LIBCPP_STD_VER >= 23
100
101_LIBCPP_POP_MACROS
102
103#endif // #define _LIBCPP___FLAT_MAP_UTILS_H
lib/libcxx/include/__format/buffer.h+341-287
......@@ -14,6 +14,7 @@
1414#include <__algorithm/fill_n.h>
1515#include <__algorithm/max.h>
1616#include <__algorithm/min.h>
17#include <__algorithm/ranges_copy.h>
1718#include <__algorithm/ranges_copy_n.h>
1819#include <__algorithm/transform.h>
1920#include <__algorithm/unwrap_iter.h>
......@@ -29,6 +30,7 @@
2930#include <__iterator/wrap_iter.h>
3031#include <__memory/addressof.h>
3132#include <__memory/allocate_at_least.h>
33#include <__memory/allocator.h>
3234#include <__memory/allocator_traits.h>
3335#include <__memory/construct_at.h>
3436#include <__memory/ranges_construct_at.h>
......@@ -37,7 +39,7 @@
3739#include <__type_traits/conditional.h>
3840#include <__utility/exception_guard.h>
3941#include <__utility/move.h>
40#include <cstddef>
42#include <stdexcept>
4143#include <string_view>
4244
4345#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -53,24 +55,147 @@ _LIBCPP_BEGIN_NAMESPACE_STD
5355
5456namespace __format {
5557
58// A helper to limit the total size of code units written.
59class _LIBCPP_HIDE_FROM_ABI __max_output_size {
60public:
61 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit __max_output_size(size_t __max_size) : __max_size_{__max_size} {}
62
63 // This function adjusts the size of a (bulk) write operations. It ensures the
64 // number of code units written by a __output_buffer never exceeds
65 // __max_size_ code units.
66 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI size_t __write_request(size_t __code_units) {
67 size_t __result =
68 __code_units_written_ < __max_size_ ? std::min(__code_units, __max_size_ - __code_units_written_) : 0;
69 __code_units_written_ += __code_units;
70 return __result;
71 }
72
73 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI size_t __code_units_written() const noexcept { return __code_units_written_; }
74
75private:
76 size_t __max_size_;
77 // The code units that would have been written if there was no limit.
78 // format_to_n returns this value.
79 size_t __code_units_written_{0};
80};
81
5682/// A "buffer" that handles writing to the proper iterator.
5783///
5884/// This helper is used together with the @ref back_insert_iterator to offer
5985/// type-erasure for the formatting functions. This reduces the number to
6086/// template instantiations.
87///
88/// The design is the following:
89/// - There is an external object that connects the buffer to the output.
90/// - This buffer object:
91/// - inherits publicly from this class.
92/// - has a static or dynamic buffer.
93/// - has a static member function to make space in its buffer write
94/// operations. This can be done by increasing the size of the internal
95/// buffer or by writing the contents of the buffer to the output iterator.
96///
97/// This member function is a constructor argument, so its name is not
98/// fixed. The code uses the name __prepare_write.
99/// - The number of output code units can be limited by a __max_output_size
100/// object. This is used in format_to_n This object:
101/// - Contains the maximum number of code units to be written.
102/// - Contains the number of code units that are requested to be written.
103/// This number is returned to the user of format_to_n.
104/// - The write functions call the object's __request_write member function.
105/// This function:
106/// - Updates the number of code units that are requested to be written.
107/// - Returns the number of code units that can be written without
108/// exceeding the maximum number of code units to be written.
109///
110/// Documentation for the buffer usage members:
111/// - __ptr_
112/// The start of the buffer.
113/// - __capacity_
114/// The number of code units that can be written. This means
115/// [__ptr_, __ptr_ + __capacity_) is a valid range to write to.
116/// - __size_
117/// The number of code units written in the buffer. The next code unit will
118/// be written at __ptr_ + __size_. This __size_ may NOT contain the total
119/// number of code units written by the __output_buffer. Whether or not it
120/// does depends on the sub-class used. Typically the total number of code
121/// units written is not interesting. It is interesting for format_to_n which
122/// has its own way to track this number.
123///
124/// Documentation for the modifying buffer operations:
125/// The subclasses have a function with the following signature:
126///
127/// static void __prepare_write(
128/// __output_buffer<_CharT>& __buffer, size_t __code_units);
129///
130/// This function is called when a write function writes more code units than
131/// the buffer's available space. When an __max_output_size object is provided
132/// the number of code units is the number of code units returned from
133/// __max_output_size::__request_write function.
134///
135/// - The __buffer contains *this. Since the class containing this function
136/// inherits from __output_buffer it's safe to cast it to the subclass being
137/// used.
138/// - The __code_units is the number of code units the caller will write + 1.
139/// - This value does not take the available space of the buffer into account.
140/// - The push_back function is more efficient when writing before resizing,
141/// this means the buffer should always have room for one code unit. Hence
142/// the + 1 is the size.
143/// - When the function returns there is room for at least one additional code
144/// unit. There is no requirement there is room for __code_units code units:
145/// - The class has some "bulk" operations. For example, __copy which copies
146/// the contents of a basic_string_view to the output. If the sub-class has
147/// a fixed size buffer the size of the basic_string_view may be larger
148/// than the buffer. In that case it's impossible to honor the requested
149/// size.
150/// - When the buffer has room for at least one code unit the function may be
151/// a no-op.
152/// - When the function makes space for more code units it uses one for these
153/// functions to signal the change:
154/// - __buffer_flushed()
155/// - This function is typically used for a fixed sized buffer.
156/// - The current contents of [__ptr_, __ptr_ + __size_) have been
157/// processed.
158/// - __ptr_ remains unchanged.
159/// - __capacity_ remains unchanged.
160/// - __size_ will be set to 0.
161/// - __buffer_moved(_CharT* __ptr, size_t __capacity)
162/// - This function is typically used for a dynamic sized buffer. There the
163/// location of the buffer changes due to reallocations.
164/// - __ptr_ will be set to __ptr. (This value may be the old value of
165/// __ptr_).
166/// - __capacity_ will be set to __capacity. (This value may be the old
167/// value of __capacity_).
168/// - __size_ remains unchanged,
169/// - The range [__ptr, __ptr + __size_) contains the original data of the
170/// range [__ptr_, __ptr_ + __size_).
171///
172/// The push_back function expects a valid buffer and a capacity of at least 1.
173/// This means:
174/// - The class is constructed with a valid buffer,
175/// - __buffer_moved is called with a valid buffer is used before the first
176/// write operation,
177/// - no write function is ever called, or
178/// - the class is constructed with a __max_output_size object with __max_size 0.
179///
180/// The latter option allows formatted_size to use the output buffer without
181/// ever writing anything to the buffer.
61182template <__fmt_char_type _CharT>
62183class _LIBCPP_TEMPLATE_VIS __output_buffer {
63184public:
64 using value_type = _CharT;
185 using value_type _LIBCPP_NODEBUG = _CharT;
186 using __prepare_write_type _LIBCPP_NODEBUG = void (*)(__output_buffer<_CharT>&, size_t);
65187
66 template <class _Tp>
67 _LIBCPP_HIDE_FROM_ABI explicit __output_buffer(_CharT* __ptr, size_t __capacity, _Tp* __obj)
68 : __ptr_(__ptr),
69 __capacity_(__capacity),
70 __flush_([](_CharT* __p, size_t __n, void* __o) { static_cast<_Tp*>(__o)->__flush(__p, __n); }),
71 __obj_(__obj) {}
188 [[nodiscard]]
189 _LIBCPP_HIDE_FROM_ABI explicit __output_buffer(_CharT* __ptr, size_t __capacity, __prepare_write_type __function)
190 : __output_buffer{__ptr, __capacity, __function, nullptr} {}
72191
73 _LIBCPP_HIDE_FROM_ABI void __reset(_CharT* __ptr, size_t __capacity) {
192 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit __output_buffer(
193 _CharT* __ptr, size_t __capacity, __prepare_write_type __function, __max_output_size* __max_output_size)
194 : __ptr_(__ptr), __capacity_(__capacity), __prepare_write_(__function), __max_output_size_(__max_output_size) {}
195
196 _LIBCPP_HIDE_FROM_ABI void __buffer_flushed() { __size_ = 0; }
197
198 _LIBCPP_HIDE_FROM_ABI void __buffer_moved(_CharT* __ptr, size_t __capacity) {
74199 __ptr_ = __ptr;
75200 __capacity_ = __capacity;
76201 }
......@@ -79,12 +204,18 @@ public:
79204
80205 // Used in std::back_insert_iterator.
81206 _LIBCPP_HIDE_FROM_ABI void push_back(_CharT __c) {
207 if (__max_output_size_ && __max_output_size_->__write_request(1) == 0)
208 return;
209
210 _LIBCPP_ASSERT_INTERNAL(
211 __ptr_ && __size_ < __capacity_ && __available() >= 1, "attempted to write outside the buffer");
212
82213 __ptr_[__size_++] = __c;
83214
84215 // Profiling showed flushing after adding is more efficient than flushing
85216 // when entering the function.
86217 if (__size_ == __capacity_)
87 __flush();
218 __prepare_write(0);
88219 }
89220
90221 /// Copies the input __str to the buffer.
......@@ -105,25 +236,20 @@ public:
105236 // upper case. For integral these strings are short.
106237 // TODO FMT Look at the improvements above.
107238 size_t __n = __str.size();
108
109 __flush_on_overflow(__n);
110 if (__n < __capacity_) { // push_back requires the buffer to have room for at least one character (so use <).
111 std::copy_n(__str.data(), __n, std::addressof(__ptr_[__size_]));
112 __size_ += __n;
113 return;
239 if (__max_output_size_) {
240 __n = __max_output_size_->__write_request(__n);
241 if (__n == 0)
242 return;
114243 }
115244
116 // The output doesn't fit in the internal buffer.
117 // Copy the data in "__capacity_" sized chunks.
118 _LIBCPP_ASSERT_INTERNAL(__size_ == 0, "the buffer should be flushed by __flush_on_overflow");
119245 const _InCharT* __first = __str.data();
120246 do {
121 size_t __chunk = std::min(__n, __capacity_);
247 __prepare_write(__n);
248 size_t __chunk = std::min(__n, __available());
122249 std::copy_n(__first, __chunk, std::addressof(__ptr_[__size_]));
123 __size_ = __chunk;
250 __size_ += __chunk;
124251 __first += __chunk;
125252 __n -= __chunk;
126 __flush();
127253 } while (__n);
128254 }
129255
......@@ -137,121 +263,59 @@ public:
137263 _LIBCPP_ASSERT_INTERNAL(__first <= __last, "not a valid range");
138264
139265 size_t __n = static_cast<size_t>(__last - __first);
140 __flush_on_overflow(__n);
141 if (__n < __capacity_) { // push_back requires the buffer to have room for at least one character (so use <).
142 std::transform(__first, __last, std::addressof(__ptr_[__size_]), std::move(__operation));
143 __size_ += __n;
144 return;
266 if (__max_output_size_) {
267 __n = __max_output_size_->__write_request(__n);
268 if (__n == 0)
269 return;
145270 }
146271
147 // The output doesn't fit in the internal buffer.
148 // Transform the data in "__capacity_" sized chunks.
149 _LIBCPP_ASSERT_INTERNAL(__size_ == 0, "the buffer should be flushed by __flush_on_overflow");
150272 do {
151 size_t __chunk = std::min(__n, __capacity_);
273 __prepare_write(__n);
274 size_t __chunk = std::min(__n, __available());
152275 std::transform(__first, __first + __chunk, std::addressof(__ptr_[__size_]), __operation);
153 __size_ = __chunk;
276 __size_ += __chunk;
154277 __first += __chunk;
155278 __n -= __chunk;
156 __flush();
157279 } while (__n);
158280 }
159281
160282 /// A \c fill_n wrapper.
161283 _LIBCPP_HIDE_FROM_ABI void __fill(size_t __n, _CharT __value) {
162 __flush_on_overflow(__n);
163 if (__n < __capacity_) { // push_back requires the buffer to have room for at least one character (so use <).
164 std::fill_n(std::addressof(__ptr_[__size_]), __n, __value);
165 __size_ += __n;
166 return;
284 if (__max_output_size_) {
285 __n = __max_output_size_->__write_request(__n);
286 if (__n == 0)
287 return;
167288 }
168289
169 // The output doesn't fit in the internal buffer.
170 // Fill the buffer in "__capacity_" sized chunks.
171 _LIBCPP_ASSERT_INTERNAL(__size_ == 0, "the buffer should be flushed by __flush_on_overflow");
172290 do {
173 size_t __chunk = std::min(__n, __capacity_);
291 __prepare_write(__n);
292 size_t __chunk = std::min(__n, __available());
174293 std::fill_n(std::addressof(__ptr_[__size_]), __chunk, __value);
175 __size_ = __chunk;
294 __size_ += __chunk;
176295 __n -= __chunk;
177 __flush();
178296 } while (__n);
179297 }
180298
181 _LIBCPP_HIDE_FROM_ABI void __flush() {
182 __flush_(__ptr_, __size_, __obj_);
183 __size_ = 0;
184 }
299 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI size_t __capacity() const { return __capacity_; }
300 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI size_t __size() const { return __size_; }
185301
186302private:
187303 _CharT* __ptr_;
188304 size_t __capacity_;
189305 size_t __size_{0};
190 void (*__flush_)(_CharT*, size_t, void*);
191 void* __obj_;
306 void (*__prepare_write_)(__output_buffer<_CharT>&, size_t);
307 __max_output_size* __max_output_size_;
192308
193 /// Flushes the buffer when the output operation would overflow the buffer.
194 ///
195 /// A simple approach for the overflow detection would be something along the
196 /// lines:
197 /// \code
198 /// // The internal buffer is large enough.
199 /// if (__n <= __capacity_) {
200 /// // Flush when we really would overflow.
201 /// if (__size_ + __n >= __capacity_)
202 /// __flush();
203 /// ...
204 /// }
205 /// \endcode
206 ///
207 /// This approach works for all cases but one:
208 /// A __format_to_n_buffer_base where \ref __enable_direct_output is true.
209 /// In that case the \ref __capacity_ of the buffer changes during the first
210 /// \ref __flush. During that operation the output buffer switches from its
211 /// __writer_ to its __storage_. The \ref __capacity_ of the former depends
212 /// on the value of n, of the latter is a fixed size. For example:
213 /// - a format_to_n call with a 10'000 char buffer,
214 /// - the buffer is filled with 9'500 chars,
215 /// - adding 1'000 elements would overflow the buffer so the buffer gets
216 /// changed and the \ref __capacity_ decreases from 10'000 to
217 /// __buffer_size (256 at the time of writing).
218 ///
219 /// This means that the \ref __flush for this class may need to copy a part of
220 /// the internal buffer to the proper output. In this example there will be
221 /// 500 characters that need this copy operation.
222 ///
223 /// Note it would be more efficient to write 500 chars directly and then swap
224 /// the buffers. This would make the code more complex and \ref format_to_n is
225 /// not the most common use case. Therefore the optimization isn't done.
226 _LIBCPP_HIDE_FROM_ABI void __flush_on_overflow(size_t __n) {
227 if (__size_ + __n >= __capacity_)
228 __flush();
229 }
230};
231
232/// A storage using an internal buffer.
233///
234/// This storage is used when writing a single element to the output iterator
235/// is expensive.
236template <__fmt_char_type _CharT>
237class _LIBCPP_TEMPLATE_VIS __internal_storage {
238public:
239 _LIBCPP_HIDE_FROM_ABI _CharT* __begin() { return __buffer_; }
240
241 static constexpr size_t __buffer_size = 256 / sizeof(_CharT);
309 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI size_t __available() const { return __capacity_ - __size_; }
242310
243private:
244 _CharT __buffer_[__buffer_size];
311 _LIBCPP_HIDE_FROM_ABI void __prepare_write(size_t __code_units) {
312 // Always have space for one additional code unit. This is a precondition of the push_back function.
313 __code_units += 1;
314 if (__available() < __code_units)
315 __prepare_write_(*this, __code_units + 1);
316 }
245317};
246318
247/// A storage writing directly to the storage.
248///
249/// This requires the storage to be a contiguous buffer of \a _CharT.
250/// Since the output is directly written to the underlying storage this class
251/// is just an empty class.
252template <__fmt_char_type _CharT>
253class _LIBCPP_TEMPLATE_VIS __direct_storage {};
254
255319template <class _OutIt, class _CharT>
256320concept __enable_direct_output =
257321 __fmt_char_type<_CharT> &&
......@@ -260,40 +324,6 @@ concept __enable_direct_output =
260324 // `#ifdef`.
261325 || same_as<_OutIt, __wrap_iter<_CharT*>>);
262326
263/// Write policy for directly writing to the underlying output.
264template <class _OutIt, __fmt_char_type _CharT>
265class _LIBCPP_TEMPLATE_VIS __writer_direct {
266public:
267 _LIBCPP_HIDE_FROM_ABI explicit __writer_direct(_OutIt __out_it) : __out_it_(__out_it) {}
268
269 _LIBCPP_HIDE_FROM_ABI _OutIt __out_it() { return __out_it_; }
270
271 _LIBCPP_HIDE_FROM_ABI void __flush(_CharT*, size_t __n) {
272 // _OutIt can be a __wrap_iter<CharT*>. Therefore the original iterator
273 // is adjusted.
274 __out_it_ += __n;
275 }
276
277private:
278 _OutIt __out_it_;
279};
280
281/// Write policy for copying the buffer to the output.
282template <class _OutIt, __fmt_char_type _CharT>
283class _LIBCPP_TEMPLATE_VIS __writer_iterator {
284public:
285 _LIBCPP_HIDE_FROM_ABI explicit __writer_iterator(_OutIt __out_it) : __out_it_{std::move(__out_it)} {}
286
287 _LIBCPP_HIDE_FROM_ABI _OutIt __out_it() && { return std::move(__out_it_); }
288
289 _LIBCPP_HIDE_FROM_ABI void __flush(_CharT* __ptr, size_t __n) {
290 __out_it_ = std::ranges::copy_n(__ptr, __n, std::move(__out_it_)).out;
291 }
292
293private:
294 _OutIt __out_it_;
295};
296
297327/// Concept to see whether a \a _Container is insertable.
298328///
299329/// The concept is used to validate whether multiple calls to a
......@@ -311,196 +341,220 @@ concept __insertable =
311341/// Extract the container type of a \ref back_insert_iterator.
312342template <class _It>
313343struct _LIBCPP_TEMPLATE_VIS __back_insert_iterator_container {
314 using type = void;
344 using type _LIBCPP_NODEBUG = void;
315345};
316346
317347template <__insertable _Container>
318348struct _LIBCPP_TEMPLATE_VIS __back_insert_iterator_container<back_insert_iterator<_Container>> {
319 using type = _Container;
349 using type _LIBCPP_NODEBUG = _Container;
320350};
321351
322/// Write policy for inserting the buffer in a container.
323template <class _Container>
324class _LIBCPP_TEMPLATE_VIS __writer_container {
352// A dynamically growing buffer.
353template <__fmt_char_type _CharT>
354class _LIBCPP_TEMPLATE_VIS __allocating_buffer : public __output_buffer<_CharT> {
325355public:
326 using _CharT = typename _Container::value_type;
356 __allocating_buffer(const __allocating_buffer&) = delete;
357 __allocating_buffer& operator=(const __allocating_buffer&) = delete;
327358
328 _LIBCPP_HIDE_FROM_ABI explicit __writer_container(back_insert_iterator<_Container> __out_it)
329 : __container_{__out_it.__get_container()} {}
359 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI __allocating_buffer() : __allocating_buffer{nullptr} {}
330360
331 _LIBCPP_HIDE_FROM_ABI auto __out_it() { return std::back_inserter(*__container_); }
361 [[nodiscard]]
362 _LIBCPP_HIDE_FROM_ABI explicit __allocating_buffer(__max_output_size* __max_output_size)
363 : __output_buffer<_CharT>{__small_buffer_, __buffer_size_, __prepare_write, __max_output_size} {}
332364
333 _LIBCPP_HIDE_FROM_ABI void __flush(_CharT* __ptr, size_t __n) {
334 __container_->insert(__container_->end(), __ptr, __ptr + __n);
365 _LIBCPP_HIDE_FROM_ABI ~__allocating_buffer() {
366 if (__ptr_ != __small_buffer_)
367 _Alloc{}.deallocate(__ptr_, this->__capacity());
335368 }
336369
337private:
338 _Container* __container_;
339};
370 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string_view<_CharT> __view() { return {__ptr_, this->__size()}; }
340371
341/// Selects the type of the writer used for the output iterator.
342template <class _OutIt, class _CharT>
343class _LIBCPP_TEMPLATE_VIS __writer_selector {
344 using _Container = typename __back_insert_iterator_container<_OutIt>::type;
372private:
373 using _Alloc _LIBCPP_NODEBUG = allocator<_CharT>;
345374
346public:
347 using type =
348 conditional_t<!same_as<_Container, void>,
349 __writer_container<_Container>,
350 conditional_t<__enable_direct_output<_OutIt, _CharT>,
351 __writer_direct<_OutIt, _CharT>,
352 __writer_iterator<_OutIt, _CharT>>>;
353};
375 // Since allocating is expensive the class has a small internal buffer. When
376 // its capacity is exceeded a dynamic buffer will be allocated.
377 static constexpr size_t __buffer_size_ = 256;
378 _CharT __small_buffer_[__buffer_size_];
354379
355/// The generic formatting buffer.
356template <class _OutIt, __fmt_char_type _CharT>
357 requires(output_iterator<_OutIt, const _CharT&>)
358class _LIBCPP_TEMPLATE_VIS __format_buffer {
359 using _Storage =
360 conditional_t<__enable_direct_output<_OutIt, _CharT>, __direct_storage<_CharT>, __internal_storage<_CharT>>;
380 _CharT* __ptr_{__small_buffer_};
361381
362public:
363 _LIBCPP_HIDE_FROM_ABI explicit __format_buffer(_OutIt __out_it)
364 requires(same_as<_Storage, __internal_storage<_CharT>>)
365 : __output_(__storage_.__begin(), __storage_.__buffer_size, this), __writer_(std::move(__out_it)) {}
382 _LIBCPP_HIDE_FROM_ABI void __grow_buffer(size_t __capacity) {
383 if (__capacity < __buffer_size_)
384 return;
366385
367 _LIBCPP_HIDE_FROM_ABI explicit __format_buffer(_OutIt __out_it)
368 requires(same_as<_Storage, __direct_storage<_CharT>>)
369 : __output_(std::__unwrap_iter(__out_it), size_t(-1), this), __writer_(std::move(__out_it)) {}
386 _LIBCPP_ASSERT_INTERNAL(__capacity > this->__capacity(), "the buffer must grow");
370387
371 _LIBCPP_HIDE_FROM_ABI auto __make_output_iterator() { return __output_.__make_output_iterator(); }
388 // _CharT is an implicit lifetime type so can be used without explicit
389 // construction or destruction.
390 _Alloc __alloc;
391 auto __result = std::__allocate_at_least(__alloc, __capacity);
392 std::copy_n(__ptr_, this->__size(), __result.ptr);
393 if (__ptr_ != __small_buffer_)
394 __alloc.deallocate(__ptr_, this->__capacity());
372395
373 _LIBCPP_HIDE_FROM_ABI void __flush(_CharT* __ptr, size_t __n) { __writer_.__flush(__ptr, __n); }
396 __ptr_ = __result.ptr;
397 this->__buffer_moved(__ptr_, __result.count);
398 }
374399
375 _LIBCPP_HIDE_FROM_ABI _OutIt __out_it() && {
376 __output_.__flush();
377 return std::move(__writer_).__out_it();
400 _LIBCPP_HIDE_FROM_ABI void __prepare_write(size_t __size_hint) {
401 __grow_buffer(std::max<size_t>(this->__capacity() + __size_hint, this->__capacity() * 1.6));
378402 }
379403
380private:
381 _LIBCPP_NO_UNIQUE_ADDRESS _Storage __storage_;
382 __output_buffer<_CharT> __output_;
383 typename __writer_selector<_OutIt, _CharT>::type __writer_;
404 _LIBCPP_HIDE_FROM_ABI static void __prepare_write(__output_buffer<_CharT>& __buffer, size_t __size_hint) {
405 static_cast<__allocating_buffer<_CharT>&>(__buffer).__prepare_write(__size_hint);
406 }
384407};
385408
386/// A buffer that counts the number of insertions.
387///
388/// Since \ref formatted_size only needs to know the size, the output itself is
389/// discarded.
390template <__fmt_char_type _CharT>
391class _LIBCPP_TEMPLATE_VIS __formatted_size_buffer {
409// A buffer that directly writes to the underlying buffer.
410template <class _OutIt, __fmt_char_type _CharT>
411class _LIBCPP_TEMPLATE_VIS __direct_iterator_buffer : public __output_buffer<_CharT> {
392412public:
393 _LIBCPP_HIDE_FROM_ABI auto __make_output_iterator() { return __output_.__make_output_iterator(); }
413 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit __direct_iterator_buffer(_OutIt __out_it)
414 : __direct_iterator_buffer{__out_it, nullptr} {}
394415
395 _LIBCPP_HIDE_FROM_ABI void __flush(const _CharT*, size_t __n) { __size_ += __n; }
416 [[nodiscard]]
417 _LIBCPP_HIDE_FROM_ABI explicit __direct_iterator_buffer(_OutIt __out_it, __max_output_size* __max_output_size)
418 : __output_buffer<_CharT>{std::__unwrap_iter(__out_it), __buffer_size, __prepare_write, __max_output_size},
419 __out_it_(__out_it) {}
396420
397 _LIBCPP_HIDE_FROM_ABI size_t __result() && {
398 __output_.__flush();
399 return __size_;
400 }
421 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _OutIt __out_it() && { return __out_it_ + this->__size(); }
401422
402423private:
403 __internal_storage<_CharT> __storage_;
404 __output_buffer<_CharT> __output_{__storage_.__begin(), __storage_.__buffer_size, this};
405 size_t __size_{0};
406};
424 // The function format_to expects a buffer large enough for the output. The
425 // function format_to_n has its own helper class that restricts the number of
426 // write options. So this function class can pretend to have an infinite
427 // buffer.
428 static constexpr size_t __buffer_size = -1;
429
430 _OutIt __out_it_;
407431
408/// The base of a buffer that counts and limits the number of insertions.
409template <class _OutIt, __fmt_char_type _CharT, bool>
410 requires(output_iterator<_OutIt, const _CharT&>)
411struct _LIBCPP_TEMPLATE_VIS __format_to_n_buffer_base {
412 using _Size = iter_difference_t<_OutIt>;
432 _LIBCPP_HIDE_FROM_ABI static void
433 __prepare_write([[maybe_unused]] __output_buffer<_CharT>& __buffer, [[maybe_unused]] size_t __size_hint) {
434 std::__throw_length_error("__direct_iterator_buffer");
435 }
436};
413437
438// A buffer that writes its output to the end of a container.
439template <class _OutIt, __fmt_char_type _CharT>
440class _LIBCPP_TEMPLATE_VIS __container_inserter_buffer : public __output_buffer<_CharT> {
414441public:
415 _LIBCPP_HIDE_FROM_ABI explicit __format_to_n_buffer_base(_OutIt __out_it, _Size __max_size)
416 : __writer_(std::move(__out_it)), __max_size_(std::max(_Size(0), __max_size)) {}
442 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit __container_inserter_buffer(_OutIt __out_it)
443 : __container_inserter_buffer{__out_it, nullptr} {}
417444
418 _LIBCPP_HIDE_FROM_ABI void __flush(_CharT* __ptr, size_t __n) {
419 if (_Size(__size_) <= __max_size_)
420 __writer_.__flush(__ptr, std::min(_Size(__n), __max_size_ - __size_));
421 __size_ += __n;
445 [[nodiscard]]
446 _LIBCPP_HIDE_FROM_ABI explicit __container_inserter_buffer(_OutIt __out_it, __max_output_size* __max_output_size)
447 : __output_buffer<_CharT>{__small_buffer_, __buffer_size, __prepare_write, __max_output_size},
448 __container_{__out_it.__get_container()} {}
449
450 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI auto __out_it() && {
451 __container_->insert(__container_->end(), __small_buffer_, __small_buffer_ + this->__size());
452 return std::back_inserter(*__container_);
422453 }
423454
424protected:
425 __internal_storage<_CharT> __storage_;
426 __output_buffer<_CharT> __output_{__storage_.__begin(), __storage_.__buffer_size, this};
427 typename __writer_selector<_OutIt, _CharT>::type __writer_;
455private:
456 typename __back_insert_iterator_container<_OutIt>::type* __container_;
457
458 // This class uses a fixed size buffer and appends the elements in
459 // __buffer_size chunks. An alternative would be to use an allocating buffer
460 // and append the output in a single write operation. Benchmarking showed no
461 // performance difference.
462 static constexpr size_t __buffer_size = 256;
463 _CharT __small_buffer_[__buffer_size];
464
465 _LIBCPP_HIDE_FROM_ABI void __prepare_write() {
466 __container_->insert(__container_->end(), __small_buffer_, __small_buffer_ + this->__size());
467 this->__buffer_flushed();
468 }
428469
429 _Size __max_size_;
430 _Size __size_{0};
470 _LIBCPP_HIDE_FROM_ABI static void
471 __prepare_write(__output_buffer<_CharT>& __buffer, [[maybe_unused]] size_t __size_hint) {
472 static_cast<__container_inserter_buffer<_OutIt, _CharT>&>(__buffer).__prepare_write();
473 }
431474};
432475
433/// The base of a buffer that counts and limits the number of insertions.
434///
435/// This version is used when \c __enable_direct_output<_OutIt, _CharT> == true.
436///
437/// This class limits the size available to the direct writer so it will not
438/// exceed the maximum number of code units.
476// A buffer that writes to an iterator.
477//
478// Unlike the __container_inserter_buffer this class' performance does benefit
479// from allocating and then inserting.
439480template <class _OutIt, __fmt_char_type _CharT>
440 requires(output_iterator<_OutIt, const _CharT&>)
441class _LIBCPP_TEMPLATE_VIS __format_to_n_buffer_base<_OutIt, _CharT, true> {
442 using _Size = iter_difference_t<_OutIt>;
443
481class _LIBCPP_TEMPLATE_VIS __iterator_buffer : public __allocating_buffer<_CharT> {
444482public:
445 _LIBCPP_HIDE_FROM_ABI explicit __format_to_n_buffer_base(_OutIt __out_it, _Size __max_size)
446 : __output_(std::__unwrap_iter(__out_it), __max_size, this),
447 __writer_(std::move(__out_it)),
448 __max_size_(__max_size) {
449 if (__max_size <= 0) [[unlikely]]
450 __output_.__reset(__storage_.__begin(), __storage_.__buffer_size);
451 }
483 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit __iterator_buffer(_OutIt __out_it)
484 : __allocating_buffer<_CharT>{}, __out_it_{std::move(__out_it)} {}
452485
453 _LIBCPP_HIDE_FROM_ABI void __flush(_CharT* __ptr, size_t __n) {
454 // A __flush to the direct writer happens in the following occasions:
455 // - The format function has written the maximum number of allowed code
456 // units. At this point it's no longer valid to write to this writer. So
457 // switch to the internal storage. This internal storage doesn't need to
458 // be written anywhere so the __flush for that storage writes no output.
459 // - Like above, but the next "mass write" operation would overflow the
460 // buffer. In that case the buffer is pre-emptively switched. The still
461 // valid code units will be written separately.
462 // - The format_to_n function is finished. In this case there's no need to
463 // switch the buffer, but for simplicity the buffers are still switched.
464 // When the __max_size <= 0 the constructor already switched the buffers.
465 if (__size_ == 0 && __ptr != __storage_.__begin()) {
466 __writer_.__flush(__ptr, __n);
467 __output_.__reset(__storage_.__begin(), __storage_.__buffer_size);
468 } else if (__size_ < __max_size_) {
469 // Copies a part of the internal buffer to the output up to n characters.
470 // See __output_buffer<_CharT>::__flush_on_overflow for more information.
471 _Size __s = std::min(_Size(__n), __max_size_ - __size_);
472 std::copy_n(__ptr, __s, __writer_.__out_it());
473 __writer_.__flush(__ptr, __s);
474 }
486 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit __iterator_buffer(_OutIt __out_it, __max_output_size* __max_output_size)
487 : __allocating_buffer<_CharT>{__max_output_size}, __out_it_{std::move(__out_it)} {}
475488
476 __size_ += __n;
489 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI auto __out_it() && {
490 return std::ranges::copy(this->__view(), std::move(__out_it_)).out;
477491 }
478492
479protected:
480 __internal_storage<_CharT> __storage_;
481 __output_buffer<_CharT> __output_;
482 __writer_direct<_OutIt, _CharT> __writer_;
493private:
494 _OutIt __out_it_;
495};
496
497// Selects the type of the buffer used for the output iterator.
498template <class _OutIt, __fmt_char_type _CharT>
499class _LIBCPP_TEMPLATE_VIS __buffer_selector {
500 using _Container _LIBCPP_NODEBUG = __back_insert_iterator_container<_OutIt>::type;
483501
484 _Size __max_size_;
485 _Size __size_{0};
502public:
503 using type _LIBCPP_NODEBUG =
504 conditional_t<!same_as<_Container, void>,
505 __container_inserter_buffer<_OutIt, _CharT>,
506 conditional_t<__enable_direct_output<_OutIt, _CharT>,
507 __direct_iterator_buffer<_OutIt, _CharT>,
508 __iterator_buffer<_OutIt, _CharT>>>;
486509};
487510
488/// The buffer that counts and limits the number of insertions.
511// A buffer that counts and limits the number of insertions.
489512template <class _OutIt, __fmt_char_type _CharT>
490 requires(output_iterator<_OutIt, const _CharT&>)
491struct _LIBCPP_TEMPLATE_VIS __format_to_n_buffer final
492 : public __format_to_n_buffer_base< _OutIt, _CharT, __enable_direct_output<_OutIt, _CharT>> {
493 using _Base = __format_to_n_buffer_base<_OutIt, _CharT, __enable_direct_output<_OutIt, _CharT>>;
494 using _Size = iter_difference_t<_OutIt>;
513class _LIBCPP_TEMPLATE_VIS __format_to_n_buffer : private __buffer_selector<_OutIt, _CharT>::type {
514public:
515 using _Base _LIBCPP_NODEBUG = __buffer_selector<_OutIt, _CharT>::type;
516
517 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI __format_to_n_buffer(_OutIt __out_it, iter_difference_t<_OutIt> __n)
518 : _Base{std::move(__out_it), std::addressof(__max_output_size_)},
519 __max_output_size_{__n < 0 ? size_t{0} : static_cast<size_t>(__n)} {}
520
521 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI auto __make_output_iterator() { return _Base::__make_output_iterator(); }
522
523 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> __result() && {
524 return {static_cast<_Base&&>(*this).__out_it(),
525 static_cast<iter_difference_t<_OutIt>>(__max_output_size_.__code_units_written())};
526 }
527
528private:
529 __max_output_size __max_output_size_;
530};
495531
532// A buffer that counts the number of insertions.
533//
534// Since formatted_size only needs to know the size, the output itself is
535// discarded.
536template <__fmt_char_type _CharT>
537class _LIBCPP_TEMPLATE_VIS __formatted_size_buffer : private __output_buffer<_CharT> {
496538public:
497 _LIBCPP_HIDE_FROM_ABI explicit __format_to_n_buffer(_OutIt __out_it, _Size __max_size)
498 : _Base(std::move(__out_it), __max_size) {}
499 _LIBCPP_HIDE_FROM_ABI auto __make_output_iterator() { return this->__output_.__make_output_iterator(); }
539 using _Base _LIBCPP_NODEBUG = __output_buffer<_CharT>;
540
541 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI __formatted_size_buffer()
542 : _Base{nullptr, 0, __prepare_write, std::addressof(__max_output_size_)} {}
543
544 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI auto __make_output_iterator() { return _Base::__make_output_iterator(); }
545
546 // This function does not need to be r-value qualified, however this is
547 // consistent with similar objects.
548 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI size_t __result() && { return __max_output_size_.__code_units_written(); }
549
550private:
551 __max_output_size __max_output_size_{0};
500552
501 _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> __result() && {
502 this->__output_.__flush();
503 return {std::move(this->__writer_).__out_it(), this->__size_};
553 _LIBCPP_HIDE_FROM_ABI static void
554 __prepare_write([[maybe_unused]] __output_buffer<_CharT>& __buffer, [[maybe_unused]] size_t __size_hint) {
555 // Note this function does not satisfy the requirement of giving a 1 code unit buffer.
556 _LIBCPP_ASSERT_INTERNAL(
557 false, "Since __max_output_size_.__max_size_ == 0 there should never be call to this function.");
504558 }
505559};
506560
......@@ -524,14 +578,14 @@ public:
524578// would lead to a circular include with formatter for vector<bool>.
525579template <__fmt_char_type _CharT>
526580class _LIBCPP_TEMPLATE_VIS __retarget_buffer {
527 using _Alloc = allocator<_CharT>;
581 using _Alloc _LIBCPP_NODEBUG = allocator<_CharT>;
528582
529583public:
530 using value_type = _CharT;
584 using value_type _LIBCPP_NODEBUG = _CharT;
531585
532586 struct __iterator {
533 using difference_type = ptrdiff_t;
534 using value_type = _CharT;
587 using difference_type _LIBCPP_NODEBUG = ptrdiff_t;
588 using value_type _LIBCPP_NODEBUG = _CharT;
535589
536590 _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(__retarget_buffer& __buffer)
537591 : __buffer_(std::addressof(__buffer)) {}
......@@ -646,7 +700,7 @@ private:
646700
647701} // namespace __format
648702
649#endif //_LIBCPP_STD_VER >= 20
703#endif // _LIBCPP_STD_VER >= 20
650704
651705_LIBCPP_END_NAMESPACE_STD
652706
lib/libcxx/include/__format/concepts.h+4-4
......@@ -34,7 +34,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3434template <class _CharT>
3535concept __fmt_char_type =
3636 same_as<_CharT, char>
37# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
37# if _LIBCPP_HAS_WIDE_CHARACTERS
3838 || same_as<_CharT, wchar_t>
3939# endif
4040 ;
......@@ -44,7 +44,7 @@ concept __fmt_char_type =
4444// (Note testing for (w)format_context would be a valid choice, but requires
4545// selecting the proper one depending on the type of _CharT.)
4646template <class _CharT>
47using __fmt_iter_for = _CharT*;
47using __fmt_iter_for _LIBCPP_NODEBUG = _CharT*;
4848
4949template <class _Tp, class _Context, class _Formatter = typename _Context::template formatter_type<remove_const_t<_Tp>>>
5050concept __formattable_with =
......@@ -75,8 +75,8 @@ template <class _Tp>
7575concept __fmt_pair_like =
7676 __is_specialization_v<_Tp, pair> || (__is_specialization_v<_Tp, tuple> && tuple_size_v<_Tp> == 2);
7777
78# endif //_LIBCPP_STD_VER >= 23
79#endif //_LIBCPP_STD_VER >= 20
78# endif // _LIBCPP_STD_VER >= 23
79#endif // _LIBCPP_STD_VER >= 20
8080
8181_LIBCPP_END_NAMESPACE_STD
8282
lib/libcxx/include/__format/container_adaptor.h+3-3
......@@ -37,8 +37,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3737template <class _Adaptor, class _CharT>
3838struct _LIBCPP_TEMPLATE_VIS __formatter_container_adaptor {
3939private:
40 using __maybe_const_container = __fmt_maybe_const<typename _Adaptor::container_type, _CharT>;
41 using __maybe_const_adaptor = __maybe_const<is_const_v<__maybe_const_container>, _Adaptor>;
40 using __maybe_const_container _LIBCPP_NODEBUG = __fmt_maybe_const<typename _Adaptor::container_type, _CharT>;
41 using __maybe_const_adaptor _LIBCPP_NODEBUG = __maybe_const<is_const_v<__maybe_const_container>, _Adaptor>;
4242 formatter<ranges::ref_view<__maybe_const_container>, _CharT> __underlying_;
4343
4444public:
......@@ -66,7 +66,7 @@ template <class _CharT, class _Tp, formattable<_CharT> _Container>
6666struct _LIBCPP_TEMPLATE_VIS formatter<stack<_Tp, _Container>, _CharT>
6767 : public __formatter_container_adaptor<stack<_Tp, _Container>, _CharT> {};
6868
69#endif //_LIBCPP_STD_VER >= 23
69#endif // _LIBCPP_STD_VER >= 23
7070
7171_LIBCPP_END_NAMESPACE_STD
7272
lib/libcxx/include/__format/enable_insertable.h+1-1
......@@ -28,7 +28,7 @@ inline constexpr bool __enable_insertable = false;
2828
2929} // namespace __format
3030
31#endif //_LIBCPP_STD_VER >= 20
31#endif // _LIBCPP_STD_VER >= 20
3232
3333_LIBCPP_END_NAMESPACE_STD
3434
lib/libcxx/include/__format/escaped_output_table.h+2-2
......@@ -63,7 +63,7 @@
6363
6464#include <__algorithm/ranges_upper_bound.h>
6565#include <__config>
66#include <cstddef>
66#include <__cstddef/ptrdiff_t.h>
6767#include <cstdint>
6868
6969#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -856,7 +856,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
856856// clang-format on
857857} // namespace __escaped_output_table
858858
859#endif //_LIBCPP_STD_VER >= 23
859#endif // _LIBCPP_STD_VER >= 23
860860
861861_LIBCPP_END_NAMESPACE_STD
862862
lib/libcxx/include/__format/extended_grapheme_cluster_table.h+2-2
......@@ -63,8 +63,8 @@
6363
6464#include <__algorithm/ranges_upper_bound.h>
6565#include <__config>
66#include <__cstddef/ptrdiff_t.h>
6667#include <__iterator/access.h>
67#include <cstddef>
6868#include <cstdint>
6969
7070#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -1656,7 +1656,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = {
16561656
16571657} // namespace __extended_grapheme_custer_property_boundary
16581658
1659#endif //_LIBCPP_STD_VER >= 20
1659#endif // _LIBCPP_STD_VER >= 20
16601660
16611661_LIBCPP_END_NAMESPACE_STD
16621662
lib/libcxx/include/__format/format_arg.h+19-18
......@@ -13,6 +13,7 @@
1313#include <__assert>
1414#include <__concepts/arithmetic.h>
1515#include <__config>
16#include <__cstddef/size_t.h>
1617#include <__format/concepts.h>
1718#include <__format/format_parse_context.h>
1819#include <__functional/invoke.h>
......@@ -113,7 +114,7 @@ _LIBCPP_HIDE_FROM_ABI decltype(auto) __visit_format_arg(_Visitor&& __vis, basic_
113114 case __format::__arg_t::__long_long:
114115 return std::invoke(std::forward<_Visitor>(__vis), __arg.__value_.__long_long_);
115116 case __format::__arg_t::__i128:
116# ifndef _LIBCPP_HAS_NO_INT128
117# if _LIBCPP_HAS_INT128
117118 return std::invoke(std::forward<_Visitor>(__vis), __arg.__value_.__i128_);
118119# else
119120 __libcpp_unreachable();
......@@ -123,7 +124,7 @@ _LIBCPP_HIDE_FROM_ABI decltype(auto) __visit_format_arg(_Visitor&& __vis, basic_
123124 case __format::__arg_t::__unsigned_long_long:
124125 return std::invoke(std::forward<_Visitor>(__vis), __arg.__value_.__unsigned_long_long_);
125126 case __format::__arg_t::__u128:
126# ifndef _LIBCPP_HAS_NO_INT128
127# if _LIBCPP_HAS_INT128
127128 return std::invoke(std::forward<_Visitor>(__vis), __arg.__value_.__u128_);
128129# else
129130 __libcpp_unreachable();
......@@ -148,7 +149,7 @@ _LIBCPP_HIDE_FROM_ABI decltype(auto) __visit_format_arg(_Visitor&& __vis, basic_
148149 __libcpp_unreachable();
149150}
150151
151# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
152# if _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
152153
153154template <class _Rp, class _Visitor, class _Context>
154155_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<
164165 case __format::__arg_t::__long_long:
165166 return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__long_long_);
166167 case __format::__arg_t::__i128:
167# ifndef _LIBCPP_HAS_NO_INT128
168# if _LIBCPP_HAS_INT128
168169 return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__i128_);
169170# else
170171 __libcpp_unreachable();
......@@ -174,7 +175,7 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<
174175 case __format::__arg_t::__unsigned_long_long:
175176 return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__unsigned_long_long_);
176177 case __format::__arg_t::__u128:
177# ifndef _LIBCPP_HAS_NO_INT128
178# if _LIBCPP_HAS_INT128
178179 return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__u128_);
179180# else
180181 __libcpp_unreachable();
......@@ -199,7 +200,7 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<
199200 __libcpp_unreachable();
200201}
201202
202# endif // _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
203# endif // _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
203204
204205/// Contains the values used in basic_format_arg.
205206///
......@@ -207,7 +208,7 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<
207208/// separate arrays.
208209template <class _Context>
209210class __basic_format_arg_value {
210 using _CharT = typename _Context::char_type;
211 using _CharT _LIBCPP_NODEBUG = typename _Context::char_type;
211212
212213public:
213214 /// Contains the implementation for basic_format_arg::handle.
......@@ -237,7 +238,7 @@ public:
237238 unsigned __unsigned_;
238239 long long __long_long_;
239240 unsigned long long __unsigned_long_long_;
240# ifndef _LIBCPP_HAS_NO_INT128
241# if _LIBCPP_HAS_INT128
241242 __int128_t __i128_;
242243 __uint128_t __u128_;
243244# endif
......@@ -261,7 +262,7 @@ public:
261262 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(long long __value) noexcept : __long_long_(__value) {}
262263 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(unsigned long long __value) noexcept
263264 : __unsigned_long_long_(__value) {}
264# ifndef _LIBCPP_HAS_NO_INT128
265# if _LIBCPP_HAS_INT128
265266 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(__int128_t __value) noexcept : __i128_(__value) {}
266267 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(__uint128_t __value) noexcept : __u128_(__value) {}
267268# endif
......@@ -276,7 +277,7 @@ public:
276277};
277278
278279template <class _Context>
279class _LIBCPP_TEMPLATE_VIS basic_format_arg {
280class _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS basic_format_arg {
280281public:
281282 class _LIBCPP_TEMPLATE_VIS handle;
282283
......@@ -284,14 +285,14 @@ public:
284285
285286 _LIBCPP_HIDE_FROM_ABI explicit operator bool() const noexcept { return __type_ != __format::__arg_t::__none; }
286287
287# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
288# if _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
288289
289290 // This function is user facing, so it must wrap the non-standard types of
290291 // the "variant" in a handle to stay conforming. See __arg_t for more details.
291292 template <class _Visitor>
292293 _LIBCPP_HIDE_FROM_ABI decltype(auto) visit(this basic_format_arg __arg, _Visitor&& __vis) {
293294 switch (__arg.__type_) {
294# ifndef _LIBCPP_HAS_NO_INT128
295# if _LIBCPP_HAS_INT128
295296 case __format::__arg_t::__i128: {
296297 typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__i128_};
297298 return std::invoke(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h});
......@@ -312,7 +313,7 @@ public:
312313 template <class _Rp, class _Visitor>
313314 _LIBCPP_HIDE_FROM_ABI _Rp visit(this basic_format_arg __arg, _Visitor&& __vis) {
314315 switch (__arg.__type_) {
315# ifndef _LIBCPP_HAS_NO_INT128
316# if _LIBCPP_HAS_INT128
316317 case __format::__arg_t::__i128: {
317318 typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__i128_};
318319 return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h});
......@@ -328,7 +329,7 @@ public:
328329 }
329330 }
330331
331# endif // _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
332# endif // _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
332333
333334private:
334335 using char_type = typename _Context::char_type;
......@@ -370,13 +371,13 @@ private:
370371// This function is user facing, so it must wrap the non-standard types of
371372// the "variant" in a handle to stay conforming. See __arg_t for more details.
372373template <class _Visitor, class _Context>
373# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
374# if _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
374375_LIBCPP_DEPRECATED_IN_CXX26
375376# endif
376377 _LIBCPP_HIDE_FROM_ABI decltype(auto)
377378 visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
378379 switch (__arg.__type_) {
379# ifndef _LIBCPP_HAS_NO_INT128
380# if _LIBCPP_HAS_INT128
380381 case __format::__arg_t::__i128: {
381382 typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__i128_};
382383 return std::invoke(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h});
......@@ -386,13 +387,13 @@ _LIBCPP_DEPRECATED_IN_CXX26
386387 typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__u128_};
387388 return std::invoke(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h});
388389 }
389# endif // _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
390# endif // _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
390391 default:
391392 return std::__visit_format_arg(std::forward<_Visitor>(__vis), __arg);
392393 }
393394}
394395
395#endif //_LIBCPP_STD_VER >= 20
396#endif // _LIBCPP_STD_VER >= 20
396397
397398_LIBCPP_END_NAMESPACE_STD
398399
lib/libcxx/include/__format/format_arg_store.h+12-6
......@@ -22,6 +22,7 @@
2222#include <__type_traits/conditional.h>
2323#include <__type_traits/extent.h>
2424#include <__type_traits/remove_const.h>
25#include <cstdint>
2526#include <string>
2627#include <string_view>
2728
......@@ -48,7 +49,7 @@ template <class _Context, same_as<typename _Context::char_type> _Tp>
4849consteval __arg_t __determine_arg_t() {
4950 return __arg_t::__char_type;
5051}
51# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
52# if _LIBCPP_HAS_WIDE_CHARACTERS
5253template <class _Context, class _CharT>
5354 requires(same_as<typename _Context::char_type, wchar_t> && same_as<_CharT, char>)
5455consteval __arg_t __determine_arg_t() {
......@@ -63,7 +64,7 @@ consteval __arg_t __determine_arg_t() {
6364 return __arg_t::__int;
6465 else if constexpr (sizeof(_Tp) <= sizeof(long long))
6566 return __arg_t::__long_long;
66# ifndef _LIBCPP_HAS_NO_INT128
67# if _LIBCPP_HAS_INT128
6768 else if constexpr (sizeof(_Tp) == sizeof(__int128_t))
6869 return __arg_t::__i128;
6970# endif
......@@ -78,7 +79,7 @@ consteval __arg_t __determine_arg_t() {
7879 return __arg_t::__unsigned;
7980 else if constexpr (sizeof(_Tp) <= sizeof(unsigned long long))
8081 return __arg_t::__unsigned_long_long;
81# ifndef _LIBCPP_HAS_NO_INT128
82# if _LIBCPP_HAS_INT128
8283 else if constexpr (sizeof(_Tp) == sizeof(__uint128_t))
8384 return __arg_t::__u128;
8485# endif
......@@ -172,7 +173,7 @@ _LIBCPP_HIDE_FROM_ABI basic_format_arg<_Context> __create_format_arg(_Tp& __valu
172173 // final else requires no adjustment.
173174 if constexpr (__arg == __arg_t::__char_type)
174175
175# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
176# if _LIBCPP_HAS_WIDE_CHARACTERS
176177 if constexpr (same_as<typename _Context::char_type, wchar_t> && same_as<_Dp, char>)
177178 return basic_format_arg<_Context>{__arg, static_cast<wchar_t>(static_cast<unsigned char>(__value))};
178179 else
......@@ -233,6 +234,11 @@ struct __packed_format_arg_store {
233234 uint64_t __types_ = 0;
234235};
235236
237template <class _Context>
238struct __packed_format_arg_store<_Context, 0> {
239 uint64_t __types_ = 0;
240};
241
236242template <class _Context, size_t _Np>
237243struct __unpacked_format_arg_store {
238244 basic_format_arg<_Context> __args_[_Np];
......@@ -251,7 +257,7 @@ struct _LIBCPP_TEMPLATE_VIS __format_arg_store {
251257 }
252258 }
253259
254 using _Storage =
260 using _Storage _LIBCPP_NODEBUG =
255261 conditional_t<__format::__use_packed_format_arg_store(sizeof...(_Args)),
256262 __format::__packed_format_arg_store<_Context, sizeof...(_Args)>,
257263 __format::__unpacked_format_arg_store<_Context, sizeof...(_Args)>>;
......@@ -259,7 +265,7 @@ struct _LIBCPP_TEMPLATE_VIS __format_arg_store {
259265 _Storage __storage;
260266};
261267
262#endif //_LIBCPP_STD_VER >= 20
268#endif // _LIBCPP_STD_VER >= 20
263269
264270_LIBCPP_END_NAMESPACE_STD
265271
lib/libcxx/include/__format/format_args.h+2-2
......@@ -11,10 +11,10 @@
1111#define _LIBCPP___FORMAT_FORMAT_ARGS_H
1212
1313#include <__config>
14#include <__cstddef/size_t.h>
1415#include <__format/format_arg.h>
1516#include <__format/format_arg_store.h>
1617#include <__fwd/format.h>
17#include <cstddef>
1818#include <cstdint>
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -71,7 +71,7 @@ private:
7171template <class _Context, class... _Args>
7272basic_format_args(__format_arg_store<_Context, _Args...>) -> basic_format_args<_Context>;
7373
74#endif //_LIBCPP_STD_VER >= 20
74#endif // _LIBCPP_STD_VER >= 20
7575
7676_LIBCPP_END_NAMESPACE_STD
7777
lib/libcxx/include/__format/format_context.h+12-12
......@@ -23,9 +23,8 @@
2323#include <__memory/addressof.h>
2424#include <__utility/move.h>
2525#include <__variant/monostate.h>
26#include <cstddef>
2726
28#ifndef _LIBCPP_HAS_NO_LOCALIZATION
27#if _LIBCPP_HAS_LOCALIZATION
2928# include <__locale>
3029# include <optional>
3130#endif
......@@ -45,7 +44,7 @@ template <class _OutIt, class _CharT>
4544 requires output_iterator<_OutIt, const _CharT&>
4645class _LIBCPP_TEMPLATE_VIS basic_format_context;
4746
48# ifndef _LIBCPP_HAS_NO_LOCALIZATION
47# if _LIBCPP_HAS_LOCALIZATION
4948/**
5049 * Helper to create a basic_format_context.
5150 *
......@@ -67,7 +66,7 @@ __format_context_create(_OutIt __out_it, basic_format_args<basic_format_context<
6766# endif
6867
6968using format_context = basic_format_context<back_insert_iterator<__format::__output_buffer<char>>, char>;
70# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
69# if _LIBCPP_HAS_WIDE_CHARACTERS
7170using wformat_context = basic_format_context< back_insert_iterator<__format::__output_buffer<wchar_t>>, wchar_t>;
7271# endif
7372
......@@ -89,7 +88,7 @@ public:
8988 _LIBCPP_HIDE_FROM_ABI basic_format_arg<basic_format_context> arg(size_t __id) const noexcept {
9089 return __args_.get(__id);
9190 }
92# ifndef _LIBCPP_HAS_NO_LOCALIZATION
91# if _LIBCPP_HAS_LOCALIZATION
9392 _LIBCPP_HIDE_FROM_ABI std::locale locale() {
9493 if (!__loc_)
9594 __loc_ = std::locale{};
......@@ -102,7 +101,7 @@ public:
102101private:
103102 iterator __out_it_;
104103 basic_format_args<basic_format_context> __args_;
105# ifndef _LIBCPP_HAS_NO_LOCALIZATION
104# if _LIBCPP_HAS_LOCALIZATION
106105
107106 // The Standard doesn't specify how the locale is stored.
108107 // [format.context]/6
......@@ -132,6 +131,7 @@ private:
132131 : __out_it_(std::move(__out_it)), __args_(__args) {}
133132# endif
134133
134public:
135135 basic_format_context(const basic_format_context&) = delete;
136136 basic_format_context& operator=(const basic_format_context&) = delete;
137137};
......@@ -163,7 +163,7 @@ public:
163163 template <class _Context>
164164 _LIBCPP_HIDE_FROM_ABI explicit basic_format_context(iterator __out_it, _Context& __ctx)
165165 : __out_it_(std::move(__out_it)),
166# ifndef _LIBCPP_HAS_NO_LOCALIZATION
166# if _LIBCPP_HAS_LOCALIZATION
167167 __loc_([](void* __c) { return static_cast<_Context*>(__c)->locale(); }),
168168# endif
169169 __ctx_(std::addressof(__ctx)),
......@@ -180,20 +180,20 @@ public:
180180 __format::__determine_arg_t<basic_format_context, decltype(__arg)>(),
181181 __basic_format_arg_value<basic_format_context>(__arg)};
182182 };
183# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
183# if _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
184184 return static_cast<_Context*>(__c)->arg(__id).visit(std::move(__visitor));
185185# else
186186 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
187187 return std::visit_format_arg(std::move(__visitor), static_cast<_Context*>(__c)->arg(__id));
188188 _LIBCPP_SUPPRESS_DEPRECATED_POP
189# endif // _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
189# endif // _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
190190 }) {
191191 }
192192
193193 _LIBCPP_HIDE_FROM_ABI basic_format_arg<basic_format_context> arg(size_t __id) const noexcept {
194194 return __arg_(__ctx_, __id);
195195 }
196# ifndef _LIBCPP_HAS_NO_LOCALIZATION
196# if _LIBCPP_HAS_LOCALIZATION
197197 _LIBCPP_HIDE_FROM_ABI std::locale locale() { return __loc_(__ctx_); }
198198# endif
199199 _LIBCPP_HIDE_FROM_ABI iterator out() { return std::move(__out_it_); }
......@@ -202,7 +202,7 @@ public:
202202private:
203203 iterator __out_it_;
204204
205# ifndef _LIBCPP_HAS_NO_LOCALIZATION
205# if _LIBCPP_HAS_LOCALIZATION
206206 std::locale (*__loc_)(void* __ctx);
207207# endif
208208
......@@ -211,7 +211,7 @@ private:
211211};
212212
213213_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(basic_format_context);
214#endif //_LIBCPP_STD_VER >= 20
214#endif // _LIBCPP_STD_VER >= 20
215215
216216_LIBCPP_END_NAMESPACE_STD
217217
lib/libcxx/include/__format/format_error.h+3-3
......@@ -35,15 +35,15 @@ public:
3535};
3636_LIBCPP_DIAGNOSTIC_POP
3737
38_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_format_error(const char* __s) {
39# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
38[[noreturn]] inline _LIBCPP_HIDE_FROM_ABI void __throw_format_error(const char* __s) {
39# if _LIBCPP_HAS_EXCEPTIONS
4040 throw format_error(__s);
4141# else
4242 _LIBCPP_VERBOSE_ABORT("format_error was thrown in -fno-exceptions mode with message \"%s\"", __s);
4343# endif
4444}
4545
46#endif //_LIBCPP_STD_VER >= 20
46#endif // _LIBCPP_STD_VER >= 20
4747
4848_LIBCPP_END_NAMESPACE_STD
4949
lib/libcxx/include/__format/format_functions.h+38-39
......@@ -31,7 +31,6 @@
3131#include <__format/formatter_pointer.h>
3232#include <__format/formatter_string.h>
3333#include <__format/parser_std_format_spec.h>
34#include <__iterator/back_insert_iterator.h>
3534#include <__iterator/concepts.h>
3635#include <__iterator/incrementable_traits.h>
3736#include <__iterator/iterator_traits.h> // iter_value_t
......@@ -40,7 +39,7 @@
4039#include <string>
4140#include <string_view>
4241
43#ifndef _LIBCPP_HAS_NO_LOCALIZATION
42#if _LIBCPP_HAS_LOCALIZATION
4443# include <__locale>
4544#endif
4645
......@@ -61,7 +60,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
6160// to do this optimization now.
6261
6362using format_args = basic_format_args<format_context>;
64# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
63# if _LIBCPP_HAS_WIDE_CHARACTERS
6564using wformat_args = basic_format_args<wformat_context>;
6665# endif
6766
......@@ -70,7 +69,7 @@ template <class _Context = format_context, class... _Args>
7069 return std::__format_arg_store<_Context, _Args...>(__args...);
7170}
7271
73# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
72# if _LIBCPP_HAS_WIDE_CHARACTERS
7473template <class... _Args>
7574[[nodiscard]] _LIBCPP_HIDE_FROM_ABI __format_arg_store<wformat_context, _Args...> make_wformat_args(_Args&... __args) {
7675 return std::__format_arg_store<wformat_context, _Args...>(__args...);
......@@ -206,7 +205,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr void __compile_time_visit_format_arg(
206205 case __arg_t::__long_long:
207206 return __format::__compile_time_validate_argument<_CharT, long long>(__parse_ctx, __ctx);
208207 case __arg_t::__i128:
209# ifndef _LIBCPP_HAS_NO_INT128
208# if _LIBCPP_HAS_INT128
210209 return __format::__compile_time_validate_argument<_CharT, __int128_t>(__parse_ctx, __ctx);
211210# else
212211 std::__throw_format_error("Invalid argument");
......@@ -217,7 +216,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr void __compile_time_visit_format_arg(
217216 case __arg_t::__unsigned_long_long:
218217 return __format::__compile_time_validate_argument<_CharT, unsigned long long>(__parse_ctx, __ctx);
219218 case __arg_t::__u128:
220# ifndef _LIBCPP_HAS_NO_INT128
219# if _LIBCPP_HAS_INT128
221220 return __format::__compile_time_validate_argument<_CharT, __uint128_t>(__parse_ctx, __ctx);
222221# else
223222 std::__throw_format_error("Invalid argument");
......@@ -355,12 +354,12 @@ public:
355354};
356355
357356_LIBCPP_HIDE_FROM_ABI inline __runtime_format_string<char> runtime_format(string_view __fmt) noexcept { return __fmt; }
358# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
357# if _LIBCPP_HAS_WIDE_CHARACTERS
359358_LIBCPP_HIDE_FROM_ABI inline __runtime_format_string<wchar_t> runtime_format(wstring_view __fmt) noexcept {
360359 return __fmt;
361360}
362361# endif
363# endif //_LIBCPP_STD_VER >= 26
362# endif // _LIBCPP_STD_VER >= 26
364363
365364template <class _CharT, class... _Args>
366365struct _LIBCPP_TEMPLATE_VIS basic_format_string {
......@@ -379,7 +378,7 @@ struct _LIBCPP_TEMPLATE_VIS basic_format_string {
379378private:
380379 basic_string_view<_CharT> __str_;
381380
382 using _Context = __format::__compile_time_basic_format_context<_CharT>;
381 using _Context _LIBCPP_NODEBUG = __format::__compile_time_basic_format_context<_CharT>;
383382
384383 static constexpr array<__format::__arg_t, sizeof...(_Args)> __types_{
385384 __format::__determine_arg_t<_Context, remove_cvref_t<_Args>>()...};
......@@ -397,7 +396,7 @@ private:
397396template <class... _Args>
398397using format_string = basic_format_string<char, type_identity_t<_Args>...>;
399398
400# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
399# if _LIBCPP_HAS_WIDE_CHARACTERS
401400template <class... _Args>
402401using wformat_string = basic_format_string<wchar_t, type_identity_t<_Args>...>;
403402# endif
......@@ -411,7 +410,7 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __vformat_to(_OutIt __out_it,
411410 return std::__format::__vformat_to(
412411 basic_format_parse_context{__fmt, __args.__size()}, std::__format_context_create(std::move(__out_it), __args));
413412 else {
414 __format::__format_buffer<_OutIt, _CharT> __buffer{std::move(__out_it)};
413 typename __format::__buffer_selector<_OutIt, _CharT>::type __buffer{std::move(__out_it)};
415414 std::__format::__vformat_to(basic_format_parse_context{__fmt, __args.__size()},
416415 std::__format_context_create(__buffer.__make_output_iterator(), __args));
417416 return std::move(__buffer).__out_it();
......@@ -426,7 +425,7 @@ _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt vformat_to(_OutIt __out_it, s
426425 return std::__vformat_to(std::move(__out_it), __fmt, __args);
427426}
428427
429# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
428# if _LIBCPP_HAS_WIDE_CHARACTERS
430429template <output_iterator<const wchar_t&> _OutIt>
431430_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
432431vformat_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) {
440439 return std::vformat_to(std::move(__out_it), __fmt.get(), std::make_format_args(__args...));
441440}
442441
443# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
442# if _LIBCPP_HAS_WIDE_CHARACTERS
444443template <output_iterator<const wchar_t&> _OutIt, class... _Args>
445444_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
446445format_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) {
452451// fires too eagerly, see http://llvm.org/PR61563.
453452template <class = void>
454453[[nodiscard]] _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI string vformat(string_view __fmt, format_args __args) {
455 string __res;
456 std::vformat_to(std::back_inserter(__res), __fmt, __args);
457 return __res;
454 __format::__allocating_buffer<char> __buffer;
455 std::vformat_to(__buffer.__make_output_iterator(), __fmt, __args);
456 return string{__buffer.__view()};
458457}
459458
460# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
459# if _LIBCPP_HAS_WIDE_CHARACTERS
461460// TODO FMT This needs to be a template or std::to_chars(floating-point) availability markup
462461// fires too eagerly, see http://llvm.org/PR61563.
463462template <class = void>
464463[[nodiscard]] _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI wstring
465464vformat(wstring_view __fmt, wformat_args __args) {
466 wstring __res;
467 std::vformat_to(std::back_inserter(__res), __fmt, __args);
468 return __res;
465 __format::__allocating_buffer<wchar_t> __buffer;
466 std::vformat_to(__buffer.__make_output_iterator(), __fmt, __args);
467 return wstring{__buffer.__view()};
469468}
470469# endif
471470
......@@ -475,7 +474,7 @@ format(format_string<_Args...> __fmt, _Args&&... __args) {
475474 return std::vformat(__fmt.get(), std::make_format_args(__args...));
476475}
477476
478# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
477# if _LIBCPP_HAS_WIDE_CHARACTERS
479478template <class... _Args>
480479[[nodiscard]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI wstring
481480format(wformat_string<_Args...> __fmt, _Args&&... __args) {
......@@ -501,7 +500,7 @@ format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, format_string<_Args.
501500 return std::__vformat_to_n<format_context>(std::move(__out_it), __n, __fmt.get(), std::make_format_args(__args...));
502501}
503502
504# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
503# if _LIBCPP_HAS_WIDE_CHARACTERS
505504template <output_iterator<const wchar_t&> _OutIt, class... _Args>
506505_LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt>
507506format_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) {
523522 return std::__vformatted_size(__fmt.get(), basic_format_args{std::make_format_args(__args...)});
524523}
525524
526# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
525# if _LIBCPP_HAS_WIDE_CHARACTERS
527526template <class... _Args>
528527[[nodiscard]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI size_t
529528formatted_size(wformat_string<_Args...> __fmt, _Args&&... __args) {
......@@ -531,7 +530,7 @@ formatted_size(wformat_string<_Args...> __fmt, _Args&&... __args) {
531530}
532531# endif
533532
534# ifndef _LIBCPP_HAS_NO_LOCALIZATION
533# if _LIBCPP_HAS_LOCALIZATION
535534
536535template <class _OutIt, class _CharT, class _FormatOutIt>
537536 requires(output_iterator<_OutIt, const _CharT&>)
......@@ -544,7 +543,7 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __vformat_to(
544543 return std::__format::__vformat_to(basic_format_parse_context{__fmt, __args.__size()},
545544 std::__format_context_create(std::move(__out_it), __args, std::move(__loc)));
546545 else {
547 __format::__format_buffer<_OutIt, _CharT> __buffer{std::move(__out_it)};
546 typename __format::__buffer_selector<_OutIt, _CharT>::type __buffer{std::move(__out_it)};
548547 std::__format::__vformat_to(
549548 basic_format_parse_context{__fmt, __args.__size()},
550549 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)
558557 return std::__vformat_to(std::move(__out_it), std::move(__loc), __fmt, __args);
559558}
560559
561# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
560# if _LIBCPP_HAS_WIDE_CHARACTERS
562561template <output_iterator<const wchar_t&> _OutIt>
563562_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
564563vformat_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&&.
572571 return std::vformat_to(std::move(__out_it), std::move(__loc), __fmt.get(), std::make_format_args(__args...));
573572}
574573
575# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
574# if _LIBCPP_HAS_WIDE_CHARACTERS
576575template <output_iterator<const wchar_t&> _OutIt, class... _Args>
577576_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt
578577format_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&&
585584template <class = void>
586585[[nodiscard]] _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI string
587586vformat(locale __loc, string_view __fmt, format_args __args) {
588 string __res;
589 std::vformat_to(std::back_inserter(__res), std::move(__loc), __fmt, __args);
590 return __res;
587 __format::__allocating_buffer<char> __buffer;
588 std::vformat_to(__buffer.__make_output_iterator(), std::move(__loc), __fmt, __args);
589 return string{__buffer.__view()};
591590}
592591
593# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
592# if _LIBCPP_HAS_WIDE_CHARACTERS
594593// TODO FMT This needs to be a template or std::to_chars(floating-point) availability markup
595594// fires too eagerly, see http://llvm.org/PR61563.
596595template <class = void>
597596[[nodiscard]] _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI wstring
598597vformat(locale __loc, wstring_view __fmt, wformat_args __args) {
599 wstring __res;
600 std::vformat_to(std::back_inserter(__res), std::move(__loc), __fmt, __args);
601 return __res;
598 __format::__allocating_buffer<wchar_t> __buffer;
599 std::vformat_to(__buffer.__make_output_iterator(), std::move(__loc), __fmt, __args);
600 return wstring{__buffer.__view()};
602601}
603602# endif
604603
......@@ -608,7 +607,7 @@ format(locale __loc, format_string<_Args...> __fmt, _Args&&... __args) {
608607 return std::vformat(std::move(__loc), __fmt.get(), std::make_format_args(__args...));
609608}
610609
611# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
610# if _LIBCPP_HAS_WIDE_CHARACTERS
612611template <class... _Args>
613612[[nodiscard]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI wstring
614613format(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
637636 std::move(__out_it), __n, std::move(__loc), __fmt.get(), std::make_format_args(__args...));
638637}
639638
640# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
639# if _LIBCPP_HAS_WIDE_CHARACTERS
641640template <output_iterator<const wchar_t&> _OutIt, class... _Args>
642641_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> format_to_n(
643642 _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) {
661660 return std::__vformatted_size(std::move(__loc), __fmt.get(), basic_format_args{std::make_format_args(__args...)});
662661}
663662
664# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
663# if _LIBCPP_HAS_WIDE_CHARACTERS
665664template <class... _Args>
666665[[nodiscard]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI size_t
667666formatted_size(locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) {
......@@ -669,9 +668,9 @@ formatted_size(locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args)
669668}
670669# endif
671670
672# endif // _LIBCPP_HAS_NO_LOCALIZATION
671# endif // _LIBCPP_HAS_LOCALIZATION
673672
674#endif //_LIBCPP_STD_VER >= 20
673#endif // _LIBCPP_STD_VER >= 20
675674
676675_LIBCPP_END_NAMESPACE_STD
677676
lib/libcxx/include/__format/format_parse_context.h+2-2
......@@ -94,11 +94,11 @@ private:
9494_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(basic_format_parse_context);
9595
9696using format_parse_context = basic_format_parse_context<char>;
97# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
97# if _LIBCPP_HAS_WIDE_CHARACTERS
9898using wformat_parse_context = basic_format_parse_context<wchar_t>;
9999# endif
100100
101#endif //_LIBCPP_STD_VER >= 20
101#endif // _LIBCPP_STD_VER >= 20
102102
103103_LIBCPP_END_NAMESPACE_STD
104104
lib/libcxx/include/__format/format_string.h+2-2
......@@ -12,10 +12,10 @@
1212
1313#include <__assert>
1414#include <__config>
15#include <__cstddef/size_t.h>
1516#include <__format/format_error.h>
1617#include <__iterator/concepts.h>
1718#include <__iterator/iterator_traits.h> // iter_value_t
18#include <cstddef>
1919#include <cstdint>
2020
2121#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -153,7 +153,7 @@ __parse_arg_id(_Iterator __begin, _Iterator __end, auto& __parse_ctx) {
153153
154154} // namespace __format
155155
156#endif //_LIBCPP_STD_VER >= 20
156#endif // _LIBCPP_STD_VER >= 20
157157
158158_LIBCPP_END_NAMESPACE_STD
159159
lib/libcxx/include/__format/format_to_n_result.h+1-1
......@@ -28,7 +28,7 @@ struct _LIBCPP_TEMPLATE_VIS format_to_n_result {
2828};
2929_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(format_to_n_result);
3030
31#endif //_LIBCPP_STD_VER >= 20
31#endif // _LIBCPP_STD_VER >= 20
3232
3333_LIBCPP_END_NAMESPACE_STD
3434
lib/libcxx/include/__format/formatter.h+3
......@@ -39,6 +39,9 @@ struct _LIBCPP_TEMPLATE_VIS formatter {
3939
4040# if _LIBCPP_STD_VER >= 23
4141
42template <class _Tp>
43constexpr bool enable_nonlocking_formatter_optimization = false;
44
4245template <class _Tp>
4346_LIBCPP_HIDE_FROM_ABI constexpr void __set_debug_format(_Tp& __formatter) {
4447 if constexpr (requires { __formatter.set_debug_format(); })
lib/libcxx/include/__format/formatter_bool.h+6-2
......@@ -20,7 +20,7 @@
2020#include <__format/parser_std_format_spec.h>
2121#include <__utility/unreachable.h>
2222
23#ifndef _LIBCPP_HAS_NO_LOCALIZATION
23#if _LIBCPP_HAS_LOCALIZATION
2424# include <__locale>
2525#endif
2626
......@@ -69,7 +69,11 @@ public:
6969 __format_spec::__parser<_CharT> __parser_;
7070};
7171
72#endif //_LIBCPP_STD_VER >= 20
72# if _LIBCPP_STD_VER >= 23
73template <>
74inline constexpr bool enable_nonlocking_formatter_optimization<bool> = true;
75# endif // _LIBCPP_STD_VER >= 23
76#endif // _LIBCPP_STD_VER >= 20
7377
7478_LIBCPP_END_NAMESPACE_STD
7579
lib/libcxx/include/__format/formatter_char.h+11-3
......@@ -77,16 +77,24 @@ public:
7777template <>
7878struct _LIBCPP_TEMPLATE_VIS formatter<char, char> : public __formatter_char<char> {};
7979
80# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
80# if _LIBCPP_HAS_WIDE_CHARACTERS
8181template <>
8282struct _LIBCPP_TEMPLATE_VIS formatter<char, wchar_t> : public __formatter_char<wchar_t> {};
8383
8484template <>
8585struct _LIBCPP_TEMPLATE_VIS formatter<wchar_t, wchar_t> : public __formatter_char<wchar_t> {};
86# endif // _LIBCPP_HAS_WIDE_CHARACTERS
8687
87# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
88# if _LIBCPP_STD_VER >= 23
89template <>
90inline constexpr bool enable_nonlocking_formatter_optimization<char> = true;
91# if _LIBCPP_HAS_WIDE_CHARACTERS
92template <>
93inline constexpr bool enable_nonlocking_formatter_optimization<wchar_t> = true;
94# endif // _LIBCPP_HAS_WIDE_CHARACTERS
95# endif // _LIBCPP_STD_VER >= 23
8896
89#endif //_LIBCPP_STD_VER >= 20
97#endif // _LIBCPP_STD_VER >= 20
9098
9199_LIBCPP_END_NAMESPACE_STD
92100
lib/libcxx/include/__format/formatter_floating_point.h+15-7
......@@ -23,6 +23,7 @@
2323#include <__concepts/arithmetic.h>
2424#include <__concepts/same_as.h>
2525#include <__config>
26#include <__cstddef/ptrdiff_t.h>
2627#include <__format/concepts.h>
2728#include <__format/format_parse_context.h>
2829#include <__format/formatter.h>
......@@ -36,9 +37,8 @@
3637#include <__utility/move.h>
3738#include <__utility/unreachable.h>
3839#include <cmath>
39#include <cstddef>
4040
41#ifndef _LIBCPP_HAS_NO_LOCALIZATION
41#if _LIBCPP_HAS_LOCALIZATION
4242# include <__locale>
4343#endif
4444
......@@ -141,7 +141,7 @@ struct __traits<double> {
141141/// on the stack or the heap.
142142template <floating_point _Fp>
143143class _LIBCPP_TEMPLATE_VIS __float_buffer {
144 using _Traits = __traits<_Fp>;
144 using _Traits _LIBCPP_NODEBUG = __traits<_Fp>;
145145
146146public:
147147 // TODO FMT Improve this constructor to do a better estimate.
......@@ -491,7 +491,7 @@ _LIBCPP_HIDE_FROM_ABI __float_result __format_buffer(
491491 }
492492}
493493
494# ifndef _LIBCPP_HAS_NO_LOCALIZATION
494# if _LIBCPP_HAS_LOCALIZATION
495495template <class _OutIt, class _Fp, class _CharT>
496496_LIBCPP_HIDE_FROM_ABI _OutIt __format_locale_specific_form(
497497 _OutIt __out_it,
......@@ -576,7 +576,7 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __format_locale_specific_form(
576576 // alignment
577577 return __formatter::__fill(std::move(__out_it), __padding.__after_, __specs.__fill_);
578578}
579# endif // _LIBCPP_HAS_NO_LOCALIZATION
579# endif // _LIBCPP_HAS_LOCALIZATION
580580
581581template <class _OutIt, class _CharT>
582582_LIBCPP_HIDE_FROM_ABI _OutIt __format_floating_point_non_finite(
......@@ -705,7 +705,7 @@ __format_floating_point(_Tp __value, _FormatContext& __ctx, __format_spec::__par
705705 }
706706 }
707707
708# ifndef _LIBCPP_HAS_NO_LOCALIZATION
708# if _LIBCPP_HAS_LOCALIZATION
709709 if (__specs.__std_.__locale_specific_form_)
710710 return __formatter::__format_locale_specific_form(__ctx.out(), __buffer, __result, __ctx.locale(), __specs);
711711# endif
......@@ -774,7 +774,15 @@ struct _LIBCPP_TEMPLATE_VIS formatter<double, _CharT> : public __formatter_float
774774template <__fmt_char_type _CharT>
775775struct _LIBCPP_TEMPLATE_VIS formatter<long double, _CharT> : public __formatter_floating_point<_CharT> {};
776776
777#endif //_LIBCPP_STD_VER >= 20
777# if _LIBCPP_STD_VER >= 23
778template <>
779inline constexpr bool enable_nonlocking_formatter_optimization<float> = true;
780template <>
781inline constexpr bool enable_nonlocking_formatter_optimization<double> = true;
782template <>
783inline constexpr bool enable_nonlocking_formatter_optimization<long double> = true;
784# endif // _LIBCPP_STD_VER >= 23
785#endif // _LIBCPP_STD_VER >= 20
778786
779787_LIBCPP_END_NAMESPACE_STD
780788
lib/libcxx/include/__format/formatter_integer.h+34-3
......@@ -67,7 +67,7 @@ template <__fmt_char_type _CharT>
6767struct _LIBCPP_TEMPLATE_VIS formatter<long, _CharT> : public __formatter_integer<_CharT> {};
6868template <__fmt_char_type _CharT>
6969struct _LIBCPP_TEMPLATE_VIS formatter<long long, _CharT> : public __formatter_integer<_CharT> {};
70# ifndef _LIBCPP_HAS_NO_INT128
70# if _LIBCPP_HAS_INT128
7171template <__fmt_char_type _CharT>
7272struct _LIBCPP_TEMPLATE_VIS formatter<__int128_t, _CharT> : public __formatter_integer<_CharT> {};
7373# endif
......@@ -83,12 +83,43 @@ template <__fmt_char_type _CharT>
8383struct _LIBCPP_TEMPLATE_VIS formatter<unsigned long, _CharT> : public __formatter_integer<_CharT> {};
8484template <__fmt_char_type _CharT>
8585struct _LIBCPP_TEMPLATE_VIS formatter<unsigned long long, _CharT> : public __formatter_integer<_CharT> {};
86# ifndef _LIBCPP_HAS_NO_INT128
86# if _LIBCPP_HAS_INT128
8787template <__fmt_char_type _CharT>
8888struct _LIBCPP_TEMPLATE_VIS formatter<__uint128_t, _CharT> : public __formatter_integer<_CharT> {};
8989# endif
9090
91#endif //_LIBCPP_STD_VER >= 20
91# if _LIBCPP_STD_VER >= 23
92template <>
93inline constexpr bool enable_nonlocking_formatter_optimization<signed char> = true;
94template <>
95inline constexpr bool enable_nonlocking_formatter_optimization<short> = true;
96template <>
97inline constexpr bool enable_nonlocking_formatter_optimization<int> = true;
98template <>
99inline constexpr bool enable_nonlocking_formatter_optimization<long> = true;
100template <>
101inline constexpr bool enable_nonlocking_formatter_optimization<long long> = true;
102# if _LIBCPP_HAS_INT128
103template <>
104inline constexpr bool enable_nonlocking_formatter_optimization<__int128_t> = true;
105# endif
106
107template <>
108inline constexpr bool enable_nonlocking_formatter_optimization<unsigned char> = true;
109template <>
110inline constexpr bool enable_nonlocking_formatter_optimization<unsigned short> = true;
111template <>
112inline constexpr bool enable_nonlocking_formatter_optimization<unsigned> = true;
113template <>
114inline constexpr bool enable_nonlocking_formatter_optimization<unsigned long> = true;
115template <>
116inline constexpr bool enable_nonlocking_formatter_optimization<unsigned long long> = true;
117# if _LIBCPP_HAS_INT128
118template <>
119inline constexpr bool enable_nonlocking_formatter_optimization<__uint128_t> = true;
120# endif
121# endif // _LIBCPP_STD_VER >= 23
122#endif // _LIBCPP_STD_VER >= 20
92123
93124_LIBCPP_END_NAMESPACE_STD
94125
lib/libcxx/include/__format/formatter_integral.h+6-5
......@@ -27,11 +27,12 @@
2727#include <__type_traits/make_unsigned.h>
2828#include <__utility/unreachable.h>
2929#include <array>
30#include <cstdint>
3031#include <limits>
3132#include <string>
3233#include <string_view>
3334
34#ifndef _LIBCPP_HAS_NO_LOCALIZATION
35#if _LIBCPP_HAS_LOCALIZATION
3536# include <__locale>
3637#endif
3738
......@@ -297,7 +298,7 @@ _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator __format_integer(
297298
298299 _Iterator __last = __formatter::__to_buffer(__first, __end, __value, __base);
299300
300# ifndef _LIBCPP_HAS_NO_LOCALIZATION
301# if _LIBCPP_HAS_LOCALIZATION
301302 if (__specs.__std_.__locale_specific_form_) {
302303 const auto& __np = std::use_facet<numpunct<_CharT>>(__ctx.locale());
303304 string __grouping = __np.grouping();
......@@ -411,7 +412,7 @@ struct _LIBCPP_TEMPLATE_VIS __bool_strings<char> {
411412 static constexpr string_view __false{"false"};
412413};
413414
414# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
415# if _LIBCPP_HAS_WIDE_CHARACTERS
415416template <>
416417struct _LIBCPP_TEMPLATE_VIS __bool_strings<wchar_t> {
417418 static constexpr wstring_view __true{L"true"};
......@@ -422,7 +423,7 @@ struct _LIBCPP_TEMPLATE_VIS __bool_strings<wchar_t> {
422423template <class _CharT, class _FormatContext>
423424_LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator
424425__format_bool(bool __value, _FormatContext& __ctx, __format_spec::__parsed_specifications<_CharT> __specs) {
425# ifndef _LIBCPP_HAS_NO_LOCALIZATION
426# if _LIBCPP_HAS_LOCALIZATION
426427 if (__specs.__std_.__locale_specific_form_) {
427428 const auto& __np = std::use_facet<numpunct<_CharT>>(__ctx.locale());
428429 basic_string<_CharT> __str = __value ? __np.truename() : __np.falsename();
......@@ -436,7 +437,7 @@ __format_bool(bool __value, _FormatContext& __ctx, __format_spec::__parsed_speci
436437
437438} // namespace __formatter
438439
439#endif //_LIBCPP_STD_VER >= 20
440#endif // _LIBCPP_STD_VER >= 20
440441
441442_LIBCPP_END_NAMESPACE_STD
442443
lib/libcxx/include/__format/formatter_output.h+9-9
......@@ -16,6 +16,8 @@
1616#include <__bit/countl.h>
1717#include <__concepts/same_as.h>
1818#include <__config>
19#include <__cstddef/ptrdiff_t.h>
20#include <__cstddef/size_t.h>
1921#include <__format/buffer.h>
2022#include <__format/concepts.h>
2123#include <__format/formatter.h>
......@@ -28,7 +30,6 @@
2830#include <__memory/pointer_traits.h>
2931#include <__utility/move.h>
3032#include <__utility/unreachable.h>
31#include <cstddef>
3233#include <string_view>
3334
3435#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)
168169 }
169170}
170171
171# ifndef _LIBCPP_HAS_NO_UNICODE
172# if _LIBCPP_HAS_UNICODE
172173template <__fmt_char_type _CharT, output_iterator<const _CharT&> _OutIt>
173174 requires(same_as<_CharT, char>)
174175_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::
182183 return __out_it;
183184}
184185
185# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
186# if _LIBCPP_HAS_WIDE_CHARACTERS
186187template <__fmt_char_type _CharT, output_iterator<const _CharT&> _OutIt>
187188 requires(same_as<_CharT, wchar_t> && sizeof(wchar_t) == 2)
188189_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<const _CharT&> _OutIt>
200201_LIBCPP_HIDE_FROM_ABI _OutIt __fill(_OutIt __out_it, size_t __n, __format_spec::__code_point<_CharT> __value) {
201202 return __formatter::__fill(std::move(__out_it), __n, __value.__data[0]);
202203}
203# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
204# else // _LIBCPP_HAS_NO_UNICODE
204# endif // _LIBCPP_HAS_WIDE_CHARACTERS
205# else // _LIBCPP_HAS_UNICODE
205206template <__fmt_char_type _CharT, output_iterator<const _CharT&> _OutIt>
206207_LIBCPP_HIDE_FROM_ABI _OutIt __fill(_OutIt __out_it, size_t __n, __format_spec::__code_point<_CharT> __value) {
207208 return __formatter::__fill(std::move(__out_it), __n, __value.__data[0]);
208209}
209# endif // _LIBCPP_HAS_NO_UNICODE
210# endif // _LIBCPP_HAS_UNICODE
210211
211212/// Writes the input to the output with the required padding.
212213///
......@@ -294,8 +295,7 @@ _LIBCPP_HIDE_FROM_ABI auto __write_transformed(
294295///
295296/// \pre !__specs.__has_precision()
296297///
297/// \note When \c _LIBCPP_HAS_NO_UNICODE is defined the function assumes the
298/// input is ASCII.
298/// \note When \c _LIBCPP_HAS_UNICODE is false the function assumes the input is ASCII.
299299template <class _CharT>
300300_LIBCPP_HIDE_FROM_ABI auto __write_string_no_precision(
301301 basic_string_view<_CharT> __str,
......@@ -326,7 +326,7 @@ _LIBCPP_HIDE_FROM_ABI int __truncate(basic_string_view<_CharT>& __str, int __pre
326326
327327} // namespace __formatter
328328
329#endif //_LIBCPP_STD_VER >= 20
329#endif // _LIBCPP_STD_VER >= 20
330330
331331_LIBCPP_END_NAMESPACE_STD
332332
lib/libcxx/include/__format/formatter_pointer.h+10-2
......@@ -11,13 +11,13 @@
1111#define _LIBCPP___FORMAT_FORMATTER_POINTER_H
1212
1313#include <__config>
14#include <__cstddef/nullptr_t.h>
1415#include <__format/concepts.h>
1516#include <__format/format_parse_context.h>
1617#include <__format/formatter.h>
1718#include <__format/formatter_integral.h>
1819#include <__format/formatter_output.h>
1920#include <__format/parser_std_format_spec.h>
20#include <cstddef>
2121#include <cstdint>
2222
2323#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -65,7 +65,15 @@ struct _LIBCPP_TEMPLATE_VIS formatter<void*, _CharT> : public __formatter_pointe
6565template <__fmt_char_type _CharT>
6666struct _LIBCPP_TEMPLATE_VIS formatter<const void*, _CharT> : public __formatter_pointer<_CharT> {};
6767
68#endif //_LIBCPP_STD_VER >= 20
68# if _LIBCPP_STD_VER >= 23
69template <>
70inline constexpr bool enable_nonlocking_formatter_optimization<nullptr_t> = true;
71template <>
72inline constexpr bool enable_nonlocking_formatter_optimization<void*> = true;
73template <>
74inline constexpr bool enable_nonlocking_formatter_optimization<const void*> = true;
75# endif // _LIBCPP_STD_VER >= 23
76#endif // _LIBCPP_STD_VER >= 20
6977
7078_LIBCPP_END_NAMESPACE_STD
7179
lib/libcxx/include/__format/formatter_string.h+38-31
......@@ -59,44 +59,26 @@ public:
5959// Formatter const char*.
6060template <__fmt_char_type _CharT>
6161struct _LIBCPP_TEMPLATE_VIS formatter<const _CharT*, _CharT> : public __formatter_string<_CharT> {
62 using _Base = __formatter_string<_CharT>;
62 using _Base _LIBCPP_NODEBUG = __formatter_string<_CharT>;
6363
6464 template <class _FormatContext>
6565 _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(const _CharT* __str, _FormatContext& __ctx) const {
6666 _LIBCPP_ASSERT_INTERNAL(__str, "The basic_format_arg constructor should have prevented an invalid pointer.");
67
68 __format_spec::__parsed_specifications<_CharT> __specs = _Base::__parser_.__get_parsed_std_specifications(__ctx);
69# if _LIBCPP_STD_VER >= 23
70 if (_Base::__parser_.__type_ == __format_spec::__type::__debug)
71 return __formatter::__format_escaped_string(basic_string_view<_CharT>{__str}, __ctx.out(), __specs);
72# endif
73
74 // When using a center or right alignment and the width option the length
75 // of __str must be known to add the padding upfront. This case is handled
76 // by the base class by converting the argument to a basic_string_view.
67 // Converting the input to a basic_string_view means the data is looped over twice;
68 // - once to determine the length, and
69 // - once to process the data.
7770 //
78 // When using left alignment and the width option the padding is added
79 // after outputting __str so the length can be determined while outputting
80 // __str. The same holds true for the precision, during outputting __str it
81 // can be validated whether the precision threshold has been reached. For
82 // now these optimizations aren't implemented. Instead the base class
83 // handles these options.
84 // TODO FMT Implement these improvements.
85 if (__specs.__has_width() || __specs.__has_precision())
86 return __formatter::__write_string(basic_string_view<_CharT>{__str}, __ctx.out(), __specs);
87
88 // No formatting required, copy the string to the output.
89 auto __out_it = __ctx.out();
90 while (*__str)
91 *__out_it++ = *__str++;
92 return __out_it;
71 // This sounds slower than writing the output directly. However internally
72 // the output algorithms have optimizations for "bulk" operations, which
73 // makes this faster than a single-pass character-by-character output.
74 return _Base::format(basic_string_view<_CharT>(__str), __ctx);
9375 }
9476};
9577
9678// Formatter char*.
9779template <__fmt_char_type _CharT>
9880struct _LIBCPP_TEMPLATE_VIS formatter<_CharT*, _CharT> : public formatter<const _CharT*, _CharT> {
99 using _Base = formatter<const _CharT*, _CharT>;
81 using _Base _LIBCPP_NODEBUG = formatter<const _CharT*, _CharT>;
10082
10183 template <class _FormatContext>
10284 _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<const
10789// Formatter char[].
10890template <__fmt_char_type _CharT, size_t _Size>
10991struct _LIBCPP_TEMPLATE_VIS formatter<_CharT[_Size], _CharT> : public __formatter_string<_CharT> {
110 using _Base = __formatter_string<_CharT>;
92 using _Base _LIBCPP_NODEBUG = __formatter_string<_CharT>;
11193
11294 template <class _FormatContext>
11395 _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator
......@@ -120,7 +102,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<_CharT[_Size], _CharT> : public __formatte
120102template <__fmt_char_type _CharT, class _Traits, class _Allocator>
121103struct _LIBCPP_TEMPLATE_VIS formatter<basic_string<_CharT, _Traits, _Allocator>, _CharT>
122104 : public __formatter_string<_CharT> {
123 using _Base = __formatter_string<_CharT>;
105 using _Base _LIBCPP_NODEBUG = __formatter_string<_CharT>;
124106
125107 template <class _FormatContext>
126108 _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator
......@@ -133,7 +115,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<basic_string<_CharT, _Traits, _Allocator>,
133115// Formatter std::string_view.
134116template <__fmt_char_type _CharT, class _Traits>
135117struct _LIBCPP_TEMPLATE_VIS formatter<basic_string_view<_CharT, _Traits>, _CharT> : public __formatter_string<_CharT> {
136 using _Base = __formatter_string<_CharT>;
118 using _Base _LIBCPP_NODEBUG = __formatter_string<_CharT>;
137119
138120 template <class _FormatContext>
139121 _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator
......@@ -143,7 +125,32 @@ struct _LIBCPP_TEMPLATE_VIS formatter<basic_string_view<_CharT, _Traits>, _CharT
143125 }
144126};
145127
146#endif //_LIBCPP_STD_VER >= 20
128# if _LIBCPP_STD_VER >= 23
129template <>
130inline constexpr bool enable_nonlocking_formatter_optimization<char*> = true;
131template <>
132inline constexpr bool enable_nonlocking_formatter_optimization<const char*> = true;
133template <size_t _Size>
134inline constexpr bool enable_nonlocking_formatter_optimization<char[_Size]> = true;
135template <class _Traits, class _Allocator>
136inline constexpr bool enable_nonlocking_formatter_optimization<basic_string<char, _Traits, _Allocator>> = true;
137template <class _Traits>
138inline constexpr bool enable_nonlocking_formatter_optimization<basic_string_view<char, _Traits>> = true;
139
140# if _LIBCPP_HAS_WIDE_CHARACTERS
141template <>
142inline constexpr bool enable_nonlocking_formatter_optimization<wchar_t*> = true;
143template <>
144inline constexpr bool enable_nonlocking_formatter_optimization<const wchar_t*> = true;
145template <size_t _Size>
146inline constexpr bool enable_nonlocking_formatter_optimization<wchar_t[_Size]> = true;
147template <class _Traits, class _Allocator>
148inline constexpr bool enable_nonlocking_formatter_optimization<basic_string<wchar_t, _Traits, _Allocator>> = true;
149template <class _Traits>
150inline constexpr bool enable_nonlocking_formatter_optimization<basic_string_view<wchar_t, _Traits>> = true;
151# endif // _LIBCPP_HAS_WIDE_CHARACTERS
152# endif // _LIBCPP_STD_VER >= 23
153#endif // _LIBCPP_STD_VER >= 20
147154
148155_LIBCPP_END_NAMESPACE_STD
149156
lib/libcxx/include/__format/formatter_tuple.h+1-1
......@@ -143,7 +143,7 @@ template <__fmt_char_type _CharT, formattable<_CharT>... _Args>
143143struct _LIBCPP_TEMPLATE_VIS formatter<tuple<_Args...>, _CharT>
144144 : public __formatter_tuple<_CharT, tuple<_Args...>, _Args...> {};
145145
146#endif //_LIBCPP_STD_VER >= 23
146#endif // _LIBCPP_STD_VER >= 23
147147
148148_LIBCPP_END_NAMESPACE_STD
149149
lib/libcxx/include/__format/indic_conjunct_break_table.h+2-2
......@@ -63,8 +63,8 @@
6363
6464#include <__algorithm/ranges_upper_bound.h>
6565#include <__config>
66#include <__cstddef/ptrdiff_t.h>
6667#include <__iterator/access.h>
67#include <cstddef>
6868#include <cstdint>
6969
7070#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -343,7 +343,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[201] = {
343343
344344} // namespace __indic_conjunct_break
345345
346#endif //_LIBCPP_STD_VER >= 20
346#endif // _LIBCPP_STD_VER >= 20
347347
348348_LIBCPP_END_NAMESPACE_STD
349349
lib/libcxx/include/__format/parser_std_format_spec.h+15-15
......@@ -52,13 +52,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD
5252
5353namespace __format_spec {
5454
55_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI inline void
55[[noreturn]] _LIBCPP_HIDE_FROM_ABI inline void
5656__throw_invalid_option_format_error(const char* __id, const char* __option) {
5757 std::__throw_format_error(
5858 (string("The format specifier for ") + __id + " does not allow the " + __option + " option").c_str());
5959}
6060
61_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI inline void __throw_invalid_type_format_error(const char* __id) {
61[[noreturn]] _LIBCPP_HIDE_FROM_ABI inline void __throw_invalid_type_format_error(const char* __id) {
6262 std::__throw_format_error(
6363 (string("The type option contains an invalid value for ") + __id + " formatting argument").c_str());
6464}
......@@ -268,7 +268,7 @@ struct __code_point<char> {
268268 char __data[4] = {' '};
269269};
270270
271# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
271# if _LIBCPP_HAS_WIDE_CHARACTERS
272272template <>
273273struct __code_point<wchar_t> {
274274 wchar_t __data[4 / sizeof(wchar_t)] = {L' '};
......@@ -321,7 +321,7 @@ struct __parsed_specifications {
321321// value in formatting functions.
322322static_assert(sizeof(__parsed_specifications<char>) == 16);
323323static_assert(is_trivially_copyable_v<__parsed_specifications<char>>);
324# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
324# if _LIBCPP_HAS_WIDE_CHARACTERS
325325static_assert(sizeof(__parsed_specifications<wchar_t>) == 16);
326326static_assert(is_trivially_copyable_v<__parsed_specifications<wchar_t>>);
327327# endif
......@@ -580,11 +580,11 @@ private:
580580 std::__throw_format_error("The fill option contains an invalid value");
581581 }
582582
583# ifndef _LIBCPP_HAS_NO_UNICODE
583# if _LIBCPP_HAS_UNICODE
584584 // range-fill and tuple-fill are identical
585585 template <contiguous_iterator _Iterator>
586586 requires same_as<_CharT, char>
587# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
587# if _LIBCPP_HAS_WIDE_CHARACTERS
588588 || (same_as<_CharT, wchar_t> && sizeof(wchar_t) == 2)
589589# endif
590590 _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_fill_align(_Iterator& __begin, _Iterator __end) {
......@@ -617,7 +617,7 @@ private:
617617 return true;
618618 }
619619
620# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
620# if _LIBCPP_HAS_WIDE_CHARACTERS
621621 template <contiguous_iterator _Iterator>
622622 requires(same_as<_CharT, wchar_t> && sizeof(wchar_t) == 4)
623623 _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_fill_align(_Iterator& __begin, _Iterator __end) {
......@@ -643,9 +643,9 @@ private:
643643 return true;
644644 }
645645
646# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
646# endif // _LIBCPP_HAS_WIDE_CHARACTERS
647647
648# else // _LIBCPP_HAS_NO_UNICODE
648# else // _LIBCPP_HAS_UNICODE
649649 // range-fill and tuple-fill are identical
650650 template <contiguous_iterator _Iterator>
651651 _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_fill_align(_Iterator& __begin, _Iterator __end) {
......@@ -670,7 +670,7 @@ private:
670670 return true;
671671 }
672672
673# endif // _LIBCPP_HAS_NO_UNICODE
673# endif // _LIBCPP_HAS_UNICODE
674674
675675 template <contiguous_iterator _Iterator>
676676 _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_sign(_Iterator& __begin) {
......@@ -874,7 +874,7 @@ private:
874874
875875// Validates whether the reserved bitfields don't change the size.
876876static_assert(sizeof(__parser<char>) == 16);
877# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
877# if _LIBCPP_HAS_WIDE_CHARACTERS
878878static_assert(sizeof(__parser<wchar_t>) == 16);
879879# endif
880880
......@@ -1026,7 +1026,7 @@ __column_width_result(size_t, _Iterator) -> __column_width_result<_Iterator>;
10261026/// "rounded up".
10271027enum class __column_width_rounding { __down, __up };
10281028
1029# ifndef _LIBCPP_HAS_NO_UNICODE
1029# if _LIBCPP_HAS_UNICODE
10301030
10311031namespace __detail {
10321032template <contiguous_iterator _Iterator>
......@@ -1148,7 +1148,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr __column_width_result<_Iterator> __estimate_colu
11481148 __result.__width_ += __ascii_size;
11491149 return __result;
11501150}
1151# else // !defined(_LIBCPP_HAS_NO_UNICODE)
1151# else // _LIBCPP_HAS_UNICODE
11521152template <class _CharT>
11531153_LIBCPP_HIDE_FROM_ABI constexpr __column_width_result<typename basic_string_view<_CharT>::const_iterator>
11541154__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
11591159 return {__width, __str.begin() + __width};
11601160}
11611161
1162# endif // !defined(_LIBCPP_HAS_NO_UNICODE)
1162# endif // _LIBCPP_HAS_UNICODE
11631163
11641164} // namespace __format_spec
11651165
1166#endif //_LIBCPP_STD_VER >= 20
1166#endif // _LIBCPP_STD_VER >= 20
11671167
11681168_LIBCPP_END_NAMESPACE_STD
11691169
lib/libcxx/include/__format/range_default_formatter.h+7-7
......@@ -40,7 +40,7 @@ concept __const_formattable_range =
4040 ranges::input_range<const _Rp> && formattable<ranges::range_reference_t<const _Rp>, _CharT>;
4141
4242template <class _Rp, class _CharT>
43using __fmt_maybe_const = conditional_t<__const_formattable_range<_Rp, _CharT>, const _Rp, _Rp>;
43using __fmt_maybe_const _LIBCPP_NODEBUG = conditional_t<__const_formattable_range<_Rp, _CharT>, const _Rp, _Rp>;
4444
4545_LIBCPP_DIAGNOSTIC_PUSH
4646_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wshadow")
......@@ -95,7 +95,7 @@ struct _LIBCPP_TEMPLATE_VIS __range_default_formatter;
9595template <ranges::input_range _Rp, class _CharT>
9696struct _LIBCPP_TEMPLATE_VIS __range_default_formatter<range_format::sequence, _Rp, _CharT> {
9797private:
98 using __maybe_const_r = __fmt_maybe_const<_Rp, _CharT>;
98 using __maybe_const_r _LIBCPP_NODEBUG = __fmt_maybe_const<_Rp, _CharT>;
9999 range_formatter<remove_cvref_t<ranges::range_reference_t<__maybe_const_r>>, _CharT> __underlying_;
100100
101101public:
......@@ -122,8 +122,8 @@ public:
122122template <ranges::input_range _Rp, class _CharT>
123123struct _LIBCPP_TEMPLATE_VIS __range_default_formatter<range_format::map, _Rp, _CharT> {
124124private:
125 using __maybe_const_map = __fmt_maybe_const<_Rp, _CharT>;
126 using __element_type = remove_cvref_t<ranges::range_reference_t<__maybe_const_map>>;
125 using __maybe_const_map _LIBCPP_NODEBUG = __fmt_maybe_const<_Rp, _CharT>;
126 using __element_type _LIBCPP_NODEBUG = remove_cvref_t<ranges::range_reference_t<__maybe_const_map>>;
127127 range_formatter<__element_type, _CharT> __underlying_;
128128
129129public:
......@@ -150,8 +150,8 @@ public:
150150template <ranges::input_range _Rp, class _CharT>
151151struct _LIBCPP_TEMPLATE_VIS __range_default_formatter<range_format::set, _Rp, _CharT> {
152152private:
153 using __maybe_const_set = __fmt_maybe_const<_Rp, _CharT>;
154 using __element_type = remove_cvref_t<ranges::range_reference_t<__maybe_const_set>>;
153 using __maybe_const_set _LIBCPP_NODEBUG = __fmt_maybe_const<_Rp, _CharT>;
154 using __element_type _LIBCPP_NODEBUG = remove_cvref_t<ranges::range_reference_t<__maybe_const_set>>;
155155 range_formatter<__element_type, _CharT> __underlying_;
156156
157157public:
......@@ -207,7 +207,7 @@ template <ranges::input_range _Rp, class _CharT>
207207 requires(format_kind<_Rp> != range_format::disabled && formattable<ranges::range_reference_t<_Rp>, _CharT>)
208208struct _LIBCPP_TEMPLATE_VIS formatter<_Rp, _CharT> : __range_default_formatter<format_kind<_Rp>, _Rp, _CharT> {};
209209
210#endif //_LIBCPP_STD_VER >= 23
210#endif // _LIBCPP_STD_VER >= 23
211211
212212_LIBCPP_END_NAMESPACE_STD
213213
lib/libcxx/include/__format/range_formatter.h+1-1
......@@ -257,7 +257,7 @@ private:
257257 basic_string_view<_CharT> __closing_bracket_ = _LIBCPP_STATICALLY_WIDEN(_CharT, "]");
258258};
259259
260#endif //_LIBCPP_STD_VER >= 23
260#endif // _LIBCPP_STD_VER >= 23
261261
262262_LIBCPP_END_NAMESPACE_STD
263263
lib/libcxx/include/__format/unicode.h+13-13
......@@ -54,7 +54,7 @@ struct __consume_result {
5454};
5555static_assert(sizeof(__consume_result) == sizeof(char32_t));
5656
57# ifndef _LIBCPP_HAS_NO_UNICODE
57# if _LIBCPP_HAS_UNICODE
5858
5959/// Implements the grapheme cluster boundary rules
6060///
......@@ -123,7 +123,7 @@ class __code_point_view;
123123/// UTF-8 specialization.
124124template <>
125125class __code_point_view<char> {
126 using _Iterator = basic_string_view<char>::const_iterator;
126 using _Iterator _LIBCPP_NODEBUG = basic_string_view<char>::const_iterator;
127127
128128public:
129129 _LIBCPP_HIDE_FROM_ABI constexpr explicit __code_point_view(_Iterator __first, _Iterator __last)
......@@ -235,7 +235,7 @@ private:
235235 _Iterator __last_;
236236};
237237
238# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
238# if _LIBCPP_HAS_WIDE_CHARACTERS
239239_LIBCPP_HIDE_FROM_ABI constexpr bool __is_surrogate_pair_high(wchar_t __value) {
240240 return __value >= 0xd800 && __value <= 0xdbff;
241241}
......@@ -249,7 +249,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __is_surrogate_pair_low(wchar_t __value) {
249249/// - 4 UTF-32 (for example Linux)
250250template <>
251251class __code_point_view<wchar_t> {
252 using _Iterator = typename basic_string_view<wchar_t>::const_iterator;
252 using _Iterator _LIBCPP_NODEBUG = typename basic_string_view<wchar_t>::const_iterator;
253253
254254public:
255255 static_assert(sizeof(wchar_t) == 2 || sizeof(wchar_t) == 4, "sizeof(wchar_t) has a not implemented value");
......@@ -292,7 +292,7 @@ private:
292292 _Iterator __first_;
293293 _Iterator __last_;
294294};
295# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
295# endif // _LIBCPP_HAS_WIDE_CHARACTERS
296296
297297// State machine to implement the Extended Grapheme Cluster Boundary
298298//
......@@ -300,8 +300,8 @@ private:
300300// This implements the extended rules see
301301// https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries
302302class __extended_grapheme_cluster_break {
303 using __EGC_property = __extended_grapheme_custer_property_boundary::__property;
304 using __inCB_property = __indic_conjunct_break::__property;
303 using __EGC_property _LIBCPP_NODEBUG = __extended_grapheme_custer_property_boundary::__property;
304 using __inCB_property _LIBCPP_NODEBUG = __indic_conjunct_break::__property;
305305
306306public:
307307 _LIBCPP_HIDE_FROM_ABI constexpr explicit __extended_grapheme_cluster_break(char32_t __first_code_point)
......@@ -527,7 +527,7 @@ private:
527527/// Therefore only this code point is extracted.
528528template <class _CharT>
529529class __extended_grapheme_cluster_view {
530 using _Iterator = typename basic_string_view<_CharT>::const_iterator;
530 using _Iterator _LIBCPP_NODEBUG = typename basic_string_view<_CharT>::const_iterator;
531531
532532public:
533533 _LIBCPP_HIDE_FROM_ABI constexpr explicit __extended_grapheme_cluster_view(_Iterator __first, _Iterator __last)
......@@ -566,13 +566,13 @@ private:
566566template <contiguous_iterator _Iterator>
567567__extended_grapheme_cluster_view(_Iterator, _Iterator) -> __extended_grapheme_cluster_view<iter_value_t<_Iterator>>;
568568
569# else // _LIBCPP_HAS_NO_UNICODE
569# else // _LIBCPP_HAS_UNICODE
570570
571571// For ASCII every character is a "code point".
572// This makes it easier to write code agnostic of the _LIBCPP_HAS_NO_UNICODE define.
572// This makes it easier to write code agnostic of the _LIBCPP_HAS_UNICODE define.
573573template <class _CharT>
574574class __code_point_view {
575 using _Iterator = typename basic_string_view<_CharT>::const_iterator;
575 using _Iterator _LIBCPP_NODEBUG = typename basic_string_view<_CharT>::const_iterator;
576576
577577public:
578578 _LIBCPP_HIDE_FROM_ABI constexpr explicit __code_point_view(_Iterator __first, _Iterator __last)
......@@ -591,11 +591,11 @@ private:
591591 _Iterator __last_;
592592};
593593
594# endif // _LIBCPP_HAS_NO_UNICODE
594# endif // _LIBCPP_HAS_UNICODE
595595
596596} // namespace __unicode
597597
598#endif //_LIBCPP_STD_VER >= 20
598#endif // _LIBCPP_STD_VER >= 20
599599
600600_LIBCPP_END_NAMESPACE_STD
601601
lib/libcxx/include/__format/width_estimation_table.h+2-2
......@@ -63,7 +63,7 @@
6363
6464#include <__algorithm/ranges_upper_bound.h>
6565#include <__config>
66#include <cstddef>
66#include <__cstddef/ptrdiff_t.h>
6767#include <cstdint>
6868
6969#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -263,7 +263,7 @@ inline constexpr uint32_t __table_upper_bound = 0x0003fffd;
263263
264264} // namespace __width_estimation_table
265265
266#endif //_LIBCPP_STD_VER >= 20
266#endif // _LIBCPP_STD_VER >= 20
267267
268268_LIBCPP_END_NAMESPACE_STD
269269
lib/libcxx/include/__format/write_escaped.h+3-3
......@@ -16,6 +16,7 @@
1616#include <__charconv/to_chars_result.h>
1717#include <__chrono/statically_widen.h>
1818#include <__format/escaped_output_table.h>
19#include <__format/extended_grapheme_cluster_table.h>
1920#include <__format/formatter_output.h>
2021#include <__format/parser_std_format_spec.h>
2122#include <__format/unicode.h>
......@@ -41,8 +42,7 @@ namespace __formatter {
4142
4243/// Writes a string using format's width estimation algorithm.
4344///
44/// \note When \c _LIBCPP_HAS_NO_UNICODE is defined the function assumes the
45/// input is ASCII.
45/// \note When \c _LIBCPP_HAS_UNICODE is false the function assumes the input is ASCII.
4646template <class _CharT>
4747_LIBCPP_HIDE_FROM_ABI auto
4848__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
103103template <class _CharT>
104104[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool
105105__is_escaped_sequence_written(basic_string<_CharT>& __str, bool __last_escaped, char32_t __value) {
106# ifdef _LIBCPP_HAS_NO_UNICODE
106# if !_LIBCPP_HAS_UNICODE
107107 // For ASCII assume everything above 127 is printable.
108108 if (__value > 127)
109109 return false;
lib/libcxx/include/__functional/binary_function.h+2-2
......@@ -42,11 +42,11 @@ struct __binary_function_keep_layout_base {
4242_LIBCPP_DIAGNOSTIC_PUSH
4343_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
4444template <class _Arg1, class _Arg2, class _Result>
45using __binary_function = binary_function<_Arg1, _Arg2, _Result>;
45using __binary_function _LIBCPP_NODEBUG = binary_function<_Arg1, _Arg2, _Result>;
4646_LIBCPP_DIAGNOSTIC_POP
4747#else
4848template <class _Arg1, class _Arg2, class _Result>
49using __binary_function = __binary_function_keep_layout_base<_Arg1, _Arg2, _Result>;
49using __binary_function _LIBCPP_NODEBUG = __binary_function_keep_layout_base<_Arg1, _Arg2, _Result>;
5050#endif
5151
5252_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__functional/bind.h+12-15
......@@ -11,13 +11,12 @@
1111#define _LIBCPP___FUNCTIONAL_BIND_H
1212
1313#include <__config>
14#include <__functional/invoke.h>
1514#include <__functional/weak_result_type.h>
1615#include <__fwd/functional.h>
1716#include <__type_traits/decay.h>
17#include <__type_traits/invoke.h>
1818#include <__type_traits/is_reference_wrapper.h>
1919#include <__type_traits/is_void.h>
20#include <cstddef>
2120#include <tuple>
2221
2322#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
8382}
8483
8584template <class _Ti, class... _Uj, size_t... _Indx>
86inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __invoke_of<_Ti&, _Uj...>::type
85inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t<_Ti&, _Uj...>
8786__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) {
8887 return __ti(std::forward<_Uj>(std::get<_Indx>(__uj))...);
8988}
9089
9190template <class _Ti, class... _Uj, __enable_if_t<is_bind_expression<_Ti>::value, int> = 0>
92inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __invoke_of<_Ti&, _Uj...>::type
91inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t<_Ti&, _Uj...>
9392__mu(_Ti& __ti, tuple<_Uj...>& __uj) {
9493 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
9594 return std::__mu_expand(__ti, __uj, __indices());
......@@ -131,12 +130,12 @@ struct __mu_return_invokable // false
131130
132131template <class _Ti, class... _Uj>
133132struct __mu_return_invokable<true, _Ti, _Uj...> {
134 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
133 using type = __invoke_result_t<_Ti&, _Uj...>;
135134};
136135
137136template <class _Ti, class... _Uj>
138137struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> >
139 : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> {};
138 : public __mu_return_invokable<__is_invocable_v<_Ti&, _Uj...>, _Ti, _Uj...> {};
140139
141140template <class _Ti, class _TupleUj>
142141struct __mu_return_impl<_Ti, false, false, true, _TupleUj> {
......@@ -169,12 +168,12 @@ struct __is_valid_bind_return {
169168
170169template <class _Fp, class... _BoundArgs, class _TupleUj>
171170struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> {
172 static const bool value = __invokable<_Fp, typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
171 static const bool value = __is_invocable_v<_Fp, typename __mu_return<_BoundArgs, _TupleUj>::type...>;
173172};
174173
175174template <class _Fp, class... _BoundArgs, class _TupleUj>
176175struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> {
177 static const bool value = __invokable<_Fp, typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
176 static const bool value = __is_invocable_v<_Fp, typename __mu_return<const _BoundArgs, _TupleUj>::type...>;
178177};
179178
180179template <class _Fp, class _BoundArgs, class _TupleUj, bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
......@@ -182,12 +181,12 @@ struct __bind_return;
182181
183182template <class _Fp, class... _BoundArgs, class _TupleUj>
184183struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> {
185 typedef typename __invoke_of< _Fp&, typename __mu_return< _BoundArgs, _TupleUj >::type... >::type type;
184 using type = __invoke_result_t< _Fp&, typename __mu_return< _BoundArgs, _TupleUj >::type... >;
186185};
187186
188187template <class _Fp, class... _BoundArgs, class _TupleUj>
189188struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> {
190 typedef typename __invoke_of< _Fp&, typename __mu_return< const _BoundArgs, _TupleUj >::type... >::type type;
189 using type = __invoke_result_t< _Fp&, typename __mu_return< const _BoundArgs, _TupleUj >::type... >;
191190};
192191
193192template <class _Fp, class _BoundArgs, size_t... _Indx, class _Args>
......@@ -199,7 +198,7 @@ __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, _
199198template <class _Fp, class... _BoundArgs>
200199class __bind : public __weak_result_type<__decay_t<_Fp> > {
201200protected:
202 using _Fd = __decay_t<_Fp>;
201 using _Fd _LIBCPP_NODEBUG = __decay_t<_Fp>;
203202 typedef tuple<__decay_t<_BoundArgs>...> _Td;
204203
205204private:
......@@ -257,8 +256,7 @@ public:
257256 is_void<_Rp>::value,
258257 int> = 0>
259258 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 result_type operator()(_Args&&... __args) {
260 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
261 return _Invoker::__call(static_cast<base&>(*this), std::forward<_Args>(__args)...);
259 return std::__invoke_r<_Rp>(static_cast<base&>(*this), std::forward<_Args>(__args)...);
262260 }
263261
264262 template <class... _Args,
......@@ -267,8 +265,7 @@ public:
267265 is_void<_Rp>::value,
268266 int> = 0>
269267 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 result_type operator()(_Args&&... __args) const {
270 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
271 return _Invoker::__call(static_cast<base const&>(*this), std::forward<_Args>(__args)...);
268 return std::__invoke_r<_Rp>(static_cast<base const&>(*this), std::forward<_Args>(__args)...);
272269 }
273270};
274271
lib/libcxx/include/__functional/boyer_moore_searcher.h+4-3
......@@ -22,9 +22,10 @@
2222#include <__memory/shared_ptr.h>
2323#include <__type_traits/make_unsigned.h>
2424#include <__utility/pair.h>
25#include <__vector/vector.h>
2526#include <array>
27#include <limits>
2628#include <unordered_map>
27#include <vector>
2829
2930#if _LIBCPP_STD_VER >= 17
3031
......@@ -91,7 +92,7 @@ class _LIBCPP_TEMPLATE_VIS boyer_moore_searcher {
9192private:
9293 using difference_type = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
9394 using value_type = typename std::iterator_traits<_RandomAccessIterator1>::value_type;
94 using __skip_table_type =
95 using __skip_table_type _LIBCPP_NODEBUG =
9596 _BMSkipTable<value_type,
9697 difference_type,
9798 _Hash,
......@@ -222,7 +223,7 @@ class _LIBCPP_TEMPLATE_VIS boyer_moore_horspool_searcher {
222223private:
223224 using difference_type = typename iterator_traits<_RandomAccessIterator1>::difference_type;
224225 using value_type = typename iterator_traits<_RandomAccessIterator1>::value_type;
225 using __skip_table_type =
226 using __skip_table_type _LIBCPP_NODEBUG =
226227 _BMSkipTable<value_type,
227228 difference_type,
228229 _Hash,
lib/libcxx/include/__functional/function.h+63-57
......@@ -12,6 +12,7 @@
1212
1313#include <__assert>
1414#include <__config>
15#include <__cstddef/nullptr_t.h>
1516#include <__exception/exception.h>
1617#include <__functional/binary_function.h>
1718#include <__functional/invoke.h>
......@@ -21,7 +22,6 @@
2122#include <__memory/allocator.h>
2223#include <__memory/allocator_destructor.h>
2324#include <__memory/allocator_traits.h>
24#include <__memory/builtin_new_allocator.h>
2525#include <__memory/compressed_pair.h>
2626#include <__memory/unique_ptr.h>
2727#include <__type_traits/aligned_storage.h>
......@@ -37,7 +37,6 @@
3737#include <__utility/piecewise_construct.h>
3838#include <__utility/swap.h>
3939#include <__verbose_abort>
40#include <new>
4140#include <tuple>
4241#include <typeinfo>
4342
......@@ -78,8 +77,8 @@ public:
7877};
7978_LIBCPP_DIAGNOSTIC_POP
8079
81_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_function_call() {
82# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
80[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_function_call() {
81# if _LIBCPP_HAS_EXCEPTIONS
8382 throw bad_function_call();
8483# else
8584 _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) {
123122 return !!__f;
124123}
125124
126# ifdef _LIBCPP_HAS_EXTENSION_BLOCKS
125# if _LIBCPP_HAS_EXTENSION_BLOCKS
127126template <class _Rp, class... _Args>
128127_LIBCPP_HIDE_FROM_ABI bool __not_null(_Rp (^__p)(_Args...)) {
129128 return __p;
......@@ -143,45 +142,45 @@ class __default_alloc_func;
143142
144143template <class _Fp, class _Ap, class _Rp, class... _ArgTypes>
145144class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> {
146 __compressed_pair<_Fp, _Ap> __f_;
145 _LIBCPP_COMPRESSED_PAIR(_Fp, __func_, _Ap, __alloc_);
147146
148147public:
149 typedef _LIBCPP_NODEBUG _Fp _Target;
150 typedef _LIBCPP_NODEBUG _Ap _Alloc;
148 using _Target _LIBCPP_NODEBUG = _Fp;
149 using _Alloc _LIBCPP_NODEBUG = _Ap;
151150
152 _LIBCPP_HIDE_FROM_ABI const _Target& __target() const { return __f_.first(); }
151 _LIBCPP_HIDE_FROM_ABI const _Target& __target() const { return __func_; }
153152
154153 // WIN32 APIs may define __allocator, so use __get_allocator instead.
155 _LIBCPP_HIDE_FROM_ABI const _Alloc& __get_allocator() const { return __f_.second(); }
154 _LIBCPP_HIDE_FROM_ABI const _Alloc& __get_allocator() const { return __alloc_; }
156155
157 _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(_Target&& __f)
158 : __f_(piecewise_construct, std::forward_as_tuple(std::move(__f)), std::forward_as_tuple()) {}
156 _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(_Target&& __f) : __func_(std::move(__f)), __alloc_() {}
159157
160 _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(const _Target& __f, const _Alloc& __a)
161 : __f_(piecewise_construct, std::forward_as_tuple(__f), std::forward_as_tuple(__a)) {}
158 _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(const _Target& __f, const _Alloc& __a) : __func_(__f), __alloc_(__a) {}
162159
163160 _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(const _Target& __f, _Alloc&& __a)
164 : __f_(piecewise_construct, std::forward_as_tuple(__f), std::forward_as_tuple(std::move(__a))) {}
161 : __func_(__f), __alloc_(std::move(__a)) {}
165162
166163 _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(_Target&& __f, _Alloc&& __a)
167 : __f_(piecewise_construct, std::forward_as_tuple(std::move(__f)), std::forward_as_tuple(std::move(__a))) {}
164 : __func_(std::move(__f)), __alloc_(std::move(__a)) {}
168165
169166 _LIBCPP_HIDE_FROM_ABI _Rp operator()(_ArgTypes&&... __arg) {
170 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
171 return _Invoker::__call(__f_.first(), std::forward<_ArgTypes>(__arg)...);
167 return std::__invoke_r<_Rp>(__func_, std::forward<_ArgTypes>(__arg)...);
172168 }
173169
174170 _LIBCPP_HIDE_FROM_ABI __alloc_func* __clone() const {
175171 typedef allocator_traits<_Alloc> __alloc_traits;
176172 typedef __rebind_alloc<__alloc_traits, __alloc_func> _AA;
177 _AA __a(__f_.second());
173 _AA __a(__alloc_);
178174 typedef __allocator_destructor<_AA> _Dp;
179175 unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
180 ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a));
176 ::new ((void*)__hold.get()) __alloc_func(__func_, _Alloc(__a));
181177 return __hold.release();
182178 }
183179
184 _LIBCPP_HIDE_FROM_ABI void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); }
180 _LIBCPP_HIDE_FROM_ABI void destroy() _NOEXCEPT {
181 __func_.~_Fp();
182 __alloc_.~_Alloc();
183 }
185184
186185 _LIBCPP_HIDE_FROM_ABI static void __destroy_and_delete(__alloc_func* __f) {
187186 typedef allocator_traits<_Alloc> __alloc_traits;
......@@ -192,12 +191,19 @@ public:
192191 }
193192};
194193
194template <class _Tp>
195struct __deallocating_deleter {
196 _LIBCPP_HIDE_FROM_ABI void operator()(void* __p) const {
197 std::__libcpp_deallocate<_Tp>(static_cast<_Tp*>(__p), __element_count(1));
198 }
199};
200
195201template <class _Fp, class _Rp, class... _ArgTypes>
196202class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> {
197203 _Fp __f_;
198204
199205public:
200 typedef _LIBCPP_NODEBUG _Fp _Target;
206 using _Target _LIBCPP_NODEBUG = _Fp;
201207
202208 _LIBCPP_HIDE_FROM_ABI const _Target& __target() const { return __f_; }
203209
......@@ -206,13 +212,13 @@ public:
206212 _LIBCPP_HIDE_FROM_ABI explicit __default_alloc_func(const _Target& __f) : __f_(__f) {}
207213
208214 _LIBCPP_HIDE_FROM_ABI _Rp operator()(_ArgTypes&&... __arg) {
209 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
210 return _Invoker::__call(__f_, std::forward<_ArgTypes>(__arg)...);
215 return std::__invoke_r<_Rp>(__f_, std::forward<_ArgTypes>(__arg)...);
211216 }
212217
213218 _LIBCPP_HIDE_FROM_ABI __default_alloc_func* __clone() const {
214 __builtin_new_allocator::__holder_t __hold = __builtin_new_allocator::__allocate_type<__default_alloc_func>(1);
215 __default_alloc_func* __res = ::new ((void*)__hold.get()) __default_alloc_func(__f_);
219 using _Self = __default_alloc_func;
220 unique_ptr<_Self, __deallocating_deleter<_Self>> __hold(std::__libcpp_allocate<_Self>(__element_count(1)));
221 _Self* __res = ::new ((void*)__hold.get()) _Self(__f_);
216222 (void)__hold.release();
217223 return __res;
218224 }
......@@ -221,7 +227,7 @@ public:
221227
222228 _LIBCPP_HIDE_FROM_ABI static void __destroy_and_delete(__default_alloc_func* __f) {
223229 __f->destroy();
224 __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1);
230 std::__libcpp_deallocate<__default_alloc_func>(__f, __element_count(1));
225231 }
226232};
227233
......@@ -243,10 +249,10 @@ public:
243249 virtual void destroy() _NOEXCEPT = 0;
244250 virtual void destroy_deallocate() _NOEXCEPT = 0;
245251 virtual _Rp operator()(_ArgTypes&&...) = 0;
246# ifndef _LIBCPP_HAS_NO_RTTI
252# if _LIBCPP_HAS_RTTI
247253 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
248254 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
249# endif // _LIBCPP_HAS_NO_RTTI
255# endif // _LIBCPP_HAS_RTTI
250256};
251257
252258// __func implements __base for a given functor type.
......@@ -272,10 +278,10 @@ public:
272278 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy() _NOEXCEPT;
273279 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy_deallocate() _NOEXCEPT;
274280 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual _Rp operator()(_ArgTypes&&... __arg);
275# ifndef _LIBCPP_HAS_NO_RTTI
281# if _LIBCPP_HAS_RTTI
276282 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual const void* target(const type_info&) const _NOEXCEPT;
277283 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual const std::type_info& target_type() const _NOEXCEPT;
278# endif // _LIBCPP_HAS_NO_RTTI
284# endif // _LIBCPP_HAS_RTTI
279285};
280286
281287template <class _Fp, class _Alloc, class _Rp, class... _ArgTypes>
......@@ -313,7 +319,7 @@ _Rp __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&&... __arg) {
313319 return __f_(std::forward<_ArgTypes>(__arg)...);
314320}
315321
316# ifndef _LIBCPP_HAS_NO_RTTI
322# if _LIBCPP_HAS_RTTI
317323
318324template <class _Fp, class _Alloc, class _Rp, class... _ArgTypes>
319325const 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
327333 return typeid(_Fp);
328334}
329335
330# endif // _LIBCPP_HAS_NO_RTTI
336# endif // _LIBCPP_HAS_RTTI
331337
332338// __value_func creates a value-type from a __func.
333339
......@@ -464,7 +470,7 @@ public:
464470
465471 _LIBCPP_HIDE_FROM_ABI explicit operator bool() const _NOEXCEPT { return __f_ != nullptr; }
466472
467# ifndef _LIBCPP_HAS_NO_RTTI
473# if _LIBCPP_HAS_RTTI
468474 _LIBCPP_HIDE_FROM_ABI const std::type_info& target_type() const _NOEXCEPT {
469475 if (__f_ == nullptr)
470476 return typeid(void);
......@@ -477,7 +483,7 @@ public:
477483 return nullptr;
478484 return (const _Tp*)__f_->target(typeid(_Tp));
479485 }
480# endif // _LIBCPP_HAS_NO_RTTI
486# endif // _LIBCPP_HAS_RTTI
481487};
482488
483489// Storage for a functor object, to be used with __policy to manage copy and
......@@ -520,7 +526,7 @@ struct __policy {
520526 nullptr,
521527 nullptr,
522528 true,
523# ifndef _LIBCPP_HAS_NO_RTTI
529# if _LIBCPP_HAS_RTTI
524530 &typeid(void)
525531# else
526532 nullptr
......@@ -547,7 +553,7 @@ private:
547553 &__large_clone<_Fun>,
548554 &__large_destroy<_Fun>,
549555 false,
550# ifndef _LIBCPP_HAS_NO_RTTI
556# if _LIBCPP_HAS_RTTI
551557 &typeid(typename _Fun::_Target)
552558# else
553559 nullptr
......@@ -562,7 +568,7 @@ private:
562568 nullptr,
563569 nullptr,
564570 false,
565# ifndef _LIBCPP_HAS_NO_RTTI
571# if _LIBCPP_HAS_RTTI
566572 &typeid(typename _Fun::_Target)
567573# else
568574 nullptr
......@@ -575,7 +581,7 @@ private:
575581// Used to choose between perfect forwarding or pass-by-value. Pass-by-value is
576582// faster for types that can be passed in registers.
577583template <typename _Tp>
578using __fast_forward = __conditional_t<is_scalar<_Tp>::value, _Tp, _Tp&&>;
584using __fast_forward _LIBCPP_NODEBUG = __conditional_t<is_scalar<_Tp>::value, _Tp, _Tp&&>;
579585
580586// __policy_invoker calls an instance of __alloc_func held in __policy_storage.
581587
......@@ -667,8 +673,8 @@ public:
667673 if (__use_small_storage<_Fun>()) {
668674 ::new ((void*)&__buf_.__small) _Fun(std::move(__f));
669675 } else {
670 __builtin_new_allocator::__holder_t __hold = __builtin_new_allocator::__allocate_type<_Fun>(1);
671 __buf_.__large = ::new ((void*)__hold.get()) _Fun(std::move(__f));
676 unique_ptr<_Fun, __deallocating_deleter<_Fun>> __hold(std::__libcpp_allocate<_Fun>(__element_count(1)));
677 __buf_.__large = ::new ((void*)__hold.get()) _Fun(std::move(__f));
672678 (void)__hold.release();
673679 }
674680 }
......@@ -724,7 +730,7 @@ public:
724730
725731 _LIBCPP_HIDE_FROM_ABI explicit operator bool() const _NOEXCEPT { return !__policy_->__is_null; }
726732
727# ifndef _LIBCPP_HAS_NO_RTTI
733# if _LIBCPP_HAS_RTTI
728734 _LIBCPP_HIDE_FROM_ABI const std::type_info& target_type() const _NOEXCEPT { return *__policy_->__type_info; }
729735
730736 template <typename _Tp>
......@@ -736,10 +742,10 @@ public:
736742 else
737743 return reinterpret_cast<const _Tp*>(&__buf_.__small);
738744 }
739# endif // _LIBCPP_HAS_NO_RTTI
745# endif // _LIBCPP_HAS_RTTI
740746};
741747
742# if defined(_LIBCPP_HAS_BLOCKS_RUNTIME)
748# if _LIBCPP_HAS_BLOCKS_RUNTIME
743749
744750extern "C" void* _Block_copy(const void*);
745751extern "C" void _Block_release(const void*);
......@@ -751,7 +757,7 @@ class __func<_Rp1 (^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> : public __base
751757
752758public:
753759 _LIBCPP_HIDE_FROM_ABI explicit __func(__block_type const& __f)
754# ifdef _LIBCPP_HAS_OBJC_ARC
760# if _LIBCPP_HAS_OBJC_ARC
755761 : __f_(__f)
756762# else
757763 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
......@@ -762,7 +768,7 @@ public:
762768 // [TODO] add && to save on a retain
763769
764770 _LIBCPP_HIDE_FROM_ABI explicit __func(__block_type __f, const _Alloc& /* unused */)
765# ifdef _LIBCPP_HAS_OBJC_ARC
771# if _LIBCPP_HAS_OBJC_ARC
766772 : __f_(__f)
767773# else
768774 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
......@@ -784,7 +790,7 @@ public:
784790 }
785791
786792 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy() _NOEXCEPT {
787# ifndef _LIBCPP_HAS_OBJC_ARC
793# if !_LIBCPP_HAS_OBJC_ARC
788794 if (__f_)
789795 _Block_release(__f_);
790796# endif
......@@ -803,7 +809,7 @@ public:
803809 return std::__invoke(__f_, std::forward<_ArgTypes>(__arg)...);
804810 }
805811
806# ifndef _LIBCPP_HAS_NO_RTTI
812# if _LIBCPP_HAS_RTTI
807813 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual const void* target(type_info const& __ti) const _NOEXCEPT {
808814 if (__ti == typeid(__func::__block_type))
809815 return &__f_;
......@@ -813,7 +819,7 @@ public:
813819 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual const std::type_info& target_type() const _NOEXCEPT {
814820 return typeid(__func::__block_type);
815821 }
816# endif // _LIBCPP_HAS_NO_RTTI
822# endif // _LIBCPP_HAS_RTTI
817823};
818824
819825# endif // _LIBCPP_HAS_EXTENSION_BLOCKS
......@@ -833,12 +839,12 @@ class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
833839 __func __f_;
834840
835841 template <class _Fp,
836 bool = _And< _IsNotSame<__remove_cvref_t<_Fp>, function>, __invokable<_Fp, _ArgTypes...> >::value>
842 bool = _And<_IsNotSame<__remove_cvref_t<_Fp>, function>, __is_invocable<_Fp, _ArgTypes...> >::value>
837843 struct __callable;
838844 template <class _Fp>
839845 struct __callable<_Fp, true> {
840846 static const bool value =
841 is_void<_Rp>::value || __is_core_convertible<typename __invoke_of<_Fp, _ArgTypes...>::type, _Rp>::value;
847 is_void<_Rp>::value || __is_core_convertible<__invoke_result_t<_Fp, _ArgTypes...>, _Rp>::value;
842848 };
843849 template <class _Fp>
844850 struct __callable<_Fp, false> {
......@@ -846,14 +852,14 @@ class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
846852 };
847853
848854 template <class _Fp>
849 using _EnableIfLValueCallable = __enable_if_t<__callable<_Fp&>::value>;
855 using _EnableIfLValueCallable _LIBCPP_NODEBUG = __enable_if_t<__callable<_Fp&>::value>;
850856
851857public:
852858 typedef _Rp result_type;
853859
854860 // construct/copy/destroy:
855861 _LIBCPP_HIDE_FROM_ABI function() _NOEXCEPT {}
856 _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI function(nullptr_t) _NOEXCEPT {}
862 _LIBCPP_HIDE_FROM_ABI function(nullptr_t) _NOEXCEPT {}
857863 _LIBCPP_HIDE_FROM_ABI function(const function&);
858864 _LIBCPP_HIDE_FROM_ABI function(function&&) _NOEXCEPT;
859865 template <class _Fp, class = _EnableIfLValueCallable<_Fp>>
......@@ -905,14 +911,14 @@ public:
905911 // function invocation:
906912 _LIBCPP_HIDE_FROM_ABI _Rp operator()(_ArgTypes...) const;
907913
908# ifndef _LIBCPP_HAS_NO_RTTI
914# if _LIBCPP_HAS_RTTI
909915 // function target access:
910916 _LIBCPP_HIDE_FROM_ABI const std::type_info& target_type() const _NOEXCEPT;
911917 template <typename _Tp>
912918 _LIBCPP_HIDE_FROM_ABI _Tp* target() _NOEXCEPT;
913919 template <typename _Tp>
914920 _LIBCPP_HIDE_FROM_ABI const _Tp* target() const _NOEXCEPT;
915# endif // _LIBCPP_HAS_NO_RTTI
921# endif // _LIBCPP_HAS_RTTI
916922};
917923
918924# if _LIBCPP_STD_VER >= 17
......@@ -989,7 +995,7 @@ _Rp function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const {
989995 return __f_(std::forward<_ArgTypes>(__arg)...);
990996}
991997
992# ifndef _LIBCPP_HAS_NO_RTTI
998# if _LIBCPP_HAS_RTTI
993999
9941000template <class _Rp, class... _ArgTypes>
9951001const std::type_info& function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT {
......@@ -1008,7 +1014,7 @@ const _Tp* function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT {
10081014 return __f_.template target<_Tp>();
10091015}
10101016
1011# endif // _LIBCPP_HAS_NO_RTTI
1017# endif // _LIBCPP_HAS_RTTI
10121018
10131019template <class _Rp, class... _ArgTypes>
10141020inline _LIBCPP_HIDE_FROM_ABI bool operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {
lib/libcxx/include/__functional/hash.h+13-8
......@@ -10,16 +10,17 @@
1010#define _LIBCPP___FUNCTIONAL_HASH_H
1111
1212#include <__config>
13#include <__cstddef/nullptr_t.h>
1314#include <__functional/unary_function.h>
1415#include <__fwd/functional.h>
1516#include <__type_traits/conjunction.h>
17#include <__type_traits/enable_if.h>
1618#include <__type_traits/invoke.h>
1719#include <__type_traits/is_constructible.h>
1820#include <__type_traits/is_enum.h>
1921#include <__type_traits/underlying_type.h>
2022#include <__utility/pair.h>
2123#include <__utility/swap.h>
22#include <cstddef>
2324#include <cstdint>
2425#include <cstring>
2526
......@@ -355,12 +356,12 @@ struct _LIBCPP_TEMPLATE_VIS hash<unsigned char> : public __unary_function<unsign
355356 _LIBCPP_HIDE_FROM_ABI size_t operator()(unsigned char __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
356357};
357358
358#ifndef _LIBCPP_HAS_NO_CHAR8_T
359#if _LIBCPP_HAS_CHAR8_T
359360template <>
360361struct _LIBCPP_TEMPLATE_VIS hash<char8_t> : public __unary_function<char8_t, size_t> {
361362 _LIBCPP_HIDE_FROM_ABI size_t operator()(char8_t __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
362363};
363#endif // !_LIBCPP_HAS_NO_CHAR8_T
364#endif // _LIBCPP_HAS_CHAR8_T
364365
365366template <>
366367struct _LIBCPP_TEMPLATE_VIS hash<char16_t> : public __unary_function<char16_t, size_t> {
......@@ -372,12 +373,12 @@ struct _LIBCPP_TEMPLATE_VIS hash<char32_t> : public __unary_function<char32_t, s
372373 _LIBCPP_HIDE_FROM_ABI size_t operator()(char32_t __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
373374};
374375
375#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
376#if _LIBCPP_HAS_WIDE_CHARACTERS
376377template <>
377378struct _LIBCPP_TEMPLATE_VIS hash<wchar_t> : public __unary_function<wchar_t, size_t> {
378379 _LIBCPP_HIDE_FROM_ABI size_t operator()(wchar_t __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
379380};
380#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
381#endif // _LIBCPP_HAS_WIDE_CHARACTERS
381382
382383template <>
383384struct _LIBCPP_TEMPLATE_VIS hash<short> : public __unary_function<short, size_t> {
......@@ -406,7 +407,11 @@ struct _LIBCPP_TEMPLATE_VIS hash<long> : public __unary_function<long, size_t> {
406407
407408template <>
408409struct _LIBCPP_TEMPLATE_VIS hash<unsigned long> : public __unary_function<unsigned long, size_t> {
409 _LIBCPP_HIDE_FROM_ABI size_t operator()(unsigned long __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
410 _LIBCPP_HIDE_FROM_ABI size_t operator()(unsigned long __v) const _NOEXCEPT {
411 static_assert(sizeof(size_t) >= sizeof(unsigned long),
412 "This would be a terrible hash function on a platform where size_t is smaller than unsigned long");
413 return static_cast<size_t>(__v);
414 }
410415};
411416
412417template <>
......@@ -415,7 +420,7 @@ struct _LIBCPP_TEMPLATE_VIS hash<long long> : public __scalar_hash<long long> {}
415420template <>
416421struct _LIBCPP_TEMPLATE_VIS hash<unsigned long long> : public __scalar_hash<unsigned long long> {};
417422
418#ifndef _LIBCPP_HAS_NO_INT128
423#if _LIBCPP_HAS_INT128
419424
420425template <>
421426struct _LIBCPP_TEMPLATE_VIS hash<__int128_t> : public __scalar_hash<__int128_t> {};
......@@ -517,7 +522,7 @@ template <class _Key, class _Hash>
517522using __check_hash_requirements _LIBCPP_NODEBUG =
518523 integral_constant<bool,
519524 is_copy_constructible<_Hash>::value && is_move_constructible<_Hash>::value &&
520 __invokable_r<size_t, _Hash, _Key const&>::value >;
525 __is_invocable_r_v<size_t, _Hash, _Key const&> >;
521526
522527template <class _Key, class _Hash = hash<_Key> >
523528using __has_enabled_hash _LIBCPP_NODEBUG =
lib/libcxx/include/__functional/identity.h+1-1
......@@ -26,7 +26,7 @@ struct __is_identity : false_type {};
2626
2727struct __identity {
2828 template <class _Tp>
29 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&& operator()(_Tp&& __t) const _NOEXCEPT {
29 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&& operator()(_Tp&& __t) const _NOEXCEPT {
3030 return std::forward<_Tp>(__t);
3131 }
3232
lib/libcxx/include/__functional/invoke.h+1
......@@ -12,6 +12,7 @@
1212
1313#include <__config>
1414#include <__type_traits/invoke.h>
15#include <__type_traits/is_void.h>
1516#include <__utility/forward.h>
1617
1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__functional/is_transparent.h+3-3
......@@ -21,11 +21,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121
2222#if _LIBCPP_STD_VER >= 14
2323
24template <class _Tp, class, class = void>
24template <class _Tp, class _Key = void, class = void>
2525inline const bool __is_transparent_v = false;
2626
27template <class _Tp, class _Up>
28inline const bool __is_transparent_v<_Tp, _Up, __void_t<typename _Tp::is_transparent> > = true;
27template <class _Tp, class _Key>
28inline const bool __is_transparent_v<_Tp, _Key, __void_t<typename _Tp::is_transparent> > = true;
2929
3030#endif
3131
lib/libcxx/include/__functional/mem_fn.h+3-5
......@@ -12,8 +12,8 @@
1212
1313#include <__config>
1414#include <__functional/binary_function.h>
15#include <__functional/invoke.h>
1615#include <__functional/weak_result_type.h>
16#include <__type_traits/invoke.h>
1717#include <__utility/forward.h>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -36,10 +36,8 @@ public:
3636
3737 // invoke
3838 template <class... _ArgTypes>
39 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
40
41 typename __invoke_return<type, _ArgTypes...>::type
42 operator()(_ArgTypes&&... __args) const {
39 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t<const _Tp&, _ArgTypes...>
40 operator()(_ArgTypes&&... __args) const _NOEXCEPT_(__is_nothrow_invocable_v<const _Tp&, _ArgTypes...>) {
4341 return std::__invoke(__f_, std::forward<_ArgTypes>(__args)...);
4442 }
4543};
lib/libcxx/include/__functional/not_fn.h+23
......@@ -16,6 +16,8 @@
1616#include <__type_traits/decay.h>
1717#include <__type_traits/enable_if.h>
1818#include <__type_traits/is_constructible.h>
19#include <__type_traits/is_member_pointer.h>
20#include <__type_traits/is_pointer.h>
1921#include <__utility/forward.h>
2022
2123#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) {
4850
4951#endif // _LIBCPP_STD_VER >= 17
5052
53#if _LIBCPP_STD_VER >= 26
54
55template <auto _Fn>
56struct __nttp_not_fn_t {
57 template <class... _Args>
58 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const
59 noexcept(noexcept(!std::invoke(_Fn, std::forward<_Args>(__args)...)))
60 -> decltype(!std::invoke(_Fn, std::forward<_Args>(__args)...)) {
61 return !std::invoke(_Fn, std::forward<_Args>(__args)...);
62 }
63};
64
65template <auto _Fn>
66[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr auto not_fn() noexcept {
67 if constexpr (using _Ty = decltype(_Fn); is_pointer_v<_Ty> || is_member_pointer_v<_Ty>)
68 static_assert(_Fn != nullptr, "f cannot be equal to nullptr");
69 return __nttp_not_fn_t<_Fn>();
70}
71
72#endif // _LIBCPP_STD_VER >= 26
73
5174_LIBCPP_END_NAMESPACE_STD
5275
5376#endif // _LIBCPP___FUNCTIONAL_NOT_FN_H
lib/libcxx/include/__functional/operations.h+14-1
......@@ -14,6 +14,7 @@
1414#include <__functional/binary_function.h>
1515#include <__functional/unary_function.h>
1616#include <__type_traits/desugars_to.h>
17#include <__type_traits/is_integral.h>
1718#include <__utility/forward.h>
1819
1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -364,6 +365,9 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(less);
364365template <class _Tp>
365366inline const bool __desugars_to_v<__less_tag, less<_Tp>, _Tp, _Tp> = true;
366367
368template <class _Tp>
369inline const bool __desugars_to_v<__totally_ordered_less_tag, less<_Tp>, _Tp, _Tp> = is_integral<_Tp>::value;
370
367371#if _LIBCPP_STD_VER >= 14
368372template <>
369373struct _LIBCPP_TEMPLATE_VIS less<void> {
......@@ -376,8 +380,11 @@ struct _LIBCPP_TEMPLATE_VIS less<void> {
376380 typedef void is_transparent;
377381};
378382
383template <class _Tp, class _Up>
384inline const bool __desugars_to_v<__less_tag, less<>, _Tp, _Up> = true;
385
379386template <class _Tp>
380inline const bool __desugars_to_v<__less_tag, less<>, _Tp, _Tp> = true;
387inline const bool __desugars_to_v<__totally_ordered_less_tag, less<>, _Tp, _Tp> = is_integral<_Tp>::value;
381388#endif
382389
383390#if _LIBCPP_STD_VER >= 14
......@@ -445,6 +452,9 @@ struct _LIBCPP_TEMPLATE_VIS greater : __binary_function<_Tp, _Tp, bool> {
445452};
446453_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(greater);
447454
455template <class _Tp>
456inline const bool __desugars_to_v<__greater_tag, greater<_Tp>, _Tp, _Tp> = true;
457
448458#if _LIBCPP_STD_VER >= 14
449459template <>
450460struct _LIBCPP_TEMPLATE_VIS greater<void> {
......@@ -456,6 +466,9 @@ struct _LIBCPP_TEMPLATE_VIS greater<void> {
456466 }
457467 typedef void is_transparent;
458468};
469
470template <class _Tp, class _Up>
471inline const bool __desugars_to_v<__greater_tag, greater<>, _Tp, _Up> = true;
459472#endif
460473
461474// Logical operations
lib/libcxx/include/__functional/perfect_forward.h+2-1
......@@ -11,6 +11,7 @@
1111#define _LIBCPP___FUNCTIONAL_PERFECT_FORWARD_H
1212
1313#include <__config>
14#include <__cstddef/size_t.h>
1415#include <__type_traits/enable_if.h>
1516#include <__type_traits/invoke.h>
1617#include <__type_traits/is_constructible.h>
......@@ -93,7 +94,7 @@ public:
9394
9495// __perfect_forward implements a perfect-forwarding call wrapper as explained in [func.require].
9596template <class _Op, class... _Args>
96using __perfect_forward = __perfect_forward_impl<_Op, index_sequence_for<_Args...>, _Args...>;
97using __perfect_forward _LIBCPP_NODEBUG = __perfect_forward_impl<_Op, index_sequence_for<_Args...>, _Args...>;
9798
9899#endif // _LIBCPP_STD_VER >= 17
99100
lib/libcxx/include/__functional/ranges_operations.h+6
......@@ -99,9 +99,15 @@ struct greater_equal {
9999template <class _Tp, class _Up>
100100inline const bool __desugars_to_v<__equal_tag, ranges::equal_to, _Tp, _Up> = true;
101101
102template <class _Tp, class _Up>
103inline const bool __desugars_to_v<__totally_ordered_less_tag, ranges::less, _Tp, _Up> = true;
104
102105template <class _Tp, class _Up>
103106inline const bool __desugars_to_v<__less_tag, ranges::less, _Tp, _Up> = true;
104107
108template <class _Tp, class _Up>
109inline const bool __desugars_to_v<__greater_tag, ranges::greater, _Tp, _Up> = true;
110
105111#endif // _LIBCPP_STD_VER >= 20
106112
107113_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__functional/reference_wrapper.h+2-2
......@@ -13,10 +13,10 @@
1313#include <__compare/synth_three_way.h>
1414#include <__concepts/boolean_testable.h>
1515#include <__config>
16#include <__functional/invoke.h>
1716#include <__functional/weak_result_type.h>
1817#include <__memory/addressof.h>
1918#include <__type_traits/enable_if.h>
19#include <__type_traits/invoke.h>
2020#include <__type_traits/is_const.h>
2121#include <__type_traits/remove_cvref.h>
2222#include <__type_traits/void_t.h>
......@@ -57,7 +57,7 @@ public:
5757
5858 // invoke
5959 template <class... _ArgTypes>
60 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __invoke_of<type&, _ArgTypes...>::type
60 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t<type&, _ArgTypes...>
6161 operator()(_ArgTypes&&... __args) const
6262#if _LIBCPP_STD_VER >= 17
6363 // Since is_nothrow_invocable requires C++17 LWG3764 is not backported
lib/libcxx/include/__functional/unary_function.h+2-2
......@@ -39,11 +39,11 @@ struct __unary_function_keep_layout_base {
3939_LIBCPP_DIAGNOSTIC_PUSH
4040_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
4141template <class _Arg, class _Result>
42using __unary_function = unary_function<_Arg, _Result>;
42using __unary_function _LIBCPP_NODEBUG = unary_function<_Arg, _Result>;
4343_LIBCPP_DIAGNOSTIC_POP
4444#else
4545template <class _Arg, class _Result>
46using __unary_function = __unary_function_keep_layout_base<_Arg, _Result>;
46using __unary_function _LIBCPP_NODEBUG = __unary_function_keep_layout_base<_Arg, _Result>;
4747#endif
4848
4949_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__functional/weak_result_type.h+1-6
......@@ -12,9 +12,9 @@
1212
1313#include <__config>
1414#include <__functional/binary_function.h>
15#include <__functional/invoke.h>
1615#include <__functional/unary_function.h>
1716#include <__type_traits/integral_constant.h>
17#include <__type_traits/invoke.h>
1818#include <__type_traits/is_same.h>
1919#include <__utility/declval.h>
2020
......@@ -221,11 +221,6 @@ struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile> {
221221#endif
222222};
223223
224template <class _Tp, class... _Args>
225struct __invoke_return {
226 typedef decltype(std::__invoke(std::declval<_Tp>(), std::declval<_Args>()...)) type;
227};
228
229224_LIBCPP_END_NAMESPACE_STD
230225
231226#endif // _LIBCPP___FUNCTIONAL_WEAK_RESULT_TYPE_H
lib/libcxx/include/__fwd/array.h+5-4
......@@ -10,7 +10,8 @@
1010#define _LIBCPP___FWD_ARRAY_H
1111
1212#include <__config>
13#include <cstddef>
13#include <__cstddef/size_t.h>
14#include <__type_traits/integral_constant.h>
1415
1516#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1617# pragma GCC system_header
......@@ -35,11 +36,11 @@ template <size_t _Ip, class _Tp, size_t _Size>
3536_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&& get(const array<_Tp, _Size>&&) _NOEXCEPT;
3637#endif
3738
38template <class>
39struct __is_std_array : false_type {};
39template <class _Tp>
40inline const bool __is_std_array_v = false;
4041
4142template <class _Tp, size_t _Size>
42struct __is_std_array<array<_Tp, _Size> > : true_type {};
43inline const bool __is_std_array_v<array<_Tp, _Size> > = true;
4344
4445_LIBCPP_END_NAMESPACE_STD
4546
lib/libcxx/include/__fwd/bit_reference.h+3
......@@ -20,6 +20,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2020template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0>
2121class __bit_iterator;
2222
23template <class, class = void>
24struct __size_difference_type_traits;
25
2326_LIBCPP_END_NAMESPACE_STD
2427
2528#endif // _LIBCPP___FWD_BIT_REFERENCE_H
lib/libcxx/include/__fwd/byte.h created+26
......@@ -0,0 +1,26 @@
1//===---------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===---------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___FWD_BYTE_H
10#define _LIBCPP___FWD_BYTE_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18#if _LIBCPP_STD_VER >= 17
19namespace std { // purposefully not versioned
20
21enum class byte : unsigned char;
22
23} // namespace std
24#endif // _LIBCPP_STD_VER >= 17
25
26#endif // _LIBCPP___FWD_BYTE_H
lib/libcxx/include/__fwd/complex.h+1-1
......@@ -10,7 +10,7 @@
1010#define _LIBCPP___FWD_COMPLEX_H
1111
1212#include <__config>
13#include <cstddef>
13#include <__cstddef/size_t.h>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1616# pragma GCC system_header
lib/libcxx/include/__fwd/format.h+1-1
......@@ -31,7 +31,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_context;
3131template <class _Tp, class _CharT = char>
3232struct _LIBCPP_TEMPLATE_VIS formatter;
3333
34#endif //_LIBCPP_STD_VER >= 20
34#endif // _LIBCPP_STD_VER >= 20
3535
3636_LIBCPP_END_NAMESPACE_STD
3737
lib/libcxx/include/__fwd/fstream.h+1-1
......@@ -32,7 +32,7 @@ using ifstream = basic_ifstream<char>;
3232using ofstream = basic_ofstream<char>;
3333using fstream = basic_fstream<char>;
3434
35#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
35#if _LIBCPP_HAS_WIDE_CHARACTERS
3636using wfilebuf = basic_filebuf<wchar_t>;
3737using wifstream = basic_ifstream<wchar_t>;
3838using wofstream = basic_ofstream<wchar_t>;
lib/libcxx/include/__fwd/get.h created+24
......@@ -0,0 +1,24 @@
1//===---------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===---------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___FWD_GET_H
10#define _LIBCPP___FWD_GET_H
11
12#include <__config>
13#include <__fwd/array.h>
14#include <__fwd/complex.h>
15#include <__fwd/pair.h>
16#include <__fwd/subrange.h>
17#include <__fwd/tuple.h>
18#include <__fwd/variant.h>
19
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21# pragma GCC system_header
22#endif
23
24#endif // _LIBCPP___FWD_GET_H
lib/libcxx/include/__fwd/ios.h+1-1
......@@ -24,7 +24,7 @@ template <class _CharT, class _Traits = char_traits<_CharT> >
2424class _LIBCPP_TEMPLATE_VIS basic_ios;
2525
2626using ios = basic_ios<char>;
27#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
27#if _LIBCPP_HAS_WIDE_CHARACTERS
2828using wios = basic_ios<wchar_t>;
2929#endif
3030
lib/libcxx/include/__fwd/istream.h+1-1
......@@ -27,7 +27,7 @@ class _LIBCPP_TEMPLATE_VIS basic_iostream;
2727using istream = basic_istream<char>;
2828using iostream = basic_iostream<char>;
2929
30#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
30#if _LIBCPP_HAS_WIDE_CHARACTERS
3131using wistream = basic_istream<wchar_t>;
3232using wiostream = basic_iostream<wchar_t>;
3333#endif
lib/libcxx/include/__fwd/memory.h+3
......@@ -20,6 +20,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2020template <class _Tp>
2121class _LIBCPP_TEMPLATE_VIS allocator;
2222
23template <class _Tp>
24class _LIBCPP_TEMPLATE_VIS shared_ptr;
25
2326_LIBCPP_END_NAMESPACE_STD
2427
2528#endif // _LIBCPP___FWD_MEMORY_H
lib/libcxx/include/__fwd/memory_resource.h+4
......@@ -15,6 +15,8 @@
1515# pragma GCC system_header
1616#endif
1717
18#if _LIBCPP_STD_VER >= 17
19
1820_LIBCPP_BEGIN_NAMESPACE_STD
1921
2022namespace pmr {
......@@ -24,4 +26,6 @@ class _LIBCPP_AVAILABILITY_PMR _LIBCPP_TEMPLATE_VIS polymorphic_allocator;
2426
2527_LIBCPP_END_NAMESPACE_STD
2628
29#endif // _LIBCPP_STD_VER >= 17
30
2731#endif // _LIBCPP___FWD_MEMORY_RESOURCE_H
lib/libcxx/include/__fwd/ostream.h+1-1
......@@ -23,7 +23,7 @@ class _LIBCPP_TEMPLATE_VIS basic_ostream;
2323
2424using ostream = basic_ostream<char>;
2525
26#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
26#if _LIBCPP_HAS_WIDE_CHARACTERS
2727using wostream = basic_ostream<wchar_t>;
2828#endif
2929
lib/libcxx/include/__fwd/pair.h+1-1
......@@ -10,8 +10,8 @@
1010#define _LIBCPP___FWD_PAIR_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__fwd/tuple.h>
14#include <cstddef>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717# pragma GCC system_header
lib/libcxx/include/__fwd/span.h+1-1
......@@ -11,7 +11,7 @@
1111#define _LIBCPP___FWD_SPAN_H
1212
1313#include <__config>
14#include <cstddef>
14#include <__cstddef/size_t.h>
1515#include <limits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__fwd/sstream.h+1-1
......@@ -34,7 +34,7 @@ using istringstream = basic_istringstream<char>;
3434using ostringstream = basic_ostringstream<char>;
3535using stringstream = basic_stringstream<char>;
3636
37#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
37#if _LIBCPP_HAS_WIDE_CHARACTERS
3838using wstringbuf = basic_stringbuf<wchar_t>;
3939using wistringstream = basic_istringstream<wchar_t>;
4040using wostringstream = basic_ostringstream<wchar_t>;
lib/libcxx/include/__fwd/streambuf.h+1-1
......@@ -23,7 +23,7 @@ class _LIBCPP_TEMPLATE_VIS basic_streambuf;
2323
2424using streambuf = basic_streambuf<char>;
2525
26#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
26#if _LIBCPP_HAS_WIDE_CHARACTERS
2727using wstreambuf = basic_streambuf<wchar_t>;
2828#endif
2929
lib/libcxx/include/__fwd/string.h+10-10
......@@ -24,7 +24,7 @@ struct _LIBCPP_TEMPLATE_VIS char_traits;
2424template <>
2525struct char_traits<char>;
2626
27#ifndef _LIBCPP_HAS_NO_CHAR8_T
27#if _LIBCPP_HAS_CHAR8_T
2828template <>
2929struct char_traits<char8_t>;
3030#endif
......@@ -34,7 +34,7 @@ struct char_traits<char16_t>;
3434template <>
3535struct char_traits<char32_t>;
3636
37#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
37#if _LIBCPP_HAS_WIDE_CHARACTERS
3838template <>
3939struct char_traits<wchar_t>;
4040#endif
......@@ -44,11 +44,11 @@ class _LIBCPP_TEMPLATE_VIS basic_string;
4444
4545using string = basic_string<char>;
4646
47#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
47#if _LIBCPP_HAS_WIDE_CHARACTERS
4848using wstring = basic_string<wchar_t>;
4949#endif
5050
51#ifndef _LIBCPP_HAS_NO_CHAR8_T
51#if _LIBCPP_HAS_CHAR8_T
5252using u8string = basic_string<char8_t>;
5353#endif
5454
......@@ -63,11 +63,11 @@ using basic_string _LIBCPP_AVAILABILITY_PMR = std::basic_string<_CharT, _Traits,
6363
6464using string _LIBCPP_AVAILABILITY_PMR = basic_string<char>;
6565
66# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
66# if _LIBCPP_HAS_WIDE_CHARACTERS
6767using wstring _LIBCPP_AVAILABILITY_PMR = basic_string<wchar_t>;
6868# endif
6969
70# ifndef _LIBCPP_HAS_NO_CHAR8_T
70# if _LIBCPP_HAS_CHAR8_T
7171using u8string _LIBCPP_AVAILABILITY_PMR = basic_string<char8_t>;
7272# endif
7373
......@@ -80,20 +80,20 @@ using u32string _LIBCPP_AVAILABILITY_PMR = basic_string<char32_t>;
8080// clang-format off
8181template <class _CharT, class _Traits, class _Allocator>
8282class _LIBCPP_PREFERRED_NAME(string)
83#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
83#if _LIBCPP_HAS_WIDE_CHARACTERS
8484 _LIBCPP_PREFERRED_NAME(wstring)
8585#endif
86#ifndef _LIBCPP_HAS_NO_CHAR8_T
86#if _LIBCPP_HAS_CHAR8_T
8787 _LIBCPP_PREFERRED_NAME(u8string)
8888#endif
8989 _LIBCPP_PREFERRED_NAME(u16string)
9090 _LIBCPP_PREFERRED_NAME(u32string)
9191#if _LIBCPP_STD_VER >= 17
9292 _LIBCPP_PREFERRED_NAME(pmr::string)
93# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
93# if _LIBCPP_HAS_WIDE_CHARACTERS
9494 _LIBCPP_PREFERRED_NAME(pmr::wstring)
9595# endif
96# ifndef _LIBCPP_HAS_NO_CHAR8_T
96# if _LIBCPP_HAS_CHAR8_T
9797 _LIBCPP_PREFERRED_NAME(pmr::u8string)
9898# endif
9999 _LIBCPP_PREFERRED_NAME(pmr::u16string)
lib/libcxx/include/__fwd/string_view.h+4-4
......@@ -23,22 +23,22 @@ template <class _CharT, class _Traits = char_traits<_CharT> >
2323class _LIBCPP_TEMPLATE_VIS basic_string_view;
2424
2525typedef basic_string_view<char> string_view;
26#ifndef _LIBCPP_HAS_NO_CHAR8_T
26#if _LIBCPP_HAS_CHAR8_T
2727typedef basic_string_view<char8_t> u8string_view;
2828#endif
2929typedef basic_string_view<char16_t> u16string_view;
3030typedef basic_string_view<char32_t> u32string_view;
31#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
31#if _LIBCPP_HAS_WIDE_CHARACTERS
3232typedef basic_string_view<wchar_t> wstring_view;
3333#endif
3434
3535// clang-format off
3636template <class _CharT, class _Traits>
3737class _LIBCPP_PREFERRED_NAME(string_view)
38#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
38#if _LIBCPP_HAS_WIDE_CHARACTERS
3939 _LIBCPP_PREFERRED_NAME(wstring_view)
4040#endif
41#ifndef _LIBCPP_HAS_NO_CHAR8_T
41#if _LIBCPP_HAS_CHAR8_T
4242 _LIBCPP_PREFERRED_NAME(u8string_view)
4343#endif
4444 _LIBCPP_PREFERRED_NAME(u16string_view)
lib/libcxx/include/__fwd/subrange.h+1-1
......@@ -11,8 +11,8 @@
1111
1212#include <__concepts/copyable.h>
1313#include <__config>
14#include <__cstddef/size_t.h>
1415#include <__iterator/concepts.h>
15#include <cstddef>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818# pragma GCC system_header
lib/libcxx/include/__fwd/tuple.h+1-1
......@@ -10,7 +10,7 @@
1010#define _LIBCPP___FWD_TUPLE_H
1111
1212#include <__config>
13#include <cstddef>
13#include <__cstddef/size_t.h>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1616# pragma GCC system_header
lib/libcxx/include/__fwd/variant.h created+77
......@@ -0,0 +1,77 @@
1//===---------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===---------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___FWD_VARIANT_H
10#define _LIBCPP___FWD_VARIANT_H
11
12#include <__config>
13#include <__cstddef/size_t.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21#if _LIBCPP_STD_VER >= 17
22
23template <class... _Types>
24class _LIBCPP_TEMPLATE_VIS variant;
25
26template <class _Tp>
27struct _LIBCPP_TEMPLATE_VIS variant_size;
28
29template <class _Tp>
30inline constexpr size_t variant_size_v = variant_size<_Tp>::value;
31
32template <size_t _Ip, class _Tp>
33struct _LIBCPP_TEMPLATE_VIS variant_alternative;
34
35template <size_t _Ip, class _Tp>
36using variant_alternative_t = typename variant_alternative<_Ip, _Tp>::type;
37
38inline constexpr size_t variant_npos = static_cast<size_t>(-1);
39
40template <size_t _Ip, class... _Types>
41_LIBCPP_HIDE_FROM_ABI
42_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr variant_alternative_t<_Ip, variant<_Types...>>&
43get(variant<_Types...>&);
44
45template <size_t _Ip, class... _Types>
46_LIBCPP_HIDE_FROM_ABI
47_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr variant_alternative_t<_Ip, variant<_Types...>>&&
48get(variant<_Types...>&&);
49
50template <size_t _Ip, class... _Types>
51_LIBCPP_HIDE_FROM_ABI
52_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const variant_alternative_t<_Ip, variant<_Types...>>&
53get(const variant<_Types...>&);
54
55template <size_t _Ip, class... _Types>
56_LIBCPP_HIDE_FROM_ABI
57_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const variant_alternative_t<_Ip, variant<_Types...>>&&
58get(const variant<_Types...>&&);
59
60template <class _Tp, class... _Types>
61_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Tp& get(variant<_Types...>&);
62
63template <class _Tp, class... _Types>
64_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Tp&& get(variant<_Types...>&&);
65
66template <class _Tp, class... _Types>
67_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const _Tp& get(const variant<_Types...>&);
68
69template <class _Tp, class... _Types>
70_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const _Tp&&
71get(const variant<_Types...>&&);
72
73#endif // _LIBCPP_STD_VER >= 17
74
75_LIBCPP_END_NAMESPACE_STD
76
77#endif // _LIBCPP___FWD_VARIANT_H
lib/libcxx/include/__fwd/vector.h+3
......@@ -21,6 +21,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121template <class _Tp, class _Alloc = allocator<_Tp> >
2222class _LIBCPP_TEMPLATE_VIS vector;
2323
24template <class _Allocator>
25class vector<bool, _Allocator>;
26
2427_LIBCPP_END_NAMESPACE_STD
2528
2629#endif // _LIBCPP___FWD_VECTOR_H
lib/libcxx/include/__hash_table+130-103
......@@ -15,9 +15,11 @@
1515#include <__assert>
1616#include <__bit/countl.h>
1717#include <__config>
18#include <__cstddef/ptrdiff_t.h>
19#include <__cstddef/size_t.h>
1820#include <__functional/hash.h>
19#include <__functional/invoke.h>
2021#include <__iterator/iterator_traits.h>
22#include <__math/rounding_functions.h>
2123#include <__memory/addressof.h>
2224#include <__memory/allocator_traits.h>
2325#include <__memory/compressed_pair.h>
......@@ -25,14 +27,16 @@
2527#include <__memory/pointer_traits.h>
2628#include <__memory/swap_allocator.h>
2729#include <__memory/unique_ptr.h>
30#include <__new/launder.h>
2831#include <__type_traits/can_extract_key.h>
29#include <__type_traits/conditional.h>
32#include <__type_traits/enable_if.h>
33#include <__type_traits/invoke.h>
3034#include <__type_traits/is_const.h>
3135#include <__type_traits/is_constructible.h>
3236#include <__type_traits/is_nothrow_assignable.h>
3337#include <__type_traits/is_nothrow_constructible.h>
34#include <__type_traits/is_pointer.h>
3538#include <__type_traits/is_reference.h>
39#include <__type_traits/is_same.h>
3640#include <__type_traits/is_swappable.h>
3741#include <__type_traits/remove_const.h>
3842#include <__type_traits/remove_cvref.h>
......@@ -40,10 +44,7 @@
4044#include <__utility/move.h>
4145#include <__utility/pair.h>
4246#include <__utility/swap.h>
43#include <cmath>
44#include <cstring>
45#include <initializer_list>
46#include <new> // __launder
47#include <limits>
4748
4849#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4950# pragma GCC system_header
......@@ -77,11 +78,18 @@ struct __hash_node_base {
7778 typedef __hash_node_base __first_node;
7879 typedef __rebind_pointer_t<_NodePtr, __first_node> __node_base_pointer;
7980 typedef _NodePtr __node_pointer;
80
81#if defined(_LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB)
8281 typedef __node_base_pointer __next_pointer;
83#else
84 typedef __conditional_t<is_pointer<__node_pointer>::value, __node_base_pointer, __node_pointer> __next_pointer;
82
83// TODO(LLVM 22): Remove this check
84#ifndef _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
85 static_assert(sizeof(__node_base_pointer) == sizeof(__node_pointer) && _LIBCPP_ALIGNOF(__node_base_pointer) ==
86 _LIBCPP_ALIGNOF(__node_pointer),
87 "It looks like you are using std::__hash_table (an implementation detail for the unordered containers) "
88 "with a fancy pointer type that thas a different representation depending on whether it points to a "
89 "__hash_table base pointer or a __hash_table node pointer (both of which are implementation details of "
90 "the standard library). This means that your ABI is being broken between LLVM 19 and LLVM 20. If you "
91 "don't care about your ABI being broken, define the _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB macro to "
92 "silence this diagnostic.");
8593#endif
8694
8795 __next_pointer __next_;
......@@ -103,8 +111,8 @@ struct __hash_node_base {
103111template <class _Tp, class _VoidPtr>
104112struct __hash_node : public __hash_node_base< __rebind_pointer_t<_VoidPtr, __hash_node<_Tp, _VoidPtr> > > {
105113 typedef _Tp __node_value_type;
106 using _Base = __hash_node_base<__rebind_pointer_t<_VoidPtr, __hash_node<_Tp, _VoidPtr> > >;
107 using __next_pointer = typename _Base::__next_pointer;
114 using _Base _LIBCPP_NODEBUG = __hash_node_base<__rebind_pointer_t<_VoidPtr, __hash_node<_Tp, _VoidPtr> > >;
115 using __next_pointer _LIBCPP_NODEBUG = typename _Base::__next_pointer;
108116
109117 size_t __hash_;
110118
......@@ -554,29 +562,29 @@ class __bucket_list_deallocator {
554562 typedef allocator_traits<allocator_type> __alloc_traits;
555563 typedef typename __alloc_traits::size_type size_type;
556564
557 __compressed_pair<size_type, allocator_type> __data_;
565 _LIBCPP_COMPRESSED_PAIR(size_type, __size_, allocator_type, __alloc_);
558566
559567public:
560568 typedef typename __alloc_traits::pointer pointer;
561569
562570 _LIBCPP_HIDE_FROM_ABI __bucket_list_deallocator() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
563 : __data_(0, __default_init_tag()) {}
571 : __size_(0) {}
564572
565573 _LIBCPP_HIDE_FROM_ABI __bucket_list_deallocator(const allocator_type& __a, size_type __size)
566574 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
567 : __data_(__size, __a) {}
575 : __size_(__size), __alloc_(__a) {}
568576
569577 _LIBCPP_HIDE_FROM_ABI __bucket_list_deallocator(__bucket_list_deallocator&& __x)
570578 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
571 : __data_(std::move(__x.__data_)) {
579 : __size_(std::move(__x.__size_)), __alloc_(std::move(__x.__alloc_)) {
572580 __x.size() = 0;
573581 }
574582
575 _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __data_.first(); }
576 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __data_.first(); }
583 _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __size_; }
584 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size_; }
577585
578 _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return __data_.second(); }
579 _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { return __data_.second(); }
586 _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return __alloc_; }
587 _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { return __alloc_; }
580588
581589 _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT { __alloc_traits::deallocate(__alloc(), __p, size()); }
582590};
......@@ -642,9 +650,9 @@ struct __enforce_unordered_container_requirements {
642650
643651template <class _Key, class _Hash, class _Equal>
644652#ifndef _LIBCPP_CXX03_LANG
645_LIBCPP_DIAGNOSE_WARNING(!__invokable<_Equal const&, _Key const&, _Key const&>::value,
653_LIBCPP_DIAGNOSE_WARNING(!__is_invocable_v<_Equal const&, _Key const&, _Key const&>,
646654 "the specified comparator type does not provide a viable const call operator")
647_LIBCPP_DIAGNOSE_WARNING(!__invokable<_Hash const&, _Key const&>::value,
655_LIBCPP_DIAGNOSE_WARNING(!__is_invocable_v<_Hash const&, _Key const&>,
648656 "the specified hash functor does not provide a viable const call operator")
649657#endif
650658 typename __enforce_unordered_container_requirements<_Key, _Hash, _Equal>::type
......@@ -716,27 +724,27 @@ private:
716724
717725 // --- Member data begin ---
718726 __bucket_list __bucket_list_;
719 __compressed_pair<__first_node, __node_allocator> __p1_;
720 __compressed_pair<size_type, hasher> __p2_;
721 __compressed_pair<float, key_equal> __p3_;
727 _LIBCPP_COMPRESSED_PAIR(__first_node, __first_node_, __node_allocator, __node_alloc_);
728 _LIBCPP_COMPRESSED_PAIR(size_type, __size_, hasher, __hasher_);
729 _LIBCPP_COMPRESSED_PAIR(float, __max_load_factor_, key_equal, __key_eq_);
722730 // --- Member data end ---
723731
724 _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __p2_.first(); }
732 _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __size_; }
725733
726734public:
727 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __p2_.first(); }
735 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size_; }
728736
729 _LIBCPP_HIDE_FROM_ABI hasher& hash_function() _NOEXCEPT { return __p2_.second(); }
730 _LIBCPP_HIDE_FROM_ABI const hasher& hash_function() const _NOEXCEPT { return __p2_.second(); }
737 _LIBCPP_HIDE_FROM_ABI hasher& hash_function() _NOEXCEPT { return __hasher_; }
738 _LIBCPP_HIDE_FROM_ABI const hasher& hash_function() const _NOEXCEPT { return __hasher_; }
731739
732 _LIBCPP_HIDE_FROM_ABI float& max_load_factor() _NOEXCEPT { return __p3_.first(); }
733 _LIBCPP_HIDE_FROM_ABI float max_load_factor() const _NOEXCEPT { return __p3_.first(); }
740 _LIBCPP_HIDE_FROM_ABI float& max_load_factor() _NOEXCEPT { return __max_load_factor_; }
741 _LIBCPP_HIDE_FROM_ABI float max_load_factor() const _NOEXCEPT { return __max_load_factor_; }
734742
735 _LIBCPP_HIDE_FROM_ABI key_equal& key_eq() _NOEXCEPT { return __p3_.second(); }
736 _LIBCPP_HIDE_FROM_ABI const key_equal& key_eq() const _NOEXCEPT { return __p3_.second(); }
743 _LIBCPP_HIDE_FROM_ABI key_equal& key_eq() _NOEXCEPT { return __key_eq_; }
744 _LIBCPP_HIDE_FROM_ABI const key_equal& key_eq() const _NOEXCEPT { return __key_eq_; }
737745
738 _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __p1_.second(); }
739 _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __p1_.second(); }
746 _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __node_alloc_; }
747 _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __node_alloc_; }
740748
741749public:
742750 typedef __hash_iterator<__node_pointer> iterator;
......@@ -875,10 +883,10 @@ public:
875883 _LIBCPP_HIDE_FROM_ABI void __rehash_unique(size_type __n) { __rehash<true>(__n); }
876884 _LIBCPP_HIDE_FROM_ABI void __rehash_multi(size_type __n) { __rehash<false>(__n); }
877885 _LIBCPP_HIDE_FROM_ABI void __reserve_unique(size_type __n) {
878 __rehash_unique(static_cast<size_type>(std::ceil(__n / max_load_factor())));
886 __rehash_unique(static_cast<size_type>(__math::ceil(__n / max_load_factor())));
879887 }
880888 _LIBCPP_HIDE_FROM_ABI void __reserve_multi(size_type __n) {
881 __rehash_multi(static_cast<size_type>(std::ceil(__n / max_load_factor())));
889 __rehash_multi(static_cast<size_type>(__math::ceil(__n / max_load_factor())));
882890 }
883891
884892 _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_(
10221030 is_nothrow_default_constructible<__bucket_list>::value&& is_nothrow_default_constructible<__first_node>::value&&
10231031 is_nothrow_default_constructible<__node_allocator>::value&& is_nothrow_default_constructible<hasher>::value&&
10241032 is_nothrow_default_constructible<key_equal>::value)
1025 : __p2_(0, __default_init_tag()), __p3_(1.0f, __default_init_tag()) {}
1033 : __size_(0), __max_load_factor_(1.0f) {}
10261034
10271035template <class _Tp, class _Hash, class _Equal, class _Alloc>
10281036inline __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, const key_equal& __eql)
1029 : __bucket_list_(nullptr, __bucket_list_deleter()), __p1_(), __p2_(0, __hf), __p3_(1.0f, __eql) {}
1037 : __bucket_list_(nullptr, __bucket_list_deleter()),
1038 __first_node_(),
1039 __node_alloc_(),
1040 __size_(0),
1041 __hasher_(__hf),
1042 __max_load_factor_(1.0f),
1043 __key_eq_(__eql) {}
10301044
10311045template <class _Tp, class _Hash, class _Equal, class _Alloc>
10321046__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(
10331047 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
10341048 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
1035 __p1_(__default_init_tag(), __node_allocator(__a)),
1036 __p2_(0, __hf),
1037 __p3_(1.0f, __eql) {}
1049 __node_alloc_(__node_allocator(__a)),
1050 __size_(0),
1051 __hasher_(__hf),
1052 __max_load_factor_(1.0f),
1053 __key_eq_(__eql) {}
10381054
10391055template <class _Tp, class _Hash, class _Equal, class _Alloc>
10401056__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a)
10411057 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
1042 __p1_(__default_init_tag(), __node_allocator(__a)),
1043 __p2_(0, __default_init_tag()),
1044 __p3_(1.0f, __default_init_tag()) {}
1058 __node_alloc_(__node_allocator(__a)),
1059 __size_(0),
1060 __max_load_factor_(1.0f) {}
10451061
10461062template <class _Tp, class _Hash, class _Equal, class _Alloc>
10471063__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)
10491065 __bucket_list_deleter(allocator_traits<__pointer_allocator>::select_on_container_copy_construction(
10501066 __u.__bucket_list_.get_deleter().__alloc()),
10511067 0)),
1052 __p1_(__default_init_tag(),
1053 allocator_traits<__node_allocator>::select_on_container_copy_construction(__u.__node_alloc())),
1054 __p2_(0, __u.hash_function()),
1055 __p3_(__u.__p3_) {}
1068 __node_alloc_(allocator_traits<__node_allocator>::select_on_container_copy_construction(__u.__node_alloc())),
1069 __size_(0),
1070 __hasher_(__u.hash_function()),
1071 __max_load_factor_(__u.__max_load_factor_),
1072 __key_eq_(__u.__key_eq_) {}
10561073
10571074template <class _Tp, class _Hash, class _Equal, class _Alloc>
10581075__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u, const allocator_type& __a)
10591076 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
1060 __p1_(__default_init_tag(), __node_allocator(__a)),
1061 __p2_(0, __u.hash_function()),
1062 __p3_(__u.__p3_) {}
1077 __node_alloc_(__node_allocator(__a)),
1078 __size_(0),
1079 __hasher_(__u.hash_function()),
1080 __max_load_factor_(__u.__max_load_factor_),
1081 __key_eq_(__u.__key_eq_) {}
10631082
10641083template <class _Tp, class _Hash, class _Equal, class _Alloc>
10651084__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
10671086 is_nothrow_move_constructible<__node_allocator>::value&& is_nothrow_move_constructible<hasher>::value&&
10681087 is_nothrow_move_constructible<key_equal>::value)
10691088 : __bucket_list_(std::move(__u.__bucket_list_)),
1070 __p1_(std::move(__u.__p1_)),
1071 __p2_(std::move(__u.__p2_)),
1072 __p3_(std::move(__u.__p3_)) {
1089 __first_node_(std::move(__u.__first_node_)),
1090 __node_alloc_(std::move(__u.__node_alloc_)),
1091 __size_(std::move(__u.__size_)),
1092 __hasher_(std::move(__u.__hasher_)),
1093 __max_load_factor_(__u.__max_load_factor_),
1094 __key_eq_(std::move(__u.__key_eq_)) {
10731095 if (size() > 0) {
1074 __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr();
1075 __u.__p1_.first().__next_ = nullptr;
1096 __bucket_list_[std::__constrain_hash(__first_node_.__next_->__hash(), bucket_count())] = __first_node_.__ptr();
1097 __u.__first_node_.__next_ = nullptr;
10761098 __u.size() = 0;
10771099 }
10781100}
......@@ -1080,17 +1102,19 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) _NOEX
10801102template <class _Tp, class _Hash, class _Equal, class _Alloc>
10811103__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u, const allocator_type& __a)
10821104 : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
1083 __p1_(__default_init_tag(), __node_allocator(__a)),
1084 __p2_(0, std::move(__u.hash_function())),
1085 __p3_(std::move(__u.__p3_)) {
1105 __node_alloc_(__node_allocator(__a)),
1106 __size_(0),
1107 __hasher_(std::move(__u.__hasher_)),
1108 __max_load_factor_(__u.__max_load_factor_),
1109 __key_eq_(std::move(__u.__key_eq_)) {
10861110 if (__a == allocator_type(__u.__node_alloc())) {
10871111 __bucket_list_.reset(__u.__bucket_list_.release());
10881112 __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
10891113 __u.__bucket_list_.get_deleter().size() = 0;
10901114 if (__u.size() > 0) {
1091 __p1_.first().__next_ = __u.__p1_.first().__next_;
1092 __u.__p1_.first().__next_ = nullptr;
1093 __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr();
1115 __first_node_.__next_ = __u.__first_node_.__next_;
1116 __u.__first_node_.__next_ = nullptr;
1117 __bucket_list_[std::__constrain_hash(__first_node_.__next_->__hash(), bucket_count())] = __first_node_.__ptr();
10941118 size() = __u.size();
10951119 __u.size() = 0;
10961120 }
......@@ -1104,7 +1128,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table() {
11041128 static_assert(is_copy_constructible<hasher>::value, "Hasher must be copy-constructible.");
11051129#endif
11061130
1107 __deallocate_node(__p1_.first().__next_);
1131 __deallocate_node(__first_node_.__next_);
11081132}
11091133
11101134template <class _Tp, class _Hash, class _Equal, class _Alloc>
......@@ -1150,8 +1174,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT {
11501174 for (size_type __i = 0; __i < __bc; ++__i)
11511175 __bucket_list_[__i] = nullptr;
11521176 size() = 0;
1153 __next_pointer __cache = __p1_.first().__next_;
1154 __p1_.first().__next_ = nullptr;
1177 __next_pointer __cache = __first_node_.__next_;
1178 __first_node_.__next_ = nullptr;
11551179 return __cache;
11561180}
11571181
......@@ -1168,10 +1192,10 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(__hash_table& __u,
11681192 hash_function() = std::move(__u.hash_function());
11691193 max_load_factor() = __u.max_load_factor();
11701194 key_eq() = std::move(__u.key_eq());
1171 __p1_.first().__next_ = __u.__p1_.first().__next_;
1195 __first_node_.__next_ = __u.__first_node_.__next_;
11721196 if (size() > 0) {
1173 __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr();
1174 __u.__p1_.first().__next_ = nullptr;
1197 __bucket_list_[std::__constrain_hash(__first_node_.__next_->__hash(), bucket_count())] = __first_node_.__ptr();
1198 __u.__first_node_.__next_ = nullptr;
11751199 __u.size() = 0;
11761200 }
11771201}
......@@ -1186,9 +1210,9 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(__hash_table& __u,
11861210 max_load_factor() = __u.max_load_factor();
11871211 if (bucket_count() != 0) {
11881212 __next_pointer __cache = __detach();
1189#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1213#if _LIBCPP_HAS_EXCEPTIONS
11901214 try {
1191#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1215#endif // _LIBCPP_HAS_EXCEPTIONS
11921216 const_iterator __i = __u.begin();
11931217 while (__cache != nullptr && __u.size() != 0) {
11941218 __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,
11961220 __node_insert_multi(__cache->__upcast());
11971221 __cache = __next;
11981222 }
1199#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1223#if _LIBCPP_HAS_EXCEPTIONS
12001224 } catch (...) {
12011225 __deallocate_node(__cache);
12021226 throw;
12031227 }
1204#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1228#endif // _LIBCPP_HAS_EXCEPTIONS
12051229 __deallocate_node(__cache);
12061230 }
12071231 const_iterator __i = __u.begin();
......@@ -1232,21 +1256,21 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __
12321256
12331257 if (bucket_count() != 0) {
12341258 __next_pointer __cache = __detach();
1235#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1259#if _LIBCPP_HAS_EXCEPTIONS
12361260 try {
1237#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1261#endif // _LIBCPP_HAS_EXCEPTIONS
12381262 for (; __cache != nullptr && __first != __last; ++__first) {
12391263 __cache->__upcast()->__get_value() = *__first;
12401264 __next_pointer __next = __cache->__next_;
12411265 __node_insert_unique(__cache->__upcast());
12421266 __cache = __next;
12431267 }
1244#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1268#if _LIBCPP_HAS_EXCEPTIONS
12451269 } catch (...) {
12461270 __deallocate_node(__cache);
12471271 throw;
12481272 }
1249#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1273#endif // _LIBCPP_HAS_EXCEPTIONS
12501274 __deallocate_node(__cache);
12511275 }
12521276 for (; __first != __last; ++__first)
......@@ -1264,21 +1288,21 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __f
12641288 " or the nodes value type");
12651289 if (bucket_count() != 0) {
12661290 __next_pointer __cache = __detach();
1267#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1291#if _LIBCPP_HAS_EXCEPTIONS
12681292 try {
1269#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1293#endif // _LIBCPP_HAS_EXCEPTIONS
12701294 for (; __cache != nullptr && __first != __last; ++__first) {
12711295 __cache->__upcast()->__get_value() = *__first;
12721296 __next_pointer __next = __cache->__next_;
12731297 __node_insert_multi(__cache->__upcast());
12741298 __cache = __next;
12751299 }
1276#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1300#if _LIBCPP_HAS_EXCEPTIONS
12771301 } catch (...) {
12781302 __deallocate_node(__cache);
12791303 throw;
12801304 }
1281#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1305#endif // _LIBCPP_HAS_EXCEPTIONS
12821306 __deallocate_node(__cache);
12831307 }
12841308 for (; __first != __last; ++__first)
......@@ -1288,7 +1312,7 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __f
12881312template <class _Tp, class _Hash, class _Equal, class _Alloc>
12891313inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
12901314__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT {
1291 return iterator(__p1_.first().__next_);
1315 return iterator(__first_node_.__next_);
12921316}
12931317
12941318template <class _Tp, class _Hash, class _Equal, class _Alloc>
......@@ -1300,7 +1324,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT {
13001324template <class _Tp, class _Hash, class _Equal, class _Alloc>
13011325inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
13021326__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT {
1303 return const_iterator(__p1_.first().__next_);
1327 return const_iterator(__first_node_.__next_);
13041328}
13051329
13061330template <class _Tp, class _Hash, class _Equal, class _Alloc>
......@@ -1312,8 +1336,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT {
13121336template <class _Tp, class _Hash, class _Equal, class _Alloc>
13131337void __hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT {
13141338 if (size() > 0) {
1315 __deallocate_node(__p1_.first().__next_);
1316 __p1_.first().__next_ = nullptr;
1339 __deallocate_node(__first_node_.__next_);
1340 __first_node_.__next_ = nullptr;
13171341 size_type __bc = bucket_count();
13181342 for (size_type __i = 0; __i < __bc; ++__i)
13191343 __bucket_list_[__i] = nullptr;
......@@ -1348,7 +1372,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_prepare(size_t __
13481372 }
13491373 if (size() + 1 > __bc * max_load_factor() || __bc == 0) {
13501374 __rehash_unique(std::max<size_type>(
1351 2 * __bc + !std::__is_hash_power2(__bc), size_type(std::ceil(float(size() + 1) / max_load_factor()))));
1375 2 * __bc + !std::__is_hash_power2(__bc), size_type(__math::ceil(float(size() + 1) / max_load_factor()))));
13521376 }
13531377 return nullptr;
13541378}
......@@ -1365,7 +1389,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_perform(__node_po
13651389 // insert_after __bucket_list_[__chash], or __first_node if bucket is null
13661390 __next_pointer __pn = __bucket_list_[__chash];
13671391 if (__pn == nullptr) {
1368 __pn = __p1_.first().__ptr();
1392 __pn = __first_node_.__ptr();
13691393 __nd->__next_ = __pn->__next_;
13701394 __pn->__next_ = __nd->__ptr();
13711395 // fix up __bucket_list_
......@@ -1408,7 +1432,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_prepare(size_t __c
14081432 size_type __bc = bucket_count();
14091433 if (size() + 1 > __bc * max_load_factor() || __bc == 0) {
14101434 __rehash_multi(std::max<size_type>(
1411 2 * __bc + !std::__is_hash_power2(__bc), size_type(std::ceil(float(size() + 1) / max_load_factor()))));
1435 2 * __bc + !std::__is_hash_power2(__bc), size_type(__math::ceil(float(size() + 1) / max_load_factor()))));
14121436 __bc = bucket_count();
14131437 }
14141438 size_t __chash = std::__constrain_hash(__cp_hash, __bc);
......@@ -1445,7 +1469,7 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_perform(
14451469 size_type __bc = bucket_count();
14461470 size_t __chash = std::__constrain_hash(__cp->__hash_, __bc);
14471471 if (__pn == nullptr) {
1448 __pn = __p1_.first().__ptr();
1472 __pn = __first_node_.__ptr();
14491473 __cp->__next_ = __pn->__next_;
14501474 __pn->__next_ = __cp->__ptr();
14511475 // fix up __bucket_list_
......@@ -1483,7 +1507,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(const_iterator __p
14831507 size_type __bc = bucket_count();
14841508 if (size() + 1 > __bc * max_load_factor() || __bc == 0) {
14851509 __rehash_multi(std::max<size_type>(
1486 2 * __bc + !std::__is_hash_power2(__bc), size_type(std::ceil(float(size() + 1) / max_load_factor()))));
1510 2 * __bc + !std::__is_hash_power2(__bc), size_type(__math::ceil(float(size() + 1) / max_load_factor()))));
14871511 __bc = bucket_count();
14881512 }
14891513 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&
15231547 __node_holder __h = __construct_node_hash(__hash, std::forward<_Args>(__args)...);
15241548 if (size() + 1 > __bc * max_load_factor() || __bc == 0) {
15251549 __rehash_unique(std::max<size_type>(
1526 2 * __bc + !std::__is_hash_power2(__bc), size_type(std::ceil(float(size() + 1) / max_load_factor()))));
1550 2 * __bc + !std::__is_hash_power2(__bc), size_type(__math::ceil(float(size() + 1) / max_load_factor()))));
15271551 __bc = bucket_count();
15281552 __chash = std::__constrain_hash(__hash, __bc);
15291553 }
15301554 // insert_after __bucket_list_[__chash], or __first_node if bucket is null
15311555 __next_pointer __pn = __bucket_list_[__chash];
15321556 if (__pn == nullptr) {
1533 __pn = __p1_.first().__ptr();
1557 __pn = __first_node_.__ptr();
15341558 __h->__next_ = __pn->__next_;
15351559 __pn->__next_ = __h.get()->__ptr();
15361560 // fix up __bucket_list_
......@@ -1692,8 +1716,8 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __n) _LIBCPP_D
16921716 else if (__n < __bc) {
16931717 __n = std::max<size_type>(
16941718 __n,
1695 std::__is_hash_power2(__bc) ? std::__next_hash_pow2(size_t(std::ceil(float(size()) / max_load_factor())))
1696 : std::__next_prime(size_t(std::ceil(float(size()) / max_load_factor()))));
1719 std::__is_hash_power2(__bc) ? std::__next_hash_pow2(size_t(__math::ceil(float(size()) / max_load_factor())))
1720 : std::__next_prime(size_t(__math::ceil(float(size()) / max_load_factor()))));
16971721 if (__n < __bc)
16981722 __do_rehash<_UniqueKeys>(__n);
16991723 }
......@@ -1708,7 +1732,7 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__do_rehash(size_type __nbc) {
17081732 if (__nbc > 0) {
17091733 for (size_type __i = 0; __i < __nbc; ++__i)
17101734 __bucket_list_[__i] = nullptr;
1711 __next_pointer __pp = __p1_.first().__ptr();
1735 __next_pointer __pp = __first_node_.__ptr();
17121736 __next_pointer __cp = __pp->__next_;
17131737 if (__cp != nullptr) {
17141738 size_type __chash = std::__constrain_hash(__cp->__hash(), __nbc);
......@@ -1885,7 +1909,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT {
18851909 // Fix up __bucket_list_
18861910 // if __pn is not in same bucket (before begin is not in same bucket) &&
18871911 // if __cn->__next_ is not in same bucket (nullptr is not in same bucket)
1888 if (__pn == __p1_.first().__ptr() || std::__constrain_hash(__pn->__hash(), __bc) != __chash) {
1912 if (__pn == __first_node_.__ptr() || std::__constrain_hash(__pn->__hash(), __bc) != __chash) {
18891913 if (__cn->__next_ == nullptr || std::__constrain_hash(__cn->__next_->__hash(), __bc) != __chash)
18901914 __bucket_list_[__chash] = nullptr;
18911915 }
......@@ -2004,14 +2028,17 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u)
20042028 std::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size());
20052029 std::__swap_allocator(__bucket_list_.get_deleter().__alloc(), __u.__bucket_list_.get_deleter().__alloc());
20062030 std::__swap_allocator(__node_alloc(), __u.__node_alloc());
2007 std::swap(__p1_.first().__next_, __u.__p1_.first().__next_);
2008 __p2_.swap(__u.__p2_);
2009 __p3_.swap(__u.__p3_);
2031 std::swap(__first_node_.__next_, __u.__first_node_.__next_);
2032 using std::swap;
2033 swap(__size_, __u.__size_);
2034 swap(__hasher_, __u.__hasher_);
2035 swap(__max_load_factor_, __u.__max_load_factor_);
2036 swap(__key_eq_, __u.__key_eq_);
20102037 if (size() > 0)
2011 __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr();
2038 __bucket_list_[std::__constrain_hash(__first_node_.__next_->__hash(), bucket_count())] = __first_node_.__ptr();
20122039 if (__u.size() > 0)
2013 __u.__bucket_list_[std::__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] =
2014 __u.__p1_.first().__ptr();
2040 __u.__bucket_list_[std::__constrain_hash(__u.__first_node_.__next_->__hash(), __u.bucket_count())] =
2041 __u.__first_node_.__ptr();
20152042}
20162043
20172044template <class _Tp, class _Hash, class _Equal, class _Alloc>
lib/libcxx/include/__iterator/access.h+1-1
......@@ -11,7 +11,7 @@
1111#define _LIBCPP___ITERATOR_ACCESS_H
1212
1313#include <__config>
14#include <cstddef>
14#include <__cstddef/size_t.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717# pragma GCC system_header
lib/libcxx/include/__iterator/advance.h+2-6
......@@ -76,9 +76,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 void advance(_InputIter& __i
7676// [range.iter.op.advance]
7777
7878namespace ranges {
79namespace __advance {
80
81struct __fn {
79struct __advance {
8280private:
8381 template <class _Ip>
8482 _LIBCPP_HIDE_FROM_ABI static constexpr void __advance_forward(_Ip& __i, iter_difference_t<_Ip> __n) {
......@@ -189,10 +187,8 @@ public:
189187 }
190188};
191189
192} // namespace __advance
193
194190inline namespace __cpo {
195inline constexpr auto advance = __advance::__fn{};
191inline constexpr auto advance = __advance{};
196192} // namespace __cpo
197193} // namespace ranges
198194
lib/libcxx/include/__iterator/aliasing_iterator.h+4-4
......@@ -10,10 +10,10 @@
1010#define _LIBCPP___ITERATOR_ALIASING_ITERATOR_H
1111
1212#include <__config>
13#include <__cstddef/ptrdiff_t.h>
1314#include <__iterator/iterator_traits.h>
1415#include <__memory/pointer_traits.h>
1516#include <__type_traits/is_trivial.h>
16#include <cstddef>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1919# pragma GCC system_header
......@@ -31,8 +31,8 @@ struct __aliasing_iterator_wrapper {
3131 class __iterator {
3232 _BaseIter __base_ = nullptr;
3333
34 using __iter_traits = iterator_traits<_BaseIter>;
35 using __base_value_type = typename __iter_traits::value_type;
34 using __iter_traits _LIBCPP_NODEBUG = iterator_traits<_BaseIter>;
35 using __base_value_type _LIBCPP_NODEBUG = typename __iter_traits::value_type;
3636
3737 static_assert(__has_random_access_iterator_category<_BaseIter>::value,
3838 "The base iterator has to be a random access iterator!");
......@@ -120,7 +120,7 @@ struct __aliasing_iterator_wrapper {
120120
121121// This is required to avoid ADL instantiations on _BaseT
122122template <class _BaseT, class _Alias>
123using __aliasing_iterator = typename __aliasing_iterator_wrapper<_BaseT, _Alias>::__iterator;
123using __aliasing_iterator _LIBCPP_NODEBUG = typename __aliasing_iterator_wrapper<_BaseT, _Alias>::__iterator;
124124
125125_LIBCPP_END_NAMESPACE_STD
126126
lib/libcxx/include/__iterator/back_insert_iterator.h+1-1
......@@ -11,11 +11,11 @@
1111#define _LIBCPP___ITERATOR_BACK_INSERT_ITERATOR_H
1212
1313#include <__config>
14#include <__cstddef/ptrdiff_t.h>
1415#include <__iterator/iterator.h>
1516#include <__iterator/iterator_traits.h>
1617#include <__memory/addressof.h>
1718#include <__utility/move.h>
18#include <cstddef>
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2121# pragma GCC system_header
lib/libcxx/include/__iterator/bounded_iter.h+18-8
......@@ -16,9 +16,13 @@
1616#include <__config>
1717#include <__iterator/iterator_traits.h>
1818#include <__memory/pointer_traits.h>
19#include <__type_traits/conjunction.h>
20#include <__type_traits/disjunction.h>
1921#include <__type_traits/enable_if.h>
2022#include <__type_traits/integral_constant.h>
2123#include <__type_traits/is_convertible.h>
24#include <__type_traits/is_same.h>
25#include <__type_traits/make_const_lvalue_ref.h>
2226#include <__utility/move.h>
2327
2428#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -47,8 +51,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4751// pointer, it is undefined at the language level (see [expr.add]). If
4852// bounded iterators exhibited this undefined behavior, we risk compiler
4953// optimizations deleting non-redundant bounds checks.
50template <class _Iterator, class = __enable_if_t< __libcpp_is_contiguous_iterator<_Iterator>::value > >
54template <class _Iterator>
5155struct __bounded_iter {
56 static_assert(__libcpp_is_contiguous_iterator<_Iterator>::value,
57 "Only contiguous iterators can be adapted by __bounded_iter.");
58
5259 using value_type = typename iterator_traits<_Iterator>::value_type;
5360 using difference_type = typename iterator_traits<_Iterator>::difference_type;
5461 using pointer = typename iterator_traits<_Iterator>::pointer;
......@@ -60,14 +67,19 @@ struct __bounded_iter {
6067
6168 // Create a singular iterator.
6269 //
63 // Such an iterator points past the end of an empty span, so it is not dereferenceable.
64 // Observing operations like comparison and assignment are valid.
70 // Such an iterator points past the end of an empty range, so it is not dereferenceable.
71 // Operations like comparison and assignment are valid.
6572 _LIBCPP_HIDE_FROM_ABI __bounded_iter() = default;
6673
6774 _LIBCPP_HIDE_FROM_ABI __bounded_iter(__bounded_iter const&) = default;
6875 _LIBCPP_HIDE_FROM_ABI __bounded_iter(__bounded_iter&&) = default;
6976
70 template <class _OtherIterator, __enable_if_t< is_convertible<_OtherIterator, _Iterator>::value, int> = 0>
77 template < class _OtherIterator,
78 __enable_if_t<
79 _And< is_convertible<const _OtherIterator&, _Iterator>,
80 _Or<is_same<reference, __iter_reference<_OtherIterator> >,
81 is_same<reference, __make_const_lvalue_ref<__iter_reference<_OtherIterator> > > > >::value,
82 int> = 0>
7183 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bounded_iter(__bounded_iter<_OtherIterator> const& __other) _NOEXCEPT
7284 : __current_(__other.__current_),
7385 __begin_(__other.__begin_),
......@@ -209,9 +221,7 @@ public:
209221 operator!=(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT {
210222 return __x.__current_ != __y.__current_;
211223 }
212#endif
213224
214 // TODO(mordante) disable these overloads in the LLVM 20 release.
215225 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool
216226 operator<(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT {
217227 return __x.__current_ < __y.__current_;
......@@ -229,7 +239,7 @@ public:
229239 return __x.__current_ >= __y.__current_;
230240 }
231241
232#if _LIBCPP_STD_VER >= 20
242#else
233243 _LIBCPP_HIDE_FROM_ABI constexpr friend strong_ordering
234244 operator<=>(__bounded_iter const& __x, __bounded_iter const& __y) noexcept {
235245 if constexpr (three_way_comparable<_Iterator, strong_ordering>) {
......@@ -249,7 +259,7 @@ public:
249259private:
250260 template <class>
251261 friend struct pointer_traits;
252 template <class, class>
262 template <class>
253263 friend struct __bounded_iter;
254264 _Iterator __current_; // current iterator
255265 _Iterator __begin_, __end_; // valid range represented as [begin, end]
lib/libcxx/include/__iterator/common_iterator.h+2-1
......@@ -26,6 +26,7 @@
2626#include <__iterator/iterator_traits.h>
2727#include <__iterator/readable_traits.h>
2828#include <__memory/addressof.h>
29#include <__type_traits/conditional.h>
2930#include <__type_traits/is_pointer.h>
3031#include <__utility/declval.h>
3132#include <variant>
......@@ -235,7 +236,7 @@ public:
235236 return std::__unchecked_get<_Sent>(__x.__hold_) - std::__unchecked_get<_I2>(__y.__hold_);
236237 }
237238
238 _LIBCPP_HIDE_FROM_ABI friend constexpr iter_rvalue_reference_t<_Iter>
239 _LIBCPP_HIDE_FROM_ABI friend constexpr decltype(auto)
239240 iter_move(const common_iterator& __i) noexcept(noexcept(ranges::iter_move(std::declval<const _Iter&>())))
240241 requires input_iterator<_Iter>
241242 {
lib/libcxx/include/__iterator/concepts.h+46-17
......@@ -26,7 +26,6 @@
2626#include <__concepts/semiregular.h>
2727#include <__concepts/totally_ordered.h>
2828#include <__config>
29#include <__functional/invoke.h>
3029#include <__iterator/incrementable_traits.h>
3130#include <__iterator/iter_move.h>
3231#include <__iterator/iterator_traits.h>
......@@ -34,7 +33,10 @@
3433#include <__memory/pointer_traits.h>
3534#include <__type_traits/add_pointer.h>
3635#include <__type_traits/common_reference.h>
36#include <__type_traits/integral_constant.h>
37#include <__type_traits/invoke.h>
3738#include <__type_traits/is_pointer.h>
39#include <__type_traits/is_primary_template.h>
3840#include <__type_traits/is_reference.h>
3941#include <__type_traits/remove_cv.h>
4042#include <__type_traits/remove_cvref.h>
......@@ -64,8 +66,33 @@ concept __indirectly_readable_impl =
6466template <class _In>
6567concept indirectly_readable = __indirectly_readable_impl<remove_cvref_t<_In>>;
6668
69template <class _Tp>
70using __projected_iterator_t _LIBCPP_NODEBUG = typename _Tp::__projected_iterator;
71
72template <class _Tp>
73using __projected_projection_t _LIBCPP_NODEBUG = typename _Tp::__projected_projection;
74
75template <class _Tp>
76concept __specialization_of_projected = requires {
77 typename __projected_iterator_t<_Tp>;
78 typename __projected_projection_t<_Tp>;
79} && __is_primary_template<_Tp>::value;
80
81template <class _Tp>
82struct __indirect_value_t_impl {
83 using type = iter_value_t<_Tp>&;
84};
85template <__specialization_of_projected _Tp>
86struct __indirect_value_t_impl<_Tp> {
87 using type = invoke_result_t<__projected_projection_t<_Tp>&,
88 typename __indirect_value_t_impl<__projected_iterator_t<_Tp>>::type>;
89};
90
91template <indirectly_readable _Tp>
92using __indirect_value_t _LIBCPP_NODEBUG = typename __indirect_value_t_impl<_Tp>::type;
93
6794template <indirectly_readable _Tp>
68using iter_common_reference_t = common_reference_t<iter_reference_t<_Tp>, iter_value_t<_Tp>&>;
95using iter_common_reference_t = common_reference_t<iter_reference_t<_Tp>, __indirect_value_t<_Tp>>;
6996
7097// [iterator.concept.writable]
7198template <class _Out, class _Tp>
......@@ -176,43 +203,45 @@ concept __has_arrow = input_iterator<_Ip> && (is_pointer_v<_Ip> || requires(_Ip
176203// [indirectcallable.indirectinvocable]
177204template <class _Fp, class _It>
178205concept indirectly_unary_invocable =
179 indirectly_readable<_It> && copy_constructible<_Fp> && invocable<_Fp&, iter_value_t<_It>&> &&
206 indirectly_readable<_It> && copy_constructible<_Fp> && invocable<_Fp&, __indirect_value_t<_It>> &&
180207 invocable<_Fp&, iter_reference_t<_It>> &&
181 common_reference_with< invoke_result_t<_Fp&, iter_value_t<_It>&>, invoke_result_t<_Fp&, iter_reference_t<_It>>>;
208 common_reference_with< invoke_result_t<_Fp&, __indirect_value_t<_It>>,
209 invoke_result_t<_Fp&, iter_reference_t<_It>>>;
182210
183211template <class _Fp, class _It>
184212concept indirectly_regular_unary_invocable =
185 indirectly_readable<_It> && copy_constructible<_Fp> && regular_invocable<_Fp&, iter_value_t<_It>&> &&
213 indirectly_readable<_It> && copy_constructible<_Fp> && regular_invocable<_Fp&, __indirect_value_t<_It>> &&
186214 regular_invocable<_Fp&, iter_reference_t<_It>> &&
187 common_reference_with< invoke_result_t<_Fp&, iter_value_t<_It>&>, invoke_result_t<_Fp&, iter_reference_t<_It>>>;
215 common_reference_with< invoke_result_t<_Fp&, __indirect_value_t<_It>>,
216 invoke_result_t<_Fp&, iter_reference_t<_It>>>;
188217
189218template <class _Fp, class _It>
190219concept indirect_unary_predicate =
191 indirectly_readable<_It> && copy_constructible<_Fp> && predicate<_Fp&, iter_value_t<_It>&> &&
220 indirectly_readable<_It> && copy_constructible<_Fp> && predicate<_Fp&, __indirect_value_t<_It>> &&
192221 predicate<_Fp&, iter_reference_t<_It>>;
193222
194223template <class _Fp, class _It1, class _It2>
195224concept indirect_binary_predicate =
196225 indirectly_readable<_It1> && indirectly_readable<_It2> && copy_constructible<_Fp> &&
197 predicate<_Fp&, iter_value_t<_It1>&, iter_value_t<_It2>&> &&
198 predicate<_Fp&, iter_value_t<_It1>&, iter_reference_t<_It2>> &&
199 predicate<_Fp&, iter_reference_t<_It1>, iter_value_t<_It2>&> &&
226 predicate<_Fp&, __indirect_value_t<_It1>, __indirect_value_t<_It2>> &&
227 predicate<_Fp&, __indirect_value_t<_It1>, iter_reference_t<_It2>> &&
228 predicate<_Fp&, iter_reference_t<_It1>, __indirect_value_t<_It2>> &&
200229 predicate<_Fp&, iter_reference_t<_It1>, iter_reference_t<_It2>>;
201230
202231template <class _Fp, class _It1, class _It2 = _It1>
203232concept indirect_equivalence_relation =
204233 indirectly_readable<_It1> && indirectly_readable<_It2> && copy_constructible<_Fp> &&
205 equivalence_relation<_Fp&, iter_value_t<_It1>&, iter_value_t<_It2>&> &&
206 equivalence_relation<_Fp&, iter_value_t<_It1>&, iter_reference_t<_It2>> &&
207 equivalence_relation<_Fp&, iter_reference_t<_It1>, iter_value_t<_It2>&> &&
234 equivalence_relation<_Fp&, __indirect_value_t<_It1>, __indirect_value_t<_It2>> &&
235 equivalence_relation<_Fp&, __indirect_value_t<_It1>, iter_reference_t<_It2>> &&
236 equivalence_relation<_Fp&, iter_reference_t<_It1>, __indirect_value_t<_It2>> &&
208237 equivalence_relation<_Fp&, iter_reference_t<_It1>, iter_reference_t<_It2>>;
209238
210239template <class _Fp, class _It1, class _It2 = _It1>
211240concept indirect_strict_weak_order =
212241 indirectly_readable<_It1> && indirectly_readable<_It2> && copy_constructible<_Fp> &&
213 strict_weak_order<_Fp&, iter_value_t<_It1>&, iter_value_t<_It2>&> &&
214 strict_weak_order<_Fp&, iter_value_t<_It1>&, iter_reference_t<_It2>> &&
215 strict_weak_order<_Fp&, iter_reference_t<_It1>, iter_value_t<_It2>&> &&
242 strict_weak_order<_Fp&, __indirect_value_t<_It1>, __indirect_value_t<_It2>> &&
243 strict_weak_order<_Fp&, __indirect_value_t<_It1>, iter_reference_t<_It2>> &&
244 strict_weak_order<_Fp&, iter_reference_t<_It1>, __indirect_value_t<_It2>> &&
216245 strict_weak_order<_Fp&, iter_reference_t<_It1>, iter_reference_t<_It2>>;
217246
218247template <class _Fp, class... _Its>
......@@ -245,7 +274,7 @@ concept indirectly_copyable_storable =
245274#endif // _LIBCPP_STD_VER >= 20
246275
247276template <class _Tp>
248using __has_random_access_iterator_category_or_concept
277using __has_random_access_iterator_category_or_concept _LIBCPP_NODEBUG
249278#if _LIBCPP_STD_VER >= 20
250279 = integral_constant<bool, random_access_iterator<_Tp>>;
251280#else // _LIBCPP_STD_VER < 20
lib/libcxx/include/__iterator/counted_iterator.h+4-4
......@@ -11,6 +11,7 @@
1111#define _LIBCPP___ITERATOR_COUNTED_ITERATOR_H
1212
1313#include <__assert>
14#include <__compare/ordering.h>
1415#include <__concepts/assignable.h>
1516#include <__concepts/common_with.h>
1617#include <__concepts/constructible.h>
......@@ -28,7 +29,6 @@
2829#include <__type_traits/add_pointer.h>
2930#include <__type_traits/conditional.h>
3031#include <__utility/move.h>
31#include <compare>
3232
3333#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3434# pragma GCC system_header
......@@ -132,7 +132,7 @@ public:
132132 _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator++(int) {
133133 _LIBCPP_ASSERT_UNCATEGORIZED(__count_ > 0, "Iterator already at or past end.");
134134 --__count_;
135# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
135# if _LIBCPP_HAS_EXCEPTIONS
136136 try {
137137 return __current_++;
138138 } catch (...) {
......@@ -141,7 +141,7 @@ public:
141141 }
142142# else
143143 return __current_++;
144# endif // _LIBCPP_HAS_NO_EXCEPTIONS
144# endif // _LIBCPP_HAS_EXCEPTIONS
145145 }
146146
147147 _LIBCPP_HIDE_FROM_ABI constexpr counted_iterator operator++(int)
......@@ -249,7 +249,7 @@ public:
249249 return __rhs.__count_ <=> __lhs.__count_;
250250 }
251251
252 _LIBCPP_HIDE_FROM_ABI friend constexpr iter_rvalue_reference_t<_Iter>
252 _LIBCPP_HIDE_FROM_ABI friend constexpr decltype(auto)
253253 iter_move(const counted_iterator& __i) noexcept(noexcept(ranges::iter_move(__i.__current_)))
254254 requires input_iterator<_Iter>
255255 {
lib/libcxx/include/__iterator/data.h-1
......@@ -11,7 +11,6 @@
1111#define _LIBCPP___ITERATOR_DATA_H
1212
1313#include <__config>
14#include <cstddef>
1514#include <initializer_list>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__iterator/distance.h+2-6
......@@ -52,9 +52,7 @@ distance(_InputIter __first, _InputIter __last) {
5252// [range.iter.op.distance]
5353
5454namespace ranges {
55namespace __distance {
56
57struct __fn {
55struct __distance {
5856 template <class _Ip, sentinel_for<_Ip> _Sp>
5957 requires(!sized_sentinel_for<_Sp, _Ip>)
6058 _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Ip> operator()(_Ip __first, _Sp __last) const {
......@@ -85,10 +83,8 @@ struct __fn {
8583 }
8684};
8785
88} // namespace __distance
89
9086inline namespace __cpo {
91inline constexpr auto distance = __distance::__fn{};
87inline constexpr auto distance = __distance{};
9288} // namespace __cpo
9389} // namespace ranges
9490
lib/libcxx/include/__iterator/empty.h-1
......@@ -11,7 +11,6 @@
1111#define _LIBCPP___ITERATOR_EMPTY_H
1212
1313#include <__config>
14#include <cstddef>
1514#include <initializer_list>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__iterator/front_insert_iterator.h+1-1
......@@ -11,11 +11,11 @@
1111#define _LIBCPP___ITERATOR_FRONT_INSERT_ITERATOR_H
1212
1313#include <__config>
14#include <__cstddef/ptrdiff_t.h>
1415#include <__iterator/iterator.h>
1516#include <__iterator/iterator_traits.h>
1617#include <__memory/addressof.h>
1718#include <__utility/move.h>
18#include <cstddef>
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2121# pragma GCC system_header
lib/libcxx/include/__iterator/incrementable_traits.h+1-1
......@@ -12,13 +12,13 @@
1212
1313#include <__concepts/arithmetic.h>
1414#include <__config>
15#include <__cstddef/ptrdiff_t.h>
1516#include <__type_traits/conditional.h>
1617#include <__type_traits/is_object.h>
1718#include <__type_traits/is_primary_template.h>
1819#include <__type_traits/make_signed.h>
1920#include <__type_traits/remove_cvref.h>
2021#include <__utility/declval.h>
21#include <cstddef>
2222
2323#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2424# pragma GCC system_header
lib/libcxx/include/__iterator/insert_iterator.h+3-3
......@@ -11,12 +11,12 @@
1111#define _LIBCPP___ITERATOR_INSERT_ITERATOR_H
1212
1313#include <__config>
14#include <__cstddef/ptrdiff_t.h>
1415#include <__iterator/iterator.h>
1516#include <__iterator/iterator_traits.h>
1617#include <__memory/addressof.h>
1718#include <__ranges/access.h>
1819#include <__utility/move.h>
19#include <cstddef>
2020
2121#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2222# pragma GCC system_header
......@@ -29,10 +29,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2929
3030#if _LIBCPP_STD_VER >= 20
3131template <class _Container>
32using __insert_iterator_iter_t = ranges::iterator_t<_Container>;
32using __insert_iterator_iter_t _LIBCPP_NODEBUG = ranges::iterator_t<_Container>;
3333#else
3434template <class _Container>
35using __insert_iterator_iter_t = typename _Container::iterator;
35using __insert_iterator_iter_t _LIBCPP_NODEBUG = typename _Container::iterator;
3636#endif
3737
3838_LIBCPP_SUPPRESS_DEPRECATED_PUSH
lib/libcxx/include/__iterator/istream_iterator.h+1-1
......@@ -11,13 +11,13 @@
1111#define _LIBCPP___ITERATOR_ISTREAM_ITERATOR_H
1212
1313#include <__config>
14#include <__cstddef/ptrdiff_t.h>
1415#include <__fwd/istream.h>
1516#include <__fwd/string.h>
1617#include <__iterator/default_sentinel.h>
1718#include <__iterator/iterator.h>
1819#include <__iterator/iterator_traits.h>
1920#include <__memory/addressof.h>
20#include <cstddef>
2121
2222#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2323# pragma GCC system_header
lib/libcxx/include/__iterator/istreambuf_iterator.h+2
......@@ -16,6 +16,8 @@
1616#include <__iterator/default_sentinel.h>
1717#include <__iterator/iterator.h>
1818#include <__iterator/iterator_traits.h>
19#include <__string/char_traits.h>
20#include <iosfwd>
1921
2022#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2123# pragma GCC system_header
lib/libcxx/include/__iterator/iterator.h+1-1
......@@ -11,7 +11,7 @@
1111#define _LIBCPP___ITERATOR_ITERATOR_H
1212
1313#include <__config>
14#include <cstddef>
14#include <__cstddef/ptrdiff_t.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717# pragma GCC system_header
lib/libcxx/include/__iterator/iterator_traits.h+31-24
......@@ -18,12 +18,15 @@
1818#include <__concepts/same_as.h>
1919#include <__concepts/totally_ordered.h>
2020#include <__config>
21#include <__cstddef/ptrdiff_t.h>
2122#include <__fwd/pair.h>
2223#include <__iterator/incrementable_traits.h>
2324#include <__iterator/readable_traits.h>
2425#include <__type_traits/common_reference.h>
2526#include <__type_traits/conditional.h>
2627#include <__type_traits/disjunction.h>
28#include <__type_traits/enable_if.h>
29#include <__type_traits/integral_constant.h>
2730#include <__type_traits/is_convertible.h>
2831#include <__type_traits/is_object.h>
2932#include <__type_traits/is_primary_template.h>
......@@ -34,7 +37,6 @@
3437#include <__type_traits/remove_cvref.h>
3538#include <__type_traits/void_t.h>
3639#include <__utility/declval.h>
37#include <cstddef>
3840
3941#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4042# pragma GCC system_header
......@@ -45,7 +47,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4547#if _LIBCPP_STD_VER >= 20
4648
4749template <class _Tp>
48using __with_reference = _Tp&;
50using __with_reference _LIBCPP_NODEBUG = _Tp&;
4951
5052template <class _Tp>
5153concept __can_reference = requires { typename __with_reference<_Tp>; };
......@@ -78,19 +80,20 @@ struct __iter_traits_cache {
7880 using type = _If< __is_primary_template<iterator_traits<_Iter> >::value, _Iter, iterator_traits<_Iter> >;
7981};
8082template <class _Iter>
81using _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type;
83using _ITER_TRAITS _LIBCPP_NODEBUG = typename __iter_traits_cache<_Iter>::type;
8284
8385struct __iter_concept_concept_test {
8486 template <class _Iter>
85 using _Apply = typename _ITER_TRAITS<_Iter>::iterator_concept;
87 using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_concept;
8688};
8789struct __iter_concept_category_test {
8890 template <class _Iter>
89 using _Apply = typename _ITER_TRAITS<_Iter>::iterator_category;
91 using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_category;
9092};
9193struct __iter_concept_random_fallback {
9294 template <class _Iter>
93 using _Apply = __enable_if_t< __is_primary_template<iterator_traits<_Iter> >::value, random_access_iterator_tag >;
95 using _Apply _LIBCPP_NODEBUG =
96 __enable_if_t<__is_primary_template<iterator_traits<_Iter> >::value, random_access_iterator_tag>;
9497};
9598
9699template <class _Iter, class _Tester>
......@@ -104,7 +107,7 @@ struct __iter_concept_cache {
104107};
105108
106109template <class _Iter>
107using _ITER_CONCEPT = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>;
110using _ITER_CONCEPT _LIBCPP_NODEBUG = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>;
108111
109112template <class _Tp>
110113struct __has_iterator_typedefs {
......@@ -362,7 +365,7 @@ struct __iterator_traits<_Ip> {
362365
363366template <class _Ip>
364367struct iterator_traits : __iterator_traits<_Ip> {
365 using __primary_template = iterator_traits;
368 using __primary_template _LIBCPP_NODEBUG = iterator_traits;
366369};
367370
368371#else // _LIBCPP_STD_VER >= 20
......@@ -395,7 +398,7 @@ struct __iterator_traits<_Iter, true>
395398
396399template <class _Iter>
397400struct _LIBCPP_TEMPLATE_VIS iterator_traits : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> {
398 using __primary_template = iterator_traits;
401 using __primary_template _LIBCPP_NODEBUG = iterator_traits;
399402};
400403#endif // _LIBCPP_STD_VER >= 20
401404
......@@ -428,16 +431,19 @@ template <class _Tp, class _Up>
428431struct __has_iterator_concept_convertible_to<_Tp, _Up, false> : false_type {};
429432
430433template <class _Tp>
431using __has_input_iterator_category = __has_iterator_category_convertible_to<_Tp, input_iterator_tag>;
434using __has_input_iterator_category _LIBCPP_NODEBUG = __has_iterator_category_convertible_to<_Tp, input_iterator_tag>;
432435
433436template <class _Tp>
434using __has_forward_iterator_category = __has_iterator_category_convertible_to<_Tp, forward_iterator_tag>;
437using __has_forward_iterator_category _LIBCPP_NODEBUG =
438 __has_iterator_category_convertible_to<_Tp, forward_iterator_tag>;
435439
436440template <class _Tp>
437using __has_bidirectional_iterator_category = __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag>;
441using __has_bidirectional_iterator_category _LIBCPP_NODEBUG =
442 __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag>;
438443
439444template <class _Tp>
440using __has_random_access_iterator_category = __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag>;
445using __has_random_access_iterator_category _LIBCPP_NODEBUG =
446 __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag>;
441447
442448// __libcpp_is_contiguous_iterator determines if an iterator is known by
443449// libc++ to be contiguous, either because it advertises itself as such
......@@ -464,48 +470,49 @@ template <class _Iter>
464470class __wrap_iter;
465471
466472template <class _Tp>
467using __has_exactly_input_iterator_category =
473using __has_exactly_input_iterator_category _LIBCPP_NODEBUG =
468474 integral_constant<bool,
469475 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
470476 !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value>;
471477
472478template <class _Tp>
473using __has_exactly_forward_iterator_category =
479using __has_exactly_forward_iterator_category _LIBCPP_NODEBUG =
474480 integral_constant<bool,
475481 __has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value &&
476482 !__has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag>::value>;
477483
478484template <class _Tp>
479using __has_exactly_bidirectional_iterator_category =
485using __has_exactly_bidirectional_iterator_category _LIBCPP_NODEBUG =
480486 integral_constant<bool,
481487 __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag>::value &&
482488 !__has_iterator_category_convertible_to<_Tp, random_access_iterator_tag>::value>;
483489
484490template <class _InputIterator>
485using __iter_value_type = typename iterator_traits<_InputIterator>::value_type;
491using __iter_value_type _LIBCPP_NODEBUG = typename iterator_traits<_InputIterator>::value_type;
486492
487493template <class _InputIterator>
488using __iter_key_type = __remove_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>;
494using __iter_key_type _LIBCPP_NODEBUG =
495 __remove_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>;
489496
490497template <class _InputIterator>
491using __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type;
498using __iter_mapped_type _LIBCPP_NODEBUG = typename iterator_traits<_InputIterator>::value_type::second_type;
492499
493500template <class _InputIterator>
494using __iter_to_alloc_type =
501using __iter_to_alloc_type _LIBCPP_NODEBUG =
495502 pair<const typename iterator_traits<_InputIterator>::value_type::first_type,
496503 typename iterator_traits<_InputIterator>::value_type::second_type>;
497504
498505template <class _Iter>
499using __iterator_category_type = typename iterator_traits<_Iter>::iterator_category;
506using __iterator_category_type _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::iterator_category;
500507
501508template <class _Iter>
502using __iterator_pointer_type = typename iterator_traits<_Iter>::pointer;
509using __iterator_pointer_type _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::pointer;
503510
504511template <class _Iter>
505using __iter_diff_t = typename iterator_traits<_Iter>::difference_type;
512using __iter_diff_t _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::difference_type;
506513
507514template <class _Iter>
508using __iter_reference = typename iterator_traits<_Iter>::reference;
515using __iter_reference _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::reference;
509516
510517#if _LIBCPP_STD_VER >= 20
511518
lib/libcxx/include/__iterator/next.h+8-11
......@@ -25,7 +25,7 @@
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
2727template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
28inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _InputIter
28[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _InputIter
2929next(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n = 1) {
3030 // Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation.
3131 // 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 =
4141// [range.iter.op.next]
4242
4343namespace ranges {
44namespace __next {
45
46struct __fn {
44struct __next {
4745 template <input_or_output_iterator _Ip>
48 _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x) const {
46 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x) const {
4947 ++__x;
5048 return __x;
5149 }
5250
5351 template <input_or_output_iterator _Ip>
54 _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n) const {
52 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n) const {
5553 ranges::advance(__x, __n);
5654 return __x;
5755 }
5856
5957 template <input_or_output_iterator _Ip, sentinel_for<_Ip> _Sp>
60 _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, _Sp __bound_sentinel) const {
58 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, _Sp __bound_sentinel) const {
6159 ranges::advance(__x, __bound_sentinel);
6260 return __x;
6361 }
6462
6563 template <input_or_output_iterator _Ip, sentinel_for<_Ip> _Sp>
66 _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Sp __bound_sentinel) const {
64 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip
65 operator()(_Ip __x, iter_difference_t<_Ip> __n, _Sp __bound_sentinel) const {
6766 ranges::advance(__x, __n, __bound_sentinel);
6867 return __x;
6968 }
7069};
7170
72} // namespace __next
73
7471inline namespace __cpo {
75inline constexpr auto next = __next::__fn{};
72inline constexpr auto next = __next{};
7673} // namespace __cpo
7774} // namespace ranges
7875
lib/libcxx/include/__iterator/ostream_iterator.h+1-1
......@@ -11,12 +11,12 @@
1111#define _LIBCPP___ITERATOR_OSTREAM_ITERATOR_H
1212
1313#include <__config>
14#include <__cstddef/ptrdiff_t.h>
1415#include <__fwd/ostream.h>
1516#include <__fwd/string.h>
1617#include <__iterator/iterator.h>
1718#include <__iterator/iterator_traits.h>
1819#include <__memory/addressof.h>
19#include <cstddef>
2020
2121#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2222# pragma GCC system_header
lib/libcxx/include/__iterator/ostreambuf_iterator.h+7-2
......@@ -11,10 +11,13 @@
1111#define _LIBCPP___ITERATOR_OSTREAMBUF_ITERATOR_H
1212
1313#include <__config>
14#include <__cstddef/ptrdiff_t.h>
15#include <__fwd/ios.h>
16#include <__fwd/ostream.h>
17#include <__fwd/streambuf.h>
1418#include <__iterator/iterator.h>
1519#include <__iterator/iterator_traits.h>
16#include <cstddef>
17#include <iosfwd> // for forward declaration of basic_streambuf
20#include <iosfwd> // for forward declaration of ostreambuf_iterator
1821
1922#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2023# pragma GCC system_header
......@@ -62,9 +65,11 @@ public:
6265 _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator& operator++(int) { return *this; }
6366 _LIBCPP_HIDE_FROM_ABI bool failed() const _NOEXCEPT { return __sbuf_ == nullptr; }
6467
68#if _LIBCPP_HAS_LOCALIZATION
6569 template <class _Ch, class _Tr>
6670 friend _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator<_Ch, _Tr> __pad_and_output(
6771 ostreambuf_iterator<_Ch, _Tr> __s, const _Ch* __ob, const _Ch* __op, const _Ch* __oe, ios_base& __iob, _Ch __fl);
72#endif // _LIBCPP_HAS_LOCALIZATION
6873};
6974
7075_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__iterator/prev.h+24-11
......@@ -17,16 +17,20 @@
1717#include <__iterator/incrementable_traits.h>
1818#include <__iterator/iterator_traits.h>
1919#include <__type_traits/enable_if.h>
20#include <__utility/move.h>
2021
2122#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2223# pragma GCC system_header
2324#endif
2425
26_LIBCPP_PUSH_MACROS
27#include <__undef_macros>
28
2529_LIBCPP_BEGIN_NAMESPACE_STD
2630
2731template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
28inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _InputIter
29prev(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n = 1) {
32[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _InputIter
33prev(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n) {
3034 // Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation.
3135 // Note that this check duplicates the similar check in `std::advance`.
3236 _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 =
3539 return __x;
3640}
3741
42// LWG 3197
43// It is unclear what the implications of "BidirectionalIterator" in the standard are.
44// However, calling std::prev(non-bidi-iterator) is obviously an error and we should catch it at compile time.
45template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
46[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _InputIter prev(_InputIter __it) {
47 static_assert(__has_bidirectional_iterator_category<_InputIter>::value,
48 "Attempt to prev(it) with a non-bidirectional iterator");
49 return std::prev(std::move(__it), 1);
50}
51
3852#if _LIBCPP_STD_VER >= 20
3953
4054// [range.iter.op.prev]
4155
4256namespace ranges {
43namespace __prev {
44
45struct __fn {
57struct __prev {
4658 template <bidirectional_iterator _Ip>
47 _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x) const {
59 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x) const {
4860 --__x;
4961 return __x;
5062 }
5163
5264 template <bidirectional_iterator _Ip>
53 _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n) const {
65 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n) const {
5466 ranges::advance(__x, -__n);
5567 return __x;
5668 }
5769
5870 template <bidirectional_iterator _Ip>
59 _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Ip __bound_iter) const {
71 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip
72 operator()(_Ip __x, iter_difference_t<_Ip> __n, _Ip __bound_iter) const {
6073 ranges::advance(__x, -__n, __bound_iter);
6174 return __x;
6275 }
6376};
6477
65} // namespace __prev
66
6778inline namespace __cpo {
68inline constexpr auto prev = __prev::__fn{};
79inline constexpr auto prev = __prev{};
6980} // namespace __cpo
7081} // namespace ranges
7182
......@@ -73,4 +84,6 @@ inline constexpr auto prev = __prev::__fn{};
7384
7485_LIBCPP_END_NAMESPACE_STD
7586
87_LIBCPP_POP_MACROS
88
7689#endif // _LIBCPP___ITERATOR_PREV_H
lib/libcxx/include/__iterator/projected.h+8
......@@ -26,6 +26,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2626template <class _It, class _Proj>
2727struct __projected_impl {
2828 struct __type {
29 using __primary_template _LIBCPP_NODEBUG = __type;
30 using __projected_iterator _LIBCPP_NODEBUG = _It;
31 using __projected_projection _LIBCPP_NODEBUG = _Proj;
32
2933 using value_type = remove_cvref_t<indirect_result_t<_Proj&, _It>>;
3034 indirect_result_t<_Proj&, _It> operator*() const; // not defined
3135 };
......@@ -34,6 +38,10 @@ struct __projected_impl {
3438template <weakly_incrementable _It, class _Proj>
3539struct __projected_impl<_It, _Proj> {
3640 struct __type {
41 using __primary_template _LIBCPP_NODEBUG = __type;
42 using __projected_iterator _LIBCPP_NODEBUG = _It;
43 using __projected_projection _LIBCPP_NODEBUG = _Proj;
44
3745 using value_type = remove_cvref_t<indirect_result_t<_Proj&, _It>>;
3846 using difference_type = iter_difference_t<_It>;
3947 indirect_result_t<_Proj&, _It> operator*() const; // not defined
lib/libcxx/include/__iterator/ranges_iterator_traits.h+3-3
......@@ -24,13 +24,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2424#if _LIBCPP_STD_VER >= 23
2525
2626template <ranges::input_range _Range>
27using __range_key_type = __remove_const_t<typename ranges::range_value_t<_Range>::first_type>;
27using __range_key_type _LIBCPP_NODEBUG = __remove_const_t<typename ranges::range_value_t<_Range>::first_type>;
2828
2929template <ranges::input_range _Range>
30using __range_mapped_type = typename ranges::range_value_t<_Range>::second_type;
30using __range_mapped_type _LIBCPP_NODEBUG = typename ranges::range_value_t<_Range>::second_type;
3131
3232template <ranges::input_range _Range>
33using __range_to_alloc_type =
33using __range_to_alloc_type _LIBCPP_NODEBUG =
3434 pair<const typename ranges::range_value_t<_Range>::first_type, typename ranges::range_value_t<_Range>::second_type>;
3535
3636#endif
lib/libcxx/include/__iterator/reverse_access.h-1
......@@ -12,7 +12,6 @@
1212
1313#include <__config>
1414#include <__iterator/reverse_iterator.h>
15#include <cstddef>
1615#include <initializer_list>
1716
1817#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__iterator/reverse_iterator.h+6-4
......@@ -136,10 +136,12 @@ public:
136136 _LIBCPP_HIDE_FROM_ABI constexpr pointer operator->() const
137137 requires is_pointer_v<_Iter> || requires(const _Iter __i) { __i.operator->(); }
138138 {
139 _Iter __tmp = current;
140 --__tmp;
139141 if constexpr (is_pointer_v<_Iter>) {
140 return std::prev(current);
142 return __tmp;
141143 } else {
142 return std::prev(current).operator->();
144 return __tmp.operator->();
143145 }
144146 }
145147#else
......@@ -327,8 +329,8 @@ __reverse_range(_Range&& __range) {
327329
328330template <class _Iter, bool __b>
329331struct __unwrap_iter_impl<reverse_iterator<reverse_iterator<_Iter> >, __b> {
330 using _UnwrappedIter = decltype(__unwrap_iter_impl<_Iter>::__unwrap(std::declval<_Iter>()));
331 using _ReverseWrapper = reverse_iterator<reverse_iterator<_Iter> >;
332 using _UnwrappedIter _LIBCPP_NODEBUG = decltype(__unwrap_iter_impl<_Iter>::__unwrap(std::declval<_Iter>()));
333 using _ReverseWrapper _LIBCPP_NODEBUG = reverse_iterator<reverse_iterator<_Iter> >;
332334
333335 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ReverseWrapper
334336 __rewrap(_ReverseWrapper __orig_iter, _UnwrappedIter __unwrapped_iter) {
lib/libcxx/include/__iterator/segmented_iterator.h+2-2
......@@ -41,8 +41,8 @@
4141// Returns the iterator composed of the segment iterator and local iterator.
4242
4343#include <__config>
44#include <__cstddef/size_t.h>
4445#include <__type_traits/integral_constant.h>
45#include <cstddef>
4646
4747#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4848# pragma GCC system_header
......@@ -72,7 +72,7 @@ template <class _Tp>
7272struct __has_specialization<_Tp, sizeof(_Tp) * 0> : true_type {};
7373
7474template <class _Iterator>
75using __is_segmented_iterator = __has_specialization<__segmented_iterator_traits<_Iterator> >;
75using __is_segmented_iterator _LIBCPP_NODEBUG = __has_specialization<__segmented_iterator_traits<_Iterator> >;
7676
7777_LIBCPP_END_NAMESPACE_STD
7878
lib/libcxx/include/__iterator/size.h+2-1
......@@ -11,9 +11,10 @@
1111#define _LIBCPP___ITERATOR_SIZE_H
1212
1313#include <__config>
14#include <__cstddef/ptrdiff_t.h>
15#include <__cstddef/size_t.h>
1416#include <__type_traits/common_type.h>
1517#include <__type_traits/make_signed.h>
16#include <cstddef>
1718
1819#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1920# pragma GCC system_header
lib/libcxx/include/__iterator/static_bounded_iter.h created+318
......@@ -0,0 +1,318 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___ITERATOR_STATIC_BOUNDED_ITER_H
11#define _LIBCPP___ITERATOR_STATIC_BOUNDED_ITER_H
12
13#include <__assert>
14#include <__compare/ordering.h>
15#include <__compare/three_way_comparable.h>
16#include <__config>
17#include <__cstddef/size_t.h>
18#include <__iterator/iterator_traits.h>
19#include <__memory/pointer_traits.h>
20#include <__type_traits/conjunction.h>
21#include <__type_traits/disjunction.h>
22#include <__type_traits/enable_if.h>
23#include <__type_traits/integral_constant.h>
24#include <__type_traits/is_convertible.h>
25#include <__type_traits/is_same.h>
26#include <__type_traits/make_const_lvalue_ref.h>
27#include <__utility/move.h>
28
29#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
30# pragma GCC system_header
31#endif
32
33_LIBCPP_PUSH_MACROS
34#include <__undef_macros>
35
36_LIBCPP_BEGIN_NAMESPACE_STD
37
38template <class _Iterator, size_t _Size>
39struct __static_bounded_iter_storage {
40 _LIBCPP_HIDE_FROM_ABI __static_bounded_iter_storage() = default;
41 _LIBCPP_HIDE_FROM_ABI
42 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __static_bounded_iter_storage(_Iterator __current, _Iterator __begin)
43 : __current_(__current), __begin_(__begin) {}
44
45 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator& __current() _NOEXCEPT { return __current_; }
46 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __current() const _NOEXCEPT { return __current_; }
47 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __begin() const _NOEXCEPT { return __begin_; }
48 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __end() const _NOEXCEPT { return __begin_ + _Size; }
49
50private:
51 _Iterator __current_; // current iterator
52 _Iterator __begin_; // start of the valid range, which is [__begin_, __begin_ + _Size)
53};
54
55template <class _Iterator>
56struct __static_bounded_iter_storage<_Iterator, 0> {
57 _LIBCPP_HIDE_FROM_ABI __static_bounded_iter_storage() = default;
58 _LIBCPP_HIDE_FROM_ABI
59 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __static_bounded_iter_storage(_Iterator __current, _Iterator /* __begin */)
60 : __current_(__current) {}
61
62 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator& __current() _NOEXCEPT { return __current_; }
63 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __current() const _NOEXCEPT { return __current_; }
64 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __begin() const _NOEXCEPT { return __current_; }
65 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __end() const _NOEXCEPT { return __current_; }
66
67private:
68 _Iterator __current_; // current iterator
69};
70
71// This is an iterator wrapper for contiguous iterators that points within a range
72// whose size is known at compile-time. This is very similar to `__bounded_iter`,
73// except that we don't have to store the end of the range in physical memory since
74// it can be computed from the start of the range.
75//
76// The operations on which this iterator wrapper traps are the same as `__bounded_iter`.
77template <class _Iterator, size_t _Size>
78struct __static_bounded_iter {
79 static_assert(__libcpp_is_contiguous_iterator<_Iterator>::value,
80 "Only contiguous iterators can be adapted by __static_bounded_iter.");
81
82 using value_type = typename iterator_traits<_Iterator>::value_type;
83 using difference_type = typename iterator_traits<_Iterator>::difference_type;
84 using pointer = typename iterator_traits<_Iterator>::pointer;
85 using reference = typename iterator_traits<_Iterator>::reference;
86 using iterator_category = typename iterator_traits<_Iterator>::iterator_category;
87#if _LIBCPP_STD_VER >= 20
88 using iterator_concept = contiguous_iterator_tag;
89#endif
90
91 // Create a singular iterator.
92 //
93 // Such an iterator points past the end of an empty range, so it is not dereferenceable.
94 // Operations like comparison and assignment are valid.
95 _LIBCPP_HIDE_FROM_ABI __static_bounded_iter() = default;
96
97 _LIBCPP_HIDE_FROM_ABI __static_bounded_iter(__static_bounded_iter const&) = default;
98 _LIBCPP_HIDE_FROM_ABI __static_bounded_iter(__static_bounded_iter&&) = default;
99
100 template <class _OtherIterator,
101 __enable_if_t<
102 _And< is_convertible<const _OtherIterator&, _Iterator>,
103 _Or<is_same<reference, __iter_reference<_OtherIterator> >,
104 is_same<reference, __make_const_lvalue_ref<__iter_reference<_OtherIterator> > > > >::value,
105 int> = 0>
106 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
107 __static_bounded_iter(__static_bounded_iter<_OtherIterator, _Size> const& __other) _NOEXCEPT
108 : __storage_(__other.__storage_.__current(), __other.__storage_.__begin()) {}
109
110 // Assign a bounded iterator to another one, rebinding the bounds of the iterator as well.
111 _LIBCPP_HIDE_FROM_ABI __static_bounded_iter& operator=(__static_bounded_iter const&) = default;
112 _LIBCPP_HIDE_FROM_ABI __static_bounded_iter& operator=(__static_bounded_iter&&) = default;
113
114private:
115 // Create an iterator wrapping the given iterator, and whose bounds are described
116 // by the provided [begin, begin + _Size] range.
117 _LIBCPP_HIDE_FROM_ABI
118 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __static_bounded_iter(_Iterator __current, _Iterator __begin)
119 : __storage_(__current, __begin) {
120 _LIBCPP_ASSERT_INTERNAL(
121 __begin <= __current, "__static_bounded_iter(current, begin): current and begin are inconsistent");
122 _LIBCPP_ASSERT_INTERNAL(
123 __current <= __end(), "__static_bounded_iter(current, begin): current and (begin + Size) are inconsistent");
124 }
125
126 template <size_t _Sz, class _It>
127 friend _LIBCPP_CONSTEXPR __static_bounded_iter<_It, _Sz> __make_static_bounded_iter(_It, _It);
128
129public:
130 // Dereference and indexing operations.
131 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator*() const _NOEXCEPT {
132 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
133 __current() != __end(), "__static_bounded_iter::operator*: Attempt to dereference an iterator at the end");
134 return *__current();
135 }
136
137 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pointer operator->() const _NOEXCEPT {
138 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
139 __current() != __end(), "__static_bounded_iter::operator->: Attempt to dereference an iterator at the end");
140 return std::__to_address(__current());
141 }
142
143 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator[](difference_type __n) const _NOEXCEPT {
144 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
145 __n >= __begin() - __current(),
146 "__static_bounded_iter::operator[]: Attempt to index an iterator past the start");
147 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
148 __n < __end() - __current(),
149 "__static_bounded_iter::operator[]: Attempt to index an iterator at or past the end");
150 return __current()[__n];
151 }
152
153 // Arithmetic operations.
154 //
155 // These operations check that the iterator remains within `[begin, end]`.
156 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __static_bounded_iter& operator++() _NOEXCEPT {
157 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
158 __current() != __end(), "__static_bounded_iter::operator++: Attempt to advance an iterator past the end");
159 ++__current();
160 return *this;
161 }
162 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __static_bounded_iter operator++(int) _NOEXCEPT {
163 __static_bounded_iter __tmp(*this);
164 ++*this;
165 return __tmp;
166 }
167
168 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __static_bounded_iter& operator--() _NOEXCEPT {
169 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
170 __current() != __begin(), "__static_bounded_iter::operator--: Attempt to rewind an iterator past the start");
171 --__current();
172 return *this;
173 }
174 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __static_bounded_iter operator--(int) _NOEXCEPT {
175 __static_bounded_iter __tmp(*this);
176 --*this;
177 return __tmp;
178 }
179
180 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __static_bounded_iter& operator+=(difference_type __n) _NOEXCEPT {
181 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
182 __n >= __begin() - __current(),
183 "__static_bounded_iter::operator+=: Attempt to rewind an iterator past the start");
184 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
185 __n <= __end() - __current(), "__static_bounded_iter::operator+=: Attempt to advance an iterator past the end");
186 __current() += __n;
187 return *this;
188 }
189 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter
190 operator+(__static_bounded_iter const& __self, difference_type __n) _NOEXCEPT {
191 __static_bounded_iter __tmp(__self);
192 __tmp += __n;
193 return __tmp;
194 }
195 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter
196 operator+(difference_type __n, __static_bounded_iter const& __self) _NOEXCEPT {
197 __static_bounded_iter __tmp(__self);
198 __tmp += __n;
199 return __tmp;
200 }
201
202 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __static_bounded_iter& operator-=(difference_type __n) _NOEXCEPT {
203 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
204 __n <= __current() - __begin(),
205 "__static_bounded_iter::operator-=: Attempt to rewind an iterator past the start");
206 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
207 __n >= __current() - __end(), "__static_bounded_iter::operator-=: Attempt to advance an iterator past the end");
208 __current() -= __n;
209 return *this;
210 }
211 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter
212 operator-(__static_bounded_iter const& __self, difference_type __n) _NOEXCEPT {
213 __static_bounded_iter __tmp(__self);
214 __tmp -= __n;
215 return __tmp;
216 }
217 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend difference_type
218 operator-(__static_bounded_iter const& __x, __static_bounded_iter const& __y) _NOEXCEPT {
219 return __x.__current() - __y.__current();
220 }
221
222 // Comparison operations.
223 //
224 // These operations do not check whether the iterators are within their bounds.
225 // The valid range for each iterator is also not considered as part of the comparison,
226 // i.e. two iterators pointing to the same location will be considered equal even
227 // if they have different validity ranges.
228 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool
229 operator==(__static_bounded_iter const& __x, __static_bounded_iter const& __y) _NOEXCEPT {
230 return __x.__current() == __y.__current();
231 }
232
233#if _LIBCPP_STD_VER <= 17
234 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool
235 operator!=(__static_bounded_iter const& __x, __static_bounded_iter const& __y) _NOEXCEPT {
236 return __x.__current() != __y.__current();
237 }
238
239 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool
240 operator<(__static_bounded_iter const& __x, __static_bounded_iter const& __y) _NOEXCEPT {
241 return __x.__current() < __y.__current();
242 }
243 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool
244 operator>(__static_bounded_iter const& __x, __static_bounded_iter const& __y) _NOEXCEPT {
245 return __x.__current() > __y.__current();
246 }
247 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool
248 operator<=(__static_bounded_iter const& __x, __static_bounded_iter const& __y) _NOEXCEPT {
249 return __x.__current() <= __y.__current();
250 }
251 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool
252 operator>=(__static_bounded_iter const& __x, __static_bounded_iter const& __y) _NOEXCEPT {
253 return __x.__current() >= __y.__current();
254 }
255
256#else
257 _LIBCPP_HIDE_FROM_ABI constexpr friend strong_ordering
258 operator<=>(__static_bounded_iter const& __x, __static_bounded_iter const& __y) noexcept {
259 if constexpr (three_way_comparable<_Iterator, strong_ordering>) {
260 return __x.__current() <=> __y.__current();
261 } else {
262 if (__x.__current() < __y.__current())
263 return strong_ordering::less;
264
265 if (__x.__current() == __y.__current())
266 return strong_ordering::equal;
267
268 return strong_ordering::greater;
269 }
270 }
271#endif // _LIBCPP_STD_VER >= 20
272
273private:
274 template <class>
275 friend struct pointer_traits;
276 template <class, size_t>
277 friend struct __static_bounded_iter;
278 __static_bounded_iter_storage<_Iterator, _Size> __storage_;
279
280 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator& __current() _NOEXCEPT {
281 return __storage_.__current();
282 }
283 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __current() const _NOEXCEPT {
284 return __storage_.__current();
285 }
286 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __begin() const _NOEXCEPT {
287 return __storage_.__begin();
288 }
289 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __end() const _NOEXCEPT { return __storage_.__end(); }
290};
291
292template <size_t _Size, class _It>
293_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __static_bounded_iter<_It, _Size>
294__make_static_bounded_iter(_It __it, _It __begin) {
295 return __static_bounded_iter<_It, _Size>(std::move(__it), std::move(__begin));
296}
297
298#if _LIBCPP_STD_VER <= 17
299template <class _Iterator, size_t _Size>
300struct __libcpp_is_contiguous_iterator<__static_bounded_iter<_Iterator, _Size> > : true_type {};
301#endif
302
303template <class _Iterator, size_t _Size>
304struct pointer_traits<__static_bounded_iter<_Iterator, _Size> > {
305 using pointer = __static_bounded_iter<_Iterator, _Size>;
306 using element_type = typename pointer_traits<_Iterator>::element_type;
307 using difference_type = typename pointer_traits<_Iterator>::difference_type;
308
309 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static element_type* to_address(pointer __it) _NOEXCEPT {
310 return std::__to_address(__it.__current());
311 }
312};
313
314_LIBCPP_END_NAMESPACE_STD
315
316_LIBCPP_POP_MACROS
317
318#endif // _LIBCPP___ITERATOR_STATIC_BOUNDED_ITER_H
lib/libcxx/include/__iterator/wrap_iter.h+15-8
......@@ -13,12 +13,17 @@
1313#include <__compare/ordering.h>
1414#include <__compare/three_way_comparable.h>
1515#include <__config>
16#include <__cstddef/size_t.h>
1617#include <__iterator/iterator_traits.h>
1718#include <__memory/addressof.h>
1819#include <__memory/pointer_traits.h>
20#include <__type_traits/conjunction.h>
21#include <__type_traits/disjunction.h>
1922#include <__type_traits/enable_if.h>
23#include <__type_traits/integral_constant.h>
2024#include <__type_traits/is_convertible.h>
21#include <cstddef>
25#include <__type_traits/is_same.h>
26#include <__type_traits/make_const_lvalue_ref.h>
2227
2328#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2429# pragma GCC system_header
......@@ -44,9 +49,14 @@ private:
4449
4550public:
4651 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter() _NOEXCEPT : __i_() {}
47 template <class _Up, __enable_if_t<is_convertible<_Up, iterator_type>::value, int> = 0>
48 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter(const __wrap_iter<_Up>& __u) _NOEXCEPT
49 : __i_(__u.base()) {}
52 template <
53 class _OtherIter,
54 __enable_if_t< _And< is_convertible<const _OtherIter&, _Iter>,
55 _Or<is_same<reference, __iter_reference<_OtherIter> >,
56 is_same<reference, __make_const_lvalue_ref<__iter_reference<_OtherIter> > > > >::value,
57 int> = 0>
58 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter(const __wrap_iter<_OtherIter>& __u) _NOEXCEPT
59 : __i_(__u.__i_) {}
5060 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator*() const _NOEXCEPT { return *__i_; }
5161 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pointer operator->() const _NOEXCEPT {
5262 return std::__to_address(__i_);
......@@ -145,9 +155,6 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
145155operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT {
146156 return !(__x == __y);
147157}
148#endif
149
150// TODO(mordante) disable these overloads in the LLVM 20 release.
151158template <class _Iter1>
152159_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
153160operator>(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
184191 return !(__y < __x);
185192}
186193
187#if _LIBCPP_STD_VER >= 20
194#else
188195template <class _Iter1, class _Iter2>
189196_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering
190197operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept {
lib/libcxx/include/__locale+34-31
......@@ -12,7 +12,7 @@
1212
1313#include <__config>
1414#include <__locale_dir/locale_base_api.h>
15#include <__memory/shared_ptr.h> // __shared_count
15#include <__memory/shared_count.h>
1616#include <__mutex/once_flag.h>
1717#include <__type_traits/make_unsigned.h>
1818#include <__utility/no_destroy.h>
......@@ -27,7 +27,7 @@
2727#include <cstddef>
2828#include <cstring>
2929
30#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
30#if _LIBCPP_HAS_WIDE_CHARACTERS
3131# include <cwchar>
3232#else
3333# include <__std_mbstate_t.h>
......@@ -50,7 +50,7 @@ _LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale&);
5050class _LIBCPP_EXPORTED_FROM_ABI locale {
5151public:
5252 // locale is essentially a shared_ptr that doesn't support weak_ptrs and never got a move constructor.
53 using __trivially_relocatable = locale;
53 using __trivially_relocatable _LIBCPP_NODEBUG = locale;
5454
5555 // types:
5656 class _LIBCPP_EXPORTED_FROM_ABI facet;
......@@ -60,8 +60,9 @@ public:
6060
6161 static const category // values assigned here are for exposition only
6262 none = 0,
63 collate = LC_COLLATE_MASK, ctype = LC_CTYPE_MASK, monetary = LC_MONETARY_MASK, numeric = LC_NUMERIC_MASK,
64 time = LC_TIME_MASK, messages = LC_MESSAGES_MASK, all = collate | ctype | monetary | numeric | time | messages;
63 collate = _LIBCPP_COLLATE_MASK, ctype = _LIBCPP_CTYPE_MASK, monetary = _LIBCPP_MONETARY_MASK,
64 numeric = _LIBCPP_NUMERIC_MASK, time = _LIBCPP_TIME_MASK, messages = _LIBCPP_MESSAGES_MASK,
65 all = collate | ctype | monetary | numeric | time | messages;
6566
6667 // construct/copy/destroy:
6768 locale() _NOEXCEPT;
......@@ -236,7 +237,7 @@ long collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) cons
236237}
237238
238239extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>;
239#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
240#if _LIBCPP_HAS_WIDE_CHARACTERS
240241extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>;
241242#endif
242243
......@@ -247,7 +248,7 @@ class _LIBCPP_TEMPLATE_VIS collate_byname;
247248
248249template <>
249250class _LIBCPP_EXPORTED_FROM_ABI collate_byname<char> : public collate<char> {
250 locale_t __l_;
251 __locale::__locale_t __l_;
251252
252253public:
253254 typedef char char_type;
......@@ -263,10 +264,10 @@ protected:
263264 string_type do_transform(const char_type* __lo, const char_type* __hi) const override;
264265};
265266
266#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
267#if _LIBCPP_HAS_WIDE_CHARACTERS
267268template <>
268269class _LIBCPP_EXPORTED_FROM_ABI collate_byname<wchar_t> : public collate<wchar_t> {
269 locale_t __l_;
270 __locale::__locale_t __l_;
270271
271272public:
272273 typedef wchar_t char_type;
......@@ -348,7 +349,7 @@ public:
348349# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
349350#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
350351# ifdef __APPLE__
351 typedef __uint32_t mask;
352 typedef uint32_t mask;
352353# elif defined(__FreeBSD__)
353354 typedef unsigned long mask;
354355# elif defined(__NetBSD__)
......@@ -449,7 +450,7 @@ public:
449450template <class _CharT>
450451class _LIBCPP_TEMPLATE_VIS ctype;
451452
452#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
453#if _LIBCPP_HAS_WIDE_CHARACTERS
453454template <>
454455class _LIBCPP_EXPORTED_FROM_ABI ctype<wchar_t> : public locale::facet, public ctype_base {
455456public:
......@@ -514,7 +515,9 @@ protected:
514515 virtual const char_type*
515516 do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
516517};
517#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
518#endif // _LIBCPP_HAS_WIDE_CHARACTERS
519
520inline _LIBCPP_HIDE_FROM_ABI bool __libcpp_isascii(int __c) { return (__c & ~0x7F) == 0; }
518521
519522template <>
520523class _LIBCPP_EXPORTED_FROM_ABI ctype<char> : public locale::facet, public ctype_base {
......@@ -527,25 +530,25 @@ public:
527530 explicit ctype(const mask* __tab = nullptr, bool __del = false, size_t __refs = 0);
528531
529532 _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const {
530 return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) != 0 : false;
533 return std::__libcpp_isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) != 0 : false;
531534 }
532535
533536 _LIBCPP_HIDE_FROM_ABI const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const {
534537 for (; __low != __high; ++__low, ++__vec)
535 *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
538 *__vec = std::__libcpp_isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
536539 return __low;
537540 }
538541
539542 _LIBCPP_HIDE_FROM_ABI const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const {
540543 for (; __low != __high; ++__low)
541 if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
544 if (std::__libcpp_isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
542545 break;
543546 return __low;
544547 }
545548
546549 _LIBCPP_HIDE_FROM_ABI const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const {
547550 for (; __low != __high; ++__low)
548 if (!isascii(*__low) || !(__tab_[static_cast<int>(*__low)] & __m))
551 if (!std::__libcpp_isascii(*__low) || !(__tab_[static_cast<int>(*__low)] & __m))
549552 break;
550553 return __low;
551554 }
......@@ -616,7 +619,7 @@ class _LIBCPP_TEMPLATE_VIS ctype_byname;
616619
617620template <>
618621class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<char> : public ctype<char> {
619 locale_t __l_;
622 __locale::__locale_t __l_;
620623
621624public:
622625 explicit ctype_byname(const char*, size_t = 0);
......@@ -630,10 +633,10 @@ protected:
630633 const char_type* do_tolower(char_type* __low, const char_type* __high) const override;
631634};
632635
633#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
636#if _LIBCPP_HAS_WIDE_CHARACTERS
634637template <>
635638class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<wchar_t> : public ctype<wchar_t> {
636 locale_t __l_;
639 __locale::__locale_t __l_;
637640
638641public:
639642 explicit ctype_byname(const char*, size_t = 0);
......@@ -655,7 +658,7 @@ protected:
655658 const char_type*
656659 do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const override;
657660};
658#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
661#endif // _LIBCPP_HAS_WIDE_CHARACTERS
659662
660663template <class _CharT>
661664inline _LIBCPP_HIDE_FROM_ABI bool isspace(_CharT __c, const locale& __loc) {
......@@ -821,10 +824,10 @@ protected:
821824
822825// template <> class codecvt<wchar_t, char, mbstate_t>
823826
824#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
827#if _LIBCPP_HAS_WIDE_CHARACTERS
825828template <>
826829class _LIBCPP_EXPORTED_FROM_ABI codecvt<wchar_t, char, mbstate_t> : public locale::facet, public codecvt_base {
827 locale_t __l_;
830 __locale::__locale_t __l_;
828831
829832public:
830833 typedef wchar_t intern_type;
......@@ -900,7 +903,7 @@ protected:
900903 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
901904 virtual int do_max_length() const _NOEXCEPT;
902905};
903#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
906#endif // _LIBCPP_HAS_WIDE_CHARACTERS
904907
905908// template <> class codecvt<char16_t, char, mbstate_t> // deprecated in C++20
906909
......@@ -982,7 +985,7 @@ protected:
982985 virtual int do_max_length() const _NOEXCEPT;
983986};
984987
985#ifndef _LIBCPP_HAS_NO_CHAR8_T
988#if _LIBCPP_HAS_CHAR8_T
986989
987990// template <> class codecvt<char16_t, char8_t, mbstate_t> // C++20
988991
......@@ -1145,7 +1148,7 @@ protected:
11451148 virtual int do_max_length() const _NOEXCEPT;
11461149};
11471150
1148#ifndef _LIBCPP_HAS_NO_CHAR8_T
1151#if _LIBCPP_HAS_CHAR8_T
11491152
11501153// template <> class codecvt<char32_t, char8_t, mbstate_t> // C++20
11511154
......@@ -1248,14 +1251,14 @@ codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname() {}
12481251_LIBCPP_SUPPRESS_DEPRECATED_POP
12491252
12501253extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>;
1251#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1254#if _LIBCPP_HAS_WIDE_CHARACTERS
12521255extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>;
12531256#endif
12541257extern template class _LIBCPP_DEPRECATED_IN_CXX20
12551258_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>; // deprecated in C++20
12561259extern template class _LIBCPP_DEPRECATED_IN_CXX20
12571260_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>; // deprecated in C++20
1258#ifndef _LIBCPP_HAS_NO_CHAR8_T
1261#if _LIBCPP_HAS_CHAR8_T
12591262extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>; // C++20
12601263extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>; // C++20
12611264#endif
......@@ -1438,7 +1441,7 @@ protected:
14381441 string __grouping_;
14391442};
14401443
1441#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1444#if _LIBCPP_HAS_WIDE_CHARACTERS
14421445template <>
14431446class _LIBCPP_EXPORTED_FROM_ABI numpunct<wchar_t> : public locale::facet {
14441447public:
......@@ -1467,7 +1470,7 @@ protected:
14671470 char_type __thousands_sep_;
14681471 string __grouping_;
14691472};
1470#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1473#endif // _LIBCPP_HAS_WIDE_CHARACTERS
14711474
14721475// template <class charT> class numpunct_byname
14731476
......@@ -1490,7 +1493,7 @@ private:
14901493 void __init(const char*);
14911494};
14921495
1493#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1496#if _LIBCPP_HAS_WIDE_CHARACTERS
14941497template <>
14951498class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname<wchar_t> : public numpunct<wchar_t> {
14961499public:
......@@ -1506,7 +1509,7 @@ protected:
15061509private:
15071510 void __init(const char*);
15081511};
1509#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1512#endif // _LIBCPP_HAS_WIDE_CHARACTERS
15101513
15111514_LIBCPP_END_NAMESPACE_STD
15121515
lib/libcxx/include/__locale_dir/locale_base_api.h+305-80
......@@ -9,90 +9,315 @@
99#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H
1010#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H
1111
12#if defined(_LIBCPP_MSVCRT_LIKE)
13# include <__locale_dir/locale_base_api/win32.h>
14#elif defined(_AIX) || defined(__MVS__)
15# include <__locale_dir/locale_base_api/ibm.h>
16#elif defined(__ANDROID__)
17# include <__locale_dir/locale_base_api/android.h>
18#elif defined(__sun__)
19# include <__locale_dir/locale_base_api/solaris.h>
20#elif defined(_NEWLIB_VERSION)
21# include <__locale_dir/locale_base_api/newlib.h>
22#elif defined(__OpenBSD__)
23# include <__locale_dir/locale_base_api/openbsd.h>
24#elif defined(__Fuchsia__)
25# include <__locale_dir/locale_base_api/fuchsia.h>
26#elif defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC)
27# include <__locale_dir/locale_base_api/musl.h>
28#elif defined(__APPLE__) || defined(__FreeBSD__)
29# include <xlocale.h>
30#endif
12#include <__config>
3113
3214#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3315# pragma GCC system_header
3416#endif
3517
36/*
37The platform-specific headers have to provide the following interface:
38
39// TODO: rename this to __libcpp_locale_t
40using locale_t = implementation-defined;
41
42implementation-defined __libcpp_mb_cur_max_l(locale_t);
43wint_t __libcpp_btowc_l(int, locale_t);
44int __libcpp_wctob_l(wint_t, locale_t);
45size_t __libcpp_wcsnrtombs_l(char* dest, const wchar_t** src, size_t wide_char_count, size_t len, mbstate_t, locale_t);
46size_t __libcpp_wcrtomb_l(char* str, wchar_t wide_char, mbstate_t*, locale_t);
47size_t __libcpp_mbsnrtowcs_l(wchar_t* dest, const char** src, size_t max_out, size_t len, mbstate_t*, locale_t);
48size_t __libcpp_mbrtowc_l(wchar_t* dest, cosnt char* src, size_t count, mbstate_t*, locale_t);
49int __libcpp_mbtowc_l(wchar_t* dest, const char* src, size_t count, locale_t);
50size_t __libcpp_mbrlen_l(const char* str, size_t count, mbstate_t*, locale_t);
51lconv* __libcpp_localeconv_l(locale_t);
52size_t __libcpp_mbsrtowcs_l(wchar_t* dest, const char** src, size_t len, mbstate_t*, locale_t);
53int __libcpp_snprintf_l(char* dest, size_t buff_size, locale_t, const char* format, ...);
54int __libcpp_asprintf_l(char** dest, locale_t, const char* format, ...);
55int __libcpp_sscanf_l(const char* dest, locale_t, const char* format, ...);
56
57// TODO: change these to reserved names
58float strtof_l(const char* str, char** str_end, locale_t);
59double strtod_l(const char* str, char** str_end, locale_t);
60long double strtold_l(const char* str, char** str_end, locale_t);
61long long strtoll_l(const char* str, char** str_end, locale_t);
62unsigned long long strtoull_l(const char* str, char** str_end, locale_t);
63
64locale_t newlocale(int category_mask, const char* locale, locale_t base);
65void freelocale(locale_t);
66
67int islower_l(int ch, locale_t);
68int isupper_l(int ch, locale_t);
69int isdigit_l(int ch, locale_t);
70int isxdigit_l(int ch, locale_t);
71int strcoll_l(const char* lhs, const char* rhs, locale_t);
72size_t strxfrm_l(char* dst, const char* src, size_t n, locale_t);
73int wcscoll_l(const char* lhs, const char* rhs, locale_t);
74size_t wcsxfrm_l(wchar_t* dst, const wchar_t* src, size_t n, locale_t);
75int toupper_l(int ch, locale_t);
76int tolower_l(int ch, locale_t);
77int iswspace_l(wint_t ch, locale_t);
78int iswprint_l(wint_t ch, locale_t);
79int iswcntrl_l(wint_t ch, locale_t);
80int iswupper_l(wint_t ch, locale_t);
81int iswlower_l(wint_t ch, locale_t);
82int iswalpha_l(wint_t ch, locale_t);
83int iswblank_l(wint_t ch, locale_t);
84int iswdigit_l(wint_t ch, locale_t);
85int iswpunct_l(wint_t ch, locale_t);
86int iswxdigit_l(wint_t ch, locale_t);
87wint_t towupper_l(wint_t ch, locale_t);
88wint_t towlower_l(wint_t ch, locale_t);
89size_t strftime_l(char* str, size_t len, const char* format, const tm*, locale_t);
90
91
92These functions are equivalent to their C counterparts,
93except that locale_t is used instead of the current global locale.
94
95The variadic functions may be implemented as templates with a parameter pack instead of variadic functions.
96*/
18// The platform-specific headers have to provide the following interface.
19//
20// These functions are equivalent to their C counterparts, except that __locale::__locale_t
21// is used instead of the current global locale.
22//
23// Variadic functions may be implemented as templates with a parameter pack instead
24// of C-style variadic functions.
25//
26// Most of these functions are only required when building the library. Functions that are also
27// required when merely using the headers are marked as such below.
28//
29// TODO: __localeconv shouldn't take a reference, but the Windows implementation doesn't allow copying __locale_t
30// TODO: Eliminate the need for any of these functions from the headers.
31//
32// Locale management
33// -----------------
34// namespace __locale {
35// using __locale_t = implementation-defined; // required by the headers
36// using __lconv_t = implementation-defined;
37// __locale_t __newlocale(int, const char*, __locale_t);
38// void __freelocale(__locale_t);
39// char* __setlocale(int, const char*);
40// __lconv_t* __localeconv(__locale_t&);
41// }
42//
43// // required by the headers
44// #define _LIBCPP_COLLATE_MASK /* implementation-defined */
45// #define _LIBCPP_CTYPE_MASK /* implementation-defined */
46// #define _LIBCPP_MONETARY_MASK /* implementation-defined */
47// #define _LIBCPP_NUMERIC_MASK /* implementation-defined */
48// #define _LIBCPP_TIME_MASK /* implementation-defined */
49// #define _LIBCPP_MESSAGES_MASK /* implementation-defined */
50// #define _LIBCPP_ALL_MASK /* implementation-defined */
51// #define _LIBCPP_LC_ALL /* implementation-defined */
52//
53// Strtonum functions
54// ------------------
55// namespace __locale {
56// // required by the headers
57// float __strtof(const char*, char**, __locale_t);
58// double __strtod(const char*, char**, __locale_t);
59// long double __strtold(const char*, char**, __locale_t);
60// long long __strtoll(const char*, char**, __locale_t);
61// unsigned long long __strtoull(const char*, char**, __locale_t);
62// }
63//
64// Character manipulation functions
65// --------------------------------
66// namespace __locale {
67// int __islower(int, __locale_t);
68// int __isupper(int, __locale_t);
69// int __isdigit(int, __locale_t); // required by the headers
70// int __isxdigit(int, __locale_t); // required by the headers
71// int __toupper(int, __locale_t);
72// int __tolower(int, __locale_t);
73// int __strcoll(const char*, const char*, __locale_t);
74// size_t __strxfrm(char*, const char*, size_t, __locale_t);
75//
76// int __iswctype(wint_t, wctype_t, __locale_t);
77// int __iswspace(wint_t, __locale_t);
78// int __iswprint(wint_t, __locale_t);
79// int __iswcntrl(wint_t, __locale_t);
80// int __iswupper(wint_t, __locale_t);
81// int __iswlower(wint_t, __locale_t);
82// int __iswalpha(wint_t, __locale_t);
83// int __iswblank(wint_t, __locale_t);
84// int __iswdigit(wint_t, __locale_t);
85// int __iswpunct(wint_t, __locale_t);
86// int __iswxdigit(wint_t, __locale_t);
87// wint_t __towupper(wint_t, __locale_t);
88// wint_t __towlower(wint_t, __locale_t);
89// int __wcscoll(const wchar_t*, const wchar_t*, __locale_t);
90// size_t __wcsxfrm(wchar_t*, const wchar_t*, size_t, __locale_t);
91//
92// size_t __strftime(char*, size_t, const char*, const tm*, __locale_t);
93// }
94//
95// Other functions
96// ---------------
97// namespace __locale {
98// implementation-defined __mb_len_max(__locale_t);
99// wint_t __btowc(int, __locale_t);
100// int __wctob(wint_t, __locale_t);
101// size_t __wcsnrtombs(char*, const wchar_t**, size_t, size_t, mbstate_t*, __locale_t);
102// size_t __wcrtomb(char*, wchar_t, mbstate_t*, __locale_t);
103// size_t __mbsnrtowcs(wchar_t*, const char**, size_t, size_t, mbstate_t*, __locale_t);
104// size_t __mbrtowc(wchar_t*, const char*, size_t, mbstate_t*, __locale_t);
105// int __mbtowc(wchar_t*, const char*, size_t, __locale_t);
106// size_t __mbrlen(const char*, size_t, mbstate_t*, __locale_t);
107// size_t __mbsrtowcs(wchar_t*, const char**, size_t, mbstate_t*, __locale_t);
108//
109// int __snprintf(char*, size_t, __locale_t, const char*, ...); // required by the headers
110// int __asprintf(char**, __locale_t, const char*, ...); // required by the headers
111// int __sscanf(const char*, __locale_t, const char*, ...); // required by the headers
112// }
113
114#if defined(__APPLE__)
115# include <__locale_dir/support/apple.h>
116#elif defined(__FreeBSD__)
117# include <__locale_dir/support/freebsd.h>
118#elif defined(_LIBCPP_MSVCRT_LIKE)
119# include <__locale_dir/support/windows.h>
120#elif defined(__Fuchsia__)
121# include <__locale_dir/support/fuchsia.h>
122#else
123
124// TODO: This is a temporary definition to bridge between the old way we defined the locale base API
125// (by providing global non-reserved names) and the new API. As we move individual platforms
126// towards the new way of defining the locale base API, this should disappear since each platform
127// will define those directly.
128# if defined(_AIX) || defined(__MVS__)
129# include <__locale_dir/locale_base_api/ibm.h>
130# elif defined(__ANDROID__)
131# include <__locale_dir/locale_base_api/android.h>
132# elif defined(__OpenBSD__)
133# include <__locale_dir/locale_base_api/openbsd.h>
134# elif defined(__wasi__) || _LIBCPP_HAS_MUSL_LIBC
135# include <__locale_dir/locale_base_api/musl.h>
136# endif
137
138# include <__locale_dir/locale_base_api/bsd_locale_fallbacks.h>
139
140# include <__cstddef/size_t.h>
141# include <__utility/forward.h>
142# include <ctype.h>
143# include <string.h>
144# include <time.h>
145# if _LIBCPP_HAS_WIDE_CHARACTERS
146# include <wctype.h>
147# endif
148_LIBCPP_BEGIN_NAMESPACE_STD
149namespace __locale {
150//
151// Locale management
152//
153# define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK
154# define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK
155# define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK
156# define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK
157# define _LIBCPP_TIME_MASK LC_TIME_MASK
158# define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
159# define _LIBCPP_ALL_MASK LC_ALL_MASK
160# define _LIBCPP_LC_ALL LC_ALL
161
162using __locale_t _LIBCPP_NODEBUG = locale_t;
163
164# if defined(_LIBCPP_BUILDING_LIBRARY)
165using __lconv_t _LIBCPP_NODEBUG = lconv;
166
167inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __name, __locale_t __loc) {
168 return newlocale(__category_mask, __name, __loc);
169}
170
171inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, char const* __locale) {
172 return ::setlocale(__category, __locale);
173}
174
175inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { freelocale(__loc); }
176
177inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) { return __libcpp_localeconv_l(__loc); }
178# endif // _LIBCPP_BUILDING_LIBRARY
179
180//
181// Strtonum functions
182//
183inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) {
184 return strtof_l(__nptr, __endptr, __loc);
185}
186
187inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) {
188 return strtod_l(__nptr, __endptr, __loc);
189}
190
191inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) {
192 return strtold_l(__nptr, __endptr, __loc);
193}
194
195inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
196 return strtoll_l(__nptr, __endptr, __base, __loc);
197}
198
199inline _LIBCPP_HIDE_FROM_ABI unsigned long long
200__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
201 return strtoull_l(__nptr, __endptr, __base, __loc);
202}
203
204//
205// Character manipulation functions
206//
207# if defined(_LIBCPP_BUILDING_LIBRARY)
208inline _LIBCPP_HIDE_FROM_ABI int __islower(int __ch, __locale_t __loc) { return islower_l(__ch, __loc); }
209inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __ch, __locale_t __loc) { return isupper_l(__ch, __loc); }
210# endif
211
212inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __ch, __locale_t __loc) { return isdigit_l(__ch, __loc); }
213inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __ch, __locale_t __loc) { return isxdigit_l(__ch, __loc); }
214
215# if defined(_LIBCPP_BUILDING_LIBRARY)
216inline _LIBCPP_HIDE_FROM_ABI int __strcoll(const char* __s1, const char* __s2, __locale_t __loc) {
217 return strcoll_l(__s1, __s2, __loc);
218}
219inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, size_t __n, __locale_t __loc) {
220 return strxfrm_l(__dest, __src, __n, __loc);
221}
222inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __ch, __locale_t __loc) { return toupper_l(__ch, __loc); }
223inline _LIBCPP_HIDE_FROM_ABI int __tolower(int __ch, __locale_t __loc) { return tolower_l(__ch, __loc); }
224
225# if _LIBCPP_HAS_WIDE_CHARACTERS
226inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __s1, const wchar_t* __s2, __locale_t __loc) {
227 return wcscoll_l(__s1, __s2, __loc);
228}
229inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) {
230 return wcsxfrm_l(__dest, __src, __n, __loc);
231}
232inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __ch, wctype_t __type, __locale_t __loc) {
233 return iswctype_l(__ch, __type, __loc);
234}
235inline _LIBCPP_HIDE_FROM_ABI int __iswspace(wint_t __ch, __locale_t __loc) { return iswspace_l(__ch, __loc); }
236inline _LIBCPP_HIDE_FROM_ABI int __iswprint(wint_t __ch, __locale_t __loc) { return iswprint_l(__ch, __loc); }
237inline _LIBCPP_HIDE_FROM_ABI int __iswcntrl(wint_t __ch, __locale_t __loc) { return iswcntrl_l(__ch, __loc); }
238inline _LIBCPP_HIDE_FROM_ABI int __iswupper(wint_t __ch, __locale_t __loc) { return iswupper_l(__ch, __loc); }
239inline _LIBCPP_HIDE_FROM_ABI int __iswlower(wint_t __ch, __locale_t __loc) { return iswlower_l(__ch, __loc); }
240inline _LIBCPP_HIDE_FROM_ABI int __iswalpha(wint_t __ch, __locale_t __loc) { return iswalpha_l(__ch, __loc); }
241inline _LIBCPP_HIDE_FROM_ABI int __iswblank(wint_t __ch, __locale_t __loc) { return iswblank_l(__ch, __loc); }
242inline _LIBCPP_HIDE_FROM_ABI int __iswdigit(wint_t __ch, __locale_t __loc) { return iswdigit_l(__ch, __loc); }
243inline _LIBCPP_HIDE_FROM_ABI int __iswpunct(wint_t __ch, __locale_t __loc) { return iswpunct_l(__ch, __loc); }
244inline _LIBCPP_HIDE_FROM_ABI int __iswxdigit(wint_t __ch, __locale_t __loc) { return iswxdigit_l(__ch, __loc); }
245inline _LIBCPP_HIDE_FROM_ABI wint_t __towupper(wint_t __ch, __locale_t __loc) { return towupper_l(__ch, __loc); }
246inline _LIBCPP_HIDE_FROM_ABI wint_t __towlower(wint_t __ch, __locale_t __loc) { return towlower_l(__ch, __loc); }
247# endif
248
249inline _LIBCPP_HIDE_FROM_ABI size_t
250__strftime(char* __s, size_t __max, const char* __format, const tm* __tm, __locale_t __loc) {
251 return strftime_l(__s, __max, __format, __tm, __loc);
252}
253
254//
255// Other functions
256//
257inline _LIBCPP_HIDE_FROM_ABI decltype(__libcpp_mb_cur_max_l(__locale_t())) __mb_len_max(__locale_t __loc) {
258 return __libcpp_mb_cur_max_l(__loc);
259}
260# if _LIBCPP_HAS_WIDE_CHARACTERS
261inline _LIBCPP_HIDE_FROM_ABI wint_t __btowc(int __ch, __locale_t __loc) { return __libcpp_btowc_l(__ch, __loc); }
262inline _LIBCPP_HIDE_FROM_ABI int __wctob(wint_t __ch, __locale_t __loc) { return __libcpp_wctob_l(__ch, __loc); }
263inline _LIBCPP_HIDE_FROM_ABI size_t
264__wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t __loc) {
265 return __libcpp_wcsnrtombs_l(__dest, __src, __nwc, __len, __ps, __loc);
266}
267inline _LIBCPP_HIDE_FROM_ABI size_t __wcrtomb(char* __s, wchar_t __ch, mbstate_t* __ps, __locale_t __loc) {
268 return __libcpp_wcrtomb_l(__s, __ch, __ps, __loc);
269}
270inline _LIBCPP_HIDE_FROM_ABI size_t
271__mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t __loc) {
272 return __libcpp_mbsnrtowcs_l(__dest, __src, __nms, __len, __ps, __loc);
273}
274inline _LIBCPP_HIDE_FROM_ABI size_t
275__mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
276 return __libcpp_mbrtowc_l(__pwc, __s, __n, __ps, __loc);
277}
278inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) {
279 return __libcpp_mbtowc_l(__pwc, __pmb, __max, __loc);
280}
281inline _LIBCPP_HIDE_FROM_ABI size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
282 return __libcpp_mbrlen_l(__s, __n, __ps, __loc);
283}
284inline _LIBCPP_HIDE_FROM_ABI size_t
285__mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) {
286 return __libcpp_mbsrtowcs_l(__dest, __src, __len, __ps, __loc);
287}
288# endif // _LIBCPP_HAS_WIDE_CHARACTERS
289# endif // _LIBCPP_BUILDING_LIBRARY
290
291_LIBCPP_DIAGNOSTIC_PUSH
292_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat")
293_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates
294# ifdef _LIBCPP_COMPILER_CLANG_BASED
295# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__)
296# else
297# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */
298# endif
299
300template <class... _Args>
301_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf(
302 char* __s, size_t __n, __locale_t __loc, const char* __format, _Args&&... __args) {
303 return std::__libcpp_snprintf_l(__s, __n, __loc, __format, std::forward<_Args>(__args)...);
304}
305template <class... _Args>
306_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf(
307 char** __s, __locale_t __loc, const char* __format, _Args&&... __args) {
308 return std::__libcpp_asprintf_l(__s, __loc, __format, std::forward<_Args>(__args)...);
309}
310template <class... _Args>
311_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf(
312 const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) {
313 return std::__libcpp_sscanf_l(__s, __loc, __format, std::forward<_Args>(__args)...);
314}
315_LIBCPP_DIAGNOSTIC_POP
316# undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
317
318} // namespace __locale
319_LIBCPP_END_NAMESPACE_STD
320
321#endif // Compatibility definition of locale base APIs
97322
98323#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H
lib/libcxx/include/__locale_dir/locale_base_api/android.h+4-9
......@@ -7,8 +7,8 @@
77//
88//===----------------------------------------------------------------------===//
99
10#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_ANDROID_H
11#define _LIBCPP___LOCALE_LOCALE_BASE_API_ANDROID_H
10#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_ANDROID_H
11#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_ANDROID_H
1212
1313#include <stdlib.h>
1414
......@@ -18,9 +18,6 @@ extern "C" {
1818}
1919
2020#include <android/api-level.h>
21#if __ANDROID_API__ < 21
22# include <__support/xlocale/__posix_l_fallback.h>
23#endif
2421
2522// If we do not have this header, we are in a platform build rather than an NDK
2623// build, which will always be at least as new as the ToT NDK, in which case we
......@@ -30,9 +27,7 @@ extern "C" {
3027// In NDK versions later than 16, locale-aware functions are provided by
3128// legacy_stdlib_inlines.h
3229# if __NDK_MAJOR__ <= 16
33# if __ANDROID_API__ < 21
34# include <__support/xlocale/__strtonum_fallback.h>
35# elif __ANDROID_API__ < 26
30# if __ANDROID_API__ < 26
3631
3732inline _LIBCPP_HIDE_FROM_ABI float strtof_l(const char* __nptr, char** __endptr, locale_t) {
3833 return ::strtof(__nptr, __endptr);
......@@ -47,4 +42,4 @@ inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr
4742# endif // __NDK_MAJOR__ <= 16
4843#endif // __has_include(<android/ndk-version.h>)
4944
50#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_ANDROID_H
45#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_ANDROID_H
lib/libcxx/include/__locale_dir/locale_base_api/bsd_locale_defaults.h deleted-36
......@@ -1,36 +0,0 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9// The BSDs have lots of *_l functions. We don't want to define those symbols
10// on other platforms though, for fear of conflicts with user code. So here,
11// we will define the mapping from an internal macro to the real BSD symbol.
12//===----------------------------------------------------------------------===//
13
14#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_BSD_LOCALE_DEFAULTS_H
15#define _LIBCPP___LOCALE_LOCALE_BASE_API_BSD_LOCALE_DEFAULTS_H
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21#define __libcpp_mb_cur_max_l(loc) MB_CUR_MAX_L(loc)
22#define __libcpp_btowc_l(ch, loc) btowc_l(ch, loc)
23#define __libcpp_wctob_l(wch, loc) wctob_l(wch, loc)
24#define __libcpp_wcsnrtombs_l(dst, src, nwc, len, ps, loc) wcsnrtombs_l(dst, src, nwc, len, ps, loc)
25#define __libcpp_wcrtomb_l(src, wc, ps, loc) wcrtomb_l(src, wc, ps, loc)
26#define __libcpp_mbsnrtowcs_l(dst, src, nms, len, ps, loc) mbsnrtowcs_l(dst, src, nms, len, ps, loc)
27#define __libcpp_mbrtowc_l(pwc, s, n, ps, l) mbrtowc_l(pwc, s, n, ps, l)
28#define __libcpp_mbtowc_l(pwc, pmb, max, l) mbtowc_l(pwc, pmb, max, l)
29#define __libcpp_mbrlen_l(s, n, ps, l) mbrlen_l(s, n, ps, l)
30#define __libcpp_localeconv_l(l) localeconv_l(l)
31#define __libcpp_mbsrtowcs_l(dest, src, len, ps, l) mbsrtowcs_l(dest, src, len, ps, l)
32#define __libcpp_snprintf_l(...) snprintf_l(__VA_ARGS__)
33#define __libcpp_asprintf_l(...) asprintf_l(__VA_ARGS__)
34#define __libcpp_sscanf_l(...) sscanf_l(__VA_ARGS__)
35
36#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_BSD_LOCALE_DEFAULTS_H
lib/libcxx/include/__locale_dir/locale_base_api/bsd_locale_fallbacks.h+38-24
......@@ -10,15 +10,15 @@
1010// of those functions for non-BSD platforms.
1111//===----------------------------------------------------------------------===//
1212
13#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H
14#define _LIBCPP___LOCALE_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H
13#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H
14#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H
1515
16#include <__locale_dir/locale_base_api/locale_guard.h>
17#include <cstdio>
16#include <locale.h>
1817#include <stdarg.h>
18#include <stdio.h>
1919#include <stdlib.h>
2020
21#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
21#if _LIBCPP_HAS_WIDE_CHARACTERS
2222# include <cwchar>
2323#endif
2424
......@@ -28,65 +28,79 @@
2828
2929_LIBCPP_BEGIN_NAMESPACE_STD
3030
31struct __locale_guard {
32 _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {}
33
34 _LIBCPP_HIDE_FROM_ABI ~__locale_guard() {
35 if (__old_loc_)
36 ::uselocale(__old_loc_);
37 }
38
39 locale_t __old_loc_;
40
41 __locale_guard(__locale_guard const&) = delete;
42 __locale_guard& operator=(__locale_guard const&) = delete;
43};
44
3145inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l) {
32 __libcpp_locale_guard __current(__l);
46 __locale_guard __current(__l);
3347 return MB_CUR_MAX;
3448}
3549
36#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
50#if _LIBCPP_HAS_WIDE_CHARACTERS
3751inline _LIBCPP_HIDE_FROM_ABI wint_t __libcpp_btowc_l(int __c, locale_t __l) {
38 __libcpp_locale_guard __current(__l);
52 __locale_guard __current(__l);
3953 return btowc(__c);
4054}
4155
4256inline _LIBCPP_HIDE_FROM_ABI int __libcpp_wctob_l(wint_t __c, locale_t __l) {
43 __libcpp_locale_guard __current(__l);
57 __locale_guard __current(__l);
4458 return wctob(__c);
4559}
4660
4761inline _LIBCPP_HIDE_FROM_ABI size_t
4862__libcpp_wcsnrtombs_l(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, locale_t __l) {
49 __libcpp_locale_guard __current(__l);
63 __locale_guard __current(__l);
5064 return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
5165}
5266
5367inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_wcrtomb_l(char* __s, wchar_t __wc, mbstate_t* __ps, locale_t __l) {
54 __libcpp_locale_guard __current(__l);
68 __locale_guard __current(__l);
5569 return wcrtomb(__s, __wc, __ps);
5670}
5771
5872inline _LIBCPP_HIDE_FROM_ABI size_t
5973__libcpp_mbsnrtowcs_l(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, locale_t __l) {
60 __libcpp_locale_guard __current(__l);
74 __locale_guard __current(__l);
6175 return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
6276}
6377
6478inline _LIBCPP_HIDE_FROM_ABI size_t
6579__libcpp_mbrtowc_l(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, locale_t __l) {
66 __libcpp_locale_guard __current(__l);
80 __locale_guard __current(__l);
6781 return mbrtowc(__pwc, __s, __n, __ps);
6882}
6983
7084inline _LIBCPP_HIDE_FROM_ABI int __libcpp_mbtowc_l(wchar_t* __pwc, const char* __pmb, size_t __max, locale_t __l) {
71 __libcpp_locale_guard __current(__l);
85 __locale_guard __current(__l);
7286 return mbtowc(__pwc, __pmb, __max);
7387}
7488
7589inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_mbrlen_l(const char* __s, size_t __n, mbstate_t* __ps, locale_t __l) {
76 __libcpp_locale_guard __current(__l);
90 __locale_guard __current(__l);
7791 return mbrlen(__s, __n, __ps);
7892}
79#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
93#endif // _LIBCPP_HAS_WIDE_CHARACTERS
8094
81inline _LIBCPP_HIDE_FROM_ABI lconv* __libcpp_localeconv_l(locale_t __l) {
82 __libcpp_locale_guard __current(__l);
95inline _LIBCPP_HIDE_FROM_ABI lconv* __libcpp_localeconv_l(locale_t& __l) {
96 __locale_guard __current(__l);
8397 return localeconv();
8498}
8599
86#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
100#if _LIBCPP_HAS_WIDE_CHARACTERS
87101inline _LIBCPP_HIDE_FROM_ABI size_t
88102__libcpp_mbsrtowcs_l(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, locale_t __l) {
89 __libcpp_locale_guard __current(__l);
103 __locale_guard __current(__l);
90104 return mbsrtowcs(__dest, __src, __len, __ps);
91105}
92106#endif
......@@ -95,7 +109,7 @@ inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __libcpp_snprintf_l(
95109 char* __s, size_t __n, locale_t __l, const char* __format, ...) {
96110 va_list __va;
97111 va_start(__va, __format);
98 __libcpp_locale_guard __current(__l);
112 __locale_guard __current(__l);
99113 int __res = vsnprintf(__s, __n, __format, __va);
100114 va_end(__va);
101115 return __res;
......@@ -105,7 +119,7 @@ inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __libcpp_asprintf_l(
105119 char** __s, locale_t __l, const char* __format, ...) {
106120 va_list __va;
107121 va_start(__va, __format);
108 __libcpp_locale_guard __current(__l);
122 __locale_guard __current(__l);
109123 int __res = vasprintf(__s, __format, __va);
110124 va_end(__va);
111125 return __res;
......@@ -115,7 +129,7 @@ inline _LIBCPP_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __libcpp_sscanf_l(
115129 const char* __s, locale_t __l, const char* __format, ...) {
116130 va_list __va;
117131 va_start(__va, __format);
118 __libcpp_locale_guard __current(__l);
132 __locale_guard __current(__l);
119133 int __res = vsscanf(__s, __format, __va);
120134 va_end(__va);
121135 return __res;
......@@ -123,4 +137,4 @@ inline _LIBCPP_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __libcpp_sscanf_l(
123137
124138_LIBCPP_END_NAMESPACE_STD
125139
126#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H
140#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H
lib/libcxx/include/__locale_dir/locale_base_api/fuchsia.h deleted-18
......@@ -1,18 +0,0 @@
1// -*- C++ -*-
2//===-----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_FUCHSIA_H
11#define _LIBCPP___LOCALE_LOCALE_BASE_API_FUCHSIA_H
12
13#include <__support/xlocale/__posix_l_fallback.h>
14#include <__support/xlocale/__strtonum_fallback.h>
15#include <cstdlib>
16#include <cwchar>
17
18#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_FUCHSIA_H
lib/libcxx/include/__locale_dir/locale_base_api/ibm.h+5-5
......@@ -7,8 +7,8 @@
77//
88//===----------------------------------------------------------------------===//
99
10#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_IBM_H
11#define _LIBCPP___LOCALE_LOCALE_BASE_API_IBM_H
10#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_IBM_H
11#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_IBM_H
1212
1313#if defined(__MVS__)
1414# include <__support/ibm/locale_mgmt_zos.h>
......@@ -82,7 +82,7 @@ strtoull_l(const char* __nptr, char** __endptr, int __base, locale_t locale) {
8282inline _LIBCPP_HIDE_FROM_ABI
8383_LIBCPP_ATTRIBUTE_FORMAT(__printf__, 2, 0) int vasprintf(char** strp, const char* fmt, va_list ap) {
8484 const size_t buff_size = 256;
85 if ((*strp = (char*)malloc(buff_size)) == NULL) {
85 if ((*strp = (char*)malloc(buff_size)) == nullptr) {
8686 return -1;
8787 }
8888
......@@ -97,7 +97,7 @@ _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 2, 0) int vasprintf(char** strp, const char
9797 va_end(ap_copy);
9898
9999 if ((size_t)str_size >= buff_size) {
100 if ((*strp = (char*)realloc(*strp, str_size + 1)) == NULL) {
100 if ((*strp = (char*)realloc(*strp, str_size + 1)) == nullptr) {
101101 return -1;
102102 }
103103 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
105105 return str_size;
106106}
107107
108#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_IBM_H
108#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_IBM_H
lib/libcxx/include/__locale_dir/locale_base_api/locale_guard.h deleted-78
......@@ -1,78 +0,0 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_LOCALE_GUARD_H
10#define _LIBCPP___LOCALE_LOCALE_BASE_API_LOCALE_GUARD_H
11
12#include <__config>
13#include <__locale> // for locale_t
14#include <clocale>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS)
23struct __libcpp_locale_guard {
24 _LIBCPP_HIDE_FROM_ABI __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {}
25
26 _LIBCPP_HIDE_FROM_ABI ~__libcpp_locale_guard() {
27 if (__old_loc_)
28 uselocale(__old_loc_);
29 }
30
31 locale_t __old_loc_;
32
33 __libcpp_locale_guard(__libcpp_locale_guard const&) = delete;
34 __libcpp_locale_guard& operator=(__libcpp_locale_guard const&) = delete;
35};
36#elif defined(_LIBCPP_MSVCRT_LIKE)
37struct __libcpp_locale_guard {
38 __libcpp_locale_guard(locale_t __l) : __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) {
39 // Setting the locale can be expensive even when the locale given is
40 // already the current locale, so do an explicit check to see if the
41 // current locale is already the one we want.
42 const char* __lc = __setlocale(nullptr);
43 // If every category is the same, the locale string will simply be the
44 // locale name, otherwise it will be a semicolon-separated string listing
45 // each category. In the second case, we know at least one category won't
46 // be what we want, so we only have to check the first case.
47 if (std::strcmp(__l.__get_locale(), __lc) != 0) {
48 __locale_all = _strdup(__lc);
49 if (__locale_all == nullptr)
50 __throw_bad_alloc();
51 __setlocale(__l.__get_locale());
52 }
53 }
54 ~__libcpp_locale_guard() {
55 // The CRT documentation doesn't explicitly say, but setlocale() does the
56 // right thing when given a semicolon-separated list of locale settings
57 // for the different categories in the same format as returned by
58 // setlocale(LC_ALL, nullptr).
59 if (__locale_all != nullptr) {
60 __setlocale(__locale_all);
61 free(__locale_all);
62 }
63 _configthreadlocale(__status);
64 }
65 static const char* __setlocale(const char* __locale) {
66 const char* __new_locale = setlocale(LC_ALL, __locale);
67 if (__new_locale == nullptr)
68 __throw_bad_alloc();
69 return __new_locale;
70 }
71 int __status;
72 char* __locale_all = nullptr;
73};
74#endif
75
76_LIBCPP_END_NAMESPACE_STD
77
78#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_LOCALE_GUARD_H
lib/libcxx/include/__locale_dir/locale_base_api/musl.h+3-3
......@@ -14,8 +14,8 @@
1414// in Musl.
1515//===----------------------------------------------------------------------===//
1616
17#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_MUSL_H
18#define _LIBCPP___LOCALE_LOCALE_BASE_API_MUSL_H
17#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_MUSL_H
18#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_MUSL_H
1919
2020#include <cstdlib>
2121#include <cwchar>
......@@ -28,4 +28,4 @@ inline _LIBCPP_HIDE_FROM_ABI unsigned long long strtoull_l(const char* __nptr, c
2828 return ::strtoull(__nptr, __endptr, __base);
2929}
3030
31#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_MUSL_H
31#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_MUSL_H
lib/libcxx/include/__locale_dir/locale_base_api/newlib.h deleted-12
......@@ -1,12 +0,0 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_NEWLIB_H
10#define _LIBCPP___LOCALE_LOCALE_BASE_API_NEWLIB_H
11
12#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_NEWLIB_H
lib/libcxx/include/__locale_dir/locale_base_api/openbsd.h+3-3
......@@ -7,8 +7,8 @@
77//
88//===----------------------------------------------------------------------===//
99
10#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_OPENBSD_H
11#define _LIBCPP___LOCALE_LOCALE_BASE_API_OPENBSD_H
10#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H
11#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H
1212
1313#include <__support/xlocale/__strtonum_fallback.h>
1414#include <clocale>
......@@ -16,4 +16,4 @@
1616#include <ctype.h>
1717#include <cwctype>
1818
19#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_OPENBSD_H
19#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H
lib/libcxx/include/__locale_dir/locale_base_api/win32.h deleted-235
......@@ -1,235 +0,0 @@
1// -*- C++ -*-
2//===-----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_WIN32_H
11#define _LIBCPP___LOCALE_LOCALE_BASE_API_WIN32_H
12
13#include <__config>
14#include <cstddef>
15#include <locale.h> // _locale_t
16#include <stdio.h>
17#include <string>
18
19#define _X_ALL LC_ALL
20#define _X_COLLATE LC_COLLATE
21#define _X_CTYPE LC_CTYPE
22#define _X_MONETARY LC_MONETARY
23#define _X_NUMERIC LC_NUMERIC
24#define _X_TIME LC_TIME
25#define _X_MAX LC_MAX
26#define _X_MESSAGES 6
27#define _NCAT (_X_MESSAGES + 1)
28
29#define _CATMASK(n) ((1 << (n)) >> 1)
30#define _M_COLLATE _CATMASK(_X_COLLATE)
31#define _M_CTYPE _CATMASK(_X_CTYPE)
32#define _M_MONETARY _CATMASK(_X_MONETARY)
33#define _M_NUMERIC _CATMASK(_X_NUMERIC)
34#define _M_TIME _CATMASK(_X_TIME)
35#define _M_MESSAGES _CATMASK(_X_MESSAGES)
36#define _M_ALL (_CATMASK(_NCAT) - 1)
37
38#define LC_COLLATE_MASK _M_COLLATE
39#define LC_CTYPE_MASK _M_CTYPE
40#define LC_MONETARY_MASK _M_MONETARY
41#define LC_NUMERIC_MASK _M_NUMERIC
42#define LC_TIME_MASK _M_TIME
43#define LC_MESSAGES_MASK _M_MESSAGES
44#define LC_ALL_MASK \
45 (LC_COLLATE_MASK | LC_CTYPE_MASK | LC_MESSAGES_MASK | LC_MONETARY_MASK | LC_NUMERIC_MASK | LC_TIME_MASK)
46
47class __lconv_storage {
48public:
49 __lconv_storage(const lconv* __lc_input) {
50 __lc_ = *__lc_input;
51
52 __decimal_point_ = __lc_input->decimal_point;
53 __thousands_sep_ = __lc_input->thousands_sep;
54 __grouping_ = __lc_input->grouping;
55 __int_curr_symbol_ = __lc_input->int_curr_symbol;
56 __currency_symbol_ = __lc_input->currency_symbol;
57 __mon_decimal_point_ = __lc_input->mon_decimal_point;
58 __mon_thousands_sep_ = __lc_input->mon_thousands_sep;
59 __mon_grouping_ = __lc_input->mon_grouping;
60 __positive_sign_ = __lc_input->positive_sign;
61 __negative_sign_ = __lc_input->negative_sign;
62
63 __lc_.decimal_point = const_cast<char*>(__decimal_point_.c_str());
64 __lc_.thousands_sep = const_cast<char*>(__thousands_sep_.c_str());
65 __lc_.grouping = const_cast<char*>(__grouping_.c_str());
66 __lc_.int_curr_symbol = const_cast<char*>(__int_curr_symbol_.c_str());
67 __lc_.currency_symbol = const_cast<char*>(__currency_symbol_.c_str());
68 __lc_.mon_decimal_point = const_cast<char*>(__mon_decimal_point_.c_str());
69 __lc_.mon_thousands_sep = const_cast<char*>(__mon_thousands_sep_.c_str());
70 __lc_.mon_grouping = const_cast<char*>(__mon_grouping_.c_str());
71 __lc_.positive_sign = const_cast<char*>(__positive_sign_.c_str());
72 __lc_.negative_sign = const_cast<char*>(__negative_sign_.c_str());
73 }
74
75 lconv* __get() { return &__lc_; }
76
77private:
78 lconv __lc_;
79 std::string __decimal_point_;
80 std::string __thousands_sep_;
81 std::string __grouping_;
82 std::string __int_curr_symbol_;
83 std::string __currency_symbol_;
84 std::string __mon_decimal_point_;
85 std::string __mon_thousands_sep_;
86 std::string __mon_grouping_;
87 std::string __positive_sign_;
88 std::string __negative_sign_;
89};
90
91class locale_t {
92public:
93 locale_t() : __locale_(nullptr), __locale_str_(nullptr), __lc_(nullptr) {}
94 locale_t(std::nullptr_t) : __locale_(nullptr), __locale_str_(nullptr), __lc_(nullptr) {}
95 locale_t(_locale_t __xlocale, const char* __xlocale_str)
96 : __locale_(__xlocale), __locale_str_(__xlocale_str), __lc_(nullptr) {}
97 locale_t(const locale_t& __l) : __locale_(__l.__locale_), __locale_str_(__l.__locale_str_), __lc_(nullptr) {}
98
99 ~locale_t() { delete __lc_; }
100
101 locale_t& operator=(const locale_t& __l) {
102 __locale_ = __l.__locale_;
103 __locale_str_ = __l.__locale_str_;
104 // __lc_ not copied
105 return *this;
106 }
107
108 friend bool operator==(const locale_t& __left, const locale_t& __right) {
109 return __left.__locale_ == __right.__locale_;
110 }
111
112 friend bool operator==(const locale_t& __left, int __right) { return __left.__locale_ == nullptr && __right == 0; }
113
114 friend bool operator==(const locale_t& __left, long long __right) {
115 return __left.__locale_ == nullptr && __right == 0;
116 }
117
118 friend bool operator==(const locale_t& __left, std::nullptr_t) { return __left.__locale_ == nullptr; }
119
120 friend bool operator==(int __left, const locale_t& __right) { return __left == 0 && nullptr == __right.__locale_; }
121
122 friend bool operator==(std::nullptr_t, const locale_t& __right) { return nullptr == __right.__locale_; }
123
124 friend bool operator!=(const locale_t& __left, const locale_t& __right) { return !(__left == __right); }
125
126 friend bool operator!=(const locale_t& __left, int __right) { return !(__left == __right); }
127
128 friend bool operator!=(const locale_t& __left, long long __right) { return !(__left == __right); }
129
130 friend bool operator!=(const locale_t& __left, std::nullptr_t __right) { return !(__left == __right); }
131
132 friend bool operator!=(int __left, const locale_t& __right) { return !(__left == __right); }
133
134 friend bool operator!=(std::nullptr_t __left, const locale_t& __right) { return !(__left == __right); }
135
136 operator bool() const { return __locale_ != nullptr; }
137
138 const char* __get_locale() const { return __locale_str_; }
139
140 operator _locale_t() const { return __locale_; }
141
142 lconv* __store_lconv(const lconv* __input_lc) {
143 delete __lc_;
144 __lc_ = new __lconv_storage(__input_lc);
145 return __lc_->__get();
146 }
147
148private:
149 _locale_t __locale_;
150 const char* __locale_str_;
151 __lconv_storage* __lc_ = nullptr;
152};
153
154// Locale management functions
155#define freelocale _free_locale
156// FIXME: base currently unused. Needs manual work to construct the new locale
157locale_t newlocale(int __mask, const char* __locale, locale_t __base);
158// uselocale can't be implemented on Windows because Windows allows partial modification
159// of thread-local locale and so _get_current_locale() returns a copy while uselocale does
160// not create any copies.
161// We can still implement raii even without uselocale though.
162
163lconv* localeconv_l(locale_t& __loc);
164size_t mbrlen_l(const char* __restrict __s, size_t __n, mbstate_t* __restrict __ps, locale_t __loc);
165size_t mbsrtowcs_l(
166 wchar_t* __restrict __dst, const char** __restrict __src, size_t __len, mbstate_t* __restrict __ps, locale_t __loc);
167size_t wcrtomb_l(char* __restrict __s, wchar_t __wc, mbstate_t* __restrict __ps, locale_t __loc);
168size_t mbrtowc_l(
169 wchar_t* __restrict __pwc, const char* __restrict __s, size_t __n, mbstate_t* __restrict __ps, locale_t __loc);
170size_t mbsnrtowcs_l(wchar_t* __restrict __dst,
171 const char** __restrict __src,
172 size_t __nms,
173 size_t __len,
174 mbstate_t* __restrict __ps,
175 locale_t __loc);
176size_t wcsnrtombs_l(char* __restrict __dst,
177 const wchar_t** __restrict __src,
178 size_t __nwc,
179 size_t __len,
180 mbstate_t* __restrict __ps,
181 locale_t __loc);
182wint_t btowc_l(int __c, locale_t __loc);
183int wctob_l(wint_t __c, locale_t __loc);
184
185decltype(MB_CUR_MAX) MB_CUR_MAX_L(locale_t __l);
186
187// the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+
188#define mbtowc_l _mbtowc_l
189#define strtoll_l _strtoi64_l
190#define strtoull_l _strtoui64_l
191#define strtod_l _strtod_l
192#if defined(_LIBCPP_MSVCRT)
193# define strtof_l _strtof_l
194# define strtold_l _strtold_l
195#else
196_LIBCPP_EXPORTED_FROM_ABI float strtof_l(const char*, char**, locale_t);
197_LIBCPP_EXPORTED_FROM_ABI long double strtold_l(const char*, char**, locale_t);
198#endif
199inline _LIBCPP_HIDE_FROM_ABI int islower_l(int __c, _locale_t __loc) { return _islower_l((int)__c, __loc); }
200
201inline _LIBCPP_HIDE_FROM_ABI int isupper_l(int __c, _locale_t __loc) { return _isupper_l((int)__c, __loc); }
202
203#define isdigit_l _isdigit_l
204#define isxdigit_l _isxdigit_l
205#define strcoll_l _strcoll_l
206#define strxfrm_l _strxfrm_l
207#define wcscoll_l _wcscoll_l
208#define wcsxfrm_l _wcsxfrm_l
209#define toupper_l _toupper_l
210#define tolower_l _tolower_l
211#define iswspace_l _iswspace_l
212#define iswprint_l _iswprint_l
213#define iswcntrl_l _iswcntrl_l
214#define iswupper_l _iswupper_l
215#define iswlower_l _iswlower_l
216#define iswalpha_l _iswalpha_l
217#define iswdigit_l _iswdigit_l
218#define iswpunct_l _iswpunct_l
219#define iswxdigit_l _iswxdigit_l
220#define towupper_l _towupper_l
221#define towlower_l _towlower_l
222#if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800
223_LIBCPP_EXPORTED_FROM_ABI size_t strftime_l(char* ret, size_t n, const char* format, const struct tm* tm, locale_t loc);
224#else
225# define strftime_l _strftime_l
226#endif
227#define sscanf_l(__s, __l, __f, ...) _sscanf_l(__s, __f, __l, __VA_ARGS__)
228_LIBCPP_EXPORTED_FROM_ABI int snprintf_l(char* __ret, size_t __n, locale_t __loc, const char* __format, ...);
229_LIBCPP_EXPORTED_FROM_ABI int asprintf_l(char** __ret, locale_t __loc, const char* __format, ...);
230_LIBCPP_EXPORTED_FROM_ABI int vasprintf_l(char** __ret, locale_t __loc, const char* __format, va_list __ap);
231
232// not-so-pressing FIXME: use locale to determine blank characters
233inline int iswblank_l(wint_t __c, locale_t /*loc*/) { return (__c == L' ' || __c == L'\t'); }
234
235#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_WIN32_H
lib/libcxx/include/__locale_dir/pad_and_output.h created+88
......@@ -0,0 +1,88 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___LOCALE_DIR_PAD_AND_OUTPUT_H
10#define _LIBCPP___LOCALE_DIR_PAD_AND_OUTPUT_H
11
12#include <__config>
13
14#if _LIBCPP_HAS_LOCALIZATION
15
16# include <ios>
17
18# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20# endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24template <class _CharT, class _OutputIterator>
25_LIBCPP_HIDE_FROM_ABI _OutputIterator __pad_and_output(
26 _OutputIterator __s, const _CharT* __ob, const _CharT* __op, const _CharT* __oe, ios_base& __iob, _CharT __fl) {
27 streamsize __sz = __oe - __ob;
28 streamsize __ns = __iob.width();
29 if (__ns > __sz)
30 __ns -= __sz;
31 else
32 __ns = 0;
33 for (; __ob < __op; ++__ob, ++__s)
34 *__s = *__ob;
35 for (; __ns; --__ns, ++__s)
36 *__s = __fl;
37 for (; __ob < __oe; ++__ob, ++__s)
38 *__s = *__ob;
39 __iob.width(0);
40 return __s;
41}
42
43template <class _CharT, class _Traits>
44_LIBCPP_HIDE_FROM_ABI ostreambuf_iterator<_CharT, _Traits> __pad_and_output(
45 ostreambuf_iterator<_CharT, _Traits> __s,
46 const _CharT* __ob,
47 const _CharT* __op,
48 const _CharT* __oe,
49 ios_base& __iob,
50 _CharT __fl) {
51 if (__s.__sbuf_ == nullptr)
52 return __s;
53 streamsize __sz = __oe - __ob;
54 streamsize __ns = __iob.width();
55 if (__ns > __sz)
56 __ns -= __sz;
57 else
58 __ns = 0;
59 streamsize __np = __op - __ob;
60 if (__np > 0) {
61 if (__s.__sbuf_->sputn(__ob, __np) != __np) {
62 __s.__sbuf_ = nullptr;
63 return __s;
64 }
65 }
66 if (__ns > 0) {
67 basic_string<_CharT, _Traits> __sp(__ns, __fl);
68 if (__s.__sbuf_->sputn(__sp.data(), __ns) != __ns) {
69 __s.__sbuf_ = nullptr;
70 return __s;
71 }
72 }
73 __np = __oe - __op;
74 if (__np > 0) {
75 if (__s.__sbuf_->sputn(__op, __np) != __np) {
76 __s.__sbuf_ = nullptr;
77 return __s;
78 }
79 }
80 __iob.width(0);
81 return __s;
82}
83
84_LIBCPP_END_NAMESPACE_STD
85
86#endif // _LIBCPP_HAS_LOCALIZATION
87
88#endif // _LIBCPP___LOCALE_DIR_PAD_AND_OUTPUT_H
lib/libcxx/include/__locale_dir/support/apple.h created+20
......@@ -0,0 +1,20 @@
1//===-----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_APPLE_H
10#define _LIBCPP___LOCALE_DIR_SUPPORT_APPLE_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18#include <__locale_dir/support/bsd_like.h>
19
20#endif // _LIBCPP___LOCALE_DIR_SUPPORT_APPLE_H
lib/libcxx/include/__locale_dir/support/bsd_like.h created+234
......@@ -0,0 +1,234 @@
1//===-----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_BSD_LIKE_H
10#define _LIBCPP___LOCALE_DIR_SUPPORT_BSD_LIKE_H
11
12#include <__config>
13#include <__cstddef/size_t.h>
14#include <__std_mbstate_t.h>
15#include <__utility/forward.h>
16#include <clocale> // std::lconv
17#include <ctype.h>
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include <time.h>
22#if _LIBCPP_HAS_WIDE_CHARACTERS
23# include <wchar.h>
24# include <wctype.h>
25#endif
26
27#include <xlocale.h>
28
29#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
30# pragma GCC system_header
31#endif
32
33_LIBCPP_BEGIN_NAMESPACE_STD
34namespace __locale {
35
36//
37// Locale management
38//
39#define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK
40#define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK
41#define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK
42#define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK
43#define _LIBCPP_TIME_MASK LC_TIME_MASK
44#define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
45#define _LIBCPP_ALL_MASK LC_ALL_MASK
46#define _LIBCPP_LC_ALL LC_ALL
47
48using __locale_t = ::locale_t;
49#if defined(_LIBCPP_BUILDING_LIBRARY)
50using __lconv_t = std::lconv;
51
52inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __locale, __locale_t __base) {
53 return ::newlocale(__category_mask, __locale, __base);
54}
55
56inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { ::freelocale(__loc); }
57
58inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, char const* __locale) {
59 return ::setlocale(__category, __locale);
60}
61
62inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) { return ::localeconv_l(__loc); }
63#endif // _LIBCPP_BUILDING_LIBRARY
64
65//
66// Strtonum functions
67//
68inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) {
69 return ::strtof_l(__nptr, __endptr, __loc);
70}
71
72inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) {
73 return ::strtod_l(__nptr, __endptr, __loc);
74}
75
76inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) {
77 return ::strtold_l(__nptr, __endptr, __loc);
78}
79
80inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
81 return ::strtoll_l(__nptr, __endptr, __base, __loc);
82}
83
84inline _LIBCPP_HIDE_FROM_ABI unsigned long long
85__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
86 return ::strtoull_l(__nptr, __endptr, __base, __loc);
87}
88
89//
90// Character manipulation functions
91//
92#if defined(_LIBCPP_BUILDING_LIBRARY)
93inline _LIBCPP_HIDE_FROM_ABI int __islower(int __c, __locale_t __loc) { return ::islower_l(__c, __loc); }
94
95inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __c, __locale_t __loc) { return ::isupper_l(__c, __loc); }
96#endif
97
98inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t __loc) { return ::isdigit_l(__c, __loc); }
99
100inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t __loc) { return ::isxdigit_l(__c, __loc); }
101
102#if defined(_LIBCPP_BUILDING_LIBRARY)
103inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __c, __locale_t __loc) { return ::toupper_l(__c, __loc); }
104
105inline _LIBCPP_HIDE_FROM_ABI int __tolower(int __c, __locale_t __loc) { return ::tolower_l(__c, __loc); }
106
107inline _LIBCPP_HIDE_FROM_ABI int __strcoll(const char* __s1, const char* __s2, __locale_t __loc) {
108 return ::strcoll_l(__s1, __s2, __loc);
109}
110
111inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, size_t __n, __locale_t __loc) {
112 return ::strxfrm_l(__dest, __src, __n, __loc);
113}
114
115# if _LIBCPP_HAS_WIDE_CHARACTERS
116inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __c, wctype_t __type, __locale_t __loc) {
117 return ::iswctype_l(__c, __type, __loc);
118}
119
120inline _LIBCPP_HIDE_FROM_ABI int __iswspace(wint_t __c, __locale_t __loc) { return ::iswspace_l(__c, __loc); }
121
122inline _LIBCPP_HIDE_FROM_ABI int __iswprint(wint_t __c, __locale_t __loc) { return ::iswprint_l(__c, __loc); }
123
124inline _LIBCPP_HIDE_FROM_ABI int __iswcntrl(wint_t __c, __locale_t __loc) { return ::iswcntrl_l(__c, __loc); }
125
126inline _LIBCPP_HIDE_FROM_ABI int __iswupper(wint_t __c, __locale_t __loc) { return ::iswupper_l(__c, __loc); }
127
128inline _LIBCPP_HIDE_FROM_ABI int __iswlower(wint_t __c, __locale_t __loc) { return ::iswlower_l(__c, __loc); }
129
130inline _LIBCPP_HIDE_FROM_ABI int __iswalpha(wint_t __c, __locale_t __loc) { return ::iswalpha_l(__c, __loc); }
131
132inline _LIBCPP_HIDE_FROM_ABI int __iswblank(wint_t __c, __locale_t __loc) { return ::iswblank_l(__c, __loc); }
133
134inline _LIBCPP_HIDE_FROM_ABI int __iswdigit(wint_t __c, __locale_t __loc) { return ::iswdigit_l(__c, __loc); }
135
136inline _LIBCPP_HIDE_FROM_ABI int __iswpunct(wint_t __c, __locale_t __loc) { return ::iswpunct_l(__c, __loc); }
137
138inline _LIBCPP_HIDE_FROM_ABI int __iswxdigit(wint_t __c, __locale_t __loc) { return ::iswxdigit_l(__c, __loc); }
139
140inline _LIBCPP_HIDE_FROM_ABI wint_t __towupper(wint_t __c, __locale_t __loc) { return ::towupper_l(__c, __loc); }
141
142inline _LIBCPP_HIDE_FROM_ABI wint_t __towlower(wint_t __c, __locale_t __loc) { return ::towlower_l(__c, __loc); }
143
144inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __ws1, const wchar_t* __ws2, __locale_t __loc) {
145 return ::wcscoll_l(__ws1, __ws2, __loc);
146}
147
148inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) {
149 return ::wcsxfrm_l(__dest, __src, __n, __loc);
150}
151# endif // _LIBCPP_HAS_WIDE_CHARACTERS
152
153inline _LIBCPP_HIDE_FROM_ABI size_t
154__strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t __loc) {
155 return ::strftime_l(__s, __max, __format, __tm, __loc);
156}
157
158//
159// Other functions
160//
161inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __mb_len_max(__locale_t __loc) { return MB_CUR_MAX_L(__loc); }
162
163# if _LIBCPP_HAS_WIDE_CHARACTERS
164inline _LIBCPP_HIDE_FROM_ABI wint_t __btowc(int __c, __locale_t __loc) { return ::btowc_l(__c, __loc); }
165
166inline _LIBCPP_HIDE_FROM_ABI int __wctob(wint_t __c, __locale_t __loc) { return ::wctob_l(__c, __loc); }
167
168inline _LIBCPP_HIDE_FROM_ABI size_t
169__wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t __loc) {
170 return ::wcsnrtombs_l(__dest, __src, __nwc, __len, __ps, __loc); // wcsnrtombs is a POSIX extension
171}
172
173inline _LIBCPP_HIDE_FROM_ABI size_t __wcrtomb(char* __s, wchar_t __wc, mbstate_t* __ps, __locale_t __loc) {
174 return ::wcrtomb_l(__s, __wc, __ps, __loc);
175}
176
177inline _LIBCPP_HIDE_FROM_ABI size_t
178__mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t __loc) {
179 return ::mbsnrtowcs_l(__dest, __src, __nms, __len, __ps, __loc); // mbsnrtowcs is a POSIX extension
180}
181
182inline _LIBCPP_HIDE_FROM_ABI size_t
183__mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
184 return ::mbrtowc_l(__pwc, __s, __n, __ps, __loc);
185}
186
187inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) {
188 return ::mbtowc_l(__pwc, __pmb, __max, __loc);
189}
190
191inline _LIBCPP_HIDE_FROM_ABI size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
192 return ::mbrlen_l(__s, __n, __ps, __loc);
193}
194
195inline _LIBCPP_HIDE_FROM_ABI size_t
196__mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) {
197 return ::mbsrtowcs_l(__dest, __src, __len, __ps, __loc);
198}
199# endif // _LIBCPP_HAS_WIDE_CHARACTERS
200#endif // _LIBCPP_BUILDING_LIBRARY
201
202_LIBCPP_DIAGNOSTIC_PUSH
203_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat")
204_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates
205#ifdef _LIBCPP_COMPILER_CLANG_BASED
206# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__)
207#else
208# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */
209#endif
210
211template <class... _Args>
212_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf(
213 char* __s, size_t __n, __locale_t __loc, const char* __format, _Args&&... __args) {
214 return ::snprintf_l(__s, __n, __loc, __format, std::forward<_Args>(__args)...);
215}
216
217template <class... _Args>
218_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf(
219 char** __s, __locale_t __loc, const char* __format, _Args&&... __args) {
220 return ::asprintf_l(__s, __loc, __format, std::forward<_Args>(__args)...); // non-standard
221}
222
223template <class... _Args>
224_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf(
225 const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) {
226 return ::sscanf_l(__s, __loc, __format, std::forward<_Args>(__args)...);
227}
228_LIBCPP_DIAGNOSTIC_POP
229#undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
230
231} // namespace __locale
232_LIBCPP_END_NAMESPACE_STD
233
234#endif // _LIBCPP___LOCALE_DIR_SUPPORT_BSD_LIKE_H
lib/libcxx/include/__locale_dir/support/freebsd.h created+20
......@@ -0,0 +1,20 @@
1//===-----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_FREEBSD_H
10#define _LIBCPP___LOCALE_DIR_SUPPORT_FREEBSD_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18#include <__locale_dir/support/bsd_like.h>
19
20#endif // _LIBCPP___LOCALE_DIR_SUPPORT_FREEBSD_H
lib/libcxx/include/__locale_dir/support/fuchsia.h created+160
......@@ -0,0 +1,160 @@
1//===-----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_FUCHSIA_H
10#define _LIBCPP___LOCALE_DIR_SUPPORT_FUCHSIA_H
11
12#include <__config>
13#include <__utility/forward.h>
14#include <clocale> // uselocale & friends
15#include <cstdio>
16#include <cstdlib>
17#include <cwchar>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24namespace __locale {
25
26struct __locale_guard {
27 _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {}
28
29 _LIBCPP_HIDE_FROM_ABI ~__locale_guard() {
30 if (__old_loc_)
31 ::uselocale(__old_loc_);
32 }
33
34 locale_t __old_loc_;
35
36 __locale_guard(__locale_guard const&) = delete;
37 __locale_guard& operator=(__locale_guard const&) = delete;
38};
39
40//
41// Locale management
42//
43#define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK
44#define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK
45#define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK
46#define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK
47#define _LIBCPP_TIME_MASK LC_TIME_MASK
48#define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
49#define _LIBCPP_ALL_MASK LC_ALL_MASK
50#define _LIBCPP_LC_ALL LC_ALL
51
52using __locale_t = locale_t;
53
54#if defined(_LIBCPP_BUILDING_LIBRARY)
55using __lconv_t = std::lconv;
56
57inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __name, __locale_t __loc) {
58 return ::newlocale(__category_mask, __name, __loc);
59}
60
61inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { ::freelocale(__loc); }
62
63inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, char const* __locale) {
64 return ::setlocale(__category, __locale);
65}
66
67inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) {
68 __locale_guard __current(__loc);
69 return std::localeconv();
70}
71
72//
73// Other functions
74//
75inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __mb_len_max(__locale_t __loc) {
76 __locale_guard __current(__loc);
77 return MB_CUR_MAX;
78}
79# if _LIBCPP_HAS_WIDE_CHARACTERS
80inline _LIBCPP_HIDE_FROM_ABI wint_t __btowc(int __ch, __locale_t __loc) {
81 __locale_guard __current(__loc);
82 return std::btowc(__ch);
83}
84inline _LIBCPP_HIDE_FROM_ABI int __wctob(wint_t __ch, __locale_t __loc) {
85 __locale_guard __current(__loc);
86 return std::wctob(__ch);
87}
88inline _LIBCPP_HIDE_FROM_ABI size_t
89__wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t __loc) {
90 __locale_guard __current(__loc);
91 return ::wcsnrtombs(__dest, __src, __nwc, __len, __ps); // non-standard
92}
93inline _LIBCPP_HIDE_FROM_ABI size_t __wcrtomb(char* __s, wchar_t __ch, mbstate_t* __ps, __locale_t __loc) {
94 __locale_guard __current(__loc);
95 return std::wcrtomb(__s, __ch, __ps);
96}
97inline _LIBCPP_HIDE_FROM_ABI size_t
98__mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t __loc) {
99 __locale_guard __current(__loc);
100 return ::mbsnrtowcs(__dest, __src, __nms, __len, __ps); // non-standard
101}
102inline _LIBCPP_HIDE_FROM_ABI size_t
103__mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
104 __locale_guard __current(__loc);
105 return std::mbrtowc(__pwc, __s, __n, __ps);
106}
107inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) {
108 __locale_guard __current(__loc);
109 return std::mbtowc(__pwc, __pmb, __max);
110}
111inline _LIBCPP_HIDE_FROM_ABI size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
112 __locale_guard __current(__loc);
113 return std::mbrlen(__s, __n, __ps);
114}
115inline _LIBCPP_HIDE_FROM_ABI size_t
116__mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) {
117 __locale_guard __current(__loc);
118 return ::mbsrtowcs(__dest, __src, __len, __ps);
119}
120# endif // _LIBCPP_HAS_WIDE_CHARACTERS
121#endif // _LIBCPP_BUILDING_LIBRARY
122
123_LIBCPP_DIAGNOSTIC_PUSH
124_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat")
125_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates
126#ifdef _LIBCPP_COMPILER_CLANG_BASED
127# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__)
128#else
129# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */
130#endif
131
132template <class... _Args>
133_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf(
134 char* __s, size_t __n, __locale_t __loc, const char* __format, _Args&&... __args) {
135 __locale_guard __current(__loc);
136 return std::snprintf(__s, __n, __format, std::forward<_Args>(__args)...);
137}
138template <class... _Args>
139_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf(
140 char** __s, __locale_t __loc, const char* __format, _Args&&... __args) {
141 __locale_guard __current(__loc);
142 return ::asprintf(__s, __format, std::forward<_Args>(__args)...); // non-standard
143}
144template <class... _Args>
145_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf(
146 const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) {
147 __locale_guard __current(__loc);
148 return std::sscanf(__s, __format, std::forward<_Args>(__args)...);
149}
150
151_LIBCPP_DIAGNOSTIC_POP
152#undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
153
154} // namespace __locale
155_LIBCPP_END_NAMESPACE_STD
156
157#include <__locale_dir/support/no_locale/characters.h>
158#include <__locale_dir/support/no_locale/strtonum.h>
159
160#endif // _LIBCPP___LOCALE_DIR_SUPPORT_FUCHSIA_H
lib/libcxx/include/__locale_dir/support/no_locale/characters.h created+102
......@@ -0,0 +1,102 @@
1//===-----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_CHARACTERS_H
10#define _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_CHARACTERS_H
11
12#include <__config>
13#include <__cstddef/size_t.h>
14#include <cctype>
15#include <cstdlib>
16#include <cstring>
17#include <ctime>
18#if _LIBCPP_HAS_WIDE_CHARACTERS
19# include <cwctype>
20#endif
21
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24#endif
25
26_LIBCPP_BEGIN_NAMESPACE_STD
27namespace __locale {
28
29//
30// Character manipulation functions
31//
32#if defined(_LIBCPP_BUILDING_LIBRARY)
33inline _LIBCPP_HIDE_FROM_ABI int __islower(int __c, __locale_t) { return std::islower(__c); }
34
35inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __c, __locale_t) { return std::isupper(__c); }
36#endif
37
38inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t) { return std::isdigit(__c); }
39
40inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t) { return std::isxdigit(__c); }
41
42#if defined(_LIBCPP_BUILDING_LIBRARY)
43inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __c, __locale_t) { return std::toupper(__c); }
44
45inline _LIBCPP_HIDE_FROM_ABI int __tolower(int __c, __locale_t) { return std::tolower(__c); }
46
47inline _LIBCPP_HIDE_FROM_ABI int __strcoll(const char* __s1, const char* __s2, __locale_t) {
48 return std::strcoll(__s1, __s2);
49}
50
51inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, size_t __n, __locale_t) {
52 return std::strxfrm(__dest, __src, __n);
53}
54
55# if _LIBCPP_HAS_WIDE_CHARACTERS
56inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __c, wctype_t __type, __locale_t) {
57 return std::iswctype(__c, __type);
58}
59
60inline _LIBCPP_HIDE_FROM_ABI int __iswspace(wint_t __c, __locale_t) { return std::iswspace(__c); }
61
62inline _LIBCPP_HIDE_FROM_ABI int __iswprint(wint_t __c, __locale_t) { return std::iswprint(__c); }
63
64inline _LIBCPP_HIDE_FROM_ABI int __iswcntrl(wint_t __c, __locale_t) { return std::iswcntrl(__c); }
65
66inline _LIBCPP_HIDE_FROM_ABI int __iswupper(wint_t __c, __locale_t) { return std::iswupper(__c); }
67
68inline _LIBCPP_HIDE_FROM_ABI int __iswlower(wint_t __c, __locale_t) { return std::iswlower(__c); }
69
70inline _LIBCPP_HIDE_FROM_ABI int __iswalpha(wint_t __c, __locale_t) { return std::iswalpha(__c); }
71
72inline _LIBCPP_HIDE_FROM_ABI int __iswblank(wint_t __c, __locale_t) { return std::iswblank(__c); }
73
74inline _LIBCPP_HIDE_FROM_ABI int __iswdigit(wint_t __c, __locale_t) { return std::iswdigit(__c); }
75
76inline _LIBCPP_HIDE_FROM_ABI int __iswpunct(wint_t __c, __locale_t) { return std::iswpunct(__c); }
77
78inline _LIBCPP_HIDE_FROM_ABI int __iswxdigit(wint_t __c, __locale_t) { return std::iswxdigit(__c); }
79
80inline _LIBCPP_HIDE_FROM_ABI wint_t __towupper(wint_t __c, __locale_t) { return std::towupper(__c); }
81
82inline _LIBCPP_HIDE_FROM_ABI wint_t __towlower(wint_t __c, __locale_t) { return std::towlower(__c); }
83
84inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __ws1, const wchar_t* __ws2, __locale_t) {
85 return std::wcscoll(__ws1, __ws2);
86}
87
88inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t) {
89 return std::wcsxfrm(__dest, __src, __n);
90}
91# endif // _LIBCPP_HAS_WIDE_CHARACTERS
92
93inline _LIBCPP_HIDE_FROM_ABI size_t
94__strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t) {
95 return std::strftime(__s, __max, __format, __tm);
96}
97#endif // _LIBCPP_BUILDING_LIBRARY
98
99} // namespace __locale
100_LIBCPP_END_NAMESPACE_STD
101
102#endif // _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_CHARACTERS_H
lib/libcxx/include/__locale_dir/support/no_locale/strtonum.h created+49
......@@ -0,0 +1,49 @@
1//===-----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_STRTONUM_H
10#define _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_STRTONUM_H
11
12#include <__config>
13#include <cstdlib>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20namespace __locale {
21
22//
23// Strtonum functions
24//
25inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t) {
26 return std::strtof(__nptr, __endptr);
27}
28
29inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t) {
30 return std::strtod(__nptr, __endptr);
31}
32
33inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t) {
34 return std::strtold(__nptr, __endptr);
35}
36
37inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t) {
38 return std::strtoll(__nptr, __endptr, __base);
39}
40
41inline _LIBCPP_HIDE_FROM_ABI unsigned long long
42__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t) {
43 return std::strtoull(__nptr, __endptr, __base);
44}
45
46} // namespace __locale
47_LIBCPP_END_NAMESPACE_STD
48
49#endif // _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_STRTONUM_H
lib/libcxx/include/__locale_dir/support/windows.h created+343
......@@ -0,0 +1,343 @@
1//===-----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_WINDOWS_H
10#define _LIBCPP___LOCALE_DIR_SUPPORT_WINDOWS_H
11
12#include <__config>
13#include <__cstddef/nullptr_t.h>
14#include <__utility/forward.h>
15#include <clocale> // std::lconv & friends
16#include <cstddef>
17#include <ctype.h> // ::_isupper_l & friends
18#include <locale.h> // ::_locale_t
19#include <stdio.h> // ::_sscanf_l
20#include <stdlib.h> // ::_strtod_l & friends
21#include <string.h> // ::_strcoll_l
22#include <string>
23#include <time.h> // ::_strftime_l
24
25#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26# pragma GCC system_header
27#endif
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30namespace __locale {
31
32using __lconv_t = std::lconv;
33
34class __lconv_storage {
35public:
36 __lconv_storage(const __lconv_t* __lc_input) {
37 __lc_ = *__lc_input;
38
39 __decimal_point_ = __lc_input->decimal_point;
40 __thousands_sep_ = __lc_input->thousands_sep;
41 __grouping_ = __lc_input->grouping;
42 __int_curr_symbol_ = __lc_input->int_curr_symbol;
43 __currency_symbol_ = __lc_input->currency_symbol;
44 __mon_decimal_point_ = __lc_input->mon_decimal_point;
45 __mon_thousands_sep_ = __lc_input->mon_thousands_sep;
46 __mon_grouping_ = __lc_input->mon_grouping;
47 __positive_sign_ = __lc_input->positive_sign;
48 __negative_sign_ = __lc_input->negative_sign;
49
50 __lc_.decimal_point = const_cast<char*>(__decimal_point_.c_str());
51 __lc_.thousands_sep = const_cast<char*>(__thousands_sep_.c_str());
52 __lc_.grouping = const_cast<char*>(__grouping_.c_str());
53 __lc_.int_curr_symbol = const_cast<char*>(__int_curr_symbol_.c_str());
54 __lc_.currency_symbol = const_cast<char*>(__currency_symbol_.c_str());
55 __lc_.mon_decimal_point = const_cast<char*>(__mon_decimal_point_.c_str());
56 __lc_.mon_thousands_sep = const_cast<char*>(__mon_thousands_sep_.c_str());
57 __lc_.mon_grouping = const_cast<char*>(__mon_grouping_.c_str());
58 __lc_.positive_sign = const_cast<char*>(__positive_sign_.c_str());
59 __lc_.negative_sign = const_cast<char*>(__negative_sign_.c_str());
60 }
61
62 __lconv_t* __get() { return &__lc_; }
63
64private:
65 __lconv_t __lc_;
66 std::string __decimal_point_;
67 std::string __thousands_sep_;
68 std::string __grouping_;
69 std::string __int_curr_symbol_;
70 std::string __currency_symbol_;
71 std::string __mon_decimal_point_;
72 std::string __mon_thousands_sep_;
73 std::string __mon_grouping_;
74 std::string __positive_sign_;
75 std::string __negative_sign_;
76};
77
78//
79// Locale management
80//
81#define _CATMASK(n) ((1 << (n)) >> 1)
82#define _LIBCPP_COLLATE_MASK _CATMASK(LC_COLLATE)
83#define _LIBCPP_CTYPE_MASK _CATMASK(LC_CTYPE)
84#define _LIBCPP_MONETARY_MASK _CATMASK(LC_MONETARY)
85#define _LIBCPP_NUMERIC_MASK _CATMASK(LC_NUMERIC)
86#define _LIBCPP_TIME_MASK _CATMASK(LC_TIME)
87#define _LIBCPP_MESSAGES_MASK _CATMASK(6)
88#define _LIBCPP_ALL_MASK \
89 (_LIBCPP_COLLATE_MASK | _LIBCPP_CTYPE_MASK | _LIBCPP_MESSAGES_MASK | _LIBCPP_MONETARY_MASK | _LIBCPP_NUMERIC_MASK | \
90 _LIBCPP_TIME_MASK)
91#define _LIBCPP_LC_ALL LC_ALL
92
93class __locale_t {
94public:
95 __locale_t() : __locale_(nullptr), __locale_str_(nullptr), __lc_(nullptr) {}
96 __locale_t(std::nullptr_t) : __locale_(nullptr), __locale_str_(nullptr), __lc_(nullptr) {}
97 __locale_t(::_locale_t __loc, const char* __loc_str) : __locale_(__loc), __locale_str_(__loc_str), __lc_(nullptr) {}
98 __locale_t(const __locale_t& __loc)
99 : __locale_(__loc.__locale_), __locale_str_(__loc.__locale_str_), __lc_(nullptr) {}
100
101 ~__locale_t() { delete __lc_; }
102
103 __locale_t& operator=(const __locale_t& __loc) {
104 __locale_ = __loc.__locale_;
105 __locale_str_ = __loc.__locale_str_;
106 // __lc_ not copied
107 return *this;
108 }
109
110 friend bool operator==(const __locale_t& __left, const __locale_t& __right) {
111 return __left.__locale_ == __right.__locale_;
112 }
113
114 friend bool operator==(const __locale_t& __left, int __right) { return __left.__locale_ == nullptr && __right == 0; }
115
116 friend bool operator==(const __locale_t& __left, long long __right) {
117 return __left.__locale_ == nullptr && __right == 0;
118 }
119
120 friend bool operator==(const __locale_t& __left, std::nullptr_t) { return __left.__locale_ == nullptr; }
121
122 friend bool operator==(int __left, const __locale_t& __right) { return __left == 0 && nullptr == __right.__locale_; }
123
124 friend bool operator==(std::nullptr_t, const __locale_t& __right) { return nullptr == __right.__locale_; }
125
126 friend bool operator!=(const __locale_t& __left, const __locale_t& __right) { return !(__left == __right); }
127
128 friend bool operator!=(const __locale_t& __left, int __right) { return !(__left == __right); }
129
130 friend bool operator!=(const __locale_t& __left, long long __right) { return !(__left == __right); }
131
132 friend bool operator!=(const __locale_t& __left, std::nullptr_t __right) { return !(__left == __right); }
133
134 friend bool operator!=(int __left, const __locale_t& __right) { return !(__left == __right); }
135
136 friend bool operator!=(std::nullptr_t __left, const __locale_t& __right) { return !(__left == __right); }
137
138 operator bool() const { return __locale_ != nullptr; }
139
140 const char* __get_locale() const { return __locale_str_; }
141
142 operator ::_locale_t() const { return __locale_; }
143
144 __lconv_t* __store_lconv(const __lconv_t* __input_lc) {
145 delete __lc_;
146 __lc_ = new __lconv_storage(__input_lc);
147 return __lc_->__get();
148 }
149
150private:
151 ::_locale_t __locale_;
152 const char* __locale_str_;
153 __lconv_storage* __lc_ = nullptr;
154};
155
156#if defined(_LIBCPP_BUILDING_LIBRARY)
157_LIBCPP_EXPORTED_FROM_ABI __locale_t __newlocale(int __mask, const char* __locale, __locale_t __base);
158inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { ::_free_locale(__loc); }
159inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, const char* __locale) {
160 char* __new_locale = ::setlocale(__category, __locale);
161 if (__new_locale == nullptr)
162 std::__throw_bad_alloc();
163 return __new_locale;
164}
165_LIBCPP_EXPORTED_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc);
166#endif // _LIBCPP_BUILDING_LIBRARY
167
168//
169// Strtonum functions
170//
171
172// the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+
173#if defined(_LIBCPP_MSVCRT)
174inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) {
175 return ::_strtof_l(__nptr, __endptr, __loc);
176}
177inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) {
178 return ::_strtold_l(__nptr, __endptr, __loc);
179}
180#else
181_LIBCPP_EXPORTED_FROM_ABI float __strtof(const char*, char**, __locale_t);
182_LIBCPP_EXPORTED_FROM_ABI long double __strtold(const char*, char**, __locale_t);
183#endif
184
185inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) {
186 return ::_strtod_l(__nptr, __endptr, __loc);
187}
188
189inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
190 return ::_strtoi64_l(__nptr, __endptr, __base, __loc);
191}
192inline _LIBCPP_HIDE_FROM_ABI unsigned long long
193__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
194 return ::_strtoui64_l(__nptr, __endptr, __base, __loc);
195}
196
197//
198// Character manipulation functions
199//
200#if defined(_LIBCPP_BUILDING_LIBRARY)
201inline _LIBCPP_HIDE_FROM_ABI int __islower(int __c, __locale_t __loc) { return _islower_l(__c, __loc); }
202
203inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __c, __locale_t __loc) { return _isupper_l(__c, __loc); }
204#endif
205
206inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t __loc) { return _isdigit_l(__c, __loc); }
207
208inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t __loc) { return _isxdigit_l(__c, __loc); }
209
210#if defined(_LIBCPP_BUILDING_LIBRARY)
211inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __c, __locale_t __loc) { return ::_toupper_l(__c, __loc); }
212
213inline _LIBCPP_HIDE_FROM_ABI int __tolower(int __c, __locale_t __loc) { return ::_tolower_l(__c, __loc); }
214
215inline _LIBCPP_HIDE_FROM_ABI int __strcoll(const char* __s1, const char* __s2, __locale_t __loc) {
216 return ::_strcoll_l(__s1, __s2, __loc);
217}
218
219inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, size_t __n, __locale_t __loc) {
220 return ::_strxfrm_l(__dest, __src, __n, __loc);
221}
222
223# if _LIBCPP_HAS_WIDE_CHARACTERS
224inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __c, wctype_t __type, __locale_t __loc) {
225 return ::_iswctype_l(__c, __type, __loc);
226}
227inline _LIBCPP_HIDE_FROM_ABI int __iswspace(wint_t __c, __locale_t __loc) { return ::_iswspace_l(__c, __loc); }
228inline _LIBCPP_HIDE_FROM_ABI int __iswprint(wint_t __c, __locale_t __loc) { return ::_iswprint_l(__c, __loc); }
229inline _LIBCPP_HIDE_FROM_ABI int __iswcntrl(wint_t __c, __locale_t __loc) { return ::_iswcntrl_l(__c, __loc); }
230inline _LIBCPP_HIDE_FROM_ABI int __iswupper(wint_t __c, __locale_t __loc) { return ::_iswupper_l(__c, __loc); }
231inline _LIBCPP_HIDE_FROM_ABI int __iswlower(wint_t __c, __locale_t __loc) { return ::_iswlower_l(__c, __loc); }
232inline _LIBCPP_HIDE_FROM_ABI int __iswalpha(wint_t __c, __locale_t __loc) { return ::_iswalpha_l(__c, __loc); }
233// TODO: use locale to determine blank characters
234inline _LIBCPP_HIDE_FROM_ABI int __iswblank(wint_t __c, __locale_t /*loc*/) { return (__c == L' ' || __c == L'\t'); }
235inline _LIBCPP_HIDE_FROM_ABI int __iswdigit(wint_t __c, __locale_t __loc) { return ::_iswdigit_l(__c, __loc); }
236inline _LIBCPP_HIDE_FROM_ABI int __iswpunct(wint_t __c, __locale_t __loc) { return ::_iswpunct_l(__c, __loc); }
237inline _LIBCPP_HIDE_FROM_ABI int __iswxdigit(wint_t __c, __locale_t __loc) { return ::_iswxdigit_l(__c, __loc); }
238inline _LIBCPP_HIDE_FROM_ABI wint_t __towupper(wint_t __c, __locale_t __loc) { return ::_towupper_l(__c, __loc); }
239inline _LIBCPP_HIDE_FROM_ABI wint_t __towlower(wint_t __c, __locale_t __loc) { return ::_towlower_l(__c, __loc); }
240
241inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __ws1, const wchar_t* __ws2, __locale_t __loc) {
242 return ::_wcscoll_l(__ws1, __ws2, __loc);
243}
244
245inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) {
246 return ::_wcsxfrm_l(__dest, __src, __n, __loc);
247}
248# endif // _LIBCPP_HAS_WIDE_CHARACTERS
249
250# if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800
251_LIBCPP_EXPORTED_FROM_ABI size_t __strftime(char*, size_t, const char*, const struct tm*, __locale_t);
252# else
253inline _LIBCPP_HIDE_FROM_ABI size_t
254__strftime(char* __ret, size_t __n, const char* __format, const struct tm* __tm, __locale_t __loc) {
255 return ::_strftime_l(__ret, __n, __format, __tm, __loc);
256}
257# endif
258
259//
260// Other functions
261//
262_LIBCPP_EXPORTED_FROM_ABI decltype(MB_CUR_MAX) __mb_len_max(__locale_t);
263_LIBCPP_EXPORTED_FROM_ABI wint_t __btowc(int, __locale_t);
264_LIBCPP_EXPORTED_FROM_ABI int __wctob(wint_t, __locale_t);
265_LIBCPP_EXPORTED_FROM_ABI size_t
266__wcsnrtombs(char* __restrict, const wchar_t** __restrict, size_t, size_t, mbstate_t* __restrict, __locale_t);
267_LIBCPP_EXPORTED_FROM_ABI size_t __wcrtomb(char* __restrict, wchar_t, mbstate_t* __restrict, __locale_t);
268_LIBCPP_EXPORTED_FROM_ABI size_t
269__mbsnrtowcs(wchar_t* __restrict, const char** __restrict, size_t, size_t, mbstate_t* __restrict, __locale_t);
270_LIBCPP_EXPORTED_FROM_ABI size_t
271__mbrtowc(wchar_t* __restrict, const char* __restrict, size_t, mbstate_t* __restrict, __locale_t);
272
273inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) {
274 return ::_mbtowc_l(__pwc, __pmb, __max, __loc);
275}
276
277_LIBCPP_EXPORTED_FROM_ABI size_t __mbrlen(const char* __restrict, size_t, mbstate_t* __restrict, __locale_t);
278
279_LIBCPP_EXPORTED_FROM_ABI size_t
280__mbsrtowcs(wchar_t* __restrict, const char** __restrict, size_t, mbstate_t* __restrict, __locale_t);
281#endif // _LIBCPP_BUILDING_LIBRARY
282
283_LIBCPP_EXPORTED_FROM_ABI _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf(
284 char* __ret, size_t __n, __locale_t __loc, const char* __format, ...);
285
286_LIBCPP_EXPORTED_FROM_ABI
287_LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf(char** __ret, __locale_t __loc, const char* __format, ...);
288
289_LIBCPP_DIAGNOSTIC_PUSH
290_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat")
291_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates
292#ifdef _LIBCPP_COMPILER_CLANG_BASED
293# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__)
294#else
295# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */
296#endif
297
298template <class... _Args>
299_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf(
300 const char* __dest, __locale_t __loc, const char* __format, _Args&&... __args) {
301 return ::_sscanf_l(__dest, __format, __loc, std::forward<_Args>(__args)...);
302}
303_LIBCPP_DIAGNOSTIC_POP
304#undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
305
306#if defined(_LIBCPP_BUILDING_LIBRARY)
307struct __locale_guard {
308 _LIBCPP_HIDE_FROM_ABI __locale_guard(__locale_t __l) : __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) {
309 // Setting the locale can be expensive even when the locale given is
310 // already the current locale, so do an explicit check to see if the
311 // current locale is already the one we want.
312 const char* __lc = __locale::__setlocale(LC_ALL, nullptr);
313 // If every category is the same, the locale string will simply be the
314 // locale name, otherwise it will be a semicolon-separated string listing
315 // each category. In the second case, we know at least one category won't
316 // be what we want, so we only have to check the first case.
317 if (std::strcmp(__l.__get_locale(), __lc) != 0) {
318 __locale_all = _strdup(__lc);
319 if (__locale_all == nullptr)
320 __throw_bad_alloc();
321 __locale::__setlocale(LC_ALL, __l.__get_locale());
322 }
323 }
324 _LIBCPP_HIDE_FROM_ABI ~__locale_guard() {
325 // The CRT documentation doesn't explicitly say, but setlocale() does the
326 // right thing when given a semicolon-separated list of locale settings
327 // for the different categories in the same format as returned by
328 // setlocale(LC_ALL, nullptr).
329 if (__locale_all != nullptr) {
330 __locale::__setlocale(LC_ALL, __locale_all);
331 free(__locale_all);
332 }
333 _configthreadlocale(__status);
334 }
335 int __status;
336 char* __locale_all = nullptr;
337};
338#endif // _LIBCPP_BUILDING_LIBRARY
339
340} // namespace __locale
341_LIBCPP_END_NAMESPACE_STD
342
343#endif // _LIBCPP___LOCALE_DIR_SUPPORT_WINDOWS_H
lib/libcxx/include/__math/abs.h+4-4
......@@ -23,19 +23,19 @@ namespace __math {
2323
2424// fabs
2525
26_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float fabs(float __x) _NOEXCEPT { return __builtin_fabsf(__x); }
26[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float fabs(float __x) _NOEXCEPT { return __builtin_fabsf(__x); }
2727
2828template <class = int>
29_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double fabs(double __x) _NOEXCEPT {
29[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double fabs(double __x) _NOEXCEPT {
3030 return __builtin_fabs(__x);
3131}
3232
33_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double fabs(long double __x) _NOEXCEPT {
33[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double fabs(long double __x) _NOEXCEPT {
3434 return __builtin_fabsl(__x);
3535}
3636
3737template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
38_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double fabs(_A1 __x) _NOEXCEPT {
38[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double fabs(_A1 __x) _NOEXCEPT {
3939 return __builtin_fabs((double)__x);
4040}
4141
lib/libcxx/include/__math/copysign.h+3-4
......@@ -13,7 +13,6 @@
1313#include <__type_traits/enable_if.h>
1414#include <__type_traits/is_arithmetic.h>
1515#include <__type_traits/promote.h>
16#include <limits>
1716
1817#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1918# pragma GCC system_header
......@@ -25,16 +24,16 @@ namespace __math {
2524
2625// copysign
2726
28_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float copysign(float __x, float __y) _NOEXCEPT {
27[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float copysign(float __x, float __y) _NOEXCEPT {
2928 return ::__builtin_copysignf(__x, __y);
3029}
3130
32_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double copysign(long double __x, long double __y) _NOEXCEPT {
31[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double copysign(long double __x, long double __y) _NOEXCEPT {
3332 return ::__builtin_copysignl(__x, __y);
3433}
3534
3635template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
37_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type copysign(_A1 __x, _A2 __y) _NOEXCEPT {
36[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type copysign(_A1 __x, _A2 __y) _NOEXCEPT {
3837 return ::__builtin_copysign(__x, __y);
3938}
4039
lib/libcxx/include/__math/hypot.h+2-3
......@@ -9,16 +9,15 @@
99#ifndef _LIBCPP___MATH_HYPOT_H
1010#define _LIBCPP___MATH_HYPOT_H
1111
12#include <__algorithm/max.h>
1312#include <__config>
1413#include <__math/abs.h>
1514#include <__math/exponential_functions.h>
15#include <__math/min_max.h>
1616#include <__math/roots.h>
1717#include <__type_traits/enable_if.h>
1818#include <__type_traits/is_arithmetic.h>
1919#include <__type_traits/is_same.h>
2020#include <__type_traits/promote.h>
21#include <__utility/pair.h>
2221#include <limits>
2322
2423#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -63,7 +62,7 @@ _LIBCPP_HIDE_FROM_ABI _Real __hypot(_Real __x, _Real __y, _Real __z) {
6362 const _Real __overflow_scale = __math::ldexp(_Real(1), -(__exp + 20));
6463
6564 // Scale arguments depending on their size
66 const _Real __max_abs = std::max(__math::fabs(__x), std::max(__math::fabs(__y), __math::fabs(__z)));
65 const _Real __max_abs = __math::fmax(__math::fabs(__x), __math::fmax(__math::fabs(__y), __math::fabs(__z)));
6766 _Real __scale;
6867 if (__max_abs > __overflow_threshold) { // x*x + y*y + z*z might overflow
6968 __scale = __overflow_scale;
lib/libcxx/include/__math/min_max.h+8-8
......@@ -25,21 +25,21 @@ namespace __math {
2525
2626// fmax
2727
28_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float fmax(float __x, float __y) _NOEXCEPT {
28[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float fmax(float __x, float __y) _NOEXCEPT {
2929 return __builtin_fmaxf(__x, __y);
3030}
3131
3232template <class = int>
33_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double fmax(double __x, double __y) _NOEXCEPT {
33[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double fmax(double __x, double __y) _NOEXCEPT {
3434 return __builtin_fmax(__x, __y);
3535}
3636
37_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double fmax(long double __x, long double __y) _NOEXCEPT {
37[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double fmax(long double __x, long double __y) _NOEXCEPT {
3838 return __builtin_fmaxl(__x, __y);
3939}
4040
4141template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
42_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmax(_A1 __x, _A2 __y) _NOEXCEPT {
42[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmax(_A1 __x, _A2 __y) _NOEXCEPT {
4343 using __result_type = typename __promote<_A1, _A2>::type;
4444 static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
4545 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
4747
4848// fmin
4949
50_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float fmin(float __x, float __y) _NOEXCEPT {
50[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float fmin(float __x, float __y) _NOEXCEPT {
5151 return __builtin_fminf(__x, __y);
5252}
5353
5454template <class = int>
55_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double fmin(double __x, double __y) _NOEXCEPT {
55[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double fmin(double __x, double __y) _NOEXCEPT {
5656 return __builtin_fmin(__x, __y);
5757}
5858
59_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double fmin(long double __x, long double __y) _NOEXCEPT {
59[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double fmin(long double __x, long double __y) _NOEXCEPT {
6060 return __builtin_fminl(__x, __y);
6161}
6262
6363template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
64_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmin(_A1 __x, _A2 __y) _NOEXCEPT {
64[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmin(_A1 __x, _A2 __y) _NOEXCEPT {
6565 using __result_type = typename __promote<_A1, _A2>::type;
6666 static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
6767 return __math::fmin((__result_type)__x, (__result_type)__y);
lib/libcxx/include/__math/remainder.h-1
......@@ -14,7 +14,6 @@
1414#include <__type_traits/is_arithmetic.h>
1515#include <__type_traits/is_same.h>
1616#include <__type_traits/promote.h>
17#include <limits>
1817
1918#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2019# pragma GCC system_header
lib/libcxx/include/__math/roots.h+4-4
......@@ -39,19 +39,19 @@ inline _LIBCPP_HIDE_FROM_ABI double sqrt(_A1 __x) _NOEXCEPT {
3939
4040// cbrt
4141
42_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float cbrt(float __x) _NOEXCEPT { return __builtin_cbrtf(__x); }
42[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float cbrt(float __x) _NOEXCEPT { return __builtin_cbrtf(__x); }
4343
4444template <class = int>
45_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double cbrt(double __x) _NOEXCEPT {
45[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double cbrt(double __x) _NOEXCEPT {
4646 return __builtin_cbrt(__x);
4747}
4848
49_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double cbrt(long double __x) _NOEXCEPT {
49[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double cbrt(long double __x) _NOEXCEPT {
5050 return __builtin_cbrtl(__x);
5151}
5252
5353template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
54_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double cbrt(_A1 __x) _NOEXCEPT {
54[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double cbrt(_A1 __x) _NOEXCEPT {
5555 return __builtin_cbrt((double)__x);
5656}
5757
lib/libcxx/include/__math/rounding_functions.h+24-24
......@@ -26,37 +26,37 @@ namespace __math {
2626
2727// ceil
2828
29_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float ceil(float __x) _NOEXCEPT { return __builtin_ceilf(__x); }
29[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float ceil(float __x) _NOEXCEPT { return __builtin_ceilf(__x); }
3030
3131template <class = int>
32_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double ceil(double __x) _NOEXCEPT {
32[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double ceil(double __x) _NOEXCEPT {
3333 return __builtin_ceil(__x);
3434}
3535
36_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double ceil(long double __x) _NOEXCEPT {
36[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double ceil(long double __x) _NOEXCEPT {
3737 return __builtin_ceill(__x);
3838}
3939
4040template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
41_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double ceil(_A1 __x) _NOEXCEPT {
41[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double ceil(_A1 __x) _NOEXCEPT {
4242 return __builtin_ceil((double)__x);
4343}
4444
4545// floor
4646
47_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float floor(float __x) _NOEXCEPT { return __builtin_floorf(__x); }
47[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float floor(float __x) _NOEXCEPT { return __builtin_floorf(__x); }
4848
4949template <class = int>
50_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double floor(double __x) _NOEXCEPT {
50[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double floor(double __x) _NOEXCEPT {
5151 return __builtin_floor(__x);
5252}
5353
54_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double floor(long double __x) _NOEXCEPT {
54[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double floor(long double __x) _NOEXCEPT {
5555 return __builtin_floorl(__x);
5656}
5757
5858template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
59_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double floor(_A1 __x) _NOEXCEPT {
59[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double floor(_A1 __x) _NOEXCEPT {
6060 return __builtin_floor((double)__x);
6161}
6262
......@@ -126,21 +126,21 @@ inline _LIBCPP_HIDE_FROM_ABI long lround(_A1 __x) _NOEXCEPT {
126126
127127// nearbyint
128128
129_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float nearbyint(float __x) _NOEXCEPT {
129[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float nearbyint(float __x) _NOEXCEPT {
130130 return __builtin_nearbyintf(__x);
131131}
132132
133133template <class = int>
134_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double nearbyint(double __x) _NOEXCEPT {
134[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double nearbyint(double __x) _NOEXCEPT {
135135 return __builtin_nearbyint(__x);
136136}
137137
138_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double nearbyint(long double __x) _NOEXCEPT {
138[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double nearbyint(long double __x) _NOEXCEPT {
139139 return __builtin_nearbyintl(__x);
140140}
141141
142142template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
143_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double nearbyint(_A1 __x) _NOEXCEPT {
143[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double nearbyint(_A1 __x) _NOEXCEPT {
144144 return __builtin_nearbyint((double)__x);
145145}
146146
......@@ -186,55 +186,55 @@ inline _LIBCPP_HIDE_FROM_ABI double nexttoward(_A1 __x, long double __y) _NOEXCE
186186
187187// rint
188188
189_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float rint(float __x) _NOEXCEPT { return __builtin_rintf(__x); }
189[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float rint(float __x) _NOEXCEPT { return __builtin_rintf(__x); }
190190
191191template <class = int>
192_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double rint(double __x) _NOEXCEPT {
192[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double rint(double __x) _NOEXCEPT {
193193 return __builtin_rint(__x);
194194}
195195
196_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double rint(long double __x) _NOEXCEPT {
196[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double rint(long double __x) _NOEXCEPT {
197197 return __builtin_rintl(__x);
198198}
199199
200200template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
201_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double rint(_A1 __x) _NOEXCEPT {
201[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double rint(_A1 __x) _NOEXCEPT {
202202 return __builtin_rint((double)__x);
203203}
204204
205205// round
206206
207_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float round(float __x) _NOEXCEPT { return __builtin_round(__x); }
207[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float round(float __x) _NOEXCEPT { return __builtin_round(__x); }
208208
209209template <class = int>
210_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double round(double __x) _NOEXCEPT {
210[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double round(double __x) _NOEXCEPT {
211211 return __builtin_round(__x);
212212}
213213
214_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double round(long double __x) _NOEXCEPT {
214[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double round(long double __x) _NOEXCEPT {
215215 return __builtin_roundl(__x);
216216}
217217
218218template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
219_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double round(_A1 __x) _NOEXCEPT {
219[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double round(_A1 __x) _NOEXCEPT {
220220 return __builtin_round((double)__x);
221221}
222222
223223// trunc
224224
225_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float trunc(float __x) _NOEXCEPT { return __builtin_trunc(__x); }
225[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float trunc(float __x) _NOEXCEPT { return __builtin_trunc(__x); }
226226
227227template <class = int>
228_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double trunc(double __x) _NOEXCEPT {
228[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double trunc(double __x) _NOEXCEPT {
229229 return __builtin_trunc(__x);
230230}
231231
232_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double trunc(long double __x) _NOEXCEPT {
232[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double trunc(long double __x) _NOEXCEPT {
233233 return __builtin_truncl(__x);
234234}
235235
236236template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
237_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double trunc(_A1 __x) _NOEXCEPT {
237[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double trunc(_A1 __x) _NOEXCEPT {
238238 return __builtin_trunc((double)__x);
239239}
240240
lib/libcxx/include/__math/traits.h+66-52
......@@ -12,11 +12,9 @@
1212#include <__config>
1313#include <__type_traits/enable_if.h>
1414#include <__type_traits/is_arithmetic.h>
15#include <__type_traits/is_floating_point.h>
1615#include <__type_traits/is_integral.h>
1716#include <__type_traits/is_signed.h>
1817#include <__type_traits/promote.h>
19#include <limits>
2018
2119#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2220# pragma GCC system_header
......@@ -28,115 +26,131 @@ namespace __math {
2826
2927// signbit
3028
31template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
32_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
29// TODO(LLVM 22): Remove conditional once support for Clang 19 is dropped.
30#if defined(_LIBCPP_COMPILER_GCC) || __has_constexpr_builtin(__builtin_signbit)
31# define _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_CONSTEXPR_SINCE_CXX23
32#else
33# define _LIBCPP_SIGNBIT_CONSTEXPR
34#endif
35
36// The universal C runtime (UCRT) in the WinSDK provides floating point overloads
37// for std::signbit(). By defining our overloads as templates, we can work around
38// this issue as templates are less preferred than non-template functions.
39template <class = void>
40[[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(float __x) _NOEXCEPT {
41 return __builtin_signbit(__x);
42}
43
44template <class = void>
45[[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(double __x) _NOEXCEPT {
46 return __builtin_signbit(__x);
47}
48
49template <class = void>
50[[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(long double __x) _NOEXCEPT {
3351 return __builtin_signbit(__x);
3452}
3553
3654template <class _A1, __enable_if_t<is_integral<_A1>::value && is_signed<_A1>::value, int> = 0>
37_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
55[[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
3856 return __x < 0;
3957}
4058
4159template <class _A1, __enable_if_t<is_integral<_A1>::value && !is_signed<_A1>::value, int> = 0>
42_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1) _NOEXCEPT {
60[[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(_A1) _NOEXCEPT {
4361 return false;
4462}
4563
4664// isfinite
4765
48template <class _A1, __enable_if_t<is_arithmetic<_A1>::value && numeric_limits<_A1>::has_infinity, int> = 0>
49_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1 __x) _NOEXCEPT {
50 return __builtin_isfinite((typename __promote<_A1>::type)__x);
51}
52
53template <class _A1, __enable_if_t<is_arithmetic<_A1>::value && !numeric_limits<_A1>::has_infinity, int> = 0>
54_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1) _NOEXCEPT {
66template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
67[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1) _NOEXCEPT {
5568 return true;
5669}
5770
58_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(float __x) _NOEXCEPT {
71[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(float __x) _NOEXCEPT {
5972 return __builtin_isfinite(__x);
6073}
6174
62_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(double __x) _NOEXCEPT {
75[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(double __x) _NOEXCEPT {
6376 return __builtin_isfinite(__x);
6477}
6578
66_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(long double __x) _NOEXCEPT {
79[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(long double __x) _NOEXCEPT {
6780 return __builtin_isfinite(__x);
6881}
6982
7083// isinf
7184
72template <class _A1, __enable_if_t<is_arithmetic<_A1>::value && numeric_limits<_A1>::has_infinity, int> = 0>
73_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(_A1 __x) _NOEXCEPT {
74 return __builtin_isinf((typename __promote<_A1>::type)__x);
75}
76
77template <class _A1, __enable_if_t<is_arithmetic<_A1>::value && !numeric_limits<_A1>::has_infinity, int> = 0>
78_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(_A1) _NOEXCEPT {
85template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
86[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(_A1) _NOEXCEPT {
7987 return false;
8088}
8189
82#ifdef _LIBCPP_PREFERRED_OVERLOAD
83_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(float __x) _NOEXCEPT {
90[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(float __x) _NOEXCEPT {
8491 return __builtin_isinf(__x);
8592}
8693
87_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool
88isinf(double __x) _NOEXCEPT {
94[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
95#ifdef _LIBCPP_PREFERRED_OVERLOAD
96_LIBCPP_PREFERRED_OVERLOAD
97#endif
98 bool
99 isinf(double __x) _NOEXCEPT {
89100 return __builtin_isinf(__x);
90101}
91102
92_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(long double __x) _NOEXCEPT {
103[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(long double __x) _NOEXCEPT {
93104 return __builtin_isinf(__x);
94105}
95#endif
96106
97107// isnan
98108
99template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
100_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(_A1 __x) _NOEXCEPT {
101 return __builtin_isnan(__x);
102}
103
104109template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
105_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(_A1) _NOEXCEPT {
110[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(_A1) _NOEXCEPT {
106111 return false;
107112}
108113
109#ifdef _LIBCPP_PREFERRED_OVERLOAD
110_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(float __x) _NOEXCEPT {
114[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(float __x) _NOEXCEPT {
111115 return __builtin_isnan(__x);
112116}
113117
114_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool
115isnan(double __x) _NOEXCEPT {
118[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
119#ifdef _LIBCPP_PREFERRED_OVERLOAD
120_LIBCPP_PREFERRED_OVERLOAD
121#endif
122 bool
123 isnan(double __x) _NOEXCEPT {
116124 return __builtin_isnan(__x);
117125}
118126
119_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(long double __x) _NOEXCEPT {
127[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(long double __x) _NOEXCEPT {
120128 return __builtin_isnan(__x);
121129}
122#endif
123130
124131// isnormal
125132
126template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
127_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT {
133template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
134[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT {
135 return __x != 0;
136}
137
138[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(float __x) _NOEXCEPT {
128139 return __builtin_isnormal(__x);
129140}
130141
131template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
132_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT {
133 return __x != 0;
142[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(double __x) _NOEXCEPT {
143 return __builtin_isnormal(__x);
144}
145
146[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(long double __x) _NOEXCEPT {
147 return __builtin_isnormal(__x);
134148}
135149
136150// isgreater
137151
138152template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
139_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) _NOEXCEPT {
153[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) _NOEXCEPT {
140154 using type = typename __promote<_A1, _A2>::type;
141155 return __builtin_isgreater((type)__x, (type)__y);
142156}
......@@ -144,7 +158,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y)
144158// isgreaterequal
145159
146160template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
147_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT {
161[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT {
148162 using type = typename __promote<_A1, _A2>::type;
149163 return __builtin_isgreaterequal((type)__x, (type)__y);
150164}
......@@ -152,7 +166,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2
152166// isless
153167
154168template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
155_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NOEXCEPT {
169[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NOEXCEPT {
156170 using type = typename __promote<_A1, _A2>::type;
157171 return __builtin_isless((type)__x, (type)__y);
158172}
......@@ -160,7 +174,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NO
160174// islessequal
161175
162176template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
163_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y) _NOEXCEPT {
177[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y) _NOEXCEPT {
164178 using type = typename __promote<_A1, _A2>::type;
165179 return __builtin_islessequal((type)__x, (type)__y);
166180}
......@@ -168,7 +182,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y
168182// islessgreater
169183
170184template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
171_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 __y) _NOEXCEPT {
185[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 __y) _NOEXCEPT {
172186 using type = typename __promote<_A1, _A2>::type;
173187 return __builtin_islessgreater((type)__x, (type)__y);
174188}
......@@ -176,7 +190,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 _
176190// isunordered
177191
178192template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
179_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isunordered(_A1 __x, _A2 __y) _NOEXCEPT {
193[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isunordered(_A1 __x, _A2 __y) _NOEXCEPT {
180194 using type = typename __promote<_A1, _A2>::type;
181195 return __builtin_isunordered((type)__x, (type)__y);
182196}
lib/libcxx/include/__mbstate_t.h+2-2
......@@ -35,7 +35,7 @@
3535# define __CORRECT_ISO_CPP_WCHAR_H_PROTO
3636#endif
3737
38#if defined(_LIBCPP_HAS_MUSL_LIBC)
38#if _LIBCPP_HAS_MUSL_LIBC
3939# define __NEED_mbstate_t
4040# include <bits/alltypes.h>
4141# undef __NEED_mbstate_t
......@@ -43,7 +43,7 @@
4343# include <bits/types/mbstate_t.h> // works on most Unixes
4444#elif __has_include(<sys/_types/_mbstate_t.h>)
4545# include <sys/_types/_mbstate_t.h> // works on Darwin
46#elif !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) && __has_include_next(<wchar.h>)
46#elif _LIBCPP_HAS_WIDE_CHARACTERS && __has_include_next(<wchar.h>)
4747# include_next <wchar.h> // fall back to the C standard provider of mbstate_t
4848#elif __has_include_next(<uchar.h>)
4949# include_next <uchar.h> // <uchar.h> is also required to make mbstate_t visible
lib/libcxx/include/__mdspan/default_accessor.h+1-2
......@@ -18,12 +18,11 @@
1818#define _LIBCPP___MDSPAN_DEFAULT_ACCESSOR_H
1919
2020#include <__config>
21#include <__cstddef/size_t.h>
2122#include <__type_traits/is_abstract.h>
2223#include <__type_traits/is_array.h>
2324#include <__type_traits/is_convertible.h>
2425#include <__type_traits/remove_const.h>
25#include <cinttypes>
26#include <cstddef>
2726
2827#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2928# pragma GCC system_header
lib/libcxx/include/__mdspan/extents.h+10-9
......@@ -19,6 +19,9 @@
1919
2020#include <__assert>
2121#include <__config>
22
23#include <__concepts/arithmetic.h>
24#include <__cstddef/byte.h>
2225#include <__type_traits/common_type.h>
2326#include <__type_traits/is_convertible.h>
2427#include <__type_traits/is_nothrow_constructible.h>
......@@ -27,9 +30,7 @@
2730#include <__utility/integer_sequence.h>
2831#include <__utility/unreachable.h>
2932#include <array>
30#include <cinttypes>
3133#include <concepts>
32#include <cstddef>
3334#include <limits>
3435#include <span>
3536
......@@ -128,14 +129,14 @@ private:
128129 // Static values member
129130 static constexpr size_t __size_ = sizeof...(_Values);
130131 static constexpr size_t __size_dynamic_ = ((_Values == _DynTag) + ... + 0);
131 using _StaticValues = __static_array<_TStatic, _Values...>;
132 using _DynamicValues = __possibly_empty_array<_TDynamic, __size_dynamic_>;
132 using _StaticValues _LIBCPP_NODEBUG = __static_array<_TStatic, _Values...>;
133 using _DynamicValues _LIBCPP_NODEBUG = __possibly_empty_array<_TDynamic, __size_dynamic_>;
133134
134135 // Dynamic values member
135136 _LIBCPP_NO_UNIQUE_ADDRESS _DynamicValues __dyn_vals_;
136137
137138 // static mapping of indices to the position in the dynamic values array
138 using _DynamicIdxMap = __static_partial_sums<static_cast<size_t>(_Values == _DynTag)...>;
139 using _DynamicIdxMap _LIBCPP_NODEBUG = __static_partial_sums<static_cast<size_t>(_Values == _DynTag)...>;
139140
140141 template <size_t... _Indices>
141142 _LIBCPP_HIDE_FROM_ABI static constexpr _DynamicValues __zeros(index_sequence<_Indices...>) noexcept {
......@@ -282,8 +283,7 @@ public:
282283 using size_type = make_unsigned_t<index_type>;
283284 using rank_type = size_t;
284285
285 static_assert(is_integral<index_type>::value && !is_same<index_type, bool>::value,
286 "extents::index_type must be a signed or unsigned integer type");
286 static_assert(__libcpp_integer<index_type>, "extents::index_type must be a signed or unsigned integer type");
287287 static_assert(((__mdspan_detail::__is_representable_as<index_type>(_Extents) || (_Extents == dynamic_extent)) && ...),
288288 "extents ctor: arguments must be representable as index_type and nonnegative");
289289
......@@ -292,7 +292,8 @@ private:
292292 static constexpr rank_type __rank_dynamic_ = ((_Extents == dynamic_extent) + ... + 0);
293293
294294 // internal storage type using __maybe_static_array
295 using _Values = __mdspan_detail::__maybe_static_array<_IndexType, size_t, dynamic_extent, _Extents...>;
295 using _Values _LIBCPP_NODEBUG =
296 __mdspan_detail::__maybe_static_array<_IndexType, size_t, dynamic_extent, _Extents...>;
296297 [[no_unique_address]] _Values __vals_;
297298
298299public:
......@@ -448,7 +449,7 @@ struct __make_dextents< _IndexType, 0, extents<_IndexType, _ExtentsPack...>> {
448449 using type = extents<_IndexType, _ExtentsPack...>;
449450};
450451
451} // end namespace __mdspan_detail
452} // namespace __mdspan_detail
452453
453454// [mdspan.extents.dextents], alias template
454455template <class _IndexType, size_t _Rank>
lib/libcxx/include/__mdspan/layout_left.h+1-3
......@@ -21,14 +21,12 @@
2121#include <__config>
2222#include <__fwd/mdspan.h>
2323#include <__mdspan/extents.h>
24#include <__type_traits/common_type.h>
2425#include <__type_traits/is_constructible.h>
2526#include <__type_traits/is_convertible.h>
2627#include <__type_traits/is_nothrow_constructible.h>
2728#include <__utility/integer_sequence.h>
2829#include <array>
29#include <cinttypes>
30#include <cstddef>
31#include <limits>
3230
3331#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3432# pragma GCC system_header
lib/libcxx/include/__mdspan/layout_right.h+2-3
......@@ -19,15 +19,14 @@
1919
2020#include <__assert>
2121#include <__config>
22#include <__cstddef/size_t.h>
2223#include <__fwd/mdspan.h>
2324#include <__mdspan/extents.h>
25#include <__type_traits/common_type.h>
2426#include <__type_traits/is_constructible.h>
2527#include <__type_traits/is_convertible.h>
2628#include <__type_traits/is_nothrow_constructible.h>
2729#include <__utility/integer_sequence.h>
28#include <cinttypes>
29#include <cstddef>
30#include <limits>
3130
3231#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3332# pragma GCC system_header
lib/libcxx/include/__mdspan/layout_stride.h+5-2
......@@ -18,19 +18,22 @@
1818#define _LIBCPP___MDSPAN_LAYOUT_STRIDE_H
1919
2020#include <__assert>
21#include <__concepts/same_as.h>
2122#include <__config>
2223#include <__fwd/mdspan.h>
2324#include <__mdspan/extents.h>
25#include <__type_traits/common_type.h>
2426#include <__type_traits/is_constructible.h>
2527#include <__type_traits/is_convertible.h>
28#include <__type_traits/is_integral.h>
2629#include <__type_traits/is_nothrow_constructible.h>
30#include <__type_traits/is_same.h>
2731#include <__utility/as_const.h>
2832#include <__utility/integer_sequence.h>
2933#include <__utility/swap.h>
3034#include <array>
31#include <cinttypes>
32#include <cstddef>
3335#include <limits>
36#include <span>
3437
3538#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3639# pragma GCC system_header
lib/libcxx/include/__mdspan/mdspan.h-3
......@@ -37,9 +37,6 @@
3737#include <__type_traits/remove_reference.h>
3838#include <__utility/integer_sequence.h>
3939#include <array>
40#include <cinttypes>
41#include <cstddef>
42#include <limits>
4340#include <span>
4441
4542#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__memory/addressof.h+3-5
......@@ -23,17 +23,15 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_NO_CFI _LIBCPP_HIDE_FROM_ABI _Tp* a
2323 return __builtin_addressof(__x);
2424}
2525
26#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
26#if _LIBCPP_HAS_OBJC_ARC
2727// Objective-C++ Automatic Reference Counting uses qualified pointers
28// that require special addressof() signatures. When
29// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler
30// itself is providing these definitions. Otherwise, we provide them.
28// that require special addressof() signatures.
3129template <class _Tp>
3230inline _LIBCPP_HIDE_FROM_ABI __strong _Tp* addressof(__strong _Tp& __x) _NOEXCEPT {
3331 return &__x;
3432}
3533
36# ifdef _LIBCPP_HAS_OBJC_ARC_WEAK
34# if _LIBCPP_HAS_OBJC_ARC_WEAK
3735template <class _Tp>
3836inline _LIBCPP_HIDE_FROM_ABI __weak _Tp* addressof(__weak _Tp& __x) _NOEXCEPT {
3937 return &__x;
lib/libcxx/include/__memory/align.h+1-1
......@@ -10,7 +10,7 @@
1010#define _LIBCPP___MEMORY_ALIGN_H
1111
1212#include <__config>
13#include <cstddef>
13#include <__cstddef/size_t.h>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1616# pragma GCC system_header
lib/libcxx/include/__memory/aligned_alloc.h+3-4
......@@ -10,7 +10,6 @@
1010#define _LIBCPP___MEMORY_ALIGNED_ALLOC_H
1111
1212#include <__config>
13#include <cstddef>
1413#include <cstdlib>
1514
1615#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -19,7 +18,7 @@
1918
2019_LIBCPP_BEGIN_NAMESPACE_STD
2120
22#ifndef _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
21#if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
2322
2423// Low-level helpers to call the aligned allocation and deallocation functions
2524// on the target platform. This is used to implement libc++'s own memory
......@@ -30,7 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3029inline _LIBCPP_HIDE_FROM_ABI void* __libcpp_aligned_alloc(std::size_t __alignment, std::size_t __size) {
3130# if defined(_LIBCPP_MSVCRT_LIKE)
3231 return ::_aligned_malloc(__size, __alignment);
33# elif _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_C11_ALIGNED_ALLOC)
32# elif _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_C11_ALIGNED_ALLOC
3433 // aligned_alloc() requires that __size is a multiple of __alignment,
3534 // but for C++ [new.delete.general], only states "if the value of an
3635 // 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) {
5756# endif
5857}
5958
60#endif // !_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
59#endif // _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
6160
6261_LIBCPP_END_NAMESPACE_STD
6362
lib/libcxx/include/__memory/allocate_at_least.h+2-2
......@@ -10,8 +10,8 @@
1010#define _LIBCPP___MEMORY_ALLOCATE_AT_LEAST_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__memory/allocator_traits.h>
14#include <cstddef>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717# pragma GCC system_header
......@@ -35,7 +35,7 @@ struct __allocation_result {
3535};
3636
3737template <class _Alloc>
38_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI
38[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI
3939_LIBCPP_CONSTEXPR __allocation_result<typename allocator_traits<_Alloc>::pointer>
4040__allocate_at_least(_Alloc& __alloc, size_t __n) {
4141 return {__alloc.allocate(__n), __n};
lib/libcxx/include/__memory/allocation_guard.h+2-3
......@@ -14,7 +14,6 @@
1414#include <__memory/addressof.h>
1515#include <__memory/allocator_traits.h>
1616#include <__utility/move.h>
17#include <cstddef>
1817
1918#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2019# pragma GCC system_header
......@@ -46,8 +45,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4645// custom allocator.
4746template <class _Alloc>
4847struct __allocation_guard {
49 using _Pointer = typename allocator_traits<_Alloc>::pointer;
50 using _Size = typename allocator_traits<_Alloc>::size_type;
48 using _Pointer _LIBCPP_NODEBUG = typename allocator_traits<_Alloc>::pointer;
49 using _Size _LIBCPP_NODEBUG = typename allocator_traits<_Alloc>::size_type;
5150
5251 template <class _AllocT> // we perform the allocator conversion inside the constructor
5352 _LIBCPP_HIDE_FROM_ABI explicit __allocation_guard(_AllocT __alloc, _Size __n)
lib/libcxx/include/__memory/allocator.h+11-102
......@@ -11,17 +11,19 @@
1111#define _LIBCPP___MEMORY_ALLOCATOR_H
1212
1313#include <__config>
14#include <__cstddef/ptrdiff_t.h>
15#include <__cstddef/size_t.h>
1416#include <__memory/addressof.h>
1517#include <__memory/allocate_at_least.h>
1618#include <__memory/allocator_traits.h>
19#include <__new/allocate.h>
20#include <__new/exceptions.h>
1721#include <__type_traits/is_const.h>
1822#include <__type_traits/is_constant_evaluated.h>
1923#include <__type_traits/is_same.h>
2024#include <__type_traits/is_void.h>
2125#include <__type_traits/is_volatile.h>
2226#include <__utility/forward.h>
23#include <cstddef>
24#include <new>
2527
2628#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2729# pragma GCC system_header
......@@ -47,23 +49,7 @@ public:
4749 typedef allocator<_Up> other;
4850 };
4951};
50
51// TODO(LLVM 20): Remove the escape hatch
52# ifdef _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST
53template <>
54class _LIBCPP_TEMPLATE_VIS allocator<const void> {
55public:
56 _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* pointer;
57 _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* const_pointer;
58 _LIBCPP_DEPRECATED_IN_CXX17 typedef const void value_type;
59
60 template <class _Up>
61 struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {
62 typedef allocator<_Up> other;
63 };
64};
65# endif // _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST
66#endif // _LIBCPP_STD_VER <= 17
52#endif // _LIBCPP_STD_VER <= 17
6753
6854// This class provides a non-trivial default constructor to the class that derives from it
6955// if the condition is satisfied.
......@@ -109,18 +95,20 @@ public:
10995 template <class _Up>
11096 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator(const allocator<_Up>&) _NOEXCEPT {}
11197
112 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* allocate(size_t __n) {
98 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* allocate(size_t __n) {
99 static_assert(sizeof(_Tp) >= 0, "cannot allocate memory for an incomplete type");
113100 if (__n > allocator_traits<allocator>::max_size(*this))
114101 __throw_bad_array_new_length();
115102 if (__libcpp_is_constant_evaluated()) {
116103 return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
117104 } else {
118 return static_cast<_Tp*>(std::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
105 return std::__libcpp_allocate<_Tp>(__element_count(__n));
119106 }
120107 }
121108
122109#if _LIBCPP_STD_VER >= 23
123110 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr allocation_result<_Tp*> allocate_at_least(size_t __n) {
111 static_assert(sizeof(_Tp) >= 0, "cannot allocate memory for an incomplete type");
124112 return {allocate(__n), __n};
125113 }
126114#endif
......@@ -129,7 +117,7 @@ public:
129117 if (__libcpp_is_constant_evaluated()) {
130118 ::operator delete(__p);
131119 } else {
132 std::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
120 std::__libcpp_deallocate<_Tp>(__p, __element_count(__n));
133121 }
134122 }
135123
......@@ -152,7 +140,7 @@ public:
152140 return std::addressof(__x);
153141 }
154142
155 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 _Tp* allocate(size_t __n, const void*) {
143 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 _Tp* allocate(size_t __n, const void*) {
156144 return allocate(__n);
157145 }
158146
......@@ -169,85 +157,6 @@ public:
169157#endif
170158};
171159
172// TODO(LLVM 20): Remove the escape hatch
173#ifdef _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST
174template <class _Tp>
175class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
176 : private __non_trivial_if<!is_void<_Tp>::value, allocator<const _Tp> > {
177 static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types");
178
179public:
180 typedef size_t size_type;
181 typedef ptrdiff_t difference_type;
182 typedef const _Tp value_type;
183 typedef true_type propagate_on_container_move_assignment;
184# if _LIBCPP_STD_VER <= 23 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_ALLOCATOR_MEMBERS)
185 _LIBCPP_DEPRECATED_IN_CXX23 typedef true_type is_always_equal;
186# endif
187
188 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator() _NOEXCEPT = default;
189
190 template <class _Up>
191 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator(const allocator<_Up>&) _NOEXCEPT {}
192
193 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const _Tp* allocate(size_t __n) {
194 if (__n > allocator_traits<allocator>::max_size(*this))
195 __throw_bad_array_new_length();
196 if (__libcpp_is_constant_evaluated()) {
197 return static_cast<const _Tp*>(::operator new(__n * sizeof(_Tp)));
198 } else {
199 return static_cast<const _Tp*>(std::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
200 }
201 }
202
203# if _LIBCPP_STD_VER >= 23
204 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr allocation_result<const _Tp*> allocate_at_least(size_t __n) {
205 return {allocate(__n), __n};
206 }
207# endif
208
209 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void deallocate(const _Tp* __p, size_t __n) {
210 if (__libcpp_is_constant_evaluated()) {
211 ::operator delete(const_cast<_Tp*>(__p));
212 } else {
213 std::__libcpp_deallocate((void*)const_cast<_Tp*>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
214 }
215 }
216
217 // C++20 Removed members
218# if _LIBCPP_STD_VER <= 17
219 _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* pointer;
220 _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer;
221 _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& reference;
222 _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& const_reference;
223
224 template <class _Up>
225 struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {
226 typedef allocator<_Up> other;
227 };
228
229 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI const_pointer address(const_reference __x) const _NOEXCEPT {
230 return std::addressof(__x);
231 }
232
233 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 const _Tp* allocate(size_t __n, const void*) {
234 return allocate(__n);
235 }
236
237 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
238 return size_type(~0) / sizeof(_Tp);
239 }
240
241 template <class _Up, class... _Args>
242 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI void construct(_Up* __p, _Args&&... __args) {
243 ::new ((void*)__p) _Up(std::forward<_Args>(__args)...);
244 }
245
246 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI void destroy(pointer __p) { __p->~_Tp(); }
247# endif
248};
249#endif // _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST
250
251160template <class _Tp, class _Up>
252161inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
253162operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {
lib/libcxx/include/__memory/allocator_arg_t.h+7-7
......@@ -7,8 +7,8 @@
77//
88//===----------------------------------------------------------------------===//
99
10#ifndef _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H
11#define _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H
10#ifndef _LIBCPP___MEMORY_ALLOCATOR_ARG_T_H
11#define _LIBCPP___MEMORY_ALLOCATOR_ARG_T_H
1212
1313#include <__config>
1414#include <__memory/uses_allocator.h>
......@@ -39,10 +39,10 @@ constexpr allocator_arg_t allocator_arg = allocator_arg_t();
3939
4040template <class _Tp, class _Alloc, class... _Args>
4141struct __uses_alloc_ctor_imp {
42 typedef _LIBCPP_NODEBUG __remove_cvref_t<_Alloc> _RawAlloc;
43 static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value;
44 static const bool __ic = is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
45 static const int value = __ua ? 2 - __ic : 0;
42 using _RawAlloc _LIBCPP_NODEBUG = __remove_cvref_t<_Alloc>;
43 static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value;
44 static const bool __ic = is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
45 static const int value = __ua ? 2 - __ic : 0;
4646};
4747
4848template <class _Tp, class _Alloc, class... _Args>
......@@ -72,4 +72,4 @@ __user_alloc_construct_impl(integral_constant<int, 2>, _Tp* __storage, const _Al
7272
7373_LIBCPP_END_NAMESPACE_STD
7474
75#endif // _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H
75#endif // _LIBCPP___MEMORY_ALLOCATOR_ARG_T_H
lib/libcxx/include/__memory/allocator_destructor.h+3-3
......@@ -20,11 +20,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Alloc>
2222class __allocator_destructor {
23 typedef _LIBCPP_NODEBUG allocator_traits<_Alloc> __alloc_traits;
23 using __alloc_traits _LIBCPP_NODEBUG = allocator_traits<_Alloc>;
2424
2525public:
26 typedef _LIBCPP_NODEBUG typename __alloc_traits::pointer pointer;
27 typedef _LIBCPP_NODEBUG typename __alloc_traits::size_type size_type;
26 using pointer _LIBCPP_NODEBUG = typename __alloc_traits::pointer;
27 using size_type _LIBCPP_NODEBUG = typename __alloc_traits::size_type;
2828
2929private:
3030 _Alloc& __alloc_;
lib/libcxx/include/__memory/allocator_traits.h+53-63
......@@ -11,8 +11,11 @@
1111#define _LIBCPP___MEMORY_ALLOCATOR_TRAITS_H
1212
1313#include <__config>
14#include <__cstddef/size_t.h>
15#include <__fwd/memory.h>
1416#include <__memory/construct_at.h>
1517#include <__memory/pointer_traits.h>
18#include <__type_traits/detected_or.h>
1619#include <__type_traits/enable_if.h>
1720#include <__type_traits/is_constructible.h>
1821#include <__type_traits/is_empty.h>
......@@ -22,7 +25,6 @@
2225#include <__type_traits/void_t.h>
2326#include <__utility/declval.h>
2427#include <__utility/forward.h>
25#include <cstddef>
2628#include <limits>
2729
2830#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -41,17 +43,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4143 struct NAME<_Tp, __void_t<typename _Tp::PROPERTY > > : true_type {}
4244
4345// __pointer
44template <class _Tp,
45 class _Alloc,
46 class _RawAlloc = __libcpp_remove_reference_t<_Alloc>,
47 bool = __has_pointer<_RawAlloc>::value>
48struct __pointer {
49 using type _LIBCPP_NODEBUG = typename _RawAlloc::pointer;
50};
51template <class _Tp, class _Alloc, class _RawAlloc>
52struct __pointer<_Tp, _Alloc, _RawAlloc, false> {
53 using type _LIBCPP_NODEBUG = _Tp*;
54};
46template <class _Tp>
47using __pointer_member _LIBCPP_NODEBUG = typename _Tp::pointer;
48
49template <class _Tp, class _Alloc>
50using __pointer _LIBCPP_NODEBUG = __detected_or_t<_Tp*, __pointer_member, __libcpp_remove_reference_t<_Alloc> >;
5551
5652// __const_pointer
5753_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_const_pointer, const_pointer);
......@@ -62,7 +58,7 @@ struct __const_pointer {
6258template <class _Tp, class _Ptr, class _Alloc>
6359struct __const_pointer<_Tp, _Ptr, _Alloc, false> {
6460#ifdef _LIBCPP_CXX03_LANG
65 using type = typename pointer_traits<_Ptr>::template rebind<const _Tp>::other;
61 using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const _Tp>::other;
6662#else
6763 using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const _Tp>;
6864#endif
......@@ -99,13 +95,11 @@ struct __const_void_pointer<_Ptr, _Alloc, false> {
9995};
10096
10197// __size_type
102_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_size_type, size_type);
103template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
104struct __size_type : make_unsigned<_DiffType> {};
98template <class _Tp>
99using __size_type_member _LIBCPP_NODEBUG = typename _Tp::size_type;
100
105101template <class _Alloc, class _DiffType>
106struct __size_type<_Alloc, _DiffType, true> {
107 using type _LIBCPP_NODEBUG = typename _Alloc::size_type;
108};
102using __size_type _LIBCPP_NODEBUG = __detected_or_t<__make_unsigned_t<_DiffType>, __size_type_member, _Alloc>;
109103
110104// __alloc_traits_difference_type
111105_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_alloc_traits_difference_type, difference_type);
......@@ -119,40 +113,38 @@ struct __alloc_traits_difference_type<_Alloc, _Ptr, true> {
119113};
120114
121115// __propagate_on_container_copy_assignment
122_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_propagate_on_container_copy_assignment, propagate_on_container_copy_assignment);
123template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
124struct __propagate_on_container_copy_assignment : false_type {};
116template <class _Tp>
117using __propagate_on_container_copy_assignment_member _LIBCPP_NODEBUG =
118 typename _Tp::propagate_on_container_copy_assignment;
119
125120template <class _Alloc>
126struct __propagate_on_container_copy_assignment<_Alloc, true> {
127 using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_copy_assignment;
128};
121using __propagate_on_container_copy_assignment _LIBCPP_NODEBUG =
122 __detected_or_t<false_type, __propagate_on_container_copy_assignment_member, _Alloc>;
129123
130124// __propagate_on_container_move_assignment
131_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_propagate_on_container_move_assignment, propagate_on_container_move_assignment);
132template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
133struct __propagate_on_container_move_assignment : false_type {};
125template <class _Tp>
126using __propagate_on_container_move_assignment_member _LIBCPP_NODEBUG =
127 typename _Tp::propagate_on_container_move_assignment;
128
134129template <class _Alloc>
135struct __propagate_on_container_move_assignment<_Alloc, true> {
136 using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_move_assignment;
137};
130using __propagate_on_container_move_assignment _LIBCPP_NODEBUG =
131 __detected_or_t<false_type, __propagate_on_container_move_assignment_member, _Alloc>;
138132
139133// __propagate_on_container_swap
140_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_propagate_on_container_swap, propagate_on_container_swap);
141template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
142struct __propagate_on_container_swap : false_type {};
134template <class _Tp>
135using __propagate_on_container_swap_member _LIBCPP_NODEBUG = typename _Tp::propagate_on_container_swap;
136
143137template <class _Alloc>
144struct __propagate_on_container_swap<_Alloc, true> {
145 using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_swap;
146};
138using __propagate_on_container_swap _LIBCPP_NODEBUG =
139 __detected_or_t<false_type, __propagate_on_container_swap_member, _Alloc>;
147140
148141// __is_always_equal
149_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_is_always_equal, is_always_equal);
150template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
151struct __is_always_equal : is_empty<_Alloc> {};
142template <class _Tp>
143using __is_always_equal_member _LIBCPP_NODEBUG = typename _Tp::is_always_equal;
144
152145template <class _Alloc>
153struct __is_always_equal<_Alloc, true> {
154 using type _LIBCPP_NODEBUG = typename _Alloc::is_always_equal;
155};
146using __is_always_equal _LIBCPP_NODEBUG =
147 __detected_or_t<typename is_empty<_Alloc>::type, __is_always_equal_member, _Alloc>;
156148
157149// __allocator_traits_rebind
158150_LIBCPP_SUPPRESS_DEPRECATED_PUSH
......@@ -177,7 +169,7 @@ struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false> {
177169_LIBCPP_SUPPRESS_DEPRECATED_POP
178170
179171template <class _Alloc, class _Tp>
180using __allocator_traits_rebind_t = typename __allocator_traits_rebind<_Alloc, _Tp>::type;
172using __allocator_traits_rebind_t _LIBCPP_NODEBUG = typename __allocator_traits_rebind<_Alloc, _Tp>::type;
181173
182174_LIBCPP_SUPPRESS_DEPRECATED_PUSH
183175
......@@ -244,20 +236,18 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(allocation_result);
244236
245237template <class _Alloc>
246238struct _LIBCPP_TEMPLATE_VIS allocator_traits {
247 using allocator_type = _Alloc;
248 using value_type = typename allocator_type::value_type;
249 using pointer = typename __pointer<value_type, allocator_type>::type;
250 using const_pointer = typename __const_pointer<value_type, pointer, allocator_type>::type;
251 using void_pointer = typename __void_pointer<pointer, allocator_type>::type;
252 using const_void_pointer = typename __const_void_pointer<pointer, allocator_type>::type;
253 using difference_type = typename __alloc_traits_difference_type<allocator_type, pointer>::type;
254 using size_type = typename __size_type<allocator_type, difference_type>::type;
255 using propagate_on_container_copy_assignment =
256 typename __propagate_on_container_copy_assignment<allocator_type>::type;
257 using propagate_on_container_move_assignment =
258 typename __propagate_on_container_move_assignment<allocator_type>::type;
259 using propagate_on_container_swap = typename __propagate_on_container_swap<allocator_type>::type;
260 using is_always_equal = typename __is_always_equal<allocator_type>::type;
239 using allocator_type = _Alloc;
240 using value_type = typename allocator_type::value_type;
241 using pointer = __pointer<value_type, allocator_type>;
242 using const_pointer = typename __const_pointer<value_type, pointer, allocator_type>::type;
243 using void_pointer = typename __void_pointer<pointer, allocator_type>::type;
244 using const_void_pointer = typename __const_void_pointer<pointer, allocator_type>::type;
245 using difference_type = typename __alloc_traits_difference_type<allocator_type, pointer>::type;
246 using size_type = __size_type<allocator_type, difference_type>;
247 using propagate_on_container_copy_assignment = __propagate_on_container_copy_assignment<allocator_type>;
248 using propagate_on_container_move_assignment = __propagate_on_container_move_assignment<allocator_type>;
249 using propagate_on_container_swap = __propagate_on_container_swap<allocator_type>;
250 using is_always_equal = __is_always_equal<allocator_type>;
261251
262252#ifndef _LIBCPP_CXX03_LANG
263253 template <class _Tp>
......@@ -275,13 +265,13 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits {
275265 };
276266#endif // _LIBCPP_CXX03_LANG
277267
278 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer
268 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer
279269 allocate(allocator_type& __a, size_type __n) {
280270 return __a.allocate(__n);
281271 }
282272
283273 template <class _Ap = _Alloc, __enable_if_t<__has_allocate_hint<_Ap, size_type, const_void_pointer>::value, int> = 0>
284 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer
274 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer
285275 allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) {
286276 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
287277 return __a.allocate(__n, __hint);
......@@ -290,7 +280,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits {
290280 template <class _Ap = _Alloc,
291281 class = void,
292282 __enable_if_t<!__has_allocate_hint<_Ap, size_type, const_void_pointer>::value, int> = 0>
293 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer
283 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer
294284 allocate(allocator_type& __a, size_type __n, const_void_pointer) {
295285 return __a.allocate(__n);
296286 }
......@@ -369,12 +359,12 @@ template <class _Traits, class _Tp>
369359using __rebind_alloc _LIBCPP_NODEBUG = typename _Traits::template rebind_alloc<_Tp>;
370360#else
371361template <class _Traits, class _Tp>
372using __rebind_alloc = typename _Traits::template rebind_alloc<_Tp>::other;
362using __rebind_alloc _LIBCPP_NODEBUG = typename _Traits::template rebind_alloc<_Tp>::other;
373363#endif
374364
375365template <class _Alloc>
376366struct __check_valid_allocator : true_type {
377 using _Traits = std::allocator_traits<_Alloc>;
367 using _Traits _LIBCPP_NODEBUG = std::allocator_traits<_Alloc>;
378368 static_assert(is_same<_Alloc, __rebind_alloc<_Traits, typename _Traits::value_type> >::value,
379369 "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
380370 "original allocator");
lib/libcxx/include/__memory/array_cookie.h created+55
......@@ -0,0 +1,55 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___MEMORY_ARRAY_COOKIE_H
11#define _LIBCPP___MEMORY_ARRAY_COOKIE_H
12
13#include <__config>
14#include <__configuration/abi.h>
15#include <__cstddef/size_t.h>
16#include <__type_traits/integral_constant.h>
17#include <__type_traits/is_trivially_destructible.h>
18#include <__type_traits/negation.h>
19
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21# pragma GCC system_header
22#endif
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26// Trait representing whether a type requires an array cookie at the start of its allocation when
27// allocated as `new T[n]` and deallocated as `delete[] array`.
28//
29// Under the Itanium C++ ABI [1], we know that an array cookie is available unless `T` is trivially
30// destructible and the call to `operator delete[]` is not a sized operator delete. Under ABIs other
31// than the Itanium ABI, we assume there are no array cookies.
32//
33// [1]: https://itanium-cxx-abi.github.io/cxx-abi/abi.html#array-cookies
34#ifdef _LIBCPP_ABI_ITANIUM
35// TODO: Use a builtin instead
36// TODO: We should factor in the choice of the usual deallocation function in this determination.
37template <class _Tp>
38struct __has_array_cookie : _Not<is_trivially_destructible<_Tp> > {};
39#else
40template <class _Tp>
41struct __has_array_cookie : false_type {};
42#endif
43
44template <class _Tp>
45// Avoid failures when -fsanitize-address-poison-custom-array-cookie is enabled
46_LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_SANITIZE("address") size_t __get_array_cookie(_Tp const* __ptr) {
47 static_assert(
48 __has_array_cookie<_Tp>::value, "Trying to access the array cookie of a type that is not guaranteed to have one");
49 size_t const* __cookie = reinterpret_cast<size_t const*>(__ptr) - 1; // TODO: Use a builtin instead
50 return *__cookie;
51}
52
53_LIBCPP_END_NAMESPACE_STD
54
55#endif // _LIBCPP___MEMORY_ARRAY_COOKIE_H
lib/libcxx/include/__memory/assume_aligned.h+2-2
......@@ -12,8 +12,8 @@
1212
1313#include <__assert>
1414#include <__config>
15#include <__cstddef/size_t.h>
1516#include <__type_traits/is_constant_evaluated.h>
16#include <cstddef>
1717#include <cstdint>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -23,7 +23,7 @@
2323_LIBCPP_BEGIN_NAMESPACE_STD
2424
2525template <size_t _Np, class _Tp>
26_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __assume_aligned(_Tp* __ptr) {
26[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __assume_aligned(_Tp* __ptr) {
2727 static_assert(_Np != 0 && (_Np & (_Np - 1)) == 0, "std::assume_aligned<N>(p) requires N to be a power of two");
2828
2929 if (__libcpp_is_constant_evaluated()) {
lib/libcxx/include/__memory/builtin_new_allocator.h deleted-67
......@@ -1,67 +0,0 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___MEMORY_BUILTIN_NEW_ALLOCATOR_H
10#define _LIBCPP___MEMORY_BUILTIN_NEW_ALLOCATOR_H
11
12#include <__config>
13#include <__memory/unique_ptr.h>
14#include <cstddef>
15#include <new>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23// __builtin_new_allocator -- A non-templated helper for allocating and
24// deallocating memory using __builtin_operator_new and
25// __builtin_operator_delete. It should be used in preference to
26// `std::allocator<T>` to avoid additional instantiations.
27struct __builtin_new_allocator {
28 struct __builtin_new_deleter {
29 typedef void* pointer_type;
30
31 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __builtin_new_deleter(size_t __size, size_t __align)
32 : __size_(__size), __align_(__align) {}
33
34 _LIBCPP_HIDE_FROM_ABI void operator()(void* __p) const _NOEXCEPT {
35 std::__libcpp_deallocate(__p, __size_, __align_);
36 }
37
38 private:
39 size_t __size_;
40 size_t __align_;
41 };
42
43 typedef unique_ptr<void, __builtin_new_deleter> __holder_t;
44
45 _LIBCPP_HIDE_FROM_ABI static __holder_t __allocate_bytes(size_t __s, size_t __align) {
46 return __holder_t(std::__libcpp_allocate(__s, __align), __builtin_new_deleter(__s, __align));
47 }
48
49 _LIBCPP_HIDE_FROM_ABI static void __deallocate_bytes(void* __p, size_t __s, size_t __align) _NOEXCEPT {
50 std::__libcpp_deallocate(__p, __s, __align);
51 }
52
53 template <class _Tp>
54 _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI static __holder_t __allocate_type(size_t __n) {
55 return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
56 }
57
58 template <class _Tp>
59 _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI static void
60 __deallocate_type(void* __p, size_t __n) _NOEXCEPT {
61 __deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
62 }
63};
64
65_LIBCPP_END_NAMESPACE_STD
66
67#endif // _LIBCPP___MEMORY_BUILTIN_NEW_ALLOCATOR_H
lib/libcxx/include/__memory/compressed_pair.h+72-138
......@@ -11,161 +11,95 @@
1111#define _LIBCPP___MEMORY_COMPRESSED_PAIR_H
1212
1313#include <__config>
14#include <__fwd/tuple.h>
15#include <__tuple/tuple_indices.h>
16#include <__type_traits/decay.h>
17#include <__type_traits/dependent_type.h>
18#include <__type_traits/enable_if.h>
19#include <__type_traits/is_constructible.h>
14#include <__cstddef/size_t.h>
15#include <__type_traits/datasizeof.h>
2016#include <__type_traits/is_empty.h>
2117#include <__type_traits/is_final.h>
22#include <__type_traits/is_same.h>
23#include <__type_traits/is_swappable.h>
24#include <__utility/forward.h>
25#include <__utility/move.h>
26#include <__utility/piecewise_construct.h>
27#include <cstddef>
18#include <__type_traits/is_reference.h>
2819
2920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3021# pragma GCC system_header
3122#endif
3223
33_LIBCPP_PUSH_MACROS
34#include <__undef_macros>
35
3624_LIBCPP_BEGIN_NAMESPACE_STD
3725
38// Tag used to default initialize one or both of the pair's elements.
39struct __default_init_tag {};
40struct __value_init_tag {};
41
42template <class _Tp, int _Idx, bool _CanBeEmptyBase = is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value>
43struct __compressed_pair_elem {
44 using _ParamT = _Tp;
45 using reference = _Tp&;
46 using const_reference = const _Tp&;
47
48 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {}
49 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_() {}
50
51 template <class _Up, __enable_if_t<!is_same<__compressed_pair_elem, __decay_t<_Up> >::value, int> = 0>
52 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(_Up&& __u)
53 : __value_(std::forward<_Up>(__u)) {}
26// ================================================================================================================== //
27// The utilites here are for staying ABI compatible with the legacy `__compressed_pair`. They should not be used //
28// for new data structures. Use `_LIBCPP_NO_UNIQUE_ADDRESS` for new data structures instead (but make sure you //
29// understand how it works). //
30// ================================================================================================================== //
5431
55#ifndef _LIBCPP_CXX03_LANG
56 template <class... _Args, size_t... _Indices>
57 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 explicit __compressed_pair_elem(
58 piecewise_construct_t, tuple<_Args...> __args, __tuple_indices<_Indices...>)
59 : __value_(std::forward<_Args>(std::get<_Indices>(__args))...) {}
60#endif
61
62 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference __get() _NOEXCEPT { return __value_; }
63 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return __value_; }
64
65private:
66 _Tp __value_;
67};
32// The first member is aligned to the alignment of the second member to force padding in front of the compressed pair
33// in case there are members before it.
34//
35// For example:
36// (assuming x86-64 linux)
37// class SomeClass {
38// uint32_t member1;
39// _LIBCPP_COMPRESSED_PAIR(uint32_t, member2, uint64_t, member3);
40// }
41//
42// The layout with __compressed_pair is:
43// member1 - offset: 0, size: 4
44// padding - offset: 4, size: 4
45// member2 - offset: 8, size: 4
46// padding - offset: 12, size: 4
47// member3 - offset: 16, size: 8
48//
49// If the [[gnu::aligned]] wasn't there, the layout would instead be:
50// member1 - offset: 0, size: 4
51// member2 - offset: 4, size: 4
52// member3 - offset: 8, size: 8
53//
54// Furthermore, that alignment must be the same as what was used in the old __compressed_pair layout, so we must
55// handle reference types specially since alignof(T&) == alignof(T).
56// See https://github.com/llvm/llvm-project/issues/118559.
6857
69template <class _Tp, int _Idx>
70struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
71 using _ParamT = _Tp;
72 using reference = _Tp&;
73 using const_reference = const _Tp&;
74 using __value_type = _Tp;
75
76 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem() = default;
77 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {}
78 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_type() {}
79
80 template <class _Up, __enable_if_t<!is_same<__compressed_pair_elem, __decay_t<_Up> >::value, int> = 0>
81 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(_Up&& __u)
82 : __value_type(std::forward<_Up>(__u)) {}
83
84#ifndef _LIBCPP_CXX03_LANG
85 template <class... _Args, size_t... _Indices>
86 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17
87 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, __tuple_indices<_Indices...>)
88 : __value_type(std::forward<_Args>(std::get<_Indices>(__args))...) {}
89#endif
58#ifndef _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING
9059
91 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference __get() _NOEXCEPT { return *this; }
92 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return *this; }
93};
60template <class _Tp>
61inline const size_t __compressed_pair_alignment = _LIBCPP_ALIGNOF(_Tp);
9462
95template <class _T1, class _T2>
96class __compressed_pair : private __compressed_pair_elem<_T1, 0>, private __compressed_pair_elem<_T2, 1> {
97public:
98 // NOTE: This static assert should never fire because __compressed_pair
99 // is *almost never* used in a scenario where it's possible for T1 == T2.
100 // (The exception is std::function where it is possible that the function
101 // object and the allocator have the same type).
102 static_assert(
103 (!is_same<_T1, _T2>::value),
104 "__compressed_pair cannot be instantiated when T1 and T2 are the same type; "
105 "The current implementation is NOT ABI-compatible with the previous implementation for this configuration");
106
107 using _Base1 _LIBCPP_NODEBUG = __compressed_pair_elem<_T1, 0>;
108 using _Base2 _LIBCPP_NODEBUG = __compressed_pair_elem<_T2, 1>;
109
110 template <bool _Dummy = true,
111 __enable_if_t< __dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
112 __dependent_type<is_default_constructible<_T2>, _Dummy>::value,
113 int> = 0>
114 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair()
115 : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {}
116
117 template <class _U1, class _U2>
118 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair(_U1&& __t1, _U2&& __t2)
119 : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
120
121#ifndef _LIBCPP_CXX03_LANG
122 template <class... _Args1, class... _Args2>
123 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 explicit __compressed_pair(
124 piecewise_construct_t __pc, tuple<_Args1...> __first_args, tuple<_Args2...> __second_args)
125 : _Base1(__pc, std::move(__first_args), typename __make_tuple_indices<sizeof...(_Args1)>::type()),
126 _Base2(__pc, std::move(__second_args), typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
127#endif
63template <class _Tp>
64inline const size_t __compressed_pair_alignment<_Tp&> = _LIBCPP_ALIGNOF(void*);
12865
129 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename _Base1::reference first() _NOEXCEPT {
130 return static_cast<_Base1&>(*this).__get();
131 }
132
133 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename _Base1::const_reference first() const _NOEXCEPT {
134 return static_cast<_Base1 const&>(*this).__get();
135 }
136
137 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename _Base2::reference second() _NOEXCEPT {
138 return static_cast<_Base2&>(*this).__get();
139 }
140
141 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename _Base2::const_reference second() const _NOEXCEPT {
142 return static_cast<_Base2 const&>(*this).__get();
143 }
144
145 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static _Base1* __get_first_base(__compressed_pair* __pair) _NOEXCEPT {
146 return static_cast<_Base1*>(__pair);
147 }
148 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static _Base2* __get_second_base(__compressed_pair* __pair) _NOEXCEPT {
149 return static_cast<_Base2*>(__pair);
150 }
151
152 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void swap(__compressed_pair& __x)
153 _NOEXCEPT_(__is_nothrow_swappable_v<_T1>&& __is_nothrow_swappable_v<_T2>) {
154 using std::swap;
155 swap(first(), __x.first());
156 swap(second(), __x.second());
157 }
66template <class _ToPad,
67 bool _Empty = ((is_empty<_ToPad>::value && !__libcpp_is_final<_ToPad>::value) ||
68 is_reference<_ToPad>::value || sizeof(_ToPad) == __datasizeof_v<_ToPad>)>
69class __compressed_pair_padding {
70 char __padding_[sizeof(_ToPad) - __datasizeof_v<_ToPad>] = {};
15871};
15972
160template <class _T1, class _T2>
161inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
162swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
163 _NOEXCEPT_(__is_nothrow_swappable_v<_T1>&& __is_nothrow_swappable_v<_T2>) {
164 __x.swap(__y);
165}
73template <class _ToPad>
74class __compressed_pair_padding<_ToPad, true> {};
75
76# define _LIBCPP_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2) \
77 _LIBCPP_NO_UNIQUE_ADDRESS __attribute__((__aligned__(::std::__compressed_pair_alignment<T2>))) T1 Initializer1; \
78 _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T1> _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \
79 _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \
80 _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T2> _LIBCPP_CONCAT3(__padding2_, __LINE__, _)
81
82# define _LIBCPP_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3, Initializer3) \
83 _LIBCPP_NO_UNIQUE_ADDRESS \
84 __attribute__((__aligned__(::std::__compressed_pair_alignment<T2>), \
85 __aligned__(::std::__compressed_pair_alignment<T3>))) T1 Initializer1; \
86 _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T1> _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \
87 _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \
88 _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T2> _LIBCPP_CONCAT3(__padding2_, __LINE__, _); \
89 _LIBCPP_NO_UNIQUE_ADDRESS T3 Initializer3; \
90 _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T3> _LIBCPP_CONCAT3(__padding3_, __LINE__, _)
91
92#else
93# define _LIBCPP_COMPRESSED_PAIR(T1, Name1, T2, Name2) \
94 _LIBCPP_NO_UNIQUE_ADDRESS T1 Name1; \
95 _LIBCPP_NO_UNIQUE_ADDRESS T2 Name2
96
97# define _LIBCPP_COMPRESSED_TRIPLE(T1, Name1, T2, Name2, T3, Name3) \
98 _LIBCPP_NO_UNIQUE_ADDRESS T1 Name1; \
99 _LIBCPP_NO_UNIQUE_ADDRESS T2 Name2; \
100 _LIBCPP_NO_UNIQUE_ADDRESS T3 Name3
101#endif // _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING
166102
167103_LIBCPP_END_NAMESPACE_STD
168104
169_LIBCPP_POP_MACROS
170
171105#endif // _LIBCPP___MEMORY_COMPRESSED_PAIR_H
lib/libcxx/include/__memory/construct_at.h+3-4
......@@ -14,13 +14,12 @@
1414#include <__config>
1515#include <__iterator/access.h>
1616#include <__memory/addressof.h>
17#include <__memory/voidify.h>
17#include <__new/placement_new_delete.h>
1818#include <__type_traits/enable_if.h>
1919#include <__type_traits/is_array.h>
2020#include <__utility/declval.h>
2121#include <__utility/forward.h>
2222#include <__utility/move.h>
23#include <new>
2423
2524#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2625# pragma GCC system_header
......@@ -38,7 +37,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3837template <class _Tp, class... _Args, class = decltype(::new(std::declval<void*>()) _Tp(std::declval<_Args>()...))>
3938_LIBCPP_HIDE_FROM_ABI constexpr _Tp* construct_at(_Tp* __location, _Args&&... __args) {
4039 _LIBCPP_ASSERT_NON_NULL(__location != nullptr, "null pointer given to construct_at");
41 return ::new (std::__voidify(*__location)) _Tp(std::forward<_Args>(__args)...);
40 return ::new (static_cast<void*>(__location)) _Tp(std::forward<_Args>(__args)...);
4241}
4342
4443#endif
......@@ -49,7 +48,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* __construct_at(_Tp* __l
4948 return std::construct_at(__location, std::forward<_Args>(__args)...);
5049#else
5150 return _LIBCPP_ASSERT_NON_NULL(__location != nullptr, "null pointer given to construct_at"),
52 ::new (std::__voidify(*__location)) _Tp(std::forward<_Args>(__args)...);
51 ::new (static_cast<void*>(__location)) _Tp(std::forward<_Args>(__args)...);
5352#endif
5453}
5554
lib/libcxx/include/__memory/destruct_n.h+11-11
......@@ -10,9 +10,9 @@
1010#define _LIBCPP___MEMORY_DESTRUCT_N_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__type_traits/integral_constant.h>
1415#include <__type_traits/is_trivially_destructible.h>
15#include <cstddef>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818# pragma GCC system_header
......@@ -25,35 +25,35 @@ private:
2525 size_t __size_;
2626
2727 template <class _Tp>
28 _LIBCPP_HIDE_FROM_ABI void __process(_Tp* __p, false_type) _NOEXCEPT {
28 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __process(_Tp* __p, false_type) _NOEXCEPT {
2929 for (size_t __i = 0; __i < __size_; ++__i, ++__p)
3030 __p->~_Tp();
3131 }
3232
3333 template <class _Tp>
34 _LIBCPP_HIDE_FROM_ABI void __process(_Tp*, true_type) _NOEXCEPT {}
34 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __process(_Tp*, true_type) _NOEXCEPT {}
3535
36 _LIBCPP_HIDE_FROM_ABI void __incr(false_type) _NOEXCEPT { ++__size_; }
37 _LIBCPP_HIDE_FROM_ABI void __incr(true_type) _NOEXCEPT {}
36 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __incr(false_type) _NOEXCEPT { ++__size_; }
37 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __incr(true_type) _NOEXCEPT {}
3838
39 _LIBCPP_HIDE_FROM_ABI void __set(size_t __s, false_type) _NOEXCEPT { __size_ = __s; }
40 _LIBCPP_HIDE_FROM_ABI void __set(size_t, true_type) _NOEXCEPT {}
39 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __set(size_t __s, false_type) _NOEXCEPT { __size_ = __s; }
40 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __set(size_t, true_type) _NOEXCEPT {}
4141
4242public:
43 _LIBCPP_HIDE_FROM_ABI explicit __destruct_n(size_t __s) _NOEXCEPT : __size_(__s) {}
43 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __destruct_n(size_t __s) _NOEXCEPT : __size_(__s) {}
4444
4545 template <class _Tp>
46 _LIBCPP_HIDE_FROM_ABI void __incr() _NOEXCEPT {
46 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __incr() _NOEXCEPT {
4747 __incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());
4848 }
4949
5050 template <class _Tp>
51 _LIBCPP_HIDE_FROM_ABI void __set(size_t __s, _Tp*) _NOEXCEPT {
51 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __set(size_t __s, _Tp*) _NOEXCEPT {
5252 __set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());
5353 }
5454
5555 template <class _Tp>
56 _LIBCPP_HIDE_FROM_ABI void operator()(_Tp* __p) _NOEXCEPT {
56 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void operator()(_Tp* __p) _NOEXCEPT {
5757 __process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());
5858 }
5959};
lib/libcxx/include/__memory/inout_ptr.h+1
......@@ -15,6 +15,7 @@
1515#include <__memory/pointer_traits.h>
1616#include <__memory/shared_ptr.h>
1717#include <__memory/unique_ptr.h>
18#include <__type_traits/is_pointer.h>
1819#include <__type_traits/is_same.h>
1920#include <__type_traits/is_specialization.h>
2021#include <__type_traits/is_void.h>
lib/libcxx/include/__memory/noexcept_move_assign_container.h created+37
......@@ -0,0 +1,37 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___MEMORY_NOEXCEPT_MOVE_ASSIGN_CONTAINER_H
10#define _LIBCPP___MEMORY_NOEXCEPT_MOVE_ASSIGN_CONTAINER_H
11
12#include <__config>
13#include <__memory/allocator_traits.h>
14#include <__type_traits/integral_constant.h>
15#include <__type_traits/is_nothrow_assignable.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23template <typename _Alloc, typename _Traits = allocator_traits<_Alloc> >
24struct __noexcept_move_assign_container
25 : public integral_constant<bool,
26 _Traits::propagate_on_container_move_assignment::value
27#if _LIBCPP_STD_VER >= 17
28 || _Traits::is_always_equal::value
29#else
30 && is_nothrow_move_assignable<_Alloc>::value
31#endif
32 > {
33};
34
35_LIBCPP_END_NAMESPACE_STD
36
37#endif // _LIBCPP___MEMORY_NOEXCEPT_MOVE_ASSIGN_CONTAINER_H
lib/libcxx/include/__memory/out_ptr.h+1
......@@ -15,6 +15,7 @@
1515#include <__memory/pointer_traits.h>
1616#include <__memory/shared_ptr.h>
1717#include <__memory/unique_ptr.h>
18#include <__type_traits/is_pointer.h>
1819#include <__type_traits/is_specialization.h>
1920#include <__type_traits/is_void.h>
2021#include <__utility/forward.h>
lib/libcxx/include/__memory/pointer_traits.h+16-14
......@@ -11,17 +11,19 @@
1111#define _LIBCPP___MEMORY_POINTER_TRAITS_H
1212
1313#include <__config>
14#include <__cstddef/ptrdiff_t.h>
1415#include <__memory/addressof.h>
1516#include <__type_traits/conditional.h>
1617#include <__type_traits/conjunction.h>
1718#include <__type_traits/decay.h>
19#include <__type_traits/enable_if.h>
20#include <__type_traits/integral_constant.h>
1821#include <__type_traits/is_class.h>
1922#include <__type_traits/is_function.h>
2023#include <__type_traits/is_void.h>
2124#include <__type_traits/void_t.h>
2225#include <__utility/declval.h>
2326#include <__utility/forward.h>
24#include <cstddef>
2527
2628#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2729# pragma GCC system_header
......@@ -48,17 +50,17 @@ struct __pointer_traits_element_type {};
4850
4951template <class _Ptr>
5052struct __pointer_traits_element_type<_Ptr, true> {
51 typedef _LIBCPP_NODEBUG typename _Ptr::element_type type;
53 using type _LIBCPP_NODEBUG = typename _Ptr::element_type;
5254};
5355
5456template <template <class, class...> class _Sp, class _Tp, class... _Args>
5557struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true> {
56 typedef _LIBCPP_NODEBUG typename _Sp<_Tp, _Args...>::element_type type;
58 using type _LIBCPP_NODEBUG = typename _Sp<_Tp, _Args...>::element_type;
5759};
5860
5961template <template <class, class...> class _Sp, class _Tp, class... _Args>
6062struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false> {
61 typedef _LIBCPP_NODEBUG _Tp type;
63 using type _LIBCPP_NODEBUG = _Tp;
6264};
6365
6466template <class _Tp, class = void>
......@@ -69,12 +71,12 @@ struct __has_difference_type<_Tp, __void_t<typename _Tp::difference_type> > : tr
6971
7072template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
7173struct __pointer_traits_difference_type {
72 typedef _LIBCPP_NODEBUG ptrdiff_t type;
74 using type _LIBCPP_NODEBUG = ptrdiff_t;
7375};
7476
7577template <class _Ptr>
7678struct __pointer_traits_difference_type<_Ptr, true> {
77 typedef _LIBCPP_NODEBUG typename _Ptr::difference_type type;
79 using type _LIBCPP_NODEBUG = typename _Ptr::difference_type;
7880};
7981
8082template <class _Tp, class _Up>
......@@ -94,18 +96,18 @@ public:
9496template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
9597struct __pointer_traits_rebind {
9698#ifndef _LIBCPP_CXX03_LANG
97 typedef _LIBCPP_NODEBUG typename _Tp::template rebind<_Up> type;
99 using type _LIBCPP_NODEBUG = typename _Tp::template rebind<_Up>;
98100#else
99 typedef _LIBCPP_NODEBUG typename _Tp::template rebind<_Up>::other type;
101 using type _LIBCPP_NODEBUG = typename _Tp::template rebind<_Up>::other;
100102#endif
101103};
102104
103105template <template <class, class...> class _Sp, class _Tp, class... _Args, class _Up>
104106struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true> {
105107#ifndef _LIBCPP_CXX03_LANG
106 typedef _LIBCPP_NODEBUG typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
108 using type _LIBCPP_NODEBUG = typename _Sp<_Tp, _Args...>::template rebind<_Up>;
107109#else
108 typedef _LIBCPP_NODEBUG typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
110 using type _LIBCPP_NODEBUG = typename _Sp<_Tp, _Args...>::template rebind<_Up>::other;
109111#endif
110112};
111113
......@@ -174,10 +176,10 @@ public:
174176
175177#ifndef _LIBCPP_CXX03_LANG
176178template <class _From, class _To>
177using __rebind_pointer_t = typename pointer_traits<_From>::template rebind<_To>;
179using __rebind_pointer_t _LIBCPP_NODEBUG = typename pointer_traits<_From>::template rebind<_To>;
178180#else
179181template <class _From, class _To>
180using __rebind_pointer_t = typename pointer_traits<_From>::template rebind<_To>::other;
182using __rebind_pointer_t _LIBCPP_NODEBUG = typename pointer_traits<_From>::template rebind<_To>::other;
181183#endif
182184
183185// to_address
......@@ -274,7 +276,7 @@ struct __pointer_of<_Tp> {
274276};
275277
276278template <typename _Tp>
277using __pointer_of_t = typename __pointer_of<_Tp>::type;
279using __pointer_of_t _LIBCPP_NODEBUG = typename __pointer_of<_Tp>::type;
278280
279281template <class _Tp, class _Up>
280282struct __pointer_of_or {
......@@ -288,7 +290,7 @@ struct __pointer_of_or<_Tp, _Up> {
288290};
289291
290292template <typename _Tp, typename _Up>
291using __pointer_of_or_t = typename __pointer_of_or<_Tp, _Up>::type;
293using __pointer_of_or_t _LIBCPP_NODEBUG = typename __pointer_of_or<_Tp, _Up>::type;
292294
293295template <class _Smart>
294296concept __resettable_smart_pointer = requires(_Smart __s) { __s.reset(); };
lib/libcxx/include/__memory/ranges_construct_at.h+8-25
......@@ -22,7 +22,6 @@
2222#include <__utility/declval.h>
2323#include <__utility/forward.h>
2424#include <__utility/move.h>
25#include <new>
2625
2726#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2827# pragma GCC system_header
......@@ -38,43 +37,33 @@ namespace ranges {
3837
3938// construct_at
4039
41namespace __construct_at {
42
43struct __fn {
40struct __construct_at {
4441 template <class _Tp, class... _Args, class = decltype(::new(std::declval<void*>()) _Tp(std::declval<_Args>()...))>
4542 _LIBCPP_HIDE_FROM_ABI constexpr _Tp* operator()(_Tp* __location, _Args&&... __args) const {
4643 return std::construct_at(__location, std::forward<_Args>(__args)...);
4744 }
4845};
4946
50} // namespace __construct_at
51
5247inline namespace __cpo {
53inline constexpr auto construct_at = __construct_at::__fn{};
48inline constexpr auto construct_at = __construct_at{};
5449} // namespace __cpo
5550
5651// destroy_at
5752
58namespace __destroy_at {
59
60struct __fn {
53struct __destroy_at {
6154 template <destructible _Tp>
6255 _LIBCPP_HIDE_FROM_ABI constexpr void operator()(_Tp* __location) const noexcept {
6356 std::destroy_at(__location);
6457 }
6558};
6659
67} // namespace __destroy_at
68
6960inline namespace __cpo {
70inline constexpr auto destroy_at = __destroy_at::__fn{};
61inline constexpr auto destroy_at = __destroy_at{};
7162} // namespace __cpo
7263
7364// destroy
7465
75namespace __destroy {
76
77struct __fn {
66struct __destroy {
7867 template <__nothrow_input_iterator _InputIterator, __nothrow_sentinel_for<_InputIterator> _Sentinel>
7968 requires destructible<iter_value_t<_InputIterator>>
8069 _LIBCPP_HIDE_FROM_ABI constexpr _InputIterator operator()(_InputIterator __first, _Sentinel __last) const noexcept {
......@@ -88,17 +77,13 @@ struct __fn {
8877 }
8978};
9079
91} // namespace __destroy
92
9380inline namespace __cpo {
94inline constexpr auto destroy = __destroy::__fn{};
81inline constexpr auto destroy = __destroy{};
9582} // namespace __cpo
9683
9784// destroy_n
9885
99namespace __destroy_n {
100
101struct __fn {
86struct __destroy_n {
10287 template <__nothrow_input_iterator _InputIterator>
10388 requires destructible<iter_value_t<_InputIterator>>
10489 _LIBCPP_HIDE_FROM_ABI constexpr _InputIterator
......@@ -107,10 +92,8 @@ struct __fn {
10792 }
10893};
10994
110} // namespace __destroy_n
111
11295inline namespace __cpo {
113inline constexpr auto destroy_n = __destroy_n::__fn{};
96inline constexpr auto destroy_n = __destroy_n{};
11497} // namespace __cpo
11598
11699} // namespace ranges
lib/libcxx/include/__memory/ranges_uninitialized_algorithms.h+20-61
......@@ -25,7 +25,6 @@
2525#include <__ranges/dangling.h>
2626#include <__type_traits/remove_reference.h>
2727#include <__utility/move.h>
28#include <new>
2928
3029#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3130# pragma GCC system_header
......@@ -42,9 +41,7 @@ namespace ranges {
4241
4342// uninitialized_default_construct
4443
45namespace __uninitialized_default_construct {
46
47struct __fn {
44struct __uninitialized_default_construct {
4845 template <__nothrow_forward_iterator _ForwardIterator, __nothrow_sentinel_for<_ForwardIterator> _Sentinel>
4946 requires default_initializable<iter_value_t<_ForwardIterator>>
5047 _LIBCPP_HIDE_FROM_ABI _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last) const {
......@@ -59,17 +56,13 @@ struct __fn {
5956 }
6057};
6158
62} // namespace __uninitialized_default_construct
63
6459inline namespace __cpo {
65inline constexpr auto uninitialized_default_construct = __uninitialized_default_construct::__fn{};
60inline constexpr auto uninitialized_default_construct = __uninitialized_default_construct{};
6661} // namespace __cpo
6762
6863// uninitialized_default_construct_n
6964
70namespace __uninitialized_default_construct_n {
71
72struct __fn {
65struct __uninitialized_default_construct_n {
7366 template <__nothrow_forward_iterator _ForwardIterator>
7467 requires default_initializable<iter_value_t<_ForwardIterator>>
7568 _LIBCPP_HIDE_FROM_ABI _ForwardIterator
......@@ -79,17 +72,13 @@ struct __fn {
7972 }
8073};
8174
82} // namespace __uninitialized_default_construct_n
83
8475inline namespace __cpo {
85inline constexpr auto uninitialized_default_construct_n = __uninitialized_default_construct_n::__fn{};
76inline constexpr auto uninitialized_default_construct_n = __uninitialized_default_construct_n{};
8677} // namespace __cpo
8778
8879// uninitialized_value_construct
8980
90namespace __uninitialized_value_construct {
91
92struct __fn {
81struct __uninitialized_value_construct {
9382 template <__nothrow_forward_iterator _ForwardIterator, __nothrow_sentinel_for<_ForwardIterator> _Sentinel>
9483 requires default_initializable<iter_value_t<_ForwardIterator>>
9584 _LIBCPP_HIDE_FROM_ABI _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last) const {
......@@ -104,17 +93,13 @@ struct __fn {
10493 }
10594};
10695
107} // namespace __uninitialized_value_construct
108
10996inline namespace __cpo {
110inline constexpr auto uninitialized_value_construct = __uninitialized_value_construct::__fn{};
97inline constexpr auto uninitialized_value_construct = __uninitialized_value_construct{};
11198} // namespace __cpo
11299
113100// uninitialized_value_construct_n
114101
115namespace __uninitialized_value_construct_n {
116
117struct __fn {
102struct __uninitialized_value_construct_n {
118103 template <__nothrow_forward_iterator _ForwardIterator>
119104 requires default_initializable<iter_value_t<_ForwardIterator>>
120105 _LIBCPP_HIDE_FROM_ABI _ForwardIterator
......@@ -124,17 +109,13 @@ struct __fn {
124109 }
125110};
126111
127} // namespace __uninitialized_value_construct_n
128
129112inline namespace __cpo {
130inline constexpr auto uninitialized_value_construct_n = __uninitialized_value_construct_n::__fn{};
113inline constexpr auto uninitialized_value_construct_n = __uninitialized_value_construct_n{};
131114} // namespace __cpo
132115
133116// uninitialized_fill
134117
135namespace __uninitialized_fill {
136
137struct __fn {
118struct __uninitialized_fill {
138119 template <__nothrow_forward_iterator _ForwardIterator, __nothrow_sentinel_for<_ForwardIterator> _Sentinel, class _Tp>
139120 requires constructible_from<iter_value_t<_ForwardIterator>, const _Tp&>
140121 _LIBCPP_HIDE_FROM_ABI _ForwardIterator operator()(_ForwardIterator __first, _Sentinel __last, const _Tp& __x) const {
......@@ -149,17 +130,13 @@ struct __fn {
149130 }
150131};
151132
152} // namespace __uninitialized_fill
153
154133inline namespace __cpo {
155inline constexpr auto uninitialized_fill = __uninitialized_fill::__fn{};
134inline constexpr auto uninitialized_fill = __uninitialized_fill{};
156135} // namespace __cpo
157136
158137// uninitialized_fill_n
159138
160namespace __uninitialized_fill_n {
161
162struct __fn {
139struct __uninitialized_fill_n {
163140 template <__nothrow_forward_iterator _ForwardIterator, class _Tp>
164141 requires constructible_from<iter_value_t<_ForwardIterator>, const _Tp&>
165142 _LIBCPP_HIDE_FROM_ABI _ForwardIterator
......@@ -169,10 +146,8 @@ struct __fn {
169146 }
170147};
171148
172} // namespace __uninitialized_fill_n
173
174149inline namespace __cpo {
175inline constexpr auto uninitialized_fill_n = __uninitialized_fill_n::__fn{};
150inline constexpr auto uninitialized_fill_n = __uninitialized_fill_n{};
176151} // namespace __cpo
177152
178153// uninitialized_copy
......@@ -180,9 +155,7 @@ inline constexpr auto uninitialized_fill_n = __uninitialized_fill_n::__fn{};
180155template <class _InputIterator, class _OutputIterator>
181156using uninitialized_copy_result = in_out_result<_InputIterator, _OutputIterator>;
182157
183namespace __uninitialized_copy {
184
185struct __fn {
158struct __uninitialized_copy {
186159 template <input_iterator _InputIterator,
187160 sentinel_for<_InputIterator> _Sentinel1,
188161 __nothrow_forward_iterator _OutputIterator,
......@@ -207,10 +180,8 @@ struct __fn {
207180 }
208181};
209182
210} // namespace __uninitialized_copy
211
212183inline namespace __cpo {
213inline constexpr auto uninitialized_copy = __uninitialized_copy::__fn{};
184inline constexpr auto uninitialized_copy = __uninitialized_copy{};
214185} // namespace __cpo
215186
216187// uninitialized_copy_n
......@@ -218,9 +189,7 @@ inline constexpr auto uninitialized_copy = __uninitialized_copy::__fn{};
218189template <class _InputIterator, class _OutputIterator>
219190using uninitialized_copy_n_result = in_out_result<_InputIterator, _OutputIterator>;
220191
221namespace __uninitialized_copy_n {
222
223struct __fn {
192struct __uninitialized_copy_n {
224193 template <input_iterator _InputIterator,
225194 __nothrow_forward_iterator _OutputIterator,
226195 __nothrow_sentinel_for<_OutputIterator> _Sentinel>
......@@ -238,10 +207,8 @@ struct __fn {
238207 }
239208};
240209
241} // namespace __uninitialized_copy_n
242
243210inline namespace __cpo {
244inline constexpr auto uninitialized_copy_n = __uninitialized_copy_n::__fn{};
211inline constexpr auto uninitialized_copy_n = __uninitialized_copy_n{};
245212} // namespace __cpo
246213
247214// uninitialized_move
......@@ -249,9 +216,7 @@ inline constexpr auto uninitialized_copy_n = __uninitialized_copy_n::__fn{};
249216template <class _InputIterator, class _OutputIterator>
250217using uninitialized_move_result = in_out_result<_InputIterator, _OutputIterator>;
251218
252namespace __uninitialized_move {
253
254struct __fn {
219struct __uninitialized_move {
255220 template <input_iterator _InputIterator,
256221 sentinel_for<_InputIterator> _Sentinel1,
257222 __nothrow_forward_iterator _OutputIterator,
......@@ -276,10 +241,8 @@ struct __fn {
276241 }
277242};
278243
279} // namespace __uninitialized_move
280
281244inline namespace __cpo {
282inline constexpr auto uninitialized_move = __uninitialized_move::__fn{};
245inline constexpr auto uninitialized_move = __uninitialized_move{};
283246} // namespace __cpo
284247
285248// uninitialized_move_n
......@@ -287,9 +250,7 @@ inline constexpr auto uninitialized_move = __uninitialized_move::__fn{};
287250template <class _InputIterator, class _OutputIterator>
288251using uninitialized_move_n_result = in_out_result<_InputIterator, _OutputIterator>;
289252
290namespace __uninitialized_move_n {
291
292struct __fn {
253struct __uninitialized_move_n {
293254 template <input_iterator _InputIterator,
294255 __nothrow_forward_iterator _OutputIterator,
295256 __nothrow_sentinel_for<_OutputIterator> _Sentinel>
......@@ -308,10 +269,8 @@ struct __fn {
308269 }
309270};
310271
311} // namespace __uninitialized_move_n
312
313272inline namespace __cpo {
314inline constexpr auto uninitialized_move_n = __uninitialized_move_n::__fn{};
273inline constexpr auto uninitialized_move_n = __uninitialized_move_n{};
315274} // namespace __cpo
316275
317276} // namespace ranges
lib/libcxx/include/__memory/raw_storage_iterator.h+1-2
......@@ -11,12 +11,11 @@
1111#define _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H
1212
1313#include <__config>
14#include <__cstddef/ptrdiff_t.h>
1415#include <__iterator/iterator.h>
1516#include <__iterator/iterator_traits.h>
1617#include <__memory/addressof.h>
1718#include <__utility/move.h>
18#include <cstddef>
19#include <new>
2019
2120#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2221# pragma GCC system_header
lib/libcxx/include/__memory/shared_count.h created+136
......@@ -0,0 +1,136 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___MEMORY_SHARED_COUNT_H
10#define _LIBCPP___MEMORY_SHARED_COUNT_H
11
12#include <__config>
13#include <typeinfo>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21// NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
22// should be sufficient for thread safety.
23// See https://llvm.org/PR22803
24#if (defined(__clang__) && __has_builtin(__atomic_add_fetch) && defined(__ATOMIC_RELAXED) && \
25 defined(__ATOMIC_ACQ_REL)) || \
26 defined(_LIBCPP_COMPILER_GCC)
27# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT 1
28#else
29# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT 0
30#endif
31
32template <class _ValueType>
33inline _LIBCPP_HIDE_FROM_ABI _ValueType __libcpp_relaxed_load(_ValueType const* __value) {
34#if _LIBCPP_HAS_THREADS && defined(__ATOMIC_RELAXED) && \
35 (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC))
36 return __atomic_load_n(__value, __ATOMIC_RELAXED);
37#else
38 return *__value;
39#endif
40}
41
42template <class _ValueType>
43inline _LIBCPP_HIDE_FROM_ABI _ValueType __libcpp_acquire_load(_ValueType const* __value) {
44#if _LIBCPP_HAS_THREADS && defined(__ATOMIC_ACQUIRE) && \
45 (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC))
46 return __atomic_load_n(__value, __ATOMIC_ACQUIRE);
47#else
48 return *__value;
49#endif
50}
51
52template <class _Tp>
53inline _LIBCPP_HIDE_FROM_ABI _Tp __libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT {
54#if _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT && _LIBCPP_HAS_THREADS
55 return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED);
56#else
57 return __t += 1;
58#endif
59}
60
61template <class _Tp>
62inline _LIBCPP_HIDE_FROM_ABI _Tp __libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT {
63#if _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT && _LIBCPP_HAS_THREADS
64 return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL);
65#else
66 return __t -= 1;
67#endif
68}
69
70class _LIBCPP_EXPORTED_FROM_ABI __shared_count {
71 __shared_count(const __shared_count&);
72 __shared_count& operator=(const __shared_count&);
73
74protected:
75 long __shared_owners_;
76 virtual ~__shared_count();
77
78private:
79 virtual void __on_zero_shared() _NOEXCEPT = 0;
80
81public:
82 _LIBCPP_HIDE_FROM_ABI explicit __shared_count(long __refs = 0) _NOEXCEPT : __shared_owners_(__refs) {}
83
84#if defined(_LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS)
85 void __add_shared() noexcept;
86 bool __release_shared() noexcept;
87#else
88 _LIBCPP_HIDE_FROM_ABI void __add_shared() _NOEXCEPT { __libcpp_atomic_refcount_increment(__shared_owners_); }
89 _LIBCPP_HIDE_FROM_ABI bool __release_shared() _NOEXCEPT {
90 if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) {
91 __on_zero_shared();
92 return true;
93 }
94 return false;
95 }
96#endif
97 _LIBCPP_HIDE_FROM_ABI long use_count() const _NOEXCEPT { return __libcpp_relaxed_load(&__shared_owners_) + 1; }
98};
99
100class _LIBCPP_EXPORTED_FROM_ABI __shared_weak_count : private __shared_count {
101 long __shared_weak_owners_;
102
103public:
104 _LIBCPP_HIDE_FROM_ABI explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
105 : __shared_count(__refs),
106 __shared_weak_owners_(__refs) {}
107
108protected:
109 ~__shared_weak_count() override;
110
111public:
112#if defined(_LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS)
113 void __add_shared() noexcept;
114 void __add_weak() noexcept;
115 void __release_shared() noexcept;
116#else
117 _LIBCPP_HIDE_FROM_ABI void __add_shared() _NOEXCEPT { __shared_count::__add_shared(); }
118 _LIBCPP_HIDE_FROM_ABI void __add_weak() _NOEXCEPT { __libcpp_atomic_refcount_increment(__shared_weak_owners_); }
119 _LIBCPP_HIDE_FROM_ABI void __release_shared() _NOEXCEPT {
120 if (__shared_count::__release_shared())
121 __release_weak();
122 }
123#endif
124 void __release_weak() _NOEXCEPT;
125 _LIBCPP_HIDE_FROM_ABI long use_count() const _NOEXCEPT { return __shared_count::use_count(); }
126 __shared_weak_count* lock() _NOEXCEPT;
127
128 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
129
130private:
131 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
132};
133
134_LIBCPP_END_NAMESPACE_STD
135
136#endif // _LIBCPP___MEMORY_SHARED_COUNT_H
lib/libcxx/include/__memory/shared_ptr.h+67-177
......@@ -13,6 +13,8 @@
1313#include <__compare/compare_three_way.h>
1414#include <__compare/ordering.h>
1515#include <__config>
16#include <__cstddef/nullptr_t.h>
17#include <__cstddef/ptrdiff_t.h>
1618#include <__exception/exception.h>
1719#include <__functional/binary_function.h>
1820#include <__functional/operations.h>
......@@ -28,20 +30,26 @@
2830#include <__memory/compressed_pair.h>
2931#include <__memory/construct_at.h>
3032#include <__memory/pointer_traits.h>
33#include <__memory/shared_count.h>
3134#include <__memory/uninitialized_algorithms.h>
3235#include <__memory/unique_ptr.h>
3336#include <__type_traits/add_lvalue_reference.h>
3437#include <__type_traits/conditional.h>
3538#include <__type_traits/conjunction.h>
3639#include <__type_traits/disjunction.h>
40#include <__type_traits/enable_if.h>
41#include <__type_traits/integral_constant.h>
3742#include <__type_traits/is_array.h>
3843#include <__type_traits/is_bounded_array.h>
3944#include <__type_traits/is_constructible.h>
4045#include <__type_traits/is_convertible.h>
46#include <__type_traits/is_function.h>
4147#include <__type_traits/is_reference.h>
48#include <__type_traits/is_same.h>
4249#include <__type_traits/is_unbounded_array.h>
4350#include <__type_traits/nat.h>
4451#include <__type_traits/negation.h>
52#include <__type_traits/remove_cv.h>
4553#include <__type_traits/remove_extent.h>
4654#include <__type_traits/remove_reference.h>
4755#include <__utility/declval.h>
......@@ -49,10 +57,8 @@
4957#include <__utility/move.h>
5058#include <__utility/swap.h>
5159#include <__verbose_abort>
52#include <cstddef>
53#include <new>
5460#include <typeinfo>
55#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
61#if _LIBCPP_HAS_ATOMIC_HEADER
5662# include <__atomic/memory_order.h>
5763#endif
5864
......@@ -65,53 +71,6 @@ _LIBCPP_PUSH_MACROS
6571
6672_LIBCPP_BEGIN_NAMESPACE_STD
6773
68// NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
69// should be sufficient for thread safety.
70// See https://llvm.org/PR22803
71#if defined(__clang__) && __has_builtin(__atomic_add_fetch) && defined(__ATOMIC_RELAXED) && defined(__ATOMIC_ACQ_REL)
72# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
73#elif defined(_LIBCPP_COMPILER_GCC)
74# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
75#endif
76
77template <class _ValueType>
78inline _LIBCPP_HIDE_FROM_ABI _ValueType __libcpp_relaxed_load(_ValueType const* __value) {
79#if !defined(_LIBCPP_HAS_NO_THREADS) && defined(__ATOMIC_RELAXED) && \
80 (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC))
81 return __atomic_load_n(__value, __ATOMIC_RELAXED);
82#else
83 return *__value;
84#endif
85}
86
87template <class _ValueType>
88inline _LIBCPP_HIDE_FROM_ABI _ValueType __libcpp_acquire_load(_ValueType const* __value) {
89#if !defined(_LIBCPP_HAS_NO_THREADS) && defined(__ATOMIC_ACQUIRE) && \
90 (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC))
91 return __atomic_load_n(__value, __ATOMIC_ACQUIRE);
92#else
93 return *__value;
94#endif
95}
96
97template <class _Tp>
98inline _LIBCPP_HIDE_FROM_ABI _Tp __libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT {
99#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
100 return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED);
101#else
102 return __t += 1;
103#endif
104}
105
106template <class _Tp>
107inline _LIBCPP_HIDE_FROM_ABI _Tp __libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT {
108#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
109 return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL);
110#else
111 return __t -= 1;
112#endif
113}
114
11574class _LIBCPP_EXPORTED_FROM_ABI bad_weak_ptr : public std::exception {
11675public:
11776 _LIBCPP_HIDE_FROM_ABI bad_weak_ptr() _NOEXCEPT = default;
......@@ -121,8 +80,8 @@ public:
12180 const char* what() const _NOEXCEPT override;
12281};
12382
124_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_weak_ptr() {
125#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
83[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_weak_ptr() {
84#if _LIBCPP_HAS_EXCEPTIONS
12685 throw bad_weak_ptr();
12786#else
12887 _LIBCPP_VERBOSE_ABORT("bad_weak_ptr was thrown in -fno-exceptions mode");
......@@ -132,79 +91,15 @@ _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_weak_ptr() {
13291template <class _Tp>
13392class _LIBCPP_TEMPLATE_VIS weak_ptr;
13493
135class _LIBCPP_EXPORTED_FROM_ABI __shared_count {
136 __shared_count(const __shared_count&);
137 __shared_count& operator=(const __shared_count&);
138
139protected:
140 long __shared_owners_;
141 virtual ~__shared_count();
142
143private:
144 virtual void __on_zero_shared() _NOEXCEPT = 0;
145
146public:
147 _LIBCPP_HIDE_FROM_ABI explicit __shared_count(long __refs = 0) _NOEXCEPT : __shared_owners_(__refs) {}
148
149#if defined(_LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS)
150 void __add_shared() noexcept;
151 bool __release_shared() noexcept;
152#else
153 _LIBCPP_HIDE_FROM_ABI void __add_shared() _NOEXCEPT { __libcpp_atomic_refcount_increment(__shared_owners_); }
154 _LIBCPP_HIDE_FROM_ABI bool __release_shared() _NOEXCEPT {
155 if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) {
156 __on_zero_shared();
157 return true;
158 }
159 return false;
160 }
161#endif
162 _LIBCPP_HIDE_FROM_ABI long use_count() const _NOEXCEPT { return __libcpp_relaxed_load(&__shared_owners_) + 1; }
163};
164
165class _LIBCPP_EXPORTED_FROM_ABI __shared_weak_count : private __shared_count {
166 long __shared_weak_owners_;
167
168public:
169 _LIBCPP_HIDE_FROM_ABI explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
170 : __shared_count(__refs),
171 __shared_weak_owners_(__refs) {}
172
173protected:
174 ~__shared_weak_count() override;
175
176public:
177#if defined(_LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS)
178 void __add_shared() noexcept;
179 void __add_weak() noexcept;
180 void __release_shared() noexcept;
181#else
182 _LIBCPP_HIDE_FROM_ABI void __add_shared() _NOEXCEPT { __shared_count::__add_shared(); }
183 _LIBCPP_HIDE_FROM_ABI void __add_weak() _NOEXCEPT { __libcpp_atomic_refcount_increment(__shared_weak_owners_); }
184 _LIBCPP_HIDE_FROM_ABI void __release_shared() _NOEXCEPT {
185 if (__shared_count::__release_shared())
186 __release_weak();
187 }
188#endif
189 void __release_weak() _NOEXCEPT;
190 _LIBCPP_HIDE_FROM_ABI long use_count() const _NOEXCEPT { return __shared_count::use_count(); }
191 __shared_weak_count* lock() _NOEXCEPT;
192
193 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
194
195private:
196 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
197};
198
19994template <class _Tp, class _Dp, class _Alloc>
20095class __shared_ptr_pointer : public __shared_weak_count {
201 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
96 _LIBCPP_COMPRESSED_TRIPLE(_Tp, __ptr_, _Dp, __deleter_, _Alloc, __alloc_);
20297
20398public:
20499 _LIBCPP_HIDE_FROM_ABI __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
205 : __data_(__compressed_pair<_Tp, _Dp>(__p, std::move(__d)), std::move(__a)) {}
100 : __ptr_(__p), __deleter_(std::move(__d)), __alloc_(std::move(__a)) {}
206101
207#ifndef _LIBCPP_HAS_NO_RTTI
102#if _LIBCPP_HAS_RTTI
208103 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const void* __get_deleter(const type_info&) const _NOEXCEPT override;
209104#endif
210105
......@@ -213,19 +108,19 @@ private:
213108 _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared_weak() _NOEXCEPT override;
214109};
215110
216#ifndef _LIBCPP_HAS_NO_RTTI
111#if _LIBCPP_HAS_RTTI
217112
218113template <class _Tp, class _Dp, class _Alloc>
219114const void* __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT {
220 return __t == typeid(_Dp) ? std::addressof(__data_.first().second()) : nullptr;
115 return __t == typeid(_Dp) ? std::addressof(__deleter_) : nullptr;
221116}
222117
223#endif // _LIBCPP_HAS_NO_RTTI
118#endif // _LIBCPP_HAS_RTTI
224119
225120template <class _Tp, class _Dp, class _Alloc>
226121void __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT {
227 __data_.first().second()(__data_.first().first());
228 __data_.first().second().~_Dp();
122 __deleter_(__ptr_);
123 __deleter_.~_Dp();
229124}
230125
231126template <class _Tp, class _Dp, class _Alloc>
......@@ -234,8 +129,8 @@ void __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT {
234129 typedef allocator_traits<_Al> _ATraits;
235130 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
236131
237 _Al __a(__data_.second());
238 __data_.second().~_Alloc();
132 _Al __a(__alloc_);
133 __alloc_.~_Alloc();
239134 __a.deallocate(_PTraits::pointer_to(*this), 1);
240135}
241136
......@@ -246,33 +141,35 @@ struct __for_overwrite_tag {};
246141
247142template <class _Tp, class _Alloc>
248143struct __shared_ptr_emplace : __shared_weak_count {
144 using __value_type _LIBCPP_NODEBUG = __remove_cv_t<_Tp>;
145
249146 template <class... _Args,
250147 class _Allocator = _Alloc,
251148 __enable_if_t<is_same<typename _Allocator::value_type, __for_overwrite_tag>::value, int> = 0>
252149 _LIBCPP_HIDE_FROM_ABI explicit __shared_ptr_emplace(_Alloc __a, _Args&&...) : __storage_(std::move(__a)) {
253150 static_assert(
254151 sizeof...(_Args) == 0, "No argument should be provided to the control block when using _for_overwrite");
255 ::new ((void*)__get_elem()) _Tp;
152 ::new (static_cast<void*>(__get_elem())) __value_type;
256153 }
257154
258155 template <class... _Args,
259156 class _Allocator = _Alloc,
260157 __enable_if_t<!is_same<typename _Allocator::value_type, __for_overwrite_tag>::value, int> = 0>
261158 _LIBCPP_HIDE_FROM_ABI explicit __shared_ptr_emplace(_Alloc __a, _Args&&... __args) : __storage_(std::move(__a)) {
262 using _TpAlloc = typename __allocator_traits_rebind<_Alloc, __remove_cv_t<_Tp> >::type;
159 using _TpAlloc = typename __allocator_traits_rebind<_Alloc, __value_type>::type;
263160 _TpAlloc __tmp(*__get_alloc());
264161 allocator_traits<_TpAlloc>::construct(__tmp, __get_elem(), std::forward<_Args>(__args)...);
265162 }
266163
267164 _LIBCPP_HIDE_FROM_ABI _Alloc* __get_alloc() _NOEXCEPT { return __storage_.__get_alloc(); }
268165
269 _LIBCPP_HIDE_FROM_ABI _Tp* __get_elem() _NOEXCEPT { return __storage_.__get_elem(); }
166 _LIBCPP_HIDE_FROM_ABI __value_type* __get_elem() _NOEXCEPT { return __storage_.__get_elem(); }
270167
271168private:
272169 template <class _Allocator = _Alloc,
273170 __enable_if_t<is_same<typename _Allocator::value_type, __for_overwrite_tag>::value, int> = 0>
274171 _LIBCPP_HIDE_FROM_ABI void __on_zero_shared_impl() _NOEXCEPT {
275 __get_elem()->~_Tp();
172 __get_elem()->~__value_type();
276173 }
277174
278175 template <class _Allocator = _Alloc,
......@@ -293,36 +190,28 @@ private:
293190 allocator_traits<_ControlBlockAlloc>::deallocate(__tmp, pointer_traits<_ControlBlockPointer>::pointer_to(*this), 1);
294191 }
295192
193 // TODO: It should be possible to refactor this to remove `_Storage` entirely.
296194 // This class implements the control block for non-array shared pointers created
297195 // through `std::allocate_shared` and `std::make_shared`.
298 //
299 // In previous versions of the library, we used a compressed pair to store
300 // both the _Alloc and the _Tp. This implies using EBO, which is incompatible
301 // with Allocator construction for _Tp. To allow implementing P0674 in C++20,
302 // we now use a properly aligned char buffer while making sure that we maintain
303 // the same layout that we had when we used a compressed pair.
304 using _CompressedPair = __compressed_pair<_Alloc, _Tp>;
305 struct _ALIGNAS_TYPE(_CompressedPair) _Storage {
306 char __blob_[sizeof(_CompressedPair)];
196 struct _Storage {
197 struct _Data {
198 _LIBCPP_COMPRESSED_PAIR(_Alloc, __alloc_, __value_type, __elem_);
199 };
200
201 _ALIGNAS_TYPE(_Data) char __buffer_[sizeof(_Data)];
307202
308203 _LIBCPP_HIDE_FROM_ABI explicit _Storage(_Alloc&& __a) { ::new ((void*)__get_alloc()) _Alloc(std::move(__a)); }
309204 _LIBCPP_HIDE_FROM_ABI ~_Storage() { __get_alloc()->~_Alloc(); }
205
310206 _LIBCPP_HIDE_FROM_ABI _Alloc* __get_alloc() _NOEXCEPT {
311 _CompressedPair* __as_pair = reinterpret_cast<_CompressedPair*>(__blob_);
312 typename _CompressedPair::_Base1* __first = _CompressedPair::__get_first_base(__as_pair);
313 _Alloc* __alloc = reinterpret_cast<_Alloc*>(__first);
314 return __alloc;
207 return std::addressof(reinterpret_cast<_Data*>(__buffer_)->__alloc_);
315208 }
316 _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _Tp* __get_elem() _NOEXCEPT {
317 _CompressedPair* __as_pair = reinterpret_cast<_CompressedPair*>(__blob_);
318 typename _CompressedPair::_Base2* __second = _CompressedPair::__get_second_base(__as_pair);
319 _Tp* __elem = reinterpret_cast<_Tp*>(__second);
320 return __elem;
209
210 _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI __value_type* __get_elem() _NOEXCEPT {
211 return std::addressof(reinterpret_cast<_Data*>(__buffer_)->__elem_);
321212 }
322213 };
323214
324 static_assert(_LIBCPP_ALIGNOF(_Storage) == _LIBCPP_ALIGNOF(_CompressedPair), "");
325 static_assert(sizeof(_Storage) == sizeof(_CompressedPair), "");
326215 _Storage __storage_;
327216};
328217
......@@ -404,7 +293,8 @@ struct __shared_ptr_deleter_ctor_reqs {
404293};
405294
406295template <class _Dp>
407using __shared_ptr_nullptr_deleter_ctor_reqs = _And<is_move_constructible<_Dp>, __well_formed_deleter<_Dp, nullptr_t> >;
296using __shared_ptr_nullptr_deleter_ctor_reqs _LIBCPP_NODEBUG =
297 _And<is_move_constructible<_Dp>, __well_formed_deleter<_Dp, nullptr_t> >;
408298
409299#if defined(_LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI)
410300# define _LIBCPP_SHARED_PTR_TRIVIAL_ABI __attribute__((__trivial_abi__))
......@@ -426,7 +316,7 @@ public:
426316
427317 // A shared_ptr contains only two raw pointers which point to the heap and move constructing already doesn't require
428318 // any bookkeeping, so it's always trivially relocatable.
429 using __trivially_relocatable = shared_ptr;
319 using __trivially_relocatable _LIBCPP_NODEBUG = shared_ptr;
430320
431321private:
432322 element_type* __ptr_;
......@@ -459,9 +349,9 @@ public:
459349
460350 template <class _Yp, class _Dp, __enable_if_t<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, _Tp>::value, int> = 0>
461351 _LIBCPP_HIDE_FROM_ABI shared_ptr(_Yp* __p, _Dp __d) : __ptr_(__p) {
462#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
352#if _LIBCPP_HAS_EXCEPTIONS
463353 try {
464#endif // _LIBCPP_HAS_NO_EXCEPTIONS
354#endif // _LIBCPP_HAS_EXCEPTIONS
465355 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
466356 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT> _CntrlBlk;
467357#ifndef _LIBCPP_CXX03_LANG
......@@ -470,12 +360,12 @@ public:
470360 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
471361#endif // not _LIBCPP_CXX03_LANG
472362 __enable_weak_this(__p, __p);
473#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
363#if _LIBCPP_HAS_EXCEPTIONS
474364 } catch (...) {
475365 __d(__p);
476366 throw;
477367 }
478#endif // _LIBCPP_HAS_NO_EXCEPTIONS
368#endif // _LIBCPP_HAS_EXCEPTIONS
479369 }
480370
481371 template <class _Yp,
......@@ -483,9 +373,9 @@ public:
483373 class _Alloc,
484374 __enable_if_t<__shared_ptr_deleter_ctor_reqs<_Dp, _Yp, _Tp>::value, int> = 0>
485375 _LIBCPP_HIDE_FROM_ABI shared_ptr(_Yp* __p, _Dp __d, _Alloc __a) : __ptr_(__p) {
486#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
376#if _LIBCPP_HAS_EXCEPTIONS
487377 try {
488#endif // _LIBCPP_HAS_NO_EXCEPTIONS
378#endif // _LIBCPP_HAS_EXCEPTIONS
489379 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
490380 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
491381 typedef __allocator_destructor<_A2> _D2;
......@@ -499,12 +389,12 @@ public:
499389#endif // not _LIBCPP_CXX03_LANG
500390 __cntrl_ = std::addressof(*__hold2.release());
501391 __enable_weak_this(__p, __p);
502#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
392#if _LIBCPP_HAS_EXCEPTIONS
503393 } catch (...) {
504394 __d(__p);
505395 throw;
506396 }
507#endif // _LIBCPP_HAS_NO_EXCEPTIONS
397#endif // _LIBCPP_HAS_EXCEPTIONS
508398 }
509399
510400 template <class _Dp>
......@@ -513,9 +403,9 @@ public:
513403 _Dp __d,
514404 __enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs<_Dp>::value, __nullptr_sfinae_tag> = __nullptr_sfinae_tag())
515405 : __ptr_(nullptr) {
516#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
406#if _LIBCPP_HAS_EXCEPTIONS
517407 try {
518#endif // _LIBCPP_HAS_NO_EXCEPTIONS
408#endif // _LIBCPP_HAS_EXCEPTIONS
519409 typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
520410 typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT> _CntrlBlk;
521411#ifndef _LIBCPP_CXX03_LANG
......@@ -523,12 +413,12 @@ public:
523413#else
524414 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
525415#endif // not _LIBCPP_CXX03_LANG
526#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
416#if _LIBCPP_HAS_EXCEPTIONS
527417 } catch (...) {
528418 __d(__p);
529419 throw;
530420 }
531#endif // _LIBCPP_HAS_NO_EXCEPTIONS
421#endif // _LIBCPP_HAS_EXCEPTIONS
532422 }
533423
534424 template <class _Dp, class _Alloc>
......@@ -538,9 +428,9 @@ public:
538428 _Alloc __a,
539429 __enable_if_t<__shared_ptr_nullptr_deleter_ctor_reqs<_Dp>::value, __nullptr_sfinae_tag> = __nullptr_sfinae_tag())
540430 : __ptr_(nullptr) {
541#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
431#if _LIBCPP_HAS_EXCEPTIONS
542432 try {
543#endif // _LIBCPP_HAS_NO_EXCEPTIONS
433#endif // _LIBCPP_HAS_EXCEPTIONS
544434 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
545435 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
546436 typedef __allocator_destructor<_A2> _D2;
......@@ -553,12 +443,12 @@ public:
553443 _CntrlBlk(__p, __d, __a);
554444#endif // not _LIBCPP_CXX03_LANG
555445 __cntrl_ = std::addressof(*__hold2.release());
556#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
446#if _LIBCPP_HAS_EXCEPTIONS
557447 } catch (...) {
558448 __d(__p);
559449 throw;
560450 }
561#endif // _LIBCPP_HAS_NO_EXCEPTIONS
451#endif // _LIBCPP_HAS_EXCEPTIONS
562452 }
563453
564454 template <class _Yp>
......@@ -771,12 +661,12 @@ public:
771661 }
772662#endif
773663
774#ifndef _LIBCPP_HAS_NO_RTTI
664#if _LIBCPP_HAS_RTTI
775665 template <class _Dp>
776666 _LIBCPP_HIDE_FROM_ABI _Dp* __get_deleter() const _NOEXCEPT {
777667 return static_cast<_Dp*>(__cntrl_ ? const_cast<void*>(__cntrl_->__get_deleter(typeid(_Dp))) : nullptr);
778668 }
779#endif // _LIBCPP_HAS_NO_RTTI
669#endif // _LIBCPP_HAS_RTTI
780670
781671 template <class _Yp, class _CntrlBlk>
782672 _LIBCPP_HIDE_FROM_ABI static shared_ptr<_Tp> __create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl) _NOEXCEPT {
......@@ -959,7 +849,7 @@ private:
959849template <class _Array, class _Alloc, class... _Arg>
960850_LIBCPP_HIDE_FROM_ABI shared_ptr<_Array>
961851__allocate_shared_unbounded_array(const _Alloc& __a, size_t __n, _Arg&&... __arg) {
962 static_assert(__libcpp_is_unbounded_array<_Array>::value);
852 static_assert(__is_unbounded_array_v<_Array>);
963853 // We compute the number of bytes necessary to hold the control block and the
964854 // array elements. Then, we allocate an array of properly-aligned dummy structs
965855 // large enough to hold the control block and array. This allows shifting the
......@@ -1036,7 +926,7 @@ private:
1036926
1037927template <class _Array, class _Alloc, class... _Arg>
1038928_LIBCPP_HIDE_FROM_ABI shared_ptr<_Array> __allocate_shared_bounded_array(const _Alloc& __a, _Arg&&... __arg) {
1039 static_assert(__libcpp_is_bounded_array<_Array>::value);
929 static_assert(__is_bounded_array_v<_Array>);
1040930 using _ControlBlock = __bounded_array_control_block<_Array, _Alloc>;
1041931 using _ControlBlockAlloc = __allocator_traits_rebind_t<_Alloc, _ControlBlock>;
1042932
......@@ -1301,14 +1191,14 @@ _LIBCPP_HIDE_FROM_ABI shared_ptr<_Tp> reinterpret_pointer_cast(shared_ptr<_Up>&&
13011191}
13021192#endif
13031193
1304#ifndef _LIBCPP_HAS_NO_RTTI
1194#if _LIBCPP_HAS_RTTI
13051195
13061196template <class _Dp, class _Tp>
13071197inline _LIBCPP_HIDE_FROM_ABI _Dp* get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT {
13081198 return __p.template __get_deleter<_Dp>();
13091199}
13101200
1311#endif // _LIBCPP_HAS_NO_RTTI
1201#endif // _LIBCPP_HAS_RTTI
13121202
13131203template <class _Tp>
13141204class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS weak_ptr {
......@@ -1321,7 +1211,7 @@ public:
13211211
13221212 // A weak_ptr contains only two raw pointers which point to the heap and move constructing already doesn't require
13231213 // any bookkeeping, so it's always trivially relocatable.
1324 using __trivially_relocatable = weak_ptr;
1214 using __trivially_relocatable _LIBCPP_NODEBUG = weak_ptr;
13251215
13261216private:
13271217 element_type* __ptr_;
......@@ -1583,7 +1473,7 @@ template <class _CharT, class _Traits, class _Yp>
15831473inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
15841474operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
15851475
1586#if !defined(_LIBCPP_HAS_NO_THREADS)
1476#if _LIBCPP_HAS_THREADS
15871477
15881478class _LIBCPP_EXPORTED_FROM_ABI __sp_mut {
15891479 void* __lx_;
......@@ -1685,7 +1575,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_weak_explicit(
16851575 return std::atomic_compare_exchange_weak(__p, __v, __w);
16861576}
16871577
1688#endif // !defined(_LIBCPP_HAS_NO_THREADS)
1578#endif // _LIBCPP_HAS_THREADS
16891579
16901580_LIBCPP_END_NAMESPACE_STD
16911581
lib/libcxx/include/__memory/temporary_buffer.h+13-43
......@@ -11,65 +11,35 @@
1111#define _LIBCPP___MEMORY_TEMPORARY_BUFFER_H
1212
1313#include <__config>
14#include <__cstddef/ptrdiff_t.h>
15#include <__memory/unique_temporary_buffer.h>
1416#include <__utility/pair.h>
15#include <cstddef>
16#include <new>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1919# pragma GCC system_header
2020#endif
2121
22#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER)
23
2224_LIBCPP_BEGIN_NAMESPACE_STD
2325
2426template <class _Tp>
25_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _LIBCPP_DEPRECATED_IN_CXX17 pair<_Tp*, ptrdiff_t>
27[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _LIBCPP_DEPRECATED_IN_CXX17 pair<_Tp*, ptrdiff_t>
2628get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT {
27 pair<_Tp*, ptrdiff_t> __r(0, 0);
28 const ptrdiff_t __m =
29 (~ptrdiff_t(0) ^ ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1))) / sizeof(_Tp);
30 if (__n > __m)
31 __n = __m;
32 while (__n > 0) {
33#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
34 if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) {
35 align_val_t __al = align_val_t(_LIBCPP_ALIGNOF(_Tp));
36 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), __al, nothrow));
37 } else {
38 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
39 }
40#else
41 if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) {
42 // Since aligned operator new is unavailable, return an empty
43 // buffer rather than one with invalid alignment.
44 return __r;
45 }
46
47 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
48#endif
49
50 if (__r.first) {
51 __r.second = __n;
52 break;
53 }
54 __n /= 2;
55 }
56 return __r;
29 __unique_temporary_buffer<_Tp> __unique_buf = std::__allocate_unique_temporary_buffer<_Tp>(__n);
30 pair<_Tp*, ptrdiff_t> __result(__unique_buf.get(), __unique_buf.get_deleter().__count_);
31 __unique_buf.release();
32 return __result;
5733}
5834
5935template <class _Tp>
6036inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 void return_temporary_buffer(_Tp* __p) _NOEXCEPT {
61 std::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp));
37 __unique_temporary_buffer<_Tp> __unique_buf(__p);
38 (void)__unique_buf;
6239}
6340
64struct __return_temporary_buffer {
65 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
66 template <class _Tp>
67 _LIBCPP_HIDE_FROM_ABI void operator()(_Tp* __p) const {
68 std::return_temporary_buffer(__p);
69 }
70 _LIBCPP_SUPPRESS_DEPRECATED_POP
71};
72
7341_LIBCPP_END_NAMESPACE_STD
7442
43#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER)
44
7545#endif // _LIBCPP___MEMORY_TEMPORARY_BUFFER_H
lib/libcxx/include/__memory/uninitialized_algorithms.h+61-59
......@@ -15,16 +15,18 @@
1515#include <__algorithm/unwrap_iter.h>
1616#include <__algorithm/unwrap_range.h>
1717#include <__config>
18#include <__cstddef/size_t.h>
1819#include <__iterator/iterator_traits.h>
1920#include <__iterator/reverse_iterator.h>
2021#include <__memory/addressof.h>
2122#include <__memory/allocator_traits.h>
2223#include <__memory/construct_at.h>
2324#include <__memory/pointer_traits.h>
24#include <__memory/voidify.h>
25#include <__type_traits/enable_if.h>
2526#include <__type_traits/extent.h>
2627#include <__type_traits/is_array.h>
2728#include <__type_traits/is_constant_evaluated.h>
29#include <__type_traits/is_same.h>
2830#include <__type_traits/is_trivially_assignable.h>
2931#include <__type_traits/is_trivially_constructible.h>
3032#include <__type_traits/is_trivially_relocatable.h>
......@@ -35,7 +37,6 @@
3537#include <__utility/exception_guard.h>
3638#include <__utility/move.h>
3739#include <__utility/pair.h>
38#include <new>
3940
4041#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4142# pragma GCC system_header
......@@ -59,12 +60,12 @@ template <class _ValueType, class _InputIterator, class _Sentinel1, class _Forwa
5960inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitialized_copy(
6061 _InputIterator __ifirst, _Sentinel1 __ilast, _ForwardIterator __ofirst, _EndPredicate __stop_copying) {
6162 _ForwardIterator __idx = __ofirst;
62#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
63#if _LIBCPP_HAS_EXCEPTIONS
6364 try {
6465#endif
6566 for (; __ifirst != __ilast && !__stop_copying(__idx); ++__ifirst, (void)++__idx)
66 ::new (std::__voidify(*__idx)) _ValueType(*__ifirst);
67#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
67 ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(*__ifirst);
68#if _LIBCPP_HAS_EXCEPTIONS
6869 } catch (...) {
6970 std::__destroy(__ofirst, __idx);
7071 throw;
......@@ -89,12 +90,12 @@ template <class _ValueType, class _InputIterator, class _Size, class _ForwardIte
8990inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator>
9091__uninitialized_copy_n(_InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst, _EndPredicate __stop_copying) {
9192 _ForwardIterator __idx = __ofirst;
92#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
93#if _LIBCPP_HAS_EXCEPTIONS
9394 try {
9495#endif
9596 for (; __n > 0 && !__stop_copying(__idx); ++__ifirst, (void)++__idx, (void)--__n)
96 ::new (std::__voidify(*__idx)) _ValueType(*__ifirst);
97#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
97 ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(*__ifirst);
98#if _LIBCPP_HAS_EXCEPTIONS
9899 } catch (...) {
99100 std::__destroy(__ofirst, __idx);
100101 throw;
......@@ -119,12 +120,12 @@ template <class _ValueType, class _ForwardIterator, class _Sentinel, class _Tp>
119120inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator
120121__uninitialized_fill(_ForwardIterator __first, _Sentinel __last, const _Tp& __x) {
121122 _ForwardIterator __idx = __first;
122#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
123#if _LIBCPP_HAS_EXCEPTIONS
123124 try {
124125#endif
125126 for (; __idx != __last; ++__idx)
126 ::new (std::__voidify(*__idx)) _ValueType(__x);
127#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
127 ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__x);
128#if _LIBCPP_HAS_EXCEPTIONS
128129 } catch (...) {
129130 std::__destroy(__first, __idx);
130131 throw;
......@@ -147,12 +148,12 @@ template <class _ValueType, class _ForwardIterator, class _Size, class _Tp>
147148inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator
148149__uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) {
149150 _ForwardIterator __idx = __first;
150#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
151#if _LIBCPP_HAS_EXCEPTIONS
151152 try {
152153#endif
153154 for (; __n > 0; ++__idx, (void)--__n)
154 ::new (std::__voidify(*__idx)) _ValueType(__x);
155#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
155 ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__x);
156#if _LIBCPP_HAS_EXCEPTIONS
156157 } catch (...) {
157158 std::__destroy(__first, __idx);
158159 throw;
......@@ -177,12 +178,12 @@ template <class _ValueType, class _ForwardIterator, class _Sentinel>
177178inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator
178179__uninitialized_default_construct(_ForwardIterator __first, _Sentinel __last) {
179180 auto __idx = __first;
180# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
181# if _LIBCPP_HAS_EXCEPTIONS
181182 try {
182183# endif
183184 for (; __idx != __last; ++__idx)
184 ::new (std::__voidify(*__idx)) _ValueType;
185# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
185 ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType;
186# if _LIBCPP_HAS_EXCEPTIONS
186187 } catch (...) {
187188 std::__destroy(__first, __idx);
188189 throw;
......@@ -203,12 +204,12 @@ inline _LIBCPP_HIDE_FROM_ABI void uninitialized_default_construct(_ForwardIterat
203204template <class _ValueType, class _ForwardIterator, class _Size>
204205inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
205206 auto __idx = __first;
206# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
207# if _LIBCPP_HAS_EXCEPTIONS
207208 try {
208209# endif
209210 for (; __n > 0; ++__idx, (void)--__n)
210 ::new (std::__voidify(*__idx)) _ValueType;
211# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
211 ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType;
212# if _LIBCPP_HAS_EXCEPTIONS
212213 } catch (...) {
213214 std::__destroy(__first, __idx);
214215 throw;
......@@ -230,12 +231,12 @@ template <class _ValueType, class _ForwardIterator, class _Sentinel>
230231inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator
231232__uninitialized_value_construct(_ForwardIterator __first, _Sentinel __last) {
232233 auto __idx = __first;
233# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
234# if _LIBCPP_HAS_EXCEPTIONS
234235 try {
235236# endif
236237 for (; __idx != __last; ++__idx)
237 ::new (std::__voidify(*__idx)) _ValueType();
238# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
238 ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType();
239# if _LIBCPP_HAS_EXCEPTIONS
239240 } catch (...) {
240241 std::__destroy(__first, __idx);
241242 throw;
......@@ -256,12 +257,12 @@ inline _LIBCPP_HIDE_FROM_ABI void uninitialized_value_construct(_ForwardIterator
256257template <class _ValueType, class _ForwardIterator, class _Size>
257258inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator __uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
258259 auto __idx = __first;
259# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
260# if _LIBCPP_HAS_EXCEPTIONS
260261 try {
261262# endif
262263 for (; __n > 0; ++__idx, (void)--__n)
263 ::new (std::__voidify(*__idx)) _ValueType();
264# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
264 ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType();
265# if _LIBCPP_HAS_EXCEPTIONS
265266 } catch (...) {
266267 std::__destroy(__first, __idx);
267268 throw;
......@@ -292,13 +293,13 @@ inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitiali
292293 _EndPredicate __stop_moving,
293294 _IterMove __iter_move) {
294295 auto __idx = __ofirst;
295# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
296# if _LIBCPP_HAS_EXCEPTIONS
296297 try {
297298# endif
298299 for (; __ifirst != __ilast && !__stop_moving(__idx); ++__idx, (void)++__ifirst) {
299 ::new (std::__voidify(*__idx)) _ValueType(__iter_move(__ifirst));
300 ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__iter_move(__ifirst));
300301 }
301# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
302# if _LIBCPP_HAS_EXCEPTIONS
302303 } catch (...) {
303304 std::__destroy(__ofirst, __idx);
304305 throw;
......@@ -330,12 +331,12 @@ template <class _ValueType,
330331inline _LIBCPP_HIDE_FROM_ABI pair<_InputIterator, _ForwardIterator> __uninitialized_move_n(
331332 _InputIterator __ifirst, _Size __n, _ForwardIterator __ofirst, _EndPredicate __stop_moving, _IterMove __iter_move) {
332333 auto __idx = __ofirst;
333# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
334# if _LIBCPP_HAS_EXCEPTIONS
334335 try {
335336# endif
336337 for (; __n > 0 && !__stop_moving(__idx); ++__idx, (void)++__ifirst, --__n)
337 ::new (std::__voidify(*__idx)) _ValueType(__iter_move(__ifirst));
338# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
338 ::new (static_cast<void*>(std::addressof(*__idx))) _ValueType(__iter_move(__ifirst));
339# if _LIBCPP_HAS_EXCEPTIONS
339340 } catch (...) {
340341 std::__destroy(__ofirst, __idx);
341342 throw;
......@@ -375,7 +376,7 @@ __allocator_destroy_multidimensional(_Alloc& __alloc, _BidirIter __first, _Bidir
375376 return;
376377
377378 if constexpr (is_array_v<_ValueType>) {
378 static_assert(!__libcpp_is_unbounded_array<_ValueType>::value,
379 static_assert(!__is_unbounded_array_v<_ValueType>,
379380 "arrays of unbounded arrays don't exist, but if they did we would mess up here");
380381
381382 using _Element = remove_extent_t<_ValueType>;
......@@ -562,17 +563,13 @@ struct __allocator_has_trivial_copy_construct<allocator<_Type>, _Type> : true_ty
562563
563564template <class _Alloc,
564565 class _In,
565 class _RawTypeIn = __remove_const_t<_In>,
566566 class _Out,
567 __enable_if_t<
568 // using _RawTypeIn because of the allocator<T const> extension
569 is_trivially_copy_constructible<_RawTypeIn>::value && is_trivially_copy_assignable<_RawTypeIn>::value &&
570 is_same<__remove_const_t<_In>, __remove_const_t<_Out> >::value &&
571 __allocator_has_trivial_copy_construct<_Alloc, _RawTypeIn>::value,
572 int> = 0>
567 __enable_if_t<is_trivially_copy_constructible<_In>::value && is_trivially_copy_assignable<_In>::value &&
568 is_same<__remove_const_t<_In>, __remove_const_t<_Out> >::value &&
569 __allocator_has_trivial_copy_construct<_Alloc, _In>::value,
570 int> = 0>
573571_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Out*
574572__uninitialized_allocator_copy_impl(_Alloc&, _In* __first1, _In* __last1, _Out* __first2) {
575 // TODO: Remove the const_cast once we drop support for std::allocator<T const>
576573 if (__libcpp_is_constant_evaluated()) {
577574 while (__first1 != __last1) {
578575 std::__construct_at(std::__to_address(__first2), *__first1);
......@@ -581,16 +578,16 @@ __uninitialized_allocator_copy_impl(_Alloc&, _In* __first1, _In* __last1, _Out*
581578 }
582579 return __first2;
583580 } else {
584 return std::copy(__first1, __last1, const_cast<_RawTypeIn*>(__first2));
581 return std::copy(__first1, __last1, __first2);
585582 }
586583}
587584
588585template <class _Alloc, class _Iter1, class _Sent1, class _Iter2>
589586_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter2
590587__uninitialized_allocator_copy(_Alloc& __alloc, _Iter1 __first1, _Sent1 __last1, _Iter2 __first2) {
591 auto __unwrapped_range = std::__unwrap_range(__first1, __last1);
588 auto __unwrapped_range = std::__unwrap_range(std::move(__first1), std::move(__last1));
592589 auto __result = std::__uninitialized_allocator_copy_impl(
593 __alloc, __unwrapped_range.first, __unwrapped_range.second, std::__unwrap_iter(__first2));
590 __alloc, std::move(__unwrapped_range.first), std::move(__unwrapped_range.second), std::__unwrap_iter(__first2));
594591 return std::__rewrap_iter(__first2, __result);
595592}
596593
......@@ -615,26 +612,28 @@ struct __allocator_has_trivial_destroy<allocator<_Tp>, _Up> : true_type {};
615612// [__first, __last) doesn't contain any objects
616613//
617614// The strong exception guarantee is provided if any of the following are true:
618// - is_nothrow_move_constructible<_Tp>
619// - is_copy_constructible<_Tp>
620// - __libcpp_is_trivially_relocatable<_Tp>
621template <class _Alloc, class _Tp>
622_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
623__uninitialized_allocator_relocate(_Alloc& __alloc, _Tp* __first, _Tp* __last, _Tp* __result) {
615// - is_nothrow_move_constructible<_ValueType>
616// - is_copy_constructible<_ValueType>
617// - __libcpp_is_trivially_relocatable<_ValueType>
618template <class _Alloc, class _ContiguousIterator>
619_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __uninitialized_allocator_relocate(
620 _Alloc& __alloc, _ContiguousIterator __first, _ContiguousIterator __last, _ContiguousIterator __result) {
621 static_assert(__libcpp_is_contiguous_iterator<_ContiguousIterator>::value, "");
622 using _ValueType = typename iterator_traits<_ContiguousIterator>::value_type;
624623 static_assert(__is_cpp17_move_insertable<_Alloc>::value,
625624 "The specified type does not meet the requirements of Cpp17MoveInsertable");
626 if (__libcpp_is_constant_evaluated() || !__libcpp_is_trivially_relocatable<_Tp>::value ||
627 !__allocator_has_trivial_move_construct<_Alloc, _Tp>::value ||
628 !__allocator_has_trivial_destroy<_Alloc, _Tp>::value) {
625 if (__libcpp_is_constant_evaluated() || !__libcpp_is_trivially_relocatable<_ValueType>::value ||
626 !__allocator_has_trivial_move_construct<_Alloc, _ValueType>::value ||
627 !__allocator_has_trivial_destroy<_Alloc, _ValueType>::value) {
629628 auto __destruct_first = __result;
630 auto __guard =
631 std::__make_exception_guard(_AllocatorDestroyRangeReverse<_Alloc, _Tp*>(__alloc, __destruct_first, __result));
629 auto __guard = std::__make_exception_guard(
630 _AllocatorDestroyRangeReverse<_Alloc, _ContiguousIterator>(__alloc, __destruct_first, __result));
632631 auto __iter = __first;
633632 while (__iter != __last) {
634#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
635 allocator_traits<_Alloc>::construct(__alloc, __result, std::move_if_noexcept(*__iter));
633#if _LIBCPP_HAS_EXCEPTIONS
634 allocator_traits<_Alloc>::construct(__alloc, std::__to_address(__result), std::move_if_noexcept(*__iter));
636635#else
637 allocator_traits<_Alloc>::construct(__alloc, __result, std::move(*__iter));
636 allocator_traits<_Alloc>::construct(__alloc, std::__to_address(__result), std::move(*__iter));
638637#endif
639638 ++__iter;
640639 ++__result;
......@@ -642,7 +641,10 @@ __uninitialized_allocator_relocate(_Alloc& __alloc, _Tp* __first, _Tp* __last, _
642641 __guard.__complete();
643642 std::__allocator_destroy(__alloc, __first, __last);
644643 } else {
645 __builtin_memcpy(const_cast<__remove_const_t<_Tp>*>(__result), __first, sizeof(_Tp) * (__last - __first));
644 // Casting to void* to suppress clang complaining that this is technically UB.
645 __builtin_memcpy(static_cast<void*>(std::__to_address(__result)),
646 std::__to_address(__first),
647 sizeof(_ValueType) * (__last - __first));
646648 }
647649}
648650
lib/libcxx/include/__memory/unique_ptr.h+243-113
......@@ -10,22 +10,30 @@
1010#ifndef _LIBCPP___MEMORY_UNIQUE_PTR_H
1111#define _LIBCPP___MEMORY_UNIQUE_PTR_H
1212
13#include <__assert>
1314#include <__compare/compare_three_way.h>
1415#include <__compare/compare_three_way_result.h>
1516#include <__compare/three_way_comparable.h>
1617#include <__config>
18#include <__cstddef/nullptr_t.h>
19#include <__cstddef/size_t.h>
1720#include <__functional/hash.h>
1821#include <__functional/operations.h>
1922#include <__memory/allocator_traits.h> // __pointer
23#include <__memory/array_cookie.h>
2024#include <__memory/auto_ptr.h>
2125#include <__memory/compressed_pair.h>
26#include <__memory/pointer_traits.h>
2227#include <__type_traits/add_lvalue_reference.h>
2328#include <__type_traits/common_type.h>
2429#include <__type_traits/conditional.h>
2530#include <__type_traits/dependent_type.h>
31#include <__type_traits/enable_if.h>
2632#include <__type_traits/integral_constant.h>
2733#include <__type_traits/is_array.h>
2834#include <__type_traits/is_assignable.h>
35#include <__type_traits/is_bounded_array.h>
36#include <__type_traits/is_constant_evaluated.h>
2937#include <__type_traits/is_constructible.h>
3038#include <__type_traits/is_convertible.h>
3139#include <__type_traits/is_function.h>
......@@ -34,14 +42,15 @@
3442#include <__type_traits/is_same.h>
3543#include <__type_traits/is_swappable.h>
3644#include <__type_traits/is_trivially_relocatable.h>
45#include <__type_traits/is_unbounded_array.h>
3746#include <__type_traits/is_void.h>
3847#include <__type_traits/remove_extent.h>
39#include <__type_traits/remove_pointer.h>
4048#include <__type_traits/type_identity.h>
4149#include <__utility/declval.h>
4250#include <__utility/forward.h>
4351#include <__utility/move.h>
44#include <cstddef>
52#include <__utility/private_constructor_tag.h>
53#include <cstdint>
4554
4655#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4756# pragma GCC system_header
......@@ -52,17 +61,6 @@ _LIBCPP_PUSH_MACROS
5261
5362_LIBCPP_BEGIN_NAMESPACE_STD
5463
55#ifndef _LIBCPP_CXX03_LANG
56
57template <class _Ptr>
58struct __is_noexcept_deref_or_void {
59 static constexpr bool value = noexcept(*std::declval<_Ptr>());
60};
61
62template <>
63struct __is_noexcept_deref_or_void<void*> : true_type {};
64#endif
65
6664template <class _Tp>
6765struct _LIBCPP_TEMPLATE_VIS default_delete {
6866 static_assert(!is_function<_Tp>::value, "default_delete cannot be instantiated for function types");
......@@ -106,6 +104,12 @@ public:
106104 }
107105};
108106
107template <class _Deleter>
108struct __is_default_deleter : false_type {};
109
110template <class _Tp>
111struct __is_default_deleter<default_delete<_Tp> > : true_type {};
112
109113template <class _Deleter>
110114struct __unique_ptr_deleter_sfinae {
111115 static_assert(!is_reference<_Deleter>::value, "incorrect specialization");
......@@ -139,7 +143,7 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr {
139143public:
140144 typedef _Tp element_type;
141145 typedef _Dp deleter_type;
142 typedef _LIBCPP_NODEBUG typename __pointer<_Tp, deleter_type>::type pointer;
146 using pointer _LIBCPP_NODEBUG = __pointer<_Tp, deleter_type>;
143147
144148 static_assert(!is_rvalue_reference<deleter_type>::value, "the specified deleter type cannot be an rvalue reference");
145149
......@@ -149,15 +153,15 @@ public:
149153 //
150154 // This unique_ptr implementation only contains a pointer to the unique object and a deleter, so there are no
151155 // references to itself. This means that the entire structure is trivially relocatable if its members are.
152 using __trivially_relocatable = __conditional_t<
156 using __trivially_relocatable _LIBCPP_NODEBUG = __conditional_t<
153157 __libcpp_is_trivially_relocatable<pointer>::value && __libcpp_is_trivially_relocatable<deleter_type>::value,
154158 unique_ptr,
155159 void>;
156160
157161private:
158 __compressed_pair<pointer, deleter_type> __ptr_;
162 _LIBCPP_COMPRESSED_PAIR(pointer, __ptr_, deleter_type, __deleter_);
159163
160 typedef _LIBCPP_NODEBUG __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
164 using _DeleterSFINAE _LIBCPP_NODEBUG = __unique_ptr_deleter_sfinae<_Dp>;
161165
162166 template <bool _Dummy>
163167 using _LValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
......@@ -185,27 +189,29 @@ private:
185189 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) >;
186190
187191 template <class _UDel>
188 using _EnableIfDeleterAssignable = __enable_if_t< is_assignable<_Dp&, _UDel&&>::value >;
192 using _EnableIfDeleterAssignable _LIBCPP_NODEBUG = __enable_if_t< is_assignable<_Dp&, _UDel&&>::value >;
189193
190194public:
191195 template <bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy> >
192 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {}
196 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(), __deleter_() {}
193197
194198 template <bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy> >
195 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
196 : __ptr_(__value_init_tag(), __value_init_tag()) {}
199 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(), __deleter_() {}
197200
198201 template <bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy> >
199 _LIBCPP_HIDE_FROM_ABI
200 _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p, __value_init_tag()) {}
202 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit unique_ptr(pointer __p) _NOEXCEPT
203 : __ptr_(__p),
204 __deleter_() {}
201205
202206 template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
203207 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPT
204 : __ptr_(__p, __d) {}
208 : __ptr_(__p),
209 __deleter_(__d) {}
205210
206211 template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > >
207212 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
208 : __ptr_(__p, std::move(__d)) {
213 : __ptr_(__p),
214 __deleter_(std::move(__d)) {
209215 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
210216 }
211217
......@@ -213,24 +219,26 @@ public:
213219 _LIBCPP_HIDE_FROM_ABI unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete;
214220
215221 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr&& __u) _NOEXCEPT
216 : __ptr_(__u.release(), std::forward<deleter_type>(__u.get_deleter())) {}
222 : __ptr_(__u.release()),
223 __deleter_(std::forward<deleter_type>(__u.get_deleter())) {}
217224
218225 template <class _Up,
219226 class _Ep,
220227 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
221228 class = _EnableIfDeleterConvertible<_Ep> >
222229 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
223 : __ptr_(__u.release(), std::forward<_Ep>(__u.get_deleter())) {}
230 : __ptr_(__u.release()),
231 __deleter_(std::forward<_Ep>(__u.get_deleter())) {}
224232
225233#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
226234 template <class _Up,
227235 __enable_if_t<is_convertible<_Up*, _Tp*>::value && is_same<_Dp, default_delete<_Tp> >::value, int> = 0>
228 _LIBCPP_HIDE_FROM_ABI unique_ptr(auto_ptr<_Up>&& __p) _NOEXCEPT : __ptr_(__p.release(), __value_init_tag()) {}
236 _LIBCPP_HIDE_FROM_ABI unique_ptr(auto_ptr<_Up>&& __p) _NOEXCEPT : __ptr_(__p.release()), __deleter_() {}
229237#endif
230238
231239 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
232240 reset(__u.release());
233 __ptr_.second() = std::forward<deleter_type>(__u.get_deleter());
241 __deleter_ = std::forward<deleter_type>(__u.get_deleter());
234242 return *this;
235243 }
236244
......@@ -240,7 +248,7 @@ public:
240248 class = _EnableIfDeleterAssignable<_Ep> >
241249 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
242250 reset(__u.release());
243 __ptr_.second() = std::forward<_Ep>(__u.get_deleter());
251 __deleter_ = std::forward<_Ep>(__u.get_deleter());
244252 return *this;
245253 }
246254
......@@ -266,33 +274,135 @@ public:
266274 }
267275
268276 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __add_lvalue_reference_t<_Tp> operator*() const
269 _NOEXCEPT_(__is_noexcept_deref_or_void<pointer>::value) {
270 return *__ptr_.first();
277 _NOEXCEPT_(_NOEXCEPT_(*std::declval<pointer>())) {
278 return *__ptr_;
271279 }
272 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer operator->() const _NOEXCEPT { return __ptr_.first(); }
273 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT { return __ptr_.first(); }
274 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 deleter_type& get_deleter() _NOEXCEPT { return __ptr_.second(); }
280 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer operator->() const _NOEXCEPT { return __ptr_; }
281 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT { return __ptr_; }
282 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 deleter_type& get_deleter() _NOEXCEPT { return __deleter_; }
275283 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const deleter_type& get_deleter() const _NOEXCEPT {
276 return __ptr_.second();
284 return __deleter_;
277285 }
278286 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit operator bool() const _NOEXCEPT {
279 return __ptr_.first() != nullptr;
287 return __ptr_ != nullptr;
280288 }
281289
282290 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer release() _NOEXCEPT {
283 pointer __t = __ptr_.first();
284 __ptr_.first() = pointer();
291 pointer __t = __ptr_;
292 __ptr_ = pointer();
285293 return __t;
286294 }
287295
288296 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void reset(pointer __p = pointer()) _NOEXCEPT {
289 pointer __tmp = __ptr_.first();
290 __ptr_.first() = __p;
297 pointer __tmp = __ptr_;
298 __ptr_ = __p;
291299 if (__tmp)
292 __ptr_.second()(__tmp);
300 __deleter_(__tmp);
293301 }
294302
295 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void swap(unique_ptr& __u) _NOEXCEPT { __ptr_.swap(__u.__ptr_); }
303 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void swap(unique_ptr& __u) _NOEXCEPT {
304 using std::swap;
305 swap(__ptr_, __u.__ptr_);
306 swap(__deleter_, __u.__deleter_);
307 }
308};
309
310// Bounds checking in unique_ptr<T[]>
311// ==================================
312//
313// We provide some helper classes that allow bounds checking when accessing a unique_ptr<T[]>.
314// There are a few cases where bounds checking can be implemented:
315//
316// 1. When an array cookie (see [1]) exists at the beginning of the array allocation, we are
317// able to reuse that cookie to extract the size of the array and perform bounds checking.
318// An array cookie is a size inserted at the beginning of the allocation by the compiler.
319// That size is inserted implicitly when doing `new T[n]` in some cases (as of writing this
320// exactly when the array elements are not trivially destructible), and its main purpose is
321// to allow the runtime to destroy the `n` array elements when doing `delete[] array`.
322// When we are able to use array cookies, we reuse information already available in the
323// current runtime, so bounds checking does not require changing libc++'s ABI.
324//
325// However, note that we cannot assume the presence of an array cookie when a custom deleter
326// is used, because the unique_ptr could have been created from an allocation that wasn't
327// obtained via `new T[n]` (since it may not be deleted with `delete[] arr`).
328//
329// 2. When the "bounded unique_ptr" ABI configuration (controlled by `_LIBCPP_ABI_BOUNDED_UNIQUE_PTR`)
330// is enabled, we store the size of the allocation (when it is known) so we can check it when
331// indexing into the `unique_ptr`. That changes the layout of `std::unique_ptr<T[]>`, which is
332// an ABI break from the default configuration.
333//
334// Note that even under this ABI configuration, we can't always know the size of the unique_ptr.
335// Indeed, the size of the allocation can only be known when the unique_ptr is created via
336// make_unique or a similar API. For example, it can't be known when constructed from an arbitrary
337// pointer, in which case we are not able to check the bounds on access:
338//
339// unique_ptr<T[], MyDeleter> ptr(new T[3]);
340//
341// When we don't know the size of the allocation via the API used to create the unique_ptr, we
342// try to fall back to using an array cookie when available.
343//
344// Finally, note that when this ABI configuration is enabled, we have no choice but to always
345// make space for the size to be stored in the unique_ptr. Indeed, while we might want to avoid
346// storing the size when an array cookie is available, knowing whether an array cookie is available
347// requires the type stored in the unique_ptr to be complete, while unique_ptr can normally
348// accommodate incomplete types.
349//
350// (1) Implementation where we rely on the array cookie to know the size of the allocation, if
351// an array cookie exists.
352struct __unique_ptr_array_bounds_stateless {
353 __unique_ptr_array_bounds_stateless() = default;
354 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __unique_ptr_array_bounds_stateless(size_t) {}
355
356 template <class _Deleter,
357 class _Tp,
358 __enable_if_t<__is_default_deleter<_Deleter>::value && __has_array_cookie<_Tp>::value, int> = 0>
359 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __in_bounds(_Tp* __ptr, size_t __index) const {
360 // In constant expressions, we can't check the array cookie so we just pretend that the index
361 // is in-bounds. The compiler catches invalid accesses anyway.
362 if (__libcpp_is_constant_evaluated())
363 return true;
364 size_t __cookie = std::__get_array_cookie(__ptr);
365 return __index < __cookie;
366 }
367
368 template <class _Deleter,
369 class _Tp,
370 __enable_if_t<!__is_default_deleter<_Deleter>::value || !__has_array_cookie<_Tp>::value, int> = 0>
371 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __in_bounds(_Tp*, size_t) const {
372 return true; // If we don't have an array cookie, we assume the access is in-bounds
373 }
374};
375
376// (2) Implementation where we store the size in the class whenever we have it.
377//
378// Semantically, we'd need to store the size as an optional<size_t>. However, since that
379// is really heavy weight, we instead store a size_t and use SIZE_MAX as a magic value
380// meaning that we don't know the size.
381struct __unique_ptr_array_bounds_stored {
382 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __unique_ptr_array_bounds_stored() : __size_(SIZE_MAX) {}
383 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __unique_ptr_array_bounds_stored(size_t __size) : __size_(__size) {}
384
385 // Use the array cookie if there's one
386 template <class _Deleter,
387 class _Tp,
388 __enable_if_t<__is_default_deleter<_Deleter>::value && __has_array_cookie<_Tp>::value, int> = 0>
389 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __in_bounds(_Tp* __ptr, size_t __index) const {
390 if (__libcpp_is_constant_evaluated())
391 return true;
392 size_t __cookie = std::__get_array_cookie(__ptr);
393 return __index < __cookie;
394 }
395
396 // Otherwise, fall back on the stored size (if any)
397 template <class _Deleter,
398 class _Tp,
399 __enable_if_t<!__is_default_deleter<_Deleter>::value || !__has_array_cookie<_Tp>::value, int> = 0>
400 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __in_bounds(_Tp*, size_t __index) const {
401 return __index < __size_;
402 }
403
404private:
405 size_t __size_;
296406};
297407
298408template <class _Tp, class _Dp>
......@@ -300,21 +410,31 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp>
300410public:
301411 typedef _Tp element_type;
302412 typedef _Dp deleter_type;
303 typedef typename __pointer<_Tp, deleter_type>::type pointer;
413 using pointer = __pointer<_Tp, deleter_type>;
304414
305415 // A unique_ptr contains the following members which may be trivially relocatable:
306 // - pointer : this may be trivially relocatable, so it's checked
416 // - pointer: this may be trivially relocatable, so it's checked
307417 // - deleter_type: this may be trivially relocatable, so it's checked
418 // - (optionally) size: this is trivially relocatable
308419 //
309420 // This unique_ptr implementation only contains a pointer to the unique object and a deleter, so there are no
310421 // references to itself. This means that the entire structure is trivially relocatable if its members are.
311 using __trivially_relocatable = __conditional_t<
422 using __trivially_relocatable _LIBCPP_NODEBUG = __conditional_t<
312423 __libcpp_is_trivially_relocatable<pointer>::value && __libcpp_is_trivially_relocatable<deleter_type>::value,
313424 unique_ptr,
314425 void>;
315426
316427private:
317 __compressed_pair<pointer, deleter_type> __ptr_;
428 template <class _Up, class _OtherDeleter>
429 friend class unique_ptr;
430
431 _LIBCPP_COMPRESSED_PAIR(pointer, __ptr_, deleter_type, __deleter_);
432#ifdef _LIBCPP_ABI_BOUNDED_UNIQUE_PTR
433 using _BoundsChecker _LIBCPP_NODEBUG = __unique_ptr_array_bounds_stored;
434#else
435 using _BoundsChecker _LIBCPP_NODEBUG = __unique_ptr_array_bounds_stateless;
436#endif
437 _LIBCPP_NO_UNIQUE_ADDRESS _BoundsChecker __checker_;
318438
319439 template <class _From>
320440 struct _CheckArrayPointerConversion : is_same<_From, pointer> {};
......@@ -363,42 +483,54 @@ private:
363483
364484public:
365485 template <bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy> >
366 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {}
486 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(), __deleter_() {}
367487
368488 template <bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy> >
369 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
370 : __ptr_(__value_init_tag(), __value_init_tag()) {}
489 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(), __deleter_() {}
371490
372491 template <class _Pp,
373492 bool _Dummy = true,
374493 class = _EnableIfDeleterDefaultConstructible<_Dummy>,
375494 class = _EnableIfPointerConvertible<_Pp> >
376 _LIBCPP_HIDE_FROM_ABI
377 _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit unique_ptr(_Pp __p) _NOEXCEPT : __ptr_(__p, __value_init_tag()) {}
495 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit unique_ptr(_Pp __ptr) _NOEXCEPT
496 : __ptr_(__ptr),
497 __deleter_() {}
498
499 // Private constructor used by make_unique & friends to pass the size that was allocated
500 template <class _Tag, class _Ptr, __enable_if_t<is_same<_Tag, __private_constructor_tag>::value, int> = 0>
501 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit unique_ptr(_Tag, _Ptr __ptr, size_t __size) _NOEXCEPT
502 : __ptr_(__ptr),
503 __checker_(__size) {}
378504
379505 template <class _Pp,
380506 bool _Dummy = true,
381507 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >,
382508 class = _EnableIfPointerConvertible<_Pp> >
383 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) _NOEXCEPT
384 : __ptr_(__p, __d) {}
509 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(_Pp __ptr, _LValRefType<_Dummy> __deleter) _NOEXCEPT
510 : __ptr_(__ptr),
511 __deleter_(__deleter) {}
385512
386513 template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
387 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) _NOEXCEPT
388 : __ptr_(nullptr, __d) {}
514 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(nullptr_t, _LValRefType<_Dummy> __deleter) _NOEXCEPT
515 : __ptr_(nullptr),
516 __deleter_(__deleter) {}
389517
390518 template <class _Pp,
391519 bool _Dummy = true,
392520 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> >,
393521 class = _EnableIfPointerConvertible<_Pp> >
394 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
395 : __ptr_(__p, std::move(__d)) {
522 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23
523 unique_ptr(_Pp __ptr, _GoodRValRefType<_Dummy> __deleter) _NOEXCEPT
524 : __ptr_(__ptr),
525 __deleter_(std::move(__deleter)) {
396526 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
397527 }
398528
399529 template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > >
400 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
401 : __ptr_(nullptr, std::move(__d)) {
530 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23
531 unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __deleter) _NOEXCEPT
532 : __ptr_(nullptr),
533 __deleter_(std::move(__deleter)) {
402534 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
403535 }
404536
......@@ -406,14 +538,17 @@ public:
406538 bool _Dummy = true,
407539 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> >,
408540 class = _EnableIfPointerConvertible<_Pp> >
409 _LIBCPP_HIDE_FROM_ABI unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete;
541 _LIBCPP_HIDE_FROM_ABI unique_ptr(_Pp __ptr, _BadRValRefType<_Dummy> __deleter) = delete;
410542
411543 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr&& __u) _NOEXCEPT
412 : __ptr_(__u.release(), std::forward<deleter_type>(__u.get_deleter())) {}
544 : __ptr_(__u.release()),
545 __deleter_(std::forward<deleter_type>(__u.get_deleter())),
546 __checker_(std::move(__u.__checker_)) {}
413547
414548 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
415549 reset(__u.release());
416 __ptr_.second() = std::forward<deleter_type>(__u.get_deleter());
550 __deleter_ = std::forward<deleter_type>(__u.get_deleter());
551 __checker_ = std::move(__u.__checker_);
417552 return *this;
418553 }
419554
......@@ -422,7 +557,9 @@ public:
422557 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
423558 class = _EnableIfDeleterConvertible<_Ep> >
424559 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
425 : __ptr_(__u.release(), std::forward<_Ep>(__u.get_deleter())) {}
560 : __ptr_(__u.release()),
561 __deleter_(std::forward<_Ep>(__u.get_deleter())),
562 __checker_(std::move(__u.__checker_)) {}
426563
427564 template <class _Up,
428565 class _Ep,
......@@ -430,7 +567,8 @@ public:
430567 class = _EnableIfDeleterAssignable<_Ep> >
431568 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
432569 reset(__u.release());
433 __ptr_.second() = std::forward<_Ep>(__u.get_deleter());
570 __deleter_ = std::forward<_Ep>(__u.get_deleter());
571 __checker_ = std::move(__u.__checker_);
434572 return *this;
435573 }
436574
......@@ -448,41 +586,52 @@ public:
448586 }
449587
450588 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __add_lvalue_reference_t<_Tp> operator[](size_t __i) const {
451 return __ptr_.first()[__i];
589 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__checker_.__in_bounds<deleter_type>(std::__to_address(__ptr_), __i),
590 "unique_ptr<T[]>::operator[](index): index out of range");
591 return __ptr_[__i];
452592 }
453 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT { return __ptr_.first(); }
593 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT { return __ptr_; }
454594
455 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 deleter_type& get_deleter() _NOEXCEPT { return __ptr_.second(); }
595 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 deleter_type& get_deleter() _NOEXCEPT { return __deleter_; }
456596
457597 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const deleter_type& get_deleter() const _NOEXCEPT {
458 return __ptr_.second();
598 return __deleter_;
459599 }
460600 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit operator bool() const _NOEXCEPT {
461 return __ptr_.first() != nullptr;
601 return __ptr_ != nullptr;
462602 }
463603
464604 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer release() _NOEXCEPT {
465 pointer __t = __ptr_.first();
466 __ptr_.first() = pointer();
605 pointer __t = __ptr_;
606 __ptr_ = pointer();
607 // The deleter and the optional bounds-checker are left unchanged. The bounds-checker
608 // will be reinitialized appropriately when/if the unique_ptr gets assigned-to or reset.
467609 return __t;
468610 }
469611
470612 template <class _Pp, __enable_if_t<_CheckArrayPointerConversion<_Pp>::value, int> = 0>
471 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void reset(_Pp __p) _NOEXCEPT {
472 pointer __tmp = __ptr_.first();
473 __ptr_.first() = __p;
613 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void reset(_Pp __ptr) _NOEXCEPT {
614 pointer __tmp = __ptr_;
615 __ptr_ = __ptr;
616 __checker_ = _BoundsChecker();
474617 if (__tmp)
475 __ptr_.second()(__tmp);
618 __deleter_(__tmp);
476619 }
477620
478621 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void reset(nullptr_t = nullptr) _NOEXCEPT {
479 pointer __tmp = __ptr_.first();
480 __ptr_.first() = nullptr;
622 pointer __tmp = __ptr_;
623 __ptr_ = nullptr;
624 __checker_ = _BoundsChecker();
481625 if (__tmp)
482 __ptr_.second()(__tmp);
626 __deleter_(__tmp);
483627 }
484628
485 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void swap(unique_ptr& __u) _NOEXCEPT { __ptr_.swap(__u.__ptr_); }
629 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void swap(unique_ptr& __u) _NOEXCEPT {
630 using std::swap;
631 swap(__ptr_, __u.__ptr_);
632 swap(__deleter_, __u.__deleter_);
633 swap(__checker_, __u.__checker_);
634 }
486635};
487636
488637template <class _Tp, class _Dp, __enable_if_t<__is_swappable_v<_Dp>, int> = 0>
......@@ -613,55 +762,36 @@ operator<=>(const unique_ptr<_T1, _D1>& __x, nullptr_t) {
613762
614763#if _LIBCPP_STD_VER >= 14
615764
616template <class _Tp>
617struct __unique_if {
618 typedef unique_ptr<_Tp> __unique_single;
619};
620
621template <class _Tp>
622struct __unique_if<_Tp[]> {
623 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
624};
625
626template <class _Tp, size_t _Np>
627struct __unique_if<_Tp[_Np]> {
628 typedef void __unique_array_known_bound;
629};
630
631template <class _Tp, class... _Args>
632inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_single
633make_unique(_Args&&... __args) {
765template <class _Tp, class... _Args, enable_if_t<!is_array<_Tp>::value, int> = 0>
766inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr<_Tp> make_unique(_Args&&... __args) {
634767 return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...));
635768}
636769
637template <class _Tp>
638inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_array_unknown_bound
639make_unique(size_t __n) {
770template <class _Tp, enable_if_t<__is_unbounded_array_v<_Tp>, int> = 0>
771inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr<_Tp> make_unique(size_t __n) {
640772 typedef __remove_extent_t<_Tp> _Up;
641 return unique_ptr<_Tp>(new _Up[__n]());
773 return unique_ptr<_Tp>(__private_constructor_tag(), new _Up[__n](), __n);
642774}
643775
644template <class _Tp, class... _Args>
645typename __unique_if<_Tp>::__unique_array_known_bound make_unique(_Args&&...) = delete;
776template <class _Tp, class... _Args, enable_if_t<__is_bounded_array_v<_Tp>, int> = 0>
777void make_unique(_Args&&...) = delete;
646778
647779#endif // _LIBCPP_STD_VER >= 14
648780
649781#if _LIBCPP_STD_VER >= 20
650782
651template <class _Tp>
652_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_single
653make_unique_for_overwrite() {
783template <class _Tp, enable_if_t<!is_array_v<_Tp>, int> = 0>
784_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr<_Tp> make_unique_for_overwrite() {
654785 return unique_ptr<_Tp>(new _Tp);
655786}
656787
657template <class _Tp>
658_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_array_unknown_bound
659make_unique_for_overwrite(size_t __n) {
660 return unique_ptr<_Tp>(new __remove_extent_t<_Tp>[__n]);
788template <class _Tp, enable_if_t<is_unbounded_array_v<_Tp>, int> = 0>
789_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr<_Tp> make_unique_for_overwrite(size_t __n) {
790 return unique_ptr<_Tp>(__private_constructor_tag(), new __remove_extent_t<_Tp>[__n], __n);
661791}
662792
663template <class _Tp, class... _Args>
664typename __unique_if<_Tp>::__unique_array_known_bound make_unique_for_overwrite(_Args&&...) = delete;
793template <class _Tp, class... _Args, enable_if_t<is_bounded_array_v<_Tp>, int> = 0>
794void make_unique_for_overwrite(_Args&&...) = delete;
665795
666796#endif // _LIBCPP_STD_VER >= 20
667797
lib/libcxx/include/__memory/unique_temporary_buffer.h created+93
......@@ -0,0 +1,93 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___MEMORY_UNIQUE_TEMPORARY_BUFFER_H
11#define _LIBCPP___MEMORY_UNIQUE_TEMPORARY_BUFFER_H
12
13#include <__assert>
14#include <__config>
15
16#include <__cstddef/ptrdiff_t.h>
17#include <__memory/allocator.h>
18#include <__memory/unique_ptr.h>
19#include <__new/allocate.h>
20#include <__new/global_new_delete.h>
21#include <__type_traits/is_constant_evaluated.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29template <class _Tp>
30struct __temporary_buffer_deleter {
31 ptrdiff_t __count_; // ignored in non-constant evaluation
32
33 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __temporary_buffer_deleter() _NOEXCEPT : __count_(0) {}
34 _LIBCPP_HIDE_FROM_ABI
35 _LIBCPP_CONSTEXPR explicit __temporary_buffer_deleter(ptrdiff_t __count) _NOEXCEPT : __count_(__count) {}
36
37 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator()(_Tp* __ptr) _NOEXCEPT {
38 if (__libcpp_is_constant_evaluated()) {
39 allocator<_Tp>().deallocate(__ptr, __count_);
40 return;
41 }
42
43 std::__libcpp_deallocate_unsized<_Tp>(__ptr);
44 }
45};
46
47template <class _Tp>
48using __unique_temporary_buffer _LIBCPP_NODEBUG = unique_ptr<_Tp, __temporary_buffer_deleter<_Tp> >;
49
50template <class _Tp>
51inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _LIBCPP_CONSTEXPR_SINCE_CXX23 __unique_temporary_buffer<_Tp>
52__allocate_unique_temporary_buffer(ptrdiff_t __count) {
53 using __deleter_type = __temporary_buffer_deleter<_Tp>;
54 using __unique_buffer_type = __unique_temporary_buffer<_Tp>;
55
56 if (__libcpp_is_constant_evaluated()) {
57 return __unique_buffer_type(allocator<_Tp>().allocate(__count), __deleter_type(__count));
58 }
59
60 _Tp* __ptr = nullptr;
61 const ptrdiff_t __max_count =
62 (~ptrdiff_t(0) ^ ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1))) / sizeof(_Tp);
63 if (__count > __max_count)
64 __count = __max_count;
65 while (__count > 0) {
66#if _LIBCPP_HAS_ALIGNED_ALLOCATION
67 if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) {
68 align_val_t __al = align_val_t(_LIBCPP_ALIGNOF(_Tp));
69 __ptr = static_cast<_Tp*>(::operator new(__count * sizeof(_Tp), __al, nothrow));
70 } else {
71 __ptr = static_cast<_Tp*>(::operator new(__count * sizeof(_Tp), nothrow));
72 }
73#else
74 if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) {
75 // Since aligned operator new is unavailable, constructs an empty buffer rather than one with invalid alignment.
76 return __unique_buffer_type();
77 }
78
79 __ptr = static_cast<_Tp*>(::operator new(__count * sizeof(_Tp), nothrow));
80#endif
81
82 if (__ptr) {
83 break;
84 }
85 __count /= 2;
86 }
87
88 return __unique_buffer_type(__ptr, __deleter_type(__count));
89}
90
91_LIBCPP_END_NAMESPACE_STD
92
93#endif // _LIBCPP___MEMORY_UNIQUE_TEMPORARY_BUFFER_H
lib/libcxx/include/__memory/uses_allocator.h+1-1
......@@ -11,8 +11,8 @@
1111#define _LIBCPP___MEMORY_USES_ALLOCATOR_H
1212
1313#include <__config>
14#include <__type_traits/integral_constant.h>
1415#include <__type_traits/is_convertible.h>
15#include <cstddef>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818# pragma GCC system_header
lib/libcxx/include/__memory/uses_allocator_construction.h+122-129
......@@ -40,104 +40,8 @@ inline constexpr bool __is_std_pair<pair<_Type1, _Type2>> = true;
4040template <class _Tp>
4141inline constexpr bool __is_cv_std_pair = __is_std_pair<remove_cv_t<_Tp>>;
4242
43template <class _Type, class _Alloc, class... _Args, __enable_if_t<!__is_cv_std_pair<_Type>, int> = 0>
44_LIBCPP_HIDE_FROM_ABI constexpr auto
45__uses_allocator_construction_args(const _Alloc& __alloc, _Args&&... __args) noexcept {
46 if constexpr (!uses_allocator_v<remove_cv_t<_Type>, _Alloc> && is_constructible_v<_Type, _Args...>) {
47 return std::forward_as_tuple(std::forward<_Args>(__args)...);
48 } else if constexpr (uses_allocator_v<remove_cv_t<_Type>, _Alloc> &&
49 is_constructible_v<_Type, allocator_arg_t, const _Alloc&, _Args...>) {
50 return tuple<allocator_arg_t, const _Alloc&, _Args&&...>(allocator_arg, __alloc, std::forward<_Args>(__args)...);
51 } else if constexpr (uses_allocator_v<remove_cv_t<_Type>, _Alloc> &&
52 is_constructible_v<_Type, _Args..., const _Alloc&>) {
53 return std::forward_as_tuple(std::forward<_Args>(__args)..., __alloc);
54 } else {
55 static_assert(
56 sizeof(_Type) + 1 == 0, "If uses_allocator_v<Type> is true, the type has to be allocator-constructible");
57 }
58}
59
60template <class _Pair, class _Alloc, class _Tuple1, class _Tuple2, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0>
61_LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(
62 const _Alloc& __alloc, piecewise_construct_t, _Tuple1&& __x, _Tuple2&& __y) noexcept {
63 return std::make_tuple(
64 piecewise_construct,
65 std::apply(
66 [&__alloc](auto&&... __args1) {
67 return std::__uses_allocator_construction_args<typename _Pair::first_type>(
68 __alloc, std::forward<decltype(__args1)>(__args1)...);
69 },
70 std::forward<_Tuple1>(__x)),
71 std::apply(
72 [&__alloc](auto&&... __args2) {
73 return std::__uses_allocator_construction_args<typename _Pair::second_type>(
74 __alloc, std::forward<decltype(__args2)>(__args2)...);
75 },
76 std::forward<_Tuple2>(__y)));
77}
78
79template <class _Pair, class _Alloc, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0>
80_LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(const _Alloc& __alloc) noexcept {
81 return std::__uses_allocator_construction_args<_Pair>(__alloc, piecewise_construct, tuple<>{}, tuple<>{});
82}
83
84template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0>
85_LIBCPP_HIDE_FROM_ABI constexpr auto
86__uses_allocator_construction_args(const _Alloc& __alloc, _Up&& __u, _Vp&& __v) noexcept {
87 return std::__uses_allocator_construction_args<_Pair>(
88 __alloc,
89 piecewise_construct,
90 std::forward_as_tuple(std::forward<_Up>(__u)),
91 std::forward_as_tuple(std::forward<_Vp>(__v)));
92}
93
94# if _LIBCPP_STD_VER >= 23
95template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0>
96_LIBCPP_HIDE_FROM_ABI constexpr auto
97__uses_allocator_construction_args(const _Alloc& __alloc, pair<_Up, _Vp>& __pair) noexcept {
98 return std::__uses_allocator_construction_args<_Pair>(
99 __alloc, piecewise_construct, std::forward_as_tuple(__pair.first), std::forward_as_tuple(__pair.second));
100}
101# endif
102
103template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0>
104_LIBCPP_HIDE_FROM_ABI constexpr auto
105__uses_allocator_construction_args(const _Alloc& __alloc, const pair<_Up, _Vp>& __pair) noexcept {
106 return std::__uses_allocator_construction_args<_Pair>(
107 __alloc, piecewise_construct, std::forward_as_tuple(__pair.first), std::forward_as_tuple(__pair.second));
108}
109
110template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0>
111_LIBCPP_HIDE_FROM_ABI constexpr auto
112__uses_allocator_construction_args(const _Alloc& __alloc, pair<_Up, _Vp>&& __pair) noexcept {
113 return std::__uses_allocator_construction_args<_Pair>(
114 __alloc,
115 piecewise_construct,
116 std::forward_as_tuple(std::get<0>(std::move(__pair))),
117 std::forward_as_tuple(std::get<1>(std::move(__pair))));
118}
119
120# if _LIBCPP_STD_VER >= 23
121template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0>
122_LIBCPP_HIDE_FROM_ABI constexpr auto
123__uses_allocator_construction_args(const _Alloc& __alloc, const pair<_Up, _Vp>&& __pair) noexcept {
124 return std::__uses_allocator_construction_args<_Pair>(
125 __alloc,
126 piecewise_construct,
127 std::forward_as_tuple(std::get<0>(std::move(__pair))),
128 std::forward_as_tuple(std::get<1>(std::move(__pair))));
129}
130
131template <class _Pair, class _Alloc, __pair_like_no_subrange _PairLike, __enable_if_t<__is_cv_std_pair<_Pair>, int> = 0>
132_LIBCPP_HIDE_FROM_ABI constexpr auto
133__uses_allocator_construction_args(const _Alloc& __alloc, _PairLike&& __p) noexcept {
134 return std::__uses_allocator_construction_args<_Pair>(
135 __alloc,
136 piecewise_construct,
137 std::forward_as_tuple(std::get<0>(std::forward<_PairLike>(__p))),
138 std::forward_as_tuple(std::get<1>(std::forward<_PairLike>(__p))));
139}
140# endif
43template <class _Tp, class = void>
44struct __uses_allocator_construction_args;
14145
14246namespace __uses_allocator_detail {
14347
......@@ -165,46 +69,135 @@ inline constexpr bool __uses_allocator_constraints = __is_cv_std_pair<_Tp> && !_
16569
16670} // namespace __uses_allocator_detail
16771
168template < class _Pair,
169 class _Alloc,
170 class _Type,
171 __enable_if_t<__uses_allocator_detail::__uses_allocator_constraints<_Pair, _Type>, int> = 0>
172_LIBCPP_HIDE_FROM_ABI constexpr auto
173__uses_allocator_construction_args(const _Alloc& __alloc, _Type&& __value) noexcept;
174
17572template <class _Type, class _Alloc, class... _Args>
17673_LIBCPP_HIDE_FROM_ABI constexpr _Type __make_obj_using_allocator(const _Alloc& __alloc, _Args&&... __args);
17774
178template < class _Pair,
179 class _Alloc,
180 class _Type,
181 __enable_if_t< __uses_allocator_detail::__uses_allocator_constraints<_Pair, _Type>, int>>
182_LIBCPP_HIDE_FROM_ABI constexpr auto
183__uses_allocator_construction_args(const _Alloc& __alloc, _Type&& __value) noexcept {
184 struct __pair_constructor {
185 using _PairMutable = remove_cv_t<_Pair>;
75template <class _Pair>
76struct __uses_allocator_construction_args<_Pair, __enable_if_t<__is_cv_std_pair<_Pair>>> {
77 template <class _Alloc, class _Tuple1, class _Tuple2>
78 static _LIBCPP_HIDE_FROM_ABI constexpr auto
79 __apply(const _Alloc& __alloc, piecewise_construct_t, _Tuple1&& __x, _Tuple2&& __y) noexcept {
80 return std::make_tuple(
81 piecewise_construct,
82 std::apply(
83 [&__alloc](auto&&... __args1) {
84 return __uses_allocator_construction_args<typename _Pair::first_type>::__apply(
85 __alloc, std::forward<decltype(__args1)>(__args1)...);
86 },
87 std::forward<_Tuple1>(__x)),
88 std::apply(
89 [&__alloc](auto&&... __args2) {
90 return __uses_allocator_construction_args<typename _Pair::second_type>::__apply(
91 __alloc, std::forward<decltype(__args2)>(__args2)...);
92 },
93 std::forward<_Tuple2>(__y)));
94 }
18695
187 _LIBCPP_HIDDEN constexpr auto __do_construct(const _PairMutable& __pair) const {
188 return std::__make_obj_using_allocator<_PairMutable>(__alloc_, __pair);
189 }
96 template <class _Alloc>
97 static _LIBCPP_HIDE_FROM_ABI constexpr auto __apply(const _Alloc& __alloc) noexcept {
98 return __uses_allocator_construction_args<_Pair>::__apply(__alloc, piecewise_construct, tuple<>{}, tuple<>{});
99 }
190100
191 _LIBCPP_HIDDEN constexpr auto __do_construct(_PairMutable&& __pair) const {
192 return std::__make_obj_using_allocator<_PairMutable>(__alloc_, std::move(__pair));
193 }
101 template <class _Alloc, class _Up, class _Vp>
102 static _LIBCPP_HIDE_FROM_ABI constexpr auto __apply(const _Alloc& __alloc, _Up&& __u, _Vp&& __v) noexcept {
103 return __uses_allocator_construction_args<_Pair>::__apply(
104 __alloc,
105 piecewise_construct,
106 std::forward_as_tuple(std::forward<_Up>(__u)),
107 std::forward_as_tuple(std::forward<_Vp>(__v)));
108 }
194109
195 const _Alloc& __alloc_;
196 _Type& __value_;
110# if _LIBCPP_STD_VER >= 23
111 template <class _Alloc, class _Up, class _Vp>
112 static _LIBCPP_HIDE_FROM_ABI constexpr auto __apply(const _Alloc& __alloc, pair<_Up, _Vp>& __pair) noexcept {
113 return __uses_allocator_construction_args<_Pair>::__apply(
114 __alloc, piecewise_construct, std::forward_as_tuple(__pair.first), std::forward_as_tuple(__pair.second));
115 }
116# endif
197117
198 _LIBCPP_HIDDEN constexpr operator _PairMutable() const { return __do_construct(std::forward<_Type>(__value_)); }
199 };
118 template <class _Alloc, class _Up, class _Vp>
119 static _LIBCPP_HIDE_FROM_ABI constexpr auto __apply(const _Alloc& __alloc, const pair<_Up, _Vp>& __pair) noexcept {
120 return __uses_allocator_construction_args<_Pair>::__apply(
121 __alloc, piecewise_construct, std::forward_as_tuple(__pair.first), std::forward_as_tuple(__pair.second));
122 }
200123
201 return std::make_tuple(__pair_constructor{__alloc, __value});
202}
124 template <class _Alloc, class _Up, class _Vp>
125 static _LIBCPP_HIDE_FROM_ABI constexpr auto __apply(const _Alloc& __alloc, pair<_Up, _Vp>&& __pair) noexcept {
126 return __uses_allocator_construction_args<_Pair>::__apply(
127 __alloc,
128 piecewise_construct,
129 std::forward_as_tuple(std::get<0>(std::move(__pair))),
130 std::forward_as_tuple(std::get<1>(std::move(__pair))));
131 }
132
133# if _LIBCPP_STD_VER >= 23
134 template <class _Alloc, class _Up, class _Vp>
135 static _LIBCPP_HIDE_FROM_ABI constexpr auto __apply(const _Alloc& __alloc, const pair<_Up, _Vp>&& __pair) noexcept {
136 return __uses_allocator_construction_args<_Pair>::__apply(
137 __alloc,
138 piecewise_construct,
139 std::forward_as_tuple(std::get<0>(std::move(__pair))),
140 std::forward_as_tuple(std::get<1>(std::move(__pair))));
141 }
142
143 template < class _Alloc, __pair_like_no_subrange _PairLike>
144 static _LIBCPP_HIDE_FROM_ABI constexpr auto __apply(const _Alloc& __alloc, _PairLike&& __p) noexcept {
145 return __uses_allocator_construction_args<_Pair>::__apply(
146 __alloc,
147 piecewise_construct,
148 std::forward_as_tuple(std::get<0>(std::forward<_PairLike>(__p))),
149 std::forward_as_tuple(std::get<1>(std::forward<_PairLike>(__p))));
150 }
151# endif
152
153 template <class _Alloc,
154 class _Type,
155 __enable_if_t<__uses_allocator_detail::__uses_allocator_constraints<_Pair, _Type>, int> = 0>
156 static _LIBCPP_HIDE_FROM_ABI constexpr auto __apply(const _Alloc& __alloc, _Type&& __value) noexcept {
157 struct __pair_constructor {
158 using _PairMutable = remove_cv_t<_Pair>;
159
160 _LIBCPP_HIDDEN constexpr auto __do_construct(const _PairMutable& __pair) const {
161 return std::__make_obj_using_allocator<_PairMutable>(__alloc_, __pair);
162 }
163
164 _LIBCPP_HIDDEN constexpr auto __do_construct(_PairMutable&& __pair) const {
165 return std::__make_obj_using_allocator<_PairMutable>(__alloc_, std::move(__pair));
166 }
167
168 const _Alloc& __alloc_;
169 _Type& __value_;
170
171 _LIBCPP_HIDDEN constexpr operator _PairMutable() const { return __do_construct(std::forward<_Type>(__value_)); }
172 };
173
174 return std::make_tuple(__pair_constructor{__alloc, __value});
175 }
176};
177
178template <class _Type>
179struct __uses_allocator_construction_args<_Type, __enable_if_t<!__is_cv_std_pair<_Type>>> {
180 template <class _Alloc, class... _Args>
181 static _LIBCPP_HIDE_FROM_ABI constexpr auto __apply(const _Alloc& __alloc, _Args&&... __args) noexcept {
182 if constexpr (!uses_allocator_v<remove_cv_t<_Type>, _Alloc> && is_constructible_v<_Type, _Args...>) {
183 return std::forward_as_tuple(std::forward<_Args>(__args)...);
184 } else if constexpr (uses_allocator_v<remove_cv_t<_Type>, _Alloc> &&
185 is_constructible_v<_Type, allocator_arg_t, const _Alloc&, _Args...>) {
186 return tuple<allocator_arg_t, const _Alloc&, _Args&&...>(allocator_arg, __alloc, std::forward<_Args>(__args)...);
187 } else if constexpr (uses_allocator_v<remove_cv_t<_Type>, _Alloc> &&
188 is_constructible_v<_Type, _Args..., const _Alloc&>) {
189 return std::forward_as_tuple(std::forward<_Args>(__args)..., __alloc);
190 } else {
191 static_assert(
192 sizeof(_Type) + 1 == 0, "If uses_allocator_v<Type> is true, the type has to be allocator-constructible");
193 }
194 }
195};
203196
204197template <class _Type, class _Alloc, class... _Args>
205198_LIBCPP_HIDE_FROM_ABI constexpr _Type __make_obj_using_allocator(const _Alloc& __alloc, _Args&&... __args) {
206199 return std::make_from_tuple<_Type>(
207 std::__uses_allocator_construction_args<_Type>(__alloc, std::forward<_Args>(__args)...));
200 __uses_allocator_construction_args<_Type>::__apply(__alloc, std::forward<_Args>(__args)...));
208201}
209202
210203template <class _Type, class _Alloc, class... _Args>
......@@ -212,7 +205,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Type*
212205__uninitialized_construct_using_allocator(_Type* __ptr, const _Alloc& __alloc, _Args&&... __args) {
213206 return std::apply(
214207 [&__ptr](auto&&... __xs) { return std::__construct_at(__ptr, std::forward<decltype(__xs)>(__xs)...); },
215 std::__uses_allocator_construction_args<_Type>(__alloc, std::forward<_Args>(__args)...));
208 __uses_allocator_construction_args<_Type>::__apply(__alloc, std::forward<_Args>(__args)...));
216209}
217210
218211#endif // _LIBCPP_STD_VER >= 17
......@@ -221,8 +214,8 @@ __uninitialized_construct_using_allocator(_Type* __ptr, const _Alloc& __alloc, _
221214
222215template <class _Type, class _Alloc, class... _Args>
223216_LIBCPP_HIDE_FROM_ABI constexpr auto uses_allocator_construction_args(const _Alloc& __alloc, _Args&&... __args) noexcept
224 -> decltype(std::__uses_allocator_construction_args<_Type>(__alloc, std::forward<_Args>(__args)...)) {
225 return /*--*/ std::__uses_allocator_construction_args<_Type>(__alloc, std::forward<_Args>(__args)...);
217 -> decltype(__uses_allocator_construction_args<_Type>::__apply(__alloc, std::forward<_Args>(__args)...)) {
218 return /*--*/ __uses_allocator_construction_args<_Type>::__apply(__alloc, std::forward<_Args>(__args)...);
226219}
227220
228221template <class _Type, class _Alloc, class... _Args>
lib/libcxx/include/__memory/voidify.h deleted-30
......@@ -1,30 +0,0 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___MEMORY_VOIDIFY_H
11#define _LIBCPP___MEMORY_VOIDIFY_H
12
13#include <__config>
14#include <__memory/addressof.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template <typename _Tp>
23_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void* __voidify(_Tp& __from) {
24 // Cast away cv-qualifiers to allow modifying elements of a range through const iterators.
25 return const_cast<void*>(static_cast<const volatile void*>(std::addressof(__from)));
26}
27
28_LIBCPP_END_NAMESPACE_STD
29
30#endif // _LIBCPP___MEMORY_VOIDIFY_H
lib/libcxx/include/__memory_resource/memory_resource.h+2-1
......@@ -10,8 +10,9 @@
1010#define _LIBCPP___MEMORY_RESOURCE_MEMORY_RESOURCE_H
1111
1212#include <__config>
13#include <__cstddef/max_align_t.h>
14#include <__cstddef/size_t.h>
1315#include <__fwd/memory_resource.h>
14#include <cstddef>
1516
1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1718# pragma GCC system_header
lib/libcxx/include/__memory_resource/monotonic_buffer_resource.h+2-5
......@@ -10,9 +10,9 @@
1010#define _LIBCPP___MEMORY_RESOURCE_MONOTONIC_BUFFER_RESOURCE_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__memory/addressof.h>
1415#include <__memory_resource/memory_resource.h>
15#include <cstddef>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818# pragma GCC system_header
......@@ -27,8 +27,7 @@ namespace pmr {
2727// [mem.res.monotonic.buffer]
2828
2929class _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI monotonic_buffer_resource : public memory_resource {
30 static const size_t __default_buffer_capacity = 1024;
31 static const size_t __default_buffer_alignment = 16;
30 static constexpr size_t __default_buffer_capacity = 1024;
3231
3332 struct __chunk_footer {
3433 __chunk_footer* __next_;
......@@ -38,7 +37,6 @@ class _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI monotonic_buffer_resour
3837 _LIBCPP_HIDE_FROM_ABI size_t __allocation_size() {
3938 return (reinterpret_cast<char*>(this) - __start_) + sizeof(*this);
4039 }
41 void* __try_allocate_from_chunk(size_t, size_t);
4240 };
4341
4442 struct __initial_descriptor {
......@@ -48,7 +46,6 @@ class _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI monotonic_buffer_resour
4846 char* __end_;
4947 size_t __size_;
5048 };
51 void* __try_allocate_from_chunk(size_t, size_t);
5249 };
5350
5451public:
lib/libcxx/include/__memory_resource/polymorphic_allocator.h+17-2
......@@ -11,12 +11,14 @@
1111
1212#include <__assert>
1313#include <__config>
14#include <__cstddef/byte.h>
15#include <__cstddef/max_align_t.h>
1416#include <__fwd/pair.h>
1517#include <__memory_resource/memory_resource.h>
18#include <__new/exceptions.h>
19#include <__new/placement_new_delete.h>
1620#include <__utility/exception_guard.h>
17#include <cstddef>
1821#include <limits>
19#include <new>
2022#include <tuple>
2123
2224#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -174,6 +176,19 @@ public:
174176
175177 _LIBCPP_HIDE_FROM_ABI memory_resource* resource() const noexcept { return __res_; }
176178
179 _LIBCPP_HIDE_FROM_ABI friend bool
180 operator==(const polymorphic_allocator& __lhs, const polymorphic_allocator& __rhs) noexcept {
181 return *__lhs.resource() == *__rhs.resource();
182 }
183
184# if _LIBCPP_STD_VER <= 17
185 // This overload is not specified, it was added due to LWG3683.
186 _LIBCPP_HIDE_FROM_ABI friend bool
187 operator!=(const polymorphic_allocator& __lhs, const polymorphic_allocator& __rhs) noexcept {
188 return *__lhs.resource() != *__rhs.resource();
189 }
190# endif
191
177192private:
178193 template <class... _Args, size_t... _Is>
179194 _LIBCPP_HIDE_FROM_ABI tuple<_Args&&...>
lib/libcxx/include/__memory_resource/pool_options.h+1-1
......@@ -10,7 +10,7 @@
1010#define _LIBCPP___MEMORY_RESOURCE_POOL_OPTIONS_H
1111
1212#include <__config>
13#include <cstddef>
13#include <__cstddef/size_t.h>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1616# pragma GCC system_header
lib/libcxx/include/__memory_resource/synchronized_pool_resource.h+7-6
......@@ -10,11 +10,12 @@
1010#define _LIBCPP___MEMORY_RESOURCE_SYNCHRONIZED_POOL_RESOURCE_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__memory_resource/memory_resource.h>
1415#include <__memory_resource/pool_options.h>
1516#include <__memory_resource/unsynchronized_pool_resource.h>
16#include <cstddef>
17#include <mutex>
17#include <__mutex/mutex.h>
18#include <__mutex/unique_lock.h>
1819
1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2021# pragma GCC system_header
......@@ -49,7 +50,7 @@ public:
4950 synchronized_pool_resource& operator=(const synchronized_pool_resource&) = delete;
5051
5152 _LIBCPP_HIDE_FROM_ABI void release() {
52# if !defined(_LIBCPP_HAS_NO_THREADS)
53# if _LIBCPP_HAS_THREADS
5354 unique_lock<mutex> __lk(__mut_);
5455# endif
5556 __unsync_.release();
......@@ -61,14 +62,14 @@ public:
6162
6263protected:
6364 _LIBCPP_HIDE_FROM_ABI_VIRTUAL void* do_allocate(size_t __bytes, size_t __align) override {
64# if !defined(_LIBCPP_HAS_NO_THREADS)
65# if _LIBCPP_HAS_THREADS
6566 unique_lock<mutex> __lk(__mut_);
6667# endif
6768 return __unsync_.allocate(__bytes, __align);
6869 }
6970
7071 _LIBCPP_HIDE_FROM_ABI_VIRTUAL void do_deallocate(void* __p, size_t __bytes, size_t __align) override {
71# if !defined(_LIBCPP_HAS_NO_THREADS)
72# if _LIBCPP_HAS_THREADS
7273 unique_lock<mutex> __lk(__mut_);
7374# endif
7475 return __unsync_.deallocate(__p, __bytes, __align);
......@@ -77,7 +78,7 @@ protected:
7778 bool do_is_equal(const memory_resource& __other) const noexcept override; // key function
7879
7980private:
80# if !defined(_LIBCPP_HAS_NO_THREADS)
81# if _LIBCPP_HAS_THREADS
8182 mutex __mut_;
8283# endif
8384 unsynchronized_pool_resource __unsync_;
lib/libcxx/include/__memory_resource/unsynchronized_pool_resource.h+1-1
......@@ -10,9 +10,9 @@
1010#define _LIBCPP___MEMORY_RESOURCE_UNSYNCHRONIZED_POOL_RESOURCE_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__memory_resource/memory_resource.h>
1415#include <__memory_resource/pool_options.h>
15#include <cstddef>
1616#include <cstdint>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__mutex/lock_guard.h+2-2
......@@ -27,13 +27,13 @@ private:
2727 mutex_type& __m_;
2828
2929public:
30 _LIBCPP_NODISCARD
30 [[__nodiscard__]]
3131 _LIBCPP_HIDE_FROM_ABI explicit lock_guard(mutex_type& __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability(__m))
3232 : __m_(__m) {
3333 __m_.lock();
3434 }
3535
36 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI lock_guard(mutex_type& __m, adopt_lock_t)
36 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI lock_guard(mutex_type& __m, adopt_lock_t)
3737 _LIBCPP_THREAD_SAFETY_ANNOTATION(requires_capability(__m))
3838 : __m_(__m) {}
3939 _LIBCPP_HIDE_FROM_ABI ~lock_guard() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) { __m_.unlock(); }
lib/libcxx/include/__mutex/mutex.h+3-3
......@@ -17,7 +17,7 @@
1717# pragma GCC system_header
1818#endif
1919
20#ifndef _LIBCPP_HAS_NO_THREADS
20#if _LIBCPP_HAS_THREADS
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
2323
......@@ -30,7 +30,7 @@ public:
3030 mutex(const mutex&) = delete;
3131 mutex& operator=(const mutex&) = delete;
3232
33# if defined(_LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION)
33# if _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
3434 _LIBCPP_HIDE_FROM_ABI ~mutex() = default;
3535# else
3636 ~mutex() _NOEXCEPT;
......@@ -48,6 +48,6 @@ static_assert(is_nothrow_default_constructible<mutex>::value, "the default const
4848
4949_LIBCPP_END_NAMESPACE_STD
5050
51#endif // _LIBCPP_HAS_NO_THREADS
51#endif // _LIBCPP_HAS_THREADS
5252
5353#endif // _LIBCPP___MUTEX_MUTEX_H
lib/libcxx/include/__mutex/once_flag.h+1-1
......@@ -11,7 +11,7 @@
1111
1212#include <__config>
1313#include <__functional/invoke.h>
14#include <__memory/shared_ptr.h> // __libcpp_acquire_load
14#include <__memory/shared_count.h> // __libcpp_acquire_load
1515#include <__tuple/tuple_indices.h>
1616#include <__tuple/tuple_size.h>
1717#include <__utility/forward.h>
lib/libcxx/include/__mutex/unique_lock.h+19-23
......@@ -14,7 +14,7 @@
1414#include <__config>
1515#include <__memory/addressof.h>
1616#include <__mutex/tag_types.h>
17#include <__system_error/system_error.h>
17#include <__system_error/throw_system_error.h>
1818#include <__utility/swap.h>
1919#include <cerrno>
2020
......@@ -22,8 +22,6 @@
2222# pragma GCC system_header
2323#endif
2424
25#ifndef _LIBCPP_HAS_NO_THREADS
26
2725_LIBCPP_BEGIN_NAMESPACE_STD
2826
2927template <class _Mutex>
......@@ -36,28 +34,28 @@ private:
3634 bool __owns_;
3735
3836public:
39 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI unique_lock() _NOEXCEPT : __m_(nullptr), __owns_(false) {}
40 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI explicit unique_lock(mutex_type& __m)
37 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI unique_lock() _NOEXCEPT : __m_(nullptr), __owns_(false) {}
38 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI explicit unique_lock(mutex_type& __m)
4139 : __m_(std::addressof(__m)), __owns_(true) {
4240 __m_->lock();
4341 }
4442
45 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI unique_lock(mutex_type& __m, defer_lock_t) _NOEXCEPT
43 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI unique_lock(mutex_type& __m, defer_lock_t) _NOEXCEPT
4644 : __m_(std::addressof(__m)),
4745 __owns_(false) {}
4846
49 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI unique_lock(mutex_type& __m, try_to_lock_t)
47 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI unique_lock(mutex_type& __m, try_to_lock_t)
5048 : __m_(std::addressof(__m)), __owns_(__m.try_lock()) {}
5149
52 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI unique_lock(mutex_type& __m, adopt_lock_t)
50 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI unique_lock(mutex_type& __m, adopt_lock_t)
5351 : __m_(std::addressof(__m)), __owns_(true) {}
5452
5553 template <class _Clock, class _Duration>
56 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI unique_lock(mutex_type& __m, const chrono::time_point<_Clock, _Duration>& __t)
54 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI unique_lock(mutex_type& __m, const chrono::time_point<_Clock, _Duration>& __t)
5755 : __m_(std::addressof(__m)), __owns_(__m.try_lock_until(__t)) {}
5856
5957 template <class _Rep, class _Period>
60 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI unique_lock(mutex_type& __m, const chrono::duration<_Rep, _Period>& __d)
58 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI unique_lock(mutex_type& __m, const chrono::duration<_Rep, _Period>& __d)
6159 : __m_(std::addressof(__m)), __owns_(__m.try_lock_for(__d)) {}
6260
6361 _LIBCPP_HIDE_FROM_ABI ~unique_lock() {
......@@ -68,7 +66,7 @@ public:
6866 unique_lock(unique_lock const&) = delete;
6967 unique_lock& operator=(unique_lock const&) = delete;
7068
71 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI unique_lock(unique_lock&& __u) _NOEXCEPT
69 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI unique_lock(unique_lock&& __u) _NOEXCEPT
7270 : __m_(__u.__m_),
7371 __owns_(__u.__owns_) {
7472 __u.__m_ = nullptr;
......@@ -86,16 +84,16 @@ public:
8684 return *this;
8785 }
8886
89 void lock();
90 bool try_lock();
87 _LIBCPP_HIDE_FROM_ABI void lock();
88 _LIBCPP_HIDE_FROM_ABI bool try_lock();
9189
9290 template <class _Rep, class _Period>
93 bool try_lock_for(const chrono::duration<_Rep, _Period>& __d);
91 _LIBCPP_HIDE_FROM_ABI bool try_lock_for(const chrono::duration<_Rep, _Period>& __d);
9492
9593 template <class _Clock, class _Duration>
96 bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
94 _LIBCPP_HIDE_FROM_ABI bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
9795
98 void unlock();
96 _LIBCPP_HIDE_FROM_ABI void unlock();
9997
10098 _LIBCPP_HIDE_FROM_ABI void swap(unique_lock& __u) _NOEXCEPT {
10199 std::swap(__m_, __u.__m_);
......@@ -116,7 +114,7 @@ public:
116114_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(unique_lock);
117115
118116template <class _Mutex>
119void unique_lock<_Mutex>::lock() {
117_LIBCPP_HIDE_FROM_ABI void unique_lock<_Mutex>::lock() {
120118 if (__m_ == nullptr)
121119 __throw_system_error(EPERM, "unique_lock::lock: references null mutex");
122120 if (__owns_)
......@@ -126,7 +124,7 @@ void unique_lock<_Mutex>::lock() {
126124}
127125
128126template <class _Mutex>
129bool unique_lock<_Mutex>::try_lock() {
127_LIBCPP_HIDE_FROM_ABI bool unique_lock<_Mutex>::try_lock() {
130128 if (__m_ == nullptr)
131129 __throw_system_error(EPERM, "unique_lock::try_lock: references null mutex");
132130 if (__owns_)
......@@ -137,7 +135,7 @@ bool unique_lock<_Mutex>::try_lock() {
137135
138136template <class _Mutex>
139137template <class _Rep, class _Period>
140bool unique_lock<_Mutex>::try_lock_for(const chrono::duration<_Rep, _Period>& __d) {
138_LIBCPP_HIDE_FROM_ABI bool unique_lock<_Mutex>::try_lock_for(const chrono::duration<_Rep, _Period>& __d) {
141139 if (__m_ == nullptr)
142140 __throw_system_error(EPERM, "unique_lock::try_lock_for: references null mutex");
143141 if (__owns_)
......@@ -148,7 +146,7 @@ bool unique_lock<_Mutex>::try_lock_for(const chrono::duration<_Rep, _Period>& __
148146
149147template <class _Mutex>
150148template <class _Clock, class _Duration>
151bool unique_lock<_Mutex>::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) {
149_LIBCPP_HIDE_FROM_ABI bool unique_lock<_Mutex>::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) {
152150 if (__m_ == nullptr)
153151 __throw_system_error(EPERM, "unique_lock::try_lock_until: references null mutex");
154152 if (__owns_)
......@@ -158,7 +156,7 @@ bool unique_lock<_Mutex>::try_lock_until(const chrono::time_point<_Clock, _Durat
158156}
159157
160158template <class _Mutex>
161void unique_lock<_Mutex>::unlock() {
159_LIBCPP_HIDE_FROM_ABI void unique_lock<_Mutex>::unlock() {
162160 if (!__owns_)
163161 __throw_system_error(EPERM, "unique_lock::unlock: not locked");
164162 __m_->unlock();
......@@ -172,6 +170,4 @@ inline _LIBCPP_HIDE_FROM_ABI void swap(unique_lock<_Mutex>& __x, unique_lock<_Mu
172170
173171_LIBCPP_END_NAMESPACE_STD
174172
175#endif // _LIBCPP_HAS_NO_THREADS
176
177173#endif // _LIBCPP___MUTEX_UNIQUE_LOCK_H
lib/libcxx/include/__new/align_val_t.h created+30
......@@ -0,0 +1,30 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___NEW_ALIGN_VAL_T_H
10#define _LIBCPP___NEW_ALIGN_VAL_T_H
11
12#include <__config>
13#include <__cstddef/size_t.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19// purposefully not using versioning namespace
20namespace std {
21#if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION && !defined(_LIBCPP_ABI_VCRUNTIME)
22# ifndef _LIBCPP_CXX03_LANG
23enum class align_val_t : size_t {};
24# else
25enum align_val_t { __zero = 0, __max = (size_t)-1 };
26# endif
27#endif
28} // namespace std
29
30#endif // _LIBCPP___NEW_ALIGN_VAL_T_H
lib/libcxx/include/__new/allocate.h created+110
......@@ -0,0 +1,110 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___NEW_ALLOCATE_H
10#define _LIBCPP___NEW_ALLOCATE_H
11
12#include <__config>
13#include <__cstddef/max_align_t.h>
14#include <__cstddef/size_t.h>
15#include <__new/align_val_t.h>
16#include <__new/global_new_delete.h> // for _LIBCPP_HAS_SIZED_DEALLOCATION
17#include <__type_traits/type_identity.h>
18#include <__utility/element_count.h>
19
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21# pragma GCC system_header
22#endif
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26_LIBCPP_CONSTEXPR inline _LIBCPP_HIDE_FROM_ABI bool __is_overaligned_for_new(size_t __align) _NOEXCEPT {
27#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
28 return __align > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
29#else
30 return __align > _LIBCPP_ALIGNOF(max_align_t);
31#endif
32}
33
34template <class... _Args>
35_LIBCPP_HIDE_FROM_ABI void* __libcpp_operator_new(_Args... __args) {
36#if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
37 return __builtin_operator_new(__args...);
38#else
39 return ::operator new(__args...);
40#endif
41}
42
43template <class... _Args>
44_LIBCPP_HIDE_FROM_ABI void __libcpp_operator_delete(_Args... __args) _NOEXCEPT {
45#if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
46 __builtin_operator_delete(__args...);
47#else
48 ::operator delete(__args...);
49#endif
50}
51
52template <class _Tp>
53inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _Tp*
54__libcpp_allocate(__element_count __n, size_t __align = _LIBCPP_ALIGNOF(_Tp)) {
55 size_t __size = static_cast<size_t>(__n) * sizeof(_Tp);
56#if _LIBCPP_HAS_ALIGNED_ALLOCATION
57 if (__is_overaligned_for_new(__align)) {
58 const align_val_t __align_val = static_cast<align_val_t>(__align);
59 return static_cast<_Tp*>(std::__libcpp_operator_new(__size, __align_val));
60 }
61#endif
62
63 (void)__align;
64 return static_cast<_Tp*>(std::__libcpp_operator_new(__size));
65}
66
67#if _LIBCPP_HAS_SIZED_DEALLOCATION
68# define _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(...) __VA_ARGS__
69#else
70# define _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(...) /* nothing */
71#endif
72
73template <class _Tp>
74inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate(
75 __type_identity_t<_Tp>* __ptr, __element_count __n, size_t __align = _LIBCPP_ALIGNOF(_Tp)) _NOEXCEPT {
76 size_t __size = static_cast<size_t>(__n) * sizeof(_Tp);
77 (void)__size;
78#if !_LIBCPP_HAS_ALIGNED_ALLOCATION
79 (void)__align;
80 return std::__libcpp_operator_delete(__ptr _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(, __size));
81#else
82 if (__is_overaligned_for_new(__align)) {
83 const align_val_t __align_val = static_cast<align_val_t>(__align);
84 return std::__libcpp_operator_delete(__ptr _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(, __size), __align_val);
85 } else {
86 return std::__libcpp_operator_delete(__ptr _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(, __size));
87 }
88#endif
89}
90
91#undef _LIBCPP_ONLY_IF_SIZED_DEALLOCATION
92
93template <class _Tp>
94inline _LIBCPP_HIDE_FROM_ABI void
95__libcpp_deallocate_unsized(__type_identity_t<_Tp>* __ptr, size_t __align = _LIBCPP_ALIGNOF(_Tp)) _NOEXCEPT {
96#if !_LIBCPP_HAS_ALIGNED_ALLOCATION
97 (void)__align;
98 return std::__libcpp_operator_delete(__ptr);
99#else
100 if (__is_overaligned_for_new(__align)) {
101 const align_val_t __align_val = static_cast<align_val_t>(__align);
102 return std::__libcpp_operator_delete(__ptr, __align_val);
103 } else {
104 return std::__libcpp_operator_delete(__ptr);
105 }
106#endif
107}
108_LIBCPP_END_NAMESPACE_STD
109
110#endif // _LIBCPP___NEW_ALLOCATE_H
lib/libcxx/include/__new/destroying_delete_t.h created+30
......@@ -0,0 +1,30 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___NEW_DESTROYING_DELETE_T_H
10#define _LIBCPP___NEW_DESTROYING_DELETE_T_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18#if _LIBCPP_STD_VER >= 20
19// purposefully not using versioning namespace
20namespace std {
21// Enable the declaration even if the compiler doesn't support the language
22// feature.
23struct destroying_delete_t {
24 explicit destroying_delete_t() = default;
25};
26inline constexpr destroying_delete_t destroying_delete{};
27} // namespace std
28#endif
29
30#endif // _LIBCPP___NEW_DESTROYING_DELETE_T_H
lib/libcxx/include/__new/exceptions.h created+74
......@@ -0,0 +1,74 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___NEW_EXCEPTIONS_H
10#define _LIBCPP___NEW_EXCEPTIONS_H
11
12#include <__config>
13#include <__exception/exception.h>
14#include <__verbose_abort>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20// purposefully not using versioning namespace
21namespace std {
22#if !defined(_LIBCPP_ABI_VCRUNTIME)
23
24class _LIBCPP_EXPORTED_FROM_ABI bad_alloc : public exception {
25public:
26 bad_alloc() _NOEXCEPT;
27 _LIBCPP_HIDE_FROM_ABI bad_alloc(const bad_alloc&) _NOEXCEPT = default;
28 _LIBCPP_HIDE_FROM_ABI bad_alloc& operator=(const bad_alloc&) _NOEXCEPT = default;
29 ~bad_alloc() _NOEXCEPT override;
30 const char* what() const _NOEXCEPT override;
31};
32
33class _LIBCPP_EXPORTED_FROM_ABI bad_array_new_length : public bad_alloc {
34public:
35 bad_array_new_length() _NOEXCEPT;
36 _LIBCPP_HIDE_FROM_ABI bad_array_new_length(const bad_array_new_length&) _NOEXCEPT = default;
37 _LIBCPP_HIDE_FROM_ABI bad_array_new_length& operator=(const bad_array_new_length&) _NOEXCEPT = default;
38 ~bad_array_new_length() _NOEXCEPT override;
39 const char* what() const _NOEXCEPT override;
40};
41
42#elif defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0 // !_LIBCPP_ABI_VCRUNTIME
43
44// When _HAS_EXCEPTIONS == 0, these complete definitions are needed,
45// since they would normally be provided in vcruntime_exception.h
46class bad_alloc : public exception {
47public:
48 bad_alloc() noexcept : exception("bad allocation") {}
49
50private:
51 friend class bad_array_new_length;
52
53 bad_alloc(char const* const __message) noexcept : exception(__message) {}
54};
55
56class bad_array_new_length : public bad_alloc {
57public:
58 bad_array_new_length() noexcept : bad_alloc("bad array new length") {}
59};
60
61#endif // defined(_LIBCPP_ABI_VCRUNTIME) && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0
62
63[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_bad_alloc(); // not in C++ spec
64
65[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_array_new_length() {
66#if _LIBCPP_HAS_EXCEPTIONS
67 throw bad_array_new_length();
68#else
69 _LIBCPP_VERBOSE_ABORT("bad_array_new_length was thrown in -fno-exceptions mode");
70#endif
71}
72} // namespace std
73
74#endif // _LIBCPP___NEW_EXCEPTIONS_H
lib/libcxx/include/__new/global_new_delete.h created+77
......@@ -0,0 +1,77 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___NEW_GLOBAL_NEW_DELETE_H
10#define _LIBCPP___NEW_GLOBAL_NEW_DELETE_H
11
12#include <__config>
13#include <__cstddef/size_t.h>
14#include <__new/align_val_t.h>
15#include <__new/exceptions.h>
16#include <__new/nothrow_t.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22#if defined(_LIBCPP_CXX03_LANG)
23# define _THROW_BAD_ALLOC throw(std::bad_alloc)
24#else
25# define _THROW_BAD_ALLOC
26#endif
27
28#if defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309L
29# define _LIBCPP_HAS_SIZED_DEALLOCATION 1
30#else
31# define _LIBCPP_HAS_SIZED_DEALLOCATION 0
32#endif
33
34#if defined(_LIBCPP_ABI_VCRUNTIME)
35# include <new.h>
36#else
37[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC;
38[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT
39 _LIBCPP_NOALIAS;
40_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT;
41_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
42# if _LIBCPP_HAS_SIZED_DEALLOCATION
43_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
44# endif
45
46[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC;
47[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT
48 _LIBCPP_NOALIAS;
49_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT;
50_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
51# if _LIBCPP_HAS_SIZED_DEALLOCATION
52_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
53# endif
54
55# if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
56[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
57[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
58operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
59_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT;
60_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
61# if _LIBCPP_HAS_SIZED_DEALLOCATION
62_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
63# endif
64
65[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
66operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
67[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
68operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
69_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT;
70_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
71# if _LIBCPP_HAS_SIZED_DEALLOCATION
72_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
73# endif
74# endif
75#endif
76
77#endif // _LIBCPP___NEW_GLOBAL_NEW_DELETE_H
lib/libcxx/include/__new/interference_size.h created+34
......@@ -0,0 +1,34 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___NEW_INTERFERENCE_SIZE_H
10#define _LIBCPP___NEW_INTERFERENCE_SIZE_H
11
12#include <__config>
13#include <__cstddef/size_t.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21#if _LIBCPP_STD_VER >= 17
22
23# if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
24
25inline constexpr size_t hardware_destructive_interference_size = __GCC_DESTRUCTIVE_SIZE;
26inline constexpr size_t hardware_constructive_interference_size = __GCC_CONSTRUCTIVE_SIZE;
27
28# endif // defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
29
30#endif // _LIBCPP_STD_VER >= 17
31
32_LIBCPP_END_NAMESPACE_STD
33
34#endif // _LIBCPP___NEW_INTERFERENCE_SIZE_H
lib/libcxx/include/__new/launder.h created+36
......@@ -0,0 +1,36 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___NEW_LAUNDER_H
10#define _LIBCPP___NEW_LAUNDER_H
11
12#include <__config>
13#include <__type_traits/is_function.h>
14#include <__type_traits/is_void.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21template <class _Tp>
22[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT {
23 static_assert(!(is_function<_Tp>::value), "can't launder functions");
24 static_assert(!is_void<_Tp>::value, "can't launder cv-void");
25 return __builtin_launder(__p);
26}
27
28#if _LIBCPP_STD_VER >= 17
29template <class _Tp>
30[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp* launder(_Tp* __p) noexcept {
31 return std::__launder(__p);
32}
33#endif
34_LIBCPP_END_NAMESPACE_STD
35
36#endif // _LIBCPP___NEW_LAUNDER_H
lib/libcxx/include/__new/new_handler.h created+29
......@@ -0,0 +1,29 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___NEW_NEW_HANDLER_H
10#define _LIBCPP___NEW_NEW_HANDLER_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18#if defined(_LIBCPP_ABI_VCRUNTIME)
19# include <new.h>
20#else
21// purposefully not using versioning namespace
22namespace std {
23typedef void (*new_handler)();
24_LIBCPP_EXPORTED_FROM_ABI new_handler set_new_handler(new_handler) _NOEXCEPT;
25_LIBCPP_EXPORTED_FROM_ABI new_handler get_new_handler() _NOEXCEPT;
26} // namespace std
27#endif // _LIBCPP_ABI_VCRUNTIME
28
29#endif // _LIBCPP___NEW_NEW_HANDLER_H
lib/libcxx/include/__new/nothrow_t.h created+30
......@@ -0,0 +1,30 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___NEW_NOTHROW_T_H
10#define _LIBCPP___NEW_NOTHROW_T_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18#if defined(_LIBCPP_ABI_VCRUNTIME)
19# include <new.h>
20#else
21// purposefully not using versioning namespace
22namespace std {
23struct _LIBCPP_EXPORTED_FROM_ABI nothrow_t {
24 explicit nothrow_t() = default;
25};
26extern _LIBCPP_EXPORTED_FROM_ABI const nothrow_t nothrow;
27} // namespace std
28#endif // _LIBCPP_ABI_VCRUNTIME
29
30#endif // _LIBCPP___NEW_NOTHROW_T_H
lib/libcxx/include/__new/placement_new_delete.h created+34
......@@ -0,0 +1,34 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___NEW_PLACEMENT_NEW_DELETE_H
10#define _LIBCPP___NEW_PLACEMENT_NEW_DELETE_H
11
12#include <__config>
13#include <__cstddef/size_t.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19#if defined(_LIBCPP_ABI_VCRUNTIME)
20# include <new.h>
21#else
22[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
23operator new(std::size_t, void* __p) _NOEXCEPT {
24 return __p;
25}
26[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
27operator new[](std::size_t, void* __p) _NOEXCEPT {
28 return __p;
29}
30inline _LIBCPP_HIDE_FROM_ABI void operator delete(void*, void*) _NOEXCEPT {}
31inline _LIBCPP_HIDE_FROM_ABI void operator delete[](void*, void*) _NOEXCEPT {}
32#endif
33
34#endif // _LIBCPP___NEW_PLACEMENT_NEW_DELETE_H
lib/libcxx/include/__node_handle+2-2
......@@ -188,10 +188,10 @@ struct __map_node_handle_specifics {
188188};
189189
190190template <class _NodeType, class _Alloc>
191using __set_node_handle = __basic_node_handle< _NodeType, _Alloc, __set_node_handle_specifics>;
191using __set_node_handle _LIBCPP_NODEBUG = __basic_node_handle< _NodeType, _Alloc, __set_node_handle_specifics>;
192192
193193template <class _NodeType, class _Alloc>
194using __map_node_handle = __basic_node_handle< _NodeType, _Alloc, __map_node_handle_specifics>;
194using __map_node_handle _LIBCPP_NODEBUG = __basic_node_handle< _NodeType, _Alloc, __map_node_handle_specifics>;
195195
196196template <class _Iterator, class _NodeType>
197197struct _LIBCPP_TEMPLATE_VIS __insert_return_type {
lib/libcxx/include/__numeric/gcd_lcm.h+10-13
......@@ -55,7 +55,8 @@ template <class _Tp>
5555constexpr _LIBCPP_HIDDEN _Tp __gcd(_Tp __a, _Tp __b) {
5656 static_assert(!is_signed<_Tp>::value, "");
5757
58 // From: https://lemire.me/blog/2013/12/26/fastest-way-to-compute-the-greatest-common-divisor
58 // Using Binary GCD algorithm https://en.wikipedia.org/wiki/Binary_GCD_algorithm, based on an implementation
59 // from https://lemire.me/blog/2024/04/13/greatest-common-divisor-the-extended-euclidean-algorithm-and-speed/
5960 //
6061 // If power of two divides both numbers, we can push it out.
6162 // - gcd( 2^x * a, 2^x * b) = 2^x * gcd(a, b)
......@@ -76,21 +77,17 @@ constexpr _LIBCPP_HIDDEN _Tp __gcd(_Tp __a, _Tp __b) {
7677 if (__a == 0)
7778 return __b;
7879
79 int __az = std::__countr_zero(__a);
80 int __bz = std::__countr_zero(__b);
81 int __shift = std::min(__az, __bz);
82 __a >>= __az;
83 __b >>= __bz;
80 _Tp __c = __a | __b;
81 int __shift = std::__countr_zero(__c);
82 __a >>= std::__countr_zero(__a);
8483 do {
85 _Tp __diff = __a - __b;
86 if (__a > __b) {
87 __a = __b;
88 __b = __diff;
84 _Tp __t = __b >> std::__countr_zero(__b);
85 if (__a > __t) {
86 __b = __a - __t;
87 __a = __t;
8988 } else {
90 __b = __b - __a;
89 __b = __t - __a;
9190 }
92 if (__diff != 0)
93 __b >>= std::__countr_zero(__diff);
9491 } while (__b != 0);
9592 return __a << __shift;
9693}
lib/libcxx/include/__numeric/midpoint.h+1-1
......@@ -11,6 +11,7 @@
1111#define _LIBCPP___NUMERIC_MIDPOINT_H
1212
1313#include <__config>
14#include <__cstddef/ptrdiff_t.h>
1415#include <__type_traits/enable_if.h>
1516#include <__type_traits/is_floating_point.h>
1617#include <__type_traits/is_integral.h>
......@@ -21,7 +22,6 @@
2122#include <__type_traits/is_void.h>
2223#include <__type_traits/make_unsigned.h>
2324#include <__type_traits/remove_pointer.h>
24#include <cstddef>
2525#include <limits>
2626
2727#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__numeric/pstl.h+2-2
......@@ -18,7 +18,7 @@
1818_LIBCPP_PUSH_MACROS
1919#include <__undef_macros>
2020
21#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
21#if _LIBCPP_HAS_EXPERIMENTAL_PSTL && _LIBCPP_STD_VER >= 17
2222
2323# include <__functional/identity.h>
2424# include <__functional/operations.h>
......@@ -167,7 +167,7 @@ _LIBCPP_HIDE_FROM_ABI _Tp transform_reduce(
167167
168168_LIBCPP_END_NAMESPACE_STD
169169
170#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
170#endif // _LIBCPP_HAS_EXPERIMENTAL_PSTL && _LIBCPP_STD_VER >= 17
171171
172172_LIBCPP_POP_MACROS
173173
lib/libcxx/include/__ostream/basic_ostream.h+133-315
......@@ -10,29 +10,32 @@
1010#define _LIBCPP___OSTREAM_BASIC_OSTREAM_H
1111
1212#include <__config>
13#include <__exception/operations.h>
14#include <__memory/shared_ptr.h>
15#include <__memory/unique_ptr.h>
16#include <__system_error/error_code.h>
17#include <__type_traits/conjunction.h>
18#include <__type_traits/enable_if.h>
19#include <__type_traits/is_base_of.h>
20#include <__type_traits/void_t.h>
21#include <__utility/declval.h>
22#include <bitset>
23#include <cstddef>
24#include <ios>
25#include <locale>
26#include <new> // for __throw_bad_alloc
27#include <streambuf>
28#include <string_view>
29
30#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
31# pragma GCC system_header
32#endif
13
14#if _LIBCPP_HAS_LOCALIZATION
15
16# include <__exception/operations.h>
17# include <__fwd/memory.h>
18# include <__memory/unique_ptr.h>
19# include <__new/exceptions.h>
20# include <__ostream/put_character_sequence.h>
21# include <__system_error/error_code.h>
22# include <__type_traits/conjunction.h>
23# include <__type_traits/enable_if.h>
24# include <__type_traits/is_base_of.h>
25# include <__type_traits/void_t.h>
26# include <__utility/declval.h>
27# include <bitset>
28# include <ios>
29# include <locale>
30# include <streambuf>
31# include <string_view>
32
33# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
34# pragma GCC system_header
35# endif
3336
3437_LIBCPP_PUSH_MACROS
35#include <__undef_macros>
38# include <__undef_macros>
3639
3740_LIBCPP_BEGIN_NAMESPACE_STD
3841
......@@ -85,6 +88,55 @@ public:
8588 return *this;
8689 }
8790
91 template <class _Tp>
92 _LIBCPP_HIDE_FROM_ABI basic_ostream& __put_num(_Tp __value) {
93# if _LIBCPP_HAS_EXCEPTIONS
94 try {
95# endif // _LIBCPP_HAS_EXCEPTIONS
96 sentry __s(*this);
97 if (__s) {
98 using _Fp = num_put<char_type, ostreambuf_iterator<char_type, traits_type> >;
99 const _Fp& __facet = std::use_facet<_Fp>(this->getloc());
100 if (__facet.put(*this, *this, this->fill(), __value).failed())
101 this->setstate(ios_base::badbit | ios_base::failbit);
102 }
103# if _LIBCPP_HAS_EXCEPTIONS
104 } catch (...) {
105 this->__set_badbit_and_consider_rethrow();
106 }
107# endif // _LIBCPP_HAS_EXCEPTIONS
108 return *this;
109 }
110
111 template <class _Tp>
112 _LIBCPP_HIDE_FROM_ABI basic_ostream& __put_num_integer_promote(_Tp __value) {
113# if _LIBCPP_HAS_EXCEPTIONS
114 try {
115# endif // _LIBCPP_HAS_EXCEPTIONS
116 sentry __s(*this);
117 if (__s) {
118 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
119
120 using _Fp = num_put<char_type, ostreambuf_iterator<char_type, traits_type> >;
121 const _Fp& __facet = std::use_facet<_Fp>(this->getloc());
122 if (__facet
123 .put(*this,
124 *this,
125 this->fill(),
126 __flags == ios_base::oct || __flags == ios_base::hex
127 ? static_cast<__copy_unsigned_t<_Tp, long> >(std::__to_unsigned_like(__value))
128 : static_cast<__copy_unsigned_t<_Tp, long> >(__value))
129 .failed())
130 this->setstate(ios_base::badbit | ios_base::failbit);
131 }
132# if _LIBCPP_HAS_EXCEPTIONS
133 } catch (...) {
134 this->__set_badbit_and_consider_rethrow();
135 }
136# endif // _LIBCPP_HAS_EXCEPTIONS
137 return *this;
138 }
139
88140 basic_ostream& operator<<(bool __n);
89141 basic_ostream& operator<<(short __n);
90142 basic_ostream& operator<<(unsigned short __n);
......@@ -99,19 +151,19 @@ public:
99151 basic_ostream& operator<<(long double __f);
100152 basic_ostream& operator<<(const void* __p);
101153
102#if _LIBCPP_STD_VER >= 23
154# if _LIBCPP_STD_VER >= 23
103155 _LIBCPP_HIDE_FROM_ABI basic_ostream& operator<<(const volatile void* __p) {
104156 return operator<<(const_cast<const void*>(__p));
105157 }
106#endif
158# endif
107159
108160 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
109161
110#if _LIBCPP_STD_VER >= 17
162# if _LIBCPP_STD_VER >= 17
111163 // LWG 2221 - nullptr. This is not backported to older standards modes.
112164 // See https://reviews.llvm.org/D127033 for more info on the rationale.
113165 _LIBCPP_HIDE_FROM_ABI basic_ostream& operator<<(nullptr_t) { return *this << "nullptr"; }
114#endif
166# endif
115167
116168 // 27.7.2.7 Unformatted output:
117169 basic_ostream& put(char_type __c);
......@@ -152,16 +204,16 @@ basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& _
152204
153205template <class _CharT, class _Traits>
154206basic_ostream<_CharT, _Traits>::sentry::~sentry() {
155 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf) && !uncaught_exception()) {
156#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
207 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf) && uncaught_exceptions() == 0) {
208# if _LIBCPP_HAS_EXCEPTIONS
157209 try {
158#endif // _LIBCPP_HAS_NO_EXCEPTIONS
210# endif // _LIBCPP_HAS_EXCEPTIONS
159211 if (__os_.rdbuf()->pubsync() == -1)
160212 __os_.setstate(ios_base::badbit);
161#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
213# if _LIBCPP_HAS_EXCEPTIONS
162214 } catch (...) {
163215 }
164#endif // _LIBCPP_HAS_NO_EXCEPTIONS
216# endif // _LIBCPP_HAS_EXCEPTIONS
165217 }
166218}
167219
......@@ -182,15 +234,15 @@ basic_ostream<_CharT, _Traits>::~basic_ostream() {}
182234template <class _CharT, class _Traits>
183235basic_ostream<_CharT, _Traits>&
184236basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb) {
185#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
237# if _LIBCPP_HAS_EXCEPTIONS
186238 try {
187#endif // _LIBCPP_HAS_NO_EXCEPTIONS
239# endif // _LIBCPP_HAS_EXCEPTIONS
188240 sentry __s(*this);
189241 if (__s) {
190242 if (__sb) {
191#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
243# if _LIBCPP_HAS_EXCEPTIONS
192244 try {
193#endif // _LIBCPP_HAS_NO_EXCEPTIONS
245# endif // _LIBCPP_HAS_EXCEPTIONS
194246 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
195247 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
196248 _Ip __i(__sb);
......@@ -204,321 +256,85 @@ basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_typ
204256 }
205257 if (__c == 0)
206258 this->setstate(ios_base::failbit);
207#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
259# if _LIBCPP_HAS_EXCEPTIONS
208260 } catch (...) {
209261 this->__set_failbit_and_consider_rethrow();
210262 }
211#endif // _LIBCPP_HAS_NO_EXCEPTIONS
263# endif // _LIBCPP_HAS_EXCEPTIONS
212264 } else
213265 this->setstate(ios_base::badbit);
214266 }
215#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
267# if _LIBCPP_HAS_EXCEPTIONS
216268 } catch (...) {
217269 this->__set_badbit_and_consider_rethrow();
218270 }
219#endif // _LIBCPP_HAS_NO_EXCEPTIONS
271# endif // _LIBCPP_HAS_EXCEPTIONS
220272 return *this;
221273}
222274
223275template <class _CharT, class _Traits>
224276basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(bool __n) {
225#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
226 try {
227#endif // _LIBCPP_HAS_NO_EXCEPTIONS
228 sentry __s(*this);
229 if (__s) {
230 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
231 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
232 if (__f.put(*this, *this, this->fill(), __n).failed())
233 this->setstate(ios_base::badbit | ios_base::failbit);
234 }
235#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
236 } catch (...) {
237 this->__set_badbit_and_consider_rethrow();
238 }
239#endif // _LIBCPP_HAS_NO_EXCEPTIONS
240 return *this;
277 return __put_num(__n);
241278}
242279
243280template <class _CharT, class _Traits>
244281basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(short __n) {
245#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
246 try {
247#endif // _LIBCPP_HAS_NO_EXCEPTIONS
248 sentry __s(*this);
249 if (__s) {
250 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
251 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
252 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
253 if (__f.put(*this,
254 *this,
255 this->fill(),
256 __flags == ios_base::oct || __flags == ios_base::hex
257 ? static_cast<long>(static_cast<unsigned short>(__n))
258 : static_cast<long>(__n))
259 .failed())
260 this->setstate(ios_base::badbit | ios_base::failbit);
261 }
262#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
263 } catch (...) {
264 this->__set_badbit_and_consider_rethrow();
265 }
266#endif // _LIBCPP_HAS_NO_EXCEPTIONS
267 return *this;
282 return __put_num_integer_promote(__n);
268283}
269284
270285template <class _CharT, class _Traits>
271286basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n) {
272#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
273 try {
274#endif // _LIBCPP_HAS_NO_EXCEPTIONS
275 sentry __s(*this);
276 if (__s) {
277 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
278 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
279 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
280 this->setstate(ios_base::badbit | ios_base::failbit);
281 }
282#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
283 } catch (...) {
284 this->__set_badbit_and_consider_rethrow();
285 }
286#endif // _LIBCPP_HAS_NO_EXCEPTIONS
287 return *this;
287 return __put_num_integer_promote(__n);
288288}
289289
290290template <class _CharT, class _Traits>
291291basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(int __n) {
292#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
293 try {
294#endif // _LIBCPP_HAS_NO_EXCEPTIONS
295 sentry __s(*this);
296 if (__s) {
297 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
298 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
299 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
300 if (__f.put(*this,
301 *this,
302 this->fill(),
303 __flags == ios_base::oct || __flags == ios_base::hex
304 ? static_cast<long>(static_cast<unsigned int>(__n))
305 : static_cast<long>(__n))
306 .failed())
307 this->setstate(ios_base::badbit | ios_base::failbit);
308 }
309#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
310 } catch (...) {
311 this->__set_badbit_and_consider_rethrow();
312 }
313#endif // _LIBCPP_HAS_NO_EXCEPTIONS
314 return *this;
292 return __put_num_integer_promote(__n);
315293}
316294
317295template <class _CharT, class _Traits>
318296basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n) {
319#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
320 try {
321#endif // _LIBCPP_HAS_NO_EXCEPTIONS
322 sentry __s(*this);
323 if (__s) {
324 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
325 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
326 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
327 this->setstate(ios_base::badbit | ios_base::failbit);
328 }
329#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
330 } catch (...) {
331 this->__set_badbit_and_consider_rethrow();
332 }
333#endif // _LIBCPP_HAS_NO_EXCEPTIONS
334 return *this;
297 return __put_num_integer_promote(__n);
335298}
336299
337300template <class _CharT, class _Traits>
338301basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long __n) {
339#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
340 try {
341#endif // _LIBCPP_HAS_NO_EXCEPTIONS
342 sentry __s(*this);
343 if (__s) {
344 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
345 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
346 if (__f.put(*this, *this, this->fill(), __n).failed())
347 this->setstate(ios_base::badbit | ios_base::failbit);
348 }
349#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
350 } catch (...) {
351 this->__set_badbit_and_consider_rethrow();
352 }
353#endif // _LIBCPP_HAS_NO_EXCEPTIONS
354 return *this;
302 return __put_num(__n);
355303}
356304
357305template <class _CharT, class _Traits>
358306basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n) {
359#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
360 try {
361#endif // _LIBCPP_HAS_NO_EXCEPTIONS
362 sentry __s(*this);
363 if (__s) {
364 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
365 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
366 if (__f.put(*this, *this, this->fill(), __n).failed())
367 this->setstate(ios_base::badbit | ios_base::failbit);
368 }
369#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
370 } catch (...) {
371 this->__set_badbit_and_consider_rethrow();
372 }
373#endif // _LIBCPP_HAS_NO_EXCEPTIONS
374 return *this;
307 return __put_num(__n);
375308}
376309
377310template <class _CharT, class _Traits>
378311basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long long __n) {
379#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
380 try {
381#endif // _LIBCPP_HAS_NO_EXCEPTIONS
382 sentry __s(*this);
383 if (__s) {
384 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
385 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
386 if (__f.put(*this, *this, this->fill(), __n).failed())
387 this->setstate(ios_base::badbit | ios_base::failbit);
388 }
389#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
390 } catch (...) {
391 this->__set_badbit_and_consider_rethrow();
392 }
393#endif // _LIBCPP_HAS_NO_EXCEPTIONS
394 return *this;
312 return __put_num(__n);
395313}
396314
397315template <class _CharT, class _Traits>
398316basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n) {
399#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
400 try {
401#endif // _LIBCPP_HAS_NO_EXCEPTIONS
402 sentry __s(*this);
403 if (__s) {
404 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
405 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
406 if (__f.put(*this, *this, this->fill(), __n).failed())
407 this->setstate(ios_base::badbit | ios_base::failbit);
408 }
409#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
410 } catch (...) {
411 this->__set_badbit_and_consider_rethrow();
412 }
413#endif // _LIBCPP_HAS_NO_EXCEPTIONS
414 return *this;
317 return __put_num(__n);
415318}
416319
417320template <class _CharT, class _Traits>
418321basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(float __n) {
419#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
420 try {
421#endif // _LIBCPP_HAS_NO_EXCEPTIONS
422 sentry __s(*this);
423 if (__s) {
424 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
425 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
426 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
427 this->setstate(ios_base::badbit | ios_base::failbit);
428 }
429#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
430 } catch (...) {
431 this->__set_badbit_and_consider_rethrow();
432 }
433#endif // _LIBCPP_HAS_NO_EXCEPTIONS
434 return *this;
322 return *this << static_cast<double>(__n);
435323}
436324
437325template <class _CharT, class _Traits>
438326basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(double __n) {
439#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
440 try {
441#endif // _LIBCPP_HAS_NO_EXCEPTIONS
442 sentry __s(*this);
443 if (__s) {
444 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
445 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
446 if (__f.put(*this, *this, this->fill(), __n).failed())
447 this->setstate(ios_base::badbit | ios_base::failbit);
448 }
449#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
450 } catch (...) {
451 this->__set_badbit_and_consider_rethrow();
452 }
453#endif // _LIBCPP_HAS_NO_EXCEPTIONS
454 return *this;
327 return __put_num(__n);
455328}
456329
457330template <class _CharT, class _Traits>
458331basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long double __n) {
459#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
460 try {
461#endif // _LIBCPP_HAS_NO_EXCEPTIONS
462 sentry __s(*this);
463 if (__s) {
464 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
465 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
466 if (__f.put(*this, *this, this->fill(), __n).failed())
467 this->setstate(ios_base::badbit | ios_base::failbit);
468 }
469#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
470 } catch (...) {
471 this->__set_badbit_and_consider_rethrow();
472 }
473#endif // _LIBCPP_HAS_NO_EXCEPTIONS
474 return *this;
332 return __put_num(__n);
475333}
476334
477335template <class _CharT, class _Traits>
478336basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(const void* __n) {
479#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
480 try {
481#endif // _LIBCPP_HAS_NO_EXCEPTIONS
482 sentry __s(*this);
483 if (__s) {
484 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
485 const _Fp& __f = std::use_facet<_Fp>(this->getloc());
486 if (__f.put(*this, *this, this->fill(), __n).failed())
487 this->setstate(ios_base::badbit | ios_base::failbit);
488 }
489#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
490 } catch (...) {
491 this->__set_badbit_and_consider_rethrow();
492 }
493#endif // _LIBCPP_HAS_NO_EXCEPTIONS
494 return *this;
495}
496
497template <class _CharT, class _Traits>
498_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
499__put_character_sequence(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str, size_t __len) {
500#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
501 try {
502#endif // _LIBCPP_HAS_NO_EXCEPTIONS
503 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
504 if (__s) {
505 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
506 if (std::__pad_and_output(
507 _Ip(__os),
508 __str,
509 (__os.flags() & ios_base::adjustfield) == ios_base::left ? __str + __len : __str,
510 __str + __len,
511 __os,
512 __os.fill())
513 .failed())
514 __os.setstate(ios_base::badbit | ios_base::failbit);
515 }
516#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
517 } catch (...) {
518 __os.__set_badbit_and_consider_rethrow();
519 }
520#endif // _LIBCPP_HAS_NO_EXCEPTIONS
521 return __os;
337 return __put_num(__n);
522338}
523339
524340template <class _CharT, class _Traits>
......@@ -528,9 +344,9 @@ _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_
528344
529345template <class _CharT, class _Traits>
530346_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn) {
531#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
347# if _LIBCPP_HAS_EXCEPTIONS
532348 try {
533#endif // _LIBCPP_HAS_NO_EXCEPTIONS
349# endif // _LIBCPP_HAS_EXCEPTIONS
534350 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
535351 if (__s) {
536352 _CharT __c = __os.widen(__cn);
......@@ -545,11 +361,11 @@ _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_
545361 .failed())
546362 __os.setstate(ios_base::badbit | ios_base::failbit);
547363 }
548#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
364# if _LIBCPP_HAS_EXCEPTIONS
549365 } catch (...) {
550366 __os.__set_badbit_and_consider_rethrow();
551367 }
552#endif // _LIBCPP_HAS_NO_EXCEPTIONS
368# endif // _LIBCPP_HAS_EXCEPTIONS
553369 return __os;
554370}
555371
......@@ -577,9 +393,9 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str) {
577393template <class _CharT, class _Traits>
578394_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
579395operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn) {
580#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
396# if _LIBCPP_HAS_EXCEPTIONS
581397 try {
582#endif // _LIBCPP_HAS_NO_EXCEPTIONS
398# endif // _LIBCPP_HAS_EXCEPTIONS
583399 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
584400 if (__s) {
585401 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
......@@ -606,11 +422,11 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn) {
606422 .failed())
607423 __os.setstate(ios_base::badbit | ios_base::failbit);
608424 }
609#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
425# if _LIBCPP_HAS_EXCEPTIONS
610426 } catch (...) {
611427 __os.__set_badbit_and_consider_rethrow();
612428 }
613#endif // _LIBCPP_HAS_NO_EXCEPTIONS
429# endif // _LIBCPP_HAS_EXCEPTIONS
614430 return __os;
615431}
616432
......@@ -635,9 +451,9 @@ operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str) {
635451
636452template <class _CharT, class _Traits>
637453basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::put(char_type __c) {
638#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
454# if _LIBCPP_HAS_EXCEPTIONS
639455 try {
640#endif // _LIBCPP_HAS_NO_EXCEPTIONS
456# endif // _LIBCPP_HAS_EXCEPTIONS
641457 sentry __s(*this);
642458 if (__s) {
643459 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
......@@ -646,37 +462,37 @@ basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::put(char_type __
646462 if (__o.failed())
647463 this->setstate(ios_base::badbit);
648464 }
649#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
465# if _LIBCPP_HAS_EXCEPTIONS
650466 } catch (...) {
651467 this->__set_badbit_and_consider_rethrow();
652468 }
653#endif // _LIBCPP_HAS_NO_EXCEPTIONS
469# endif // _LIBCPP_HAS_EXCEPTIONS
654470 return *this;
655471}
656472
657473template <class _CharT, class _Traits>
658474basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n) {
659#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
475# if _LIBCPP_HAS_EXCEPTIONS
660476 try {
661#endif // _LIBCPP_HAS_NO_EXCEPTIONS
477# endif // _LIBCPP_HAS_EXCEPTIONS
662478 sentry __sen(*this);
663479 if (__sen && __n) {
664480 if (this->rdbuf()->sputn(__s, __n) != __n)
665481 this->setstate(ios_base::badbit);
666482 }
667#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
483# if _LIBCPP_HAS_EXCEPTIONS
668484 } catch (...) {
669485 this->__set_badbit_and_consider_rethrow();
670486 }
671#endif // _LIBCPP_HAS_NO_EXCEPTIONS
487# endif // _LIBCPP_HAS_EXCEPTIONS
672488 return *this;
673489}
674490
675491template <class _CharT, class _Traits>
676492basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::flush() {
677#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
493# if _LIBCPP_HAS_EXCEPTIONS
678494 try {
679#endif // _LIBCPP_HAS_NO_EXCEPTIONS
495# endif // _LIBCPP_HAS_EXCEPTIONS
680496 if (this->rdbuf()) {
681497 sentry __s(*this);
682498 if (__s) {
......@@ -684,11 +500,11 @@ basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::flush() {
684500 this->setstate(ios_base::badbit);
685501 }
686502 }
687#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
503# if _LIBCPP_HAS_EXCEPTIONS
688504 } catch (...) {
689505 this->__set_badbit_and_consider_rethrow();
690506 }
691#endif // _LIBCPP_HAS_NO_EXCEPTIONS
507# endif // _LIBCPP_HAS_EXCEPTIONS
692508 return *this;
693509}
694510
......@@ -797,9 +613,9 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x) {
797613 std::use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
798614}
799615
800#if _LIBCPP_STD_VER >= 20
616# if _LIBCPP_STD_VER >= 20
801617
802# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
618# if _LIBCPP_HAS_WIDE_CHARACTERS
803619template <class _Traits>
804620basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, wchar_t) = delete;
805621
......@@ -818,9 +634,9 @@ basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, co
818634template <class _Traits>
819635basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char32_t*) = delete;
820636
821# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
637# endif // _LIBCPP_HAS_WIDE_CHARACTERS
822638
823# ifndef _LIBCPP_HAS_NO_CHAR8_T
639# if _LIBCPP_HAS_CHAR8_T
824640template <class _Traits>
825641basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char8_t) = delete;
826642
......@@ -832,7 +648,7 @@ basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const ch
832648
833649template <class _Traits>
834650basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char8_t*) = delete;
835# endif
651# endif
836652
837653template <class _Traits>
838654basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char16_t) = delete;
......@@ -846,15 +662,17 @@ basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const ch
846662template <class _Traits>
847663basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char32_t*) = delete;
848664
849#endif // _LIBCPP_STD_VER >= 20
665# endif // _LIBCPP_STD_VER >= 20
850666
851667extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>;
852#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
668# if _LIBCPP_HAS_WIDE_CHARACTERS
853669extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>;
854#endif
670# endif
855671
856672_LIBCPP_END_NAMESPACE_STD
857673
858674_LIBCPP_POP_MACROS
859675
676#endif // _LIBCPP_HAS_LOCALIZATION
677
860678#endif // _LIBCPP___OSTREAM_BASIC_OSTREAM_H
lib/libcxx/include/__ostream/print.h+42-37
......@@ -10,21 +10,24 @@
1010#define _LIBCPP___OSTREAM_PRINT_H
1111
1212#include <__config>
13#include <__fwd/ostream.h>
14#include <__iterator/ostreambuf_iterator.h>
15#include <__ostream/basic_ostream.h>
16#include <format>
17#include <ios>
18#include <locale>
19#include <print>
20
21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22# pragma GCC system_header
23#endif
13
14#if _LIBCPP_HAS_LOCALIZATION
15
16# include <__fwd/ostream.h>
17# include <__iterator/ostreambuf_iterator.h>
18# include <__ostream/basic_ostream.h>
19# include <format>
20# include <ios>
21# include <locale>
22# include <print>
23
24# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26# endif
2427
2528_LIBCPP_BEGIN_NAMESPACE_STD
2629
27#if _LIBCPP_STD_VER >= 23
30# if _LIBCPP_STD_VER >= 23
2831
2932template <class = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
3033_LIBCPP_HIDE_FROM_ABI inline void
......@@ -49,9 +52,9 @@ __vprint_nonunicode(ostream& __os, string_view __fmt, format_args __args, bool _
4952 const char* __str = __o.data();
5053 size_t __len = __o.size();
5154
52# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
55# if _LIBCPP_HAS_EXCEPTIONS
5356 try {
54# endif // _LIBCPP_HAS_NO_EXCEPTIONS
57# endif // _LIBCPP_HAS_EXCEPTIONS
5558 typedef ostreambuf_iterator<char> _Ip;
5659 if (std::__pad_and_output(
5760 _Ip(__os),
......@@ -63,11 +66,11 @@ __vprint_nonunicode(ostream& __os, string_view __fmt, format_args __args, bool _
6366 .failed())
6467 __os.setstate(ios_base::badbit | ios_base::failbit);
6568
66# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
69# if _LIBCPP_HAS_EXCEPTIONS
6770 } catch (...) {
6871 __os.__set_badbit_and_consider_rethrow();
6972 }
70# endif // _LIBCPP_HAS_NO_EXCEPTIONS
73# endif // _LIBCPP_HAS_EXCEPTIONS
7174 }
7275}
7376
......@@ -91,12 +94,12 @@ _LIBCPP_HIDE_FROM_ABI inline void vprint_nonunicode(ostream& __os, string_view _
9194// is determined in the same way as the print(FILE*, ...) overloads.
9295_LIBCPP_EXPORTED_FROM_ABI FILE* __get_ostream_file(ostream& __os);
9396
94# ifndef _LIBCPP_HAS_NO_UNICODE
97# if _LIBCPP_HAS_UNICODE
9598template <class = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
9699_LIBCPP_HIDE_FROM_ABI void __vprint_unicode(ostream& __os, string_view __fmt, format_args __args, bool __write_nl) {
97# if _LIBCPP_AVAILABILITY_HAS_PRINT == 0
100# if _LIBCPP_AVAILABILITY_HAS_PRINT == 0
98101 return std::__vprint_nonunicode(__os, __fmt, __args, __write_nl);
99# else
102# else
100103 FILE* __file = std::__get_ostream_file(__os);
101104 if (!__file || !__print::__is_terminal(__file))
102105 return std::__vprint_nonunicode(__os, __fmt, __args, __write_nl);
......@@ -112,49 +115,49 @@ _LIBCPP_HIDE_FROM_ABI void __vprint_unicode(ostream& __os, string_view __fmt, fo
112115 // This is the path for the native API, start with flushing.
113116 __os.flush();
114117
115# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
118# if _LIBCPP_HAS_EXCEPTIONS
116119 try {
117# endif // _LIBCPP_HAS_NO_EXCEPTIONS
120# endif // _LIBCPP_HAS_EXCEPTIONS
118121 ostream::sentry __s(__os);
119122 if (__s) {
120# ifndef _LIBCPP_WIN32API
123# ifndef _LIBCPP_WIN32API
121124 __print::__vprint_unicode_posix(__file, __fmt, __args, __write_nl, true);
122# elif !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
125# elif _LIBCPP_HAS_WIDE_CHARACTERS
123126 __print::__vprint_unicode_windows(__file, __fmt, __args, __write_nl, true);
124# else
125# error "Windows builds with wchar_t disabled are not supported."
126# endif
127# else
128# error "Windows builds with wchar_t disabled are not supported."
129# endif
127130 }
128131
129# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
132# if _LIBCPP_HAS_EXCEPTIONS
130133 } catch (...) {
131134 __os.__set_badbit_and_consider_rethrow();
132135 }
133# endif // _LIBCPP_HAS_NO_EXCEPTIONS
134# endif // _LIBCPP_AVAILABILITY_HAS_PRINT
136# endif // _LIBCPP_HAS_EXCEPTIONS
137# endif // _LIBCPP_AVAILABILITY_HAS_PRINT
135138}
136139
137140template <class = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
138141_LIBCPP_HIDE_FROM_ABI inline void vprint_unicode(ostream& __os, string_view __fmt, format_args __args) {
139142 std::__vprint_unicode(__os, __fmt, __args, false);
140143}
141# endif // _LIBCPP_HAS_NO_UNICODE
144# endif // _LIBCPP_HAS_UNICODE
142145
143146template <class... _Args>
144147_LIBCPP_HIDE_FROM_ABI void print(ostream& __os, format_string<_Args...> __fmt, _Args&&... __args) {
145# ifndef _LIBCPP_HAS_NO_UNICODE
148# if _LIBCPP_HAS_UNICODE
146149 if constexpr (__print::__use_unicode_execution_charset)
147150 std::__vprint_unicode(__os, __fmt.get(), std::make_format_args(__args...), false);
148151 else
149152 std::__vprint_nonunicode(__os, __fmt.get(), std::make_format_args(__args...), false);
150# else // _LIBCPP_HAS_NO_UNICODE
153# else // _LIBCPP_HAS_UNICODE
151154 std::__vprint_nonunicode(__os, __fmt.get(), std::make_format_args(__args...), false);
152# endif // _LIBCPP_HAS_NO_UNICODE
155# endif // _LIBCPP_HAS_UNICODE
153156}
154157
155158template <class... _Args>
156159_LIBCPP_HIDE_FROM_ABI void println(ostream& __os, format_string<_Args...> __fmt, _Args&&... __args) {
157# ifndef _LIBCPP_HAS_NO_UNICODE
160# if _LIBCPP_HAS_UNICODE
158161 // Note the wording in the Standard is inefficient. The output of
159162 // std::format is a std::string which is then copied. This solution
160163 // just appends a newline at the end of the output.
......@@ -162,9 +165,9 @@ _LIBCPP_HIDE_FROM_ABI void println(ostream& __os, format_string<_Args...> __fmt,
162165 std::__vprint_unicode(__os, __fmt.get(), std::make_format_args(__args...), true);
163166 else
164167 std::__vprint_nonunicode(__os, __fmt.get(), std::make_format_args(__args...), true);
165# else // _LIBCPP_HAS_NO_UNICODE
168# else // _LIBCPP_HAS_UNICODE
166169 std::__vprint_nonunicode(__os, __fmt.get(), std::make_format_args(__args...), true);
167# endif // _LIBCPP_HAS_NO_UNICODE
170# endif // _LIBCPP_HAS_UNICODE
168171}
169172
170173template <class = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
......@@ -172,8 +175,10 @@ _LIBCPP_HIDE_FROM_ABI inline void println(ostream& __os) {
172175 std::print(__os, "\n");
173176}
174177
175#endif // _LIBCPP_STD_VER >= 23
178# endif // _LIBCPP_STD_VER >= 23
176179
177180_LIBCPP_END_NAMESPACE_STD
178181
182#endif // _LIBCPP_HAS_LOCALIZATION
183
179184#endif // _LIBCPP___OSTREAM_PRINT_H
lib/libcxx/include/__ostream/put_character_sequence.h created+59
......@@ -0,0 +1,59 @@
1//===---------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===---------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___OSTREAM_PUT_CHARACTER_SEQUENCE_H
10#define _LIBCPP___OSTREAM_PUT_CHARACTER_SEQUENCE_H
11
12#include <__config>
13
14#if _LIBCPP_HAS_LOCALIZATION
15
16# include <__cstddef/size_t.h>
17# include <__fwd/ostream.h>
18# include <__iterator/ostreambuf_iterator.h>
19# include <__locale_dir/pad_and_output.h>
20# include <ios>
21
22# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24# endif
25
26_LIBCPP_BEGIN_NAMESPACE_STD
27
28template <class _CharT, class _Traits>
29_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
30__put_character_sequence(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str, size_t __len) {
31# if _LIBCPP_HAS_EXCEPTIONS
32 try {
33# endif // _LIBCPP_HAS_EXCEPTIONS
34 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
35 if (__s) {
36 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
37 if (std::__pad_and_output(
38 _Ip(__os),
39 __str,
40 (__os.flags() & ios_base::adjustfield) == ios_base::left ? __str + __len : __str,
41 __str + __len,
42 __os,
43 __os.fill())
44 .failed())
45 __os.setstate(ios_base::badbit | ios_base::failbit);
46 }
47# if _LIBCPP_HAS_EXCEPTIONS
48 } catch (...) {
49 __os.__set_badbit_and_consider_rethrow();
50 }
51# endif // _LIBCPP_HAS_EXCEPTIONS
52 return __os;
53}
54
55_LIBCPP_END_NAMESPACE_STD
56
57#endif // _LIBCPP_HAS_LOCALIZATION
58
59#endif // _LIBCPP___OSTREAM_PUT_CHARACTER_SEQUENCE_H
lib/libcxx/include/__pstl/backend.h+14-10
......@@ -19,16 +19,20 @@
1919_LIBCPP_PUSH_MACROS
2020#include <__undef_macros>
2121
22#if defined(_LIBCPP_PSTL_BACKEND_SERIAL)
23# include <__pstl/backends/default.h>
24# include <__pstl/backends/serial.h>
25#elif defined(_LIBCPP_PSTL_BACKEND_STD_THREAD)
26# include <__pstl/backends/default.h>
27# include <__pstl/backends/std_thread.h>
28#elif defined(_LIBCPP_PSTL_BACKEND_LIBDISPATCH)
29# include <__pstl/backends/default.h>
30# include <__pstl/backends/libdispatch.h>
31#endif
22#if _LIBCPP_STD_VER >= 17
23
24# if defined(_LIBCPP_PSTL_BACKEND_SERIAL)
25# include <__pstl/backends/default.h>
26# include <__pstl/backends/serial.h>
27# elif defined(_LIBCPP_PSTL_BACKEND_STD_THREAD)
28# include <__pstl/backends/default.h>
29# include <__pstl/backends/std_thread.h>
30# elif defined(_LIBCPP_PSTL_BACKEND_LIBDISPATCH)
31# include <__pstl/backends/default.h>
32# include <__pstl/backends/libdispatch.h>
33# endif
34
35#endif // _LIBCPP_STD_VER >= 17
3236
3337_LIBCPP_POP_MACROS
3438
lib/libcxx/include/__pstl/backend_fwd.h+15-9
......@@ -39,6 +39,8 @@ _LIBCPP_PUSH_MACROS
3939// the user.
4040//
4141
42#if _LIBCPP_STD_VER >= 17
43
4244_LIBCPP_BEGIN_NAMESPACE_STD
4345namespace __pstl {
4446
......@@ -50,18 +52,20 @@ struct __libdispatch_backend_tag;
5052struct __serial_backend_tag;
5153struct __std_thread_backend_tag;
5254
53#if defined(_LIBCPP_PSTL_BACKEND_SERIAL)
54using __current_configuration = __backend_configuration<__serial_backend_tag, __default_backend_tag>;
55#elif defined(_LIBCPP_PSTL_BACKEND_STD_THREAD)
56using __current_configuration = __backend_configuration<__std_thread_backend_tag, __default_backend_tag>;
57#elif defined(_LIBCPP_PSTL_BACKEND_LIBDISPATCH)
58using __current_configuration = __backend_configuration<__libdispatch_backend_tag, __default_backend_tag>;
59#else
55# if defined(_LIBCPP_PSTL_BACKEND_SERIAL)
56using __current_configuration _LIBCPP_NODEBUG = __backend_configuration<__serial_backend_tag, __default_backend_tag>;
57# elif defined(_LIBCPP_PSTL_BACKEND_STD_THREAD)
58using __current_configuration _LIBCPP_NODEBUG =
59 __backend_configuration<__std_thread_backend_tag, __default_backend_tag>;
60# elif defined(_LIBCPP_PSTL_BACKEND_LIBDISPATCH)
61using __current_configuration _LIBCPP_NODEBUG =
62 __backend_configuration<__libdispatch_backend_tag, __default_backend_tag>;
63# else
6064
6165// ...New vendors can add parallel backends here...
6266
63# error "Invalid PSTL backend configuration"
64#endif
67# error "Invalid PSTL backend configuration"
68# endif
6569
6670template <class _Backend, class _ExecutionPolicy>
6771struct __find_if;
......@@ -296,6 +300,8 @@ struct __reduce;
296300} // namespace __pstl
297301_LIBCPP_END_NAMESPACE_STD
298302
303#endif // _LIBCPP_STD_VER >= 17
304
299305_LIBCPP_POP_MACROS
300306
301307#endif // _LIBCPP___PSTL_BACKEND_FWD_H
lib/libcxx/include/__pstl/backends/default.h+5-1
......@@ -33,6 +33,8 @@
3333_LIBCPP_PUSH_MACROS
3434#include <__undef_macros>
3535
36#if _LIBCPP_STD_VER >= 17
37
3638_LIBCPP_BEGIN_NAMESPACE_STD
3739namespace __pstl {
3840
......@@ -163,7 +165,7 @@ struct __is_partitioned<__default_backend_tag, _ExecutionPolicy> {
163165 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool>
164166 operator()(_Policy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred&& __pred) const noexcept {
165167 using _FindIfNot = __dispatch<__find_if_not, __current_configuration, _ExecutionPolicy>;
166 auto __maybe_first = _FindIfNot()(__policy, std::move(__first), std::move(__last), __pred);
168 auto __maybe_first = _FindIfNot()(__policy, std::move(__first), __last, __pred);
167169 if (__maybe_first == nullopt)
168170 return nullopt;
169171
......@@ -498,6 +500,8 @@ struct __rotate_copy<__default_backend_tag, _ExecutionPolicy> {
498500} // namespace __pstl
499501_LIBCPP_END_NAMESPACE_STD
500502
503#endif // _LIBCPP_STD_VER >= 17
504
501505_LIBCPP_POP_MACROS
502506
503507#endif // _LIBCPP___PSTL_BACKENDS_DEFAULT_H
lib/libcxx/include/__pstl/backends/libdispatch.h+10-6
......@@ -16,12 +16,14 @@
1616#include <__algorithm/upper_bound.h>
1717#include <__atomic/atomic.h>
1818#include <__config>
19#include <__cstddef/ptrdiff_t.h>
1920#include <__exception/terminate.h>
2021#include <__iterator/iterator_traits.h>
2122#include <__iterator/move_iterator.h>
2223#include <__memory/allocator.h>
2324#include <__memory/construct_at.h>
2425#include <__memory/unique_ptr.h>
26#include <__new/exceptions.h>
2527#include <__numeric/reduce.h>
2628#include <__pstl/backend_fwd.h>
2729#include <__pstl/cpu_algos/any_of.h>
......@@ -37,13 +39,13 @@
3739#include <__utility/exception_guard.h>
3840#include <__utility/move.h>
3941#include <__utility/pair.h>
40#include <cstddef>
41#include <new>
4242#include <optional>
4343
4444_LIBCPP_PUSH_MACROS
4545#include <__undef_macros>
4646
47#if _LIBCPP_STD_VER >= 17
48
4749_LIBCPP_BEGIN_NAMESPACE_STD
4850namespace __pstl {
4951
......@@ -140,15 +142,15 @@ struct __cpu_traits<__libdispatch_backend_tag> {
140142
141143 unique_ptr<__merge_range_t[], decltype(__destroy)> __ranges(
142144 [&]() -> __merge_range_t* {
143#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
145# if _LIBCPP_HAS_EXCEPTIONS
144146 try {
145#endif
147# endif
146148 return std::allocator<__merge_range_t>().allocate(__n_ranges);
147#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
149# if _LIBCPP_HAS_EXCEPTIONS
148150 } catch (const std::bad_alloc&) {
149151 return nullptr;
150152 }
151#endif
153# endif
152154 }(),
153155 __destroy);
154156
......@@ -392,6 +394,8 @@ struct __fill<__libdispatch_backend_tag, _ExecutionPolicy>
392394} // namespace __pstl
393395_LIBCPP_END_NAMESPACE_STD
394396
397#endif // _LIBCPP_STD_VER >= 17
398
395399_LIBCPP_POP_MACROS
396400
397401#endif // _LIBCPP___PSTL_BACKENDS_LIBDISPATCH_H
lib/libcxx/include/__pstl/backends/serial.h+4
......@@ -30,6 +30,8 @@
3030_LIBCPP_PUSH_MACROS
3131#include <__undef_macros>
3232
33#if _LIBCPP_STD_VER >= 17
34
3335_LIBCPP_BEGIN_NAMESPACE_STD
3436namespace __pstl {
3537
......@@ -176,6 +178,8 @@ struct __transform_reduce_binary<__serial_backend_tag, _ExecutionPolicy> {
176178} // namespace __pstl
177179_LIBCPP_END_NAMESPACE_STD
178180
181#endif // _LIBCPP_STD_VER >= 17
182
179183_LIBCPP_POP_MACROS
180184
181185#endif // _LIBCPP___PSTL_BACKENDS_SERIAL_H
lib/libcxx/include/__pstl/backends/std_thread.h+4-1
......@@ -22,7 +22,6 @@
2222#include <__pstl/cpu_algos/transform_reduce.h>
2323#include <__utility/empty.h>
2424#include <__utility/move.h>
25#include <cstddef>
2625#include <optional>
2726
2827#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -32,6 +31,8 @@
3231_LIBCPP_PUSH_MACROS
3332#include <__undef_macros>
3433
34#if _LIBCPP_STD_VER >= 17
35
3536_LIBCPP_BEGIN_NAMESPACE_STD
3637namespace __pstl {
3738
......@@ -131,6 +132,8 @@ struct __fill<__std_thread_backend_tag, _ExecutionPolicy>
131132} // namespace __pstl
132133_LIBCPP_END_NAMESPACE_STD
133134
135#endif // _LIBCPP_STD_VER >= 17
136
134137_LIBCPP_POP_MACROS
135138
136139#endif // _LIBCPP___PSTL_BACKENDS_STD_THREAD_H
lib/libcxx/include/__pstl/cpu_algos/any_of.h+4
......@@ -26,6 +26,8 @@
2626_LIBCPP_PUSH_MACROS
2727#include <__undef_macros>
2828
29#if _LIBCPP_STD_VER >= 17
30
2931_LIBCPP_BEGIN_NAMESPACE_STD
3032namespace __pstl {
3133
......@@ -94,6 +96,8 @@ struct __cpu_parallel_any_of {
9496} // namespace __pstl
9597_LIBCPP_END_NAMESPACE_STD
9698
99#endif // _LIBCPP_STD_VER >= 17
100
97101_LIBCPP_POP_MACROS
98102
99103#endif // _LIBCPP___PSTL_CPU_ALGOS_ANY_OF_H
lib/libcxx/include/__pstl/cpu_algos/cpu_traits.h+4-1
......@@ -10,7 +10,6 @@
1010#define _LIBCPP___PSTL_CPU_ALGOS_CPU_TRAITS_H
1111
1212#include <__config>
13#include <cstddef>
1413
1514#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1615# pragma GCC system_header
......@@ -19,6 +18,8 @@
1918_LIBCPP_PUSH_MACROS
2019#include <__undef_macros>
2120
21#if _LIBCPP_STD_VER >= 17
22
2223_LIBCPP_BEGIN_NAMESPACE_STD
2324namespace __pstl {
2425
......@@ -81,6 +82,8 @@ struct __cpu_traits;
8182} // namespace __pstl
8283_LIBCPP_END_NAMESPACE_STD
8384
85#endif // _LIBCPP_STD_VER >= 17
86
8487_LIBCPP_POP_MACROS
8588
8689#endif // _LIBCPP___PSTL_CPU_ALGOS_CPU_TRAITS_H
lib/libcxx/include/__pstl/cpu_algos/fill.h+4
......@@ -23,6 +23,8 @@
2323# pragma GCC system_header
2424#endif
2525
26#if _LIBCPP_STD_VER >= 17
27
2628_LIBCPP_BEGIN_NAMESPACE_STD
2729namespace __pstl {
2830
......@@ -63,4 +65,6 @@ struct __cpu_parallel_fill {
6365} // namespace __pstl
6466_LIBCPP_END_NAMESPACE_STD
6567
68#endif // _LIBCPP_STD_VER >= 17
69
6670#endif // _LIBCPP___PSTL_CPU_ALGOS_FILL_H
lib/libcxx/include/__pstl/cpu_algos/find_if.h+4-1
......@@ -21,7 +21,6 @@
2121#include <__type_traits/is_execution_policy.h>
2222#include <__utility/move.h>
2323#include <__utility/pair.h>
24#include <cstddef>
2524#include <optional>
2625
2726#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -31,6 +30,8 @@
3130_LIBCPP_PUSH_MACROS
3231#include <__undef_macros>
3332
33#if _LIBCPP_STD_VER >= 17
34
3435_LIBCPP_BEGIN_NAMESPACE_STD
3536namespace __pstl {
3637
......@@ -132,6 +133,8 @@ struct __cpu_parallel_find_if {
132133} // namespace __pstl
133134_LIBCPP_END_NAMESPACE_STD
134135
136#endif // _LIBCPP_STD_VER >= 17
137
135138_LIBCPP_POP_MACROS
136139
137140#endif // _LIBCPP___PSTL_CPU_ALGOS_FIND_IF_H
lib/libcxx/include/__pstl/cpu_algos/for_each.h+4
......@@ -23,6 +23,8 @@
2323# pragma GCC system_header
2424#endif
2525
26#if _LIBCPP_STD_VER >= 17
27
2628_LIBCPP_BEGIN_NAMESPACE_STD
2729namespace __pstl {
2830
......@@ -63,4 +65,6 @@ struct __cpu_parallel_for_each {
6365} // namespace __pstl
6466_LIBCPP_END_NAMESPACE_STD
6567
68#endif // _LIBCPP_STD_VER >= 17
69
6670#endif // _LIBCPP___PSTL_CPU_ALGOS_FOR_EACH_H
lib/libcxx/include/__pstl/cpu_algos/merge.h+4
......@@ -26,6 +26,8 @@
2626_LIBCPP_PUSH_MACROS
2727#include <__undef_macros>
2828
29#if _LIBCPP_STD_VER >= 17
30
2931_LIBCPP_BEGIN_NAMESPACE_STD
3032namespace __pstl {
3133
......@@ -80,6 +82,8 @@ struct __cpu_parallel_merge {
8082} // namespace __pstl
8183_LIBCPP_END_NAMESPACE_STD
8284
85#endif // _LIBCPP_STD_VER >= 17
86
8387_LIBCPP_POP_MACROS
8488
8589#endif // _LIBCPP___PSTL_CPU_ALGOS_MERGE_H
lib/libcxx/include/__pstl/cpu_algos/stable_sort.h+4
......@@ -21,6 +21,8 @@
2121# pragma GCC system_header
2222#endif
2323
24#if _LIBCPP_STD_VER >= 17
25
2426_LIBCPP_BEGIN_NAMESPACE_STD
2527namespace __pstl {
2628
......@@ -44,4 +46,6 @@ struct __cpu_parallel_stable_sort {
4446} // namespace __pstl
4547_LIBCPP_END_NAMESPACE_STD
4648
49#endif // _LIBCPP_STD_VER >= 17
50
4751#endif // _LIBCPP___PSTL_CPU_ALGOS_STABLE_SORT_H
lib/libcxx/include/__pstl/cpu_algos/transform.h+4
......@@ -27,6 +27,8 @@
2727_LIBCPP_PUSH_MACROS
2828#include <__undef_macros>
2929
30#if _LIBCPP_STD_VER >= 17
31
3032_LIBCPP_BEGIN_NAMESPACE_STD
3133namespace __pstl {
3234
......@@ -148,6 +150,8 @@ struct __cpu_parallel_transform_binary {
148150} // namespace __pstl
149151_LIBCPP_END_NAMESPACE_STD
150152
153#endif // _LIBCPP_STD_VER >= 17
154
151155_LIBCPP_POP_MACROS
152156
153157#endif // _LIBCPP___PSTL_CPU_ALGOS_TRANSFORM_H
lib/libcxx/include/__pstl/cpu_algos/transform_reduce.h+4-2
......@@ -20,8 +20,6 @@
2020#include <__type_traits/is_arithmetic.h>
2121#include <__type_traits/is_execution_policy.h>
2222#include <__utility/move.h>
23#include <cstddef>
24#include <new>
2523#include <optional>
2624
2725#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -31,6 +29,8 @@
3129_LIBCPP_PUSH_MACROS
3230#include <__undef_macros>
3331
32#if _LIBCPP_STD_VER >= 17
33
3434_LIBCPP_BEGIN_NAMESPACE_STD
3535namespace __pstl {
3636
......@@ -211,6 +211,8 @@ struct __cpu_parallel_transform_reduce {
211211} // namespace __pstl
212212_LIBCPP_END_NAMESPACE_STD
213213
214#endif // _LIBCPP_STD_VER >= 17
215
214216_LIBCPP_POP_MACROS
215217
216218#endif // _LIBCPP___PSTL_CPU_ALGOS_TRANSFORM_REDUCE_H
lib/libcxx/include/__pstl/dispatch.h+6-1
......@@ -23,6 +23,8 @@
2323_LIBCPP_PUSH_MACROS
2424#include <__undef_macros>
2525
26#if _LIBCPP_STD_VER >= 17
27
2628_LIBCPP_BEGIN_NAMESPACE_STD
2729namespace __pstl {
2830
......@@ -56,11 +58,14 @@ struct __find_first_implemented<_Algorithm, __backend_configuration<_B1, _Bn...>
5658 __find_first_implemented<_Algorithm, __backend_configuration<_Bn...>, _ExecutionPolicy> > {};
5759
5860template <template <class, class> class _Algorithm, class _BackendConfiguration, class _ExecutionPolicy>
59using __dispatch = typename __find_first_implemented<_Algorithm, _BackendConfiguration, _ExecutionPolicy>::type;
61using __dispatch _LIBCPP_NODEBUG =
62 typename __find_first_implemented<_Algorithm, _BackendConfiguration, _ExecutionPolicy>::type;
6063
6164} // namespace __pstl
6265_LIBCPP_END_NAMESPACE_STD
6366
67#endif // _LIBCPP_STD_VER >= 17
68
6469_LIBCPP_POP_MACROS
6570
6671#endif // _LIBCPP___PSTL_DISPATCH_H
lib/libcxx/include/__pstl/handle_exception.h+5-1
......@@ -10,9 +10,9 @@
1010#define _LIBCPP___PSTL_HANDLE_EXCEPTION_H
1111
1212#include <__config>
13#include <__new/exceptions.h>
1314#include <__utility/forward.h>
1415#include <__utility/move.h>
15#include <new> // __throw_bad_alloc
1616#include <optional>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -22,6 +22,8 @@
2222_LIBCPP_PUSH_MACROS
2323#include <__undef_macros>
2424
25#if _LIBCPP_STD_VER >= 17
26
2527_LIBCPP_BEGIN_NAMESPACE_STD
2628namespace __pstl {
2729
......@@ -52,6 +54,8 @@ _LIBCPP_HIDE_FROM_ABI auto __handle_exception(_Args&&... __args) {
5254} // namespace __pstl
5355_LIBCPP_END_NAMESPACE_STD
5456
57#endif // _LIBCPP_STD_VER >= 17
58
5559_LIBCPP_POP_MACROS
5660
5761#endif // _LIBCPP___PSTL_HANDLE_EXCEPTION_H
lib/libcxx/include/__random/binomial_distribution.h+3-2
......@@ -97,12 +97,13 @@ public:
9797 }
9898};
9999
100#ifndef _LIBCPP_MSVCRT_LIKE
100// The LLVM C library provides this with conflicting `noexcept` attributes.
101#if !defined(_LIBCPP_MSVCRT_LIKE) && !defined(__LLVM_LIBC__)
101102extern "C" double lgamma_r(double, int*);
102103#endif
103104
104105inline _LIBCPP_HIDE_FROM_ABI double __libcpp_lgamma(double __d) {
105#if defined(_LIBCPP_MSVCRT_LIKE)
106#if defined(_LIBCPP_MSVCRT_LIKE) || defined(__LLVM_LIBC__)
106107 return lgamma(__d);
107108#else
108109 int __sign;
lib/libcxx/include/__random/discard_block_engine.h+3-9
......@@ -10,11 +10,11 @@
1010#define _LIBCPP___RANDOM_DISCARD_BLOCK_ENGINE_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__random/is_seed_sequence.h>
1415#include <__type_traits/enable_if.h>
1516#include <__type_traits/is_convertible.h>
1617#include <__utility/move.h>
17#include <cstddef>
1818#include <iosfwd>
1919#include <limits>
2020
......@@ -43,8 +43,8 @@ public:
4343 typedef typename _Engine::result_type result_type;
4444
4545 // engine characteristics
46 static _LIBCPP_CONSTEXPR const size_t block_size = __p;
47 static _LIBCPP_CONSTEXPR const size_t used_block = __r;
46 static inline _LIBCPP_CONSTEXPR const size_t block_size = __p;
47 static inline _LIBCPP_CONSTEXPR const size_t used_block = __r;
4848
4949#ifdef _LIBCPP_CXX03_LANG
5050 static const result_type _Min = _Engine::_Min;
......@@ -110,12 +110,6 @@ public:
110110 operator>>(basic_istream<_CharT, _Traits>& __is, discard_block_engine<_Eng, _Pp, _Rp>& __x);
111111};
112112
113template <class _Engine, size_t __p, size_t __r>
114_LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size;
115
116template <class _Engine, size_t __p, size_t __r>
117_LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block;
118
119113template <class _Engine, size_t __p, size_t __r>
120114typename discard_block_engine<_Engine, __p, __r>::result_type discard_block_engine<_Engine, __p, __r>::operator()() {
121115 if (__n_ >= static_cast<int>(__r)) {
lib/libcxx/include/__random/discrete_distribution.h+2-2
......@@ -13,10 +13,10 @@
1313#include <__config>
1414#include <__random/is_valid.h>
1515#include <__random/uniform_real_distribution.h>
16#include <cstddef>
16#include <__vector/vector.h>
17#include <initializer_list>
1718#include <iosfwd>
1819#include <numeric>
19#include <vector>
2020
2121#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2222# pragma GCC system_header
lib/libcxx/include/__random/independent_bits_engine.h+1-1
......@@ -10,6 +10,7 @@
1010#define _LIBCPP___RANDOM_INDEPENDENT_BITS_ENGINE_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__fwd/istream.h>
1415#include <__fwd/ostream.h>
1516#include <__random/is_seed_sequence.h>
......@@ -18,7 +19,6 @@
1819#include <__type_traits/enable_if.h>
1920#include <__type_traits/is_convertible.h>
2021#include <__utility/move.h>
21#include <cstddef>
2222#include <limits>
2323
2424#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__random/is_valid.h+2-2
......@@ -66,12 +66,12 @@ struct __libcpp_random_is_valid_inttype<unsigned long> : true_type {};
6666template <>
6767struct __libcpp_random_is_valid_inttype<unsigned long long> : true_type {};
6868
69#ifndef _LIBCPP_HAS_NO_INT128
69#if _LIBCPP_HAS_INT128
7070template <>
7171struct __libcpp_random_is_valid_inttype<__int128_t> : true_type {}; // extension
7272template <>
7373struct __libcpp_random_is_valid_inttype<__uint128_t> : true_type {}; // extension
74#endif // _LIBCPP_HAS_NO_INT128
74#endif // _LIBCPP_HAS_INT128
7575
7676// [rand.req.urng]/3:
7777// A class G meets the uniform random bit generator requirements if G models
lib/libcxx/include/__random/linear_congruential_engine.h+6-22
......@@ -48,7 +48,7 @@ struct __lce_alg_picker {
4848 : _Schrage ? _LCE_Schrage
4949 : _LCE_Promote;
5050
51#ifdef _LIBCPP_HAS_NO_INT128
51#if !_LIBCPP_HAS_INT128
5252 static_assert(_Mp != (unsigned long long)(-1) || _Full || _Part || _Schrage,
5353 "The current values for a, c, and m are not currently supported on platforms without __int128");
5454#endif
......@@ -63,7 +63,7 @@ struct __lce_ta;
6363
6464// 64
6565
66#ifndef _LIBCPP_HAS_NO_INT128
66#if _LIBCPP_HAS_INT128
6767template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp>
6868struct __lce_ta<_Ap, _Cp, _Mp, (unsigned long long)(-1), _LCE_Promote> {
6969 typedef unsigned long long result_type;
......@@ -251,12 +251,12 @@ public:
251251 static_assert(_Min < _Max, "linear_congruential_engine invalid parameters");
252252
253253 // engine characteristics
254 static _LIBCPP_CONSTEXPR const result_type multiplier = __a;
255 static _LIBCPP_CONSTEXPR const result_type increment = __c;
256 static _LIBCPP_CONSTEXPR const result_type modulus = __m;
254 static inline _LIBCPP_CONSTEXPR const result_type multiplier = __a;
255 static inline _LIBCPP_CONSTEXPR const result_type increment = __c;
256 static inline _LIBCPP_CONSTEXPR const result_type modulus = __m;
257257 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
258258 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
259 static _LIBCPP_CONSTEXPR const result_type default_seed = 1u;
259 static inline _LIBCPP_CONSTEXPR const result_type default_seed = 1u;
260260
261261 // constructors and seeding functions
262262#ifndef _LIBCPP_CXX03_LANG
......@@ -318,22 +318,6 @@ private:
318318 operator>>(basic_istream<_CharT, _Traits>& __is, linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x);
319319};
320320
321template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
322_LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
323 linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier;
324
325template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
326_LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
327 linear_congruential_engine<_UIntType, __a, __c, __m>::increment;
328
329template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
330_LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
331 linear_congruential_engine<_UIntType, __a, __c, __m>::modulus;
332
333template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
334_LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type
335 linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed;
336
337321template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
338322template <class _Sseq>
339323void linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, integral_constant<unsigned, 1>) {
lib/libcxx/include/__random/log2.h+5-5
......@@ -10,8 +10,8 @@
1010#define _LIBCPP___RANDOM_LOG2_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__type_traits/conditional.h>
14#include <cstddef>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717# pragma GCC system_header
......@@ -38,7 +38,7 @@ struct __log2_imp<unsigned long long, 0, _Rp> {
3838 static const size_t value = _Rp + 1;
3939};
4040
41#ifndef _LIBCPP_HAS_NO_INT128
41#if _LIBCPP_HAS_INT128
4242
4343template <__uint128_t _Xp, size_t _Rp>
4444struct __log2_imp<__uint128_t, _Xp, _Rp> {
......@@ -47,16 +47,16 @@ struct __log2_imp<__uint128_t, _Xp, _Rp> {
4747 : __log2_imp<unsigned long long, _Xp, 63>::value;
4848};
4949
50#endif // _LIBCPP_HAS_NO_INT128
50#endif // _LIBCPP_HAS_INT128
5151
5252template <class _UIntType, _UIntType _Xp>
5353struct __log2 {
5454 static const size_t value = __log2_imp<
55#ifndef _LIBCPP_HAS_NO_INT128
55#if _LIBCPP_HAS_INT128
5656 __conditional_t<sizeof(_UIntType) <= sizeof(unsigned long long), unsigned long long, __uint128_t>,
5757#else
5858 unsigned long long,
59#endif // _LIBCPP_HAS_NO_INT128
59#endif // _LIBCPP_HAS_INT128
6060 _Xp,
6161 sizeof(_UIntType) * __CHAR_BIT__ - 1>::value;
6262};
lib/libcxx/include/__random/mersenne_twister_engine.h+16-338
......@@ -12,8 +12,9 @@
1212#include <__algorithm/equal.h>
1313#include <__algorithm/min.h>
1414#include <__config>
15#include <__cstddef/size_t.h>
1516#include <__random/is_seed_sequence.h>
16#include <cstddef>
17#include <__type_traits/enable_if.h>
1718#include <cstdint>
1819#include <iosfwd>
1920#include <limits>
......@@ -165,22 +166,22 @@ public:
165166 static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters");
166167
167168 // engine characteristics
168 static _LIBCPP_CONSTEXPR const size_t word_size = __w;
169 static _LIBCPP_CONSTEXPR const size_t state_size = __n;
170 static _LIBCPP_CONSTEXPR const size_t shift_size = __m;
171 static _LIBCPP_CONSTEXPR const size_t mask_bits = __r;
172 static _LIBCPP_CONSTEXPR const result_type xor_mask = __a;
173 static _LIBCPP_CONSTEXPR const size_t tempering_u = __u;
174 static _LIBCPP_CONSTEXPR const result_type tempering_d = __d;
175 static _LIBCPP_CONSTEXPR const size_t tempering_s = __s;
176 static _LIBCPP_CONSTEXPR const result_type tempering_b = __b;
177 static _LIBCPP_CONSTEXPR const size_t tempering_t = __t;
178 static _LIBCPP_CONSTEXPR const result_type tempering_c = __c;
179 static _LIBCPP_CONSTEXPR const size_t tempering_l = __l;
180 static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f;
169 static inline _LIBCPP_CONSTEXPR const size_t word_size = __w;
170 static inline _LIBCPP_CONSTEXPR const size_t state_size = __n;
171 static inline _LIBCPP_CONSTEXPR const size_t shift_size = __m;
172 static inline _LIBCPP_CONSTEXPR const size_t mask_bits = __r;
173 static inline _LIBCPP_CONSTEXPR const result_type xor_mask = __a;
174 static inline _LIBCPP_CONSTEXPR const size_t tempering_u = __u;
175 static inline _LIBCPP_CONSTEXPR const result_type tempering_d = __d;
176 static inline _LIBCPP_CONSTEXPR const size_t tempering_s = __s;
177 static inline _LIBCPP_CONSTEXPR const result_type tempering_b = __b;
178 static inline _LIBCPP_CONSTEXPR const size_t tempering_t = __t;
179 static inline _LIBCPP_CONSTEXPR const result_type tempering_c = __c;
180 static inline _LIBCPP_CONSTEXPR const size_t tempering_l = __l;
181 static inline _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f;
181182 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
182183 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
183 static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u;
184 static inline _LIBCPP_CONSTEXPR const result_type default_seed = 5489u;
184185
185186 // constructors and seeding functions
186187#ifndef _LIBCPP_CXX03_LANG
......@@ -309,329 +310,6 @@ private:
309310 }
310311};
311312
312template <class _UIntType,
313 size_t __w,
314 size_t __n,
315 size_t __m,
316 size_t __r,
317 _UIntType __a,
318 size_t __u,
319 _UIntType __d,
320 size_t __s,
321 _UIntType __b,
322 size_t __t,
323 _UIntType __c,
324 size_t __l,
325 _UIntType __f>
326_LIBCPP_CONSTEXPR const size_t
327 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size;
328
329template <class _UIntType,
330 size_t __w,
331 size_t __n,
332 size_t __m,
333 size_t __r,
334 _UIntType __a,
335 size_t __u,
336 _UIntType __d,
337 size_t __s,
338 _UIntType __b,
339 size_t __t,
340 _UIntType __c,
341 size_t __l,
342 _UIntType __f>
343_LIBCPP_CONSTEXPR const size_t
344 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size;
345
346template <class _UIntType,
347 size_t __w,
348 size_t __n,
349 size_t __m,
350 size_t __r,
351 _UIntType __a,
352 size_t __u,
353 _UIntType __d,
354 size_t __s,
355 _UIntType __b,
356 size_t __t,
357 _UIntType __c,
358 size_t __l,
359 _UIntType __f>
360_LIBCPP_CONSTEXPR const size_t
361 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size;
362
363template <class _UIntType,
364 size_t __w,
365 size_t __n,
366 size_t __m,
367 size_t __r,
368 _UIntType __a,
369 size_t __u,
370 _UIntType __d,
371 size_t __s,
372 _UIntType __b,
373 size_t __t,
374 _UIntType __c,
375 size_t __l,
376 _UIntType __f>
377_LIBCPP_CONSTEXPR const size_t
378 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits;
379
380template <class _UIntType,
381 size_t __w,
382 size_t __n,
383 size_t __m,
384 size_t __r,
385 _UIntType __a,
386 size_t __u,
387 _UIntType __d,
388 size_t __s,
389 _UIntType __b,
390 size_t __t,
391 _UIntType __c,
392 size_t __l,
393 _UIntType __f>
394_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
395 _UIntType,
396 __w,
397 __n,
398 __m,
399 __r,
400 __a,
401 __u,
402 __d,
403 __s,
404 __b,
405 __t,
406 __c,
407 __l,
408 __f>::result_type
409 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask;
410
411template <class _UIntType,
412 size_t __w,
413 size_t __n,
414 size_t __m,
415 size_t __r,
416 _UIntType __a,
417 size_t __u,
418 _UIntType __d,
419 size_t __s,
420 _UIntType __b,
421 size_t __t,
422 _UIntType __c,
423 size_t __l,
424 _UIntType __f>
425_LIBCPP_CONSTEXPR const size_t
426 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u;
427
428template <class _UIntType,
429 size_t __w,
430 size_t __n,
431 size_t __m,
432 size_t __r,
433 _UIntType __a,
434 size_t __u,
435 _UIntType __d,
436 size_t __s,
437 _UIntType __b,
438 size_t __t,
439 _UIntType __c,
440 size_t __l,
441 _UIntType __f>
442_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
443 _UIntType,
444 __w,
445 __n,
446 __m,
447 __r,
448 __a,
449 __u,
450 __d,
451 __s,
452 __b,
453 __t,
454 __c,
455 __l,
456 __f>::result_type
457 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d;
458
459template <class _UIntType,
460 size_t __w,
461 size_t __n,
462 size_t __m,
463 size_t __r,
464 _UIntType __a,
465 size_t __u,
466 _UIntType __d,
467 size_t __s,
468 _UIntType __b,
469 size_t __t,
470 _UIntType __c,
471 size_t __l,
472 _UIntType __f>
473_LIBCPP_CONSTEXPR const size_t
474 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s;
475
476template <class _UIntType,
477 size_t __w,
478 size_t __n,
479 size_t __m,
480 size_t __r,
481 _UIntType __a,
482 size_t __u,
483 _UIntType __d,
484 size_t __s,
485 _UIntType __b,
486 size_t __t,
487 _UIntType __c,
488 size_t __l,
489 _UIntType __f>
490_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
491 _UIntType,
492 __w,
493 __n,
494 __m,
495 __r,
496 __a,
497 __u,
498 __d,
499 __s,
500 __b,
501 __t,
502 __c,
503 __l,
504 __f>::result_type
505 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b;
506
507template <class _UIntType,
508 size_t __w,
509 size_t __n,
510 size_t __m,
511 size_t __r,
512 _UIntType __a,
513 size_t __u,
514 _UIntType __d,
515 size_t __s,
516 _UIntType __b,
517 size_t __t,
518 _UIntType __c,
519 size_t __l,
520 _UIntType __f>
521_LIBCPP_CONSTEXPR const size_t
522 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t;
523
524template <class _UIntType,
525 size_t __w,
526 size_t __n,
527 size_t __m,
528 size_t __r,
529 _UIntType __a,
530 size_t __u,
531 _UIntType __d,
532 size_t __s,
533 _UIntType __b,
534 size_t __t,
535 _UIntType __c,
536 size_t __l,
537 _UIntType __f>
538_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
539 _UIntType,
540 __w,
541 __n,
542 __m,
543 __r,
544 __a,
545 __u,
546 __d,
547 __s,
548 __b,
549 __t,
550 __c,
551 __l,
552 __f>::result_type
553 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c;
554
555template <class _UIntType,
556 size_t __w,
557 size_t __n,
558 size_t __m,
559 size_t __r,
560 _UIntType __a,
561 size_t __u,
562 _UIntType __d,
563 size_t __s,
564 _UIntType __b,
565 size_t __t,
566 _UIntType __c,
567 size_t __l,
568 _UIntType __f>
569_LIBCPP_CONSTEXPR const size_t
570 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l;
571
572template <class _UIntType,
573 size_t __w,
574 size_t __n,
575 size_t __m,
576 size_t __r,
577 _UIntType __a,
578 size_t __u,
579 _UIntType __d,
580 size_t __s,
581 _UIntType __b,
582 size_t __t,
583 _UIntType __c,
584 size_t __l,
585 _UIntType __f>
586_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
587 _UIntType,
588 __w,
589 __n,
590 __m,
591 __r,
592 __a,
593 __u,
594 __d,
595 __s,
596 __b,
597 __t,
598 __c,
599 __l,
600 __f>::result_type
601 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::
602 initialization_multiplier;
603
604template <class _UIntType,
605 size_t __w,
606 size_t __n,
607 size_t __m,
608 size_t __r,
609 _UIntType __a,
610 size_t __u,
611 _UIntType __d,
612 size_t __s,
613 _UIntType __b,
614 size_t __t,
615 _UIntType __c,
616 size_t __l,
617 _UIntType __f>
618_LIBCPP_CONSTEXPR const typename mersenne_twister_engine<
619 _UIntType,
620 __w,
621 __n,
622 __m,
623 __r,
624 __a,
625 __u,
626 __d,
627 __s,
628 __b,
629 __t,
630 __c,
631 __l,
632 __f>::result_type
633 mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed;
634
635313template <class _UIntType,
636314 size_t __w,
637315 size_t __n,
lib/libcxx/include/__random/piecewise_constant_distribution.h+3-1
......@@ -11,11 +11,13 @@
1111
1212#include <__algorithm/upper_bound.h>
1313#include <__config>
14#include <__cstddef/ptrdiff_t.h>
1415#include <__random/is_valid.h>
1516#include <__random/uniform_real_distribution.h>
17#include <__vector/vector.h>
18#include <initializer_list>
1619#include <iosfwd>
1720#include <numeric>
18#include <vector>
1921
2022#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2123# pragma GCC system_header
lib/libcxx/include/__random/piecewise_linear_distribution.h+4-1
......@@ -11,11 +11,14 @@
1111
1212#include <__algorithm/upper_bound.h>
1313#include <__config>
14#include <__cstddef/ptrdiff_t.h>
1415#include <__random/is_valid.h>
1516#include <__random/uniform_real_distribution.h>
17#include <__vector/comparison.h>
18#include <__vector/vector.h>
1619#include <cmath>
20#include <initializer_list>
1721#include <iosfwd>
18#include <vector>
1922
2023#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2124# pragma GCC system_header
lib/libcxx/include/__random/random_device.h+2-2
......@@ -21,7 +21,7 @@ _LIBCPP_PUSH_MACROS
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
2323
24#if !defined(_LIBCPP_HAS_NO_RANDOM_DEVICE)
24#if _LIBCPP_HAS_RANDOM_DEVICE
2525
2626class _LIBCPP_EXPORTED_FROM_ABI random_device {
2727# ifdef _LIBCPP_USING_DEV_RANDOM
......@@ -72,7 +72,7 @@ public:
7272 void operator=(const random_device&) = delete;
7373};
7474
75#endif // !_LIBCPP_HAS_NO_RANDOM_DEVICE
75#endif // _LIBCPP_HAS_RANDOM_DEVICE
7676
7777_LIBCPP_END_NAMESPACE_STD
7878
lib/libcxx/include/__random/seed_seq.h+3-1
......@@ -14,10 +14,12 @@
1414#include <__algorithm/max.h>
1515#include <__config>
1616#include <__iterator/iterator_traits.h>
17#include <__type_traits/enable_if.h>
18#include <__type_traits/is_integral.h>
1719#include <__type_traits/is_unsigned.h>
20#include <__vector/vector.h>
1821#include <cstdint>
1922#include <initializer_list>
20#include <vector>
2123
2224#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2325# pragma GCC system_header
lib/libcxx/include/__random/shuffle_order_engine.h+2-5
......@@ -11,12 +11,12 @@
1111
1212#include <__algorithm/equal.h>
1313#include <__config>
14#include <__cstddef/size_t.h>
1415#include <__random/is_seed_sequence.h>
1516#include <__type_traits/enable_if.h>
1617#include <__type_traits/integral_constant.h>
1718#include <__type_traits/is_convertible.h>
1819#include <__utility/move.h>
19#include <cstddef>
2020#include <cstdint>
2121#include <iosfwd>
2222
......@@ -66,7 +66,7 @@ private:
6666
6767public:
6868 // engine characteristics
69 static _LIBCPP_CONSTEXPR const size_t table_size = __k;
69 static inline _LIBCPP_CONSTEXPR const size_t table_size = __k;
7070
7171#ifdef _LIBCPP_CXX03_LANG
7272 static const result_type _Min = _Engine::_Min;
......@@ -173,9 +173,6 @@ private:
173173 }
174174};
175175
176template <class _Engine, size_t __k>
177_LIBCPP_CONSTEXPR const size_t shuffle_order_engine<_Engine, __k>::table_size;
178
179176template <class _Eng, size_t _Kp>
180177_LIBCPP_HIDE_FROM_ABI bool
181178operator==(const shuffle_order_engine<_Eng, _Kp>& __x, const shuffle_order_engine<_Eng, _Kp>& __y) {
lib/libcxx/include/__random/subtract_with_carry_engine.h+6-18
......@@ -12,9 +12,10 @@
1212#include <__algorithm/equal.h>
1313#include <__algorithm/min.h>
1414#include <__config>
15#include <__cstddef/size_t.h>
1516#include <__random/is_seed_sequence.h>
1617#include <__random/linear_congruential_engine.h>
17#include <cstddef>
18#include <__type_traits/enable_if.h>
1819#include <cstdint>
1920#include <iosfwd>
2021#include <limits>
......@@ -71,12 +72,12 @@ public:
7172 static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters");
7273
7374 // engine characteristics
74 static _LIBCPP_CONSTEXPR const size_t word_size = __w;
75 static _LIBCPP_CONSTEXPR const size_t short_lag = __s;
76 static _LIBCPP_CONSTEXPR const size_t long_lag = __r;
75 static inline _LIBCPP_CONSTEXPR const size_t word_size = __w;
76 static inline _LIBCPP_CONSTEXPR const size_t short_lag = __s;
77 static inline _LIBCPP_CONSTEXPR const size_t long_lag = __r;
7778 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type min() { return _Min; }
7879 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR result_type max() { return _Max; }
79 static _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u;
80 static inline _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u;
8081
8182 // constructors and seeding functions
8283#ifndef _LIBCPP_CXX03_LANG
......@@ -129,19 +130,6 @@ private:
129130 _LIBCPP_HIDE_FROM_ABI void __seed(_Sseq& __q, integral_constant<unsigned, 2>);
130131};
131132
132template <class _UIntType, size_t __w, size_t __s, size_t __r>
133_LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size;
134
135template <class _UIntType, size_t __w, size_t __s, size_t __r>
136_LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag;
137
138template <class _UIntType, size_t __w, size_t __s, size_t __r>
139_LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag;
140
141template <class _UIntType, size_t __w, size_t __s, size_t __r>
142_LIBCPP_CONSTEXPR const typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::result_type
143 subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed;
144
145133template <class _UIntType, size_t __w, size_t __s, size_t __r>
146134void subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, integral_constant<unsigned, 1>) {
147135 linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> __e(__sd == 0u ? default_seed : __sd);
lib/libcxx/include/__random/uniform_int_distribution.h+1-1
......@@ -11,11 +11,11 @@
1111
1212#include <__bit/countl.h>
1313#include <__config>
14#include <__cstddef/size_t.h>
1415#include <__random/is_valid.h>
1516#include <__random/log2.h>
1617#include <__type_traits/conditional.h>
1718#include <__type_traits/make_unsigned.h>
18#include <cstddef>
1919#include <cstdint>
2020#include <iosfwd>
2121#include <limits>
lib/libcxx/include/__random/uniform_random_bit_generator.h+1-1
......@@ -13,8 +13,8 @@
1313#include <__concepts/invocable.h>
1414#include <__concepts/same_as.h>
1515#include <__config>
16#include <__functional/invoke.h>
1716#include <__type_traits/integral_constant.h>
17#include <__type_traits/invoke.h>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2020# pragma GCC system_header
lib/libcxx/include/__ranges/access.h+1-1
......@@ -12,6 +12,7 @@
1212
1313#include <__concepts/class_or_enum.h>
1414#include <__config>
15#include <__cstddef/size_t.h>
1516#include <__iterator/concepts.h>
1617#include <__iterator/readable_traits.h>
1718#include <__ranges/enable_borrowed_range.h>
......@@ -21,7 +22,6 @@
2122#include <__type_traits/remove_reference.h>
2223#include <__utility/auto_cast.h>
2324#include <__utility/declval.h>
24#include <cstddef>
2525
2626#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2727# pragma GCC system_header
lib/libcxx/include/__ranges/chunk_by_view.h+2-2
......@@ -59,7 +59,7 @@ class _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS chunk_by_view : public view_interface
5959 _LIBCPP_NO_UNIQUE_ADDRESS __movable_box<_Pred> __pred_;
6060
6161 // We cache the result of begin() to allow providing an amortized O(1).
62 using _Cache = __non_propagating_cache<iterator_t<_View>>;
62 using _Cache _LIBCPP_NODEBUG = __non_propagating_cache<iterator_t<_View>>;
6363 _Cache __cached_begin_;
6464
6565 class __iterator;
......@@ -215,7 +215,7 @@ struct __fn {
215215 requires constructible_from<decay_t<_Pred>, _Pred>
216216 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Pred&& __pred) const
217217 noexcept(is_nothrow_constructible_v<decay_t<_Pred>, _Pred>) {
218 return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Pred>(__pred)));
218 return __pipeable(std::__bind_back(*this, std::forward<_Pred>(__pred)));
219219 }
220220};
221221} // namespace __chunk_by
lib/libcxx/include/__ranges/counted.h+1-1
......@@ -12,6 +12,7 @@
1212
1313#include <__concepts/convertible_to.h>
1414#include <__config>
15#include <__cstddef/size_t.h>
1516#include <__iterator/concepts.h>
1617#include <__iterator/counted_iterator.h>
1718#include <__iterator/default_sentinel.h>
......@@ -22,7 +23,6 @@
2223#include <__type_traits/decay.h>
2324#include <__utility/forward.h>
2425#include <__utility/move.h>
25#include <cstddef>
2626#include <span>
2727
2828#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__ranges/drop_view.h+4-4
......@@ -15,6 +15,7 @@
1515#include <__concepts/constructible.h>
1616#include <__concepts/convertible_to.h>
1717#include <__config>
18#include <__cstddef/size_t.h>
1819#include <__functional/bind_back.h>
1920#include <__fwd/span.h>
2021#include <__fwd/string_view.h>
......@@ -42,7 +43,6 @@
4243#include <__utility/auto_cast.h>
4344#include <__utility/forward.h>
4445#include <__utility/move.h>
45#include <cstddef>
4646
4747#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4848# pragma GCC system_header
......@@ -64,7 +64,7 @@ class drop_view : public view_interface<drop_view<_View>> {
6464 // Note: drop_view<input-range>::begin() is still trivially amortized O(1) because
6565 // one can't call begin() on it more than once.
6666 static constexpr bool _UseCache = forward_range<_View> && !(random_access_range<_View> && sized_range<_View>);
67 using _Cache = _If<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
67 using _Cache _LIBCPP_NODEBUG = _If<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
6868 _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache();
6969 range_difference_t<_View> __count_ = 0;
7070 _View __base_ = _View();
......@@ -204,7 +204,7 @@ struct __passthrough_type<subrange<_Iter, _Sent, _Kind>> {
204204};
205205
206206template <class _Tp>
207using __passthrough_type_t = typename __passthrough_type<_Tp>::type;
207using __passthrough_type_t _LIBCPP_NODEBUG = typename __passthrough_type<_Tp>::type;
208208
209209struct __fn {
210210 // [range.drop.overview]: the `empty_view` case.
......@@ -307,7 +307,7 @@ struct __fn {
307307 requires constructible_from<decay_t<_Np>, _Np>
308308 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Np&& __n) const
309309 noexcept(is_nothrow_constructible_v<decay_t<_Np>, _Np>) {
310 return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Np>(__n)));
310 return __pipeable(std::__bind_back(*this, std::forward<_Np>(__n)));
311311 }
312312};
313313
lib/libcxx/include/__ranges/drop_while_view.h+2-2
......@@ -90,7 +90,7 @@ private:
9090 _LIBCPP_NO_UNIQUE_ADDRESS __movable_box<_Pred> __pred_;
9191
9292 static constexpr bool _UseCache = forward_range<_View>;
93 using _Cache = _If<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
93 using _Cache _LIBCPP_NODEBUG = _If<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
9494 _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache();
9595};
9696
......@@ -115,7 +115,7 @@ struct __fn {
115115 requires constructible_from<decay_t<_Pred>, _Pred>
116116 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Pred&& __pred) const
117117 noexcept(is_nothrow_constructible_v<decay_t<_Pred>, _Pred>) {
118 return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Pred>(__pred)));
118 return __pipeable(std::__bind_back(*this, std::forward<_Pred>(__pred)));
119119 }
120120};
121121
lib/libcxx/include/__ranges/elements_view.h+4-4
......@@ -16,7 +16,7 @@
1616#include <__concepts/derived_from.h>
1717#include <__concepts/equality_comparable.h>
1818#include <__config>
19#include <__fwd/complex.h>
19#include <__fwd/get.h>
2020#include <__iterator/concepts.h>
2121#include <__iterator/iterator_traits.h>
2222#include <__ranges/access.h>
......@@ -37,7 +37,7 @@
3737#include <__utility/declval.h>
3838#include <__utility/forward.h>
3939#include <__utility/move.h>
40#include <cstddef>
40#include <tuple> // std::get
4141
4242#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4343# pragma GCC system_header
......@@ -171,7 +171,7 @@ class elements_view<_View, _Np>::__iterator
171171 template <bool>
172172 friend class __sentinel;
173173
174 using _Base = __maybe_const<_Const, _View>;
174 using _Base _LIBCPP_NODEBUG = __maybe_const<_Const, _View>;
175175
176176 iterator_t<_Base> __current_ = iterator_t<_Base>();
177177
......@@ -335,7 +335,7 @@ template <input_range _View, size_t _Np>
335335template <bool _Const>
336336class elements_view<_View, _Np>::__sentinel {
337337private:
338 using _Base = __maybe_const<_Const, _View>;
338 using _Base _LIBCPP_NODEBUG = __maybe_const<_Const, _View>;
339339 _LIBCPP_NO_UNIQUE_ADDRESS sentinel_t<_Base> __end_ = sentinel_t<_Base>();
340340
341341 template <bool>
lib/libcxx/include/__ranges/empty_view.h+1-1
......@@ -11,10 +11,10 @@
1111#define _LIBCPP___RANGES_EMPTY_VIEW_H
1212
1313#include <__config>
14#include <__cstddef/size_t.h>
1415#include <__ranges/enable_borrowed_range.h>
1516#include <__ranges/view_interface.h>
1617#include <__type_traits/is_object.h>
17#include <cstddef>
1818
1919#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2020# pragma GCC system_header
lib/libcxx/include/__ranges/filter_view.h+3-3
......@@ -61,7 +61,7 @@ class _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS filter_view : public view_interface<f
6161 // We cache the result of begin() to allow providing an amortized O(1) begin() whenever
6262 // the underlying range is at least a forward_range.
6363 static constexpr bool _UseCache = forward_range<_View>;
64 using _Cache = _If<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
64 using _Cache _LIBCPP_NODEBUG = _If<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
6565 _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache();
6666
6767 class __iterator;
......@@ -115,7 +115,7 @@ struct __filter_iterator_category {};
115115
116116template <forward_range _View>
117117struct __filter_iterator_category<_View> {
118 using _Cat = typename iterator_traits<iterator_t<_View>>::iterator_category;
118 using _Cat _LIBCPP_NODEBUG = typename iterator_traits<iterator_t<_View>>::iterator_category;
119119 using iterator_category =
120120 _If<derived_from<_Cat, bidirectional_iterator_tag>,
121121 bidirectional_iterator_tag,
......@@ -239,7 +239,7 @@ struct __fn {
239239 requires constructible_from<decay_t<_Pred>, _Pred>
240240 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Pred&& __pred) const
241241 noexcept(is_nothrow_constructible_v<decay_t<_Pred>, _Pred>) {
242 return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Pred>(__pred)));
242 return __pipeable(std::__bind_back(*this, std::forward<_Pred>(__pred)));
243243 }
244244};
245245} // namespace __filter
lib/libcxx/include/__ranges/iota_view.h+1-1
......@@ -68,7 +68,7 @@ struct __get_wider_signed {
6868};
6969
7070template <class _Start>
71using _IotaDiffT =
71using _IotaDiffT _LIBCPP_NODEBUG =
7272 typename _If< (!integral<_Start> || sizeof(iter_difference_t<_Start>) > sizeof(_Start)),
7373 type_identity<iter_difference_t<_Start>>,
7474 __get_wider_signed<_Start> >::type;
lib/libcxx/include/__ranges/istream_view.h+2-2
......@@ -14,6 +14,7 @@
1414#include <__concepts/derived_from.h>
1515#include <__concepts/movable.h>
1616#include <__config>
17#include <__cstddef/ptrdiff_t.h>
1718#include <__fwd/istream.h>
1819#include <__fwd/string.h>
1920#include <__iterator/default_sentinel.h>
......@@ -22,7 +23,6 @@
2223#include <__ranges/view_interface.h>
2324#include <__type_traits/remove_cvref.h>
2425#include <__utility/forward.h>
25#include <cstddef>
2626
2727#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2828# pragma GCC system_header
......@@ -99,7 +99,7 @@ private:
9999template <class _Val>
100100using istream_view = basic_istream_view<_Val, char>;
101101
102# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
102# if _LIBCPP_HAS_WIDE_CHARACTERS
103103template <class _Val>
104104using wistream_view = basic_istream_view<_Val, wchar_t>;
105105# endif
lib/libcxx/include/__ranges/join_view.h+18-17
......@@ -55,8 +55,8 @@ struct __join_view_iterator_category {};
5555template <class _View>
5656 requires is_reference_v<range_reference_t<_View>> && forward_range<_View> && forward_range<range_reference_t<_View>>
5757struct __join_view_iterator_category<_View> {
58 using _OuterC = typename iterator_traits<iterator_t<_View>>::iterator_category;
59 using _InnerC = typename iterator_traits<iterator_t<range_reference_t<_View>>>::iterator_category;
58 using _OuterC _LIBCPP_NODEBUG = typename iterator_traits<iterator_t<_View>>::iterator_category;
59 using _InnerC _LIBCPP_NODEBUG = typename iterator_traits<iterator_t<range_reference_t<_View>>>::iterator_category;
6060
6161 using iterator_category =
6262 _If< derived_from<_OuterC, bidirectional_iterator_tag> && derived_from<_InnerC, bidirectional_iterator_tag> &&
......@@ -71,7 +71,7 @@ template <input_range _View>
7171 requires view<_View> && input_range<range_reference_t<_View>>
7272class join_view : public view_interface<join_view<_View>> {
7373private:
74 using _InnerRange = range_reference_t<_View>;
74 using _InnerRange _LIBCPP_NODEBUG = range_reference_t<_View>;
7575
7676 template <bool>
7777 struct __iterator;
......@@ -85,11 +85,12 @@ private:
8585 _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
8686
8787 static constexpr bool _UseOuterCache = !forward_range<_View>;
88 using _OuterCache = _If<_UseOuterCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
88 using _OuterCache _LIBCPP_NODEBUG = _If<_UseOuterCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
8989 _LIBCPP_NO_UNIQUE_ADDRESS _OuterCache __outer_;
9090
9191 static constexpr bool _UseInnerCache = !is_reference_v<_InnerRange>;
92 using _InnerCache = _If<_UseInnerCache, __non_propagating_cache<remove_cvref_t<_InnerRange>>, __empty_cache>;
92 using _InnerCache _LIBCPP_NODEBUG =
93 _If<_UseInnerCache, __non_propagating_cache<remove_cvref_t<_InnerRange>>, __empty_cache>;
9394 _LIBCPP_NO_UNIQUE_ADDRESS _InnerCache __inner_;
9495
9596public:
......@@ -155,9 +156,9 @@ private:
155156 template <bool>
156157 friend struct __sentinel;
157158
158 using _Parent = __maybe_const<_Const, join_view>;
159 using _Base = __maybe_const<_Const, _View>;
160 sentinel_t<_Base> __end_ = sentinel_t<_Base>();
159 using _Parent _LIBCPP_NODEBUG = __maybe_const<_Const, join_view>;
160 using _Base _LIBCPP_NODEBUG = __maybe_const<_Const, _View>;
161 sentinel_t<_Base> __end_ = sentinel_t<_Base>();
161162
162163public:
163164 _LIBCPP_HIDE_FROM_ABI __sentinel() = default;
......@@ -190,18 +191,18 @@ struct join_view<_View>::__iterator final : public __join_view_iterator_category
190191 static constexpr bool __is_join_view_iterator = true;
191192
192193private:
193 using _Parent = __maybe_const<_Const, join_view<_View>>;
194 using _Base = __maybe_const<_Const, _View>;
195 using _Outer = iterator_t<_Base>;
196 using _Inner = iterator_t<range_reference_t<_Base>>;
197 using _InnerRange = range_reference_t<_View>;
194 using _Parent _LIBCPP_NODEBUG = __maybe_const<_Const, join_view<_View>>;
195 using _Base _LIBCPP_NODEBUG = __maybe_const<_Const, _View>;
196 using _Outer _LIBCPP_NODEBUG = iterator_t<_Base>;
197 using _Inner _LIBCPP_NODEBUG = iterator_t<range_reference_t<_Base>>;
198 using _InnerRange _LIBCPP_NODEBUG = range_reference_t<_View>;
198199
199200 static_assert(!_Const || forward_range<_Base>, "Const can only be true when Base models forward_range.");
200201
201202 static constexpr bool __ref_is_glvalue = is_reference_v<range_reference_t<_Base>>;
202203
203204 static constexpr bool _OuterPresent = forward_range<_Base>;
204 using _OuterType = _If<_OuterPresent, _Outer, std::__empty>;
205 using _OuterType _LIBCPP_NODEBUG = _If<_OuterPresent, _Outer, std::__empty>;
205206 _LIBCPP_NO_UNIQUE_ADDRESS _OuterType __outer_ = _OuterType();
206207
207208 optional<_Inner> __inner_;
......@@ -377,9 +378,9 @@ template <class _JoinViewIterator>
377378 __has_random_access_iterator_category<typename _JoinViewIterator::_Outer>::value &&
378379 __has_random_access_iterator_category<typename _JoinViewIterator::_Inner>::value)
379380struct __segmented_iterator_traits<_JoinViewIterator> {
380 using __segment_iterator =
381 _LIBCPP_NODEBUG __iterator_with_data<typename _JoinViewIterator::_Outer, typename _JoinViewIterator::_Parent*>;
382 using __local_iterator = typename _JoinViewIterator::_Inner;
381 using __segment_iterator _LIBCPP_NODEBUG =
382 __iterator_with_data<typename _JoinViewIterator::_Outer, typename _JoinViewIterator::_Parent*>;
383 using __local_iterator _LIBCPP_NODEBUG = typename _JoinViewIterator::_Inner;
383384
384385 // TODO: Would it make sense to enable the optimization for other iterator types?
385386
lib/libcxx/include/__ranges/lazy_split_view.h+7-6
......@@ -72,7 +72,8 @@ class lazy_split_view : public view_interface<lazy_split_view<_View, _Pattern>>
7272 _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
7373 _LIBCPP_NO_UNIQUE_ADDRESS _Pattern __pattern_ = _Pattern();
7474
75 using _MaybeCurrent = _If<!forward_range<_View>, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
75 using _MaybeCurrent _LIBCPP_NODEBUG =
76 _If<!forward_range<_View>, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
7677 _LIBCPP_NO_UNIQUE_ADDRESS _MaybeCurrent __current_ = _MaybeCurrent();
7778
7879 template <bool>
......@@ -146,11 +147,11 @@ private:
146147 friend struct __inner_iterator;
147148 friend __outer_iterator<true>;
148149
149 using _Parent = __maybe_const<_Const, lazy_split_view>;
150 using _Base = __maybe_const<_Const, _View>;
150 using _Parent _LIBCPP_NODEBUG = __maybe_const<_Const, lazy_split_view>;
151 using _Base _LIBCPP_NODEBUG = __maybe_const<_Const, _View>;
151152
152153 _Parent* __parent_ = nullptr;
153 using _MaybeCurrent = _If<forward_range<_View>, iterator_t<_Base>, __empty_cache>;
154 using _MaybeCurrent _LIBCPP_NODEBUG = _If<forward_range<_View>, iterator_t<_Base>, __empty_cache>;
154155 _LIBCPP_NO_UNIQUE_ADDRESS _MaybeCurrent __current_ = _MaybeCurrent();
155156 bool __trailing_empty_ = false;
156157
......@@ -283,7 +284,7 @@ private:
283284 template <bool _Const>
284285 struct __inner_iterator : __inner_iterator_category<__maybe_const<_Const, _View>> {
285286 private:
286 using _Base = __maybe_const<_Const, _View>;
287 using _Base _LIBCPP_NODEBUG = __maybe_const<_Const, _View>;
287288 // Workaround for a GCC issue.
288289 static constexpr bool _OuterConst = _Const;
289290 __outer_iterator<_Const> __i_ = __outer_iterator<_OuterConst>();
......@@ -420,7 +421,7 @@ struct __fn {
420421 requires constructible_from<decay_t<_Pattern>, _Pattern>
421422 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Pattern&& __pattern) const
422423 noexcept(is_nothrow_constructible_v<decay_t<_Pattern>, _Pattern>) {
423 return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Pattern>(__pattern)));
424 return __pipeable(std::__bind_back(*this, std::forward<_Pattern>(__pattern)));
424425 }
425426};
426427} // namespace __lazy_split_view
lib/libcxx/include/__ranges/range_adaptor.h+8-10
......@@ -19,8 +19,10 @@
1919#include <__functional/invoke.h>
2020#include <__ranges/concepts.h>
2121#include <__type_traits/decay.h>
22#include <__type_traits/invoke.h>
2223#include <__type_traits/is_class.h>
2324#include <__type_traits/is_nothrow_constructible.h>
25#include <__type_traits/remove_cv.h>
2426#include <__type_traits/remove_cvref.h>
2527#include <__utility/forward.h>
2628#include <__utility/move.h>
......@@ -45,15 +47,15 @@ namespace ranges {
4547// - `f1 | f2` is an adaptor closure `g` such that `g(x)` is equivalent to `f2(f1(x))`
4648template <class _Tp>
4749 requires is_class_v<_Tp> && same_as<_Tp, remove_cv_t<_Tp>>
48struct __range_adaptor_closure;
50struct __range_adaptor_closure {};
4951
5052// Type that wraps an arbitrary function object and makes it into a range adaptor closure,
5153// i.e. something that can be called via the `x | f` notation.
5254template <class _Fn>
53struct __range_adaptor_closure_t : _Fn, __range_adaptor_closure<__range_adaptor_closure_t<_Fn>> {
54 _LIBCPP_HIDE_FROM_ABI constexpr explicit __range_adaptor_closure_t(_Fn&& __f) : _Fn(std::move(__f)) {}
55struct __pipeable : _Fn, __range_adaptor_closure<__pipeable<_Fn>> {
56 _LIBCPP_HIDE_FROM_ABI constexpr explicit __pipeable(_Fn&& __f) : _Fn(std::move(__f)) {}
5557};
56_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(__range_adaptor_closure_t);
58_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(__pipeable);
5759
5860template <class _Tp>
5961_Tp __derived_from_range_adaptor_closure(__range_adaptor_closure<_Tp>*);
......@@ -77,17 +79,13 @@ template <_RangeAdaptorClosure _Closure, _RangeAdaptorClosure _OtherClosure>
7779[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator|(_Closure&& __c1, _OtherClosure&& __c2) noexcept(
7880 is_nothrow_constructible_v<decay_t<_Closure>, _Closure> &&
7981 is_nothrow_constructible_v<decay_t<_OtherClosure>, _OtherClosure>) {
80 return __range_adaptor_closure_t(std::__compose(std::forward<_OtherClosure>(__c2), std::forward<_Closure>(__c1)));
82 return __pipeable(std::__compose(std::forward<_OtherClosure>(__c2), std::forward<_Closure>(__c1)));
8183}
8284
83template <class _Tp>
84 requires is_class_v<_Tp> && same_as<_Tp, remove_cv_t<_Tp>>
85struct __range_adaptor_closure {};
86
8785# if _LIBCPP_STD_VER >= 23
8886template <class _Tp>
8987 requires is_class_v<_Tp> && same_as<_Tp, remove_cv_t<_Tp>>
90class range_adaptor_closure : public __range_adaptor_closure<_Tp> {};
88class _LIBCPP_NO_SPECIALIZATIONS range_adaptor_closure : public __range_adaptor_closure<_Tp> {};
9189# endif // _LIBCPP_STD_VER >= 23
9290
9391} // namespace ranges
lib/libcxx/include/__ranges/repeat_view.h+3-2
......@@ -15,6 +15,7 @@
1515#include <__concepts/same_as.h>
1616#include <__concepts/semiregular.h>
1717#include <__config>
18#include <__cstddef/ptrdiff_t.h>
1819#include <__iterator/concepts.h>
1920#include <__iterator/iterator_traits.h>
2021#include <__iterator/unreachable_sentinel.h>
......@@ -60,7 +61,7 @@ struct __repeat_view_iterator_difference<_Tp> {
6061};
6162
6263template <class _Tp>
63using __repeat_view_iterator_difference_t = typename __repeat_view_iterator_difference<_Tp>::type;
64using __repeat_view_iterator_difference_t _LIBCPP_NODEBUG = typename __repeat_view_iterator_difference<_Tp>::type;
6465
6566namespace views::__drop {
6667struct __fn;
......@@ -138,7 +139,7 @@ template <move_constructible _Tp, semiregular _Bound>
138139class repeat_view<_Tp, _Bound>::__iterator {
139140 friend class repeat_view;
140141
141 using _IndexT = conditional_t<same_as<_Bound, unreachable_sentinel_t>, ptrdiff_t, _Bound>;
142 using _IndexT _LIBCPP_NODEBUG = conditional_t<same_as<_Bound, unreachable_sentinel_t>, ptrdiff_t, _Bound>;
142143
143144 _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(const _Tp* __value, _IndexT __bound_sentinel = _IndexT())
144145 : __value_(__value), __current_(__bound_sentinel) {}
lib/libcxx/include/__ranges/reverse_view.h+2-1
......@@ -47,7 +47,8 @@ class reverse_view : public view_interface<reverse_view<_View>> {
4747 // We cache begin() whenever ranges::next is not guaranteed O(1) to provide an
4848 // amortized O(1) begin() method.
4949 static constexpr bool _UseCache = !random_access_range<_View> && !common_range<_View>;
50 using _Cache = _If<_UseCache, __non_propagating_cache<reverse_iterator<iterator_t<_View>>>, __empty_cache>;
50 using _Cache _LIBCPP_NODEBUG =
51 _If<_UseCache, __non_propagating_cache<reverse_iterator<iterator_t<_View>>>, __empty_cache>;
5152 _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache();
5253 _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
5354
lib/libcxx/include/__ranges/single_view.h+2-1
......@@ -12,6 +12,8 @@
1212
1313#include <__concepts/constructible.h>
1414#include <__config>
15#include <__cstddef/ptrdiff_t.h>
16#include <__cstddef/size_t.h>
1517#include <__ranges/movable_box.h>
1618#include <__ranges/range_adaptor.h>
1719#include <__ranges/view_interface.h>
......@@ -20,7 +22,6 @@
2022#include <__utility/forward.h>
2123#include <__utility/in_place.h>
2224#include <__utility/move.h>
23#include <cstddef>
2425
2526#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2627# pragma GCC system_header
lib/libcxx/include/__ranges/size.h+2-1
......@@ -13,6 +13,8 @@
1313#include <__concepts/arithmetic.h>
1414#include <__concepts/class_or_enum.h>
1515#include <__config>
16#include <__cstddef/ptrdiff_t.h>
17#include <__cstddef/size_t.h>
1618#include <__iterator/concepts.h>
1719#include <__iterator/iterator_traits.h>
1820#include <__ranges/access.h>
......@@ -22,7 +24,6 @@
2224#include <__type_traits/remove_cvref.h>
2325#include <__utility/auto_cast.h>
2426#include <__utility/declval.h>
25#include <cstddef>
2627
2728#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2829# pragma GCC system_header
lib/libcxx/include/__ranges/split_view.h+2-2
......@@ -52,7 +52,7 @@ class split_view : public view_interface<split_view<_View, _Pattern>> {
5252private:
5353 _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
5454 _LIBCPP_NO_UNIQUE_ADDRESS _Pattern __pattern_ = _Pattern();
55 using _Cache = __non_propagating_cache<subrange<iterator_t<_View>>>;
55 using _Cache _LIBCPP_NODEBUG = __non_propagating_cache<subrange<iterator_t<_View>>>;
5656 _Cache __cached_begin_ = _Cache();
5757
5858 template <class, class>
......@@ -211,7 +211,7 @@ struct __fn {
211211 requires constructible_from<decay_t<_Pattern>, _Pattern>
212212 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Pattern&& __pattern) const
213213 noexcept(is_nothrow_constructible_v<decay_t<_Pattern>, _Pattern>) {
214 return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Pattern>(__pattern)));
214 return __pipeable(std::__bind_back(*this, std::forward<_Pattern>(__pattern)));
215215 }
216216};
217217} // namespace __split_view
lib/libcxx/include/__ranges/subrange.h+3-2
......@@ -17,6 +17,7 @@
1717#include <__concepts/derived_from.h>
1818#include <__concepts/different_from.h>
1919#include <__config>
20#include <__cstddef/size_t.h>
2021#include <__fwd/subrange.h>
2122#include <__iterator/advance.h>
2223#include <__iterator/concepts.h>
......@@ -33,13 +34,13 @@
3334#include <__tuple/tuple_size.h>
3435#include <__type_traits/conditional.h>
3536#include <__type_traits/decay.h>
37#include <__type_traits/integral_constant.h>
3638#include <__type_traits/is_pointer.h>
3739#include <__type_traits/is_reference.h>
3840#include <__type_traits/make_unsigned.h>
3941#include <__type_traits/remove_const.h>
4042#include <__type_traits/remove_pointer.h>
4143#include <__utility/move.h>
42#include <cstddef>
4344
4445#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4546# pragma GCC system_header
......@@ -81,7 +82,7 @@ private:
8182 struct _Empty {
8283 _LIBCPP_HIDE_FROM_ABI constexpr _Empty(auto) noexcept {}
8384 };
84 using _Size = conditional_t<_StoreSize, make_unsigned_t<iter_difference_t<_Iter>>, _Empty>;
85 using _Size _LIBCPP_NODEBUG = conditional_t<_StoreSize, make_unsigned_t<iter_difference_t<_Iter>>, _Empty>;
8586 _LIBCPP_NO_UNIQUE_ADDRESS _Iter __begin_ = _Iter();
8687 _LIBCPP_NO_UNIQUE_ADDRESS _Sent __end_ = _Sent();
8788 _LIBCPP_NO_UNIQUE_ADDRESS _Size __size_ = 0;
lib/libcxx/include/__ranges/take_view.h+4-5
......@@ -42,7 +42,6 @@
4242#include <__utility/auto_cast.h>
4343#include <__utility/forward.h>
4444#include <__utility/move.h>
45#include <cstddef>
4645
4746#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4847# pragma GCC system_header
......@@ -162,9 +161,9 @@ public:
162161template <view _View>
163162template <bool _Const>
164163class take_view<_View>::__sentinel {
165 using _Base = __maybe_const<_Const, _View>;
164 using _Base _LIBCPP_NODEBUG = __maybe_const<_Const, _View>;
166165 template <bool _OtherConst>
167 using _Iter = counted_iterator<iterator_t<__maybe_const<_OtherConst, _View>>>;
166 using _Iter _LIBCPP_NODEBUG = counted_iterator<iterator_t<__maybe_const<_OtherConst, _View>>>;
168167 _LIBCPP_NO_UNIQUE_ADDRESS sentinel_t<_Base> __end_ = sentinel_t<_Base>();
169168
170169 template <bool>
......@@ -245,7 +244,7 @@ struct __passthrough_type<subrange<_Iter, _Sent, _Kind>> {
245244};
246245
247246template <class _Tp>
248using __passthrough_type_t = typename __passthrough_type<_Tp>::type;
247using __passthrough_type_t _LIBCPP_NODEBUG = typename __passthrough_type<_Tp>::type;
249248
250249struct __fn {
251250 // [range.take.overview]: the `empty_view` case.
......@@ -347,7 +346,7 @@ struct __fn {
347346 requires constructible_from<decay_t<_Np>, _Np>
348347 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Np&& __n) const
349348 noexcept(is_nothrow_constructible_v<decay_t<_Np>, _Np>) {
350 return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Np>(__n)));
349 return __pipeable(std::__bind_back(*this, std::forward<_Np>(__n)));
351350 }
352351};
353352
lib/libcxx/include/__ranges/take_while_view.h+2-2
......@@ -103,7 +103,7 @@ template <view _View, class _Pred>
103103 requires input_range<_View> && is_object_v<_Pred> && indirect_unary_predicate<const _Pred, iterator_t<_View>>
104104template <bool _Const>
105105class take_while_view<_View, _Pred>::__sentinel {
106 using _Base = __maybe_const<_Const, _View>;
106 using _Base _LIBCPP_NODEBUG = __maybe_const<_Const, _View>;
107107
108108 sentinel_t<_Base> __end_ = sentinel_t<_Base>();
109109 const _Pred* __pred_ = nullptr;
......@@ -149,7 +149,7 @@ struct __fn {
149149 requires constructible_from<decay_t<_Pred>, _Pred>
150150 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Pred&& __pred) const
151151 noexcept(is_nothrow_constructible_v<decay_t<_Pred>, _Pred>) {
152 return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Pred>(__pred)));
152 return __pipeable(std::__bind_back(*this, std::forward<_Pred>(__pred)));
153153 }
154154};
155155
lib/libcxx/include/__ranges/to.h+20-19
......@@ -10,15 +10,13 @@
1010#ifndef _LIBCPP___RANGES_TO_H
1111#define _LIBCPP___RANGES_TO_H
1212
13#include <__algorithm/ranges_copy.h>
1413#include <__concepts/constructible.h>
1514#include <__concepts/convertible_to.h>
1615#include <__concepts/derived_from.h>
1716#include <__concepts/same_as.h>
1817#include <__config>
18#include <__cstddef/ptrdiff_t.h>
1919#include <__functional/bind_back.h>
20#include <__iterator/back_insert_iterator.h>
21#include <__iterator/insert_iterator.h>
2220#include <__iterator/iterator_traits.h>
2321#include <__ranges/access.h>
2422#include <__ranges/concepts.h>
......@@ -33,7 +31,6 @@
3331#include <__type_traits/type_identity.h>
3432#include <__utility/declval.h>
3533#include <__utility/forward.h>
36#include <cstddef>
3734
3835#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3936# pragma GCC system_header
......@@ -54,21 +51,14 @@ constexpr bool __reservable_container =
5451 };
5552
5653template <class _Container, class _Ref>
57constexpr bool __container_insertable = requires(_Container& __c, _Ref&& __ref) {
54constexpr bool __container_appendable = requires(_Container& __c, _Ref&& __ref) {
5855 requires(
56 requires { __c.emplace_back(std::forward<_Ref>(__ref)); } ||
5957 requires { __c.push_back(std::forward<_Ref>(__ref)); } ||
58 requires { __c.emplace(__c.end(), std::forward<_Ref>(__ref)); } ||
6059 requires { __c.insert(__c.end(), std::forward<_Ref>(__ref)); });
6160};
6261
63template <class _Ref, class _Container>
64_LIBCPP_HIDE_FROM_ABI constexpr auto __container_inserter(_Container& __c) {
65 if constexpr (requires { __c.push_back(std::declval<_Ref>()); }) {
66 return std::back_inserter(__c);
67 } else {
68 return std::inserter(__c, __c.end());
69 }
70}
71
7262// Note: making this a concept allows short-circuiting the second condition.
7363template <class _Container, class _Range>
7464concept __try_non_recursive_conversion =
......@@ -113,14 +103,25 @@ template <class _Container, input_range _Range, class... _Args>
113103
114104 // Case 4 -- default-construct (or construct from the extra arguments) and insert, reserving the size if possible.
115105 else if constexpr (constructible_from<_Container, _Args...> &&
116 __container_insertable<_Container, range_reference_t<_Range>>) {
106 __container_appendable<_Container, range_reference_t<_Range>>) {
117107 _Container __result(std::forward<_Args>(__args)...);
118108 if constexpr (sized_range<_Range> && __reservable_container<_Container>) {
119109 __result.reserve(static_cast<range_size_t<_Container>>(ranges::size(__range)));
120110 }
121111
122 ranges::copy(__range, ranges::__container_inserter<range_reference_t<_Range>>(__result));
123
112 for (auto&& __ref : __range) {
113 using _Ref = decltype(__ref);
114 if constexpr (requires { __result.emplace_back(std::declval<_Ref>()); }) {
115 __result.emplace_back(std::forward<_Ref>(__ref));
116 } else if constexpr (requires { __result.push_back(std::declval<_Ref>()); }) {
117 __result.push_back(std::forward<_Ref>(__ref));
118 } else if constexpr (requires { __result.emplace(__result.end(), std::declval<_Ref>()); }) {
119 __result.emplace(__result.end(), std::forward<_Ref>(__ref));
120 } else {
121 static_assert(requires { __result.insert(__result.end(), std::declval<_Ref>()); });
122 __result.insert(__result.end(), std::forward<_Ref>(__ref));
123 }
124 }
124125 return __result;
125126
126127 } else {
......@@ -214,7 +215,7 @@ template <class _Container, class... _Args>
214215 }
215216 { return ranges::to<_Container>(std::forward<_Range>(__range), std::forward<_Tail>(__tail)...); };
216217
217 return __range_adaptor_closure_t(std::__bind_back(__to_func, std::forward<_Args>(__args)...));
218 return __pipeable(std::__bind_back(__to_func, std::forward<_Args>(__args)...));
218219}
219220
220221// Range adaptor closure object 2 -- wrapping the `ranges::to` version where `_Container` is a template template
......@@ -233,7 +234,7 @@ template <template <class...> class _Container, class... _Args>
233234 };
234235 // clang-format on
235236
236 return __range_adaptor_closure_t(std::__bind_back(__to_func, std::forward<_Args>(__args)...));
237 return __pipeable(std::__bind_back(__to_func, std::forward<_Args>(__args)...));
237238}
238239
239240} // namespace ranges
lib/libcxx/include/__ranges/transform_view.h+10-8
......@@ -34,6 +34,7 @@
3434#include <__ranges/view_interface.h>
3535#include <__type_traits/conditional.h>
3636#include <__type_traits/decay.h>
37#include <__type_traits/invoke.h>
3738#include <__type_traits/is_nothrow_constructible.h>
3839#include <__type_traits/is_object.h>
3940#include <__type_traits/is_reference.h>
......@@ -158,7 +159,7 @@ struct __transform_view_iterator_category_base {};
158159
159160template <forward_range _View, class _Fn>
160161struct __transform_view_iterator_category_base<_View, _Fn> {
161 using _Cat = typename iterator_traits<iterator_t<_View>>::iterator_category;
162 using _Cat _LIBCPP_NODEBUG = typename iterator_traits<iterator_t<_View>>::iterator_category;
162163
163164 using iterator_category =
164165 conditional_t< is_reference_v<invoke_result_t<_Fn&, range_reference_t<_View>>>,
......@@ -173,10 +174,11 @@ template <input_range _View, copy_constructible _Fn>
173174# endif
174175 requires __transform_view_constraints<_View, _Fn>
175176template <bool _Const>
176class transform_view<_View, _Fn>::__iterator : public __transform_view_iterator_category_base<_View, _Fn> {
177class transform_view<_View, _Fn>::__iterator
178 : public __transform_view_iterator_category_base<_View, __maybe_const<_Const, _Fn>> {
177179
178 using _Parent = __maybe_const<_Const, transform_view>;
179 using _Base = __maybe_const<_Const, _View>;
180 using _Parent _LIBCPP_NODEBUG = __maybe_const<_Const, transform_view>;
181 using _Base _LIBCPP_NODEBUG = __maybe_const<_Const, _View>;
180182
181183 _Parent* __parent_ = nullptr;
182184
......@@ -190,7 +192,7 @@ public:
190192 iterator_t<_Base> __current_ = iterator_t<_Base>();
191193
192194 using iterator_concept = typename __transform_view_iterator_concept<_View>::type;
193 using value_type = remove_cvref_t<invoke_result_t<_Fn&, range_reference_t<_Base>>>;
195 using value_type = remove_cvref_t<invoke_result_t<__maybe_const<_Const, _Fn>&, range_reference_t<_Base>>>;
194196 using difference_type = range_difference_t<_Base>;
195197
196198 _LIBCPP_HIDE_FROM_ABI __iterator()
......@@ -336,8 +338,8 @@ template <input_range _View, copy_constructible _Fn>
336338 requires __transform_view_constraints<_View, _Fn>
337339template <bool _Const>
338340class transform_view<_View, _Fn>::__sentinel {
339 using _Parent = __maybe_const<_Const, transform_view>;
340 using _Base = __maybe_const<_Const, _View>;
341 using _Parent _LIBCPP_NODEBUG = __maybe_const<_Const, transform_view>;
342 using _Base _LIBCPP_NODEBUG = __maybe_const<_Const, _View>;
341343
342344 sentinel_t<_Base> __end_ = sentinel_t<_Base>();
343345
......@@ -396,7 +398,7 @@ struct __fn {
396398 requires constructible_from<decay_t<_Fn>, _Fn>
397399 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Fn&& __f) const
398400 noexcept(is_nothrow_constructible_v<decay_t<_Fn>, _Fn>) {
399 return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Fn>(__f)));
401 return __pipeable(std::__bind_back(*this, std::forward<_Fn>(__f)));
400402 }
401403};
402404} // namespace __transform
lib/libcxx/include/__ranges/zip_view.h+8-47
......@@ -36,7 +36,6 @@
3636#include <__utility/forward.h>
3737#include <__utility/integer_sequence.h>
3838#include <__utility/move.h>
39#include <__utility/pair.h>
4039#include <tuple>
4140
4241#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -58,22 +57,11 @@ concept __zip_is_common =
5857 (!(bidirectional_range<_Ranges> && ...) && (common_range<_Ranges> && ...)) ||
5958 ((random_access_range<_Ranges> && ...) && (sized_range<_Ranges> && ...));
6059
61template <typename _Tp, typename _Up>
62auto __tuple_or_pair_test() -> pair<_Tp, _Up>;
63
64template <typename... _Types>
65 requires(sizeof...(_Types) != 2)
66auto __tuple_or_pair_test() -> tuple<_Types...>;
67
68template <class... _Types>
69using __tuple_or_pair = decltype(__tuple_or_pair_test<_Types...>());
70
7160template <class _Fun, class _Tuple>
7261_LIBCPP_HIDE_FROM_ABI constexpr auto __tuple_transform(_Fun&& __f, _Tuple&& __tuple) {
7362 return std::apply(
7463 [&]<class... _Types>(_Types&&... __elements) {
75 return __tuple_or_pair<invoke_result_t<_Fun&, _Types>...>(
76 std::invoke(__f, std::forward<_Types>(__elements))...);
64 return tuple<invoke_result_t<_Fun&, _Types>...>(std::invoke(__f, std::forward<_Types>(__elements))...);
7765 },
7866 std::forward<_Tuple>(__tuple));
7967}
......@@ -88,7 +76,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr void __tuple_for_each(_Fun&& __f, _Tuple&& __tup
8876}
8977
9078template <class _Fun, class _Tuple1, class _Tuple2, size_t... _Indices>
91_LIBCPP_HIDE_FROM_ABI constexpr __tuple_or_pair<
79_LIBCPP_HIDE_FROM_ABI constexpr tuple<
9280 invoke_result_t<_Fun&,
9381 typename tuple_element<_Indices, remove_cvref_t<_Tuple1>>::type,
9482 typename tuple_element<_Indices, remove_cvref_t<_Tuple2>>::type>...>
......@@ -250,10 +238,9 @@ template <input_range... _Views>
250238 requires(view<_Views> && ...) && (sizeof...(_Views) > 0)
251239template <bool _Const>
252240class zip_view<_Views...>::__iterator : public __zip_view_iterator_category_base<_Const, _Views...> {
253 __tuple_or_pair<iterator_t<__maybe_const<_Const, _Views>>...> __current_;
241 tuple<iterator_t<__maybe_const<_Const, _Views>>...> __current_;
254242
255 _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(
256 __tuple_or_pair<iterator_t<__maybe_const<_Const, _Views>>...> __current)
243 _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(tuple<iterator_t<__maybe_const<_Const, _Views>>...> __current)
257244 : __current_(std::move(__current)) {}
258245
259246 template <bool>
......@@ -266,7 +253,7 @@ class zip_view<_Views...>::__iterator : public __zip_view_iterator_category_base
266253
267254public:
268255 using iterator_concept = decltype(__get_zip_view_iterator_tag<_Const, _Views...>());
269 using value_type = __tuple_or_pair<range_value_t<__maybe_const<_Const, _Views>>...>;
256 using value_type = tuple<range_value_t<__maybe_const<_Const, _Views>>...>;
270257 using difference_type = common_type_t<range_difference_t<__maybe_const<_Const, _Views>>...>;
271258
272259 _LIBCPP_HIDE_FROM_ABI __iterator() = default;
......@@ -340,33 +327,8 @@ public:
340327 }
341328 }
342329
343 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(const __iterator& __x, const __iterator& __y)
344 requires __zip_all_random_access<_Const, _Views...>
345 {
346 return __x.__current_ < __y.__current_;
347 }
348
349 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(const __iterator& __x, const __iterator& __y)
350 requires __zip_all_random_access<_Const, _Views...>
351 {
352 return __y < __x;
353 }
354
355 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(const __iterator& __x, const __iterator& __y)
356 requires __zip_all_random_access<_Const, _Views...>
357 {
358 return !(__y < __x);
359 }
360
361 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(const __iterator& __x, const __iterator& __y)
362 requires __zip_all_random_access<_Const, _Views...>
363 {
364 return !(__x < __y);
365 }
366
367330 _LIBCPP_HIDE_FROM_ABI friend constexpr auto operator<=>(const __iterator& __x, const __iterator& __y)
368 requires __zip_all_random_access<_Const, _Views...> &&
369 (three_way_comparable<iterator_t<__maybe_const<_Const, _Views>>> && ...)
331 requires __zip_all_random_access<_Const, _Views...>
370332 {
371333 return __x.__current_ <=> __y.__current_;
372334 }
......@@ -427,10 +389,9 @@ template <input_range... _Views>
427389 requires(view<_Views> && ...) && (sizeof...(_Views) > 0)
428390template <bool _Const>
429391class zip_view<_Views...>::__sentinel {
430 __tuple_or_pair<sentinel_t<__maybe_const<_Const, _Views>>...> __end_;
392 tuple<sentinel_t<__maybe_const<_Const, _Views>>...> __end_;
431393
432 _LIBCPP_HIDE_FROM_ABI constexpr explicit __sentinel(
433 __tuple_or_pair<sentinel_t<__maybe_const<_Const, _Views>>...> __end)
394 _LIBCPP_HIDE_FROM_ABI constexpr explicit __sentinel(tuple<sentinel_t<__maybe_const<_Const, _Views>>...> __end)
434395 : __end_(__end) {}
435396
436397 friend class zip_view<_Views...>;
lib/libcxx/include/__split_buffer+89-192
......@@ -23,7 +23,6 @@
2323#include <__memory/compressed_pair.h>
2424#include <__memory/pointer_traits.h>
2525#include <__memory/swap_allocator.h>
26#include <__type_traits/add_lvalue_reference.h>
2726#include <__type_traits/conditional.h>
2827#include <__type_traits/enable_if.h>
2928#include <__type_traits/integral_constant.h>
......@@ -35,7 +34,6 @@
3534#include <__type_traits/remove_reference.h>
3635#include <__utility/forward.h>
3736#include <__utility/move.h>
38#include <cstddef>
3937
4038#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4139# pragma GCC system_header
......@@ -47,30 +45,30 @@ _LIBCPP_PUSH_MACROS
4745_LIBCPP_BEGIN_NAMESPACE_STD
4846
4947// __split_buffer allocates a contiguous chunk of memory and stores objects in the range [__begin_, __end_).
50// It has uninitialized memory in the ranges [__first_, __begin_) and [__end_, __end_cap_.first()). That allows
48// It has uninitialized memory in the ranges [__first_, __begin_) and [__end_, __cap_). That allows
5149// it to grow both in the front and back without having to move the data.
5250
5351template <class _Tp, class _Allocator = allocator<_Tp> >
5452struct __split_buffer {
5553public:
56 using value_type = _Tp;
57 using allocator_type = _Allocator;
58 using __alloc_rr = __libcpp_remove_reference_t<allocator_type>;
59 using __alloc_traits = allocator_traits<__alloc_rr>;
60 using reference = value_type&;
61 using const_reference = const value_type&;
62 using size_type = typename __alloc_traits::size_type;
63 using difference_type = typename __alloc_traits::difference_type;
64 using pointer = typename __alloc_traits::pointer;
65 using const_pointer = typename __alloc_traits::const_pointer;
66 using iterator = pointer;
67 using const_iterator = const_pointer;
54 using value_type = _Tp;
55 using allocator_type = _Allocator;
56 using __alloc_rr _LIBCPP_NODEBUG = __libcpp_remove_reference_t<allocator_type>;
57 using __alloc_traits _LIBCPP_NODEBUG = allocator_traits<__alloc_rr>;
58 using reference = value_type&;
59 using const_reference = const value_type&;
60 using size_type = typename __alloc_traits::size_type;
61 using difference_type = typename __alloc_traits::difference_type;
62 using pointer = typename __alloc_traits::pointer;
63 using const_pointer = typename __alloc_traits::const_pointer;
64 using iterator = pointer;
65 using const_iterator = const_pointer;
6866
6967 // A __split_buffer contains the following members which may be trivially relocatable:
7068 // - pointer: may be trivially relocatable, so it's checked
7169 // - allocator_type: may be trivially relocatable, so it's checked
7270 // __split_buffer doesn't have any self-references, so it's trivially relocatable if its members are.
73 using __trivially_relocatable = __conditional_t<
71 using __trivially_relocatable _LIBCPP_NODEBUG = __conditional_t<
7472 __libcpp_is_trivially_relocatable<pointer>::value && __libcpp_is_trivially_relocatable<allocator_type>::value,
7573 __split_buffer,
7674 void>;
......@@ -78,23 +76,20 @@ public:
7876 pointer __first_;
7977 pointer __begin_;
8078 pointer __end_;
81 __compressed_pair<pointer, allocator_type> __end_cap_;
82
83 using __alloc_ref = __add_lvalue_reference_t<allocator_type>;
84 using __alloc_const_ref = __add_lvalue_reference_t<allocator_type>;
79 _LIBCPP_COMPRESSED_PAIR(pointer, __cap_, allocator_type, __alloc_);
8580
8681 __split_buffer(const __split_buffer&) = delete;
8782 __split_buffer& operator=(const __split_buffer&) = delete;
8883
8984 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __split_buffer()
9085 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
91 : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __default_init_tag()) {}
86 : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __cap_(nullptr) {}
9287
9388 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit __split_buffer(__alloc_rr& __a)
94 : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a) {}
89 : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __cap_(nullptr), __alloc_(__a) {}
9590
9691 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit __split_buffer(const __alloc_rr& __a)
97 : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a) {}
92 : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __cap_(nullptr), __alloc_(__a) {}
9893
9994 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
10095 __split_buffer(size_type __cap, size_type __start, __alloc_rr& __a);
......@@ -111,16 +106,6 @@ public:
111106
112107 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~__split_buffer();
113108
114 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __alloc_rr& __alloc() _NOEXCEPT { return __end_cap_.second(); }
115 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const __alloc_rr& __alloc() const _NOEXCEPT {
116 return __end_cap_.second();
117 }
118
119 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer& __end_cap() _NOEXCEPT { return __end_cap_.first(); }
120 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const pointer& __end_cap() const _NOEXCEPT {
121 return __end_cap_.first();
122 }
123
124109 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __begin_; }
125110 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __begin_; }
126111
......@@ -136,7 +121,7 @@ public:
136121 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool empty() const { return __end_ == __begin_; }
137122
138123 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type capacity() const {
139 return static_cast<size_type>(__end_cap() - __first_);
124 return static_cast<size_type>(__cap_ - __first_);
140125 }
141126
142127 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type __front_spare() const {
......@@ -144,7 +129,7 @@ public:
144129 }
145130
146131 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type __back_spare() const {
147 return static_cast<size_type>(__end_cap() - __end_);
132 return static_cast<size_type>(__cap_ - __end_);
148133 }
149134
150135 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference front() { return *__begin_; }
......@@ -152,13 +137,10 @@ public:
152137 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference back() { return *(__end_ - 1); }
153138 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference back() const { return *(__end_ - 1); }
154139
155 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n);
156140 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void shrink_to_fit() _NOEXCEPT;
157 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_front(const_reference __x);
158 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(const_reference __x);
159 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_front(value_type&& __x);
160 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x);
161141
142 template <class... _Args>
143 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void emplace_front(_Args&&... __args);
162144 template <class... _Args>
163145 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args);
164146
......@@ -168,9 +150,6 @@ public:
168150 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n);
169151 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n, const_reference __x);
170152
171 template <class _InputIter, __enable_if_t<__has_exactly_input_iterator_category<_InputIter>::value, int> = 0>
172 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(_InputIter __first, _InputIter __last);
173
174153 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
175154 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
176155 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
......@@ -205,7 +184,7 @@ public:
205184private:
206185 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__split_buffer& __c, true_type)
207186 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
208 __alloc() = std::move(__c.__alloc());
187 __alloc_ = std::move(__c.__alloc_);
209188 }
210189
211190 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__split_buffer&, false_type) _NOEXCEPT {}
......@@ -234,14 +213,14 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __split_buffer<_Tp, _Allocator>::__invariants
234213 return false;
235214 if (__end_ != nullptr)
236215 return false;
237 if (__end_cap() != nullptr)
216 if (__cap_ != nullptr)
238217 return false;
239218 } else {
240219 if (__begin_ < __first_)
241220 return false;
242221 if (__end_ < __begin_)
243222 return false;
244 if (__end_cap() < __end_)
223 if (__cap_ < __end_)
245224 return false;
246225 }
247226 return true;
......@@ -256,7 +235,7 @@ template <class _Tp, class _Allocator>
256235_LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n) {
257236 _ConstructTransaction __tx(&this->__end_, __n);
258237 for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) {
259 __alloc_traits::construct(this->__alloc(), std::__to_address(__tx.__pos_));
238 __alloc_traits::construct(__alloc_, std::__to_address(__tx.__pos_));
260239 }
261240}
262241
......@@ -271,29 +250,22 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void
271250__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) {
272251 _ConstructTransaction __tx(&this->__end_, __n);
273252 for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) {
274 __alloc_traits::construct(this->__alloc(), std::__to_address(__tx.__pos_), __x);
253 __alloc_traits::construct(__alloc_, std::__to_address(__tx.__pos_), __x);
275254 }
276255}
277256
278template <class _Tp, class _Allocator>
279template <class _InputIter, __enable_if_t<__has_exactly_input_iterator_category<_InputIter>::value, int> >
280_LIBCPP_CONSTEXPR_SINCE_CXX20 void
281__split_buffer<_Tp, _Allocator>::__construct_at_end(_InputIter __first, _InputIter __last) {
282 __construct_at_end_with_sentinel(__first, __last);
283}
284
285257template <class _Tp, class _Allocator>
286258template <class _Iterator, class _Sentinel>
287259_LIBCPP_CONSTEXPR_SINCE_CXX20 void
288260__split_buffer<_Tp, _Allocator>::__construct_at_end_with_sentinel(_Iterator __first, _Sentinel __last) {
289 __alloc_rr& __a = this->__alloc();
261 __alloc_rr& __a = __alloc_;
290262 for (; __first != __last; ++__first) {
291 if (__end_ == __end_cap()) {
292 size_type __old_cap = __end_cap() - __first_;
263 if (__end_ == __cap_) {
264 size_type __old_cap = __cap_ - __first_;
293265 size_type __new_cap = std::max<size_type>(2 * __old_cap, 8);
294266 __split_buffer __buf(__new_cap, 0, __a);
295267 for (pointer __p = __begin_; __p != __end_; ++__p, (void)++__buf.__end_)
296 __alloc_traits::construct(__buf.__alloc(), std::__to_address(__buf.__end_), std::move(*__p));
268 __alloc_traits::construct(__buf.__alloc_, std::__to_address(__buf.__end_), std::move(*__p));
297269 swap(__buf);
298270 }
299271 __alloc_traits::construct(__a, std::__to_address(this->__end_), *__first);
......@@ -313,7 +285,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void
313285__split_buffer<_Tp, _Allocator>::__construct_at_end_with_size(_ForwardIterator __first, size_type __n) {
314286 _ConstructTransaction __tx(&this->__end_, __n);
315287 for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_, (void)++__first) {
316 __alloc_traits::construct(this->__alloc(), std::__to_address(__tx.__pos_), *__first);
288 __alloc_traits::construct(__alloc_, std::__to_address(__tx.__pos_), *__first);
317289 }
318290}
319291
......@@ -321,7 +293,7 @@ template <class _Tp, class _Allocator>
321293_LIBCPP_CONSTEXPR_SINCE_CXX20 inline void
322294__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_type) {
323295 while (__begin_ != __new_begin)
324 __alloc_traits::destroy(__alloc(), std::__to_address(__begin_++));
296 __alloc_traits::destroy(__alloc_, std::__to_address(__begin_++));
325297}
326298
327299template <class _Tp, class _Allocator>
......@@ -334,7 +306,7 @@ template <class _Tp, class _Allocator>
334306_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void
335307__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_type) _NOEXCEPT {
336308 while (__new_last != __end_)
337 __alloc_traits::destroy(__alloc(), std::__to_address(--__end_));
309 __alloc_traits::destroy(__alloc_, std::__to_address(--__end_));
338310}
339311
340312template <class _Tp, class _Allocator>
......@@ -346,23 +318,23 @@ __split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, true_type
346318template <class _Tp, class _Allocator>
347319_LIBCPP_CONSTEXPR_SINCE_CXX20
348320__split_buffer<_Tp, _Allocator>::__split_buffer(size_type __cap, size_type __start, __alloc_rr& __a)
349 : __end_cap_(nullptr, __a) {
321 : __cap_(nullptr), __alloc_(__a) {
350322 if (__cap == 0) {
351323 __first_ = nullptr;
352324 } else {
353 auto __allocation = std::__allocate_at_least(__alloc(), __cap);
325 auto __allocation = std::__allocate_at_least(__alloc_, __cap);
354326 __first_ = __allocation.ptr;
355327 __cap = __allocation.count;
356328 }
357329 __begin_ = __end_ = __first_ + __start;
358 __end_cap() = __first_ + __cap;
330 __cap_ = __first_ + __cap;
359331}
360332
361333template <class _Tp, class _Allocator>
362334_LIBCPP_CONSTEXPR_SINCE_CXX20 __split_buffer<_Tp, _Allocator>::~__split_buffer() {
363335 clear();
364336 if (__first_)
365 __alloc_traits::deallocate(__alloc(), __first_, capacity());
337 __alloc_traits::deallocate(__alloc_, __first_, capacity());
366338}
367339
368340template <class _Tp, class _Allocator>
......@@ -371,31 +343,32 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 __split_buffer<_Tp, _Allocator>::__split_buffer(__
371343 : __first_(std::move(__c.__first_)),
372344 __begin_(std::move(__c.__begin_)),
373345 __end_(std::move(__c.__end_)),
374 __end_cap_(std::move(__c.__end_cap_)) {
375 __c.__first_ = nullptr;
376 __c.__begin_ = nullptr;
377 __c.__end_ = nullptr;
378 __c.__end_cap() = nullptr;
346 __cap_(std::move(__c.__cap_)),
347 __alloc_(std::move(__c.__alloc_)) {
348 __c.__first_ = nullptr;
349 __c.__begin_ = nullptr;
350 __c.__end_ = nullptr;
351 __c.__cap_ = nullptr;
379352}
380353
381354template <class _Tp, class _Allocator>
382355_LIBCPP_CONSTEXPR_SINCE_CXX20
383356__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c, const __alloc_rr& __a)
384 : __end_cap_(nullptr, __a) {
385 if (__a == __c.__alloc()) {
386 __first_ = __c.__first_;
387 __begin_ = __c.__begin_;
388 __end_ = __c.__end_;
389 __end_cap() = __c.__end_cap();
390 __c.__first_ = nullptr;
391 __c.__begin_ = nullptr;
392 __c.__end_ = nullptr;
393 __c.__end_cap() = nullptr;
357 : __cap_(nullptr), __alloc_(__a) {
358 if (__a == __c.__alloc_) {
359 __first_ = __c.__first_;
360 __begin_ = __c.__begin_;
361 __end_ = __c.__end_;
362 __cap_ = __c.__cap_;
363 __c.__first_ = nullptr;
364 __c.__begin_ = nullptr;
365 __c.__end_ = nullptr;
366 __c.__cap_ = nullptr;
394367 } else {
395 auto __allocation = std::__allocate_at_least(__alloc(), __c.size());
368 auto __allocation = std::__allocate_at_least(__alloc_, __c.size());
396369 __first_ = __allocation.ptr;
397370 __begin_ = __end_ = __first_;
398 __end_cap() = __first_ + __allocation.count;
371 __cap_ = __first_ + __allocation.count;
399372 typedef move_iterator<iterator> _Ip;
400373 __construct_at_end(_Ip(__c.begin()), _Ip(__c.end()));
401374 }
......@@ -409,12 +382,12 @@ __split_buffer<_Tp, _Allocator>::operator=(__split_buffer&& __c)
409382 !__alloc_traits::propagate_on_container_move_assignment::value) {
410383 clear();
411384 shrink_to_fit();
412 __first_ = __c.__first_;
413 __begin_ = __c.__begin_;
414 __end_ = __c.__end_;
415 __end_cap() = __c.__end_cap();
385 __first_ = __c.__first_;
386 __begin_ = __c.__begin_;
387 __end_ = __c.__end_;
388 __cap_ = __c.__cap_;
416389 __move_assign_alloc(__c, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());
417 __c.__first_ = __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
390 __c.__first_ = __c.__begin_ = __c.__end_ = __c.__cap_ = nullptr;
418391 return *this;
419392}
420393
......@@ -424,151 +397,75 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::swap(__split
424397 std::swap(__first_, __x.__first_);
425398 std::swap(__begin_, __x.__begin_);
426399 std::swap(__end_, __x.__end_);
427 std::swap(__end_cap(), __x.__end_cap());
428 std::__swap_allocator(__alloc(), __x.__alloc());
429}
430
431template <class _Tp, class _Allocator>
432_LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::reserve(size_type __n) {
433 if (__n < capacity()) {
434 __split_buffer<value_type, __alloc_rr&> __t(__n, 0, __alloc());
435 __t.__construct_at_end(move_iterator<pointer>(__begin_), move_iterator<pointer>(__end_));
436 std::swap(__first_, __t.__first_);
437 std::swap(__begin_, __t.__begin_);
438 std::swap(__end_, __t.__end_);
439 std::swap(__end_cap(), __t.__end_cap());
440 }
400 std::swap(__cap_, __x.__cap_);
401 std::__swap_allocator(__alloc_, __x.__alloc_);
441402}
442403
443404template <class _Tp, class _Allocator>
444405_LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT {
445406 if (capacity() > size()) {
446#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
407#if _LIBCPP_HAS_EXCEPTIONS
447408 try {
448#endif // _LIBCPP_HAS_NO_EXCEPTIONS
449 __split_buffer<value_type, __alloc_rr&> __t(size(), 0, __alloc());
450 __t.__construct_at_end(move_iterator<pointer>(__begin_), move_iterator<pointer>(__end_));
451 __t.__end_ = __t.__begin_ + (__end_ - __begin_);
452 std::swap(__first_, __t.__first_);
453 std::swap(__begin_, __t.__begin_);
454 std::swap(__end_, __t.__end_);
455 std::swap(__end_cap(), __t.__end_cap());
456#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
409#endif // _LIBCPP_HAS_EXCEPTIONS
410 __split_buffer<value_type, __alloc_rr&> __t(size(), 0, __alloc_);
411 if (__t.capacity() < capacity()) {
412 __t.__construct_at_end(move_iterator<pointer>(__begin_), move_iterator<pointer>(__end_));
413 __t.__end_ = __t.__begin_ + (__end_ - __begin_);
414 std::swap(__first_, __t.__first_);
415 std::swap(__begin_, __t.__begin_);
416 std::swap(__end_, __t.__end_);
417 std::swap(__cap_, __t.__cap_);
418 }
419#if _LIBCPP_HAS_EXCEPTIONS
457420 } catch (...) {
458421 }
459#endif // _LIBCPP_HAS_NO_EXCEPTIONS
422#endif // _LIBCPP_HAS_EXCEPTIONS
460423 }
461424}
462425
463426template <class _Tp, class _Allocator>
464_LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::push_front(const_reference __x) {
465 if (__begin_ == __first_) {
466 if (__end_ < __end_cap()) {
467 difference_type __d = __end_cap() - __end_;
468 __d = (__d + 1) / 2;
469 __begin_ = std::move_backward(__begin_, __end_, __end_ + __d);
470 __end_ += __d;
471 } else {
472 size_type __c = std::max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
473 __split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc());
474 __t.__construct_at_end(move_iterator<pointer>(__begin_), move_iterator<pointer>(__end_));
475 std::swap(__first_, __t.__first_);
476 std::swap(__begin_, __t.__begin_);
477 std::swap(__end_, __t.__end_);
478 std::swap(__end_cap(), __t.__end_cap());
479 }
480 }
481 __alloc_traits::construct(__alloc(), std::__to_address(__begin_ - 1), __x);
482 --__begin_;
483}
484
485template <class _Tp, class _Allocator>
486_LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::push_front(value_type&& __x) {
427template <class... _Args>
428_LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::emplace_front(_Args&&... __args) {
487429 if (__begin_ == __first_) {
488 if (__end_ < __end_cap()) {
489 difference_type __d = __end_cap() - __end_;
430 if (__end_ < __cap_) {
431 difference_type __d = __cap_ - __end_;
490432 __d = (__d + 1) / 2;
491433 __begin_ = std::move_backward(__begin_, __end_, __end_ + __d);
492434 __end_ += __d;
493435 } else {
494 size_type __c = std::max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
495 __split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc());
436 size_type __c = std::max<size_type>(2 * static_cast<size_type>(__cap_ - __first_), 1);
437 __split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc_);
496438 __t.__construct_at_end(move_iterator<pointer>(__begin_), move_iterator<pointer>(__end_));
497439 std::swap(__first_, __t.__first_);
498440 std::swap(__begin_, __t.__begin_);
499441 std::swap(__end_, __t.__end_);
500 std::swap(__end_cap(), __t.__end_cap());
442 std::swap(__cap_, __t.__cap_);
501443 }
502444 }
503 __alloc_traits::construct(__alloc(), std::__to_address(__begin_ - 1), std::move(__x));
445 __alloc_traits::construct(__alloc_, std::__to_address(__begin_ - 1), std::forward<_Args>(__args)...);
504446 --__begin_;
505447}
506448
507template <class _Tp, class _Allocator>
508_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void
509__split_buffer<_Tp, _Allocator>::push_back(const_reference __x) {
510 if (__end_ == __end_cap()) {
511 if (__begin_ > __first_) {
512 difference_type __d = __begin_ - __first_;
513 __d = (__d + 1) / 2;
514 __end_ = std::move(__begin_, __end_, __begin_ - __d);
515 __begin_ -= __d;
516 } else {
517 size_type __c = std::max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
518 __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc());
519 __t.__construct_at_end(move_iterator<pointer>(__begin_), move_iterator<pointer>(__end_));
520 std::swap(__first_, __t.__first_);
521 std::swap(__begin_, __t.__begin_);
522 std::swap(__end_, __t.__end_);
523 std::swap(__end_cap(), __t.__end_cap());
524 }
525 }
526 __alloc_traits::construct(__alloc(), std::__to_address(__end_), __x);
527 ++__end_;
528}
529
530template <class _Tp, class _Allocator>
531_LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::push_back(value_type&& __x) {
532 if (__end_ == __end_cap()) {
533 if (__begin_ > __first_) {
534 difference_type __d = __begin_ - __first_;
535 __d = (__d + 1) / 2;
536 __end_ = std::move(__begin_, __end_, __begin_ - __d);
537 __begin_ -= __d;
538 } else {
539 size_type __c = std::max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
540 __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc());
541 __t.__construct_at_end(move_iterator<pointer>(__begin_), move_iterator<pointer>(__end_));
542 std::swap(__first_, __t.__first_);
543 std::swap(__begin_, __t.__begin_);
544 std::swap(__end_, __t.__end_);
545 std::swap(__end_cap(), __t.__end_cap());
546 }
547 }
548 __alloc_traits::construct(__alloc(), std::__to_address(__end_), std::move(__x));
549 ++__end_;
550}
551
552449template <class _Tp, class _Allocator>
553450template <class... _Args>
554451_LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::emplace_back(_Args&&... __args) {
555 if (__end_ == __end_cap()) {
452 if (__end_ == __cap_) {
556453 if (__begin_ > __first_) {
557454 difference_type __d = __begin_ - __first_;
558455 __d = (__d + 1) / 2;
559456 __end_ = std::move(__begin_, __end_, __begin_ - __d);
560457 __begin_ -= __d;
561458 } else {
562 size_type __c = std::max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
563 __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc());
459 size_type __c = std::max<size_type>(2 * static_cast<size_type>(__cap_ - __first_), 1);
460 __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc_);
564461 __t.__construct_at_end(move_iterator<pointer>(__begin_), move_iterator<pointer>(__end_));
565462 std::swap(__first_, __t.__first_);
566463 std::swap(__begin_, __t.__begin_);
567464 std::swap(__end_, __t.__end_);
568 std::swap(__end_cap(), __t.__end_cap());
465 std::swap(__cap_, __t.__cap_);
569466 }
570467 }
571 __alloc_traits::construct(__alloc(), std::__to_address(__end_), std::forward<_Args>(__args)...);
468 __alloc_traits::construct(__alloc_, std::__to_address(__end_), std::forward<_Args>(__args)...);
572469 ++__end_;
573470}
574471
lib/libcxx/include/__stop_token/atomic_unique_lock.h+4-4
......@@ -7,8 +7,8 @@
77//
88//===----------------------------------------------------------------------===//
99
10#ifndef _LIBCPP___STOP_TOKEN_ATOMIC_UNIQUE_GUARD_H
11#define _LIBCPP___STOP_TOKEN_ATOMIC_UNIQUE_GUARD_H
10#ifndef _LIBCPP___STOP_TOKEN_ATOMIC_UNIQUE_LOCK_H
11#define _LIBCPP___STOP_TOKEN_ATOMIC_UNIQUE_LOCK_H
1212
1313#include <__bit/popcount.h>
1414#include <__config>
......@@ -133,8 +133,8 @@ private:
133133 _LIBCPP_HIDE_FROM_ABI static constexpr auto __set_locked_bit = [](_State __state) { return __state | _LockedBit; };
134134};
135135
136#endif // _LIBCPP_STD_VER >= 20
136#endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS
137137
138138_LIBCPP_END_NAMESPACE_STD
139139
140#endif // _LIBCPP___STOP_TOKEN_ATOMIC_UNIQUE_GUARD_H
140#endif // _LIBCPP___STOP_TOKEN_ATOMIC_UNIQUE_LOCK_H
lib/libcxx/include/__stop_token/intrusive_shared_ptr.h+1-1
......@@ -13,10 +13,10 @@
1313#include <__atomic/atomic.h>
1414#include <__atomic/memory_order.h>
1515#include <__config>
16#include <__cstddef/nullptr_t.h>
1617#include <__type_traits/is_reference.h>
1718#include <__utility/move.h>
1819#include <__utility/swap.h>
19#include <cstddef>
2020
2121#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2222# pragma GCC system_header
lib/libcxx/include/__stop_token/stop_callback.h+3-3
......@@ -31,7 +31,7 @@ _LIBCPP_PUSH_MACROS
3131
3232_LIBCPP_BEGIN_NAMESPACE_STD
3333
34#if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN) && !defined(_LIBCPP_HAS_NO_THREADS)
34#if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS
3535
3636template <class _Callback>
3737class _LIBCPP_AVAILABILITY_SYNC stop_callback : private __stop_callback_base {
......@@ -93,10 +93,10 @@ private:
9393template <class _Callback>
9494_LIBCPP_AVAILABILITY_SYNC stop_callback(stop_token, _Callback) -> stop_callback<_Callback>;
9595
96#endif // _LIBCPP_STD_VER >= 20
96#endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS
9797
9898_LIBCPP_END_NAMESPACE_STD
9999
100100_LIBCPP_POP_MACROS
101101
102#endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN) && !defined(_LIBCPP_HAS_NO_THREADS)
102#endif // _LIBCPP___STOP_TOKEN_STOP_CALLBACK_H
lib/libcxx/include/__stop_token/stop_source.h+3-3
......@@ -22,7 +22,7 @@
2222
2323_LIBCPP_BEGIN_NAMESPACE_STD
2424
25#if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN) && !defined(_LIBCPP_HAS_NO_THREADS)
25#if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS
2626
2727struct nostopstate_t {
2828 explicit nostopstate_t() = default;
......@@ -84,8 +84,8 @@ private:
8484 __intrusive_shared_ptr<__stop_state> __state_;
8585};
8686
87#endif // _LIBCPP_STD_VER >= 20
87#endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS
8888
8989_LIBCPP_END_NAMESPACE_STD
9090
91#endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN) && !defined(_LIBCPP_HAS_NO_THREADS)
91#endif // _LIBCPP___STOP_TOKEN_STOP_SOURCE_H
lib/libcxx/include/__stop_token/stop_state.h+6-6
......@@ -24,10 +24,10 @@
2424
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
27#if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_THREADS)
27#if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS
2828
2929struct __stop_callback_base : __intrusive_node_base<__stop_callback_base> {
30 using __callback_fn_t = void(__stop_callback_base*) noexcept;
30 using __callback_fn_t _LIBCPP_NODEBUG = void(__stop_callback_base*) noexcept;
3131 _LIBCPP_HIDE_FROM_ABI explicit __stop_callback_base(__callback_fn_t* __callback_fn) : __callback_fn_(__callback_fn) {}
3232
3333 _LIBCPP_HIDE_FROM_ABI void __invoke() noexcept { __callback_fn_(this); }
......@@ -58,9 +58,9 @@ class __stop_state {
5858 // It is used by __intrusive_shared_ptr, but it is stored here for better layout
5959 atomic<uint32_t> __ref_count_ = 0;
6060
61 using __state_t = uint32_t;
62 using __callback_list_lock = __atomic_unique_lock<__state_t, __callback_list_locked_bit>;
63 using __callback_list = __intrusive_list_view<__stop_callback_base>;
61 using __state_t _LIBCPP_NODEBUG = uint32_t;
62 using __callback_list_lock _LIBCPP_NODEBUG = __atomic_unique_lock<__state_t, __callback_list_locked_bit>;
63 using __callback_list _LIBCPP_NODEBUG = __intrusive_list_view<__stop_callback_base>;
6464
6565 __callback_list __callback_list_;
6666 __thread_id __requesting_thread_;
......@@ -229,7 +229,7 @@ struct __intrusive_shared_ptr_traits<__stop_state> {
229229 }
230230};
231231
232#endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_THREADS)
232#endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS
233233
234234_LIBCPP_END_NAMESPACE_STD
235235
lib/libcxx/include/__stop_token/stop_token.h+2-2
......@@ -20,7 +20,7 @@
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN) && !defined(_LIBCPP_HAS_NO_THREADS)
23#if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS
2424
2525class _LIBCPP_AVAILABILITY_SYNC stop_token {
2626public:
......@@ -56,7 +56,7 @@ private:
5656 _LIBCPP_HIDE_FROM_ABI explicit stop_token(const __intrusive_shared_ptr<__stop_state>& __state) : __state_(__state) {}
5757};
5858
59#endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN) && !defined(_LIBCPP_HAS_NO_THREADS)
59#endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS
6060
6161_LIBCPP_END_NAMESPACE_STD
6262
lib/libcxx/include/__string/char_traits.h+7-6
......@@ -17,18 +17,19 @@
1717#include <__assert>
1818#include <__compare/ordering.h>
1919#include <__config>
20#include <__cstddef/ptrdiff_t.h>
2021#include <__functional/hash.h>
2122#include <__functional/identity.h>
2223#include <__iterator/iterator_traits.h>
24#include <__std_mbstate_t.h>
2325#include <__string/constexpr_c_functions.h>
2426#include <__type_traits/is_constant_evaluated.h>
2527#include <__utility/is_pointer_in_range.h>
26#include <cstddef>
2728#include <cstdint>
2829#include <cstdio>
2930#include <iosfwd>
3031
31#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
32#if _LIBCPP_HAS_WIDE_CHARACTERS
3233# include <cwchar> // for wmemcpy
3334#endif
3435
......@@ -233,7 +234,7 @@ struct __char_traits_base {
233234
234235// char_traits<wchar_t>
235236
236#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
237#if _LIBCPP_HAS_WIDE_CHARACTERS
237238template <>
238239struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t> : __char_traits_base<wchar_t, wint_t, static_cast<wint_t>(WEOF)> {
239240 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 int
......@@ -254,9 +255,9 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t> : __char_traits_base<wchar_t, w
254255 return std::__constexpr_wmemchr(__s, __a, __n);
255256 }
256257};
257#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
258#endif // _LIBCPP_HAS_WIDE_CHARACTERS
258259
259#ifndef _LIBCPP_HAS_NO_CHAR8_T
260#if _LIBCPP_HAS_CHAR8_T
260261
261262template <>
262263struct _LIBCPP_TEMPLATE_VIS char_traits<char8_t>
......@@ -276,7 +277,7 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char8_t>
276277 }
277278};
278279
279#endif // _LIBCPP_HAS_NO_CHAR8_T
280#endif // _LIBCPP_HAS_CHAR8_T
280281
281282template <>
282283struct _LIBCPP_TEMPLATE_VIS char_traits<char16_t>
lib/libcxx/include/__string/constexpr_c_functions.h+7-8
......@@ -10,20 +10,23 @@
1010#define _LIBCPP___STRING_CONSTEXPR_C_FUNCTIONS_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__memory/addressof.h>
1415#include <__memory/construct_at.h>
1516#include <__type_traits/datasizeof.h>
17#include <__type_traits/enable_if.h>
1618#include <__type_traits/is_always_bitcastable.h>
1719#include <__type_traits/is_assignable.h>
1820#include <__type_traits/is_constant_evaluated.h>
1921#include <__type_traits/is_constructible.h>
2022#include <__type_traits/is_equality_comparable.h>
23#include <__type_traits/is_integral.h>
2124#include <__type_traits/is_same.h>
2225#include <__type_traits/is_trivially_copyable.h>
2326#include <__type_traits/is_trivially_lexicographically_comparable.h>
2427#include <__type_traits/remove_cv.h>
28#include <__utility/element_count.h>
2529#include <__utility/is_pointer_in_range.h>
26#include <cstddef>
2730
2831#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2932# pragma GCC system_header
......@@ -31,17 +34,13 @@
3134
3235_LIBCPP_BEGIN_NAMESPACE_STD
3336
34// Type used to encode that a function takes an integer that represents a number
35// of elements as opposed to a number of bytes.
36enum class __element_count : size_t {};
37
3837template <class _Tp>
3938inline const bool __is_char_type = false;
4039
4140template <>
4241inline const bool __is_char_type<char> = true;
4342
44#ifndef _LIBCPP_HAS_NO_CHAR8_T
43#if _LIBCPP_HAS_CHAR8_T
4544template <>
4645inline const bool __is_char_type<char8_t> = true;
4746#endif
......@@ -64,13 +63,13 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 size_t __constexpr_st
6463 return __builtin_strlen(reinterpret_cast<const char*>(__str));
6564}
6665
67// Because of __libcpp_is_trivially_lexicographically_comparable we know that comparing the object representations is
66// Because of __is_trivially_lexicographically_comparable_v we know that comparing the object representations is
6867// equivalent to a std::memcmp. Since we have multiple objects contiguously in memory, we can call memcmp once instead
6968// of invoking it on every object individually.
7069template <class _Tp, class _Up>
7170_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int
7271__constexpr_memcmp(const _Tp* __lhs, const _Up* __rhs, __element_count __n) {
73 static_assert(__libcpp_is_trivially_lexicographically_comparable<_Tp, _Up>::value,
72 static_assert(__is_trivially_lexicographically_comparable_v<_Tp, _Up>,
7473 "_Tp and _Up have to be trivially lexicographically comparable");
7574
7675 auto __count = static_cast<size_t>(__n);
lib/libcxx/include/__support/xlocale/__nop_locale_mgmt.h+2-4
......@@ -15,13 +15,11 @@
1515// Patch over lack of extended locale support
1616typedef void* locale_t;
1717
18inline _LIBCPP_HIDE_FROM_ABI locale_t duplocale(locale_t) { return NULL; }
18inline _LIBCPP_HIDE_FROM_ABI locale_t duplocale(locale_t) { return nullptr; }
1919
2020inline _LIBCPP_HIDE_FROM_ABI void freelocale(locale_t) {}
2121
22inline _LIBCPP_HIDE_FROM_ABI locale_t newlocale(int, const char*, locale_t) { return NULL; }
23
24inline _LIBCPP_HIDE_FROM_ABI locale_t uselocale(locale_t) { return NULL; }
22inline _LIBCPP_HIDE_FROM_ABI locale_t newlocale(int, const char*, locale_t) { return nullptr; }
2523
2624#define LC_COLLATE_MASK (1 << LC_COLLATE)
2725#define LC_CTYPE_MASK (1 << LC_CTYPE)
lib/libcxx/include/__support/xlocale/__posix_l_fallback.h+6-22
......@@ -20,29 +20,15 @@
2020#include <string.h>
2121#include <time.h>
2222
23#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
23#if _LIBCPP_HAS_WIDE_CHARACTERS
2424# include <wchar.h>
2525# include <wctype.h>
2626#endif
2727
28inline _LIBCPP_HIDE_FROM_ABI int isalnum_l(int __c, locale_t) { return ::isalnum(__c); }
29
30inline _LIBCPP_HIDE_FROM_ABI int isalpha_l(int __c, locale_t) { return ::isalpha(__c); }
31
32inline _LIBCPP_HIDE_FROM_ABI int iscntrl_l(int __c, locale_t) { return ::iscntrl(__c); }
33
3428inline _LIBCPP_HIDE_FROM_ABI int isdigit_l(int __c, locale_t) { return ::isdigit(__c); }
3529
36inline _LIBCPP_HIDE_FROM_ABI int isgraph_l(int __c, locale_t) { return ::isgraph(__c); }
37
3830inline _LIBCPP_HIDE_FROM_ABI int islower_l(int __c, locale_t) { return ::islower(__c); }
3931
40inline _LIBCPP_HIDE_FROM_ABI int isprint_l(int __c, locale_t) { return ::isprint(__c); }
41
42inline _LIBCPP_HIDE_FROM_ABI int ispunct_l(int __c, locale_t) { return ::ispunct(__c); }
43
44inline _LIBCPP_HIDE_FROM_ABI int isspace_l(int __c, locale_t) { return ::isspace(__c); }
45
4632inline _LIBCPP_HIDE_FROM_ABI int isupper_l(int __c, locale_t) { return ::isupper(__c); }
4733
4834inline _LIBCPP_HIDE_FROM_ABI int isxdigit_l(int __c, locale_t) { return ::isxdigit(__c); }
......@@ -51,8 +37,8 @@ inline _LIBCPP_HIDE_FROM_ABI int toupper_l(int __c, locale_t) { return ::toupper
5137
5238inline _LIBCPP_HIDE_FROM_ABI int tolower_l(int __c, locale_t) { return ::tolower(__c); }
5339
54#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
55inline _LIBCPP_HIDE_FROM_ABI int iswalnum_l(wint_t __c, locale_t) { return ::iswalnum(__c); }
40#if _LIBCPP_HAS_WIDE_CHARACTERS
41inline _LIBCPP_HIDE_FROM_ABI int iswctype_l(wint_t __c, wctype_t __type, locale_t) { return ::iswctype(__c, __type); }
5642
5743inline _LIBCPP_HIDE_FROM_ABI int iswalpha_l(wint_t __c, locale_t) { return ::iswalpha(__c); }
5844
......@@ -62,8 +48,6 @@ inline _LIBCPP_HIDE_FROM_ABI int iswcntrl_l(wint_t __c, locale_t) { return ::isw
6248
6349inline _LIBCPP_HIDE_FROM_ABI int iswdigit_l(wint_t __c, locale_t) { return ::iswdigit(__c); }
6450
65inline _LIBCPP_HIDE_FROM_ABI int iswgraph_l(wint_t __c, locale_t) { return ::iswgraph(__c); }
66
6751inline _LIBCPP_HIDE_FROM_ABI int iswlower_l(wint_t __c, locale_t) { return ::iswlower(__c); }
6852
6953inline _LIBCPP_HIDE_FROM_ABI int iswprint_l(wint_t __c, locale_t) { return ::iswprint(__c); }
......@@ -79,7 +63,7 @@ inline _LIBCPP_HIDE_FROM_ABI int iswxdigit_l(wint_t __c, locale_t) { return ::is
7963inline _LIBCPP_HIDE_FROM_ABI wint_t towupper_l(wint_t __c, locale_t) { return ::towupper(__c); }
8064
8165inline _LIBCPP_HIDE_FROM_ABI wint_t towlower_l(wint_t __c, locale_t) { return ::towlower(__c); }
82#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
66#endif // _LIBCPP_HAS_WIDE_CHARACTERS
8367
8468inline _LIBCPP_HIDE_FROM_ABI int strcoll_l(const char* __s1, const char* __s2, locale_t) {
8569 return ::strcoll(__s1, __s2);
......@@ -94,7 +78,7 @@ strftime_l(char* __s, size_t __max, const char* __format, const struct tm* __tm,
9478 return ::strftime(__s, __max, __format, __tm);
9579}
9680
97#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
81#if _LIBCPP_HAS_WIDE_CHARACTERS
9882inline _LIBCPP_HIDE_FROM_ABI int wcscoll_l(const wchar_t* __ws1, const wchar_t* __ws2, locale_t) {
9983 return ::wcscoll(__ws1, __ws2);
10084}
......@@ -102,6 +86,6 @@ inline _LIBCPP_HIDE_FROM_ABI int wcscoll_l(const wchar_t* __ws1, const wchar_t*
10286inline _LIBCPP_HIDE_FROM_ABI size_t wcsxfrm_l(wchar_t* __dest, const wchar_t* __src, size_t __n, locale_t) {
10387 return ::wcsxfrm(__dest, __src, __n);
10488}
105#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
89#endif // _LIBCPP_HAS_WIDE_CHARACTERS
10690
10791#endif // _LIBCPP___SUPPORT_XLOCALE_POSIX_L_FALLBACK_H
lib/libcxx/include/__support/xlocale/__strtonum_fallback.h+1-1
......@@ -18,7 +18,7 @@
1818#include <__config>
1919#include <stdlib.h>
2020
21#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
21#if _LIBCPP_HAS_WIDE_CHARACTERS
2222# include <wchar.h>
2323#endif
2424
lib/libcxx/include/__system_error/errc.h+1-1
......@@ -133,7 +133,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
133133// enum class errc
134134//
135135// LWG3869 deprecates the UNIX STREAMS macros and enum values.
136// This makes the code clumbersome:
136// This makes the code cumbersome:
137137// - the enum value is deprecated and should show a diagnostic,
138138// - the macro is deprecated and should _not_ show a diagnostic in this
139139// context, and
lib/libcxx/include/__system_error/error_code.h-1
......@@ -17,7 +17,6 @@
1717#include <__system_error/errc.h>
1818#include <__system_error/error_category.h>
1919#include <__system_error/error_condition.h>
20#include <cstddef>
2120#include <string>
2221
2322#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__system_error/error_condition.h-1
......@@ -16,7 +16,6 @@
1616#include <__functional/unary_function.h>
1717#include <__system_error/errc.h>
1818#include <__system_error/error_category.h>
19#include <cstddef>
2019#include <string>
2120
2221#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__system_error/system_error.h+6-3
......@@ -39,9 +39,12 @@ public:
3939 _LIBCPP_HIDE_FROM_ABI const error_code& code() const _NOEXCEPT { return __ec_; }
4040};
4141
42_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_system_error(int __ev, const char* __what_arg);
43_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI inline void __throw_system_error(error_code __ec, const char* __what_arg) {
44#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
42// __ev is expected to be an error in the generic_category domain (e.g. from
43// errno, or std::errc::*), not system_category (e.g. from windows syscalls).
44[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_system_error(int __ev, const char* __what_arg);
45
46[[__noreturn__]] _LIBCPP_HIDE_FROM_ABI inline void __throw_system_error(error_code __ec, const char* __what_arg) {
47#if _LIBCPP_HAS_EXCEPTIONS
4548 throw system_error(__ec, __what_arg);
4649#else
4750 _LIBCPP_VERBOSE_ABORT(
lib/libcxx/include/__system_error/throw_system_error.h created+25
......@@ -0,0 +1,25 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___SYSTEM_ERROR_THROW_SYSTEM_ERROR_H
11#define _LIBCPP___SYSTEM_ERROR_THROW_SYSTEM_ERROR_H
12
13#include <__config>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_system_error(int __ev, const char* __what_arg);
22
23_LIBCPP_END_NAMESPACE_STD
24
25#endif // _LIBCPP___SYSTEM_ERROR_THROW_SYSTEM_ERROR_H
lib/libcxx/include/__thread/formatter.h+2-2
......@@ -31,7 +31,7 @@
3131
3232_LIBCPP_BEGIN_NAMESPACE_STD
3333
34# ifndef _LIBCPP_HAS_NO_THREADS
34# if _LIBCPP_HAS_THREADS
3535
3636template <__fmt_char_type _CharT>
3737struct _LIBCPP_TEMPLATE_VIS formatter<__thread_id, _CharT> {
......@@ -71,7 +71,7 @@ public:
7171 __format_spec::__parser<_CharT> __parser_{.__alignment_ = __format_spec::__alignment::__right};
7272};
7373
74# endif // !_LIBCPP_HAS_NO_THREADS
74# endif // _LIBCPP_HAS_THREADS
7575
7676_LIBCPP_END_NAMESPACE_STD
7777
lib/libcxx/include/__thread/id.h+2-2
......@@ -22,7 +22,7 @@
2222
2323_LIBCPP_BEGIN_NAMESPACE_STD
2424
25#ifndef _LIBCPP_HAS_NO_THREADS
25#if _LIBCPP_HAS_THREADS
2626class _LIBCPP_EXPORTED_FROM_ABI __thread_id;
2727
2828namespace this_thread {
......@@ -114,7 +114,7 @@ inline _LIBCPP_HIDE_FROM_ABI __thread_id get_id() _NOEXCEPT { return __libcpp_th
114114
115115} // namespace this_thread
116116
117#endif // !_LIBCPP_HAS_NO_THREADS
117#endif // _LIBCPP_HAS_THREADS
118118
119119_LIBCPP_END_NAMESPACE_STD
120120
lib/libcxx/include/__thread/jthread.h+5-3
......@@ -11,17 +11,19 @@
1111#define _LIBCPP___THREAD_JTHREAD_H
1212
1313#include <__config>
14#include <__functional/invoke.h>
1514#include <__stop_token/stop_source.h>
1615#include <__stop_token/stop_token.h>
16#include <__thread/id.h>
1717#include <__thread/support.h>
1818#include <__thread/thread.h>
1919#include <__type_traits/decay.h>
20#include <__type_traits/invoke.h>
2021#include <__type_traits/is_constructible.h>
2122#include <__type_traits/is_same.h>
2223#include <__type_traits/remove_cvref.h>
2324#include <__utility/forward.h>
2425#include <__utility/move.h>
26#include <__utility/swap.h>
2527
2628#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2729# pragma GCC system_header
......@@ -30,7 +32,7 @@
3032_LIBCPP_PUSH_MACROS
3133#include <__undef_macros>
3234
33#if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN)
35#if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS
3436
3537_LIBCPP_BEGIN_NAMESPACE_STD
3638
......@@ -127,7 +129,7 @@ private:
127129
128130_LIBCPP_END_NAMESPACE_STD
129131
130#endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN)
132#endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_THREADS
131133
132134_LIBCPP_POP_MACROS
133135
lib/libcxx/include/__thread/support.h+6-6
......@@ -104,20 +104,20 @@ _LIBCPP_END_NAMESPACE_STD
104104
105105*/
106106
107#if !defined(_LIBCPP_HAS_NO_THREADS)
107#if _LIBCPP_HAS_THREADS
108108
109# if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
109# if _LIBCPP_HAS_THREAD_API_EXTERNAL
110110# include <__thread/support/external.h>
111# elif defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
111# elif _LIBCPP_HAS_THREAD_API_PTHREAD
112112# include <__thread/support/pthread.h>
113# elif defined(_LIBCPP_HAS_THREAD_API_C11)
113# elif _LIBCPP_HAS_THREAD_API_C11
114114# include <__thread/support/c11.h>
115# elif defined(_LIBCPP_HAS_THREAD_API_WIN32)
115# elif _LIBCPP_HAS_THREAD_API_WIN32
116116# include <__thread/support/windows.h>
117117# else
118118# error "No threading API was selected"
119119# endif
120120
121#endif // !_LIBCPP_HAS_NO_THREADS
121#endif // _LIBCPP_HAS_THREADS
122122
123123#endif // _LIBCPP___THREAD_SUPPORT_H
lib/libcxx/include/__thread/support/pthread.h+1-1
......@@ -39,7 +39,7 @@
3939
4040_LIBCPP_BEGIN_NAMESPACE_STD
4141
42using __libcpp_timespec_t = ::timespec;
42using __libcpp_timespec_t _LIBCPP_NODEBUG = ::timespec;
4343
4444//
4545// Mutex
lib/libcxx/include/__thread/this_thread.h+5
......@@ -10,6 +10,7 @@
1010#ifndef _LIBCPP___THREAD_THIS_THREAD_H
1111#define _LIBCPP___THREAD_THIS_THREAD_H
1212
13#include <__chrono/duration.h>
1314#include <__chrono/steady_clock.h>
1415#include <__chrono/time_point.h>
1516#include <__condition_variable/condition_variable.h>
......@@ -29,6 +30,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2930
3031namespace this_thread {
3132
33#if _LIBCPP_HAS_THREADS
34
3235_LIBCPP_EXPORTED_FROM_ABI void sleep_for(const chrono::nanoseconds& __ns);
3336
3437template <class _Rep, class _Period>
......@@ -65,6 +68,8 @@ inline _LIBCPP_HIDE_FROM_ABI void sleep_until(const chrono::time_point<chrono::s
6568
6669inline _LIBCPP_HIDE_FROM_ABI void yield() _NOEXCEPT { __libcpp_thread_yield(); }
6770
71#endif // _LIBCPP_HAS_THREADS
72
6873} // namespace this_thread
6974
7075_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__thread/thread.h+19-10
......@@ -10,6 +10,7 @@
1010#ifndef _LIBCPP___THREAD_THREAD_H
1111#define _LIBCPP___THREAD_THREAD_H
1212
13#include <__assert>
1314#include <__condition_variable/condition_variable.h>
1415#include <__config>
1516#include <__exception/terminate.h>
......@@ -17,13 +18,17 @@
1718#include <__functional/unary_function.h>
1819#include <__memory/unique_ptr.h>
1920#include <__mutex/mutex.h>
20#include <__system_error/system_error.h>
21#include <__system_error/throw_system_error.h>
2122#include <__thread/id.h>
2223#include <__thread/support.h>
24#include <__type_traits/decay.h>
25#include <__type_traits/enable_if.h>
26#include <__type_traits/is_same.h>
27#include <__type_traits/remove_cvref.h>
2328#include <__utility/forward.h>
2429#include <tuple>
2530
26#ifndef _LIBCPP_HAS_NO_LOCALIZATION
31#if _LIBCPP_HAS_LOCALIZATION
2732# include <locale>
2833# include <sstream>
2934#endif
......@@ -37,6 +42,8 @@ _LIBCPP_PUSH_MACROS
3742
3843_LIBCPP_BEGIN_NAMESPACE_STD
3944
45#if _LIBCPP_HAS_THREADS
46
4047template <class _Tp>
4148class __thread_specific_ptr;
4249class _LIBCPP_EXPORTED_FROM_ABI __thread_struct;
......@@ -117,7 +124,7 @@ struct _LIBCPP_TEMPLATE_VIS hash<__thread_id> : public __unary_function<__thread
117124 }
118125};
119126
120#ifndef _LIBCPP_HAS_NO_LOCALIZATION
127# if _LIBCPP_HAS_LOCALIZATION
121128template <class _CharT, class _Traits>
122129_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
123130operator<<(basic_ostream<_CharT, _Traits>& __os, __thread_id __id) {
......@@ -142,7 +149,7 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, __thread_id __id) {
142149 __sstr << __id.__id_;
143150 return __os << __sstr.str();
144151}
145#endif // _LIBCPP_HAS_NO_LOCALIZATION
152# endif // _LIBCPP_HAS_LOCALIZATION
146153
147154class _LIBCPP_EXPORTED_FROM_ABI thread {
148155 __libcpp_thread_t __t_;
......@@ -155,13 +162,13 @@ public:
155162 typedef __libcpp_thread_t native_handle_type;
156163
157164 _LIBCPP_HIDE_FROM_ABI thread() _NOEXCEPT : __t_(_LIBCPP_NULL_THREAD) {}
158#ifndef _LIBCPP_CXX03_LANG
165# ifndef _LIBCPP_CXX03_LANG
159166 template <class _Fp, class... _Args, __enable_if_t<!is_same<__remove_cvref_t<_Fp>, thread>::value, int> = 0>
160167 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS explicit thread(_Fp&& __f, _Args&&... __args);
161#else // _LIBCPP_CXX03_LANG
168# else // _LIBCPP_CXX03_LANG
162169 template <class _Fp>
163170 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS explicit thread(_Fp __f);
164#endif
171# endif
165172 ~thread();
166173
167174 _LIBCPP_HIDE_FROM_ABI thread(thread&& __t) _NOEXCEPT : __t_(__t.__t_) { __t.__t_ = _LIBCPP_NULL_THREAD; }
......@@ -185,7 +192,7 @@ public:
185192 static unsigned hardware_concurrency() _NOEXCEPT;
186193};
187194
188#ifndef _LIBCPP_CXX03_LANG
195# ifndef _LIBCPP_CXX03_LANG
189196
190197template <class _TSp, class _Fp, class... _Args, size_t... _Indices>
191198inline _LIBCPP_HIDE_FROM_ABI void __thread_execute(tuple<_TSp, _Fp, _Args...>& __t, __tuple_indices<_Indices...>) {
......@@ -215,7 +222,7 @@ thread::thread(_Fp&& __f, _Args&&... __args) {
215222 __throw_system_error(__ec, "thread constructor failed");
216223}
217224
218#else // _LIBCPP_CXX03_LANG
225# else // _LIBCPP_CXX03_LANG
219226
220227template <class _Fp>
221228struct __thread_invoke_pair {
......@@ -247,10 +254,12 @@ thread::thread(_Fp __f) {
247254 __throw_system_error(__ec, "thread constructor failed");
248255}
249256
250#endif // _LIBCPP_CXX03_LANG
257# endif // _LIBCPP_CXX03_LANG
251258
252259inline _LIBCPP_HIDE_FROM_ABI void swap(thread& __x, thread& __y) _NOEXCEPT { __x.swap(__y); }
253260
261#endif // _LIBCPP_HAS_THREADS
262
254263_LIBCPP_END_NAMESPACE_STD
255264
256265_LIBCPP_POP_MACROS
lib/libcxx/include/__thread/timed_backoff_policy.h+2-2
......@@ -12,7 +12,7 @@
1212
1313#include <__config>
1414
15#ifndef _LIBCPP_HAS_NO_THREADS
15#if _LIBCPP_HAS_THREADS
1616
1717# include <__chrono/duration.h>
1818# include <__thread/support.h>
......@@ -39,6 +39,6 @@ struct __libcpp_timed_backoff_policy {
3939
4040_LIBCPP_END_NAMESPACE_STD
4141
42#endif // _LIBCPP_HAS_NO_THREADS
42#endif // _LIBCPP_HAS_THREADS
4343
4444#endif // _LIBCPP___THREAD_TIMED_BACKOFF_POLICY_H
lib/libcxx/include/__tree+42-38
......@@ -13,7 +13,6 @@
1313#include <__algorithm/min.h>
1414#include <__assert>
1515#include <__config>
16#include <__functional/invoke.h>
1716#include <__iterator/distance.h>
1817#include <__iterator/iterator_traits.h>
1918#include <__iterator/next.h>
......@@ -24,12 +23,12 @@
2423#include <__memory/swap_allocator.h>
2524#include <__memory/unique_ptr.h>
2625#include <__type_traits/can_extract_key.h>
27#include <__type_traits/conditional.h>
26#include <__type_traits/enable_if.h>
27#include <__type_traits/invoke.h>
2828#include <__type_traits/is_const.h>
2929#include <__type_traits/is_constructible.h>
3030#include <__type_traits/is_nothrow_assignable.h>
3131#include <__type_traits/is_nothrow_constructible.h>
32#include <__type_traits/is_pointer.h>
3332#include <__type_traits/is_same.h>
3433#include <__type_traits/is_swappable.h>
3534#include <__type_traits/remove_const_ref.h>
......@@ -566,11 +565,18 @@ struct __tree_node_base_types {
566565
567566 typedef __tree_end_node<__node_base_pointer> __end_node_type;
568567 typedef __rebind_pointer_t<_VoidPtr, __end_node_type> __end_node_pointer;
569#if defined(_LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB)
570568 typedef __end_node_pointer __parent_pointer;
571#else
572 typedef __conditional_t< is_pointer<__end_node_pointer>::value, __end_node_pointer, __node_base_pointer>
573 __parent_pointer;
569
570// TODO(LLVM 22): Remove this check
571#ifndef _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
572 static_assert(sizeof(__node_base_pointer) == sizeof(__end_node_pointer) && _LIBCPP_ALIGNOF(__node_base_pointer) ==
573 _LIBCPP_ALIGNOF(__end_node_pointer),
574 "It looks like you are using std::__tree (an implementation detail for (multi)map/set) with a fancy "
575 "pointer type that thas a different representation depending on whether it points to a __tree base "
576 "pointer or a __tree node pointer (both of which are implementation details of the standard library). "
577 "This means that your ABI is being broken between LLVM 19 and LLVM 20. If you don't care about your "
578 "ABI being broken, define the _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB macro to silence this "
579 "diagnostic.");
574580#endif
575581
576582private:
......@@ -605,12 +611,7 @@ public:
605611 typedef _Tp __node_value_type;
606612 typedef __rebind_pointer_t<_VoidPtr, __node_value_type> __node_value_type_pointer;
607613 typedef __rebind_pointer_t<_VoidPtr, const __node_value_type> __const_node_value_type_pointer;
608#if defined(_LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB)
609614 typedef typename __base::__end_node_pointer __iter_pointer;
610#else
611 typedef __conditional_t< is_pointer<__node_pointer>::value, typename __base::__end_node_pointer, __node_pointer>
612 __iter_pointer;
613#endif
614615
615616private:
616617 static_assert(!is_const<__node_type>::value, "_NodePtr should never be a pointer to const");
......@@ -875,7 +876,7 @@ private:
875876
876877template <class _Tp, class _Compare>
877878#ifndef _LIBCPP_CXX03_LANG
878_LIBCPP_DIAGNOSE_WARNING(!__invokable<_Compare const&, _Tp const&, _Tp const&>::value,
879_LIBCPP_DIAGNOSE_WARNING(!__is_invocable_v<_Compare const&, _Tp const&, _Tp const&>,
879880 "the specified comparator type does not provide a viable const call operator")
880881#endif
881882int __diagnose_non_const_comparator();
......@@ -932,21 +933,21 @@ private:
932933
933934private:
934935 __iter_pointer __begin_node_;
935 __compressed_pair<__end_node_t, __node_allocator> __pair1_;
936 __compressed_pair<size_type, value_compare> __pair3_;
936 _LIBCPP_COMPRESSED_PAIR(__end_node_t, __end_node_, __node_allocator, __node_alloc_);
937 _LIBCPP_COMPRESSED_PAIR(size_type, __size_, value_compare, __value_comp_);
937938
938939public:
939940 _LIBCPP_HIDE_FROM_ABI __iter_pointer __end_node() _NOEXCEPT {
940 return static_cast<__iter_pointer>(pointer_traits<__end_node_ptr>::pointer_to(__pair1_.first()));
941 return static_cast<__iter_pointer>(pointer_traits<__end_node_ptr>::pointer_to(__end_node_));
941942 }
942943 _LIBCPP_HIDE_FROM_ABI __iter_pointer __end_node() const _NOEXCEPT {
943944 return static_cast<__iter_pointer>(
944 pointer_traits<__end_node_ptr>::pointer_to(const_cast<__end_node_t&>(__pair1_.first())));
945 pointer_traits<__end_node_ptr>::pointer_to(const_cast<__end_node_t&>(__end_node_)));
945946 }
946 _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __pair1_.second(); }
947 _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __node_alloc_; }
947948
948949private:
949 _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __pair1_.second(); }
950 _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __node_alloc_; }
950951 _LIBCPP_HIDE_FROM_ABI __iter_pointer& __begin_node() _NOEXCEPT { return __begin_node_; }
951952 _LIBCPP_HIDE_FROM_ABI const __iter_pointer& __begin_node() const _NOEXCEPT { return __begin_node_; }
952953
......@@ -954,12 +955,12 @@ public:
954955 _LIBCPP_HIDE_FROM_ABI allocator_type __alloc() const _NOEXCEPT { return allocator_type(__node_alloc()); }
955956
956957private:
957 _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __pair3_.first(); }
958 _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __size_; }
958959
959960public:
960 _LIBCPP_HIDE_FROM_ABI const size_type& size() const _NOEXCEPT { return __pair3_.first(); }
961 _LIBCPP_HIDE_FROM_ABI value_compare& value_comp() _NOEXCEPT { return __pair3_.second(); }
962 _LIBCPP_HIDE_FROM_ABI const value_compare& value_comp() const _NOEXCEPT { return __pair3_.second(); }
961 _LIBCPP_HIDE_FROM_ABI const size_type& size() const _NOEXCEPT { return __size_; }
962 _LIBCPP_HIDE_FROM_ABI value_compare& value_comp() _NOEXCEPT { return __value_comp_; }
963 _LIBCPP_HIDE_FROM_ABI const value_compare& value_comp() const _NOEXCEPT { return __value_comp_; }
963964
964965public:
965966 _LIBCPP_HIDE_FROM_ABI __node_pointer __root() const _NOEXCEPT {
......@@ -1324,21 +1325,19 @@ private:
13241325template <class _Tp, class _Compare, class _Allocator>
13251326__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp) _NOEXCEPT_(
13261327 is_nothrow_default_constructible<__node_allocator>::value&& is_nothrow_copy_constructible<value_compare>::value)
1327 : __pair3_(0, __comp) {
1328 : __size_(0), __value_comp_(__comp) {
13281329 __begin_node() = __end_node();
13291330}
13301331
13311332template <class _Tp, class _Compare, class _Allocator>
13321333__tree<_Tp, _Compare, _Allocator>::__tree(const allocator_type& __a)
1333 : __begin_node_(__iter_pointer()),
1334 __pair1_(__default_init_tag(), __node_allocator(__a)),
1335 __pair3_(0, __default_init_tag()) {
1334 : __begin_node_(__iter_pointer()), __node_alloc_(__node_allocator(__a)), __size_(0) {
13361335 __begin_node() = __end_node();
13371336}
13381337
13391338template <class _Tp, class _Compare, class _Allocator>
13401339__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp, const allocator_type& __a)
1341 : __begin_node_(__iter_pointer()), __pair1_(__default_init_tag(), __node_allocator(__a)), __pair3_(0, __comp) {
1340 : __begin_node_(__iter_pointer()), __node_alloc_(__node_allocator(__a)), __size_(0), __value_comp_(__comp) {
13421341 __begin_node() = __end_node();
13431342}
13441343
......@@ -1437,8 +1436,9 @@ void __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _
14371436template <class _Tp, class _Compare, class _Allocator>
14381437__tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t)
14391438 : __begin_node_(__iter_pointer()),
1440 __pair1_(__default_init_tag(), __node_traits::select_on_container_copy_construction(__t.__node_alloc())),
1441 __pair3_(0, __t.value_comp()) {
1439 __node_alloc_(__node_traits::select_on_container_copy_construction(__t.__node_alloc())),
1440 __size_(0),
1441 __value_comp_(__t.value_comp()) {
14421442 __begin_node() = __end_node();
14431443}
14441444
......@@ -1446,8 +1446,10 @@ template <class _Tp, class _Compare, class _Allocator>
14461446__tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) _NOEXCEPT_(
14471447 is_nothrow_move_constructible<__node_allocator>::value&& is_nothrow_move_constructible<value_compare>::value)
14481448 : __begin_node_(std::move(__t.__begin_node_)),
1449 __pair1_(std::move(__t.__pair1_)),
1450 __pair3_(std::move(__t.__pair3_)) {
1449 __end_node_(std::move(__t.__end_node_)),
1450 __node_alloc_(std::move(__t.__node_alloc_)),
1451 __size_(__t.__size_),
1452 __value_comp_(std::move(__t.__value_comp_)) {
14511453 if (size() == 0)
14521454 __begin_node() = __end_node();
14531455 else {
......@@ -1460,7 +1462,7 @@ __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) _NOEXCEPT_(
14601462
14611463template <class _Tp, class _Compare, class _Allocator>
14621464__tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __a)
1463 : __pair1_(__default_init_tag(), __node_allocator(__a)), __pair3_(0, std::move(__t.value_comp())) {
1465 : __node_alloc_(__node_allocator(__a)), __size_(0), __value_comp_(std::move(__t.value_comp())) {
14641466 if (__a == __t.__alloc()) {
14651467 if (__t.size() == 0)
14661468 __begin_node() = __end_node();
......@@ -1482,10 +1484,11 @@ template <class _Tp, class _Compare, class _Allocator>
14821484void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, true_type)
14831485 _NOEXCEPT_(is_nothrow_move_assignable<value_compare>::value&& is_nothrow_move_assignable<__node_allocator>::value) {
14841486 destroy(static_cast<__node_pointer>(__end_node()->__left_));
1485 __begin_node_ = __t.__begin_node_;
1486 __pair1_.first() = __t.__pair1_.first();
1487 __begin_node_ = __t.__begin_node_;
1488 __end_node_ = __t.__end_node_;
14871489 __move_assign_alloc(__t);
1488 __pair3_ = std::move(__t.__pair3_);
1490 __size_ = __t.__size_;
1491 __value_comp_ = std::move(__t.__value_comp_);
14891492 if (size() == 0)
14901493 __begin_node() = __end_node();
14911494 else {
......@@ -1554,9 +1557,10 @@ void __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t)
15541557{
15551558 using std::swap;
15561559 swap(__begin_node_, __t.__begin_node_);
1557 swap(__pair1_.first(), __t.__pair1_.first());
1560 swap(__end_node_, __t.__end_node_);
15581561 std::__swap_allocator(__node_alloc(), __t.__node_alloc());
1559 __pair3_.swap(__t.__pair3_);
1562 swap(__size_, __t.__size_);
1563 swap(__value_comp_, __t.__value_comp_);
15601564 if (size() == 0)
15611565 __begin_node() = __end_node();
15621566 else
lib/libcxx/include/__tuple/find_index.h+1-1
......@@ -10,8 +10,8 @@
1010#define _LIBCPP___TUPLE_FIND_INDEX_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__type_traits/is_same.h>
14#include <cstddef>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717# pragma GCC system_header
lib/libcxx/include/__tuple/make_tuple_types.h+9-9
......@@ -10,6 +10,7 @@
1010#define _LIBCPP___TUPLE_MAKE_TUPLE_TYPES_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__fwd/array.h>
1415#include <__fwd/tuple.h>
1516#include <__tuple/tuple_element.h>
......@@ -17,9 +18,8 @@
1718#include <__tuple/tuple_size.h>
1819#include <__tuple/tuple_types.h>
1920#include <__type_traits/copy_cvref.h>
20#include <__type_traits/remove_cv.h>
21#include <__type_traits/remove_cvref.h>
2122#include <__type_traits/remove_reference.h>
22#include <cstddef>
2323
2424#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2525# pragma GCC system_header
......@@ -47,9 +47,9 @@ struct __make_tuple_types_flat<_Tuple<_Types...>, __tuple_indices<_Idx...>> {
4747template <class _Vt, size_t _Np, size_t... _Idx>
4848struct __make_tuple_types_flat<array<_Vt, _Np>, __tuple_indices<_Idx...>> {
4949 template <size_t>
50 using __value_type = _Vt;
50 using __value_type _LIBCPP_NODEBUG = _Vt;
5151 template <class _Tp>
52 using __apply_quals = __tuple_types<__copy_cvref_t<_Tp, __value_type<_Idx>>...>;
52 using __apply_quals _LIBCPP_NODEBUG = __tuple_types<__copy_cvref_t<_Tp, __value_type<_Idx>>...>;
5353};
5454
5555template <class _Tp,
......@@ -58,19 +58,19 @@ template <class _Tp,
5858 bool _SameSize = (_Ep == tuple_size<__libcpp_remove_reference_t<_Tp> >::value)>
5959struct __make_tuple_types {
6060 static_assert(_Sp <= _Ep, "__make_tuple_types input error");
61 using _RawTp = __remove_cv_t<__libcpp_remove_reference_t<_Tp> >;
62 using _Maker = __make_tuple_types_flat<_RawTp, typename __make_tuple_indices<_Ep, _Sp>::type>;
63 using type = typename _Maker::template __apply_quals<_Tp>;
61 using _RawTp _LIBCPP_NODEBUG = __remove_cvref_t<_Tp>;
62 using _Maker _LIBCPP_NODEBUG = __make_tuple_types_flat<_RawTp, typename __make_tuple_indices<_Ep, _Sp>::type>;
63 using type = typename _Maker::template __apply_quals<_Tp>;
6464};
6565
6666template <class... _Types, size_t _Ep>
6767struct __make_tuple_types<tuple<_Types...>, _Ep, 0, true> {
68 typedef _LIBCPP_NODEBUG __tuple_types<_Types...> type;
68 using type _LIBCPP_NODEBUG = __tuple_types<_Types...>;
6969};
7070
7171template <class... _Types, size_t _Ep>
7272struct __make_tuple_types<__tuple_types<_Types...>, _Ep, 0, true> {
73 typedef _LIBCPP_NODEBUG __tuple_types<_Types...> type;
73 using type _LIBCPP_NODEBUG = __tuple_types<_Types...>;
7474};
7575
7676_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__tuple/sfinae_helpers.h+3-3
......@@ -10,6 +10,7 @@
1010#define _LIBCPP___TUPLE_SFINAE_HELPERS_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__fwd/tuple.h>
1415#include <__tuple/make_tuple_types.h>
1516#include <__tuple/tuple_element.h>
......@@ -23,7 +24,6 @@
2324#include <__type_traits/is_same.h>
2425#include <__type_traits/remove_cvref.h>
2526#include <__type_traits/remove_reference.h>
26#include <cstddef>
2727
2828#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2929# pragma GCC system_header
......@@ -41,7 +41,7 @@ struct __tuple_sfinae_base {
4141 static auto __do_test(...) -> false_type;
4242
4343 template <class _FromArgs, class _ToArgs>
44 using __constructible = decltype(__do_test<is_constructible>(_ToArgs{}, _FromArgs{}));
44 using __constructible _LIBCPP_NODEBUG = decltype(__do_test<is_constructible>(_ToArgs{}, _FromArgs{}));
4545};
4646
4747// __tuple_constructible
......@@ -59,7 +59,7 @@ struct __tuple_constructible<_Tp, _Up, true, true>
5959
6060template <size_t _Ip, class... _Tp>
6161struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, tuple<_Tp...> > {
62 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
62 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, __tuple_types<_Tp...> >::type;
6363};
6464
6565struct _LIBCPP_EXPORTED_FROM_ABI __check_tuple_constructor_fail {
lib/libcxx/include/__tuple/tuple_element.h+5-5
......@@ -10,9 +10,9 @@
1010#define _LIBCPP___TUPLE_TUPLE_ELEMENT_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__tuple/tuple_indices.h>
1415#include <__tuple/tuple_types.h>
15#include <cstddef>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818# pragma GCC system_header
......@@ -25,17 +25,17 @@ struct _LIBCPP_TEMPLATE_VIS tuple_element;
2525
2626template <size_t _Ip, class _Tp>
2727struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp> {
28 typedef _LIBCPP_NODEBUG const typename tuple_element<_Ip, _Tp>::type type;
28 using type _LIBCPP_NODEBUG = const typename tuple_element<_Ip, _Tp>::type;
2929};
3030
3131template <size_t _Ip, class _Tp>
3232struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp> {
33 typedef _LIBCPP_NODEBUG volatile typename tuple_element<_Ip, _Tp>::type type;
33 using type _LIBCPP_NODEBUG = volatile typename tuple_element<_Ip, _Tp>::type;
3434};
3535
3636template <size_t _Ip, class _Tp>
3737struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp> {
38 typedef _LIBCPP_NODEBUG const volatile typename tuple_element<_Ip, _Tp>::type type;
38 using type _LIBCPP_NODEBUG = const volatile typename tuple_element<_Ip, _Tp>::type;
3939};
4040
4141#ifndef _LIBCPP_CXX03_LANG
......@@ -43,7 +43,7 @@ struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp> {
4343template <size_t _Ip, class... _Types>
4444struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...> > {
4545 static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range");
46 typedef _LIBCPP_NODEBUG __type_pack_element<_Ip, _Types...> type;
46 using type _LIBCPP_NODEBUG = __type_pack_element<_Ip, _Types...>;
4747};
4848
4949# if _LIBCPP_STD_VER >= 14
lib/libcxx/include/__tuple/tuple_indices.h+1-1
......@@ -10,8 +10,8 @@
1010#define _LIBCPP___TUPLE_MAKE_TUPLE_INDICES_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__utility/integer_sequence.h>
14#include <cstddef>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717# pragma GCC system_header
lib/libcxx/include/__tuple/tuple_like_ext.h+1-1
......@@ -10,12 +10,12 @@
1010#define _LIBCPP___TUPLE_TUPLE_LIKE_EXT_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__fwd/array.h>
1415#include <__fwd/pair.h>
1516#include <__fwd/tuple.h>
1617#include <__tuple/tuple_types.h>
1718#include <__type_traits/integral_constant.h>
18#include <cstddef>
1919
2020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2121# pragma GCC system_header
lib/libcxx/include/__tuple/tuple_like_no_subrange.h+1-1
......@@ -10,13 +10,13 @@
1010#define _LIBCPP___TUPLE_TUPLE_LIKE_NO_SUBRANGE_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__fwd/array.h>
1415#include <__fwd/complex.h>
1516#include <__fwd/pair.h>
1617#include <__fwd/tuple.h>
1718#include <__tuple/tuple_size.h>
1819#include <__type_traits/remove_cvref.h>
19#include <cstddef>
2020
2121#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2222# pragma GCC system_header
lib/libcxx/include/__tuple/tuple_size.h+4-2
......@@ -10,11 +10,13 @@
1010#define _LIBCPP___TUPLE_TUPLE_SIZE_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__fwd/tuple.h>
1415#include <__tuple/tuple_types.h>
16#include <__type_traits/enable_if.h>
17#include <__type_traits/integral_constant.h>
1518#include <__type_traits/is_const.h>
1619#include <__type_traits/is_volatile.h>
17#include <cstddef>
1820
1921#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2022# pragma GCC system_header
......@@ -27,7 +29,7 @@ struct _LIBCPP_TEMPLATE_VIS tuple_size;
2729
2830#if !defined(_LIBCPP_CXX03_LANG)
2931template <class _Tp, class...>
30using __enable_if_tuple_size_imp = _Tp;
32using __enable_if_tuple_size_imp _LIBCPP_NODEBUG = _Tp;
3133
3234template <class _Tp>
3335struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp< const _Tp,
lib/libcxx/include/__type_traits/add_const.h deleted-32
......@@ -1,32 +0,0 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_ADD_CONST_H
10#define _LIBCPP___TYPE_TRAITS_ADD_CONST_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20template <class _Tp>
21struct _LIBCPP_TEMPLATE_VIS add_const {
22 typedef _LIBCPP_NODEBUG const _Tp type;
23};
24
25#if _LIBCPP_STD_VER >= 14
26template <class _Tp>
27using add_const_t = typename add_const<_Tp>::type;
28#endif
29
30_LIBCPP_END_NAMESPACE_STD
31
32#endif // _LIBCPP___TYPE_TRAITS_ADD_CONST_H
lib/libcxx/include/__type_traits/add_cv.h deleted-32
......@@ -1,32 +0,0 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_ADD_CV_H
10#define _LIBCPP___TYPE_TRAITS_ADD_CV_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20template <class _Tp>
21struct _LIBCPP_TEMPLATE_VIS add_cv {
22 typedef _LIBCPP_NODEBUG const volatile _Tp type;
23};
24
25#if _LIBCPP_STD_VER >= 14
26template <class _Tp>
27using add_cv_t = typename add_cv<_Tp>::type;
28#endif
29
30_LIBCPP_END_NAMESPACE_STD
31
32#endif // _LIBCPP___TYPE_TRAITS_ADD_CV_H
lib/libcxx/include/__type_traits/add_cv_quals.h created+52
......@@ -0,0 +1,52 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_ADD_CV_H
10#define _LIBCPP___TYPE_TRAITS_ADD_CV_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20template <class _Tp>
21struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS add_const {
22 using type _LIBCPP_NODEBUG = const _Tp;
23};
24
25#if _LIBCPP_STD_VER >= 14
26template <class _Tp>
27using add_const_t = typename add_const<_Tp>::type;
28#endif
29
30template <class _Tp>
31struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS add_cv {
32 using type _LIBCPP_NODEBUG = const volatile _Tp;
33};
34
35#if _LIBCPP_STD_VER >= 14
36template <class _Tp>
37using add_cv_t = typename add_cv<_Tp>::type;
38#endif
39
40template <class _Tp>
41struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS add_volatile {
42 using type _LIBCPP_NODEBUG = volatile _Tp;
43};
44
45#if _LIBCPP_STD_VER >= 14
46template <class _Tp>
47using add_volatile_t = typename add_volatile<_Tp>::type;
48#endif
49
50_LIBCPP_END_NAMESPACE_STD
51
52#endif // _LIBCPP___TYPE_TRAITS_ADD_CV_H
lib/libcxx/include/__type_traits/add_lvalue_reference.h+4-4
......@@ -21,17 +21,17 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121#if __has_builtin(__add_lvalue_reference)
2222
2323template <class _Tp>
24using __add_lvalue_reference_t = __add_lvalue_reference(_Tp);
24using __add_lvalue_reference_t _LIBCPP_NODEBUG = __add_lvalue_reference(_Tp);
2525
2626#else
2727
2828template <class _Tp, bool = __libcpp_is_referenceable<_Tp>::value>
2929struct __add_lvalue_reference_impl {
30 typedef _LIBCPP_NODEBUG _Tp type;
30 using type _LIBCPP_NODEBUG = _Tp;
3131};
3232template <class _Tp >
3333struct __add_lvalue_reference_impl<_Tp, true> {
34 typedef _LIBCPP_NODEBUG _Tp& type;
34 using type _LIBCPP_NODEBUG = _Tp&;
3535};
3636
3737template <class _Tp>
......@@ -40,7 +40,7 @@ using __add_lvalue_reference_t = typename __add_lvalue_reference_impl<_Tp>::type
4040#endif // __has_builtin(__add_lvalue_reference)
4141
4242template <class _Tp>
43struct add_lvalue_reference {
43struct _LIBCPP_NO_SPECIALIZATIONS add_lvalue_reference {
4444 using type _LIBCPP_NODEBUG = __add_lvalue_reference_t<_Tp>;
4545};
4646
lib/libcxx/include/__type_traits/add_pointer.h+4-4
......@@ -23,16 +23,16 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2323#if !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS) && __has_builtin(__add_pointer)
2424
2525template <class _Tp>
26using __add_pointer_t = __add_pointer(_Tp);
26using __add_pointer_t _LIBCPP_NODEBUG = __add_pointer(_Tp);
2727
2828#else
2929template <class _Tp, bool = __libcpp_is_referenceable<_Tp>::value || is_void<_Tp>::value>
3030struct __add_pointer_impl {
31 typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tp>* type;
31 using type _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tp>*;
3232};
3333template <class _Tp>
3434struct __add_pointer_impl<_Tp, false> {
35 typedef _LIBCPP_NODEBUG _Tp type;
35 using type _LIBCPP_NODEBUG = _Tp;
3636};
3737
3838template <class _Tp>
......@@ -41,7 +41,7 @@ using __add_pointer_t = typename __add_pointer_impl<_Tp>::type;
4141#endif // !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS) && __has_builtin(__add_pointer)
4242
4343template <class _Tp>
44struct add_pointer {
44struct _LIBCPP_NO_SPECIALIZATIONS add_pointer {
4545 using type _LIBCPP_NODEBUG = __add_pointer_t<_Tp>;
4646};
4747
lib/libcxx/include/__type_traits/add_rvalue_reference.h+4-4
......@@ -21,17 +21,17 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121#if __has_builtin(__add_rvalue_reference)
2222
2323template <class _Tp>
24using __add_rvalue_reference_t = __add_rvalue_reference(_Tp);
24using __add_rvalue_reference_t _LIBCPP_NODEBUG = __add_rvalue_reference(_Tp);
2525
2626#else
2727
2828template <class _Tp, bool = __libcpp_is_referenceable<_Tp>::value>
2929struct __add_rvalue_reference_impl {
30 typedef _LIBCPP_NODEBUG _Tp type;
30 using type _LIBCPP_NODEBUG = _Tp;
3131};
3232template <class _Tp >
3333struct __add_rvalue_reference_impl<_Tp, true> {
34 typedef _LIBCPP_NODEBUG _Tp&& type;
34 using type _LIBCPP_NODEBUG = _Tp&&;
3535};
3636
3737template <class _Tp>
......@@ -40,7 +40,7 @@ using __add_rvalue_reference_t = typename __add_rvalue_reference_impl<_Tp>::type
4040#endif // __has_builtin(__add_rvalue_reference)
4141
4242template <class _Tp>
43struct add_rvalue_reference {
43struct _LIBCPP_NO_SPECIALIZATIONS add_rvalue_reference {
4444 using type = __add_rvalue_reference_t<_Tp>;
4545};
4646
lib/libcxx/include/__type_traits/add_volatile.h deleted-32
......@@ -1,32 +0,0 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_ADD_VOLATILE_H
10#define _LIBCPP___TYPE_TRAITS_ADD_VOLATILE_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20template <class _Tp>
21struct _LIBCPP_TEMPLATE_VIS add_volatile {
22 typedef _LIBCPP_NODEBUG volatile _Tp type;
23};
24
25#if _LIBCPP_STD_VER >= 14
26template <class _Tp>
27using add_volatile_t = typename add_volatile<_Tp>::type;
28#endif
29
30_LIBCPP_END_NAMESPACE_STD
31
32#endif // _LIBCPP___TYPE_TRAITS_ADD_VOLATILE_H
lib/libcxx/include/__type_traits/aligned_storage.h+21-71
......@@ -10,11 +10,9 @@
1010#define _LIBCPP___TYPE_TRAITS_ALIGNED_STORAGE_H
1111
1212#include <__config>
13#include <__type_traits/conditional.h>
13#include <__cstddef/size_t.h>
1414#include <__type_traits/integral_constant.h>
15#include <__type_traits/nat.h>
1615#include <__type_traits/type_list.h>
17#include <cstddef>
1816
1917#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2018# pragma GCC system_header
......@@ -35,42 +33,23 @@ struct __struct_double4 {
3533 double __lx[4];
3634};
3735
38// clang-format off
39typedef __type_list<__align_type<unsigned char>,
40 __type_list<__align_type<unsigned short>,
41 __type_list<__align_type<unsigned int>,
42 __type_list<__align_type<unsigned long>,
43 __type_list<__align_type<unsigned long long>,
44 __type_list<__align_type<double>,
45 __type_list<__align_type<long double>,
46 __type_list<__align_type<__struct_double>,
47 __type_list<__align_type<__struct_double4>,
48 __type_list<__align_type<int*>,
49 __nat
50 > > > > > > > > > > __all_types;
51// clang-format on
52
53template <size_t _Align>
54struct _ALIGNAS(_Align) __fallback_overaligned {};
55
56template <class _TL, size_t _Align>
57struct __find_pod;
58
59template <class _Hp, size_t _Align>
60struct __find_pod<__type_list<_Hp, __nat>, _Align> {
61 typedef __conditional_t<_Align == _Hp::value, typename _Hp::type, __fallback_overaligned<_Align> > type;
62};
63
64template <class _Hp, class _Tp, size_t _Align>
65struct __find_pod<__type_list<_Hp, _Tp>, _Align> {
66 typedef __conditional_t<_Align == _Hp::value, typename _Hp::type, typename __find_pod<_Tp, _Align>::type> type;
67};
36using __all_types _LIBCPP_NODEBUG =
37 __type_list<__align_type<unsigned char>,
38 __align_type<unsigned short>,
39 __align_type<unsigned int>,
40 __align_type<unsigned long>,
41 __align_type<unsigned long long>,
42 __align_type<double>,
43 __align_type<long double>,
44 __align_type<__struct_double>,
45 __align_type<__struct_double4>,
46 __align_type<int*> >;
6847
6948template <class _TL, size_t _Len>
7049struct __find_max_align;
7150
72template <class _Hp, size_t _Len>
73struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};
51template <class _Head, size_t _Len>
52struct __find_max_align<__type_list<_Head>, _Len> : public integral_constant<size_t, _Head::value> {};
7453
7554template <size_t _Len, size_t _A1, size_t _A2>
7655struct __select_align {
......@@ -82,15 +61,15 @@ public:
8261 static const size_t value = _Len < __max ? __min : __max;
8362};
8463
85template <class _Hp, class _Tp, size_t _Len>
86struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
87 : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
64template <class _Head, class... _Tail, size_t _Len>
65struct __find_max_align<__type_list<_Head, _Tail...>, _Len>
66 : public integral_constant<
67 size_t,
68 __select_align<_Len, _Head::value, __find_max_align<__type_list<_Tail...>, _Len>::value>::value> {};
8869
8970template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
90struct _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_TEMPLATE_VIS aligned_storage {
91 typedef typename __find_pod<__all_types, _Align>::type _Aligner;
92 union type {
93 _Aligner __align;
71struct _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS aligned_storage {
72 union _ALIGNAS(_Align) type {
9473 unsigned char __data[(_Len + _Align - 1) / _Align * _Align];
9574 };
9675};
......@@ -104,35 +83,6 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
10483
10584#endif
10685
107#define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
108 template <size_t _Len> \
109 struct _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_TEMPLATE_VIS aligned_storage<_Len, n> { \
110 struct _ALIGNAS(n) type { \
111 unsigned char __lx[(_Len + n - 1) / n * n]; \
112 }; \
113 }
114
115_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1);
116_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2);
117_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4);
118_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8);
119_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10);
120_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20);
121_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40);
122_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80);
123_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100);
124_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200);
125_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400);
126_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
127_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
128_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
129// PE/COFF does not support alignment beyond 8192 (=0x2000)
130#if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
131_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
132#endif // !defined(_LIBCPP_OBJECT_FORMAT_COFF)
133
134#undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
135
13686_LIBCPP_END_NAMESPACE_STD
13787
13888#endif // _LIBCPP___TYPE_TRAITS_ALIGNED_STORAGE_H
lib/libcxx/include/__type_traits/aligned_union.h+2-3
......@@ -10,9 +10,8 @@
1010#define _LIBCPP___TYPE_TRAITS_ALIGNED_UNION_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__type_traits/aligned_storage.h>
14#include <__type_traits/integral_constant.h>
15#include <cstddef>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1817# pragma GCC system_header
......@@ -34,7 +33,7 @@ struct __static_max<_I0, _I1, _In...> {
3433};
3534
3635template <size_t _Len, class _Type0, class... _Types>
37struct _LIBCPP_DEPRECATED_IN_CXX23 aligned_union {
36struct _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_NO_SPECIALIZATIONS aligned_union {
3837 static const size_t alignment_value =
3938 __static_max<_LIBCPP_PREFERRED_ALIGNOF(_Type0), _LIBCPP_PREFERRED_ALIGNOF(_Types)...>::value;
4039 static const size_t __len = __static_max<_Len, sizeof(_Type0), sizeof(_Types)...>::value;
lib/libcxx/include/__type_traits/alignment_of.h+4-3
......@@ -10,8 +10,8 @@
1010#define _LIBCPP___TYPE_TRAITS_ALIGNMENT_OF_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__type_traits/integral_constant.h>
14#include <cstddef>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717# pragma GCC system_header
......@@ -20,11 +20,12 @@
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
2222template <class _Tp>
23struct _LIBCPP_TEMPLATE_VIS alignment_of : public integral_constant<size_t, _LIBCPP_ALIGNOF(_Tp)> {};
23struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS alignment_of
24 : public integral_constant<size_t, _LIBCPP_ALIGNOF(_Tp)> {};
2425
2526#if _LIBCPP_STD_VER >= 17
2627template <class _Tp>
27inline constexpr size_t alignment_of_v = _LIBCPP_ALIGNOF(_Tp);
28_LIBCPP_NO_SPECIALIZATIONS inline constexpr size_t alignment_of_v = _LIBCPP_ALIGNOF(_Tp);
2829#endif
2930
3031_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/common_reference.h+10-11
......@@ -15,7 +15,6 @@
1515#include <__type_traits/copy_cvref.h>
1616#include <__type_traits/is_convertible.h>
1717#include <__type_traits/is_reference.h>
18#include <__type_traits/remove_cv.h>
1918#include <__type_traits/remove_cvref.h>
2019#include <__type_traits/remove_reference.h>
2120#include <__utility/declval.h>
......@@ -30,7 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3029#if _LIBCPP_STD_VER >= 20
3130// Let COND_RES(X, Y) be:
3231template <class _Xp, class _Yp>
33using __cond_res = decltype(false ? std::declval<_Xp (&)()>()() : std::declval<_Yp (&)()>()());
32using __cond_res _LIBCPP_NODEBUG = decltype(false ? std::declval<_Xp (&)()>()() : std::declval<_Yp (&)()>()());
3433
3534// Let `XREF(A)` denote a unary alias template `T` such that `T<U>` denotes the same type as `U`
3635// with the addition of `A`'s cv and reference qualifiers, for a non-reference cv-unqualified type
......@@ -39,7 +38,7 @@ using __cond_res = decltype(false ? std::declval<_Xp (&)()>()() : std::declval<_
3938template <class _Tp>
4039struct __xref {
4140 template <class _Up>
42 using __apply = __copy_cvref_t<_Tp, _Up>;
41 using __apply _LIBCPP_NODEBUG = __copy_cvref_t<_Tp, _Up>;
4342};
4443
4544// Given types A and B, let X be remove_reference_t<A>, let Y be remove_reference_t<B>,
......@@ -48,10 +47,10 @@ template <class _Ap, class _Bp, class _Xp = remove_reference_t<_Ap>, class _Yp =
4847struct __common_ref;
4948
5049template <class _Xp, class _Yp>
51using __common_ref_t = typename __common_ref<_Xp, _Yp>::__type;
50using __common_ref_t _LIBCPP_NODEBUG = typename __common_ref<_Xp, _Yp>::__type;
5251
5352template <class _Xp, class _Yp>
54using __cv_cond_res = __cond_res<__copy_cv_t<_Xp, _Yp>&, __copy_cv_t<_Yp, _Xp>&>;
53using __cv_cond_res _LIBCPP_NODEBUG = __cond_res<__copy_cv_t<_Xp, _Yp>&, __copy_cv_t<_Yp, _Xp>&>;
5554
5655// If A and B are both lvalue reference types, COMMON-REF(A, B) is
5756// COND-RES(COPYCV(X, Y)&, COPYCV(Y, X)&) if that type exists and is a reference type.
......@@ -61,13 +60,13 @@ template <class _Ap, class _Bp, class _Xp, class _Yp>
6160 requires { typename __cv_cond_res<_Xp, _Yp>; } &&
6261 is_reference_v<__cv_cond_res<_Xp, _Yp>>
6362struct __common_ref<_Ap&, _Bp&, _Xp, _Yp> {
64 using __type = __cv_cond_res<_Xp, _Yp>;
63 using __type _LIBCPP_NODEBUG = __cv_cond_res<_Xp, _Yp>;
6564};
6665// clang-format on
6766
6867// Otherwise, let C be remove_reference_t<COMMON-REF(X&, Y&)>&&. ...
6968template <class _Xp, class _Yp>
70using __common_ref_C = remove_reference_t<__common_ref_t<_Xp&, _Yp&>>&&;
69using __common_ref_C _LIBCPP_NODEBUG = remove_reference_t<__common_ref_t<_Xp&, _Yp&>>&&;
7170
7271// .... If A and B are both rvalue reference types, C is well-formed, and
7372// is_convertible_v<A, C> && is_convertible_v<B, C> is true, then COMMON-REF(A, B) is C.
......@@ -78,13 +77,13 @@ template <class _Ap, class _Bp, class _Xp, class _Yp>
7877 is_convertible_v<_Ap&&, __common_ref_C<_Xp, _Yp>> &&
7978 is_convertible_v<_Bp&&, __common_ref_C<_Xp, _Yp>>
8079struct __common_ref<_Ap&&, _Bp&&, _Xp, _Yp> {
81 using __type = __common_ref_C<_Xp, _Yp>;
80 using __type _LIBCPP_NODEBUG = __common_ref_C<_Xp, _Yp>;
8281};
8382// clang-format on
8483
8584// Otherwise, let D be COMMON-REF(const X&, Y&). ...
8685template <class _Tp, class _Up>
87using __common_ref_D = __common_ref_t<const _Tp&, _Up&>;
86using __common_ref_D _LIBCPP_NODEBUG = __common_ref_t<const _Tp&, _Up&>;
8887
8988// ... If A is an rvalue reference and B is an lvalue reference and D is well-formed and
9089// is_convertible_v<A, D> is true, then COMMON-REF(A, B) is D.
......@@ -94,7 +93,7 @@ template <class _Ap, class _Bp, class _Xp, class _Yp>
9493 requires { typename __common_ref_D<_Xp, _Yp>; } &&
9594 is_convertible_v<_Ap&&, __common_ref_D<_Xp, _Yp>>
9695struct __common_ref<_Ap&&, _Bp&, _Xp, _Yp> {
97 using __type = __common_ref_D<_Xp, _Yp>;
96 using __type _LIBCPP_NODEBUG = __common_ref_D<_Xp, _Yp>;
9897};
9998// clang-format on
10099
......@@ -150,7 +149,7 @@ template <class, class, template <class> class, template <class> class>
150149struct basic_common_reference {};
151150
152151template <class _Tp, class _Up>
153using __basic_common_reference_t =
152using __basic_common_reference_t _LIBCPP_NODEBUG =
154153 typename basic_common_reference<remove_cvref_t<_Tp>,
155154 remove_cvref_t<_Up>,
156155 __xref<_Tp>::template __apply,
lib/libcxx/include/__type_traits/common_type.h+21-5
......@@ -14,8 +14,10 @@
1414#include <__type_traits/decay.h>
1515#include <__type_traits/is_same.h>
1616#include <__type_traits/remove_cvref.h>
17#include <__type_traits/type_identity.h>
1718#include <__type_traits/void_t.h>
1819#include <__utility/declval.h>
20#include <__utility/empty.h>
1921
2022#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2123# pragma GCC system_header
......@@ -23,10 +25,22 @@
2325
2426_LIBCPP_BEGIN_NAMESPACE_STD
2527
26#if _LIBCPP_STD_VER >= 20
28#if __has_builtin(__builtin_common_type)
29
30template <class... _Args>
31struct common_type;
32
33template <class... _Args>
34using __common_type_t _LIBCPP_NODEBUG = typename common_type<_Args...>::type;
35
36template <class... _Args>
37struct common_type : __builtin_common_type<__common_type_t, __type_identity, __empty, _Args...> {};
38
39#else
40# if _LIBCPP_STD_VER >= 20
2741// Let COND_RES(X, Y) be:
2842template <class _Tp, class _Up>
29using __cond_type = decltype(false ? std::declval<_Tp>() : std::declval<_Up>());
43using __cond_type _LIBCPP_NODEBUG = decltype(false ? std::declval<_Tp>() : std::declval<_Up>());
3044
3145template <class _Tp, class _Up, class = void>
3246struct __common_type3 {};
......@@ -39,15 +53,15 @@ struct __common_type3<_Tp, _Up, void_t<__cond_type<const _Tp&, const _Up&>>> {
3953
4054template <class _Tp, class _Up, class = void>
4155struct __common_type2_imp : __common_type3<_Tp, _Up> {};
42#else
56# else
4357template <class _Tp, class _Up, class = void>
4458struct __common_type2_imp {};
45#endif
59# endif
4660
4761// sub-bullet 3 - "if decay_t<decltype(false ? declval<D1>() : declval<D2>())> ..."
4862template <class _Tp, class _Up>
4963struct __common_type2_imp<_Tp, _Up, __void_t<decltype(true ? std::declval<_Tp>() : std::declval<_Up>())> > {
50 typedef _LIBCPP_NODEBUG __decay_t<decltype(true ? std::declval<_Tp>() : std::declval<_Up>())> type;
64 using type _LIBCPP_NODEBUG = __decay_t<decltype(true ? std::declval<_Tp>() : std::declval<_Up>())>;
5165};
5266
5367template <class, class = void>
......@@ -92,6 +106,8 @@ template <class _Tp, class _Up, class _Vp, class... _Rest>
92106struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up, _Vp, _Rest...>
93107 : __common_type_impl<__common_types<_Tp, _Up, _Vp, _Rest...> > {};
94108
109#endif
110
95111#if _LIBCPP_STD_VER >= 14
96112template <class... _Tp>
97113using common_type_t = typename common_type<_Tp...>::type;
lib/libcxx/include/__type_traits/conditional.h+7-1
......@@ -36,13 +36,19 @@ template <bool _Cond, class _IfRes, class _ElseRes>
3636using _If _LIBCPP_NODEBUG = typename _IfImpl<_Cond>::template _Select<_IfRes, _ElseRes>;
3737
3838template <bool _Bp, class _If, class _Then>
39struct _LIBCPP_TEMPLATE_VIS conditional {
39struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS conditional {
4040 using type _LIBCPP_NODEBUG = _If;
4141};
42
43_LIBCPP_DIAGNOSTIC_PUSH
44#if __has_warning("-Winvalid-specialization")
45_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
46#endif
4247template <class _If, class _Then>
4348struct _LIBCPP_TEMPLATE_VIS conditional<false, _If, _Then> {
4449 using type _LIBCPP_NODEBUG = _Then;
4550};
51_LIBCPP_DIAGNOSTIC_POP
4652
4753#if _LIBCPP_STD_VER >= 14
4854template <bool _Bp, class _IfRes, class _ElseRes>
lib/libcxx/include/__type_traits/conjunction.h+8-3
......@@ -22,7 +22,7 @@
2222_LIBCPP_BEGIN_NAMESPACE_STD
2323
2424template <class...>
25using __expand_to_true = true_type;
25using __expand_to_true _LIBCPP_NODEBUG = true_type;
2626
2727template <class... _Pred>
2828__expand_to_true<__enable_if_t<_Pred::value>...> __and_helper(int);
......@@ -47,16 +47,21 @@ struct __all : _IsSame<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)...
4747#if _LIBCPP_STD_VER >= 17
4848
4949template <class...>
50struct conjunction : true_type {};
50struct _LIBCPP_NO_SPECIALIZATIONS conjunction : true_type {};
5151
52_LIBCPP_DIAGNOSTIC_PUSH
53# if __has_warning("-Winvalid-specialization")
54_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
55# endif
5256template <class _Arg>
5357struct conjunction<_Arg> : _Arg {};
5458
5559template <class _Arg, class... _Args>
5660struct conjunction<_Arg, _Args...> : conditional_t<!bool(_Arg::value), _Arg, conjunction<_Args...>> {};
61_LIBCPP_DIAGNOSTIC_POP
5762
5863template <class... _Args>
59inline constexpr bool conjunction_v = conjunction<_Args...>::value;
64_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool conjunction_v = conjunction<_Args...>::value;
6065
6166#endif // _LIBCPP_STD_VER >= 17
6267
lib/libcxx/include/__type_traits/container_traits.h created+43
......@@ -0,0 +1,43 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___TYPE_TRAITS_CONTAINER_TRAITS_H
11#define _LIBCPP___TYPE_TRAITS_CONTAINER_TRAITS_H
12
13#include <__config>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21// // __container_traits is a general purpose utility containing traits describing various containers operations.
22// It currently only has one trait: `__emplacement_has_strong_exception_safety_guarantee`, but it's
23// intended to be extended in the future.
24//
25// These traits should only be used for optimization or QoI purposes. In particular, since this is a libc++ internal
26// mechanism, no user-defined containers should be expected to specialize these traits (in fact it would be illegal for
27// them to do so). Hence, when using these traits to implement something, make sure that a container that fails to
28// specialize these traits does not result in non-conforming code.
29//
30// When a trait is nonsensical for a type, this class still provides a fallback value for that trait.
31// For example, `std::array` does not support `insert` or `emplace`, so
32// `__emplacement_has_strong_exception_safety_guarantee` is false for such types.
33template <class _Container>
34struct __container_traits {
35 // A trait that tells whether a single element insertion/emplacement via member function
36 // `insert(...)` or `emplace(...)` has strong exception guarantee, that is, if the function
37 // exits via an exception, the original container is unaffected
38 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = false;
39};
40
41_LIBCPP_END_NAMESPACE_STD
42
43#endif // _LIBCPP___TYPE_TRAITS_CONTAINER_TRAITS_H
lib/libcxx/include/__type_traits/copy_cv.h+5-5
......@@ -22,29 +22,29 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222template <class _From>
2323struct __copy_cv {
2424 template <class _To>
25 using __apply = _To;
25 using __apply _LIBCPP_NODEBUG = _To;
2626};
2727
2828template <class _From>
2929struct __copy_cv<const _From> {
3030 template <class _To>
31 using __apply = const _To;
31 using __apply _LIBCPP_NODEBUG = const _To;
3232};
3333
3434template <class _From>
3535struct __copy_cv<volatile _From> {
3636 template <class _To>
37 using __apply = volatile _To;
37 using __apply _LIBCPP_NODEBUG = volatile _To;
3838};
3939
4040template <class _From>
4141struct __copy_cv<const volatile _From> {
4242 template <class _To>
43 using __apply = const volatile _To;
43 using __apply _LIBCPP_NODEBUG = const volatile _To;
4444};
4545
4646template <class _From, class _To>
47using __copy_cv_t = typename __copy_cv<_From>::template __apply<_To>;
47using __copy_cv_t _LIBCPP_NODEBUG = typename __copy_cv<_From>::template __apply<_To>;
4848
4949_LIBCPP_END_NAMESPACE_STD
5050
lib/libcxx/include/__type_traits/copy_cvref.h+12-9
......@@ -20,23 +20,26 @@
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23template <class _From, class _To>
23template <class _From>
2424struct __copy_cvref {
25 using type = __copy_cv_t<_From, _To>;
25 template <class _To>
26 using __apply _LIBCPP_NODEBUG = __copy_cv_t<_From, _To>;
2627};
2728
28template <class _From, class _To>
29struct __copy_cvref<_From&, _To> {
30 using type = __add_lvalue_reference_t<__copy_cv_t<_From, _To> >;
29template <class _From>
30struct __copy_cvref<_From&> {
31 template <class _To>
32 using __apply _LIBCPP_NODEBUG = __add_lvalue_reference_t<__copy_cv_t<_From, _To> >;
3133};
3234
33template <class _From, class _To>
34struct __copy_cvref<_From&&, _To> {
35 using type = __add_rvalue_reference_t<__copy_cv_t<_From, _To> >;
35template <class _From>
36struct __copy_cvref<_From&&> {
37 template <class _To>
38 using __apply _LIBCPP_NODEBUG = __add_rvalue_reference_t<__copy_cv_t<_From, _To> >;
3639};
3740
3841template <class _From, class _To>
39using __copy_cvref_t = typename __copy_cvref<_From, _To>::type;
42using __copy_cvref_t _LIBCPP_NODEBUG = typename __copy_cvref<_From>::template __apply<_To>;
4043
4144_LIBCPP_END_NAMESPACE_STD
4245
lib/libcxx/include/__type_traits/datasizeof.h+8-23
......@@ -10,9 +10,7 @@
1010#define _LIBCPP___TYPE_TRAITS_DATASIZEOF_H
1111
1212#include <__config>
13#include <__type_traits/is_class.h>
14#include <__type_traits/is_final.h>
15#include <cstddef>
13#include <__cstddef/size_t.h>
1614
1715#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1816# pragma GCC system_header
......@@ -26,39 +24,26 @@
2624
2725_LIBCPP_BEGIN_NAMESPACE_STD
2826
29#if __has_keyword(__datasizeof) || __has_extension(datasizeof)
27// TODO: Enable this again once #94816 is fixed.
28#if (__has_keyword(__datasizeof) || __has_extension(datasizeof)) && 0
3029template <class _Tp>
3130inline const size_t __datasizeof_v = __datasizeof(_Tp);
3231#else
33// NOLINTNEXTLINE(readability-redundant-preprocessor) This is https://llvm.org/PR64825
34# if __has_cpp_attribute(__no_unique_address__)
3532template <class _Tp>
3633struct _FirstPaddingByte {
37 [[__no_unique_address__]] _Tp __v_;
34 _LIBCPP_NO_UNIQUE_ADDRESS _Tp __v_;
3835 char __first_padding_byte_;
3936};
40# else
41template <class _Tp, bool = __libcpp_is_final<_Tp>::value || !is_class<_Tp>::value>
42struct _FirstPaddingByte : _Tp {
43 char __first_padding_byte_;
44};
45
46template <class _Tp>
47struct _FirstPaddingByte<_Tp, true> {
48 _Tp __v_;
49 char __first_padding_byte_;
50};
51# endif // __has_cpp_attribute(__no_unique_address__)
5237
53// _FirstPaddingByte<> is sometimes non-standard layout. Using `offsetof` is UB in that case, but GCC and Clang allow
54// the use as an extension.
38// _FirstPaddingByte<> is sometimes non-standard layout.
39// It is conditionally-supported to use __builtin_offsetof in that case, but GCC and Clang allow it.
5540_LIBCPP_DIAGNOSTIC_PUSH
5641_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-offsetof")
5742_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Winvalid-offsetof")
5843template <class _Tp>
59inline const size_t __datasizeof_v = offsetof(_FirstPaddingByte<_Tp>, __first_padding_byte_);
44inline const size_t __datasizeof_v = __builtin_offsetof(_FirstPaddingByte<_Tp>, __first_padding_byte_);
6045_LIBCPP_DIAGNOSTIC_POP
61#endif // __has_extension(datasizeof)
46#endif // __has_extension(datasizeof)
6247
6348_LIBCPP_END_NAMESPACE_STD
6449
lib/libcxx/include/__type_traits/decay.h+6-7
......@@ -30,33 +30,32 @@ template <class _Tp>
3030using __decay_t _LIBCPP_NODEBUG = __decay(_Tp);
3131
3232template <class _Tp>
33struct decay {
33struct _LIBCPP_NO_SPECIALIZATIONS decay {
3434 using type _LIBCPP_NODEBUG = __decay_t<_Tp>;
3535};
3636
3737#else
3838template <class _Up, bool>
3939struct __decay {
40 typedef _LIBCPP_NODEBUG __remove_cv_t<_Up> type;
40 using type _LIBCPP_NODEBUG = __remove_cv_t<_Up>;
4141};
4242
4343template <class _Up>
4444struct __decay<_Up, true> {
4545public:
46 typedef _LIBCPP_NODEBUG
46 using type _LIBCPP_NODEBUG =
4747 __conditional_t<is_array<_Up>::value,
4848 __add_pointer_t<__remove_extent_t<_Up> >,
49 __conditional_t<is_function<_Up>::value, typename add_pointer<_Up>::type, __remove_cv_t<_Up> > >
50 type;
49 __conditional_t<is_function<_Up>::value, typename add_pointer<_Up>::type, __remove_cv_t<_Up> > >;
5150};
5251
5352template <class _Tp>
5453struct _LIBCPP_TEMPLATE_VIS decay {
5554private:
56 typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tp> _Up;
55 using _Up _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tp>;
5756
5857public:
59 typedef _LIBCPP_NODEBUG typename __decay<_Up, __libcpp_is_referenceable<_Up>::value>::type type;
58 using type _LIBCPP_NODEBUG = typename __decay<_Up, __libcpp_is_referenceable<_Up>::value>::type;
6059};
6160
6261template <class _Tp>
lib/libcxx/include/__type_traits/desugars_to.h+18-1
......@@ -17,11 +17,28 @@
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
1919
20// Tags to represent the canonical operations
20// Tags to represent the canonical operations.
21
22// syntactically, the operation is equivalent to calling `a == b`
2123struct __equal_tag {};
24
25// syntactically, the operation is equivalent to calling `a + b`
2226struct __plus_tag {};
27
28// syntactically, the operation is equivalent to calling `a < b`
2329struct __less_tag {};
2430
31// syntactically, the operation is equivalent to calling `a > b`
32struct __greater_tag {};
33
34// syntactically, the operation is equivalent to calling `a < b`, and these expressions
35// have to be true for any `a` and `b`:
36// - `(a < b) == (b > a)`
37// - `(!(a < b) && !(b < a)) == (a == b)`
38// For example, this is satisfied for std::less on integral types, but also for ranges::less on all types due to
39// additional semantic requirements on that operation.
40struct __totally_ordered_less_tag {};
41
2542// This class template is used to determine whether an operation "desugars"
2643// (or boils down) to a given canonical operation.
2744//
lib/libcxx/include/__type_traits/detected_or.h created+36
......@@ -0,0 +1,36 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_DETECTED_OR_H
10#define _LIBCPP___TYPE_TRAITS_DETECTED_OR_H
11
12#include <__config>
13#include <__type_traits/void_t.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Default, class _Void, template <class...> class _Op, class... _Args>
22struct __detector {
23 using type _LIBCPP_NODEBUG = _Default;
24};
25
26template <class _Default, template <class...> class _Op, class... _Args>
27struct __detector<_Default, __void_t<_Op<_Args...> >, _Op, _Args...> {
28 using type _LIBCPP_NODEBUG = _Op<_Args...>;
29};
30
31template <class _Default, template <class...> class _Op, class... _Args>
32using __detected_or_t _LIBCPP_NODEBUG = typename __detector<_Default, void, _Op, _Args...>::type;
33
34_LIBCPP_END_NAMESPACE_STD
35
36#endif // _LIBCPP___TYPE_TRAITS_DETECTED_OR_H
lib/libcxx/include/__type_traits/disjunction.h+3-3
......@@ -31,7 +31,7 @@ struct _OrImpl<true> {
3131template <>
3232struct _OrImpl<false> {
3333 template <class _Res, class...>
34 using _Result = _Res;
34 using _Result _LIBCPP_NODEBUG = _Res;
3535};
3636
3737// _Or always performs lazy evaluation of its arguments.
......@@ -46,10 +46,10 @@ using _Or _LIBCPP_NODEBUG = typename _OrImpl<sizeof...(_Args) != 0>::template _R
4646#if _LIBCPP_STD_VER >= 17
4747
4848template <class... _Args>
49struct disjunction : _Or<_Args...> {};
49struct _LIBCPP_NO_SPECIALIZATIONS disjunction : _Or<_Args...> {};
5050
5151template <class... _Args>
52inline constexpr bool disjunction_v = _Or<_Args...>::value;
52_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool disjunction_v = _Or<_Args...>::value;
5353
5454#endif // _LIBCPP_STD_VER >= 17
5555
lib/libcxx/include/__type_traits/enable_if.h+7-1
......@@ -18,11 +18,17 @@
1818_LIBCPP_BEGIN_NAMESPACE_STD
1919
2020template <bool, class _Tp = void>
21struct _LIBCPP_TEMPLATE_VIS enable_if {};
21struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS enable_if{};
22
23_LIBCPP_DIAGNOSTIC_PUSH
24#if __has_warning("-Winvalid-specialization")
25_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
26#endif
2227template <class _Tp>
2328struct _LIBCPP_TEMPLATE_VIS enable_if<true, _Tp> {
2429 typedef _Tp type;
2530};
31_LIBCPP_DIAGNOSTIC_POP
2632
2733template <bool _Bp, class _Tp = void>
2834using __enable_if_t _LIBCPP_NODEBUG = typename enable_if<_Bp, _Tp>::type;
lib/libcxx/include/__type_traits/extent.h+3-3
......@@ -10,8 +10,8 @@
1010#define _LIBCPP___TYPE_TRAITS_EXTENT_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__type_traits/integral_constant.h>
14#include <cstddef>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717# pragma GCC system_header
......@@ -22,11 +22,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#if __has_builtin(__array_extent)
2323
2424template <class _Tp, size_t _Dim = 0>
25struct _LIBCPP_TEMPLATE_VIS extent : integral_constant<size_t, __array_extent(_Tp, _Dim)> {};
25struct _LIBCPP_NO_SPECIALIZATIONS _LIBCPP_TEMPLATE_VIS extent : integral_constant<size_t, __array_extent(_Tp, _Dim)> {};
2626
2727# if _LIBCPP_STD_VER >= 17
2828template <class _Tp, unsigned _Ip = 0>
29inline constexpr size_t extent_v = __array_extent(_Tp, _Ip);
29_LIBCPP_NO_SPECIALIZATIONS inline constexpr size_t extent_v = __array_extent(_Tp, _Ip);
3030# endif
3131
3232#else // __has_builtin(__array_extent)
lib/libcxx/include/__type_traits/has_unique_object_representation.h+3-2
......@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#if _LIBCPP_STD_VER >= 17
2323
2424template <class _Tp>
25struct _LIBCPP_TEMPLATE_VIS has_unique_object_representations
25struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS has_unique_object_representations
2626 // TODO: We work around a Clang and GCC bug in __has_unique_object_representations by using remove_all_extents
2727 // even though it should not be necessary. This was reported to the compilers:
2828 // - Clang: https://github.com/llvm/llvm-project/issues/95311
......@@ -31,7 +31,8 @@ struct _LIBCPP_TEMPLATE_VIS has_unique_object_representations
3131 : public integral_constant<bool, __has_unique_object_representations(remove_all_extents_t<_Tp>)> {};
3232
3333template <class _Tp>
34inline constexpr bool has_unique_object_representations_v = __has_unique_object_representations(_Tp);
34_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool has_unique_object_representations_v =
35 __has_unique_object_representations(_Tp);
3536
3637#endif
3738
lib/libcxx/include/__type_traits/has_virtual_destructor.h+3-2
......@@ -19,11 +19,12 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor : public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS has_virtual_destructor
23 : public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
2324
2425#if _LIBCPP_STD_VER >= 17
2526template <class _Tp>
26inline constexpr bool has_virtual_destructor_v = __has_virtual_destructor(_Tp);
27_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool has_virtual_destructor_v = __has_virtual_destructor(_Tp);
2728#endif
2829
2930_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/integral_constant.h+2-5
......@@ -18,8 +18,8 @@
1818_LIBCPP_BEGIN_NAMESPACE_STD
1919
2020template <class _Tp, _Tp __v>
21struct _LIBCPP_TEMPLATE_VIS integral_constant {
22 static _LIBCPP_CONSTEXPR const _Tp value = __v;
21struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS integral_constant {
22 static inline _LIBCPP_CONSTEXPR const _Tp value = __v;
2323 typedef _Tp value_type;
2424 typedef integral_constant type;
2525 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR operator value_type() const _NOEXCEPT { return value; }
......@@ -28,9 +28,6 @@ struct _LIBCPP_TEMPLATE_VIS integral_constant {
2828#endif
2929};
3030
31template <class _Tp, _Tp __v>
32_LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp, __v>::value;
33
3431typedef integral_constant<bool, true> true_type;
3532typedef integral_constant<bool, false> false_type;
3633
lib/libcxx/include/__type_traits/invoke.h+75-25
......@@ -29,6 +29,36 @@
2929# pragma GCC system_header
3030#endif
3131
32// This file defines the following libc++-internal API (back-ported to C++03):
33//
34// template <class... Args>
35// decltype(auto) __invoke(Args&&... args) noexcept(noexcept(std::invoke(std::forward<Args>(args...)))) {
36// return std::invoke(std::forward<Args>(args)...);
37// }
38//
39// template <class Ret, class... Args>
40// Ret __invoke_r(Args&&... args) {
41// return std::invoke_r(std::forward<Args>(args)...);
42// }
43//
44// template <class Ret, class Func, class... Args>
45// inline const bool __is_invocable_r_v = is_invocable_r_v<Ret, Func, Args...>;
46//
47// template <class Func, class... Args>
48// struct __is_invocable : is_invocable<Func, Args...> {};
49//
50// template <class Func, class... Args>
51// inline const bool __is_invocable_v = is_invocable_v<Func, Args...>;
52//
53// template <class Func, class... Args>
54// inline const bool __is_nothrow_invocable_v = is_nothrow_invocable_v<Func, Args...>;
55//
56// template <class Func, class... Args>
57// struct __invoke_result : invoke_result {};
58//
59// template <class Func, class... Args>
60// using __invoke_result_t = invoke_result_t<Func, Args...>;
61
3262_LIBCPP_BEGIN_NAMESPACE_STD
3363
3464template <class _DecayedFp>
......@@ -44,12 +74,12 @@ template <class _Fp,
4474 class _DecayFp = __decay_t<_Fp>,
4575 class _DecayA0 = __decay_t<_A0>,
4676 class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
47using __enable_if_bullet1 =
77using __enable_if_bullet1 _LIBCPP_NODEBUG =
4878 __enable_if_t<is_member_function_pointer<_DecayFp>::value &&
4979 (is_same<_ClassT, _DecayA0>::value || is_base_of<_ClassT, _DecayA0>::value)>;
5080
5181template <class _Fp, class _A0, class _DecayFp = __decay_t<_Fp>, class _DecayA0 = __decay_t<_A0> >
52using __enable_if_bullet2 =
82using __enable_if_bullet2 _LIBCPP_NODEBUG =
5383 __enable_if_t<is_member_function_pointer<_DecayFp>::value && __is_reference_wrapper<_DecayA0>::value>;
5484
5585template <class _Fp,
......@@ -57,7 +87,7 @@ template <class _Fp,
5787 class _DecayFp = __decay_t<_Fp>,
5888 class _DecayA0 = __decay_t<_A0>,
5989 class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
60using __enable_if_bullet3 =
90using __enable_if_bullet3 _LIBCPP_NODEBUG =
6191 __enable_if_t<is_member_function_pointer<_DecayFp>::value &&
6292 !(is_same<_ClassT, _DecayA0>::value || is_base_of<_ClassT, _DecayA0>::value) &&
6393 !__is_reference_wrapper<_DecayA0>::value>;
......@@ -67,12 +97,12 @@ template <class _Fp,
6797 class _DecayFp = __decay_t<_Fp>,
6898 class _DecayA0 = __decay_t<_A0>,
6999 class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
70using __enable_if_bullet4 =
100using __enable_if_bullet4 _LIBCPP_NODEBUG =
71101 __enable_if_t<is_member_object_pointer<_DecayFp>::value &&
72102 (is_same<_ClassT, _DecayA0>::value || is_base_of<_ClassT, _DecayA0>::value)>;
73103
74104template <class _Fp, class _A0, class _DecayFp = __decay_t<_Fp>, class _DecayA0 = __decay_t<_A0> >
75using __enable_if_bullet5 =
105using __enable_if_bullet5 _LIBCPP_NODEBUG =
76106 __enable_if_t<is_member_object_pointer<_DecayFp>::value && __is_reference_wrapper<_DecayA0>::value>;
77107
78108template <class _Fp,
......@@ -80,7 +110,7 @@ template <class _Fp,
80110 class _DecayFp = __decay_t<_Fp>,
81111 class _DecayA0 = __decay_t<_A0>,
82112 class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
83using __enable_if_bullet6 =
113using __enable_if_bullet6 _LIBCPP_NODEBUG =
84114 __enable_if_t<is_member_object_pointer<_DecayFp>::value &&
85115 !(is_same<_ClassT, _DecayA0>::value || is_base_of<_ClassT, _DecayA0>::value) &&
86116 !__is_reference_wrapper<_DecayA0>::value>;
......@@ -159,7 +189,7 @@ struct __invokable_r {
159189
160190 // FIXME: Check that _Ret, _Fp, and _Args... are all complete types, cv void,
161191 // or incomplete array types as required by the standard.
162 using _Result = decltype(__try_call<_Fp, _Args...>(0));
192 using _Result _LIBCPP_NODEBUG = decltype(__try_call<_Fp, _Args...>(0));
163193
164194 using type = __conditional_t<_IsNotSame<_Result, __nat>::value,
165195 __conditional_t<is_void<_Ret>::value, true_type, __is_core_convertible<_Result, _Ret> >,
......@@ -167,7 +197,7 @@ struct __invokable_r {
167197 static const bool value = type::value;
168198};
169199template <class _Fp, class... _Args>
170using __invokable = __invokable_r<void, _Fp, _Args...>;
200using __is_invocable _LIBCPP_NODEBUG = __invokable_r<void, _Fp, _Args...>;
171201
172202template <bool _IsInvokable, bool _IsCVVoid, class _Ret, class _Fp, class... _Args>
173203struct __nothrow_invokable_r_imp {
......@@ -199,15 +229,12 @@ struct __nothrow_invokable_r_imp<true, true, _Ret, _Fp, _Args...> {
199229};
200230
201231template <class _Ret, class _Fp, class... _Args>
202using __nothrow_invokable_r =
232using __nothrow_invokable_r _LIBCPP_NODEBUG =
203233 __nothrow_invokable_r_imp<__invokable_r<_Ret, _Fp, _Args...>::value, is_void<_Ret>::value, _Ret, _Fp, _Args...>;
204234
205235template <class _Fp, class... _Args>
206using __nothrow_invokable = __nothrow_invokable_r_imp<__invokable<_Fp, _Args...>::value, true, void, _Fp, _Args...>;
207
208template <class _Fp, class... _Args>
209struct __invoke_of
210 : public enable_if<__invokable<_Fp, _Args...>::value, typename __invokable_r<void, _Fp, _Args...>::_Result> {};
236using __nothrow_invokable _LIBCPP_NODEBUG =
237 __nothrow_invokable_r_imp<__is_invocable<_Fp, _Args...>::value, true, void, _Fp, _Args...>;
211238
212239template <class _Ret, bool = is_void<_Ret>::value>
213240struct __invoke_void_return_wrapper {
......@@ -225,40 +252,63 @@ struct __invoke_void_return_wrapper<_Ret, true> {
225252 }
226253};
227254
255template <class _Func, class... _Args>
256inline const bool __is_invocable_v = __is_invocable<_Func, _Args...>::value;
257
258template <class _Ret, class _Func, class... _Args>
259inline const bool __is_invocable_r_v = __invokable_r<_Ret, _Func, _Args...>::value;
260
261template <class _Func, class... _Args>
262inline const bool __is_nothrow_invocable_v = __nothrow_invokable<_Func, _Args...>::value;
263
264template <class _Func, class... _Args>
265struct __invoke_result
266 : enable_if<__is_invocable_v<_Func, _Args...>, typename __invokable_r<void, _Func, _Args...>::_Result> {};
267
268template <class _Func, class... _Args>
269using __invoke_result_t _LIBCPP_NODEBUG = typename __invoke_result<_Func, _Args...>::type;
270
271template <class _Ret, class... _Args>
272_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Ret __invoke_r(_Args&&... __args) {
273 return __invoke_void_return_wrapper<_Ret>::__call(std::forward<_Args>(__args)...);
274}
275
228276#if _LIBCPP_STD_VER >= 17
229277
230278// is_invocable
231279
232280template <class _Fn, class... _Args>
233struct _LIBCPP_TEMPLATE_VIS is_invocable : integral_constant<bool, __invokable<_Fn, _Args...>::value> {};
281struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_invocable : bool_constant<__is_invocable_v<_Fn, _Args...>> {};
234282
235283template <class _Ret, class _Fn, class... _Args>
236struct _LIBCPP_TEMPLATE_VIS is_invocable_r : integral_constant<bool, __invokable_r<_Ret, _Fn, _Args...>::value> {};
284struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_invocable_r
285 : bool_constant<__is_invocable_r_v<_Ret, _Fn, _Args...>> {};
237286
238287template <class _Fn, class... _Args>
239inline constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value;
288_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_invocable_v = __is_invocable_v<_Fn, _Args...>;
240289
241290template <class _Ret, class _Fn, class... _Args>
242inline constexpr bool is_invocable_r_v = is_invocable_r<_Ret, _Fn, _Args...>::value;
291_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_invocable_r_v = __is_invocable_r_v<_Ret, _Fn, _Args...>;
243292
244293// is_nothrow_invocable
245294
246295template <class _Fn, class... _Args>
247struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable : integral_constant<bool, __nothrow_invokable<_Fn, _Args...>::value> {
248};
296struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_invocable
297 : bool_constant<__nothrow_invokable<_Fn, _Args...>::value> {};
249298
250299template <class _Ret, class _Fn, class... _Args>
251struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable_r
252 : integral_constant<bool, __nothrow_invokable_r<_Ret, _Fn, _Args...>::value> {};
300struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_invocable_r
301 : bool_constant<__nothrow_invokable_r<_Ret, _Fn, _Args...>::value> {};
253302
254303template <class _Fn, class... _Args>
255inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<_Fn, _Args...>::value;
304_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<_Fn, _Args...>::value;
256305
257306template <class _Ret, class _Fn, class... _Args>
258inline constexpr bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
307_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_invocable_r_v =
308 is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
259309
260310template <class _Fn, class... _Args>
261struct _LIBCPP_TEMPLATE_VIS invoke_result : __invoke_of<_Fn, _Args...> {};
311struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS invoke_result : __invoke_result<_Fn, _Args...> {};
262312
263313template <class _Fn, class... _Args>
264314using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
lib/libcxx/include/__type_traits/is_abstract.h+3-2
......@@ -19,11 +19,12 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS is_abstract : public integral_constant<bool, __is_abstract(_Tp)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_abstract
23 : public integral_constant<bool, __is_abstract(_Tp)> {};
2324
2425#if _LIBCPP_STD_VER >= 17
2526template <class _Tp>
26inline constexpr bool is_abstract_v = __is_abstract(_Tp);
27_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_abstract_v = __is_abstract(_Tp);
2728#endif
2829
2930_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_aggregate.h+3-2
......@@ -21,10 +21,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121#if _LIBCPP_STD_VER >= 17
2222
2323template <class _Tp>
24struct _LIBCPP_TEMPLATE_VIS is_aggregate : public integral_constant<bool, __is_aggregate(_Tp)> {};
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_aggregate
25 : public integral_constant<bool, __is_aggregate(_Tp)> {};
2526
2627template <class _Tp>
27inline constexpr bool is_aggregate_v = __is_aggregate(_Tp);
28_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_aggregate_v = __is_aggregate(_Tp);
2829
2930#endif // _LIBCPP_STD_VER >= 17
3031
lib/libcxx/include/__type_traits/is_allocator.h+1-1
......@@ -10,10 +10,10 @@
1010#define _LIBCPP___TYPE_IS_ALLOCATOR_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__type_traits/integral_constant.h>
1415#include <__type_traits/void_t.h>
1516#include <__utility/declval.h>
16#include <cstddef>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1919# pragma GCC system_header
lib/libcxx/include/__type_traits/is_always_bitcastable.h+2-4
......@@ -10,9 +10,7 @@
1010#define _LIBCPP___TYPE_TRAITS_IS_ALWAYS_BITCASTABLE_H
1111
1212#include <__config>
13#include <__type_traits/integral_constant.h>
1413#include <__type_traits/is_integral.h>
15#include <__type_traits/is_object.h>
1614#include <__type_traits/is_same.h>
1715#include <__type_traits/is_trivially_copyable.h>
1816#include <__type_traits/remove_cv.h>
......@@ -31,8 +29,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3129// considered bit-castable.
3230template <class _From, class _To>
3331struct __is_always_bitcastable {
34 using _UnqualFrom = __remove_cv_t<_From>;
35 using _UnqualTo = __remove_cv_t<_To>;
32 using _UnqualFrom _LIBCPP_NODEBUG = __remove_cv_t<_From>;
33 using _UnqualTo _LIBCPP_NODEBUG = __remove_cv_t<_To>;
3634
3735 // clang-format off
3836 static const bool value =
lib/libcxx/include/__type_traits/is_arithmetic.h+2-2
......@@ -21,12 +21,12 @@
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
2323template <class _Tp>
24struct _LIBCPP_TEMPLATE_VIS is_arithmetic
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_arithmetic
2525 : public integral_constant<bool, is_integral<_Tp>::value || is_floating_point<_Tp>::value> {};
2626
2727#if _LIBCPP_STD_VER >= 17
2828template <class _Tp>
29inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value;
29_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value;
3030#endif
3131
3232_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_array.h+3-3
......@@ -10,8 +10,8 @@
1010#define _LIBCPP___TYPE_TRAITS_IS_ARRAY_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__type_traits/integral_constant.h>
14#include <cstddef>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717# pragma GCC system_header
......@@ -23,11 +23,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2323 (!defined(_LIBCPP_COMPILER_CLANG_BASED) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1900))
2424
2525template <class _Tp>
26struct _LIBCPP_TEMPLATE_VIS is_array : _BoolConstant<__is_array(_Tp)> {};
26struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_array : _BoolConstant<__is_array(_Tp)> {};
2727
2828# if _LIBCPP_STD_VER >= 17
2929template <class _Tp>
30inline constexpr bool is_array_v = __is_array(_Tp);
30_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_array_v = __is_array(_Tp);
3131# endif
3232
3333#else
lib/libcxx/include/__type_traits/is_assignable.h+6-6
......@@ -21,30 +21,30 @@
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
2323template <class _Tp, class _Up>
24struct _LIBCPP_TEMPLATE_VIS is_assignable : _BoolConstant<__is_assignable(_Tp, _Up)> {};
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_assignable : _BoolConstant<__is_assignable(_Tp, _Up)> {};
2525
2626#if _LIBCPP_STD_VER >= 17
2727template <class _Tp, class _Arg>
28inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Arg);
28_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Arg);
2929#endif
3030
3131template <class _Tp>
32struct _LIBCPP_TEMPLATE_VIS is_copy_assignable
32struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_copy_assignable
3333 : public integral_constant<bool,
3434 __is_assignable(__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<const _Tp>)> {};
3535
3636#if _LIBCPP_STD_VER >= 17
3737template <class _Tp>
38inline constexpr bool is_copy_assignable_v = is_copy_assignable<_Tp>::value;
38_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_copy_assignable_v = is_copy_assignable<_Tp>::value;
3939#endif
4040
4141template <class _Tp>
42struct _LIBCPP_TEMPLATE_VIS is_move_assignable
42struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_move_assignable
4343 : public integral_constant<bool, __is_assignable(__add_lvalue_reference_t<_Tp>, __add_rvalue_reference_t<_Tp>)> {};
4444
4545#if _LIBCPP_STD_VER >= 17
4646template <class _Tp>
47inline constexpr bool is_move_assignable_v = is_move_assignable<_Tp>::value;
47_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_move_assignable_v = is_move_assignable<_Tp>::value;
4848#endif
4949
5050_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_base_of.h+16-2
......@@ -19,11 +19,25 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Bp, class _Dp>
22struct _LIBCPP_TEMPLATE_VIS is_base_of : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_base_of
23 : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
2324
2425#if _LIBCPP_STD_VER >= 17
2526template <class _Bp, class _Dp>
26inline constexpr bool is_base_of_v = __is_base_of(_Bp, _Dp);
27_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_base_of_v = __is_base_of(_Bp, _Dp);
28#endif
29
30#if _LIBCPP_STD_VER >= 26
31# if __has_builtin(__builtin_is_virtual_base_of)
32
33template <class _Base, class _Derived>
34struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_virtual_base_of
35 : public bool_constant<__builtin_is_virtual_base_of(_Base, _Derived)> {};
36
37template <class _Base, class _Derived>
38_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_virtual_base_of_v = __builtin_is_virtual_base_of(_Base, _Derived);
39
40# endif
2741#endif
2842
2943_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_bounded_array.h+11-5
......@@ -10,8 +10,8 @@
1010#define _LIBCPP___TYPE_TRAITS_IS_BOUNDED_ARRAY_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__type_traits/integral_constant.h>
14#include <cstddef>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717# pragma GCC system_header
......@@ -20,19 +20,25 @@
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
2222template <class>
23struct _LIBCPP_TEMPLATE_VIS __libcpp_is_bounded_array : false_type {};
23inline const bool __is_bounded_array_v = false;
2424template <class _Tp, size_t _Np>
25struct _LIBCPP_TEMPLATE_VIS __libcpp_is_bounded_array<_Tp[_Np]> : true_type {};
25inline const bool __is_bounded_array_v<_Tp[_Np]> = true;
2626
2727#if _LIBCPP_STD_VER >= 20
2828
2929template <class>
30struct _LIBCPP_TEMPLATE_VIS is_bounded_array : false_type {};
30struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_bounded_array : false_type {};
31
32_LIBCPP_DIAGNOSTIC_PUSH
33# if __has_warning("-Winvalid-specialization")
34_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
35# endif
3136template <class _Tp, size_t _Np>
3237struct _LIBCPP_TEMPLATE_VIS is_bounded_array<_Tp[_Np]> : true_type {};
38_LIBCPP_DIAGNOSTIC_POP
3339
3440template <class _Tp>
35inline constexpr bool is_bounded_array_v = is_bounded_array<_Tp>::value;
41_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_bounded_array_v = is_bounded_array<_Tp>::value;
3642
3743#endif
3844
lib/libcxx/include/__type_traits/is_char_like_type.h+1-1
......@@ -21,7 +21,7 @@
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
2323template <class _CharT>
24using _IsCharLikeType = _And<is_standard_layout<_CharT>, is_trivial<_CharT> >;
24using _IsCharLikeType _LIBCPP_NODEBUG = _And<is_standard_layout<_CharT>, is_trivial<_CharT> >;
2525
2626_LIBCPP_END_NAMESPACE_STD
2727
lib/libcxx/include/__type_traits/is_class.h+2-2
......@@ -19,11 +19,11 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS is_class : public integral_constant<bool, __is_class(_Tp)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_class : public integral_constant<bool, __is_class(_Tp)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
26inline constexpr bool is_class_v = __is_class(_Tp);
26_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_class_v = __is_class(_Tp);
2727#endif
2828
2929_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_compound.h+2-2
......@@ -22,11 +22,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#if __has_builtin(__is_compound)
2323
2424template <class _Tp>
25struct _LIBCPP_TEMPLATE_VIS is_compound : _BoolConstant<__is_compound(_Tp)> {};
25struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_compound : _BoolConstant<__is_compound(_Tp)> {};
2626
2727# if _LIBCPP_STD_VER >= 17
2828template <class _Tp>
29inline constexpr bool is_compound_v = __is_compound(_Tp);
29_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_compound_v = __is_compound(_Tp);
3030# endif
3131
3232#else // __has_builtin(__is_compound)
lib/libcxx/include/__type_traits/is_const.h+2-2
......@@ -21,11 +21,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121#if __has_builtin(__is_const)
2222
2323template <class _Tp>
24struct _LIBCPP_TEMPLATE_VIS is_const : _BoolConstant<__is_const(_Tp)> {};
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_const : _BoolConstant<__is_const(_Tp)> {};
2525
2626# if _LIBCPP_STD_VER >= 17
2727template <class _Tp>
28inline constexpr bool is_const_v = __is_const(_Tp);
28_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_const_v = __is_const(_Tp);
2929# endif
3030
3131#else
lib/libcxx/include/__type_traits/is_constructible.h+10-8
......@@ -21,37 +21,39 @@
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
2323template <class _Tp, class... _Args>
24struct _LIBCPP_TEMPLATE_VIS is_constructible : public integral_constant<bool, __is_constructible(_Tp, _Args...)> {};
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_constructible
25 : public integral_constant<bool, __is_constructible(_Tp, _Args...)> {};
2526
2627#if _LIBCPP_STD_VER >= 17
2728template <class _Tp, class... _Args>
28inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...);
29_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...);
2930#endif
3031
3132template <class _Tp>
32struct _LIBCPP_TEMPLATE_VIS is_copy_constructible
33struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_copy_constructible
3334 : public integral_constant<bool, __is_constructible(_Tp, __add_lvalue_reference_t<const _Tp>)> {};
3435
3536#if _LIBCPP_STD_VER >= 17
3637template <class _Tp>
37inline constexpr bool is_copy_constructible_v = is_copy_constructible<_Tp>::value;
38_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_copy_constructible_v = is_copy_constructible<_Tp>::value;
3839#endif
3940
4041template <class _Tp>
41struct _LIBCPP_TEMPLATE_VIS is_move_constructible
42struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_move_constructible
4243 : public integral_constant<bool, __is_constructible(_Tp, __add_rvalue_reference_t<_Tp>)> {};
4344
4445#if _LIBCPP_STD_VER >= 17
4546template <class _Tp>
46inline constexpr bool is_move_constructible_v = is_move_constructible<_Tp>::value;
47_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_move_constructible_v = is_move_constructible<_Tp>::value;
4748#endif
4849
4950template <class _Tp>
50struct _LIBCPP_TEMPLATE_VIS is_default_constructible : public integral_constant<bool, __is_constructible(_Tp)> {};
51struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_default_constructible
52 : public integral_constant<bool, __is_constructible(_Tp)> {};
5153
5254#if _LIBCPP_STD_VER >= 17
5355template <class _Tp>
54inline constexpr bool is_default_constructible_v = __is_constructible(_Tp);
56_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_default_constructible_v = __is_constructible(_Tp);
5557#endif
5658
5759_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_convertible.h+3-2
......@@ -19,11 +19,12 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _T1, class _T2>
22struct _LIBCPP_TEMPLATE_VIS is_convertible : public integral_constant<bool, __is_convertible(_T1, _T2)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_convertible
23 : public integral_constant<bool, __is_convertible(_T1, _T2)> {};
2324
2425#if _LIBCPP_STD_VER >= 17
2526template <class _From, class _To>
26inline constexpr bool is_convertible_v = __is_convertible(_From, _To);
27_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_convertible_v = __is_convertible(_From, _To);
2728#endif
2829
2930_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_destructible.h+2-2
......@@ -25,11 +25,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2525#if __has_builtin(__is_destructible)
2626
2727template <class _Tp>
28struct _LIBCPP_TEMPLATE_VIS is_destructible : _BoolConstant<__is_destructible(_Tp)> {};
28struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_destructible : _BoolConstant<__is_destructible(_Tp)> {};
2929
3030# if _LIBCPP_STD_VER >= 17
3131template <class _Tp>
32inline constexpr bool is_destructible_v = __is_destructible(_Tp);
32_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_destructible_v = __is_destructible(_Tp);
3333# endif
3434
3535#else // __has_builtin(__is_destructible)
lib/libcxx/include/__type_traits/is_empty.h+2-2
......@@ -19,11 +19,11 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS is_empty : public integral_constant<bool, __is_empty(_Tp)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_empty : public integral_constant<bool, __is_empty(_Tp)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
26inline constexpr bool is_empty_v = __is_empty(_Tp);
26_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_empty_v = __is_empty(_Tp);
2727#endif
2828
2929_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_enum.h+4-4
......@@ -19,20 +19,20 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS is_enum : public integral_constant<bool, __is_enum(_Tp)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_enum : public integral_constant<bool, __is_enum(_Tp)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
26inline constexpr bool is_enum_v = __is_enum(_Tp);
26_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_enum_v = __is_enum(_Tp);
2727#endif
2828
2929#if _LIBCPP_STD_VER >= 23
3030
3131template <class _Tp>
32struct _LIBCPP_TEMPLATE_VIS is_scoped_enum : bool_constant<__is_scoped_enum(_Tp)> {};
32struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_scoped_enum : bool_constant<__is_scoped_enum(_Tp)> {};
3333
3434template <class _Tp>
35inline constexpr bool is_scoped_enum_v = __is_scoped_enum(_Tp);
35_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_scoped_enum_v = __is_scoped_enum(_Tp);
3636
3737#endif // _LIBCPP_STD_VER >= 23
3838
lib/libcxx/include/__type_traits/is_equality_comparable.h+1-1
......@@ -80,7 +80,7 @@ struct __libcpp_is_trivially_equality_comparable_impl<_Tp*, _Up*>
8080};
8181
8282template <class _Tp, class _Up>
83using __libcpp_is_trivially_equality_comparable =
83using __libcpp_is_trivially_equality_comparable _LIBCPP_NODEBUG =
8484 __libcpp_is_trivially_equality_comparable_impl<__remove_cv_t<_Tp>, __remove_cv_t<_Up> >;
8585
8686_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_execution_policy.h+2-2
......@@ -21,7 +21,7 @@
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
2323template <class>
24inline constexpr bool is_execution_policy_v = false;
24_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_execution_policy_v = false;
2525
2626template <class>
2727inline constexpr bool __is_unsequenced_execution_policy_impl = false;
......@@ -50,7 +50,7 @@ __remove_parallel_policy(const _ExecutionPolicy& = _ExecutionPolicy{execution::_
5050// Removes the "parallel" part of an execution policy.
5151// For example, turns par_unseq into unseq, and par into seq.
5252template <class _ExecutionPolicy>
53using __remove_parallel_policy_t = decltype(std::__remove_parallel_policy<_ExecutionPolicy>());
53using __remove_parallel_policy_t _LIBCPP_NODEBUG = decltype(std::__remove_parallel_policy<_ExecutionPolicy>());
5454
5555_LIBCPP_END_NAMESPACE_STD
5656
lib/libcxx/include/__type_traits/is_final.h+2-2
......@@ -23,12 +23,12 @@ struct _LIBCPP_TEMPLATE_VIS __libcpp_is_final : public integral_constant<bool, _
2323
2424#if _LIBCPP_STD_VER >= 14
2525template <class _Tp>
26struct _LIBCPP_TEMPLATE_VIS is_final : public integral_constant<bool, __is_final(_Tp)> {};
26struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_final : public integral_constant<bool, __is_final(_Tp)> {};
2727#endif
2828
2929#if _LIBCPP_STD_VER >= 17
3030template <class _Tp>
31inline constexpr bool is_final_v = __is_final(_Tp);
31_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_final_v = __is_final(_Tp);
3232#endif
3333
3434_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_floating_point.h+3-2
......@@ -27,11 +27,12 @@ template <> struct __libcpp_is_floating_point<long double> : public tru
2727// clang-format on
2828
2929template <class _Tp>
30struct _LIBCPP_TEMPLATE_VIS is_floating_point : public __libcpp_is_floating_point<__remove_cv_t<_Tp> > {};
30struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_floating_point
31 : public __libcpp_is_floating_point<__remove_cv_t<_Tp> > {};
3132
3233#if _LIBCPP_STD_VER >= 17
3334template <class _Tp>
34inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
35_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
3536#endif
3637
3738_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_function.h+2-2
......@@ -19,11 +19,11 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS is_function : integral_constant<bool, __is_function(_Tp)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_function : integral_constant<bool, __is_function(_Tp)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
26inline constexpr bool is_function_v = __is_function(_Tp);
26_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_function_v = __is_function(_Tp);
2727#endif
2828
2929_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_fundamental.h+2-2
......@@ -23,11 +23,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2323#if __has_builtin(__is_fundamental)
2424
2525template <class _Tp>
26struct _LIBCPP_TEMPLATE_VIS is_fundamental : _BoolConstant<__is_fundamental(_Tp)> {};
26struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_fundamental : _BoolConstant<__is_fundamental(_Tp)> {};
2727
2828# if _LIBCPP_STD_VER >= 17
2929template <class _Tp>
30inline constexpr bool is_fundamental_v = __is_fundamental(_Tp);
30_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_fundamental_v = __is_fundamental(_Tp);
3131# endif
3232
3333#else // __has_builtin(__is_fundamental)
lib/libcxx/include/__type_traits/is_implicit_lifetime.h created+36
......@@ -0,0 +1,36 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_IMPLICIT_LIFETIME_H
10#define _LIBCPP___TYPE_TRAITS_IS_IMPLICIT_LIFETIME_H
11
12#include <__config>
13#include <__type_traits/integral_constant.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21#if _LIBCPP_STD_VER >= 23
22# if __has_builtin(__builtin_is_implicit_lifetime)
23
24template <class _Tp>
25struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_implicit_lifetime
26 : public bool_constant<__builtin_is_implicit_lifetime(_Tp)> {};
27
28template <class _Tp>
29_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_implicit_lifetime_v = __builtin_is_implicit_lifetime(_Tp);
30
31# endif
32#endif
33
34_LIBCPP_END_NAMESPACE_STD
35
36#endif // _LIBCPP___TYPE_TRAITS_IS_IMPLICIT_LIFETIME_H
lib/libcxx/include/__type_traits/is_integral.h+5-5
......@@ -25,10 +25,10 @@ template <> struct __libcpp_is_integral<bool> { enum { va
2525template <> struct __libcpp_is_integral<char> { enum { value = 1 }; };
2626template <> struct __libcpp_is_integral<signed char> { enum { value = 1 }; };
2727template <> struct __libcpp_is_integral<unsigned char> { enum { value = 1 }; };
28#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
28#if _LIBCPP_HAS_WIDE_CHARACTERS
2929template <> struct __libcpp_is_integral<wchar_t> { enum { value = 1 }; };
3030#endif
31#ifndef _LIBCPP_HAS_NO_CHAR8_T
31#if _LIBCPP_HAS_CHAR8_T
3232template <> struct __libcpp_is_integral<char8_t> { enum { value = 1 }; };
3333#endif
3434template <> struct __libcpp_is_integral<char16_t> { enum { value = 1 }; };
......@@ -41,7 +41,7 @@ template <> struct __libcpp_is_integral<long> { enum { va
4141template <> struct __libcpp_is_integral<unsigned long> { enum { value = 1 }; };
4242template <> struct __libcpp_is_integral<long long> { enum { value = 1 }; };
4343template <> struct __libcpp_is_integral<unsigned long long> { enum { value = 1 }; };
44#ifndef _LIBCPP_HAS_NO_INT128
44#if _LIBCPP_HAS_INT128
4545template <> struct __libcpp_is_integral<__int128_t> { enum { value = 1 }; };
4646template <> struct __libcpp_is_integral<__uint128_t> { enum { value = 1 }; };
4747#endif
......@@ -50,11 +50,11 @@ template <> struct __libcpp_is_integral<__uint128_t> { enum { va
5050#if __has_builtin(__is_integral)
5151
5252template <class _Tp>
53struct _LIBCPP_TEMPLATE_VIS is_integral : _BoolConstant<__is_integral(_Tp)> {};
53struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_integral : _BoolConstant<__is_integral(_Tp)> {};
5454
5555# if _LIBCPP_STD_VER >= 17
5656template <class _Tp>
57inline constexpr bool is_integral_v = __is_integral(_Tp);
57_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_integral_v = __is_integral(_Tp);
5858# endif
5959
6060#else
lib/libcxx/include/__type_traits/is_literal_type.h+3-3
......@@ -20,12 +20,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2020
2121#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
2222template <class _Tp>
23struct _LIBCPP_TEMPLATE_VIS
24_LIBCPP_DEPRECATED_IN_CXX17 is_literal_type : public integral_constant<bool, __is_literal_type(_Tp)> {};
23struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_NO_SPECIALIZATIONS is_literal_type
24 : public integral_constant<bool, __is_literal_type(_Tp)> {};
2525
2626# if _LIBCPP_STD_VER >= 17
2727template <class _Tp>
28_LIBCPP_DEPRECATED_IN_CXX17 inline constexpr bool is_literal_type_v = __is_literal_type(_Tp);
28_LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_literal_type_v = __is_literal_type(_Tp);
2929# endif // _LIBCPP_STD_VER >= 17
3030#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
3131
lib/libcxx/include/__type_traits/is_member_pointer.h+10-8
......@@ -19,24 +19,26 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS is_member_pointer : _BoolConstant<__is_member_pointer(_Tp)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_member_pointer : _BoolConstant<__is_member_pointer(_Tp)> {};
2323
2424template <class _Tp>
25struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer : _BoolConstant<__is_member_object_pointer(_Tp)> {};
25struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_member_object_pointer
26 : _BoolConstant<__is_member_object_pointer(_Tp)> {};
2627
2728template <class _Tp>
28struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer : _BoolConstant<__is_member_function_pointer(_Tp)> {};
29struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_member_function_pointer
30 : _BoolConstant<__is_member_function_pointer(_Tp)> {};
2931
30# if _LIBCPP_STD_VER >= 17
32#if _LIBCPP_STD_VER >= 17
3133template <class _Tp>
32inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp);
34_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp);
3335
3436template <class _Tp>
35inline constexpr bool is_member_object_pointer_v = __is_member_object_pointer(_Tp);
37_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_member_object_pointer_v = __is_member_object_pointer(_Tp);
3638
3739template <class _Tp>
38inline constexpr bool is_member_function_pointer_v = __is_member_function_pointer(_Tp);
39# endif
40_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_member_function_pointer_v = __is_member_function_pointer(_Tp);
41#endif
4042
4143_LIBCPP_END_NAMESPACE_STD
4244
lib/libcxx/include/__type_traits/is_nothrow_assignable.h+7-7
......@@ -21,34 +21,34 @@
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
2323template <class _Tp, class _Arg>
24struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable : public integral_constant<bool, __is_nothrow_assignable(_Tp, _Arg)> {
25};
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_assignable
25 : public integral_constant<bool, __is_nothrow_assignable(_Tp, _Arg)> {};
2626
2727#if _LIBCPP_STD_VER >= 17
2828template <class _Tp, class _Arg>
29inline constexpr bool is_nothrow_assignable_v = __is_nothrow_assignable(_Tp, _Arg);
29_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_assignable_v = __is_nothrow_assignable(_Tp, _Arg);
3030#endif
3131
3232template <class _Tp>
33struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_assignable
33struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_copy_assignable
3434 : public integral_constant<
3535 bool,
3636 __is_nothrow_assignable(__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<const _Tp>)> {};
3737
3838#if _LIBCPP_STD_VER >= 17
3939template <class _Tp>
40inline constexpr bool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<_Tp>::value;
40_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<_Tp>::value;
4141#endif
4242
4343template <class _Tp>
44struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_assignable
44struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_move_assignable
4545 : public integral_constant<bool,
4646 __is_nothrow_assignable(__add_lvalue_reference_t<_Tp>, __add_rvalue_reference_t<_Tp>)> {
4747};
4848
4949#if _LIBCPP_STD_VER >= 17
5050template <class _Tp>
51inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<_Tp>::value;
51_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<_Tp>::value;
5252#endif
5353
5454_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_nothrow_constructible.h+11-8
......@@ -21,39 +21,42 @@
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
2323template < class _Tp, class... _Args>
24struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_constructible
2525 : public integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {};
2626
2727#if _LIBCPP_STD_VER >= 17
2828template <class _Tp, class... _Args>
29inline constexpr bool is_nothrow_constructible_v = is_nothrow_constructible<_Tp, _Args...>::value;
29_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_constructible_v =
30 is_nothrow_constructible<_Tp, _Args...>::value;
3031#endif
3132
3233template <class _Tp>
33struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_constructible
34struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_copy_constructible
3435 : public integral_constant< bool, __is_nothrow_constructible(_Tp, __add_lvalue_reference_t<const _Tp>)> {};
3536
3637#if _LIBCPP_STD_VER >= 17
3738template <class _Tp>
38inline constexpr bool is_nothrow_copy_constructible_v = is_nothrow_copy_constructible<_Tp>::value;
39_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_copy_constructible_v =
40 is_nothrow_copy_constructible<_Tp>::value;
3941#endif
4042
4143template <class _Tp>
42struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_constructible
44struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_move_constructible
4345 : public integral_constant<bool, __is_nothrow_constructible(_Tp, __add_rvalue_reference_t<_Tp>)> {};
4446
4547#if _LIBCPP_STD_VER >= 17
4648template <class _Tp>
47inline constexpr bool is_nothrow_move_constructible_v = is_nothrow_move_constructible<_Tp>::value;
49_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_move_constructible_v =
50 is_nothrow_move_constructible<_Tp>::value;
4851#endif
4952
5053template <class _Tp>
51struct _LIBCPP_TEMPLATE_VIS is_nothrow_default_constructible
54struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_default_constructible
5255 : public integral_constant<bool, __is_nothrow_constructible(_Tp)> {};
5356
5457#if _LIBCPP_STD_VER >= 17
5558template <class _Tp>
56inline constexpr bool is_nothrow_default_constructible_v = __is_nothrow_constructible(_Tp);
59_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_default_constructible_v = __is_nothrow_constructible(_Tp);
5760#endif
5861
5962_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_nothrow_convertible.h+2-2
......@@ -29,10 +29,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2929# if __has_builtin(__is_nothrow_convertible)
3030
3131template <class _Tp, class _Up>
32struct is_nothrow_convertible : bool_constant<__is_nothrow_convertible(_Tp, _Up)> {};
32struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_convertible : bool_constant<__is_nothrow_convertible(_Tp, _Up)> {};
3333
3434template <class _Tp, class _Up>
35inline constexpr bool is_nothrow_convertible_v = __is_nothrow_convertible(_Tp, _Up);
35_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_convertible_v = __is_nothrow_convertible(_Tp, _Up);
3636
3737# else // __has_builtin(__is_nothrow_convertible)
3838
lib/libcxx/include/__type_traits/is_nothrow_destructible.h+4-3
......@@ -10,10 +10,10 @@
1010#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_DESTRUCTIBLE_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__type_traits/integral_constant.h>
1415#include <__type_traits/is_destructible.h>
1516#include <__utility/declval.h>
16#include <cstddef>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1919# pragma GCC system_header
......@@ -24,7 +24,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2424#if __has_builtin(__is_nothrow_destructible)
2525
2626template <class _Tp>
27struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible : integral_constant<bool, __is_nothrow_destructible(_Tp)> {};
27struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_destructible
28 : integral_constant<bool, __is_nothrow_destructible(_Tp)> {};
2829
2930#else
3031
......@@ -55,7 +56,7 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&&> : public true_type {}
5556
5657#if _LIBCPP_STD_VER >= 17
5758template <class _Tp>
58inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<_Tp>::value;
59_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<_Tp>::value;
5960#endif
6061
6162_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_null_pointer.h+4-3
......@@ -10,8 +10,8 @@
1010#define _LIBCPP___TYPE_TRAITS_IS_NULL_POINTER_H
1111
1212#include <__config>
13#include <__cstddef/nullptr_t.h>
1314#include <__type_traits/integral_constant.h>
14#include <cstddef>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717# pragma GCC system_header
......@@ -24,11 +24,12 @@ inline const bool __is_null_pointer_v = __is_same(__remove_cv(_Tp), nullptr_t);
2424
2525#if _LIBCPP_STD_VER >= 14
2626template <class _Tp>
27struct _LIBCPP_TEMPLATE_VIS is_null_pointer : integral_constant<bool, __is_null_pointer_v<_Tp>> {};
27struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_null_pointer
28 : integral_constant<bool, __is_null_pointer_v<_Tp>> {};
2829
2930# if _LIBCPP_STD_VER >= 17
3031template <class _Tp>
31inline constexpr bool is_null_pointer_v = __is_null_pointer_v<_Tp>;
32_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_null_pointer_v = __is_null_pointer_v<_Tp>;
3233# endif
3334#endif // _LIBCPP_STD_VER >= 14
3435
lib/libcxx/include/__type_traits/is_object.h+2-2
......@@ -19,11 +19,11 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS is_object : _BoolConstant<__is_object(_Tp)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_object : _BoolConstant<__is_object(_Tp)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
26inline constexpr bool is_object_v = __is_object(_Tp);
26_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_object_v = __is_object(_Tp);
2727#endif
2828
2929_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_pod.h+2-2
......@@ -19,11 +19,11 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS is_pod : public integral_constant<bool, __is_pod(_Tp)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_pod : public integral_constant<bool, __is_pod(_Tp)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
26inline constexpr bool is_pod_v = __is_pod(_Tp);
26_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_pod_v = __is_pod(_Tp);
2727#endif
2828
2929_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_pointer.h+3-3
......@@ -22,11 +22,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#if __has_builtin(__is_pointer)
2323
2424template <class _Tp>
25struct _LIBCPP_TEMPLATE_VIS is_pointer : _BoolConstant<__is_pointer(_Tp)> {};
25struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_pointer : _BoolConstant<__is_pointer(_Tp)> {};
2626
2727# if _LIBCPP_STD_VER >= 17
2828template <class _Tp>
29inline constexpr bool is_pointer_v = __is_pointer(_Tp);
29_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_pointer_v = __is_pointer(_Tp);
3030# endif
3131
3232#else // __has_builtin(__is_pointer)
......@@ -40,7 +40,7 @@ template <class _Tp>
4040struct __libcpp_remove_objc_qualifiers {
4141 typedef _Tp type;
4242};
43# if defined(_LIBCPP_HAS_OBJC_ARC)
43# if _LIBCPP_HAS_OBJC_ARC
4444// clang-format off
4545template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __strong> { typedef _Tp type; };
4646template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __weak> { typedef _Tp type; };
lib/libcxx/include/__type_traits/is_polymorphic.h+3-2
......@@ -19,11 +19,12 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS is_polymorphic : public integral_constant<bool, __is_polymorphic(_Tp)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_polymorphic
23 : public integral_constant<bool, __is_polymorphic(_Tp)> {};
2324
2425#if _LIBCPP_STD_VER >= 17
2526template <class _Tp>
26inline constexpr bool is_polymorphic_v = __is_polymorphic(_Tp);
27_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_polymorphic_v = __is_polymorphic(_Tp);
2728#endif
2829
2930_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_primary_template.h+3-2
......@@ -21,10 +21,11 @@
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
2323template <class _Tp>
24using __test_for_primary_template = __enable_if_t<_IsSame<_Tp, typename _Tp::__primary_template>::value>;
24using __test_for_primary_template _LIBCPP_NODEBUG =
25 __enable_if_t<_IsSame<_Tp, typename _Tp::__primary_template>::value>;
2526
2627template <class _Tp>
27using __is_primary_template = _IsValidExpansion<__test_for_primary_template, _Tp>;
28using __is_primary_template _LIBCPP_NODEBUG = _IsValidExpansion<__test_for_primary_template, _Tp>;
2829
2930_LIBCPP_END_NAMESPACE_STD
3031
lib/libcxx/include/__type_traits/is_reference.h+8-6
......@@ -19,26 +19,28 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS is_reference : _BoolConstant<__is_reference(_Tp)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_reference : _BoolConstant<__is_reference(_Tp)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
26inline constexpr bool is_reference_v = __is_reference(_Tp);
26_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_reference_v = __is_reference(_Tp);
2727#endif
2828
2929#if __has_builtin(__is_lvalue_reference) && __has_builtin(__is_rvalue_reference)
3030
3131template <class _Tp>
32struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference : _BoolConstant<__is_lvalue_reference(_Tp)> {};
32struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_lvalue_reference : _BoolConstant<__is_lvalue_reference(_Tp)> {
33};
3334
3435template <class _Tp>
35struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference : _BoolConstant<__is_rvalue_reference(_Tp)> {};
36struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_rvalue_reference : _BoolConstant<__is_rvalue_reference(_Tp)> {
37};
3638
3739# if _LIBCPP_STD_VER >= 17
3840template <class _Tp>
39inline constexpr bool is_lvalue_reference_v = __is_lvalue_reference(_Tp);
41_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_lvalue_reference_v = __is_lvalue_reference(_Tp);
4042template <class _Tp>
41inline constexpr bool is_rvalue_reference_v = __is_rvalue_reference(_Tp);
43_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_rvalue_reference_v = __is_rvalue_reference(_Tp);
4244# endif
4345
4446#else // __has_builtin(__is_lvalue_reference)
lib/libcxx/include/__type_traits/is_same.h+4-4
......@@ -19,11 +19,11 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp, class _Up>
22struct _LIBCPP_TEMPLATE_VIS is_same : _BoolConstant<__is_same(_Tp, _Up)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_same : _BoolConstant<__is_same(_Tp, _Up)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp, class _Up>
26inline constexpr bool is_same_v = __is_same(_Tp, _Up);
26_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_same_v = __is_same(_Tp, _Up);
2727#endif
2828
2929// _IsSame<T,U> has the same effect as is_same<T,U> but instantiates fewer types:
......@@ -34,10 +34,10 @@ inline constexpr bool is_same_v = __is_same(_Tp, _Up);
3434// (such as in a dependent return type).
3535
3636template <class _Tp, class _Up>
37using _IsSame = _BoolConstant<__is_same(_Tp, _Up)>;
37using _IsSame _LIBCPP_NODEBUG = _BoolConstant<__is_same(_Tp, _Up)>;
3838
3939template <class _Tp, class _Up>
40using _IsNotSame = _BoolConstant<!__is_same(_Tp, _Up)>;
40using _IsNotSame _LIBCPP_NODEBUG = _BoolConstant<!__is_same(_Tp, _Up)>;
4141
4242_LIBCPP_END_NAMESPACE_STD
4343
lib/libcxx/include/__type_traits/is_scalar.h+3-3
......@@ -26,18 +26,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2626#if __has_builtin(__is_scalar)
2727
2828template <class _Tp>
29struct _LIBCPP_TEMPLATE_VIS is_scalar : _BoolConstant<__is_scalar(_Tp)> {};
29struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_scalar : _BoolConstant<__is_scalar(_Tp)> {};
3030
3131# if _LIBCPP_STD_VER >= 17
3232template <class _Tp>
33inline constexpr bool is_scalar_v = __is_scalar(_Tp);
33_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_scalar_v = __is_scalar(_Tp);
3434# endif
3535
3636#else // __has_builtin(__is_scalar)
3737
3838template <class _Tp>
3939struct __is_block : false_type {};
40# if defined(_LIBCPP_HAS_EXTENSION_BLOCKS)
40# if _LIBCPP_HAS_EXTENSION_BLOCKS
4141template <class _Rp, class... _Args>
4242struct __is_block<_Rp (^)(_Args...)> : true_type {};
4343# endif
lib/libcxx/include/__type_traits/is_signed.h+2-2
......@@ -23,11 +23,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2323#if __has_builtin(__is_signed)
2424
2525template <class _Tp>
26struct _LIBCPP_TEMPLATE_VIS is_signed : _BoolConstant<__is_signed(_Tp)> {};
26struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_signed : _BoolConstant<__is_signed(_Tp)> {};
2727
2828# if _LIBCPP_STD_VER >= 17
2929template <class _Tp>
30inline constexpr bool is_signed_v = __is_signed(_Tp);
30_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_signed_v = __is_signed(_Tp);
3131# endif
3232
3333#else // __has_builtin(__is_signed)
lib/libcxx/include/__type_traits/is_signed_integer.h+1-1
......@@ -25,7 +25,7 @@ template <> struct __libcpp_is_signed_integer<signed short> : publi
2525template <> struct __libcpp_is_signed_integer<signed int> : public true_type {};
2626template <> struct __libcpp_is_signed_integer<signed long> : public true_type {};
2727template <> struct __libcpp_is_signed_integer<signed long long> : public true_type {};
28#ifndef _LIBCPP_HAS_NO_INT128
28#if _LIBCPP_HAS_INT128
2929template <> struct __libcpp_is_signed_integer<__int128_t> : public true_type {};
3030#endif
3131// clang-format on
lib/libcxx/include/__type_traits/is_standard_layout.h+3-2
......@@ -19,11 +19,12 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS is_standard_layout : public integral_constant<bool, __is_standard_layout(_Tp)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_standard_layout
23 : public integral_constant<bool, __is_standard_layout(_Tp)> {};
2324
2425#if _LIBCPP_STD_VER >= 17
2526template <class _Tp>
26inline constexpr bool is_standard_layout_v = __is_standard_layout(_Tp);
27_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_standard_layout_v = __is_standard_layout(_Tp);
2728#endif
2829
2930_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_swappable.h+16-11
......@@ -10,15 +10,16 @@
1010#define _LIBCPP___TYPE_TRAITS_IS_SWAPPABLE_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__type_traits/add_lvalue_reference.h>
1415#include <__type_traits/enable_if.h>
16#include <__type_traits/integral_constant.h>
1517#include <__type_traits/is_assignable.h>
1618#include <__type_traits/is_constructible.h>
1719#include <__type_traits/is_nothrow_assignable.h>
1820#include <__type_traits/is_nothrow_constructible.h>
1921#include <__type_traits/void_t.h>
2022#include <__utility/declval.h>
21#include <cstddef>
2223
2324#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2425# pragma GCC system_header
......@@ -40,10 +41,11 @@ inline const bool __is_nothrow_swappable_v = __is_nothrow_swappable_with_v<_Tp&,
4041
4142#ifndef _LIBCPP_CXX03_LANG
4243template <class _Tp>
43using __swap_result_t = __enable_if_t<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>;
44using __swap_result_t _LIBCPP_NODEBUG =
45 __enable_if_t<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>;
4446#else
4547template <class>
46using __swap_result_t = void;
48using __swap_result_t _LIBCPP_NODEBUG = void;
4749#endif
4850
4951template <class _Tp>
......@@ -72,30 +74,33 @@ inline const bool __is_nothrow_swappable_with_v<_Tp, _Up, true> =
7274#if _LIBCPP_STD_VER >= 17
7375
7476template <class _Tp, class _Up>
75inline constexpr bool is_swappable_with_v = __is_swappable_with_v<_Tp, _Up>;
77_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_swappable_with_v = __is_swappable_with_v<_Tp, _Up>;
7678
7779template <class _Tp, class _Up>
78struct _LIBCPP_TEMPLATE_VIS is_swappable_with : bool_constant<is_swappable_with_v<_Tp, _Up>> {};
80struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_swappable_with
81 : bool_constant<is_swappable_with_v<_Tp, _Up>> {};
7982
8083template <class _Tp>
81inline constexpr bool is_swappable_v =
84_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_swappable_v =
8285 is_swappable_with_v<__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<_Tp>>;
8386
8487template <class _Tp>
85struct _LIBCPP_TEMPLATE_VIS is_swappable : bool_constant<is_swappable_v<_Tp>> {};
88struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_swappable : bool_constant<is_swappable_v<_Tp>> {};
8689
8790template <class _Tp, class _Up>
88inline constexpr bool is_nothrow_swappable_with_v = __is_nothrow_swappable_with_v<_Tp, _Up>;
91_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_swappable_with_v = __is_nothrow_swappable_with_v<_Tp, _Up>;
8992
9093template <class _Tp, class _Up>
91struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable_with : bool_constant<is_nothrow_swappable_with_v<_Tp, _Up>> {};
94struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_swappable_with
95 : bool_constant<is_nothrow_swappable_with_v<_Tp, _Up>> {};
9296
9397template <class _Tp>
94inline constexpr bool is_nothrow_swappable_v =
98_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_swappable_v =
9599 is_nothrow_swappable_with_v<__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<_Tp>>;
96100
97101template <class _Tp>
98struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable : bool_constant<is_nothrow_swappable_v<_Tp>> {};
102struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_swappable
103 : bool_constant<is_nothrow_swappable_v<_Tp>> {};
99104
100105#endif // _LIBCPP_STD_VER >= 17
101106
lib/libcxx/include/__type_traits/is_trivial.h+3-2
......@@ -19,11 +19,12 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS is_trivial : public integral_constant<bool, __is_trivial(_Tp)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivial : public integral_constant<bool, __is_trivial(_Tp)> {
23};
2324
2425#if _LIBCPP_STD_VER >= 17
2526template <class _Tp>
26inline constexpr bool is_trivial_v = __is_trivial(_Tp);
27_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_trivial_v = __is_trivial(_Tp);
2728#endif
2829
2930_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_trivially_assignable.h+9-7
......@@ -10,7 +10,6 @@
1010#define _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_ASSIGNABLE_H
1111
1212#include <__config>
13#include <__type_traits/add_const.h>
1413#include <__type_traits/add_lvalue_reference.h>
1514#include <__type_traits/add_rvalue_reference.h>
1615#include <__type_traits/integral_constant.h>
......@@ -22,33 +21,36 @@
2221_LIBCPP_BEGIN_NAMESPACE_STD
2322
2423template <class _Tp, class _Arg>
25struct is_trivially_assignable : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)> {};
24struct _LIBCPP_NO_SPECIALIZATIONS is_trivially_assignable
25 : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)> {};
2626
2727#if _LIBCPP_STD_VER >= 17
2828template <class _Tp, class _Arg>
29inline constexpr bool is_trivially_assignable_v = __is_trivially_assignable(_Tp, _Arg);
29_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_trivially_assignable_v = __is_trivially_assignable(_Tp, _Arg);
3030#endif
3131
3232template <class _Tp>
33struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_assignable
33struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivially_copy_assignable
3434 : public integral_constant<
3535 bool,
3636 __is_trivially_assignable(__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<const _Tp>)> {};
3737
3838#if _LIBCPP_STD_VER >= 17
3939template <class _Tp>
40inline constexpr bool is_trivially_copy_assignable_v = is_trivially_copy_assignable<_Tp>::value;
40_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_trivially_copy_assignable_v =
41 is_trivially_copy_assignable<_Tp>::value;
4142#endif
4243
4344template <class _Tp>
44struct _LIBCPP_TEMPLATE_VIS is_trivially_move_assignable
45struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivially_move_assignable
4546 : public integral_constant<
4647 bool,
4748 __is_trivially_assignable(__add_lvalue_reference_t<_Tp>, __add_rvalue_reference_t<_Tp>)> {};
4849
4950#if _LIBCPP_STD_VER >= 17
5051template <class _Tp>
51inline constexpr bool is_trivially_move_assignable_v = is_trivially_move_assignable<_Tp>::value;
52_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_trivially_move_assignable_v =
53 is_trivially_move_assignable<_Tp>::value;
5254#endif
5355
5456_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_trivially_constructible.h+12-8
......@@ -21,39 +21,43 @@
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
2323template <class _Tp, class... _Args>
24struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivially_constructible
2525 : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)> {};
2626
2727#if _LIBCPP_STD_VER >= 17
2828template <class _Tp, class... _Args>
29inline constexpr bool is_trivially_constructible_v = __is_trivially_constructible(_Tp, _Args...);
29_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_trivially_constructible_v =
30 __is_trivially_constructible(_Tp, _Args...);
3031#endif
3132
3233template <class _Tp>
33struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_constructible
34struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivially_copy_constructible
3435 : public integral_constant<bool, __is_trivially_constructible(_Tp, __add_lvalue_reference_t<const _Tp>)> {};
3536
3637#if _LIBCPP_STD_VER >= 17
3738template <class _Tp>
38inline constexpr bool is_trivially_copy_constructible_v = is_trivially_copy_constructible<_Tp>::value;
39_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_trivially_copy_constructible_v =
40 is_trivially_copy_constructible<_Tp>::value;
3941#endif
4042
4143template <class _Tp>
42struct _LIBCPP_TEMPLATE_VIS is_trivially_move_constructible
44struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivially_move_constructible
4345 : public integral_constant<bool, __is_trivially_constructible(_Tp, __add_rvalue_reference_t<_Tp>)> {};
4446
4547#if _LIBCPP_STD_VER >= 17
4648template <class _Tp>
47inline constexpr bool is_trivially_move_constructible_v = is_trivially_move_constructible<_Tp>::value;
49_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_trivially_move_constructible_v =
50 is_trivially_move_constructible<_Tp>::value;
4851#endif
4952
5053template <class _Tp>
51struct _LIBCPP_TEMPLATE_VIS is_trivially_default_constructible
54struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivially_default_constructible
5255 : public integral_constant<bool, __is_trivially_constructible(_Tp)> {};
5356
5457#if _LIBCPP_STD_VER >= 17
5558template <class _Tp>
56inline constexpr bool is_trivially_default_constructible_v = __is_trivially_constructible(_Tp);
59_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_trivially_default_constructible_v =
60 __is_trivially_constructible(_Tp);
5761#endif
5862
5963_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_trivially_copyable.h+4-5
......@@ -20,17 +20,16 @@
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
2222template <class _Tp>
23struct _LIBCPP_TEMPLATE_VIS is_trivially_copyable : public integral_constant<bool, __is_trivially_copyable(_Tp)> {};
23struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivially_copyable
24 : public integral_constant<bool, __is_trivially_copyable(_Tp)> {};
2425
2526#if _LIBCPP_STD_VER >= 17
2627template <class _Tp>
27inline constexpr bool is_trivially_copyable_v = __is_trivially_copyable(_Tp);
28_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_trivially_copyable_v = __is_trivially_copyable(_Tp);
2829#endif
2930
30#if _LIBCPP_STD_VER >= 20
3131template <class _Tp>
32inline constexpr bool __is_cheap_to_copy = is_trivially_copyable_v<_Tp> && sizeof(_Tp) <= sizeof(std::intmax_t);
33#endif
32inline const bool __is_cheap_to_copy = __is_trivially_copyable(_Tp) && sizeof(_Tp) <= sizeof(std::intmax_t);
3433
3534_LIBCPP_END_NAMESPACE_STD
3635
lib/libcxx/include/__type_traits/is_trivially_destructible.h+2-2
......@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#if __has_builtin(__is_trivially_destructible)
2323
2424template <class _Tp>
25struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
25struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivially_destructible
2626 : public integral_constant<bool, __is_trivially_destructible(_Tp)> {};
2727
2828#elif __has_builtin(__has_trivial_destructor)
......@@ -39,7 +39,7 @@ struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
3939
4040#if _LIBCPP_STD_VER >= 17
4141template <class _Tp>
42inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<_Tp>::value;
42_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<_Tp>::value;
4343#endif
4444
4545_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_trivially_lexicographically_comparable.h+15-5
......@@ -10,6 +10,7 @@
1010#define _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_LEXICOGRAPHICALLY_COMPARABLE_H
1111
1212#include <__config>
13#include <__fwd/byte.h>
1314#include <__type_traits/integral_constant.h>
1415#include <__type_traits/is_same.h>
1516#include <__type_traits/is_unsigned.h>
......@@ -40,13 +41,22 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4041// unsigned integer types with sizeof(T) > 1: depending on the endianness, the LSB might be the first byte to be
4142// compared. This means that when comparing unsigned(129) and unsigned(2)
4243// using memcmp(), the result would be that 2 > 129.
43// TODO: Do we want to enable this on big-endian systems?
44
45template <class _Tp>
46inline const bool __is_std_byte_v = false;
47
48#if _LIBCPP_STD_VER >= 17
49template <>
50inline const bool __is_std_byte_v<byte> = true;
51#endif
4452
4553template <class _Tp, class _Up>
46struct __libcpp_is_trivially_lexicographically_comparable
47 : integral_constant<bool,
48 is_same<__remove_cv_t<_Tp>, __remove_cv_t<_Up> >::value && sizeof(_Tp) == 1 &&
49 is_unsigned<_Tp>::value> {};
54inline const bool __is_trivially_lexicographically_comparable_v =
55 is_same<__remove_cv_t<_Tp>, __remove_cv_t<_Up> >::value &&
56#ifdef _LIBCPP_LITTLE_ENDIAN
57 sizeof(_Tp) == 1 &&
58#endif
59 (is_unsigned<_Tp>::value || __is_std_byte_v<_Tp>);
5060
5161_LIBCPP_END_NAMESPACE_STD
5262
lib/libcxx/include/__type_traits/is_trivially_relocatable.h+5-3
......@@ -11,7 +11,6 @@
1111
1212#include <__config>
1313#include <__type_traits/enable_if.h>
14#include <__type_traits/integral_constant.h>
1514#include <__type_traits/is_same.h>
1615#include <__type_traits/is_trivially_copyable.h>
1716
......@@ -23,8 +22,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2322
2423// A type is trivially relocatable if a move construct + destroy of the original object is equivalent to
2524// `memcpy(dst, src, sizeof(T))`.
26
27#if __has_builtin(__is_trivially_relocatable)
25//
26// Note that we don't use the __is_trivially_relocatable Clang builtin right now because it does not
27// implement the semantics of any current or future trivial relocation proposal and it can lead to
28// incorrect optimizations on some platforms (Windows) and supported compilers (AppleClang).
29#if __has_builtin(__is_trivially_relocatable) && 0
2830template <class _Tp, class = void>
2931struct __libcpp_is_trivially_relocatable : integral_constant<bool, __is_trivially_relocatable(_Tp)> {};
3032#else
lib/libcxx/include/__type_traits/is_unbounded_array.h+10-4
......@@ -19,19 +19,25 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class>
22struct _LIBCPP_TEMPLATE_VIS __libcpp_is_unbounded_array : false_type {};
22inline const bool __is_unbounded_array_v = false;
2323template <class _Tp>
24struct _LIBCPP_TEMPLATE_VIS __libcpp_is_unbounded_array<_Tp[]> : true_type {};
24inline const bool __is_unbounded_array_v<_Tp[]> = true;
2525
2626#if _LIBCPP_STD_VER >= 20
2727
2828template <class>
29struct _LIBCPP_TEMPLATE_VIS is_unbounded_array : false_type {};
29struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_unbounded_array : false_type {};
30
31_LIBCPP_DIAGNOSTIC_PUSH
32# if __has_warning("-Winvalid-specialization")
33_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
34# endif
3035template <class _Tp>
3136struct _LIBCPP_TEMPLATE_VIS is_unbounded_array<_Tp[]> : true_type {};
37_LIBCPP_DIAGNOSTIC_POP
3238
3339template <class _Tp>
34inline constexpr bool is_unbounded_array_v = is_unbounded_array<_Tp>::value;
40_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_unbounded_array_v = is_unbounded_array<_Tp>::value;
3541
3642#endif
3743
lib/libcxx/include/__type_traits/is_union.h+2-2
......@@ -19,11 +19,11 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS is_union : public integral_constant<bool, __is_union(_Tp)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_union : public integral_constant<bool, __is_union(_Tp)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
26inline constexpr bool is_union_v = __is_union(_Tp);
26_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_union_v = __is_union(_Tp);
2727#endif
2828
2929_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/is_unsigned.h+2-2
......@@ -23,11 +23,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2323#if __has_builtin(__is_unsigned)
2424
2525template <class _Tp>
26struct _LIBCPP_TEMPLATE_VIS is_unsigned : _BoolConstant<__is_unsigned(_Tp)> {};
26struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_unsigned : _BoolConstant<__is_unsigned(_Tp)> {};
2727
2828# if _LIBCPP_STD_VER >= 17
2929template <class _Tp>
30inline constexpr bool is_unsigned_v = __is_unsigned(_Tp);
30_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_unsigned_v = __is_unsigned(_Tp);
3131# endif
3232
3333#else // __has_builtin(__is_unsigned)
lib/libcxx/include/__type_traits/is_unsigned_integer.h+1-1
......@@ -25,7 +25,7 @@ template <> struct __libcpp_is_unsigned_integer<unsigned short> : p
2525template <> struct __libcpp_is_unsigned_integer<unsigned int> : public true_type {};
2626template <> struct __libcpp_is_unsigned_integer<unsigned long> : public true_type {};
2727template <> struct __libcpp_is_unsigned_integer<unsigned long long> : public true_type {};
28#ifndef _LIBCPP_HAS_NO_INT128
28#if _LIBCPP_HAS_INT128
2929template <> struct __libcpp_is_unsigned_integer<__uint128_t> : public true_type {};
3030#endif
3131// clang-format on
lib/libcxx/include/__type_traits/is_void.h+4-4
......@@ -19,12 +19,12 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS is_void : _BoolConstant<__is_same(__remove_cv(_Tp), void)> {};
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_void : _BoolConstant<__is_same(__remove_cv(_Tp), void)> {};
2323
24# if _LIBCPP_STD_VER >= 17
24#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
26inline constexpr bool is_void_v = __is_same(__remove_cv(_Tp), void);
27# endif
26_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_void_v = __is_same(__remove_cv(_Tp), void);
27#endif
2828
2929_LIBCPP_END_NAMESPACE_STD
3030
lib/libcxx/include/__type_traits/is_volatile.h+2-2
......@@ -21,11 +21,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121#if __has_builtin(__is_volatile)
2222
2323template <class _Tp>
24struct _LIBCPP_TEMPLATE_VIS is_volatile : _BoolConstant<__is_volatile(_Tp)> {};
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_volatile : _BoolConstant<__is_volatile(_Tp)> {};
2525
2626# if _LIBCPP_STD_VER >= 17
2727template <class _Tp>
28inline constexpr bool is_volatile_v = __is_volatile(_Tp);
28_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_volatile_v = __is_volatile(_Tp);
2929# endif
3030
3131#else
lib/libcxx/include/__type_traits/make_32_64_or_128_bit.h+2-2
......@@ -31,11 +31,11 @@ template <class _Tp>
3131 requires(is_signed_v<_Tp> || is_unsigned_v<_Tp> || is_same_v<_Tp, char>)
3232#endif
3333// clang-format off
34using __make_32_64_or_128_bit_t =
34using __make_32_64_or_128_bit_t _LIBCPP_NODEBUG =
3535 __copy_unsigned_t<_Tp,
3636 __conditional_t<sizeof(_Tp) <= sizeof(int32_t), int32_t,
3737 __conditional_t<sizeof(_Tp) <= sizeof(int64_t), int64_t,
38#ifndef _LIBCPP_HAS_NO_INT128
38#if _LIBCPP_HAS_INT128
3939 __conditional_t<sizeof(_Tp) <= sizeof(__int128_t), __int128_t,
4040 /* else */ void>
4141#else
lib/libcxx/include/__type_traits/make_const_lvalue_ref.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22using __make_const_lvalue_ref = const __libcpp_remove_reference_t<_Tp>&;
22using __make_const_lvalue_ref _LIBCPP_NODEBUG = const __libcpp_remove_reference_t<_Tp>&;
2323
2424_LIBCPP_END_NAMESPACE_STD
2525
lib/libcxx/include/__type_traits/make_signed.h+13-18
......@@ -13,7 +13,6 @@
1313#include <__type_traits/copy_cv.h>
1414#include <__type_traits/is_enum.h>
1515#include <__type_traits/is_integral.h>
16#include <__type_traits/nat.h>
1716#include <__type_traits/remove_cv.h>
1817#include <__type_traits/type_list.h>
1918
......@@ -26,24 +25,20 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2625#if __has_builtin(__make_signed)
2726
2827template <class _Tp>
29using __make_signed_t = __make_signed(_Tp);
28using __make_signed_t _LIBCPP_NODEBUG = __make_signed(_Tp);
3029
3130#else
32// clang-format off
33typedef __type_list<signed char,
34 __type_list<signed short,
35 __type_list<signed int,
36 __type_list<signed long,
37 __type_list<signed long long,
38# ifndef _LIBCPP_HAS_NO_INT128
39 __type_list<__int128_t,
40# endif
41 __nat
42# ifndef _LIBCPP_HAS_NO_INT128
43 >
31using __signed_types =
32 __type_list<signed char,
33 signed short,
34 signed int,
35 signed long,
36 signed long long
37# if _LIBCPP_HAS_INT128
38 ,
39 __int128_t
4440# endif
45 > > > > > __signed_types;
46// clang-format on
41 >;
4742
4843template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
4944struct __make_signed{};
......@@ -63,7 +58,7 @@ template <> struct __make_signed< signed long, true> {typedef long ty
6358template <> struct __make_signed<unsigned long, true> {typedef long type;};
6459template <> struct __make_signed< signed long long, true> {typedef long long type;};
6560template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
66# ifndef _LIBCPP_HAS_NO_INT128
61# if _LIBCPP_HAS_INT128
6762template <> struct __make_signed<__int128_t, true> {typedef __int128_t type;};
6863template <> struct __make_signed<__uint128_t, true> {typedef __int128_t type;};
6964# endif
......@@ -75,7 +70,7 @@ using __make_signed_t = __copy_cv_t<_Tp, typename __make_signed<__remove_cv_t<_T
7570#endif // __has_builtin(__make_signed)
7671
7772template <class _Tp>
78struct make_signed {
73struct _LIBCPP_NO_SPECIALIZATIONS make_signed {
7974 using type _LIBCPP_NODEBUG = __make_signed_t<_Tp>;
8075};
8176
lib/libcxx/include/__type_traits/make_unsigned.h+15-22
......@@ -15,7 +15,6 @@
1515#include <__type_traits/is_enum.h>
1616#include <__type_traits/is_integral.h>
1717#include <__type_traits/is_unsigned.h>
18#include <__type_traits/nat.h>
1918#include <__type_traits/remove_cv.h>
2019#include <__type_traits/type_list.h>
2120
......@@ -28,24 +27,20 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2827#if __has_builtin(__make_unsigned)
2928
3029template <class _Tp>
31using __make_unsigned_t = __make_unsigned(_Tp);
30using __make_unsigned_t _LIBCPP_NODEBUG = __make_unsigned(_Tp);
3231
3332#else
34// clang-format off
35typedef __type_list<unsigned char,
36 __type_list<unsigned short,
37 __type_list<unsigned int,
38 __type_list<unsigned long,
39 __type_list<unsigned long long,
40# ifndef _LIBCPP_HAS_NO_INT128
41 __type_list<__uint128_t,
42# endif
43 __nat
44# ifndef _LIBCPP_HAS_NO_INT128
45 >
33using __unsigned_types =
34 __type_list<unsigned char,
35 unsigned short,
36 unsigned int,
37 unsigned long,
38 unsigned long long
39# if _LIBCPP_HAS_INT128
40 ,
41 __uint128_t
4642# endif
47 > > > > > __unsigned_types;
48// clang-format on
43 >;
4944
5045template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
5146struct __make_unsigned{};
......@@ -65,7 +60,7 @@ template <> struct __make_unsigned< signed long, true> {typedef unsigned l
6560template <> struct __make_unsigned<unsigned long, true> {typedef unsigned long type;};
6661template <> struct __make_unsigned< signed long long, true> {typedef unsigned long long type;};
6762template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
68# ifndef _LIBCPP_HAS_NO_INT128
63# if _LIBCPP_HAS_INT128
6964template <> struct __make_unsigned<__int128_t, true> {typedef __uint128_t type;};
7065template <> struct __make_unsigned<__uint128_t, true> {typedef __uint128_t type;};
7166# endif
......@@ -77,7 +72,7 @@ using __make_unsigned_t = __copy_cv_t<_Tp, typename __make_unsigned<__remove_cv_
7772#endif // __has_builtin(__make_unsigned)
7873
7974template <class _Tp>
80struct make_unsigned {
75struct _LIBCPP_NO_SPECIALIZATIONS make_unsigned {
8176 using type _LIBCPP_NODEBUG = __make_unsigned_t<_Tp>;
8277};
8378
......@@ -86,15 +81,13 @@ template <class _Tp>
8681using make_unsigned_t = __make_unsigned_t<_Tp>;
8782#endif
8883
89#ifndef _LIBCPP_CXX03_LANG
9084template <class _Tp>
91_LIBCPP_HIDE_FROM_ABI constexpr __make_unsigned_t<_Tp> __to_unsigned_like(_Tp __x) noexcept {
85_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __make_unsigned_t<_Tp> __to_unsigned_like(_Tp __x) _NOEXCEPT {
9286 return static_cast<__make_unsigned_t<_Tp> >(__x);
9387}
94#endif
9588
9689template <class _Tp, class _Up>
97using __copy_unsigned_t = __conditional_t<is_unsigned<_Tp>::value, __make_unsigned_t<_Up>, _Up>;
90using __copy_unsigned_t _LIBCPP_NODEBUG = __conditional_t<is_unsigned<_Tp>::value, __make_unsigned_t<_Up>, _Up>;
9891
9992_LIBCPP_END_NAMESPACE_STD
10093
lib/libcxx/include/__type_traits/maybe_const.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <bool _Const, class _Tp>
22using __maybe_const = __conditional_t<_Const, const _Tp, _Tp>;
22using __maybe_const _LIBCPP_NODEBUG = __conditional_t<_Const, const _Tp, _Tp>;
2323
2424_LIBCPP_END_NAMESPACE_STD
2525
lib/libcxx/include/__type_traits/negation.h+2-2
......@@ -23,9 +23,9 @@ struct _Not : _BoolConstant<!_Pred::value> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
26struct negation : _Not<_Tp> {};
26struct _LIBCPP_NO_SPECIALIZATIONS negation : _Not<_Tp> {};
2727template <class _Tp>
28inline constexpr bool negation_v = !_Tp::value;
28_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool negation_v = !_Tp::value;
2929#endif // _LIBCPP_STD_VER >= 17
3030
3131_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/noexcept_move_assign_container.h deleted-37
......@@ -1,37 +0,0 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_NOEXCEPT_MOVE_ASSIGN_CONTAINER_H
10#define _LIBCPP___TYPE_TRAITS_NOEXCEPT_MOVE_ASSIGN_CONTAINER_H
11
12#include <__config>
13#include <__memory/allocator_traits.h>
14#include <__type_traits/integral_constant.h>
15#include <__type_traits/is_nothrow_assignable.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23template <typename _Alloc, typename _Traits = allocator_traits<_Alloc> >
24struct __noexcept_move_assign_container
25 : public integral_constant<bool,
26 _Traits::propagate_on_container_move_assignment::value
27#if _LIBCPP_STD_VER >= 17
28 || _Traits::is_always_equal::value
29#else
30 && is_nothrow_move_assignable<_Alloc>::value
31#endif
32 > {
33};
34
35_LIBCPP_END_NAMESPACE_STD
36
37#endif // _LIBCPP___TYPE_TRAITS_NOEXCEPT_MOVE_ASSIGN_CONTAINER_H
lib/libcxx/include/__type_traits/promote.h+2-83
......@@ -13,20 +13,12 @@
1313#include <__type_traits/integral_constant.h>
1414#include <__type_traits/is_arithmetic.h>
1515
16#if defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER == 1700
17# include <__type_traits/is_same.h>
18# include <__utility/declval.h>
19#endif
20
2116#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2217# pragma GCC system_header
2318#endif
2419
2520_LIBCPP_BEGIN_NAMESPACE_STD
2621
27// TODO(LLVM-20): Remove this workaround
28#if !defined(_LIBCPP_CLANG_VER) || _LIBCPP_CLANG_VER != 1700
29
3022template <class... _Args>
3123class __promote {
3224 static_assert((is_arithmetic<_Args>::value && ...));
......@@ -39,10 +31,10 @@ class __promote {
3931 static double __test(unsigned long);
4032 static double __test(long long);
4133 static double __test(unsigned long long);
42# ifndef _LIBCPP_HAS_NO_INT128
34#if _LIBCPP_HAS_INT128
4335 static double __test(__int128_t);
4436 static double __test(__uint128_t);
45# endif
37#endif
4638 static double __test(double);
4739 static long double __test(long double);
4840
......@@ -50,79 +42,6 @@ public:
5042 using type = decltype((__test(_Args()) + ...));
5143};
5244
53#else
54
55template <class _Tp>
56struct __numeric_type {
57 static void __test(...);
58 static float __test(float);
59 static double __test(char);
60 static double __test(int);
61 static double __test(unsigned);
62 static double __test(long);
63 static double __test(unsigned long);
64 static double __test(long long);
65 static double __test(unsigned long long);
66# ifndef _LIBCPP_HAS_NO_INT128
67 static double __test(__int128_t);
68 static double __test(__uint128_t);
69# endif
70 static double __test(double);
71 static long double __test(long double);
72
73 typedef decltype(__test(std::declval<_Tp>())) type;
74 static const bool value = _IsNotSame<type, void>::value;
75};
76
77template <>
78struct __numeric_type<void> {
79 static const bool value = true;
80};
81
82template <class _A1,
83 class _A2 = void,
84 class _A3 = void,
85 bool = __numeric_type<_A1>::value && __numeric_type<_A2>::value && __numeric_type<_A3>::value>
86class __promote_imp {
87public:
88 static const bool value = false;
89};
90
91template <class _A1, class _A2, class _A3>
92class __promote_imp<_A1, _A2, _A3, true> {
93private:
94 typedef typename __promote_imp<_A1>::type __type1;
95 typedef typename __promote_imp<_A2>::type __type2;
96 typedef typename __promote_imp<_A3>::type __type3;
97
98public:
99 typedef decltype(__type1() + __type2() + __type3()) type;
100 static const bool value = true;
101};
102
103template <class _A1, class _A2>
104class __promote_imp<_A1, _A2, void, true> {
105private:
106 typedef typename __promote_imp<_A1>::type __type1;
107 typedef typename __promote_imp<_A2>::type __type2;
108
109public:
110 typedef decltype(__type1() + __type2()) type;
111 static const bool value = true;
112};
113
114template <class _A1>
115class __promote_imp<_A1, void, void, true> {
116public:
117 typedef typename __numeric_type<_A1>::type type;
118 static const bool value = true;
119};
120
121template <class _A1, class _A2 = void, class _A3 = void>
122class __promote : public __promote_imp<_A1, _A2, _A3> {};
123
124#endif // !defined(_LIBCPP_CLANG_VER) || _LIBCPP_CLANG_VER >= 1700
125
12645_LIBCPP_END_NAMESPACE_STD
12746
12847#endif // _LIBCPP___TYPE_TRAITS_PROMOTE_H
lib/libcxx/include/__type_traits/rank.h+9-3
......@@ -10,8 +10,8 @@
1010#define _LIBCPP___TYPE_TRAITS_RANK_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__type_traits/integral_constant.h>
14#include <cstddef>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717# pragma GCC system_header
......@@ -28,17 +28,23 @@ struct rank : integral_constant<size_t, __array_rank(_Tp)> {};
2828#else
2929
3030template <class _Tp>
31struct _LIBCPP_TEMPLATE_VIS rank : public integral_constant<size_t, 0> {};
31struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS rank : public integral_constant<size_t, 0> {};
32
33_LIBCPP_DIAGNOSTIC_PUSH
34# if __has_warning("-Winvalid-specialization")
35_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
36# endif
3237template <class _Tp>
3338struct _LIBCPP_TEMPLATE_VIS rank<_Tp[]> : public integral_constant<size_t, rank<_Tp>::value + 1> {};
3439template <class _Tp, size_t _Np>
3540struct _LIBCPP_TEMPLATE_VIS rank<_Tp[_Np]> : public integral_constant<size_t, rank<_Tp>::value + 1> {};
41_LIBCPP_DIAGNOSTIC_POP
3642
3743#endif // __has_builtin(__array_rank)
3844
3945#if _LIBCPP_STD_VER >= 17
4046template <class _Tp>
41inline constexpr size_t rank_v = rank<_Tp>::value;
47_LIBCPP_NO_SPECIALIZATIONS inline constexpr size_t rank_v = rank<_Tp>::value;
4248#endif
4349
4450_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/remove_all_extents.h+3-3
......@@ -10,7 +10,7 @@
1010#define _LIBCPP___TYPE_TRAITS_REMOVE_ALL_EXTENTS_H
1111
1212#include <__config>
13#include <cstddef>
13#include <__cstddef/size_t.h>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1616# pragma GCC system_header
......@@ -20,12 +20,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2020
2121#if __has_builtin(__remove_all_extents)
2222template <class _Tp>
23struct remove_all_extents {
23struct _LIBCPP_NO_SPECIALIZATIONS remove_all_extents {
2424 using type _LIBCPP_NODEBUG = __remove_all_extents(_Tp);
2525};
2626
2727template <class _Tp>
28using __remove_all_extents_t = __remove_all_extents(_Tp);
28using __remove_all_extents_t _LIBCPP_NODEBUG = __remove_all_extents(_Tp);
2929#else
3030template <class _Tp>
3131struct _LIBCPP_TEMPLATE_VIS remove_all_extents {
lib/libcxx/include/__type_traits/remove_const.h+2-2
......@@ -19,12 +19,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
1919
2020#if __has_builtin(__remove_const)
2121template <class _Tp>
22struct remove_const {
22struct _LIBCPP_NO_SPECIALIZATIONS remove_const {
2323 using type _LIBCPP_NODEBUG = __remove_const(_Tp);
2424};
2525
2626template <class _Tp>
27using __remove_const_t = __remove_const(_Tp);
27using __remove_const_t _LIBCPP_NODEBUG = __remove_const(_Tp);
2828#else
2929template <class _Tp>
3030struct _LIBCPP_TEMPLATE_VIS remove_const {
lib/libcxx/include/__type_traits/remove_const_ref.h+1-1
......@@ -20,7 +20,7 @@
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
2222template <class _Tp>
23using __remove_const_ref_t = __remove_const_t<__libcpp_remove_reference_t<_Tp> >;
23using __remove_const_ref_t _LIBCPP_NODEBUG = __remove_const_t<__libcpp_remove_reference_t<_Tp> >;
2424
2525_LIBCPP_END_NAMESPACE_STD
2626
lib/libcxx/include/__type_traits/remove_cv.h+5-12
......@@ -10,8 +10,6 @@
1010#define _LIBCPP___TYPE_TRAITS_REMOVE_CV_H
1111
1212#include <__config>
13#include <__type_traits/remove_const.h>
14#include <__type_traits/remove_volatile.h>
1513
1614#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1715# pragma GCC system_header
......@@ -19,23 +17,18 @@
1917
2018_LIBCPP_BEGIN_NAMESPACE_STD
2119
22#if __has_builtin(__remove_cv) && !defined(_LIBCPP_COMPILER_GCC)
2320template <class _Tp>
24struct remove_cv {
21struct _LIBCPP_NO_SPECIALIZATIONS remove_cv {
2522 using type _LIBCPP_NODEBUG = __remove_cv(_Tp);
2623};
2724
25#if defined(_LIBCPP_COMPILER_GCC)
2826template <class _Tp>
29using __remove_cv_t = __remove_cv(_Tp);
27using __remove_cv_t _LIBCPP_NODEBUG = typename remove_cv<_Tp>::type;
3028#else
3129template <class _Tp>
32struct _LIBCPP_TEMPLATE_VIS remove_cv {
33 typedef __remove_volatile_t<__remove_const_t<_Tp> > type;
34};
35
36template <class _Tp>
37using __remove_cv_t = __remove_volatile_t<__remove_const_t<_Tp> >;
38#endif // __has_builtin(__remove_cv)
30using __remove_cv_t _LIBCPP_NODEBUG = __remove_cv(_Tp);
31#endif
3932
4033#if _LIBCPP_STD_VER >= 14
4134template <class _Tp>
lib/libcxx/include/__type_traits/remove_cvref.h+11-8
......@@ -11,8 +11,6 @@
1111
1212#include <__config>
1313#include <__type_traits/is_same.h>
14#include <__type_traits/remove_cv.h>
15#include <__type_traits/remove_reference.h>
1614
1715#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1816# pragma GCC system_header
......@@ -20,21 +18,26 @@
2018
2119_LIBCPP_BEGIN_NAMESPACE_STD
2220
23#if __has_builtin(__remove_cvref) && !defined(_LIBCPP_COMPILER_GCC)
21#if defined(_LIBCPP_COMPILER_GCC)
2422template <class _Tp>
25using __remove_cvref_t _LIBCPP_NODEBUG = __remove_cvref(_Tp);
23struct __remove_cvref_gcc {
24 using type = __remove_cvref(_Tp);
25};
26
27template <class _Tp>
28using __remove_cvref_t _LIBCPP_NODEBUG = typename __remove_cvref_gcc<_Tp>::type;
2629#else
2730template <class _Tp>
28using __remove_cvref_t _LIBCPP_NODEBUG = __remove_cv_t<__libcpp_remove_reference_t<_Tp> >;
31using __remove_cvref_t _LIBCPP_NODEBUG = __remove_cvref(_Tp);
2932#endif // __has_builtin(__remove_cvref)
3033
3134template <class _Tp, class _Up>
32struct __is_same_uncvref : _IsSame<__remove_cvref_t<_Tp>, __remove_cvref_t<_Up> > {};
35using __is_same_uncvref _LIBCPP_NODEBUG = _IsSame<__remove_cvref_t<_Tp>, __remove_cvref_t<_Up> >;
3336
3437#if _LIBCPP_STD_VER >= 20
3538template <class _Tp>
36struct remove_cvref {
37 using type _LIBCPP_NODEBUG = __remove_cvref_t<_Tp>;
39struct _LIBCPP_NO_SPECIALIZATIONS remove_cvref {
40 using type _LIBCPP_NODEBUG = __remove_cvref(_Tp);
3841};
3942
4043template <class _Tp>
lib/libcxx/include/__type_traits/remove_extent.h+3-3
......@@ -10,7 +10,7 @@
1010#define _LIBCPP___TYPE_TRAITS_REMOVE_EXTENT_H
1111
1212#include <__config>
13#include <cstddef>
13#include <__cstddef/size_t.h>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1616# pragma GCC system_header
......@@ -20,12 +20,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2020
2121#if __has_builtin(__remove_extent)
2222template <class _Tp>
23struct remove_extent {
23struct _LIBCPP_NO_SPECIALIZATIONS remove_extent {
2424 using type _LIBCPP_NODEBUG = __remove_extent(_Tp);
2525};
2626
2727template <class _Tp>
28using __remove_extent_t = __remove_extent(_Tp);
28using __remove_extent_t _LIBCPP_NODEBUG = __remove_extent(_Tp);
2929#else
3030template <class _Tp>
3131struct _LIBCPP_TEMPLATE_VIS remove_extent {
lib/libcxx/include/__type_traits/remove_pointer.h+8-8
......@@ -19,24 +19,24 @@ _LIBCPP_BEGIN_NAMESPACE_STD
1919
2020#if !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS) && __has_builtin(__remove_pointer)
2121template <class _Tp>
22struct remove_pointer {
22struct _LIBCPP_NO_SPECIALIZATIONS remove_pointer {
2323 using type _LIBCPP_NODEBUG = __remove_pointer(_Tp);
2424};
2525
2626# ifdef _LIBCPP_COMPILER_GCC
2727template <class _Tp>
28using __remove_pointer_t = typename remove_pointer<_Tp>::type;
28using __remove_pointer_t _LIBCPP_NODEBUG = typename remove_pointer<_Tp>::type;
2929# else
3030template <class _Tp>
31using __remove_pointer_t = __remove_pointer(_Tp);
31using __remove_pointer_t _LIBCPP_NODEBUG = __remove_pointer(_Tp);
3232# endif
3333#else
3434// clang-format off
35template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer {typedef _LIBCPP_NODEBUG _Tp type;};
36template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp*> {typedef _LIBCPP_NODEBUG _Tp type;};
37template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const> {typedef _LIBCPP_NODEBUG _Tp type;};
38template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* volatile> {typedef _LIBCPP_NODEBUG _Tp type;};
39template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const volatile> {typedef _LIBCPP_NODEBUG _Tp type;};
35template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer {using type _LIBCPP_NODEBUG = _Tp;};
36template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp*> {using type _LIBCPP_NODEBUG = _Tp;};
37template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const> {using type _LIBCPP_NODEBUG = _Tp;};
38template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* volatile> {using type _LIBCPP_NODEBUG = _Tp;};
39template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const volatile> {using type _LIBCPP_NODEBUG = _Tp;};
4040// clang-format on
4141
4242template <class _Tp>
lib/libcxx/include/__type_traits/remove_reference.h+2-2
......@@ -19,12 +19,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
1919
2020#if __has_builtin(__remove_reference_t)
2121template <class _Tp>
22struct remove_reference {
22struct _LIBCPP_NO_SPECIALIZATIONS remove_reference {
2323 using type _LIBCPP_NODEBUG = __remove_reference_t(_Tp);
2424};
2525
2626template <class _Tp>
27using __libcpp_remove_reference_t = __remove_reference_t(_Tp);
27using __libcpp_remove_reference_t _LIBCPP_NODEBUG = __remove_reference_t(_Tp);
2828#elif __has_builtin(__remove_reference)
2929template <class _Tp>
3030struct remove_reference {
lib/libcxx/include/__type_traits/remove_volatile.h+2-2
......@@ -19,12 +19,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
1919
2020#if __has_builtin(__remove_volatile)
2121template <class _Tp>
22struct remove_volatile {
22struct _LIBCPP_NO_SPECIALIZATIONS remove_volatile {
2323 using type _LIBCPP_NODEBUG = __remove_volatile(_Tp);
2424};
2525
2626template <class _Tp>
27using __remove_volatile_t = __remove_volatile(_Tp);
27using __remove_volatile_t _LIBCPP_NODEBUG = __remove_volatile(_Tp);
2828#else
2929template <class _Tp>
3030struct _LIBCPP_TEMPLATE_VIS remove_volatile {
lib/libcxx/include/__type_traits/result_of.h+8-3
......@@ -10,7 +10,7 @@
1010#define _LIBCPP___TYPE_TRAITS_RESULT_OF_H
1111
1212#include <__config>
13#include <__functional/invoke.h>
13#include <__type_traits/invoke.h>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1616# pragma GCC system_header
......@@ -22,10 +22,15 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222
2323#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
2424template <class _Callable>
25class _LIBCPP_DEPRECATED_IN_CXX17 result_of;
25struct _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_NO_SPECIALIZATIONS result_of;
2626
27_LIBCPP_DIAGNOSTIC_PUSH
28#if __has_warning("-Winvalid-specialization")
29_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
30#endif
2731template <class _Fp, class... _Args>
28class _LIBCPP_TEMPLATE_VIS result_of<_Fp(_Args...)> : public __invoke_of<_Fp, _Args...> {};
32struct _LIBCPP_TEMPLATE_VIS result_of<_Fp(_Args...)> : __invoke_result<_Fp, _Args...> {};
33_LIBCPP_DIAGNOSTIC_POP
2934
3035# if _LIBCPP_STD_VER >= 14
3136template <class _Tp>
lib/libcxx/include/__type_traits/type_identity.h+1-1
......@@ -27,7 +27,7 @@ using __type_identity_t _LIBCPP_NODEBUG = typename __type_identity<_Tp>::type;
2727
2828#if _LIBCPP_STD_VER >= 20
2929template <class _Tp>
30struct type_identity {
30struct _LIBCPP_NO_SPECIALIZATIONS type_identity {
3131 typedef _Tp type;
3232};
3333template <class _Tp>
lib/libcxx/include/__type_traits/type_list.h+17-12
......@@ -10,7 +10,7 @@
1010#define _LIBCPP___TYPE_TRAITS_TYPE_LIST_H
1111
1212#include <__config>
13#include <cstddef>
13#include <__cstddef/size_t.h>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1616# pragma GCC system_header
......@@ -18,23 +18,28 @@
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
21template <class _Hp, class _Tp>
22struct __type_list {
23 typedef _Hp _Head;
24 typedef _Tp _Tail;
21template <class... _Types>
22struct __type_list {};
23
24template <class>
25struct __type_list_head;
26
27template <class _Head, class... _Tail>
28struct __type_list_head<__type_list<_Head, _Tail...> > {
29 using type _LIBCPP_NODEBUG = _Head;
2530};
2631
27template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)>
32template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename __type_list_head<_TypeList>::type)>
2833struct __find_first;
2934
30template <class _Hp, class _Tp, size_t _Size>
31struct __find_first<__type_list<_Hp, _Tp>, _Size, true> {
32 typedef _LIBCPP_NODEBUG _Hp type;
35template <class _Head, class... _Tail, size_t _Size>
36struct __find_first<__type_list<_Head, _Tail...>, _Size, true> {
37 using type _LIBCPP_NODEBUG = _Head;
3338};
3439
35template <class _Hp, class _Tp, size_t _Size>
36struct __find_first<__type_list<_Hp, _Tp>, _Size, false> {
37 typedef _LIBCPP_NODEBUG typename __find_first<_Tp, _Size>::type type;
40template <class _Head, class... _Tail, size_t _Size>
41struct __find_first<__type_list<_Head, _Tail...>, _Size, false> {
42 using type _LIBCPP_NODEBUG = typename __find_first<__type_list<_Tail...>, _Size>::type;
3843};
3944
4045_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/underlying_type.h+1-1
......@@ -30,7 +30,7 @@ struct __underlying_type_impl<_Tp, true> {
3030};
3131
3232template <class _Tp>
33struct underlying_type : __underlying_type_impl<_Tp, is_enum<_Tp>::value> {};
33struct _LIBCPP_NO_SPECIALIZATIONS underlying_type : __underlying_type_impl<_Tp, is_enum<_Tp>::value> {};
3434
3535#if _LIBCPP_STD_VER >= 14
3636template <class _Tp>
lib/libcxx/include/__type_traits/unwrap_ref.h+8-15
......@@ -21,38 +21,31 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121
2222template <class _Tp>
2323struct __unwrap_reference {
24 typedef _LIBCPP_NODEBUG _Tp type;
24 using type _LIBCPP_NODEBUG = _Tp;
2525};
2626
2727template <class _Tp>
2828struct __unwrap_reference<reference_wrapper<_Tp> > {
29 typedef _LIBCPP_NODEBUG _Tp& type;
29 using type _LIBCPP_NODEBUG = _Tp&;
3030};
3131
32template <class _Tp>
33using __unwrap_ref_decay_t _LIBCPP_NODEBUG = typename __unwrap_reference<__decay_t<_Tp> >::type;
34
3235#if _LIBCPP_STD_VER >= 20
3336template <class _Tp>
34struct unwrap_reference : __unwrap_reference<_Tp> {};
37struct _LIBCPP_NO_SPECIALIZATIONS unwrap_reference : __unwrap_reference<_Tp> {};
3538
3639template <class _Tp>
3740using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3841
3942template <class _Tp>
40struct unwrap_ref_decay : unwrap_reference<__decay_t<_Tp> > {};
43struct _LIBCPP_NO_SPECIALIZATIONS unwrap_ref_decay : unwrap_reference<__decay_t<_Tp> > {};
4144
4245template <class _Tp>
43using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
46using unwrap_ref_decay_t = __unwrap_ref_decay_t<_Tp>;
4447#endif // _LIBCPP_STD_VER >= 20
4548
46template <class _Tp>
47struct __unwrap_ref_decay
48#if _LIBCPP_STD_VER >= 20
49 : unwrap_ref_decay<_Tp>
50#else
51 : __unwrap_reference<__decay_t<_Tp> >
52#endif
53{
54};
55
5649_LIBCPP_END_NAMESPACE_STD
5750
5851#endif // _LIBCPP___TYPE_TRAITS_UNWRAP_REF_H
lib/libcxx/include/__type_traits/void_t.h+1-1
......@@ -23,7 +23,7 @@ using void_t = void;
2323#endif
2424
2525template <class...>
26using __void_t = void;
26using __void_t _LIBCPP_NODEBUG = void;
2727
2828_LIBCPP_END_NAMESPACE_STD
2929
lib/libcxx/include/__utility/as_const.h+1-4
......@@ -10,9 +10,6 @@
1010#define _LIBCPP___UTILITY_AS_CONST_H
1111
1212#include <__config>
13#include <__type_traits/add_const.h>
14#include <__utility/forward.h>
15#include <__utility/move.h>
1613
1714#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1815# pragma GCC system_header
......@@ -22,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2219
2320#if _LIBCPP_STD_VER >= 17
2421template <class _Tp>
25[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept {
22[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& as_const(_Tp& __t) noexcept {
2623 return __t;
2724}
2825
lib/libcxx/include/__utility/convert_to_integral.h+1-1
......@@ -42,7 +42,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR long long __convert_to_integral(_
4242 return __val;
4343}
4444
45#ifndef _LIBCPP_HAS_NO_INT128
45#if _LIBCPP_HAS_INT128
4646inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __int128_t __convert_to_integral(__int128_t __val) { return __val; }
4747
4848inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __uint128_t __convert_to_integral(__uint128_t __val) { return __val; }
lib/libcxx/include/__utility/element_count.h created+27
......@@ -0,0 +1,27 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___UTILITY_ELEMENT_COUNT_H
10#define _LIBCPP___UTILITY_ELEMENT_COUNT_H
11
12#include <__config>
13#include <__cstddef/size_t.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21// Type used to encode that a function takes an integer that represents a number
22// of elements as opposed to a number of bytes.
23enum class __element_count : size_t {};
24
25_LIBCPP_END_NAMESPACE_STD
26
27#endif // _LIBCPP___UTILITY_ELEMENT_COUNT_H
lib/libcxx/include/__utility/exception_guard.h+9-9
......@@ -44,7 +44,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4444// less common, especially one that tries to catch an exception through -fno-exceptions code.
4545//
4646// __exception_guard can help greatly simplify code that would normally be cluttered by
47// `#if _LIBCPP_HAS_NO_EXCEPTIONS`. For example:
47// `#if _LIBCPP_HAS_EXCEPTIONS`. For example:
4848//
4949// template <class Iterator, class Size, class OutputIterator>
5050// Iterator uninitialized_copy_n(Iterator iter, Size n, OutputIterator out) {
......@@ -96,10 +96,10 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(__exception_guard_exceptions);
9696template <class _Rollback>
9797struct __exception_guard_noexceptions {
9898 __exception_guard_noexceptions() = delete;
99 _LIBCPP_HIDE_FROM_ABI
100 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODEBUG explicit __exception_guard_noexceptions(_Rollback) {}
99 _LIBCPP_NODEBUG _LIBCPP_HIDE_FROM_ABI
100 _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit __exception_guard_noexceptions(_Rollback) {}
101101
102 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODEBUG
102 _LIBCPP_NODEBUG _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
103103 __exception_guard_noexceptions(__exception_guard_noexceptions&& __other)
104104 _NOEXCEPT_(is_nothrow_move_constructible<_Rollback>::value)
105105 : __completed_(__other.__completed_) {
......@@ -110,11 +110,11 @@ struct __exception_guard_noexceptions {
110110 __exception_guard_noexceptions& operator=(__exception_guard_noexceptions const&) = delete;
111111 __exception_guard_noexceptions& operator=(__exception_guard_noexceptions&&) = delete;
112112
113 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODEBUG void __complete() _NOEXCEPT {
113 _LIBCPP_NODEBUG _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __complete() _NOEXCEPT {
114114 __completed_ = true;
115115 }
116116
117 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NODEBUG ~__exception_guard_noexceptions() {
117 _LIBCPP_NODEBUG _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__exception_guard_noexceptions() {
118118 _LIBCPP_ASSERT_INTERNAL(__completed_, "__exception_guard not completed with exceptions disabled");
119119 }
120120
......@@ -124,12 +124,12 @@ private:
124124
125125_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(__exception_guard_noexceptions);
126126
127#ifdef _LIBCPP_HAS_NO_EXCEPTIONS
127#if !_LIBCPP_HAS_EXCEPTIONS
128128template <class _Rollback>
129using __exception_guard = __exception_guard_noexceptions<_Rollback>;
129using __exception_guard _LIBCPP_NODEBUG = __exception_guard_noexceptions<_Rollback>;
130130#else
131131template <class _Rollback>
132using __exception_guard = __exception_guard_exceptions<_Rollback>;
132using __exception_guard _LIBCPP_NODEBUG = __exception_guard_exceptions<_Rollback>;
133133#endif
134134
135135template <class _Rollback>
lib/libcxx/include/__utility/forward.h+2-2
......@@ -21,13 +21,13 @@
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
2323template <class _Tp>
24_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&&
24[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&&
2525forward(_LIBCPP_LIFETIMEBOUND __libcpp_remove_reference_t<_Tp>& __t) _NOEXCEPT {
2626 return static_cast<_Tp&&>(__t);
2727}
2828
2929template <class _Tp>
30_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&&
30[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&&
3131forward(_LIBCPP_LIFETIMEBOUND __libcpp_remove_reference_t<_Tp>&& __t) _NOEXCEPT {
3232 static_assert(!is_lvalue_reference<_Tp>::value, "cannot forward an rvalue as an lvalue");
3333 return static_cast<_Tp&&>(__t);
lib/libcxx/include/__utility/forward_like.h+20-3
......@@ -12,6 +12,7 @@
1212
1313#include <__config>
1414#include <__type_traits/conditional.h>
15#include <__type_traits/is_base_of.h>
1516#include <__type_traits/is_const.h>
1617#include <__type_traits/is_reference.h>
1718#include <__type_traits/remove_reference.h>
......@@ -25,13 +26,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2526#if _LIBCPP_STD_VER >= 23
2627
2728template <class _Ap, class _Bp>
28using _CopyConst = _If<is_const_v<_Ap>, const _Bp, _Bp>;
29using _CopyConst _LIBCPP_NODEBUG = _If<is_const_v<_Ap>, const _Bp, _Bp>;
2930
3031template <class _Ap, class _Bp>
31using _OverrideRef = _If<is_rvalue_reference_v<_Ap>, remove_reference_t<_Bp>&&, _Bp&>;
32using _OverrideRef _LIBCPP_NODEBUG = _If<is_rvalue_reference_v<_Ap>, remove_reference_t<_Bp>&&, _Bp&>;
3233
3334template <class _Ap, class _Bp>
34using _ForwardLike = _OverrideRef<_Ap&&, _CopyConst<remove_reference_t<_Ap>, remove_reference_t<_Bp>>>;
35using _ForwardLike _LIBCPP_NODEBUG = _OverrideRef<_Ap&&, _CopyConst<remove_reference_t<_Ap>, remove_reference_t<_Bp>>>;
3536
3637template <class _Tp, class _Up>
3738[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto
......@@ -39,6 +40,22 @@ forward_like(_LIBCPP_LIFETIMEBOUND _Up&& __ux) noexcept -> _ForwardLike<_Tp, _Up
3940 return static_cast<_ForwardLike<_Tp, _Up>>(__ux);
4041}
4142
43// This function is used for `deducing this` cases where you want to make sure the operation is performed on the class
44// itself and not on a derived class. For example
45// struct S {
46// template <class Self>
47// void func(Self&& self) {
48// // This will always call `do_something` of S instead of any class derived from S.
49// std::__forward_as<Self, S>(self).do_something();
50// }
51// };
52template <class _Tp, class _As, class _Up>
53[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _ForwardLike<_Tp, _As>
54__forward_as(_LIBCPP_LIFETIMEBOUND _Up&& __val) noexcept {
55 static_assert(is_base_of_v<_As, remove_reference_t<_Up>>);
56 return static_cast<_ForwardLike<_Tp, _As>>(__val);
57}
58
4259#endif // _LIBCPP_STD_VER >= 23
4360
4461_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__utility/in_place.h+4-3
......@@ -10,8 +10,9 @@
1010#define _LIBCPP___UTILITY_IN_PLACE_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
14#include <__type_traits/integral_constant.h>
1315#include <__type_traits/remove_cvref.h>
14#include <cstddef>
1516
1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1718# pragma GCC system_header
......@@ -46,7 +47,7 @@ template <class _Tp>
4647struct __is_inplace_type_imp<in_place_type_t<_Tp>> : true_type {};
4748
4849template <class _Tp>
49using __is_inplace_type = __is_inplace_type_imp<__remove_cvref_t<_Tp>>;
50using __is_inplace_type _LIBCPP_NODEBUG = __is_inplace_type_imp<__remove_cvref_t<_Tp>>;
5051
5152template <class _Tp>
5253struct __is_inplace_index_imp : false_type {};
......@@ -54,7 +55,7 @@ template <size_t _Idx>
5455struct __is_inplace_index_imp<in_place_index_t<_Idx>> : true_type {};
5556
5657template <class _Tp>
57using __is_inplace_index = __is_inplace_index_imp<__remove_cvref_t<_Tp>>;
58using __is_inplace_index _LIBCPP_NODEBUG = __is_inplace_index_imp<__remove_cvref_t<_Tp>>;
5859
5960#endif // _LIBCPP_STD_VER >= 17
6061
lib/libcxx/include/__utility/integer_sequence.h+5-5
......@@ -10,8 +10,8 @@
1010#define _LIBCPP___UTILITY_INTEGER_SEQUENCE_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1314#include <__type_traits/is_integral.h>
14#include <cstddef>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717# pragma GCC system_header
......@@ -25,19 +25,19 @@ struct __tuple_indices;
2525template <class _IdxType, _IdxType... _Values>
2626struct __integer_sequence {
2727 template <template <class _OIdxType, _OIdxType...> class _ToIndexSeq, class _ToIndexType>
28 using __convert = _ToIndexSeq<_ToIndexType, _Values...>;
28 using __convert _LIBCPP_NODEBUG = _ToIndexSeq<_ToIndexType, _Values...>;
2929
3030 template <size_t _Sp>
31 using __to_tuple_indices = __tuple_indices<(_Values + _Sp)...>;
31 using __to_tuple_indices _LIBCPP_NODEBUG = __tuple_indices<(_Values + _Sp)...>;
3232};
3333
3434#if __has_builtin(__make_integer_seq)
3535template <size_t _Ep, size_t _Sp>
36using __make_indices_imp =
36using __make_indices_imp _LIBCPP_NODEBUG =
3737 typename __make_integer_seq<__integer_sequence, size_t, _Ep - _Sp>::template __to_tuple_indices<_Sp>;
3838#elif __has_builtin(__integer_pack)
3939template <size_t _Ep, size_t _Sp>
40using __make_indices_imp =
40using __make_indices_imp _LIBCPP_NODEBUG =
4141 typename __integer_sequence<size_t, __integer_pack(_Ep - _Sp)...>::template __to_tuple_indices<_Sp>;
4242#else
4343# error "No known way to get an integer pack from the compiler"
lib/libcxx/include/__utility/is_pointer_in_range.h+8
......@@ -57,6 +57,14 @@ __is_pointer_in_range(const _Tp* __begin, const _Tp* __end, const _Up* __ptr) {
5757 reinterpret_cast<const char*>(__ptr) < reinterpret_cast<const char*>(__end);
5858}
5959
60template <class _Tp, class _Up>
61_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
62__is_overlapping_range(const _Tp* __begin, const _Tp* __end, const _Up* __begin2) {
63 auto __size = __end - __begin;
64 auto __end2 = __begin2 + __size;
65 return std::__is_pointer_in_range(__begin, __end, __begin2) || std::__is_pointer_in_range(__begin2, __end2, __begin);
66}
67
6068_LIBCPP_END_NAMESPACE_STD
6169
6270#endif // _LIBCPP___UTILITY_IS_POINTER_IN_RANGE_H
lib/libcxx/include/__utility/move.h+4-4
......@@ -26,18 +26,18 @@ _LIBCPP_PUSH_MACROS
2626_LIBCPP_BEGIN_NAMESPACE_STD
2727
2828template <class _Tp>
29_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __libcpp_remove_reference_t<_Tp>&&
29[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __libcpp_remove_reference_t<_Tp>&&
3030move(_LIBCPP_LIFETIMEBOUND _Tp&& __t) _NOEXCEPT {
31 typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tp> _Up;
31 using _Up _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tp>;
3232 return static_cast<_Up&&>(__t);
3333}
3434
3535template <class _Tp>
36using __move_if_noexcept_result_t =
36using __move_if_noexcept_result_t _LIBCPP_NODEBUG =
3737 __conditional_t<!is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, const _Tp&, _Tp&&>;
3838
3939template <class _Tp>
40_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __move_if_noexcept_result_t<_Tp>
40[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __move_if_noexcept_result_t<_Tp>
4141move_if_noexcept(_LIBCPP_LIFETIMEBOUND _Tp& __x) _NOEXCEPT {
4242 return std::move(__x);
4343}
lib/libcxx/include/__utility/no_destroy.h+1-1
......@@ -10,9 +10,9 @@
1010#define _LIBCPP___UTILITY_NO_DESTROY_H
1111
1212#include <__config>
13#include <__new/placement_new_delete.h>
1314#include <__type_traits/is_constant_evaluated.h>
1415#include <__utility/forward.h>
15#include <new>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1818# pragma GCC system_header
lib/libcxx/include/__utility/pair.h+11-51
......@@ -13,11 +13,10 @@
1313#include <__compare/synth_three_way.h>
1414#include <__concepts/different_from.h>
1515#include <__config>
16#include <__cstddef/size_t.h>
1617#include <__fwd/array.h>
1718#include <__fwd/pair.h>
1819#include <__fwd/tuple.h>
19#include <__tuple/sfinae_helpers.h>
20#include <__tuple/tuple_element.h>
2120#include <__tuple/tuple_indices.h>
2221#include <__tuple/tuple_like_no_subrange.h>
2322#include <__tuple/tuple_size.h>
......@@ -25,6 +24,7 @@
2524#include <__type_traits/common_type.h>
2625#include <__type_traits/conditional.h>
2726#include <__type_traits/decay.h>
27#include <__type_traits/enable_if.h>
2828#include <__type_traits/integral_constant.h>
2929#include <__type_traits/is_assignable.h>
3030#include <__type_traits/is_constructible.h>
......@@ -32,7 +32,6 @@
3232#include <__type_traits/is_implicitly_default_constructible.h>
3333#include <__type_traits/is_nothrow_assignable.h>
3434#include <__type_traits/is_nothrow_constructible.h>
35#include <__type_traits/is_reference.h>
3635#include <__type_traits/is_same.h>
3736#include <__type_traits/is_swappable.h>
3837#include <__type_traits/is_trivially_relocatable.h>
......@@ -43,7 +42,6 @@
4342#include <__utility/forward.h>
4443#include <__utility/move.h>
4544#include <__utility/piecewise_construct.h>
46#include <cstddef>
4745
4846#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4947# pragma GCC system_header
......@@ -73,7 +71,7 @@ struct _LIBCPP_TEMPLATE_VIS pair
7371 _T1 first;
7472 _T2 second;
7573
76 using __trivially_relocatable =
74 using __trivially_relocatable _LIBCPP_NODEBUG =
7775 __conditional_t<__libcpp_is_trivially_relocatable<_T1>::value && __libcpp_is_trivially_relocatable<_T2>::value,
7876 pair,
7977 void>;
......@@ -81,38 +79,6 @@ struct _LIBCPP_TEMPLATE_VIS pair
8179 _LIBCPP_HIDE_FROM_ABI pair(pair const&) = default;
8280 _LIBCPP_HIDE_FROM_ABI pair(pair&&) = default;
8381
84 // When we are requested for pair to be trivially copyable by the ABI macro, we use defaulted members
85 // if it is both legal to do it (i.e. no references) and we have a way to actually implement it, which requires
86 // the __enable_if__ attribute before C++20.
87#ifdef _LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR
88 // FIXME: This should really just be a static constexpr variable. It's in a struct to avoid gdb printing the value
89 // when printing a pair
90 struct __has_defaulted_members {
91 static const bool value = !is_reference<first_type>::value && !is_reference<second_type>::value;
92 };
93# if _LIBCPP_STD_VER >= 20
94 _LIBCPP_HIDE_FROM_ABI constexpr pair& operator=(const pair&)
95 requires __has_defaulted_members::value
96 = default;
97
98 _LIBCPP_HIDE_FROM_ABI constexpr pair& operator=(pair&&)
99 requires __has_defaulted_members::value
100 = default;
101# elif __has_attribute(__enable_if__)
102 _LIBCPP_HIDE_FROM_ABI pair& operator=(const pair&)
103 __attribute__((__enable_if__(__has_defaulted_members::value, ""))) = default;
104
105 _LIBCPP_HIDE_FROM_ABI pair& operator=(pair&&)
106 __attribute__((__enable_if__(__has_defaulted_members::value, ""))) = default;
107# else
108# error "_LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR isn't supported with this compiler"
109# endif
110#else
111 struct __has_defaulted_members {
112 static const bool value = false;
113 };
114#endif // defined(_LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR) && __has_attribute(__enable_if__)
115
11682#ifdef _LIBCPP_CXX03_LANG
11783 _LIBCPP_HIDE_FROM_ABI pair() : first(), second() {}
11884
......@@ -164,8 +130,7 @@ struct _LIBCPP_TEMPLATE_VIS pair
164130 };
165131
166132 template <bool _MaybeEnable>
167 using _CheckArgsDep _LIBCPP_NODEBUG =
168 typename conditional< _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type;
133 using _CheckArgsDep _LIBCPP_NODEBUG = __conditional_t<_MaybeEnable, _CheckArgs, void>;
169134
170135 template <bool _Dummy = true, __enable_if_t<_CheckArgsDep<_Dummy>::__enable_default(), int> = 0>
171136 explicit(!_CheckArgsDep<_Dummy>::__enable_implicit_default()) _LIBCPP_HIDE_FROM_ABI constexpr pair() noexcept(
......@@ -258,8 +223,7 @@ struct _LIBCPP_TEMPLATE_VIS pair
258223 typename __make_tuple_indices<sizeof...(_Args2) >::type()) {}
259224
260225 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair&
261 operator=(__conditional_t<!__has_defaulted_members::value && is_copy_assignable<first_type>::value &&
262 is_copy_assignable<second_type>::value,
226 operator=(__conditional_t<is_copy_assignable<first_type>::value && is_copy_assignable<second_type>::value,
263227 pair,
264228 __nat> const& __p) noexcept(is_nothrow_copy_assignable<first_type>::value &&
265229 is_nothrow_copy_assignable<second_type>::value) {
......@@ -268,12 +232,10 @@ struct _LIBCPP_TEMPLATE_VIS pair
268232 return *this;
269233 }
270234
271 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair&
272 operator=(__conditional_t<!__has_defaulted_members::value && is_move_assignable<first_type>::value &&
273 is_move_assignable<second_type>::value,
274 pair,
275 __nat>&& __p) noexcept(is_nothrow_move_assignable<first_type>::value &&
276 is_nothrow_move_assignable<second_type>::value) {
235 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& operator=(
236 __conditional_t<is_move_assignable<first_type>::value && is_move_assignable<second_type>::value, pair, __nat>&&
237 __p) noexcept(is_nothrow_move_assignable<first_type>::value &&
238 is_nothrow_move_assignable<second_type>::value) {
277239 first = std::forward<first_type>(__p.first);
278240 second = std::forward<second_type>(__p.second);
279241 return *this;
......@@ -570,11 +532,9 @@ swap(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) noexcept(noexcept(__x
570532#endif
571533
572534template <class _T1, class _T2>
573inline _LIBCPP_HIDE_FROM_ABI
574_LIBCPP_CONSTEXPR_SINCE_CXX14 pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>
535inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<__unwrap_ref_decay_t<_T1>, __unwrap_ref_decay_t<_T2> >
575536make_pair(_T1&& __t1, _T2&& __t2) {
576 return pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>(
577 std::forward<_T1>(__t1), std::forward<_T2>(__t2));
537 return pair<__unwrap_ref_decay_t<_T1>, __unwrap_ref_decay_t<_T2> >(std::forward<_T1>(__t1), std::forward<_T2>(__t2));
578538}
579539
580540template <class _T1, class _T2>
lib/libcxx/include/__utility/priority_tag.h+1-1
......@@ -10,7 +10,7 @@
1010#define _LIBCPP___UTILITY_PRIORITY_TAG_H
1111
1212#include <__config>
13#include <cstddef>
13#include <__cstddef/size_t.h>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1616# pragma GCC system_header
lib/libcxx/include/__utility/scope_guard.h created+56
......@@ -0,0 +1,56 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___UTILITY_SCOPE_GUARD_H
11#define _LIBCPP___UTILITY_SCOPE_GUARD_H
12
13#include <__assert>
14#include <__config>
15#include <__utility/move.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26template <class _Func>
27class __scope_guard {
28 _Func __func_;
29
30public:
31 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __scope_guard(_Func __func) : __func_(std::move(__func)) {}
32 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__scope_guard() { __func_(); }
33
34 __scope_guard(const __scope_guard&) = delete;
35 __scope_guard& operator=(const __scope_guard&) = delete;
36 __scope_guard& operator=(__scope_guard&&) = delete;
37
38// C++14 doesn't have mandatory RVO, so we have to provide a declaration even though no compiler will ever generate
39// a call to the move constructor.
40#if _LIBCPP_STD_VER <= 14
41 __scope_guard(__scope_guard&&);
42#else
43 __scope_guard(__scope_guard&&) = delete;
44#endif
45};
46
47template <class _Func>
48_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __scope_guard<_Func> __make_scope_guard(_Func __func) {
49 return __scope_guard<_Func>(std::move(__func));
50}
51
52_LIBCPP_END_NAMESPACE_STD
53
54_LIBCPP_POP_MACROS
55
56#endif // _LIBCPP___UTILITY_SCOPE_GUARD_H
lib/libcxx/include/__utility/small_buffer.h+6-4
......@@ -10,14 +10,16 @@
1010#define _LIBCPP___UTILITY_SMALL_BUFFER_H
1111
1212#include <__config>
13#include <__cstddef/byte.h>
14#include <__cstddef/size_t.h>
1315#include <__memory/construct_at.h>
16#include <__new/allocate.h>
17#include <__new/launder.h>
1418#include <__type_traits/decay.h>
1519#include <__type_traits/is_trivially_constructible.h>
1620#include <__type_traits/is_trivially_destructible.h>
1721#include <__utility/exception_guard.h>
1822#include <__utility/forward.h>
19#include <cstddef>
20#include <new>
2123
2224#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2325# pragma GCC system_header
......@@ -66,7 +68,7 @@ public:
6668 if constexpr (__fits_in_buffer<_Stored>) {
6769 return std::launder(reinterpret_cast<_Stored*>(__buffer_));
6870 } else {
69 byte* __allocation = static_cast<byte*>(::operator new[](sizeof(_Stored), align_val_t{alignof(_Stored)}));
71 byte* __allocation = reinterpret_cast<byte*>(std::__libcpp_allocate<_Stored>(__element_count(1)));
7072 std::construct_at(reinterpret_cast<byte**>(__buffer_), __allocation);
7173 return std::launder(reinterpret_cast<_Stored*>(__allocation));
7274 }
......@@ -75,7 +77,7 @@ public:
7577 template <class _Stored>
7678 _LIBCPP_HIDE_FROM_ABI void __dealloc() noexcept {
7779 if constexpr (!__fits_in_buffer<_Stored>)
78 ::operator delete[](*reinterpret_cast<void**>(__buffer_), sizeof(_Stored), align_val_t{alignof(_Stored)});
80 std::__libcpp_deallocate<_Stored>(__get<_Stored>(), __element_count(1));
7981 }
8082
8183 template <class _Stored, class... _Args>
lib/libcxx/include/__utility/swap.h+5-3
......@@ -10,6 +10,8 @@
1010#define _LIBCPP___UTILITY_SWAP_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
14#include <__type_traits/enable_if.h>
1315#include <__type_traits/is_assignable.h>
1416#include <__type_traits/is_constructible.h>
1517#include <__type_traits/is_nothrow_assignable.h>
......@@ -17,7 +19,6 @@
1719#include <__type_traits/is_swappable.h>
1820#include <__utility/declval.h>
1921#include <__utility/move.h>
20#include <cstddef>
2122
2223#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2324# pragma GCC system_header
......@@ -30,10 +31,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3031
3132#ifndef _LIBCPP_CXX03_LANG
3233template <class _Tp>
33using __swap_result_t = __enable_if_t<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>;
34using __swap_result_t _LIBCPP_NODEBUG =
35 __enable_if_t<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>;
3436#else
3537template <class>
36using __swap_result_t = void;
38using __swap_result_t _LIBCPP_NODEBUG = void;
3739#endif
3840
3941template <class _Tp>
lib/libcxx/include/__utility/unreachable.h+1-1
......@@ -18,7 +18,7 @@
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
21_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI inline void __libcpp_unreachable() {
21[[__noreturn__]] _LIBCPP_HIDE_FROM_ABI inline void __libcpp_unreachable() {
2222 _LIBCPP_ASSERT_INTERNAL(false, "std::unreachable() was reached");
2323 __builtin_unreachable();
2424}
lib/libcxx/include/__variant/monostate.h+1-1
......@@ -12,8 +12,8 @@
1212
1313#include <__compare/ordering.h>
1414#include <__config>
15#include <__cstddef/size_t.h>
1516#include <__functional/hash.h>
16#include <cstddef>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1919# pragma GCC system_header
lib/libcxx/include/__vector/comparison.h created+71
......@@ -0,0 +1,71 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___VECTOR_COMPARISON_H
10#define _LIBCPP___VECTOR_COMPARISON_H
11
12#include <__algorithm/equal.h>
13#include <__algorithm/lexicographical_compare.h>
14#include <__algorithm/lexicographical_compare_three_way.h>
15#include <__compare/synth_three_way.h>
16#include <__config>
17#include <__fwd/vector.h>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25template <class _Tp, class _Allocator>
26_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI bool
27operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
28 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
29 return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
30}
31
32#if _LIBCPP_STD_VER <= 17
33
34template <class _Tp, class _Allocator>
35inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
36 return !(__x == __y);
37}
38
39template <class _Tp, class _Allocator>
40inline _LIBCPP_HIDE_FROM_ABI bool operator<(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
41 return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
42}
43
44template <class _Tp, class _Allocator>
45inline _LIBCPP_HIDE_FROM_ABI bool operator>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
46 return __y < __x;
47}
48
49template <class _Tp, class _Allocator>
50inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
51 return !(__x < __y);
52}
53
54template <class _Tp, class _Allocator>
55inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
56 return !(__y < __x);
57}
58
59#else // _LIBCPP_STD_VER <= 17
60
61template <class _Tp, class _Allocator>
62_LIBCPP_HIDE_FROM_ABI constexpr __synth_three_way_result<_Tp>
63operator<=>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
64 return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
65}
66
67#endif // _LIBCPP_STD_VER <= 17
68
69_LIBCPP_END_NAMESPACE_STD
70
71#endif // _LIBCPP___VECTOR_COMPARISON_H
lib/libcxx/include/__vector/container_traits.h created+39
......@@ -0,0 +1,39 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___VECTOR_CONTAINER_TRAITS_H
10#define _LIBCPP___VECTOR_CONTAINER_TRAITS_H
11
12#include <__config>
13#include <__fwd/vector.h>
14#include <__memory/allocator_traits.h>
15#include <__type_traits/container_traits.h>
16#include <__type_traits/disjunction.h>
17#include <__type_traits/is_nothrow_constructible.h>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25template <class _Tp, class _Allocator>
26struct __container_traits<vector<_Tp, _Allocator> > {
27 // http://eel.is/c++draft/vector.modifiers#2
28 // If an exception is thrown other than by the copy constructor, move constructor, assignment operator, or move
29 // assignment operator of T or by any InputIterator operation, there are no effects. If an exception is thrown while
30 // inserting a single element at the end and T is Cpp17CopyInsertable or is_nothrow_move_constructible_v<T> is true,
31 // there are no effects. Otherwise, if an exception is thrown by the move constructor of a non-Cpp17CopyInsertable T,
32 // the effects are unspecified.
33 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
34 _Or<is_nothrow_move_constructible<_Tp>, __is_cpp17_copy_insertable<_Allocator> >::value;
35};
36
37_LIBCPP_END_NAMESPACE_STD
38
39#endif // _LIBCPP___VECTOR_CONTAINER_TRAITS_H
lib/libcxx/include/__vector/erase.h created+50
......@@ -0,0 +1,50 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___VECTOR_ERASE_H
10#define _LIBCPP___VECTOR_ERASE_H
11
12#include <__algorithm/remove.h>
13#include <__algorithm/remove_if.h>
14#include <__config>
15#include <__fwd/vector.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18# pragma GCC system_header
19#endif
20
21_LIBCPP_PUSH_MACROS
22#include <__undef_macros>
23
24#if _LIBCPP_STD_VER >= 20
25
26_LIBCPP_BEGIN_NAMESPACE_STD
27
28template <class _Tp, class _Allocator, class _Up>
29_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
30erase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
31 auto __old_size = __c.size();
32 __c.erase(std::remove(__c.begin(), __c.end(), __v), __c.end());
33 return __old_size - __c.size();
34}
35
36template <class _Tp, class _Allocator, class _Predicate>
37_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
38erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) {
39 auto __old_size = __c.size();
40 __c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end());
41 return __old_size - __c.size();
42}
43
44_LIBCPP_END_NAMESPACE_STD
45
46#endif // _LIBCPP_STD_VER >= 20
47
48_LIBCPP_POP_MACROS
49
50#endif // _LIBCPP___VECTOR_ERASE_H
lib/libcxx/include/__vector/pmr.h created+33
......@@ -0,0 +1,33 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___VECTOR_PMR_H
10#define _LIBCPP___VECTOR_PMR_H
11
12#include <__config>
13#include <__fwd/vector.h>
14#include <__memory_resource/polymorphic_allocator.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20#if _LIBCPP_STD_VER >= 17
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24namespace pmr {
25template <class _ValueT>
26using vector _LIBCPP_AVAILABILITY_PMR = std::vector<_ValueT, polymorphic_allocator<_ValueT>>;
27} // namespace pmr
28
29_LIBCPP_END_NAMESPACE_STD
30
31#endif
32
33#endif // _LIBCPP___VECTOR_PMR_H
lib/libcxx/include/__vector/swap.h created+29
......@@ -0,0 +1,29 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___VECTOR_SWAP_H
10#define _LIBCPP___VECTOR_SWAP_H
11
12#include <__config>
13#include <__fwd/vector.h>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_BEGIN_NAMESPACE_STD
20
21template <class _Tp, class _Allocator>
22_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void
23swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
24 __x.swap(__y);
25}
26
27_LIBCPP_END_NAMESPACE_STD
28
29#endif // _LIBCPP___VECTOR_SWAP_H
lib/libcxx/include/__vector/vector.h created+1416
......@@ -0,0 +1,1416 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___VECTOR_VECTOR_H
10#define _LIBCPP___VECTOR_VECTOR_H
11
12#include <__algorithm/copy.h>
13#include <__algorithm/copy_n.h>
14#include <__algorithm/fill_n.h>
15#include <__algorithm/max.h>
16#include <__algorithm/min.h>
17#include <__algorithm/move.h>
18#include <__algorithm/move_backward.h>
19#include <__algorithm/ranges_copy_n.h>
20#include <__algorithm/rotate.h>
21#include <__assert>
22#include <__config>
23#include <__debug_utils/sanitizers.h>
24#include <__format/enable_insertable.h>
25#include <__fwd/vector.h>
26#include <__iterator/advance.h>
27#include <__iterator/bounded_iter.h>
28#include <__iterator/concepts.h>
29#include <__iterator/distance.h>
30#include <__iterator/iterator_traits.h>
31#include <__iterator/move_iterator.h>
32#include <__iterator/next.h>
33#include <__iterator/reverse_iterator.h>
34#include <__iterator/wrap_iter.h>
35#include <__memory/addressof.h>
36#include <__memory/allocate_at_least.h>
37#include <__memory/allocator.h>
38#include <__memory/allocator_traits.h>
39#include <__memory/compressed_pair.h>
40#include <__memory/noexcept_move_assign_container.h>
41#include <__memory/pointer_traits.h>
42#include <__memory/swap_allocator.h>
43#include <__memory/temp_value.h>
44#include <__memory/uninitialized_algorithms.h>
45#include <__ranges/access.h>
46#include <__ranges/concepts.h>
47#include <__ranges/container_compatible_range.h>
48#include <__ranges/from_range.h>
49#include <__split_buffer>
50#include <__type_traits/conditional.h>
51#include <__type_traits/enable_if.h>
52#include <__type_traits/is_allocator.h>
53#include <__type_traits/is_constant_evaluated.h>
54#include <__type_traits/is_constructible.h>
55#include <__type_traits/is_nothrow_assignable.h>
56#include <__type_traits/is_nothrow_constructible.h>
57#include <__type_traits/is_pointer.h>
58#include <__type_traits/is_same.h>
59#include <__type_traits/is_trivially_relocatable.h>
60#include <__type_traits/type_identity.h>
61#include <__utility/exception_guard.h>
62#include <__utility/forward.h>
63#include <__utility/is_pointer_in_range.h>
64#include <__utility/move.h>
65#include <__utility/pair.h>
66#include <__utility/swap.h>
67#include <initializer_list>
68#include <limits>
69#include <stdexcept>
70
71// These headers define parts of vectors definition, since they define ADL functions or class specializations.
72#include <__vector/comparison.h>
73#include <__vector/container_traits.h>
74#include <__vector/swap.h>
75
76#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
77# pragma GCC system_header
78#endif
79
80_LIBCPP_PUSH_MACROS
81#include <__undef_macros>
82
83_LIBCPP_BEGIN_NAMESPACE_STD
84
85template <class _Tp, class _Allocator /* = allocator<_Tp> */>
86class _LIBCPP_TEMPLATE_VIS vector {
87private:
88 typedef allocator<_Tp> __default_allocator_type;
89
90public:
91 //
92 // Types
93 //
94 typedef vector __self;
95 typedef _Tp value_type;
96 typedef _Allocator allocator_type;
97 typedef allocator_traits<allocator_type> __alloc_traits;
98 typedef value_type& reference;
99 typedef const value_type& const_reference;
100 typedef typename __alloc_traits::size_type size_type;
101 typedef typename __alloc_traits::difference_type difference_type;
102 typedef typename __alloc_traits::pointer pointer;
103 typedef typename __alloc_traits::const_pointer const_pointer;
104#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
105 // Users might provide custom allocators, and prior to C++20 we have no existing way to detect whether the allocator's
106 // pointer type is contiguous (though it has to be by the Standard). Using the wrapper type ensures the iterator is
107 // considered contiguous.
108 typedef __bounded_iter<__wrap_iter<pointer> > iterator;
109 typedef __bounded_iter<__wrap_iter<const_pointer> > const_iterator;
110#else
111 typedef __wrap_iter<pointer> iterator;
112 typedef __wrap_iter<const_pointer> const_iterator;
113#endif
114 typedef std::reverse_iterator<iterator> reverse_iterator;
115 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
116
117 // A vector containers the following members which may be trivially relocatable:
118 // - pointer: may be trivially relocatable, so it's checked
119 // - allocator_type: may be trivially relocatable, so it's checked
120 // vector doesn't contain any self-references, so it's trivially relocatable if its members are.
121 using __trivially_relocatable _LIBCPP_NODEBUG = __conditional_t<
122 __libcpp_is_trivially_relocatable<pointer>::value && __libcpp_is_trivially_relocatable<allocator_type>::value,
123 vector,
124 void>;
125
126 static_assert(__check_valid_allocator<allocator_type>::value, "");
127 static_assert(is_same<typename allocator_type::value_type, value_type>::value,
128 "Allocator::value_type must be same type as value_type");
129
130 //
131 // [vector.cons], construct/copy/destroy
132 //
133 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector()
134 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) {}
135 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(const allocator_type& __a)
136#if _LIBCPP_STD_VER <= 14
137 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
138#else
139 noexcept
140#endif
141 : __alloc_(__a) {
142 }
143
144 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n) {
145 auto __guard = std::__make_exception_guard(__destroy_vector(*this));
146 if (__n > 0) {
147 __vallocate(__n);
148 __construct_at_end(__n);
149 }
150 __guard.__complete();
151 }
152
153#if _LIBCPP_STD_VER >= 14
154 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n, const allocator_type& __a)
155 : __alloc_(__a) {
156 auto __guard = std::__make_exception_guard(__destroy_vector(*this));
157 if (__n > 0) {
158 __vallocate(__n);
159 __construct_at_end(__n);
160 }
161 __guard.__complete();
162 }
163#endif
164
165 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __x) {
166 auto __guard = std::__make_exception_guard(__destroy_vector(*this));
167 if (__n > 0) {
168 __vallocate(__n);
169 __construct_at_end(__n, __x);
170 }
171 __guard.__complete();
172 }
173
174 template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0>
175 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
176 vector(size_type __n, const value_type& __x, const allocator_type& __a)
177 : __alloc_(__a) {
178 auto __guard = std::__make_exception_guard(__destroy_vector(*this));
179 if (__n > 0) {
180 __vallocate(__n);
181 __construct_at_end(__n, __x);
182 }
183 __guard.__complete();
184 }
185
186 template <class _InputIterator,
187 __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
188 is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
189 int> = 0>
190 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_InputIterator __first, _InputIterator __last) {
191 __init_with_sentinel(__first, __last);
192 }
193
194 template <class _InputIterator,
195 __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
196 is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
197 int> = 0>
198 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
199 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a)
200 : __alloc_(__a) {
201 __init_with_sentinel(__first, __last);
202 }
203
204 template <
205 class _ForwardIterator,
206 __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
207 is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
208 int> = 0>
209 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_ForwardIterator __first, _ForwardIterator __last) {
210 size_type __n = static_cast<size_type>(std::distance(__first, __last));
211 __init_with_size(__first, __last, __n);
212 }
213
214 template <
215 class _ForwardIterator,
216 __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
217 is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
218 int> = 0>
219 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
220 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a)
221 : __alloc_(__a) {
222 size_type __n = static_cast<size_type>(std::distance(__first, __last));
223 __init_with_size(__first, __last, __n);
224 }
225
226#if _LIBCPP_STD_VER >= 23
227 template <_ContainerCompatibleRange<_Tp> _Range>
228 _LIBCPP_HIDE_FROM_ABI constexpr vector(
229 from_range_t, _Range&& __range, const allocator_type& __alloc = allocator_type())
230 : __alloc_(__alloc) {
231 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
232 auto __n = static_cast<size_type>(ranges::distance(__range));
233 __init_with_size(ranges::begin(__range), ranges::end(__range), __n);
234
235 } else {
236 __init_with_sentinel(ranges::begin(__range), ranges::end(__range));
237 }
238 }
239#endif
240
241private:
242 class __destroy_vector {
243 public:
244 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __destroy_vector(vector& __vec) : __vec_(__vec) {}
245
246 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() {
247 if (__vec_.__begin_ != nullptr) {
248 __vec_.clear();
249 __vec_.__annotate_delete();
250 __alloc_traits::deallocate(__vec_.__alloc_, __vec_.__begin_, __vec_.capacity());
251 }
252 }
253
254 private:
255 vector& __vec_;
256 };
257
258public:
259 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector (*this)(); }
260
261 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x)
262 : __alloc_(__alloc_traits::select_on_container_copy_construction(__x.__alloc_)) {
263 __init_with_size(__x.__begin_, __x.__end_, __x.size());
264 }
265 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
266 vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
267 : __alloc_(__a) {
268 __init_with_size(__x.__begin_, __x.__end_, __x.size());
269 }
270 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector& operator=(const vector& __x);
271
272#ifndef _LIBCPP_CXX03_LANG
273 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(initializer_list<value_type> __il) {
274 __init_with_size(__il.begin(), __il.end(), __il.size());
275 }
276
277 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
278 vector(initializer_list<value_type> __il, const allocator_type& __a)
279 : __alloc_(__a) {
280 __init_with_size(__il.begin(), __il.end(), __il.size());
281 }
282
283 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector& operator=(initializer_list<value_type> __il) {
284 assign(__il.begin(), __il.end());
285 return *this;
286 }
287#endif // !_LIBCPP_CXX03_LANG
288
289 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(vector&& __x)
290#if _LIBCPP_STD_VER >= 17
291 noexcept;
292#else
293 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
294#endif
295
296 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
297 vector(vector&& __x, const __type_identity_t<allocator_type>& __a);
298 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector& operator=(vector&& __x)
299 _NOEXCEPT_(__noexcept_move_assign_container<_Allocator, __alloc_traits>::value) {
300 __move_assign(__x, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());
301 return *this;
302 }
303
304 template <class _InputIterator,
305 __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
306 is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
307 int> = 0>
308 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_InputIterator __first, _InputIterator __last) {
309 __assign_with_sentinel(__first, __last);
310 }
311 template <
312 class _ForwardIterator,
313 __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
314 is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
315 int> = 0>
316 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_ForwardIterator __first, _ForwardIterator __last) {
317 __assign_with_size(__first, __last, std::distance(__first, __last));
318 }
319
320#if _LIBCPP_STD_VER >= 23
321 template <_ContainerCompatibleRange<_Tp> _Range>
322 _LIBCPP_HIDE_FROM_ABI constexpr void assign_range(_Range&& __range) {
323 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
324 auto __n = static_cast<size_type>(ranges::distance(__range));
325 __assign_with_size(ranges::begin(__range), ranges::end(__range), __n);
326
327 } else {
328 __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
329 }
330 }
331#endif
332
333 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const_reference __u);
334
335#ifndef _LIBCPP_CXX03_LANG
336 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<value_type> __il) {
337 assign(__il.begin(), __il.end());
338 }
339#endif
340
341 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT {
342 return this->__alloc_;
343 }
344
345 //
346 // Iterators
347 //
348 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT {
349 return __make_iter(__add_alignment_assumption(this->__begin_));
350 }
351 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT {
352 return __make_iter(__add_alignment_assumption(this->__begin_));
353 }
354 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT {
355 return __make_iter(__add_alignment_assumption(this->__end_));
356 }
357 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT {
358 return __make_iter(__add_alignment_assumption(this->__end_));
359 }
360
361 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT {
362 return reverse_iterator(end());
363 }
364 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT {
365 return const_reverse_iterator(end());
366 }
367 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT {
368 return reverse_iterator(begin());
369 }
370 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT {
371 return const_reverse_iterator(begin());
372 }
373
374 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return begin(); }
375 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return end(); }
376 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT {
377 return rbegin();
378 }
379 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
380
381 //
382 // [vector.capacity], capacity
383 //
384 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT {
385 return static_cast<size_type>(this->__end_ - this->__begin_);
386 }
387 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type capacity() const _NOEXCEPT {
388 return static_cast<size_type>(this->__cap_ - this->__begin_);
389 }
390 [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT {
391 return this->__begin_ == this->__end_;
392 }
393 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
394 return std::min<size_type>(__alloc_traits::max_size(this->__alloc_), numeric_limits<difference_type>::max());
395 }
396 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n);
397 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void shrink_to_fit() _NOEXCEPT;
398
399 //
400 // element access
401 //
402 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference operator[](size_type __n) _NOEXCEPT {
403 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector[] index out of bounds");
404 return this->__begin_[__n];
405 }
406 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __n) const _NOEXCEPT {
407 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector[] index out of bounds");
408 return this->__begin_[__n];
409 }
410 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference at(size_type __n) {
411 if (__n >= size())
412 this->__throw_out_of_range();
413 return this->__begin_[__n];
414 }
415 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const {
416 if (__n >= size())
417 this->__throw_out_of_range();
418 return this->__begin_[__n];
419 }
420
421 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference front() _NOEXCEPT {
422 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "front() called on an empty vector");
423 return *this->__begin_;
424 }
425 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference front() const _NOEXCEPT {
426 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "front() called on an empty vector");
427 return *this->__begin_;
428 }
429 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference back() _NOEXCEPT {
430 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "back() called on an empty vector");
431 return *(this->__end_ - 1);
432 }
433 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference back() const _NOEXCEPT {
434 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "back() called on an empty vector");
435 return *(this->__end_ - 1);
436 }
437
438 //
439 // [vector.data], data access
440 //
441 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI value_type* data() _NOEXCEPT {
442 return std::__to_address(this->__begin_);
443 }
444
445 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const value_type* data() const _NOEXCEPT {
446 return std::__to_address(this->__begin_);
447 }
448
449 //
450 // [vector.modifiers], modifiers
451 //
452 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(const_reference __x) { emplace_back(__x); }
453
454 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x) { emplace_back(std::move(__x)); }
455
456 template <class... _Args>
457 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
458#if _LIBCPP_STD_VER >= 17
459 reference
460 emplace_back(_Args&&... __args);
461#else
462 void
463 emplace_back(_Args&&... __args);
464#endif
465
466#if _LIBCPP_STD_VER >= 23
467 template <_ContainerCompatibleRange<_Tp> _Range>
468 _LIBCPP_HIDE_FROM_ABI constexpr void append_range(_Range&& __range) {
469 insert_range(end(), std::forward<_Range>(__range));
470 }
471#endif
472
473 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void pop_back() {
474 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector::pop_back called on an empty vector");
475 this->__destruct_at_end(this->__end_ - 1);
476 }
477
478 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, const_reference __x);
479
480 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, value_type&& __x);
481 template <class... _Args>
482 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __position, _Args&&... __args);
483
484 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
485 insert(const_iterator __position, size_type __n, const_reference __x);
486
487 template <class _InputIterator,
488 __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
489 is_constructible< value_type, typename iterator_traits<_InputIterator>::reference>::value,
490 int> = 0>
491 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
492 insert(const_iterator __position, _InputIterator __first, _InputIterator __last) {
493 return __insert_with_sentinel(__position, __first, __last);
494 }
495
496 template <
497 class _ForwardIterator,
498 __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
499 is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
500 int> = 0>
501 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
502 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) {
503 return __insert_with_size(__position, __first, __last, std::distance(__first, __last));
504 }
505
506#if _LIBCPP_STD_VER >= 23
507 template <_ContainerCompatibleRange<_Tp> _Range>
508 _LIBCPP_HIDE_FROM_ABI constexpr iterator insert_range(const_iterator __position, _Range&& __range) {
509 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
510 auto __n = static_cast<size_type>(ranges::distance(__range));
511 return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n);
512
513 } else {
514 return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
515 }
516 }
517#endif
518
519#ifndef _LIBCPP_CXX03_LANG
520 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
521 insert(const_iterator __position, initializer_list<value_type> __il) {
522 return insert(__position, __il.begin(), __il.end());
523 }
524#endif
525
526 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position);
527 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last);
528
529 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT {
530 size_type __old_size = size();
531 __base_destruct_at_end(this->__begin_);
532 __annotate_shrink(__old_size);
533 }
534
535 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz);
536 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz, const_reference __x);
537
538 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void swap(vector&)
539#if _LIBCPP_STD_VER >= 14
540 _NOEXCEPT;
541#else
542 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>);
543#endif
544
545 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool __invariants() const;
546
547private:
548 pointer __begin_ = nullptr;
549 pointer __end_ = nullptr;
550 _LIBCPP_COMPRESSED_PAIR(pointer, __cap_ = nullptr, allocator_type, __alloc_);
551
552 // Allocate space for __n objects
553 // throws length_error if __n > max_size()
554 // throws (probably bad_alloc) if memory run out
555 // Precondition: __begin_ == __end_ == __cap_ == nullptr
556 // Precondition: __n > 0
557 // Postcondition: capacity() >= __n
558 // Postcondition: size() == 0
559 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
560 if (__n > max_size())
561 __throw_length_error();
562 auto __allocation = std::__allocate_at_least(this->__alloc_, __n);
563 __begin_ = __allocation.ptr;
564 __end_ = __allocation.ptr;
565 __cap_ = __begin_ + __allocation.count;
566 __annotate_new(0);
567 }
568
569 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vdeallocate() _NOEXCEPT;
570 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type __recommend(size_type __new_size) const;
571 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n);
572 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n, const_reference __x);
573
574 template <class _InputIterator, class _Sentinel>
575 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
576 __init_with_size(_InputIterator __first, _Sentinel __last, size_type __n) {
577 auto __guard = std::__make_exception_guard(__destroy_vector(*this));
578
579 if (__n > 0) {
580 __vallocate(__n);
581 __construct_at_end(std::move(__first), std::move(__last), __n);
582 }
583
584 __guard.__complete();
585 }
586
587 template <class _InputIterator, class _Sentinel>
588 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
589 __init_with_sentinel(_InputIterator __first, _Sentinel __last) {
590 auto __guard = std::__make_exception_guard(__destroy_vector(*this));
591
592 for (; __first != __last; ++__first)
593 emplace_back(*__first);
594
595 __guard.__complete();
596 }
597
598 template <class _Iterator, class _Sentinel>
599 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iterator __first, _Sentinel __last);
600
601 // The `_Iterator` in `*_with_size` functions can be input-only only if called from `*_range` (since C++23).
602 // Otherwise, `_Iterator` is a forward iterator.
603
604 template <class _Iterator, class _Sentinel>
605 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
606 __assign_with_size(_Iterator __first, _Sentinel __last, difference_type __n);
607
608 template <class _InputIterator, class _Sentinel>
609 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
610 __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last);
611
612 template <class _Iterator, class _Sentinel>
613 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
614 __insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n);
615
616 template <class _InputIterator, class _Sentinel>
617 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
618 __construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n);
619
620 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n);
621 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n, const_reference __x);
622
623 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator __make_iter(pointer __p) _NOEXCEPT {
624#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
625 // Bound the iterator according to the capacity, rather than the size.
626 //
627 // Vector guarantees that iterators stay valid as long as no reallocation occurs even if new elements are inserted
628 // into the container; for these cases, we need to make sure that the newly-inserted elements can be accessed
629 // through the bounded iterator without failing checks. The downside is that the bounded iterator won't catch
630 // access that is logically out-of-bounds, i.e., goes beyond the size, but is still within the capacity. With the
631 // current implementation, there is no connection between a bounded iterator and its associated container, so we
632 // don't have a way to update existing valid iterators when the container is resized and thus have to go with
633 // a laxer approach.
634 return std::__make_bounded_iter(
635 std::__wrap_iter<pointer>(__p),
636 std::__wrap_iter<pointer>(this->__begin_),
637 std::__wrap_iter<pointer>(this->__cap_));
638#else
639 return iterator(__p);
640#endif // _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
641 }
642
643 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator __make_iter(const_pointer __p) const _NOEXCEPT {
644#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
645 // Bound the iterator according to the capacity, rather than the size.
646 return std::__make_bounded_iter(
647 std::__wrap_iter<const_pointer>(__p),
648 std::__wrap_iter<const_pointer>(this->__begin_),
649 std::__wrap_iter<const_pointer>(this->__cap_));
650#else
651 return const_iterator(__p);
652#endif // _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
653 }
654
655 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
656 __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
657 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer
658 __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
659 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
660 __move_range(pointer __from_s, pointer __from_e, pointer __to);
661 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, true_type)
662 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
663 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, false_type)
664 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
665 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __destruct_at_end(pointer __new_last) _NOEXCEPT {
666 size_type __old_size = size();
667 __base_destruct_at_end(__new_last);
668 __annotate_shrink(__old_size);
669 }
670
671 template <class... _Args>
672 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI inline pointer __emplace_back_slow_path(_Args&&... __args);
673
674 // The following functions are no-ops outside of AddressSanitizer mode.
675 // We call annotations for every allocator, unless explicitly disabled.
676 //
677 // To disable annotations for a particular allocator, change value of
678 // __asan_annotate_container_with_allocator to false.
679 // For more details, see the "Using libc++" documentation page or
680 // the documentation for __sanitizer_annotate_contiguous_container.
681
682 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
683 __annotate_contiguous_container(const void* __old_mid, const void* __new_mid) const {
684 std::__annotate_contiguous_container<_Allocator>(data(), data() + capacity(), __old_mid, __new_mid);
685 }
686
687 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_new(size_type __current_size) const _NOEXCEPT {
688 (void)__current_size;
689#if _LIBCPP_HAS_ASAN
690 __annotate_contiguous_container(data() + capacity(), data() + __current_size);
691#endif
692 }
693
694 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_delete() const _NOEXCEPT {
695#if _LIBCPP_HAS_ASAN
696 __annotate_contiguous_container(data() + size(), data() + capacity());
697#endif
698 }
699
700 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_increase(size_type __n) const _NOEXCEPT {
701 (void)__n;
702#if _LIBCPP_HAS_ASAN
703 __annotate_contiguous_container(data() + size(), data() + size() + __n);
704#endif
705 }
706
707 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_shrink(size_type __old_size) const _NOEXCEPT {
708 (void)__old_size;
709#if _LIBCPP_HAS_ASAN
710 __annotate_contiguous_container(data() + __old_size, data() + size());
711#endif
712 }
713
714 struct _ConstructTransaction {
715 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit _ConstructTransaction(vector& __v, size_type __n)
716 : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
717#if _LIBCPP_HAS_ASAN
718 __v_.__annotate_increase(__n);
719#endif
720 }
721
722 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~_ConstructTransaction() {
723 __v_.__end_ = __pos_;
724#if _LIBCPP_HAS_ASAN
725 if (__pos_ != __new_end_) {
726 __v_.__annotate_shrink(__new_end_ - __v_.__begin_);
727 }
728#endif
729 }
730
731 vector& __v_;
732 pointer __pos_;
733 const_pointer const __new_end_;
734
735 _ConstructTransaction(_ConstructTransaction const&) = delete;
736 _ConstructTransaction& operator=(_ConstructTransaction const&) = delete;
737 };
738
739 template <class... _Args>
740 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_one_at_end(_Args&&... __args) {
741 _ConstructTransaction __tx(*this, 1);
742 __alloc_traits::construct(this->__alloc_, std::__to_address(__tx.__pos_), std::forward<_Args>(__args)...);
743 ++__tx.__pos_;
744 }
745
746 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __base_destruct_at_end(pointer __new_last) _NOEXCEPT {
747 pointer __soon_to_be_end = this->__end_;
748 while (__new_last != __soon_to_be_end)
749 __alloc_traits::destroy(this->__alloc_, std::__to_address(--__soon_to_be_end));
750 this->__end_ = __new_last;
751 }
752
753 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector& __c) {
754 __copy_assign_alloc(__c, integral_constant<bool, __alloc_traits::propagate_on_container_copy_assignment::value>());
755 }
756
757 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector& __c)
758 _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value ||
759 is_nothrow_move_assignable<allocator_type>::value) {
760 __move_assign_alloc(__c, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());
761 }
762
763 [[__noreturn__]] _LIBCPP_HIDE_FROM_ABI static void __throw_length_error() { std::__throw_length_error("vector"); }
764
765 [[__noreturn__]] _LIBCPP_HIDE_FROM_ABI static void __throw_out_of_range() { std::__throw_out_of_range("vector"); }
766
767 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector& __c, true_type) {
768 if (this->__alloc_ != __c.__alloc_) {
769 clear();
770 __annotate_delete();
771 __alloc_traits::deallocate(this->__alloc_, this->__begin_, capacity());
772 this->__begin_ = this->__end_ = this->__cap_ = nullptr;
773 }
774 this->__alloc_ = __c.__alloc_;
775 }
776
777 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector&, false_type) {}
778
779 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector& __c, true_type)
780 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
781 this->__alloc_ = std::move(__c.__alloc_);
782 }
783
784 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector&, false_type) _NOEXCEPT {}
785
786 template <class _Ptr = pointer, __enable_if_t<is_pointer<_Ptr>::value, int> = 0>
787 static _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI pointer
788 __add_alignment_assumption(_Ptr __p) _NOEXCEPT {
789 if (!__libcpp_is_constant_evaluated()) {
790 return static_cast<pointer>(__builtin_assume_aligned(__p, _LIBCPP_ALIGNOF(decltype(*__p))));
791 }
792 return __p;
793 }
794
795 template <class _Ptr = pointer, __enable_if_t<!is_pointer<_Ptr>::value, int> = 0>
796 static _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI pointer
797 __add_alignment_assumption(_Ptr __p) _NOEXCEPT {
798 return __p;
799 }
800};
801
802#if _LIBCPP_STD_VER >= 17
803template <class _InputIterator,
804 class _Alloc = allocator<__iter_value_type<_InputIterator>>,
805 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
806 class = enable_if_t<__is_allocator<_Alloc>::value> >
807vector(_InputIterator, _InputIterator) -> vector<__iter_value_type<_InputIterator>, _Alloc>;
808
809template <class _InputIterator,
810 class _Alloc,
811 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
812 class = enable_if_t<__is_allocator<_Alloc>::value> >
813vector(_InputIterator, _InputIterator, _Alloc) -> vector<__iter_value_type<_InputIterator>, _Alloc>;
814#endif
815
816#if _LIBCPP_STD_VER >= 23
817template <ranges::input_range _Range,
818 class _Alloc = allocator<ranges::range_value_t<_Range>>,
819 class = enable_if_t<__is_allocator<_Alloc>::value> >
820vector(from_range_t, _Range&&, _Alloc = _Alloc()) -> vector<ranges::range_value_t<_Range>, _Alloc>;
821#endif
822
823// __swap_out_circular_buffer relocates the objects in [__begin_, __end_) into the front of __v and swaps the buffers of
824// *this and __v. It is assumed that __v provides space for exactly (__end_ - __begin_) objects in the front. This
825// function has a strong exception guarantee.
826template <class _Tp, class _Allocator>
827_LIBCPP_CONSTEXPR_SINCE_CXX20 void
828vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) {
829 __annotate_delete();
830 auto __new_begin = __v.__begin_ - (__end_ - __begin_);
831 std::__uninitialized_allocator_relocate(
832 this->__alloc_, std::__to_address(__begin_), std::__to_address(__end_), std::__to_address(__new_begin));
833 __v.__begin_ = __new_begin;
834 __end_ = __begin_; // All the objects have been destroyed by relocating them.
835 std::swap(this->__begin_, __v.__begin_);
836 std::swap(this->__end_, __v.__end_);
837 std::swap(this->__cap_, __v.__cap_);
838 __v.__first_ = __v.__begin_;
839 __annotate_new(size());
840}
841
842// __swap_out_circular_buffer relocates the objects in [__begin_, __p) into the front of __v, the objects in
843// [__p, __end_) into the back of __v and swaps the buffers of *this and __v. It is assumed that __v provides space for
844// exactly (__p - __begin_) objects in the front and space for at least (__end_ - __p) objects in the back. This
845// function has a strong exception guarantee if __begin_ == __p || __end_ == __p.
846template <class _Tp, class _Allocator>
847_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::pointer
848vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) {
849 __annotate_delete();
850 pointer __ret = __v.__begin_;
851
852 // Relocate [__p, __end_) first to avoid having a hole in [__begin_, __end_)
853 // in case something in [__begin_, __p) throws.
854 std::__uninitialized_allocator_relocate(
855 this->__alloc_, std::__to_address(__p), std::__to_address(__end_), std::__to_address(__v.__end_));
856 __v.__end_ += (__end_ - __p);
857 __end_ = __p; // The objects in [__p, __end_) have been destroyed by relocating them.
858 auto __new_begin = __v.__begin_ - (__p - __begin_);
859
860 std::__uninitialized_allocator_relocate(
861 this->__alloc_, std::__to_address(__begin_), std::__to_address(__p), std::__to_address(__new_begin));
862 __v.__begin_ = __new_begin;
863 __end_ = __begin_; // All the objects have been destroyed by relocating them.
864
865 std::swap(this->__begin_, __v.__begin_);
866 std::swap(this->__end_, __v.__end_);
867 std::swap(this->__cap_, __v.__cap_);
868 __v.__first_ = __v.__begin_;
869 __annotate_new(size());
870 return __ret;
871}
872
873template <class _Tp, class _Allocator>
874_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT {
875 if (this->__begin_ != nullptr) {
876 clear();
877 __annotate_delete();
878 __alloc_traits::deallocate(this->__alloc_, this->__begin_, capacity());
879 this->__begin_ = this->__end_ = this->__cap_ = nullptr;
880 }
881}
882
883// Precondition: __new_size > capacity()
884template <class _Tp, class _Allocator>
885_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
886vector<_Tp, _Allocator>::__recommend(size_type __new_size) const {
887 const size_type __ms = max_size();
888 if (__new_size > __ms)
889 this->__throw_length_error();
890 const size_type __cap = capacity();
891 if (__cap >= __ms / 2)
892 return __ms;
893 return std::max<size_type>(2 * __cap, __new_size);
894}
895
896// Default constructs __n objects starting at __end_
897// throws if construction throws
898// Precondition: __n > 0
899// Precondition: size() + __n <= capacity()
900// Postcondition: size() == size() + __n
901template <class _Tp, class _Allocator>
902_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__construct_at_end(size_type __n) {
903 _ConstructTransaction __tx(*this, __n);
904 const_pointer __new_end = __tx.__new_end_;
905 for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
906 __alloc_traits::construct(this->__alloc_, std::__to_address(__pos));
907 }
908}
909
910// Copy constructs __n objects starting at __end_ from __x
911// throws if construction throws
912// Precondition: __n > 0
913// Precondition: size() + __n <= capacity()
914// Postcondition: size() == old size() + __n
915// Postcondition: [i] == __x for all i in [size() - __n, __n)
916template <class _Tp, class _Allocator>
917_LIBCPP_CONSTEXPR_SINCE_CXX20 inline void
918vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) {
919 _ConstructTransaction __tx(*this, __n);
920 const_pointer __new_end = __tx.__new_end_;
921 for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
922 __alloc_traits::construct(this->__alloc_, std::__to_address(__pos), __x);
923 }
924}
925
926template <class _Tp, class _Allocator>
927template <class _InputIterator, class _Sentinel>
928_LIBCPP_CONSTEXPR_SINCE_CXX20 void
929vector<_Tp, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
930 _ConstructTransaction __tx(*this, __n);
931 __tx.__pos_ = std::__uninitialized_allocator_copy(this->__alloc_, std::move(__first), std::move(__last), __tx.__pos_);
932}
933
934// Default constructs __n objects starting at __end_
935// throws if construction throws
936// Postcondition: size() == size() + __n
937// Exception safety: strong.
938template <class _Tp, class _Allocator>
939_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__append(size_type __n) {
940 if (static_cast<size_type>(this->__cap_ - this->__end_) >= __n)
941 this->__construct_at_end(__n);
942 else {
943 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), this->__alloc_);
944 __v.__construct_at_end(__n);
945 __swap_out_circular_buffer(__v);
946 }
947}
948
949// Default constructs __n objects starting at __end_
950// throws if construction throws
951// Postcondition: size() == size() + __n
952// Exception safety: strong.
953template <class _Tp, class _Allocator>
954_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) {
955 if (static_cast<size_type>(this->__cap_ - this->__end_) >= __n)
956 this->__construct_at_end(__n, __x);
957 else {
958 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), this->__alloc_);
959 __v.__construct_at_end(__n, __x);
960 __swap_out_circular_buffer(__v);
961 }
962}
963
964template <class _Tp, class _Allocator>
965_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(vector&& __x)
966#if _LIBCPP_STD_VER >= 17
967 noexcept
968#else
969 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
970#endif
971 : __alloc_(std::move(__x.__alloc_)) {
972 this->__begin_ = __x.__begin_;
973 this->__end_ = __x.__end_;
974 this->__cap_ = __x.__cap_;
975 __x.__begin_ = __x.__end_ = __x.__cap_ = nullptr;
976}
977
978template <class _Tp, class _Allocator>
979_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI
980vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
981 : __alloc_(__a) {
982 if (__a == __x.__alloc_) {
983 this->__begin_ = __x.__begin_;
984 this->__end_ = __x.__end_;
985 this->__cap_ = __x.__cap_;
986 __x.__begin_ = __x.__end_ = __x.__cap_ = nullptr;
987 } else {
988 typedef move_iterator<iterator> _Ip;
989 __init_with_size(_Ip(__x.begin()), _Ip(__x.end()), __x.size());
990 }
991}
992
993template <class _Tp, class _Allocator>
994_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
995 _NOEXCEPT_(__alloc_traits::is_always_equal::value) {
996 if (this->__alloc_ != __c.__alloc_) {
997 typedef move_iterator<iterator> _Ip;
998 assign(_Ip(__c.begin()), _Ip(__c.end()));
999 } else
1000 __move_assign(__c, true_type());
1001}
1002
1003template <class _Tp, class _Allocator>
1004_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
1005 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
1006 __vdeallocate();
1007 __move_assign_alloc(__c); // this can throw
1008 this->__begin_ = __c.__begin_;
1009 this->__end_ = __c.__end_;
1010 this->__cap_ = __c.__cap_;
1011 __c.__begin_ = __c.__end_ = __c.__cap_ = nullptr;
1012}
1013
1014template <class _Tp, class _Allocator>
1015_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>&
1016vector<_Tp, _Allocator>::operator=(const vector& __x) {
1017 if (this != std::addressof(__x)) {
1018 __copy_assign_alloc(__x);
1019 assign(__x.__begin_, __x.__end_);
1020 }
1021 return *this;
1022}
1023
1024template <class _Tp, class _Allocator>
1025template <class _Iterator, class _Sentinel>
1026_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
1027vector<_Tp, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __last) {
1028 pointer __cur = __begin_;
1029 for (; __first != __last && __cur != __end_; ++__first, (void)++__cur)
1030 *__cur = *__first;
1031 if (__cur != __end_) {
1032 __destruct_at_end(__cur);
1033 } else {
1034 for (; __first != __last; ++__first)
1035 emplace_back(*__first);
1036 }
1037}
1038
1039template <class _Tp, class _Allocator>
1040template <class _Iterator, class _Sentinel>
1041_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
1042vector<_Tp, _Allocator>::__assign_with_size(_Iterator __first, _Sentinel __last, difference_type __n) {
1043 size_type __new_size = static_cast<size_type>(__n);
1044 if (__new_size <= capacity()) {
1045 if (__new_size > size()) {
1046#if _LIBCPP_STD_VER >= 23
1047 auto __mid = ranges::copy_n(std::move(__first), size(), this->__begin_).in;
1048 __construct_at_end(std::move(__mid), std::move(__last), __new_size - size());
1049#else
1050 _Iterator __mid = std::next(__first, size());
1051 std::copy(__first, __mid, this->__begin_);
1052 __construct_at_end(__mid, __last, __new_size - size());
1053#endif
1054 } else {
1055 pointer __m = std::__copy(std::move(__first), __last, this->__begin_).second;
1056 this->__destruct_at_end(__m);
1057 }
1058 } else {
1059 __vdeallocate();
1060 __vallocate(__recommend(__new_size));
1061 __construct_at_end(std::move(__first), std::move(__last), __new_size);
1062 }
1063}
1064
1065template <class _Tp, class _Allocator>
1066_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) {
1067 if (__n <= capacity()) {
1068 size_type __s = size();
1069 std::fill_n(this->__begin_, std::min(__n, __s), __u);
1070 if (__n > __s)
1071 __construct_at_end(__n - __s, __u);
1072 else
1073 this->__destruct_at_end(this->__begin_ + __n);
1074 } else {
1075 __vdeallocate();
1076 __vallocate(__recommend(static_cast<size_type>(__n)));
1077 __construct_at_end(__n, __u);
1078 }
1079}
1080
1081template <class _Tp, class _Allocator>
1082_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::reserve(size_type __n) {
1083 if (__n > capacity()) {
1084 if (__n > max_size())
1085 this->__throw_length_error();
1086 __split_buffer<value_type, allocator_type&> __v(__n, size(), this->__alloc_);
1087 __swap_out_circular_buffer(__v);
1088 }
1089}
1090
1091template <class _Tp, class _Allocator>
1092_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT {
1093 if (capacity() > size()) {
1094#if _LIBCPP_HAS_EXCEPTIONS
1095 try {
1096#endif // _LIBCPP_HAS_EXCEPTIONS
1097 __split_buffer<value_type, allocator_type&> __v(size(), size(), this->__alloc_);
1098 // The Standard mandates shrink_to_fit() does not increase the capacity.
1099 // With equal capacity keep the existing buffer. This avoids extra work
1100 // due to swapping the elements.
1101 if (__v.capacity() < capacity())
1102 __swap_out_circular_buffer(__v);
1103#if _LIBCPP_HAS_EXCEPTIONS
1104 } catch (...) {
1105 }
1106#endif // _LIBCPP_HAS_EXCEPTIONS
1107 }
1108}
1109
1110template <class _Tp, class _Allocator>
1111template <class... _Args>
1112_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::pointer
1113vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) {
1114 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), this->__alloc_);
1115 // __v.emplace_back(std::forward<_Args>(__args)...);
1116 __alloc_traits::construct(this->__alloc_, std::__to_address(__v.__end_), std::forward<_Args>(__args)...);
1117 __v.__end_++;
1118 __swap_out_circular_buffer(__v);
1119 return this->__end_;
1120}
1121
1122template <class _Tp, class _Allocator>
1123template <class... _Args>
1124_LIBCPP_CONSTEXPR_SINCE_CXX20 inline
1125#if _LIBCPP_STD_VER >= 17
1126 typename vector<_Tp, _Allocator>::reference
1127#else
1128 void
1129#endif
1130 vector<_Tp, _Allocator>::emplace_back(_Args&&... __args) {
1131 pointer __end = this->__end_;
1132 if (__end < this->__cap_) {
1133 __construct_one_at_end(std::forward<_Args>(__args)...);
1134 ++__end;
1135 } else {
1136 __end = __emplace_back_slow_path(std::forward<_Args>(__args)...);
1137 }
1138 this->__end_ = __end;
1139#if _LIBCPP_STD_VER >= 17
1140 return *(__end - 1);
1141#endif
1142}
1143
1144template <class _Tp, class _Allocator>
1145_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator
1146vector<_Tp, _Allocator>::erase(const_iterator __position) {
1147 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
1148 __position != end(), "vector::erase(iterator) called with a non-dereferenceable iterator");
1149 difference_type __ps = __position - cbegin();
1150 pointer __p = this->__begin_ + __ps;
1151 this->__destruct_at_end(std::move(__p + 1, this->__end_, __p));
1152 return __make_iter(__p);
1153}
1154
1155template <class _Tp, class _Allocator>
1156_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1157vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) {
1158 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__first <= __last, "vector::erase(first, last) called with invalid range");
1159 pointer __p = this->__begin_ + (__first - begin());
1160 if (__first != __last) {
1161 this->__destruct_at_end(std::move(__p + (__last - __first), this->__end_, __p));
1162 }
1163 return __make_iter(__p);
1164}
1165
1166template <class _Tp, class _Allocator>
1167_LIBCPP_CONSTEXPR_SINCE_CXX20 void
1168vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) {
1169 pointer __old_last = this->__end_;
1170 difference_type __n = __old_last - __to;
1171 {
1172 pointer __i = __from_s + __n;
1173 _ConstructTransaction __tx(*this, __from_e - __i);
1174 for (pointer __pos = __tx.__pos_; __i < __from_e; ++__i, (void)++__pos, __tx.__pos_ = __pos) {
1175 __alloc_traits::construct(this->__alloc_, std::__to_address(__pos), std::move(*__i));
1176 }
1177 }
1178 std::move_backward(__from_s, __from_s + __n, __old_last);
1179}
1180
1181template <class _Tp, class _Allocator>
1182_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1183vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) {
1184 pointer __p = this->__begin_ + (__position - begin());
1185 if (this->__end_ < this->__cap_) {
1186 if (__p == this->__end_) {
1187 __construct_one_at_end(__x);
1188 } else {
1189 __move_range(__p, this->__end_, __p + 1);
1190 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1191 if (std::__is_pointer_in_range(std::__to_address(__p), std::__to_address(__end_), std::addressof(__x)))
1192 ++__xr;
1193 *__p = *__xr;
1194 }
1195 } else {
1196 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, this->__alloc_);
1197 __v.emplace_back(__x);
1198 __p = __swap_out_circular_buffer(__v, __p);
1199 }
1200 return __make_iter(__p);
1201}
1202
1203template <class _Tp, class _Allocator>
1204_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1205vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) {
1206 pointer __p = this->__begin_ + (__position - begin());
1207 if (this->__end_ < this->__cap_) {
1208 if (__p == this->__end_) {
1209 __construct_one_at_end(std::move(__x));
1210 } else {
1211 __move_range(__p, this->__end_, __p + 1);
1212 *__p = std::move(__x);
1213 }
1214 } else {
1215 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, this->__alloc_);
1216 __v.emplace_back(std::move(__x));
1217 __p = __swap_out_circular_buffer(__v, __p);
1218 }
1219 return __make_iter(__p);
1220}
1221
1222template <class _Tp, class _Allocator>
1223template <class... _Args>
1224_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1225vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) {
1226 pointer __p = this->__begin_ + (__position - begin());
1227 if (this->__end_ < this->__cap_) {
1228 if (__p == this->__end_) {
1229 __construct_one_at_end(std::forward<_Args>(__args)...);
1230 } else {
1231 __temp_value<value_type, _Allocator> __tmp(this->__alloc_, std::forward<_Args>(__args)...);
1232 __move_range(__p, this->__end_, __p + 1);
1233 *__p = std::move(__tmp.get());
1234 }
1235 } else {
1236 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, this->__alloc_);
1237 __v.emplace_back(std::forward<_Args>(__args)...);
1238 __p = __swap_out_circular_buffer(__v, __p);
1239 }
1240 return __make_iter(__p);
1241}
1242
1243template <class _Tp, class _Allocator>
1244_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1245vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) {
1246 pointer __p = this->__begin_ + (__position - begin());
1247 if (__n > 0) {
1248 // We can't compare unrelated pointers inside constant expressions
1249 if (!__libcpp_is_constant_evaluated() && __n <= static_cast<size_type>(this->__cap_ - this->__end_)) {
1250 size_type __old_n = __n;
1251 pointer __old_last = this->__end_;
1252 if (__n > static_cast<size_type>(this->__end_ - __p)) {
1253 size_type __cx = __n - (this->__end_ - __p);
1254 __construct_at_end(__cx, __x);
1255 __n -= __cx;
1256 }
1257 if (__n > 0) {
1258 __move_range(__p, __old_last, __p + __old_n);
1259 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1260 if (__p <= __xr && __xr < this->__end_)
1261 __xr += __old_n;
1262 std::fill_n(__p, __n, *__xr);
1263 }
1264 } else {
1265 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, this->__alloc_);
1266 __v.__construct_at_end(__n, __x);
1267 __p = __swap_out_circular_buffer(__v, __p);
1268 }
1269 }
1270 return __make_iter(__p);
1271}
1272
1273template <class _Tp, class _Allocator>
1274template <class _InputIterator, class _Sentinel>
1275_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator
1276vector<_Tp, _Allocator>::__insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last) {
1277 difference_type __off = __position - begin();
1278 pointer __p = this->__begin_ + __off;
1279 pointer __old_last = this->__end_;
1280 for (; this->__end_ != this->__cap_ && __first != __last; ++__first)
1281 __construct_one_at_end(*__first);
1282
1283 if (__first == __last)
1284 (void)std::rotate(__p, __old_last, this->__end_);
1285 else {
1286 __split_buffer<value_type, allocator_type&> __v(__alloc_);
1287 auto __guard = std::__make_exception_guard(
1288 _AllocatorDestroyRangeReverse<allocator_type, pointer>(__alloc_, __old_last, this->__end_));
1289 __v.__construct_at_end_with_sentinel(std::move(__first), std::move(__last));
1290 __split_buffer<value_type, allocator_type&> __merged(
1291 __recommend(size() + __v.size()), __off, __alloc_); // has `__off` positions available at the front
1292 std::__uninitialized_allocator_relocate(
1293 __alloc_, std::__to_address(__old_last), std::__to_address(this->__end_), std::__to_address(__merged.__end_));
1294 __guard.__complete(); // Release the guard once objects in [__old_last_, __end_) have been successfully relocated.
1295 __merged.__end_ += this->__end_ - __old_last;
1296 this->__end_ = __old_last;
1297 std::__uninitialized_allocator_relocate(
1298 __alloc_, std::__to_address(__v.__begin_), std::__to_address(__v.__end_), std::__to_address(__merged.__end_));
1299 __merged.__end_ += __v.size();
1300 __v.__end_ = __v.__begin_;
1301 __p = __swap_out_circular_buffer(__merged, __p);
1302 }
1303 return __make_iter(__p);
1304}
1305
1306template <class _Tp, class _Allocator>
1307template <class _Iterator, class _Sentinel>
1308_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator
1309vector<_Tp, _Allocator>::__insert_with_size(
1310 const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n) {
1311 pointer __p = this->__begin_ + (__position - begin());
1312 if (__n > 0) {
1313 if (__n <= this->__cap_ - this->__end_) {
1314 pointer __old_last = this->__end_;
1315 difference_type __dx = this->__end_ - __p;
1316 if (__n > __dx) {
1317#if _LIBCPP_STD_VER >= 23
1318 if constexpr (!forward_iterator<_Iterator>) {
1319 __construct_at_end(std::move(__first), std::move(__last), __n);
1320 std::rotate(__p, __old_last, this->__end_);
1321 } else
1322#endif
1323 {
1324 _Iterator __m = std::next(__first, __dx);
1325 __construct_at_end(__m, __last, __n - __dx);
1326 if (__dx > 0) {
1327 __move_range(__p, __old_last, __p + __n);
1328 std::copy(__first, __m, __p);
1329 }
1330 }
1331 } else {
1332 __move_range(__p, __old_last, __p + __n);
1333#if _LIBCPP_STD_VER >= 23
1334 if constexpr (!forward_iterator<_Iterator>) {
1335 ranges::copy_n(std::move(__first), __n, __p);
1336 } else
1337#endif
1338 {
1339 std::copy_n(__first, __n, __p);
1340 }
1341 }
1342 } else {
1343 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, this->__alloc_);
1344 __v.__construct_at_end_with_size(std::move(__first), __n);
1345 __p = __swap_out_circular_buffer(__v, __p);
1346 }
1347 }
1348 return __make_iter(__p);
1349}
1350
1351template <class _Tp, class _Allocator>
1352_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::resize(size_type __sz) {
1353 size_type __cs = size();
1354 if (__cs < __sz)
1355 this->__append(__sz - __cs);
1356 else if (__cs > __sz)
1357 this->__destruct_at_end(this->__begin_ + __sz);
1358}
1359
1360template <class _Tp, class _Allocator>
1361_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x) {
1362 size_type __cs = size();
1363 if (__cs < __sz)
1364 this->__append(__sz - __cs, __x);
1365 else if (__cs > __sz)
1366 this->__destruct_at_end(this->__begin_ + __sz);
1367}
1368
1369template <class _Tp, class _Allocator>
1370_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::swap(vector& __x)
1371#if _LIBCPP_STD_VER >= 14
1372 _NOEXCEPT
1373#else
1374 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>)
1375#endif
1376{
1377 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1378 __alloc_traits::propagate_on_container_swap::value || this->__alloc_ == __x.__alloc_,
1379 "vector::swap: Either propagate_on_container_swap must be true"
1380 " or the allocators must compare equal");
1381 std::swap(this->__begin_, __x.__begin_);
1382 std::swap(this->__end_, __x.__end_);
1383 std::swap(this->__cap_, __x.__cap_);
1384 std::__swap_allocator(this->__alloc_, __x.__alloc_);
1385}
1386
1387template <class _Tp, class _Allocator>
1388_LIBCPP_CONSTEXPR_SINCE_CXX20 bool vector<_Tp, _Allocator>::__invariants() const {
1389 if (this->__begin_ == nullptr) {
1390 if (this->__end_ != nullptr || this->__cap_ != nullptr)
1391 return false;
1392 } else {
1393 if (this->__begin_ > this->__end_)
1394 return false;
1395 if (this->__begin_ == this->__cap_)
1396 return false;
1397 if (this->__end_ > this->__cap_)
1398 return false;
1399 }
1400 return true;
1401}
1402
1403#if _LIBCPP_STD_VER >= 20
1404template <>
1405inline constexpr bool __format::__enable_insertable<vector<char>> = true;
1406# if _LIBCPP_HAS_WIDE_CHARACTERS
1407template <>
1408inline constexpr bool __format::__enable_insertable<vector<wchar_t>> = true;
1409# endif
1410#endif // _LIBCPP_STD_VER >= 20
1411
1412_LIBCPP_END_NAMESPACE_STD
1413
1414_LIBCPP_POP_MACROS
1415
1416#endif // _LIBCPP___VECTOR_VECTOR_H
lib/libcxx/include/__vector/vector_bool.h created+1131
......@@ -0,0 +1,1131 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___VECTOR_VECTOR_BOOL_H
10#define _LIBCPP___VECTOR_VECTOR_BOOL_H
11
12#include <__algorithm/copy.h>
13#include <__algorithm/fill_n.h>
14#include <__algorithm/iterator_operations.h>
15#include <__algorithm/max.h>
16#include <__assert>
17#include <__bit_reference>
18#include <__config>
19#include <__functional/unary_function.h>
20#include <__fwd/bit_reference.h>
21#include <__fwd/functional.h>
22#include <__fwd/vector.h>
23#include <__iterator/distance.h>
24#include <__iterator/iterator_traits.h>
25#include <__iterator/reverse_iterator.h>
26#include <__memory/addressof.h>
27#include <__memory/allocate_at_least.h>
28#include <__memory/allocator.h>
29#include <__memory/allocator_traits.h>
30#include <__memory/compressed_pair.h>
31#include <__memory/construct_at.h>
32#include <__memory/noexcept_move_assign_container.h>
33#include <__memory/pointer_traits.h>
34#include <__memory/swap_allocator.h>
35#include <__ranges/access.h>
36#include <__ranges/concepts.h>
37#include <__ranges/container_compatible_range.h>
38#include <__ranges/from_range.h>
39#include <__type_traits/enable_if.h>
40#include <__type_traits/is_constant_evaluated.h>
41#include <__type_traits/is_nothrow_assignable.h>
42#include <__type_traits/is_nothrow_constructible.h>
43#include <__type_traits/type_identity.h>
44#include <__utility/exception_guard.h>
45#include <__utility/forward.h>
46#include <__utility/move.h>
47#include <__utility/swap.h>
48#include <climits>
49#include <initializer_list>
50#include <limits>
51#include <stdexcept>
52
53// These headers define parts of vectors definition, since they define ADL functions or class specializations.
54#include <__vector/comparison.h>
55#include <__vector/container_traits.h>
56#include <__vector/swap.h>
57
58#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
59# pragma GCC system_header
60#endif
61
62_LIBCPP_PUSH_MACROS
63#include <__undef_macros>
64
65_LIBCPP_BEGIN_NAMESPACE_STD
66
67template <class _Allocator>
68struct hash<vector<bool, _Allocator> >;
69
70template <class _Allocator>
71struct __has_storage_type<vector<bool, _Allocator> > {
72 static const bool value = true;
73};
74
75template <class _Allocator>
76class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> {
77public:
78 typedef vector __self;
79 typedef bool value_type;
80 typedef _Allocator allocator_type;
81 typedef allocator_traits<allocator_type> __alloc_traits;
82 typedef typename __alloc_traits::size_type size_type;
83 typedef typename __alloc_traits::difference_type difference_type;
84 typedef size_type __storage_type;
85 typedef __bit_iterator<vector, false> pointer;
86 typedef __bit_iterator<vector, true> const_pointer;
87 typedef pointer iterator;
88 typedef const_pointer const_iterator;
89 typedef std::reverse_iterator<iterator> reverse_iterator;
90 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
91
92private:
93 typedef __rebind_alloc<__alloc_traits, __storage_type> __storage_allocator;
94 typedef allocator_traits<__storage_allocator> __storage_traits;
95 typedef typename __storage_traits::pointer __storage_pointer;
96 typedef typename __storage_traits::const_pointer __const_storage_pointer;
97
98 __storage_pointer __begin_;
99 size_type __size_;
100 _LIBCPP_COMPRESSED_PAIR(size_type, __cap_, __storage_allocator, __alloc_);
101
102public:
103 typedef __bit_reference<vector> reference;
104#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
105 using const_reference = bool;
106#else
107 typedef __bit_const_reference<vector> const_reference;
108#endif
109
110private:
111 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
112
113 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type
114 __internal_cap_to_external(size_type __n) _NOEXCEPT {
115 return __n * __bits_per_word;
116 }
117 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type
118 __external_cap_to_internal(size_type __n) _NOEXCEPT {
119 return __n > 0 ? (__n - 1) / __bits_per_word + 1 : size_type(0);
120 }
121
122public:
123 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector()
124 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
125
126 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(const allocator_type& __a)
127#if _LIBCPP_STD_VER <= 14
128 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
129#else
130 _NOEXCEPT;
131#endif
132
133private:
134 class __destroy_vector {
135 public:
136 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __destroy_vector(vector& __vec) : __vec_(__vec) {}
137
138 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() {
139 if (__vec_.__begin_ != nullptr)
140 __storage_traits::deallocate(__vec_.__alloc_, __vec_.__begin_, __vec_.__cap_);
141 }
142
143 private:
144 vector& __vec_;
145 };
146
147public:
148 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~vector() { __destroy_vector (*this)(); }
149
150 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n);
151#if _LIBCPP_STD_VER >= 14
152 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n, const allocator_type& __a);
153#endif
154 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(size_type __n, const value_type& __v);
155 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
156 vector(size_type __n, const value_type& __v, const allocator_type& __a);
157 template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
158 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_InputIterator __first, _InputIterator __last);
159 template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
160 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
161 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
162 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
163 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_ForwardIterator __first, _ForwardIterator __last);
164 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
165 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
166 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a);
167
168#if _LIBCPP_STD_VER >= 23
169 template <_ContainerCompatibleRange<bool> _Range>
170 _LIBCPP_HIDE_FROM_ABI constexpr vector(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
171 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) {
172 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
173 auto __n = static_cast<size_type>(ranges::distance(__range));
174 __init_with_size(ranges::begin(__range), ranges::end(__range), __n);
175
176 } else {
177 __init_with_sentinel(ranges::begin(__range), ranges::end(__range));
178 }
179 }
180#endif
181
182 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v);
183 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v, const allocator_type& __a);
184 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(const vector& __v);
185
186#ifndef _LIBCPP_CXX03_LANG
187 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(initializer_list<value_type> __il);
188 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
189 vector(initializer_list<value_type> __il, const allocator_type& __a);
190
191 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(initializer_list<value_type> __il) {
192 assign(__il.begin(), __il.end());
193 return *this;
194 }
195
196#endif // !_LIBCPP_CXX03_LANG
197
198 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(vector&& __v)
199#if _LIBCPP_STD_VER >= 17
200 noexcept;
201#else
202 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
203#endif
204 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
205 vector(vector&& __v, const __type_identity_t<allocator_type>& __a);
206 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(vector&& __v)
207 _NOEXCEPT_(__noexcept_move_assign_container<_Allocator, __alloc_traits>::value);
208
209 template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
210 void _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_InputIterator __first, _InputIterator __last);
211 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
212 void _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_ForwardIterator __first, _ForwardIterator __last);
213
214#if _LIBCPP_STD_VER >= 23
215 template <_ContainerCompatibleRange<bool> _Range>
216 _LIBCPP_HIDE_FROM_ABI constexpr void assign_range(_Range&& __range) {
217 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
218 auto __n = static_cast<size_type>(ranges::distance(__range));
219 __assign_with_size(ranges::begin(__range), ranges::end(__range), __n);
220
221 } else {
222 __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
223 }
224 }
225#endif
226
227 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void assign(size_type __n, const value_type& __x);
228
229#ifndef _LIBCPP_CXX03_LANG
230 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void assign(initializer_list<value_type> __il) {
231 assign(__il.begin(), __il.end());
232 }
233#endif
234
235 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator_type get_allocator() const _NOEXCEPT {
236 return allocator_type(this->__alloc_);
237 }
238
239 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT;
240 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type capacity() const _NOEXCEPT {
241 return __internal_cap_to_external(__cap_);
242 }
243 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type size() const _NOEXCEPT { return __size_; }
244 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool empty() const _NOEXCEPT {
245 return __size_ == 0;
246 }
247 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void reserve(size_type __n);
248 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT;
249
250 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator begin() _NOEXCEPT { return __make_iter(0); }
251 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator begin() const _NOEXCEPT { return __make_iter(0); }
252 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator end() _NOEXCEPT { return __make_iter(__size_); }
253 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator end() const _NOEXCEPT {
254 return __make_iter(__size_);
255 }
256
257 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator rbegin() _NOEXCEPT {
258 return reverse_iterator(end());
259 }
260 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator rbegin() const _NOEXCEPT {
261 return const_reverse_iterator(end());
262 }
263 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator rend() _NOEXCEPT {
264 return reverse_iterator(begin());
265 }
266 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator rend() const _NOEXCEPT {
267 return const_reverse_iterator(begin());
268 }
269
270 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator cbegin() const _NOEXCEPT { return __make_iter(0); }
271 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator cend() const _NOEXCEPT {
272 return __make_iter(__size_);
273 }
274 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator crbegin() const _NOEXCEPT {
275 return rbegin();
276 }
277 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
278
279 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator[](size_type __n) {
280 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector<bool>::operator[] index out of bounds");
281 return __make_ref(__n);
282 }
283 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference operator[](size_type __n) const {
284 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector<bool>::operator[] index out of bounds");
285 return __make_ref(__n);
286 }
287 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference at(size_type __n);
288 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference at(size_type __n) const;
289
290 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference front() {
291 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector<bool>::front() called on an empty vector");
292 return __make_ref(0);
293 }
294 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front() const {
295 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector<bool>::front() called on an empty vector");
296 return __make_ref(0);
297 }
298 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference back() {
299 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector<bool>::back() called on an empty vector");
300 return __make_ref(__size_ - 1);
301 }
302 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference back() const {
303 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector<bool>::back() called on an empty vector");
304 return __make_ref(__size_ - 1);
305 }
306
307 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(const value_type& __x);
308#if _LIBCPP_STD_VER >= 14
309 template <class... _Args>
310# if _LIBCPP_STD_VER >= 17
311 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference emplace_back(_Args&&... __args)
312# else
313 _LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args)
314# endif
315 {
316 push_back(value_type(std::forward<_Args>(__args)...));
317# if _LIBCPP_STD_VER >= 17
318 return this->back();
319# endif
320 }
321#endif
322
323#if _LIBCPP_STD_VER >= 23
324 template <_ContainerCompatibleRange<bool> _Range>
325 _LIBCPP_HIDE_FROM_ABI constexpr void append_range(_Range&& __range) {
326 insert_range(end(), std::forward<_Range>(__range));
327 }
328#endif
329
330 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back() {
331 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector<bool>::pop_back called on an empty vector");
332 --__size_;
333 }
334
335#if _LIBCPP_STD_VER >= 14
336 template <class... _Args>
337 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator emplace(const_iterator __position, _Args&&... __args) {
338 return insert(__position, value_type(std::forward<_Args>(__args)...));
339 }
340#endif
341
342 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, const value_type& __x);
343 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
344 insert(const_iterator __position, size_type __n, const value_type& __x);
345 template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
346 iterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
347 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
348 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
349 iterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
350 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
351
352#if _LIBCPP_STD_VER >= 23
353 template <_ContainerCompatibleRange<bool> _Range>
354 _LIBCPP_HIDE_FROM_ABI constexpr iterator insert_range(const_iterator __position, _Range&& __range) {
355 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
356 auto __n = static_cast<size_type>(ranges::distance(__range));
357 return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n);
358
359 } else {
360 return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
361 }
362 }
363#endif
364
365#ifndef _LIBCPP_CXX03_LANG
366 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
367 insert(const_iterator __position, initializer_list<value_type> __il) {
368 return insert(__position, __il.begin(), __il.end());
369 }
370#endif
371
372 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __position);
373 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __first, const_iterator __last);
374
375 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void clear() _NOEXCEPT { __size_ = 0; }
376
377 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(vector&)
378#if _LIBCPP_STD_VER >= 14
379 _NOEXCEPT;
380#else
381 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>);
382#endif
383 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void swap(reference __x, reference __y) _NOEXCEPT {
384 std::swap(__x, __y);
385 }
386
387 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __sz, value_type __x = false);
388 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void flip() _NOEXCEPT;
389
390 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const;
391
392private:
393 [[__noreturn__]] _LIBCPP_HIDE_FROM_ABI static void __throw_length_error() { std::__throw_length_error("vector"); }
394
395 [[__noreturn__]] _LIBCPP_HIDE_FROM_ABI static void __throw_out_of_range() { std::__throw_out_of_range("vector"); }
396
397 template <class _InputIterator, class _Sentinel>
398 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
399 __init_with_size(_InputIterator __first, _Sentinel __last, size_type __n) {
400 auto __guard = std::__make_exception_guard(__destroy_vector(*this));
401
402 if (__n > 0) {
403 __vallocate(__n);
404 __construct_at_end(std::move(__first), std::move(__last), __n);
405 }
406
407 __guard.__complete();
408 }
409
410 template <class _InputIterator, class _Sentinel>
411 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
412 __init_with_sentinel(_InputIterator __first, _Sentinel __last) {
413 auto __guard = std::__make_exception_guard(__destroy_vector(*this));
414
415 for (; __first != __last; ++__first)
416 push_back(*__first);
417
418 __guard.__complete();
419 }
420
421 template <class _Iterator, class _Sentinel>
422 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iterator __first, _Sentinel __last);
423
424 // The `_Iterator` in `*_with_size` functions can be input-only only if called from `*_range` (since C++23).
425 // Otherwise, `_Iterator` is a forward iterator.
426
427 template <class _Iterator, class _Sentinel>
428 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
429 __assign_with_size(_Iterator __first, _Sentinel __last, difference_type __ns);
430
431 template <class _InputIterator, class _Sentinel>
432 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
433 __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last);
434
435 template <class _Iterator, class _Sentinel>
436 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
437 __insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n);
438
439 // Allocate space for __n objects
440 // throws length_error if __n > max_size()
441 // throws (probably bad_alloc) if memory run out
442 // Precondition: __begin_ == __end_ == __cap_ == nullptr
443 // Precondition: __n > 0
444 // Postcondition: capacity() >= __n
445 // Postcondition: size() == 0
446 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vallocate(size_type __n) {
447 if (__n > max_size())
448 __throw_length_error();
449 auto __allocation = std::__allocate_at_least(__alloc_, __external_cap_to_internal(__n));
450 __begin_ = __allocation.ptr;
451 __size_ = 0;
452 __cap_ = __allocation.count;
453 if (__libcpp_is_constant_evaluated()) {
454 for (size_type __i = 0; __i != __cap_; ++__i)
455 std::__construct_at(std::__to_address(__begin_) + __i);
456 }
457 }
458
459 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vdeallocate() _NOEXCEPT;
460 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type __align_it(size_type __new_size) _NOEXCEPT {
461 return (__new_size + (__bits_per_word - 1)) & ~((size_type)__bits_per_word - 1);
462 }
463 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __recommend(size_type __new_size) const;
464 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __construct_at_end(size_type __n, bool __x);
465 template <class _InputIterator, class _Sentinel>
466 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
467 __construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n);
468 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference __make_ref(size_type __pos) _NOEXCEPT {
469 return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
470 }
471 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference __make_ref(size_type __pos) const _NOEXCEPT {
472 return __bit_const_reference<vector>(
473 __begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
474 }
475 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator __make_iter(size_type __pos) _NOEXCEPT {
476 return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));
477 }
478 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator __make_iter(size_type __pos) const _NOEXCEPT {
479 return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));
480 }
481 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT {
482 return begin() + (__p - cbegin());
483 }
484
485 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __copy_assign_alloc(const vector& __v) {
486 __copy_assign_alloc(
487 __v, integral_constant<bool, __storage_traits::propagate_on_container_copy_assignment::value>());
488 }
489 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __copy_assign_alloc(const vector& __c, true_type) {
490 if (__alloc_ != __c.__alloc_)
491 __vdeallocate();
492 __alloc_ = __c.__alloc_;
493 }
494
495 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __copy_assign_alloc(const vector&, false_type) {}
496
497 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, false_type);
498 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, true_type)
499 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
500 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(vector& __c)
501 _NOEXCEPT_(!__storage_traits::propagate_on_container_move_assignment::value ||
502 is_nothrow_move_assignable<allocator_type>::value) {
503 __move_assign_alloc(
504 __c, integral_constant<bool, __storage_traits::propagate_on_container_move_assignment::value>());
505 }
506 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(vector& __c, true_type)
507 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
508 __alloc_ = std::move(__c.__alloc_);
509 }
510
511 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(vector&, false_type) _NOEXCEPT {}
512
513 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t __hash_code() const _NOEXCEPT;
514
515 friend class __bit_reference<vector>;
516 friend class __bit_const_reference<vector>;
517 friend class __bit_iterator<vector, false>;
518 friend class __bit_iterator<vector, true>;
519 friend struct __bit_array<vector>;
520 friend struct _LIBCPP_TEMPLATE_VIS hash<vector>;
521};
522
523template <class _Allocator>
524_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::__vdeallocate() _NOEXCEPT {
525 if (this->__begin_ != nullptr) {
526 __storage_traits::deallocate(this->__alloc_, this->__begin_, __cap_);
527 this->__begin_ = nullptr;
528 this->__size_ = this->__cap_ = 0;
529 }
530}
531
532template <class _Allocator>
533_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::size_type
534vector<bool, _Allocator>::max_size() const _NOEXCEPT {
535 size_type __amax = __storage_traits::max_size(__alloc_);
536 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
537 if (__nmax / __bits_per_word <= __amax)
538 return __nmax;
539 return __internal_cap_to_external(__amax);
540}
541
542// Precondition: __new_size > capacity()
543template <class _Allocator>
544inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::size_type
545vector<bool, _Allocator>::__recommend(size_type __new_size) const {
546 const size_type __ms = max_size();
547 if (__new_size > __ms)
548 this->__throw_length_error();
549 const size_type __cap = capacity();
550 if (__cap >= __ms / 2)
551 return __ms;
552 return std::max(2 * __cap, __align_it(__new_size));
553}
554
555// Default constructs __n objects starting at __end_
556// Precondition: __n > 0
557// Precondition: size() + __n <= capacity()
558// Postcondition: size() == size() + __n
559template <class _Allocator>
560inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
561vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) {
562 size_type __old_size = this->__size_;
563 this->__size_ += __n;
564 if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) {
565 if (this->__size_ <= __bits_per_word)
566 this->__begin_[0] = __storage_type(0);
567 else
568 this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
569 }
570 std::fill_n(__make_iter(__old_size), __n, __x);
571}
572
573template <class _Allocator>
574template <class _InputIterator, class _Sentinel>
575_LIBCPP_CONSTEXPR_SINCE_CXX20 void
576vector<bool, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
577 size_type __old_size = this->__size_;
578 this->__size_ += __n;
579 if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) {
580 if (this->__size_ <= __bits_per_word)
581 this->__begin_[0] = __storage_type(0);
582 else
583 this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
584 }
585 std::__copy(std::move(__first), std::move(__last), __make_iter(__old_size));
586}
587
588template <class _Allocator>
589inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector()
590 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
591 : __begin_(nullptr), __size_(0), __cap_(0) {}
592
593template <class _Allocator>
594inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(const allocator_type& __a)
595#if _LIBCPP_STD_VER <= 14
596 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
597#else
598 _NOEXCEPT
599#endif
600 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) {
601}
602
603template <class _Allocator>
604_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(size_type __n)
605 : __begin_(nullptr), __size_(0), __cap_(0) {
606 if (__n > 0) {
607 __vallocate(__n);
608 __construct_at_end(__n, false);
609 }
610}
611
612#if _LIBCPP_STD_VER >= 14
613template <class _Allocator>
614_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
615 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) {
616 if (__n > 0) {
617 __vallocate(__n);
618 __construct_at_end(__n, false);
619 }
620}
621#endif
622
623template <class _Allocator>
624_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
625 : __begin_(nullptr), __size_(0), __cap_(0) {
626 if (__n > 0) {
627 __vallocate(__n);
628 __construct_at_end(__n, __x);
629 }
630}
631
632template <class _Allocator>
633_LIBCPP_CONSTEXPR_SINCE_CXX20
634vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
635 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) {
636 if (__n > 0) {
637 __vallocate(__n);
638 __construct_at_end(__n, __x);
639 }
640}
641
642template <class _Allocator>
643template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
644_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last)
645 : __begin_(nullptr), __size_(0), __cap_(0) {
646 __init_with_sentinel(__first, __last);
647}
648
649template <class _Allocator>
650template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
651_LIBCPP_CONSTEXPR_SINCE_CXX20
652vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a)
653 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) {
654 __init_with_sentinel(__first, __last);
655}
656
657template <class _Allocator>
658template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
659_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last)
660 : __begin_(nullptr), __size_(0), __cap_(0) {
661 auto __n = static_cast<size_type>(std::distance(__first, __last));
662 __init_with_size(__first, __last, __n);
663}
664
665template <class _Allocator>
666template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
667_LIBCPP_CONSTEXPR_SINCE_CXX20
668vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a)
669 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) {
670 auto __n = static_cast<size_type>(std::distance(__first, __last));
671 __init_with_size(__first, __last, __n);
672}
673
674#ifndef _LIBCPP_CXX03_LANG
675
676template <class _Allocator>
677_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
678 : __begin_(nullptr), __size_(0), __cap_(0) {
679 size_type __n = static_cast<size_type>(__il.size());
680 if (__n > 0) {
681 __vallocate(__n);
682 __construct_at_end(__il.begin(), __il.end(), __n);
683 }
684}
685
686template <class _Allocator>
687_LIBCPP_CONSTEXPR_SINCE_CXX20
688vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
689 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) {
690 size_type __n = static_cast<size_type>(__il.size());
691 if (__n > 0) {
692 __vallocate(__n);
693 __construct_at_end(__il.begin(), __il.end(), __n);
694 }
695}
696
697#endif // _LIBCPP_CXX03_LANG
698
699template <class _Allocator>
700_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(const vector& __v)
701 : __begin_(nullptr),
702 __size_(0),
703 __cap_(0),
704 __alloc_(__storage_traits::select_on_container_copy_construction(__v.__alloc_)) {
705 if (__v.size() > 0) {
706 __vallocate(__v.size());
707 __construct_at_end(__v.begin(), __v.end(), __v.size());
708 }
709}
710
711template <class _Allocator>
712_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
713 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(__a) {
714 if (__v.size() > 0) {
715 __vallocate(__v.size());
716 __construct_at_end(__v.begin(), __v.end(), __v.size());
717 }
718}
719
720template <class _Allocator>
721_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>& vector<bool, _Allocator>::operator=(const vector& __v) {
722 if (this != std::addressof(__v)) {
723 __copy_assign_alloc(__v);
724 if (__v.__size_) {
725 if (__v.__size_ > capacity()) {
726 __vdeallocate();
727 __vallocate(__v.__size_);
728 }
729 std::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
730 }
731 __size_ = __v.__size_;
732 }
733 return *this;
734}
735
736template <class _Allocator>
737inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(vector&& __v)
738#if _LIBCPP_STD_VER >= 17
739 _NOEXCEPT
740#else
741 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
742#endif
743 : __begin_(__v.__begin_),
744 __size_(__v.__size_),
745 __cap_(__v.__cap_),
746 __alloc_(std::move(__v.__alloc_)) {
747 __v.__begin_ = nullptr;
748 __v.__size_ = 0;
749 __v.__cap_ = 0;
750}
751
752template <class _Allocator>
753_LIBCPP_CONSTEXPR_SINCE_CXX20
754vector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a)
755 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(__a) {
756 if (__a == allocator_type(__v.__alloc_)) {
757 this->__begin_ = __v.__begin_;
758 this->__size_ = __v.__size_;
759 this->__cap_ = __v.__cap_;
760 __v.__begin_ = nullptr;
761 __v.__cap_ = __v.__size_ = 0;
762 } else if (__v.size() > 0) {
763 __vallocate(__v.size());
764 __construct_at_end(__v.begin(), __v.end(), __v.size());
765 }
766}
767
768template <class _Allocator>
769inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>&
770vector<bool, _Allocator>::operator=(vector&& __v)
771 _NOEXCEPT_(__noexcept_move_assign_container<_Allocator, __alloc_traits>::value) {
772 __move_assign(__v, integral_constant<bool, __storage_traits::propagate_on_container_move_assignment::value>());
773 return *this;
774}
775
776template <class _Allocator>
777_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::__move_assign(vector& __c, false_type) {
778 if (__alloc_ != __c.__alloc_)
779 assign(__c.begin(), __c.end());
780 else
781 __move_assign(__c, true_type());
782}
783
784template <class _Allocator>
785_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
786 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
787 __vdeallocate();
788 __move_assign_alloc(__c);
789 this->__begin_ = __c.__begin_;
790 this->__size_ = __c.__size_;
791 this->__cap_ = __c.__cap_;
792 __c.__begin_ = nullptr;
793 __c.__cap_ = __c.__size_ = 0;
794}
795
796template <class _Allocator>
797_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::assign(size_type __n, const value_type& __x) {
798 __size_ = 0;
799 if (__n > 0) {
800 size_type __c = capacity();
801 if (__n <= __c)
802 __size_ = __n;
803 else {
804 vector __v(get_allocator());
805 __v.reserve(__recommend(__n));
806 __v.__size_ = __n;
807 swap(__v);
808 }
809 std::fill_n(begin(), __n, __x);
810 }
811}
812
813template <class _Allocator>
814template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
815_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last) {
816 __assign_with_sentinel(__first, __last);
817}
818
819template <class _Allocator>
820template <class _Iterator, class _Sentinel>
821_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
822vector<bool, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __last) {
823 clear();
824 for (; __first != __last; ++__first)
825 push_back(*__first);
826}
827
828template <class _Allocator>
829template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
830_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) {
831 __assign_with_size(__first, __last, std::distance(__first, __last));
832}
833
834template <class _Allocator>
835template <class _Iterator, class _Sentinel>
836_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
837vector<bool, _Allocator>::__assign_with_size(_Iterator __first, _Sentinel __last, difference_type __ns) {
838 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__ns >= 0, "invalid range specified");
839
840 clear();
841
842 const size_t __n = static_cast<size_type>(__ns);
843 if (__n) {
844 if (__n > capacity()) {
845 __vdeallocate();
846 __vallocate(__n);
847 }
848 __construct_at_end(std::move(__first), std::move(__last), __n);
849 }
850}
851
852template <class _Allocator>
853_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::reserve(size_type __n) {
854 if (__n > capacity()) {
855 if (__n > max_size())
856 this->__throw_length_error();
857 vector __v(this->get_allocator());
858 __v.__vallocate(__n);
859 __v.__construct_at_end(this->begin(), this->end(), this->size());
860 swap(__v);
861 }
862}
863
864template <class _Allocator>
865_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT {
866 if (__external_cap_to_internal(size()) < __cap_) {
867#if _LIBCPP_HAS_EXCEPTIONS
868 try {
869#endif // _LIBCPP_HAS_EXCEPTIONS
870 vector __v(*this, allocator_type(__alloc_));
871 if (__v.__cap_ < __cap_)
872 __v.swap(*this);
873#if _LIBCPP_HAS_EXCEPTIONS
874 } catch (...) {
875 }
876#endif // _LIBCPP_HAS_EXCEPTIONS
877 }
878}
879
880template <class _Allocator>
881_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::reference vector<bool, _Allocator>::at(size_type __n) {
882 if (__n >= size())
883 this->__throw_out_of_range();
884 return (*this)[__n];
885}
886
887template <class _Allocator>
888_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::const_reference
889vector<bool, _Allocator>::at(size_type __n) const {
890 if (__n >= size())
891 this->__throw_out_of_range();
892 return (*this)[__n];
893}
894
895template <class _Allocator>
896_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::push_back(const value_type& __x) {
897 if (this->__size_ == this->capacity())
898 reserve(__recommend(this->__size_ + 1));
899 ++this->__size_;
900 back() = __x;
901}
902
903template <class _Allocator>
904_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
905vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x) {
906 iterator __r;
907 if (size() < capacity()) {
908 const_iterator __old_end = end();
909 ++__size_;
910 std::copy_backward(__position, __old_end, end());
911 __r = __const_iterator_cast(__position);
912 } else {
913 vector __v(get_allocator());
914 __v.reserve(__recommend(__size_ + 1));
915 __v.__size_ = __size_ + 1;
916 __r = std::copy(cbegin(), __position, __v.begin());
917 std::copy_backward(__position, cend(), __v.end());
918 swap(__v);
919 }
920 *__r = __x;
921 return __r;
922}
923
924template <class _Allocator>
925_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
926vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x) {
927 iterator __r;
928 size_type __c = capacity();
929 if (__n <= __c && size() <= __c - __n) {
930 const_iterator __old_end = end();
931 __size_ += __n;
932 std::copy_backward(__position, __old_end, end());
933 __r = __const_iterator_cast(__position);
934 } else {
935 vector __v(get_allocator());
936 __v.reserve(__recommend(__size_ + __n));
937 __v.__size_ = __size_ + __n;
938 __r = std::copy(cbegin(), __position, __v.begin());
939 std::copy_backward(__position, cend(), __v.end());
940 swap(__v);
941 }
942 std::fill_n(__r, __n, __x);
943 return __r;
944}
945
946template <class _Allocator>
947template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
948_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
949vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) {
950 return __insert_with_sentinel(__position, __first, __last);
951}
952
953template <class _Allocator>
954template <class _InputIterator, class _Sentinel>
955_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<bool, _Allocator>::iterator
956vector<bool, _Allocator>::__insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last) {
957 difference_type __off = __position - begin();
958 iterator __p = __const_iterator_cast(__position);
959 iterator __old_end = end();
960 for (; size() != capacity() && __first != __last; ++__first) {
961 ++this->__size_;
962 back() = *__first;
963 }
964 vector __v(get_allocator());
965 if (__first != __last) {
966#if _LIBCPP_HAS_EXCEPTIONS
967 try {
968#endif // _LIBCPP_HAS_EXCEPTIONS
969 __v.__assign_with_sentinel(std::move(__first), std::move(__last));
970 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
971 difference_type __old_p = __p - begin();
972 reserve(__recommend(size() + __v.size()));
973 __p = begin() + __old_p;
974 __old_end = begin() + __old_size;
975#if _LIBCPP_HAS_EXCEPTIONS
976 } catch (...) {
977 erase(__old_end, end());
978 throw;
979 }
980#endif // _LIBCPP_HAS_EXCEPTIONS
981 }
982 __p = std::rotate(__p, __old_end, end());
983 insert(__p, __v.begin(), __v.end());
984 return begin() + __off;
985}
986
987template <class _Allocator>
988template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
989_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
990vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) {
991 return __insert_with_size(__position, __first, __last, std::distance(__first, __last));
992}
993
994template <class _Allocator>
995template <class _Iterator, class _Sentinel>
996_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<bool, _Allocator>::iterator
997vector<bool, _Allocator>::__insert_with_size(
998 const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n_signed) {
999 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__n_signed >= 0, "invalid range specified");
1000 const size_type __n = static_cast<size_type>(__n_signed);
1001 iterator __r;
1002 size_type __c = capacity();
1003 if (__n <= __c && size() <= __c - __n) {
1004 const_iterator __old_end = end();
1005 __size_ += __n;
1006 std::copy_backward(__position, __old_end, end());
1007 __r = __const_iterator_cast(__position);
1008 } else {
1009 vector __v(get_allocator());
1010 __v.reserve(__recommend(__size_ + __n));
1011 __v.__size_ = __size_ + __n;
1012 __r = std::copy(cbegin(), __position, __v.begin());
1013 std::copy_backward(__position, cend(), __v.end());
1014 swap(__v);
1015 }
1016 std::__copy(std::move(__first), std::move(__last), __r);
1017 return __r;
1018}
1019
1020template <class _Allocator>
1021inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
1022vector<bool, _Allocator>::erase(const_iterator __position) {
1023 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
1024 __position != end(), "vector<bool>::erase(iterator) called with a non-dereferenceable iterator");
1025 iterator __r = __const_iterator_cast(__position);
1026 std::copy(__position + 1, this->cend(), __r);
1027 --__size_;
1028 return __r;
1029}
1030
1031template <class _Allocator>
1032_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
1033vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last) {
1034 _LIBCPP_ASSERT_VALID_INPUT_RANGE(
1035 __first <= __last, "vector<bool>::erase(iterator, iterator) called with an invalid range");
1036 iterator __r = __const_iterator_cast(__first);
1037 difference_type __d = __last - __first;
1038 std::copy(__last, this->cend(), __r);
1039 __size_ -= __d;
1040 return __r;
1041}
1042
1043template <class _Allocator>
1044_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::swap(vector& __x)
1045#if _LIBCPP_STD_VER >= 14
1046 _NOEXCEPT
1047#else
1048 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>)
1049#endif
1050{
1051 std::swap(this->__begin_, __x.__begin_);
1052 std::swap(this->__size_, __x.__size_);
1053 std::swap(this->__cap_, __x.__cap_);
1054 std::__swap_allocator(this->__alloc_, __x.__alloc_);
1055}
1056
1057template <class _Allocator>
1058_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::resize(size_type __sz, value_type __x) {
1059 size_type __cs = size();
1060 if (__cs < __sz) {
1061 iterator __r;
1062 size_type __c = capacity();
1063 size_type __n = __sz - __cs;
1064 if (__n <= __c && __cs <= __c - __n) {
1065 __r = end();
1066 __size_ += __n;
1067 } else {
1068 vector __v(get_allocator());
1069 __v.reserve(__recommend(__size_ + __n));
1070 __v.__size_ = __size_ + __n;
1071 __r = std::copy(cbegin(), cend(), __v.begin());
1072 swap(__v);
1073 }
1074 std::fill_n(__r, __n, __x);
1075 } else
1076 __size_ = __sz;
1077}
1078
1079template <class _Allocator>
1080_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::flip() _NOEXCEPT {
1081 // Flip each storage word entirely, including the last potentially partial word.
1082 // The unused bits in the last word are safe to flip as they won't be accessed.
1083 __storage_pointer __p = __begin_;
1084 for (size_type __n = __external_cap_to_internal(size()); __n != 0; ++__p, --__n)
1085 *__p = ~*__p;
1086}
1087
1088template <class _Allocator>
1089_LIBCPP_CONSTEXPR_SINCE_CXX20 bool vector<bool, _Allocator>::__invariants() const {
1090 if (this->__begin_ == nullptr) {
1091 if (this->__size_ != 0 || this->__cap_ != 0)
1092 return false;
1093 } else {
1094 if (this->__cap_ == 0)
1095 return false;
1096 if (this->__size_ > this->capacity())
1097 return false;
1098 }
1099 return true;
1100}
1101
1102template <class _Allocator>
1103_LIBCPP_CONSTEXPR_SINCE_CXX20 size_t vector<bool, _Allocator>::__hash_code() const _NOEXCEPT {
1104 size_t __h = 0;
1105 // do middle whole words
1106 size_type __n = __size_;
1107 __storage_pointer __p = __begin_;
1108 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
1109 __h ^= *__p;
1110 // do last partial word
1111 if (__n > 0) {
1112 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
1113 __h ^= *__p & __m;
1114 }
1115 return __h;
1116}
1117
1118template <class _Allocator>
1119struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
1120 : public __unary_function<vector<bool, _Allocator>, size_t> {
1121 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t
1122 operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT {
1123 return __vec.__hash_code();
1124 }
1125};
1126
1127_LIBCPP_END_NAMESPACE_STD
1128
1129_LIBCPP_POP_MACROS
1130
1131#endif // _LIBCPP___VECTOR_VECTOR_BOOL_H
lib/libcxx/include/__vector/vector_bool_formatter.h created+49
......@@ -0,0 +1,49 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___VECTOR_VECTOR_BOOL_FORMATTER_H
10#define _LIBCPP___VECTOR_VECTOR_BOOL_FORMATTER_H
11
12#include <__concepts/same_as.h>
13#include <__config>
14#include <__format/formatter.h>
15#include <__format/formatter_bool.h>
16#include <__fwd/vector.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22#if _LIBCPP_STD_VER >= 23
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26template <class _Tp, class _CharT>
27// Since is-vector-bool-reference is only used once it's inlined here.
28 requires same_as<typename _Tp::__container, vector<bool, typename _Tp::__container::allocator_type>>
29struct _LIBCPP_TEMPLATE_VIS formatter<_Tp, _CharT> {
30private:
31 formatter<bool, _CharT> __underlying_;
32
33public:
34 template <class _ParseContext>
35 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
36 return __underlying_.parse(__ctx);
37 }
38
39 template <class _FormatContext>
40 _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(const _Tp& __ref, _FormatContext& __ctx) const {
41 return __underlying_.format(__ref, __ctx);
42 }
43};
44
45_LIBCPP_END_NAMESPACE_STD
46
47#endif // _LIBCPP_STD_VER >= 23
48
49#endif // _LIBCPP___VECTOR_VECTOR_BOOL_FORMATTER_H
lib/libcxx/include/__verbose_abort+8-2
......@@ -18,10 +18,16 @@
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
21#if defined(_LIBCPP_VERBOSE_ABORT_NOT_NOEXCEPT)
22# define _LIBCPP_VERBOSE_ABORT_NOEXCEPT
23#else
24# define _LIBCPP_VERBOSE_ABORT_NOEXCEPT _NOEXCEPT
25#endif
26
2127// This function should never be called directly from the code -- it should only be called through
2228// the _LIBCPP_VERBOSE_ABORT macro.
23_LIBCPP_NORETURN _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_OVERRIDABLE_FUNC_VIS
24_LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2) void __libcpp_verbose_abort(const char* __format, ...);
29[[__noreturn__]] _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_ATTRIBUTE_FORMAT(
30 __printf__, 1, 2) void __libcpp_verbose_abort(const char* __format, ...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT;
2531
2632// _LIBCPP_VERBOSE_ABORT(format, args...)
2733//
lib/libcxx/include/algorithm+250-237
......@@ -313,6 +313,9 @@ namespace ranges {
313313 template<class I, class F>
314314 using for_each_result = in_fun_result<I, F>; // since C++20
315315
316 template<class I, class F>
317 using for_each_n_result = in_fun_result<I, F>; // since C++20
318
316319 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
317320 indirectly_unary_invocable<projected<I, Proj>> Fun>
318321 constexpr ranges::for_each_result<I, Fun>
......@@ -700,6 +703,12 @@ namespace ranges {
700703 ranges::lexicographical_compare(R1&& r1, R2&& r2, Comp comp = {},
701704 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
702705
706 template<class I, class O>
707 using move_result = in_out_result<I, O>; // since C++20
708
709 template<class I, class O>
710 using move_backward_result = in_out_result<I, O>; // since C++20
711
703712 template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2>
704713 requires indirectly_movable<I1, I2>
705714 constexpr ranges::move_backward_result<I1, I2>
......@@ -1228,9 +1237,9 @@ template <class InputIterator1, class InputIterator2>
12281237 mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
12291238
12301239template <class InputIterator1, class InputIterator2>
1231 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
1240 constexpr pair<InputIterator1, InputIterator2>
12321241 mismatch(InputIterator1 first1, InputIterator1 last1,
1233 InputIterator2 first2, InputIterator2 last2); // **C++14**
1242 InputIterator2 first2, InputIterator2 last2); // since C++14, constexpr in C++20
12341243
12351244template <class InputIterator1, class InputIterator2, class BinaryPredicate>
12361245 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
......@@ -1238,19 +1247,19 @@ template <class InputIterator1, class InputIterator2, class BinaryPredicate>
12381247 InputIterator2 first2, BinaryPredicate pred);
12391248
12401249template <class InputIterator1, class InputIterator2, class BinaryPredicate>
1241 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
1250 constexpr pair<InputIterator1, InputIterator2>
12421251 mismatch(InputIterator1 first1, InputIterator1 last1,
12431252 InputIterator2 first2, InputIterator2 last2,
1244 BinaryPredicate pred); // **C++14**
1253 BinaryPredicate pred); // since C++14, constexpr in C++20
12451254
12461255template <class InputIterator1, class InputIterator2>
12471256 constexpr bool // constexpr in C++20
12481257 equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
12491258
12501259template <class InputIterator1, class InputIterator2>
1251 constexpr bool // constexpr in C++20
1260 constexpr bool
12521261 equal(InputIterator1 first1, InputIterator1 last1,
1253 InputIterator2 first2, InputIterator2 last2); // **C++14**
1262 InputIterator2 first2, InputIterator2 last2); // since C++14, constexpr in C++20
12541263
12551264template <class InputIterator1, class InputIterator2, class BinaryPredicate>
12561265 constexpr bool // constexpr in C++20
......@@ -1258,10 +1267,10 @@ template <class InputIterator1, class InputIterator2, class BinaryPredicate>
12581267 InputIterator2 first2, BinaryPredicate pred);
12591268
12601269template <class InputIterator1, class InputIterator2, class BinaryPredicate>
1261 constexpr bool // constexpr in C++20
1270 constexpr bool
12621271 equal(InputIterator1 first1, InputIterator1 last1,
12631272 InputIterator2 first2, InputIterator2 last2,
1264 BinaryPredicate pred); // **C++14**
1273 BinaryPredicate pred); // since C++14, constexpr in C++20
12651274
12661275template<class ForwardIterator1, class ForwardIterator2>
12671276 constexpr bool // constexpr in C++20
......@@ -1269,9 +1278,9 @@ template<class ForwardIterator1, class ForwardIterator2>
12691278 ForwardIterator2 first2);
12701279
12711280template<class ForwardIterator1, class ForwardIterator2>
1272 constexpr bool // constexpr in C++20
1281 constexpr bool
12731282 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
1274 ForwardIterator2 first2, ForwardIterator2 last2); // **C++14**
1283 ForwardIterator2 first2, ForwardIterator2 last2); // since C++14, constexpr in C++20
12751284
12761285template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
12771286 constexpr bool // constexpr in C++20
......@@ -1279,10 +1288,10 @@ template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
12791288 ForwardIterator2 first2, BinaryPredicate pred);
12801289
12811290template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
1282 constexpr bool // constexpr in C++20
1291 constexpr bool
12831292 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
12841293 ForwardIterator2 first2, ForwardIterator2 last2,
1285 BinaryPredicate pred); // **C++14**
1294 BinaryPredicate pred); // since C++14, constexpr in C++20
12861295
12871296template <class ForwardIterator1, class ForwardIterator2>
12881297 constexpr ForwardIterator1 // constexpr in C++20
......@@ -1521,11 +1530,11 @@ template <class RandomAccessIterator, class Compare>
15211530 sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
15221531
15231532template <class RandomAccessIterator>
1524 void
1533 constexpr void // constexpr in C++26
15251534 stable_sort(RandomAccessIterator first, RandomAccessIterator last);
15261535
15271536template <class RandomAccessIterator, class Compare>
1528 void
1537 constexpr void // constexpr in C++26
15291538 stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
15301539
15311540template <class RandomAccessIterator>
......@@ -1818,232 +1827,236 @@ template <class BidirectionalIterator, class Compare>
18181827
18191828*/
18201829
1821#include <__config>
1822
1823#include <__algorithm/adjacent_find.h>
1824#include <__algorithm/all_of.h>
1825#include <__algorithm/any_of.h>
1826#include <__algorithm/binary_search.h>
1827#include <__algorithm/copy.h>
1828#include <__algorithm/copy_backward.h>
1829#include <__algorithm/copy_if.h>
1830#include <__algorithm/copy_n.h>
1831#include <__algorithm/count.h>
1832#include <__algorithm/count_if.h>
1833#include <__algorithm/equal.h>
1834#include <__algorithm/equal_range.h>
1835#include <__algorithm/fill.h>
1836#include <__algorithm/fill_n.h>
1837#include <__algorithm/find.h>
1838#include <__algorithm/find_end.h>
1839#include <__algorithm/find_first_of.h>
1840#include <__algorithm/find_if.h>
1841#include <__algorithm/find_if_not.h>
1842#include <__algorithm/for_each.h>
1843#include <__algorithm/generate.h>
1844#include <__algorithm/generate_n.h>
1845#include <__algorithm/includes.h>
1846#include <__algorithm/inplace_merge.h>
1847#include <__algorithm/is_heap.h>
1848#include <__algorithm/is_heap_until.h>
1849#include <__algorithm/is_partitioned.h>
1850#include <__algorithm/is_permutation.h>
1851#include <__algorithm/is_sorted.h>
1852#include <__algorithm/is_sorted_until.h>
1853#include <__algorithm/iter_swap.h>
1854#include <__algorithm/lexicographical_compare.h>
1855#include <__algorithm/lower_bound.h>
1856#include <__algorithm/make_heap.h>
1857#include <__algorithm/max.h>
1858#include <__algorithm/max_element.h>
1859#include <__algorithm/merge.h>
1860#include <__algorithm/min.h>
1861#include <__algorithm/min_element.h>
1862#include <__algorithm/minmax.h>
1863#include <__algorithm/minmax_element.h>
1864#include <__algorithm/mismatch.h>
1865#include <__algorithm/move.h>
1866#include <__algorithm/move_backward.h>
1867#include <__algorithm/next_permutation.h>
1868#include <__algorithm/none_of.h>
1869#include <__algorithm/nth_element.h>
1870#include <__algorithm/partial_sort.h>
1871#include <__algorithm/partial_sort_copy.h>
1872#include <__algorithm/partition.h>
1873#include <__algorithm/partition_copy.h>
1874#include <__algorithm/partition_point.h>
1875#include <__algorithm/pop_heap.h>
1876#include <__algorithm/prev_permutation.h>
1877#include <__algorithm/push_heap.h>
1878#include <__algorithm/remove.h>
1879#include <__algorithm/remove_copy.h>
1880#include <__algorithm/remove_copy_if.h>
1881#include <__algorithm/remove_if.h>
1882#include <__algorithm/replace.h>
1883#include <__algorithm/replace_copy.h>
1884#include <__algorithm/replace_copy_if.h>
1885#include <__algorithm/replace_if.h>
1886#include <__algorithm/reverse.h>
1887#include <__algorithm/reverse_copy.h>
1888#include <__algorithm/rotate.h>
1889#include <__algorithm/rotate_copy.h>
1890#include <__algorithm/search.h>
1891#include <__algorithm/search_n.h>
1892#include <__algorithm/set_difference.h>
1893#include <__algorithm/set_intersection.h>
1894#include <__algorithm/set_symmetric_difference.h>
1895#include <__algorithm/set_union.h>
1896#include <__algorithm/shuffle.h>
1897#include <__algorithm/sort.h>
1898#include <__algorithm/sort_heap.h>
1899#include <__algorithm/stable_partition.h>
1900#include <__algorithm/stable_sort.h>
1901#include <__algorithm/swap_ranges.h>
1902#include <__algorithm/transform.h>
1903#include <__algorithm/unique.h>
1904#include <__algorithm/unique_copy.h>
1905#include <__algorithm/upper_bound.h>
1906
1907#if _LIBCPP_STD_VER >= 17
1908# include <__algorithm/clamp.h>
1909# include <__algorithm/for_each_n.h>
1910# include <__algorithm/pstl.h>
1911# include <__algorithm/sample.h>
1912#endif // _LIBCPP_STD_VER >= 17
1913
1914#if _LIBCPP_STD_VER >= 20
1915# include <__algorithm/in_found_result.h>
1916# include <__algorithm/in_fun_result.h>
1917# include <__algorithm/in_in_out_result.h>
1918# include <__algorithm/in_in_result.h>
1919# include <__algorithm/in_out_out_result.h>
1920# include <__algorithm/in_out_result.h>
1921# include <__algorithm/lexicographical_compare_three_way.h>
1922# include <__algorithm/min_max_result.h>
1923# include <__algorithm/ranges_adjacent_find.h>
1924# include <__algorithm/ranges_all_of.h>
1925# include <__algorithm/ranges_any_of.h>
1926# include <__algorithm/ranges_binary_search.h>
1927# include <__algorithm/ranges_clamp.h>
1928# include <__algorithm/ranges_contains.h>
1929# include <__algorithm/ranges_copy.h>
1930# include <__algorithm/ranges_copy_backward.h>
1931# include <__algorithm/ranges_copy_if.h>
1932# include <__algorithm/ranges_copy_n.h>
1933# include <__algorithm/ranges_count.h>
1934# include <__algorithm/ranges_count_if.h>
1935# include <__algorithm/ranges_equal.h>
1936# include <__algorithm/ranges_equal_range.h>
1937# include <__algorithm/ranges_fill.h>
1938# include <__algorithm/ranges_fill_n.h>
1939# include <__algorithm/ranges_find.h>
1940# include <__algorithm/ranges_find_end.h>
1941# include <__algorithm/ranges_find_first_of.h>
1942# include <__algorithm/ranges_find_if.h>
1943# include <__algorithm/ranges_find_if_not.h>
1944# include <__algorithm/ranges_for_each.h>
1945# include <__algorithm/ranges_for_each_n.h>
1946# include <__algorithm/ranges_generate.h>
1947# include <__algorithm/ranges_generate_n.h>
1948# include <__algorithm/ranges_includes.h>
1949# include <__algorithm/ranges_inplace_merge.h>
1950# include <__algorithm/ranges_is_heap.h>
1951# include <__algorithm/ranges_is_heap_until.h>
1952# include <__algorithm/ranges_is_partitioned.h>
1953# include <__algorithm/ranges_is_permutation.h>
1954# include <__algorithm/ranges_is_sorted.h>
1955# include <__algorithm/ranges_is_sorted_until.h>
1956# include <__algorithm/ranges_lexicographical_compare.h>
1957# include <__algorithm/ranges_lower_bound.h>
1958# include <__algorithm/ranges_make_heap.h>
1959# include <__algorithm/ranges_max.h>
1960# include <__algorithm/ranges_max_element.h>
1961# include <__algorithm/ranges_merge.h>
1962# include <__algorithm/ranges_min.h>
1963# include <__algorithm/ranges_min_element.h>
1964# include <__algorithm/ranges_minmax.h>
1965# include <__algorithm/ranges_minmax_element.h>
1966# include <__algorithm/ranges_mismatch.h>
1967# include <__algorithm/ranges_move.h>
1968# include <__algorithm/ranges_move_backward.h>
1969# include <__algorithm/ranges_next_permutation.h>
1970# include <__algorithm/ranges_none_of.h>
1971# include <__algorithm/ranges_nth_element.h>
1972# include <__algorithm/ranges_partial_sort.h>
1973# include <__algorithm/ranges_partial_sort_copy.h>
1974# include <__algorithm/ranges_partition.h>
1975# include <__algorithm/ranges_partition_copy.h>
1976# include <__algorithm/ranges_partition_point.h>
1977# include <__algorithm/ranges_pop_heap.h>
1978# include <__algorithm/ranges_prev_permutation.h>
1979# include <__algorithm/ranges_push_heap.h>
1980# include <__algorithm/ranges_remove.h>
1981# include <__algorithm/ranges_remove_copy.h>
1982# include <__algorithm/ranges_remove_copy_if.h>
1983# include <__algorithm/ranges_remove_if.h>
1984# include <__algorithm/ranges_replace.h>
1985# include <__algorithm/ranges_replace_copy.h>
1986# include <__algorithm/ranges_replace_copy_if.h>
1987# include <__algorithm/ranges_replace_if.h>
1988# include <__algorithm/ranges_reverse.h>
1989# include <__algorithm/ranges_reverse_copy.h>
1990# include <__algorithm/ranges_rotate.h>
1991# include <__algorithm/ranges_rotate_copy.h>
1992# include <__algorithm/ranges_sample.h>
1993# include <__algorithm/ranges_search.h>
1994# include <__algorithm/ranges_search_n.h>
1995# include <__algorithm/ranges_set_difference.h>
1996# include <__algorithm/ranges_set_intersection.h>
1997# include <__algorithm/ranges_set_symmetric_difference.h>
1998# include <__algorithm/ranges_set_union.h>
1999# include <__algorithm/ranges_shuffle.h>
2000# include <__algorithm/ranges_sort.h>
2001# include <__algorithm/ranges_sort_heap.h>
2002# include <__algorithm/ranges_stable_partition.h>
2003# include <__algorithm/ranges_stable_sort.h>
2004# include <__algorithm/ranges_swap_ranges.h>
2005# include <__algorithm/ranges_transform.h>
2006# include <__algorithm/ranges_unique.h>
2007# include <__algorithm/ranges_unique_copy.h>
2008# include <__algorithm/ranges_upper_bound.h>
2009# include <__algorithm/shift_left.h>
2010# include <__algorithm/shift_right.h>
2011#endif
2012
2013#if _LIBCPP_STD_VER >= 23
2014# include <__algorithm/fold.h>
2015# include <__algorithm/ranges_contains_subrange.h>
2016# include <__algorithm/ranges_ends_with.h>
2017# include <__algorithm/ranges_find_last.h>
2018# include <__algorithm/ranges_starts_with.h>
2019#endif // _LIBCPP_STD_VER >= 23
2020
2021#include <version>
1830#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
1831# include <__cxx03/algorithm>
1832#else
1833# include <__config>
1834
1835# include <__algorithm/adjacent_find.h>
1836# include <__algorithm/all_of.h>
1837# include <__algorithm/any_of.h>
1838# include <__algorithm/binary_search.h>
1839# include <__algorithm/copy.h>
1840# include <__algorithm/copy_backward.h>
1841# include <__algorithm/copy_if.h>
1842# include <__algorithm/copy_n.h>
1843# include <__algorithm/count.h>
1844# include <__algorithm/count_if.h>
1845# include <__algorithm/equal.h>
1846# include <__algorithm/equal_range.h>
1847# include <__algorithm/fill.h>
1848# include <__algorithm/fill_n.h>
1849# include <__algorithm/find.h>
1850# include <__algorithm/find_end.h>
1851# include <__algorithm/find_first_of.h>
1852# include <__algorithm/find_if.h>
1853# include <__algorithm/find_if_not.h>
1854# include <__algorithm/for_each.h>
1855# include <__algorithm/generate.h>
1856# include <__algorithm/generate_n.h>
1857# include <__algorithm/includes.h>
1858# include <__algorithm/inplace_merge.h>
1859# include <__algorithm/is_heap.h>
1860# include <__algorithm/is_heap_until.h>
1861# include <__algorithm/is_partitioned.h>
1862# include <__algorithm/is_permutation.h>
1863# include <__algorithm/is_sorted.h>
1864# include <__algorithm/is_sorted_until.h>
1865# include <__algorithm/iter_swap.h>
1866# include <__algorithm/lexicographical_compare.h>
1867# include <__algorithm/lower_bound.h>
1868# include <__algorithm/make_heap.h>
1869# include <__algorithm/max.h>
1870# include <__algorithm/max_element.h>
1871# include <__algorithm/merge.h>
1872# include <__algorithm/min.h>
1873# include <__algorithm/min_element.h>
1874# include <__algorithm/minmax.h>
1875# include <__algorithm/minmax_element.h>
1876# include <__algorithm/mismatch.h>
1877# include <__algorithm/move.h>
1878# include <__algorithm/move_backward.h>
1879# include <__algorithm/next_permutation.h>
1880# include <__algorithm/none_of.h>
1881# include <__algorithm/nth_element.h>
1882# include <__algorithm/partial_sort.h>
1883# include <__algorithm/partial_sort_copy.h>
1884# include <__algorithm/partition.h>
1885# include <__algorithm/partition_copy.h>
1886# include <__algorithm/partition_point.h>
1887# include <__algorithm/pop_heap.h>
1888# include <__algorithm/prev_permutation.h>
1889# include <__algorithm/push_heap.h>
1890# include <__algorithm/remove.h>
1891# include <__algorithm/remove_copy.h>
1892# include <__algorithm/remove_copy_if.h>
1893# include <__algorithm/remove_if.h>
1894# include <__algorithm/replace.h>
1895# include <__algorithm/replace_copy.h>
1896# include <__algorithm/replace_copy_if.h>
1897# include <__algorithm/replace_if.h>
1898# include <__algorithm/reverse.h>
1899# include <__algorithm/reverse_copy.h>
1900# include <__algorithm/rotate.h>
1901# include <__algorithm/rotate_copy.h>
1902# include <__algorithm/search.h>
1903# include <__algorithm/search_n.h>
1904# include <__algorithm/set_difference.h>
1905# include <__algorithm/set_intersection.h>
1906# include <__algorithm/set_symmetric_difference.h>
1907# include <__algorithm/set_union.h>
1908# include <__algorithm/shuffle.h>
1909# include <__algorithm/sort.h>
1910# include <__algorithm/sort_heap.h>
1911# include <__algorithm/stable_partition.h>
1912# include <__algorithm/stable_sort.h>
1913# include <__algorithm/swap_ranges.h>
1914# include <__algorithm/transform.h>
1915# include <__algorithm/unique.h>
1916# include <__algorithm/unique_copy.h>
1917# include <__algorithm/upper_bound.h>
1918
1919# if _LIBCPP_STD_VER >= 17
1920# include <__algorithm/clamp.h>
1921# include <__algorithm/for_each_n.h>
1922# include <__algorithm/pstl.h>
1923# include <__algorithm/sample.h>
1924# endif // _LIBCPP_STD_VER >= 17
1925
1926# if _LIBCPP_STD_VER >= 20
1927# include <__algorithm/in_found_result.h>
1928# include <__algorithm/in_fun_result.h>
1929# include <__algorithm/in_in_out_result.h>
1930# include <__algorithm/in_in_result.h>
1931# include <__algorithm/in_out_out_result.h>
1932# include <__algorithm/in_out_result.h>
1933# include <__algorithm/lexicographical_compare_three_way.h>
1934# include <__algorithm/min_max_result.h>
1935# include <__algorithm/ranges_adjacent_find.h>
1936# include <__algorithm/ranges_all_of.h>
1937# include <__algorithm/ranges_any_of.h>
1938# include <__algorithm/ranges_binary_search.h>
1939# include <__algorithm/ranges_clamp.h>
1940# include <__algorithm/ranges_contains.h>
1941# include <__algorithm/ranges_copy.h>
1942# include <__algorithm/ranges_copy_backward.h>
1943# include <__algorithm/ranges_copy_if.h>
1944# include <__algorithm/ranges_copy_n.h>
1945# include <__algorithm/ranges_count.h>
1946# include <__algorithm/ranges_count_if.h>
1947# include <__algorithm/ranges_equal.h>
1948# include <__algorithm/ranges_equal_range.h>
1949# include <__algorithm/ranges_fill.h>
1950# include <__algorithm/ranges_fill_n.h>
1951# include <__algorithm/ranges_find.h>
1952# include <__algorithm/ranges_find_end.h>
1953# include <__algorithm/ranges_find_first_of.h>
1954# include <__algorithm/ranges_find_if.h>
1955# include <__algorithm/ranges_find_if_not.h>
1956# include <__algorithm/ranges_for_each.h>
1957# include <__algorithm/ranges_for_each_n.h>
1958# include <__algorithm/ranges_generate.h>
1959# include <__algorithm/ranges_generate_n.h>
1960# include <__algorithm/ranges_includes.h>
1961# include <__algorithm/ranges_inplace_merge.h>
1962# include <__algorithm/ranges_is_heap.h>
1963# include <__algorithm/ranges_is_heap_until.h>
1964# include <__algorithm/ranges_is_partitioned.h>
1965# include <__algorithm/ranges_is_permutation.h>
1966# include <__algorithm/ranges_is_sorted.h>
1967# include <__algorithm/ranges_is_sorted_until.h>
1968# include <__algorithm/ranges_lexicographical_compare.h>
1969# include <__algorithm/ranges_lower_bound.h>
1970# include <__algorithm/ranges_make_heap.h>
1971# include <__algorithm/ranges_max.h>
1972# include <__algorithm/ranges_max_element.h>
1973# include <__algorithm/ranges_merge.h>
1974# include <__algorithm/ranges_min.h>
1975# include <__algorithm/ranges_min_element.h>
1976# include <__algorithm/ranges_minmax.h>
1977# include <__algorithm/ranges_minmax_element.h>
1978# include <__algorithm/ranges_mismatch.h>
1979# include <__algorithm/ranges_move.h>
1980# include <__algorithm/ranges_move_backward.h>
1981# include <__algorithm/ranges_next_permutation.h>
1982# include <__algorithm/ranges_none_of.h>
1983# include <__algorithm/ranges_nth_element.h>
1984# include <__algorithm/ranges_partial_sort.h>
1985# include <__algorithm/ranges_partial_sort_copy.h>
1986# include <__algorithm/ranges_partition.h>
1987# include <__algorithm/ranges_partition_copy.h>
1988# include <__algorithm/ranges_partition_point.h>
1989# include <__algorithm/ranges_pop_heap.h>
1990# include <__algorithm/ranges_prev_permutation.h>
1991# include <__algorithm/ranges_push_heap.h>
1992# include <__algorithm/ranges_remove.h>
1993# include <__algorithm/ranges_remove_copy.h>
1994# include <__algorithm/ranges_remove_copy_if.h>
1995# include <__algorithm/ranges_remove_if.h>
1996# include <__algorithm/ranges_replace.h>
1997# include <__algorithm/ranges_replace_copy.h>
1998# include <__algorithm/ranges_replace_copy_if.h>
1999# include <__algorithm/ranges_replace_if.h>
2000# include <__algorithm/ranges_reverse.h>
2001# include <__algorithm/ranges_reverse_copy.h>
2002# include <__algorithm/ranges_rotate.h>
2003# include <__algorithm/ranges_rotate_copy.h>
2004# include <__algorithm/ranges_sample.h>
2005# include <__algorithm/ranges_search.h>
2006# include <__algorithm/ranges_search_n.h>
2007# include <__algorithm/ranges_set_difference.h>
2008# include <__algorithm/ranges_set_intersection.h>
2009# include <__algorithm/ranges_set_symmetric_difference.h>
2010# include <__algorithm/ranges_set_union.h>
2011# include <__algorithm/ranges_shuffle.h>
2012# include <__algorithm/ranges_sort.h>
2013# include <__algorithm/ranges_sort_heap.h>
2014# include <__algorithm/ranges_stable_partition.h>
2015# include <__algorithm/ranges_stable_sort.h>
2016# include <__algorithm/ranges_swap_ranges.h>
2017# include <__algorithm/ranges_transform.h>
2018# include <__algorithm/ranges_unique.h>
2019# include <__algorithm/ranges_unique_copy.h>
2020# include <__algorithm/ranges_upper_bound.h>
2021# include <__algorithm/shift_left.h>
2022# include <__algorithm/shift_right.h>
2023# endif
2024
2025# if _LIBCPP_STD_VER >= 23
2026# include <__algorithm/ranges_contains_subrange.h>
2027# include <__algorithm/ranges_ends_with.h>
2028# include <__algorithm/ranges_find_last.h>
2029# include <__algorithm/ranges_fold.h>
2030# include <__algorithm/ranges_starts_with.h>
2031# endif // _LIBCPP_STD_VER >= 23
2032
2033# include <version>
20222034
20232035// standard-mandated includes
20242036
20252037// [algorithm.syn]
2026#include <initializer_list>
2027
2028#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2029# pragma GCC system_header
2030#endif
2031
2032#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER == 14
2033# include <execution>
2034#endif
2035
2036#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
2037# include <atomic>
2038# include <bit>
2039# include <concepts>
2040# include <cstdlib>
2041# include <cstring>
2042# include <iterator>
2043# include <memory>
2044# include <stdexcept>
2045# include <type_traits>
2046# include <utility>
2047#endif
2038# include <initializer_list>
2039
2040# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2041# pragma GCC system_header
2042# endif
2043
2044# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER == 14
2045# include <execution>
2046# endif
2047
2048# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
2049# include <atomic>
2050# include <bit>
2051# include <concepts>
2052# include <cstdlib>
2053# include <cstring>
2054# include <iterator>
2055# include <memory>
2056# include <stdexcept>
2057# include <type_traits>
2058# include <utility>
2059# endif
2060#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
20482061
20492062#endif // _LIBCPP_ALGORITHM
lib/libcxx/include/any+77-73
......@@ -80,40 +80,44 @@ namespace std {
8080
8181*/
8282
83#include <__config>
84#include <__memory/allocator.h>
85#include <__memory/allocator_destructor.h>
86#include <__memory/allocator_traits.h>
87#include <__memory/unique_ptr.h>
88#include <__type_traits/add_const.h>
89#include <__type_traits/add_pointer.h>
90#include <__type_traits/aligned_storage.h>
91#include <__type_traits/conditional.h>
92#include <__type_traits/decay.h>
93#include <__type_traits/is_constructible.h>
94#include <__type_traits/is_function.h>
95#include <__type_traits/is_nothrow_constructible.h>
96#include <__type_traits/is_reference.h>
97#include <__type_traits/is_same.h>
98#include <__type_traits/is_void.h>
99#include <__type_traits/remove_cv.h>
100#include <__type_traits/remove_cvref.h>
101#include <__type_traits/remove_reference.h>
102#include <__utility/forward.h>
103#include <__utility/in_place.h>
104#include <__utility/move.h>
105#include <__utility/unreachable.h>
106#include <__verbose_abort>
107#include <initializer_list>
108#include <typeinfo>
109#include <version>
110
111#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
112# pragma GCC system_header
113#endif
83#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
84# include <__cxx03/any>
85#else
86# include <__config>
87# include <__memory/allocator.h>
88# include <__memory/allocator_destructor.h>
89# include <__memory/allocator_traits.h>
90# include <__memory/unique_ptr.h>
91# include <__type_traits/add_cv_quals.h>
92# include <__type_traits/add_pointer.h>
93# include <__type_traits/aligned_storage.h>
94# include <__type_traits/conditional.h>
95# include <__type_traits/decay.h>
96# include <__type_traits/enable_if.h>
97# include <__type_traits/is_constructible.h>
98# include <__type_traits/is_function.h>
99# include <__type_traits/is_nothrow_constructible.h>
100# include <__type_traits/is_reference.h>
101# include <__type_traits/is_same.h>
102# include <__type_traits/is_void.h>
103# include <__type_traits/remove_cv.h>
104# include <__type_traits/remove_cvref.h>
105# include <__type_traits/remove_reference.h>
106# include <__utility/forward.h>
107# include <__utility/in_place.h>
108# include <__utility/move.h>
109# include <__utility/unreachable.h>
110# include <__verbose_abort>
111# include <initializer_list>
112# include <typeinfo>
113# include <version>
114
115# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
116# pragma GCC system_header
117# endif
114118
115119_LIBCPP_PUSH_MACROS
116#include <__undef_macros>
120# include <__undef_macros>
117121
118122namespace std {
119123class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_BAD_ANY_CAST bad_any_cast : public bad_cast {
......@@ -124,14 +128,14 @@ public:
124128
125129_LIBCPP_BEGIN_NAMESPACE_STD
126130
127#if _LIBCPP_STD_VER >= 17
131# if _LIBCPP_STD_VER >= 17
128132
129_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST void __throw_bad_any_cast() {
130# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
133[[noreturn]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST void __throw_bad_any_cast() {
134# if _LIBCPP_HAS_EXCEPTIONS
131135 throw bad_any_cast();
132# else
136# else
133137 _LIBCPP_VERBOSE_ABORT("bad_any_cast was thrown in -fno-exceptions mode");
134# endif
138# endif
135139}
136140
137141// Forward declarations
......@@ -145,11 +149,11 @@ _LIBCPP_HIDE_FROM_ABI add_pointer_t<_ValueType> any_cast(any*) _NOEXCEPT;
145149
146150namespace __any_imp {
147151_LIBCPP_SUPPRESS_DEPRECATED_PUSH
148using _Buffer = aligned_storage_t<3 * sizeof(void*), alignof(void*)>;
152using _Buffer _LIBCPP_NODEBUG = aligned_storage_t<3 * sizeof(void*), alignof(void*)>;
149153_LIBCPP_SUPPRESS_DEPRECATED_POP
150154
151155template <class _Tp>
152using _IsSmallObject =
156using _IsSmallObject _LIBCPP_NODEBUG =
153157 integral_constant<bool,
154158 sizeof(_Tp) <= sizeof(_Buffer) && alignof(_Buffer) % alignof(_Tp) == 0 &&
155159 is_nothrow_move_constructible<_Tp>::value >;
......@@ -165,8 +169,6 @@ template <class _Tp>
165169struct _LIBCPP_TEMPLATE_VIS __unique_typeinfo {
166170 static constexpr int __id = 0;
167171};
168template <class _Tp>
169constexpr int __unique_typeinfo<_Tp>::__id;
170172
171173template <class _Tp>
172174inline _LIBCPP_HIDE_FROM_ABI constexpr const void* __get_fallback_typeid() {
......@@ -175,15 +177,15 @@ inline _LIBCPP_HIDE_FROM_ABI constexpr const void* __get_fallback_typeid() {
175177
176178template <class _Tp>
177179inline _LIBCPP_HIDE_FROM_ABI bool __compare_typeid(type_info const* __id, const void* __fallback_id) {
178# if !defined(_LIBCPP_HAS_NO_RTTI)
180# if _LIBCPP_HAS_RTTI
179181 if (__id && *__id == typeid(_Tp))
180182 return true;
181# endif
183# endif
182184 return !__id && __fallback_id == __any_imp::__get_fallback_typeid<_Tp>();
183185}
184186
185187template <class _Tp>
186using _Handler = conditional_t< _IsSmallObject<_Tp>::value, _SmallHandler<_Tp>, _LargeHandler<_Tp>>;
188using _Handler _LIBCPP_NODEBUG = conditional_t< _IsSmallObject<_Tp>::value, _SmallHandler<_Tp>, _LargeHandler<_Tp>>;
187189
188190} // namespace __any_imp
189191
......@@ -265,7 +267,7 @@ public:
265267 // 6.3.4 any observers
266268 _LIBCPP_HIDE_FROM_ABI bool has_value() const _NOEXCEPT { return __h_ != nullptr; }
267269
268# if !defined(_LIBCPP_HAS_NO_RTTI)
270# if _LIBCPP_HAS_RTTI
269271 _LIBCPP_HIDE_FROM_ABI const type_info& type() const _NOEXCEPT {
270272 if (__h_) {
271273 return *static_cast<type_info const*>(this->__call(_Action::_TypeInfo));
......@@ -273,11 +275,12 @@ public:
273275 return typeid(void);
274276 }
275277 }
276# endif
278# endif
277279
278280private:
279 typedef __any_imp::_Action _Action;
280 using _HandleFuncPtr = void* (*)(_Action, any const*, any*, const type_info*, const void* __fallback_info);
281 using _Action _LIBCPP_NODEBUG = __any_imp::_Action;
282 using _HandleFuncPtr
283 _LIBCPP_NODEBUG = void* (*)(_Action, any const*, any*, const type_info*, const void* __fallback_info);
281284
282285 union _Storage {
283286 _LIBCPP_HIDE_FROM_ABI constexpr _Storage() : __ptr(nullptr) {}
......@@ -371,11 +374,11 @@ private:
371374 }
372375
373376 _LIBCPP_HIDE_FROM_ABI static void* __type_info() {
374# if !defined(_LIBCPP_HAS_NO_RTTI)
377# if _LIBCPP_HAS_RTTI
375378 return const_cast<void*>(static_cast<void const*>(&typeid(_Tp)));
376# else
379# else
377380 return nullptr;
378# endif
381# endif
379382 }
380383};
381384
......@@ -443,11 +446,11 @@ private:
443446 }
444447
445448 _LIBCPP_HIDE_FROM_ABI static void* __type_info() {
446# if !defined(_LIBCPP_HAS_NO_RTTI)
449# if _LIBCPP_HAS_RTTI
447450 return const_cast<void*>(static_cast<void const*>(&typeid(_Tp)));
448# else
451# else
449452 return nullptr;
450# endif
453# endif
451454 }
452455};
453456
......@@ -578,37 +581,38 @@ _LIBCPP_HIDE_FROM_ABI add_pointer_t<_ValueType> any_cast(any* __any) _NOEXCEPT {
578581 void* __p = __any->__call(
579582 _Action::_Get,
580583 nullptr,
581# if !defined(_LIBCPP_HAS_NO_RTTI)
584# if _LIBCPP_HAS_RTTI
582585 &typeid(_ValueType),
583# else
586# else
584587 nullptr,
585# endif
588# endif
586589 __any_imp::__get_fallback_typeid<_ValueType>());
587590 return std::__pointer_or_func_cast<_ReturnType>(__p, is_function<_ValueType>{});
588591 }
589592 return nullptr;
590593}
591594
592#endif // _LIBCPP_STD_VER >= 17
595# endif // _LIBCPP_STD_VER >= 17
593596
594597_LIBCPP_END_NAMESPACE_STD
595598
596599_LIBCPP_POP_MACROS
597600
598#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
599# include <chrono>
600#endif
601
602#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
603# include <atomic>
604# include <concepts>
605# include <cstdlib>
606# include <iosfwd>
607# include <iterator>
608# include <memory>
609# include <stdexcept>
610# include <type_traits>
611# include <variant>
612#endif
601# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
602# include <chrono>
603# endif
604
605# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
606# include <atomic>
607# include <concepts>
608# include <cstdlib>
609# include <iosfwd>
610# include <iterator>
611# include <memory>
612# include <stdexcept>
613# include <type_traits>
614# include <variant>
615# endif
616#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
613617
614618#endif // _LIBCPP_ANY
lib/libcxx/include/array+158-99
......@@ -19,17 +19,17 @@ template <class T, size_t N >
1919struct array
2020{
2121 // types:
22 typedef T & reference;
23 typedef const T & const_reference;
24 typedef implementation defined iterator;
25 typedef implementation defined const_iterator;
26 typedef size_t size_type;
27 typedef ptrdiff_t difference_type;
28 typedef T value_type;
29 typedef T* pointer;
30 typedef const T* const_pointer;
31 typedef std::reverse_iterator<iterator> reverse_iterator;
32 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
22 using value_type = T;
23 using pointer = T*;
24 using const_pointer = const T*;
25 using reference = T&;
26 using const_reference = const T&;
27 using size_type = size_t;
28 using difference_type = ptrdiff_t;
29 using iterator = implementation-defined;
30 using const_iterator = implementation-defined;
31 using reverse_iterator = std::reverse_iterator<iterator>;
32 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
3333
3434 // No explicit construct/copy/destroy for aggregate type
3535 void fill(const T& u); // constexpr in C++20
......@@ -111,78 +111,88 @@ template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexce
111111
112112*/
113113
114#include <__algorithm/equal.h>
115#include <__algorithm/fill_n.h>
116#include <__algorithm/lexicographical_compare.h>
117#include <__algorithm/lexicographical_compare_three_way.h>
118#include <__algorithm/swap_ranges.h>
119#include <__assert>
120#include <__config>
121#include <__fwd/array.h>
122#include <__iterator/reverse_iterator.h>
123#include <__iterator/wrap_iter.h>
124#include <__tuple/sfinae_helpers.h>
125#include <__type_traits/conditional.h>
126#include <__type_traits/conjunction.h>
127#include <__type_traits/is_array.h>
128#include <__type_traits/is_const.h>
129#include <__type_traits/is_constructible.h>
130#include <__type_traits/is_nothrow_constructible.h>
131#include <__type_traits/is_same.h>
132#include <__type_traits/is_swappable.h>
133#include <__type_traits/is_trivially_relocatable.h>
134#include <__type_traits/remove_cv.h>
135#include <__utility/empty.h>
136#include <__utility/integer_sequence.h>
137#include <__utility/move.h>
138#include <__utility/unreachable.h>
139#include <stdexcept>
140#include <version>
114#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
115# include <__cxx03/array>
116#else
117# include <__algorithm/equal.h>
118# include <__algorithm/fill_n.h>
119# include <__algorithm/lexicographical_compare.h>
120# include <__algorithm/lexicographical_compare_three_way.h>
121# include <__algorithm/swap_ranges.h>
122# include <__assert>
123# include <__config>
124# include <__cstddef/ptrdiff_t.h>
125# include <__fwd/array.h>
126# include <__iterator/reverse_iterator.h>
127# include <__iterator/static_bounded_iter.h>
128# include <__iterator/wrap_iter.h>
129# include <__tuple/sfinae_helpers.h>
130# include <__type_traits/conditional.h>
131# include <__type_traits/conjunction.h>
132# include <__type_traits/enable_if.h>
133# include <__type_traits/is_array.h>
134# include <__type_traits/is_const.h>
135# include <__type_traits/is_constructible.h>
136# include <__type_traits/is_nothrow_constructible.h>
137# include <__type_traits/is_same.h>
138# include <__type_traits/is_swappable.h>
139# include <__type_traits/is_trivially_relocatable.h>
140# include <__type_traits/remove_cv.h>
141# include <__utility/empty.h>
142# include <__utility/integer_sequence.h>
143# include <__utility/move.h>
144# include <__utility/unreachable.h>
145# include <stdexcept>
146# include <version>
141147
142148// standard-mandated includes
143149
144150// [iterator.range]
145#include <__iterator/access.h>
146#include <__iterator/data.h>
147#include <__iterator/empty.h>
148#include <__iterator/reverse_access.h>
149#include <__iterator/size.h>
151# include <__iterator/access.h>
152# include <__iterator/data.h>
153# include <__iterator/empty.h>
154# include <__iterator/reverse_access.h>
155# include <__iterator/size.h>
150156
151157// [array.syn]
152#include <compare>
153#include <initializer_list>
158# include <compare>
159# include <initializer_list>
154160
155161// [tuple.helper]
156#include <__tuple/tuple_element.h>
157#include <__tuple/tuple_size.h>
162# include <__tuple/tuple_element.h>
163# include <__tuple/tuple_size.h>
158164
159#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
160# pragma GCC system_header
161#endif
165# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
166# pragma GCC system_header
167# endif
162168
163169_LIBCPP_PUSH_MACROS
164#include <__undef_macros>
170# include <__undef_macros>
165171
166172_LIBCPP_BEGIN_NAMESPACE_STD
167173
168174template <class _Tp, size_t _Size>
169175struct _LIBCPP_TEMPLATE_VIS array {
170 using __trivially_relocatable = __conditional_t<__libcpp_is_trivially_relocatable<_Tp>::value, array, void>;
176 using __trivially_relocatable _LIBCPP_NODEBUG =
177 __conditional_t<__libcpp_is_trivially_relocatable<_Tp>::value, array, void>;
171178
172179 // types:
173 using __self = array;
174 using value_type = _Tp;
175 using reference = value_type&;
176 using const_reference = const value_type&;
177 using pointer = value_type*;
178 using const_pointer = const value_type*;
179#if defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY)
180 using __self _LIBCPP_NODEBUG = array;
181 using value_type = _Tp;
182 using reference = value_type&;
183 using const_reference = const value_type&;
184 using pointer = value_type*;
185 using const_pointer = const value_type*;
186# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
187 using iterator = __static_bounded_iter<pointer, _Size>;
188 using const_iterator = __static_bounded_iter<const_pointer, _Size>;
189# elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY)
180190 using iterator = __wrap_iter<pointer>;
181191 using const_iterator = __wrap_iter<const_pointer>;
182#else
192# else
183193 using iterator = pointer;
184194 using const_iterator = const_pointer;
185#endif
195# endif
186196 using size_type = size_t;
187197 using difference_type = ptrdiff_t;
188198 using reverse_iterator = std::reverse_iterator<iterator>;
......@@ -200,13 +210,33 @@ struct _LIBCPP_TEMPLATE_VIS array {
200210 }
201211
202212 // iterators:
203 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator begin() _NOEXCEPT { return iterator(data()); }
213 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator begin() _NOEXCEPT {
214# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
215 return std::__make_static_bounded_iter<_Size>(data(), data());
216# else
217 return iterator(data());
218# endif
219 }
204220 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator begin() const _NOEXCEPT {
221# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
222 return std::__make_static_bounded_iter<_Size>(data(), data());
223# else
205224 return const_iterator(data());
225# endif
226 }
227 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator end() _NOEXCEPT {
228# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
229 return std::__make_static_bounded_iter<_Size>(data() + _Size, data());
230# else
231 return iterator(data() + _Size);
232# endif
206233 }
207 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator end() _NOEXCEPT { return iterator(data() + _Size); }
208234 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator end() const _NOEXCEPT {
235# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
236 return std::__make_static_bounded_iter<_Size>(data() + _Size, data());
237# else
209238 return const_iterator(data() + _Size);
239# endif
210240 }
211241
212242 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rbegin() _NOEXCEPT {
......@@ -232,7 +262,7 @@ struct _LIBCPP_TEMPLATE_VIS array {
232262 // capacity:
233263 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT { return _Size; }
234264 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT { return _Size; }
235 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return _Size == 0; }
265 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return _Size == 0; }
236266
237267 // element access:
238268 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](size_type __n) _NOEXCEPT {
......@@ -270,20 +300,28 @@ struct _LIBCPP_TEMPLATE_VIS array {
270300template <class _Tp>
271301struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> {
272302 // types:
273 typedef array __self;
274 typedef _Tp value_type;
275 typedef value_type& reference;
276 typedef const value_type& const_reference;
277 typedef value_type* iterator;
278 typedef const value_type* const_iterator;
279 typedef value_type* pointer;
280 typedef const value_type* const_pointer;
281 typedef size_t size_type;
282 typedef ptrdiff_t difference_type;
283 typedef std::reverse_iterator<iterator> reverse_iterator;
284 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
285
286 typedef __conditional_t<is_const<_Tp>::value, const __empty, __empty> _EmptyType;
303 using __self _LIBCPP_NODEBUG = array;
304 using value_type = _Tp;
305 using reference = value_type&;
306 using const_reference = const value_type&;
307 using pointer = value_type*;
308 using const_pointer = const value_type*;
309# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
310 using iterator = __static_bounded_iter<pointer, 0>;
311 using const_iterator = __static_bounded_iter<const_pointer, 0>;
312# elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY)
313 using iterator = __wrap_iter<pointer>;
314 using const_iterator = __wrap_iter<const_pointer>;
315# else
316 using iterator = pointer;
317 using const_iterator = const_pointer;
318# endif
319 using size_type = size_t;
320 using difference_type = ptrdiff_t;
321 using reverse_iterator = std::reverse_iterator<iterator>;
322 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
323
324 using _EmptyType _LIBCPP_NODEBUG = __conditional_t<is_const<_Tp>::value, const __empty, __empty>;
287325
288326 struct _ArrayInStructT {
289327 _Tp __data_[1];
......@@ -303,13 +341,33 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> {
303341 }
304342
305343 // iterators:
306 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator begin() _NOEXCEPT { return iterator(data()); }
344 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator begin() _NOEXCEPT {
345# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
346 return std::__make_static_bounded_iter<0>(data(), data());
347# else
348 return iterator(data());
349# endif
350 }
307351 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator begin() const _NOEXCEPT {
352# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
353 return std::__make_static_bounded_iter<0>(data(), data());
354# else
308355 return const_iterator(data());
356# endif
357 }
358 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator end() _NOEXCEPT {
359# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
360 return std::__make_static_bounded_iter<0>(data(), data());
361# else
362 return iterator(data());
363# endif
309364 }
310 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator end() _NOEXCEPT { return iterator(data()); }
311365 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator end() const _NOEXCEPT {
366# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY)
367 return std::__make_static_bounded_iter<0>(data(), data());
368# else
312369 return const_iterator(data());
370# endif
313371 }
314372
315373 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rbegin() _NOEXCEPT {
......@@ -335,7 +393,7 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> {
335393 // capacity:
336394 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT { return 0; }
337395 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT { return 0; }
338 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return true; }
396 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return true; }
339397
340398 // element access:
341399 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](size_type) _NOEXCEPT {
......@@ -379,10 +437,10 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> {
379437 }
380438};
381439
382#if _LIBCPP_STD_VER >= 17
440# if _LIBCPP_STD_VER >= 17
383441template <class _Tp, class... _Args, class = enable_if_t<__all<_IsSame<_Tp, _Args>::value...>::value> >
384442array(_Tp, _Args...) -> array<_Tp, 1 + sizeof...(_Args)>;
385#endif
443# endif
386444
387445template <class _Tp, size_t _Size>
388446inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
......@@ -390,7 +448,7 @@ operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
390448 return std::equal(__x.begin(), __x.end(), __y.begin());
391449}
392450
393#if _LIBCPP_STD_VER <= 17
451# if _LIBCPP_STD_VER <= 17
394452
395453template <class _Tp, size_t _Size>
396454inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
......@@ -417,16 +475,15 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const array<_Tp, _Size>& __x, const
417475 return !(__x < __y);
418476}
419477
420#else // _LIBCPP_STD_VER <= 17
478# else // _LIBCPP_STD_VER <= 17
421479
422480template <class _Tp, size_t _Size>
423481_LIBCPP_HIDE_FROM_ABI constexpr __synth_three_way_result<_Tp>
424482operator<=>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) {
425 return std::lexicographical_compare_three_way(
426 __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
483 return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
427484}
428485
429#endif // _LIBCPP_STD_VER <= 17
486# endif // _LIBCPP_STD_VER <= 17
430487
431488template <class _Tp, size_t _Size, __enable_if_t<_Size == 0 || __is_swappable_v<_Tp>, int> = 0>
432489inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
......@@ -440,7 +497,7 @@ struct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> > : public integral_con
440497template <size_t _Ip, class _Tp, size_t _Size>
441498struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > {
442499 static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
443 typedef _Tp type;
500 using type = _Tp;
444501};
445502
446503template <size_t _Ip, class _Tp, size_t _Size>
......@@ -467,7 +524,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&& get(const
467524 return std::move(__a.__elems_[_Ip]);
468525}
469526
470#if _LIBCPP_STD_VER >= 20
527# if _LIBCPP_STD_VER >= 20
471528
472529template <typename _Tp, size_t _Size, size_t... _Index>
473530_LIBCPP_HIDE_FROM_ABI constexpr array<remove_cv_t<_Tp>, _Size>
......@@ -497,19 +554,21 @@ to_array(_Tp (&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) {
497554 return std::__to_array_rvalue_impl(std::move(__arr), make_index_sequence<_Size>());
498555}
499556
500#endif // _LIBCPP_STD_VER >= 20
557# endif // _LIBCPP_STD_VER >= 20
501558
502559_LIBCPP_END_NAMESPACE_STD
503560
504561_LIBCPP_POP_MACROS
505562
506#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
507# include <algorithm>
508# include <concepts>
509# include <cstdlib>
510# include <iterator>
511# include <type_traits>
512# include <utility>
513#endif
563# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
564# include <algorithm>
565# include <concepts>
566# include <cstdlib>
567# include <iterator>
568# include <new>
569# include <type_traits>
570# include <utility>
571# endif
572#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
514573
515574#endif // _LIBCPP_ARRAY
lib/libcxx/include/atomic+96-87
......@@ -101,12 +101,12 @@ struct atomic
101101 bool compare_exchange_strong(T& expc, T desr,
102102 memory_order m = memory_order_seq_cst) noexcept;
103103
104 void wait(T, memory_order = memory_order::seq_cst) const volatile noexcept;
105 void wait(T, memory_order = memory_order::seq_cst) const noexcept;
106 void notify_one() volatile noexcept;
107 void notify_one() noexcept;
108 void notify_all() volatile noexcept;
109 void notify_all() noexcept;
104 void wait(T, memory_order = memory_order::seq_cst) const volatile noexcept; // since C++20
105 void wait(T, memory_order = memory_order::seq_cst) const noexcept; // since C++20
106 void notify_one() volatile noexcept; // since C++20
107 void notify_one() noexcept; // since C++20
108 void notify_all() volatile noexcept; // since C++20
109 void notify_all() noexcept; // since C++20
110110};
111111
112112template <>
......@@ -184,12 +184,12 @@ struct atomic<integral>
184184 integral operator^=(integral op) volatile noexcept;
185185 integral operator^=(integral op) noexcept;
186186
187 void wait(integral, memory_order = memory_order::seq_cst) const volatile noexcept;
188 void wait(integral, memory_order = memory_order::seq_cst) const noexcept;
189 void notify_one() volatile noexcept;
190 void notify_one() noexcept;
191 void notify_all() volatile noexcept;
192 void notify_all() noexcept;
187 void wait(integral, memory_order = memory_order::seq_cst) const volatile noexcept; // since C++20
188 void wait(integral, memory_order = memory_order::seq_cst) const noexcept; // since C++20
189 void notify_one() volatile noexcept; // since C++20
190 void notify_one() noexcept; // since C++20
191 void notify_all() volatile noexcept; // since C++20
192 void notify_all() noexcept; // since C++20
193193};
194194
195195template <class T>
......@@ -254,12 +254,12 @@ struct atomic<T*>
254254 T* operator-=(ptrdiff_t op) volatile noexcept;
255255 T* operator-=(ptrdiff_t op) noexcept;
256256
257 void wait(T*, memory_order = memory_order::seq_cst) const volatile noexcept;
258 void wait(T*, memory_order = memory_order::seq_cst) const noexcept;
259 void notify_one() volatile noexcept;
260 void notify_one() noexcept;
261 void notify_all() volatile noexcept;
262 void notify_all() noexcept;
257 void wait(T*, memory_order = memory_order::seq_cst) const volatile noexcept; // since C++20
258 void wait(T*, memory_order = memory_order::seq_cst) const noexcept; // since C++20
259 void notify_one() volatile noexcept; // since C++20
260 void notify_one() noexcept; // since C++20
261 void notify_all() volatile noexcept; // since C++20
262 void notify_all() noexcept; // since C++20
263263};
264264
265265template<>
......@@ -321,12 +321,12 @@ struct atomic<floating-point-type> { // since C++20
321321 floating-point-type operator-=(floating-point-type) volatile noexcept;
322322 floating-point-type operator-=(floating-point-type) noexcept;
323323
324 void wait(floating-point-type, memory_order = memory_order::seq_cst) const volatile noexcept;
325 void wait(floating-point-type, memory_order = memory_order::seq_cst) const noexcept;
326 void notify_one() volatile noexcept;
327 void notify_one() noexcept;
328 void notify_all() volatile noexcept;
329 void notify_all() noexcept;
324 void wait(floating-point-type, memory_order = memory_order::seq_cst) const volatile noexcept; // since C++20
325 void wait(floating-point-type, memory_order = memory_order::seq_cst) const noexcept; // since C++20
326 void notify_one() volatile noexcept; // since C++20
327 void notify_one() noexcept; // since C++20
328 void notify_all() volatile noexcept; // since C++20
329 void notify_all() noexcept; // since C++20
330330};
331331
332332// [atomics.nonmembers], non-member functions
......@@ -443,23 +443,23 @@ template<class T>
443443 memory_order) noexcept;
444444
445445template<class T>
446 void atomic_wait(const volatile atomic<T>*, atomic<T>::value_type) noexcept;
446 void atomic_wait(const volatile atomic<T>*, atomic<T>::value_type) noexcept; // since C++20
447447template<class T>
448 void atomic_wait(const atomic<T>*, atomic<T>::value_type) noexcept;
448 void atomic_wait(const atomic<T>*, atomic<T>::value_type) noexcept; // since C++20
449449template<class T>
450 void atomic_wait_explicit(const volatile atomic<T>*, atomic<T>::value_type,
450 void atomic_wait_explicit(const volatile atomic<T>*, atomic<T>::value_type, // since C++20
451451 memory_order) noexcept;
452452template<class T>
453 void atomic_wait_explicit(const atomic<T>*, atomic<T>::value_type,
453 void atomic_wait_explicit(const atomic<T>*, atomic<T>::value_type, // since C++20
454454 memory_order) noexcept;
455455template<class T>
456 void atomic_notify_one(volatile atomic<T>*) noexcept;
456 void atomic_notify_one(volatile atomic<T>*) noexcept; // since C++20
457457template<class T>
458 void atomic_notify_one(atomic<T>*) noexcept;
458 void atomic_notify_one(atomic<T>*) noexcept; // since C++20
459459template<class T>
460 void atomic_notify_all(volatile atomic<T>*) noexcept;
460 void atomic_notify_all(volatile atomic<T>*) noexcept; // since C++20
461461template<class T>
462 void atomic_notify_all(atomic<T>*) noexcept;
462 void atomic_notify_all(atomic<T>*) noexcept; // since C++20
463463
464464// Atomics for standard typedef types
465465
......@@ -534,12 +534,12 @@ typedef struct atomic_flag
534534 void clear(memory_order m = memory_order_seq_cst) volatile noexcept;
535535 void clear(memory_order m = memory_order_seq_cst) noexcept;
536536
537 void wait(bool, memory_order = memory_order::seq_cst) const volatile noexcept;
538 void wait(bool, memory_order = memory_order::seq_cst) const noexcept;
539 void notify_one() volatile noexcept;
540 void notify_one() noexcept;
541 void notify_all() volatile noexcept;
542 void notify_all() noexcept;
537 void wait(bool, memory_order = memory_order::seq_cst) const volatile noexcept; // since C++20
538 void wait(bool, memory_order = memory_order::seq_cst) const noexcept; // since C++20
539 void notify_one() volatile noexcept; // since C++20
540 void notify_one() noexcept; // since C++20
541 void notify_all() volatile noexcept; // since C++20
542 void notify_all() noexcept; // since C++20
543543} atomic_flag;
544544
545545bool atomic_flag_test(volatile atomic_flag* obj) noexcept;
......@@ -557,14 +557,14 @@ void atomic_flag_clear(atomic_flag* obj) noexcept;
557557void atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept;
558558void atomic_flag_clear_explicit(atomic_flag* obj, memory_order m) noexcept;
559559
560void atomic_wait(const volatile atomic_flag* obj, T old) noexcept;
561void atomic_wait(const atomic_flag* obj, T old) noexcept;
562void atomic_wait_explicit(const volatile atomic_flag* obj, T old, memory_order m) noexcept;
563void atomic_wait_explicit(const atomic_flag* obj, T old, memory_order m) noexcept;
564void atomic_one(volatile atomic_flag* obj) noexcept;
565void atomic_one(atomic_flag* obj) noexcept;
566void atomic_all(volatile atomic_flag* obj) noexcept;
567void atomic_all(atomic_flag* obj) noexcept;
560void atomic_wait(const volatile atomic_flag* obj, T old) noexcept; // since C++20
561void atomic_wait(const atomic_flag* obj, T old) noexcept; // since C++20
562void atomic_wait_explicit(const volatile atomic_flag* obj, T old, memory_order m) noexcept; // since C++20
563void atomic_wait_explicit(const atomic_flag* obj, T old, memory_order m) noexcept; // since C++20
564void atomic_one(volatile atomic_flag* obj) noexcept; // since C++20
565void atomic_one(atomic_flag* obj) noexcept; // since C++20
566void atomic_all(volatile atomic_flag* obj) noexcept; // since C++20
567void atomic_all(atomic_flag* obj) noexcept; // since C++20
568568
569569// fences
570570
......@@ -587,46 +587,55 @@ template <class T>
587587
588588*/
589589
590#include <__config>
591
592#if _LIBCPP_STD_VER < 23 && defined(_LIBCPP_STDATOMIC_H)
593# error <atomic> is incompatible with <stdatomic.h> before C++23. Please compile with -std=c++23.
594#endif
595
596#include <__atomic/aliases.h>
597#include <__atomic/atomic.h>
598#include <__atomic/atomic_base.h>
599#include <__atomic/atomic_flag.h>
600#include <__atomic/atomic_init.h>
601#include <__atomic/atomic_lock_free.h>
602#include <__atomic/atomic_sync.h>
603#include <__atomic/check_memory_order.h>
604#include <__atomic/contention_t.h>
605#include <__atomic/cxx_atomic_impl.h>
606#include <__atomic/fence.h>
607#include <__atomic/is_always_lock_free.h>
608#include <__atomic/kill_dependency.h>
609#include <__atomic/memory_order.h>
610#include <version>
611
612#if _LIBCPP_STD_VER >= 20
613# include <__atomic/atomic_ref.h>
614#endif
615
616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
617# pragma GCC system_header
618#endif
619
620#ifdef _LIBCPP_HAS_NO_ATOMIC_HEADER
621# error <atomic> is not implemented
622#endif
623
624#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
625# include <cmath>
626# include <compare>
627# include <cstdlib>
628# include <cstring>
629# include <type_traits>
630#endif
590#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
591# include <__cxx03/atomic>
592#else
593# include <__config>
594
595# if defined(_LIBCPP_STDATOMIC_H) || defined(kill_dependency) || defined(atomic_load)
596# define _LIBCPP_STDATOMIC_H_HAS_DEFINITELY_BEEN_INCLUDED 1
597# else
598# define _LIBCPP_STDATOMIC_H_HAS_DEFINITELY_BEEN_INCLUDED 0
599# endif
600
601# if _LIBCPP_STD_VER < 23 && _LIBCPP_STDATOMIC_H_HAS_DEFINITELY_BEEN_INCLUDED
602# error <atomic> is incompatible with <stdatomic.h> before C++23. Please compile with -std=c++23.
603# endif
604
605# include <__atomic/aliases.h>
606# include <__atomic/atomic.h>
607# include <__atomic/atomic_flag.h>
608# include <__atomic/atomic_init.h>
609# include <__atomic/atomic_lock_free.h>
610# include <__atomic/atomic_sync.h>
611# include <__atomic/check_memory_order.h>
612# include <__atomic/contention_t.h>
613# include <__atomic/fence.h>
614# include <__atomic/is_always_lock_free.h>
615# include <__atomic/kill_dependency.h>
616# include <__atomic/memory_order.h>
617# include <version>
618
619# if _LIBCPP_STD_VER >= 20
620# include <__atomic/atomic_ref.h>
621# endif
622
623# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
624# pragma GCC system_header
625# endif
626
627# if !_LIBCPP_HAS_ATOMIC_HEADER
628# error <atomic> is not implemented
629# endif
630
631# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
632# include <cmath>
633# include <compare>
634# include <cstddef>
635# include <cstdlib>
636# include <cstring>
637# include <type_traits>
638# endif
639#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
631640
632641#endif // _LIBCPP_ATOMIC
lib/libcxx/include/barrier+43-144
......@@ -17,7 +17,7 @@ namespace std
1717{
1818
1919 template<class CompletionFunction = see below>
20 class barrier
20 class barrier // since C++20
2121 {
2222 public:
2323 using arrival_token = see below;
......@@ -45,30 +45,33 @@ namespace std
4545
4646*/
4747
48#include <__config>
49
50#if !defined(_LIBCPP_HAS_NO_THREADS)
51
52# include <__assert>
53# include <__atomic/atomic_base.h>
54# include <__atomic/memory_order.h>
55# include <__memory/unique_ptr.h>
56# include <__thread/poll_with_backoff.h>
57# include <__thread/timed_backoff_policy.h>
58# include <__utility/move.h>
59# include <cstddef>
60# include <cstdint>
61# include <limits>
62# include <version>
63
64# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
65# pragma GCC system_header
66# endif
48#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
49# include <__cxx03/barrier>
50#else
51# include <__config>
52
53# if _LIBCPP_HAS_THREADS
54
55# include <__assert>
56# include <__atomic/atomic.h>
57# include <__atomic/memory_order.h>
58# include <__cstddef/ptrdiff_t.h>
59# include <__memory/unique_ptr.h>
60# include <__thread/poll_with_backoff.h>
61# include <__thread/timed_backoff_policy.h>
62# include <__utility/move.h>
63# include <cstdint>
64# include <limits>
65# include <version>
66
67# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
68# pragma GCC system_header
69# endif
6770
6871_LIBCPP_PUSH_MACROS
69# include <__undef_macros>
72# include <__undef_macros>
7073
71# if _LIBCPP_STD_VER >= 14
74# if _LIBCPP_STD_VER >= 20
7275
7376_LIBCPP_BEGIN_NAMESPACE_STD
7477
......@@ -76,8 +79,6 @@ struct __empty_completion {
7679 inline _LIBCPP_HIDE_FROM_ABI void operator()() noexcept {}
7780};
7881
79# ifndef _LIBCPP_HAS_NO_TREE_BARRIER
80
8182/*
8283
8384The default implementation of __barrier_base is a classic tree barrier.
......@@ -92,7 +93,7 @@ It looks different from literature pseudocode for two main reasons:
9293
9394*/
9495
95using __barrier_phase_t = uint8_t;
96using __barrier_phase_t _LIBCPP_NODEBUG = uint8_t;
9697
9798class __barrier_algorithm_base;
9899
......@@ -109,9 +110,9 @@ template <class _CompletionF>
109110class __barrier_base {
110111 ptrdiff_t __expected_;
111112 unique_ptr<__barrier_algorithm_base, void (*)(__barrier_algorithm_base*)> __base_;
112 __atomic_base<ptrdiff_t> __expected_adjustment_;
113 atomic<ptrdiff_t> __expected_adjustment_;
113114 _CompletionF __completion_;
114 __atomic_base<__barrier_phase_t> __phase_;
115 atomic<__barrier_phase_t> __phase_;
115116
116117public:
117118 using arrival_token = __barrier_phase_t;
......@@ -125,7 +126,7 @@ public:
125126 __expected_adjustment_(0),
126127 __completion_(std::move(__completion)),
127128 __phase_(0) {}
128 _LIBCPP_NODISCARD _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI arrival_token arrive(ptrdiff_t __update) {
129 [[nodiscard]] _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI arrival_token arrive(ptrdiff_t __update) {
129130 _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
130131 __update <= __expected_, "update is greater than the expected count for the current barrier phase");
131132
......@@ -150,111 +151,8 @@ public:
150151 }
151152};
152153
153# else
154
155/*
156
157The alternative implementation of __barrier_base is a central barrier.
158
159Two versions of this algorithm are provided:
160 1. A fairly straightforward implementation of the litterature for the
161 general case where the completion function is not empty.
162 2. An optimized implementation that exploits 2's complement arithmetic
163 and well-defined overflow in atomic arithmetic, to handle the phase
164 roll-over for free.
165
166*/
167
168template <class _CompletionF>
169class __barrier_base {
170 __atomic_base<ptrdiff_t> __expected;
171 __atomic_base<ptrdiff_t> __arrived;
172 _CompletionF __completion;
173 __atomic_base<bool> __phase;
174
175public:
176 using arrival_token = bool;
177
178 static constexpr ptrdiff_t max() noexcept { return numeric_limits<ptrdiff_t>::max(); }
179
180 _LIBCPP_HIDE_FROM_ABI __barrier_base(ptrdiff_t __expected, _CompletionF __completion = _CompletionF())
181 : __expected(__expected), __arrived(__expected), __completion(std::move(__completion)), __phase(false) {}
182 [[nodiscard]] _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI arrival_token arrive(ptrdiff_t update) {
183 auto const __old_phase = __phase.load(memory_order_relaxed);
184 auto const __result = __arrived.fetch_sub(update, memory_order_acq_rel) - update;
185 auto const new_expected = __expected.load(memory_order_relaxed);
186
187 _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
188 update <= new_expected, "update is greater than the expected count for the current barrier phase");
189
190 if (0 == __result) {
191 __completion();
192 __arrived.store(new_expected, memory_order_relaxed);
193 __phase.store(!__old_phase, memory_order_release);
194 __phase.notify_all();
195 }
196 return __old_phase;
197 }
198 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void wait(arrival_token&& __old_phase) const {
199 __phase.wait(__old_phase, memory_order_acquire);
200 }
201 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void arrive_and_drop() {
202 __expected.fetch_sub(1, memory_order_relaxed);
203 (void)arrive(1);
204 }
205};
206
207template <>
208class __barrier_base<__empty_completion> {
209 static constexpr uint64_t __expected_unit = 1ull;
210 static constexpr uint64_t __arrived_unit = 1ull << 32;
211 static constexpr uint64_t __expected_mask = __arrived_unit - 1;
212 static constexpr uint64_t __phase_bit = 1ull << 63;
213 static constexpr uint64_t __arrived_mask = (__phase_bit - 1) & ~__expected_mask;
214
215 __atomic_base<uint64_t> __phase_arrived_expected;
216
217 static _LIBCPP_HIDE_FROM_ABI constexpr uint64_t __init(ptrdiff_t __count) _NOEXCEPT {
218 return ((uint64_t(1u << 31) - __count) << 32) | (uint64_t(1u << 31) - __count);
219 }
220
221public:
222 using arrival_token = uint64_t;
223
224 static constexpr ptrdiff_t max() noexcept { return ptrdiff_t(1u << 31) - 1; }
225
226 _LIBCPP_HIDE_FROM_ABI explicit inline __barrier_base(ptrdiff_t __count, __empty_completion = __empty_completion())
227 : __phase_arrived_expected(__init(__count)) {}
228 [[nodiscard]] inline _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI arrival_token arrive(ptrdiff_t update) {
229 auto const __inc = __arrived_unit * update;
230 auto const __old = __phase_arrived_expected.fetch_add(__inc, memory_order_acq_rel);
231
232 _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
233 update <= __old, "update is greater than the expected count for the current barrier phase");
234
235 if ((__old ^ (__old + __inc)) & __phase_bit) {
236 __phase_arrived_expected.fetch_add((__old & __expected_mask) << 32, memory_order_relaxed);
237 __phase_arrived_expected.notify_all();
238 }
239 return __old & __phase_bit;
240 }
241 inline _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void wait(arrival_token&& __phase) const {
242 auto const __test_fn = [=]() -> bool {
243 uint64_t const __current = __phase_arrived_expected.load(memory_order_acquire);
244 return ((__current & __phase_bit) != __phase);
245 };
246 __libcpp_thread_poll_with_backoff(__test_fn, __libcpp_timed_backoff_policy());
247 }
248 inline _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void arrive_and_drop() {
249 __phase_arrived_expected.fetch_add(__expected_unit, memory_order_relaxed);
250 (void)arrive(1);
251 }
252};
253
254# endif // !_LIBCPP_HAS_NO_TREE_BARRIER
255
256154template <class _CompletionF = __empty_completion>
257class _LIBCPP_DEPRECATED_ATOMIC_SYNC barrier {
155class barrier {
258156 __barrier_base<_CompletionF> __b_;
259157
260158public:
......@@ -277,7 +175,7 @@ public:
277175 barrier(barrier const&) = delete;
278176 barrier& operator=(barrier const&) = delete;
279177
280 _LIBCPP_NODISCARD _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI arrival_token arrive(ptrdiff_t __update = 1) {
178 [[nodiscard]] _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI arrival_token arrive(ptrdiff_t __update = 1) {
281179 _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__update > 0, "barrier:arrive must be called with a value greater than 0");
282180 return __b_.arrive(__update);
283181 }
......@@ -290,19 +188,20 @@ public:
290188
291189_LIBCPP_END_NAMESPACE_STD
292190
293# endif // _LIBCPP_STD_VER >= 14
191# endif // _LIBCPP_STD_VER >= 20
294192
295193_LIBCPP_POP_MACROS
296194
297#endif // !defined(_LIBCPP_HAS_NO_THREADS)
195# endif // _LIBCPP_HAS_THREADS
298196
299#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
300# include <atomic>
301# include <concepts>
302# include <iterator>
303# include <memory>
304# include <stdexcept>
305# include <variant>
306#endif
197# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
198# include <atomic>
199# include <concepts>
200# include <iterator>
201# include <memory>
202# include <stdexcept>
203# include <variant>
204# endif
205#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
307206
308#endif //_LIBCPP_BARRIER
207#endif // _LIBCPP_BARRIER
lib/libcxx/include/bit+36-36
......@@ -61,41 +61,41 @@ namespace std {
6161
6262*/
6363
64#include <__config>
65
66#if _LIBCPP_STD_VER >= 20
67# include <__bit/bit_cast.h>
68# include <__bit/bit_ceil.h>
69# include <__bit/bit_floor.h>
70# include <__bit/bit_log2.h>
71# include <__bit/bit_width.h>
72# include <__bit/countl.h>
73# include <__bit/countr.h>
74# include <__bit/endian.h>
75# include <__bit/has_single_bit.h>
76# include <__bit/popcount.h>
77# include <__bit/rotate.h>
78#endif
79
80#if _LIBCPP_STD_VER >= 23
81# include <__bit/byteswap.h>
82#endif
83
84#include <version>
85
86#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
87# pragma GCC system_header
88#endif
89
90#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
91# include <cstdint>
92#endif
93
94#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
95# include <cstdlib>
96# include <iosfwd>
97# include <limits>
98# include <type_traits>
99#endif
64#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
65# include <__cxx03/bit>
66#else
67# include <__config>
68
69# if _LIBCPP_STD_VER >= 20
70# include <__bit/bit_cast.h>
71# include <__bit/bit_ceil.h>
72# include <__bit/bit_floor.h>
73# include <__bit/bit_log2.h>
74# include <__bit/bit_width.h>
75# include <__bit/countl.h>
76# include <__bit/countr.h>
77# include <__bit/endian.h>
78# include <__bit/has_single_bit.h>
79# include <__bit/popcount.h>
80# include <__bit/rotate.h>
81# endif
82
83# if _LIBCPP_STD_VER >= 23
84# include <__bit/byteswap.h>
85# endif
86
87# include <version>
88
89# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
90# pragma GCC system_header
91# endif
92
93# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
94# include <cstdlib>
95# include <iosfwd>
96# include <limits>
97# include <type_traits>
98# endif
99#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
100100
101101#endif // _LIBCPP_BIT
lib/libcxx/include/bitset+135-125
......@@ -126,32 +126,38 @@ template <size_t N> struct hash<std::bitset<N>>;
126126
127127// clang-format on
128128
129#include <__algorithm/count.h>
130#include <__algorithm/fill.h>
131#include <__algorithm/find.h>
132#include <__bit_reference>
133#include <__config>
134#include <__functional/hash.h>
135#include <__functional/unary_function.h>
136#include <__type_traits/is_char_like_type.h>
137#include <climits>
138#include <cstddef>
139#include <stdexcept>
140#include <string_view>
141#include <version>
129#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
130# include <__cxx03/bitset>
131#else
132# include <__algorithm/count.h>
133# include <__algorithm/fill.h>
134# include <__algorithm/fill_n.h>
135# include <__algorithm/find.h>
136# include <__assert>
137# include <__bit_reference>
138# include <__config>
139# include <__cstddef/ptrdiff_t.h>
140# include <__cstddef/size_t.h>
141# include <__functional/hash.h>
142# include <__functional/unary_function.h>
143# include <__type_traits/is_char_like_type.h>
144# include <climits>
145# include <stdexcept>
146# include <string_view>
147# include <version>
142148
143149// standard-mandated includes
144150
145151// [bitset.syn]
146#include <iosfwd>
147#include <string>
152# include <iosfwd>
153# include <string>
148154
149#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
150# pragma GCC system_header
151#endif
155# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
156# pragma GCC system_header
157# endif
152158
153159_LIBCPP_PUSH_MACROS
154#include <__undef_macros>
160# include <__undef_macros>
155161
156162_LIBCPP_BEGIN_NAMESPACE_STD
157163
......@@ -166,9 +172,7 @@ struct __has_storage_type<__bitset<_N_words, _Size> > {
166172template <size_t _N_words, size_t _Size>
167173class __bitset {
168174public:
169 typedef ptrdiff_t difference_type;
170 typedef size_t size_type;
171 typedef size_type __storage_type;
175 typedef size_t __storage_type;
172176
173177protected:
174178 typedef __bitset __self;
......@@ -185,9 +189,9 @@ protected:
185189 __storage_type __first_[_N_words];
186190
187191 typedef __bit_reference<__bitset> reference;
188 typedef __bit_const_reference<__bitset> const_reference;
189 typedef __bit_iterator<__bitset, false> iterator;
190 typedef __bit_iterator<__bitset, true> const_iterator;
192 typedef __bit_const_reference<__bitset> __const_reference;
193 typedef __bit_iterator<__bitset, false> __iterator;
194 typedef __bit_iterator<__bitset, true> __const_iterator;
191195
192196 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
193197 _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
......@@ -195,14 +199,14 @@ protected:
195199 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT {
196200 return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
197201 }
198 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT {
199 return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
202 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __const_reference __make_ref(size_t __pos) const _NOEXCEPT {
203 return __const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
200204 }
201 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT {
202 return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
205 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __iterator __make_iter(size_t __pos) _NOEXCEPT {
206 return __iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
203207 }
204 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
205 return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
208 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
209 return __const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
206210 }
207211
208212 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT;
......@@ -222,10 +226,10 @@ protected:
222226 _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;
223227
224228private:
225#ifdef _LIBCPP_CXX03_LANG
229# ifdef _LIBCPP_CXX03_LANG
226230 void __init(unsigned long long __v, false_type) _NOEXCEPT;
227231 _LIBCPP_HIDE_FROM_ABI void __init(unsigned long long __v, true_type) _NOEXCEPT;
228#endif // _LIBCPP_CXX03_LANG
232# endif // _LIBCPP_CXX03_LANG
229233 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(false_type) const;
230234 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(true_type) const;
231235 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(false_type) const;
......@@ -236,16 +240,16 @@ private:
236240
237241template <size_t _N_words, size_t _Size>
238242inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset() _NOEXCEPT
239#ifndef _LIBCPP_CXX03_LANG
243# ifndef _LIBCPP_CXX03_LANG
240244 : __first_{0}
241#endif
245# endif
242246{
243#ifdef _LIBCPP_CXX03_LANG
247# ifdef _LIBCPP_CXX03_LANG
244248 std::fill_n(__first_, _N_words, __storage_type(0));
245#endif
249# endif
246250}
247251
248#ifdef _LIBCPP_CXX03_LANG
252# ifdef _LIBCPP_CXX03_LANG
249253
250254template <size_t _N_words, size_t _Size>
251255void __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT {
......@@ -271,54 +275,54 @@ inline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::__init(unsigned lon
271275 std::fill(__first_ + 1, __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));
272276}
273277
274#endif // _LIBCPP_CXX03_LANG
278# endif // _LIBCPP_CXX03_LANG
275279
276280template <size_t _N_words, size_t _Size>
277281inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
278#ifndef _LIBCPP_CXX03_LANG
279# if __SIZEOF_SIZE_T__ == 8
282# ifndef _LIBCPP_CXX03_LANG
283# if __SIZEOF_SIZE_T__ == 8
280284 : __first_{__v}
281# elif __SIZEOF_SIZE_T__ == 4
285# elif __SIZEOF_SIZE_T__ == 4
282286 : __first_{static_cast<__storage_type>(__v),
283287 _Size >= 2 * __bits_per_word
284288 ? static_cast<__storage_type>(__v >> __bits_per_word)
285289 : static_cast<__storage_type>((__v >> __bits_per_word) &
286290 (__storage_type(1) << (_Size - __bits_per_word)) - 1)}
287# else
288# error This constructor has not been ported to this platform
291# else
292# error This constructor has not been ported to this platform
293# endif
289294# endif
290#endif
291295{
292#ifdef _LIBCPP_CXX03_LANG
296# ifdef _LIBCPP_CXX03_LANG
293297 __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
294#endif
298# endif
295299}
296300
297301template <size_t _N_words, size_t _Size>
298302inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
299303__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT {
300 for (size_type __i = 0; __i < _N_words; ++__i)
304 for (size_t __i = 0; __i < _N_words; ++__i)
301305 __first_[__i] &= __v.__first_[__i];
302306}
303307
304308template <size_t _N_words, size_t _Size>
305309inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
306310__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT {
307 for (size_type __i = 0; __i < _N_words; ++__i)
311 for (size_t __i = 0; __i < _N_words; ++__i)
308312 __first_[__i] |= __v.__first_[__i];
309313}
310314
311315template <size_t _N_words, size_t _Size>
312316inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
313317__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {
314 for (size_type __i = 0; __i < _N_words; ++__i)
318 for (size_t __i = 0; __i < _N_words; ++__i)
315319 __first_[__i] ^= __v.__first_[__i];
316320}
317321
318322template <size_t _N_words, size_t _Size>
319323_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Size>::flip() _NOEXCEPT {
320324 // do middle whole words
321 size_type __n = _Size;
325 size_t __n = _Size;
322326 __storage_pointer __p = __first_;
323327 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
324328 *__p = ~*__p;
......@@ -334,8 +338,8 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Siz
334338template <size_t _N_words, size_t _Size>
335339_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
336340__bitset<_N_words, _Size>::to_ulong(false_type) const {
337 const_iterator __e = __make_iter(_Size);
338 const_iterator __i = std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
341 __const_iterator __e = __make_iter(_Size);
342 __const_iterator __i = std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
339343 if (__i != __e)
340344 __throw_overflow_error("bitset to_ulong overflow error");
341345
......@@ -351,8 +355,8 @@ __bitset<_N_words, _Size>::to_ulong(true_type) const {
351355template <size_t _N_words, size_t _Size>
352356_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
353357__bitset<_N_words, _Size>::to_ullong(false_type) const {
354 const_iterator __e = __make_iter(_Size);
355 const_iterator __i = std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
358 __const_iterator __e = __make_iter(_Size);
359 __const_iterator __i = std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
356360 if (__i != __e)
357361 __throw_overflow_error("bitset to_ullong overflow error");
358362
......@@ -386,7 +390,7 @@ __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const {
386390template <size_t _N_words, size_t _Size>
387391_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::all() const _NOEXCEPT {
388392 // do middle whole words
389 size_type __n = _Size;
393 size_t __n = _Size;
390394 __const_storage_pointer __p = __first_;
391395 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
392396 if (~*__p)
......@@ -403,7 +407,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Siz
403407template <size_t _N_words, size_t _Size>
404408_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::any() const _NOEXCEPT {
405409 // do middle whole words
406 size_type __n = _Size;
410 size_t __n = _Size;
407411 __const_storage_pointer __p = __first_;
408412 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
409413 if (*__p)
......@@ -420,7 +424,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Siz
420424template <size_t _N_words, size_t _Size>
421425inline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT {
422426 size_t __h = 0;
423 for (size_type __i = 0; __i < _N_words; ++__i)
427 for (size_t __i = 0; __i < _N_words; ++__i)
424428 __h ^= __first_[__i];
425429 return __h;
426430}
......@@ -428,9 +432,7 @@ inline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT {
428432template <size_t _Size>
429433class __bitset<1, _Size> {
430434public:
431 typedef ptrdiff_t difference_type;
432 typedef size_t size_type;
433 typedef size_type __storage_type;
435 typedef size_t __storage_type;
434436
435437protected:
436438 typedef __bitset __self;
......@@ -447,9 +449,9 @@ protected:
447449 __storage_type __first_;
448450
449451 typedef __bit_reference<__bitset> reference;
450 typedef __bit_const_reference<__bitset> const_reference;
451 typedef __bit_iterator<__bitset, false> iterator;
452 typedef __bit_iterator<__bitset, true> const_iterator;
452 typedef __bit_const_reference<__bitset> __const_reference;
453 typedef __bit_iterator<__bitset, false> __iterator;
454 typedef __bit_iterator<__bitset, true> __const_iterator;
453455
454456 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
455457 _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
......@@ -457,14 +459,14 @@ protected:
457459 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT {
458460 return reference(&__first_, __storage_type(1) << __pos);
459461 }
460 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT {
461 return const_reference(&__first_, __storage_type(1) << __pos);
462 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __const_reference __make_ref(size_t __pos) const _NOEXCEPT {
463 return __const_reference(&__first_, __storage_type(1) << __pos);
462464 }
463 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT {
464 return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
465 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __iterator __make_iter(size_t __pos) _NOEXCEPT {
466 return __iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
465467 }
466 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
467 return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
468 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
469 return __const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
468470 }
469471
470472 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT;
......@@ -545,9 +547,7 @@ inline size_t __bitset<1, _Size>::__hash_code() const _NOEXCEPT {
545547template <>
546548class __bitset<0, 0> {
547549public:
548 typedef ptrdiff_t difference_type;
549 typedef size_t size_type;
550 typedef size_type __storage_type;
550 typedef size_t __storage_type;
551551
552552protected:
553553 typedef __bitset __self;
......@@ -562,9 +562,9 @@ protected:
562562 friend struct __bit_array<__bitset>;
563563
564564 typedef __bit_reference<__bitset> reference;
565 typedef __bit_const_reference<__bitset> const_reference;
566 typedef __bit_iterator<__bitset, false> iterator;
567 typedef __bit_iterator<__bitset, true> const_iterator;
565 typedef __bit_const_reference<__bitset> __const_reference;
566 typedef __bit_iterator<__bitset, false> __iterator;
567 typedef __bit_iterator<__bitset, true> __const_iterator;
568568
569569 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
570570 _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
......@@ -572,14 +572,14 @@ protected:
572572 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t) _NOEXCEPT {
573573 return reference(nullptr, 1);
574574 }
575 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT {
576 return const_reference(nullptr, 1);
575 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __const_reference __make_ref(size_t) const _NOEXCEPT {
576 return __const_reference(nullptr, 1);
577577 }
578 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t) _NOEXCEPT {
579 return iterator(nullptr, 0);
578 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __iterator __make_iter(size_t) _NOEXCEPT {
579 return __iterator(nullptr, 0);
580580 }
581 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t) const _NOEXCEPT {
582 return const_iterator(nullptr, 0);
581 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __const_iterator __make_iter(size_t) const _NOEXCEPT {
582 return __const_iterator(nullptr, 0);
583583 }
584584
585585 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset&) _NOEXCEPT {}
......@@ -611,30 +611,30 @@ class _LIBCPP_TEMPLATE_VIS bitset
611611 : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> {
612612public:
613613 static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
614 typedef __bitset<__n_words, _Size> base;
614 typedef __bitset<__n_words, _Size> __base;
615615
616616public:
617 typedef typename base::reference reference;
618 typedef typename base::const_reference const_reference;
617 typedef typename __base::reference reference;
618 typedef typename __base::__const_reference __const_reference;
619619
620620 // 23.3.5.1 constructors:
621621 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
622 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
622 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset(unsigned long long __v) _NOEXCEPT : __base(__v) {}
623623 template <class _CharT, __enable_if_t<_IsCharLikeType<_CharT>::value, int> = 0>
624624 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset(
625625 const _CharT* __str,
626#if _LIBCPP_STD_VER >= 26
626# if _LIBCPP_STD_VER >= 26
627627 typename basic_string_view<_CharT>::size_type __n = basic_string_view<_CharT>::npos,
628#else
628# else
629629 typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
630#endif
630# endif
631631 _CharT __zero = _CharT('0'),
632632 _CharT __one = _CharT('1')) {
633633
634634 size_t __rlen = std::min(__n, char_traits<_CharT>::length(__str));
635635 __init_from_string_view(basic_string_view<_CharT>(__str, __rlen), __zero, __one);
636636 }
637#if _LIBCPP_STD_VER >= 26
637# if _LIBCPP_STD_VER >= 26
638638 template <class _CharT, class _Traits>
639639 _LIBCPP_HIDE_FROM_ABI constexpr explicit bitset(
640640 basic_string_view<_CharT, _Traits> __str,
......@@ -648,7 +648,7 @@ public:
648648 size_t __rlen = std::min(__n, __str.size() - __pos);
649649 __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one);
650650 }
651#endif
651# endif
652652 template <class _CharT, class _Traits, class _Allocator>
653653 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset(
654654 const basic_string<_CharT, _Traits, _Allocator>& __str,
......@@ -679,12 +679,21 @@ public:
679679 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& flip(size_t __pos);
680680
681681 // element access:
682#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
683 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator[](size_t __p) const { return base::__make_ref(__p); }
684#else
685 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference operator[](size_t __p) const { return base::__make_ref(__p); }
686#endif
687 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference operator[](size_t __p) { return base::__make_ref(__p); }
682# ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
683 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator[](size_t __p) const {
684 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p < _Size, "bitset::operator[] index out of bounds");
685 return __base::__make_ref(__p);
686 }
687# else
688 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __const_reference operator[](size_t __p) const {
689 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p < _Size, "bitset::operator[] index out of bounds");
690 return __base::__make_ref(__p);
691 }
692# endif
693 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference operator[](size_t __p) {
694 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p < _Size, "bitset::operator[] index out of bounds");
695 return __base::__make_ref(__p);
696 }
688697 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const;
689698 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const;
690699 template <class _CharT, class _Traits, class _Allocator>
......@@ -701,9 +710,9 @@ public:
701710 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t count() const _NOEXCEPT;
702711 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT { return _Size; }
703712 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const bitset& __rhs) const _NOEXCEPT;
704#if _LIBCPP_STD_VER <= 17
713# if _LIBCPP_STD_VER <= 17
705714 _LIBCPP_HIDE_FROM_ABI bool operator!=(const bitset& __rhs) const _NOEXCEPT;
706#endif
715# endif
707716 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool test(size_t __pos) const;
708717 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
709718 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
......@@ -725,10 +734,10 @@ private:
725734 _CharT __c = __str[__mp - 1 - __i];
726735 (*this)[__i] = _Traits::eq(__c, __one);
727736 }
728 std::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
737 std::fill(__base::__make_iter(__i), __base::__make_iter(_Size), false);
729738 }
730739
731 _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return base::__hash_code(); }
740 _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return __base::__hash_code(); }
732741
733742 friend struct hash<bitset>;
734743};
......@@ -736,43 +745,43 @@ private:
736745template <size_t _Size>
737746inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&
738747bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT {
739 base::operator&=(__rhs);
748 __base::operator&=(__rhs);
740749 return *this;
741750}
742751
743752template <size_t _Size>
744753inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&
745754bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT {
746 base::operator|=(__rhs);
755 __base::operator|=(__rhs);
747756 return *this;
748757}
749758
750759template <size_t _Size>
751760inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&
752761bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT {
753 base::operator^=(__rhs);
762 __base::operator^=(__rhs);
754763 return *this;
755764}
756765
757766template <size_t _Size>
758767_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT {
759768 __pos = std::min(__pos, _Size);
760 std::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
761 std::fill_n(base::__make_iter(0), __pos, false);
769 std::copy_backward(__base::__make_iter(0), __base::__make_iter(_Size - __pos), __base::__make_iter(_Size));
770 std::fill_n(__base::__make_iter(0), __pos, false);
762771 return *this;
763772}
764773
765774template <size_t _Size>
766775_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT {
767776 __pos = std::min(__pos, _Size);
768 std::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
769 std::fill_n(base::__make_iter(_Size - __pos), __pos, false);
777 std::copy(__base::__make_iter(__pos), __base::__make_iter(_Size), __base::__make_iter(0));
778 std::fill_n(__base::__make_iter(_Size - __pos), __pos, false);
770779 return *this;
771780}
772781
773782template <size_t _Size>
774783inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set() _NOEXCEPT {
775 std::fill_n(base::__make_iter(0), _Size, true);
784 std::fill_n(__base::__make_iter(0), _Size, true);
776785 return *this;
777786}
778787
......@@ -787,7 +796,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>
787796
788797template <size_t _Size>
789798inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset() _NOEXCEPT {
790 std::fill_n(base::__make_iter(0), _Size, false);
799 std::fill_n(__base::__make_iter(0), _Size, false);
791800 return *this;
792801}
793802
......@@ -809,7 +818,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> bitset<
809818
810819template <size_t _Size>
811820inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip() _NOEXCEPT {
812 base::flip();
821 __base::flip();
813822 return *this;
814823}
815824
......@@ -818,19 +827,19 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>
818827 if (__pos >= _Size)
819828 __throw_out_of_range("bitset flip argument out of range");
820829
821 reference __r = base::__make_ref(__pos);
830 reference __r = __base::__make_ref(__pos);
822831 __r = ~__r;
823832 return *this;
824833}
825834
826835template <size_t _Size>
827836inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long bitset<_Size>::to_ulong() const {
828 return base::to_ulong();
837 return __base::to_ulong();
829838}
830839
831840template <size_t _Size>
832841inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long bitset<_Size>::to_ullong() const {
833 return base::to_ullong();
842 return __base::to_ullong();
834843}
835844
836845template <size_t _Size>
......@@ -867,23 +876,23 @@ bitset<_Size>::to_string(char __zero, char __one) const {
867876
868877template <size_t _Size>
869878inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t bitset<_Size>::count() const _NOEXCEPT {
870 return static_cast<size_t>(std::count(base::__make_iter(0), base::__make_iter(_Size), true));
879 return static_cast<size_t>(std::count(__base::__make_iter(0), __base::__make_iter(_Size), true));
871880}
872881
873882template <size_t _Size>
874883inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool
875884bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT {
876 return std::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
885 return std::equal(__base::__make_iter(0), __base::__make_iter(_Size), __rhs.__make_iter(0));
877886}
878887
879#if _LIBCPP_STD_VER <= 17
888# if _LIBCPP_STD_VER <= 17
880889
881890template <size_t _Size>
882891inline _LIBCPP_HIDE_FROM_ABI bool bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT {
883892 return !(*this == __rhs);
884893}
885894
886#endif
895# endif
887896
888897template <size_t _Size>
889898_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::test(size_t __pos) const {
......@@ -895,12 +904,12 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::test(siz
895904
896905template <size_t _Size>
897906inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::all() const _NOEXCEPT {
898 return base::all();
907 return __base::all();
899908}
900909
901910template <size_t _Size>
902911inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::any() const _NOEXCEPT {
903 return base::any();
912 return __base::any();
904913}
905914
906915template <size_t _Size>
......@@ -960,10 +969,11 @@ _LIBCPP_END_NAMESPACE_STD
960969
961970_LIBCPP_POP_MACROS
962971
963#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
964# include <concepts>
965# include <cstdlib>
966# include <type_traits>
967#endif
972# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
973# include <concepts>
974# include <cstdlib>
975# include <type_traits>
976# endif
977#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
968978
969979#endif // _LIBCPP_BITSET
lib/libcxx/include/cassert+13-9
......@@ -16,16 +16,20 @@ Macros:
1616
1717*/
1818
19#include <__config>
19#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
20# include <__cxx03/cassert>
21#else
22# include <__config>
2023
2124// <assert.h> is not provided by libc++
22#if __has_include(<assert.h>)
23# include <assert.h>
24# ifdef _LIBCPP_ASSERT_H
25# error "If libc++ starts defining <assert.h>, the __has_include check should move to libc++'s <assert.h>"
25# if __has_include(<assert.h>)
26# include <assert.h>
27# ifdef _LIBCPP_ASSERT_H
28# error "If libc++ starts defining <assert.h>, the __has_include check should move to libc++'s <assert.h>"
29# endif
2630# endif
27#endif
2831
29#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
30# pragma GCC system_header
31#endif
32# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
33# pragma GCC system_header
34# endif
35#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
lib/libcxx/include/ccomplex+21-4
......@@ -17,10 +17,27 @@
1717
1818*/
1919
20#include <complex>
20#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
21# include <__cxx03/ccomplex>
22#else
23# include <complex>
24
25# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26# pragma GCC system_header
27# endif
28
29# if _LIBCPP_STD_VER >= 20
30
31using __standard_header_ccomplex
32 _LIBCPP_DEPRECATED_("removed in C++20. Include <complex> instead.") _LIBCPP_NODEBUG = void;
33using __use_standard_header_ccomplex _LIBCPP_NODEBUG = __standard_header_ccomplex;
34
35# elif _LIBCPP_STD_VER >= 17
36
37using __standard_header_ccomplex _LIBCPP_DEPRECATED_("Include <complex> instead.") _LIBCPP_NODEBUG = void;
38using __use_standard_header_ccomplex _LIBCPP_NODEBUG = __standard_header_ccomplex;
2139
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24#endif
40# endif
41#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
2542
2643#endif // _LIBCPP_CCOMPLEX
lib/libcxx/include/cctype+53-49
......@@ -34,78 +34,81 @@ int toupper(int c);
3434} // std
3535*/
3636
37#include <__config>
37#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
38# include <__cxx03/cctype>
39#else
40# include <__config>
3841
39#include <ctype.h>
42# include <ctype.h>
4043
41#ifndef _LIBCPP_CTYPE_H
44# ifndef _LIBCPP_CTYPE_H
4245# error <cctype> tried including <ctype.h> but didn't find libc++'s <ctype.h> header. \
4346 This usually means that your header search paths are not configured properly. \
4447 The header search paths should contain the C++ Standard Library headers before \
4548 any C Standard Library.
46#endif
49# endif
4750
48#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
49# pragma GCC system_header
50#endif
51# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
52# pragma GCC system_header
53# endif
5154
5255_LIBCPP_BEGIN_NAMESPACE_STD
5356
54#ifdef isalnum
55# undef isalnum
56#endif
57# ifdef isalnum
58# undef isalnum
59# endif
5760
58#ifdef isalpha
59# undef isalpha
60#endif
61# ifdef isalpha
62# undef isalpha
63# endif
6164
62#ifdef isblank
63# undef isblank
64#endif
65# ifdef isblank
66# undef isblank
67# endif
6568
66#ifdef iscntrl
67# undef iscntrl
68#endif
69# ifdef iscntrl
70# undef iscntrl
71# endif
6972
70#ifdef isdigit
71# undef isdigit
72#endif
73# ifdef isdigit
74# undef isdigit
75# endif
7376
74#ifdef isgraph
75# undef isgraph
76#endif
77# ifdef isgraph
78# undef isgraph
79# endif
7780
78#ifdef islower
79# undef islower
80#endif
81# ifdef islower
82# undef islower
83# endif
8184
82#ifdef isprint
83# undef isprint
84#endif
85# ifdef isprint
86# undef isprint
87# endif
8588
86#ifdef ispunct
87# undef ispunct
88#endif
89# ifdef ispunct
90# undef ispunct
91# endif
8992
90#ifdef isspace
91# undef isspace
92#endif
93# ifdef isspace
94# undef isspace
95# endif
9396
94#ifdef isupper
95# undef isupper
96#endif
97# ifdef isupper
98# undef isupper
99# endif
97100
98#ifdef isxdigit
99# undef isxdigit
100#endif
101# ifdef isxdigit
102# undef isxdigit
103# endif
101104
102#ifdef tolower
103# undef tolower
104#endif
105# ifdef tolower
106# undef tolower
107# endif
105108
106#ifdef toupper
107# undef toupper
108#endif
109# ifdef toupper
110# undef toupper
111# endif
109112
110113using ::isalnum _LIBCPP_USING_IF_EXISTS;
111114using ::isalpha _LIBCPP_USING_IF_EXISTS;
......@@ -123,5 +126,6 @@ using ::tolower _LIBCPP_USING_IF_EXISTS;
123126using ::toupper _LIBCPP_USING_IF_EXISTS;
124127
125128_LIBCPP_END_NAMESPACE_STD
129#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
126130
127131#endif // _LIBCPP_CCTYPE
lib/libcxx/include/cerrno+11-7
......@@ -22,21 +22,24 @@ Macros:
2222
2323*/
2424
25#include <__config>
25#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
26# include <__cxx03/cerrno>
27#else
28# include <__config>
2629
27#include <errno.h>
30# include <errno.h>
2831
29#ifndef _LIBCPP_ERRNO_H
32# ifndef _LIBCPP_ERRNO_H
3033# error <cerrno> tried including <errno.h> but didn't find libc++'s <errno.h> header. \
3134 This usually means that your header search paths are not configured properly. \
3235 The header search paths should contain the C++ Standard Library headers before \
3336 any C Standard Library, and you are probably using compiler flags that make that \
3437 not be the case.
35#endif
38# endif
3639
37#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
38# pragma GCC system_header
39#endif
40# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
41# pragma GCC system_header
42# endif
4043
4144// LWG3869 Deprecate std::errc constants related to UNIX STREAMS
4245//
......@@ -44,5 +47,6 @@ Macros:
4447// deprecated in libc++ in https://github.com/llvm/llvm-project/pull/80542.
4548// Based on the post commit feedback the macro are no longer deprecated.
4649// Instead libc++ leaves the deprecation to the provider of errno.h.
50#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
4751
4852#endif // _LIBCPP_CERRNO
lib/libcxx/include/cfenv+12-7
......@@ -52,21 +52,24 @@ int feupdateenv(const fenv_t* envp);
5252} // std
5353*/
5454
55#include <__config>
55#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
56# include <__cxx03/cfenv>
57#else
58# include <__config>
5659
57#include <fenv.h>
60# include <fenv.h>
5861
59#ifndef _LIBCPP_FENV_H
62# ifndef _LIBCPP_FENV_H
6063# error <cfenv> tried including <fenv.h> but didn't find libc++'s <fenv.h> header. \
6164 This usually means that your header search paths are not configured properly. \
6265 The header search paths should contain the C++ Standard Library headers before \
6366 any C Standard Library, and you are probably using compiler flags that make that \
6467 not be the case.
65#endif
68# endif
6669
67#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
68# pragma GCC system_header
69#endif
70# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
71# pragma GCC system_header
72# endif
7073
7174_LIBCPP_BEGIN_NAMESPACE_STD
7275
......@@ -87,4 +90,6 @@ using ::feupdateenv _LIBCPP_USING_IF_EXISTS;
8790
8891_LIBCPP_END_NAMESPACE_STD
8992
93#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
94
9095#endif // _LIBCPP_CFENV
lib/libcxx/include/cfloat+11-7
......@@ -69,20 +69,24 @@ Macros:
6969 LDBL_TRUE_MIN // C11
7070*/
7171
72#include <__config>
72#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
73# include <__cxx03/cfloat>
74#else
75# include <__config>
7376
74#include <float.h>
77# include <float.h>
7578
76#ifndef _LIBCPP_FLOAT_H
79# ifndef _LIBCPP_FLOAT_H
7780# error <cfloat> tried including <float.h> but didn't find libc++'s <float.h> header. \
7881 This usually means that your header search paths are not configured properly. \
7982 The header search paths should contain the C++ Standard Library headers before \
8083 any C Standard Library, and you are probably using compiler flags that make that \
8184 not be the case.
82#endif
85# endif
8386
84#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
85# pragma GCC system_header
86#endif
87# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
88# pragma GCC system_header
89# endif
90#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
8791
8892#endif // _LIBCPP_CFLOAT
lib/libcxx/include/charconv+43-37
......@@ -65,51 +65,57 @@ namespace std {
6565 constexpr from_chars_result from_chars(const char* first, const char* last,
6666 see below& value, int base = 10); // constexpr since C++23
6767
68} // namespace std
69
70*/
68 from_chars_result from_chars(const char* first, const char* last,
69 float& value, chars_format fmt);
7170
72#include <__config>
71 from_chars_result from_chars(const char* first, const char* last,
72 double& value, chars_format fmt);
7373
74#if _LIBCPP_STD_VER >= 17
75# include <__charconv/chars_format.h>
76# include <__charconv/from_chars_integral.h>
77# include <__charconv/from_chars_result.h>
78# include <__charconv/tables.h>
79# include <__charconv/to_chars.h>
80# include <__charconv/to_chars_base_10.h>
81# include <__charconv/to_chars_floating_point.h>
82# include <__charconv/to_chars_integral.h>
83# include <__charconv/to_chars_result.h>
84# include <__charconv/traits.h>
85#endif // _LIBCPP_STD_VER >= 17
74} // namespace std
8675
87#include <version>
76*/
8877
89#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
90# pragma GCC system_header
91#endif
78#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
79# include <__cxx03/charconv>
80#else
81# include <__config>
82
83# if _LIBCPP_STD_VER >= 17
84# include <__charconv/chars_format.h>
85# include <__charconv/from_chars_floating_point.h>
86# include <__charconv/from_chars_integral.h>
87# include <__charconv/from_chars_result.h>
88# include <__charconv/tables.h>
89# include <__charconv/to_chars.h>
90# include <__charconv/to_chars_base_10.h>
91# include <__charconv/to_chars_floating_point.h>
92# include <__charconv/to_chars_integral.h>
93# include <__charconv/to_chars_result.h>
94# include <__charconv/traits.h>
95# endif // _LIBCPP_STD_VER >= 17
96
97# include <version>
98
99# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
100# pragma GCC system_header
101# endif
92102
93103_LIBCPP_BEGIN_NAMESPACE_STD
94104
95105_LIBCPP_END_NAMESPACE_STD
96106
97#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 14
98# include <cerrno>
99# include <cstddef>
100# include <initializer_list>
101# include <new>
102#endif
103
104#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
105# include <cmath>
106# include <concepts>
107# include <cstdint>
108# include <cstdlib>
109# include <cstring>
110# include <iosfwd>
111# include <limits>
112# include <type_traits>
113#endif
107# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
108# include <cmath>
109# include <concepts>
110# include <cstddef>
111# include <cstdint>
112# include <cstdlib>
113# include <cstring>
114# include <iosfwd>
115# include <limits>
116# include <new>
117# include <type_traits>
118# endif
119#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
114120
115121#endif // _LIBCPP_CHARCONV
lib/libcxx/include/chrono+112-71
......@@ -300,6 +300,41 @@ template<class charT, class traits> // C++20
300300 basic_ostream<charT, traits>&
301301 operator<<(basic_ostream<charT, traits>& os, const sys_days& dp);
302302
303// [time.clock.utc], class utc_clock
304class utc_clock { // C++20
305public:
306 using rep = a signed arithmetic type;
307 using period = ratio<unspecified, unspecified>;
308 using duration = chrono::duration<rep, period>;
309 using time_point = chrono::time_point<utc_clock>;
310 static constexpr bool is_steady = unspecified;
311
312 static time_point now();
313
314 template<class Duration>
315 static sys_time<common_type_t<Duration, seconds>>
316 to_sys(const utc_time<Duration>& t);
317 template<class Duration>
318 static utc_time<common_type_t<Duration, seconds>>
319 from_sys(const sys_time<Duration>& t);
320};
321
322template<class Duration>
323using utc_time = time_point<utc_clock, Duration>; // C++20
324using utc_seconds = utc_time<seconds>; // C++20
325
326template<class charT, class traits, class Duration> // C++20
327 basic_ostream<charT, traits>&
328 operator<<(basic_ostream<charT, traits>& os, const utc_time<Duration>& t);
329
330struct leap_second_info { // C++20
331 bool is_leap_second;
332 seconds elapsed;
333};
334
335template<class Duration> // C++20
336 leap_second_info get_leap_second_info(const utc_time<Duration>& ut);
337
303338class file_clock // C++20
304339{
305340public:
......@@ -861,6 +896,8 @@ strong_ordering operator<=>(const time_zone_link& x, const time_zone_link& y);
861896namespace std {
862897 template<class Duration, class charT>
863898 struct formatter<chrono::sys_time<Duration>, charT>; // C++20
899 template<class Duration, class charT>
900 struct formatter<chrono::utc_time<Duration>, charT>; // C++20
864901 template<class Duration, class charT>
865902 struct formatter<chrono::filetime<Duration>, charT>; // C++20
866903 template<class Duration, class charT>
......@@ -939,84 +976,88 @@ constexpr chrono::year operator ""y(unsigned lo
939976
940977// clang-format on
941978
942#include <__config>
943
944#include <__chrono/duration.h>
945#include <__chrono/file_clock.h>
946#include <__chrono/high_resolution_clock.h>
947#include <__chrono/steady_clock.h>
948#include <__chrono/system_clock.h>
949#include <__chrono/time_point.h>
950
951#if _LIBCPP_STD_VER >= 20
952# include <__chrono/calendar.h>
953# include <__chrono/day.h>
954# include <__chrono/exception.h>
955# include <__chrono/hh_mm_ss.h>
956# include <__chrono/literals.h>
957# include <__chrono/local_info.h>
958# include <__chrono/month.h>
959# include <__chrono/month_weekday.h>
960# include <__chrono/monthday.h>
961# include <__chrono/sys_info.h>
962# include <__chrono/weekday.h>
963# include <__chrono/year.h>
964# include <__chrono/year_month.h>
965# include <__chrono/year_month_day.h>
966# include <__chrono/year_month_weekday.h>
967
968# if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
969# include <__chrono/formatter.h>
970# include <__chrono/ostream.h>
971# include <__chrono/parser_std_format_spec.h>
972# include <__chrono/statically_widen.h>
973# endif
979#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
980# include <__cxx03/chrono>
981#else
982# include <__config>
983
984# include <__chrono/duration.h>
985# include <__chrono/file_clock.h>
986# include <__chrono/high_resolution_clock.h>
987# include <__chrono/steady_clock.h>
988# include <__chrono/system_clock.h>
989# include <__chrono/time_point.h>
990
991# if _LIBCPP_STD_VER >= 20
992# include <__chrono/calendar.h>
993# include <__chrono/day.h>
994# include <__chrono/exception.h>
995# include <__chrono/hh_mm_ss.h>
996# include <__chrono/literals.h>
997# include <__chrono/local_info.h>
998# include <__chrono/month.h>
999# include <__chrono/month_weekday.h>
1000# include <__chrono/monthday.h>
1001# include <__chrono/sys_info.h>
1002# include <__chrono/weekday.h>
1003# include <__chrono/year.h>
1004# include <__chrono/year_month.h>
1005# include <__chrono/year_month_day.h>
1006# include <__chrono/year_month_weekday.h>
1007
1008# if _LIBCPP_HAS_LOCALIZATION
1009# include <__chrono/formatter.h>
1010# include <__chrono/ostream.h>
1011# include <__chrono/parser_std_format_spec.h>
1012# include <__chrono/statically_widen.h>
1013# endif
1014
1015# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
1016# include <__chrono/leap_second.h>
1017# include <__chrono/time_zone.h>
1018# include <__chrono/time_zone_link.h>
1019# include <__chrono/tzdb.h>
1020# include <__chrono/tzdb_list.h>
1021# include <__chrono/utc_clock.h>
1022# include <__chrono/zoned_time.h>
1023# endif
9741024
975# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
976 !defined(_LIBCPP_HAS_NO_LOCALIZATION)
977# include <__chrono/leap_second.h>
978# include <__chrono/time_zone.h>
979# include <__chrono/time_zone_link.h>
980# include <__chrono/tzdb.h>
981# include <__chrono/tzdb_list.h>
982# include <__chrono/zoned_time.h>
9831025# endif
9841026
985#endif
986
987#include <version>
1027# include <version>
9881028
9891029// standard-mandated includes
9901030
9911031// [time.syn]
992#include <compare>
993
994#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
995# pragma GCC system_header
996#endif
997
998#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
999# include <cstdint>
1000# include <stdexcept>
1001# include <string_view>
1002# include <vector>
1003#endif
1004
1005#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1006# include <bit>
1007# include <concepts>
1008# include <cstring>
1009# include <forward_list>
1010# include <string>
1011# include <tuple>
1012#endif
1013
1014#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER == 20
1015# include <charconv>
1016# if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
1017# include <locale>
1018# include <ostream>
1032# include <compare>
1033
1034# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1035# pragma GCC system_header
1036# endif
1037
1038# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
1039# include <cstdint>
1040# include <stdexcept>
1041# include <string_view>
1042# endif
1043
1044# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1045# include <bit>
1046# include <concepts>
1047# include <cstring>
1048# include <forward_list>
1049# include <string>
1050# include <tuple>
1051# include <vector>
1052# endif
1053
1054# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER == 20
1055# include <charconv>
1056# if _LIBCPP_HAS_LOCALIZATION
1057# include <locale>
1058# include <ostream>
1059# endif
10191060# endif
1020#endif
1061#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
10211062
10221063#endif // _LIBCPP_CHRONO
lib/libcxx/include/cinttypes+13-8
......@@ -234,26 +234,29 @@ uintmax_t wcstoumax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int
234234} // std
235235*/
236236
237#include <__config>
237#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
238# include <__cxx03/cinttypes>
239#else
240# include <__config>
238241
239242// standard-mandated includes
240243
241244// [cinttypes.syn]
242#include <cstdint>
245# include <cstdint>
243246
244#include <inttypes.h>
247# include <inttypes.h>
245248
246#ifndef _LIBCPP_INTTYPES_H
249# ifndef _LIBCPP_INTTYPES_H
247250# error <cinttypes> tried including <inttypes.h> but didn't find libc++'s <inttypes.h> header. \
248251 This usually means that your header search paths are not configured properly. \
249252 The header search paths should contain the C++ Standard Library headers before \
250253 any C Standard Library, and you are probably using compiler flags that make that \
251254 not be the case.
252#endif
255# endif
253256
254#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
255# pragma GCC system_header
256#endif
257# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
258# pragma GCC system_header
259# endif
257260
258261_LIBCPP_BEGIN_NAMESPACE_STD
259262
......@@ -267,4 +270,6 @@ using ::wcstoumax _LIBCPP_USING_IF_EXISTS;
267270
268271_LIBCPP_END_NAMESPACE_STD
269272
273#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
274
270275#endif // _LIBCPP_CINTTYPES
lib/libcxx/include/ciso646+16-4
......@@ -15,10 +15,22 @@
1515
1616*/
1717
18#include <__config>
18#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
19# include <__cxx03/ciso646>
20#else
21# include <__config>
1922
20#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21# pragma GCC system_header
22#endif
23# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25# endif
26
27# if _LIBCPP_STD_VER >= 20
28
29using __standard_header_ciso646
30 _LIBCPP_DEPRECATED_("removed in C++20. Include <version> instead.") _LIBCPP_NODEBUG = void;
31using __use_standard_header_ciso646 _LIBCPP_NODEBUG = __standard_header_ciso646;
32
33# endif
34#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
2335
2436#endif // _LIBCPP_CISO646
lib/libcxx/include/climits+10-5
......@@ -37,12 +37,17 @@ Macros:
3737
3838*/
3939
40#include <__config>
40#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
41# include <__cxx03/climits>
42#else
43# include <__config>
4144
42#include <limits.h>
45# include <limits.h>
4346
44#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
45# pragma GCC system_header
46#endif
47# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
48# pragma GCC system_header
49# endif
50
51#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
4752
4853#endif // _LIBCPP_CLIMITS
lib/libcxx/include/clocale+12-13
......@@ -34,21 +34,18 @@ lconv* localeconv();
3434
3535*/
3636
37#include <__config>
37#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
38# include <__cxx03/clocale>
39#else
40# include <__config>
3841
39#include <locale.h>
42# if __has_include(<locale.h>)
43# include <locale.h>
44# endif
4045
41#ifndef _LIBCPP_LOCALE_H
42# error <clocale> tried including <locale.h> but didn't find libc++'s <locale.h> header. \
43 This usually means that your header search paths are not configured properly. \
44 The header search paths should contain the C++ Standard Library headers before \
45 any C Standard Library, and you are probably using compiler flags that make that \
46 not be the case.
47#endif
48
49#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
50# pragma GCC system_header
51#endif
46# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
47# pragma GCC system_header
48# endif
5249
5350_LIBCPP_BEGIN_NAMESPACE_STD
5451
......@@ -58,4 +55,6 @@ using ::localeconv _LIBCPP_USING_IF_EXISTS;
5855
5956_LIBCPP_END_NAMESPACE_STD
6057
58#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
59
6160#endif // _LIBCPP_CLOCALE
lib/libcxx/include/cmath+33-57
......@@ -312,35 +312,38 @@ constexpr long double lerp(long double a, long double b, long double t) noexcept
312312
313313*/
314314
315#include <__config>
316#include <__math/hypot.h>
317#include <__type_traits/enable_if.h>
318#include <__type_traits/is_arithmetic.h>
319#include <__type_traits/is_constant_evaluated.h>
320#include <__type_traits/is_floating_point.h>
321#include <__type_traits/is_same.h>
322#include <__type_traits/promote.h>
323#include <__type_traits/remove_cv.h>
324#include <limits>
325#include <version>
326
327#include <__math/special_functions.h>
328#include <math.h>
329
330#ifndef _LIBCPP_MATH_H
315#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
316# include <__cxx03/cmath>
317#else
318# include <__config>
319# include <__math/hypot.h>
320# include <__type_traits/enable_if.h>
321# include <__type_traits/is_arithmetic.h>
322# include <__type_traits/is_constant_evaluated.h>
323# include <__type_traits/is_floating_point.h>
324# include <__type_traits/is_same.h>
325# include <__type_traits/promote.h>
326# include <__type_traits/remove_cv.h>
327# include <limits>
328# include <version>
329
330# include <__math/special_functions.h>
331# include <math.h>
332
333# ifndef _LIBCPP_MATH_H
331334# error <cmath> tried including <math.h> but didn't find libc++'s <math.h> header. \
332335 This usually means that your header search paths are not configured properly. \
333336 The header search paths should contain the C++ Standard Library headers before \
334337 any C Standard Library, and you are probably using compiler flags that make that \
335338 not be the case.
336#endif
339# endif
337340
338#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
339# pragma GCC system_header
340#endif
341# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
342# pragma GCC system_header
343# endif
341344
342345_LIBCPP_PUSH_MACROS
343#include <__undef_macros>
346# include <__undef_macros>
344347
345348_LIBCPP_BEGIN_NAMESPACE_STD
346349
......@@ -554,27 +557,13 @@ using ::scalbnl _LIBCPP_USING_IF_EXISTS;
554557using ::tgammal _LIBCPP_USING_IF_EXISTS;
555558using ::truncl _LIBCPP_USING_IF_EXISTS;
556559
557template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
558_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isnan(_A1 __lcpp_x) _NOEXCEPT {
559#if __has_builtin(__builtin_isnan)
560 return __builtin_isnan(__lcpp_x);
561#else
562 return isnan(__lcpp_x);
563#endif
564}
565
566template <class _A1, __enable_if_t<!is_floating_point<_A1>::value, int> = 0>
567_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isnan(_A1 __lcpp_x) _NOEXCEPT {
568 return std::isnan(__lcpp_x);
569}
570
571560template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
572561_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isinf(_A1 __lcpp_x) _NOEXCEPT {
573#if __has_builtin(__builtin_isinf)
562# if __has_builtin(__builtin_isinf)
574563 return __builtin_isinf(__lcpp_x);
575#else
564# else
576565 return isinf(__lcpp_x);
577#endif
566# endif
578567}
579568
580569template <class _A1, __enable_if_t<!is_floating_point<_A1>::value, int> = 0>
......@@ -582,21 +571,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isinf(_A1 __lcpp_x) _NO
582571 return std::isinf(__lcpp_x);
583572}
584573
585template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
586_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isfinite(_A1 __lcpp_x) _NOEXCEPT {
587#if __has_builtin(__builtin_isfinite)
588 return __builtin_isfinite(__lcpp_x);
589#else
590 return isfinite(__lcpp_x);
591#endif
592}
593
594template <class _A1, __enable_if_t<!is_floating_point<_A1>::value, int> = 0>
595_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isfinite(_A1 __lcpp_x) _NOEXCEPT {
596 return __builtin_isfinite(__lcpp_x);
597}
598
599#if _LIBCPP_STD_VER >= 20
574# if _LIBCPP_STD_VER >= 20
600575template <typename _Fp>
601576_LIBCPP_HIDE_FROM_ABI constexpr _Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept {
602577 if ((__a <= 0 && __b >= 0) || (__a >= 0 && __b <= 0))
......@@ -633,14 +608,15 @@ inline _LIBCPP_HIDE_FROM_ABI constexpr
633608 _IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value && _IsSame<_A3, __result_type>::value));
634609 return std::__lerp((__result_type)__a, (__result_type)__b, (__result_type)__t);
635610}
636#endif // _LIBCPP_STD_VER >= 20
611# endif // _LIBCPP_STD_VER >= 20
637612
638613_LIBCPP_END_NAMESPACE_STD
639614
640615_LIBCPP_POP_MACROS
641616
642#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
643# include <type_traits>
644#endif
617# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
618# include <type_traits>
619# endif
620#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
645621
646622#endif // _LIBCPP_CMATH
lib/libcxx/include/codecvt+34-30
......@@ -54,15 +54,18 @@ class codecvt_utf8_utf16
5454
5555*/
5656
57#include <__config>
58#include <__locale>
59#include <version>
57#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
58# include <__cxx03/codecvt>
59#else
60# include <__config>
61# include <__locale>
62# include <version>
6063
61#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
62# pragma GCC system_header
63#endif
64# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
65# pragma GCC system_header
66# endif
6467
65#if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT)
68# if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT)
6669
6770_LIBCPP_BEGIN_NAMESPACE_STD
6871
......@@ -73,7 +76,7 @@ enum _LIBCPP_DEPRECATED_IN_CXX17 codecvt_mode { consume_header = 4, generate_hea
7376template <class _Elem>
7477class __codecvt_utf8;
7578
76# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
79# if _LIBCPP_HAS_WIDE_CHARACTERS
7780template <>
7881class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8<wchar_t> : public codecvt<wchar_t, char, mbstate_t> {
7982 unsigned long __maxcode_;
......@@ -112,7 +115,7 @@ protected:
112115 int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
113116 int do_max_length() const _NOEXCEPT override;
114117};
115# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
118# endif // _LIBCPP_HAS_WIDE_CHARACTERS
116119
117120_LIBCPP_SUPPRESS_DEPRECATED_PUSH
118121template <>
......@@ -203,7 +206,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
203206template <class _Elem, bool _LittleEndian>
204207class __codecvt_utf16;
205208
206# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
209# if _LIBCPP_HAS_WIDE_CHARACTERS
207210template <>
208211class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf16<wchar_t, false> : public codecvt<wchar_t, char, mbstate_t> {
209212 unsigned long __maxcode_;
......@@ -281,7 +284,7 @@ protected:
281284 int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
282285 int do_max_length() const _NOEXCEPT override;
283286};
284# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
287# endif // _LIBCPP_HAS_WIDE_CHARACTERS
285288
286289_LIBCPP_SUPPRESS_DEPRECATED_PUSH
287290template <>
......@@ -448,7 +451,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
448451template <class _Elem>
449452class __codecvt_utf8_utf16;
450453
451# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
454# if _LIBCPP_HAS_WIDE_CHARACTERS
452455template <>
453456class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8_utf16<wchar_t> : public codecvt<wchar_t, char, mbstate_t> {
454457 unsigned long __maxcode_;
......@@ -487,7 +490,7 @@ protected:
487490 int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
488491 int do_max_length() const _NOEXCEPT override;
489492};
490# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
493# endif // _LIBCPP_HAS_WIDE_CHARACTERS
491494
492495_LIBCPP_SUPPRESS_DEPRECATED_PUSH
493496template <>
......@@ -576,22 +579,23 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
576579
577580_LIBCPP_END_NAMESPACE_STD
578581
579#endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT)
580
581#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
582# include <atomic>
583# include <concepts>
584# include <cstddef>
585# include <cstdlib>
586# include <cstring>
587# include <initializer_list>
588# include <iosfwd>
589# include <limits>
590# include <mutex>
591# include <new>
592# include <stdexcept>
593# include <type_traits>
594# include <typeinfo>
595#endif
582# endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT)
583
584# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
585# include <atomic>
586# include <concepts>
587# include <cstddef>
588# include <cstdlib>
589# include <cstring>
590# include <initializer_list>
591# include <iosfwd>
592# include <limits>
593# include <mutex>
594# include <new>
595# include <stdexcept>
596# include <type_traits>
597# include <typeinfo>
598# endif
599#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
596600
597601#endif // _LIBCPP_CODECVT
lib/libcxx/include/compare+33-34
......@@ -140,39 +140,38 @@ namespace std {
140140}
141141*/
142142
143#include <__config>
144
145#if _LIBCPP_STD_VER >= 20
146# include <__compare/common_comparison_category.h>
147# include <__compare/compare_partial_order_fallback.h>
148# include <__compare/compare_strong_order_fallback.h>
149# include <__compare/compare_three_way.h>
150# include <__compare/compare_three_way_result.h>
151# include <__compare/compare_weak_order_fallback.h>
152# include <__compare/is_eq.h>
153# include <__compare/ordering.h>
154# include <__compare/partial_order.h>
155# include <__compare/strong_order.h>
156# include <__compare/synth_three_way.h>
157# include <__compare/three_way_comparable.h>
158# include <__compare/weak_order.h>
159#endif // _LIBCPP_STD_VER >= 20
160
161#include <version>
162
163#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
164# pragma GCC system_header
165#endif
166
167#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
168# include <cstddef>
169# include <cstdint>
170# include <limits>
171#endif
172
173#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
174# include <cmath>
175# include <type_traits>
176#endif
143#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
144# include <__cxx03/compare>
145#else
146# include <__config>
147
148# if _LIBCPP_STD_VER >= 20
149# include <__compare/common_comparison_category.h>
150# include <__compare/compare_partial_order_fallback.h>
151# include <__compare/compare_strong_order_fallback.h>
152# include <__compare/compare_three_way.h>
153# include <__compare/compare_three_way_result.h>
154# include <__compare/compare_weak_order_fallback.h>
155# include <__compare/is_eq.h>
156# include <__compare/ordering.h>
157# include <__compare/partial_order.h>
158# include <__compare/strong_order.h>
159# include <__compare/synth_three_way.h>
160# include <__compare/three_way_comparable.h>
161# include <__compare/weak_order.h>
162# endif // _LIBCPP_STD_VER >= 20
163
164# include <version>
165
166# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
167# pragma GCC system_header
168# endif
169
170# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
171# include <cmath>
172# include <cstddef>
173# include <type_traits>
174# endif
175#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
177176
178177#endif // _LIBCPP_COMPARE
lib/libcxx/include/complex+100-98
......@@ -256,26 +256,29 @@ template<class T> complex<T> tanh (const complex<T>&);
256256
257257*/
258258
259#include <__config>
260#include <__fwd/complex.h>
261#include <__fwd/tuple.h>
262#include <__tuple/tuple_element.h>
263#include <__tuple/tuple_size.h>
264#include <__type_traits/conditional.h>
265#include <__utility/move.h>
266#include <cmath>
267#include <version>
268
269#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
270# include <sstream> // for std::basic_ostringstream
271#endif
272
273#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
274# pragma GCC system_header
275#endif
259#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
260# include <__cxx03/complex>
261#else
262# include <__config>
263# include <__fwd/complex.h>
264# include <__fwd/tuple.h>
265# include <__tuple/tuple_element.h>
266# include <__tuple/tuple_size.h>
267# include <__type_traits/conditional.h>
268# include <__utility/move.h>
269# include <cmath>
270# include <version>
271
272# if _LIBCPP_HAS_LOCALIZATION
273# include <sstream> // for std::basic_ostringstream
274# endif
275
276# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
277# pragma GCC system_header
278# endif
276279
277280_LIBCPP_PUSH_MACROS
278#include <__undef_macros>
281# include <__undef_macros>
279282
280283_LIBCPP_BEGIN_NAMESPACE_STD
281284
......@@ -374,7 +377,7 @@ public:
374377 return *this;
375378 }
376379
377#if _LIBCPP_STD_VER >= 26
380# if _LIBCPP_STD_VER >= 26
378381 template <size_t _Ip, class _Xp>
379382 friend _LIBCPP_HIDE_FROM_ABI constexpr _Xp& get(complex<_Xp>&) noexcept;
380383
......@@ -386,7 +389,7 @@ public:
386389
387390 template <size_t _Ip, class _Xp>
388391 friend _LIBCPP_HIDE_FROM_ABI constexpr const _Xp&& get(const complex<_Xp>&&) noexcept;
389#endif
392# endif
390393};
391394
392395template <>
......@@ -397,18 +400,18 @@ class _LIBCPP_TEMPLATE_VIS complex<long double>;
397400struct __from_builtin_tag {};
398401
399402template <class _Tp>
400using __complex_t =
403using __complex_t _LIBCPP_NODEBUG =
401404 __conditional_t<is_same<_Tp, float>::value,
402405 _Complex float,
403406 __conditional_t<is_same<_Tp, double>::value, _Complex double, _Complex long double> >;
404407
405408template <class _Tp>
406409_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __complex_t<_Tp> __make_complex(_Tp __re, _Tp __im) {
407#if __has_builtin(__builtin_complex)
410# if __has_builtin(__builtin_complex)
408411 return __builtin_complex(__re, __im);
409#else
412# else
410413 return __complex_t<_Tp>{__re, __im};
411#endif
414# endif
412415}
413416
414417template <>
......@@ -493,7 +496,7 @@ public:
493496 return *this;
494497 }
495498
496#if _LIBCPP_STD_VER >= 26
499# if _LIBCPP_STD_VER >= 26
497500 template <size_t _Ip, class _Xp>
498501 friend _LIBCPP_HIDE_FROM_ABI constexpr _Xp& get(complex<_Xp>&) noexcept;
499502
......@@ -505,7 +508,7 @@ public:
505508
506509 template <size_t _Ip, class _Xp>
507510 friend _LIBCPP_HIDE_FROM_ABI constexpr const _Xp&& get(const complex<_Xp>&&) noexcept;
508#endif
511# endif
509512};
510513
511514template <>
......@@ -593,7 +596,7 @@ public:
593596 return *this;
594597 }
595598
596#if _LIBCPP_STD_VER >= 26
599# if _LIBCPP_STD_VER >= 26
597600 template <size_t _Ip, class _Xp>
598601 friend _LIBCPP_HIDE_FROM_ABI constexpr _Xp& get(complex<_Xp>&) noexcept;
599602
......@@ -605,7 +608,7 @@ public:
605608
606609 template <size_t _Ip, class _Xp>
607610 friend _LIBCPP_HIDE_FROM_ABI constexpr const _Xp&& get(const complex<_Xp>&&) noexcept;
608#endif
611# endif
609612};
610613
611614template <>
......@@ -694,7 +697,7 @@ public:
694697 return *this;
695698 }
696699
697#if _LIBCPP_STD_VER >= 26
700# if _LIBCPP_STD_VER >= 26
698701 template <size_t _Ip, class _Xp>
699702 friend _LIBCPP_HIDE_FROM_ABI constexpr _Xp& get(complex<_Xp>&) noexcept;
700703
......@@ -706,7 +709,7 @@ public:
706709
707710 template <size_t _Ip, class _Xp>
708711 friend _LIBCPP_HIDE_FROM_ABI constexpr const _Xp&& get(const complex<_Xp>&&) noexcept;
709#endif
712# endif
710713};
711714
712715inline _LIBCPP_CONSTEXPR complex<float>::complex(const complex<double>& __c) : __re_(__c.real()), __im_(__c.imag()) {}
......@@ -861,7 +864,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator==(const
861864 return __x.real() == __y && __x.imag() == 0;
862865}
863866
864#if _LIBCPP_STD_VER <= 17
867# if _LIBCPP_STD_VER <= 17
865868
866869template <class _Tp>
867870inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator==(const _Tp& __x, const complex<_Tp>& __y) {
......@@ -884,7 +887,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator!=(const
884887 return !(__x == __y);
885888}
886889
887#endif
890# endif
888891
889892// 26.3.7 values:
890893
......@@ -997,14 +1000,14 @@ conj(_Tp __re) {
9971000template <class _Tp>
9981001inline _LIBCPP_HIDE_FROM_ABI complex<_Tp> proj(const complex<_Tp>& __c) {
9991002 complex<_Tp> __r = __c;
1000 if (std::__constexpr_isinf(__c.real()) || std::__constexpr_isinf(__c.imag()))
1003 if (std::isinf(__c.real()) || std::isinf(__c.imag()))
10011004 __r = complex<_Tp>(INFINITY, std::copysign(_Tp(0), __c.imag()));
10021005 return __r;
10031006}
10041007
10051008template <class _Tp, __enable_if_t<is_floating_point<_Tp>::value, int> = 0>
10061009inline _LIBCPP_HIDE_FROM_ABI typename __libcpp_complex_overload_traits<_Tp>::_ComplexType proj(_Tp __re) {
1007 if (std::__constexpr_isinf(__re))
1010 if (std::isinf(__re))
10081011 __re = std::abs(__re);
10091012 return complex<_Tp>(__re);
10101013}
......@@ -1019,23 +1022,23 @@ inline _LIBCPP_HIDE_FROM_ABI typename __libcpp_complex_overload_traits<_Tp>::_Co
10191022
10201023template <class _Tp>
10211024_LIBCPP_HIDE_FROM_ABI complex<_Tp> polar(const _Tp& __rho, const _Tp& __theta = _Tp()) {
1022 if (std::__constexpr_isnan(__rho) || std::signbit(__rho))
1025 if (std::isnan(__rho) || std::signbit(__rho))
10231026 return complex<_Tp>(_Tp(NAN), _Tp(NAN));
1024 if (std::__constexpr_isnan(__theta)) {
1025 if (std::__constexpr_isinf(__rho))
1027 if (std::isnan(__theta)) {
1028 if (std::isinf(__rho))
10261029 return complex<_Tp>(__rho, __theta);
10271030 return complex<_Tp>(__theta, __theta);
10281031 }
1029 if (std::__constexpr_isinf(__theta)) {
1030 if (std::__constexpr_isinf(__rho))
1032 if (std::isinf(__theta)) {
1033 if (std::isinf(__rho))
10311034 return complex<_Tp>(__rho, _Tp(NAN));
10321035 return complex<_Tp>(_Tp(NAN), _Tp(NAN));
10331036 }
10341037 _Tp __x = __rho * std::cos(__theta);
1035 if (std::__constexpr_isnan(__x))
1038 if (std::isnan(__x))
10361039 __x = 0;
10371040 _Tp __y = __rho * std::sin(__theta);
1038 if (std::__constexpr_isnan(__y))
1041 if (std::isnan(__y))
10391042 __y = 0;
10401043 return complex<_Tp>(__x, __y);
10411044}
......@@ -1058,14 +1061,12 @@ inline _LIBCPP_HIDE_FROM_ABI complex<_Tp> log10(const complex<_Tp>& __x) {
10581061
10591062template <class _Tp>
10601063_LIBCPP_HIDE_FROM_ABI complex<_Tp> sqrt(const complex<_Tp>& __x) {
1061 if (std::__constexpr_isinf(__x.imag()))
1064 if (std::isinf(__x.imag()))
10621065 return complex<_Tp>(_Tp(INFINITY), __x.imag());
1063 if (std::__constexpr_isinf(__x.real())) {
1066 if (std::isinf(__x.real())) {
10641067 if (__x.real() > _Tp(0))
1065 return complex<_Tp>(
1066 __x.real(), std::__constexpr_isnan(__x.imag()) ? __x.imag() : std::copysign(_Tp(0), __x.imag()));
1067 return complex<_Tp>(
1068 std::__constexpr_isnan(__x.imag()) ? __x.imag() : _Tp(0), std::copysign(__x.real(), __x.imag()));
1068 return complex<_Tp>(__x.real(), std::isnan(__x.imag()) ? __x.imag() : std::copysign(_Tp(0), __x.imag()));
1069 return complex<_Tp>(std::isnan(__x.imag()) ? __x.imag() : _Tp(0), std::copysign(__x.real(), __x.imag()));
10691070 }
10701071 return std::polar(std::sqrt(std::abs(__x)), std::arg(__x) / _Tp(2));
10711072}
......@@ -1078,12 +1079,12 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> exp(const complex<_Tp>& __x) {
10781079 if (__i == 0) {
10791080 return complex<_Tp>(std::exp(__x.real()), std::copysign(_Tp(0), __x.imag()));
10801081 }
1081 if (std::__constexpr_isinf(__x.real())) {
1082 if (std::isinf(__x.real())) {
10821083 if (__x.real() < _Tp(0)) {
1083 if (!std::__constexpr_isfinite(__i))
1084 if (!std::isfinite(__i))
10841085 __i = _Tp(1);
1085 } else if (__i == 0 || !std::__constexpr_isfinite(__i)) {
1086 if (std::__constexpr_isinf(__i))
1086 } else if (__i == 0 || !std::isfinite(__i)) {
1087 if (std::isinf(__i))
10871088 __i = _Tp(NAN);
10881089 return complex<_Tp>(__x.real(), __i);
10891090 }
......@@ -1099,20 +1100,20 @@ inline _LIBCPP_HIDE_FROM_ABI complex<_Tp> pow(const complex<_Tp>& __x, const com
10991100 return std::exp(__y * std::log(__x));
11001101}
11011102
1102template <class _Tp, class _Up>
1103template <class _Tp, class _Up, __enable_if_t<is_floating_point<_Tp>::value && is_floating_point<_Up>::value, int> = 0>
11031104inline _LIBCPP_HIDE_FROM_ABI complex<typename __promote<_Tp, _Up>::type>
11041105pow(const complex<_Tp>& __x, const complex<_Up>& __y) {
11051106 typedef complex<typename __promote<_Tp, _Up>::type> result_type;
11061107 return std::pow(result_type(__x), result_type(__y));
11071108}
11081109
1109template <class _Tp, class _Up, __enable_if_t<is_arithmetic<_Up>::value, int> = 0>
1110template <class _Tp, class _Up, __enable_if_t<is_floating_point<_Tp>::value && is_arithmetic<_Up>::value, int> = 0>
11101111inline _LIBCPP_HIDE_FROM_ABI complex<typename __promote<_Tp, _Up>::type> pow(const complex<_Tp>& __x, const _Up& __y) {
11111112 typedef complex<typename __promote<_Tp, _Up>::type> result_type;
11121113 return std::pow(result_type(__x), result_type(__y));
11131114}
11141115
1115template <class _Tp, class _Up, __enable_if_t<is_arithmetic<_Tp>::value, int> = 0>
1116template <class _Tp, class _Up, __enable_if_t<is_arithmetic<_Tp>::value && is_floating_point<_Up>::value, int> = 0>
11161117inline _LIBCPP_HIDE_FROM_ABI complex<typename __promote<_Tp, _Up>::type> pow(const _Tp& __x, const complex<_Up>& __y) {
11171118 typedef complex<typename __promote<_Tp, _Up>::type> result_type;
11181119 return std::pow(result_type(__x), result_type(__y));
......@@ -1130,21 +1131,21 @@ inline _LIBCPP_HIDE_FROM_ABI complex<_Tp> __sqr(const complex<_Tp>& __x) {
11301131template <class _Tp>
11311132_LIBCPP_HIDE_FROM_ABI complex<_Tp> asinh(const complex<_Tp>& __x) {
11321133 const _Tp __pi(atan2(+0., -0.));
1133 if (std::__constexpr_isinf(__x.real())) {
1134 if (std::__constexpr_isnan(__x.imag()))
1134 if (std::isinf(__x.real())) {
1135 if (std::isnan(__x.imag()))
11351136 return __x;
1136 if (std::__constexpr_isinf(__x.imag()))
1137 if (std::isinf(__x.imag()))
11371138 return complex<_Tp>(__x.real(), std::copysign(__pi * _Tp(0.25), __x.imag()));
11381139 return complex<_Tp>(__x.real(), std::copysign(_Tp(0), __x.imag()));
11391140 }
1140 if (std::__constexpr_isnan(__x.real())) {
1141 if (std::__constexpr_isinf(__x.imag()))
1141 if (std::isnan(__x.real())) {
1142 if (std::isinf(__x.imag()))
11421143 return complex<_Tp>(__x.imag(), __x.real());
11431144 if (__x.imag() == 0)
11441145 return __x;
11451146 return complex<_Tp>(__x.real(), __x.real());
11461147 }
1147 if (std::__constexpr_isinf(__x.imag()))
1148 if (std::isinf(__x.imag()))
11481149 return complex<_Tp>(std::copysign(__x.imag(), __x.real()), std::copysign(__pi / _Tp(2), __x.imag()));
11491150 complex<_Tp> __z = std::log(__x + std::sqrt(std::__sqr(__x) + _Tp(1)));
11501151 return complex<_Tp>(std::copysign(__z.real(), __x.real()), std::copysign(__z.imag(), __x.imag()));
......@@ -1155,10 +1156,10 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> asinh(const complex<_Tp>& __x) {
11551156template <class _Tp>
11561157_LIBCPP_HIDE_FROM_ABI complex<_Tp> acosh(const complex<_Tp>& __x) {
11571158 const _Tp __pi(atan2(+0., -0.));
1158 if (std::__constexpr_isinf(__x.real())) {
1159 if (std::__constexpr_isnan(__x.imag()))
1159 if (std::isinf(__x.real())) {
1160 if (std::isnan(__x.imag()))
11601161 return complex<_Tp>(std::abs(__x.real()), __x.imag());
1161 if (std::__constexpr_isinf(__x.imag())) {
1162 if (std::isinf(__x.imag())) {
11621163 if (__x.real() > 0)
11631164 return complex<_Tp>(__x.real(), std::copysign(__pi * _Tp(0.25), __x.imag()));
11641165 else
......@@ -1168,12 +1169,12 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> acosh(const complex<_Tp>& __x) {
11681169 return complex<_Tp>(-__x.real(), std::copysign(__pi, __x.imag()));
11691170 return complex<_Tp>(__x.real(), std::copysign(_Tp(0), __x.imag()));
11701171 }
1171 if (std::__constexpr_isnan(__x.real())) {
1172 if (std::__constexpr_isinf(__x.imag()))
1172 if (std::isnan(__x.real())) {
1173 if (std::isinf(__x.imag()))
11731174 return complex<_Tp>(std::abs(__x.imag()), __x.real());
11741175 return complex<_Tp>(__x.real(), __x.real());
11751176 }
1176 if (std::__constexpr_isinf(__x.imag()))
1177 if (std::isinf(__x.imag()))
11771178 return complex<_Tp>(std::abs(__x.imag()), std::copysign(__pi / _Tp(2), __x.imag()));
11781179 complex<_Tp> __z = std::log(__x + std::sqrt(std::__sqr(__x) - _Tp(1)));
11791180 return complex<_Tp>(std::copysign(__z.real(), _Tp(0)), std::copysign(__z.imag(), __x.imag()));
......@@ -1184,18 +1185,18 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> acosh(const complex<_Tp>& __x) {
11841185template <class _Tp>
11851186_LIBCPP_HIDE_FROM_ABI complex<_Tp> atanh(const complex<_Tp>& __x) {
11861187 const _Tp __pi(atan2(+0., -0.));
1187 if (std::__constexpr_isinf(__x.imag())) {
1188 if (std::isinf(__x.imag())) {
11881189 return complex<_Tp>(std::copysign(_Tp(0), __x.real()), std::copysign(__pi / _Tp(2), __x.imag()));
11891190 }
1190 if (std::__constexpr_isnan(__x.imag())) {
1191 if (std::__constexpr_isinf(__x.real()) || __x.real() == 0)
1191 if (std::isnan(__x.imag())) {
1192 if (std::isinf(__x.real()) || __x.real() == 0)
11921193 return complex<_Tp>(std::copysign(_Tp(0), __x.real()), __x.imag());
11931194 return complex<_Tp>(__x.imag(), __x.imag());
11941195 }
1195 if (std::__constexpr_isnan(__x.real())) {
1196 if (std::isnan(__x.real())) {
11961197 return complex<_Tp>(__x.real(), __x.real());
11971198 }
1198 if (std::__constexpr_isinf(__x.real())) {
1199 if (std::isinf(__x.real())) {
11991200 return complex<_Tp>(std::copysign(_Tp(0), __x.real()), std::copysign(__pi / _Tp(2), __x.imag()));
12001201 }
12011202 if (std::abs(__x.real()) == _Tp(1) && __x.imag() == _Tp(0)) {
......@@ -1209,11 +1210,11 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> atanh(const complex<_Tp>& __x) {
12091210
12101211template <class _Tp>
12111212_LIBCPP_HIDE_FROM_ABI complex<_Tp> sinh(const complex<_Tp>& __x) {
1212 if (std::__constexpr_isinf(__x.real()) && !std::__constexpr_isfinite(__x.imag()))
1213 if (std::isinf(__x.real()) && !std::isfinite(__x.imag()))
12131214 return complex<_Tp>(__x.real(), _Tp(NAN));
1214 if (__x.real() == 0 && !std::__constexpr_isfinite(__x.imag()))
1215 if (__x.real() == 0 && !std::isfinite(__x.imag()))
12151216 return complex<_Tp>(__x.real(), _Tp(NAN));
1216 if (__x.imag() == 0 && !std::__constexpr_isfinite(__x.real()))
1217 if (__x.imag() == 0 && !std::isfinite(__x.real()))
12171218 return __x;
12181219 return complex<_Tp>(std::sinh(__x.real()) * std::cos(__x.imag()), std::cosh(__x.real()) * std::sin(__x.imag()));
12191220}
......@@ -1222,13 +1223,13 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> sinh(const complex<_Tp>& __x) {
12221223
12231224template <class _Tp>
12241225_LIBCPP_HIDE_FROM_ABI complex<_Tp> cosh(const complex<_Tp>& __x) {
1225 if (std::__constexpr_isinf(__x.real()) && !std::__constexpr_isfinite(__x.imag()))
1226 if (std::isinf(__x.real()) && !std::isfinite(__x.imag()))
12261227 return complex<_Tp>(std::abs(__x.real()), _Tp(NAN));
1227 if (__x.real() == 0 && !std::__constexpr_isfinite(__x.imag()))
1228 if (__x.real() == 0 && !std::isfinite(__x.imag()))
12281229 return complex<_Tp>(_Tp(NAN), __x.real());
12291230 if (__x.real() == 0 && __x.imag() == 0)
12301231 return complex<_Tp>(_Tp(1), __x.imag());
1231 if (__x.imag() == 0 && !std::__constexpr_isfinite(__x.real()))
1232 if (__x.imag() == 0 && !std::isfinite(__x.real()))
12321233 return complex<_Tp>(std::abs(__x.real()), __x.imag());
12331234 return complex<_Tp>(std::cosh(__x.real()) * std::cos(__x.imag()), std::sinh(__x.real()) * std::sin(__x.imag()));
12341235}
......@@ -1237,18 +1238,18 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> cosh(const complex<_Tp>& __x) {
12371238
12381239template <class _Tp>
12391240_LIBCPP_HIDE_FROM_ABI complex<_Tp> tanh(const complex<_Tp>& __x) {
1240 if (std::__constexpr_isinf(__x.real())) {
1241 if (!std::__constexpr_isfinite(__x.imag()))
1241 if (std::isinf(__x.real())) {
1242 if (!std::isfinite(__x.imag()))
12421243 return complex<_Tp>(std::copysign(_Tp(1), __x.real()), _Tp(0));
12431244 return complex<_Tp>(std::copysign(_Tp(1), __x.real()), std::copysign(_Tp(0), std::sin(_Tp(2) * __x.imag())));
12441245 }
1245 if (std::__constexpr_isnan(__x.real()) && __x.imag() == 0)
1246 if (std::isnan(__x.real()) && __x.imag() == 0)
12461247 return __x;
12471248 _Tp __2r(_Tp(2) * __x.real());
12481249 _Tp __2i(_Tp(2) * __x.imag());
12491250 _Tp __d(std::cosh(__2r) + std::cos(__2i));
12501251 _Tp __2rsh(std::sinh(__2r));
1251 if (std::__constexpr_isinf(__2rsh) && std::__constexpr_isinf(__d))
1252 if (std::isinf(__2rsh) && std::isinf(__d))
12521253 return complex<_Tp>(__2rsh > _Tp(0) ? _Tp(1) : _Tp(-1), __2i > _Tp(0) ? _Tp(0) : _Tp(-0.));
12531254 return complex<_Tp>(__2rsh / __d, std::sin(__2i) / __d);
12541255}
......@@ -1266,10 +1267,10 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> asin(const complex<_Tp>& __x) {
12661267template <class _Tp>
12671268_LIBCPP_HIDE_FROM_ABI complex<_Tp> acos(const complex<_Tp>& __x) {
12681269 const _Tp __pi(atan2(+0., -0.));
1269 if (std::__constexpr_isinf(__x.real())) {
1270 if (std::__constexpr_isnan(__x.imag()))
1270 if (std::isinf(__x.real())) {
1271 if (std::isnan(__x.imag()))
12711272 return complex<_Tp>(__x.imag(), __x.real());
1272 if (std::__constexpr_isinf(__x.imag())) {
1273 if (std::isinf(__x.imag())) {
12731274 if (__x.real() < _Tp(0))
12741275 return complex<_Tp>(_Tp(0.75) * __pi, -__x.imag());
12751276 return complex<_Tp>(_Tp(0.25) * __pi, -__x.imag());
......@@ -1278,12 +1279,12 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> acos(const complex<_Tp>& __x) {
12781279 return complex<_Tp>(__pi, std::signbit(__x.imag()) ? -__x.real() : __x.real());
12791280 return complex<_Tp>(_Tp(0), std::signbit(__x.imag()) ? __x.real() : -__x.real());
12801281 }
1281 if (std::__constexpr_isnan(__x.real())) {
1282 if (std::__constexpr_isinf(__x.imag()))
1282 if (std::isnan(__x.real())) {
1283 if (std::isinf(__x.imag()))
12831284 return complex<_Tp>(__x.real(), -__x.imag());
12841285 return complex<_Tp>(__x.real(), __x.real());
12851286 }
1286 if (std::__constexpr_isinf(__x.imag()))
1287 if (std::isinf(__x.imag()))
12871288 return complex<_Tp>(__pi / _Tp(2), -__x.imag());
12881289 if (__x.real() == 0 && (__x.imag() == 0 || std::isnan(__x.imag())))
12891290 return complex<_Tp>(__pi / _Tp(2), -__x.imag());
......@@ -1324,7 +1325,7 @@ _LIBCPP_HIDE_FROM_ABI complex<_Tp> tan(const complex<_Tp>& __x) {
13241325 return complex<_Tp>(__z.imag(), -__z.real());
13251326}
13261327
1327#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
1328# if _LIBCPP_HAS_LOCALIZATION
13281329template <class _Tp, class _CharT, class _Traits>
13291330_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
13301331operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x) {
......@@ -1381,9 +1382,9 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x) {
13811382 __s << '(' << __x.real() << ',' << __x.imag() << ')';
13821383 return __os << __s.str();
13831384}
1384#endif // !_LIBCPP_HAS_NO_LOCALIZATION
1385# endif // _LIBCPP_HAS_LOCALIZATION
13851386
1386#if _LIBCPP_STD_VER >= 26
1387# if _LIBCPP_STD_VER >= 26
13871388
13881389// [complex.tuple], tuple interface
13891390
......@@ -1436,9 +1437,9 @@ _LIBCPP_HIDE_FROM_ABI constexpr const _Xp&& get(const complex<_Xp>&& __z) noexce
14361437 }
14371438}
14381439
1439#endif // _LIBCPP_STD_VER >= 26
1440# endif // _LIBCPP_STD_VER >= 26
14401441
1441#if _LIBCPP_STD_VER >= 14
1442# if _LIBCPP_STD_VER >= 14
14421443// Literal suffix for complex number literals [complex.literals]
14431444inline namespace literals {
14441445inline namespace complex_literals {
......@@ -1465,16 +1466,17 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr complex<float> operator""if(unsigned long
14651466}
14661467} // namespace complex_literals
14671468} // namespace literals
1468#endif
1469# endif
14691470
14701471_LIBCPP_END_NAMESPACE_STD
14711472
14721473_LIBCPP_POP_MACROS
14731474
1474#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1475# include <iosfwd>
1476# include <stdexcept>
1477# include <type_traits>
1478#endif
1475# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1476# include <iosfwd>
1477# include <stdexcept>
1478# include <type_traits>
1479# endif
1480#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
14791481
14801482#endif // _LIBCPP_COMPLEX
lib/libcxx/include/complex.h+15-11
......@@ -17,16 +17,20 @@
1717
1818*/
1919
20#include <__config>
21
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24#endif
25
26#ifdef __cplusplus
27# include <ccomplex>
28#elif __has_include_next(<complex.h>)
29# include_next <complex.h>
30#endif
20#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
21# include <__cxx03/complex.h>
22#else
23# include <__config>
24
25# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26# pragma GCC system_header
27# endif
28
29# ifdef __cplusplus
30# include <complex>
31# elif __has_include_next(<complex.h>)
32# include_next <complex.h>
33# endif
34#endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
3135
3236#endif // _LIBCPP_COMPLEX_H
lib/libcxx/include/concepts+41-40
......@@ -129,45 +129,46 @@ namespace std {
129129
130130*/
131131
132#include <__config>
133
134#if _LIBCPP_STD_VER >= 20
135# include <__concepts/arithmetic.h>
136# include <__concepts/assignable.h>
137# include <__concepts/boolean_testable.h>
138# include <__concepts/class_or_enum.h>
139# include <__concepts/common_reference_with.h>
140# include <__concepts/common_with.h>
141# include <__concepts/constructible.h>
142# include <__concepts/convertible_to.h>
143# include <__concepts/copyable.h>
144# include <__concepts/derived_from.h>
145# include <__concepts/destructible.h>
146# include <__concepts/different_from.h>
147# include <__concepts/equality_comparable.h>
148# include <__concepts/invocable.h>
149# include <__concepts/movable.h>
150# include <__concepts/predicate.h>
151# include <__concepts/regular.h>
152# include <__concepts/relation.h>
153# include <__concepts/same_as.h>
154# include <__concepts/semiregular.h>
155# include <__concepts/swappable.h>
156# include <__concepts/totally_ordered.h>
157#endif // _LIBCPP_STD_VER >= 20
158
159#include <version>
160
161#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
162# include <cstddef>
163#endif
164
165#if _LIBCPP_STD_VER <= 20 && !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
166# include <type_traits>
167#endif
168
169#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
170# pragma GCC system_header
171#endif
132#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
133# include <__cxx03/concepts>
134#else
135# include <__config>
136
137# if _LIBCPP_STD_VER >= 20
138# include <__concepts/arithmetic.h>
139# include <__concepts/assignable.h>
140# include <__concepts/boolean_testable.h>
141# include <__concepts/class_or_enum.h>
142# include <__concepts/common_reference_with.h>
143# include <__concepts/common_with.h>
144# include <__concepts/constructible.h>
145# include <__concepts/convertible_to.h>
146# include <__concepts/copyable.h>
147# include <__concepts/derived_from.h>
148# include <__concepts/destructible.h>
149# include <__concepts/different_from.h>
150# include <__concepts/equality_comparable.h>
151# include <__concepts/invocable.h>
152# include <__concepts/movable.h>
153# include <__concepts/predicate.h>
154# include <__concepts/regular.h>
155# include <__concepts/relation.h>
156# include <__concepts/same_as.h>
157# include <__concepts/semiregular.h>
158# include <__concepts/swappable.h>
159# include <__concepts/totally_ordered.h>
160# endif // _LIBCPP_STD_VER >= 20
161
162# include <version>
163
164# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
165# include <cstddef>
166# include <type_traits>
167# endif
168
169# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
170# pragma GCC system_header
171# endif
172#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
172173
173174#endif // _LIBCPP_CONCEPTS
lib/libcxx/include/condition_variable+43-39
......@@ -118,29 +118,32 @@ public:
118118
119119*/
120120
121#include <__chrono/duration.h>
122#include <__chrono/steady_clock.h>
123#include <__chrono/time_point.h>
124#include <__condition_variable/condition_variable.h>
125#include <__config>
126#include <__memory/shared_ptr.h>
127#include <__mutex/lock_guard.h>
128#include <__mutex/mutex.h>
129#include <__mutex/tag_types.h>
130#include <__mutex/unique_lock.h>
131#include <__stop_token/stop_callback.h>
132#include <__stop_token/stop_token.h>
133#include <__utility/move.h>
134#include <version>
135
136#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
137# pragma GCC system_header
138#endif
121#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
122# include <__cxx03/condition_variable>
123#else
124# include <__chrono/duration.h>
125# include <__chrono/steady_clock.h>
126# include <__chrono/time_point.h>
127# include <__condition_variable/condition_variable.h>
128# include <__config>
129# include <__memory/shared_ptr.h>
130# include <__mutex/lock_guard.h>
131# include <__mutex/mutex.h>
132# include <__mutex/tag_types.h>
133# include <__mutex/unique_lock.h>
134# include <__stop_token/stop_callback.h>
135# include <__stop_token/stop_token.h>
136# include <__utility/move.h>
137# include <version>
138
139# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
140# pragma GCC system_header
141# endif
139142
140143_LIBCPP_PUSH_MACROS
141#include <__undef_macros>
144# include <__undef_macros>
142145
143#ifndef _LIBCPP_HAS_NO_THREADS
146# if _LIBCPP_HAS_THREADS
144147
145148_LIBCPP_BEGIN_NAMESPACE_STD
146149
......@@ -173,7 +176,7 @@ public:
173176 template <class _Lock, class _Rep, class _Period, class _Predicate>
174177 bool _LIBCPP_HIDE_FROM_ABI wait_for(_Lock& __lock, const chrono::duration<_Rep, _Period>& __d, _Predicate __pred);
175178
176# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN)
179# if _LIBCPP_STD_VER >= 20
177180
178181 template <class _Lock, class _Predicate>
179182 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI bool wait(_Lock& __lock, stop_token __stoken, _Predicate __pred);
......@@ -186,7 +189,7 @@ public:
186189 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI bool
187190 wait_for(_Lock& __lock, stop_token __stoken, const chrono::duration<_Rep, _Period>& __rel_time, _Predicate __pred);
188191
189# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN)
192# endif // _LIBCPP_STD_VER >= 20
190193};
191194
192195inline condition_variable_any::condition_variable_any() : __mut_(make_shared<mutex>()) {}
......@@ -260,7 +263,7 @@ condition_variable_any::wait_for(_Lock& __lock, const chrono::duration<_Rep, _Pe
260263 return wait_until(__lock, chrono::steady_clock::now() + __d, std::move(__pred));
261264}
262265
263# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN)
266# if _LIBCPP_STD_VER >= 20
264267
265268template <class _Lock, class _Predicate>
266269bool condition_variable_any::wait(_Lock& __user_lock, stop_token __stoken, _Predicate __pred) {
......@@ -341,29 +344,30 @@ bool condition_variable_any::wait_for(
341344 return wait_until(__lock, std::move(__stoken), chrono::steady_clock::now() + __rel_time, std::move(__pred));
342345}
343346
344# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN)
347# endif // _LIBCPP_STD_VER >= 20
345348
346349_LIBCPP_EXPORTED_FROM_ABI void notify_all_at_thread_exit(condition_variable&, unique_lock<mutex>);
347350
348351_LIBCPP_END_NAMESPACE_STD
349352
350#endif // !_LIBCPP_HAS_NO_THREADS
353# endif // _LIBCPP_HAS_THREADS
351354
352355_LIBCPP_POP_MACROS
353356
354#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
355# include <atomic>
356# include <concepts>
357# include <cstdint>
358# include <cstdlib>
359# include <cstring>
360# include <initializer_list>
361# include <iosfwd>
362# include <new>
363# include <stdexcept>
364# include <system_error>
365# include <type_traits>
366# include <typeinfo>
367#endif
357# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
358# include <atomic>
359# include <concepts>
360# include <cstdint>
361# include <cstdlib>
362# include <cstring>
363# include <initializer_list>
364# include <iosfwd>
365# include <new>
366# include <stdexcept>
367# include <system_error>
368# include <type_traits>
369# include <typeinfo>
370# endif
371#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
368372
369373#endif // _LIBCPP_CONDITION_VARIABLE
lib/libcxx/include/coroutine+22-17
......@@ -38,30 +38,35 @@ struct suspend_always;
3838
3939 */
4040
41#include <__config>
41#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
42# include <__cxx03/coroutine>
43#else
44# include <__config>
4245
43#if _LIBCPP_STD_VER >= 20
44# include <__coroutine/coroutine_handle.h>
45# include <__coroutine/coroutine_traits.h>
46# include <__coroutine/noop_coroutine_handle.h>
47# include <__coroutine/trivial_awaitables.h>
48#endif // _LIBCPP_STD_VER >= 20
46# if _LIBCPP_STD_VER >= 20
47# include <__coroutine/coroutine_handle.h>
48# include <__coroutine/coroutine_traits.h>
49# include <__coroutine/noop_coroutine_handle.h>
50# include <__coroutine/trivial_awaitables.h>
51# endif // _LIBCPP_STD_VER >= 20
4952
50#include <version>
53# include <version>
5154
5255// standard-mandated includes
5356
5457// [coroutine.syn]
55#include <compare>
58# include <compare>
5659
57#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
58# pragma GCC system_header
59#endif
60# ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
61# pragma GCC system_header
62# endif
6063
61#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
62# include <iosfwd>
63# include <limits>
64# include <type_traits>
65#endif
64# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
65# include <cstddef>
66# include <iosfwd>
67# include <limits>
68# include <type_traits>
69# endif
70#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
6671
6772#endif // _LIBCPP_COROUTINE
lib/libcxx/include/csetjmp+14-9
......@@ -30,19 +30,22 @@ void longjmp(jmp_buf env, int val);
3030
3131*/
3232
33#include <__config>
33#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
34# include <__cxx03/csetjmp>
35#else
36# include <__config>
3437
3538// <setjmp.h> is not provided by libc++
36#if __has_include(<setjmp.h>)
37# include <setjmp.h>
38# ifdef _LIBCPP_SETJMP_H
39# error "If libc++ starts defining <setjmp.h>, the __has_include check should move to libc++'s <setjmp.h>"
39# if __has_include(<setjmp.h>)
40# include <setjmp.h>
41# ifdef _LIBCPP_SETJMP_H
42# error "If libc++ starts defining <setjmp.h>, the __has_include check should move to libc++'s <setjmp.h>"
43# endif
4044# endif
41#endif
4245
43#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
44# pragma GCC system_header
45#endif
46# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
47# pragma GCC system_header
48# endif
4649
4750_LIBCPP_BEGIN_NAMESPACE_STD
4851
......@@ -51,4 +54,6 @@ using ::longjmp _LIBCPP_USING_IF_EXISTS;
5154
5255_LIBCPP_END_NAMESPACE_STD
5356
57#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
58
5459#endif // _LIBCPP_CSETJMP
lib/libcxx/include/csignal+14-9
......@@ -39,19 +39,22 @@ int raise(int sig);
3939
4040*/
4141
42#include <__config>
42#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
43# include <__cxx03/csignal>
44#else
45# include <__config>
4346
4447// <signal.h> is not provided by libc++
45#if __has_include(<signal.h>)
46# include <signal.h>
47# ifdef _LIBCPP_SIGNAL_H
48# error "If libc++ starts defining <signal.h>, the __has_include check should move to libc++'s <signal.h>"
48# if __has_include(<signal.h>)
49# include <signal.h>
50# ifdef _LIBCPP_SIGNAL_H
51# error "If libc++ starts defining <signal.h>, the __has_include check should move to libc++'s <signal.h>"
52# endif
4953# endif
50#endif
5154
52#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
53# pragma GCC system_header
54#endif
55# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
56# pragma GCC system_header
57# endif
5558
5659_LIBCPP_BEGIN_NAMESPACE_STD
5760
......@@ -61,4 +64,6 @@ using ::raise _LIBCPP_USING_IF_EXISTS;
6164
6265_LIBCPP_END_NAMESPACE_STD
6366
67#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
68
6469#endif // _LIBCPP_CSIGNAL
lib/libcxx/include/cstdalign created+59
......@@ -0,0 +1,59 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_CSTDALIGN
11#define _LIBCPP_CSTDALIGN
12
13/*
14 cstdalign synopsis
15
16Macros:
17
18 __alignas_is_defined
19 __alignof_is_defined
20
21*/
22
23#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
24# include <__cxx03/__config>
25#else
26# include <__config>
27
28// <stdalign.h> is not provided by libc++
29# if __has_include(<stdalign.h>)
30# include <stdalign.h>
31# ifdef _LIBCPP_STDALIGN_H
32# error "If libc++ starts defining <stdalign.h>, the __has_include check should move to libc++'s <stdalign.h>"
33# endif
34# endif
35
36# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
37# pragma GCC system_header
38# endif
39
40# undef __alignas_is_defined
41# define __alignas_is_defined 1
42
43# undef __alignof_is_defined
44# define __alignof_is_defined 1
45
46# if _LIBCPP_STD_VER >= 20
47
48using __standard_header_cstdalign _LIBCPP_DEPRECATED_("removed in C++20.") _LIBCPP_NODEBUG = void;
49using __use_standard_header_cstdalign _LIBCPP_NODEBUG = __standard_header_cstdalign;
50
51# elif _LIBCPP_STD_VER >= 17
52
53using __standard_header_cstdalign _LIBCPP_DEPRECATED _LIBCPP_NODEBUG = void;
54using __use_standard_header_cstdalign _LIBCPP_NODEBUG = __standard_header_cstdalign;
55
56# endif
57#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
58
59#endif // _LIBCPP_CSTDALIGN
lib/libcxx/include/cstdarg+14-9
......@@ -31,19 +31,22 @@ Types:
3131
3232*/
3333
34#include <__config>
34#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
35# include <__cxx03/cstdarg>
36#else
37# include <__config>
3538
3639// <stdarg.h> is not provided by libc++
37#if __has_include(<stdarg.h>)
38# include <stdarg.h>
39# ifdef _LIBCPP_STDARG_H
40# error "If libc++ starts defining <stdarg.h>, the __has_include check should move to libc++'s <stdarg.h>"
40# if __has_include(<stdarg.h>)
41# include <stdarg.h>
42# ifdef _LIBCPP_STDARG_H
43# error "If libc++ starts defining <stdarg.h>, the __has_include check should move to libc++'s <stdarg.h>"
44# endif
4145# endif
42#endif
4346
44#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
45# pragma GCC system_header
46#endif
47# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
48# pragma GCC system_header
49# endif
4750
4851_LIBCPP_BEGIN_NAMESPACE_STD
4952
......@@ -51,4 +54,6 @@ using ::va_list _LIBCPP_USING_IF_EXISTS;
5154
5255_LIBCPP_END_NAMESPACE_STD
5356
57#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
58
5459#endif // _LIBCPP_CSTDARG
lib/libcxx/include/cstdbool+22-6
......@@ -19,13 +19,29 @@ Macros:
1919
2020*/
2121
22#include <__config>
22#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
23# include <__cxx03/cstdbool>
24#else
25# include <__config>
2326
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26#endif
27# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28# pragma GCC system_header
29# endif
2730
28#undef __bool_true_false_are_defined
29#define __bool_true_false_are_defined 1
31# undef __bool_true_false_are_defined
32# define __bool_true_false_are_defined 1
33
34# if _LIBCPP_STD_VER >= 20
35
36using __standard_header_cstdbool _LIBCPP_DEPRECATED_("removed in C++20.") _LIBCPP_NODEBUG = void;
37using __use_standard_header_cstdbool _LIBCPP_NODEBUG = __standard_header_cstdbool;
38
39# elif _LIBCPP_STD_VER >= 17
40
41using __standard_header_cstdbool _LIBCPP_DEPRECATED _LIBCPP_NODEBUG = void;
42using __use_standard_header_cstdbool _LIBCPP_NODEBUG = __standard_header_cstdbool;
43
44# endif
45#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
3046
3147#endif // _LIBCPP_CSTDBOOL
lib/libcxx/include/cstddef+19-89
......@@ -33,101 +33,31 @@ Types:
3333
3434*/
3535
36#include <__config>
37#include <__type_traits/enable_if.h>
38#include <__type_traits/integral_constant.h>
39#include <__type_traits/is_integral.h>
40#include <version>
36#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
37# include <__cxx03/cstddef>
38#else
39# include <__config>
40# include <version>
4141
42#include <stddef.h>
42# include <stddef.h>
4343
44#ifndef _LIBCPP_STDDEF_H
44# ifndef _LIBCPP_STDDEF_H
4545# error <cstddef> tried including <stddef.h> but didn't find libc++'s <stddef.h> header. \
4646 This usually means that your header search paths are not configured properly. \
4747 The header search paths should contain the C++ Standard Library headers before \
4848 any C Standard Library, and you are probably using compiler flags that make that \
4949 not be the case.
50#endif
51
52#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
53# pragma GCC system_header
54#endif
55
56_LIBCPP_BEGIN_NAMESPACE_STD
57
58using ::nullptr_t;
59using ::ptrdiff_t _LIBCPP_USING_IF_EXISTS;
60using ::size_t _LIBCPP_USING_IF_EXISTS;
61
62#if !defined(_LIBCPP_CXX03_LANG)
63using ::max_align_t _LIBCPP_USING_IF_EXISTS;
64#endif
65
66_LIBCPP_END_NAMESPACE_STD
67
68#if _LIBCPP_STD_VER >= 17
69namespace std // purposefully not versioned
70{
71enum class byte : unsigned char {};
72
73_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator|(byte __lhs, byte __rhs) noexcept {
74 return static_cast<byte>(
75 static_cast<unsigned char>(static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs)));
76}
77
78_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept {
79 return __lhs = __lhs | __rhs;
80}
81
82_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator&(byte __lhs, byte __rhs) noexcept {
83 return static_cast<byte>(
84 static_cast<unsigned char>(static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs)));
85}
86
87_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept {
88 return __lhs = __lhs & __rhs;
89}
90
91_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator^(byte __lhs, byte __rhs) noexcept {
92 return static_cast<byte>(
93 static_cast<unsigned char>(static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs)));
94}
95
96_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept {
97 return __lhs = __lhs ^ __rhs;
98}
99
100_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator~(byte __b) noexcept {
101 return static_cast<byte>(static_cast<unsigned char>(~static_cast<unsigned int>(__b)));
102}
103
104template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
105_LIBCPP_HIDE_FROM_ABI constexpr byte& operator<<=(byte& __lhs, _Integer __shift) noexcept {
106 return __lhs = __lhs << __shift;
107}
108
109template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
110_LIBCPP_HIDE_FROM_ABI constexpr byte operator<<(byte __lhs, _Integer __shift) noexcept {
111 return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift));
112}
113
114template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
115_LIBCPP_HIDE_FROM_ABI constexpr byte& operator>>=(byte& __lhs, _Integer __shift) noexcept {
116 return __lhs = __lhs >> __shift;
117}
118
119template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
120_LIBCPP_HIDE_FROM_ABI constexpr byte operator>>(byte __lhs, _Integer __shift) noexcept {
121 return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift));
122}
123
124template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
125[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Integer to_integer(byte __b) noexcept {
126 return static_cast<_Integer>(__b);
127}
128
129} // namespace std
130
131#endif
50# endif
51
52# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
53# pragma GCC system_header
54# endif
55
56# include <__cstddef/byte.h>
57# include <__cstddef/max_align_t.h>
58# include <__cstddef/nullptr_t.h>
59# include <__cstddef/ptrdiff_t.h>
60# include <__cstddef/size_t.h>
61#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
13262
13363#endif // _LIBCPP_CSTDDEF
lib/libcxx/include/cstdint+12-13
......@@ -140,21 +140,18 @@ Types:
140140} // std
141141*/
142142
143#include <__config>
143#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
144# include <__cxx03/cstdint>
145#else
146# include <__config>
144147
145#include <stdint.h>
148# if __has_include(<stdint.h>)
149# include <stdint.h>
150# endif
146151
147#ifndef _LIBCPP_STDINT_H
148# error <cstdint> tried including <stdint.h> but didn't find libc++'s <stdint.h> header. \
149 This usually means that your header search paths are not configured properly. \
150 The header search paths should contain the C++ Standard Library headers before \
151 any C Standard Library, and you are probably using compiler flags that make that \
152 not be the case.
153#endif
154
155#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
156# pragma GCC system_header
157#endif
152# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
153# pragma GCC system_header
154# endif
158155
159156_LIBCPP_BEGIN_NAMESPACE_STD
160157
......@@ -196,4 +193,6 @@ using ::uintmax_t _LIBCPP_USING_IF_EXISTS;
196193
197194_LIBCPP_END_NAMESPACE_STD
198195
196#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
197
199198#endif // _LIBCPP_CSTDINT
lib/libcxx/include/cstdio+15-10
......@@ -95,27 +95,30 @@ void perror(const char* s);
9595} // std
9696*/
9797
98#include <__config>
98#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
99# include <__cxx03/cstdio>
100#else
101# include <__config>
102# include <__cstddef/size_t.h>
99103
100#include <stdio.h>
104# include <stdio.h>
101105
102#ifndef _LIBCPP_STDIO_H
106# ifndef _LIBCPP_STDIO_H
103107# error <cstdio> tried including <stdio.h> but didn't find libc++'s <stdio.h> header. \
104108 This usually means that your header search paths are not configured properly. \
105109 The header search paths should contain the C++ Standard Library headers before \
106110 any C Standard Library, and you are probably using compiler flags that make that \
107111 not be the case.
108#endif
112# endif
109113
110#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
111# pragma GCC system_header
112#endif
114# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
115# pragma GCC system_header
116# endif
113117
114118_LIBCPP_BEGIN_NAMESPACE_STD
115119
116120using ::FILE _LIBCPP_USING_IF_EXISTS;
117121using ::fpos_t _LIBCPP_USING_IF_EXISTS;
118using ::size_t _LIBCPP_USING_IF_EXISTS;
119122
120123using ::fclose _LIBCPP_USING_IF_EXISTS;
121124using ::fflush _LIBCPP_USING_IF_EXISTS;
......@@ -158,9 +161,9 @@ using ::tmpfile _LIBCPP_USING_IF_EXISTS;
158161using ::tmpnam _LIBCPP_USING_IF_EXISTS;
159162
160163using ::getchar _LIBCPP_USING_IF_EXISTS;
161#if _LIBCPP_STD_VER <= 11
164# if _LIBCPP_STD_VER <= 11
162165using ::gets _LIBCPP_USING_IF_EXISTS;
163#endif
166# endif
164167using ::scanf _LIBCPP_USING_IF_EXISTS;
165168using ::vscanf _LIBCPP_USING_IF_EXISTS;
166169
......@@ -171,4 +174,6 @@ using ::vprintf _LIBCPP_USING_IF_EXISTS;
171174
172175_LIBCPP_END_NAMESPACE_STD
173176
177#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
178
174179#endif // _LIBCPP_CSTDIO
lib/libcxx/include/cstdlib+19-14
......@@ -81,25 +81,28 @@ void *aligned_alloc(size_t alignment, size_t size); // C11
8181
8282*/
8383
84#include <__config>
84#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
85# include <__cxx03/cstdlib>
86#else
87# include <__config>
88# include <__cstddef/size_t.h>
8589
86#include <stdlib.h>
90# include <stdlib.h>
8791
88#ifndef _LIBCPP_STDLIB_H
92# ifndef _LIBCPP_STDLIB_H
8993# error <cstdlib> tried including <stdlib.h> but didn't find libc++'s <stdlib.h> header. \
9094 This usually means that your header search paths are not configured properly. \
9195 The header search paths should contain the C++ Standard Library headers before \
9296 any C Standard Library, and you are probably using compiler flags that make that \
9397 not be the case.
94#endif
98# endif
9599
96#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
97# pragma GCC system_header
98#endif
100# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
101# pragma GCC system_header
102# endif
99103
100104_LIBCPP_BEGIN_NAMESPACE_STD
101105
102using ::size_t _LIBCPP_USING_IF_EXISTS;
103106using ::div_t _LIBCPP_USING_IF_EXISTS;
104107using ::ldiv_t _LIBCPP_USING_IF_EXISTS;
105108using ::lldiv_t _LIBCPP_USING_IF_EXISTS;
......@@ -135,20 +138,22 @@ using ::div _LIBCPP_USING_IF_EXISTS;
135138using ::ldiv _LIBCPP_USING_IF_EXISTS;
136139using ::lldiv _LIBCPP_USING_IF_EXISTS;
137140using ::mblen _LIBCPP_USING_IF_EXISTS;
138#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
141# if _LIBCPP_HAS_WIDE_CHARACTERS
139142using ::mbtowc _LIBCPP_USING_IF_EXISTS;
140143using ::wctomb _LIBCPP_USING_IF_EXISTS;
141144using ::mbstowcs _LIBCPP_USING_IF_EXISTS;
142145using ::wcstombs _LIBCPP_USING_IF_EXISTS;
143#endif
144#if !defined(_LIBCPP_CXX03_LANG)
146# endif
147# if !defined(_LIBCPP_CXX03_LANG)
145148using ::at_quick_exit _LIBCPP_USING_IF_EXISTS;
146149using ::quick_exit _LIBCPP_USING_IF_EXISTS;
147#endif
148#if _LIBCPP_STD_VER >= 17
150# endif
151# if _LIBCPP_STD_VER >= 17
149152using ::aligned_alloc _LIBCPP_USING_IF_EXISTS;
150#endif
153# endif
151154
152155_LIBCPP_END_NAMESPACE_STD
153156
157#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
158
154159#endif // _LIBCPP_CSTDLIB
lib/libcxx/include/cstring+14-9
......@@ -56,26 +56,29 @@ size_t strlen(const char* s);
5656
5757*/
5858
59#include <__config>
60#include <__type_traits/is_constant_evaluated.h>
59#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
60# include <__cxx03/cstring>
61#else
62# include <__config>
63# include <__cstddef/size_t.h>
64# include <__type_traits/is_constant_evaluated.h>
6165
62#include <string.h>
66# include <string.h>
6367
64#ifndef _LIBCPP_STRING_H
68# ifndef _LIBCPP_STRING_H
6569# error <cstring> tried including <string.h> but didn't find libc++'s <string.h> header. \
6670 This usually means that your header search paths are not configured properly. \
6771 The header search paths should contain the C++ Standard Library headers before \
6872 any C Standard Library, and you are probably using compiler flags that make that \
6973 not be the case.
70#endif
74# endif
7175
72#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
73# pragma GCC system_header
74#endif
76# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
77# pragma GCC system_header
78# endif
7579
7680_LIBCPP_BEGIN_NAMESPACE_STD
7781
78using ::size_t _LIBCPP_USING_IF_EXISTS;
7982using ::memcpy _LIBCPP_USING_IF_EXISTS;
8083using ::memmove _LIBCPP_USING_IF_EXISTS;
8184using ::strcpy _LIBCPP_USING_IF_EXISTS;
......@@ -101,4 +104,6 @@ using ::strlen _LIBCPP_USING_IF_EXISTS;
101104
102105_LIBCPP_END_NAMESPACE_STD
103106
107#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
108
104109#endif // _LIBCPP_CSTRING
lib/libcxx/include/ctgmath+23-5
......@@ -18,11 +18,29 @@
1818
1919*/
2020
21#include <ccomplex>
22#include <cmath>
21#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
22# include <__cxx03/ctgmath>
23#else
24# include <cmath>
25# include <complex>
26
27# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28# pragma GCC system_header
29# endif
30
31# if _LIBCPP_STD_VER >= 20
32
33using __standard_header_ctgmath
34 _LIBCPP_DEPRECATED_("removed in C++20. Include <cmath> and <complex> instead.") _LIBCPP_NODEBUG = void;
35using __use_standard_header_ctgmath _LIBCPP_NODEBUG = __standard_header_ctgmath;
36
37# elif _LIBCPP_STD_VER >= 17
38
39using __standard_header_ctgmath _LIBCPP_DEPRECATED_("Include <cmath> and <complex> instead.") _LIBCPP_NODEBUG = void;
40using __use_standard_header_ctgmath _LIBCPP_NODEBUG = __standard_header_ctgmath;
41
42# endif
2343
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26#endif
44#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
2745
2846#endif // _LIBCPP_CTGMATH
lib/libcxx/include/ctime+19-14
......@@ -45,29 +45,32 @@ int timespec_get( struct timespec *ts, int base); // C++17
4545
4646*/
4747
48#include <__config>
48#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
49# include <__cxx03/ctime>
50#else
51# include <__config>
52# include <__cstddef/size_t.h>
4953
5054// <time.h> is not provided by libc++
51#if __has_include(<time.h>)
52# include <time.h>
53# ifdef _LIBCPP_TIME_H
54# error "If libc++ starts defining <time.h>, the __has_include check should move to libc++'s <time.h>"
55# if __has_include(<time.h>)
56# include <time.h>
57# ifdef _LIBCPP_TIME_H
58# error "If libc++ starts defining <time.h>, the __has_include check should move to libc++'s <time.h>"
59# endif
5560# endif
56#endif
5761
58#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
59# pragma GCC system_header
60#endif
62# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
63# pragma GCC system_header
64# endif
6165
6266_LIBCPP_BEGIN_NAMESPACE_STD
6367
6468using ::clock_t _LIBCPP_USING_IF_EXISTS;
65using ::size_t _LIBCPP_USING_IF_EXISTS;
6669using ::time_t _LIBCPP_USING_IF_EXISTS;
6770using ::tm _LIBCPP_USING_IF_EXISTS;
68#if _LIBCPP_STD_VER >= 17
71# if _LIBCPP_STD_VER >= 17
6972using ::timespec _LIBCPP_USING_IF_EXISTS;
70#endif
73# endif
7174using ::clock _LIBCPP_USING_IF_EXISTS;
7275using ::difftime _LIBCPP_USING_IF_EXISTS;
7376using ::mktime _LIBCPP_USING_IF_EXISTS;
......@@ -77,10 +80,12 @@ using ::ctime _LIBCPP_USING_IF_EXISTS;
7780using ::gmtime _LIBCPP_USING_IF_EXISTS;
7881using ::localtime _LIBCPP_USING_IF_EXISTS;
7982using ::strftime _LIBCPP_USING_IF_EXISTS;
80#if _LIBCPP_STD_VER >= 17
83# if _LIBCPP_STD_VER >= 17
8184using ::timespec_get _LIBCPP_USING_IF_EXISTS;
82#endif
85# endif
8386
8487_LIBCPP_END_NAMESPACE_STD
8588
89#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
90
8691#endif // _LIBCPP_CTIME
lib/libcxx/include/ctype.h+32-28
......@@ -29,33 +29,37 @@ int tolower(int c);
2929int toupper(int c);
3030*/
3131
32#include <__config>
33
34#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
35# pragma GCC system_header
36#endif
37
38#if __has_include_next(<ctype.h>)
39# include_next <ctype.h>
40#endif
41
42#ifdef __cplusplus
43
44# undef isalnum
45# undef isalpha
46# undef isblank
47# undef iscntrl
48# undef isdigit
49# undef isgraph
50# undef islower
51# undef isprint
52# undef ispunct
53# undef isspace
54# undef isupper
55# undef isxdigit
56# undef tolower
57# undef toupper
58
59#endif
32#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
33# include <__cxx03/ctype.h>
34#else
35# include <__config>
36
37# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
38# pragma GCC system_header
39# endif
40
41# if __has_include_next(<ctype.h>)
42# include_next <ctype.h>
43# endif
44
45# ifdef __cplusplus
46
47# undef isalnum
48# undef isalpha
49# undef isblank
50# undef iscntrl
51# undef isdigit
52# undef isgraph
53# undef islower
54# undef isprint
55# undef ispunct
56# undef isspace
57# undef isupper
58# undef isxdigit
59# undef tolower
60# undef toupper
61
62# endif
63#endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
6064
6165#endif // _LIBCPP_CTYPE_H
lib/libcxx/include/cuchar+17-12
......@@ -36,40 +36,45 @@ size_t c32rtomb(char* s, char32_t c32, mbstate_t* ps);
3636
3737*/
3838
39#include <__config>
39#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
40# include <__cxx03/cuchar>
41#else
42# include <__config>
43# include <__cstddef/size_t.h>
4044
41#include <uchar.h>
45# include <uchar.h>
4246
43#ifndef _LIBCPP_UCHAR_H
47# ifndef _LIBCPP_UCHAR_H
4448# error <cuchar> tried including <uchar.h> but didn't find libc++'s <uchar.h> header. \
4549 This usually means that your header search paths are not configured properly. \
4650 The header search paths should contain the C++ Standard Library headers before \
4751 any C Standard Library, and you are probably using compiler flags that make that \
4852 not be the case.
49#endif
53# endif
5054
51#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
52# pragma GCC system_header
53#endif
55# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
56# pragma GCC system_header
57# endif
5458
5559_LIBCPP_BEGIN_NAMESPACE_STD
5660
57#if !defined(_LIBCPP_CXX03_LANG)
61# if !defined(_LIBCPP_CXX03_LANG)
5862
5963using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
60using ::size_t _LIBCPP_USING_IF_EXISTS;
6164
62# if !defined(_LIBCPP_HAS_NO_C8RTOMB_MBRTOC8)
65# if _LIBCPP_HAS_C8RTOMB_MBRTOC8
6366using ::mbrtoc8 _LIBCPP_USING_IF_EXISTS;
6467using ::c8rtomb _LIBCPP_USING_IF_EXISTS;
65# endif
68# endif
6669using ::mbrtoc16 _LIBCPP_USING_IF_EXISTS;
6770using ::c16rtomb _LIBCPP_USING_IF_EXISTS;
6871using ::mbrtoc32 _LIBCPP_USING_IF_EXISTS;
6972using ::c32rtomb _LIBCPP_USING_IF_EXISTS;
7073
71#endif // _LIBCPP_CXX03_LANG
74# endif // _LIBCPP_CXX03_LANG
7275
7376_LIBCPP_END_NAMESPACE_STD
7477
78#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
79
7580#endif // _LIBCPP_CUCHAR
lib/libcxx/include/cwchar+31-27
......@@ -102,32 +102,35 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
102102
103103*/
104104
105#include <__config>
106#include <__type_traits/copy_cv.h>
107#include <__type_traits/is_constant_evaluated.h>
108#include <__type_traits/is_equality_comparable.h>
109#include <__type_traits/is_same.h>
110#include <__type_traits/remove_cv.h>
111#include <cwctype>
105#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
106# include <__cxx03/cwchar>
107#else
108# include <__config>
109# include <__cstddef/size_t.h>
110# include <__type_traits/copy_cv.h>
111# include <__type_traits/is_constant_evaluated.h>
112# include <__type_traits/is_equality_comparable.h>
113# include <__type_traits/is_same.h>
114# include <__type_traits/remove_cv.h>
115# include <cwctype>
112116
113#include <wchar.h>
117# include <wchar.h>
114118
115#ifndef _LIBCPP_WCHAR_H
119# ifndef _LIBCPP_WCHAR_H
116120# error <cwchar> tried including <wchar.h> but didn't find libc++'s <wchar.h> header. \
117121 This usually means that your header search paths are not configured properly. \
118122 The header search paths should contain the C++ Standard Library headers before \
119123 any C Standard Library, and you are probably using compiler flags that make that \
120124 not be the case.
121#endif
125# endif
122126
123#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
124# pragma GCC system_header
125#endif
127# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
128# pragma GCC system_header
129# endif
126130
127131_LIBCPP_BEGIN_NAMESPACE_STD
128132
129133using ::mbstate_t _LIBCPP_USING_IF_EXISTS;
130using ::size_t _LIBCPP_USING_IF_EXISTS;
131134using ::tm _LIBCPP_USING_IF_EXISTS;
132135using ::wint_t _LIBCPP_USING_IF_EXISTS;
133136using ::FILE _LIBCPP_USING_IF_EXISTS;
......@@ -194,9 +197,9 @@ using ::vwprintf _LIBCPP_USING_IF_EXISTS;
194197using ::wprintf _LIBCPP_USING_IF_EXISTS;
195198
196199inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 size_t __constexpr_wcslen(const wchar_t* __str) {
197#if __has_builtin(__builtin_wcslen)
200# if __has_builtin(__builtin_wcslen)
198201 return __builtin_wcslen(__str);
199#else
202# else
200203 if (!__libcpp_is_constant_evaluated())
201204 return std::wcslen(__str);
202205
......@@ -204,14 +207,14 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 size_t __constexpr_wc
204207 for (; *__str != L'\0'; ++__str)
205208 ++__len;
206209 return __len;
207#endif
210# endif
208211}
209212
210213inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int
211214__constexpr_wmemcmp(const wchar_t* __lhs, const wchar_t* __rhs, size_t __count) {
212#if __has_builtin(__builtin_wmemcmp)
215# if __has_builtin(__builtin_wmemcmp)
213216 return __builtin_wmemcmp(__lhs, __rhs, __count);
214#else
217# else
215218 if (!__libcpp_is_constant_evaluated())
216219 return std::wmemcmp(__lhs, __rhs, __count);
217220
......@@ -222,7 +225,7 @@ __constexpr_wmemcmp(const wchar_t* __lhs, const wchar_t* __rhs, size_t __count)
222225 return 1;
223226 }
224227 return 0;
225#endif
228# endif
226229}
227230
228231template <class _Tp, class _Up>
......@@ -231,18 +234,18 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __constexpr_wmemchr(_Tp
231234 __libcpp_is_trivially_equality_comparable<_Tp, _Tp>::value,
232235 "Calling wmemchr on non-trivially equality comparable types is unsafe.");
233236
234#if __has_builtin(__builtin_wmemchr)
237# if __has_builtin(__builtin_wmemchr)
235238 if (!__libcpp_is_constant_evaluated()) {
236239 wchar_t __value_buffer = 0;
237240 __builtin_memcpy(&__value_buffer, &__value, sizeof(wchar_t));
238241 return reinterpret_cast<_Tp*>(
239242 __builtin_wmemchr(reinterpret_cast<__copy_cv_t<_Tp, wchar_t>*>(__str), __value_buffer, __count));
240243 }
241# if _LIBCPP_STD_VER >= 17
244# if _LIBCPP_STD_VER >= 17
242245 else if constexpr (is_same_v<remove_cv_t<_Tp>, wchar_t>)
243246 return __builtin_wmemchr(__str, __value, __count);
244# endif
245#endif // __has_builtin(__builtin_wmemchr)
247# endif
248# endif // __has_builtin(__builtin_wmemchr)
246249
247250 for (; __count; --__count) {
248251 if (*__str == __value)
......@@ -254,8 +257,9 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __constexpr_wmemchr(_Tp
254257
255258_LIBCPP_END_NAMESPACE_STD
256259
257#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
258# include <cstddef>
259#endif
260# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
261# include <cstddef>
262# endif
263#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
260264
261265#endif // _LIBCPP_CWCHAR
lib/libcxx/include/cwctype+15-10
......@@ -49,26 +49,29 @@ wctrans_t wctrans(const char* property);
4949
5050*/
5151
52#include <__config>
53#include <cctype>
52#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
53# include <__cxx03/cwctype>
54#else
55# include <__config>
56# include <cctype>
5457
55#include <wctype.h>
58# include <wctype.h>
5659
57#ifndef _LIBCPP_WCTYPE_H
60# ifndef _LIBCPP_WCTYPE_H
5861# error <cwctype> tried including <wctype.h> but didn't find libc++'s <wctype.h> header. \
5962 This usually means that your header search paths are not configured properly. \
6063 The header search paths should contain the C++ Standard Library headers before \
6164 any C Standard Library, and you are probably using compiler flags that make that \
6265 not be the case.
63#endif
66# endif
6467
65#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
66# pragma GCC system_header
67#endif
68# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
69# pragma GCC system_header
70# endif
6871
6972_LIBCPP_BEGIN_NAMESPACE_STD
7073
71#if defined(_LIBCPP_INCLUDED_C_LIBRARY_WCTYPE_H)
74# if defined(_LIBCPP_INCLUDED_C_LIBRARY_WCTYPE_H)
7275using ::wint_t _LIBCPP_USING_IF_EXISTS;
7376using ::wctrans_t _LIBCPP_USING_IF_EXISTS;
7477using ::wctype_t _LIBCPP_USING_IF_EXISTS;
......@@ -90,8 +93,10 @@ using ::towlower _LIBCPP_USING_IF_EXISTS;
9093using ::towupper _LIBCPP_USING_IF_EXISTS;
9194using ::towctrans _LIBCPP_USING_IF_EXISTS;
9295using ::wctrans _LIBCPP_USING_IF_EXISTS;
93#endif // _LIBCPP_INCLUDED_C_LIBRARY_WCTYPE_H
96# endif // _LIBCPP_INCLUDED_C_LIBRARY_WCTYPE_H
9497
9598_LIBCPP_END_NAMESPACE_STD
9699
100#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
101
97102#endif // _LIBCPP_CWCTYPE
lib/libcxx/include/deque+267-233
......@@ -177,72 +177,90 @@ template <class T, class Allocator, class Predicate>
177177
178178*/
179179
180#include <__algorithm/copy.h>
181#include <__algorithm/copy_backward.h>
182#include <__algorithm/copy_n.h>
183#include <__algorithm/equal.h>
184#include <__algorithm/fill_n.h>
185#include <__algorithm/lexicographical_compare.h>
186#include <__algorithm/lexicographical_compare_three_way.h>
187#include <__algorithm/min.h>
188#include <__algorithm/remove.h>
189#include <__algorithm/remove_if.h>
190#include <__algorithm/unwrap_iter.h>
191#include <__assert>
192#include <__config>
193#include <__debug_utils/sanitizers.h>
194#include <__format/enable_insertable.h>
195#include <__fwd/deque.h>
196#include <__iterator/distance.h>
197#include <__iterator/iterator_traits.h>
198#include <__iterator/next.h>
199#include <__iterator/prev.h>
200#include <__iterator/reverse_iterator.h>
201#include <__iterator/segmented_iterator.h>
202#include <__memory/addressof.h>
203#include <__memory/allocator_destructor.h>
204#include <__memory/pointer_traits.h>
205#include <__memory/temp_value.h>
206#include <__memory/unique_ptr.h>
207#include <__memory_resource/polymorphic_allocator.h>
208#include <__ranges/access.h>
209#include <__ranges/concepts.h>
210#include <__ranges/container_compatible_range.h>
211#include <__ranges/from_range.h>
212#include <__ranges/size.h>
213#include <__split_buffer>
214#include <__type_traits/is_allocator.h>
215#include <__type_traits/is_convertible.h>
216#include <__type_traits/is_same.h>
217#include <__type_traits/is_swappable.h>
218#include <__type_traits/type_identity.h>
219#include <__utility/forward.h>
220#include <__utility/move.h>
221#include <__utility/pair.h>
222#include <__utility/swap.h>
223#include <limits>
224#include <stdexcept>
225#include <version>
180#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
181# include <__cxx03/deque>
182#else
183# include <__algorithm/copy.h>
184# include <__algorithm/copy_backward.h>
185# include <__algorithm/copy_n.h>
186# include <__algorithm/equal.h>
187# include <__algorithm/fill_n.h>
188# include <__algorithm/lexicographical_compare.h>
189# include <__algorithm/lexicographical_compare_three_way.h>
190# include <__algorithm/max.h>
191# include <__algorithm/min.h>
192# include <__algorithm/move.h>
193# include <__algorithm/move_backward.h>
194# include <__algorithm/remove.h>
195# include <__algorithm/remove_if.h>
196# include <__algorithm/unwrap_iter.h>
197# include <__assert>
198# include <__config>
199# include <__debug_utils/sanitizers.h>
200# include <__format/enable_insertable.h>
201# include <__fwd/deque.h>
202# include <__iterator/distance.h>
203# include <__iterator/iterator_traits.h>
204# include <__iterator/move_iterator.h>
205# include <__iterator/next.h>
206# include <__iterator/prev.h>
207# include <__iterator/reverse_iterator.h>
208# include <__iterator/segmented_iterator.h>
209# include <__memory/addressof.h>
210# include <__memory/allocator.h>
211# include <__memory/allocator_destructor.h>
212# include <__memory/allocator_traits.h>
213# include <__memory/compressed_pair.h>
214# include <__memory/pointer_traits.h>
215# include <__memory/swap_allocator.h>
216# include <__memory/temp_value.h>
217# include <__memory/unique_ptr.h>
218# include <__memory_resource/polymorphic_allocator.h>
219# include <__ranges/access.h>
220# include <__ranges/concepts.h>
221# include <__ranges/container_compatible_range.h>
222# include <__ranges/from_range.h>
223# include <__ranges/size.h>
224# include <__split_buffer>
225# include <__type_traits/conditional.h>
226# include <__type_traits/container_traits.h>
227# include <__type_traits/disjunction.h>
228# include <__type_traits/enable_if.h>
229# include <__type_traits/is_allocator.h>
230# include <__type_traits/is_convertible.h>
231# include <__type_traits/is_nothrow_assignable.h>
232# include <__type_traits/is_nothrow_constructible.h>
233# include <__type_traits/is_same.h>
234# include <__type_traits/is_swappable.h>
235# include <__type_traits/is_trivially_relocatable.h>
236# include <__type_traits/type_identity.h>
237# include <__utility/forward.h>
238# include <__utility/move.h>
239# include <__utility/pair.h>
240# include <__utility/swap.h>
241# include <limits>
242# include <stdexcept>
243# include <version>
226244
227245// standard-mandated includes
228246
229247// [iterator.range]
230#include <__iterator/access.h>
231#include <__iterator/data.h>
232#include <__iterator/empty.h>
233#include <__iterator/reverse_access.h>
234#include <__iterator/size.h>
248# include <__iterator/access.h>
249# include <__iterator/data.h>
250# include <__iterator/empty.h>
251# include <__iterator/reverse_access.h>
252# include <__iterator/size.h>
235253
236254// [deque.syn]
237#include <compare>
238#include <initializer_list>
255# include <compare>
256# include <initializer_list>
239257
240#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
241# pragma GCC system_header
242#endif
258# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
259# pragma GCC system_header
260# endif
243261
244262_LIBCPP_PUSH_MACROS
245#include <__undef_macros>
263# include <__undef_macros>
246264
247265_LIBCPP_BEGIN_NAMESPACE_STD
248266
......@@ -257,13 +275,13 @@ template <class _ValueType,
257275 class _MapPointer,
258276 class _DiffType,
259277 _DiffType _BS =
260#ifdef _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
278# ifdef _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
261279 // Keep template parameter to avoid changing all template declarations thoughout
262280 // this file.
263281 0
264#else
282# else
265283 __deque_block_size<_ValueType, _DiffType>::value
266#endif
284# endif
267285 >
268286class _LIBCPP_TEMPLATE_VIS __deque_iterator {
269287 typedef _MapPointer __map_iterator;
......@@ -284,10 +302,10 @@ public:
284302 typedef _Reference reference;
285303
286304 _LIBCPP_HIDE_FROM_ABI __deque_iterator() _NOEXCEPT
287#if _LIBCPP_STD_VER >= 14
305# if _LIBCPP_STD_VER >= 14
288306 : __m_iter_(nullptr),
289307 __ptr_(nullptr)
290#endif
308# endif
291309 {
292310 }
293311
......@@ -376,13 +394,10 @@ public:
376394 return __x.__ptr_ == __y.__ptr_;
377395 }
378396
379#if _LIBCPP_STD_VER <= 17
397# if _LIBCPP_STD_VER <= 17
380398 _LIBCPP_HIDE_FROM_ABI friend bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y) {
381399 return !(__x == __y);
382400 }
383#endif
384
385 // TODO(mordante) disable these overloads in the LLVM 20 release.
386401 _LIBCPP_HIDE_FROM_ABI friend bool operator<(const __deque_iterator& __x, const __deque_iterator& __y) {
387402 return __x.__m_iter_ < __y.__m_iter_ || (__x.__m_iter_ == __y.__m_iter_ && __x.__ptr_ < __y.__ptr_);
388403 }
......@@ -399,7 +414,8 @@ public:
399414 return !(__x < __y);
400415 }
401416
402#if _LIBCPP_STD_VER >= 20
417# else
418
403419 _LIBCPP_HIDE_FROM_ABI friend strong_ordering operator<=>(const __deque_iterator& __x, const __deque_iterator& __y) {
404420 if (__x.__m_iter_ < __y.__m_iter_)
405421 return strong_ordering::less;
......@@ -420,7 +436,7 @@ public:
420436
421437 return strong_ordering::greater;
422438 }
423#endif // _LIBCPP_STD_VER >= 20
439# endif // _LIBCPP_STD_VER >= 20
424440
425441private:
426442 _LIBCPP_HIDE_FROM_ABI explicit __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT
......@@ -440,12 +456,13 @@ template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
440456struct __segmented_iterator_traits<
441457 __deque_iterator<_ValueType, _Pointer, _Reference, _MapPointer, _DiffType, _BlockSize> > {
442458private:
443 using _Iterator = __deque_iterator<_ValueType, _Pointer, _Reference, _MapPointer, _DiffType, _BlockSize>;
459 using _Iterator _LIBCPP_NODEBUG =
460 __deque_iterator<_ValueType, _Pointer, _Reference, _MapPointer, _DiffType, _BlockSize>;
444461
445462public:
446 using __is_segmented_iterator = true_type;
447 using __segment_iterator = _MapPointer;
448 using __local_iterator = _Pointer;
463 using __is_segmented_iterator _LIBCPP_NODEBUG = true_type;
464 using __segment_iterator _LIBCPP_NODEBUG = _MapPointer;
465 using __local_iterator _LIBCPP_NODEBUG = _Pointer;
449466
450467 static _LIBCPP_HIDE_FROM_ABI __segment_iterator __segment(_Iterator __iter) { return __iter.__m_iter_; }
451468 static _LIBCPP_HIDE_FROM_ABI __local_iterator __local(_Iterator __iter) { return __iter.__ptr_; }
......@@ -475,8 +492,8 @@ public:
475492
476493 using value_type = _Tp;
477494
478 using allocator_type = _Allocator;
479 using __alloc_traits = allocator_traits<allocator_type>;
495 using allocator_type = _Allocator;
496 using __alloc_traits _LIBCPP_NODEBUG = allocator_traits<allocator_type>;
480497 static_assert(__check_valid_allocator<allocator_type>::value, "");
481498 static_assert(is_same<typename allocator_type::value_type, value_type>::value,
482499 "Allocator::value_type must be same type as value_type");
......@@ -487,13 +504,13 @@ public:
487504 using pointer = typename __alloc_traits::pointer;
488505 using const_pointer = typename __alloc_traits::const_pointer;
489506
490 using __pointer_allocator = __rebind_alloc<__alloc_traits, pointer>;
491 using __const_pointer_allocator = __rebind_alloc<__alloc_traits, const_pointer>;
492 using __map = __split_buffer<pointer, __pointer_allocator>;
493 using __map_alloc_traits = allocator_traits<__pointer_allocator>;
494 using __map_pointer = typename __map_alloc_traits::pointer;
495 using __map_const_pointer = typename allocator_traits<__const_pointer_allocator>::const_pointer;
496 using __map_const_iterator = typename __map::const_iterator;
507 using __pointer_allocator _LIBCPP_NODEBUG = __rebind_alloc<__alloc_traits, pointer>;
508 using __const_pointer_allocator _LIBCPP_NODEBUG = __rebind_alloc<__alloc_traits, const_pointer>;
509 using __map _LIBCPP_NODEBUG = __split_buffer<pointer, __pointer_allocator>;
510 using __map_alloc_traits _LIBCPP_NODEBUG = allocator_traits<__pointer_allocator>;
511 using __map_pointer _LIBCPP_NODEBUG = typename __map_alloc_traits::pointer;
512 using __map_const_pointer _LIBCPP_NODEBUG = typename allocator_traits<__const_pointer_allocator>::const_pointer;
513 using __map_const_iterator _LIBCPP_NODEBUG = typename __map::const_iterator;
497514
498515 using reference = value_type&;
499516 using const_reference = const value_type&;
......@@ -509,7 +526,7 @@ public:
509526 // - size_type: is always trivially relocatable, since it is required to be an integral type
510527 // - allocator_type: may not be trivially relocatable, so it's checked
511528 // None of these are referencing the `deque` itself, so if all of them are trivially relocatable, `deque` is too.
512 using __trivially_relocatable = __conditional_t<
529 using __trivially_relocatable _LIBCPP_NODEBUG = __conditional_t<
513530 __libcpp_is_trivially_relocatable<__map>::value && __libcpp_is_trivially_relocatable<allocator_type>::value,
514531 deque,
515532 void>;
......@@ -584,12 +601,12 @@ private:
584601
585602 __map __map_;
586603 size_type __start_;
587 __compressed_pair<size_type, allocator_type> __size_;
604 _LIBCPP_COMPRESSED_PAIR(size_type, __size_, allocator_type, __alloc_);
588605
589606public:
590607 // construct/copy/destroy:
591608 _LIBCPP_HIDE_FROM_ABI deque() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
592 : __start_(0), __size_(0, __default_init_tag()) {
609 : __start_(0), __size_(0) {
593610 __annotate_new(0);
594611 }
595612
......@@ -603,19 +620,19 @@ public:
603620 }
604621
605622 _LIBCPP_HIDE_FROM_ABI explicit deque(const allocator_type& __a)
606 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {
623 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) {
607624 __annotate_new(0);
608625 }
609626
610627 explicit _LIBCPP_HIDE_FROM_ABI deque(size_type __n);
611#if _LIBCPP_STD_VER >= 14
628# if _LIBCPP_STD_VER >= 14
612629 explicit _LIBCPP_HIDE_FROM_ABI deque(size_type __n, const _Allocator& __a);
613#endif
630# endif
614631 _LIBCPP_HIDE_FROM_ABI deque(size_type __n, const value_type& __v);
615632
616633 template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0>
617634 _LIBCPP_HIDE_FROM_ABI deque(size_type __n, const value_type& __v, const allocator_type& __a)
618 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {
635 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) {
619636 __annotate_new(0);
620637 if (__n > 0)
621638 __append(__n, __v);
......@@ -626,10 +643,10 @@ public:
626643 template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
627644 _LIBCPP_HIDE_FROM_ABI deque(_InputIter __f, _InputIter __l, const allocator_type& __a);
628645
629#if _LIBCPP_STD_VER >= 23
646# if _LIBCPP_STD_VER >= 23
630647 template <_ContainerCompatibleRange<_Tp> _Range>
631648 _LIBCPP_HIDE_FROM_ABI deque(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
632 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {
649 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) {
633650 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
634651 __append_with_size(ranges::begin(__range), ranges::distance(__range));
635652
......@@ -639,14 +656,14 @@ public:
639656 }
640657 }
641658 }
642#endif
659# endif
643660
644661 _LIBCPP_HIDE_FROM_ABI deque(const deque& __c);
645662 _LIBCPP_HIDE_FROM_ABI deque(const deque& __c, const __type_identity_t<allocator_type>& __a);
646663
647664 _LIBCPP_HIDE_FROM_ABI deque& operator=(const deque& __c);
648665
649#ifndef _LIBCPP_CXX03_LANG
666# ifndef _LIBCPP_CXX03_LANG
650667 _LIBCPP_HIDE_FROM_ABI deque(initializer_list<value_type> __il);
651668 _LIBCPP_HIDE_FROM_ABI deque(initializer_list<value_type> __il, const allocator_type& __a);
652669
......@@ -662,7 +679,7 @@ public:
662679 is_nothrow_move_assignable<allocator_type>::value);
663680
664681 _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<value_type> __il) { assign(__il.begin(), __il.end()); }
665#endif // _LIBCPP_CXX03_LANG
682# endif // _LIBCPP_CXX03_LANG
666683
667684 template <class _InputIter,
668685 __enable_if_t<__has_input_iterator_category<_InputIter>::value &&
......@@ -672,7 +689,7 @@ public:
672689 template <class _RAIter, __enable_if_t<__has_random_access_iterator_category<_RAIter>::value, int> = 0>
673690 _LIBCPP_HIDE_FROM_ABI void assign(_RAIter __f, _RAIter __l);
674691
675#if _LIBCPP_STD_VER >= 23
692# if _LIBCPP_STD_VER >= 23
676693 template <_ContainerCompatibleRange<_Tp> _Range>
677694 _LIBCPP_HIDE_FROM_ABI void assign_range(_Range&& __range) {
678695 if constexpr (ranges::random_access_range<_Range>) {
......@@ -687,13 +704,13 @@ public:
687704 __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
688705 }
689706 }
690#endif
707# endif
691708
692709 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const value_type& __v);
693710
694711 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT;
695 _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return __size_.second(); }
696 _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { return __size_.second(); }
712 _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return __alloc_; }
713 _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { return __alloc_; }
697714
698715 // iterators:
699716
......@@ -732,8 +749,8 @@ public:
732749 // capacity:
733750 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size(); }
734751
735 _LIBCPP_HIDE_FROM_ABI size_type& __size() _NOEXCEPT { return __size_.first(); }
736 _LIBCPP_HIDE_FROM_ABI const size_type& __size() const _NOEXCEPT { return __size_.first(); }
752 _LIBCPP_HIDE_FROM_ABI size_type& __size() _NOEXCEPT { return __size_; }
753 _LIBCPP_HIDE_FROM_ABI const size_type& __size() const _NOEXCEPT { return __size_; }
737754
738755 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
739756 return std::min<size_type>(__alloc_traits::max_size(__alloc()), numeric_limits<difference_type>::max());
......@@ -741,7 +758,7 @@ public:
741758 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n);
742759 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n, const value_type& __v);
743760 _LIBCPP_HIDE_FROM_ABI void shrink_to_fit() _NOEXCEPT;
744 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return size() == 0; }
761 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return size() == 0; }
745762
746763 // element access:
747764 _LIBCPP_HIDE_FROM_ABI reference operator[](size_type __i) _NOEXCEPT;
......@@ -756,25 +773,25 @@ public:
756773 // 23.2.2.3 modifiers:
757774 _LIBCPP_HIDE_FROM_ABI void push_front(const value_type& __v);
758775 _LIBCPP_HIDE_FROM_ABI void push_back(const value_type& __v);
759#ifndef _LIBCPP_CXX03_LANG
760# if _LIBCPP_STD_VER >= 17
776# ifndef _LIBCPP_CXX03_LANG
777# if _LIBCPP_STD_VER >= 17
761778 template <class... _Args>
762779 _LIBCPP_HIDE_FROM_ABI reference emplace_front(_Args&&... __args);
763780 template <class... _Args>
764781 _LIBCPP_HIDE_FROM_ABI reference emplace_back(_Args&&... __args);
765# else
782# else
766783 template <class... _Args>
767784 _LIBCPP_HIDE_FROM_ABI void emplace_front(_Args&&... __args);
768785 template <class... _Args>
769786 _LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args);
770# endif
787# endif
771788 template <class... _Args>
772789 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __p, _Args&&... __args);
773790
774791 _LIBCPP_HIDE_FROM_ABI void push_front(value_type&& __v);
775792 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __v);
776793
777# if _LIBCPP_STD_VER >= 23
794# if _LIBCPP_STD_VER >= 23
778795 template <_ContainerCompatibleRange<_Tp> _Range>
779796 _LIBCPP_HIDE_FROM_ABI void prepend_range(_Range&& __range) {
780797 insert_range(begin(), std::forward<_Range>(__range));
......@@ -784,14 +801,14 @@ public:
784801 _LIBCPP_HIDE_FROM_ABI void append_range(_Range&& __range) {
785802 insert_range(end(), std::forward<_Range>(__range));
786803 }
787# endif
804# endif
788805
789806 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v);
790807
791808 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, initializer_list<value_type> __il) {
792809 return insert(__p, __il.begin(), __il.end());
793810 }
794#endif // _LIBCPP_CXX03_LANG
811# endif // _LIBCPP_CXX03_LANG
795812 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v);
796813 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, size_type __n, const value_type& __v);
797814 template <class _InputIter, __enable_if_t<__has_exactly_input_iterator_category<_InputIter>::value, int> = 0>
......@@ -802,7 +819,7 @@ public:
802819 template <class _BiIter, __enable_if_t<__has_bidirectional_iterator_category<_BiIter>::value, int> = 0>
803820 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, _BiIter __f, _BiIter __l);
804821
805#if _LIBCPP_STD_VER >= 23
822# if _LIBCPP_STD_VER >= 23
806823 template <_ContainerCompatibleRange<_Tp> _Range>
807824 _LIBCPP_HIDE_FROM_ABI iterator insert_range(const_iterator __position, _Range&& __range) {
808825 if constexpr (ranges::bidirectional_range<_Range>) {
......@@ -817,7 +834,7 @@ public:
817834 return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
818835 }
819836 }
820#endif
837# endif
821838
822839 _LIBCPP_HIDE_FROM_ABI void pop_front();
823840 _LIBCPP_HIDE_FROM_ABI void pop_back();
......@@ -825,11 +842,11 @@ public:
825842 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l);
826843
827844 _LIBCPP_HIDE_FROM_ABI void swap(deque& __c)
828#if _LIBCPP_STD_VER >= 14
845# if _LIBCPP_STD_VER >= 14
829846 _NOEXCEPT;
830#else
847# else
831848 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>);
832#endif
849# endif
833850 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT;
834851
835852 _LIBCPP_HIDE_FROM_ABI bool __invariants() const {
......@@ -907,7 +924,7 @@ private:
907924 (void)__end;
908925 (void)__annotation_type;
909926 (void)__place;
910#ifndef _LIBCPP_HAS_NO_ASAN
927# if _LIBCPP_HAS_ASAN
911928 // __beg - index of the first item to annotate
912929 // __end - index behind the last item to annotate (so last item + 1)
913930 // __annotation_type - __asan_unposion or __asan_poison
......@@ -1000,23 +1017,23 @@ private:
10001017 std::__annotate_double_ended_contiguous_container<_Allocator>(
10011018 __mem_beg, __mem_end, __old_beg, __old_end, __new_beg, __new_end);
10021019 }
1003#endif // !_LIBCPP_HAS_NO_ASAN
1020# endif // _LIBCPP_HAS_ASAN
10041021 }
10051022
10061023 _LIBCPP_HIDE_FROM_ABI void __annotate_new(size_type __current_size) const _NOEXCEPT {
10071024 (void)__current_size;
1008#ifndef _LIBCPP_HAS_NO_ASAN
1025# if _LIBCPP_HAS_ASAN
10091026 if (__current_size == 0)
10101027 __annotate_from_to(0, __map_.size() * __block_size, __asan_poison, __asan_back_moved);
10111028 else {
10121029 __annotate_from_to(0, __start_, __asan_poison, __asan_front_moved);
10131030 __annotate_from_to(__start_ + __current_size, __map_.size() * __block_size, __asan_poison, __asan_back_moved);
10141031 }
1015#endif
1032# endif // _LIBCPP_HAS_ASAN
10161033 }
10171034
10181035 _LIBCPP_HIDE_FROM_ABI void __annotate_delete() const _NOEXCEPT {
1019#ifndef _LIBCPP_HAS_NO_ASAN
1036# if _LIBCPP_HAS_ASAN
10201037 if (empty()) {
10211038 for (size_t __i = 0; __i < __map_.size(); ++__i) {
10221039 __annotate_whole_block(__i, __asan_unposion);
......@@ -1025,37 +1042,37 @@ private:
10251042 __annotate_from_to(0, __start_, __asan_unposion, __asan_front_moved);
10261043 __annotate_from_to(__start_ + size(), __map_.size() * __block_size, __asan_unposion, __asan_back_moved);
10271044 }
1028#endif
1045# endif // _LIBCPP_HAS_ASAN
10291046 }
10301047
10311048 _LIBCPP_HIDE_FROM_ABI void __annotate_increase_front(size_type __n) const _NOEXCEPT {
10321049 (void)__n;
1033#ifndef _LIBCPP_HAS_NO_ASAN
1050# if _LIBCPP_HAS_ASAN
10341051 __annotate_from_to(__start_ - __n, __start_, __asan_unposion, __asan_front_moved);
1035#endif
1052# endif
10361053 }
10371054
10381055 _LIBCPP_HIDE_FROM_ABI void __annotate_increase_back(size_type __n) const _NOEXCEPT {
10391056 (void)__n;
1040#ifndef _LIBCPP_HAS_NO_ASAN
1057# if _LIBCPP_HAS_ASAN
10411058 __annotate_from_to(__start_ + size(), __start_ + size() + __n, __asan_unposion, __asan_back_moved);
1042#endif
1059# endif
10431060 }
10441061
10451062 _LIBCPP_HIDE_FROM_ABI void __annotate_shrink_front(size_type __old_size, size_type __old_start) const _NOEXCEPT {
10461063 (void)__old_size;
10471064 (void)__old_start;
1048#ifndef _LIBCPP_HAS_NO_ASAN
1065# if _LIBCPP_HAS_ASAN
10491066 __annotate_from_to(__old_start, __old_start + (__old_size - size()), __asan_poison, __asan_front_moved);
1050#endif
1067# endif
10511068 }
10521069
10531070 _LIBCPP_HIDE_FROM_ABI void __annotate_shrink_back(size_type __old_size, size_type __old_start) const _NOEXCEPT {
10541071 (void)__old_size;
10551072 (void)__old_start;
1056#ifndef _LIBCPP_HAS_NO_ASAN
1073# if _LIBCPP_HAS_ASAN
10571074 __annotate_from_to(__old_start + size(), __old_start + __old_size, __asan_poison, __asan_back_moved);
1058#endif
1075# endif
10591076 }
10601077
10611078 _LIBCPP_HIDE_FROM_ABI void __annotate_poison_block(const void* __beginning, const void* __end) const _NOEXCEPT {
......@@ -1066,7 +1083,7 @@ private:
10661083 __annotate_whole_block(size_t __block_index, __asan_annotation_type __annotation_type) const _NOEXCEPT {
10671084 (void)__block_index;
10681085 (void)__annotation_type;
1069#ifndef _LIBCPP_HAS_NO_ASAN
1086# if _LIBCPP_HAS_ASAN
10701087 __map_const_iterator __block_it = __map_.begin() + __block_index;
10711088 const void* __block_start = std::__to_address(*__block_it);
10721089 const void* __block_end = std::__to_address(*__block_it + __block_size);
......@@ -1077,9 +1094,9 @@ private:
10771094 std::__annotate_double_ended_contiguous_container<_Allocator>(
10781095 __block_start, __block_end, __block_start, __block_start, __block_start, __block_end);
10791096 }
1080#endif
1097# endif
10811098 }
1082#if !defined(_LIBCPP_HAS_NO_ASAN)
1099# if _LIBCPP_HAS_ASAN
10831100
10841101public:
10851102 _LIBCPP_HIDE_FROM_ABI bool __verify_asan_annotations() const _NOEXCEPT {
......@@ -1141,7 +1158,7 @@ public:
11411158 }
11421159
11431160private:
1144#endif // _LIBCPP_VERIFY_ASAN_DEQUE_ANNOTATIONS
1161# endif // _LIBCPP_HAS_ASAN
11451162 _LIBCPP_HIDE_FROM_ABI bool __maybe_remove_front_spare(bool __keep_one = true) {
11461163 if (__front_spare_blocks() >= 2 || (!__keep_one && __front_spare_blocks())) {
11471164 __annotate_whole_block(0, __asan_unposion);
......@@ -1216,8 +1233,8 @@ private:
12161233 clear();
12171234 shrink_to_fit();
12181235 }
1219 __alloc() = __c.__alloc();
1220 __map_.__alloc() = __c.__map_.__alloc();
1236 __alloc() = __c.__alloc();
1237 __map_.__alloc_ = __c.__map_.__alloc_;
12211238 }
12221239
12231240 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const deque&, false_type) {}
......@@ -1231,7 +1248,7 @@ template <class _Tp, class _Alloc>
12311248_LIBCPP_CONSTEXPR const typename allocator_traits<_Alloc>::difference_type deque<_Tp, _Alloc>::__block_size =
12321249 __deque_block_size<value_type, difference_type>::value;
12331250
1234#if _LIBCPP_STD_VER >= 17
1251# if _LIBCPP_STD_VER >= 17
12351252template <class _InputIterator,
12361253 class _Alloc = allocator<__iter_value_type<_InputIterator>>,
12371254 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
......@@ -1243,34 +1260,34 @@ template <class _InputIterator,
12431260 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
12441261 class = enable_if_t<__is_allocator<_Alloc>::value> >
12451262deque(_InputIterator, _InputIterator, _Alloc) -> deque<__iter_value_type<_InputIterator>, _Alloc>;
1246#endif
1263# endif
12471264
1248#if _LIBCPP_STD_VER >= 23
1265# if _LIBCPP_STD_VER >= 23
12491266template <ranges::input_range _Range,
12501267 class _Alloc = allocator<ranges::range_value_t<_Range>>,
12511268 class = enable_if_t<__is_allocator<_Alloc>::value> >
12521269deque(from_range_t, _Range&&, _Alloc = _Alloc()) -> deque<ranges::range_value_t<_Range>, _Alloc>;
1253#endif
1270# endif
12541271
12551272template <class _Tp, class _Allocator>
1256deque<_Tp, _Allocator>::deque(size_type __n) : __start_(0), __size_(0, __default_init_tag()) {
1273deque<_Tp, _Allocator>::deque(size_type __n) : __start_(0), __size_(0) {
12571274 __annotate_new(0);
12581275 if (__n > 0)
12591276 __append(__n);
12601277}
12611278
1262#if _LIBCPP_STD_VER >= 14
1279# if _LIBCPP_STD_VER >= 14
12631280template <class _Tp, class _Allocator>
12641281deque<_Tp, _Allocator>::deque(size_type __n, const _Allocator& __a)
1265 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {
1282 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) {
12661283 __annotate_new(0);
12671284 if (__n > 0)
12681285 __append(__n);
12691286}
1270#endif
1287# endif
12711288
12721289template <class _Tp, class _Allocator>
1273deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v) : __start_(0), __size_(0, __default_init_tag()) {
1290deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v) : __start_(0), __size_(0) {
12741291 __annotate_new(0);
12751292 if (__n > 0)
12761293 __append(__n, __v);
......@@ -1278,7 +1295,7 @@ deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v) : __start_(0
12781295
12791296template <class _Tp, class _Allocator>
12801297template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> >
1281deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l) : __start_(0), __size_(0, __default_init_tag()) {
1298deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l) : __start_(0), __size_(0) {
12821299 __annotate_new(0);
12831300 __append(__f, __l);
12841301}
......@@ -1286,7 +1303,7 @@ deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l) : __start_(0), __s
12861303template <class _Tp, class _Allocator>
12871304template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> >
12881305deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a)
1289 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {
1306 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) {
12901307 __annotate_new(0);
12911308 __append(__f, __l);
12921309}
......@@ -1295,14 +1312,15 @@ template <class _Tp, class _Allocator>
12951312deque<_Tp, _Allocator>::deque(const deque& __c)
12961313 : __map_(__pointer_allocator(__alloc_traits::select_on_container_copy_construction(__c.__alloc()))),
12971314 __start_(0),
1298 __size_(0, __map_.__alloc()) {
1315 __size_(0),
1316 __alloc_(__map_.__alloc_) {
12991317 __annotate_new(0);
13001318 __append(__c.begin(), __c.end());
13011319}
13021320
13031321template <class _Tp, class _Allocator>
13041322deque<_Tp, _Allocator>::deque(const deque& __c, const __type_identity_t<allocator_type>& __a)
1305 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {
1323 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) {
13061324 __annotate_new(0);
13071325 __append(__c.begin(), __c.end());
13081326}
......@@ -1316,24 +1334,27 @@ deque<_Tp, _Allocator>& deque<_Tp, _Allocator>::operator=(const deque& __c) {
13161334 return *this;
13171335}
13181336
1319#ifndef _LIBCPP_CXX03_LANG
1337# ifndef _LIBCPP_CXX03_LANG
13201338
13211339template <class _Tp, class _Allocator>
1322deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il) : __start_(0), __size_(0, __default_init_tag()) {
1340deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il) : __start_(0), __size_(0) {
13231341 __annotate_new(0);
13241342 __append(__il.begin(), __il.end());
13251343}
13261344
13271345template <class _Tp, class _Allocator>
13281346deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il, const allocator_type& __a)
1329 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {
1347 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0), __alloc_(__a) {
13301348 __annotate_new(0);
13311349 __append(__il.begin(), __il.end());
13321350}
13331351
13341352template <class _Tp, class _Allocator>
13351353inline deque<_Tp, _Allocator>::deque(deque&& __c) noexcept(is_nothrow_move_constructible<allocator_type>::value)
1336 : __map_(std::move(__c.__map_)), __start_(std::move(__c.__start_)), __size_(std::move(__c.__size_)) {
1354 : __map_(std::move(__c.__map_)),
1355 __start_(std::move(__c.__start_)),
1356 __size_(std::move(__c.__size_)),
1357 __alloc_(std::move(__c.__alloc_)) {
13371358 __c.__start_ = 0;
13381359 __c.__size() = 0;
13391360}
......@@ -1342,7 +1363,8 @@ template <class _Tp, class _Allocator>
13421363inline deque<_Tp, _Allocator>::deque(deque&& __c, const __type_identity_t<allocator_type>& __a)
13431364 : __map_(std::move(__c.__map_), __pointer_allocator(__a)),
13441365 __start_(std::move(__c.__start_)),
1345 __size_(std::move(__c.__size()), __a) {
1366 __size_(std::move(__c.__size_)),
1367 __alloc_(__a) {
13461368 if (__a == __c.__alloc()) {
13471369 __c.__start_ = 0;
13481370 __c.__size() = 0;
......@@ -1380,7 +1402,7 @@ void deque<_Tp, _Allocator>::__move_assign(deque& __c,
13801402 __move_assign(__c);
13811403}
13821404
1383#endif // _LIBCPP_CXX03_LANG
1405# endif // _LIBCPP_CXX03_LANG
13841406
13851407template <class _Tp, class _Allocator>
13861408template <class _InputIter,
......@@ -1568,7 +1590,7 @@ void deque<_Tp, _Allocator>::push_front(const value_type& __v) {
15681590 ++__size();
15691591}
15701592
1571#ifndef _LIBCPP_CXX03_LANG
1593# ifndef _LIBCPP_CXX03_LANG
15721594template <class _Tp, class _Allocator>
15731595void deque<_Tp, _Allocator>::push_back(value_type&& __v) {
15741596 allocator_type& __a = __alloc();
......@@ -1582,11 +1604,11 @@ void deque<_Tp, _Allocator>::push_back(value_type&& __v) {
15821604
15831605template <class _Tp, class _Allocator>
15841606template <class... _Args>
1585# if _LIBCPP_STD_VER >= 17
1607# if _LIBCPP_STD_VER >= 17
15861608typename deque<_Tp, _Allocator>::reference
1587# else
1609# else
15881610void
1589# endif
1611# endif
15901612deque<_Tp, _Allocator>::emplace_back(_Args&&... __args) {
15911613 allocator_type& __a = __alloc();
15921614 if (__back_spare() == 0)
......@@ -1595,9 +1617,9 @@ deque<_Tp, _Allocator>::emplace_back(_Args&&... __args) {
15951617 __annotate_increase_back(1);
15961618 __alloc_traits::construct(__a, std::addressof(*end()), std::forward<_Args>(__args)...);
15971619 ++__size();
1598# if _LIBCPP_STD_VER >= 17
1620# if _LIBCPP_STD_VER >= 17
15991621 return *--end();
1600# endif
1622# endif
16011623}
16021624
16031625template <class _Tp, class _Allocator>
......@@ -1614,11 +1636,11 @@ void deque<_Tp, _Allocator>::push_front(value_type&& __v) {
16141636
16151637template <class _Tp, class _Allocator>
16161638template <class... _Args>
1617# if _LIBCPP_STD_VER >= 17
1639# if _LIBCPP_STD_VER >= 17
16181640typename deque<_Tp, _Allocator>::reference
1619# else
1641# else
16201642void
1621# endif
1643# endif
16221644deque<_Tp, _Allocator>::emplace_front(_Args&&... __args) {
16231645 allocator_type& __a = __alloc();
16241646 if (__front_spare() == 0)
......@@ -1628,9 +1650,9 @@ deque<_Tp, _Allocator>::emplace_front(_Args&&... __args) {
16281650 __alloc_traits::construct(__a, std::addressof(*--begin()), std::forward<_Args>(__args)...);
16291651 --__start_;
16301652 ++__size();
1631# if _LIBCPP_STD_VER >= 17
1653# if _LIBCPP_STD_VER >= 17
16321654 return *begin();
1633# endif
1655# endif
16341656}
16351657
16361658template <class _Tp, class _Allocator>
......@@ -1728,7 +1750,7 @@ typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::emplace(const_
17281750 return begin() + __pos;
17291751}
17301752
1731#endif // _LIBCPP_CXX03_LANG
1753# endif // _LIBCPP_CXX03_LANG
17321754
17331755template <class _Tp, class _Allocator>
17341756typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v) {
......@@ -1951,11 +1973,11 @@ template <class _Tp, class _Allocator>
19511973template <class _InputIterator, class _Sentinel>
19521974_LIBCPP_HIDE_FROM_ABI void deque<_Tp, _Allocator>::__append_with_sentinel(_InputIterator __f, _Sentinel __l) {
19531975 for (; __f != __l; ++__f)
1954#ifdef _LIBCPP_CXX03_LANG
1976# ifdef _LIBCPP_CXX03_LANG
19551977 push_back(*__f);
1956#else
1978# else
19571979 emplace_back(*__f);
1958#endif
1980# endif
19591981}
19601982
19611983template <class _Tp, class _Allocator>
......@@ -2023,39 +2045,39 @@ void deque<_Tp, _Allocator>::__add_front_capacity() {
20232045 __start_ += __block_size;
20242046 pointer __pt = __map_.back();
20252047 __map_.pop_back();
2026 __map_.push_front(__pt);
2048 __map_.emplace_front(__pt);
20272049 }
20282050 // Else if __map_.size() < __map_.capacity() then we need to allocate 1 buffer
20292051 else if (__map_.size() < __map_.capacity()) { // we can put the new buffer into the map, but don't shift things around
20302052 // until all buffers are allocated. If we throw, we don't need to fix
20312053 // anything up (any added buffers are undetectible)
20322054 if (__map_.__front_spare() > 0)
2033 __map_.push_front(__alloc_traits::allocate(__a, __block_size));
2055 __map_.emplace_front(__alloc_traits::allocate(__a, __block_size));
20342056 else {
2035 __map_.push_back(__alloc_traits::allocate(__a, __block_size));
2057 __map_.emplace_back(__alloc_traits::allocate(__a, __block_size));
20362058 // Done allocating, reorder capacity
20372059 pointer __pt = __map_.back();
20382060 __map_.pop_back();
2039 __map_.push_front(__pt);
2061 __map_.emplace_front(__pt);
20402062 }
20412063 __start_ = __map_.size() == 1 ? __block_size / 2 : __start_ + __block_size;
20422064 }
20432065 // Else need to allocate 1 buffer, *and* we need to reallocate __map_.
20442066 else {
20452067 __split_buffer<pointer, __pointer_allocator&> __buf(
2046 std::max<size_type>(2 * __map_.capacity(), 1), 0, __map_.__alloc());
2068 std::max<size_type>(2 * __map_.capacity(), 1), 0, __map_.__alloc_);
20472069
20482070 typedef __allocator_destructor<_Allocator> _Dp;
20492071 unique_ptr<pointer, _Dp> __hold(__alloc_traits::allocate(__a, __block_size), _Dp(__a, __block_size));
2050 __buf.push_back(__hold.get());
2072 __buf.emplace_back(__hold.get());
20512073 __hold.release();
20522074
20532075 for (__map_pointer __i = __map_.begin(); __i != __map_.end(); ++__i)
2054 __buf.push_back(*__i);
2076 __buf.emplace_back(*__i);
20552077 std::swap(__map_.__first_, __buf.__first_);
20562078 std::swap(__map_.__begin_, __buf.__begin_);
20572079 std::swap(__map_.__end_, __buf.__end_);
2058 std::swap(__map_.__end_cap(), __buf.__end_cap());
2080 std::swap(__map_.__cap_, __buf.__cap_);
20592081 __start_ = __map_.size() == 1 ? __block_size / 2 : __start_ + __block_size;
20602082 }
20612083 __annotate_whole_block(0, __asan_poison);
......@@ -2077,7 +2099,7 @@ void deque<_Tp, _Allocator>::__add_front_capacity(size_type __n) {
20772099 for (; __back_capacity > 0; --__back_capacity) {
20782100 pointer __pt = __map_.back();
20792101 __map_.pop_back();
2080 __map_.push_front(__pt);
2102 __map_.emplace_front(__pt);
20812103 }
20822104 }
20832105 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
......@@ -2088,17 +2110,17 @@ void deque<_Tp, _Allocator>::__add_front_capacity(size_type __n) {
20882110 for (; __nb > 0; --__nb, __start_ += __block_size - (__map_.size() == 1)) {
20892111 if (__map_.__front_spare() == 0)
20902112 break;
2091 __map_.push_front(__alloc_traits::allocate(__a, __block_size));
2113 __map_.emplace_front(__alloc_traits::allocate(__a, __block_size));
20922114 __annotate_whole_block(0, __asan_poison);
20932115 }
20942116 for (; __nb > 0; --__nb, ++__back_capacity)
2095 __map_.push_back(__alloc_traits::allocate(__a, __block_size));
2117 __map_.emplace_back(__alloc_traits::allocate(__a, __block_size));
20962118 // Done allocating, reorder capacity
20972119 __start_ += __back_capacity * __block_size;
20982120 for (; __back_capacity > 0; --__back_capacity) {
20992121 pointer __pt = __map_.back();
21002122 __map_.pop_back();
2101 __map_.push_front(__pt);
2123 __map_.emplace_front(__pt);
21022124 __annotate_whole_block(0, __asan_poison);
21032125 }
21042126 }
......@@ -2106,33 +2128,33 @@ void deque<_Tp, _Allocator>::__add_front_capacity(size_type __n) {
21062128 else {
21072129 size_type __ds = (__nb + __back_capacity) * __block_size - __map_.empty();
21082130 __split_buffer<pointer, __pointer_allocator&> __buf(
2109 std::max<size_type>(2 * __map_.capacity(), __nb + __map_.size()), 0, __map_.__alloc());
2110#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2131 std::max<size_type>(2 * __map_.capacity(), __nb + __map_.size()), 0, __map_.__alloc_);
2132# if _LIBCPP_HAS_EXCEPTIONS
21112133 try {
2112#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2134# endif // _LIBCPP_HAS_EXCEPTIONS
21132135 for (; __nb > 0; --__nb) {
2114 __buf.push_back(__alloc_traits::allocate(__a, __block_size));
2136 __buf.emplace_back(__alloc_traits::allocate(__a, __block_size));
21152137 // ASan: this is empty container, we have to poison whole block
21162138 __annotate_poison_block(std::__to_address(__buf.back()), std::__to_address(__buf.back() + __block_size));
21172139 }
2118#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2140# if _LIBCPP_HAS_EXCEPTIONS
21192141 } catch (...) {
21202142 __annotate_delete();
21212143 for (__map_pointer __i = __buf.begin(); __i != __buf.end(); ++__i)
21222144 __alloc_traits::deallocate(__a, *__i, __block_size);
21232145 throw;
21242146 }
2125#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2147# endif // _LIBCPP_HAS_EXCEPTIONS
21262148 for (; __back_capacity > 0; --__back_capacity) {
2127 __buf.push_back(__map_.back());
2149 __buf.emplace_back(__map_.back());
21282150 __map_.pop_back();
21292151 }
21302152 for (__map_pointer __i = __map_.begin(); __i != __map_.end(); ++__i)
2131 __buf.push_back(*__i);
2153 __buf.emplace_back(*__i);
21322154 std::swap(__map_.__first_, __buf.__first_);
21332155 std::swap(__map_.__begin_, __buf.__begin_);
21342156 std::swap(__map_.__end_, __buf.__end_);
2135 std::swap(__map_.__end_cap(), __buf.__end_cap());
2157 std::swap(__map_.__cap_, __buf.__cap_);
21362158 __start_ += __ds;
21372159 }
21382160}
......@@ -2146,39 +2168,39 @@ void deque<_Tp, _Allocator>::__add_back_capacity() {
21462168 __start_ -= __block_size;
21472169 pointer __pt = __map_.front();
21482170 __map_.pop_front();
2149 __map_.push_back(__pt);
2171 __map_.emplace_back(__pt);
21502172 }
21512173 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
21522174 else if (__map_.size() < __map_.capacity()) { // we can put the new buffer into the map, but don't shift things around
21532175 // until it is allocated. If we throw, we don't need to fix
21542176 // anything up (any added buffers are undetectible)
21552177 if (__map_.__back_spare() != 0)
2156 __map_.push_back(__alloc_traits::allocate(__a, __block_size));
2178 __map_.emplace_back(__alloc_traits::allocate(__a, __block_size));
21572179 else {
2158 __map_.push_front(__alloc_traits::allocate(__a, __block_size));
2180 __map_.emplace_front(__alloc_traits::allocate(__a, __block_size));
21592181 // Done allocating, reorder capacity
21602182 pointer __pt = __map_.front();
21612183 __map_.pop_front();
2162 __map_.push_back(__pt);
2184 __map_.emplace_back(__pt);
21632185 }
21642186 __annotate_whole_block(__map_.size() - 1, __asan_poison);
21652187 }
21662188 // Else need to allocate 1 buffer, *and* we need to reallocate __map_.
21672189 else {
21682190 __split_buffer<pointer, __pointer_allocator&> __buf(
2169 std::max<size_type>(2 * __map_.capacity(), 1), __map_.size(), __map_.__alloc());
2191 std::max<size_type>(2 * __map_.capacity(), 1), __map_.size(), __map_.__alloc_);
21702192
21712193 typedef __allocator_destructor<_Allocator> _Dp;
21722194 unique_ptr<pointer, _Dp> __hold(__alloc_traits::allocate(__a, __block_size), _Dp(__a, __block_size));
2173 __buf.push_back(__hold.get());
2195 __buf.emplace_back(__hold.get());
21742196 __hold.release();
21752197
21762198 for (__map_pointer __i = __map_.end(); __i != __map_.begin();)
2177 __buf.push_front(*--__i);
2199 __buf.emplace_front(*--__i);
21782200 std::swap(__map_.__first_, __buf.__first_);
21792201 std::swap(__map_.__begin_, __buf.__begin_);
21802202 std::swap(__map_.__end_, __buf.__end_);
2181 std::swap(__map_.__end_cap(), __buf.__end_cap());
2203 std::swap(__map_.__cap_, __buf.__cap_);
21822204 __annotate_whole_block(__map_.size() - 1, __asan_poison);
21832205 }
21842206}
......@@ -2199,7 +2221,7 @@ void deque<_Tp, _Allocator>::__add_back_capacity(size_type __n) {
21992221 for (; __front_capacity > 0; --__front_capacity) {
22002222 pointer __pt = __map_.front();
22012223 __map_.pop_front();
2202 __map_.push_back(__pt);
2224 __map_.emplace_back(__pt);
22032225 }
22042226 }
22052227 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
......@@ -2210,11 +2232,11 @@ void deque<_Tp, _Allocator>::__add_back_capacity(size_type __n) {
22102232 for (; __nb > 0; --__nb) {
22112233 if (__map_.__back_spare() == 0)
22122234 break;
2213 __map_.push_back(__alloc_traits::allocate(__a, __block_size));
2235 __map_.emplace_back(__alloc_traits::allocate(__a, __block_size));
22142236 __annotate_whole_block(__map_.size() - 1, __asan_poison);
22152237 }
22162238 for (; __nb > 0; --__nb, ++__front_capacity, __start_ += __block_size - (__map_.size() == 1)) {
2217 __map_.push_front(__alloc_traits::allocate(__a, __block_size));
2239 __map_.emplace_front(__alloc_traits::allocate(__a, __block_size));
22182240 __annotate_whole_block(0, __asan_poison);
22192241 }
22202242 // Done allocating, reorder capacity
......@@ -2222,7 +2244,7 @@ void deque<_Tp, _Allocator>::__add_back_capacity(size_type __n) {
22222244 for (; __front_capacity > 0; --__front_capacity) {
22232245 pointer __pt = __map_.front();
22242246 __map_.pop_front();
2225 __map_.push_back(__pt);
2247 __map_.emplace_back(__pt);
22262248 }
22272249 }
22282250 // Else need to allocate __nb buffers, *and* we need to reallocate __map_.
......@@ -2231,33 +2253,33 @@ void deque<_Tp, _Allocator>::__add_back_capacity(size_type __n) {
22312253 __split_buffer<pointer, __pointer_allocator&> __buf(
22322254 std::max<size_type>(2 * __map_.capacity(), __nb + __map_.size()),
22332255 __map_.size() - __front_capacity,
2234 __map_.__alloc());
2235#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2256 __map_.__alloc_);
2257# if _LIBCPP_HAS_EXCEPTIONS
22362258 try {
2237#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2259# endif // _LIBCPP_HAS_EXCEPTIONS
22382260 for (; __nb > 0; --__nb) {
2239 __buf.push_back(__alloc_traits::allocate(__a, __block_size));
2261 __buf.emplace_back(__alloc_traits::allocate(__a, __block_size));
22402262 // ASan: this is an empty container, we have to poison the whole block
22412263 __annotate_poison_block(std::__to_address(__buf.back()), std::__to_address(__buf.back() + __block_size));
22422264 }
2243#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2265# if _LIBCPP_HAS_EXCEPTIONS
22442266 } catch (...) {
22452267 __annotate_delete();
22462268 for (__map_pointer __i = __buf.begin(); __i != __buf.end(); ++__i)
22472269 __alloc_traits::deallocate(__a, *__i, __block_size);
22482270 throw;
22492271 }
2250#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2272# endif // _LIBCPP_HAS_EXCEPTIONS
22512273 for (; __front_capacity > 0; --__front_capacity) {
2252 __buf.push_back(__map_.front());
2274 __buf.emplace_back(__map_.front());
22532275 __map_.pop_front();
22542276 }
22552277 for (__map_pointer __i = __map_.end(); __i != __map_.begin();)
2256 __buf.push_front(*--__i);
2278 __buf.emplace_front(*--__i);
22572279 std::swap(__map_.__first_, __buf.__first_);
22582280 std::swap(__map_.__begin_, __buf.__begin_);
22592281 std::swap(__map_.__end_, __buf.__end_);
2260 std::swap(__map_.__end_cap(), __buf.__end_cap());
2282 std::swap(__map_.__cap_, __buf.__cap_);
22612283 __start_ -= __ds;
22622284 }
22632285}
......@@ -2413,7 +2435,7 @@ typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::erase(const_it
24132435 difference_type __pos = __f - __b;
24142436 iterator __p = __b + __pos;
24152437 allocator_type& __a = __alloc();
2416 if (static_cast<size_t>(__pos) <= (size() - 1) / 2) { // erase from front
2438 if (static_cast<size_type>(__pos) <= (size() - 1) / 2) { // erase from front
24172439 std::move_backward(__b, __p, std::next(__p));
24182440 __alloc_traits::destroy(__a, std::addressof(*__b));
24192441 --__size();
......@@ -2441,7 +2463,7 @@ typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::erase(const_it
24412463 iterator __p = __b + __pos;
24422464 if (__n > 0) {
24432465 allocator_type& __a = __alloc();
2444 if (static_cast<size_t>(__pos) <= (size() - __n) / 2) { // erase from front
2466 if (static_cast<size_type>(__pos) <= (size() - __n) / 2) { // erase from front
24452467 iterator __i = std::move_backward(__b, __p, __p + __n);
24462468 for (; __b != __i; ++__b)
24472469 __alloc_traits::destroy(__a, std::addressof(*__b));
......@@ -2484,11 +2506,11 @@ void deque<_Tp, _Allocator>::__erase_to_end(const_iterator __f) {
24842506
24852507template <class _Tp, class _Allocator>
24862508inline void deque<_Tp, _Allocator>::swap(deque& __c)
2487#if _LIBCPP_STD_VER >= 14
2509# if _LIBCPP_STD_VER >= 14
24882510 _NOEXCEPT
2489#else
2511# else
24902512 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>)
2491#endif
2513# endif
24922514{
24932515 __map_.swap(__c.__map_);
24942516 std::swap(__start_, __c.__start_);
......@@ -2524,7 +2546,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator==(const deque<_Tp, _Allocator>& __x,
25242546 return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
25252547}
25262548
2527#if _LIBCPP_STD_VER <= 17
2549# if _LIBCPP_STD_VER <= 17
25282550
25292551template <class _Tp, class _Allocator>
25302552inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) {
......@@ -2551,7 +2573,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const deque<_Tp, _Allocator>& __x,
25512573 return !(__y < __x);
25522574}
25532575
2554#else // _LIBCPP_STD_VER <= 17
2576# else // _LIBCPP_STD_VER <= 17
25552577
25562578template <class _Tp, class _Allocator>
25572579_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Tp>
......@@ -2559,7 +2581,7 @@ operator<=>(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y
25592581 return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
25602582}
25612583
2562#endif // _LIBCPP_STD_VER <= 17
2584# endif // _LIBCPP_STD_VER <= 17
25632585
25642586template <class _Tp, class _Allocator>
25652587inline _LIBCPP_HIDE_FROM_ABI void swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y)
......@@ -2567,7 +2589,7 @@ inline _LIBCPP_HIDE_FROM_ABI void swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _
25672589 __x.swap(__y);
25682590}
25692591
2570#if _LIBCPP_STD_VER >= 20
2592# if _LIBCPP_STD_VER >= 20
25712593template <class _Tp, class _Allocator, class _Up>
25722594inline _LIBCPP_HIDE_FROM_ABI typename deque<_Tp, _Allocator>::size_type
25732595erase(deque<_Tp, _Allocator>& __c, const _Up& __v) {
......@@ -2586,36 +2608,48 @@ erase_if(deque<_Tp, _Allocator>& __c, _Predicate __pred) {
25862608
25872609template <>
25882610inline constexpr bool __format::__enable_insertable<std::deque<char>> = true;
2589# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2611# if _LIBCPP_HAS_WIDE_CHARACTERS
25902612template <>
25912613inline constexpr bool __format::__enable_insertable<std::deque<wchar_t>> = true;
2592# endif
2614# endif
2615
2616# endif // _LIBCPP_STD_VER >= 20
25932617
2594#endif // _LIBCPP_STD_VER >= 20
2618template <class _Tp, class _Allocator>
2619struct __container_traits<deque<_Tp, _Allocator> > {
2620 // http://eel.is/c++draft/deque.modifiers#3
2621 // If an exception is thrown other than by the copy constructor, move constructor, assignment operator, or move
2622 // assignment operator of T, there are no effects. If an exception is thrown while inserting a single element at
2623 // either end, there are no effects. Otherwise, if an exception is thrown by the move constructor of a
2624 // non-Cpp17CopyInsertable T, the effects are unspecified.
2625 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
2626 _Or<is_nothrow_move_constructible<_Tp>, __is_cpp17_copy_insertable<_Allocator> >::value;
2627};
25952628
25962629_LIBCPP_END_NAMESPACE_STD
25972630
2598#if _LIBCPP_STD_VER >= 17
2631# if _LIBCPP_STD_VER >= 17
25992632_LIBCPP_BEGIN_NAMESPACE_STD
26002633namespace pmr {
26012634template <class _ValueT>
26022635using deque _LIBCPP_AVAILABILITY_PMR = std::deque<_ValueT, polymorphic_allocator<_ValueT>>;
26032636} // namespace pmr
26042637_LIBCPP_END_NAMESPACE_STD
2605#endif
2638# endif
26062639
26072640_LIBCPP_POP_MACROS
26082641
2609#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
2610# include <algorithm>
2611# include <atomic>
2612# include <concepts>
2613# include <cstdlib>
2614# include <functional>
2615# include <iosfwd>
2616# include <iterator>
2617# include <type_traits>
2618# include <typeinfo>
2619#endif
2642# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
2643# include <algorithm>
2644# include <atomic>
2645# include <concepts>
2646# include <cstdlib>
2647# include <functional>
2648# include <iosfwd>
2649# include <iterator>
2650# include <type_traits>
2651# include <typeinfo>
2652# endif
2653#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
26202654
26212655#endif // _LIBCPP_DEQUE
lib/libcxx/include/errno.h+272-268
......@@ -22,378 +22,382 @@ Macros:
2222
2323*/
2424
25#include <__config>
25#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
26# include <__cxx03/errno.h>
27#else
28# include <__config>
2629
27#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28# pragma GCC system_header
29#endif
30# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
31# pragma GCC system_header
32# endif
3033
31#if __has_include_next(<errno.h>)
32# include_next <errno.h>
33#endif
34# if __has_include_next(<errno.h>)
35# include_next <errno.h>
36# endif
3437
35#ifdef __cplusplus
38# ifdef __cplusplus
3639
37# if !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE)
40# if !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE)
3841
39# ifdef ELAST
42# ifdef ELAST
4043
4144static const int __elast1 = ELAST + 1;
4245static const int __elast2 = ELAST + 2;
4346
44# else
47# else
4548
4649static const int __elast1 = 104;
4750static const int __elast2 = 105;
4851
49# endif
52# endif
5053
51# ifdef ENOTRECOVERABLE
54# ifdef ENOTRECOVERABLE
5255
53# define EOWNERDEAD __elast1
56# define EOWNERDEAD __elast1
5457
55# ifdef ELAST
56# undef ELAST
57# define ELAST EOWNERDEAD
58# endif
58# ifdef ELAST
59# undef ELAST
60# define ELAST EOWNERDEAD
61# endif
5962
60# elif defined(EOWNERDEAD)
63# elif defined(EOWNERDEAD)
6164
62# define ENOTRECOVERABLE __elast1
63# ifdef ELAST
64# undef ELAST
65# define ELAST ENOTRECOVERABLE
66# endif
65# define ENOTRECOVERABLE __elast1
66# ifdef ELAST
67# undef ELAST
68# define ELAST ENOTRECOVERABLE
69# endif
6770
68# else // defined(EOWNERDEAD)
71# else // defined(EOWNERDEAD)
6972
70# define EOWNERDEAD __elast1
71# define ENOTRECOVERABLE __elast2
72# ifdef ELAST
73# undef ELAST
74# define ELAST ENOTRECOVERABLE
75# endif
73# define EOWNERDEAD __elast1
74# define ENOTRECOVERABLE __elast2
75# ifdef ELAST
76# undef ELAST
77# define ELAST ENOTRECOVERABLE
78# endif
7679
77# endif // defined(EOWNERDEAD)
80# endif // defined(EOWNERDEAD)
7881
79# endif // !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE)
82# endif // !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE)
8083
8184// supply errno values likely to be missing, particularly on Windows
8285
83# ifndef EAFNOSUPPORT
84# define EAFNOSUPPORT 9901
85# endif
86# ifndef EAFNOSUPPORT
87# define EAFNOSUPPORT 9901
88# endif
8689
87# ifndef EADDRINUSE
88# define EADDRINUSE 9902
89# endif
90# ifndef EADDRINUSE
91# define EADDRINUSE 9902
92# endif
9093
91# ifndef EADDRNOTAVAIL
92# define EADDRNOTAVAIL 9903
93# endif
94# ifndef EADDRNOTAVAIL
95# define EADDRNOTAVAIL 9903
96# endif
9497
95# ifndef EISCONN
96# define EISCONN 9904
97# endif
98# ifndef EISCONN
99# define EISCONN 9904
100# endif
98101
99# ifndef EBADMSG
100# define EBADMSG 9905
101# endif
102# ifndef EBADMSG
103# define EBADMSG 9905
104# endif
102105
103# ifndef ECONNABORTED
104# define ECONNABORTED 9906
105# endif
106# ifndef ECONNABORTED
107# define ECONNABORTED 9906
108# endif
106109
107# ifndef EALREADY
108# define EALREADY 9907
109# endif
110# ifndef EALREADY
111# define EALREADY 9907
112# endif
110113
111# ifndef ECONNREFUSED
112# define ECONNREFUSED 9908
113# endif
114# ifndef ECONNREFUSED
115# define ECONNREFUSED 9908
116# endif
114117
115# ifndef ECONNRESET
116# define ECONNRESET 9909
117# endif
118# ifndef ECONNRESET
119# define ECONNRESET 9909
120# endif
118121
119# ifndef EDESTADDRREQ
120# define EDESTADDRREQ 9910
121# endif
122# ifndef EDESTADDRREQ
123# define EDESTADDRREQ 9910
124# endif
122125
123# ifndef EHOSTUNREACH
124# define EHOSTUNREACH 9911
125# endif
126# ifndef EHOSTUNREACH
127# define EHOSTUNREACH 9911
128# endif
126129
127# ifndef EIDRM
128# define EIDRM 9912
129# endif
130# ifndef EIDRM
131# define EIDRM 9912
132# endif
130133
131# ifndef EMSGSIZE
132# define EMSGSIZE 9913
133# endif
134# ifndef EMSGSIZE
135# define EMSGSIZE 9913
136# endif
134137
135# ifndef ENETDOWN
136# define ENETDOWN 9914
137# endif
138# ifndef ENETDOWN
139# define ENETDOWN 9914
140# endif
138141
139# ifndef ENETRESET
140# define ENETRESET 9915
141# endif
142# ifndef ENETRESET
143# define ENETRESET 9915
144# endif
142145
143# ifndef ENETUNREACH
144# define ENETUNREACH 9916
145# endif
146# ifndef ENETUNREACH
147# define ENETUNREACH 9916
148# endif
146149
147# ifndef ENOBUFS
148# define ENOBUFS 9917
149# endif
150# ifndef ENOBUFS
151# define ENOBUFS 9917
152# endif
150153
151# ifndef ENOLINK
152# define ENOLINK 9918
153# endif
154# ifndef ENOLINK
155# define ENOLINK 9918
156# endif
154157
155# ifndef ENODATA
156# define ENODATA 9919
157# endif
158# ifndef ENODATA
159# define ENODATA 9919
160# endif
158161
159# ifndef ENOMSG
160# define ENOMSG 9920
161# endif
162# ifndef ENOMSG
163# define ENOMSG 9920
164# endif
162165
163# ifndef ENOPROTOOPT
164# define ENOPROTOOPT 9921
165# endif
166# ifndef ENOPROTOOPT
167# define ENOPROTOOPT 9921
168# endif
166169
167# ifndef ENOSR
168# define ENOSR 9922
169# endif
170# ifndef ENOSR
171# define ENOSR 9922
172# endif
170173
171# ifndef ENOTSOCK
172# define ENOTSOCK 9923
173# endif
174# ifndef ENOTSOCK
175# define ENOTSOCK 9923
176# endif
174177
175# ifndef ENOSTR
176# define ENOSTR 9924
177# endif
178# ifndef ENOSTR
179# define ENOSTR 9924
180# endif
178181
179# ifndef ENOTCONN
180# define ENOTCONN 9925
181# endif
182# ifndef ENOTCONN
183# define ENOTCONN 9925
184# endif
182185
183# ifndef ENOTSUP
184# define ENOTSUP 9926
185# endif
186# ifndef ENOTSUP
187# define ENOTSUP 9926
188# endif
186189
187# ifndef ECANCELED
188# define ECANCELED 9927
189# endif
190# ifndef ECANCELED
191# define ECANCELED 9927
192# endif
190193
191# ifndef EINPROGRESS
192# define EINPROGRESS 9928
193# endif
194# ifndef EINPROGRESS
195# define EINPROGRESS 9928
196# endif
194197
195# ifndef EOPNOTSUPP
196# define EOPNOTSUPP 9929
197# endif
198# ifndef EOPNOTSUPP
199# define EOPNOTSUPP 9929
200# endif
198201
199# ifndef EWOULDBLOCK
200# define EWOULDBLOCK 9930
201# endif
202# ifndef EWOULDBLOCK
203# define EWOULDBLOCK 9930
204# endif
202205
203# ifndef EOWNERDEAD
204# define EOWNERDEAD 9931
205# endif
206# ifndef EOWNERDEAD
207# define EOWNERDEAD 9931
208# endif
206209
207# ifndef EPROTO
208# define EPROTO 9932
209# endif
210# ifndef EPROTO
211# define EPROTO 9932
212# endif
210213
211# ifndef EPROTONOSUPPORT
212# define EPROTONOSUPPORT 9933
213# endif
214# ifndef EPROTONOSUPPORT
215# define EPROTONOSUPPORT 9933
216# endif
214217
215# ifndef ENOTRECOVERABLE
216# define ENOTRECOVERABLE 9934
217# endif
218# ifndef ENOTRECOVERABLE
219# define ENOTRECOVERABLE 9934
220# endif
218221
219# ifndef ETIME
220# define ETIME 9935
221# endif
222# ifndef ETIME
223# define ETIME 9935
224# endif
222225
223# ifndef ETXTBSY
224# define ETXTBSY 9936
225# endif
226# ifndef ETXTBSY
227# define ETXTBSY 9936
228# endif
226229
227# ifndef ETIMEDOUT
228# define ETIMEDOUT 9938
229# endif
230# ifndef ETIMEDOUT
231# define ETIMEDOUT 9938
232# endif
230233
231# ifndef ELOOP
232# define ELOOP 9939
233# endif
234# ifndef ELOOP
235# define ELOOP 9939
236# endif
234237
235# ifndef EOVERFLOW
236# define EOVERFLOW 9940
237# endif
238# ifndef EOVERFLOW
239# define EOVERFLOW 9940
240# endif
238241
239# ifndef EPROTOTYPE
240# define EPROTOTYPE 9941
241# endif
242# ifndef EPROTOTYPE
243# define EPROTOTYPE 9941
244# endif
242245
243# ifndef ENOSYS
244# define ENOSYS 9942
245# endif
246# ifndef ENOSYS
247# define ENOSYS 9942
248# endif
246249
247# ifndef EINVAL
248# define EINVAL 9943
249# endif
250# ifndef EINVAL
251# define EINVAL 9943
252# endif
250253
251# ifndef ERANGE
252# define ERANGE 9944
253# endif
254# ifndef ERANGE
255# define ERANGE 9944
256# endif
254257
255# ifndef EILSEQ
256# define EILSEQ 9945
257# endif
258# ifndef EILSEQ
259# define EILSEQ 9945
260# endif
258261
259262// Windows Mobile doesn't appear to define these:
260263
261# ifndef E2BIG
262# define E2BIG 9946
263# endif
264# ifndef E2BIG
265# define E2BIG 9946
266# endif
264267
265# ifndef EDOM
266# define EDOM 9947
267# endif
268# ifndef EDOM
269# define EDOM 9947
270# endif
268271
269# ifndef EFAULT
270# define EFAULT 9948
271# endif
272# ifndef EFAULT
273# define EFAULT 9948
274# endif
272275
273# ifndef EBADF
274# define EBADF 9949
275# endif
276# ifndef EBADF
277# define EBADF 9949
278# endif
276279
277# ifndef EPIPE
278# define EPIPE 9950
279# endif
280# ifndef EPIPE
281# define EPIPE 9950
282# endif
280283
281# ifndef EXDEV
282# define EXDEV 9951
283# endif
284# ifndef EXDEV
285# define EXDEV 9951
286# endif
284287
285# ifndef EBUSY
286# define EBUSY 9952
287# endif
288# ifndef EBUSY
289# define EBUSY 9952
290# endif
288291
289# ifndef ENOTEMPTY
290# define ENOTEMPTY 9953
291# endif
292# ifndef ENOTEMPTY
293# define ENOTEMPTY 9953
294# endif
292295
293# ifndef ENOEXEC
294# define ENOEXEC 9954
295# endif
296# ifndef ENOEXEC
297# define ENOEXEC 9954
298# endif
296299
297# ifndef EEXIST
298# define EEXIST 9955
299# endif
300# ifndef EEXIST
301# define EEXIST 9955
302# endif
300303
301# ifndef EFBIG
302# define EFBIG 9956
303# endif
304# ifndef EFBIG
305# define EFBIG 9956
306# endif
304307
305# ifndef ENAMETOOLONG
306# define ENAMETOOLONG 9957
307# endif
308# ifndef ENAMETOOLONG
309# define ENAMETOOLONG 9957
310# endif
308311
309# ifndef ENOTTY
310# define ENOTTY 9958
311# endif
312# ifndef ENOTTY
313# define ENOTTY 9958
314# endif
312315
313# ifndef EINTR
314# define EINTR 9959
315# endif
316# ifndef EINTR
317# define EINTR 9959
318# endif
316319
317# ifndef ESPIPE
318# define ESPIPE 9960
319# endif
320# ifndef ESPIPE
321# define ESPIPE 9960
322# endif
320323
321# ifndef EIO
322# define EIO 9961
323# endif
324# ifndef EIO
325# define EIO 9961
326# endif
324327
325# ifndef EISDIR
326# define EISDIR 9962
327# endif
328# ifndef EISDIR
329# define EISDIR 9962
330# endif
328331
329# ifndef ECHILD
330# define ECHILD 9963
331# endif
332# ifndef ECHILD
333# define ECHILD 9963
334# endif
332335
333# ifndef ENOLCK
334# define ENOLCK 9964
335# endif
336# ifndef ENOLCK
337# define ENOLCK 9964
338# endif
336339
337# ifndef ENOSPC
338# define ENOSPC 9965
339# endif
340# ifndef ENOSPC
341# define ENOSPC 9965
342# endif
340343
341# ifndef ENXIO
342# define ENXIO 9966
343# endif
344# ifndef ENXIO
345# define ENXIO 9966
346# endif
344347
345# ifndef ENODEV
346# define ENODEV 9967
347# endif
348# ifndef ENODEV
349# define ENODEV 9967
350# endif
348351
349# ifndef ENOENT
350# define ENOENT 9968
351# endif
352# ifndef ENOENT
353# define ENOENT 9968
354# endif
352355
353# ifndef ESRCH
354# define ESRCH 9969
355# endif
356# ifndef ESRCH
357# define ESRCH 9969
358# endif
356359
357# ifndef ENOTDIR
358# define ENOTDIR 9970
359# endif
360# ifndef ENOTDIR
361# define ENOTDIR 9970
362# endif
360363
361# ifndef ENOMEM
362# define ENOMEM 9971
363# endif
364# ifndef ENOMEM
365# define ENOMEM 9971
366# endif
364367
365# ifndef EPERM
366# define EPERM 9972
367# endif
368# ifndef EPERM
369# define EPERM 9972
370# endif
368371
369# ifndef EACCES
370# define EACCES 9973
371# endif
372# ifndef EACCES
373# define EACCES 9973
374# endif
372375
373# ifndef EROFS
374# define EROFS 9974
375# endif
376# ifndef EROFS
377# define EROFS 9974
378# endif
376379
377# ifndef EDEADLK
378# define EDEADLK 9975
379# endif
380# ifndef EDEADLK
381# define EDEADLK 9975
382# endif
380383
381# ifndef EAGAIN
382# define EAGAIN 9976
383# endif
384# ifndef EAGAIN
385# define EAGAIN 9976
386# endif
384387
385# ifndef ENFILE
386# define ENFILE 9977
387# endif
388# ifndef ENFILE
389# define ENFILE 9977
390# endif
388391
389# ifndef EMFILE
390# define EMFILE 9978
391# endif
392# ifndef EMFILE
393# define EMFILE 9978
394# endif
392395
393# ifndef EMLINK
394# define EMLINK 9979
395# endif
396# ifndef EMLINK
397# define EMLINK 9979
398# endif
396399
397#endif // __cplusplus
400# endif // __cplusplus
401#endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
398402
399403#endif // _LIBCPP_ERRNO_H
lib/libcxx/include/exception+23-17
......@@ -47,7 +47,7 @@ terminate_handler set_terminate(terminate_handler f ) noexcept;
4747terminate_handler get_terminate() noexcept;
4848[[noreturn]] void terminate() noexcept;
4949
50bool uncaught_exception() noexcept;
50bool uncaught_exception() noexcept; // deprecated in C++17, removed in C++20
5151int uncaught_exceptions() noexcept; // C++17
5252
5353typedef unspecified exception_ptr;
......@@ -76,21 +76,27 @@ template <class E> void rethrow_if_nested(const E& e);
7676
7777*/
7878
79#include <__config>
80#include <__exception/exception.h>
81#include <__exception/exception_ptr.h>
82#include <__exception/nested_exception.h>
83#include <__exception/operations.h>
84#include <__exception/terminate.h>
85#include <version>
86
87#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
88# pragma GCC system_header
89#endif
90
91#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
92# include <cstdlib>
93# include <type_traits>
94#endif
79#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
80# include <__cxx03/exception>
81#else
82# include <__config>
83# include <__exception/exception.h>
84# include <__exception/exception_ptr.h>
85# include <__exception/nested_exception.h>
86# include <__exception/operations.h>
87# include <__exception/terminate.h>
88# include <version>
89
90# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
91# pragma GCC system_header
92# endif
93
94# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
95# include <cstddef>
96# include <cstdlib>
97# include <new>
98# include <type_traits>
99# endif
100#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
95101
96102#endif // _LIBCPP_EXCEPTION
lib/libcxx/include/execution+33-19
......@@ -32,17 +32,20 @@ namespace std {
3232}
3333*/
3434
35#include <__config>
36#include <__type_traits/is_execution_policy.h>
37#include <__type_traits/is_same.h>
38#include <__type_traits/remove_cvref.h>
39#include <version>
40
41#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
42# pragma GCC system_header
43#endif
35#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
36# include <__cxx03/execution>
37#else
38# include <__config>
39# include <__type_traits/is_execution_policy.h>
40# include <__type_traits/is_same.h>
41# include <__type_traits/remove_cvref.h>
42# include <version>
43
44# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
45# pragma GCC system_header
46# endif
4447
45#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
48# if _LIBCPP_HAS_EXPERIMENTAL_PSTL && _LIBCPP_STD_VER >= 17
4649
4750_LIBCPP_BEGIN_NAMESPACE_STD
4851
......@@ -79,7 +82,7 @@ struct __unsequenced_policy {
7982
8083constexpr __unsequenced_policy __unseq{__disable_user_instantiations_tag{}};
8184
82# if _LIBCPP_STD_VER >= 20
85# if _LIBCPP_STD_VER >= 20
8386
8487struct unsequenced_policy {
8588 _LIBCPP_HIDE_FROM_ABI constexpr explicit unsequenced_policy(__disable_user_instantiations_tag) {}
......@@ -89,10 +92,14 @@ struct unsequenced_policy {
8992
9093inline constexpr unsequenced_policy unseq{__disable_user_instantiations_tag{}};
9194
92# endif // _LIBCPP_STD_VER >= 20
95# endif // _LIBCPP_STD_VER >= 20
9396
9497} // namespace execution
9598
99_LIBCPP_DIAGNOSTIC_PUSH
100# if __has_warning("-Winvalid-specialization")
101_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
102# endif
96103template <>
97104inline constexpr bool is_execution_policy_v<execution::sequenced_policy> = true;
98105
......@@ -104,6 +111,7 @@ inline constexpr bool is_execution_policy_v<execution::parallel_unsequenced_poli
104111
105112template <>
106113inline constexpr bool is_execution_policy_v<execution::__unsequenced_policy> = true;
114_LIBCPP_DIAGNOSTIC_POP
107115
108116template <>
109117inline constexpr bool __is_parallel_execution_policy_impl<execution::parallel_policy> = true;
......@@ -117,17 +125,22 @@ inline constexpr bool __is_unsequenced_execution_policy_impl<execution::__unsequ
117125template <>
118126inline constexpr bool __is_unsequenced_execution_policy_impl<execution::parallel_unsequenced_policy> = true;
119127
120# if _LIBCPP_STD_VER >= 20
128# if _LIBCPP_STD_VER >= 20
129_LIBCPP_DIAGNOSTIC_PUSH
130# if __has_warning("-Winvalid-specialization")
131_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
132# endif
121133template <>
122134inline constexpr bool is_execution_policy_v<execution::unsequenced_policy> = true;
135_LIBCPP_DIAGNOSTIC_POP
123136
124137template <>
125138inline constexpr bool __is_unsequenced_execution_policy_impl<execution::unsequenced_policy> = true;
126139
127# endif
140# endif
128141
129142template <class _Tp>
130struct is_execution_policy : bool_constant<is_execution_policy_v<_Tp>> {};
143struct _LIBCPP_NO_SPECIALIZATIONS is_execution_policy : bool_constant<is_execution_policy_v<_Tp>> {};
131144
132145template <class _ExecutionPolicy>
133146_LIBCPP_HIDE_FROM_ABI auto __remove_parallel_policy(const _ExecutionPolicy&) {
......@@ -140,10 +153,11 @@ _LIBCPP_HIDE_FROM_ABI auto __remove_parallel_policy(const _ExecutionPolicy&) {
140153
141154_LIBCPP_END_NAMESPACE_STD
142155
143#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
156# endif // _LIBCPP_HAS_EXPERIMENTAL_PSTL && _LIBCPP_STD_VER >= 17
144157
145#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
146# include <cstddef>
147#endif
158# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
159# include <cstddef>
160# endif
161#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
148162
149163#endif // _LIBCPP_EXECUTION
lib/libcxx/include/expected+18-20
......@@ -38,25 +38,23 @@ namespace std {
3838
3939*/
4040
41#include <__config>
42
43#if _LIBCPP_STD_VER >= 23
44# include <__expected/bad_expected_access.h>
45# include <__expected/expected.h>
46# include <__expected/unexpect.h>
47# include <__expected/unexpected.h>
48#endif
49
50#include <version>
51
52#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
53# pragma GCC system_header
54#endif
55
56#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
57# include <cstddef>
58# include <initializer_list>
59# include <new>
60#endif
41#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
42# include <__cxx03/expected>
43#else
44# include <__config>
45
46# if _LIBCPP_STD_VER >= 23
47# include <__expected/bad_expected_access.h>
48# include <__expected/expected.h>
49# include <__expected/unexpect.h>
50# include <__expected/unexpected.h>
51# endif
52
53# include <version>
54
55# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
56# pragma GCC system_header
57# endif
58#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
6159
6260#endif // _LIBCPP_EXPECTED
lib/libcxx/include/experimental/__config deleted-45
......@@ -1,45 +0,0 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_EXPERIMENTAL_CONFIG
11#define _LIBCPP_EXPERIMENTAL_CONFIG
12
13#include <__config>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL \
20 namespace std { \
21 namespace experimental {
22#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL \
23 } \
24 }
25
26#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 {
27#define _LIBCPP_END_NAMESPACE_LFTS \
28 } \
29 } \
30 }
31
32#define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 {
33#define _LIBCPP_END_NAMESPACE_LFTS_V2 \
34 } \
35 } \
36 }
37
38// TODO: support more targets
39#if defined(__AVX__)
40# define _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES 32
41#else
42# define _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES 16
43#endif
44
45#endif
lib/libcxx/include/experimental/__simd/aligned_tag.h+2-2
......@@ -10,10 +10,10 @@
1010#ifndef _LIBCPP_EXPERIMENTAL___SIMD_ALIGNED_TAG_H
1111#define _LIBCPP_EXPERIMENTAL___SIMD_ALIGNED_TAG_H
1212
13#include <__config>
14#include <__cstddef/size_t.h>
1315#include <__memory/assume_aligned.h>
1416#include <__type_traits/remove_const.h>
15#include <cstddef>
16#include <experimental/__config>
1717#include <experimental/__simd/traits.h>
1818
1919#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
lib/libcxx/include/experimental/__simd/declaration.h+9-2
......@@ -10,11 +10,18 @@
1010#ifndef _LIBCPP_EXPERIMENTAL___SIMD_DECLARATION_H
1111#define _LIBCPP_EXPERIMENTAL___SIMD_DECLARATION_H
1212
13#include <cstddef>
14#include <experimental/__config>
13#include <__config>
14#include <__cstddef/size_t.h>
1515
1616#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
1717
18// TODO: support more targets
19# if defined(__AVX__)
20# define _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES 32
21# else
22# define _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES 16
23# endif
24
1825_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
1926inline namespace parallelism_v2 {
2027namespace simd_abi {
lib/libcxx/include/experimental/__simd/reference.h+89-2
......@@ -10,12 +10,14 @@
1010#ifndef _LIBCPP_EXPERIMENTAL___SIMD_REFERENCE_H
1111#define _LIBCPP_EXPERIMENTAL___SIMD_REFERENCE_H
1212
13#include <__config>
14#include <__cstddef/size_t.h>
15#include <__type_traits/enable_if.h>
1316#include <__type_traits/is_assignable.h>
1417#include <__type_traits/is_same.h>
18#include <__utility/declval.h>
1519#include <__utility/forward.h>
1620#include <__utility/move.h>
17#include <cstddef>
18#include <experimental/__config>
1921#include <experimental/__simd/utility.h>
2022
2123_LIBCPP_PUSH_MACROS
......@@ -71,6 +73,91 @@ public:
7173
7274 template <class _Tp1, class _Storage1, class _Vp1>
7375 friend void swap(__simd_reference<_Tp1, _Storage1, _Vp1>&& __a, _Vp1& __b) noexcept;
76
77 template <class _Up, class = decltype(std::declval<value_type&>() += std::declval<_Up>())>
78 _LIBCPP_HIDE_FROM_ABI __simd_reference operator+=(_Up&& __v) && noexcept {
79 __set(__get() + static_cast<value_type>(std::forward<_Up>(__v)));
80 return {__s_, __idx_};
81 }
82
83 template <class _Up, class = decltype(std::declval<value_type&>() -= std::declval<_Up>())>
84 _LIBCPP_HIDE_FROM_ABI __simd_reference operator-=(_Up&& __v) && noexcept {
85 __set(__get() - static_cast<value_type>(std::forward<_Up>(__v)));
86 return {__s_, __idx_};
87 }
88
89 template <class _Up, class = decltype(std::declval<value_type&>() *= std::declval<_Up>())>
90 _LIBCPP_HIDE_FROM_ABI __simd_reference operator*=(_Up&& __v) && noexcept {
91 __set(__get() * static_cast<value_type>(std::forward<_Up>(__v)));
92 return {__s_, __idx_};
93 }
94
95 template <class _Up, class = decltype(std::declval<value_type&>() /= std::declval<_Up>())>
96 _LIBCPP_HIDE_FROM_ABI __simd_reference operator/=(_Up&& __v) && noexcept {
97 __set(__get() / static_cast<value_type>(std::forward<_Up>(__v)));
98 return {__s_, __idx_};
99 }
100
101 template <class _Up, class = decltype(std::declval<value_type&>() %= std::declval<_Up>())>
102 _LIBCPP_HIDE_FROM_ABI __simd_reference operator%=(_Up&& __v) && noexcept {
103 __set(__get() % static_cast<value_type>(std::forward<_Up>(__v)));
104 return {__s_, __idx_};
105 }
106
107 template <class _Up, class = decltype(std::declval<value_type&>() &= std::declval<_Up>())>
108 _LIBCPP_HIDE_FROM_ABI __simd_reference operator&=(_Up&& __v) && noexcept {
109 __set(__get() & static_cast<value_type>(std::forward<_Up>(__v)));
110 return {__s_, __idx_};
111 }
112
113 template <class _Up, class = decltype(std::declval<value_type&>() |= std::declval<_Up>())>
114 _LIBCPP_HIDE_FROM_ABI __simd_reference operator|=(_Up&& __v) && noexcept {
115 __set(__get() | static_cast<value_type>(std::forward<_Up>(__v)));
116 return {__s_, __idx_};
117 }
118
119 template <class _Up, class = decltype(std::declval<value_type&>() ^= std::declval<_Up>())>
120 _LIBCPP_HIDE_FROM_ABI __simd_reference operator^=(_Up&& __v) && noexcept {
121 __set(__get() ^ static_cast<value_type>(std::forward<_Up>(__v)));
122 return {__s_, __idx_};
123 }
124
125 template <class _Up, class = decltype(std::declval<value_type&>() <<= std::declval<_Up>())>
126 _LIBCPP_HIDE_FROM_ABI __simd_reference operator<<=(_Up&& __v) && noexcept {
127 __set(__get() << static_cast<value_type>(std::forward<_Up>(__v)));
128 return {__s_, __idx_};
129 }
130
131 template <class _Up, class = decltype(std::declval<value_type&>() >>= std::declval<_Up>())>
132 _LIBCPP_HIDE_FROM_ABI __simd_reference operator>>=(_Up&& __v) && noexcept {
133 __set(__get() >> static_cast<value_type>(std::forward<_Up>(__v)));
134 return {__s_, __idx_};
135 }
136
137 // Note: All legal vectorizable types support operator++/--.
138 // There doesn't seem to be a way to trigger the constraint.
139 // Therefore, no SFINAE check is added here.
140 __simd_reference _LIBCPP_HIDE_FROM_ABI operator++() && noexcept {
141 __set(__get() + 1);
142 return {__s_, __idx_};
143 }
144
145 value_type _LIBCPP_HIDE_FROM_ABI operator++(int) && noexcept {
146 auto __r = __get();
147 __set(__get() + 1);
148 return __r;
149 }
150
151 __simd_reference _LIBCPP_HIDE_FROM_ABI operator--() && noexcept {
152 __set(__get() - 1);
153 return {__s_, __idx_};
154 }
155
156 value_type _LIBCPP_HIDE_FROM_ABI operator--(int) && noexcept {
157 auto __r = __get();
158 __set(__get() - 1);
159 return __r;
160 }
74161};
75162
76163template <class _Tp, class _Storage, class _Vp>
lib/libcxx/include/experimental/__simd/scalar.h+20-5
......@@ -11,8 +11,9 @@
1111#define _LIBCPP_EXPERIMENTAL___SIMD_SCALAR_H
1212
1313#include <__assert>
14#include <cstddef>
15#include <experimental/__config>
14#include <__config>
15#include <__cstddef/size_t.h>
16#include <__type_traits/integral_constant.h>
1617#include <experimental/__simd/declaration.h>
1718#include <experimental/__simd/traits.h>
1819
......@@ -48,8 +49,8 @@ struct __mask_storage<_Tp, simd_abi::__scalar> : __simd_storage<bool, simd_abi::
4849
4950template <class _Tp>
5051struct __simd_operations<_Tp, simd_abi::__scalar> {
51 using _SimdStorage = __simd_storage<_Tp, simd_abi::__scalar>;
52 using _MaskStorage = __mask_storage<_Tp, simd_abi::__scalar>;
52 using _SimdStorage _LIBCPP_NODEBUG = __simd_storage<_Tp, simd_abi::__scalar>;
53 using _MaskStorage _LIBCPP_NODEBUG = __mask_storage<_Tp, simd_abi::__scalar>;
5354
5455 static _LIBCPP_HIDE_FROM_ABI _SimdStorage __broadcast(_Tp __v) noexcept { return {__v}; }
5556
......@@ -67,11 +68,25 @@ struct __simd_operations<_Tp, simd_abi::__scalar> {
6768 static _LIBCPP_HIDE_FROM_ABI void __store(_SimdStorage __s, _Up* __mem) noexcept {
6869 *__mem = static_cast<_Up>(__s.__data);
6970 }
71
72 static _LIBCPP_HIDE_FROM_ABI void __increment(_SimdStorage& __s) noexcept { ++__s.__data; }
73
74 static _LIBCPP_HIDE_FROM_ABI void __decrement(_SimdStorage& __s) noexcept { --__s.__data; }
75
76 static _LIBCPP_HIDE_FROM_ABI _MaskStorage __negate(_SimdStorage __s) noexcept { return {!__s.__data}; }
77
78 static _LIBCPP_HIDE_FROM_ABI _SimdStorage __bitwise_not(_SimdStorage __s) noexcept {
79 return {static_cast<_Tp>(~__s.__data)};
80 }
81
82 static _LIBCPP_HIDE_FROM_ABI _SimdStorage __unary_minus(_SimdStorage __s) noexcept {
83 return {static_cast<_Tp>(-__s.__data)};
84 }
7085};
7186
7287template <class _Tp>
7388struct __mask_operations<_Tp, simd_abi::__scalar> {
74 using _MaskStorage = __mask_storage<_Tp, simd_abi::__scalar>;
89 using _MaskStorage _LIBCPP_NODEBUG = __mask_storage<_Tp, simd_abi::__scalar>;
7590
7691 static _LIBCPP_HIDE_FROM_ABI _MaskStorage __broadcast(bool __v) noexcept { return {__v}; }
7792
lib/libcxx/include/experimental/__simd/simd.h+58-5
......@@ -10,11 +10,13 @@
1010#ifndef _LIBCPP_EXPERIMENTAL___SIMD_SIMD_H
1111#define _LIBCPP_EXPERIMENTAL___SIMD_SIMD_H
1212
13#include <__config>
14#include <__cstddef/size_t.h>
15#include <__type_traits/enable_if.h>
16#include <__type_traits/is_integral.h>
1317#include <__type_traits/is_same.h>
1418#include <__type_traits/remove_cvref.h>
1519#include <__utility/forward.h>
16#include <cstddef>
17#include <experimental/__config>
1820#include <experimental/__simd/declaration.h>
1921#include <experimental/__simd/reference.h>
2022#include <experimental/__simd/traits.h>
......@@ -25,15 +27,29 @@
2527_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
2628inline namespace parallelism_v2 {
2729
30template <class _Simd, class _Impl, bool>
31class __simd_int_operators {};
32
33template <class _Simd, class _Impl>
34class __simd_int_operators<_Simd, _Impl, true> {
35public:
36 // unary operators for integral _Tp
37 _LIBCPP_HIDE_FROM_ABI _Simd operator~() const noexcept {
38 return _Simd(_Impl::__bitwise_not((*static_cast<const _Simd*>(this)).__s_), _Simd::__storage_tag);
39 }
40};
41
2842// class template simd [simd.class]
2943// TODO: implement simd class
3044template <class _Tp, class _Abi>
31class simd {
32 using _Impl = __simd_operations<_Tp, _Abi>;
33 using _Storage = typename _Impl::_SimdStorage;
45class simd : public __simd_int_operators<simd<_Tp, _Abi>, __simd_operations<_Tp, _Abi>, is_integral_v<_Tp>> {
46 using _Impl _LIBCPP_NODEBUG = __simd_operations<_Tp, _Abi>;
47 using _Storage _LIBCPP_NODEBUG = typename _Impl::_SimdStorage;
3448
3549 _Storage __s_;
3650
51 friend class __simd_int_operators<simd, _Impl, true>;
52
3753public:
3854 using value_type = _Tp;
3955 using reference = __simd_reference<_Tp, _Storage, value_type>;
......@@ -44,6 +60,12 @@ public:
4460
4561 _LIBCPP_HIDE_FROM_ABI simd() noexcept = default;
4662
63 // explicit conversion from and to implementation-defined types
64 struct __storage_tag_t {};
65 static constexpr __storage_tag_t __storage_tag{};
66 explicit _LIBCPP_HIDE_FROM_ABI operator _Storage() const { return __s_; }
67 explicit _LIBCPP_HIDE_FROM_ABI simd(const _Storage& __s, __storage_tag_t) : __s_(__s) {}
68
4769 // broadcast constructor
4870 template <class _Up, enable_if_t<__can_broadcast_v<value_type, __remove_cvref_t<_Up>>, int> = 0>
4971 _LIBCPP_HIDE_FROM_ABI simd(_Up&& __v) noexcept : __s_(_Impl::__broadcast(static_cast<value_type>(__v))) {}
......@@ -84,6 +106,37 @@ public:
84106 // scalar access [simd.subscr]
85107 _LIBCPP_HIDE_FROM_ABI reference operator[](size_t __i) noexcept { return reference(__s_, __i); }
86108 _LIBCPP_HIDE_FROM_ABI value_type operator[](size_t __i) const noexcept { return __s_.__get(__i); }
109
110 // simd unary operators
111 _LIBCPP_HIDE_FROM_ABI simd& operator++() noexcept {
112 _Impl::__increment(__s_);
113 return *this;
114 }
115
116 _LIBCPP_HIDE_FROM_ABI simd operator++(int) noexcept {
117 simd __r = *this;
118 _Impl::__increment(__s_);
119 return __r;
120 }
121
122 _LIBCPP_HIDE_FROM_ABI simd& operator--() noexcept {
123 _Impl::__decrement(__s_);
124 return *this;
125 }
126
127 _LIBCPP_HIDE_FROM_ABI simd operator--(int) noexcept {
128 simd __r = *this;
129 _Impl::__decrement(__s_);
130 return __r;
131 }
132
133 _LIBCPP_HIDE_FROM_ABI mask_type operator!() const noexcept {
134 return mask_type(_Impl::__negate(__s_), mask_type::__storage_tag);
135 }
136
137 _LIBCPP_HIDE_FROM_ABI simd operator+() const noexcept { return *this; }
138
139 _LIBCPP_HIDE_FROM_ABI simd operator-() const noexcept { return simd(_Impl::__unary_minus(__s_), __storage_tag); }
87140};
88141
89142template <class _Tp, class _Abi>
lib/libcxx/include/experimental/__simd/simd_mask.h+11-4
......@@ -10,9 +10,10 @@
1010#ifndef _LIBCPP_EXPERIMENTAL___SIMD_SIMD_MASK_H
1111#define _LIBCPP_EXPERIMENTAL___SIMD_SIMD_MASK_H
1212
13#include <__config>
14#include <__cstddef/size_t.h>
15#include <__type_traits/enable_if.h>
1316#include <__type_traits/is_same.h>
14#include <cstddef>
15#include <experimental/__config>
1617#include <experimental/__simd/declaration.h>
1718#include <experimental/__simd/reference.h>
1819#include <experimental/__simd/traits.h>
......@@ -26,8 +27,8 @@ inline namespace parallelism_v2 {
2627// TODO: implement simd_mask class
2728template <class _Tp, class _Abi>
2829class simd_mask {
29 using _Impl = __mask_operations<_Tp, _Abi>;
30 using _Storage = typename _Impl::_MaskStorage;
30 using _Impl _LIBCPP_NODEBUG = __mask_operations<_Tp, _Abi>;
31 using _Storage _LIBCPP_NODEBUG = typename _Impl::_MaskStorage;
3132
3233 _Storage __s_;
3334
......@@ -41,6 +42,12 @@ public:
4142
4243 _LIBCPP_HIDE_FROM_ABI simd_mask() noexcept = default;
4344
45 // explicit conversion from and to implementation-defined types
46 struct __storage_tag_t {};
47 static constexpr __storage_tag_t __storage_tag{};
48 explicit _LIBCPP_HIDE_FROM_ABI operator _Storage() const { return __s_; }
49 explicit _LIBCPP_HIDE_FROM_ABI simd_mask(const _Storage& __s, __storage_tag_t) : __s_(__s) {}
50
4451 // broadcast constructor
4552 _LIBCPP_HIDE_FROM_ABI explicit simd_mask(value_type __v) noexcept : __s_(_Impl::__broadcast(__v)) {}
4653
lib/libcxx/include/experimental/__simd/traits.h+2-2
......@@ -11,10 +11,10 @@
1111#define _LIBCPP_EXPERIMENTAL___SIMD_TRAITS_H
1212
1313#include <__bit/bit_ceil.h>
14#include <__config>
15#include <__cstddef/size_t.h>
1416#include <__type_traits/integral_constant.h>
1517#include <__type_traits/is_same.h>
16#include <cstddef>
17#include <experimental/__config>
1818#include <experimental/__simd/declaration.h>
1919#include <experimental/__simd/utility.h>
2020
lib/libcxx/include/experimental/__simd/utility.h+3-3
......@@ -10,6 +10,8 @@
1010#ifndef _LIBCPP_EXPERIMENTAL___SIMD_UTILITY_H
1111#define _LIBCPP_EXPERIMENTAL___SIMD_UTILITY_H
1212
13#include <__config>
14#include <__cstddef/size_t.h>
1315#include <__type_traits/is_arithmetic.h>
1416#include <__type_traits/is_const.h>
1517#include <__type_traits/is_constant_evaluated.h>
......@@ -20,9 +22,7 @@
2022#include <__type_traits/void_t.h>
2123#include <__utility/declval.h>
2224#include <__utility/integer_sequence.h>
23#include <cstddef>
2425#include <cstdint>
25#include <experimental/__config>
2626#include <limits>
2727
2828_LIBCPP_PUSH_MACROS
......@@ -47,7 +47,7 @@ _LIBCPP_HIDE_FROM_ABI auto __choose_mask_type() {
4747 } else if constexpr (sizeof(_Tp) == 8) {
4848 return uint64_t{};
4949 }
50# ifndef _LIBCPP_HAS_NO_INT128
50# if _LIBCPP_HAS_INT128
5151 else if constexpr (sizeof(_Tp) == 16) {
5252 return __uint128_t{};
5353 }
lib/libcxx/include/experimental/__simd/vec_ext.h+18-7
......@@ -12,10 +12,11 @@
1212
1313#include <__assert>
1414#include <__bit/bit_ceil.h>
15#include <__config>
16#include <__cstddef/size_t.h>
17#include <__type_traits/integral_constant.h>
1518#include <__utility/forward.h>
1619#include <__utility/integer_sequence.h>
17#include <cstddef>
18#include <experimental/__config>
1920#include <experimental/__simd/declaration.h>
2021#include <experimental/__simd/traits.h>
2122#include <experimental/__simd/utility.h>
......@@ -39,11 +40,11 @@ struct __simd_storage<_Tp, simd_abi::__vec_ext<_Np>> {
3940 _Tp __data __attribute__((__vector_size__(std::__bit_ceil((sizeof(_Tp) * _Np)))));
4041
4142 _LIBCPP_HIDE_FROM_ABI _Tp __get(size_t __idx) const noexcept {
42 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__idx >= 0 && __idx < _Np, "Index is out of bounds");
43 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__idx < _Np, "Index is out of bounds");
4344 return __data[__idx];
4445 }
4546 _LIBCPP_HIDE_FROM_ABI void __set(size_t __idx, _Tp __v) noexcept {
46 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__idx >= 0 && __idx < _Np, "Index is out of bounds");
47 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__idx < _Np, "Index is out of bounds");
4748 __data[__idx] = __v;
4849 }
4950};
......@@ -54,8 +55,8 @@ struct __mask_storage<_Tp, simd_abi::__vec_ext<_Np>>
5455
5556template <class _Tp, int _Np>
5657struct __simd_operations<_Tp, simd_abi::__vec_ext<_Np>> {
57 using _SimdStorage = __simd_storage<_Tp, simd_abi::__vec_ext<_Np>>;
58 using _MaskStorage = __mask_storage<_Tp, simd_abi::__vec_ext<_Np>>;
58 using _SimdStorage _LIBCPP_NODEBUG = __simd_storage<_Tp, simd_abi::__vec_ext<_Np>>;
59 using _MaskStorage _LIBCPP_NODEBUG = __mask_storage<_Tp, simd_abi::__vec_ext<_Np>>;
5960
6061 static _LIBCPP_HIDE_FROM_ABI _SimdStorage __broadcast(_Tp __v) noexcept {
6162 _SimdStorage __result;
......@@ -86,11 +87,21 @@ struct __simd_operations<_Tp, simd_abi::__vec_ext<_Np>> {
8687 for (size_t __i = 0; __i < _Np; __i++)
8788 __mem[__i] = static_cast<_Up>(__s.__data[__i]);
8889 }
90
91 static _LIBCPP_HIDE_FROM_ABI void __increment(_SimdStorage& __s) noexcept { __s.__data = __s.__data + 1; }
92
93 static _LIBCPP_HIDE_FROM_ABI void __decrement(_SimdStorage& __s) noexcept { __s.__data = __s.__data - 1; }
94
95 static _LIBCPP_HIDE_FROM_ABI _MaskStorage __negate(_SimdStorage __s) noexcept { return {!__s.__data}; }
96
97 static _LIBCPP_HIDE_FROM_ABI _SimdStorage __bitwise_not(_SimdStorage __s) noexcept { return {~__s.__data}; }
98
99 static _LIBCPP_HIDE_FROM_ABI _SimdStorage __unary_minus(_SimdStorage __s) noexcept { return {-__s.__data}; }
89100};
90101
91102template <class _Tp, int _Np>
92103struct __mask_operations<_Tp, simd_abi::__vec_ext<_Np>> {
93 using _MaskStorage = __mask_storage<_Tp, simd_abi::__vec_ext<_Np>>;
104 using _MaskStorage _LIBCPP_NODEBUG = __mask_storage<_Tp, simd_abi::__vec_ext<_Np>>;
94105
95106 static _LIBCPP_HIDE_FROM_ABI _MaskStorage __broadcast(bool __v) noexcept {
96107 _MaskStorage __result;
lib/libcxx/include/experimental/iterator+24-17
......@@ -52,21 +52,26 @@ namespace std {
5252
5353*/
5454
55#include <__memory/addressof.h>
56#include <__type_traits/decay.h>
57#include <__utility/forward.h>
58#include <__utility/move.h>
59#include <experimental/__config>
60#include <iterator>
61
62#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
63# pragma GCC system_header
64#endif
55#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
56# include <__cxx03/experimental/iterator>
57#else
58# include <__config>
59# include <__memory/addressof.h>
60# include <__ostream/basic_ostream.h>
61# include <__string/char_traits.h>
62# include <__type_traits/decay.h>
63# include <__utility/forward.h>
64# include <__utility/move.h>
65# include <iterator>
66
67# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
68# pragma GCC system_header
69# endif
6570
6671_LIBCPP_PUSH_MACROS
67#include <__undef_macros>
72# include <__undef_macros>
6873
69#if _LIBCPP_STD_VER >= 14
74# if _LIBCPP_STD_VER >= 14
7075
7176_LIBCPP_BEGIN_NAMESPACE_LFTS
7277
......@@ -115,13 +120,15 @@ make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os, _Delim&& __d) {
115120
116121_LIBCPP_END_NAMESPACE_LFTS
117122
118#endif // _LIBCPP_STD_VER >= 14
123# endif // _LIBCPP_STD_VER >= 14
119124
120125_LIBCPP_POP_MACROS
121126
122#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
123# include <iosfwd>
124# include <type_traits>
125#endif
127# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
128# include <cstddef>
129# include <iosfwd>
130# include <type_traits>
131# endif
132#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
126133
127134#endif // _LIBCPP_EXPERIMENTAL_ITERATOR
lib/libcxx/include/experimental/memory+30-23
......@@ -49,25 +49,30 @@ public:
4949}
5050*/
5151
52#include <__functional/hash.h>
53#include <__functional/operations.h>
54#include <__type_traits/add_lvalue_reference.h>
55#include <__type_traits/add_pointer.h>
56#include <__type_traits/common_type.h>
57#include <__type_traits/enable_if.h>
58#include <__type_traits/is_convertible.h>
59#include <cstddef>
60#include <experimental/__config>
61
62#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
63# pragma GCC system_header
64#endif
65
66#ifdef _LIBCPP_ENABLE_EXPERIMENTAL
52#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
53# include <__cxx03/experimental/memory>
54#else
55# include <__config>
56# include <__cstddef/nullptr_t.h>
57# include <__cstddef/size_t.h>
58# include <__functional/hash.h>
59# include <__functional/operations.h>
60# include <__type_traits/add_lvalue_reference.h>
61# include <__type_traits/add_pointer.h>
62# include <__type_traits/common_type.h>
63# include <__type_traits/enable_if.h>
64# include <__type_traits/is_convertible.h>
65# include <version>
66
67# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
68# pragma GCC system_header
69# endif
70
71# ifdef _LIBCPP_ENABLE_EXPERIMENTAL
6772
6873_LIBCPP_BEGIN_NAMESPACE_LFTS_V2
6974
70# if _LIBCPP_STD_VER >= 17
75# if _LIBCPP_STD_VER >= 17
7176
7277template <class _Wp>
7378class observer_ptr {
......@@ -170,7 +175,7 @@ _LIBCPP_HIDE_FROM_ABI bool operator>=(observer_ptr<_W1> __a, observer_ptr<_W2> _
170175 return !(__a < __b);
171176}
172177
173# endif // _LIBCPP_STD_VER >= 17
178# endif // _LIBCPP_STD_VER >= 17
174179
175180_LIBCPP_END_NAMESPACE_LFTS_V2
176181
......@@ -178,21 +183,23 @@ _LIBCPP_BEGIN_NAMESPACE_STD
178183
179184// hash
180185
181# if _LIBCPP_STD_VER >= 17
186# if _LIBCPP_STD_VER >= 17
182187template <class _Tp>
183188struct hash<experimental::observer_ptr<_Tp>> {
184189 _LIBCPP_HIDE_FROM_ABI size_t operator()(const experimental::observer_ptr<_Tp>& __ptr) const noexcept {
185190 return hash<_Tp*>()(__ptr.get());
186191 }
187192};
188# endif // _LIBCPP_STD_VER >= 17
193# endif // _LIBCPP_STD_VER >= 17
189194
190195_LIBCPP_END_NAMESPACE_STD
191196
192#endif // _LIBCPP_ENABLE_EXPERIMENTAL
197# endif // _LIBCPP_ENABLE_EXPERIMENTAL
193198
194#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
195# include <limits>
196#endif
199# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
200# include <cstddef>
201# include <limits>
202# endif
203#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
197204
198205#endif /* _LIBCPP_EXPERIMENTAL_MEMORY */
lib/libcxx/include/experimental/propagate_const+39-32
......@@ -107,37 +107,42 @@
107107
108108*/
109109
110#include <__functional/operations.h>
111#include <__fwd/functional.h>
112#include <__type_traits/conditional.h>
113#include <__type_traits/decay.h>
114#include <__type_traits/enable_if.h>
115#include <__type_traits/is_array.h>
116#include <__type_traits/is_constructible.h>
117#include <__type_traits/is_convertible.h>
118#include <__type_traits/is_function.h>
119#include <__type_traits/is_pointer.h>
120#include <__type_traits/is_reference.h>
121#include <__type_traits/is_same.h>
122#include <__type_traits/is_swappable.h>
123#include <__type_traits/remove_cv.h>
124#include <__type_traits/remove_pointer.h>
125#include <__type_traits/remove_reference.h>
126#include <__utility/declval.h>
127#include <__utility/forward.h>
128#include <__utility/move.h>
129#include <__utility/swap.h>
130#include <cstddef>
131#include <experimental/__config>
132
133#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
134# pragma GCC system_header
135#endif
110#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
111# include <__cxx03/experimental/propagate_const>
112#else
113# include <__config>
114# include <__cstddef/nullptr_t.h>
115# include <__cstddef/size_t.h>
116# include <__functional/operations.h>
117# include <__fwd/functional.h>
118# include <__type_traits/conditional.h>
119# include <__type_traits/decay.h>
120# include <__type_traits/enable_if.h>
121# include <__type_traits/is_array.h>
122# include <__type_traits/is_constructible.h>
123# include <__type_traits/is_convertible.h>
124# include <__type_traits/is_function.h>
125# include <__type_traits/is_pointer.h>
126# include <__type_traits/is_reference.h>
127# include <__type_traits/is_same.h>
128# include <__type_traits/is_swappable.h>
129# include <__type_traits/remove_cv.h>
130# include <__type_traits/remove_pointer.h>
131# include <__type_traits/remove_reference.h>
132# include <__utility/declval.h>
133# include <__utility/forward.h>
134# include <__utility/move.h>
135# include <__utility/swap.h>
136# include <version>
137
138# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
139# pragma GCC system_header
140# endif
136141
137142_LIBCPP_PUSH_MACROS
138#include <__undef_macros>
143# include <__undef_macros>
139144
140#if _LIBCPP_STD_VER >= 14
145# if _LIBCPP_STD_VER >= 14
141146
142147_LIBCPP_BEGIN_NAMESPACE_LFTS_V2
143148
......@@ -479,12 +484,14 @@ struct greater_equal<experimental::propagate_const<_Tp>> {
479484
480485_LIBCPP_END_NAMESPACE_STD
481486
482#endif // _LIBCPP_STD_VER >= 14
487# endif // _LIBCPP_STD_VER >= 14
483488
484489_LIBCPP_POP_MACROS
485490
486#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
487# include <type_traits>
488#endif
491# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
492# include <cstddef>
493# include <type_traits>
494# endif
495#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
489496
490497#endif // _LIBCPP_EXPERIMENTAL_PROPAGATE_CONST
lib/libcxx/include/experimental/simd+17-9
......@@ -75,14 +75,22 @@ inline namespace parallelism_v2 {
7575# pragma GCC system_header
7676#endif
7777
78#include <experimental/__config>
79#include <experimental/__simd/aligned_tag.h>
80#include <experimental/__simd/declaration.h>
81#include <experimental/__simd/reference.h>
82#include <experimental/__simd/scalar.h>
83#include <experimental/__simd/simd.h>
84#include <experimental/__simd/simd_mask.h>
85#include <experimental/__simd/traits.h>
86#include <experimental/__simd/vec_ext.h>
78#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
79# include <__cxx03/experimental/simd>
80#else
81# include <__config>
82# include <experimental/__simd/aligned_tag.h>
83# include <experimental/__simd/declaration.h>
84# include <experimental/__simd/reference.h>
85# include <experimental/__simd/scalar.h>
86# include <experimental/__simd/simd.h>
87# include <experimental/__simd/simd_mask.h>
88# include <experimental/__simd/traits.h>
89# include <experimental/__simd/vec_ext.h>
90
91# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
92# include <cstddef>
93# endif
94#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
8795
8896#endif /* _LIBCPP_EXPERIMENTAL_SIMD */
lib/libcxx/include/experimental/type_traits+16-8
......@@ -68,16 +68,19 @@ inline namespace fundamentals_v1 {
6868
6969 */
7070
71#include <experimental/__config>
71#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
72# include <__cxx03/experimental/type_traits>
73#else
74# include <__config>
7275
73#if _LIBCPP_STD_VER >= 14
76# if _LIBCPP_STD_VER >= 14
7477
75# include <initializer_list>
76# include <type_traits>
78# include <initializer_list>
79# include <type_traits>
7780
78# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
79# pragma GCC system_header
80# endif
81# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
82# pragma GCC system_header
83# endif
8184
8285_LIBCPP_BEGIN_NAMESPACE_LFTS
8386
......@@ -148,6 +151,11 @@ constexpr bool is_detected_convertible_v = is_detected_convertible<_To, _Op, _Ar
148151
149152_LIBCPP_END_NAMESPACE_LFTS
150153
151#endif /* _LIBCPP_STD_VER >= 14 */
154# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
155# include <cstddef>
156# endif
157
158# endif /* _LIBCPP_STD_VER >= 14 */
159#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
152160
153161#endif /* _LIBCPP_EXPERIMENTAL_TYPE_TRAITS */
lib/libcxx/include/experimental/utility+13-5
......@@ -30,12 +30,15 @@ inline namespace fundamentals_v1 {
3030
3131 */
3232
33#include <experimental/__config>
34#include <utility>
33#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
34# include <__cxx03/experimental/utility>
35#else
36# include <__config>
37# include <utility>
3538
36#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
37# pragma GCC system_header
38#endif
39# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
40# pragma GCC system_header
41# endif
3942
4043_LIBCPP_BEGIN_NAMESPACE_LFTS
4144
......@@ -43,4 +46,9 @@ struct _LIBCPP_TEMPLATE_VIS erased_type {};
4346
4447_LIBCPP_END_NAMESPACE_LFTS
4548
49# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
50# include <cstddef>
51# endif
52#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
53
4654#endif /* _LIBCPP_EXPERIMENTAL_UTILITY */
lib/libcxx/include/ext/hash_map+26-22
......@@ -201,23 +201,26 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
201201
202202*/
203203
204#include <__config>
205#include <__hash_table>
206#include <algorithm>
207#include <ext/__hash>
208#include <functional>
209
210#if defined(__DEPRECATED) && __DEPRECATED
211# if defined(_LIBCPP_WARNING)
204#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
205# include <__cxx03/ext/hash_map>
206#else
207# include <__config>
208# include <__hash_table>
209# include <algorithm>
210# include <ext/__hash>
211# include <functional>
212
213# if defined(__DEPRECATED) && __DEPRECATED
214# if defined(_LIBCPP_WARNING)
212215_LIBCPP_WARNING("Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>")
213# else
214# warning Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>
216# else
217# warning Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>
218# endif
215219# endif
216#endif
217220
218#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
219# pragma GCC system_header
220#endif
221# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
222# pragma GCC system_header
223# endif
221224
222225namespace __gnu_cxx {
223226
......@@ -312,17 +315,17 @@ public:
312315 _LIBCPP_HIDE_FROM_ABI explicit __hash_map_node_destructor(allocator_type& __na)
313316 : __na_(__na), __first_constructed(false), __second_constructed(false) {}
314317
315#ifndef _LIBCPP_CXX03_LANG
318# ifndef _LIBCPP_CXX03_LANG
316319 _LIBCPP_HIDE_FROM_ABI __hash_map_node_destructor(std::__hash_node_destructor<allocator_type>&& __x)
317320 : __na_(__x.__na_), __first_constructed(__x.__value_constructed), __second_constructed(__x.__value_constructed) {
318321 __x.__value_constructed = false;
319322 }
320#else // _LIBCPP_CXX03_LANG
323# else // _LIBCPP_CXX03_LANG
321324 _LIBCPP_HIDE_FROM_ABI __hash_map_node_destructor(const std::__hash_node_destructor<allocator_type>& __x)
322325 : __na_(__x.__na_), __first_constructed(__x.__value_constructed), __second_constructed(__x.__value_constructed) {
323326 const_cast<bool&>(__x.__value_constructed) = false;
324327 }
325#endif // _LIBCPP_CXX03_LANG
328# endif // _LIBCPP_CXX03_LANG
326329
327330 _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) {
328331 if (__second_constructed)
......@@ -863,10 +866,11 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const hash_multimap<_Key, _Tp, _Has
863866
864867} // namespace __gnu_cxx
865868
866#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
867# include <concepts>
868# include <iterator>
869# include <type_traits>
870#endif
869# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
870# include <concepts>
871# include <iterator>
872# include <type_traits>
873# endif
874#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
871875
872876#endif // _LIBCPP_HASH_MAP
lib/libcxx/include/ext/hash_set+23-19
......@@ -192,23 +192,26 @@ template <class Value, class Hash, class Pred, class Alloc>
192192
193193*/
194194
195#include <__config>
196#include <__hash_table>
197#include <algorithm>
198#include <ext/__hash>
199#include <functional>
200
201#if defined(__DEPRECATED) && __DEPRECATED
202# if defined(_LIBCPP_WARNING)
195#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
196# include <__cxx03/ext/hash_set>
197#else
198# include <__config>
199# include <__hash_table>
200# include <algorithm>
201# include <ext/__hash>
202# include <functional>
203
204# if defined(__DEPRECATED) && __DEPRECATED
205# if defined(_LIBCPP_WARNING)
203206_LIBCPP_WARNING("Use of the header <ext/hash_set> is deprecated. Migrate to <unordered_set>")
204# else
205# warning Use of the header <ext/hash_set> is deprecated. Migrate to <unordered_set>
207# else
208# warning Use of the header <ext/hash_set> is deprecated. Migrate to <unordered_set>
209# endif
206210# endif
207#endif
208211
209#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
210# pragma GCC system_header
211#endif
212# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
213# pragma GCC system_header
214# endif
212215
213216namespace __gnu_cxx {
214217
......@@ -575,10 +578,11 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const hash_multiset<_Value, _Hash,
575578
576579} // namespace __gnu_cxx
577580
578#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
579# include <concepts>
580# include <iterator>
581# include <type_traits>
582#endif
581# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
582# include <concepts>
583# include <iterator>
584# include <type_traits>
585# endif
586#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
583587
584588#endif // _LIBCPP_HASH_SET
lib/libcxx/include/fenv.h+46-42
......@@ -49,66 +49,70 @@ int feupdateenv(const fenv_t* envp);
4949
5050*/
5151
52#include <__config>
52#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
53# include <__cxx03/fenv.h>
54#else
55# include <__config>
5356
54#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
55# pragma GCC system_header
56#endif
57# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
58# pragma GCC system_header
59# endif
5760
58#if __has_include_next(<fenv.h>)
59# include_next <fenv.h>
60#endif
61# if __has_include_next(<fenv.h>)
62# include_next <fenv.h>
63# endif
6164
62#ifdef __cplusplus
65# ifdef __cplusplus
6366
6467extern "C++" {
6568
66# ifdef feclearexcept
67# undef feclearexcept
68# endif
69# ifdef feclearexcept
70# undef feclearexcept
71# endif
6972
70# ifdef fegetexceptflag
71# undef fegetexceptflag
72# endif
73# ifdef fegetexceptflag
74# undef fegetexceptflag
75# endif
7376
74# ifdef feraiseexcept
75# undef feraiseexcept
76# endif
77# ifdef feraiseexcept
78# undef feraiseexcept
79# endif
7780
78# ifdef fesetexceptflag
79# undef fesetexceptflag
80# endif
81# ifdef fesetexceptflag
82# undef fesetexceptflag
83# endif
8184
82# ifdef fetestexcept
83# undef fetestexcept
84# endif
85# ifdef fetestexcept
86# undef fetestexcept
87# endif
8588
86# ifdef fegetround
87# undef fegetround
88# endif
89# ifdef fegetround
90# undef fegetround
91# endif
8992
90# ifdef fesetround
91# undef fesetround
92# endif
93# ifdef fesetround
94# undef fesetround
95# endif
9396
94# ifdef fegetenv
95# undef fegetenv
96# endif
97# ifdef fegetenv
98# undef fegetenv
99# endif
97100
98# ifdef feholdexcept
99# undef feholdexcept
100# endif
101# ifdef feholdexcept
102# undef feholdexcept
103# endif
101104
102# ifdef fesetenv
103# undef fesetenv
104# endif
105# ifdef fesetenv
106# undef fesetenv
107# endif
105108
106# ifdef feupdateenv
107# undef feupdateenv
108# endif
109# ifdef feupdateenv
110# undef feupdateenv
111# endif
109112
110113} // extern "C++"
111114
112#endif // defined(__cplusplus)
115# endif // defined(__cplusplus)
116#endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
113117
114118#endif // _LIBCPP_FENV_H
lib/libcxx/include/filesystem+40-36
......@@ -533,45 +533,49 @@ inline constexpr bool std::ranges::enable_view<std::filesystem::recursive_direct
533533
534534*/
535535
536#include <__config>
537
538#if _LIBCPP_STD_VER >= 17
539# include <__filesystem/copy_options.h>
540# include <__filesystem/directory_entry.h>
541# include <__filesystem/directory_iterator.h>
542# include <__filesystem/directory_options.h>
543# include <__filesystem/file_status.h>
544# include <__filesystem/file_time_type.h>
545# include <__filesystem/file_type.h>
546# include <__filesystem/filesystem_error.h>
547# include <__filesystem/operations.h>
548# include <__filesystem/path.h>
549# include <__filesystem/path_iterator.h>
550# include <__filesystem/perm_options.h>
551# include <__filesystem/perms.h>
552# include <__filesystem/recursive_directory_iterator.h>
553# include <__filesystem/space_info.h>
554# include <__filesystem/u8path.h>
555#endif
556
557#include <version>
536#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
537# include <__cxx03/filesystem>
538#else
539# include <__config>
540
541# if _LIBCPP_STD_VER >= 17
542# include <__filesystem/copy_options.h>
543# include <__filesystem/directory_entry.h>
544# include <__filesystem/directory_iterator.h>
545# include <__filesystem/directory_options.h>
546# include <__filesystem/file_status.h>
547# include <__filesystem/file_time_type.h>
548# include <__filesystem/file_type.h>
549# include <__filesystem/filesystem_error.h>
550# include <__filesystem/operations.h>
551# include <__filesystem/path.h>
552# include <__filesystem/path_iterator.h>
553# include <__filesystem/perm_options.h>
554# include <__filesystem/perms.h>
555# include <__filesystem/recursive_directory_iterator.h>
556# include <__filesystem/space_info.h>
557# include <__filesystem/u8path.h>
558# endif
559
560# include <version>
558561
559562// standard-mandated includes
560563
561564// [fs.filesystem.syn]
562#include <compare>
563
564#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
565# pragma GCC system_header
566#endif
567
568#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
569# include <concepts>
570# include <cstdlib>
571# include <cstring>
572# include <iosfwd>
573# include <new>
574# include <system_error>
575#endif
565# include <compare>
566
567# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
568# pragma GCC system_header
569# endif
570
571# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
572# include <concepts>
573# include <cstdlib>
574# include <cstring>
575# include <iosfwd>
576# include <new>
577# include <system_error>
578# endif
579#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
576580
577581#endif // _LIBCPP_FILESYSTEM
lib/libcxx/include/flat_map created+83
......@@ -0,0 +1,83 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_FLAT_MAP
11#define _LIBCPP_FLAT_MAP
12
13/*
14 Header <flat_map> synopsis
15
16#include <compare> // see [compare.syn]
17#include <initializer_list> // see [initializer.list.syn]
18
19namespace std {
20 // [flat.map], class template flat_map
21 template<class Key, class T, class Compare = less<Key>,
22 class KeyContainer = vector<Key>, class MappedContainer = vector<T>>
23 class flat_map;
24
25 struct sorted_unique_t { explicit sorted_unique_t() = default; };
26 inline constexpr sorted_unique_t sorted_unique{};
27
28 template<class Key, class T, class Compare, class KeyContainer, class MappedContainer,
29 class Allocator>
30 struct uses_allocator<flat_map<Key, T, Compare, KeyContainer, MappedContainer>,
31 Allocator>;
32
33 // [flat.map.erasure], erasure for flat_map
34 template<class Key, class T, class Compare, class KeyContainer, class MappedContainer,
35 class Predicate>
36 typename flat_map<Key, T, Compare, KeyContainer, MappedContainer>::size_type
37 erase_if(flat_map<Key, T, Compare, KeyContainer, MappedContainer>& c, Predicate pred);
38
39 // [flat.multimap], class template flat_multimap
40 template<class Key, class T, class Compare = less<Key>,
41 class KeyContainer = vector<Key>, class MappedContainer = vector<T>>
42 class flat_multimap;
43
44 struct sorted_equivalent_t { explicit sorted_equivalent_t() = default; };
45 inline constexpr sorted_equivalent_t sorted_equivalent{};
46
47 template<class Key, class T, class Compare, class KeyContainer, class MappedContainer,
48 class Allocator>
49 struct uses_allocator<flat_multimap<Key, T, Compare, KeyContainer, MappedContainer>,
50 Allocator>;
51
52 // [flat.multimap.erasure], erasure for flat_multimap
53 template<class Key, class T, class Compare, class KeyContainer, class MappedContainer,
54 class Predicate>
55 typename flat_multimap<Key, T, Compare, KeyContainer, MappedContainer>::size_type
56 erase_if(flat_multimap<Key, T, Compare, KeyContainer, MappedContainer>& c, Predicate pred);
57*/
58
59#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
60# include <__cxx03/__config>
61#else
62# include <__config>
63
64# if _LIBCPP_STD_VER >= 23
65# include <__flat_map/flat_map.h>
66# include <__flat_map/flat_multimap.h>
67# include <__flat_map/sorted_equivalent.h>
68# include <__flat_map/sorted_unique.h>
69# endif
70
71// for feature-test macros
72# include <version>
73
74// standard required includes
75# include <compare>
76# include <initializer_list>
77
78# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
79# pragma GCC system_header
80# endif
81#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
82
83#endif // _LIBCPP_FLAT_MAP
lib/libcxx/include/float.h+19-15
......@@ -70,26 +70,30 @@ Macros:
7070
7171*/
7272
73#include <__config>
73#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
74# include <__cxx03/float.h>
75#else
76# include <__config>
7477
75#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
76# pragma GCC system_header
77#endif
78# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
79# pragma GCC system_header
80# endif
7881
79#if __has_include_next(<float.h>)
80# include_next <float.h>
81#endif
82# if __has_include_next(<float.h>)
83# include_next <float.h>
84# endif
8285
83#ifdef __cplusplus
86# ifdef __cplusplus
8487
85# ifndef FLT_EVAL_METHOD
86# define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
87# endif
88# ifndef FLT_EVAL_METHOD
89# define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
90# endif
8891
89# ifndef DECIMAL_DIG
90# define DECIMAL_DIG __DECIMAL_DIG__
91# endif
92# ifndef DECIMAL_DIG
93# define DECIMAL_DIG __DECIMAL_DIG__
94# endif
9295
93#endif // __cplusplus
96# endif // __cplusplus
97#endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
9498
9599#endif // _LIBCPP_FLOAT_H
lib/libcxx/include/format+77-70
......@@ -126,6 +126,9 @@ namespace std {
126126 // [format.formatter], formatter
127127 template<class T, class charT = char> struct formatter;
128128
129 template<class T>
130 constexpr bool enable_nonlocking_formatter_optimization = false; // since C++23
131
129132 // [format.parse.ctx], class template basic_format_parse_context
130133 template<class charT> class basic_format_parse_context;
131134 using format_parse_context = basic_format_parse_context<char>;
......@@ -133,7 +136,7 @@ namespace std {
133136
134137 // [format.range], formatting of ranges
135138 // [format.range.fmtkind], variable template format_kind
136 enum class range_format { // since C++23
139 enum class range_format { // since C++23
137140 disabled,
138141 map,
139142 set,
......@@ -143,20 +146,20 @@ namespace std {
143146 };
144147
145148 template<class R>
146 constexpr unspecified format_kind = unspecified; // since C++23
149 constexpr unspecified format_kind = unspecified; // since C++23
147150
148151 template<ranges::input_range R>
149152 requires same_as<R, remove_cvref_t<R>>
150 constexpr range_format format_kind<R> = see below; // since C++23
153 constexpr range_format format_kind<R> = see below; // since C++23
151154
152155 // [format.range.formatter], class template range_formatter
153156 template<class T, class charT = char>
154157 requires same_as<remove_cvref_t<T>, T> && formattable<T, charT>
155 class range_formatter; // since C++23
158 class range_formatter; // since C++23
156159
157160 // [format.range.fmtdef], class template range-default-formatter
158161 template<range_format K, ranges::input_range R, class charT>
159 struct range-default-formatter; // exposition only, since C++23
162 struct range-default-formatter; // exposition only, since C++23
160163
161164 // [format.range.fmtmap], [format.range.fmtset], [format.range.fmtstr],
162165 // specializations for maps, sets, and strings
......@@ -173,7 +176,7 @@ namespace std {
173176 see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg); // Deprecated in C++26
174177
175178 // [format.arg.store], class template format-arg-store
176 template<class Context, class... Args> struct format-arg-store; // exposition only
179 template<class Context, class... Args> struct format-arg-store; // exposition only
177180
178181 template<class Context = format_context, class... Args>
179182 format-arg-store<Context, Args...>
......@@ -188,70 +191,74 @@ namespace std {
188191
189192*/
190193
191#include <__config>
192
193#if _LIBCPP_STD_VER >= 20
194# include <__format/buffer.h>
195# include <__format/concepts.h>
196# include <__format/container_adaptor.h>
197# include <__format/enable_insertable.h>
198# include <__format/escaped_output_table.h>
199# include <__format/extended_grapheme_cluster_table.h>
200# include <__format/format_arg.h>
201# include <__format/format_arg_store.h>
202# include <__format/format_args.h>
203# include <__format/format_context.h>
204# include <__format/format_error.h>
205# include <__format/format_functions.h>
206# include <__format/format_parse_context.h>
207# include <__format/format_string.h>
208# include <__format/format_to_n_result.h>
209# include <__format/formatter.h>
210# include <__format/formatter_bool.h>
211# include <__format/formatter_char.h>
212# include <__format/formatter_floating_point.h>
213# include <__format/formatter_integer.h>
214# include <__format/formatter_pointer.h>
215# include <__format/formatter_string.h>
216# include <__format/formatter_tuple.h>
217# include <__format/parser_std_format_spec.h>
218# include <__format/range_default_formatter.h>
219# include <__format/range_formatter.h>
220# include <__format/unicode.h>
221# include <__fwd/format.h>
222#endif
223
224#include <version>
225
226#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
227# pragma GCC system_header
228#endif
229
230#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
231# include <array>
232# include <cctype>
233# include <cerrno>
234# include <clocale>
235# include <cmath>
236# include <cstddef>
237# include <cstdint>
238# include <cstdlib>
239# include <cstring>
240# include <initializer_list>
241# include <limits>
242# include <locale>
243# include <new>
244# include <optional>
245# include <queue>
246# include <stack>
247# include <stdexcept>
248# include <string>
249# include <string_view>
250# include <tuple>
251
252# if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
253# include <cwchar>
194#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
195# include <__cxx03/format>
196#else
197# include <__config>
198
199# if _LIBCPP_STD_VER >= 20
200# include <__format/buffer.h>
201# include <__format/concepts.h>
202# include <__format/container_adaptor.h>
203# include <__format/enable_insertable.h>
204# include <__format/escaped_output_table.h>
205# include <__format/extended_grapheme_cluster_table.h>
206# include <__format/format_arg.h>
207# include <__format/format_arg_store.h>
208# include <__format/format_args.h>
209# include <__format/format_context.h>
210# include <__format/format_error.h>
211# include <__format/format_functions.h>
212# include <__format/format_parse_context.h>
213# include <__format/format_string.h>
214# include <__format/format_to_n_result.h>
215# include <__format/formatter.h>
216# include <__format/formatter_bool.h>
217# include <__format/formatter_char.h>
218# include <__format/formatter_floating_point.h>
219# include <__format/formatter_integer.h>
220# include <__format/formatter_pointer.h>
221# include <__format/formatter_string.h>
222# include <__format/formatter_tuple.h>
223# include <__format/parser_std_format_spec.h>
224# include <__format/range_default_formatter.h>
225# include <__format/range_formatter.h>
226# include <__format/unicode.h>
227# include <__fwd/format.h>
228# endif
229
230# include <version>
231
232# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
233# pragma GCC system_header
234# endif
235
236# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
237# include <array>
238# include <cctype>
239# include <cerrno>
240# include <clocale>
241# include <cmath>
242# include <cstddef>
243# include <cstdint>
244# include <cstdlib>
245# include <cstring>
246# include <initializer_list>
247# include <limits>
248# include <locale>
249# include <new>
250# include <optional>
251# include <queue>
252# include <stack>
253# include <stdexcept>
254# include <string>
255# include <string_view>
256# include <tuple>
257
258# if _LIBCPP_HAS_WIDE_CHARACTERS
259# include <cwchar>
260# endif
254261# endif
255#endif
262#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
256263
257264#endif // _LIBCPP_FORMAT
lib/libcxx/include/forward_list+255-229
......@@ -195,62 +195,70 @@ template <class T, class Allocator, class Predicate>
195195
196196*/
197197
198#include <__algorithm/comp.h>
199#include <__algorithm/lexicographical_compare.h>
200#include <__algorithm/lexicographical_compare_three_way.h>
201#include <__algorithm/min.h>
202#include <__config>
203#include <__iterator/distance.h>
204#include <__iterator/iterator_traits.h>
205#include <__iterator/move_iterator.h>
206#include <__iterator/next.h>
207#include <__memory/addressof.h>
208#include <__memory/allocation_guard.h>
209#include <__memory/allocator.h>
210#include <__memory/allocator_traits.h>
211#include <__memory/compressed_pair.h>
212#include <__memory/construct_at.h>
213#include <__memory/pointer_traits.h>
214#include <__memory/swap_allocator.h>
215#include <__memory_resource/polymorphic_allocator.h>
216#include <__ranges/access.h>
217#include <__ranges/concepts.h>
218#include <__ranges/container_compatible_range.h>
219#include <__ranges/from_range.h>
220#include <__type_traits/conditional.h>
221#include <__type_traits/is_allocator.h>
222#include <__type_traits/is_const.h>
223#include <__type_traits/is_nothrow_assignable.h>
224#include <__type_traits/is_nothrow_constructible.h>
225#include <__type_traits/is_pointer.h>
226#include <__type_traits/is_same.h>
227#include <__type_traits/is_swappable.h>
228#include <__type_traits/type_identity.h>
229#include <__utility/forward.h>
230#include <__utility/move.h>
231#include <limits>
232#include <new> // __launder
233#include <version>
198#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
199# include <__cxx03/forward_list>
200#else
201# include <__algorithm/comp.h>
202# include <__algorithm/lexicographical_compare.h>
203# include <__algorithm/lexicographical_compare_three_way.h>
204# include <__algorithm/min.h>
205# include <__assert>
206# include <__config>
207# include <__cstddef/nullptr_t.h>
208# include <__iterator/distance.h>
209# include <__iterator/iterator_traits.h>
210# include <__iterator/move_iterator.h>
211# include <__iterator/next.h>
212# include <__memory/addressof.h>
213# include <__memory/allocation_guard.h>
214# include <__memory/allocator.h>
215# include <__memory/allocator_traits.h>
216# include <__memory/compressed_pair.h>
217# include <__memory/construct_at.h>
218# include <__memory/pointer_traits.h>
219# include <__memory/swap_allocator.h>
220# include <__memory_resource/polymorphic_allocator.h>
221# include <__new/launder.h>
222# include <__ranges/access.h>
223# include <__ranges/concepts.h>
224# include <__ranges/container_compatible_range.h>
225# include <__ranges/from_range.h>
226# include <__type_traits/conditional.h>
227# include <__type_traits/container_traits.h>
228# include <__type_traits/enable_if.h>
229# include <__type_traits/is_allocator.h>
230# include <__type_traits/is_const.h>
231# include <__type_traits/is_nothrow_assignable.h>
232# include <__type_traits/is_nothrow_constructible.h>
233# include <__type_traits/is_pointer.h>
234# include <__type_traits/is_same.h>
235# include <__type_traits/is_swappable.h>
236# include <__type_traits/type_identity.h>
237# include <__utility/forward.h>
238# include <__utility/move.h>
239# include <__utility/swap.h>
240# include <limits>
241# include <version>
234242
235243// standard-mandated includes
236244
237245// [iterator.range]
238#include <__iterator/access.h>
239#include <__iterator/data.h>
240#include <__iterator/empty.h>
241#include <__iterator/reverse_access.h>
242#include <__iterator/size.h>
246# include <__iterator/access.h>
247# include <__iterator/data.h>
248# include <__iterator/empty.h>
249# include <__iterator/reverse_access.h>
250# include <__iterator/size.h>
243251
244252// [forward.list.syn]
245#include <compare>
246#include <initializer_list>
253# include <compare>
254# include <initializer_list>
247255
248#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
249# pragma GCC system_header
250#endif
256# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
257# pragma GCC system_header
258# endif
251259
252260_LIBCPP_PUSH_MACROS
253#include <__undef_macros>
261# include <__undef_macros>
254262
255263_LIBCPP_BEGIN_NAMESPACE_STD
256264
......@@ -276,18 +284,20 @@ struct __forward_node_traits {
276284 typedef __rebind_pointer_t<_NodePtr, __begin_node> __begin_node_pointer;
277285 typedef __rebind_pointer_t<_NodePtr, void> __void_pointer;
278286
279#if defined(_LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB)
280 typedef __begin_node_pointer __iter_node_pointer;
281#else
282 typedef __conditional_t<is_pointer<__void_pointer>::value, __begin_node_pointer, __node_pointer> __iter_node_pointer;
283#endif
284
285 typedef __conditional_t<is_same<__iter_node_pointer, __node_pointer>::value, __begin_node_pointer, __node_pointer>
286 __non_iter_node_pointer;
287// TODO(LLVM 22): Remove this check
288# ifndef _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
289 static_assert(sizeof(__begin_node_pointer) == sizeof(__node_pointer) && _LIBCPP_ALIGNOF(__begin_node_pointer) ==
290 _LIBCPP_ALIGNOF(__node_pointer),
291 "It looks like you are using std::forward_list with a fancy pointer type that thas a different "
292 "representation depending on whether it points to a forward_list base pointer or a forward_list node "
293 "pointer (both of which are implementation details of the standard library). This means that your ABI "
294 "is being broken between LLVM 19 and LLVM 20. If you don't care about your ABI being broken, define "
295 "the _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB macro to silence this diagnostic.");
296# endif
287297
288 _LIBCPP_HIDE_FROM_ABI static __iter_node_pointer __as_iter_node(__iter_node_pointer __p) { return __p; }
289 _LIBCPP_HIDE_FROM_ABI static __iter_node_pointer __as_iter_node(__non_iter_node_pointer __p) {
290 return static_cast<__iter_node_pointer>(static_cast<__void_pointer>(__p));
298 _LIBCPP_HIDE_FROM_ABI static __begin_node_pointer __as_iter_node(__begin_node_pointer __p) { return __p; }
299 _LIBCPP_HIDE_FROM_ABI static __begin_node_pointer __as_iter_node(__node_pointer __p) {
300 return static_cast<__begin_node_pointer>(static_cast<__void_pointer>(__p));
291301 }
292302};
293303
......@@ -307,7 +317,8 @@ struct __forward_begin_node {
307317};
308318
309319template <class _Tp, class _VoidPtr>
310using __begin_node_of = __forward_begin_node<__rebind_pointer_t<_VoidPtr, __forward_list_node<_Tp, _VoidPtr> > >;
320using __begin_node_of _LIBCPP_NODEBUG =
321 __forward_begin_node<__rebind_pointer_t<_VoidPtr, __forward_list_node<_Tp, _VoidPtr> > >;
311322
312323template <class _Tp, class _VoidPtr>
313324struct __forward_list_node : public __begin_node_of<_Tp, _VoidPtr> {
......@@ -317,7 +328,7 @@ struct __forward_list_node : public __begin_node_of<_Tp, _VoidPtr> {
317328
318329 // We allow starting the lifetime of nodes without initializing the value held by the node,
319330 // since that is handled by the list itself in order to be allocator-aware.
320#ifndef _LIBCPP_CXX03_LANG
331# ifndef _LIBCPP_CXX03_LANG
321332
322333private:
323334 union {
......@@ -326,14 +337,14 @@ private:
326337
327338public:
328339 _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return __value_; }
329#else
340# else
330341
331342private:
332343 _ALIGNAS_TYPE(_Tp) char __buffer_[sizeof(_Tp)];
333344
334345public:
335346 _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return *std::__launder(reinterpret_cast<_Tp*>(&__buffer_)); }
336#endif
347# endif
337348
338349 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_node(_NodePtr __next) : _Base(__next) {}
339350 _LIBCPP_HIDE_FROM_ABI ~__forward_list_node() {}
......@@ -349,10 +360,9 @@ class _LIBCPP_TEMPLATE_VIS __forward_list_iterator {
349360 typedef __forward_node_traits<_NodePtr> __traits;
350361 typedef typename __traits::__node_pointer __node_pointer;
351362 typedef typename __traits::__begin_node_pointer __begin_node_pointer;
352 typedef typename __traits::__iter_node_pointer __iter_node_pointer;
353363 typedef typename __traits::__void_pointer __void_pointer;
354364
355 __iter_node_pointer __ptr_;
365 __begin_node_pointer __ptr_;
356366
357367 _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __get_begin() const {
358368 return static_cast<__begin_node_pointer>(static_cast<__void_pointer>(__ptr_));
......@@ -415,10 +425,9 @@ class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator {
415425 typedef typename __traits::__node_type __node_type;
416426 typedef typename __traits::__node_pointer __node_pointer;
417427 typedef typename __traits::__begin_node_pointer __begin_node_pointer;
418 typedef typename __traits::__iter_node_pointer __iter_node_pointer;
419428 typedef typename __traits::__void_pointer __void_pointer;
420429
421 __iter_node_pointer __ptr_;
430 __begin_node_pointer __ptr_;
422431
423432 _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __get_begin() const {
424433 return static_cast<__begin_node_pointer>(static_cast<__void_pointer>(__ptr_));
......@@ -490,34 +499,31 @@ protected:
490499 typedef __rebind_alloc<allocator_traits<allocator_type>, __begin_node> __begin_node_allocator;
491500 typedef typename allocator_traits<__begin_node_allocator>::pointer __begin_node_pointer;
492501
493 __compressed_pair<__begin_node, __node_allocator> __before_begin_;
502 _LIBCPP_COMPRESSED_PAIR(__begin_node, __before_begin_, __node_allocator, __alloc_);
494503
495504 _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __before_begin() _NOEXCEPT {
496 return pointer_traits<__begin_node_pointer>::pointer_to(__before_begin_.first());
505 return pointer_traits<__begin_node_pointer>::pointer_to(__before_begin_);
497506 }
498507 _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __before_begin() const _NOEXCEPT {
499 return pointer_traits<__begin_node_pointer>::pointer_to(const_cast<__begin_node&>(__before_begin_.first()));
508 return pointer_traits<__begin_node_pointer>::pointer_to(const_cast<__begin_node&>(__before_begin_));
500509 }
501510
502 _LIBCPP_HIDE_FROM_ABI __node_allocator& __alloc() _NOEXCEPT { return __before_begin_.second(); }
503 _LIBCPP_HIDE_FROM_ABI const __node_allocator& __alloc() const _NOEXCEPT { return __before_begin_.second(); }
504
505511 typedef __forward_list_iterator<__node_pointer> iterator;
506512 typedef __forward_list_const_iterator<__node_pointer> const_iterator;
507513
508514 _LIBCPP_HIDE_FROM_ABI __forward_list_base() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
509 : __before_begin_(__begin_node(), __default_init_tag()) {}
515 : __before_begin_(__begin_node()) {}
510516 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_base(const allocator_type& __a)
511 : __before_begin_(__begin_node(), __node_allocator(__a)) {}
517 : __before_begin_(__begin_node()), __alloc_(__node_allocator(__a)) {}
512518 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_base(const __node_allocator& __a)
513 : __before_begin_(__begin_node(), __a) {}
519 : __before_begin_(__begin_node()), __alloc_(__a) {}
514520
515521public:
516#ifndef _LIBCPP_CXX03_LANG
522# ifndef _LIBCPP_CXX03_LANG
517523 _LIBCPP_HIDE_FROM_ABI
518524 __forward_list_base(__forward_list_base&& __x) noexcept(is_nothrow_move_constructible<__node_allocator>::value);
519525 _LIBCPP_HIDE_FROM_ABI __forward_list_base(__forward_list_base&& __x, const allocator_type& __a);
520#endif // _LIBCPP_CXX03_LANG
526# endif // _LIBCPP_CXX03_LANG
521527
522528 __forward_list_base(const __forward_list_base&) = delete;
523529 __forward_list_base& operator=(const __forward_list_base&) = delete;
......@@ -537,8 +543,7 @@ protected:
537543
538544 template <class... _Args>
539545 _LIBCPP_HIDE_FROM_ABI __node_pointer __create_node(__node_pointer __next, _Args&&... __args) {
540 __node_allocator& __a = __alloc();
541 __allocation_guard<__node_allocator> __guard(__a, 1);
546 __allocation_guard<__node_allocator> __guard(__alloc_, 1);
542547 // Begin the lifetime of the node itself. Note that this doesn't begin the lifetime of the value
543548 // held inside the node, since we need to use the allocator's construct() method for that.
544549 //
......@@ -548,26 +553,25 @@ protected:
548553 std::__construct_at(std::addressof(*__guard.__get()), __next);
549554
550555 // Now construct the value_type using the allocator's construct() method.
551 __node_traits::construct(__a, std::addressof(__guard.__get()->__get_value()), std::forward<_Args>(__args)...);
556 __node_traits::construct(__alloc_, std::addressof(__guard.__get()->__get_value()), std::forward<_Args>(__args)...);
552557 return __guard.__release_ptr();
553558 }
554559
555560 _LIBCPP_HIDE_FROM_ABI void __delete_node(__node_pointer __node) {
556561 // For the same reason as above, we use the allocator's destroy() method for the value_type,
557562 // but not for the node itself.
558 __node_allocator& __a = __alloc();
559 __node_traits::destroy(__a, std::addressof(__node->__get_value()));
563 __node_traits::destroy(__alloc_, std::addressof(__node->__get_value()));
560564 std::__destroy_at(std::addressof(*__node));
561 __node_traits::deallocate(__a, __node, 1);
565 __node_traits::deallocate(__alloc_, __node, 1);
562566 }
563567
564568public:
565569 _LIBCPP_HIDE_FROM_ABI void swap(__forward_list_base& __x)
566#if _LIBCPP_STD_VER >= 14
570# if _LIBCPP_STD_VER >= 14
567571 _NOEXCEPT;
568#else
572# else
569573 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<__node_allocator>);
570#endif
574# endif
571575
572576protected:
573577 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT;
......@@ -575,37 +579,37 @@ protected:
575579private:
576580 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __forward_list_base&, false_type) {}
577581 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __forward_list_base& __x, true_type) {
578 if (__alloc() != __x.__alloc())
582 if (__alloc_ != __x.__alloc_)
579583 clear();
580 __alloc() = __x.__alloc();
584 __alloc_ = __x.__alloc_;
581585 }
582586
583587 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__forward_list_base&, false_type) _NOEXCEPT {}
584588 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__forward_list_base& __x, true_type)
585589 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) {
586 __alloc() = std::move(__x.__alloc());
590 __alloc_ = std::move(__x.__alloc_);
587591 }
588592};
589593
590#ifndef _LIBCPP_CXX03_LANG
594# ifndef _LIBCPP_CXX03_LANG
591595
592596template <class _Tp, class _Alloc>
593597inline __forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x) noexcept(
594598 is_nothrow_move_constructible<__node_allocator>::value)
595 : __before_begin_(std::move(__x.__before_begin_)) {
599 : __before_begin_(std::move(__x.__before_begin_)), __alloc_(std::move(__x.__alloc_)) {
596600 __x.__before_begin()->__next_ = nullptr;
597601}
598602
599603template <class _Tp, class _Alloc>
600604inline __forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x, const allocator_type& __a)
601 : __before_begin_(__begin_node(), __node_allocator(__a)) {
602 if (__alloc() == __x.__alloc()) {
605 : __before_begin_(__begin_node()), __alloc_(__node_allocator(__a)) {
606 if (__alloc_ == __x.__alloc_) {
603607 __before_begin()->__next_ = __x.__before_begin()->__next_;
604608 __x.__before_begin()->__next_ = nullptr;
605609 }
606610}
607611
608#endif // _LIBCPP_CXX03_LANG
612# endif // _LIBCPP_CXX03_LANG
609613
610614template <class _Tp, class _Alloc>
611615__forward_list_base<_Tp, _Alloc>::~__forward_list_base() {
......@@ -614,14 +618,13 @@ __forward_list_base<_Tp, _Alloc>::~__forward_list_base() {
614618
615619template <class _Tp, class _Alloc>
616620inline void __forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x)
617#if _LIBCPP_STD_VER >= 14
621# if _LIBCPP_STD_VER >= 14
618622 _NOEXCEPT
619#else
623# else
620624 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<__node_allocator>)
621#endif
625# endif
622626{
623 std::__swap_allocator(
624 __alloc(), __x.__alloc(), integral_constant<bool, __node_traits::propagate_on_container_swap::value>());
627 std::__swap_allocator(__alloc_, __x.__alloc_);
625628 using std::swap;
626629 swap(__before_begin()->__next_, __x.__before_begin()->__next_);
627630}
......@@ -638,12 +641,12 @@ void __forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT {
638641
639642template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
640643class _LIBCPP_TEMPLATE_VIS forward_list : private __forward_list_base<_Tp, _Alloc> {
641 typedef __forward_list_base<_Tp, _Alloc> base;
642 typedef typename base::__node_allocator __node_allocator;
643 typedef typename base::__node_type __node_type;
644 typedef typename base::__node_traits __node_traits;
645 typedef typename base::__node_pointer __node_pointer;
646 typedef typename base::__begin_node_pointer __begin_node_pointer;
644 typedef __forward_list_base<_Tp, _Alloc> __base;
645 typedef typename __base::__node_allocator __node_allocator;
646 typedef typename __base::__node_type __node_type;
647 typedef typename __base::__node_traits __node_traits;
648 typedef typename __base::__node_pointer __node_pointer;
649 typedef typename __base::__begin_node_pointer __begin_node_pointer;
647650
648651public:
649652 typedef _Tp value_type;
......@@ -664,25 +667,25 @@ public:
664667 typedef typename allocator_traits<allocator_type>::size_type size_type;
665668 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
666669
667 typedef typename base::iterator iterator;
668 typedef typename base::const_iterator const_iterator;
669#if _LIBCPP_STD_VER >= 20
670 typedef typename __base::iterator iterator;
671 typedef typename __base::const_iterator const_iterator;
672# if _LIBCPP_STD_VER >= 20
670673 typedef size_type __remove_return_type;
671#else
674# else
672675 typedef void __remove_return_type;
673#endif
676# endif
674677
675678 _LIBCPP_HIDE_FROM_ABI forward_list() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) {
676679 } // = default;
677680 _LIBCPP_HIDE_FROM_ABI explicit forward_list(const allocator_type& __a);
678681 _LIBCPP_HIDE_FROM_ABI explicit forward_list(size_type __n);
679#if _LIBCPP_STD_VER >= 14
682# if _LIBCPP_STD_VER >= 14
680683 _LIBCPP_HIDE_FROM_ABI explicit forward_list(size_type __n, const allocator_type& __a);
681#endif
684# endif
682685 _LIBCPP_HIDE_FROM_ABI forward_list(size_type __n, const value_type& __v);
683686
684687 template <__enable_if_t<__is_allocator<_Alloc>::value, int> = 0>
685 _LIBCPP_HIDE_FROM_ABI forward_list(size_type __n, const value_type& __v, const allocator_type& __a) : base(__a) {
688 _LIBCPP_HIDE_FROM_ABI forward_list(size_type __n, const value_type& __v, const allocator_type& __a) : __base(__a) {
686689 insert_after(cbefore_begin(), __n, __v);
687690 }
688691
......@@ -692,22 +695,22 @@ public:
692695 template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
693696 _LIBCPP_HIDE_FROM_ABI forward_list(_InputIterator __f, _InputIterator __l, const allocator_type& __a);
694697
695#if _LIBCPP_STD_VER >= 23
698# if _LIBCPP_STD_VER >= 23
696699 template <_ContainerCompatibleRange<_Tp> _Range>
697700 _LIBCPP_HIDE_FROM_ABI forward_list(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
698 : base(__a) {
701 : __base(__a) {
699702 prepend_range(std::forward<_Range>(__range));
700703 }
701#endif
704# endif
702705
703706 _LIBCPP_HIDE_FROM_ABI forward_list(const forward_list& __x);
704707 _LIBCPP_HIDE_FROM_ABI forward_list(const forward_list& __x, const __type_identity_t<allocator_type>& __a);
705708
706709 _LIBCPP_HIDE_FROM_ABI forward_list& operator=(const forward_list& __x);
707710
708#ifndef _LIBCPP_CXX03_LANG
709 _LIBCPP_HIDE_FROM_ABI forward_list(forward_list&& __x) noexcept(is_nothrow_move_constructible<base>::value)
710 : base(std::move(__x)) {}
711# ifndef _LIBCPP_CXX03_LANG
712 _LIBCPP_HIDE_FROM_ABI forward_list(forward_list&& __x) noexcept(is_nothrow_move_constructible<__base>::value)
713 : __base(std::move(__x)) {}
711714 _LIBCPP_HIDE_FROM_ABI forward_list(forward_list&& __x, const __type_identity_t<allocator_type>& __a);
712715
713716 _LIBCPP_HIDE_FROM_ABI forward_list(initializer_list<value_type> __il);
......@@ -720,74 +723,82 @@ public:
720723 _LIBCPP_HIDE_FROM_ABI forward_list& operator=(initializer_list<value_type> __il);
721724
722725 _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<value_type> __il);
723#endif // _LIBCPP_CXX03_LANG
726# endif // _LIBCPP_CXX03_LANG
724727
725728 // ~forward_list() = default;
726729
727730 template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
728731 void _LIBCPP_HIDE_FROM_ABI assign(_InputIterator __f, _InputIterator __l);
729732
730#if _LIBCPP_STD_VER >= 23
733# if _LIBCPP_STD_VER >= 23
731734 template <_ContainerCompatibleRange<_Tp> _Range>
732735 _LIBCPP_HIDE_FROM_ABI void assign_range(_Range&& __range) {
733736 __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
734737 }
735#endif
738# endif
736739
737740 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const value_type& __v);
738741
739 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT { return allocator_type(base::__alloc()); }
742 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT { return allocator_type(this->__alloc_); }
740743
741 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return iterator(base::__before_begin()->__next_); }
744 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return iterator(__base::__before_begin()->__next_); }
742745 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT {
743 return const_iterator(base::__before_begin()->__next_);
746 return const_iterator(__base::__before_begin()->__next_);
744747 }
745748 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return iterator(nullptr); }
746749 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return const_iterator(nullptr); }
747750
748751 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT {
749 return const_iterator(base::__before_begin()->__next_);
752 return const_iterator(__base::__before_begin()->__next_);
750753 }
751754 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return const_iterator(nullptr); }
752755
753 _LIBCPP_HIDE_FROM_ABI iterator before_begin() _NOEXCEPT { return iterator(base::__before_begin()); }
754 _LIBCPP_HIDE_FROM_ABI const_iterator before_begin() const _NOEXCEPT { return const_iterator(base::__before_begin()); }
756 _LIBCPP_HIDE_FROM_ABI iterator before_begin() _NOEXCEPT { return iterator(__base::__before_begin()); }
757 _LIBCPP_HIDE_FROM_ABI const_iterator before_begin() const _NOEXCEPT {
758 return const_iterator(__base::__before_begin());
759 }
755760 _LIBCPP_HIDE_FROM_ABI const_iterator cbefore_begin() const _NOEXCEPT {
756 return const_iterator(base::__before_begin());
761 return const_iterator(__base::__before_begin());
757762 }
758763
759 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT {
760 return base::__before_begin()->__next_ == nullptr;
764 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT {
765 return __base::__before_begin()->__next_ == nullptr;
761766 }
762767 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
763 return std::min<size_type>(__node_traits::max_size(base::__alloc()), numeric_limits<difference_type>::max());
768 return std::min<size_type>(__node_traits::max_size(this->__alloc_), numeric_limits<difference_type>::max());
764769 }
765770
766 _LIBCPP_HIDE_FROM_ABI reference front() { return base::__before_begin()->__next_->__get_value(); }
767 _LIBCPP_HIDE_FROM_ABI const_reference front() const { return base::__before_begin()->__next_->__get_value(); }
771 _LIBCPP_HIDE_FROM_ABI reference front() {
772 _LIBCPP_ASSERT_NON_NULL(!empty(), "forward_list::front called on an empty list");
773 return __base::__before_begin()->__next_->__get_value();
774 }
775 _LIBCPP_HIDE_FROM_ABI const_reference front() const {
776 _LIBCPP_ASSERT_NON_NULL(!empty(), "forward_list::front called on an empty list");
777 return __base::__before_begin()->__next_->__get_value();
778 }
768779
769#ifndef _LIBCPP_CXX03_LANG
770# if _LIBCPP_STD_VER >= 17
780# ifndef _LIBCPP_CXX03_LANG
781# if _LIBCPP_STD_VER >= 17
771782 template <class... _Args>
772783 _LIBCPP_HIDE_FROM_ABI reference emplace_front(_Args&&... __args);
773# else
784# else
774785 template <class... _Args>
775786 _LIBCPP_HIDE_FROM_ABI void emplace_front(_Args&&... __args);
776# endif
787# endif
777788 _LIBCPP_HIDE_FROM_ABI void push_front(value_type&& __v);
778#endif // _LIBCPP_CXX03_LANG
789# endif // _LIBCPP_CXX03_LANG
779790 _LIBCPP_HIDE_FROM_ABI void push_front(const value_type& __v);
780791
781#if _LIBCPP_STD_VER >= 23
792# if _LIBCPP_STD_VER >= 23
782793 template <_ContainerCompatibleRange<_Tp> _Range>
783794 _LIBCPP_HIDE_FROM_ABI void prepend_range(_Range&& __range) {
784795 insert_range_after(cbefore_begin(), std::forward<_Range>(__range));
785796 }
786#endif
797# endif
787798
788799 _LIBCPP_HIDE_FROM_ABI void pop_front();
789800
790#ifndef _LIBCPP_CXX03_LANG
801# ifndef _LIBCPP_CXX03_LANG
791802 template <class... _Args>
792803 _LIBCPP_HIDE_FROM_ABI iterator emplace_after(const_iterator __p, _Args&&... __args);
793804
......@@ -795,18 +806,18 @@ public:
795806 _LIBCPP_HIDE_FROM_ABI iterator insert_after(const_iterator __p, initializer_list<value_type> __il) {
796807 return insert_after(__p, __il.begin(), __il.end());
797808 }
798#endif // _LIBCPP_CXX03_LANG
809# endif // _LIBCPP_CXX03_LANG
799810 _LIBCPP_HIDE_FROM_ABI iterator insert_after(const_iterator __p, const value_type& __v);
800811 _LIBCPP_HIDE_FROM_ABI iterator insert_after(const_iterator __p, size_type __n, const value_type& __v);
801812 template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
802813 _LIBCPP_HIDE_FROM_ABI iterator insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l);
803814
804#if _LIBCPP_STD_VER >= 23
815# if _LIBCPP_STD_VER >= 23
805816 template <_ContainerCompatibleRange<_Tp> _Range>
806817 _LIBCPP_HIDE_FROM_ABI iterator insert_range_after(const_iterator __position, _Range&& __range) {
807818 return __insert_after_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
808819 }
809#endif
820# endif
810821
811822 template <class _InputIterator, class _Sentinel>
812823 _LIBCPP_HIDE_FROM_ABI iterator __insert_after_with_sentinel(const_iterator __p, _InputIterator __f, _Sentinel __l);
......@@ -815,18 +826,18 @@ public:
815826 _LIBCPP_HIDE_FROM_ABI iterator erase_after(const_iterator __f, const_iterator __l);
816827
817828 _LIBCPP_HIDE_FROM_ABI void swap(forward_list& __x)
818#if _LIBCPP_STD_VER >= 14
829# if _LIBCPP_STD_VER >= 14
819830 _NOEXCEPT
820#else
831# else
821832 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<__node_allocator>)
822#endif
833# endif
823834 {
824 base::swap(__x);
835 __base::swap(__x);
825836 }
826837
827838 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n);
828839 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n, const value_type& __v);
829 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { base::clear(); }
840 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __base::clear(); }
830841
831842 _LIBCPP_HIDE_FROM_ABI void splice_after(const_iterator __p, forward_list&& __x);
832843 _LIBCPP_HIDE_FROM_ABI void splice_after(const_iterator __p, forward_list&& __x, const_iterator __i);
......@@ -842,13 +853,13 @@ public:
842853 _LIBCPP_HIDE_FROM_ABI __remove_return_type unique() { return unique(__equal_to()); }
843854 template <class _BinaryPredicate>
844855 _LIBCPP_HIDE_FROM_ABI __remove_return_type unique(_BinaryPredicate __binary_pred);
845#ifndef _LIBCPP_CXX03_LANG
856# ifndef _LIBCPP_CXX03_LANG
846857 _LIBCPP_HIDE_FROM_ABI void merge(forward_list&& __x) { merge(__x, __less<>()); }
847858 template <class _Compare>
848859 _LIBCPP_HIDE_FROM_ABI void merge(forward_list&& __x, _Compare __comp) {
849860 merge(__x, std::move(__comp));
850861 }
851#endif // _LIBCPP_CXX03_LANG
862# endif // _LIBCPP_CXX03_LANG
852863 _LIBCPP_HIDE_FROM_ABI void merge(forward_list& __x) { merge(__x, __less<>()); }
853864 template <class _Compare>
854865 _LIBCPP_HIDE_FROM_ABI void merge(forward_list& __x, _Compare __comp);
......@@ -858,11 +869,11 @@ public:
858869 _LIBCPP_HIDE_FROM_ABI void reverse() _NOEXCEPT;
859870
860871private:
861#ifndef _LIBCPP_CXX03_LANG
872# ifndef _LIBCPP_CXX03_LANG
862873 _LIBCPP_HIDE_FROM_ABI void __move_assign(forward_list& __x, true_type)
863874 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
864875 _LIBCPP_HIDE_FROM_ABI void __move_assign(forward_list& __x, false_type);
865#endif // _LIBCPP_CXX03_LANG
876# endif // _LIBCPP_CXX03_LANG
866877
867878 template <class _Iter, class _Sent>
868879 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iter __f, _Sent __l);
......@@ -875,7 +886,7 @@ private:
875886 static _LIBCPP_HIDDEN __node_pointer __sort(__node_pointer __f, difference_type __sz, _Compare& __comp);
876887};
877888
878#if _LIBCPP_STD_VER >= 17
889# if _LIBCPP_STD_VER >= 17
879890template <class _InputIterator,
880891 class _Alloc = allocator<__iter_value_type<_InputIterator>>,
881892 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
......@@ -887,37 +898,37 @@ template <class _InputIterator,
887898 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
888899 class = enable_if_t<__is_allocator<_Alloc>::value> >
889900forward_list(_InputIterator, _InputIterator, _Alloc) -> forward_list<__iter_value_type<_InputIterator>, _Alloc>;
890#endif
901# endif
891902
892#if _LIBCPP_STD_VER >= 23
903# if _LIBCPP_STD_VER >= 23
893904template <ranges::input_range _Range,
894905 class _Alloc = allocator<ranges::range_value_t<_Range>>,
895906 class = enable_if_t<__is_allocator<_Alloc>::value> >
896907forward_list(from_range_t, _Range&&, _Alloc = _Alloc()) -> forward_list<ranges::range_value_t<_Range>, _Alloc>;
897#endif
908# endif
898909
899910template <class _Tp, class _Alloc>
900inline forward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a) : base(__a) {}
911inline forward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a) : __base(__a) {}
901912
902913template <class _Tp, class _Alloc>
903914forward_list<_Tp, _Alloc>::forward_list(size_type __n) {
904915 if (__n > 0) {
905 for (__begin_node_pointer __p = base::__before_begin(); __n > 0; --__n, __p = __p->__next_as_begin()) {
916 for (__begin_node_pointer __p = __base::__before_begin(); __n > 0; --__n, __p = __p->__next_as_begin()) {
906917 __p->__next_ = this->__create_node(/* next = */ nullptr);
907918 }
908919 }
909920}
910921
911#if _LIBCPP_STD_VER >= 14
922# if _LIBCPP_STD_VER >= 14
912923template <class _Tp, class _Alloc>
913forward_list<_Tp, _Alloc>::forward_list(size_type __n, const allocator_type& __base_alloc) : base(__base_alloc) {
924forward_list<_Tp, _Alloc>::forward_list(size_type __n, const allocator_type& __base_alloc) : __base(__base_alloc) {
914925 if (__n > 0) {
915 for (__begin_node_pointer __p = base::__before_begin(); __n > 0; --__n, __p = __p->__next_as_begin()) {
926 for (__begin_node_pointer __p = __base::__before_begin(); __n > 0; --__n, __p = __p->__next_as_begin()) {
916927 __p->__next_ = this->__create_node(/* next = */ nullptr);
917928 }
918929 }
919930}
920#endif
931# endif
921932
922933template <class _Tp, class _Alloc>
923934forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v) {
......@@ -932,36 +943,37 @@ forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l)
932943
933944template <class _Tp, class _Alloc>
934945template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> >
935forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l, const allocator_type& __a) : base(__a) {
946forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
947 : __base(__a) {
936948 insert_after(cbefore_begin(), __f, __l);
937949}
938950
939951template <class _Tp, class _Alloc>
940952forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x)
941 : base(__node_traits::select_on_container_copy_construction(__x.__alloc())) {
953 : __base(__node_traits::select_on_container_copy_construction(__x.__alloc_)) {
942954 insert_after(cbefore_begin(), __x.begin(), __x.end());
943955}
944956
945957template <class _Tp, class _Alloc>
946958forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x, const __type_identity_t<allocator_type>& __a)
947 : base(__a) {
959 : __base(__a) {
948960 insert_after(cbefore_begin(), __x.begin(), __x.end());
949961}
950962
951963template <class _Tp, class _Alloc>
952964forward_list<_Tp, _Alloc>& forward_list<_Tp, _Alloc>::operator=(const forward_list& __x) {
953965 if (this != std::addressof(__x)) {
954 base::__copy_assign_alloc(__x);
966 __base::__copy_assign_alloc(__x);
955967 assign(__x.begin(), __x.end());
956968 }
957969 return *this;
958970}
959971
960#ifndef _LIBCPP_CXX03_LANG
972# ifndef _LIBCPP_CXX03_LANG
961973template <class _Tp, class _Alloc>
962974forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x, const __type_identity_t<allocator_type>& __a)
963 : base(std::move(__x), __a) {
964 if (base::__alloc() != __x.__alloc()) {
975 : __base(std::move(__x), __a) {
976 if (this->__alloc_ != __x.__alloc_) {
965977 typedef move_iterator<iterator> _Ip;
966978 insert_after(cbefore_begin(), _Ip(__x.begin()), _Ip(__x.end()));
967979 }
......@@ -973,7 +985,7 @@ forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il) {
973985}
974986
975987template <class _Tp, class _Alloc>
976forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il, const allocator_type& __a) : base(__a) {
988forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il, const allocator_type& __a) : __base(__a) {
977989 insert_after(cbefore_begin(), __il.begin(), __il.end());
978990}
979991
......@@ -981,14 +993,14 @@ template <class _Tp, class _Alloc>
981993void forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type)
982994 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
983995 clear();
984 base::__move_assign_alloc(__x);
985 base::__before_begin()->__next_ = __x.__before_begin()->__next_;
986 __x.__before_begin()->__next_ = nullptr;
996 __base::__move_assign_alloc(__x);
997 __base::__before_begin()->__next_ = __x.__before_begin()->__next_;
998 __x.__before_begin()->__next_ = nullptr;
987999}
9881000
9891001template <class _Tp, class _Alloc>
9901002void forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type) {
991 if (base::__alloc() == __x.__alloc())
1003 if (this->__alloc_ == __x.__alloc_)
9921004 __move_assign(__x, true_type());
9931005 else {
9941006 typedef move_iterator<iterator> _Ip;
......@@ -1009,7 +1021,7 @@ inline forward_list<_Tp, _Alloc>& forward_list<_Tp, _Alloc>::operator=(initializ
10091021 return *this;
10101022}
10111023
1012#endif // _LIBCPP_CXX03_LANG
1024# endif // _LIBCPP_CXX03_LANG
10131025
10141026template <class _Tp, class _Alloc>
10151027template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> >
......@@ -1044,7 +1056,7 @@ void forward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v) {
10441056 erase_after(__i, __e);
10451057}
10461058
1047#ifndef _LIBCPP_CXX03_LANG
1059# ifndef _LIBCPP_CXX03_LANG
10481060
10491061template <class _Tp, class _Alloc>
10501062inline void forward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il) {
......@@ -1053,39 +1065,41 @@ inline void forward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il)
10531065
10541066template <class _Tp, class _Alloc>
10551067template <class... _Args>
1056# if _LIBCPP_STD_VER >= 17
1068# if _LIBCPP_STD_VER >= 17
10571069typename forward_list<_Tp, _Alloc>::reference
1058# else
1070# else
10591071void
1060# endif
1072# endif
10611073forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args) {
1062 base::__before_begin()->__next_ =
1063 this->__create_node(/* next = */ base::__before_begin()->__next_, std::forward<_Args>(__args)...);
1064# if _LIBCPP_STD_VER >= 17
1065 return base::__before_begin()->__next_->__get_value();
1066# endif
1074 __base::__before_begin()->__next_ =
1075 this->__create_node(/* next = */ __base::__before_begin()->__next_, std::forward<_Args>(__args)...);
1076# if _LIBCPP_STD_VER >= 17
1077 return __base::__before_begin()->__next_->__get_value();
1078# endif
10671079}
10681080
10691081template <class _Tp, class _Alloc>
10701082void forward_list<_Tp, _Alloc>::push_front(value_type&& __v) {
1071 base::__before_begin()->__next_ = this->__create_node(/* next = */ base::__before_begin()->__next_, std::move(__v));
1083 __base::__before_begin()->__next_ =
1084 this->__create_node(/* next = */ __base::__before_begin()->__next_, std::move(__v));
10721085}
10731086
1074#endif // _LIBCPP_CXX03_LANG
1087# endif // _LIBCPP_CXX03_LANG
10751088
10761089template <class _Tp, class _Alloc>
10771090void forward_list<_Tp, _Alloc>::push_front(const value_type& __v) {
1078 base::__before_begin()->__next_ = this->__create_node(/* next = */ base::__before_begin()->__next_, __v);
1091 __base::__before_begin()->__next_ = this->__create_node(/* next = */ __base::__before_begin()->__next_, __v);
10791092}
10801093
10811094template <class _Tp, class _Alloc>
10821095void forward_list<_Tp, _Alloc>::pop_front() {
1083 __node_pointer __p = base::__before_begin()->__next_;
1084 base::__before_begin()->__next_ = __p->__next_;
1096 _LIBCPP_ASSERT_NON_NULL(!empty(), "forward_list::pop_front called on an empty list");
1097 __node_pointer __p = __base::__before_begin()->__next_;
1098 __base::__before_begin()->__next_ = __p->__next_;
10851099 this->__delete_node(__p);
10861100}
10871101
1088#ifndef _LIBCPP_CXX03_LANG
1102# ifndef _LIBCPP_CXX03_LANG
10891103
10901104template <class _Tp, class _Alloc>
10911105template <class... _Args>
......@@ -1104,7 +1118,7 @@ forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v) {
11041118 return iterator(__r->__next_);
11051119}
11061120
1107#endif // _LIBCPP_CXX03_LANG
1121# endif // _LIBCPP_CXX03_LANG
11081122
11091123template <class _Tp, class _Alloc>
11101124typename forward_list<_Tp, _Alloc>::iterator
......@@ -1121,13 +1135,13 @@ forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n, const
11211135 if (__n > 0) {
11221136 __node_pointer __first = this->__create_node(/* next = */ nullptr, __v);
11231137 __node_pointer __last = __first;
1124#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1138# if _LIBCPP_HAS_EXCEPTIONS
11251139 try {
1126#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1140# endif // _LIBCPP_HAS_EXCEPTIONS
11271141 for (--__n; __n != 0; --__n, __last = __last->__next_) {
11281142 __last->__next_ = this->__create_node(/* next = */ nullptr, __v);
11291143 }
1130#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1144# if _LIBCPP_HAS_EXCEPTIONS
11311145 } catch (...) {
11321146 while (__first != nullptr) {
11331147 __node_pointer __next = __first->__next_;
......@@ -1136,7 +1150,7 @@ forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n, const
11361150 }
11371151 throw;
11381152 }
1139#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1153# endif // _LIBCPP_HAS_EXCEPTIONS
11401154 __last->__next_ = __r->__next_;
11411155 __r->__next_ = __first;
11421156 __r = static_cast<__begin_node_pointer>(__last);
......@@ -1161,13 +1175,13 @@ forward_list<_Tp, _Alloc>::__insert_after_with_sentinel(const_iterator __p, _Inp
11611175 __node_pointer __first = this->__create_node(/* next = */ nullptr, *__f);
11621176 __node_pointer __last = __first;
11631177
1164#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1178# if _LIBCPP_HAS_EXCEPTIONS
11651179 try {
1166#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1180# endif // _LIBCPP_HAS_EXCEPTIONS
11671181 for (++__f; __f != __l; ++__f, ((void)(__last = __last->__next_))) {
11681182 __last->__next_ = this->__create_node(/* next = */ nullptr, *__f);
11691183 }
1170#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1184# if _LIBCPP_HAS_EXCEPTIONS
11711185 } catch (...) {
11721186 while (__first != nullptr) {
11731187 __node_pointer __next = __first->__next_;
......@@ -1176,7 +1190,7 @@ forward_list<_Tp, _Alloc>::__insert_after_with_sentinel(const_iterator __p, _Inp
11761190 }
11771191 throw;
11781192 }
1179#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1193# endif // _LIBCPP_HAS_EXCEPTIONS
11801194
11811195 __last->__next_ = __r->__next_;
11821196 __r->__next_ = __first;
......@@ -1378,8 +1392,9 @@ template <class _Tp, class _Alloc>
13781392template <class _Compare>
13791393void forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp) {
13801394 if (this != std::addressof(__x)) {
1381 base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_, __x.__before_begin()->__next_, __comp);
1382 __x.__before_begin()->__next_ = nullptr;
1395 __base::__before_begin()->__next_ =
1396 __merge(__base::__before_begin()->__next_, __x.__before_begin()->__next_, __comp);
1397 __x.__before_begin()->__next_ = nullptr;
13831398 }
13841399}
13851400
......@@ -1423,7 +1438,7 @@ forward_list<_Tp, _Alloc>::__merge(__node_pointer __f1, __node_pointer __f2, _Co
14231438template <class _Tp, class _Alloc>
14241439template <class _Compare>
14251440inline void forward_list<_Tp, _Alloc>::sort(_Compare __comp) {
1426 base::__before_begin()->__next_ = __sort(base::__before_begin()->__next_, std::distance(begin(), end()), __comp);
1441 __base::__before_begin()->__next_ = __sort(__base::__before_begin()->__next_, std::distance(begin(), end()), __comp);
14271442}
14281443
14291444template <class _Tp, class _Alloc>
......@@ -1453,7 +1468,7 @@ forward_list<_Tp, _Alloc>::__sort(__node_pointer __f1, difference_type __sz, _Co
14531468
14541469template <class _Tp, class _Alloc>
14551470void forward_list<_Tp, _Alloc>::reverse() _NOEXCEPT {
1456 __node_pointer __p = base::__before_begin()->__next_;
1471 __node_pointer __p = __base::__before_begin()->__next_;
14571472 if (__p != nullptr) {
14581473 __node_pointer __f = __p->__next_;
14591474 __p->__next_ = nullptr;
......@@ -1463,7 +1478,7 @@ void forward_list<_Tp, _Alloc>::reverse() _NOEXCEPT {
14631478 __p = __f;
14641479 __f = __t;
14651480 }
1466 base::__before_begin()->__next_ = __p;
1481 __base::__before_begin()->__next_ = __p;
14671482 }
14681483}
14691484
......@@ -1481,7 +1496,7 @@ _LIBCPP_HIDE_FROM_ABI bool operator==(const forward_list<_Tp, _Alloc>& __x, cons
14811496 return (__ix == __ex) == (__iy == __ey);
14821497}
14831498
1484#if _LIBCPP_STD_VER <= 17
1499# if _LIBCPP_STD_VER <= 17
14851500
14861501template <class _Tp, class _Alloc>
14871502inline _LIBCPP_HIDE_FROM_ABI bool
......@@ -1513,16 +1528,15 @@ operator<=(const forward_list<_Tp, _Alloc>& __x, const forward_list<_Tp, _Alloc>
15131528 return !(__y < __x);
15141529}
15151530
1516#else // #if _LIBCPP_STD_VER <= 17
1531# else // #if _LIBCPP_STD_VER <= 17
15171532
15181533template <class _Tp, class _Allocator>
15191534_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Tp>
15201535operator<=>(const forward_list<_Tp, _Allocator>& __x, const forward_list<_Tp, _Allocator>& __y) {
1521 return std::lexicographical_compare_three_way(
1522 __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
1536 return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
15231537}
15241538
1525#endif // #if _LIBCPP_STD_VER <= 17
1539# endif // #if _LIBCPP_STD_VER <= 17
15261540
15271541template <class _Tp, class _Alloc>
15281542inline _LIBCPP_HIDE_FROM_ABI void swap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y)
......@@ -1530,7 +1544,7 @@ inline _LIBCPP_HIDE_FROM_ABI void swap(forward_list<_Tp, _Alloc>& __x, forward_l
15301544 __x.swap(__y);
15311545}
15321546
1533#if _LIBCPP_STD_VER >= 20
1547# if _LIBCPP_STD_VER >= 20
15341548template <class _Tp, class _Allocator, class _Predicate>
15351549inline _LIBCPP_HIDE_FROM_ABI typename forward_list<_Tp, _Allocator>::size_type
15361550erase_if(forward_list<_Tp, _Allocator>& __c, _Predicate __pred) {
......@@ -1542,34 +1556,46 @@ inline _LIBCPP_HIDE_FROM_ABI typename forward_list<_Tp, _Allocator>::size_type
15421556erase(forward_list<_Tp, _Allocator>& __c, const _Up& __v) {
15431557 return std::erase_if(__c, [&](auto& __elem) { return __elem == __v; });
15441558}
1545#endif
1559# endif
1560
1561template <class _Tp, class _Allocator>
1562struct __container_traits<forward_list<_Tp, _Allocator> > {
1563 // http://eel.is/c++draft/container.reqmts
1564 // Unless otherwise specified (see [associative.reqmts.except], [unord.req.except], [deque.modifiers],
1565 // [inplace.vector.modifiers], and [vector.modifiers]) all container types defined in this Clause meet the following
1566 // additional requirements:
1567 // - If an exception is thrown by an insert() or emplace() function while inserting a single element, that
1568 // function has no effects.
1569 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
1570};
15461571
15471572_LIBCPP_END_NAMESPACE_STD
15481573
1549#if _LIBCPP_STD_VER >= 17
1574# if _LIBCPP_STD_VER >= 17
15501575_LIBCPP_BEGIN_NAMESPACE_STD
15511576namespace pmr {
15521577template <class _ValueT>
15531578using forward_list _LIBCPP_AVAILABILITY_PMR = std::forward_list<_ValueT, polymorphic_allocator<_ValueT>>;
15541579} // namespace pmr
15551580_LIBCPP_END_NAMESPACE_STD
1556#endif
1581# endif
15571582
15581583_LIBCPP_POP_MACROS
15591584
1560#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1561# include <algorithm>
1562# include <atomic>
1563# include <concepts>
1564# include <cstdint>
1565# include <cstdlib>
1566# include <cstring>
1567# include <functional>
1568# include <iosfwd>
1569# include <iterator>
1570# include <stdexcept>
1571# include <type_traits>
1572# include <typeinfo>
1573#endif
1585# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1586# include <algorithm>
1587# include <atomic>
1588# include <concepts>
1589# include <cstdint>
1590# include <cstdlib>
1591# include <cstring>
1592# include <functional>
1593# include <iosfwd>
1594# include <iterator>
1595# include <stdexcept>
1596# include <type_traits>
1597# include <typeinfo>
1598# endif
1599#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
15741600
15751601#endif // _LIBCPP_FORWARD_LIST
lib/libcxx/include/fstream+181-159
......@@ -186,41 +186,43 @@ typedef basic_fstream<wchar_t> wfstream;
186186
187187*/
188188
189#include <__algorithm/max.h>
190#include <__assert>
191#include <__config>
192#include <__fwd/fstream.h>
193#include <__locale>
194#include <__type_traits/enable_if.h>
195#include <__type_traits/is_same.h>
196#include <__utility/move.h>
197#include <__utility/swap.h>
198#include <__utility/unreachable.h>
199#include <cstdio>
200#include <filesystem>
201#include <istream>
202#include <ostream>
203#include <typeinfo>
204#include <version>
205
206#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
207# pragma GCC system_header
208#endif
189#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
190# include <__cxx03/fstream>
191#else
192# include <__algorithm/max.h>
193# include <__assert>
194# include <__config>
195# include <__filesystem/path.h>
196# include <__fwd/fstream.h>
197# include <__locale>
198# include <__memory/addressof.h>
199# include <__memory/unique_ptr.h>
200# include <__ostream/basic_ostream.h>
201# include <__type_traits/enable_if.h>
202# include <__type_traits/is_same.h>
203# include <__utility/move.h>
204# include <__utility/swap.h>
205# include <__utility/unreachable.h>
206# include <cstdio>
207# include <istream>
208# include <streambuf>
209# include <typeinfo>
210# include <version>
211
212# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
213# pragma GCC system_header
214# endif
209215
210216_LIBCPP_PUSH_MACROS
211#include <__undef_macros>
212
213#if defined(_LIBCPP_MSVCRT) || defined(_NEWLIB_VERSION)
214# define _LIBCPP_HAS_NO_OFF_T_FUNCTIONS
215#endif
217# include <__undef_macros>
216218
217#if !defined(_LIBCPP_HAS_NO_FILESYSTEM)
219# if _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
218220
219221_LIBCPP_BEGIN_NAMESPACE_STD
220222
221# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_WIN32API)
223# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_WIN32API)
222224_LIBCPP_EXPORTED_FROM_ABI void* __filebuf_windows_native_handle(FILE* __file) noexcept;
223# endif
225# endif
224226
225227template <class _CharT, class _Traits>
226228class _LIBCPP_TEMPLATE_VIS basic_filebuf : public basic_streambuf<_CharT, _Traits> {
......@@ -231,15 +233,15 @@ public:
231233 typedef typename traits_type::pos_type pos_type;
232234 typedef typename traits_type::off_type off_type;
233235 typedef typename traits_type::state_type state_type;
234# if _LIBCPP_STD_VER >= 26
235# if defined(_LIBCPP_WIN32API)
236# if _LIBCPP_STD_VER >= 26
237# if defined(_LIBCPP_WIN32API)
236238 using native_handle_type = void*; // HANDLE
237# elif __has_include(<unistd.h>)
239# elif __has_include(<unistd.h>)
238240 using native_handle_type = int; // POSIX file descriptor
239# else
240# error "Provide a native file handle!"
241# else
242# error "Provide a native file handle!"
243# endif
241244# endif
242# endif
243245
244246 // 27.9.1.2 Constructors/destructor:
245247 basic_filebuf();
......@@ -253,36 +255,36 @@ public:
253255 // 27.9.1.4 Members:
254256 _LIBCPP_HIDE_FROM_ABI bool is_open() const;
255257 basic_filebuf* open(const char* __s, ios_base::openmode __mode);
256# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
258# if _LIBCPP_HAS_OPEN_WITH_WCHAR
257259 basic_filebuf* open(const wchar_t* __s, ios_base::openmode __mode);
258# endif
260# endif
259261 _LIBCPP_HIDE_FROM_ABI basic_filebuf* open(const string& __s, ios_base::openmode __mode);
260262
261# if _LIBCPP_STD_VER >= 17
263# if _LIBCPP_STD_VER >= 17
262264 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_HIDE_FROM_ABI basic_filebuf*
263265 open(const filesystem::path& __p, ios_base::openmode __mode) {
264266 return open(__p.c_str(), __mode);
265267 }
266# endif
268# endif
267269 _LIBCPP_HIDE_FROM_ABI basic_filebuf* __open(int __fd, ios_base::openmode __mode);
268270 basic_filebuf* close();
269# if _LIBCPP_STD_VER >= 26
271# if _LIBCPP_STD_VER >= 26
270272 _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept {
271273 _LIBCPP_ASSERT_UNCATEGORIZED(this->is_open(), "File must be opened");
272# if defined(_LIBCPP_WIN32API)
274# if defined(_LIBCPP_WIN32API)
273275 return std::__filebuf_windows_native_handle(__file_);
274# elif __has_include(<unistd.h>)
276# elif __has_include(<unistd.h>)
275277 return fileno(__file_);
276# else
277# error "Provide a way to determine the file native handle!"
278# endif
278# else
279# error "Provide a way to determine the file native handle!"
280# endif
279281 }
280# endif // _LIBCPP_STD_VER >= 26
282# endif // _LIBCPP_STD_VER >= 26
281283
282284 _LIBCPP_HIDE_FROM_ABI inline static const char* __make_mdstring(ios_base::openmode __mode) _NOEXCEPT;
283# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
285# if _LIBCPP_HAS_OPEN_WITH_WCHAR
284286 _LIBCPP_HIDE_FROM_ABI inline static const wchar_t* __make_mdwstring(ios_base::openmode __mode) _NOEXCEPT;
285# endif
287# endif
286288
287289protected:
288290 // 27.9.1.5 Overridden virtual functions:
......@@ -354,6 +356,9 @@ private:
354356 bool __read_mode();
355357 void __write_mode();
356358
359 _LIBCPP_HIDE_FROM_ABI static int __fseek(FILE* __file, pos_type __offset, int __whence);
360 _LIBCPP_HIDE_FROM_ABI static pos_type __ftell(FILE* __file);
361
357362 _LIBCPP_EXPORTED_FROM_ABI friend FILE* __get_ostream_file(ostream&);
358363
359364 // There are multiple (__)open function, they use different C-API open
......@@ -484,14 +489,14 @@ inline basic_filebuf<_CharT, _Traits>& basic_filebuf<_CharT, _Traits>::operator=
484489
485490template <class _CharT, class _Traits>
486491basic_filebuf<_CharT, _Traits>::~basic_filebuf() {
487# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
492# if _LIBCPP_HAS_EXCEPTIONS
488493 try {
489# endif // _LIBCPP_HAS_NO_EXCEPTIONS
494# endif // _LIBCPP_HAS_EXCEPTIONS
490495 close();
491# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
496# if _LIBCPP_HAS_EXCEPTIONS
492497 } catch (...) {
493498 }
494# endif // _LIBCPP_HAS_NO_EXCEPTIONS
499# endif // _LIBCPP_HAS_EXCEPTIONS
495500 if (__owns_eb_)
496501 delete[] __extbuf_;
497502 if (__owns_ib_)
......@@ -611,7 +616,7 @@ const char* basic_filebuf<_CharT, _Traits>::__make_mdstring(ios_base::openmode _
611616 case ios_base::in | ios_base::out | ios_base::app | ios_base::binary:
612617 case ios_base::in | ios_base::app | ios_base::binary:
613618 return "a+b" _LIBCPP_FOPEN_CLOEXEC_MODE;
614# if _LIBCPP_STD_VER >= 23
619# if _LIBCPP_STD_VER >= 23
615620 case ios_base::out | ios_base::noreplace:
616621 case ios_base::out | ios_base::trunc | ios_base::noreplace:
617622 return "wx" _LIBCPP_FOPEN_CLOEXEC_MODE;
......@@ -622,14 +627,14 @@ const char* basic_filebuf<_CharT, _Traits>::__make_mdstring(ios_base::openmode _
622627 return "wbx" _LIBCPP_FOPEN_CLOEXEC_MODE;
623628 case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary | ios_base::noreplace:
624629 return "w+bx" _LIBCPP_FOPEN_CLOEXEC_MODE;
625# endif // _LIBCPP_STD_VER >= 23
630# endif // _LIBCPP_STD_VER >= 23
626631 default:
627632 return nullptr;
628633 }
629634 __libcpp_unreachable();
630635}
631636
632# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
637# if _LIBCPP_HAS_OPEN_WITH_WCHAR
633638template <class _CharT, class _Traits>
634639const wchar_t* basic_filebuf<_CharT, _Traits>::__make_mdwstring(ios_base::openmode __mode) _NOEXCEPT {
635640 switch (__mode & ~ios_base::ate) {
......@@ -663,7 +668,7 @@ const wchar_t* basic_filebuf<_CharT, _Traits>::__make_mdwstring(ios_base::openmo
663668 case ios_base::in | ios_base::out | ios_base::app | ios_base::binary:
664669 case ios_base::in | ios_base::app | ios_base::binary:
665670 return L"a+b";
666# if _LIBCPP_STD_VER >= 23
671# if _LIBCPP_STD_VER >= 23
667672 case ios_base::out | ios_base::noreplace:
668673 case ios_base::out | ios_base::trunc | ios_base::noreplace:
669674 return L"wx";
......@@ -674,13 +679,13 @@ const wchar_t* basic_filebuf<_CharT, _Traits>::__make_mdwstring(ios_base::openmo
674679 return L"wbx";
675680 case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary | ios_base::noreplace:
676681 return L"w+bx";
677# endif // _LIBCPP_STD_VER >= 23
682# endif // _LIBCPP_STD_VER >= 23
678683 default:
679684 return nullptr;
680685 }
681686 __libcpp_unreachable();
682687}
683# endif
688# endif
684689
685690template <class _CharT, class _Traits>
686691basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) {
......@@ -704,7 +709,7 @@ inline basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::__open(in
704709 return __do_open(fdopen(__fd, __mdstr), __mode);
705710}
706711
707# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
712# if _LIBCPP_HAS_OPEN_WITH_WCHAR
708713// This is basically the same as the char* overload except that it uses _wfopen
709714// and long mode strings.
710715template <class _CharT, class _Traits>
......@@ -717,7 +722,7 @@ basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::open(const wchar
717722
718723 return __do_open(_wfopen(__s, __mdstr), __mode);
719724}
720# endif
725# endif
721726
722727template <class _CharT, class _Traits>
723728inline basic_filebuf<_CharT, _Traits>*
......@@ -928,31 +933,42 @@ basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way,
928933 default:
929934 return pos_type(off_type(-1));
930935 }
931# if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS)
932 if (fseek(__file_, __width > 0 ? __width * __off : 0, __whence))
936 if (__fseek(__file_, __width > 0 ? __width * __off : 0, __whence))
933937 return pos_type(off_type(-1));
934 pos_type __r = ftell(__file_);
935# else
936 if (::fseeko(__file_, __width > 0 ? __width * __off : 0, __whence))
937 return pos_type(off_type(-1));
938 pos_type __r = ftello(__file_);
939# endif
938 pos_type __r = __ftell(__file_);
940939 __r.state(__st_);
941940 return __r;
942941}
943942
943template <class _CharT, class _Traits>
944int basic_filebuf<_CharT, _Traits>::__fseek(FILE* __file, pos_type __offset, int __whence) {
945# if defined(_LIBCPP_MSVCRT_LIKE)
946 return _fseeki64(__file, __offset, __whence);
947# elif defined(_NEWLIB_VERSION)
948 return fseek(__file, __offset, __whence);
949# else
950 return ::fseeko(__file, __offset, __whence);
951# endif
952}
953
954template <class _CharT, class _Traits>
955typename basic_filebuf<_CharT, _Traits>::pos_type basic_filebuf<_CharT, _Traits>::__ftell(FILE* __file) {
956# if defined(_LIBCPP_MSVCRT_LIKE)
957 return _ftelli64(__file);
958# elif defined(_NEWLIB_VERSION)
959 return ftell(__file);
960# else
961 return ftello(__file);
962# endif
963}
964
944965template <class _CharT, class _Traits>
945966typename basic_filebuf<_CharT, _Traits>::pos_type
946967basic_filebuf<_CharT, _Traits>::seekpos(pos_type __sp, ios_base::openmode) {
947968 if (__file_ == nullptr || sync())
948969 return pos_type(off_type(-1));
949# if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS)
950 if (fseek(__file_, __sp, SEEK_SET))
970 if (__fseek(__file_, __sp, SEEK_SET))
951971 return pos_type(off_type(-1));
952# else
953 if (::fseeko(__file_, __sp, SEEK_SET))
954 return pos_type(off_type(-1));
955# endif
956972 __st_ = __sp.state();
957973 return __sp;
958974}
......@@ -999,13 +1015,8 @@ int basic_filebuf<_CharT, _Traits>::sync() {
9991015 }
10001016 }
10011017 }
1002# if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS)
1003 if (fseek(__file_, -__c, SEEK_CUR))
1004 return -1;
1005# else
1006 if (::fseeko(__file_, -__c, SEEK_CUR))
1018 if (__fseek(__file_, -__c, SEEK_CUR))
10071019 return -1;
1008# endif
10091020 if (__update_st)
10101021 __st_ = __state;
10111022 __extbufnext_ = __extbufend_ = __extbuf_;
......@@ -1091,42 +1102,42 @@ public:
10911102 typedef typename traits_type::int_type int_type;
10921103 typedef typename traits_type::pos_type pos_type;
10931104 typedef typename traits_type::off_type off_type;
1094# if _LIBCPP_STD_VER >= 26
1105# if _LIBCPP_STD_VER >= 26
10951106 using native_handle_type = typename basic_filebuf<_CharT, _Traits>::native_handle_type;
1096# endif
1107# endif
10971108
10981109 _LIBCPP_HIDE_FROM_ABI basic_ifstream();
10991110 _LIBCPP_HIDE_FROM_ABI explicit basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in);
1100# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
1111# if _LIBCPP_HAS_OPEN_WITH_WCHAR
11011112 _LIBCPP_HIDE_FROM_ABI explicit basic_ifstream(const wchar_t* __s, ios_base::openmode __mode = ios_base::in);
1102# endif
1113# endif
11031114 _LIBCPP_HIDE_FROM_ABI explicit basic_ifstream(const string& __s, ios_base::openmode __mode = ios_base::in);
1104# if _LIBCPP_STD_VER >= 17
1115# if _LIBCPP_STD_VER >= 17
11051116 template <class _Tp, class = enable_if_t<is_same_v<_Tp, filesystem::path>>>
11061117 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY
11071118 _LIBCPP_HIDE_FROM_ABI explicit basic_ifstream(const _Tp& __p, ios_base::openmode __mode = ios_base::in)
11081119 : basic_ifstream(__p.c_str(), __mode) {}
1109# endif // _LIBCPP_STD_VER >= 17
1120# endif // _LIBCPP_STD_VER >= 17
11101121 _LIBCPP_HIDE_FROM_ABI basic_ifstream(basic_ifstream&& __rhs);
11111122 _LIBCPP_HIDE_FROM_ABI basic_ifstream& operator=(basic_ifstream&& __rhs);
11121123 _LIBCPP_HIDE_FROM_ABI void swap(basic_ifstream& __rhs);
11131124
11141125 _LIBCPP_HIDE_FROM_ABI basic_filebuf<char_type, traits_type>* rdbuf() const;
1115# if _LIBCPP_STD_VER >= 26
1126# if _LIBCPP_STD_VER >= 26
11161127 _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept { return rdbuf()->native_handle(); }
1117# endif
1128# endif
11181129 _LIBCPP_HIDE_FROM_ABI bool is_open() const;
11191130 void open(const char* __s, ios_base::openmode __mode = ios_base::in);
1120# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
1131# if _LIBCPP_HAS_OPEN_WITH_WCHAR
11211132 void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::in);
1122# endif
1133# endif
11231134 void open(const string& __s, ios_base::openmode __mode = ios_base::in);
1124# if _LIBCPP_STD_VER >= 17
1135# if _LIBCPP_STD_VER >= 17
11251136 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_HIDE_FROM_ABI void
11261137 open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in) {
11271138 return open(__p.c_str(), __mode);
11281139 }
1129# endif // _LIBCPP_STD_VER >= 17
1140# endif // _LIBCPP_STD_VER >= 17
11301141
11311142 _LIBCPP_HIDE_FROM_ABI void __open(int __fd, ios_base::openmode __mode);
11321143 _LIBCPP_HIDE_FROM_ABI void close();
......@@ -1136,27 +1147,29 @@ private:
11361147};
11371148
11381149template <class _CharT, class _Traits>
1139inline basic_ifstream<_CharT, _Traits>::basic_ifstream() : basic_istream<char_type, traits_type>(&__sb_) {}
1150inline basic_ifstream<_CharT, _Traits>::basic_ifstream()
1151 : basic_istream<char_type, traits_type>(std::addressof(__sb_)) {}
11401152
11411153template <class _CharT, class _Traits>
11421154inline basic_ifstream<_CharT, _Traits>::basic_ifstream(const char* __s, ios_base::openmode __mode)
1143 : basic_istream<char_type, traits_type>(&__sb_) {
1155 : basic_istream<char_type, traits_type>(std::addressof(__sb_)) {
11441156 if (__sb_.open(__s, __mode | ios_base::in) == nullptr)
11451157 this->setstate(ios_base::failbit);
11461158}
11471159
1148# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
1160# if _LIBCPP_HAS_OPEN_WITH_WCHAR
11491161template <class _CharT, class _Traits>
11501162inline basic_ifstream<_CharT, _Traits>::basic_ifstream(const wchar_t* __s, ios_base::openmode __mode)
1151 : basic_istream<char_type, traits_type>(&__sb_) {
1163 : basic_istream<char_type, traits_type>(std::addressof(__sb_)) {
11521164 if (__sb_.open(__s, __mode | ios_base::in) == nullptr)
11531165 this->setstate(ios_base::failbit);
11541166}
1155# endif
1167# endif
11561168
1169// extension
11571170template <class _CharT, class _Traits>
11581171inline basic_ifstream<_CharT, _Traits>::basic_ifstream(const string& __s, ios_base::openmode __mode)
1159 : basic_istream<char_type, traits_type>(&__sb_) {
1172 : basic_istream<char_type, traits_type>(std::addressof(__sb_)) {
11601173 if (__sb_.open(__s, __mode | ios_base::in) == nullptr)
11611174 this->setstate(ios_base::failbit);
11621175}
......@@ -1164,7 +1177,7 @@ inline basic_ifstream<_CharT, _Traits>::basic_ifstream(const string& __s, ios_ba
11641177template <class _CharT, class _Traits>
11651178inline basic_ifstream<_CharT, _Traits>::basic_ifstream(basic_ifstream&& __rhs)
11661179 : basic_istream<char_type, traits_type>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
1167 this->set_rdbuf(&__sb_);
1180 this->set_rdbuf(std::addressof(__sb_));
11681181}
11691182
11701183template <class _CharT, class _Traits>
......@@ -1187,7 +1200,7 @@ inline _LIBCPP_HIDE_FROM_ABI void swap(basic_ifstream<_CharT, _Traits>& __x, bas
11871200
11881201template <class _CharT, class _Traits>
11891202inline basic_filebuf<_CharT, _Traits>* basic_ifstream<_CharT, _Traits>::rdbuf() const {
1190 return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_);
1203 return const_cast<basic_filebuf<char_type, traits_type>*>(std::addressof(__sb_));
11911204}
11921205
11931206template <class _CharT, class _Traits>
......@@ -1203,7 +1216,7 @@ void basic_ifstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode _
12031216 this->setstate(ios_base::failbit);
12041217}
12051218
1206# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
1219# if _LIBCPP_HAS_OPEN_WITH_WCHAR
12071220template <class _CharT, class _Traits>
12081221void basic_ifstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) {
12091222 if (__sb_.open(__s, __mode | ios_base::in))
......@@ -1211,7 +1224,7 @@ void basic_ifstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmod
12111224 else
12121225 this->setstate(ios_base::failbit);
12131226}
1214# endif
1227# endif
12151228
12161229template <class _CharT, class _Traits>
12171230void basic_ifstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) {
......@@ -1245,45 +1258,45 @@ public:
12451258 typedef typename traits_type::int_type int_type;
12461259 typedef typename traits_type::pos_type pos_type;
12471260 typedef typename traits_type::off_type off_type;
1248# if _LIBCPP_STD_VER >= 26
1261# if _LIBCPP_STD_VER >= 26
12491262 using native_handle_type = typename basic_filebuf<_CharT, _Traits>::native_handle_type;
1250# endif
1263# endif
12511264
12521265 _LIBCPP_HIDE_FROM_ABI basic_ofstream();
12531266 _LIBCPP_HIDE_FROM_ABI explicit basic_ofstream(const char* __s, ios_base::openmode __mode = ios_base::out);
1254# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
1267# if _LIBCPP_HAS_OPEN_WITH_WCHAR
12551268 _LIBCPP_HIDE_FROM_ABI explicit basic_ofstream(const wchar_t* __s, ios_base::openmode __mode = ios_base::out);
1256# endif
1269# endif
12571270 _LIBCPP_HIDE_FROM_ABI explicit basic_ofstream(const string& __s, ios_base::openmode __mode = ios_base::out);
12581271
1259# if _LIBCPP_STD_VER >= 17
1272# if _LIBCPP_STD_VER >= 17
12601273 template <class _Tp, class = enable_if_t<is_same_v<_Tp, filesystem::path>>>
12611274 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY
12621275 _LIBCPP_HIDE_FROM_ABI explicit basic_ofstream(const _Tp& __p, ios_base::openmode __mode = ios_base::out)
12631276 : basic_ofstream(__p.c_str(), __mode) {}
1264# endif // _LIBCPP_STD_VER >= 17
1277# endif // _LIBCPP_STD_VER >= 17
12651278
12661279 _LIBCPP_HIDE_FROM_ABI basic_ofstream(basic_ofstream&& __rhs);
12671280 _LIBCPP_HIDE_FROM_ABI basic_ofstream& operator=(basic_ofstream&& __rhs);
12681281 _LIBCPP_HIDE_FROM_ABI void swap(basic_ofstream& __rhs);
12691282
12701283 _LIBCPP_HIDE_FROM_ABI basic_filebuf<char_type, traits_type>* rdbuf() const;
1271# if _LIBCPP_STD_VER >= 26
1284# if _LIBCPP_STD_VER >= 26
12721285 _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept { return rdbuf()->native_handle(); }
1273# endif
1286# endif
12741287 _LIBCPP_HIDE_FROM_ABI bool is_open() const;
12751288 void open(const char* __s, ios_base::openmode __mode = ios_base::out);
1276# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
1289# if _LIBCPP_HAS_OPEN_WITH_WCHAR
12771290 void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::out);
1278# endif
1291# endif
12791292 void open(const string& __s, ios_base::openmode __mode = ios_base::out);
12801293
1281# if _LIBCPP_STD_VER >= 17
1294# if _LIBCPP_STD_VER >= 17
12821295 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_HIDE_FROM_ABI void
12831296 open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::out) {
12841297 return open(__p.c_str(), __mode);
12851298 }
1286# endif // _LIBCPP_STD_VER >= 17
1299# endif // _LIBCPP_STD_VER >= 17
12871300
12881301 _LIBCPP_HIDE_FROM_ABI void __open(int __fd, ios_base::openmode __mode);
12891302 _LIBCPP_HIDE_FROM_ABI void close();
......@@ -1293,27 +1306,29 @@ private:
12931306};
12941307
12951308template <class _CharT, class _Traits>
1296inline basic_ofstream<_CharT, _Traits>::basic_ofstream() : basic_ostream<char_type, traits_type>(&__sb_) {}
1309inline basic_ofstream<_CharT, _Traits>::basic_ofstream()
1310 : basic_ostream<char_type, traits_type>(std::addressof(__sb_)) {}
12971311
12981312template <class _CharT, class _Traits>
12991313inline basic_ofstream<_CharT, _Traits>::basic_ofstream(const char* __s, ios_base::openmode __mode)
1300 : basic_ostream<char_type, traits_type>(&__sb_) {
1314 : basic_ostream<char_type, traits_type>(std::addressof(__sb_)) {
13011315 if (__sb_.open(__s, __mode | ios_base::out) == nullptr)
13021316 this->setstate(ios_base::failbit);
13031317}
13041318
1305# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
1319# if _LIBCPP_HAS_OPEN_WITH_WCHAR
13061320template <class _CharT, class _Traits>
13071321inline basic_ofstream<_CharT, _Traits>::basic_ofstream(const wchar_t* __s, ios_base::openmode __mode)
1308 : basic_ostream<char_type, traits_type>(&__sb_) {
1322 : basic_ostream<char_type, traits_type>(std::addressof(__sb_)) {
13091323 if (__sb_.open(__s, __mode | ios_base::out) == nullptr)
13101324 this->setstate(ios_base::failbit);
13111325}
1312# endif
1326# endif
13131327
1328// extension
13141329template <class _CharT, class _Traits>
13151330inline basic_ofstream<_CharT, _Traits>::basic_ofstream(const string& __s, ios_base::openmode __mode)
1316 : basic_ostream<char_type, traits_type>(&__sb_) {
1331 : basic_ostream<char_type, traits_type>(std::addressof(__sb_)) {
13171332 if (__sb_.open(__s, __mode | ios_base::out) == nullptr)
13181333 this->setstate(ios_base::failbit);
13191334}
......@@ -1321,7 +1336,7 @@ inline basic_ofstream<_CharT, _Traits>::basic_ofstream(const string& __s, ios_ba
13211336template <class _CharT, class _Traits>
13221337inline basic_ofstream<_CharT, _Traits>::basic_ofstream(basic_ofstream&& __rhs)
13231338 : basic_ostream<char_type, traits_type>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
1324 this->set_rdbuf(&__sb_);
1339 this->set_rdbuf(std::addressof(__sb_));
13251340}
13261341
13271342template <class _CharT, class _Traits>
......@@ -1344,7 +1359,7 @@ inline _LIBCPP_HIDE_FROM_ABI void swap(basic_ofstream<_CharT, _Traits>& __x, bas
13441359
13451360template <class _CharT, class _Traits>
13461361inline basic_filebuf<_CharT, _Traits>* basic_ofstream<_CharT, _Traits>::rdbuf() const {
1347 return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_);
1362 return const_cast<basic_filebuf<char_type, traits_type>*>(std::addressof(__sb_));
13481363}
13491364
13501365template <class _CharT, class _Traits>
......@@ -1360,7 +1375,7 @@ void basic_ofstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode _
13601375 this->setstate(ios_base::failbit);
13611376}
13621377
1363# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
1378# if _LIBCPP_HAS_OPEN_WITH_WCHAR
13641379template <class _CharT, class _Traits>
13651380void basic_ofstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) {
13661381 if (__sb_.open(__s, __mode | ios_base::out))
......@@ -1368,7 +1383,7 @@ void basic_ofstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmod
13681383 else
13691384 this->setstate(ios_base::failbit);
13701385}
1371# endif
1386# endif
13721387
13731388template <class _CharT, class _Traits>
13741389void basic_ofstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) {
......@@ -1402,26 +1417,26 @@ public:
14021417 typedef typename traits_type::int_type int_type;
14031418 typedef typename traits_type::pos_type pos_type;
14041419 typedef typename traits_type::off_type off_type;
1405# if _LIBCPP_STD_VER >= 26
1420# if _LIBCPP_STD_VER >= 26
14061421 using native_handle_type = typename basic_filebuf<_CharT, _Traits>::native_handle_type;
1407# endif
1422# endif
14081423
14091424 _LIBCPP_HIDE_FROM_ABI basic_fstream();
14101425 _LIBCPP_HIDE_FROM_ABI explicit basic_fstream(const char* __s,
14111426 ios_base::openmode __mode = ios_base::in | ios_base::out);
1412# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
1427# if _LIBCPP_HAS_OPEN_WITH_WCHAR
14131428 _LIBCPP_HIDE_FROM_ABI explicit basic_fstream(const wchar_t* __s,
14141429 ios_base::openmode __mode = ios_base::in | ios_base::out);
1415# endif
1430# endif
14161431 _LIBCPP_HIDE_FROM_ABI explicit basic_fstream(const string& __s,
14171432 ios_base::openmode __mode = ios_base::in | ios_base::out);
14181433
1419# if _LIBCPP_STD_VER >= 17
1434# if _LIBCPP_STD_VER >= 17
14201435 template <class _Tp, class = enable_if_t<is_same_v<_Tp, filesystem::path>>>
14211436 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_HIDE_FROM_ABI explicit basic_fstream(
14221437 const _Tp& __p, ios_base::openmode __mode = ios_base::in | ios_base::out)
14231438 : basic_fstream(__p.c_str(), __mode) {}
1424# endif // _LIBCPP_STD_VER >= 17
1439# endif // _LIBCPP_STD_VER >= 17
14251440
14261441 _LIBCPP_HIDE_FROM_ABI basic_fstream(basic_fstream&& __rhs);
14271442
......@@ -1430,22 +1445,22 @@ public:
14301445 _LIBCPP_HIDE_FROM_ABI void swap(basic_fstream& __rhs);
14311446
14321447 _LIBCPP_HIDE_FROM_ABI basic_filebuf<char_type, traits_type>* rdbuf() const;
1433# if _LIBCPP_STD_VER >= 26
1448# if _LIBCPP_STD_VER >= 26
14341449 _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept { return rdbuf()->native_handle(); }
1435# endif
1450# endif
14361451 _LIBCPP_HIDE_FROM_ABI bool is_open() const;
14371452 _LIBCPP_HIDE_FROM_ABI void open(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
1438# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
1453# if _LIBCPP_HAS_OPEN_WITH_WCHAR
14391454 void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
1440# endif
1455# endif
14411456 _LIBCPP_HIDE_FROM_ABI void open(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
14421457
1443# if _LIBCPP_STD_VER >= 17
1458# if _LIBCPP_STD_VER >= 17
14441459 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_HIDE_FROM_ABI void
14451460 open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in | ios_base::out) {
14461461 return open(__p.c_str(), __mode);
14471462 }
1448# endif // _LIBCPP_STD_VER >= 17
1463# endif // _LIBCPP_STD_VER >= 17
14491464
14501465 _LIBCPP_HIDE_FROM_ABI void close();
14511466
......@@ -1454,35 +1469,37 @@ private:
14541469};
14551470
14561471template <class _CharT, class _Traits>
1457inline basic_fstream<_CharT, _Traits>::basic_fstream() : basic_iostream<char_type, traits_type>(&__sb_) {}
1472inline basic_fstream<_CharT, _Traits>::basic_fstream()
1473 : basic_iostream<char_type, traits_type>(std::addressof(__sb_)) {}
14581474
14591475template <class _CharT, class _Traits>
14601476inline basic_fstream<_CharT, _Traits>::basic_fstream(const char* __s, ios_base::openmode __mode)
1461 : basic_iostream<char_type, traits_type>(&__sb_) {
1477 : basic_iostream<char_type, traits_type>(std::addressof(__sb_)) {
14621478 if (__sb_.open(__s, __mode) == nullptr)
14631479 this->setstate(ios_base::failbit);
14641480}
14651481
1466# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
1482# if _LIBCPP_HAS_OPEN_WITH_WCHAR
14671483template <class _CharT, class _Traits>
14681484inline basic_fstream<_CharT, _Traits>::basic_fstream(const wchar_t* __s, ios_base::openmode __mode)
1469 : basic_iostream<char_type, traits_type>(&__sb_) {
1485 : basic_iostream<char_type, traits_type>(std::addressof(__sb_)) {
14701486 if (__sb_.open(__s, __mode) == nullptr)
14711487 this->setstate(ios_base::failbit);
14721488}
1473# endif
1489# endif
14741490
14751491template <class _CharT, class _Traits>
14761492inline basic_fstream<_CharT, _Traits>::basic_fstream(const string& __s, ios_base::openmode __mode)
1477 : basic_iostream<char_type, traits_type>(&__sb_) {
1493 : basic_iostream<char_type, traits_type>(std::addressof(__sb_)) {
14781494 if (__sb_.open(__s, __mode) == nullptr)
14791495 this->setstate(ios_base::failbit);
14801496}
14811497
1498// extension
14821499template <class _CharT, class _Traits>
14831500inline basic_fstream<_CharT, _Traits>::basic_fstream(basic_fstream&& __rhs)
14841501 : basic_iostream<char_type, traits_type>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
1485 this->set_rdbuf(&__sb_);
1502 this->set_rdbuf(std::addressof(__sb_));
14861503}
14871504
14881505template <class _CharT, class _Traits>
......@@ -1505,7 +1522,7 @@ inline _LIBCPP_HIDE_FROM_ABI void swap(basic_fstream<_CharT, _Traits>& __x, basi
15051522
15061523template <class _CharT, class _Traits>
15071524inline basic_filebuf<_CharT, _Traits>* basic_fstream<_CharT, _Traits>::rdbuf() const {
1508 return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_);
1525 return const_cast<basic_filebuf<char_type, traits_type>*>(std::addressof(__sb_));
15091526}
15101527
15111528template <class _CharT, class _Traits>
......@@ -1521,7 +1538,7 @@ void basic_fstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __
15211538 this->setstate(ios_base::failbit);
15221539}
15231540
1524# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
1541# if _LIBCPP_HAS_OPEN_WITH_WCHAR
15251542template <class _CharT, class _Traits>
15261543void basic_fstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) {
15271544 if (__sb_.open(__s, __mode))
......@@ -1529,7 +1546,7 @@ void basic_fstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode
15291546 else
15301547 this->setstate(ios_base::failbit);
15311548}
1532# endif
1549# endif
15331550
15341551template <class _CharT, class _Traits>
15351552void basic_fstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) {
......@@ -1545,28 +1562,33 @@ inline void basic_fstream<_CharT, _Traits>::close() {
15451562 this->setstate(ios_base::failbit);
15461563}
15471564
1548# if _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
1565# if _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
15491566extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ifstream<char>;
15501567extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ofstream<char>;
15511568extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_filebuf<char>;
1552# endif
1569# endif
15531570
15541571_LIBCPP_END_NAMESPACE_STD
15551572
1556#endif // _LIBCPP_HAS_NO_FILESYSTEM
1573# endif // _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
15571574
15581575_LIBCPP_POP_MACROS
15591576
1560#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1561# include <atomic>
1562# include <concepts>
1563# include <cstdlib>
1564# include <iosfwd>
1565# include <limits>
1566# include <mutex>
1567# include <new>
1568# include <stdexcept>
1569# include <type_traits>
1570#endif
1577# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1578# include <atomic>
1579# include <concepts>
1580# include <cstdlib>
1581# include <iosfwd>
1582# include <limits>
1583# include <mutex>
1584# include <new>
1585# include <stdexcept>
1586# include <type_traits>
1587# endif
1588
1589# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 23
1590# include <filesystem>
1591# endif
1592#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
15711593
15721594#endif // _LIBCPP_FSTREAM
lib/libcxx/include/functional+75-69
......@@ -214,7 +214,9 @@ template <class Predicate> // deprecated in C++17, removed in C++20
214214binary_negate<Predicate> not2(const Predicate& pred);
215215
216216template <class F>
217constexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20
217 constexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20
218template <auto f>
219 constexpr unspecified not_fn() noexcept; // C++26
218220
219221// [func.bind.partial], function templates bind_front and bind_back
220222template<class F, class... Args>
......@@ -395,7 +397,7 @@ const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const);
395397template <class S, class T, class A>
396398const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); // deprecated in C++11, removed in C++17
397399
398template<class R, class T> constexpr unspecified mem_fn(R T::*); // constexpr in C++20
400template<class R, class T> constexpr unspecified mem_fn(R T::*) noexcept; // constexpr in C++20
399401
400402class bad_function_call
401403 : public exception
......@@ -527,72 +529,76 @@ POLICY: For non-variadic implementations, the number of arguments is limited
527529
528530*/
529531
530#include <__config>
531
532#include <__functional/binary_function.h>
533#include <__functional/binary_negate.h>
534#include <__functional/bind.h>
535#include <__functional/binder1st.h>
536#include <__functional/binder2nd.h>
537#include <__functional/hash.h>
538#include <__functional/mem_fn.h> // TODO: deprecate
539#include <__functional/mem_fun_ref.h>
540#include <__functional/operations.h>
541#include <__functional/pointer_to_binary_function.h>
542#include <__functional/pointer_to_unary_function.h>
543#include <__functional/reference_wrapper.h>
544#include <__functional/unary_function.h>
545#include <__functional/unary_negate.h>
546
547#ifndef _LIBCPP_CXX03_LANG
548# include <__functional/function.h>
549#endif
550
551#if _LIBCPP_STD_VER >= 17
552# include <__functional/boyer_moore_searcher.h>
553# include <__functional/default_searcher.h>
554# include <__functional/invoke.h>
555# include <__functional/not_fn.h>
556#endif
557
558#if _LIBCPP_STD_VER >= 20
559# include <__functional/bind_back.h>
560# include <__functional/bind_front.h>
561# include <__functional/identity.h>
562# include <__functional/ranges_operations.h>
563# include <__type_traits/unwrap_ref.h>
564#endif
565
566#include <version>
567
568#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
569# pragma GCC system_header
570#endif
571
572#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && defined(_LIBCPP_CXX03_LANG)
573# include <limits>
574# include <new>
575#endif
576
577#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 14
578# include <array>
579# include <initializer_list>
580# include <unordered_map>
581# include <vector>
582#endif
583
584#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
585# include <atomic>
586# include <concepts>
587# include <cstdlib>
588# include <exception>
589# include <iosfwd>
590# include <memory>
591# include <stdexcept>
592# include <tuple>
593# include <type_traits>
594# include <typeinfo>
595# include <utility>
596#endif
532#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
533# include <__cxx03/functional>
534#else
535# include <__config>
536
537# include <__functional/binary_function.h>
538# include <__functional/binary_negate.h>
539# include <__functional/bind.h>
540# include <__functional/binder1st.h>
541# include <__functional/binder2nd.h>
542# include <__functional/hash.h>
543# include <__functional/mem_fn.h> // TODO: deprecate
544# include <__functional/mem_fun_ref.h>
545# include <__functional/operations.h>
546# include <__functional/pointer_to_binary_function.h>
547# include <__functional/pointer_to_unary_function.h>
548# include <__functional/reference_wrapper.h>
549# include <__functional/unary_function.h>
550# include <__functional/unary_negate.h>
551
552# ifndef _LIBCPP_CXX03_LANG
553# include <__functional/function.h>
554# endif
555
556# if _LIBCPP_STD_VER >= 17
557# include <__functional/boyer_moore_searcher.h>
558# include <__functional/default_searcher.h>
559# include <__functional/invoke.h>
560# include <__functional/not_fn.h>
561# endif
562
563# if _LIBCPP_STD_VER >= 20
564# include <__functional/bind_back.h>
565# include <__functional/bind_front.h>
566# include <__functional/identity.h>
567# include <__functional/ranges_operations.h>
568# include <__type_traits/unwrap_ref.h>
569# endif
570
571# include <version>
572
573# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
574# pragma GCC system_header
575# endif
576
577# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && defined(_LIBCPP_CXX03_LANG)
578# include <limits>
579# include <new>
580# endif
581
582# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 14
583# include <array>
584# include <initializer_list>
585# include <unordered_map>
586# endif
587
588# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
589# include <atomic>
590# include <concepts>
591# include <cstdlib>
592# include <exception>
593# include <iosfwd>
594# include <memory>
595# include <stdexcept>
596# include <tuple>
597# include <type_traits>
598# include <typeinfo>
599# include <utility>
600# include <vector>
601# endif
602#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
597603
598604#endif // _LIBCPP_FUNCTIONAL
lib/libcxx/include/future+153-125
......@@ -329,7 +329,7 @@ public:
329329 template <class F>
330330 explicit packaged_task(F&& f);
331331 template <class F, class Allocator>
332 packaged_task(allocator_arg_t, const Allocator& a, F&& f);
332 packaged_task(allocator_arg_t, const Allocator& a, F&& f); // removed in C++17
333333 ~packaged_task();
334334
335335 // no copy
......@@ -356,50 +356,68 @@ public:
356356template <class R>
357357 void swap(packaged_task<R(ArgTypes...)&, packaged_task<R(ArgTypes...)>&) noexcept;
358358
359template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
359template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>; // removed in C++17
360360
361361} // std
362362
363363*/
364364
365#include <__config>
366
367#if !defined(_LIBCPP_HAS_NO_THREADS)
368
369# include <__assert>
370# include <__chrono/duration.h>
371# include <__chrono/time_point.h>
372# include <__exception/exception_ptr.h>
373# include <__memory/addressof.h>
374# include <__memory/allocator.h>
375# include <__memory/allocator_arg_t.h>
376# include <__memory/allocator_destructor.h>
377# include <__memory/allocator_traits.h>
378# include <__memory/compressed_pair.h>
379# include <__memory/pointer_traits.h>
380# include <__memory/shared_ptr.h>
381# include <__memory/unique_ptr.h>
382# include <__memory/uses_allocator.h>
383# include <__system_error/error_category.h>
384# include <__system_error/error_code.h>
385# include <__system_error/error_condition.h>
386# include <__type_traits/aligned_storage.h>
387# include <__type_traits/strip_signature.h>
388# include <__utility/auto_cast.h>
389# include <__utility/forward.h>
390# include <__utility/move.h>
391# include <mutex>
392# include <new>
393# include <stdexcept>
394# include <thread>
395# include <version>
396
397# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
398# pragma GCC system_header
399# endif
365#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
366# include <__cxx03/future>
367#else
368# include <__config>
369
370# if _LIBCPP_HAS_THREADS
371
372# include <__assert>
373# include <__chrono/duration.h>
374# include <__chrono/steady_clock.h>
375# include <__chrono/time_point.h>
376# include <__condition_variable/condition_variable.h>
377# include <__cstddef/nullptr_t.h>
378# include <__exception/exception_ptr.h>
379# include <__memory/addressof.h>
380# include <__memory/allocator.h>
381# include <__memory/allocator_arg_t.h>
382# include <__memory/allocator_destructor.h>
383# include <__memory/allocator_traits.h>
384# include <__memory/compressed_pair.h>
385# include <__memory/pointer_traits.h>
386# include <__memory/shared_count.h>
387# include <__memory/unique_ptr.h>
388# include <__memory/uses_allocator.h>
389# include <__mutex/lock_guard.h>
390# include <__mutex/mutex.h>
391# include <__mutex/unique_lock.h>
392# include <__system_error/error_category.h>
393# include <__system_error/error_code.h>
394# include <__system_error/error_condition.h>
395# include <__thread/thread.h>
396# include <__type_traits/add_lvalue_reference.h>
397# include <__type_traits/aligned_storage.h>
398# include <__type_traits/conditional.h>
399# include <__type_traits/decay.h>
400# include <__type_traits/enable_if.h>
401# include <__type_traits/invoke.h>
402# include <__type_traits/is_same.h>
403# include <__type_traits/remove_cvref.h>
404# include <__type_traits/remove_reference.h>
405# include <__type_traits/strip_signature.h>
406# include <__type_traits/underlying_type.h>
407# include <__utility/auto_cast.h>
408# include <__utility/forward.h>
409# include <__utility/move.h>
410# include <__utility/swap.h>
411# include <stdexcept>
412# include <tuple>
413# include <version>
414
415# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
416# pragma GCC system_header
417# endif
400418
401419_LIBCPP_PUSH_MACROS
402# include <__undef_macros>
420# include <__undef_macros>
403421
404422_LIBCPP_BEGIN_NAMESPACE_STD
405423
......@@ -411,16 +429,16 @@ _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_errc)
411429template <>
412430struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<future_errc> : public true_type {};
413431
414# ifdef _LIBCPP_CXX03_LANG
432# ifdef _LIBCPP_CXX03_LANG
415433template <>
416434struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<future_errc::__lx> : public true_type {};
417# endif
435# endif
418436
419437// enum class launch
420438_LIBCPP_DECLARE_STRONG_ENUM(launch){async = 1, deferred = 2, any = async | deferred};
421439_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(launch)
422440
423# ifndef _LIBCPP_CXX03_LANG
441# ifndef _LIBCPP_CXX03_LANG
424442
425443typedef underlying_type<launch>::type __launch_underlying_type;
426444
......@@ -455,7 +473,7 @@ inline _LIBCPP_HIDE_FROM_ABI launch& operator^=(launch& __x, launch __y) {
455473 return __x;
456474}
457475
458# endif // !_LIBCPP_CXX03_LANG
476# endif // !_LIBCPP_CXX03_LANG
459477
460478// enum class future_status
461479_LIBCPP_DECLARE_STRONG_ENUM(future_status){ready, timeout, deferred};
......@@ -471,7 +489,7 @@ inline _LIBCPP_HIDE_FROM_ABI error_condition make_error_condition(future_errc __
471489 return error_condition(static_cast<int>(__e), future_category());
472490}
473491
474_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_future_error(future_errc __ev);
492[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_future_error(future_errc __ev);
475493
476494class _LIBCPP_EXPORTED_FROM_ABI future_error : public logic_error {
477495 error_code __ec_;
......@@ -482,9 +500,9 @@ class _LIBCPP_EXPORTED_FROM_ABI future_error : public logic_error {
482500 friend class promise;
483501
484502public:
485# if _LIBCPP_STD_VER >= 17
503# if _LIBCPP_STD_VER >= 17
486504 _LIBCPP_HIDE_FROM_ABI explicit future_error(future_errc __ec) : future_error(std::make_error_code(__ec)) {}
487# endif
505# endif
488506
489507 _LIBCPP_HIDE_FROM_ABI const error_code& code() const _NOEXCEPT { return __ec_; }
490508
......@@ -494,12 +512,12 @@ public:
494512
495513// Declared above std::future_error
496514void __throw_future_error(future_errc __ev) {
497# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
515# if _LIBCPP_HAS_EXCEPTIONS
498516 throw future_error(make_error_code(__ev));
499# else
517# else
500518 (void)__ev;
501519 _LIBCPP_VERBOSE_ABORT("future_error was thrown in -fno-exceptions mode");
502# endif
520# endif
503521}
504522
505523class _LIBCPP_EXPORTED_FROM_ABI __assoc_sub_state : public __shared_count {
......@@ -588,7 +606,7 @@ public:
588606 _LIBCPP_HIDE_FROM_ABI void set_value_at_thread_exit(_Arg&& __arg);
589607
590608 _LIBCPP_HIDE_FROM_ABI _Rp move();
591 _LIBCPP_HIDE_FROM_ABI __add_lvalue_reference_t<_Rp> copy();
609 _LIBCPP_HIDE_FROM_ABI _Rp& copy();
592610};
593611
594612template <class _Rp>
......@@ -630,7 +648,7 @@ _Rp __assoc_state<_Rp>::move() {
630648}
631649
632650template <class _Rp>
633__add_lvalue_reference_t<_Rp> __assoc_state<_Rp>::copy() {
651_Rp& __assoc_state<_Rp>::copy() {
634652 unique_lock<mutex> __lk(this->__mut_);
635653 this->__sub_wait(__lk);
636654 if (this->__exception_ != nullptr)
......@@ -773,15 +791,15 @@ inline __deferred_assoc_state<_Rp, _Fp>::__deferred_assoc_state(_Fp&& __f) : __f
773791
774792template <class _Rp, class _Fp>
775793void __deferred_assoc_state<_Rp, _Fp>::__execute() {
776# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
794# if _LIBCPP_HAS_EXCEPTIONS
777795 try {
778# endif // _LIBCPP_HAS_NO_EXCEPTIONS
796# endif // _LIBCPP_HAS_EXCEPTIONS
779797 this->set_value(__func_());
780# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
798# if _LIBCPP_HAS_EXCEPTIONS
781799 } catch (...) {
782800 this->set_exception(current_exception());
783801 }
784# endif // _LIBCPP_HAS_NO_EXCEPTIONS
802# endif // _LIBCPP_HAS_EXCEPTIONS
785803}
786804
787805template <class _Fp>
......@@ -803,16 +821,16 @@ inline __deferred_assoc_state<void, _Fp>::__deferred_assoc_state(_Fp&& __f) : __
803821
804822template <class _Fp>
805823void __deferred_assoc_state<void, _Fp>::__execute() {
806# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
824# if _LIBCPP_HAS_EXCEPTIONS
807825 try {
808# endif // _LIBCPP_HAS_NO_EXCEPTIONS
826# endif // _LIBCPP_HAS_EXCEPTIONS
809827 __func_();
810828 this->set_value();
811# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
829# if _LIBCPP_HAS_EXCEPTIONS
812830 } catch (...) {
813831 this->set_exception(current_exception());
814832 }
815# endif // _LIBCPP_HAS_NO_EXCEPTIONS
833# endif // _LIBCPP_HAS_EXCEPTIONS
816834}
817835
818836template <class _Rp, class _Fp>
......@@ -834,15 +852,15 @@ inline __async_assoc_state<_Rp, _Fp>::__async_assoc_state(_Fp&& __f) : __func_(s
834852
835853template <class _Rp, class _Fp>
836854void __async_assoc_state<_Rp, _Fp>::__execute() {
837# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
855# if _LIBCPP_HAS_EXCEPTIONS
838856 try {
839# endif // _LIBCPP_HAS_NO_EXCEPTIONS
857# endif // _LIBCPP_HAS_EXCEPTIONS
840858 this->set_value(__func_());
841# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
859# if _LIBCPP_HAS_EXCEPTIONS
842860 } catch (...) {
843861 this->set_exception(current_exception());
844862 }
845# endif // _LIBCPP_HAS_NO_EXCEPTIONS
863# endif // _LIBCPP_HAS_EXCEPTIONS
846864}
847865
848866template <class _Rp, class _Fp>
......@@ -870,16 +888,16 @@ inline __async_assoc_state<void, _Fp>::__async_assoc_state(_Fp&& __f) : __func_(
870888
871889template <class _Fp>
872890void __async_assoc_state<void, _Fp>::__execute() {
873# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
891# if _LIBCPP_HAS_EXCEPTIONS
874892 try {
875# endif // _LIBCPP_HAS_NO_EXCEPTIONS
893# endif // _LIBCPP_HAS_EXCEPTIONS
876894 __func_();
877895 this->set_value();
878# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
896# if _LIBCPP_HAS_EXCEPTIONS
879897 } catch (...) {
880898 this->set_exception(current_exception());
881899 }
882# endif // _LIBCPP_HAS_NO_EXCEPTIONS
900# endif // _LIBCPP_HAS_EXCEPTIONS
883901}
884902
885903template <class _Fp>
......@@ -1399,13 +1417,13 @@ class __packaged_task_func;
13991417
14001418template <class _Fp, class _Alloc, class _Rp, class... _ArgTypes>
14011419class __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)> : public __packaged_task_base<_Rp(_ArgTypes...)> {
1402 __compressed_pair<_Fp, _Alloc> __f_;
1420 _LIBCPP_COMPRESSED_PAIR(_Fp, __func_, _Alloc, __alloc_);
14031421
14041422public:
1405 _LIBCPP_HIDE_FROM_ABI explicit __packaged_task_func(const _Fp& __f) : __f_(__f, __default_init_tag()) {}
1406 _LIBCPP_HIDE_FROM_ABI explicit __packaged_task_func(_Fp&& __f) : __f_(std::move(__f), __default_init_tag()) {}
1407 _LIBCPP_HIDE_FROM_ABI __packaged_task_func(const _Fp& __f, const _Alloc& __a) : __f_(__f, __a) {}
1408 _LIBCPP_HIDE_FROM_ABI __packaged_task_func(_Fp&& __f, const _Alloc& __a) : __f_(std::move(__f), __a) {}
1423 _LIBCPP_HIDE_FROM_ABI explicit __packaged_task_func(const _Fp& __f) : __func_(__f) {}
1424 _LIBCPP_HIDE_FROM_ABI explicit __packaged_task_func(_Fp&& __f) : __func_(std::move(__f)) {}
1425 _LIBCPP_HIDE_FROM_ABI __packaged_task_func(const _Fp& __f, const _Alloc& __a) : __func_(__f), __alloc_(__a) {}
1426 _LIBCPP_HIDE_FROM_ABI __packaged_task_func(_Fp&& __f, const _Alloc& __a) : __func_(std::move(__f)), __alloc_(__a) {}
14091427 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __move_to(__packaged_task_base<_Rp(_ArgTypes...)>*) _NOEXCEPT;
14101428 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy();
14111429 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy_deallocate();
......@@ -1415,12 +1433,13 @@ public:
14151433template <class _Fp, class _Alloc, class _Rp, class... _ArgTypes>
14161434void __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__move_to(
14171435 __packaged_task_base<_Rp(_ArgTypes...)>* __p) _NOEXCEPT {
1418 ::new ((void*)__p) __packaged_task_func(std::move(__f_.first()), std::move(__f_.second()));
1436 ::new ((void*)__p) __packaged_task_func(std::move(__func_), std::move(__alloc_));
14191437}
14201438
14211439template <class _Fp, class _Alloc, class _Rp, class... _ArgTypes>
14221440void __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() {
1423 __f_.~__compressed_pair<_Fp, _Alloc>();
1441 __func_.~_Fp();
1442 __alloc_.~_Alloc();
14241443}
14251444
14261445template <class _Fp, class _Alloc, class _Rp, class... _ArgTypes>
......@@ -1428,14 +1447,15 @@ void __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate()
14281447 typedef typename __allocator_traits_rebind<_Alloc, __packaged_task_func>::type _Ap;
14291448 typedef allocator_traits<_Ap> _ATraits;
14301449 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
1431 _Ap __a(__f_.second());
1432 __f_.~__compressed_pair<_Fp, _Alloc>();
1450 _Ap __a(__alloc_);
1451 __func_.~_Fp();
1452 __alloc_.~_Alloc();
14331453 __a.deallocate(_PTraits::pointer_to(*this), 1);
14341454}
14351455
14361456template <class _Fp, class _Alloc, class _Rp, class... _ArgTypes>
14371457_Rp __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&&... __arg) {
1438 return std::__invoke(__f_.first(), std::forward<_ArgTypes>(__arg)...);
1458 return std::__invoke(__func_, std::forward<_ArgTypes>(__arg)...);
14391459}
14401460
14411461template <class _Callable>
......@@ -1472,7 +1492,7 @@ public:
14721492
14731493 _LIBCPP_HIDE_FROM_ABI void swap(__packaged_task_function&) _NOEXCEPT;
14741494
1475 _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _Rp operator()(_ArgTypes...) const;
1495 _LIBCPP_HIDE_FROM_ABI _Rp operator()(_ArgTypes...) const;
14761496};
14771497
14781498template <class _Rp, class... _ArgTypes>
......@@ -1592,11 +1612,11 @@ inline _Rp __packaged_task_function<_Rp(_ArgTypes...)>::operator()(_ArgTypes...
15921612template <class _Rp, class... _ArgTypes>
15931613class _LIBCPP_TEMPLATE_VIS packaged_task<_Rp(_ArgTypes...)> {
15941614public:
1595 typedef _Rp result_type; // extension
1615 using result_type _LIBCPP_DEPRECATED = _Rp; // extension
15961616
15971617private:
1598 __packaged_task_function<result_type(_ArgTypes...)> __f_;
1599 promise<result_type> __p_;
1618 __packaged_task_function<_Rp(_ArgTypes...)> __f_;
1619 promise<_Rp> __p_;
16001620
16011621public:
16021622 // construction and destruction
......@@ -1605,9 +1625,11 @@ public:
16051625 template <class _Fp, __enable_if_t<!is_same<__remove_cvref_t<_Fp>, packaged_task>::value, int> = 0>
16061626 _LIBCPP_HIDE_FROM_ABI explicit packaged_task(_Fp&& __f) : __f_(std::forward<_Fp>(__f)) {}
16071627
1628# if _LIBCPP_STD_VER <= 14
16081629 template <class _Fp, class _Allocator, __enable_if_t<!is_same<__remove_cvref_t<_Fp>, packaged_task>::value, int> = 0>
16091630 _LIBCPP_HIDE_FROM_ABI packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f)
16101631 : __f_(allocator_arg_t(), __a, std::forward<_Fp>(__f)), __p_(allocator_arg_t(), __a) {}
1632# endif
16111633 // ~packaged_task() = default;
16121634
16131635 // no copy
......@@ -1631,7 +1653,7 @@ public:
16311653 _LIBCPP_HIDE_FROM_ABI bool valid() const _NOEXCEPT { return __p_.__state_ != nullptr; }
16321654
16331655 // result retrieval
1634 _LIBCPP_HIDE_FROM_ABI future<result_type> get_future() { return __p_.get_future(); }
1656 _LIBCPP_HIDE_FROM_ABI future<_Rp> get_future() { return __p_.get_future(); }
16351657
16361658 // execution
16371659 _LIBCPP_HIDE_FROM_ABI void operator()(_ArgTypes... __args);
......@@ -1646,15 +1668,15 @@ void packaged_task<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __args) {
16461668 __throw_future_error(future_errc::no_state);
16471669 if (__p_.__state_->__has_value())
16481670 __throw_future_error(future_errc::promise_already_satisfied);
1649# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1671# if _LIBCPP_HAS_EXCEPTIONS
16501672 try {
1651# endif // _LIBCPP_HAS_NO_EXCEPTIONS
1673# endif // _LIBCPP_HAS_EXCEPTIONS
16521674 __p_.set_value(__f_(std::forward<_ArgTypes>(__args)...));
1653# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1675# if _LIBCPP_HAS_EXCEPTIONS
16541676 } catch (...) {
16551677 __p_.set_exception(current_exception());
16561678 }
1657# endif // _LIBCPP_HAS_NO_EXCEPTIONS
1679# endif // _LIBCPP_HAS_EXCEPTIONS
16581680}
16591681
16601682template <class _Rp, class... _ArgTypes>
......@@ -1663,41 +1685,43 @@ void packaged_task<_Rp(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __
16631685 __throw_future_error(future_errc::no_state);
16641686 if (__p_.__state_->__has_value())
16651687 __throw_future_error(future_errc::promise_already_satisfied);
1666# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1688# if _LIBCPP_HAS_EXCEPTIONS
16671689 try {
1668# endif // _LIBCPP_HAS_NO_EXCEPTIONS
1690# endif // _LIBCPP_HAS_EXCEPTIONS
16691691 __p_.set_value_at_thread_exit(__f_(std::forward<_ArgTypes>(__args)...));
1670# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1692# if _LIBCPP_HAS_EXCEPTIONS
16711693 } catch (...) {
16721694 __p_.set_exception_at_thread_exit(current_exception());
16731695 }
1674# endif // _LIBCPP_HAS_NO_EXCEPTIONS
1696# endif // _LIBCPP_HAS_EXCEPTIONS
16751697}
16761698
16771699template <class _Rp, class... _ArgTypes>
16781700void packaged_task<_Rp(_ArgTypes...)>::reset() {
16791701 if (!valid())
16801702 __throw_future_error(future_errc::no_state);
1681 __p_ = promise<result_type>();
1703 __p_ = promise<_Rp>();
16821704}
16831705
16841706template <class... _ArgTypes>
16851707class _LIBCPP_TEMPLATE_VIS packaged_task<void(_ArgTypes...)> {
16861708public:
1687 typedef void result_type; // extension
1709 using result_type _LIBCPP_DEPRECATED = void; // extension
16881710
16891711private:
1690 __packaged_task_function<result_type(_ArgTypes...)> __f_;
1691 promise<result_type> __p_;
1712 __packaged_task_function<void(_ArgTypes...)> __f_;
1713 promise<void> __p_;
16921714
16931715public:
16941716 // construction and destruction
16951717 _LIBCPP_HIDE_FROM_ABI packaged_task() _NOEXCEPT : __p_(nullptr) {}
16961718 template <class _Fp, __enable_if_t<!is_same<__remove_cvref_t<_Fp>, packaged_task>::value, int> = 0>
16971719 _LIBCPP_HIDE_FROM_ABI explicit packaged_task(_Fp&& __f) : __f_(std::forward<_Fp>(__f)) {}
1720# if _LIBCPP_STD_VER <= 14
16981721 template <class _Fp, class _Allocator, __enable_if_t<!is_same<__remove_cvref_t<_Fp>, packaged_task>::value, int> = 0>
16991722 _LIBCPP_HIDE_FROM_ABI packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f)
17001723 : __f_(allocator_arg_t(), __a, std::forward<_Fp>(__f)), __p_(allocator_arg_t(), __a) {}
1724# endif
17011725 // ~packaged_task() = default;
17021726
17031727 // no copy
......@@ -1721,7 +1745,7 @@ public:
17211745 _LIBCPP_HIDE_FROM_ABI bool valid() const _NOEXCEPT { return __p_.__state_ != nullptr; }
17221746
17231747 // result retrieval
1724 _LIBCPP_HIDE_FROM_ABI future<result_type> get_future() { return __p_.get_future(); }
1748 _LIBCPP_HIDE_FROM_ABI future<void> get_future() { return __p_.get_future(); }
17251749
17261750 // execution
17271751 _LIBCPP_HIDE_FROM_ABI void operator()(_ArgTypes... __args);
......@@ -1730,7 +1754,7 @@ public:
17301754 _LIBCPP_HIDE_FROM_ABI void reset();
17311755};
17321756
1733# if _LIBCPP_STD_VER >= 17
1757# if _LIBCPP_STD_VER >= 17
17341758
17351759template <class _Rp, class... _Args>
17361760packaged_task(_Rp (*)(_Args...)) -> packaged_task<_Rp(_Args...)>;
......@@ -1738,7 +1762,7 @@ packaged_task(_Rp (*)(_Args...)) -> packaged_task<_Rp(_Args...)>;
17381762template <class _Fp, class _Stripped = typename __strip_signature<decltype(&_Fp::operator())>::type>
17391763packaged_task(_Fp) -> packaged_task<_Stripped>;
17401764
1741# endif
1765# endif
17421766
17431767template <class... _ArgTypes>
17441768void packaged_task<void(_ArgTypes...)>::operator()(_ArgTypes... __args) {
......@@ -1746,16 +1770,16 @@ void packaged_task<void(_ArgTypes...)>::operator()(_ArgTypes... __args) {
17461770 __throw_future_error(future_errc::no_state);
17471771 if (__p_.__state_->__has_value())
17481772 __throw_future_error(future_errc::promise_already_satisfied);
1749# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1773# if _LIBCPP_HAS_EXCEPTIONS
17501774 try {
1751# endif // _LIBCPP_HAS_NO_EXCEPTIONS
1775# endif // _LIBCPP_HAS_EXCEPTIONS
17521776 __f_(std::forward<_ArgTypes>(__args)...);
17531777 __p_.set_value();
1754# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1778# if _LIBCPP_HAS_EXCEPTIONS
17551779 } catch (...) {
17561780 __p_.set_exception(current_exception());
17571781 }
1758# endif // _LIBCPP_HAS_NO_EXCEPTIONS
1782# endif // _LIBCPP_HAS_EXCEPTIONS
17591783}
17601784
17611785template <class... _ArgTypes>
......@@ -1764,23 +1788,23 @@ void packaged_task<void(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... _
17641788 __throw_future_error(future_errc::no_state);
17651789 if (__p_.__state_->__has_value())
17661790 __throw_future_error(future_errc::promise_already_satisfied);
1767# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1791# if _LIBCPP_HAS_EXCEPTIONS
17681792 try {
1769# endif // _LIBCPP_HAS_NO_EXCEPTIONS
1793# endif // _LIBCPP_HAS_EXCEPTIONS
17701794 __f_(std::forward<_ArgTypes>(__args)...);
17711795 __p_.set_value_at_thread_exit();
1772# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1796# if _LIBCPP_HAS_EXCEPTIONS
17731797 } catch (...) {
17741798 __p_.set_exception_at_thread_exit(current_exception());
17751799 }
1776# endif // _LIBCPP_HAS_NO_EXCEPTIONS
1800# endif // _LIBCPP_HAS_EXCEPTIONS
17771801}
17781802
17791803template <class... _ArgTypes>
17801804void packaged_task<void(_ArgTypes...)>::reset() {
17811805 if (!valid())
17821806 __throw_future_error(future_errc::no_state);
1783 __p_ = promise<result_type>();
1807 __p_ = promise<void>();
17841808}
17851809
17861810template <class _Rp, class... _ArgTypes>
......@@ -1789,8 +1813,10 @@ swap(packaged_task<_Rp(_ArgTypes...)>& __x, packaged_task<_Rp(_ArgTypes...)>& __
17891813 __x.swap(__y);
17901814}
17911815
1816# if _LIBCPP_STD_VER <= 14
17921817template <class _Callable, class _Alloc>
17931818struct _LIBCPP_TEMPLATE_VIS uses_allocator<packaged_task<_Callable>, _Alloc> : public true_type {};
1819# endif
17941820
17951821template <class _Rp, class _Fp>
17961822_LIBCPP_HIDE_FROM_ABI future<_Rp> __make_deferred_assoc_state(_Fp&& __f) {
......@@ -1807,14 +1833,14 @@ _LIBCPP_HIDE_FROM_ABI future<_Rp> __make_async_assoc_state(_Fp&& __f) {
18071833 return future<_Rp>(__h.get());
18081834}
18091835
1810# ifndef _LIBCPP_CXX03_LANG
1836# ifndef _LIBCPP_CXX03_LANG
18111837
18121838template <class _Fp, class... _Args>
18131839class _LIBCPP_HIDDEN __async_func {
18141840 tuple<_Fp, _Args...> __f_;
18151841
18161842public:
1817 typedef typename __invoke_of<_Fp, _Args...>::type _Rp;
1843 using _Rp _LIBCPP_NODEBUG = __invoke_result_t<_Fp, _Args...>;
18181844
18191845 _LIBCPP_HIDE_FROM_ABI explicit __async_func(_Fp&& __f, _Args&&... __args)
18201846 : __f_(std::move(__f), std::move(__args)...) {}
......@@ -1838,23 +1864,23 @@ inline _LIBCPP_HIDE_FROM_ABI bool __does_policy_contain(launch __policy, launch
18381864}
18391865
18401866template <class _Fp, class... _Args>
1841_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI future<typename __invoke_of<__decay_t<_Fp>, __decay_t<_Args>...>::type>
1867[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI future<__invoke_result_t<__decay_t<_Fp>, __decay_t<_Args>...> >
18421868async(launch __policy, _Fp&& __f, _Args&&... __args) {
18431869 typedef __async_func<__decay_t<_Fp>, __decay_t<_Args>...> _BF;
18441870 typedef typename _BF::_Rp _Rp;
18451871
1846# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1872# if _LIBCPP_HAS_EXCEPTIONS
18471873 try {
1848# endif
1874# endif
18491875 if (__does_policy_contain(__policy, launch::async))
18501876 return std::__make_async_assoc_state<_Rp>(
18511877 _BF(_LIBCPP_AUTO_CAST(std::forward<_Fp>(__f)), _LIBCPP_AUTO_CAST(std::forward<_Args>(__args))...));
1852# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1878# if _LIBCPP_HAS_EXCEPTIONS
18531879 } catch (...) {
18541880 if (__policy == launch::async)
18551881 throw;
18561882 }
1857# endif
1883# endif
18581884
18591885 if (__does_policy_contain(__policy, launch::deferred))
18601886 return std::__make_deferred_assoc_state<_Rp>(
......@@ -1863,12 +1889,12 @@ async(launch __policy, _Fp&& __f, _Args&&... __args) {
18631889}
18641890
18651891template <class _Fp, class... _Args>
1866_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI future<typename __invoke_of<__decay_t<_Fp>, __decay_t<_Args>...>::type>
1892[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI future<__invoke_result_t<__decay_t<_Fp>, __decay_t<_Args>...> >
18671893async(_Fp&& __f, _Args&&... __args) {
18681894 return std::async(launch::any, std::forward<_Fp>(__f), std::forward<_Args>(__args)...);
18691895}
18701896
1871# endif // C++03
1897# endif // C++03
18721898
18731899// shared_future
18741900
......@@ -2045,18 +2071,20 @@ _LIBCPP_END_NAMESPACE_STD
20452071
20462072_LIBCPP_POP_MACROS
20472073
2048#endif // !defined(_LIBCPP_HAS_NO_THREADS)
2074# endif // _LIBCPP_HAS_THREADS
20492075
2050#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
2051# include <chrono>
2052#endif
2076# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
2077# include <chrono>
2078# endif
20532079
2054#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
2055# include <atomic>
2056# include <cstdlib>
2057# include <exception>
2058# include <iosfwd>
2059# include <system_error>
2060#endif
2080# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
2081# include <atomic>
2082# include <cstdlib>
2083# include <exception>
2084# include <iosfwd>
2085# include <system_error>
2086# include <thread>
2087# endif
2088#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
20612089
20622090#endif // _LIBCPP_FUTURE
lib/libcxx/include/initializer_list+16-7
......@@ -42,17 +42,21 @@ template<class E> const E* end(initializer_list<E> il) noexcept; // constexpr in
4242
4343*/
4444
45#include <__config>
46#include <cstddef>
45#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
46# include <__cxx03/initializer_list>
47#else
48# include <__config>
49# include <__cstddef/size_t.h>
50# include <version>
4751
48#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
49# pragma GCC system_header
50#endif
52# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
53# pragma GCC system_header
54# endif
5155
5256namespace std // purposefully not versioned
5357{
5458
55#ifndef _LIBCPP_CXX03_LANG
59# ifndef _LIBCPP_CXX03_LANG
5660
5761template <class _Ep>
5862class _LIBCPP_TEMPLATE_VIS initializer_list {
......@@ -91,8 +95,13 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Ep* end(initia
9195 return __il.end();
9296}
9397
94#endif // !defined(_LIBCPP_CXX03_LANG)
98# endif // !defined(_LIBCPP_CXX03_LANG)
9599
96100} // namespace std
97101
102# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
103# include <cstddef>
104# endif
105#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
106
98107#endif // _LIBCPP_INITIALIZER_LIST
lib/libcxx/include/inttypes.h+19-15
......@@ -235,30 +235,34 @@ uintmax_t wcstoumax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int
235235
236236*/
237237
238#include <__config>
238#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
239# include <__cxx03/inttypes.h>
240#else
241# include <__config>
239242
240#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
241# pragma GCC system_header
242#endif
243# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
244# pragma GCC system_header
245# endif
243246
244247/* C99 stdlib (e.g. glibc < 2.18) does not provide format macros needed
245248 for C++11 unless __STDC_FORMAT_MACROS is defined
246249*/
247#if defined(__cplusplus) && !defined(__STDC_FORMAT_MACROS)
248# define __STDC_FORMAT_MACROS
249#endif
250# if defined(__cplusplus) && !defined(__STDC_FORMAT_MACROS)
251# define __STDC_FORMAT_MACROS
252# endif
250253
251#if __has_include_next(<inttypes.h>)
252# include_next <inttypes.h>
253#endif
254# if __has_include_next(<inttypes.h>)
255# include_next <inttypes.h>
256# endif
254257
255#ifdef __cplusplus
258# ifdef __cplusplus
256259
257# include <stdint.h>
260# include <stdint.h>
258261
259# undef imaxabs
260# undef imaxdiv
262# undef imaxabs
263# undef imaxdiv
261264
262#endif // __cplusplus
265# endif // __cplusplus
266#endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
263267
264268#endif // _LIBCPP_INTTYPES_H
lib/libcxx/include/iomanip+51-24
......@@ -42,13 +42,22 @@ template <class charT, class traits, class Allocator>
4242
4343*/
4444
45#include <__config>
46#include <istream>
47#include <version>
45#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
46# include <__cxx03/iomanip>
47#else
48# include <__config>
4849
49#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
50# pragma GCC system_header
51#endif
50# if _LIBCPP_HAS_LOCALIZATION
51
52# include <__ostream/put_character_sequence.h>
53# include <ios>
54# include <iosfwd>
55# include <locale>
56# include <version>
57
58# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
59# pragma GCC system_header
60# endif
5261
5362_LIBCPP_BEGIN_NAMESPACE_STD
5463
......@@ -231,9 +240,9 @@ public:
231240template <class _CharT, class _Traits, class _MoneyT>
232241_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
233242operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x) {
234#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
243# if _LIBCPP_HAS_EXCEPTIONS
235244 try {
236#endif // _LIBCPP_HAS_NO_EXCEPTIONS
245# endif // _LIBCPP_HAS_EXCEPTIONS
237246 typename basic_istream<_CharT, _Traits>::sentry __s(__is);
238247 if (__s) {
239248 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
......@@ -243,11 +252,11 @@ operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x) {
243252 __mf.get(_Ip(__is), _Ip(), __x.__intl_, __is, __err, __x.__mon_);
244253 __is.setstate(__err);
245254 }
246#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
255# if _LIBCPP_HAS_EXCEPTIONS
247256 } catch (...) {
248257 __is.__set_badbit_and_consider_rethrow();
249258 }
250#endif // _LIBCPP_HAS_NO_EXCEPTIONS
259# endif // _LIBCPP_HAS_EXCEPTIONS
251260 return __is;
252261}
253262
......@@ -280,9 +289,9 @@ public:
280289template <class _CharT, class _Traits, class _MoneyT>
281290_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
282291operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x) {
283#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
292# if _LIBCPP_HAS_EXCEPTIONS
284293 try {
285#endif // _LIBCPP_HAS_NO_EXCEPTIONS
294# endif // _LIBCPP_HAS_EXCEPTIONS
286295 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
287296 if (__s) {
288297 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
......@@ -291,11 +300,11 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x) {
291300 if (__mf.put(_Op(__os), __x.__intl_, __os, __os.fill(), __x.__mon_).failed())
292301 __os.setstate(ios_base::badbit);
293302 }
294#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
303# if _LIBCPP_HAS_EXCEPTIONS
295304 } catch (...) {
296305 __os.__set_badbit_and_consider_rethrow();
297306 }
298#endif // _LIBCPP_HAS_NO_EXCEPTIONS
307# endif // _LIBCPP_HAS_EXCEPTIONS
299308 return __os;
300309}
301310
......@@ -328,9 +337,9 @@ public:
328337template <class _CharT, class _Traits>
329338_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
330339operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x) {
331#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
340# if _LIBCPP_HAS_EXCEPTIONS
332341 try {
333#endif // _LIBCPP_HAS_NO_EXCEPTIONS
342# endif // _LIBCPP_HAS_EXCEPTIONS
334343 typename basic_istream<_CharT, _Traits>::sentry __s(__is);
335344 if (__s) {
336345 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
......@@ -340,11 +349,11 @@ operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x) {
340349 __tf.get(_Ip(__is), _Ip(), __is, __err, __x.__tm_, __x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_));
341350 __is.setstate(__err);
342351 }
343#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
352# if _LIBCPP_HAS_EXCEPTIONS
344353 } catch (...) {
345354 __is.__set_badbit_and_consider_rethrow();
346355 }
347#endif // _LIBCPP_HAS_NO_EXCEPTIONS
356# endif // _LIBCPP_HAS_EXCEPTIONS
348357 return __is;
349358}
350359
......@@ -377,9 +386,9 @@ public:
377386template <class _CharT, class _Traits>
378387_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
379388operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x) {
380#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
389# if _LIBCPP_HAS_EXCEPTIONS
381390 try {
382#endif // _LIBCPP_HAS_NO_EXCEPTIONS
391# endif // _LIBCPP_HAS_EXCEPTIONS
383392 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
384393 if (__s) {
385394 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
......@@ -389,11 +398,11 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x) {
389398 .failed())
390399 __os.setstate(ios_base::badbit);
391400 }
392#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
401# if _LIBCPP_HAS_EXCEPTIONS
393402 } catch (...) {
394403 __os.__set_badbit_and_consider_rethrow();
395404 }
396#endif // _LIBCPP_HAS_NO_EXCEPTIONS
405# endif // _LIBCPP_HAS_EXCEPTIONS
397406 return __os;
398407}
399408
......@@ -505,7 +514,7 @@ __quoted(basic_string<_CharT, _Traits, _Allocator>& __s, _CharT __delim = _CharT
505514 return __quoted_proxy<_CharT, _Traits, _Allocator>(__s, __delim, __escape);
506515}
507516
508#if _LIBCPP_STD_VER >= 14
517# if _LIBCPP_STD_VER >= 14
509518
510519template <class _CharT>
511520_LIBCPP_HIDE_FROM_ABI auto quoted(const _CharT* __s, _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\')) {
......@@ -535,8 +544,26 @@ quoted(basic_string_view<_CharT, _Traits> __sv, _CharT __delim = _CharT('"'), _C
535544 return __quoted_output_proxy<_CharT, _Traits>(__sv.data(), __sv.data() + __sv.size(), __delim, __escape);
536545}
537546
538#endif // _LIBCPP_STD_VER >= 14
547# endif // _LIBCPP_STD_VER >= 14
539548
540549_LIBCPP_END_NAMESPACE_STD
541550
551# endif // _LIBCPP_HAS_LOCALIZATION
552
553# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
554# include <array>
555# include <bitset>
556# include <deque>
557# include <format>
558# include <functional>
559# include <istream>
560# include <ostream>
561# include <print>
562# include <queue>
563# include <stack>
564# include <unordered_map>
565# include <vector>
566# endif
567#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
568
542569#endif // _LIBCPP_IOMANIP
lib/libcxx/include/ios+73-65
......@@ -211,36 +211,40 @@ storage-class-specifier const error_category& iostream_category() noexcept;
211211
212212*/
213213
214#include <__config>
215
216#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
217
218# include <__fwd/ios.h>
219# include <__ios/fpos.h>
220# include <__locale>
221# include <__system_error/error_category.h>
222# include <__system_error/error_code.h>
223# include <__system_error/error_condition.h>
224# include <__system_error/system_error.h>
225# include <__utility/swap.h>
226# include <__verbose_abort>
227# include <version>
214#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
215# include <__cxx03/ios>
216#else
217# include <__config>
218
219# if _LIBCPP_HAS_LOCALIZATION
220
221# include <__fwd/ios.h>
222# include <__ios/fpos.h>
223# include <__locale>
224# include <__memory/addressof.h>
225# include <__system_error/error_category.h>
226# include <__system_error/error_code.h>
227# include <__system_error/error_condition.h>
228# include <__system_error/system_error.h>
229# include <__utility/swap.h>
230# include <__verbose_abort>
231# include <version>
228232
229233// standard-mandated includes
230234
231235// [ios.syn]
232# include <iosfwd>
236# include <iosfwd>
233237
234# if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
235# include <__atomic/atomic.h> // for __xindex_
236# endif
238# if _LIBCPP_HAS_ATOMIC_HEADER
239# include <__atomic/atomic.h> // for __xindex_
240# endif
237241
238# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
239# pragma GCC system_header
240# endif
242# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
243# pragma GCC system_header
244# endif
241245
242246_LIBCPP_PUSH_MACROS
243# include <__undef_macros>
247# include <__undef_macros>
244248
245249_LIBCPP_BEGIN_NAMESPACE_STD
246250
......@@ -283,20 +287,20 @@ public:
283287 static const openmode in = 0x08;
284288 static const openmode out = 0x10;
285289 static const openmode trunc = 0x20;
286# if _LIBCPP_STD_VER >= 23
290# if _LIBCPP_STD_VER >= 23
287291 static const openmode noreplace = 0x40;
288# endif
292# endif
289293
290294 enum seekdir { beg, cur, end };
291295
292# if _LIBCPP_STD_VER <= 14
296# if _LIBCPP_STD_VER <= 14
293297 typedef iostate io_state;
294298 typedef openmode open_mode;
295299 typedef seekdir seek_dir;
296300
297301 typedef std::streamoff streamoff;
298302 typedef std::streampos streampos;
299# endif
303# endif
300304
301305 class _LIBCPP_EXPORTED_FROM_ABI Init;
302306
......@@ -396,11 +400,11 @@ private:
396400 size_t __event_cap_;
397401// TODO(EricWF): Enable this for both Clang and GCC. Currently it is only
398402// enabled with clang.
399# if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
403# if _LIBCPP_HAS_C_ATOMIC_IMP && _LIBCPP_HAS_THREADS
400404 static atomic<int> __xindex_;
401# else
405# else
402406 static int __xindex_;
403# endif
407# endif
404408 long* __iarray_;
405409 size_t __iarray_size_;
406410 size_t __iarray_cap_;
......@@ -416,10 +420,10 @@ _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc)
416420template <>
417421struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc> : public true_type {};
418422
419# ifdef _LIBCPP_CXX03_LANG
423# ifdef _LIBCPP_CXX03_LANG
420424template <>
421425struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc::__lx> : public true_type {};
422# endif
426# endif
423427
424428_LIBCPP_EXPORTED_FROM_ABI const error_category& iostream_category() _NOEXCEPT;
425429
......@@ -439,12 +443,12 @@ public:
439443 ~failure() _NOEXCEPT override;
440444};
441445
442_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_failure(char const* __msg) {
443# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
446[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_failure(char const* __msg) {
447# if _LIBCPP_HAS_EXCEPTIONS
444448 throw ios_base::failure(__msg);
445# else
449# else
446450 _LIBCPP_VERBOSE_ABORT("ios_base::failure was thrown in -fno-exceptions mode with message \"%s\"", __msg);
447# endif
451# endif
448452}
449453
450454class _LIBCPP_EXPORTED_FROM_ABI ios_base::Init {
......@@ -523,7 +527,10 @@ template <class _Traits>
523527// Attribute 'packed' is used to keep the layout compatible with the previous
524528// definition of the '__fill_' and '_set_' pair in basic_ios on AIX & z/OS.
525529struct _LIBCPP_PACKED _FillHelper {
526 _LIBCPP_HIDE_FROM_ABI void __init() { __set_ = false; }
530 _LIBCPP_HIDE_FROM_ABI void __init() {
531 __set_ = false;
532 __fill_val_ = _Traits::eof();
533 }
527534 _LIBCPP_HIDE_FROM_ABI _FillHelper& operator=(typename _Traits::int_type __x) {
528535 __set_ = true;
529536 __fill_val_ = __x;
......@@ -565,13 +572,13 @@ public:
565572 static_assert(is_same<_CharT, typename traits_type::char_type>::value,
566573 "traits_type::char_type must be the same type as CharT");
567574
568# ifdef _LIBCPP_CXX03_LANG
575# ifdef _LIBCPP_CXX03_LANG
569576 // Preserve the ability to compare with literal 0,
570577 // and implicitly convert to bool, but not implicitly convert to int.
571578 _LIBCPP_HIDE_FROM_ABI operator void*() const { return fail() ? nullptr : (void*)this; }
572# else
579# else
573580 _LIBCPP_HIDE_FROM_ABI explicit operator bool() const { return !fail(); }
574# endif
581# endif
575582
576583 _LIBCPP_HIDE_FROM_ABI bool operator!() const { return fail(); }
577584 _LIBCPP_HIDE_FROM_ABI iostate rdstate() const { return ios_base::rdstate(); }
......@@ -621,11 +628,11 @@ protected:
621628private:
622629 basic_ostream<char_type, traits_type>* __tie_;
623630
624#if defined(_LIBCPP_ABI_IOS_ALLOW_ARBITRARY_FILL_VALUE)
625 using _FillType = _FillHelper<traits_type>;
626#else
627 using _FillType = _SentinelValueFill<traits_type>;
628#endif
631# if defined(_LIBCPP_ABI_IOS_ALLOW_ARBITRARY_FILL_VALUE)
632 using _FillType _LIBCPP_NODEBUG = _FillHelper<traits_type>;
633# else
634 using _FillType _LIBCPP_NODEBUG = _SentinelValueFill<traits_type>;
635# endif
629636 mutable _FillType __fill_;
630637};
631638
......@@ -640,7 +647,7 @@ basic_ios<_CharT, _Traits>::~basic_ios() {}
640647template <class _CharT, class _Traits>
641648inline _LIBCPP_HIDE_FROM_ABI void basic_ios<_CharT, _Traits>::init(basic_streambuf<char_type, traits_type>* __sb) {
642649 ios_base::init(__sb);
643 __tie_ = nullptr;
650 __tie_ = nullptr;
644651 __fill_.__init();
645652}
646653
......@@ -707,7 +714,7 @@ inline _LIBCPP_HIDE_FROM_ABI _CharT basic_ios<_CharT, _Traits>::fill(char_type _
707714
708715template <class _CharT, class _Traits>
709716basic_ios<_CharT, _Traits>& basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs) {
710 if (this != &__rhs) {
717 if (this != std::addressof(__rhs)) {
711718 __call_callbacks(erase_event);
712719 ios_base::copyfmt(__rhs);
713720 __tie_ = __rhs.__tie_;
......@@ -740,9 +747,9 @@ inline _LIBCPP_HIDE_FROM_ABI void basic_ios<_CharT, _Traits>::set_rdbuf(basic_st
740747
741748extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<char>;
742749
743# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
750# if _LIBCPP_HAS_WIDE_CHARACTERS
744751extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<wchar_t>;
745# endif
752# endif
746753
747754_LIBCPP_HIDE_FROM_ABI inline ios_base& boolalpha(ios_base& __str) {
748755 __str.setf(ios_base::boolalpha);
......@@ -868,22 +875,23 @@ _LIBCPP_END_NAMESPACE_STD
868875
869876_LIBCPP_POP_MACROS
870877
871#endif // !defined(_LIBCPP_HAS_NO_LOCALIZATION)
872
873#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
874# include <atomic>
875# include <concepts>
876# include <cstddef>
877# include <cstdlib>
878# include <cstring>
879# include <initializer_list>
880# include <limits>
881# include <mutex>
882# include <new>
883# include <stdexcept>
884# include <system_error>
885# include <type_traits>
886# include <typeinfo>
887#endif
878# endif // _LIBCPP_HAS_LOCALIZATION
879
880# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
881# include <atomic>
882# include <concepts>
883# include <cstddef>
884# include <cstdlib>
885# include <cstring>
886# include <initializer_list>
887# include <limits>
888# include <mutex>
889# include <new>
890# include <stdexcept>
891# include <system_error>
892# include <type_traits>
893# include <typeinfo>
894# endif
895#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
888896
889897#endif // _LIBCPP_IOS
lib/libcxx/include/iosfwd+32-27
......@@ -105,21 +105,24 @@ using wosyncstream = basic_osyncstream<wchar_t>; // C++20
105105
106106*/
107107
108#include <__config>
109#include <__fwd/fstream.h>
110#include <__fwd/ios.h>
111#include <__fwd/istream.h>
112#include <__fwd/memory.h>
113#include <__fwd/ostream.h>
114#include <__fwd/sstream.h>
115#include <__fwd/streambuf.h>
116#include <__fwd/string.h>
117#include <__std_mbstate_t.h>
118#include <version>
119
120#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
121# pragma GCC system_header
122#endif
108#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
109# include <__cxx03/iosfwd>
110#else
111# include <__config>
112# include <__fwd/fstream.h>
113# include <__fwd/ios.h>
114# include <__fwd/istream.h>
115# include <__fwd/memory.h>
116# include <__fwd/ostream.h>
117# include <__fwd/sstream.h>
118# include <__fwd/streambuf.h>
119# include <__fwd/string.h>
120# include <__std_mbstate_t.h>
121# include <version>
122
123# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
124# pragma GCC system_header
125# endif
123126
124127_LIBCPP_BEGIN_NAMESPACE_STD
125128
......@@ -131,34 +134,34 @@ class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator;
131134template <class _State>
132135class _LIBCPP_TEMPLATE_VIS fpos;
133136typedef fpos<mbstate_t> streampos;
134#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
137# if _LIBCPP_HAS_WIDE_CHARACTERS
135138typedef fpos<mbstate_t> wstreampos;
136#endif
137#ifndef _LIBCPP_HAS_NO_CHAR8_T
139# endif
140# if _LIBCPP_HAS_CHAR8_T
138141typedef fpos<mbstate_t> u8streampos;
139#endif
142# endif
140143typedef fpos<mbstate_t> u16streampos;
141144typedef fpos<mbstate_t> u32streampos;
142145
143#if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM)
146# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_EXPERIMENTAL_SYNCSTREAM
144147
145148template <class _CharT, class _Traits = char_traits<_CharT>, class _Allocator = allocator<_CharT>>
146149class basic_syncbuf;
147150
148151using syncbuf = basic_syncbuf<char>;
149# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
152# if _LIBCPP_HAS_WIDE_CHARACTERS
150153using wsyncbuf = basic_syncbuf<wchar_t>;
151# endif
154# endif
152155
153156template <class _CharT, class _Traits = char_traits<_CharT>, class _Allocator = allocator<_CharT>>
154157class basic_osyncstream;
155158
156159using osyncstream = basic_osyncstream<char>;
157# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
160# if _LIBCPP_HAS_WIDE_CHARACTERS
158161using wosyncstream = basic_osyncstream<wchar_t>;
159# endif
162# endif
160163
161#endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM)
164# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_EXPERIMENTAL_SYNCSTREAM
162165
163166template <class _CharT, class _Traits>
164167class __save_flags {
......@@ -170,8 +173,8 @@ class __save_flags {
170173 _CharT __fill_;
171174
172175public:
173 __save_flags(const __save_flags&) = delete;
174 __save_flags& operator=(const __save_flags&) = delete;
176 __save_flags(const __save_flags&) = delete;
177 __save_flags& operator=(const __save_flags&) = delete;
175178
176179 _LIBCPP_HIDE_FROM_ABI explicit __save_flags(__stream_type& __stream)
177180 : __stream_(__stream), __fmtflags_(__stream.flags()), __fill_(__stream.fill()) {}
......@@ -183,4 +186,6 @@ public:
183186
184187_LIBCPP_END_NAMESPACE_STD
185188
189#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
190
186191#endif // _LIBCPP_IOSFWD
lib/libcxx/include/iostream+16-11
......@@ -33,20 +33,23 @@ extern wostream wclog;
3333
3434*/
3535
36#include <__config>
37#include <version>
36#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
37# include <__cxx03/iostream>
38#else
39# include <__config>
40# include <version>
3841
3942// standard-mandated includes
4043
4144// [iostream.syn]
42#include <ios>
43#include <istream>
44#include <ostream>
45#include <streambuf>
45# include <ios>
46# include <istream>
47# include <ostream>
48# include <streambuf>
4649
47#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
48# pragma GCC system_header
49#endif
50# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
51# pragma GCC system_header
52# endif
5053
5154_LIBCPP_BEGIN_NAMESPACE_STD
5255
......@@ -55,13 +58,15 @@ extern _LIBCPP_EXPORTED_FROM_ABI ostream cout;
5558extern _LIBCPP_EXPORTED_FROM_ABI ostream cerr;
5659extern _LIBCPP_EXPORTED_FROM_ABI ostream clog;
5760
58#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
61# if _LIBCPP_HAS_WIDE_CHARACTERS
5962extern _LIBCPP_EXPORTED_FROM_ABI wistream wcin;
6063extern _LIBCPP_EXPORTED_FROM_ABI wostream wcout;
6164extern _LIBCPP_EXPORTED_FROM_ABI wostream wcerr;
6265extern _LIBCPP_EXPORTED_FROM_ABI wostream wclog;
63#endif
66# endif
6467
6568_LIBCPP_END_NAMESPACE_STD
6669
70#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
71
6772#endif // _LIBCPP_IOSTREAM
lib/libcxx/include/istream+143-127
......@@ -158,26 +158,33 @@ template <class Stream, class T>
158158
159159*/
160160
161#include <__config>
162#include <__fwd/istream.h>
163#include <__iterator/istreambuf_iterator.h>
164#include <__ostream/basic_ostream.h>
165#include <__type_traits/conjunction.h>
166#include <__type_traits/enable_if.h>
167#include <__type_traits/is_base_of.h>
168#include <__utility/declval.h>
169#include <__utility/forward.h>
170#include <bitset>
171#include <ios>
172#include <locale>
173#include <version>
174
175#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
176# pragma GCC system_header
177#endif
161#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
162# include <__cxx03/istream>
163#else
164# include <__config>
165
166# if _LIBCPP_HAS_LOCALIZATION
167
168# include <__fwd/istream.h>
169# include <__iterator/istreambuf_iterator.h>
170# include <__ostream/basic_ostream.h>
171# include <__type_traits/conjunction.h>
172# include <__type_traits/enable_if.h>
173# include <__type_traits/is_base_of.h>
174# include <__type_traits/make_unsigned.h>
175# include <__utility/declval.h>
176# include <__utility/forward.h>
177# include <bitset>
178# include <ios>
179# include <locale>
180# include <version>
181
182# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
183# pragma GCC system_header
184# endif
178185
179186_LIBCPP_PUSH_MACROS
180#include <__undef_macros>
187# include <__undef_macros>
181188
182189_LIBCPP_BEGIN_NAMESPACE_STD
183190
......@@ -353,13 +360,13 @@ __input_arithmetic(basic_istream<_CharT, _Traits>& __is, _Tp& __n) {
353360 ios_base::iostate __state = ios_base::goodbit;
354361 typename basic_istream<_CharT, _Traits>::sentry __s(__is);
355362 if (__s) {
356#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
363# if _LIBCPP_HAS_EXCEPTIONS
357364 try {
358#endif // _LIBCPP_HAS_NO_EXCEPTIONS
365# endif // _LIBCPP_HAS_EXCEPTIONS
359366 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
360367 typedef num_get<_CharT, _Ip> _Fp;
361368 std::use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __state, __n);
362#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
369# if _LIBCPP_HAS_EXCEPTIONS
363370 } catch (...) {
364371 __state |= ios_base::badbit;
365372 __is.__setstate_nothrow(__state);
......@@ -367,7 +374,7 @@ __input_arithmetic(basic_istream<_CharT, _Traits>& __is, _Tp& __n) {
367374 throw;
368375 }
369376 }
370#endif
377# endif
371378 __is.setstate(__state);
372379 }
373380 return __is;
......@@ -434,9 +441,9 @@ __input_arithmetic_with_numeric_limits(basic_istream<_CharT, _Traits>& __is, _Tp
434441 ios_base::iostate __state = ios_base::goodbit;
435442 typename basic_istream<_CharT, _Traits>::sentry __s(__is);
436443 if (__s) {
437#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
444# if _LIBCPP_HAS_EXCEPTIONS
438445 try {
439#endif // _LIBCPP_HAS_NO_EXCEPTIONS
446# endif // _LIBCPP_HAS_EXCEPTIONS
440447 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
441448 typedef num_get<_CharT, _Ip> _Fp;
442449 long __temp;
......@@ -450,7 +457,7 @@ __input_arithmetic_with_numeric_limits(basic_istream<_CharT, _Traits>& __is, _Tp
450457 } else {
451458 __n = static_cast<_Tp>(__temp);
452459 }
453#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
460# if _LIBCPP_HAS_EXCEPTIONS
454461 } catch (...) {
455462 __state |= ios_base::badbit;
456463 __is.__setstate_nothrow(__state);
......@@ -458,7 +465,7 @@ __input_arithmetic_with_numeric_limits(basic_istream<_CharT, _Traits>& __is, _Tp
458465 throw;
459466 }
460467 }
461#endif // _LIBCPP_HAS_NO_EXCEPTIONS
468# endif // _LIBCPP_HAS_EXCEPTIONS
462469 __is.setstate(__state);
463470 }
464471 return __is;
......@@ -480,9 +487,9 @@ __input_c_string(basic_istream<_CharT, _Traits>& __is, _CharT* __p, size_t __n)
480487 ios_base::iostate __state = ios_base::goodbit;
481488 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
482489 if (__sen) {
483#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
490# if _LIBCPP_HAS_EXCEPTIONS
484491 try {
485#endif
492# endif
486493 _CharT* __s = __p;
487494 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());
488495 while (__s != __p + (__n - 1)) {
......@@ -501,7 +508,7 @@ __input_c_string(basic_istream<_CharT, _Traits>& __is, _CharT* __p, size_t __n)
501508 __is.width(0);
502509 if (__s == __p)
503510 __state |= ios_base::failbit;
504#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
511# if _LIBCPP_HAS_EXCEPTIONS
505512 } catch (...) {
506513 __state |= ios_base::badbit;
507514 __is.__setstate_nothrow(__state);
......@@ -509,13 +516,13 @@ __input_c_string(basic_istream<_CharT, _Traits>& __is, _CharT* __p, size_t __n)
509516 throw;
510517 }
511518 }
512#endif
519# endif
513520 __is.setstate(__state);
514521 }
515522 return __is;
516523}
517524
518#if _LIBCPP_STD_VER >= 20
525# if _LIBCPP_STD_VER >= 20
519526
520527template <class _CharT, class _Traits, size_t _Np>
521528inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
......@@ -538,7 +545,7 @@ operator>>(basic_istream<char, _Traits>& __is, signed char (&__buf)[_Np]) {
538545 return __is >> (char(&)[_Np])__buf;
539546}
540547
541#else
548# else
542549
543550template <class _CharT, class _Traits>
544551inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
......@@ -561,22 +568,22 @@ operator>>(basic_istream<char, _Traits>& __is, signed char* __s) {
561568 return __is >> (char*)__s;
562569}
563570
564#endif // _LIBCPP_STD_VER >= 20
571# endif // _LIBCPP_STD_VER >= 20
565572
566573template <class _CharT, class _Traits>
567574_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c) {
568575 ios_base::iostate __state = ios_base::goodbit;
569576 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
570577 if (__sen) {
571#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
578# if _LIBCPP_HAS_EXCEPTIONS
572579 try {
573#endif
580# endif
574581 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
575582 if (_Traits::eq_int_type(__i, _Traits::eof()))
576583 __state |= ios_base::eofbit | ios_base::failbit;
577584 else
578585 __c = _Traits::to_char_type(__i);
579#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
586# if _LIBCPP_HAS_EXCEPTIONS
580587 } catch (...) {
581588 __state |= ios_base::badbit;
582589 __is.__setstate_nothrow(__state);
......@@ -584,7 +591,7 @@ _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& operator>>(basic_istream<_
584591 throw;
585592 }
586593 }
587#endif
594# endif
588595 __is.setstate(__state);
589596 }
590597 return __is;
......@@ -610,9 +617,9 @@ basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_typ
610617 sentry __s(*this, true);
611618 if (__s) {
612619 if (__sb) {
613#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
620# if _LIBCPP_HAS_EXCEPTIONS
614621 try {
615#endif // _LIBCPP_HAS_NO_EXCEPTIONS
622# endif // _LIBCPP_HAS_EXCEPTIONS
616623 while (true) {
617624 typename traits_type::int_type __i = this->rdbuf()->sgetc();
618625 if (traits_type::eq_int_type(__i, _Traits::eof())) {
......@@ -626,7 +633,7 @@ basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_typ
626633 }
627634 if (__gc_ == 0)
628635 __state |= ios_base::failbit;
629#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
636# if _LIBCPP_HAS_EXCEPTIONS
630637 } catch (...) {
631638 __state |= ios_base::badbit;
632639 if (__gc_ == 0)
......@@ -637,7 +644,7 @@ basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_typ
637644 throw;
638645 }
639646 }
640#endif // _LIBCPP_HAS_NO_EXCEPTIONS
647# endif // _LIBCPP_HAS_EXCEPTIONS
641648 } else {
642649 __state |= ios_base::failbit;
643650 }
......@@ -653,22 +660,22 @@ typename basic_istream<_CharT, _Traits>::int_type basic_istream<_CharT, _Traits>
653660 int_type __r = traits_type::eof();
654661 sentry __s(*this, true);
655662 if (__s) {
656#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
663# if _LIBCPP_HAS_EXCEPTIONS
657664 try {
658#endif
665# endif
659666 __r = this->rdbuf()->sbumpc();
660667 if (traits_type::eq_int_type(__r, traits_type::eof()))
661668 __state |= ios_base::failbit | ios_base::eofbit;
662669 else
663670 __gc_ = 1;
664#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
671# if _LIBCPP_HAS_EXCEPTIONS
665672 } catch (...) {
666673 this->__setstate_nothrow(this->rdstate() | ios_base::badbit);
667674 if (this->exceptions() & ios_base::badbit) {
668675 throw;
669676 }
670677 }
671#endif
678# endif
672679 this->setstate(__state);
673680 }
674681 return __r;
......@@ -681,9 +688,9 @@ basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(char_type* _
681688 sentry __sen(*this, true);
682689 if (__sen) {
683690 if (__n > 0) {
684#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
691# if _LIBCPP_HAS_EXCEPTIONS
685692 try {
686#endif
693# endif
687694 while (__gc_ < __n - 1) {
688695 int_type __i = this->rdbuf()->sgetc();
689696 if (traits_type::eq_int_type(__i, traits_type::eof())) {
......@@ -699,7 +706,7 @@ basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(char_type* _
699706 }
700707 if (__gc_ == 0)
701708 __state |= ios_base::failbit;
702#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
709# if _LIBCPP_HAS_EXCEPTIONS
703710 } catch (...) {
704711 __state |= ios_base::badbit;
705712 this->__setstate_nothrow(__state);
......@@ -709,7 +716,7 @@ basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(char_type* _
709716 throw;
710717 }
711718 }
712#endif
719# endif
713720 } else {
714721 __state |= ios_base::failbit;
715722 }
......@@ -730,9 +737,9 @@ basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __s
730737 __gc_ = 0;
731738 sentry __sen(*this, true);
732739 if (__sen) {
733#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
740# if _LIBCPP_HAS_EXCEPTIONS
734741 try {
735#endif // _LIBCPP_HAS_NO_EXCEPTIONS
742# endif // _LIBCPP_HAS_EXCEPTIONS
736743 while (true) {
737744 typename traits_type::int_type __i = this->rdbuf()->sgetc();
738745 if (traits_type::eq_int_type(__i, traits_type::eof())) {
......@@ -747,12 +754,12 @@ basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __s
747754 __inc_gcount();
748755 this->rdbuf()->sbumpc();
749756 }
750#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
757# if _LIBCPP_HAS_EXCEPTIONS
751758 } catch (...) {
752759 __state |= ios_base::badbit;
753760 // according to the spec, exceptions here are caught but not rethrown
754761 }
755#endif // _LIBCPP_HAS_NO_EXCEPTIONS
762# endif // _LIBCPP_HAS_EXCEPTIONS
756763 if (__gc_ == 0)
757764 __state |= ios_base::failbit;
758765 this->setstate(__state);
......@@ -767,9 +774,9 @@ basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_typ
767774 __gc_ = 0;
768775 sentry __sen(*this, true);
769776 if (__sen) {
770#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
777# if _LIBCPP_HAS_EXCEPTIONS
771778 try {
772#endif // _LIBCPP_HAS_NO_EXCEPTIONS
779# endif // _LIBCPP_HAS_EXCEPTIONS
773780 while (true) {
774781 typename traits_type::int_type __i = this->rdbuf()->sgetc();
775782 if (traits_type::eq_int_type(__i, traits_type::eof())) {
......@@ -790,7 +797,7 @@ basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_typ
790797 this->rdbuf()->sbumpc();
791798 __inc_gcount();
792799 }
793#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
800# if _LIBCPP_HAS_EXCEPTIONS
794801 } catch (...) {
795802 __state |= ios_base::badbit;
796803 this->__setstate_nothrow(__state);
......@@ -802,7 +809,7 @@ basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_typ
802809 throw;
803810 }
804811 }
805#endif // _LIBCPP_HAS_NO_EXCEPTIONS
812# endif // _LIBCPP_HAS_EXCEPTIONS
806813 }
807814 if (__n > 0)
808815 *__s = char_type();
......@@ -818,9 +825,9 @@ basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::ignore(streamsiz
818825 __gc_ = 0;
819826 sentry __sen(*this, true);
820827 if (__sen) {
821#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
828# if _LIBCPP_HAS_EXCEPTIONS
822829 try {
823#endif // _LIBCPP_HAS_NO_EXCEPTIONS
830# endif // _LIBCPP_HAS_EXCEPTIONS
824831 if (__n == numeric_limits<streamsize>::max()) {
825832 while (true) {
826833 typename traits_type::int_type __i = this->rdbuf()->sbumpc();
......@@ -844,7 +851,7 @@ basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::ignore(streamsiz
844851 break;
845852 }
846853 }
847#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
854# if _LIBCPP_HAS_EXCEPTIONS
848855 } catch (...) {
849856 __state |= ios_base::badbit;
850857 this->__setstate_nothrow(__state);
......@@ -852,7 +859,7 @@ basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::ignore(streamsiz
852859 throw;
853860 }
854861 }
855#endif // _LIBCPP_HAS_NO_EXCEPTIONS
862# endif // _LIBCPP_HAS_EXCEPTIONS
856863 this->setstate(__state);
857864 }
858865 return *this;
......@@ -865,13 +872,13 @@ typename basic_istream<_CharT, _Traits>::int_type basic_istream<_CharT, _Traits>
865872 int_type __r = traits_type::eof();
866873 sentry __sen(*this, true);
867874 if (__sen) {
868#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
875# if _LIBCPP_HAS_EXCEPTIONS
869876 try {
870#endif // _LIBCPP_HAS_NO_EXCEPTIONS
877# endif // _LIBCPP_HAS_EXCEPTIONS
871878 __r = this->rdbuf()->sgetc();
872879 if (traits_type::eq_int_type(__r, traits_type::eof()))
873880 __state |= ios_base::eofbit;
874#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
881# if _LIBCPP_HAS_EXCEPTIONS
875882 } catch (...) {
876883 __state |= ios_base::badbit;
877884 this->__setstate_nothrow(__state);
......@@ -879,7 +886,7 @@ typename basic_istream<_CharT, _Traits>::int_type basic_istream<_CharT, _Traits>
879886 throw;
880887 }
881888 }
882#endif // _LIBCPP_HAS_NO_EXCEPTIONS
889# endif // _LIBCPP_HAS_EXCEPTIONS
883890 this->setstate(__state);
884891 }
885892 return __r;
......@@ -891,13 +898,13 @@ basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::read(char_type*
891898 __gc_ = 0;
892899 sentry __sen(*this, true);
893900 if (__sen) {
894#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
901# if _LIBCPP_HAS_EXCEPTIONS
895902 try {
896#endif // _LIBCPP_HAS_NO_EXCEPTIONS
903# endif // _LIBCPP_HAS_EXCEPTIONS
897904 __gc_ = this->rdbuf()->sgetn(__s, __n);
898905 if (__gc_ != __n)
899906 __state |= ios_base::failbit | ios_base::eofbit;
900#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
907# if _LIBCPP_HAS_EXCEPTIONS
901908 } catch (...) {
902909 __state |= ios_base::badbit;
903910 this->__setstate_nothrow(__state);
......@@ -905,7 +912,7 @@ basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::read(char_type*
905912 throw;
906913 }
907914 }
908#endif // _LIBCPP_HAS_NO_EXCEPTIONS
915# endif // _LIBCPP_HAS_EXCEPTIONS
909916 } else {
910917 __state |= ios_base::failbit;
911918 }
......@@ -919,9 +926,9 @@ streamsize basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize _
919926 __gc_ = 0;
920927 sentry __sen(*this, true);
921928 if (__sen) {
922#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
929# if _LIBCPP_HAS_EXCEPTIONS
923930 try {
924#endif // _LIBCPP_HAS_NO_EXCEPTIONS
931# endif // _LIBCPP_HAS_EXCEPTIONS
925932 streamsize __c = this->rdbuf()->in_avail();
926933 switch (__c) {
927934 case -1:
......@@ -936,7 +943,7 @@ streamsize basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize _
936943 __state |= ios_base::failbit | ios_base::eofbit;
937944 break;
938945 }
939#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
946# if _LIBCPP_HAS_EXCEPTIONS
940947 } catch (...) {
941948 __state |= ios_base::badbit;
942949 this->__setstate_nothrow(__state);
......@@ -944,7 +951,7 @@ streamsize basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize _
944951 throw;
945952 }
946953 }
947#endif // _LIBCPP_HAS_NO_EXCEPTIONS
954# endif // _LIBCPP_HAS_EXCEPTIONS
948955 } else {
949956 __state |= ios_base::failbit;
950957 }
......@@ -959,12 +966,12 @@ basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::putback(char_typ
959966 this->clear(__state);
960967 sentry __sen(*this, true);
961968 if (__sen) {
962#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
969# if _LIBCPP_HAS_EXCEPTIONS
963970 try {
964#endif // _LIBCPP_HAS_NO_EXCEPTIONS
971# endif // _LIBCPP_HAS_EXCEPTIONS
965972 if (this->rdbuf() == nullptr || this->rdbuf()->sputbackc(__c) == traits_type::eof())
966973 __state |= ios_base::badbit;
967#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
974# if _LIBCPP_HAS_EXCEPTIONS
968975 } catch (...) {
969976 __state |= ios_base::badbit;
970977 this->__setstate_nothrow(__state);
......@@ -972,7 +979,7 @@ basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::putback(char_typ
972979 throw;
973980 }
974981 }
975#endif // _LIBCPP_HAS_NO_EXCEPTIONS
982# endif // _LIBCPP_HAS_EXCEPTIONS
976983 } else {
977984 __state |= ios_base::failbit;
978985 }
......@@ -987,12 +994,12 @@ basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::unget() {
987994 this->clear(__state);
988995 sentry __sen(*this, true);
989996 if (__sen) {
990#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
997# if _LIBCPP_HAS_EXCEPTIONS
991998 try {
992#endif // _LIBCPP_HAS_NO_EXCEPTIONS
999# endif // _LIBCPP_HAS_EXCEPTIONS
9931000 if (this->rdbuf() == nullptr || this->rdbuf()->sungetc() == traits_type::eof())
9941001 __state |= ios_base::badbit;
995#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1002# if _LIBCPP_HAS_EXCEPTIONS
9961003 } catch (...) {
9971004 __state |= ios_base::badbit;
9981005 this->__setstate_nothrow(__state);
......@@ -1000,7 +1007,7 @@ basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::unget() {
10001007 throw;
10011008 }
10021009 }
1003#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1010# endif // _LIBCPP_HAS_EXCEPTIONS
10041011 } else {
10051012 __state |= ios_base::failbit;
10061013 }
......@@ -1017,14 +1024,14 @@ int basic_istream<_CharT, _Traits>::sync() {
10171024
10181025 int __r = 0;
10191026 if (__sen) {
1020#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1027# if _LIBCPP_HAS_EXCEPTIONS
10211028 try {
1022#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1029# endif // _LIBCPP_HAS_EXCEPTIONS
10231030 if (this->rdbuf()->pubsync() == -1) {
10241031 __state |= ios_base::badbit;
10251032 __r = -1;
10261033 }
1027#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1034# if _LIBCPP_HAS_EXCEPTIONS
10281035 } catch (...) {
10291036 __state |= ios_base::badbit;
10301037 this->__setstate_nothrow(__state);
......@@ -1032,7 +1039,7 @@ int basic_istream<_CharT, _Traits>::sync() {
10321039 throw;
10331040 }
10341041 }
1035#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1042# endif // _LIBCPP_HAS_EXCEPTIONS
10361043 this->setstate(__state);
10371044 }
10381045 return __r;
......@@ -1044,11 +1051,11 @@ typename basic_istream<_CharT, _Traits>::pos_type basic_istream<_CharT, _Traits>
10441051 pos_type __r(-1);
10451052 sentry __sen(*this, true);
10461053 if (__sen) {
1047#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1054# if _LIBCPP_HAS_EXCEPTIONS
10481055 try {
1049#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1056# endif // _LIBCPP_HAS_EXCEPTIONS
10501057 __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
1051#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1058# if _LIBCPP_HAS_EXCEPTIONS
10521059 } catch (...) {
10531060 __state |= ios_base::badbit;
10541061 this->__setstate_nothrow(__state);
......@@ -1056,7 +1063,7 @@ typename basic_istream<_CharT, _Traits>::pos_type basic_istream<_CharT, _Traits>
10561063 throw;
10571064 }
10581065 }
1059#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1066# endif // _LIBCPP_HAS_EXCEPTIONS
10601067 this->setstate(__state);
10611068 }
10621069 return __r;
......@@ -1068,12 +1075,12 @@ basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::seekg(pos_type _
10681075 this->clear(__state);
10691076 sentry __sen(*this, true);
10701077 if (__sen) {
1071#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1078# if _LIBCPP_HAS_EXCEPTIONS
10721079 try {
1073#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1080# endif // _LIBCPP_HAS_EXCEPTIONS
10741081 if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
10751082 __state |= ios_base::failbit;
1076#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1083# if _LIBCPP_HAS_EXCEPTIONS
10771084 } catch (...) {
10781085 __state |= ios_base::badbit;
10791086 this->__setstate_nothrow(__state);
......@@ -1081,7 +1088,7 @@ basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::seekg(pos_type _
10811088 throw;
10821089 }
10831090 }
1084#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1091# endif // _LIBCPP_HAS_EXCEPTIONS
10851092 this->setstate(__state);
10861093 }
10871094 return *this;
......@@ -1093,12 +1100,12 @@ basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::seekg(off_type _
10931100 this->clear(__state);
10941101 sentry __sen(*this, true);
10951102 if (__sen) {
1096#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1103# if _LIBCPP_HAS_EXCEPTIONS
10971104 try {
1098#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1105# endif // _LIBCPP_HAS_EXCEPTIONS
10991106 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1))
11001107 __state |= ios_base::failbit;
1101#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1108# if _LIBCPP_HAS_EXCEPTIONS
11021109 } catch (...) {
11031110 __state |= ios_base::badbit;
11041111 this->__setstate_nothrow(__state);
......@@ -1106,7 +1113,7 @@ basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::seekg(off_type _
11061113 throw;
11071114 }
11081115 }
1109#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1116# endif // _LIBCPP_HAS_EXCEPTIONS
11101117 this->setstate(__state);
11111118 }
11121119 return *this;
......@@ -1117,9 +1124,9 @@ _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& ws(basic_istream<_CharT, _
11171124 ios_base::iostate __state = ios_base::goodbit;
11181125 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
11191126 if (__sen) {
1120#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1127# if _LIBCPP_HAS_EXCEPTIONS
11211128 try {
1122#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1129# endif // _LIBCPP_HAS_EXCEPTIONS
11231130 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());
11241131 while (true) {
11251132 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
......@@ -1131,7 +1138,7 @@ _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& ws(basic_istream<_CharT, _
11311138 break;
11321139 __is.rdbuf()->sbumpc();
11331140 }
1134#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1141# if _LIBCPP_HAS_EXCEPTIONS
11351142 } catch (...) {
11361143 __state |= ios_base::badbit;
11371144 __is.__setstate_nothrow(__state);
......@@ -1139,7 +1146,7 @@ _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& ws(basic_istream<_CharT, _
11391146 throw;
11401147 }
11411148 }
1142#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1149# endif // _LIBCPP_HAS_EXCEPTIONS
11431150 __is.setstate(__state);
11441151 }
11451152 return __is;
......@@ -1207,16 +1214,21 @@ operator>>(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _
12071214 ios_base::iostate __state = ios_base::goodbit;
12081215 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
12091216 if (__sen) {
1210#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1217# if _LIBCPP_HAS_EXCEPTIONS
12111218 try {
1212#endif
1219# endif
12131220 __str.clear();
1214 streamsize __n = __is.width();
1215 if (__n <= 0)
1216 __n = __str.max_size();
1217 if (__n <= 0)
1218 __n = numeric_limits<streamsize>::max();
1219 streamsize __c = 0;
1221 using _Size = typename basic_string<_CharT, _Traits, _Allocator>::size_type;
1222 streamsize const __width = __is.width();
1223 _Size const __max_size = __str.max_size();
1224 _Size __n;
1225 if (__width <= 0) {
1226 __n = __max_size;
1227 } else {
1228 __n = std::__to_unsigned_like(__width) < __max_size ? static_cast<_Size>(__width) : __max_size;
1229 }
1230
1231 _Size __c = 0;
12201232 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());
12211233 while (__c < __n) {
12221234 typename _Traits::int_type __i = __is.rdbuf()->sgetc();
......@@ -1234,7 +1246,7 @@ operator>>(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _
12341246 __is.width(0);
12351247 if (__c == 0)
12361248 __state |= ios_base::failbit;
1237#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1249# if _LIBCPP_HAS_EXCEPTIONS
12381250 } catch (...) {
12391251 __state |= ios_base::badbit;
12401252 __is.__setstate_nothrow(__state);
......@@ -1242,7 +1254,7 @@ operator>>(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _
12421254 throw;
12431255 }
12441256 }
1245#endif
1257# endif
12461258 __is.setstate(__state);
12471259 }
12481260 return __is;
......@@ -1254,9 +1266,9 @@ getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _All
12541266 ios_base::iostate __state = ios_base::goodbit;
12551267 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
12561268 if (__sen) {
1257#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1269# if _LIBCPP_HAS_EXCEPTIONS
12581270 try {
1259#endif
1271# endif
12601272 __str.clear();
12611273 streamsize __extr = 0;
12621274 while (true) {
......@@ -1277,7 +1289,7 @@ getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _All
12771289 }
12781290 if (__extr == 0)
12791291 __state |= ios_base::failbit;
1280#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1292# if _LIBCPP_HAS_EXCEPTIONS
12811293 } catch (...) {
12821294 __state |= ios_base::badbit;
12831295 __is.__setstate_nothrow(__state);
......@@ -1285,7 +1297,7 @@ getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _All
12851297 throw;
12861298 }
12871299 }
1288#endif
1300# endif
12891301 __is.setstate(__state);
12901302 }
12911303 return __is;
......@@ -1315,9 +1327,9 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) {
13151327 ios_base::iostate __state = ios_base::goodbit;
13161328 typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
13171329 if (__sen) {
1318#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1330# if _LIBCPP_HAS_EXCEPTIONS
13191331 try {
1320#endif
1332# endif
13211333 basic_string<_CharT, _Traits> __str;
13221334 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__is.getloc());
13231335 size_t __c = 0;
......@@ -1339,7 +1351,7 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) {
13391351 __x = bitset<_Size>(__str);
13401352 if (_Size > 0 && __c == 0)
13411353 __state |= ios_base::failbit;
1342#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1354# if _LIBCPP_HAS_EXCEPTIONS
13431355 } catch (...) {
13441356 __state |= ios_base::badbit;
13451357 __is.__setstate_nothrow(__state);
......@@ -1347,27 +1359,31 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) {
13471359 throw;
13481360 }
13491361 }
1350#endif
1362# endif
13511363 __is.setstate(__state);
13521364 }
13531365 return __is;
13541366}
13551367
13561368extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>;
1357#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1369# if _LIBCPP_HAS_WIDE_CHARACTERS
13581370extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>;
1359#endif
1371# endif
13601372extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>;
13611373
13621374_LIBCPP_END_NAMESPACE_STD
13631375
1364#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1365# include <concepts>
1366# include <iosfwd>
1367# include <ostream>
1368# include <type_traits>
1369#endif
1376# endif // _LIBCPP_HAS_LOCALIZATION
1377
1378# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1379# include <concepts>
1380# include <iosfwd>
1381# include <ostream>
1382# include <type_traits>
1383# endif
13701384
13711385_LIBCPP_POP_MACROS
13721386
1387#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
1388
13731389#endif // _LIBCPP_ISTREAM
lib/libcxx/include/iterator+72-67
......@@ -679,76 +679,81 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
679679
680680*/
681681
682#include <__config>
683#include <__iterator/access.h>
684#include <__iterator/advance.h>
685#include <__iterator/back_insert_iterator.h>
686#include <__iterator/distance.h>
687#include <__iterator/front_insert_iterator.h>
688#include <__iterator/insert_iterator.h>
689#include <__iterator/istream_iterator.h>
690#include <__iterator/istreambuf_iterator.h>
691#include <__iterator/iterator.h>
692#include <__iterator/iterator_traits.h>
693#include <__iterator/move_iterator.h>
694#include <__iterator/next.h>
695#include <__iterator/ostream_iterator.h>
696#include <__iterator/ostreambuf_iterator.h>
697#include <__iterator/prev.h>
698#include <__iterator/reverse_iterator.h>
699#include <__iterator/wrap_iter.h>
700
701#if _LIBCPP_STD_VER >= 14
702# include <__iterator/reverse_access.h>
703#endif
704
705#if _LIBCPP_STD_VER >= 17
706# include <__iterator/data.h>
707# include <__iterator/empty.h>
708# include <__iterator/size.h>
709#endif
710
711#if _LIBCPP_STD_VER >= 20
712# include <__iterator/common_iterator.h>
713# include <__iterator/concepts.h>
714# include <__iterator/counted_iterator.h>
715# include <__iterator/default_sentinel.h>
716# include <__iterator/incrementable_traits.h>
717# include <__iterator/indirectly_comparable.h>
718# include <__iterator/iter_move.h>
719# include <__iterator/iter_swap.h>
720# include <__iterator/mergeable.h>
721# include <__iterator/move_sentinel.h>
722# include <__iterator/permutable.h>
723# include <__iterator/projected.h>
724# include <__iterator/readable_traits.h>
725# include <__iterator/sortable.h>
726# include <__iterator/unreachable_sentinel.h>
727#endif
728
729#include <version>
682#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
683# include <__cxx03/iterator>
684#else
685# include <__config>
686# include <__iterator/access.h>
687# include <__iterator/advance.h>
688# include <__iterator/back_insert_iterator.h>
689# include <__iterator/distance.h>
690# include <__iterator/front_insert_iterator.h>
691# include <__iterator/insert_iterator.h>
692# include <__iterator/istream_iterator.h>
693# include <__iterator/istreambuf_iterator.h>
694# include <__iterator/iterator.h>
695# include <__iterator/iterator_traits.h>
696# include <__iterator/move_iterator.h>
697# include <__iterator/next.h>
698# include <__iterator/ostream_iterator.h>
699# include <__iterator/ostreambuf_iterator.h>
700# include <__iterator/prev.h>
701# include <__iterator/reverse_iterator.h>
702# include <__iterator/wrap_iter.h>
703
704# if _LIBCPP_STD_VER >= 14
705# include <__iterator/reverse_access.h>
706# endif
707
708# if _LIBCPP_STD_VER >= 17
709# include <__iterator/data.h>
710# include <__iterator/empty.h>
711# include <__iterator/size.h>
712# endif
713
714# if _LIBCPP_STD_VER >= 20
715# include <__iterator/common_iterator.h>
716# include <__iterator/concepts.h>
717# include <__iterator/counted_iterator.h>
718# include <__iterator/default_sentinel.h>
719# include <__iterator/incrementable_traits.h>
720# include <__iterator/indirectly_comparable.h>
721# include <__iterator/iter_move.h>
722# include <__iterator/iter_swap.h>
723# include <__iterator/mergeable.h>
724# include <__iterator/move_sentinel.h>
725# include <__iterator/permutable.h>
726# include <__iterator/projected.h>
727# include <__iterator/readable_traits.h>
728# include <__iterator/sortable.h>
729# include <__iterator/unreachable_sentinel.h>
730# endif
731
732# include <version>
730733
731734// standard-mandated includes
732735
733736// [iterator.synopsis]
734#include <compare>
735#include <concepts>
736
737#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
738# pragma GCC system_header
739#endif
740
741#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
742# include <variant>
743#endif
744
745#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
746# include <cstdlib>
747# include <exception>
748# include <new>
749# include <type_traits>
750# include <typeinfo>
751# include <utility>
752#endif
737# include <compare>
738# include <concepts>
739
740# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
741# pragma GCC system_header
742# endif
743
744# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
745# include <variant>
746# endif
747
748# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
749# include <cstddef>
750# include <cstdlib>
751# include <exception>
752# include <new>
753# include <type_traits>
754# include <typeinfo>
755# include <utility>
756# endif
757#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
753758
754759#endif // _LIBCPP_ITERATOR
lib/libcxx/include/latch+31-25
......@@ -16,7 +16,7 @@
1616namespace std
1717{
1818
19 class latch
19 class latch // since C++20
2020 {
2121 public:
2222 static constexpr ptrdiff_t max() noexcept;
......@@ -40,31 +40,34 @@ namespace std
4040
4141*/
4242
43#include <__config>
43#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
44# include <__cxx03/latch>
45#else
46# include <__config>
4447
45#if !defined(_LIBCPP_HAS_NO_THREADS)
48# if _LIBCPP_HAS_THREADS
4649
47# include <__assert>
48# include <__atomic/atomic_base.h>
49# include <__atomic/atomic_sync.h>
50# include <__atomic/memory_order.h>
51# include <cstddef>
52# include <limits>
53# include <version>
50# include <__assert>
51# include <__atomic/atomic.h>
52# include <__atomic/atomic_sync.h>
53# include <__atomic/memory_order.h>
54# include <__cstddef/ptrdiff_t.h>
55# include <limits>
56# include <version>
5457
55# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
56# pragma GCC system_header
57# endif
58# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
59# pragma GCC system_header
60# endif
5861
5962_LIBCPP_PUSH_MACROS
60# include <__undef_macros>
63# include <__undef_macros>
6164
62# if _LIBCPP_STD_VER >= 14
65# if _LIBCPP_STD_VER >= 20
6366
6467_LIBCPP_BEGIN_NAMESPACE_STD
6568
66class _LIBCPP_DEPRECATED_ATOMIC_SYNC latch {
67 __atomic_base<ptrdiff_t> __a_;
69class latch {
70 atomic<ptrdiff_t> __a_;
6871
6972public:
7073 static _LIBCPP_HIDE_FROM_ABI constexpr ptrdiff_t max() noexcept { return numeric_limits<ptrdiff_t>::max(); }
......@@ -99,8 +102,9 @@ public:
99102 return try_wait_impl(__value);
100103 }
101104 inline _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void wait() const {
102 std::__atomic_wait_unless(
103 __a_, [this](ptrdiff_t& __value) -> bool { return try_wait_impl(__value); }, memory_order_acquire);
105 std::__atomic_wait_unless(__a_, memory_order_acquire, [this](ptrdiff_t& __value) -> bool {
106 return try_wait_impl(__value);
107 });
104108 }
105109 inline _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void arrive_and_wait(ptrdiff_t __update = 1) {
106110 _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__update >= 0, "latch::arrive_and_wait called with a negative value");
......@@ -116,14 +120,16 @@ private:
116120
117121_LIBCPP_END_NAMESPACE_STD
118122
119# endif // _LIBCPP_STD_VER >= 14
123# endif // _LIBCPP_STD_VER >= 20
120124
121125_LIBCPP_POP_MACROS
122126
123#endif // !defined(_LIBCPP_HAS_NO_THREADS)
127# endif // _LIBCPP_HAS_THREADS
124128
125#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
126# include <atomic>
127#endif
129# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
130# include <atomic>
131# include <cstddef>
132# endif
133#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
128134
129#endif //_LIBCPP_LATCH
135#endif // _LIBCPP_LATCH
lib/libcxx/include/limits+118-161
......@@ -102,18 +102,21 @@ template<> class numeric_limits<cv long double>;
102102
103103*/
104104
105#include <__config>
106#include <__type_traits/is_arithmetic.h>
107#include <__type_traits/is_signed.h>
108#include <__type_traits/remove_cv.h>
105#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
106# include <__cxx03/limits>
107#else
108# include <__config>
109# include <__type_traits/is_arithmetic.h>
110# include <__type_traits/is_signed.h>
111# include <__type_traits/remove_cv.h>
109112
110#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
111# pragma GCC system_header
112#endif
113# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
114# pragma GCC system_header
115# endif
113116
114117_LIBCPP_PUSH_MACROS
115#include <__undef_macros>
116#include <version>
118# include <__undef_macros>
119# include <version>
117120
118121_LIBCPP_BEGIN_NAMESPACE_STD
119122
......@@ -137,9 +140,9 @@ protected:
137140 typedef _Tp type;
138141
139142 static _LIBCPP_CONSTEXPR const bool is_specialized = false;
140 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return type(); }
141 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return type(); }
142 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return type(); }
143 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return type(); }
144 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return type(); }
145 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return type(); }
143146
144147 static _LIBCPP_CONSTEXPR const int digits = 0;
145148 static _LIBCPP_CONSTEXPR const int digits10 = 0;
......@@ -148,8 +151,8 @@ protected:
148151 static _LIBCPP_CONSTEXPR const bool is_integer = false;
149152 static _LIBCPP_CONSTEXPR const bool is_exact = false;
150153 static _LIBCPP_CONSTEXPR const int radix = 0;
151 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return type(); }
152 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return type(); }
154 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return type(); }
155 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return type(); }
153156
154157 static _LIBCPP_CONSTEXPR const int min_exponent = 0;
155158 static _LIBCPP_CONSTEXPR const int min_exponent10 = 0;
......@@ -161,10 +164,10 @@ protected:
161164 static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false;
162165 static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent;
163166 static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
164 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return type(); }
165 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return type(); }
166 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return type(); }
167 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return type(); }
167 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return type(); }
168 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return type(); }
169 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return type(); }
170 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return type(); }
168171
169172 static _LIBCPP_CONSTEXPR const bool is_iec559 = false;
170173 static _LIBCPP_CONSTEXPR const bool is_bounded = false;
......@@ -198,15 +201,15 @@ protected:
198201 static _LIBCPP_CONSTEXPR const int max_digits10 = 0;
199202 static _LIBCPP_CONSTEXPR const type __min = __libcpp_compute_min<type, digits, is_signed>::value;
200203 static _LIBCPP_CONSTEXPR const type __max = is_signed ? type(type(~0) ^ __min) : type(~0);
201 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __min; }
202 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __max; }
203 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return min(); }
204 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __min; }
205 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __max; }
206 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return min(); }
204207
205208 static _LIBCPP_CONSTEXPR const bool is_integer = true;
206209 static _LIBCPP_CONSTEXPR const bool is_exact = true;
207210 static _LIBCPP_CONSTEXPR const int radix = 2;
208 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return type(0); }
209 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return type(0); }
211 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return type(0); }
212 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return type(0); }
210213
211214 static _LIBCPP_CONSTEXPR const int min_exponent = 0;
212215 static _LIBCPP_CONSTEXPR const int min_exponent10 = 0;
......@@ -218,20 +221,20 @@ protected:
218221 static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false;
219222 static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent;
220223 static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
221 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return type(0); }
222 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return type(0); }
223 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return type(0); }
224 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return type(0); }
224 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return type(0); }
225 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return type(0); }
226 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return type(0); }
227 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return type(0); }
225228
226229 static _LIBCPP_CONSTEXPR const bool is_iec559 = false;
227230 static _LIBCPP_CONSTEXPR const bool is_bounded = true;
228231 static _LIBCPP_CONSTEXPR const bool is_modulo = !std::is_signed<_Tp>::value;
229232
230#if defined(__i386__) || defined(__x86_64__) || defined(__pnacl__) || defined(__wasm__)
233# if defined(__i386__) || defined(__x86_64__) || defined(__pnacl__) || defined(__wasm__)
231234 static _LIBCPP_CONSTEXPR const bool traps = true;
232#else
235# else
233236 static _LIBCPP_CONSTEXPR const bool traps = false;
234#endif
237# endif
235238 static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
236239 static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero;
237240};
......@@ -249,15 +252,15 @@ protected:
249252 static _LIBCPP_CONSTEXPR const int max_digits10 = 0;
250253 static _LIBCPP_CONSTEXPR const type __min = false;
251254 static _LIBCPP_CONSTEXPR const type __max = true;
252 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __min; }
253 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __max; }
254 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return min(); }
255 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __min; }
256 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __max; }
257 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return min(); }
255258
256259 static _LIBCPP_CONSTEXPR const bool is_integer = true;
257260 static _LIBCPP_CONSTEXPR const bool is_exact = true;
258261 static _LIBCPP_CONSTEXPR const int radix = 2;
259 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return type(0); }
260 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return type(0); }
262 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return type(0); }
263 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return type(0); }
261264
262265 static _LIBCPP_CONSTEXPR const int min_exponent = 0;
263266 static _LIBCPP_CONSTEXPR const int min_exponent10 = 0;
......@@ -269,10 +272,10 @@ protected:
269272 static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false;
270273 static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent;
271274 static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
272 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return type(0); }
273 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return type(0); }
274 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return type(0); }
275 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return type(0); }
275 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return type(0); }
276 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return type(0); }
277 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return type(0); }
278 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return type(0); }
276279
277280 static _LIBCPP_CONSTEXPR const bool is_iec559 = false;
278281 static _LIBCPP_CONSTEXPR const bool is_bounded = true;
......@@ -294,15 +297,15 @@ protected:
294297 static _LIBCPP_CONSTEXPR const int digits = __FLT_MANT_DIG__;
295298 static _LIBCPP_CONSTEXPR const int digits10 = __FLT_DIG__;
296299 static _LIBCPP_CONSTEXPR const int max_digits10 = 2 + (digits * 30103l) / 100000l;
297 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __FLT_MIN__; }
298 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __FLT_MAX__; }
299 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return -max(); }
300 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __FLT_MIN__; }
301 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __FLT_MAX__; }
302 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return -max(); }
300303
301304 static _LIBCPP_CONSTEXPR const bool is_integer = false;
302305 static _LIBCPP_CONSTEXPR const bool is_exact = false;
303306 static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__;
304 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return __FLT_EPSILON__; }
305 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return 0.5F; }
307 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return __FLT_EPSILON__; }
308 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return 0.5F; }
306309
307310 static _LIBCPP_CONSTEXPR const int min_exponent = __FLT_MIN_EXP__;
308311 static _LIBCPP_CONSTEXPR const int min_exponent10 = __FLT_MIN_10_EXP__;
......@@ -314,16 +317,16 @@ protected:
314317 static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true;
315318 static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present;
316319 static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
317 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {
320 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {
318321 return __builtin_huge_valf();
319322 }
320 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {
323 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {
321324 return __builtin_nanf("");
322325 }
323 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {
326 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {
324327 return __builtin_nansf("");
325328 }
326 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {
329 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {
327330 return __FLT_DENORM_MIN__;
328331 }
329332
......@@ -332,11 +335,11 @@ protected:
332335 static _LIBCPP_CONSTEXPR const bool is_modulo = false;
333336
334337 static _LIBCPP_CONSTEXPR const bool traps = false;
335#if (defined(__arm__) || defined(__aarch64__))
338# if (defined(__arm__) || defined(__aarch64__))
336339 static _LIBCPP_CONSTEXPR const bool tinyness_before = true;
337#else
340# else
338341 static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
339#endif
342# endif
340343 static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest;
341344};
342345
......@@ -351,15 +354,15 @@ protected:
351354 static _LIBCPP_CONSTEXPR const int digits = __DBL_MANT_DIG__;
352355 static _LIBCPP_CONSTEXPR const int digits10 = __DBL_DIG__;
353356 static _LIBCPP_CONSTEXPR const int max_digits10 = 2 + (digits * 30103l) / 100000l;
354 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __DBL_MIN__; }
355 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __DBL_MAX__; }
356 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return -max(); }
357 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __DBL_MIN__; }
358 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __DBL_MAX__; }
359 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return -max(); }
357360
358361 static _LIBCPP_CONSTEXPR const bool is_integer = false;
359362 static _LIBCPP_CONSTEXPR const bool is_exact = false;
360363 static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__;
361 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return __DBL_EPSILON__; }
362 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return 0.5; }
364 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return __DBL_EPSILON__; }
365 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return 0.5; }
363366
364367 static _LIBCPP_CONSTEXPR const int min_exponent = __DBL_MIN_EXP__;
365368 static _LIBCPP_CONSTEXPR const int min_exponent10 = __DBL_MIN_10_EXP__;
......@@ -371,16 +374,16 @@ protected:
371374 static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true;
372375 static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present;
373376 static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
374 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {
377 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {
375378 return __builtin_huge_val();
376379 }
377 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {
380 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {
378381 return __builtin_nan("");
379382 }
380 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {
383 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {
381384 return __builtin_nans("");
382385 }
383 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {
386 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {
384387 return __DBL_DENORM_MIN__;
385388 }
386389
......@@ -389,11 +392,11 @@ protected:
389392 static _LIBCPP_CONSTEXPR const bool is_modulo = false;
390393
391394 static _LIBCPP_CONSTEXPR const bool traps = false;
392#if (defined(__arm__) || defined(__aarch64__))
395# if (defined(__arm__) || defined(__aarch64__))
393396 static _LIBCPP_CONSTEXPR const bool tinyness_before = true;
394#else
397# else
395398 static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
396#endif
399# endif
397400 static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest;
398401};
399402
......@@ -408,15 +411,15 @@ protected:
408411 static _LIBCPP_CONSTEXPR const int digits = __LDBL_MANT_DIG__;
409412 static _LIBCPP_CONSTEXPR const int digits10 = __LDBL_DIG__;
410413 static _LIBCPP_CONSTEXPR const int max_digits10 = 2 + (digits * 30103l) / 100000l;
411 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __LDBL_MIN__; }
412 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __LDBL_MAX__; }
413 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return -max(); }
414 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __LDBL_MIN__; }
415 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __LDBL_MAX__; }
416 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return -max(); }
414417
415418 static _LIBCPP_CONSTEXPR const bool is_integer = false;
416419 static _LIBCPP_CONSTEXPR const bool is_exact = false;
417420 static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__;
418 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return __LDBL_EPSILON__; }
419 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return 0.5L; }
421 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return __LDBL_EPSILON__; }
422 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return 0.5L; }
420423
421424 static _LIBCPP_CONSTEXPR const int min_exponent = __LDBL_MIN_EXP__;
422425 static _LIBCPP_CONSTEXPR const int min_exponent10 = __LDBL_MIN_10_EXP__;
......@@ -428,33 +431,33 @@ protected:
428431 static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true;
429432 static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present;
430433 static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
431 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {
434 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {
432435 return __builtin_huge_vall();
433436 }
434 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {
437 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {
435438 return __builtin_nanl("");
436439 }
437 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {
440 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {
438441 return __builtin_nansl("");
439442 }
440 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {
443 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {
441444 return __LDBL_DENORM_MIN__;
442445 }
443446
444#if defined(__powerpc__) && defined(__LONG_DOUBLE_IBM128__)
447# if defined(__powerpc__) && defined(__LONG_DOUBLE_IBM128__)
445448 static _LIBCPP_CONSTEXPR const bool is_iec559 = false;
446#else
449# else
447450 static _LIBCPP_CONSTEXPR const bool is_iec559 = true;
448#endif
451# endif
449452 static _LIBCPP_CONSTEXPR const bool is_bounded = true;
450453 static _LIBCPP_CONSTEXPR const bool is_modulo = false;
451454
452455 static _LIBCPP_CONSTEXPR const bool traps = false;
453#if (defined(__arm__) || defined(__aarch64__))
456# if (defined(__arm__) || defined(__aarch64__))
454457 static _LIBCPP_CONSTEXPR const bool tinyness_before = true;
455#else
458# else
456459 static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
457#endif
460# endif
458461 static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest;
459462};
460463
......@@ -464,106 +467,59 @@ class _LIBCPP_TEMPLATE_VIS numeric_limits : private __libcpp_numeric_limits<_Tp>
464467 typedef typename __base::type type;
465468
466469public:
467 static _LIBCPP_CONSTEXPR const bool is_specialized = __base::is_specialized;
468 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __base::min(); }
469 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __base::max(); }
470 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return __base::lowest(); }
471
472 static _LIBCPP_CONSTEXPR const int digits = __base::digits;
473 static _LIBCPP_CONSTEXPR const int digits10 = __base::digits10;
474 static _LIBCPP_CONSTEXPR const int max_digits10 = __base::max_digits10;
475 static _LIBCPP_CONSTEXPR const bool is_signed = __base::is_signed;
476 static _LIBCPP_CONSTEXPR const bool is_integer = __base::is_integer;
477 static _LIBCPP_CONSTEXPR const bool is_exact = __base::is_exact;
478 static _LIBCPP_CONSTEXPR const int radix = __base::radix;
479 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {
470 static inline _LIBCPP_CONSTEXPR const bool is_specialized = __base::is_specialized;
471 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __base::min(); }
472 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __base::max(); }
473 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return __base::lowest(); }
474
475 static inline _LIBCPP_CONSTEXPR const int digits = __base::digits;
476 static inline _LIBCPP_CONSTEXPR const int digits10 = __base::digits10;
477 static inline _LIBCPP_CONSTEXPR const int max_digits10 = __base::max_digits10;
478 static inline _LIBCPP_CONSTEXPR const bool is_signed = __base::is_signed;
479 static inline _LIBCPP_CONSTEXPR const bool is_integer = __base::is_integer;
480 static inline _LIBCPP_CONSTEXPR const bool is_exact = __base::is_exact;
481 static inline _LIBCPP_CONSTEXPR const int radix = __base::radix;
482 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {
480483 return __base::epsilon();
481484 }
482 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {
485 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {
483486 return __base::round_error();
484487 }
485488
486 static _LIBCPP_CONSTEXPR const int min_exponent = __base::min_exponent;
487 static _LIBCPP_CONSTEXPR const int min_exponent10 = __base::min_exponent10;
488 static _LIBCPP_CONSTEXPR const int max_exponent = __base::max_exponent;
489 static _LIBCPP_CONSTEXPR const int max_exponent10 = __base::max_exponent10;
489 static inline _LIBCPP_CONSTEXPR const int min_exponent = __base::min_exponent;
490 static inline _LIBCPP_CONSTEXPR const int min_exponent10 = __base::min_exponent10;
491 static inline _LIBCPP_CONSTEXPR const int max_exponent = __base::max_exponent;
492 static inline _LIBCPP_CONSTEXPR const int max_exponent10 = __base::max_exponent10;
490493
491 static _LIBCPP_CONSTEXPR const bool has_infinity = __base::has_infinity;
492 static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = __base::has_quiet_NaN;
493 static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = __base::has_signaling_NaN;
494 static inline _LIBCPP_CONSTEXPR const bool has_infinity = __base::has_infinity;
495 static inline _LIBCPP_CONSTEXPR const bool has_quiet_NaN = __base::has_quiet_NaN;
496 static inline _LIBCPP_CONSTEXPR const bool has_signaling_NaN = __base::has_signaling_NaN;
494497 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
495 static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = __base::has_denorm;
496 static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = __base::has_denorm_loss;
498 static inline _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = __base::has_denorm;
499 static inline _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = __base::has_denorm_loss;
497500 _LIBCPP_SUPPRESS_DEPRECATED_POP
498 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {
501 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {
499502 return __base::infinity();
500503 }
501 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {
504 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {
502505 return __base::quiet_NaN();
503506 }
504 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {
507 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {
505508 return __base::signaling_NaN();
506509 }
507 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {
510 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {
508511 return __base::denorm_min();
509512 }
510513
511 static _LIBCPP_CONSTEXPR const bool is_iec559 = __base::is_iec559;
512 static _LIBCPP_CONSTEXPR const bool is_bounded = __base::is_bounded;
513 static _LIBCPP_CONSTEXPR const bool is_modulo = __base::is_modulo;
514 static inline _LIBCPP_CONSTEXPR const bool is_iec559 = __base::is_iec559;
515 static inline _LIBCPP_CONSTEXPR const bool is_bounded = __base::is_bounded;
516 static inline _LIBCPP_CONSTEXPR const bool is_modulo = __base::is_modulo;
514517
515 static _LIBCPP_CONSTEXPR const bool traps = __base::traps;
516 static _LIBCPP_CONSTEXPR const bool tinyness_before = __base::tinyness_before;
517 static _LIBCPP_CONSTEXPR const float_round_style round_style = __base::round_style;
518 static inline _LIBCPP_CONSTEXPR const bool traps = __base::traps;
519 static inline _LIBCPP_CONSTEXPR const bool tinyness_before = __base::tinyness_before;
520 static inline _LIBCPP_CONSTEXPR const float_round_style round_style = __base::round_style;
518521};
519522
520template <class _Tp>
521_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_specialized;
522template <class _Tp>
523_LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::digits;
524template <class _Tp>
525_LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::digits10;
526template <class _Tp>
527_LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::max_digits10;
528template <class _Tp>
529_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_signed;
530template <class _Tp>
531_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_integer;
532template <class _Tp>
533_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_exact;
534template <class _Tp>
535_LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::radix;
536template <class _Tp>
537_LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::min_exponent;
538template <class _Tp>
539_LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::min_exponent10;
540template <class _Tp>
541_LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::max_exponent;
542template <class _Tp>
543_LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::max_exponent10;
544template <class _Tp>
545_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_infinity;
546template <class _Tp>
547_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_quiet_NaN;
548template <class _Tp>
549_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_signaling_NaN;
550template <class _Tp>
551_LIBCPP_CONSTEXPR const float_denorm_style numeric_limits<_Tp>::has_denorm;
552template <class _Tp>
553_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_denorm_loss;
554template <class _Tp>
555_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_iec559;
556template <class _Tp>
557_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_bounded;
558template <class _Tp>
559_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_modulo;
560template <class _Tp>
561_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::traps;
562template <class _Tp>
563_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::tinyness_before;
564template <class _Tp>
565_LIBCPP_CONSTEXPR const float_round_style numeric_limits<_Tp>::round_style;
566
567523template <class _Tp>
568524class _LIBCPP_TEMPLATE_VIS numeric_limits<const _Tp> : public numeric_limits<_Tp> {};
569525
......@@ -577,8 +533,9 @@ _LIBCPP_END_NAMESPACE_STD
577533
578534_LIBCPP_POP_MACROS
579535
580#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
581# include <type_traits>
582#endif
536# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
537# include <type_traits>
538# endif
539#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
583540
584541#endif // _LIBCPP_LIMITS
lib/libcxx/include/list+369-357
......@@ -197,67 +197,72 @@ template <class T, class Allocator, class Predicate>
197197
198198*/
199199
200#include <__algorithm/comp.h>
201#include <__algorithm/equal.h>
202#include <__algorithm/lexicographical_compare.h>
203#include <__algorithm/lexicographical_compare_three_way.h>
204#include <__algorithm/min.h>
205#include <__assert>
206#include <__config>
207#include <__format/enable_insertable.h>
208#include <__iterator/distance.h>
209#include <__iterator/iterator_traits.h>
210#include <__iterator/move_iterator.h>
211#include <__iterator/next.h>
212#include <__iterator/prev.h>
213#include <__iterator/reverse_iterator.h>
214#include <__memory/addressof.h>
215#include <__memory/allocation_guard.h>
216#include <__memory/allocator.h>
217#include <__memory/allocator_traits.h>
218#include <__memory/compressed_pair.h>
219#include <__memory/construct_at.h>
220#include <__memory/pointer_traits.h>
221#include <__memory/swap_allocator.h>
222#include <__memory_resource/polymorphic_allocator.h>
223#include <__ranges/access.h>
224#include <__ranges/concepts.h>
225#include <__ranges/container_compatible_range.h>
226#include <__ranges/from_range.h>
227#include <__type_traits/conditional.h>
228#include <__type_traits/is_allocator.h>
229#include <__type_traits/is_nothrow_assignable.h>
230#include <__type_traits/is_nothrow_constructible.h>
231#include <__type_traits/is_pointer.h>
232#include <__type_traits/is_same.h>
233#include <__type_traits/type_identity.h>
234#include <__utility/forward.h>
235#include <__utility/move.h>
236#include <__utility/swap.h>
237#include <cstring>
238#include <limits>
239#include <new> // __launder
240#include <version>
200#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
201# include <__cxx03/list>
202#else
203# include <__algorithm/comp.h>
204# include <__algorithm/equal.h>
205# include <__algorithm/lexicographical_compare.h>
206# include <__algorithm/lexicographical_compare_three_way.h>
207# include <__algorithm/min.h>
208# include <__assert>
209# include <__config>
210# include <__format/enable_insertable.h>
211# include <__iterator/distance.h>
212# include <__iterator/iterator_traits.h>
213# include <__iterator/move_iterator.h>
214# include <__iterator/next.h>
215# include <__iterator/prev.h>
216# include <__iterator/reverse_iterator.h>
217# include <__memory/addressof.h>
218# include <__memory/allocation_guard.h>
219# include <__memory/allocator.h>
220# include <__memory/allocator_traits.h>
221# include <__memory/compressed_pair.h>
222# include <__memory/construct_at.h>
223# include <__memory/pointer_traits.h>
224# include <__memory/swap_allocator.h>
225# include <__memory_resource/polymorphic_allocator.h>
226# include <__new/launder.h>
227# include <__ranges/access.h>
228# include <__ranges/concepts.h>
229# include <__ranges/container_compatible_range.h>
230# include <__ranges/from_range.h>
231# include <__type_traits/conditional.h>
232# include <__type_traits/container_traits.h>
233# include <__type_traits/enable_if.h>
234# include <__type_traits/is_allocator.h>
235# include <__type_traits/is_nothrow_assignable.h>
236# include <__type_traits/is_nothrow_constructible.h>
237# include <__type_traits/is_pointer.h>
238# include <__type_traits/is_same.h>
239# include <__type_traits/type_identity.h>
240# include <__utility/forward.h>
241# include <__utility/move.h>
242# include <__utility/swap.h>
243# include <cstring>
244# include <limits>
245# include <version>
241246
242247// standard-mandated includes
243248
244249// [iterator.range]
245#include <__iterator/access.h>
246#include <__iterator/data.h>
247#include <__iterator/empty.h>
248#include <__iterator/reverse_access.h>
249#include <__iterator/size.h>
250# include <__iterator/access.h>
251# include <__iterator/data.h>
252# include <__iterator/empty.h>
253# include <__iterator/reverse_access.h>
254# include <__iterator/size.h>
250255
251256// [list.syn]
252#include <compare>
253#include <initializer_list>
257# include <compare>
258# include <initializer_list>
254259
255#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
256# pragma GCC system_header
257#endif
260# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
261# pragma GCC system_header
262# endif
258263
259264_LIBCPP_PUSH_MACROS
260#include <__undef_macros>
265# include <__undef_macros>
261266
262267_LIBCPP_BEGIN_NAMESPACE_STD
263268
......@@ -271,19 +276,21 @@ struct __list_node_pointer_traits {
271276 typedef __rebind_pointer_t<_VoidPtr, __list_node<_Tp, _VoidPtr> > __node_pointer;
272277 typedef __rebind_pointer_t<_VoidPtr, __list_node_base<_Tp, _VoidPtr> > __base_pointer;
273278
274#if defined(_LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB)
275 typedef __base_pointer __link_pointer;
276#else
277 typedef __conditional_t<is_pointer<_VoidPtr>::value, __base_pointer, __node_pointer> __link_pointer;
278#endif
279
280 typedef __conditional_t<is_same<__link_pointer, __node_pointer>::value, __base_pointer, __node_pointer>
281 __non_link_pointer;
279// TODO(LLVM 22): Remove this check
280# ifndef _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
281 static_assert(sizeof(__node_pointer) == sizeof(__node_pointer) && _LIBCPP_ALIGNOF(__base_pointer) ==
282 _LIBCPP_ALIGNOF(__node_pointer),
283 "It looks like you are using std::list with a fancy pointer type that thas a different representation "
284 "depending on whether it points to a list base pointer or a list node pointer (both of which are "
285 "implementation details of the standard library). This means that your ABI is being broken between "
286 "LLVM 19 and LLVM 20. If you don't care about your ABI being broken, define the "
287 "_LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB macro to silence this diagnostic.");
288# endif
282289
283 static _LIBCPP_HIDE_FROM_ABI __link_pointer __unsafe_link_pointer_cast(__link_pointer __p) { return __p; }
290 static _LIBCPP_HIDE_FROM_ABI __base_pointer __unsafe_link_pointer_cast(__base_pointer __p) { return __p; }
284291
285 static _LIBCPP_HIDE_FROM_ABI __link_pointer __unsafe_link_pointer_cast(__non_link_pointer __p) {
286 return static_cast<__link_pointer>(static_cast<_VoidPtr>(__p));
292 static _LIBCPP_HIDE_FROM_ABI __base_pointer __unsafe_link_pointer_cast(__node_pointer __p) {
293 return static_cast<__base_pointer>(static_cast<_VoidPtr>(__p));
287294 }
288295};
289296
......@@ -292,16 +299,13 @@ struct __list_node_base {
292299 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
293300 typedef typename _NodeTraits::__node_pointer __node_pointer;
294301 typedef typename _NodeTraits::__base_pointer __base_pointer;
295 typedef typename _NodeTraits::__link_pointer __link_pointer;
296302
297 __link_pointer __prev_;
298 __link_pointer __next_;
303 __base_pointer __prev_;
304 __base_pointer __next_;
299305
300 _LIBCPP_HIDE_FROM_ABI __list_node_base()
301 : __prev_(_NodeTraits::__unsafe_link_pointer_cast(__self())),
302 __next_(_NodeTraits::__unsafe_link_pointer_cast(__self())) {}
306 _LIBCPP_HIDE_FROM_ABI __list_node_base() : __prev_(__self()), __next_(__self()) {}
303307
304 _LIBCPP_HIDE_FROM_ABI explicit __list_node_base(__link_pointer __prev, __link_pointer __next)
308 _LIBCPP_HIDE_FROM_ABI explicit __list_node_base(__base_pointer __prev, __base_pointer __next)
305309 : __prev_(__prev), __next_(__next) {}
306310
307311 _LIBCPP_HIDE_FROM_ABI __base_pointer __self() { return pointer_traits<__base_pointer>::pointer_to(*this); }
......@@ -313,7 +317,7 @@ template <class _Tp, class _VoidPtr>
313317struct __list_node : public __list_node_base<_Tp, _VoidPtr> {
314318 // We allow starting the lifetime of nodes without initializing the value held by the node,
315319 // since that is handled by the list itself in order to be allocator-aware.
316#ifndef _LIBCPP_CXX03_LANG
320# ifndef _LIBCPP_CXX03_LANG
317321
318322private:
319323 union {
......@@ -322,22 +326,22 @@ private:
322326
323327public:
324328 _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return __value_; }
325#else
329# else
326330
327331private:
328332 _ALIGNAS_TYPE(_Tp) char __buffer_[sizeof(_Tp)];
329333
330334public:
331335 _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return *std::__launder(reinterpret_cast<_Tp*>(&__buffer_)); }
332#endif
336# endif
333337
334338 typedef __list_node_base<_Tp, _VoidPtr> __base;
335 typedef typename __base::__link_pointer __link_pointer;
339 typedef typename __base::__base_pointer __base_pointer;
336340
337 _LIBCPP_HIDE_FROM_ABI explicit __list_node(__link_pointer __prev, __link_pointer __next) : __base(__prev, __next) {}
341 _LIBCPP_HIDE_FROM_ABI explicit __list_node(__base_pointer __prev, __base_pointer __next) : __base(__prev, __next) {}
338342 _LIBCPP_HIDE_FROM_ABI ~__list_node() {}
339343
340 _LIBCPP_HIDE_FROM_ABI __link_pointer __as_link() { return static_cast<__link_pointer>(__base::__self()); }
344 _LIBCPP_HIDE_FROM_ABI __base_pointer __as_link() { return __base::__self(); }
341345};
342346
343347template <class _Tp, class _Alloc = allocator<_Tp> >
......@@ -350,11 +354,11 @@ class _LIBCPP_TEMPLATE_VIS __list_const_iterator;
350354template <class _Tp, class _VoidPtr>
351355class _LIBCPP_TEMPLATE_VIS __list_iterator {
352356 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
353 typedef typename _NodeTraits::__link_pointer __link_pointer;
357 typedef typename _NodeTraits::__base_pointer __base_pointer;
354358
355 __link_pointer __ptr_;
359 __base_pointer __ptr_;
356360
357 _LIBCPP_HIDE_FROM_ABI explicit __list_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
361 _LIBCPP_HIDE_FROM_ABI explicit __list_iterator(__base_pointer __p) _NOEXCEPT : __ptr_(__p) {}
358362
359363 template <class, class>
360364 friend class list;
......@@ -408,11 +412,11 @@ public:
408412template <class _Tp, class _VoidPtr>
409413class _LIBCPP_TEMPLATE_VIS __list_const_iterator {
410414 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
411 typedef typename _NodeTraits::__link_pointer __link_pointer;
415 typedef typename _NodeTraits::__base_pointer __base_pointer;
412416
413 __link_pointer __ptr_;
417 __base_pointer __ptr_;
414418
415 _LIBCPP_HIDE_FROM_ABI explicit __list_const_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
419 _LIBCPP_HIDE_FROM_ABI explicit __list_const_iterator(__base_pointer __p) _NOEXCEPT : __ptr_(__p) {}
416420
417421 template <class, class>
418422 friend class list;
......@@ -466,7 +470,7 @@ public:
466470template <class _Tp, class _Alloc>
467471class __list_imp {
468472public:
469 __list_imp(const __list_imp&) = delete;
473 __list_imp(const __list_imp&) = delete;
470474 __list_imp& operator=(const __list_imp&) = delete;
471475
472476 typedef _Alloc allocator_type;
......@@ -485,8 +489,8 @@ protected:
485489 typedef typename __node_alloc_traits::pointer __node_pointer;
486490 typedef typename __node_alloc_traits::pointer __node_const_pointer;
487491 typedef __list_node_pointer_traits<value_type, __void_pointer> __node_pointer_traits;
488 typedef typename __node_pointer_traits::__link_pointer __link_pointer;
489 typedef __link_pointer __link_const_pointer;
492 typedef typename __node_pointer_traits::__base_pointer __base_pointer;
493 typedef __base_pointer __link_const_pointer;
490494 typedef typename __alloc_traits::pointer pointer;
491495 typedef typename __alloc_traits::const_pointer const_pointer;
492496 typedef typename __alloc_traits::difference_type difference_type;
......@@ -497,31 +501,26 @@ protected:
497501 "internal allocator type must differ from user-specified type; otherwise overload resolution breaks");
498502
499503 __node_base __end_;
500 __compressed_pair<size_type, __node_allocator> __size_alloc_;
504 _LIBCPP_COMPRESSED_PAIR(size_type, __size_, __node_allocator, __node_alloc_);
501505
502 _LIBCPP_HIDE_FROM_ABI __link_pointer __end_as_link() const _NOEXCEPT {
506 _LIBCPP_HIDE_FROM_ABI __base_pointer __end_as_link() const _NOEXCEPT {
503507 return __node_pointer_traits::__unsafe_link_pointer_cast(const_cast<__node_base&>(__end_).__self());
504508 }
505509
506 _LIBCPP_HIDE_FROM_ABI size_type& __sz() _NOEXCEPT { return __size_alloc_.first(); }
507 _LIBCPP_HIDE_FROM_ABI const size_type& __sz() const _NOEXCEPT { return __size_alloc_.first(); }
508 _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __size_alloc_.second(); }
509 _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __size_alloc_.second(); }
510
511510 _LIBCPP_HIDE_FROM_ABI size_type __node_alloc_max_size() const _NOEXCEPT {
512 return __node_alloc_traits::max_size(__node_alloc());
511 return __node_alloc_traits::max_size(__node_alloc_);
513512 }
514 _LIBCPP_HIDE_FROM_ABI static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT;
513 _LIBCPP_HIDE_FROM_ABI static void __unlink_nodes(__base_pointer __f, __base_pointer __l) _NOEXCEPT;
515514
516515 _LIBCPP_HIDE_FROM_ABI __list_imp() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
517516 _LIBCPP_HIDE_FROM_ABI __list_imp(const allocator_type& __a);
518517 _LIBCPP_HIDE_FROM_ABI __list_imp(const __node_allocator& __a);
519#ifndef _LIBCPP_CXX03_LANG
518# ifndef _LIBCPP_CXX03_LANG
520519 _LIBCPP_HIDE_FROM_ABI __list_imp(__node_allocator&& __a) _NOEXCEPT;
521#endif
520# endif
522521 _LIBCPP_HIDE_FROM_ABI ~__list_imp();
523522 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT;
524 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __sz() == 0; }
523 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __size_ == 0; }
525524
526525 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return iterator(__end_.__next_); }
527526 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return const_iterator(__end_.__next_); }
......@@ -529,11 +528,11 @@ protected:
529528 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return const_iterator(__end_as_link()); }
530529
531530 _LIBCPP_HIDE_FROM_ABI void swap(__list_imp& __c)
532#if _LIBCPP_STD_VER >= 14
531# if _LIBCPP_STD_VER >= 14
533532 _NOEXCEPT;
534#else
533# else
535534 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>);
536#endif
535# endif
537536
538537 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __list_imp& __c) {
539538 __copy_assign_alloc(
......@@ -548,9 +547,8 @@ protected:
548547 }
549548
550549 template <class... _Args>
551 _LIBCPP_HIDE_FROM_ABI __node_pointer __create_node(__link_pointer __prev, __link_pointer __next, _Args&&... __args) {
552 __node_allocator& __alloc = __node_alloc();
553 __allocation_guard<__node_allocator> __guard(__alloc, 1);
550 _LIBCPP_HIDE_FROM_ABI __node_pointer __create_node(__base_pointer __prev, __base_pointer __next, _Args&&... __args) {
551 __allocation_guard<__node_allocator> __guard(__node_alloc_, 1);
554552 // Begin the lifetime of the node itself. Note that this doesn't begin the lifetime of the value
555553 // held inside the node, since we need to use the allocator's construct() method for that.
556554 //
......@@ -561,31 +559,30 @@ protected:
561559
562560 // Now construct the value_type using the allocator's construct() method.
563561 __node_alloc_traits::construct(
564 __alloc, std::addressof(__guard.__get()->__get_value()), std::forward<_Args>(__args)...);
562 __node_alloc_, std::addressof(__guard.__get()->__get_value()), std::forward<_Args>(__args)...);
565563 return __guard.__release_ptr();
566564 }
567565
568566 _LIBCPP_HIDE_FROM_ABI void __delete_node(__node_pointer __node) {
569567 // For the same reason as above, we use the allocator's destroy() method for the value_type,
570568 // but not for the node itself.
571 __node_allocator& __alloc = __node_alloc();
572 __node_alloc_traits::destroy(__alloc, std::addressof(__node->__get_value()));
569 __node_alloc_traits::destroy(__node_alloc_, std::addressof(__node->__get_value()));
573570 std::__destroy_at(std::addressof(*__node));
574 __node_alloc_traits::deallocate(__alloc, __node, 1);
571 __node_alloc_traits::deallocate(__node_alloc_, __node, 1);
575572 }
576573
577574private:
578575 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __list_imp& __c, true_type) {
579 if (__node_alloc() != __c.__node_alloc())
576 if (__node_alloc_ != __c.__node_alloc_)
580577 clear();
581 __node_alloc() = __c.__node_alloc();
578 __node_alloc_ = __c.__node_alloc_;
582579 }
583580
584581 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __list_imp&, false_type) {}
585582
586583 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__list_imp& __c, true_type)
587584 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) {
588 __node_alloc() = std::move(__c.__node_alloc());
585 __node_alloc_ = std::move(__c.__node_alloc_);
589586 }
590587
591588 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__list_imp&, false_type) _NOEXCEPT {}
......@@ -593,25 +590,28 @@ private:
593590
594591// Unlink nodes [__f, __l]
595592template <class _Tp, class _Alloc>
596inline void __list_imp<_Tp, _Alloc>::__unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT {
593inline void __list_imp<_Tp, _Alloc>::__unlink_nodes(__base_pointer __f, __base_pointer __l) _NOEXCEPT {
597594 __f->__prev_->__next_ = __l->__next_;
598595 __l->__next_->__prev_ = __f->__prev_;
599596}
600597
601598template <class _Tp, class _Alloc>
602599inline __list_imp<_Tp, _Alloc>::__list_imp() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
603 : __size_alloc_(0, __default_init_tag()) {}
600 : __size_(0) {}
604601
605602template <class _Tp, class _Alloc>
606inline __list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a) : __size_alloc_(0, __node_allocator(__a)) {}
603inline __list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
604 : __size_(0), __node_alloc_(__node_allocator(__a)) {}
607605
608606template <class _Tp, class _Alloc>
609inline __list_imp<_Tp, _Alloc>::__list_imp(const __node_allocator& __a) : __size_alloc_(0, __a) {}
607inline __list_imp<_Tp, _Alloc>::__list_imp(const __node_allocator& __a) : __size_(0), __node_alloc_(__a) {}
610608
611#ifndef _LIBCPP_CXX03_LANG
609# ifndef _LIBCPP_CXX03_LANG
612610template <class _Tp, class _Alloc>
613inline __list_imp<_Tp, _Alloc>::__list_imp(__node_allocator&& __a) _NOEXCEPT : __size_alloc_(0, std::move(__a)) {}
614#endif
611inline __list_imp<_Tp, _Alloc>::__list_imp(__node_allocator&& __a) _NOEXCEPT
612 : __size_(0),
613 __node_alloc_(std::move(__a)) {}
614# endif
615615
616616template <class _Tp, class _Alloc>
617617__list_imp<_Tp, _Alloc>::~__list_imp() {
......@@ -621,10 +621,10 @@ __list_imp<_Tp, _Alloc>::~__list_imp() {
621621template <class _Tp, class _Alloc>
622622void __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT {
623623 if (!empty()) {
624 __link_pointer __f = __end_.__next_;
625 __link_pointer __l = __end_as_link();
624 __base_pointer __f = __end_.__next_;
625 __base_pointer __l = __end_as_link();
626626 __unlink_nodes(__f, __l->__prev_);
627 __sz() = 0;
627 __size_ = 0;
628628 while (__f != __l) {
629629 __node_pointer __np = __f->__as_node();
630630 __f = __f->__next_;
......@@ -635,25 +635,25 @@ void __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT {
635635
636636template <class _Tp, class _Alloc>
637637void __list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
638#if _LIBCPP_STD_VER >= 14
638# if _LIBCPP_STD_VER >= 14
639639 _NOEXCEPT
640#else
640# else
641641 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>)
642#endif
642# endif
643643{
644644 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
645 __alloc_traits::propagate_on_container_swap::value || this->__node_alloc() == __c.__node_alloc(),
645 __alloc_traits::propagate_on_container_swap::value || this->__node_alloc_ == __c.__node_alloc_,
646646 "list::swap: Either propagate_on_container_swap must be true"
647647 " or the allocators must compare equal");
648648 using std::swap;
649 std::__swap_allocator(__node_alloc(), __c.__node_alloc());
650 swap(__sz(), __c.__sz());
649 std::__swap_allocator(__node_alloc_, __c.__node_alloc_);
650 swap(__size_, __c.__size_);
651651 swap(__end_, __c.__end_);
652 if (__sz() == 0)
652 if (__size_ == 0)
653653 __end_.__next_ = __end_.__prev_ = __end_as_link();
654654 else
655655 __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_as_link();
656 if (__c.__sz() == 0)
656 if (__c.__size_ == 0)
657657 __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_as_link();
658658 else
659659 __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link();
......@@ -661,14 +661,14 @@ void __list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
661661
662662template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
663663class _LIBCPP_TEMPLATE_VIS list : private __list_imp<_Tp, _Alloc> {
664 typedef __list_imp<_Tp, _Alloc> base;
665 typedef typename base::__node_type __node_type;
666 typedef typename base::__node_allocator __node_allocator;
667 typedef typename base::__node_pointer __node_pointer;
668 typedef typename base::__node_alloc_traits __node_alloc_traits;
669 typedef typename base::__node_base __node_base;
670 typedef typename base::__node_base_pointer __node_base_pointer;
671 typedef typename base::__link_pointer __link_pointer;
664 typedef __list_imp<_Tp, _Alloc> __base;
665 typedef typename __base::__node_type __node_type;
666 typedef typename __base::__node_allocator __node_allocator;
667 typedef typename __base::__node_pointer __node_pointer;
668 typedef typename __base::__node_alloc_traits __node_alloc_traits;
669 typedef typename __base::__node_base __node_base;
670 typedef typename __base::__node_base_pointer __node_base_pointer;
671 typedef typename __base::__base_pointer __base_pointer;
672672
673673public:
674674 typedef _Tp value_type;
......@@ -678,29 +678,29 @@ public:
678678 "Allocator::value_type must be same type as value_type");
679679 typedef value_type& reference;
680680 typedef const value_type& const_reference;
681 typedef typename base::pointer pointer;
682 typedef typename base::const_pointer const_pointer;
683 typedef typename base::size_type size_type;
684 typedef typename base::difference_type difference_type;
685 typedef typename base::iterator iterator;
686 typedef typename base::const_iterator const_iterator;
681 typedef typename __base::pointer pointer;
682 typedef typename __base::const_pointer const_pointer;
683 typedef typename __base::size_type size_type;
684 typedef typename __base::difference_type difference_type;
685 typedef typename __base::iterator iterator;
686 typedef typename __base::const_iterator const_iterator;
687687 typedef std::reverse_iterator<iterator> reverse_iterator;
688688 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
689#if _LIBCPP_STD_VER >= 20
689# if _LIBCPP_STD_VER >= 20
690690 typedef size_type __remove_return_type;
691#else
691# else
692692 typedef void __remove_return_type;
693#endif
693# endif
694694
695695 _LIBCPP_HIDE_FROM_ABI list() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) {}
696 _LIBCPP_HIDE_FROM_ABI explicit list(const allocator_type& __a) : base(__a) {}
696 _LIBCPP_HIDE_FROM_ABI explicit list(const allocator_type& __a) : __base(__a) {}
697697 _LIBCPP_HIDE_FROM_ABI explicit list(size_type __n);
698#if _LIBCPP_STD_VER >= 14
698# if _LIBCPP_STD_VER >= 14
699699 _LIBCPP_HIDE_FROM_ABI explicit list(size_type __n, const allocator_type& __a);
700#endif
700# endif
701701 _LIBCPP_HIDE_FROM_ABI list(size_type __n, const value_type& __x);
702702 template <__enable_if_t<__is_allocator<_Alloc>::value, int> = 0>
703 _LIBCPP_HIDE_FROM_ABI list(size_type __n, const value_type& __x, const allocator_type& __a) : base(__a) {
703 _LIBCPP_HIDE_FROM_ABI list(size_type __n, const value_type& __x, const allocator_type& __a) : __base(__a) {
704704 for (; __n > 0; --__n)
705705 push_back(__x);
706706 }
......@@ -711,17 +711,18 @@ public:
711711 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> = 0>
712712 _LIBCPP_HIDE_FROM_ABI list(_InpIter __f, _InpIter __l, const allocator_type& __a);
713713
714#if _LIBCPP_STD_VER >= 23
714# if _LIBCPP_STD_VER >= 23
715715 template <_ContainerCompatibleRange<_Tp> _Range>
716 _LIBCPP_HIDE_FROM_ABI list(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type()) : base(__a) {
716 _LIBCPP_HIDE_FROM_ABI list(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
717 : __base(__a) {
717718 prepend_range(std::forward<_Range>(__range));
718719 }
719#endif
720# endif
720721
721722 _LIBCPP_HIDE_FROM_ABI list(const list& __c);
722723 _LIBCPP_HIDE_FROM_ABI list(const list& __c, const __type_identity_t<allocator_type>& __a);
723724 _LIBCPP_HIDE_FROM_ABI list& operator=(const list& __c);
724#ifndef _LIBCPP_CXX03_LANG
725# ifndef _LIBCPP_CXX03_LANG
725726 _LIBCPP_HIDE_FROM_ABI list(initializer_list<value_type> __il);
726727 _LIBCPP_HIDE_FROM_ABI list(initializer_list<value_type> __il, const allocator_type& __a);
727728
......@@ -737,34 +738,34 @@ public:
737738 }
738739
739740 _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<value_type> __il) { assign(__il.begin(), __il.end()); }
740#endif // _LIBCPP_CXX03_LANG
741# endif // _LIBCPP_CXX03_LANG
741742
742743 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> = 0>
743744 _LIBCPP_HIDE_FROM_ABI void assign(_InpIter __f, _InpIter __l);
744745
745#if _LIBCPP_STD_VER >= 23
746# if _LIBCPP_STD_VER >= 23
746747 template <_ContainerCompatibleRange<_Tp> _Range>
747748 _LIBCPP_HIDE_FROM_ABI void assign_range(_Range&& __range) {
748749 __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
749750 }
750#endif
751# endif
751752
752753 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const value_type& __x);
753754
754755 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT;
755756
756 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return base::__sz(); }
757 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return base::empty(); }
757 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return this->__size_; }
758 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __base::empty(); }
758759 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
759 return std::min<size_type>(base::__node_alloc_max_size(), numeric_limits<difference_type >::max());
760 return std::min<size_type>(this->__node_alloc_max_size(), numeric_limits<difference_type >::max());
760761 }
761762
762 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return base::begin(); }
763 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return base::begin(); }
764 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return base::end(); }
765 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return base::end(); }
766 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return base::begin(); }
767 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return base::end(); }
763 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __base::begin(); }
764 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __base::begin(); }
765 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __base::end(); }
766 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return __base::end(); }
767 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return __base::begin(); }
768 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return __base::end(); }
768769
769770 _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { return reverse_iterator(end()); }
770771 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
......@@ -775,26 +776,26 @@ public:
775776
776777 _LIBCPP_HIDE_FROM_ABI reference front() {
777778 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::front called on empty list");
778 return base::__end_.__next_->__as_node()->__get_value();
779 return __base::__end_.__next_->__as_node()->__get_value();
779780 }
780781 _LIBCPP_HIDE_FROM_ABI const_reference front() const {
781782 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::front called on empty list");
782 return base::__end_.__next_->__as_node()->__get_value();
783 return __base::__end_.__next_->__as_node()->__get_value();
783784 }
784785 _LIBCPP_HIDE_FROM_ABI reference back() {
785786 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::back called on empty list");
786 return base::__end_.__prev_->__as_node()->__get_value();
787 return __base::__end_.__prev_->__as_node()->__get_value();
787788 }
788789 _LIBCPP_HIDE_FROM_ABI const_reference back() const {
789790 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::back called on empty list");
790 return base::__end_.__prev_->__as_node()->__get_value();
791 return __base::__end_.__prev_->__as_node()->__get_value();
791792 }
792793
793#ifndef _LIBCPP_CXX03_LANG
794# ifndef _LIBCPP_CXX03_LANG
794795 _LIBCPP_HIDE_FROM_ABI void push_front(value_type&& __x);
795796 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x);
796797
797# if _LIBCPP_STD_VER >= 23
798# if _LIBCPP_STD_VER >= 23
798799 template <_ContainerCompatibleRange<_Tp> _Range>
799800 _LIBCPP_HIDE_FROM_ABI void prepend_range(_Range&& __range) {
800801 insert_range(begin(), std::forward<_Range>(__range));
......@@ -804,20 +805,20 @@ public:
804805 _LIBCPP_HIDE_FROM_ABI void append_range(_Range&& __range) {
805806 insert_range(end(), std::forward<_Range>(__range));
806807 }
807# endif
808# endif
808809
809810 template <class... _Args>
810# if _LIBCPP_STD_VER >= 17
811# if _LIBCPP_STD_VER >= 17
811812 _LIBCPP_HIDE_FROM_ABI reference emplace_front(_Args&&... __args);
812# else
813# else
813814 _LIBCPP_HIDE_FROM_ABI void emplace_front(_Args&&... __args);
814# endif
815# endif
815816 template <class... _Args>
816# if _LIBCPP_STD_VER >= 17
817# if _LIBCPP_STD_VER >= 17
817818 _LIBCPP_HIDE_FROM_ABI reference emplace_back(_Args&&... __args);
818# else
819# else
819820 _LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args);
820# endif
821# endif
821822 template <class... _Args>
822823 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __p, _Args&&... __args);
823824
......@@ -826,19 +827,19 @@ public:
826827 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, initializer_list<value_type> __il) {
827828 return insert(__p, __il.begin(), __il.end());
828829 }
829#endif // _LIBCPP_CXX03_LANG
830# endif // _LIBCPP_CXX03_LANG
830831
831832 _LIBCPP_HIDE_FROM_ABI void push_front(const value_type& __x);
832833 _LIBCPP_HIDE_FROM_ABI void push_back(const value_type& __x);
833834
834#ifndef _LIBCPP_CXX03_LANG
835# ifndef _LIBCPP_CXX03_LANG
835836 template <class _Arg>
836837 _LIBCPP_HIDE_FROM_ABI void __emplace_back(_Arg&& __arg) {
837838 emplace_back(std::forward<_Arg>(__arg));
838839 }
839#else
840# else
840841 _LIBCPP_HIDE_FROM_ABI void __emplace_back(value_type const& __arg) { push_back(__arg); }
841#endif
842# endif
842843
843844 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __x);
844845 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, size_type __n, const value_type& __x);
......@@ -846,23 +847,23 @@ public:
846847 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> = 0>
847848 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, _InpIter __f, _InpIter __l);
848849
849#if _LIBCPP_STD_VER >= 23
850# if _LIBCPP_STD_VER >= 23
850851 template <_ContainerCompatibleRange<_Tp> _Range>
851852 _LIBCPP_HIDE_FROM_ABI iterator insert_range(const_iterator __position, _Range&& __range) {
852853 return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
853854 }
854#endif
855# endif
855856
856857 _LIBCPP_HIDE_FROM_ABI void swap(list& __c)
857#if _LIBCPP_STD_VER >= 14
858# if _LIBCPP_STD_VER >= 14
858859 _NOEXCEPT
859#else
860# else
860861 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<__node_allocator>)
861#endif
862# endif
862863 {
863 base::swap(__c);
864 __base::swap(__c);
864865 }
865 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { base::clear(); }
866 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __base::clear(); }
866867
867868 _LIBCPP_HIDE_FROM_ABI void pop_front();
868869 _LIBCPP_HIDE_FROM_ABI void pop_back();
......@@ -874,13 +875,13 @@ public:
874875 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n, const value_type& __x);
875876
876877 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list& __c);
877#ifndef _LIBCPP_CXX03_LANG
878# ifndef _LIBCPP_CXX03_LANG
878879 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list&& __c) { splice(__p, __c); }
879880 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list&& __c, const_iterator __i) { splice(__p, __c, __i); }
880881 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l) {
881882 splice(__p, __c, __f, __l);
882883 }
883#endif
884# endif
884885 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list& __c, const_iterator __i);
885886 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
886887
......@@ -891,14 +892,14 @@ public:
891892 template <class _BinaryPred>
892893 _LIBCPP_HIDE_FROM_ABI __remove_return_type unique(_BinaryPred __binary_pred);
893894 _LIBCPP_HIDE_FROM_ABI void merge(list& __c);
894#ifndef _LIBCPP_CXX03_LANG
895# ifndef _LIBCPP_CXX03_LANG
895896 _LIBCPP_HIDE_FROM_ABI void merge(list&& __c) { merge(__c); }
896897
897898 template <class _Comp>
898899 _LIBCPP_HIDE_FROM_ABI void merge(list&& __c, _Comp __comp) {
899900 merge(__c, __comp);
900901 }
901#endif
902# endif
902903 template <class _Comp>
903904 _LIBCPP_HIDE_FROM_ABI void merge(list& __c, _Comp __comp);
904905
......@@ -917,9 +918,9 @@ private:
917918 template <class _Iterator, class _Sentinel>
918919 _LIBCPP_HIDE_FROM_ABI iterator __insert_with_sentinel(const_iterator __p, _Iterator __f, _Sentinel __l);
919920
920 _LIBCPP_HIDE_FROM_ABI static void __link_nodes(__link_pointer __p, __link_pointer __f, __link_pointer __l);
921 _LIBCPP_HIDE_FROM_ABI void __link_nodes_at_front(__link_pointer __f, __link_pointer __l);
922 _LIBCPP_HIDE_FROM_ABI void __link_nodes_at_back(__link_pointer __f, __link_pointer __l);
921 _LIBCPP_HIDE_FROM_ABI static void __link_nodes(__base_pointer __p, __base_pointer __f, __base_pointer __l);
922 _LIBCPP_HIDE_FROM_ABI void __link_nodes_at_front(__base_pointer __f, __base_pointer __l);
923 _LIBCPP_HIDE_FROM_ABI void __link_nodes_at_back(__base_pointer __f, __base_pointer __l);
923924 _LIBCPP_HIDE_FROM_ABI iterator __iterator(size_type __n);
924925 // TODO: Make this _LIBCPP_HIDE_FROM_ABI
925926 template <class _Comp>
......@@ -930,7 +931,7 @@ private:
930931 _LIBCPP_HIDE_FROM_ABI void __move_assign(list& __c, false_type);
931932};
932933
933#if _LIBCPP_STD_VER >= 17
934# if _LIBCPP_STD_VER >= 17
934935template <class _InputIterator,
935936 class _Alloc = allocator<__iter_value_type<_InputIterator>>,
936937 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
......@@ -942,18 +943,18 @@ template <class _InputIterator,
942943 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
943944 class = enable_if_t<__is_allocator<_Alloc>::value> >
944945list(_InputIterator, _InputIterator, _Alloc) -> list<__iter_value_type<_InputIterator>, _Alloc>;
945#endif
946# endif
946947
947#if _LIBCPP_STD_VER >= 23
948# if _LIBCPP_STD_VER >= 23
948949template <ranges::input_range _Range,
949950 class _Alloc = allocator<ranges::range_value_t<_Range>>,
950951 class = enable_if_t<__is_allocator<_Alloc>::value> >
951952list(from_range_t, _Range&&, _Alloc = _Alloc()) -> list<ranges::range_value_t<_Range>, _Alloc>;
952#endif
953# endif
953954
954955// Link in nodes [__f, __l] just prior to __p
955956template <class _Tp, class _Alloc>
956inline void list<_Tp, _Alloc>::__link_nodes(__link_pointer __p, __link_pointer __f, __link_pointer __l) {
957inline void list<_Tp, _Alloc>::__link_nodes(__base_pointer __p, __base_pointer __f, __base_pointer __l) {
957958 __p->__prev_->__next_ = __f;
958959 __f->__prev_ = __p->__prev_;
959960 __p->__prev_ = __l;
......@@ -962,44 +963,44 @@ inline void list<_Tp, _Alloc>::__link_nodes(__link_pointer __p, __link_pointer _
962963
963964// Link in nodes [__f, __l] at the front of the list
964965template <class _Tp, class _Alloc>
965inline void list<_Tp, _Alloc>::__link_nodes_at_front(__link_pointer __f, __link_pointer __l) {
966 __f->__prev_ = base::__end_as_link();
967 __l->__next_ = base::__end_.__next_;
968 __l->__next_->__prev_ = __l;
969 base::__end_.__next_ = __f;
966inline void list<_Tp, _Alloc>::__link_nodes_at_front(__base_pointer __f, __base_pointer __l) {
967 __f->__prev_ = __base::__end_as_link();
968 __l->__next_ = __base::__end_.__next_;
969 __l->__next_->__prev_ = __l;
970 __base::__end_.__next_ = __f;
970971}
971972
972973// Link in nodes [__f, __l] at the back of the list
973974template <class _Tp, class _Alloc>
974inline void list<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l) {
975 __l->__next_ = base::__end_as_link();
976 __f->__prev_ = base::__end_.__prev_;
977 __f->__prev_->__next_ = __f;
978 base::__end_.__prev_ = __l;
975inline void list<_Tp, _Alloc>::__link_nodes_at_back(__base_pointer __f, __base_pointer __l) {
976 __l->__next_ = __base::__end_as_link();
977 __f->__prev_ = __base::__end_.__prev_;
978 __f->__prev_->__next_ = __f;
979 __base::__end_.__prev_ = __l;
979980}
980981
981982template <class _Tp, class _Alloc>
982983inline typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::__iterator(size_type __n) {
983 return __n <= base::__sz() / 2 ? std::next(begin(), __n) : std::prev(end(), base::__sz() - __n);
984 return __n <= this->__size_ / 2 ? std::next(begin(), __n) : std::prev(end(), this->__size_ - __n);
984985}
985986
986987template <class _Tp, class _Alloc>
987988list<_Tp, _Alloc>::list(size_type __n) {
988989 for (; __n > 0; --__n)
989#ifndef _LIBCPP_CXX03_LANG
990# ifndef _LIBCPP_CXX03_LANG
990991 emplace_back();
991#else
992# else
992993 push_back(value_type());
993#endif
994# endif
994995}
995996
996#if _LIBCPP_STD_VER >= 14
997# if _LIBCPP_STD_VER >= 14
997998template <class _Tp, class _Alloc>
998list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a) {
999list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : __base(__a) {
9991000 for (; __n > 0; --__n)
10001001 emplace_back();
10011002}
1002#endif
1003# endif
10031004
10041005template <class _Tp, class _Alloc>
10051006list<_Tp, _Alloc>::list(size_type __n, const value_type& __x) {
......@@ -1016,28 +1017,28 @@ list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l) {
10161017
10171018template <class _Tp, class _Alloc>
10181019template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> >
1019list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a) : base(__a) {
1020list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a) : __base(__a) {
10201021 for (; __f != __l; ++__f)
10211022 __emplace_back(*__f);
10221023}
10231024
10241025template <class _Tp, class _Alloc>
10251026list<_Tp, _Alloc>::list(const list& __c)
1026 : base(__node_alloc_traits::select_on_container_copy_construction(__c.__node_alloc())) {
1027 : __base(__node_alloc_traits::select_on_container_copy_construction(__c.__node_alloc_)) {
10271028 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
10281029 push_back(*__i);
10291030}
10301031
10311032template <class _Tp, class _Alloc>
1032list<_Tp, _Alloc>::list(const list& __c, const __type_identity_t<allocator_type>& __a) : base(__a) {
1033list<_Tp, _Alloc>::list(const list& __c, const __type_identity_t<allocator_type>& __a) : __base(__a) {
10331034 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
10341035 push_back(*__i);
10351036}
10361037
1037#ifndef _LIBCPP_CXX03_LANG
1038# ifndef _LIBCPP_CXX03_LANG
10381039
10391040template <class _Tp, class _Alloc>
1040list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a) : base(__a) {
1041list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a) : __base(__a) {
10411042 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(), __e = __il.end(); __i != __e; ++__i)
10421043 push_back(*__i);
10431044}
......@@ -1050,12 +1051,12 @@ list<_Tp, _Alloc>::list(initializer_list<value_type> __il) {
10501051
10511052template <class _Tp, class _Alloc>
10521053inline list<_Tp, _Alloc>::list(list&& __c) noexcept(is_nothrow_move_constructible<__node_allocator>::value)
1053 : base(std::move(__c.__node_alloc())) {
1054 : __base(std::move(__c.__node_alloc_)) {
10541055 splice(end(), __c);
10551056}
10561057
10571058template <class _Tp, class _Alloc>
1058inline list<_Tp, _Alloc>::list(list&& __c, const __type_identity_t<allocator_type>& __a) : base(__a) {
1059inline list<_Tp, _Alloc>::list(list&& __c, const __type_identity_t<allocator_type>& __a) : __base(__a) {
10591060 if (__a == __c.get_allocator())
10601061 splice(end(), __c);
10611062 else {
......@@ -1074,7 +1075,7 @@ inline list<_Tp, _Alloc>& list<_Tp, _Alloc>::operator=(list&& __c) noexcept(
10741075
10751076template <class _Tp, class _Alloc>
10761077void list<_Tp, _Alloc>::__move_assign(list& __c, false_type) {
1077 if (base::__node_alloc() != __c.__node_alloc()) {
1078 if (this->__node_alloc_ != __c.__node_alloc_) {
10781079 typedef move_iterator<iterator> _Ip;
10791080 assign(_Ip(__c.begin()), _Ip(__c.end()));
10801081 } else
......@@ -1085,16 +1086,16 @@ template <class _Tp, class _Alloc>
10851086void list<_Tp, _Alloc>::__move_assign(list& __c,
10861087 true_type) noexcept(is_nothrow_move_assignable<__node_allocator>::value) {
10871088 clear();
1088 base::__move_assign_alloc(__c);
1089 __base::__move_assign_alloc(__c);
10891090 splice(end(), __c);
10901091}
10911092
1092#endif // _LIBCPP_CXX03_LANG
1093# endif // _LIBCPP_CXX03_LANG
10931094
10941095template <class _Tp, class _Alloc>
10951096inline list<_Tp, _Alloc>& list<_Tp, _Alloc>::operator=(const list& __c) {
10961097 if (this != std::addressof(__c)) {
1097 base::__copy_assign_alloc(__c);
1098 __base::__copy_assign_alloc(__c);
10981099 assign(__c.begin(), __c.end());
10991100 }
11001101 return *this;
......@@ -1133,14 +1134,14 @@ void list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x) {
11331134
11341135template <class _Tp, class _Alloc>
11351136inline _Alloc list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT {
1136 return allocator_type(base::__node_alloc());
1137 return allocator_type(this->__node_alloc_);
11371138}
11381139
11391140template <class _Tp, class _Alloc>
11401141typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x) {
11411142 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, __x);
11421143 __link_nodes(__p.__ptr_, __node->__as_link(), __node->__as_link());
1143 ++base::__sz();
1144 ++this->__size_;
11441145 return iterator(__node->__as_link());
11451146}
11461147
......@@ -1154,16 +1155,16 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _
11541155 ++__ds;
11551156 __r = iterator(__node->__as_link());
11561157 iterator __e = __r;
1157#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1158# if _LIBCPP_HAS_EXCEPTIONS
11581159 try {
1159#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1160# endif // _LIBCPP_HAS_EXCEPTIONS
11601161 for (--__n; __n != 0; --__n, (void)++__e, ++__ds) {
11611162 __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, __x)->__as_link();
11621163 }
1163#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1164# if _LIBCPP_HAS_EXCEPTIONS
11641165 } catch (...) {
11651166 while (true) {
1166 __link_pointer __prev = __e.__ptr_->__prev_;
1167 __base_pointer __prev = __e.__ptr_->__prev_;
11671168 __node_pointer __current = __e.__ptr_->__as_node();
11681169 this->__delete_node(__current);
11691170 if (__prev == 0)
......@@ -1172,9 +1173,9 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _
11721173 }
11731174 throw;
11741175 }
1175#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1176# endif // _LIBCPP_HAS_EXCEPTIONS
11761177 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
1177 base::__sz() += __ds;
1178 this->__size_ += __ds;
11781179 }
11791180 return __r;
11801181}
......@@ -1196,16 +1197,16 @@ list<_Tp, _Alloc>::__insert_with_sentinel(const_iterator __p, _Iterator __f, _Se
11961197 ++__ds;
11971198 __r = iterator(__node->__as_link());
11981199 iterator __e = __r;
1199#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1200# if _LIBCPP_HAS_EXCEPTIONS
12001201 try {
1201#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1202# endif // _LIBCPP_HAS_EXCEPTIONS
12021203 for (++__f; __f != __l; ++__f, (void)++__e, ++__ds) {
12031204 __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, *__f)->__as_link();
12041205 }
1205#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1206# if _LIBCPP_HAS_EXCEPTIONS
12061207 } catch (...) {
12071208 while (true) {
1208 __link_pointer __prev = __e.__ptr_->__prev_;
1209 __base_pointer __prev = __e.__ptr_->__prev_;
12091210 __node_pointer __current = __e.__ptr_->__as_node();
12101211 this->__delete_node(__current);
12111212 if (__prev == 0)
......@@ -1214,9 +1215,9 @@ list<_Tp, _Alloc>::__insert_with_sentinel(const_iterator __p, _Iterator __f, _Se
12141215 }
12151216 throw;
12161217 }
1217#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1218# endif // _LIBCPP_HAS_EXCEPTIONS
12181219 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
1219 base::__sz() += __ds;
1220 this->__size_ += __ds;
12201221 }
12211222 return __r;
12221223}
......@@ -1224,71 +1225,71 @@ list<_Tp, _Alloc>::__insert_with_sentinel(const_iterator __p, _Iterator __f, _Se
12241225template <class _Tp, class _Alloc>
12251226void list<_Tp, _Alloc>::push_front(const value_type& __x) {
12261227 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, __x);
1227 __link_pointer __nl = __node->__as_link();
1228 __base_pointer __nl = __node->__as_link();
12281229 __link_nodes_at_front(__nl, __nl);
1229 ++base::__sz();
1230 ++this->__size_;
12301231}
12311232
12321233template <class _Tp, class _Alloc>
12331234void list<_Tp, _Alloc>::push_back(const value_type& __x) {
12341235 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, __x);
1235 __link_pointer __nl = __node->__as_link();
1236 __base_pointer __nl = __node->__as_link();
12361237 __link_nodes_at_back(__nl, __nl);
1237 ++base::__sz();
1238 ++this->__size_;
12381239}
12391240
1240#ifndef _LIBCPP_CXX03_LANG
1241# ifndef _LIBCPP_CXX03_LANG
12411242
12421243template <class _Tp, class _Alloc>
12431244void list<_Tp, _Alloc>::push_front(value_type&& __x) {
12441245 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::move(__x));
1245 __link_pointer __nl = __node->__as_link();
1246 __base_pointer __nl = __node->__as_link();
12461247 __link_nodes_at_front(__nl, __nl);
1247 ++base::__sz();
1248 ++this->__size_;
12481249}
12491250
12501251template <class _Tp, class _Alloc>
12511252void list<_Tp, _Alloc>::push_back(value_type&& __x) {
12521253 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::move(__x));
1253 __link_pointer __nl = __node->__as_link();
1254 __base_pointer __nl = __node->__as_link();
12541255 __link_nodes_at_back(__nl, __nl);
1255 ++base::__sz();
1256 ++this->__size_;
12561257}
12571258
12581259template <class _Tp, class _Alloc>
12591260template <class... _Args>
1260# if _LIBCPP_STD_VER >= 17
1261# if _LIBCPP_STD_VER >= 17
12611262typename list<_Tp, _Alloc>::reference
1262# else
1263# else
12631264void
1264# endif
1265# endif
12651266list<_Tp, _Alloc>::emplace_front(_Args&&... __args) {
12661267 __node_pointer __node =
12671268 this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::forward<_Args>(__args)...);
1268 __link_pointer __nl = __node->__as_link();
1269 __base_pointer __nl = __node->__as_link();
12691270 __link_nodes_at_front(__nl, __nl);
1270 ++base::__sz();
1271# if _LIBCPP_STD_VER >= 17
1271 ++this->__size_;
1272# if _LIBCPP_STD_VER >= 17
12721273 return __node->__get_value();
1273# endif
1274# endif
12741275}
12751276
12761277template <class _Tp, class _Alloc>
12771278template <class... _Args>
1278# if _LIBCPP_STD_VER >= 17
1279# if _LIBCPP_STD_VER >= 17
12791280typename list<_Tp, _Alloc>::reference
1280# else
1281# else
12811282void
1282# endif
1283# endif
12831284list<_Tp, _Alloc>::emplace_back(_Args&&... __args) {
12841285 __node_pointer __node =
12851286 this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::forward<_Args>(__args)...);
1286 __link_pointer __nl = __node->__as_link();
1287 __base_pointer __nl = __node->__as_link();
12871288 __link_nodes_at_back(__nl, __nl);
1288 ++base::__sz();
1289# if _LIBCPP_STD_VER >= 17
1289 ++this->__size_;
1290# if _LIBCPP_STD_VER >= 17
12901291 return __node->__get_value();
1291# endif
1292# endif
12921293}
12931294
12941295template <class _Tp, class _Alloc>
......@@ -1296,48 +1297,48 @@ template <class... _Args>
12961297typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) {
12971298 __node_pointer __node =
12981299 this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::forward<_Args>(__args)...);
1299 __link_pointer __nl = __node->__as_link();
1300 __base_pointer __nl = __node->__as_link();
13001301 __link_nodes(__p.__ptr_, __nl, __nl);
1301 ++base::__sz();
1302 ++this->__size_;
13021303 return iterator(__nl);
13031304}
13041305
13051306template <class _Tp, class _Alloc>
13061307typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) {
13071308 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::move(__x));
1308 __link_pointer __nl = __node->__as_link();
1309 __base_pointer __nl = __node->__as_link();
13091310 __link_nodes(__p.__ptr_, __nl, __nl);
1310 ++base::__sz();
1311 ++this->__size_;
13111312 return iterator(__nl);
13121313}
13131314
1314#endif // _LIBCPP_CXX03_LANG
1315# endif // _LIBCPP_CXX03_LANG
13151316
13161317template <class _Tp, class _Alloc>
13171318void list<_Tp, _Alloc>::pop_front() {
13181319 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::pop_front() called with empty list");
1319 __link_pointer __n = base::__end_.__next_;
1320 base::__unlink_nodes(__n, __n);
1321 --base::__sz();
1320 __base_pointer __n = __base::__end_.__next_;
1321 __base::__unlink_nodes(__n, __n);
1322 --this->__size_;
13221323 this->__delete_node(__n->__as_node());
13231324}
13241325
13251326template <class _Tp, class _Alloc>
13261327void list<_Tp, _Alloc>::pop_back() {
13271328 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::pop_back() called on an empty list");
1328 __link_pointer __n = base::__end_.__prev_;
1329 base::__unlink_nodes(__n, __n);
1330 --base::__sz();
1329 __base_pointer __n = __base::__end_.__prev_;
1330 __base::__unlink_nodes(__n, __n);
1331 --this->__size_;
13311332 this->__delete_node(__n->__as_node());
13321333}
13331334
13341335template <class _Tp, class _Alloc>
13351336typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::erase(const_iterator __p) {
13361337 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p != end(), "list::erase(iterator) called with a non-dereferenceable iterator");
1337 __link_pointer __n = __p.__ptr_;
1338 __link_pointer __r = __n->__next_;
1339 base::__unlink_nodes(__n, __n);
1340 --base::__sz();
1338 __base_pointer __n = __p.__ptr_;
1339 __base_pointer __r = __n->__next_;
1340 __base::__unlink_nodes(__n, __n);
1341 --this->__size_;
13411342 this->__delete_node(__n->__as_node());
13421343 return iterator(__r);
13431344}
......@@ -1345,11 +1346,11 @@ typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::erase(const_iterator __p
13451346template <class _Tp, class _Alloc>
13461347typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) {
13471348 if (__f != __l) {
1348 base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
1349 __base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
13491350 while (__f != __l) {
1350 __link_pointer __n = __f.__ptr_;
1351 __base_pointer __n = __f.__ptr_;
13511352 ++__f;
1352 --base::__sz();
1353 --this->__size_;
13531354 this->__delete_node(__n->__as_node());
13541355 }
13551356 }
......@@ -1358,25 +1359,25 @@ typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::erase(const_iterator __f
13581359
13591360template <class _Tp, class _Alloc>
13601361void list<_Tp, _Alloc>::resize(size_type __n) {
1361 if (__n < base::__sz())
1362 if (__n < this->__size_)
13621363 erase(__iterator(__n), end());
1363 else if (__n > base::__sz()) {
1364 __n -= base::__sz();
1364 else if (__n > this->__size_) {
1365 __n -= this->__size_;
13651366 size_type __ds = 0;
13661367 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr);
13671368 ++__ds;
13681369 iterator __r = iterator(__node->__as_link());
13691370 iterator __e = __r;
1370#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1371# if _LIBCPP_HAS_EXCEPTIONS
13711372 try {
1372#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1373# endif // _LIBCPP_HAS_EXCEPTIONS
13731374 for (--__n; __n != 0; --__n, (void)++__e, ++__ds) {
13741375 __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr)->__as_link();
13751376 }
1376#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1377# if _LIBCPP_HAS_EXCEPTIONS
13771378 } catch (...) {
13781379 while (true) {
1379 __link_pointer __prev = __e.__ptr_->__prev_;
1380 __base_pointer __prev = __e.__ptr_->__prev_;
13801381 __node_pointer __current = __e.__ptr_->__as_node();
13811382 this->__delete_node(__current);
13821383 if (__prev == 0)
......@@ -1385,34 +1386,34 @@ void list<_Tp, _Alloc>::resize(size_type __n) {
13851386 }
13861387 throw;
13871388 }
1388#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1389# endif // _LIBCPP_HAS_EXCEPTIONS
13891390 __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
1390 base::__sz() += __ds;
1391 this->__size_ += __ds;
13911392 }
13921393}
13931394
13941395template <class _Tp, class _Alloc>
13951396void list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) {
1396 if (__n < base::__sz())
1397 if (__n < this->__size_)
13971398 erase(__iterator(__n), end());
1398 else if (__n > base::__sz()) {
1399 __n -= base::__sz();
1399 else if (__n > this->__size_) {
1400 __n -= this->__size_;
14001401 size_type __ds = 0;
14011402 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, __x);
14021403 ++__ds;
1403 __link_pointer __nl = __node->__as_link();
1404 __base_pointer __nl = __node->__as_link();
14041405 iterator __r = iterator(__nl);
14051406 iterator __e = __r;
1406#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1407# if _LIBCPP_HAS_EXCEPTIONS
14071408 try {
1408#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1409# endif // _LIBCPP_HAS_EXCEPTIONS
14091410 for (--__n; __n != 0; --__n, (void)++__e, ++__ds) {
14101411 __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, __x)->__as_link();
14111412 }
1412#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1413# if _LIBCPP_HAS_EXCEPTIONS
14131414 } catch (...) {
14141415 while (true) {
1415 __link_pointer __prev = __e.__ptr_->__prev_;
1416 __base_pointer __prev = __e.__ptr_->__prev_;
14161417 __node_pointer __current = __e.__ptr_->__as_node();
14171418 this->__delete_node(__current);
14181419 if (__prev == 0)
......@@ -1421,9 +1422,9 @@ void list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) {
14211422 }
14221423 throw;
14231424 }
1424#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1425 __link_nodes(base::__end_as_link(), __r.__ptr_, __e.__ptr_);
1426 base::__sz() += __ds;
1425# endif // _LIBCPP_HAS_EXCEPTIONS
1426 __link_nodes(__base::__end_as_link(), __r.__ptr_, __e.__ptr_);
1427 this->__size_ += __ds;
14271428 }
14281429}
14291430
......@@ -1432,38 +1433,38 @@ void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) {
14321433 _LIBCPP_ASSERT_VALID_INPUT_RANGE(
14331434 this != std::addressof(__c), "list::splice(iterator, list) called with this == &list");
14341435 if (!__c.empty()) {
1435 __link_pointer __f = __c.__end_.__next_;
1436 __link_pointer __l = __c.__end_.__prev_;
1437 base::__unlink_nodes(__f, __l);
1436 __base_pointer __f = __c.__end_.__next_;
1437 __base_pointer __l = __c.__end_.__prev_;
1438 __base::__unlink_nodes(__f, __l);
14381439 __link_nodes(__p.__ptr_, __f, __l);
1439 base::__sz() += __c.__sz();
1440 __c.__sz() = 0;
1440 this->__size_ += __c.__size_;
1441 __c.__size_ = 0;
14411442 }
14421443}
14431444
14441445template <class _Tp, class _Alloc>
14451446void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) {
14461447 if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_) {
1447 __link_pointer __f = __i.__ptr_;
1448 base::__unlink_nodes(__f, __f);
1448 __base_pointer __f = __i.__ptr_;
1449 __base::__unlink_nodes(__f, __f);
14491450 __link_nodes(__p.__ptr_, __f, __f);
1450 --__c.__sz();
1451 ++base::__sz();
1451 --__c.__size_;
1452 ++this->__size_;
14521453 }
14531454}
14541455
14551456template <class _Tp, class _Alloc>
14561457void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l) {
14571458 if (__f != __l) {
1458 __link_pointer __first = __f.__ptr_;
1459 __base_pointer __first = __f.__ptr_;
14591460 --__l;
1460 __link_pointer __last = __l.__ptr_;
1461 __base_pointer __last = __l.__ptr_;
14611462 if (this != std::addressof(__c)) {
14621463 size_type __s = std::distance(__f, __l) + 1;
1463 __c.__sz() -= __s;
1464 base::__sz() += __s;
1464 __c.__size_ -= __s;
1465 this->__size_ += __s;
14651466 }
1466 base::__unlink_nodes(__first, __last);
1467 __base::__unlink_nodes(__first, __last);
14671468 __link_nodes(__p.__ptr_, __first, __last);
14681469 }
14691470}
......@@ -1543,12 +1544,12 @@ void list<_Tp, _Alloc>::merge(list& __c, _Comp __comp) {
15431544 iterator __m2 = std::next(__f2);
15441545 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, (void)++__ds)
15451546 ;
1546 base::__sz() += __ds;
1547 __c.__sz() -= __ds;
1548 __link_pointer __f = __f2.__ptr_;
1549 __link_pointer __l = __m2.__ptr_->__prev_;
1547 this->__size_ += __ds;
1548 __c.__size_ -= __ds;
1549 __base_pointer __f = __f2.__ptr_;
1550 __base_pointer __l = __m2.__ptr_->__prev_;
15501551 __f2 = __m2;
1551 base::__unlink_nodes(__f, __l);
1552 __base::__unlink_nodes(__f, __l);
15521553 __m2 = std::next(__f1);
15531554 __link_nodes(__f1.__ptr_, __f, __l);
15541555 __f1 = __m2;
......@@ -1567,7 +1568,7 @@ inline void list<_Tp, _Alloc>::sort() {
15671568template <class _Tp, class _Alloc>
15681569template <class _Comp>
15691570inline void list<_Tp, _Alloc>::sort(_Comp __comp) {
1570 __sort(begin(), end(), base::__sz(), __comp);
1571 __sort(begin(), end(), this->__size_, __comp);
15711572}
15721573
15731574template <class _Tp, class _Alloc>
......@@ -1580,8 +1581,8 @@ list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __
15801581 return __f1;
15811582 case 2:
15821583 if (__comp(*--__e2, *__f1)) {
1583 __link_pointer __f = __e2.__ptr_;
1584 base::__unlink_nodes(__f, __f);
1584 __base_pointer __f = __e2.__ptr_;
1585 __base::__unlink_nodes(__f, __f);
15851586 __link_nodes(__f1.__ptr_, __f, __f);
15861587 return __e2;
15871588 }
......@@ -1595,11 +1596,11 @@ list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __
15951596 iterator __m2 = std::next(__f2);
15961597 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
15971598 ;
1598 __link_pointer __f = __f2.__ptr_;
1599 __link_pointer __l = __m2.__ptr_->__prev_;
1599 __base_pointer __f = __f2.__ptr_;
1600 __base_pointer __l = __m2.__ptr_->__prev_;
16001601 __r = __f2;
16011602 __e1 = __f2 = __m2;
1602 base::__unlink_nodes(__f, __l);
1603 __base::__unlink_nodes(__f, __l);
16031604 __m2 = std::next(__f1);
16041605 __link_nodes(__f1.__ptr_, __f, __l);
16051606 __f1 = __m2;
......@@ -1610,12 +1611,12 @@ list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __
16101611 iterator __m2 = std::next(__f2);
16111612 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
16121613 ;
1613 __link_pointer __f = __f2.__ptr_;
1614 __link_pointer __l = __m2.__ptr_->__prev_;
1614 __base_pointer __f = __f2.__ptr_;
1615 __base_pointer __l = __m2.__ptr_->__prev_;
16151616 if (__e1 == __f2)
16161617 __e1 = __m2;
16171618 __f2 = __m2;
1618 base::__unlink_nodes(__f, __l);
1619 __base::__unlink_nodes(__f, __l);
16191620 __m2 = std::next(__f1);
16201621 __link_nodes(__f1.__ptr_, __f, __l);
16211622 __f1 = __m2;
......@@ -1627,7 +1628,7 @@ list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __
16271628
16281629template <class _Tp, class _Alloc>
16291630void list<_Tp, _Alloc>::reverse() _NOEXCEPT {
1630 if (base::__sz() > 1) {
1631 if (this->__size_ > 1) {
16311632 iterator __e = end();
16321633 for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;) {
16331634 std::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
......@@ -1647,7 +1648,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator==(const list<_Tp, _Alloc>& __x, const
16471648 return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
16481649}
16491650
1650#if _LIBCPP_STD_VER <= 17
1651# if _LIBCPP_STD_VER <= 17
16511652
16521653template <class _Tp, class _Alloc>
16531654inline _LIBCPP_HIDE_FROM_ABI bool operator<(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
......@@ -1674,16 +1675,15 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const list<_Tp, _Alloc>& __x, const
16741675 return !(__y < __x);
16751676}
16761677
1677#else // _LIBCPP_STD_VER <= 17
1678# else // _LIBCPP_STD_VER <= 17
16781679
16791680template <class _Tp, class _Allocator>
16801681_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Tp>
16811682operator<=>(const list<_Tp, _Allocator>& __x, const list<_Tp, _Allocator>& __y) {
1682 return std::lexicographical_compare_three_way(
1683 __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
1683 return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
16841684}
16851685
1686#endif // _LIBCPP_STD_VER <= 17
1686# endif // _LIBCPP_STD_VER <= 17
16871687
16881688template <class _Tp, class _Alloc>
16891689inline _LIBCPP_HIDE_FROM_ABI void swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
......@@ -1691,7 +1691,7 @@ inline _LIBCPP_HIDE_FROM_ABI void swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>
16911691 __x.swap(__y);
16921692}
16931693
1694#if _LIBCPP_STD_VER >= 20
1694# if _LIBCPP_STD_VER >= 20
16951695template <class _Tp, class _Allocator, class _Predicate>
16961696inline _LIBCPP_HIDE_FROM_ABI typename list<_Tp, _Allocator>::size_type
16971697erase_if(list<_Tp, _Allocator>& __c, _Predicate __pred) {
......@@ -1706,38 +1706,50 @@ erase(list<_Tp, _Allocator>& __c, const _Up& __v) {
17061706
17071707template <>
17081708inline constexpr bool __format::__enable_insertable<std::list<char>> = true;
1709# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1709# if _LIBCPP_HAS_WIDE_CHARACTERS
17101710template <>
17111711inline constexpr bool __format::__enable_insertable<std::list<wchar_t>> = true;
1712# endif
1712# endif
17131713
1714#endif // _LIBCPP_STD_VER >= 20
1714# endif // _LIBCPP_STD_VER >= 20
1715
1716template <class _Tp, class _Allocator>
1717struct __container_traits<list<_Tp, _Allocator> > {
1718 // http://eel.is/c++draft/container.reqmts
1719 // Unless otherwise specified (see [associative.reqmts.except], [unord.req.except], [deque.modifiers],
1720 // [inplace.vector.modifiers], and [vector.modifiers]) all container types defined in this Clause meet the following
1721 // additional requirements:
1722 // - If an exception is thrown by an insert() or emplace() function while inserting a single element, that
1723 // function has no effects.
1724 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
1725};
17151726
17161727_LIBCPP_END_NAMESPACE_STD
17171728
1718#if _LIBCPP_STD_VER >= 17
1729# if _LIBCPP_STD_VER >= 17
17191730_LIBCPP_BEGIN_NAMESPACE_STD
17201731namespace pmr {
17211732template <class _ValueT>
17221733using list _LIBCPP_AVAILABILITY_PMR = std::list<_ValueT, polymorphic_allocator<_ValueT>>;
17231734} // namespace pmr
17241735_LIBCPP_END_NAMESPACE_STD
1725#endif
1736# endif
17261737
17271738_LIBCPP_POP_MACROS
17281739
1729#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1730# include <algorithm>
1731# include <atomic>
1732# include <concepts>
1733# include <cstdint>
1734# include <cstdlib>
1735# include <functional>
1736# include <iosfwd>
1737# include <iterator>
1738# include <stdexcept>
1739# include <type_traits>
1740# include <typeinfo>
1741#endif
1740# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1741# include <algorithm>
1742# include <atomic>
1743# include <concepts>
1744# include <cstdint>
1745# include <cstdlib>
1746# include <functional>
1747# include <iosfwd>
1748# include <iterator>
1749# include <stdexcept>
1750# include <type_traits>
1751# include <typeinfo>
1752# endif
1753#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
17421754
17431755#endif // _LIBCPP_LIST
lib/libcxx/include/locale+179-240
......@@ -187,74 +187,72 @@ template <class charT> class messages_byname;
187187
188188*/
189189
190#include <__config>
191
192#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
193
194# include <__algorithm/copy.h>
195# include <__algorithm/equal.h>
196# include <__algorithm/find.h>
197# include <__algorithm/max.h>
198# include <__algorithm/reverse.h>
199# include <__algorithm/unwrap_iter.h>
200# include <__assert>
201# include <__iterator/access.h>
202# include <__iterator/back_insert_iterator.h>
203# include <__iterator/istreambuf_iterator.h>
204# include <__iterator/ostreambuf_iterator.h>
205# include <__locale>
206# include <__memory/unique_ptr.h>
207# include <__type_traits/make_unsigned.h>
208# include <cerrno>
209# include <cstdio>
210# include <cstdlib>
211# include <ctime>
212# include <ios>
213# include <limits>
214# include <new>
215# include <streambuf>
216# include <version>
217
218// TODO: Fix __bsd_locale_defaults.h
190#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
191# include <__cxx03/locale>
192#else
193# include <__config>
194
195# if _LIBCPP_HAS_LOCALIZATION
196
197# include <__algorithm/copy.h>
198# include <__algorithm/equal.h>
199# include <__algorithm/find.h>
200# include <__algorithm/max.h>
201# include <__algorithm/reverse.h>
202# include <__algorithm/unwrap_iter.h>
203# include <__assert>
204# include <__iterator/access.h>
205# include <__iterator/back_insert_iterator.h>
206# include <__iterator/istreambuf_iterator.h>
207# include <__iterator/ostreambuf_iterator.h>
208# include <__locale>
209# include <__locale_dir/pad_and_output.h>
210# include <__memory/unique_ptr.h>
211# include <__new/exceptions.h>
212# include <__type_traits/make_unsigned.h>
213# include <cerrno>
214# include <cstdio>
215# include <cstdlib>
216# include <ctime>
217# include <ios>
218# include <limits>
219# include <streambuf>
220# include <version>
221
222// TODO: Properly qualify calls now that the locale base API defines functions instead of macros
219223// NOLINTBEGIN(libcpp-robust-against-adl)
220224
221# if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
225# if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
222226// Most unix variants have catopen. These are the specific ones that don't.
223# if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__EMSCRIPTEN__)
224# define _LIBCPP_HAS_CATOPEN 1
225# include <nl_types.h>
227# if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__EMSCRIPTEN__)
228# define _LIBCPP_HAS_CATOPEN 1
229# include <nl_types.h>
230# else
231# define _LIBCPP_HAS_CATOPEN 0
232# endif
233# else
234# define _LIBCPP_HAS_CATOPEN 0
226235# endif
227# endif
228
229# ifdef _LIBCPP_LOCALE__L_EXTENSIONS
230# include <__locale_dir/locale_base_api/bsd_locale_defaults.h>
231# else
232# include <__locale_dir/locale_base_api/bsd_locale_fallbacks.h>
233# endif
234
235# if defined(__APPLE__) || defined(__FreeBSD__)
236# include <xlocale.h>
237# endif
238236
239# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
240# pragma GCC system_header
241# endif
237# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
238# pragma GCC system_header
239# endif
242240
243241_LIBCPP_PUSH_MACROS
244# include <__undef_macros>
242# include <__undef_macros>
245243
246244_LIBCPP_BEGIN_NAMESPACE_STD
247245
248# if defined(__APPLE__) || defined(__FreeBSD__)
249# define _LIBCPP_GET_C_LOCALE 0
250# elif defined(__NetBSD__)
251# define _LIBCPP_GET_C_LOCALE LC_C_LOCALE
252# else
253# define _LIBCPP_GET_C_LOCALE __cloc()
246# if defined(__APPLE__) || defined(__FreeBSD__)
247# define _LIBCPP_GET_C_LOCALE 0
248# elif defined(__NetBSD__)
249# define _LIBCPP_GET_C_LOCALE LC_C_LOCALE
250# else
251# define _LIBCPP_GET_C_LOCALE __cloc()
254252// Get the C locale object
255_LIBCPP_EXPORTED_FROM_ABI locale_t __cloc();
256# define __cloc_defined
257# endif
253_LIBCPP_EXPORTED_FROM_ABI __locale::__locale_t __cloc();
254# define __cloc_defined
255# endif
258256
259257// __scan_keyword
260258// Scans [__b, __e) until a match is found in the basic_strings range
......@@ -402,7 +400,7 @@ struct __num_get : protected __num_get_base {
402400 unsigned*& __g_end,
403401 unsigned& __dc,
404402 _CharT* __atoms);
405# ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
403# ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
406404 static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep);
407405 static int __stage2_int_loop(
408406 _CharT __ct,
......@@ -416,7 +414,7 @@ struct __num_get : protected __num_get_base {
416414 unsigned*& __g_end,
417415 _CharT* __atoms);
418416
419# else
417# else
420418 static string __stage2_int_prep(ios_base& __iob, _CharT& __thousands_sep) {
421419 locale __loc = __iob.getloc();
422420 const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
......@@ -451,10 +449,10 @@ private:
451449 (void)__atoms;
452450 return __src;
453451 }
454# endif
452# endif
455453};
456454
457# ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
455# ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
458456template <class _CharT>
459457string __num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep) {
460458 locale __loc = __iob.getloc();
......@@ -463,7 +461,7 @@ string __num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _C
463461 __thousands_sep = __np.thousands_sep();
464462 return __np.grouping();
465463}
466# endif
464# endif
467465
468466template <class _CharT>
469467string __num_get<_CharT>::__stage2_float_prep(
......@@ -478,16 +476,16 @@ string __num_get<_CharT>::__stage2_float_prep(
478476
479477template <class _CharT>
480478int
481# ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
479# ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
482480__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
483481 unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
484482 unsigned* __g, unsigned*& __g_end, _CharT* __atoms)
485# else
483# else
486484__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
487485 unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
488486 unsigned* __g, unsigned*& __g_end, const _CharT* __atoms)
489487
490# endif
488# endif
491489{
492490 if (__a_end == __a && (__ct == __atoms[24] || __ct == __atoms[25])) {
493491 *__a_end++ = __ct == __atoms[24] ? '+' : '-';
......@@ -586,9 +584,9 @@ int __num_get<_CharT>::__stage2_float_loop(
586584}
587585
588586extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<char>;
589# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
587# if _LIBCPP_HAS_WIDE_CHARACTERS
590588extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<wchar_t>;
591# endif
589# endif
592590
593591template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
594592class _LIBCPP_TEMPLATE_VIS num_get : public locale::facet, private __num_get<_CharT> {
......@@ -727,7 +725,7 @@ __num_get_signed_integral(const char* __a, const char* __a_end, ios_base::iostat
727725 __libcpp_remove_reference_t<decltype(errno)> __save_errno = errno;
728726 errno = 0;
729727 char* __p2;
730 long long __ll = strtoll_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
728 long long __ll = __locale::__strtoll(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
731729 __libcpp_remove_reference_t<decltype(errno)> __current_errno = errno;
732730 if (__current_errno == 0)
733731 errno = __save_errno;
......@@ -759,7 +757,7 @@ __num_get_unsigned_integral(const char* __a, const char* __a_end, ios_base::iost
759757 __libcpp_remove_reference_t<decltype(errno)> __save_errno = errno;
760758 errno = 0;
761759 char* __p2;
762 unsigned long long __ll = strtoull_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
760 unsigned long long __ll = __locale::__strtoull(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
763761 __libcpp_remove_reference_t<decltype(errno)> __current_errno = errno;
764762 if (__current_errno == 0)
765763 errno = __save_errno;
......@@ -784,17 +782,17 @@ _LIBCPP_HIDE_FROM_ABI _Tp __do_strtod(const char* __a, char** __p2);
784782
785783template <>
786784inline _LIBCPP_HIDE_FROM_ABI float __do_strtod<float>(const char* __a, char** __p2) {
787 return strtof_l(__a, __p2, _LIBCPP_GET_C_LOCALE);
785 return __locale::__strtof(__a, __p2, _LIBCPP_GET_C_LOCALE);
788786}
789787
790788template <>
791789inline _LIBCPP_HIDE_FROM_ABI double __do_strtod<double>(const char* __a, char** __p2) {
792 return strtod_l(__a, __p2, _LIBCPP_GET_C_LOCALE);
790 return __locale::__strtod(__a, __p2, _LIBCPP_GET_C_LOCALE);
793791}
794792
795793template <>
796794inline _LIBCPP_HIDE_FROM_ABI long double __do_strtod<long double>(const char* __a, char** __p2) {
797 return strtold_l(__a, __p2, _LIBCPP_GET_C_LOCALE);
795 return __locale::__strtold(__a, __p2, _LIBCPP_GET_C_LOCALE);
798796}
799797
800798template <class _Tp>
......@@ -858,14 +856,14 @@ _InputIterator num_get<_CharT, _InputIterator>::__do_get_signed(
858856 // Stage 2
859857 char_type __thousands_sep;
860858 const int __atoms_size = __num_get_base::__int_chr_cnt;
861# ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
859# ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
862860 char_type __atoms1[__atoms_size];
863861 const char_type* __atoms = this->__do_widen(__iob, __atoms1);
864862 string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
865# else
863# else
866864 char_type __atoms[__atoms_size];
867865 string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
868# endif
866# endif
869867 string __buf;
870868 __buf.resize(__buf.capacity());
871869 char* __a = &__buf[0];
......@@ -907,14 +905,14 @@ _InputIterator num_get<_CharT, _InputIterator>::__do_get_unsigned(
907905 // Stage 2
908906 char_type __thousands_sep;
909907 const int __atoms_size = __num_get_base::__int_chr_cnt;
910# ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
908# ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
911909 char_type __atoms1[__atoms_size];
912910 const char_type* __atoms = this->__do_widen(__iob, __atoms1);
913911 string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
914# else
912# else
915913 char_type __atoms[__atoms_size];
916914 string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
917# endif
915# endif
918916 string __buf;
919917 __buf.resize(__buf.capacity());
920918 char* __a = &__buf[0];
......@@ -1048,7 +1046,7 @@ _InputIterator num_get<_CharT, _InputIterator>::do_get(
10481046 }
10491047 // Stage 3
10501048 __buf.resize(__a_end - __a);
1051 if (__libcpp_sscanf_l(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1)
1049 if (__locale::__sscanf(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1)
10521050 __err = ios_base::failbit;
10531051 // EOF checked
10541052 if (__b == __e)
......@@ -1057,9 +1055,9 @@ _InputIterator num_get<_CharT, _InputIterator>::do_get(
10571055}
10581056
10591057extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<char>;
1060# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1058# if _LIBCPP_HAS_WIDE_CHARACTERS
10611059extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<wchar_t>;
1062# endif
1060# endif
10631061
10641062struct _LIBCPP_EXPORTED_FROM_ABI __num_put_base {
10651063protected:
......@@ -1131,11 +1129,11 @@ void __num_put<_CharT>::__widen_and_group_float(
11311129 *__oe++ = __ct.widen(*__nf++);
11321130 *__oe++ = __ct.widen(*__nf++);
11331131 for (__ns = __nf; __ns < __ne; ++__ns)
1134 if (!isxdigit_l(*__ns, _LIBCPP_GET_C_LOCALE))
1132 if (!__locale::__isxdigit(*__ns, _LIBCPP_GET_C_LOCALE))
11351133 break;
11361134 } else {
11371135 for (__ns = __nf; __ns < __ne; ++__ns)
1138 if (!isdigit_l(*__ns, _LIBCPP_GET_C_LOCALE))
1136 if (!__locale::__isdigit(*__ns, _LIBCPP_GET_C_LOCALE))
11391137 break;
11401138 }
11411139 if (__grouping.empty()) {
......@@ -1175,9 +1173,9 @@ void __num_put<_CharT>::__widen_and_group_float(
11751173}
11761174
11771175extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<char>;
1178# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1176# if _LIBCPP_HAS_WIDE_CHARACTERS
11791177extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<wchar_t>;
1180# endif
1178# endif
11811179
11821180template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
11831181class _LIBCPP_TEMPLATE_VIS num_put : public locale::facet, private __num_put<_CharT> {
......@@ -1245,66 +1243,6 @@ protected:
12451243template <class _CharT, class _OutputIterator>
12461244locale::id num_put<_CharT, _OutputIterator>::id;
12471245
1248template <class _CharT, class _OutputIterator>
1249_LIBCPP_HIDE_FROM_ABI _OutputIterator __pad_and_output(
1250 _OutputIterator __s, const _CharT* __ob, const _CharT* __op, const _CharT* __oe, ios_base& __iob, _CharT __fl) {
1251 streamsize __sz = __oe - __ob;
1252 streamsize __ns = __iob.width();
1253 if (__ns > __sz)
1254 __ns -= __sz;
1255 else
1256 __ns = 0;
1257 for (; __ob < __op; ++__ob, ++__s)
1258 *__s = *__ob;
1259 for (; __ns; --__ns, ++__s)
1260 *__s = __fl;
1261 for (; __ob < __oe; ++__ob, ++__s)
1262 *__s = *__ob;
1263 __iob.width(0);
1264 return __s;
1265}
1266
1267template <class _CharT, class _Traits>
1268_LIBCPP_HIDE_FROM_ABI ostreambuf_iterator<_CharT, _Traits> __pad_and_output(
1269 ostreambuf_iterator<_CharT, _Traits> __s,
1270 const _CharT* __ob,
1271 const _CharT* __op,
1272 const _CharT* __oe,
1273 ios_base& __iob,
1274 _CharT __fl) {
1275 if (__s.__sbuf_ == nullptr)
1276 return __s;
1277 streamsize __sz = __oe - __ob;
1278 streamsize __ns = __iob.width();
1279 if (__ns > __sz)
1280 __ns -= __sz;
1281 else
1282 __ns = 0;
1283 streamsize __np = __op - __ob;
1284 if (__np > 0) {
1285 if (__s.__sbuf_->sputn(__ob, __np) != __np) {
1286 __s.__sbuf_ = nullptr;
1287 return __s;
1288 }
1289 }
1290 if (__ns > 0) {
1291 basic_string<_CharT, _Traits> __sp(__ns, __fl);
1292 if (__s.__sbuf_->sputn(__sp.data(), __ns) != __ns) {
1293 __s.__sbuf_ = nullptr;
1294 return __s;
1295 }
1296 }
1297 __np = __oe - __op;
1298 if (__np > 0) {
1299 if (__s.__sbuf_->sputn(__op, __np) != __np) {
1300 __s.__sbuf_ = nullptr;
1301 return __s;
1302 }
1303 }
1304 __iob.width(0);
1305 return __s;
1306}
1307
13081246template <class _CharT, class _OutputIterator>
13091247_OutputIterator
13101248num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, bool __v) const {
......@@ -1336,7 +1274,7 @@ _LIBCPP_HIDE_FROM_ABI inline _OutputIterator num_put<_CharT, _OutputIterator>::_
13361274 _LIBCPP_DIAGNOSTIC_PUSH
13371275 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
13381276 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
1339 int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
1277 int __nc = __locale::__snprintf(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
13401278 _LIBCPP_DIAGNOSTIC_POP
13411279 char* __ne = __nar + __nc;
13421280 char* __np = this->__identify_padding(__nar, __ne, __iob);
......@@ -1389,15 +1327,15 @@ _LIBCPP_HIDE_FROM_ABI inline _OutputIterator num_put<_CharT, _OutputIterator>::_
13891327 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
13901328 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
13911329 if (__specify_precision)
1392 __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
1330 __nc = __locale::__snprintf(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
13931331 else
1394 __nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
1332 __nc = __locale::__snprintf(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
13951333 unique_ptr<char, void (*)(void*)> __nbh(nullptr, free);
13961334 if (__nc > static_cast<int>(__nbuf - 1)) {
13971335 if (__specify_precision)
1398 __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
1336 __nc = __locale::__asprintf(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
13991337 else
1400 __nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
1338 __nc = __locale::__asprintf(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
14011339 if (__nc == -1)
14021340 __throw_bad_alloc();
14031341 __nbh.reset(__nb);
......@@ -1442,7 +1380,7 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_ty
14421380 // Stage 1 - Get pointer in narrow char
14431381 const unsigned __nbuf = 20;
14441382 char __nar[__nbuf];
1445 int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, "%p", __v);
1383 int __nc = __locale::__snprintf(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, "%p", __v);
14461384 char* __ne = __nar + __nc;
14471385 char* __np = this->__identify_padding(__nar, __ne, __iob);
14481386 // Stage 2 - Widen __nar
......@@ -1462,9 +1400,9 @@ num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_ty
14621400}
14631401
14641402extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<char>;
1465# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1403# if _LIBCPP_HAS_WIDE_CHARACTERS
14661404extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<wchar_t>;
1467# endif
1405# endif
14681406
14691407template <class _CharT, class _InputIterator>
14701408_LIBCPP_HIDE_FROM_ABI int __get_up_to_n_digits(
......@@ -1529,7 +1467,7 @@ _LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__x() const;
15291467template <>
15301468_LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__X() const;
15311469
1532# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1470# if _LIBCPP_HAS_WIDE_CHARACTERS
15331471template <>
15341472_LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__weeks() const;
15351473template <>
......@@ -1544,7 +1482,7 @@ template <>
15441482_LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__x() const;
15451483template <>
15461484_LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__X() const;
1547# endif
1485# endif
15481486
15491487template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
15501488class _LIBCPP_TEMPLATE_VIS time_get : public locale::facet, public time_base, private __time_get_c_storage<_CharT> {
......@@ -1998,13 +1936,13 @@ _InputIterator time_get<_CharT, _InputIterator>::do_get(
19981936}
19991937
20001938extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<char>;
2001# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1939# if _LIBCPP_HAS_WIDE_CHARACTERS
20021940extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<wchar_t>;
2003# endif
1941# endif
20041942
20051943class _LIBCPP_EXPORTED_FROM_ABI __time_get {
20061944protected:
2007 locale_t __loc_;
1945 __locale::__locale_t __loc_;
20081946
20091947 __time_get(const char* __nm);
20101948 __time_get(const string& __nm);
......@@ -2036,32 +1974,32 @@ private:
20361974 string_type __analyze(char __fmt, const ctype<_CharT>&);
20371975};
20381976
2039# define _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(_CharT) \
2040 template <> \
2041 _LIBCPP_EXPORTED_FROM_ABI time_base::dateorder __time_get_storage<_CharT>::__do_date_order() const; \
2042 template <> \
2043 _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const char*); \
2044 template <> \
2045 _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const string&); \
2046 template <> \
2047 _LIBCPP_EXPORTED_FROM_ABI void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \
2048 template <> \
2049 _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::string_type __time_get_storage<_CharT>::__analyze( \
2050 char, const ctype<_CharT>&); \
2051 extern template _LIBCPP_EXPORTED_FROM_ABI time_base::dateorder __time_get_storage<_CharT>::__do_date_order() \
2052 const; \
2053 extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const char*); \
2054 extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const string&); \
2055 extern template _LIBCPP_EXPORTED_FROM_ABI void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \
2056 extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::string_type \
2057 __time_get_storage<_CharT>::__analyze(char, const ctype<_CharT>&); \
2058 /**/
1977# define _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(_CharT) \
1978 template <> \
1979 _LIBCPP_EXPORTED_FROM_ABI time_base::dateorder __time_get_storage<_CharT>::__do_date_order() const; \
1980 template <> \
1981 _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const char*); \
1982 template <> \
1983 _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const string&); \
1984 template <> \
1985 _LIBCPP_EXPORTED_FROM_ABI void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \
1986 template <> \
1987 _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::string_type __time_get_storage<_CharT>::__analyze( \
1988 char, const ctype<_CharT>&); \
1989 extern template _LIBCPP_EXPORTED_FROM_ABI time_base::dateorder __time_get_storage<_CharT>::__do_date_order() \
1990 const; \
1991 extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const char*); \
1992 extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const string&); \
1993 extern template _LIBCPP_EXPORTED_FROM_ABI void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \
1994 extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::string_type \
1995 __time_get_storage<_CharT>::__analyze(char, const ctype<_CharT>&); \
1996 /**/
20591997
20601998_LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(char)
2061# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1999# if _LIBCPP_HAS_WIDE_CHARACTERS
20622000_LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(wchar_t)
2063# endif
2064# undef _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION
2001# endif
2002# undef _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION
20652003
20662004template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
20672005class _LIBCPP_TEMPLATE_VIS time_get_byname
......@@ -2094,12 +2032,12 @@ private:
20942032};
20952033
20962034extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<char>;
2097# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2035# if _LIBCPP_HAS_WIDE_CHARACTERS
20982036extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<wchar_t>;
2099# endif
2037# endif
21002038
21012039class _LIBCPP_EXPORTED_FROM_ABI __time_put {
2102 locale_t __loc_;
2040 __locale::__locale_t __loc_;
21032041
21042042protected:
21052043 _LIBCPP_HIDE_FROM_ABI __time_put() : __loc_(_LIBCPP_GET_C_LOCALE) {}
......@@ -2107,9 +2045,9 @@ protected:
21072045 __time_put(const string& __nm);
21082046 ~__time_put();
21092047 void __do_put(char* __nb, char*& __ne, const tm* __tm, char __fmt, char __mod) const;
2110# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2048# if _LIBCPP_HAS_WIDE_CHARACTERS
21112049 void __do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm, char __fmt, char __mod) const;
2112# endif
2050# endif
21132051};
21142052
21152053template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
......@@ -2183,9 +2121,9 @@ _OutputIterator time_put<_CharT, _OutputIterator>::do_put(
21832121}
21842122
21852123extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<char>;
2186# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2124# if _LIBCPP_HAS_WIDE_CHARACTERS
21872125extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<wchar_t>;
2188# endif
2126# endif
21892127
21902128template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
21912129class _LIBCPP_TEMPLATE_VIS time_put_byname : public time_put<_CharT, _OutputIterator> {
......@@ -2201,9 +2139,9 @@ protected:
22012139};
22022140
22032141extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<char>;
2204# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2142# if _LIBCPP_HAS_WIDE_CHARACTERS
22052143extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<wchar_t>;
2206# endif
2144# endif
22072145
22082146// money_base
22092147
......@@ -2268,10 +2206,10 @@ const bool moneypunct<_CharT, _International>::intl;
22682206
22692207extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, false>;
22702208extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, true>;
2271# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2209# if _LIBCPP_HAS_WIDE_CHARACTERS
22722210extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, false>;
22732211extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, true>;
2274# endif
2212# endif
22752213
22762214// moneypunct_byname
22772215
......@@ -2326,14 +2264,14 @@ _LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<char, true>::init(const char*);
23262264extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, false>;
23272265extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, true>;
23282266
2329# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2267# if _LIBCPP_HAS_WIDE_CHARACTERS
23302268template <>
23312269_LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<wchar_t, false>::init(const char*);
23322270template <>
23332271_LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<wchar_t, true>::init(const char*);
23342272extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, false>;
23352273extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, true>;
2336# endif
2274# endif
23372275
23382276// money_get
23392277
......@@ -2394,9 +2332,9 @@ void __money_get<_CharT>::__gather_info(
23942332}
23952333
23962334extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<char>;
2397# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2335# if _LIBCPP_HAS_WIDE_CHARACTERS
23982336extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<wchar_t>;
2399# endif
2337# endif
24002338
24012339template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
24022340class _LIBCPP_TEMPLATE_VIS money_get : public locale::facet, private __money_get<_CharT> {
......@@ -2704,9 +2642,9 @@ _InputIterator money_get<_CharT, _InputIterator>::do_get(
27042642}
27052643
27062644extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<char>;
2707# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2645# if _LIBCPP_HAS_WIDE_CHARACTERS
27082646extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<wchar_t>;
2709# endif
2647# endif
27102648
27112649// money_put
27122650
......@@ -2882,9 +2820,9 @@ void __money_put<_CharT>::__format(
28822820}
28832821
28842822extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<char>;
2885# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2823# if _LIBCPP_HAS_WIDE_CHARACTERS
28862824extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<wchar_t>;
2887# endif
2825# endif
28882826
28892827template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
28902828class _LIBCPP_TEMPLATE_VIS money_put : public locale::facet, private __money_put<_CharT> {
......@@ -2932,7 +2870,7 @@ _OutputIterator money_put<_CharT, _OutputIterator>::do_put(
29322870 unique_ptr<char_type, void (*)(void*)> __hd(0, free);
29332871 // secure memory for digit storage
29342872 if (static_cast<size_t>(__n) > __bs - 1) {
2935 __n = __libcpp_asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units);
2873 __n = __locale::__asprintf(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units);
29362874 if (__n == -1)
29372875 __throw_bad_alloc();
29382876 __hn.reset(__bb);
......@@ -3028,9 +2966,9 @@ _OutputIterator money_put<_CharT, _OutputIterator>::do_put(
30282966}
30292967
30302968extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<char>;
3031# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2969# if _LIBCPP_HAS_WIDE_CHARACTERS
30322970extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<wchar_t>;
3033# endif
2971# endif
30342972
30352973// messages
30362974
......@@ -3074,18 +3012,18 @@ locale::id messages<_CharT>::id;
30743012
30753013template <class _CharT>
30763014typename messages<_CharT>::catalog messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const {
3077# ifdef _LIBCPP_HAS_CATOPEN
3015# if _LIBCPP_HAS_CATOPEN
30783016 return (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE);
3079# else // !_LIBCPP_HAS_CATOPEN
3017# else // !_LIBCPP_HAS_CATOPEN
30803018 (void)__nm;
30813019 return -1;
3082# endif // _LIBCPP_HAS_CATOPEN
3020# endif // _LIBCPP_HAS_CATOPEN
30833021}
30843022
30853023template <class _CharT>
30863024typename messages<_CharT>::string_type
30873025messages<_CharT>::do_get(catalog __c, int __set, int __msgid, const string_type& __dflt) const {
3088# ifdef _LIBCPP_HAS_CATOPEN
3026# if _LIBCPP_HAS_CATOPEN
30893027 string __ndflt;
30903028 __narrow_to_utf8<sizeof(char_type) * __CHAR_BIT__>()(
30913029 std::back_inserter(__ndflt), __dflt.c_str(), __dflt.c_str() + __dflt.size());
......@@ -3095,27 +3033,27 @@ messages<_CharT>::do_get(catalog __c, int __set, int __msgid, const string_type&
30953033 string_type __w;
30963034 __widen_from_utf8<sizeof(char_type) * __CHAR_BIT__>()(std::back_inserter(__w), __n, __n + std::strlen(__n));
30973035 return __w;
3098# else // !_LIBCPP_HAS_CATOPEN
3036# else // !_LIBCPP_HAS_CATOPEN
30993037 (void)__c;
31003038 (void)__set;
31013039 (void)__msgid;
31023040 return __dflt;
3103# endif // _LIBCPP_HAS_CATOPEN
3041# endif // _LIBCPP_HAS_CATOPEN
31043042}
31053043
31063044template <class _CharT>
31073045void messages<_CharT>::do_close(catalog __c) const {
3108# ifdef _LIBCPP_HAS_CATOPEN
3046# if _LIBCPP_HAS_CATOPEN
31093047 catclose((nl_catd)__c);
3110# else // !_LIBCPP_HAS_CATOPEN
3048# else // !_LIBCPP_HAS_CATOPEN
31113049 (void)__c;
3112# endif // _LIBCPP_HAS_CATOPEN
3050# endif // _LIBCPP_HAS_CATOPEN
31133051}
31143052
31153053extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<char>;
3116# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3054# if _LIBCPP_HAS_WIDE_CHARACTERS
31173055extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<wchar_t>;
3118# endif
3056# endif
31193057
31203058template <class _CharT>
31213059class _LIBCPP_TEMPLATE_VIS messages_byname : public messages<_CharT> {
......@@ -3132,11 +3070,11 @@ protected:
31323070};
31333071
31343072extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<char>;
3135# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3073# if _LIBCPP_HAS_WIDE_CHARACTERS
31363074extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<wchar_t>;
3137# endif
3075# endif
31383076
3139# if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT)
3077# if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT)
31403078
31413079template <class _Codecvt,
31423080 class _Elem = wchar_t,
......@@ -3157,19 +3095,19 @@ private:
31573095 size_t __cvtcount_;
31583096
31593097public:
3160# ifndef _LIBCPP_CXX03_LANG
3098# ifndef _LIBCPP_CXX03_LANG
31613099 _LIBCPP_HIDE_FROM_ABI wstring_convert() : wstring_convert(new _Codecvt) {}
31623100 _LIBCPP_HIDE_FROM_ABI explicit wstring_convert(_Codecvt* __pcvt);
3163# else
3101# else
31643102 _LIBCPP_HIDE_FROM_ABI _LIBCPP_EXPLICIT_SINCE_CXX14 wstring_convert(_Codecvt* __pcvt = new _Codecvt);
3165# endif
3103# endif
31663104
31673105 _LIBCPP_HIDE_FROM_ABI wstring_convert(_Codecvt* __pcvt, state_type __state);
31683106 _LIBCPP_EXPLICIT_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
31693107 wstring_convert(const byte_string& __byte_err, const wide_string& __wide_err = wide_string());
3170# ifndef _LIBCPP_CXX03_LANG
3108# ifndef _LIBCPP_CXX03_LANG
31713109 _LIBCPP_HIDE_FROM_ABI wstring_convert(wstring_convert&& __wc);
3172# endif
3110# endif
31733111 _LIBCPP_HIDE_FROM_ABI ~wstring_convert();
31743112
31753113 wstring_convert(const wstring_convert& __wc) = delete;
......@@ -3214,7 +3152,7 @@ wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert(
32143152 __cvtptr_ = new _Codecvt;
32153153}
32163154
3217# ifndef _LIBCPP_CXX03_LANG
3155# ifndef _LIBCPP_CXX03_LANG
32183156
32193157template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
32203158inline wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert(wstring_convert&& __wc)
......@@ -3226,7 +3164,7 @@ inline wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert
32263164 __wc.__cvtptr_ = nullptr;
32273165}
32283166
3229# endif // _LIBCPP_CXX03_LANG
3167# endif // _LIBCPP_CXX03_LANG
32303168
32313169_LIBCPP_SUPPRESS_DEPRECATED_PUSH
32323170template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
......@@ -3380,14 +3318,14 @@ private:
33803318 bool __always_noconv_;
33813319
33823320public:
3383# ifndef _LIBCPP_CXX03_LANG
3321# ifndef _LIBCPP_CXX03_LANG
33843322 _LIBCPP_HIDE_FROM_ABI wbuffer_convert() : wbuffer_convert(nullptr) {}
33853323 explicit _LIBCPP_HIDE_FROM_ABI
33863324 wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt = new _Codecvt, state_type __state = state_type());
3387# else
3325# else
33883326 _LIBCPP_EXPLICIT_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
33893327 wbuffer_convert(streambuf* __bytebuf = nullptr, _Codecvt* __pcvt = new _Codecvt, state_type __state = state_type());
3390# endif
3328# endif
33913329
33923330 _LIBCPP_HIDE_FROM_ABI ~wbuffer_convert();
33933331
......@@ -3743,7 +3681,7 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>* wbuffer_convert<_Codecvt, _Elem, _Tr>::__
37433681
37443682_LIBCPP_SUPPRESS_DEPRECATED_POP
37453683
3746# endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT)
3684# endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT)
37473685
37483686_LIBCPP_END_NAMESPACE_STD
37493687
......@@ -3751,17 +3689,18 @@ _LIBCPP_POP_MACROS
37513689
37523690// NOLINTEND(libcpp-robust-against-adl)
37533691
3754#endif // !defined(_LIBCPP_HAS_NO_LOCALIZATION)
3755
3756#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
3757# include <atomic>
3758# include <concepts>
3759# include <cstdarg>
3760# include <iterator>
3761# include <mutex>
3762# include <stdexcept>
3763# include <type_traits>
3764# include <typeinfo>
3765#endif
3692# endif // _LIBCPP_HAS_LOCALIZATION
3693
3694# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
3695# include <atomic>
3696# include <concepts>
3697# include <cstdarg>
3698# include <iterator>
3699# include <mutex>
3700# include <stdexcept>
3701# include <type_traits>
3702# include <typeinfo>
3703# endif
3704#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
37663705
37673706#endif // _LIBCPP_LOCALE
lib/libcxx/include/locale.h deleted-46
......@@ -1,46 +0,0 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_LOCALE_H
11#define _LIBCPP_LOCALE_H
12
13/*
14 locale.h synopsis
15
16Macros:
17
18 LC_ALL
19 LC_COLLATE
20 LC_CTYPE
21 LC_MONETARY
22 LC_NUMERIC
23 LC_TIME
24
25Types:
26
27 lconv
28
29Functions:
30
31 setlocale
32 localeconv
33
34*/
35
36#include <__config>
37
38#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
39# pragma GCC system_header
40#endif
41
42#if __has_include_next(<locale.h>)
43# include_next <locale.h>
44#endif
45
46#endif // _LIBCPP_LOCALE_H
lib/libcxx/include/map+194-166
......@@ -571,53 +571,64 @@ erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
571571
572572*/
573573
574#include <__algorithm/equal.h>
575#include <__algorithm/lexicographical_compare.h>
576#include <__algorithm/lexicographical_compare_three_way.h>
577#include <__assert>
578#include <__config>
579#include <__functional/binary_function.h>
580#include <__functional/is_transparent.h>
581#include <__functional/operations.h>
582#include <__iterator/erase_if_container.h>
583#include <__iterator/iterator_traits.h>
584#include <__iterator/ranges_iterator_traits.h>
585#include <__iterator/reverse_iterator.h>
586#include <__memory/addressof.h>
587#include <__memory/allocator.h>
588#include <__memory_resource/polymorphic_allocator.h>
589#include <__node_handle>
590#include <__ranges/concepts.h>
591#include <__ranges/container_compatible_range.h>
592#include <__ranges/from_range.h>
593#include <__tree>
594#include <__type_traits/is_allocator.h>
595#include <__utility/forward.h>
596#include <__utility/piecewise_construct.h>
597#include <__utility/swap.h>
598#include <stdexcept>
599#include <tuple>
600#include <version>
574#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
575# include <__cxx03/map>
576#else
577# include <__algorithm/equal.h>
578# include <__algorithm/lexicographical_compare.h>
579# include <__algorithm/lexicographical_compare_three_way.h>
580# include <__assert>
581# include <__config>
582# include <__functional/binary_function.h>
583# include <__functional/is_transparent.h>
584# include <__functional/operations.h>
585# include <__iterator/erase_if_container.h>
586# include <__iterator/iterator_traits.h>
587# include <__iterator/ranges_iterator_traits.h>
588# include <__iterator/reverse_iterator.h>
589# include <__memory/addressof.h>
590# include <__memory/allocator.h>
591# include <__memory/allocator_traits.h>
592# include <__memory/pointer_traits.h>
593# include <__memory/unique_ptr.h>
594# include <__memory_resource/polymorphic_allocator.h>
595# include <__new/launder.h>
596# include <__node_handle>
597# include <__ranges/concepts.h>
598# include <__ranges/container_compatible_range.h>
599# include <__ranges/from_range.h>
600# include <__tree>
601# include <__type_traits/container_traits.h>
602# include <__type_traits/is_allocator.h>
603# include <__type_traits/remove_const.h>
604# include <__type_traits/type_identity.h>
605# include <__utility/forward.h>
606# include <__utility/pair.h>
607# include <__utility/piecewise_construct.h>
608# include <__utility/swap.h>
609# include <stdexcept>
610# include <tuple>
611# include <version>
601612
602613// standard-mandated includes
603614
604615// [iterator.range]
605#include <__iterator/access.h>
606#include <__iterator/data.h>
607#include <__iterator/empty.h>
608#include <__iterator/reverse_access.h>
609#include <__iterator/size.h>
616# include <__iterator/access.h>
617# include <__iterator/data.h>
618# include <__iterator/empty.h>
619# include <__iterator/reverse_access.h>
620# include <__iterator/size.h>
610621
611622// [associative.map.syn]
612#include <compare>
613#include <initializer_list>
623# include <compare>
624# include <initializer_list>
614625
615#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
616# pragma GCC system_header
617#endif
626# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
627# pragma GCC system_header
628# endif
618629
619630_LIBCPP_PUSH_MACROS
620#include <__undef_macros>
631# include <__undef_macros>
621632
622633_LIBCPP_BEGIN_NAMESPACE_STD
623634
......@@ -646,7 +657,7 @@ public:
646657 swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y));
647658 }
648659
649#if _LIBCPP_STD_VER >= 14
660# if _LIBCPP_STD_VER >= 14
650661 template <typename _K2>
651662 _LIBCPP_HIDE_FROM_ABI bool operator()(const _K2& __x, const _CP& __y) const {
652663 return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);
......@@ -656,7 +667,7 @@ public:
656667 _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _K2& __y) const {
657668 return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);
658669 }
659#endif
670# endif
660671};
661672
662673template <class _Key, class _CP, class _Compare>
......@@ -684,7 +695,7 @@ public:
684695 swap(__comp_, __y.__comp_);
685696 }
686697
687#if _LIBCPP_STD_VER >= 14
698# if _LIBCPP_STD_VER >= 14
688699 template <typename _K2>
689700 _LIBCPP_HIDE_FROM_ABI bool operator()(const _K2& __x, const _CP& __y) const {
690701 return __comp_(__x, __y.__get_value().first);
......@@ -694,7 +705,7 @@ public:
694705 _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _K2& __y) const {
695706 return __comp_(__x.__get_value().first, __y);
696707 }
697#endif
708# endif
698709};
699710
700711template <class _Key, class _CP, class _Compare, bool __b>
......@@ -724,14 +735,14 @@ public:
724735 __first_constructed(false),
725736 __second_constructed(false) {}
726737
727#ifndef _LIBCPP_CXX03_LANG
738# ifndef _LIBCPP_CXX03_LANG
728739 _LIBCPP_HIDE_FROM_ABI __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
729740 : __na_(__x.__na_),
730741 __first_constructed(__x.__value_constructed),
731742 __second_constructed(__x.__value_constructed) {
732743 __x.__value_constructed = false;
733744 }
734#endif // _LIBCPP_CXX03_LANG
745# endif // _LIBCPP_CXX03_LANG
735746
736747 __map_node_destructor& operator=(const __map_node_destructor&) = delete;
737748
......@@ -752,7 +763,7 @@ class multimap;
752763template <class _TreeIterator>
753764class __map_const_iterator;
754765
755#ifndef _LIBCPP_CXX03_LANG
766# ifndef _LIBCPP_CXX03_LANG
756767
757768template <class _Key, class _Tp>
758769struct _LIBCPP_STANDALONE_DEBUG __value_type {
......@@ -767,19 +778,19 @@ private:
767778
768779public:
769780 _LIBCPP_HIDE_FROM_ABI value_type& __get_value() {
770# if _LIBCPP_STD_VER >= 17
781# if _LIBCPP_STD_VER >= 17
771782 return *std::launder(std::addressof(__cc_));
772# else
783# else
773784 return __cc_;
774# endif
785# endif
775786 }
776787
777788 _LIBCPP_HIDE_FROM_ABI const value_type& __get_value() const {
778# if _LIBCPP_STD_VER >= 17
789# if _LIBCPP_STD_VER >= 17
779790 return *std::launder(std::addressof(__cc_));
780# else
791# else
781792 return __cc_;
782# endif
793# endif
783794 }
784795
785796 _LIBCPP_HIDE_FROM_ABI __nc_ref_pair_type __ref() {
......@@ -814,7 +825,7 @@ public:
814825 __value_type(__value_type&&) = delete;
815826};
816827
817#else
828# else
818829
819830template <class _Key, class _Tp>
820831struct __value_type {
......@@ -835,7 +846,7 @@ public:
835846 ~__value_type() = delete;
836847};
837848
838#endif // _LIBCPP_CXX03_LANG
849# endif // _LIBCPP_CXX03_LANG
839850
840851template <class _Tp>
841852struct __extract_key_value_types;
......@@ -1011,10 +1022,10 @@ public:
10111022 typedef std::reverse_iterator<iterator> reverse_iterator;
10121023 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
10131024
1014#if _LIBCPP_STD_VER >= 17
1025# if _LIBCPP_STD_VER >= 17
10151026 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
10161027 typedef __insert_return_type<iterator, node_type> insert_return_type;
1017#endif
1028# endif
10181029
10191030 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
10201031 friend class _LIBCPP_TEMPLATE_VIS map;
......@@ -1046,7 +1057,7 @@ public:
10461057 insert(__f, __l);
10471058 }
10481059
1049#if _LIBCPP_STD_VER >= 23
1060# if _LIBCPP_STD_VER >= 23
10501061 template <_ContainerCompatibleRange<value_type> _Range>
10511062 _LIBCPP_HIDE_FROM_ABI
10521063 map(from_range_t,
......@@ -1056,37 +1067,37 @@ public:
10561067 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {
10571068 insert_range(std::forward<_Range>(__range));
10581069 }
1059#endif
1070# endif
10601071
1061#if _LIBCPP_STD_VER >= 14
1072# if _LIBCPP_STD_VER >= 14
10621073 template <class _InputIterator>
10631074 _LIBCPP_HIDE_FROM_ABI map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
10641075 : map(__f, __l, key_compare(), __a) {}
1065#endif
1076# endif
10661077
1067#if _LIBCPP_STD_VER >= 23
1078# if _LIBCPP_STD_VER >= 23
10681079 template <_ContainerCompatibleRange<value_type> _Range>
10691080 _LIBCPP_HIDE_FROM_ABI map(from_range_t, _Range&& __range, const allocator_type& __a)
10701081 : map(from_range, std::forward<_Range>(__range), key_compare(), __a) {}
1071#endif
1082# endif
10721083
10731084 _LIBCPP_HIDE_FROM_ABI map(const map& __m) : __tree_(__m.__tree_) { insert(__m.begin(), __m.end()); }
10741085
10751086 _LIBCPP_HIDE_FROM_ABI map& operator=(const map& __m) {
1076#ifndef _LIBCPP_CXX03_LANG
1087# ifndef _LIBCPP_CXX03_LANG
10771088 __tree_ = __m.__tree_;
1078#else
1089# else
10791090 if (this != std::addressof(__m)) {
10801091 __tree_.clear();
10811092 __tree_.value_comp() = __m.__tree_.value_comp();
10821093 __tree_.__copy_assign_alloc(__m.__tree_);
10831094 insert(__m.begin(), __m.end());
10841095 }
1085#endif
1096# endif
10861097 return *this;
10871098 }
10881099
1089#ifndef _LIBCPP_CXX03_LANG
1100# ifndef _LIBCPP_CXX03_LANG
10901101
10911102 _LIBCPP_HIDE_FROM_ABI map(map&& __m) noexcept(is_nothrow_move_constructible<__base>::value)
10921103 : __tree_(std::move(__m.__tree_)) {}
......@@ -1108,17 +1119,17 @@ public:
11081119 insert(__il.begin(), __il.end());
11091120 }
11101121
1111# if _LIBCPP_STD_VER >= 14
1122# if _LIBCPP_STD_VER >= 14
11121123 _LIBCPP_HIDE_FROM_ABI map(initializer_list<value_type> __il, const allocator_type& __a)
11131124 : map(__il, key_compare(), __a) {}
1114# endif
1125# endif
11151126
11161127 _LIBCPP_HIDE_FROM_ABI map& operator=(initializer_list<value_type> __il) {
11171128 __tree_.__assign_unique(__il.begin(), __il.end());
11181129 return *this;
11191130 }
11201131
1121#endif // _LIBCPP_CXX03_LANG
1132# endif // _LIBCPP_CXX03_LANG
11221133
11231134 _LIBCPP_HIDE_FROM_ABI explicit map(const allocator_type& __a) : __tree_(typename __base::allocator_type(__a)) {}
11241135
......@@ -1144,14 +1155,14 @@ public:
11441155 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return rbegin(); }
11451156 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
11461157
1147 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __tree_.size() == 0; }
1158 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __tree_.size() == 0; }
11481159 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __tree_.size(); }
11491160 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __tree_.max_size(); }
11501161
11511162 _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](const key_type& __k);
1152#ifndef _LIBCPP_CXX03_LANG
1163# ifndef _LIBCPP_CXX03_LANG
11531164 _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](key_type&& __k);
1154#endif
1165# endif
11551166
11561167 _LIBCPP_HIDE_FROM_ABI mapped_type& at(const key_type& __k);
11571168 _LIBCPP_HIDE_FROM_ABI const mapped_type& at(const key_type& __k) const;
......@@ -1160,7 +1171,7 @@ public:
11601171 _LIBCPP_HIDE_FROM_ABI key_compare key_comp() const { return __tree_.value_comp().key_comp(); }
11611172 _LIBCPP_HIDE_FROM_ABI value_compare value_comp() const { return value_compare(__tree_.value_comp().key_comp()); }
11621173
1163#ifndef _LIBCPP_CXX03_LANG
1174# ifndef _LIBCPP_CXX03_LANG
11641175 template <class... _Args>
11651176 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> emplace(_Args&&... __args) {
11661177 return __tree_.__emplace_unique(std::forward<_Args>(__args)...);
......@@ -1181,7 +1192,7 @@ public:
11811192 return __tree_.__insert_unique(__pos.__i_, std::forward<_Pp>(__p));
11821193 }
11831194
1184#endif // _LIBCPP_CXX03_LANG
1195# endif // _LIBCPP_CXX03_LANG
11851196
11861197 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __v) { return __tree_.__insert_unique(__v); }
11871198
......@@ -1189,7 +1200,7 @@ public:
11891200 return __tree_.__insert_unique(__p.__i_, __v);
11901201 }
11911202
1192#ifndef _LIBCPP_CXX03_LANG
1203# ifndef _LIBCPP_CXX03_LANG
11931204 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __v) {
11941205 return __tree_.__insert_unique(std::move(__v));
11951206 }
......@@ -1199,7 +1210,7 @@ public:
11991210 }
12001211
12011212 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
1202#endif
1213# endif
12031214
12041215 template <class _InputIterator>
12051216 _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __f, _InputIterator __l) {
......@@ -1207,7 +1218,7 @@ public:
12071218 insert(__e.__i_, *__f);
12081219 }
12091220
1210#if _LIBCPP_STD_VER >= 23
1221# if _LIBCPP_STD_VER >= 23
12111222 template <_ContainerCompatibleRange<value_type> _Range>
12121223 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
12131224 const_iterator __end = cend();
......@@ -1215,9 +1226,9 @@ public:
12151226 insert(__end.__i_, std::forward<decltype(__element)>(__element));
12161227 }
12171228 }
1218#endif
1229# endif
12191230
1220#if _LIBCPP_STD_VER >= 17
1231# if _LIBCPP_STD_VER >= 17
12211232
12221233 template <class... _Args>
12231234 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args) {
......@@ -1302,7 +1313,7 @@ public:
13021313 return __r;
13031314 }
13041315
1305#endif // _LIBCPP_STD_VER >= 17
1316# endif // _LIBCPP_STD_VER >= 17
13061317
13071318 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __tree_.erase(__p.__i_); }
13081319 _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __p) { return __tree_.erase(__p.__i_); }
......@@ -1312,7 +1323,7 @@ public:
13121323 }
13131324 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __tree_.clear(); }
13141325
1315#if _LIBCPP_STD_VER >= 17
1326# if _LIBCPP_STD_VER >= 17
13161327 _LIBCPP_HIDE_FROM_ABI insert_return_type insert(node_type&& __nh) {
13171328 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
13181329 "node_type with incompatible allocator passed to map::insert()");
......@@ -1353,13 +1364,13 @@ public:
13531364 __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
13541365 __tree_.__node_handle_merge_unique(__source.__tree_);
13551366 }
1356#endif
1367# endif
13571368
13581369 _LIBCPP_HIDE_FROM_ABI void swap(map& __m) _NOEXCEPT_(__is_nothrow_swappable_v<__base>) { __tree_.swap(__m.__tree_); }
13591370
13601371 _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __tree_.find(__k); }
13611372 _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __tree_.find(__k); }
1362#if _LIBCPP_STD_VER >= 14
1373# if _LIBCPP_STD_VER >= 14
13631374 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
13641375 _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
13651376 return __tree_.find(__k);
......@@ -1368,27 +1379,27 @@ public:
13681379 _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
13691380 return __tree_.find(__k);
13701381 }
1371#endif
1382# endif
13721383
13731384 _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __tree_.__count_unique(__k); }
1374#if _LIBCPP_STD_VER >= 14
1385# if _LIBCPP_STD_VER >= 14
13751386 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
13761387 _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
13771388 return __tree_.__count_multi(__k);
13781389 }
1379#endif
1390# endif
13801391
1381#if _LIBCPP_STD_VER >= 20
1392# if _LIBCPP_STD_VER >= 20
13821393 _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
13831394 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
13841395 _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
13851396 return find(__k) != end();
13861397 }
1387#endif // _LIBCPP_STD_VER >= 20
1398# endif // _LIBCPP_STD_VER >= 20
13881399
13891400 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __k) { return __tree_.lower_bound(__k); }
13901401 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __k) const { return __tree_.lower_bound(__k); }
1391#if _LIBCPP_STD_VER >= 14
1402# if _LIBCPP_STD_VER >= 14
13921403 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
13931404 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _K2& __k) {
13941405 return __tree_.lower_bound(__k);
......@@ -1398,11 +1409,11 @@ public:
13981409 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _K2& __k) const {
13991410 return __tree_.lower_bound(__k);
14001411 }
1401#endif
1412# endif
14021413
14031414 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __k) { return __tree_.upper_bound(__k); }
14041415 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __k) const { return __tree_.upper_bound(__k); }
1405#if _LIBCPP_STD_VER >= 14
1416# if _LIBCPP_STD_VER >= 14
14061417 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
14071418 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _K2& __k) {
14081419 return __tree_.upper_bound(__k);
......@@ -1411,7 +1422,7 @@ public:
14111422 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _K2& __k) const {
14121423 return __tree_.upper_bound(__k);
14131424 }
1414#endif
1425# endif
14151426
14161427 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
14171428 return __tree_.__equal_range_unique(__k);
......@@ -1419,7 +1430,7 @@ public:
14191430 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
14201431 return __tree_.__equal_range_unique(__k);
14211432 }
1422#if _LIBCPP_STD_VER >= 14
1433# if _LIBCPP_STD_VER >= 14
14231434 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
14241435 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
14251436 return __tree_.__equal_range_multi(__k);
......@@ -1428,7 +1439,7 @@ public:
14281439 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
14291440 return __tree_.__equal_range_multi(__k);
14301441 }
1431#endif
1442# endif
14321443
14331444private:
14341445 typedef typename __base::__node __node;
......@@ -1440,12 +1451,12 @@ private:
14401451 typedef __map_node_destructor<__node_allocator> _Dp;
14411452 typedef unique_ptr<__node, _Dp> __node_holder;
14421453
1443#ifdef _LIBCPP_CXX03_LANG
1454# ifdef _LIBCPP_CXX03_LANG
14441455 _LIBCPP_HIDE_FROM_ABI __node_holder __construct_node_with_key(const key_type& __k);
1445#endif
1456# endif
14461457};
14471458
1448#if _LIBCPP_STD_VER >= 17
1459# if _LIBCPP_STD_VER >= 17
14491460template <class _InputIterator,
14501461 class _Compare = less<__iter_key_type<_InputIterator>>,
14511462 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
......@@ -1455,7 +1466,7 @@ template <class _InputIterator,
14551466map(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
14561467 -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
14571468
1458# if _LIBCPP_STD_VER >= 23
1469# if _LIBCPP_STD_VER >= 23
14591470template <ranges::input_range _Range,
14601471 class _Compare = less<__range_key_type<_Range>>,
14611472 class _Allocator = allocator<__range_to_alloc_type<_Range>>,
......@@ -1463,7 +1474,7 @@ template <ranges::input_range _Range,
14631474 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
14641475map(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator())
14651476 -> map<__range_key_type<_Range>, __range_mapped_type<_Range>, _Compare, _Allocator>;
1466# endif
1477# endif
14671478
14681479template <class _Key,
14691480 class _Tp,
......@@ -1485,18 +1496,18 @@ map(_InputIterator, _InputIterator, _Allocator)
14851496 less<__iter_key_type<_InputIterator>>,
14861497 _Allocator>;
14871498
1488# if _LIBCPP_STD_VER >= 23
1499# if _LIBCPP_STD_VER >= 23
14891500template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
14901501map(from_range_t, _Range&&, _Allocator)
14911502 -> map<__range_key_type<_Range>, __range_mapped_type<_Range>, less<__range_key_type<_Range>>, _Allocator>;
1492# endif
1503# endif
14931504
14941505template <class _Key, class _Tp, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
14951506map(initializer_list<pair<_Key, _Tp>>,
14961507 _Allocator) -> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
1497#endif
1508# endif
14981509
1499#ifndef _LIBCPP_CXX03_LANG
1510# ifndef _LIBCPP_CXX03_LANG
15001511template <class _Key, class _Tp, class _Compare, class _Allocator>
15011512map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
15021513 : __tree_(std::move(__m.__tree_), typename __base::allocator_type(__a)) {
......@@ -1527,7 +1538,7 @@ _Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k) {
15271538 // NOLINTEND(bugprone-use-after-move)
15281539}
15291540
1530#else // _LIBCPP_CXX03_LANG
1541# else // _LIBCPP_CXX03_LANG
15311542
15321543template <class _Key, class _Tp, class _Compare, class _Allocator>
15331544typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
......@@ -1554,7 +1565,7 @@ _Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) {
15541565 return __r->__value_.__get_value().second;
15551566}
15561567
1557#endif // _LIBCPP_CXX03_LANG
1568# endif // _LIBCPP_CXX03_LANG
15581569
15591570template <class _Key, class _Tp, class _Compare, class _Allocator>
15601571_Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) {
......@@ -1580,7 +1591,7 @@ operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp,
15801591 return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
15811592}
15821593
1583#if _LIBCPP_STD_VER <= 17
1594# if _LIBCPP_STD_VER <= 17
15841595
15851596template <class _Key, class _Tp, class _Compare, class _Allocator>
15861597inline _LIBCPP_HIDE_FROM_ABI bool
......@@ -1612,7 +1623,7 @@ operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp,
16121623 return !(__y < __x);
16131624}
16141625
1615#else // #if _LIBCPP_STD_VER <= 17
1626# else // #if _LIBCPP_STD_VER <= 17
16161627
16171628template <class _Key, class _Tp, class _Compare, class _Allocator>
16181629_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<pair<const _Key, _Tp>>
......@@ -1620,7 +1631,7 @@ operator<=>(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp
16201631 return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
16211632}
16221633
1623#endif // #if _LIBCPP_STD_VER <= 17
1634# endif // #if _LIBCPP_STD_VER <= 17
16241635
16251636template <class _Key, class _Tp, class _Compare, class _Allocator>
16261637inline _LIBCPP_HIDE_FROM_ABI void
......@@ -1629,13 +1640,21 @@ swap(map<_Key, _Tp, _Compare, _Allocator>& __x, map<_Key, _Tp, _Compare, _Alloca
16291640 __x.swap(__y);
16301641}
16311642
1632#if _LIBCPP_STD_VER >= 20
1643# if _LIBCPP_STD_VER >= 20
16331644template <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate>
16341645inline _LIBCPP_HIDE_FROM_ABI typename map<_Key, _Tp, _Compare, _Allocator>::size_type
16351646erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) {
16361647 return std::__libcpp_erase_if_container(__c, __pred);
16371648}
1638#endif
1649# endif
1650
1651template <class _Key, class _Tp, class _Compare, class _Allocator>
1652struct __container_traits<map<_Key, _Tp, _Compare, _Allocator> > {
1653 // http://eel.is/c++draft/associative.reqmts.except#2
1654 // For associative containers, if an exception is thrown by any operation from within
1655 // an insert or emplace function inserting a single element, the insertion has no effect.
1656 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
1657};
16391658
16401659template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
16411660class _LIBCPP_TEMPLATE_VIS multimap {
......@@ -1687,9 +1706,9 @@ public:
16871706 typedef std::reverse_iterator<iterator> reverse_iterator;
16881707 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
16891708
1690#if _LIBCPP_STD_VER >= 17
1709# if _LIBCPP_STD_VER >= 17
16911710 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
1692#endif
1711# endif
16931712
16941713 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
16951714 friend class _LIBCPP_TEMPLATE_VIS map;
......@@ -1721,7 +1740,7 @@ public:
17211740 insert(__f, __l);
17221741 }
17231742
1724#if _LIBCPP_STD_VER >= 23
1743# if _LIBCPP_STD_VER >= 23
17251744 template <_ContainerCompatibleRange<value_type> _Range>
17261745 _LIBCPP_HIDE_FROM_ABI
17271746 multimap(from_range_t,
......@@ -1731,19 +1750,19 @@ public:
17311750 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {
17321751 insert_range(std::forward<_Range>(__range));
17331752 }
1734#endif
1753# endif
17351754
1736#if _LIBCPP_STD_VER >= 14
1755# if _LIBCPP_STD_VER >= 14
17371756 template <class _InputIterator>
17381757 _LIBCPP_HIDE_FROM_ABI multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
17391758 : multimap(__f, __l, key_compare(), __a) {}
1740#endif
1759# endif
17411760
1742#if _LIBCPP_STD_VER >= 23
1761# if _LIBCPP_STD_VER >= 23
17431762 template <_ContainerCompatibleRange<value_type> _Range>
17441763 _LIBCPP_HIDE_FROM_ABI multimap(from_range_t, _Range&& __range, const allocator_type& __a)
17451764 : multimap(from_range, std::forward<_Range>(__range), key_compare(), __a) {}
1746#endif
1765# endif
17471766
17481767 _LIBCPP_HIDE_FROM_ABI multimap(const multimap& __m)
17491768 : __tree_(__m.__tree_.value_comp(),
......@@ -1752,20 +1771,20 @@ public:
17521771 }
17531772
17541773 _LIBCPP_HIDE_FROM_ABI multimap& operator=(const multimap& __m) {
1755#ifndef _LIBCPP_CXX03_LANG
1774# ifndef _LIBCPP_CXX03_LANG
17561775 __tree_ = __m.__tree_;
1757#else
1776# else
17581777 if (this != std::addressof(__m)) {
17591778 __tree_.clear();
17601779 __tree_.value_comp() = __m.__tree_.value_comp();
17611780 __tree_.__copy_assign_alloc(__m.__tree_);
17621781 insert(__m.begin(), __m.end());
17631782 }
1764#endif
1783# endif
17651784 return *this;
17661785 }
17671786
1768#ifndef _LIBCPP_CXX03_LANG
1787# ifndef _LIBCPP_CXX03_LANG
17691788
17701789 _LIBCPP_HIDE_FROM_ABI multimap(multimap&& __m) noexcept(is_nothrow_move_constructible<__base>::value)
17711790 : __tree_(std::move(__m.__tree_)) {}
......@@ -1788,17 +1807,17 @@ public:
17881807 insert(__il.begin(), __il.end());
17891808 }
17901809
1791# if _LIBCPP_STD_VER >= 14
1810# if _LIBCPP_STD_VER >= 14
17921811 _LIBCPP_HIDE_FROM_ABI multimap(initializer_list<value_type> __il, const allocator_type& __a)
17931812 : multimap(__il, key_compare(), __a) {}
1794# endif
1813# endif
17951814
17961815 _LIBCPP_HIDE_FROM_ABI multimap& operator=(initializer_list<value_type> __il) {
17971816 __tree_.__assign_multi(__il.begin(), __il.end());
17981817 return *this;
17991818 }
18001819
1801#endif // _LIBCPP_CXX03_LANG
1820# endif // _LIBCPP_CXX03_LANG
18021821
18031822 _LIBCPP_HIDE_FROM_ABI explicit multimap(const allocator_type& __a) : __tree_(typename __base::allocator_type(__a)) {}
18041823
......@@ -1824,7 +1843,7 @@ public:
18241843 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return rbegin(); }
18251844 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
18261845
1827 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __tree_.size() == 0; }
1846 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __tree_.size() == 0; }
18281847 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __tree_.size(); }
18291848 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __tree_.max_size(); }
18301849
......@@ -1832,7 +1851,7 @@ public:
18321851 _LIBCPP_HIDE_FROM_ABI key_compare key_comp() const { return __tree_.value_comp().key_comp(); }
18331852 _LIBCPP_HIDE_FROM_ABI value_compare value_comp() const { return value_compare(__tree_.value_comp().key_comp()); }
18341853
1835#ifndef _LIBCPP_CXX03_LANG
1854# ifndef _LIBCPP_CXX03_LANG
18361855
18371856 template <class... _Args>
18381857 _LIBCPP_HIDE_FROM_ABI iterator emplace(_Args&&... __args) {
......@@ -1862,7 +1881,7 @@ public:
18621881
18631882 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
18641883
1865#endif // _LIBCPP_CXX03_LANG
1884# endif // _LIBCPP_CXX03_LANG
18661885
18671886 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __v) { return __tree_.__insert_multi(__v); }
18681887
......@@ -1876,7 +1895,7 @@ public:
18761895 __tree_.__insert_multi(__e.__i_, *__f);
18771896 }
18781897
1879#if _LIBCPP_STD_VER >= 23
1898# if _LIBCPP_STD_VER >= 23
18801899 template <_ContainerCompatibleRange<value_type> _Range>
18811900 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
18821901 const_iterator __end = cend();
......@@ -1884,7 +1903,7 @@ public:
18841903 __tree_.__insert_multi(__end.__i_, std::forward<decltype(__element)>(__element));
18851904 }
18861905 }
1887#endif
1906# endif
18881907
18891908 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __tree_.erase(__p.__i_); }
18901909 _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __p) { return __tree_.erase(__p.__i_); }
......@@ -1893,7 +1912,7 @@ public:
18931912 return __tree_.erase(__f.__i_, __l.__i_);
18941913 }
18951914
1896#if _LIBCPP_STD_VER >= 17
1915# if _LIBCPP_STD_VER >= 17
18971916 _LIBCPP_HIDE_FROM_ABI iterator insert(node_type&& __nh) {
18981917 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
18991918 "node_type with incompatible allocator passed to multimap::insert()");
......@@ -1934,7 +1953,7 @@ public:
19341953 __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
19351954 return __tree_.__node_handle_merge_multi(__source.__tree_);
19361955 }
1937#endif
1956# endif
19381957
19391958 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __tree_.clear(); }
19401959
......@@ -1944,7 +1963,7 @@ public:
19441963
19451964 _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __tree_.find(__k); }
19461965 _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __tree_.find(__k); }
1947#if _LIBCPP_STD_VER >= 14
1966# if _LIBCPP_STD_VER >= 14
19481967 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
19491968 _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
19501969 return __tree_.find(__k);
......@@ -1953,27 +1972,27 @@ public:
19531972 _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
19541973 return __tree_.find(__k);
19551974 }
1956#endif
1975# endif
19571976
19581977 _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __tree_.__count_multi(__k); }
1959#if _LIBCPP_STD_VER >= 14
1978# if _LIBCPP_STD_VER >= 14
19601979 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
19611980 _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
19621981 return __tree_.__count_multi(__k);
19631982 }
1964#endif
1983# endif
19651984
1966#if _LIBCPP_STD_VER >= 20
1985# if _LIBCPP_STD_VER >= 20
19671986 _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
19681987 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
19691988 _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
19701989 return find(__k) != end();
19711990 }
1972#endif // _LIBCPP_STD_VER >= 20
1991# endif // _LIBCPP_STD_VER >= 20
19731992
19741993 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __k) { return __tree_.lower_bound(__k); }
19751994 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __k) const { return __tree_.lower_bound(__k); }
1976#if _LIBCPP_STD_VER >= 14
1995# if _LIBCPP_STD_VER >= 14
19771996 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
19781997 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _K2& __k) {
19791998 return __tree_.lower_bound(__k);
......@@ -1983,11 +2002,11 @@ public:
19832002 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _K2& __k) const {
19842003 return __tree_.lower_bound(__k);
19852004 }
1986#endif
2005# endif
19872006
19882007 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __k) { return __tree_.upper_bound(__k); }
19892008 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __k) const { return __tree_.upper_bound(__k); }
1990#if _LIBCPP_STD_VER >= 14
2009# if _LIBCPP_STD_VER >= 14
19912010 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
19922011 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _K2& __k) {
19932012 return __tree_.upper_bound(__k);
......@@ -1996,7 +2015,7 @@ public:
19962015 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _K2& __k) const {
19972016 return __tree_.upper_bound(__k);
19982017 }
1999#endif
2018# endif
20002019
20012020 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
20022021 return __tree_.__equal_range_multi(__k);
......@@ -2004,7 +2023,7 @@ public:
20042023 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
20052024 return __tree_.__equal_range_multi(__k);
20062025 }
2007#if _LIBCPP_STD_VER >= 14
2026# if _LIBCPP_STD_VER >= 14
20082027 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
20092028 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
20102029 return __tree_.__equal_range_multi(__k);
......@@ -2013,7 +2032,7 @@ public:
20132032 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
20142033 return __tree_.__equal_range_multi(__k);
20152034 }
2016#endif
2035# endif
20172036
20182037private:
20192038 typedef typename __base::__node __node;
......@@ -2024,7 +2043,7 @@ private:
20242043 typedef unique_ptr<__node, _Dp> __node_holder;
20252044};
20262045
2027#if _LIBCPP_STD_VER >= 17
2046# if _LIBCPP_STD_VER >= 17
20282047template <class _InputIterator,
20292048 class _Compare = less<__iter_key_type<_InputIterator>>,
20302049 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
......@@ -2034,7 +2053,7 @@ template <class _InputIterator,
20342053multimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
20352054 -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
20362055
2037# if _LIBCPP_STD_VER >= 23
2056# if _LIBCPP_STD_VER >= 23
20382057template <ranges::input_range _Range,
20392058 class _Compare = less<__range_key_type<_Range>>,
20402059 class _Allocator = allocator<__range_to_alloc_type<_Range>>,
......@@ -2042,7 +2061,7 @@ template <ranges::input_range _Range,
20422061 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
20432062multimap(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator())
20442063 -> multimap<__range_key_type<_Range>, __range_mapped_type<_Range>, _Compare, _Allocator>;
2045# endif
2064# endif
20462065
20472066template <class _Key,
20482067 class _Tp,
......@@ -2064,18 +2083,18 @@ multimap(_InputIterator, _InputIterator, _Allocator)
20642083 less<__iter_key_type<_InputIterator>>,
20652084 _Allocator>;
20662085
2067# if _LIBCPP_STD_VER >= 23
2086# if _LIBCPP_STD_VER >= 23
20682087template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
20692088multimap(from_range_t, _Range&&, _Allocator)
20702089 -> multimap<__range_key_type<_Range>, __range_mapped_type<_Range>, less<__range_key_type<_Range>>, _Allocator>;
2071# endif
2090# endif
20722091
20732092template <class _Key, class _Tp, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
20742093multimap(initializer_list<pair<_Key, _Tp>>,
20752094 _Allocator) -> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
2076#endif
2095# endif
20772096
2078#ifndef _LIBCPP_CXX03_LANG
2097# ifndef _LIBCPP_CXX03_LANG
20792098template <class _Key, class _Tp, class _Compare, class _Allocator>
20802099multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
20812100 : __tree_(std::move(__m.__tree_), typename __base::allocator_type(__a)) {
......@@ -2085,7 +2104,7 @@ multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const alloca
20852104 __tree_.__insert_multi(__e.__i_, std::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move()));
20862105 }
20872106}
2088#endif
2107# endif
20892108
20902109template <class _Key, class _Tp, class _Compare, class _Allocator>
20912110inline _LIBCPP_HIDE_FROM_ABI bool
......@@ -2093,7 +2112,7 @@ operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<
20932112 return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
20942113}
20952114
2096#if _LIBCPP_STD_VER <= 17
2115# if _LIBCPP_STD_VER <= 17
20972116
20982117template <class _Key, class _Tp, class _Compare, class _Allocator>
20992118inline _LIBCPP_HIDE_FROM_ABI bool
......@@ -2125,7 +2144,7 @@ operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<
21252144 return !(__y < __x);
21262145}
21272146
2128#else // #if _LIBCPP_STD_VER <= 17
2147# else // #if _LIBCPP_STD_VER <= 17
21292148
21302149template <class _Key, class _Tp, class _Compare, class _Allocator>
21312150_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<pair<const _Key, _Tp>>
......@@ -2134,7 +2153,7 @@ operator<=>(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
21342153 return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), __synth_three_way);
21352154}
21362155
2137#endif // #if _LIBCPP_STD_VER <= 17
2156# endif // #if _LIBCPP_STD_VER <= 17
21382157
21392158template <class _Key, class _Tp, class _Compare, class _Allocator>
21402159inline _LIBCPP_HIDE_FROM_ABI void
......@@ -2143,17 +2162,25 @@ swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x, multimap<_Key, _Tp, _Compar
21432162 __x.swap(__y);
21442163}
21452164
2146#if _LIBCPP_STD_VER >= 20
2165# if _LIBCPP_STD_VER >= 20
21472166template <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate>
21482167inline _LIBCPP_HIDE_FROM_ABI typename multimap<_Key, _Tp, _Compare, _Allocator>::size_type
21492168erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) {
21502169 return std::__libcpp_erase_if_container(__c, __pred);
21512170}
2152#endif
2171# endif
2172
2173template <class _Key, class _Tp, class _Compare, class _Allocator>
2174struct __container_traits<multimap<_Key, _Tp, _Compare, _Allocator> > {
2175 // http://eel.is/c++draft/associative.reqmts.except#2
2176 // For associative containers, if an exception is thrown by any operation from within
2177 // an insert or emplace function inserting a single element, the insertion has no effect.
2178 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
2179};
21532180
21542181_LIBCPP_END_NAMESPACE_STD
21552182
2156#if _LIBCPP_STD_VER >= 17
2183# if _LIBCPP_STD_VER >= 17
21572184_LIBCPP_BEGIN_NAMESPACE_STD
21582185namespace pmr {
21592186template <class _KeyT, class _ValueT, class _CompareT = std::less<_KeyT>>
......@@ -2165,17 +2192,18 @@ using multimap _LIBCPP_AVAILABILITY_PMR =
21652192 std::multimap<_KeyT, _ValueT, _CompareT, polymorphic_allocator<std::pair<const _KeyT, _ValueT>>>;
21662193} // namespace pmr
21672194_LIBCPP_END_NAMESPACE_STD
2168#endif
2195# endif
21692196
21702197_LIBCPP_POP_MACROS
21712198
2172#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
2173# include <concepts>
2174# include <cstdlib>
2175# include <functional>
2176# include <iterator>
2177# include <type_traits>
2178# include <utility>
2179#endif
2199# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
2200# include <concepts>
2201# include <cstdlib>
2202# include <functional>
2203# include <iterator>
2204# include <type_traits>
2205# include <utility>
2206# endif
2207#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
21802208
21812209#endif // _LIBCPP_MAP
lib/libcxx/include/math.h+90-86
......@@ -291,93 +291,96 @@ long double truncl(long double x);
291291
292292*/
293293
294# include <__config>
294# if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
295# include <__cxx03/math.h>
296# else
297# include <__config>
295298
296# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
297# pragma GCC system_header
298# endif
299# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
300# pragma GCC system_header
301# endif
299302
300# if __has_include_next(<math.h>)
301# include_next <math.h>
302# endif
303# if __has_include_next(<math.h>)
304# include_next <math.h>
305# endif
303306
304# ifdef __cplusplus
307# ifdef __cplusplus
305308
306309// We support including .h headers inside 'extern "C"' contexts, so switch
307310// back to C++ linkage before including these C++ headers.
308311extern "C++" {
309312
310# ifdef fpclassify
311# undef fpclassify
312# endif
313
314# ifdef signbit
315# undef signbit
316# endif
317
318# ifdef isfinite
319# undef isfinite
320# endif
321
322# ifdef isinf
323# undef isinf
324# endif
325
326# ifdef isnan
327# undef isnan
328# endif
329
330# ifdef isnormal
331# undef isnormal
332# endif
333
334# ifdef isgreater
335# undef isgreater
336# endif
337
338# ifdef isgreaterequal
339# undef isgreaterequal
340# endif
341
342# ifdef isless
343# undef isless
344# endif
345
346# ifdef islessequal
347# undef islessequal
348# endif
349
350# ifdef islessgreater
351# undef islessgreater
352# endif
353
354# ifdef isunordered
355# undef isunordered
356# endif
357
358# include <__math/abs.h>
359# include <__math/copysign.h>
360# include <__math/error_functions.h>
361# include <__math/exponential_functions.h>
362# include <__math/fdim.h>
363# include <__math/fma.h>
364# include <__math/gamma.h>
365# include <__math/hyperbolic_functions.h>
366# include <__math/hypot.h>
367# include <__math/inverse_hyperbolic_functions.h>
368# include <__math/inverse_trigonometric_functions.h>
369# include <__math/logarithms.h>
370# include <__math/min_max.h>
371# include <__math/modulo.h>
372# include <__math/remainder.h>
373# include <__math/roots.h>
374# include <__math/rounding_functions.h>
375# include <__math/traits.h>
376# include <__math/trigonometric_functions.h>
377# include <__type_traits/enable_if.h>
378# include <__type_traits/is_floating_point.h>
379# include <__type_traits/is_integral.h>
380# include <stdlib.h>
313# ifdef fpclassify
314# undef fpclassify
315# endif
316
317# ifdef signbit
318# undef signbit
319# endif
320
321# ifdef isfinite
322# undef isfinite
323# endif
324
325# ifdef isinf
326# undef isinf
327# endif
328
329# ifdef isnan
330# undef isnan
331# endif
332
333# ifdef isnormal
334# undef isnormal
335# endif
336
337# ifdef isgreater
338# undef isgreater
339# endif
340
341# ifdef isgreaterequal
342# undef isgreaterequal
343# endif
344
345# ifdef isless
346# undef isless
347# endif
348
349# ifdef islessequal
350# undef islessequal
351# endif
352
353# ifdef islessgreater
354# undef islessgreater
355# endif
356
357# ifdef isunordered
358# undef isunordered
359# endif
360
361# include <__math/abs.h>
362# include <__math/copysign.h>
363# include <__math/error_functions.h>
364# include <__math/exponential_functions.h>
365# include <__math/fdim.h>
366# include <__math/fma.h>
367# include <__math/gamma.h>
368# include <__math/hyperbolic_functions.h>
369# include <__math/hypot.h>
370# include <__math/inverse_hyperbolic_functions.h>
371# include <__math/inverse_trigonometric_functions.h>
372# include <__math/logarithms.h>
373# include <__math/min_max.h>
374# include <__math/modulo.h>
375# include <__math/remainder.h>
376# include <__math/roots.h>
377# include <__math/rounding_functions.h>
378# include <__math/traits.h>
379# include <__math/trigonometric_functions.h>
380# include <__type_traits/enable_if.h>
381# include <__type_traits/is_floating_point.h>
382# include <__type_traits/is_integral.h>
383# include <stdlib.h>
381384
382385// fpclassify relies on implementation-defined constants, so we can't move it to a detail header
383386_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -388,22 +391,22 @@ namespace __math {
388391
389392// template on non-double overloads to make them weaker than same overloads from MSVC runtime
390393template <class = int>
391_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI int fpclassify(float __x) _NOEXCEPT {
394[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI int fpclassify(float __x) _NOEXCEPT {
392395 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
393396}
394397
395398template <class = int>
396_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI int fpclassify(double __x) _NOEXCEPT {
399[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI int fpclassify(double __x) _NOEXCEPT {
397400 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
398401}
399402
400403template <class = int>
401_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI int fpclassify(long double __x) _NOEXCEPT {
404[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI int fpclassify(long double __x) _NOEXCEPT {
402405 return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
403406}
404407
405408template <class _A1, std::__enable_if_t<std::is_integral<_A1>::value, int> = 0>
406_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI int fpclassify(_A1 __x) _NOEXCEPT {
409[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI int fpclassify(_A1 __x) _NOEXCEPT {
407410 return __x == 0 ? FP_ZERO : FP_NORMAL;
408411}
409412
......@@ -415,7 +418,7 @@ using std::__math::fpclassify;
415418using std::__math::signbit;
416419
417420// The MSVC runtime already provides these functions as templates
418# ifndef _LIBCPP_MSVCRT
421# ifndef _LIBCPP_MSVCRT
419422using std::__math::isfinite;
420423using std::__math::isgreater;
421424using std::__math::isgreaterequal;
......@@ -426,7 +429,7 @@ using std::__math::islessgreater;
426429using std::__math::isnan;
427430using std::__math::isnormal;
428431using std::__math::isunordered;
429# endif // _LIBCPP_MSVCRT
432# endif // _LIBCPP_MSVCRT
430433
431434// abs
432435//
......@@ -501,7 +504,8 @@ using std::__math::trunc;
501504
502505} // extern "C++"
503506
504# endif // __cplusplus
507# endif // __cplusplus
508# endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
505509
506510#else // _LIBCPP_MATH_H
507511
lib/libcxx/include/mdspan+21-26
......@@ -408,31 +408,26 @@ namespace std {
408408#ifndef _LIBCPP_MDSPAN
409409#define _LIBCPP_MDSPAN
410410
411#include <__config>
412
413#if _LIBCPP_STD_VER >= 23
414# include <__fwd/mdspan.h>
415# include <__mdspan/default_accessor.h>
416# include <__mdspan/extents.h>
417# include <__mdspan/layout_left.h>
418# include <__mdspan/layout_right.h>
419# include <__mdspan/layout_stride.h>
420# include <__mdspan/mdspan.h>
421#endif
422
423#include <version>
424
425#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
426# pragma GCC system_header
427#endif
428
429#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
430# include <array>
431# include <cinttypes>
432# include <concepts>
433# include <cstddef>
434# include <limits>
435# include <span>
436#endif
411#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
412# include <__cxx03/mdspan>
413#else
414# include <__config>
415
416# if _LIBCPP_STD_VER >= 23
417# include <__fwd/mdspan.h>
418# include <__mdspan/default_accessor.h>
419# include <__mdspan/extents.h>
420# include <__mdspan/layout_left.h>
421# include <__mdspan/layout_right.h>
422# include <__mdspan/layout_stride.h>
423# include <__mdspan/mdspan.h>
424# endif
425
426# include <version>
427
428# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
429# pragma GCC system_header
430# endif
431#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
437432
438433#endif // _LIBCPP_MDSPAN
lib/libcxx/include/memory+58-54
......@@ -182,8 +182,8 @@ public:
182182 raw_storage_iterator operator++(int);
183183};
184184
185template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
186template <class T> void return_temporary_buffer(T* p) noexcept;
185template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept; // deprecated in C++17, removed in C++20
186template <class T> void return_temporary_buffer(T* p) noexcept; // deprecated in C++17, removed in C++20
187187
188188template <class T> T* addressof(T& r) noexcept;
189189template <class T> T* addressof(const T&& r) noexcept = delete;
......@@ -934,65 +934,69 @@ template<class Pointer = void, class Smart, class... Args>
934934
935935// clang-format on
936936
937#include <__config>
938#include <__memory/addressof.h>
939#include <__memory/align.h>
940#include <__memory/allocator.h>
941#include <__memory/allocator_arg_t.h>
942#include <__memory/allocator_traits.h>
943#include <__memory/auto_ptr.h>
944#include <__memory/inout_ptr.h>
945#include <__memory/out_ptr.h>
946#include <__memory/pointer_traits.h>
947#include <__memory/raw_storage_iterator.h>
948#include <__memory/shared_ptr.h>
949#include <__memory/temporary_buffer.h>
950#include <__memory/uninitialized_algorithms.h>
951#include <__memory/unique_ptr.h>
952#include <__memory/uses_allocator.h>
937#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
938# include <__cxx03/memory>
939#else
940# include <__config>
941# include <__memory/addressof.h>
942# include <__memory/align.h>
943# include <__memory/allocator.h>
944# include <__memory/allocator_arg_t.h>
945# include <__memory/allocator_traits.h>
946# include <__memory/auto_ptr.h>
947# include <__memory/inout_ptr.h>
948# include <__memory/out_ptr.h>
949# include <__memory/pointer_traits.h>
950# include <__memory/raw_storage_iterator.h>
951# include <__memory/shared_ptr.h>
952# include <__memory/temporary_buffer.h>
953# include <__memory/uninitialized_algorithms.h>
954# include <__memory/unique_ptr.h>
955# include <__memory/uses_allocator.h>
953956
954957// standard-mandated includes
955958
956#if _LIBCPP_STD_VER >= 17
957# include <__memory/construct_at.h>
958#endif
959# if _LIBCPP_STD_VER >= 17
960# include <__memory/construct_at.h>
961# endif
959962
960#if _LIBCPP_STD_VER >= 20
961# include <__memory/assume_aligned.h>
962# include <__memory/concepts.h>
963# include <__memory/ranges_construct_at.h>
964# include <__memory/ranges_uninitialized_algorithms.h>
965# include <__memory/uses_allocator_construction.h>
966#endif
963# if _LIBCPP_STD_VER >= 20
964# include <__memory/assume_aligned.h>
965# include <__memory/concepts.h>
966# include <__memory/ranges_construct_at.h>
967# include <__memory/ranges_uninitialized_algorithms.h>
968# include <__memory/uses_allocator_construction.h>
969# endif
967970
968#if _LIBCPP_STD_VER >= 23
969# include <__memory/allocate_at_least.h>
970#endif
971# if _LIBCPP_STD_VER >= 23
972# include <__memory/allocate_at_least.h>
973# endif
971974
972#include <version>
975# include <version>
973976
974977// [memory.syn]
975#include <compare>
976
977#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
978# pragma GCC system_header
979#endif
980
981#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
982# include <atomic>
983# include <concepts>
984# include <cstddef>
985# include <cstdint>
986# include <cstdlib>
987# include <cstring>
988# include <iosfwd>
989# include <iterator>
990# include <new>
991# include <stdexcept>
992# include <tuple>
993# include <type_traits>
994# include <typeinfo>
995# include <utility>
996#endif
978# include <compare>
979
980# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
981# pragma GCC system_header
982# endif
983
984# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
985# include <atomic>
986# include <concepts>
987# include <cstddef>
988# include <cstdint>
989# include <cstdlib>
990# include <cstring>
991# include <iosfwd>
992# include <iterator>
993# include <new>
994# include <stdexcept>
995# include <tuple>
996# include <type_traits>
997# include <typeinfo>
998# include <utility>
999# endif
1000#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
9971001
9981002#endif // _LIBCPP_MEMORY
lib/libcxx/include/memory_resource+28-30
......@@ -49,35 +49,33 @@ namespace std::pmr {
4949
5050 */
5151
52#include <__config>
53
54#if _LIBCPP_STD_VER >= 17
55# include <__memory_resource/memory_resource.h>
56# include <__memory_resource/monotonic_buffer_resource.h>
57# include <__memory_resource/polymorphic_allocator.h>
58# include <__memory_resource/pool_options.h>
59# include <__memory_resource/synchronized_pool_resource.h>
60# include <__memory_resource/unsynchronized_pool_resource.h>
61#endif
62
63#include <version>
64
65#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
66# pragma GCC system_header
67#endif
68
69#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 14
70# include <cstddef>
71# include <cstdint>
72# include <limits>
73# include <mutex>
74# include <new>
75# include <stdexcept>
76# include <tuple>
77#endif
78
79#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
80# include <stdexcept>
81#endif
52#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
53# include <__cxx03/memory_resource>
54#else
55# include <__config>
56
57# if _LIBCPP_STD_VER >= 17
58# include <__memory_resource/memory_resource.h>
59# include <__memory_resource/monotonic_buffer_resource.h>
60# include <__memory_resource/polymorphic_allocator.h>
61# include <__memory_resource/pool_options.h>
62# include <__memory_resource/synchronized_pool_resource.h>
63# include <__memory_resource/unsynchronized_pool_resource.h>
64# endif
65
66# include <version>
67
68# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
69# pragma GCC system_header
70# endif
71
72# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER >= 17 && _LIBCPP_STD_VER <= 20
73# include <mutex>
74# endif
75
76# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
77# include <stdexcept>
78# endif
79#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
8280
8381#endif /* _LIBCPP_MEMORY_RESOURCE */
lib/libcxx/include/mutex+48-46
......@@ -186,36 +186,37 @@ template<class Callable, class ...Args>
186186
187187*/
188188
189#include <__chrono/steady_clock.h>
190#include <__chrono/time_point.h>
191#include <__condition_variable/condition_variable.h>
192#include <__config>
193#include <__memory/shared_ptr.h>
194#include <__mutex/lock_guard.h>
195#include <__mutex/mutex.h>
196#include <__mutex/once_flag.h>
197#include <__mutex/tag_types.h>
198#include <__mutex/unique_lock.h>
199#include <__thread/id.h>
200#include <__thread/support.h>
201#include <__utility/forward.h>
202#include <cstddef>
203#include <limits>
204#ifndef _LIBCPP_CXX03_LANG
205# include <tuple>
206#endif
207#include <version>
208
209#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
210# pragma GCC system_header
211#endif
189#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
190# include <__cxx03/mutex>
191#else
192# include <__chrono/steady_clock.h>
193# include <__chrono/time_point.h>
194# include <__condition_variable/condition_variable.h>
195# include <__config>
196# include <__mutex/lock_guard.h>
197# include <__mutex/mutex.h>
198# include <__mutex/once_flag.h>
199# include <__mutex/tag_types.h>
200# include <__mutex/unique_lock.h>
201# include <__thread/id.h>
202# include <__thread/support.h>
203# include <__utility/forward.h>
204# include <limits>
205# ifndef _LIBCPP_CXX03_LANG
206# include <tuple>
207# endif
208# include <version>
209
210# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
211# pragma GCC system_header
212# endif
212213
213214_LIBCPP_PUSH_MACROS
214#include <__undef_macros>
215# include <__undef_macros>
215216
216217_LIBCPP_BEGIN_NAMESPACE_STD
217218
218#ifndef _LIBCPP_HAS_NO_THREADS
219# if _LIBCPP_HAS_THREADS
219220
220221class _LIBCPP_EXPORTED_FROM_ABI recursive_mutex {
221222 __libcpp_recursive_mutex_t __m_;
......@@ -335,7 +336,7 @@ _LIBCPP_HIDE_FROM_ABI int try_lock(_L0& __l0, _L1& __l1) {
335336 return 0;
336337}
337338
338# ifndef _LIBCPP_CXX03_LANG
339# ifndef _LIBCPP_CXX03_LANG
339340
340341template <class _L0, class _L1, class _L2, class... _L3>
341342_LIBCPP_HIDE_FROM_ABI int try_lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3) {
......@@ -351,7 +352,7 @@ _LIBCPP_HIDE_FROM_ABI int try_lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3
351352 return __r;
352353}
353354
354# endif // _LIBCPP_CXX03_LANG
355# endif // _LIBCPP_CXX03_LANG
355356
356357template <class _L0, class _L1>
357358_LIBCPP_HIDE_FROM_ABI void lock(_L0& __l0, _L1& __l1) {
......@@ -375,7 +376,7 @@ _LIBCPP_HIDE_FROM_ABI void lock(_L0& __l0, _L1& __l1) {
375376 }
376377}
377378
378# ifndef _LIBCPP_CXX03_LANG
379# ifndef _LIBCPP_CXX03_LANG
379380
380381template <class _L0, class _L1, class _L2, class... _L3>
381382void __lock_first(int __i, _L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3) {
......@@ -418,9 +419,9 @@ inline _LIBCPP_HIDE_FROM_ABI void lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&...
418419 std::__lock_first(0, __l0, __l1, __l2, __l3...);
419420}
420421
421# endif // _LIBCPP_CXX03_LANG
422# endif // _LIBCPP_CXX03_LANG
422423
423# if _LIBCPP_STD_VER >= 17
424# if _LIBCPP_STD_VER >= 17
424425template <class... _Mutexes>
425426class _LIBCPP_TEMPLATE_VIS scoped_lock;
426427
......@@ -491,26 +492,27 @@ private:
491492};
492493_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(scoped_lock);
493494
494# endif // _LIBCPP_STD_VER >= 17
495#endif // !_LIBCPP_HAS_NO_THREADS
495# endif // _LIBCPP_STD_VER >= 17
496# endif // _LIBCPP_HAS_THREADS
496497
497498_LIBCPP_END_NAMESPACE_STD
498499
499500_LIBCPP_POP_MACROS
500501
501#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
502# include <atomic>
503# include <concepts>
504# include <cstdlib>
505# include <cstring>
506# include <ctime>
507# include <initializer_list>
508# include <iosfwd>
509# include <new>
510# include <stdexcept>
511# include <system_error>
512# include <type_traits>
513# include <typeinfo>
514#endif
502# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
503# include <atomic>
504# include <concepts>
505# include <cstdlib>
506# include <cstring>
507# include <ctime>
508# include <initializer_list>
509# include <iosfwd>
510# include <new>
511# include <stdexcept>
512# include <system_error>
513# include <type_traits>
514# include <typeinfo>
515# endif
516#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
515517
516518#endif // _LIBCPP_MUTEX
lib/libcxx/include/new+28-266
......@@ -79,284 +79,46 @@ void operator delete[](void* ptr, const std::nothrow_t&) noexcept; // repla
7979void operator delete[](void* ptr, std::align_val_t alignment,
8080 const std::nothrow_t&) noexcept; // replaceable, C++17
8181
82void* operator new (std::size_t size, void* ptr) noexcept; // nodiscard in C++20
83void* operator new[](std::size_t size, void* ptr) noexcept; // nodiscard in C++20
82void* operator new (std::size_t size, void* ptr) noexcept; // nodiscard in C++20, constexpr since C++26
83void* operator new[](std::size_t size, void* ptr) noexcept; // nodiscard in C++20, constexpr since C++26
8484void operator delete (void* ptr, void*) noexcept;
8585void operator delete[](void* ptr, void*) noexcept;
8686
8787*/
8888
89#include <__config>
90#include <__exception/exception.h>
91#include <__type_traits/is_function.h>
92#include <__type_traits/is_same.h>
93#include <__type_traits/remove_cv.h>
94#include <__verbose_abort>
95#include <cstddef>
96#include <version>
97
98#if defined(_LIBCPP_ABI_VCRUNTIME)
99# include <new.h>
100#endif
101
102#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
103# pragma GCC system_header
104#endif
105
106#if !defined(__cpp_sized_deallocation) || __cpp_sized_deallocation < 201309L
107# define _LIBCPP_HAS_NO_LANGUAGE_SIZED_DEALLOCATION
108#endif
109
110#if !defined(_LIBCPP_BUILDING_LIBRARY) && _LIBCPP_STD_VER < 14 && defined(_LIBCPP_HAS_NO_LANGUAGE_SIZED_DEALLOCATION)
111# define _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION
112#endif
113
114#if defined(_LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION) || defined(_LIBCPP_HAS_NO_LANGUAGE_SIZED_DEALLOCATION)
115# define _LIBCPP_HAS_NO_SIZED_DEALLOCATION
116#endif
117
118namespace std // purposefully not using versioning namespace
119{
120
121#if !defined(_LIBCPP_ABI_VCRUNTIME)
122struct _LIBCPP_EXPORTED_FROM_ABI nothrow_t {
123 explicit nothrow_t() = default;
124};
125extern _LIBCPP_EXPORTED_FROM_ABI const nothrow_t nothrow;
126
127class _LIBCPP_EXPORTED_FROM_ABI bad_alloc : public exception {
128public:
129 bad_alloc() _NOEXCEPT;
130 _LIBCPP_HIDE_FROM_ABI bad_alloc(const bad_alloc&) _NOEXCEPT = default;
131 _LIBCPP_HIDE_FROM_ABI bad_alloc& operator=(const bad_alloc&) _NOEXCEPT = default;
132 ~bad_alloc() _NOEXCEPT override;
133 const char* what() const _NOEXCEPT override;
134};
135
136class _LIBCPP_EXPORTED_FROM_ABI bad_array_new_length : public bad_alloc {
137public:
138 bad_array_new_length() _NOEXCEPT;
139 _LIBCPP_HIDE_FROM_ABI bad_array_new_length(const bad_array_new_length&) _NOEXCEPT = default;
140 _LIBCPP_HIDE_FROM_ABI bad_array_new_length& operator=(const bad_array_new_length&) _NOEXCEPT = default;
141 ~bad_array_new_length() _NOEXCEPT override;
142 const char* what() const _NOEXCEPT override;
143};
144
145typedef void (*new_handler)();
146_LIBCPP_EXPORTED_FROM_ABI new_handler set_new_handler(new_handler) _NOEXCEPT;
147_LIBCPP_EXPORTED_FROM_ABI new_handler get_new_handler() _NOEXCEPT;
148
149#elif defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0 // !_LIBCPP_ABI_VCRUNTIME
150
151// When _HAS_EXCEPTIONS == 0, these complete definitions are needed,
152// since they would normally be provided in vcruntime_exception.h
153class bad_alloc : public exception {
154public:
155 bad_alloc() noexcept : exception("bad allocation") {}
156
157private:
158 friend class bad_array_new_length;
159
160 bad_alloc(char const* const __message) noexcept : exception(__message) {}
161};
162
163class bad_array_new_length : public bad_alloc {
164public:
165 bad_array_new_length() noexcept : bad_alloc("bad array new length") {}
166};
167#endif // defined(_LIBCPP_ABI_VCRUNTIME) && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0
168
169_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_bad_alloc(); // not in C++ spec
170
171_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_array_new_length() {
172#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
173 throw bad_array_new_length();
174#else
175 _LIBCPP_VERBOSE_ABORT("bad_array_new_length was thrown in -fno-exceptions mode");
176#endif
177}
178
179#if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) && !defined(_LIBCPP_ABI_VCRUNTIME)
180# ifndef _LIBCPP_CXX03_LANG
181enum class align_val_t : size_t {};
182# else
183enum align_val_t { __zero = 0, __max = (size_t)-1 };
184# endif
185#endif
186
187#if _LIBCPP_STD_VER >= 20
188// Enable the declaration even if the compiler doesn't support the language
189// feature.
190struct destroying_delete_t {
191 explicit destroying_delete_t() = default;
192};
193inline constexpr destroying_delete_t destroying_delete{};
194#endif // _LIBCPP_STD_VER >= 20
195
196} // namespace std
197
198#if defined(_LIBCPP_CXX03_LANG)
199# define _THROW_BAD_ALLOC throw(std::bad_alloc)
89#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
90# include <__cxx03/new>
20091#else
201# define _THROW_BAD_ALLOC
202#endif
203
204#if !defined(_LIBCPP_ABI_VCRUNTIME)
205
206_LIBCPP_NODISCARD _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC;
207_LIBCPP_NODISCARD _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT
208 _LIBCPP_NOALIAS;
209_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT;
210_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
211# ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION
212_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
92# include <__config>
93# include <__new/align_val_t.h>
94# include <__new/allocate.h>
95# include <__new/exceptions.h>
96# include <__new/global_new_delete.h>
97# include <__new/new_handler.h>
98# include <__new/nothrow_t.h>
99# include <__new/placement_new_delete.h>
100
101# if _LIBCPP_STD_VER >= 17
102# include <__new/interference_size.h>
103# include <__new/launder.h>
213104# endif
214105
215_LIBCPP_NODISCARD _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC;
216_LIBCPP_NODISCARD _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT
217 _LIBCPP_NOALIAS;
218_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT;
219_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
220# ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION
221_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
106# if _LIBCPP_STD_VER >= 20
107# include <__new/destroying_delete_t.h>
222108# endif
223109
224# ifndef _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
225_LIBCPP_NODISCARD _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
226_LIBCPP_NODISCARD _LIBCPP_OVERRIDABLE_FUNC_VIS void*
227operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
228_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT;
229_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
230# ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION
231_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
232# endif
110// feature-test macros
111# include <version>
233112
234_LIBCPP_NODISCARD _LIBCPP_OVERRIDABLE_FUNC_VIS void*
235operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
236_LIBCPP_NODISCARD _LIBCPP_OVERRIDABLE_FUNC_VIS void*
237operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
238_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT;
239_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
240# ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION
241_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
242# endif
113# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
114# pragma GCC system_header
243115# endif
244116
245_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI void* operator new(std::size_t, void* __p) _NOEXCEPT { return __p; }
246_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI void* operator new[](std::size_t, void* __p) _NOEXCEPT { return __p; }
247inline _LIBCPP_HIDE_FROM_ABI void operator delete(void*, void*) _NOEXCEPT {}
248inline _LIBCPP_HIDE_FROM_ABI void operator delete[](void*, void*) _NOEXCEPT {}
249
250#endif // !_LIBCPP_ABI_VCRUNTIME
251
252_LIBCPP_BEGIN_NAMESPACE_STD
253
254_LIBCPP_CONSTEXPR inline _LIBCPP_HIDE_FROM_ABI bool __is_overaligned_for_new(size_t __align) _NOEXCEPT {
255#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
256 return __align > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
257#else
258 return __align > _LIBCPP_ALIGNOF(max_align_t);
259#endif
260}
261
262template <class... _Args>
263_LIBCPP_HIDE_FROM_ABI void* __libcpp_operator_new(_Args... __args) {
264#if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
265 return __builtin_operator_new(__args...);
266#else
267 return ::operator new(__args...);
268#endif
269}
270
271template <class... _Args>
272_LIBCPP_HIDE_FROM_ABI void __libcpp_operator_delete(_Args... __args) {
273#if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
274 __builtin_operator_delete(__args...);
275#else
276 ::operator delete(__args...);
277#endif
278}
279
280inline _LIBCPP_HIDE_FROM_ABI void* __libcpp_allocate(size_t __size, size_t __align) {
281#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
282 if (__is_overaligned_for_new(__align)) {
283 const align_val_t __align_val = static_cast<align_val_t>(__align);
284 return __libcpp_operator_new(__size, __align_val);
285 }
286#endif
287
288 (void)__align;
289 return __libcpp_operator_new(__size);
290}
291
292template <class... _Args>
293_LIBCPP_HIDE_FROM_ABI void __do_deallocate_handle_size(void* __ptr, size_t __size, _Args... __args) {
294#ifdef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
295 (void)__size;
296 return std::__libcpp_operator_delete(__ptr, __args...);
297#else
298 return std::__libcpp_operator_delete(__ptr, __size, __args...);
299#endif
300}
301
302inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate(void* __ptr, size_t __size, size_t __align) {
303#if defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
304 (void)__align;
305 return __do_deallocate_handle_size(__ptr, __size);
306#else
307 if (__is_overaligned_for_new(__align)) {
308 const align_val_t __align_val = static_cast<align_val_t>(__align);
309 return __do_deallocate_handle_size(__ptr, __size, __align_val);
310 } else {
311 return __do_deallocate_handle_size(__ptr, __size);
312 }
313#endif
314}
315
316inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate_unsized(void* __ptr, size_t __align) {
317#if defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
318 (void)__align;
319 return __libcpp_operator_delete(__ptr);
320#else
321 if (__is_overaligned_for_new(__align)) {
322 const align_val_t __align_val = static_cast<align_val_t>(__align);
323 return __libcpp_operator_delete(__ptr, __align_val);
324 } else {
325 return __libcpp_operator_delete(__ptr);
326 }
327#endif
328}
329
330template <class _Tp>
331_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT {
332 static_assert(!(is_function<_Tp>::value), "can't launder functions");
333 static_assert(!(is_same<void, __remove_cv_t<_Tp> >::value), "can't launder cv-void");
334 return __builtin_launder(__p);
335}
336
337#if _LIBCPP_STD_VER >= 17
338template <class _Tp>
339[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp* launder(_Tp* __p) noexcept {
340 return std::__launder(__p);
341}
342#endif
343
344#if _LIBCPP_STD_VER >= 17
345
346# if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
347
348inline constexpr size_t hardware_destructive_interference_size = __GCC_DESTRUCTIVE_SIZE;
349inline constexpr size_t hardware_constructive_interference_size = __GCC_CONSTRUCTIVE_SIZE;
350
351# endif // defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
352
353#endif // _LIBCPP_STD_VER >= 17
354
355_LIBCPP_END_NAMESPACE_STD
356
357#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
358# include <cstdlib>
359# include <type_traits>
360#endif
117# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
118# include <cstddef>
119# include <cstdlib>
120# include <type_traits>
121# endif
122#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
361123
362124#endif // _LIBCPP_NEW
lib/libcxx/include/numbers+17-12
......@@ -58,15 +58,18 @@ namespace std::numbers {
5858}
5959*/
6060
61#include <__concepts/arithmetic.h>
62#include <__config>
63#include <version>
61#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
62# include <__cxx03/numbers>
63#else
64# include <__concepts/arithmetic.h>
65# include <__config>
66# include <version>
6467
65#if _LIBCPP_STD_VER >= 20
68# if _LIBCPP_STD_VER >= 20
6669
67# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
68# pragma GCC system_header
69# endif
70# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
71# pragma GCC system_header
72# endif
7073
7174_LIBCPP_BEGIN_NAMESPACE_STD
7275
......@@ -154,11 +157,13 @@ inline constexpr double phi = phi_v<double>;
154157
155158_LIBCPP_END_NAMESPACE_STD
156159
157#endif // _LIBCPP_STD_VER >= 20
160# endif // _LIBCPP_STD_VER >= 20
158161
159#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
160# include <concepts>
161# include <type_traits>
162#endif
162# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
163# include <concepts>
164# include <cstddef>
165# include <type_traits>
166# endif
167#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
163168
164169#endif // _LIBCPP_NUMBERS
lib/libcxx/include/numeric+51-47
......@@ -156,52 +156,56 @@ constexpr T saturate_cast(U x) noexcept; // freestanding, Sin
156156
157157*/
158158
159#include <__config>
160
161#include <__numeric/accumulate.h>
162#include <__numeric/adjacent_difference.h>
163#include <__numeric/inner_product.h>
164#include <__numeric/iota.h>
165#include <__numeric/partial_sum.h>
166
167#if _LIBCPP_STD_VER >= 17
168# include <__numeric/exclusive_scan.h>
169# include <__numeric/gcd_lcm.h>
170# include <__numeric/inclusive_scan.h>
171# include <__numeric/pstl.h>
172# include <__numeric/reduce.h>
173# include <__numeric/transform_exclusive_scan.h>
174# include <__numeric/transform_inclusive_scan.h>
175# include <__numeric/transform_reduce.h>
176#endif
177
178#if _LIBCPP_STD_VER >= 20
179# include <__numeric/midpoint.h>
180# include <__numeric/saturation_arithmetic.h>
181#endif
182
183#include <version>
184
185#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
186# pragma GCC system_header
187#endif
188
189#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 14
190# include <initializer_list>
191# include <limits>
192#endif
193
194#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
195# include <climits>
196# include <cmath>
197# include <concepts>
198# include <cstdint>
199# include <execution>
200# include <functional>
201# include <iterator>
202# include <new>
203# include <optional>
204# include <type_traits>
205#endif
159#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
160# include <__cxx03/numeric>
161#else
162# include <__config>
163
164# include <__numeric/accumulate.h>
165# include <__numeric/adjacent_difference.h>
166# include <__numeric/inner_product.h>
167# include <__numeric/iota.h>
168# include <__numeric/partial_sum.h>
169
170# if _LIBCPP_STD_VER >= 17
171# include <__numeric/exclusive_scan.h>
172# include <__numeric/gcd_lcm.h>
173# include <__numeric/inclusive_scan.h>
174# include <__numeric/pstl.h>
175# include <__numeric/reduce.h>
176# include <__numeric/transform_exclusive_scan.h>
177# include <__numeric/transform_inclusive_scan.h>
178# include <__numeric/transform_reduce.h>
179# endif
180
181# if _LIBCPP_STD_VER >= 20
182# include <__numeric/midpoint.h>
183# include <__numeric/saturation_arithmetic.h>
184# endif
185
186# include <version>
187
188# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
189# pragma GCC system_header
190# endif
191
192# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 14
193# include <initializer_list>
194# include <limits>
195# endif
196
197# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
198# include <climits>
199# include <cmath>
200# include <concepts>
201# include <cstdint>
202# include <execution>
203# include <functional>
204# include <iterator>
205# include <new>
206# include <optional>
207# include <type_traits>
208# endif
209#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
206210
207211#endif // _LIBCPP_NUMERIC
lib/libcxx/include/optional+119-110
......@@ -177,64 +177,71 @@ namespace std {
177177
178178*/
179179
180#include <__assert>
181#include <__compare/compare_three_way_result.h>
182#include <__compare/three_way_comparable.h>
183#include <__concepts/invocable.h>
184#include <__config>
185#include <__exception/exception.h>
186#include <__functional/hash.h>
187#include <__functional/invoke.h>
188#include <__functional/unary_function.h>
189#include <__fwd/functional.h>
190#include <__memory/addressof.h>
191#include <__memory/construct_at.h>
192#include <__tuple/sfinae_helpers.h>
193#include <__type_traits/add_pointer.h>
194#include <__type_traits/conditional.h>
195#include <__type_traits/conjunction.h>
196#include <__type_traits/decay.h>
197#include <__type_traits/disjunction.h>
198#include <__type_traits/is_array.h>
199#include <__type_traits/is_assignable.h>
200#include <__type_traits/is_constructible.h>
201#include <__type_traits/is_convertible.h>
202#include <__type_traits/is_destructible.h>
203#include <__type_traits/is_nothrow_assignable.h>
204#include <__type_traits/is_nothrow_constructible.h>
205#include <__type_traits/is_object.h>
206#include <__type_traits/is_reference.h>
207#include <__type_traits/is_scalar.h>
208#include <__type_traits/is_swappable.h>
209#include <__type_traits/is_trivially_assignable.h>
210#include <__type_traits/is_trivially_constructible.h>
211#include <__type_traits/is_trivially_destructible.h>
212#include <__type_traits/is_trivially_relocatable.h>
213#include <__type_traits/negation.h>
214#include <__type_traits/remove_const.h>
215#include <__type_traits/remove_cvref.h>
216#include <__type_traits/remove_reference.h>
217#include <__utility/declval.h>
218#include <__utility/forward.h>
219#include <__utility/in_place.h>
220#include <__utility/move.h>
221#include <__utility/swap.h>
222#include <__verbose_abort>
223#include <initializer_list>
224#include <new>
225#include <version>
180#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
181# include <__cxx03/optional>
182#else
183# include <__assert>
184# include <__compare/compare_three_way_result.h>
185# include <__compare/ordering.h>
186# include <__compare/three_way_comparable.h>
187# include <__concepts/invocable.h>
188# include <__config>
189# include <__exception/exception.h>
190# include <__functional/hash.h>
191# include <__functional/invoke.h>
192# include <__functional/unary_function.h>
193# include <__fwd/functional.h>
194# include <__memory/addressof.h>
195# include <__memory/construct_at.h>
196# include <__tuple/sfinae_helpers.h>
197# include <__type_traits/add_pointer.h>
198# include <__type_traits/conditional.h>
199# include <__type_traits/conjunction.h>
200# include <__type_traits/decay.h>
201# include <__type_traits/disjunction.h>
202# include <__type_traits/enable_if.h>
203# include <__type_traits/invoke.h>
204# include <__type_traits/is_array.h>
205# include <__type_traits/is_assignable.h>
206# include <__type_traits/is_constructible.h>
207# include <__type_traits/is_convertible.h>
208# include <__type_traits/is_destructible.h>
209# include <__type_traits/is_nothrow_assignable.h>
210# include <__type_traits/is_nothrow_constructible.h>
211# include <__type_traits/is_object.h>
212# include <__type_traits/is_reference.h>
213# include <__type_traits/is_same.h>
214# include <__type_traits/is_scalar.h>
215# include <__type_traits/is_swappable.h>
216# include <__type_traits/is_trivially_assignable.h>
217# include <__type_traits/is_trivially_constructible.h>
218# include <__type_traits/is_trivially_destructible.h>
219# include <__type_traits/is_trivially_relocatable.h>
220# include <__type_traits/negation.h>
221# include <__type_traits/remove_const.h>
222# include <__type_traits/remove_cv.h>
223# include <__type_traits/remove_cvref.h>
224# include <__type_traits/remove_reference.h>
225# include <__utility/declval.h>
226# include <__utility/forward.h>
227# include <__utility/in_place.h>
228# include <__utility/move.h>
229# include <__utility/swap.h>
230# include <__verbose_abort>
231# include <initializer_list>
232# include <version>
226233
227234// standard-mandated includes
228235
229236// [optional.syn]
230#include <compare>
237# include <compare>
231238
232#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
233# pragma GCC system_header
234#endif
239# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
240# pragma GCC system_header
241# endif
235242
236243_LIBCPP_PUSH_MACROS
237#include <__undef_macros>
244# include <__undef_macros>
238245
239246namespace std // purposefully not using versioning namespace
240247{
......@@ -251,17 +258,17 @@ public:
251258
252259} // namespace std
253260
254#if _LIBCPP_STD_VER >= 17
261# if _LIBCPP_STD_VER >= 17
255262
256263_LIBCPP_BEGIN_NAMESPACE_STD
257264
258_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS void
265[[noreturn]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS void
259266__throw_bad_optional_access() {
260# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
267# if _LIBCPP_HAS_EXCEPTIONS
261268 throw bad_optional_access();
262# else
269# else
263270 _LIBCPP_VERBOSE_ABORT("bad_optional_access was thrown in -fno-exceptions mode");
264# endif
271# endif
265272}
266273
267274struct nullopt_t {
......@@ -284,7 +291,7 @@ struct __optional_destruct_base<_Tp, false> {
284291 static_assert(is_object_v<value_type>, "instantiation of optional with a non-object type is undefined behavior");
285292 union {
286293 char __null_state_;
287 value_type __val_;
294 remove_cv_t<value_type> __val_;
288295 };
289296 bool __engaged_;
290297
......@@ -299,12 +306,12 @@ struct __optional_destruct_base<_Tp, false> {
299306 _LIBCPP_HIDE_FROM_ABI constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args)
300307 : __val_(std::forward<_Args>(__args)...), __engaged_(true) {}
301308
302# if _LIBCPP_STD_VER >= 23
309# if _LIBCPP_STD_VER >= 23
303310 template <class _Fp, class... _Args>
304311 _LIBCPP_HIDE_FROM_ABI constexpr explicit __optional_destruct_base(
305312 __optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args)
306313 : __val_(std::invoke(std::forward<_Fp>(__f), std::forward<_Args>(__args)...)), __engaged_(true) {}
307# endif
314# endif
308315
309316 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void reset() noexcept {
310317 if (__engaged_) {
......@@ -320,7 +327,7 @@ struct __optional_destruct_base<_Tp, true> {
320327 static_assert(is_object_v<value_type>, "instantiation of optional with a non-object type is undefined behavior");
321328 union {
322329 char __null_state_;
323 value_type __val_;
330 remove_cv_t<value_type> __val_;
324331 };
325332 bool __engaged_;
326333
......@@ -330,12 +337,12 @@ struct __optional_destruct_base<_Tp, true> {
330337 _LIBCPP_HIDE_FROM_ABI constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args)
331338 : __val_(std::forward<_Args>(__args)...), __engaged_(true) {}
332339
333# if _LIBCPP_STD_VER >= 23
340# if _LIBCPP_STD_VER >= 23
334341 template <class _Fp, class... _Args>
335342 _LIBCPP_HIDE_FROM_ABI constexpr __optional_destruct_base(
336343 __optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args)
337344 : __val_(std::invoke(std::forward<_Fp>(__f), std::forward<_Args>(__args)...)), __engaged_(true) {}
338# endif
345# endif
339346
340347 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void reset() noexcept {
341348 if (__engaged_) {
......@@ -346,8 +353,8 @@ struct __optional_destruct_base<_Tp, true> {
346353
347354template <class _Tp, bool = is_reference<_Tp>::value>
348355struct __optional_storage_base : __optional_destruct_base<_Tp> {
349 using __base = __optional_destruct_base<_Tp>;
350 using value_type = _Tp;
356 using __base _LIBCPP_NODEBUG = __optional_destruct_base<_Tp>;
357 using value_type = _Tp;
351358 using __base::__base;
352359
353360 _LIBCPP_HIDE_FROM_ABI constexpr bool has_value() const noexcept { return this->__engaged_; }
......@@ -374,7 +381,7 @@ struct __optional_storage_base : __optional_destruct_base<_Tp> {
374381 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __assign_from(_That&& __opt) {
375382 if (this->__engaged_ == __opt.has_value()) {
376383 if (this->__engaged_)
377 this->__val_ = std::forward<_That>(__opt).__get();
384 static_cast<_Tp&>(this->__val_) = std::forward<_That>(__opt).__get();
378385 } else {
379386 if (this->__engaged_)
380387 this->reset();
......@@ -389,8 +396,8 @@ struct __optional_storage_base : __optional_destruct_base<_Tp> {
389396// to ensure we can make the change in an ABI-compatible manner.
390397template <class _Tp>
391398struct __optional_storage_base<_Tp, true> {
392 using value_type = _Tp;
393 using __raw_type = remove_reference_t<_Tp>;
399 using value_type = _Tp;
400 using __raw_type _LIBCPP_NODEBUG = remove_reference_t<_Tp>;
394401 __raw_type* __value_;
395402
396403 template <class _Up>
......@@ -548,23 +555,23 @@ struct __optional_move_assign_base<_Tp, false> : __optional_copy_assign_base<_Tp
548555};
549556
550557template <class _Tp>
551using __optional_sfinae_ctor_base_t =
558using __optional_sfinae_ctor_base_t _LIBCPP_NODEBUG =
552559 __sfinae_ctor_base< is_copy_constructible<_Tp>::value, is_move_constructible<_Tp>::value >;
553560
554561template <class _Tp>
555using __optional_sfinae_assign_base_t =
562using __optional_sfinae_assign_base_t _LIBCPP_NODEBUG =
556563 __sfinae_assign_base< (is_copy_constructible<_Tp>::value && is_copy_assignable<_Tp>::value),
557564 (is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value) >;
558565
559566template <class _Tp>
560567class optional;
561568
562# if _LIBCPP_STD_VER >= 20
569# if _LIBCPP_STD_VER >= 20
563570
564571template <class _Tp>
565572concept __is_derived_from_optional = requires(const _Tp& __t) { []<class _Up>(const optional<_Up>&) {}(__t); };
566573
567# endif // _LIBCPP_STD_VER >= 20
574# endif // _LIBCPP_STD_VER >= 20
568575
569576template <class _Tp>
570577struct __is_std_optional : false_type {};
......@@ -576,12 +583,13 @@ class _LIBCPP_DECLSPEC_EMPTY_BASES optional
576583 : private __optional_move_assign_base<_Tp>,
577584 private __optional_sfinae_ctor_base_t<_Tp>,
578585 private __optional_sfinae_assign_base_t<_Tp> {
579 using __base = __optional_move_assign_base<_Tp>;
586 using __base _LIBCPP_NODEBUG = __optional_move_assign_base<_Tp>;
580587
581588public:
582589 using value_type = _Tp;
583590
584 using __trivially_relocatable = conditional_t<__libcpp_is_trivially_relocatable<_Tp>::value, optional, void>;
591 using __trivially_relocatable _LIBCPP_NODEBUG =
592 conditional_t<__libcpp_is_trivially_relocatable<_Tp>::value, optional, void>;
585593
586594private:
587595 // Disable the reference extension using this static assert.
......@@ -606,7 +614,7 @@ private:
606614 }
607615 };
608616 template <class _Up>
609 using _CheckOptionalArgsCtor =
617 using _CheckOptionalArgsCtor _LIBCPP_NODEBUG =
610618 _If< _IsNotSame<__remove_cvref_t<_Up>, in_place_t>::value && _IsNotSame<__remove_cvref_t<_Up>, optional>::value &&
611619 (!is_same_v<remove_cv_t<_Tp>, bool> || !__is_std_optional<__remove_cvref_t<_Up>>::value),
612620 _CheckOptionalArgsConstructor,
......@@ -614,7 +622,7 @@ private:
614622 template <class _QualUp>
615623 struct _CheckOptionalLikeConstructor {
616624 template <class _Up, class _Opt = optional<_Up>>
617 using __check_constructible_from_opt =
625 using __check_constructible_from_opt _LIBCPP_NODEBUG =
618626 _Or< is_constructible<_Tp, _Opt&>,
619627 is_constructible<_Tp, _Opt const&>,
620628 is_constructible<_Tp, _Opt&&>,
......@@ -624,7 +632,7 @@ private:
624632 is_convertible<_Opt&&, _Tp>,
625633 is_convertible<_Opt const&&, _Tp> >;
626634 template <class _Up, class _Opt = optional<_Up>>
627 using __check_assignable_from_opt =
635 using __check_assignable_from_opt _LIBCPP_NODEBUG =
628636 _Or< is_assignable<_Tp&, _Opt&>,
629637 is_assignable<_Tp&, _Opt const&>,
630638 is_assignable<_Tp&, _Opt&&>,
......@@ -648,12 +656,12 @@ private:
648656 };
649657
650658 template <class _Up, class _QualUp>
651 using _CheckOptionalLikeCtor =
659 using _CheckOptionalLikeCtor _LIBCPP_NODEBUG =
652660 _If< _And< _IsNotSame<_Up, _Tp>, is_constructible<_Tp, _QualUp> >::value,
653661 _CheckOptionalLikeConstructor<_QualUp>,
654662 __check_tuple_constructor_fail >;
655663 template <class _Up, class _QualUp>
656 using _CheckOptionalLikeAssign =
664 using _CheckOptionalLikeAssign _LIBCPP_NODEBUG =
657665 _If< _And< _IsNotSame<_Up, _Tp>, is_constructible<_Tp, _QualUp>, is_assignable<_Tp&, _QualUp> >::value,
658666 _CheckOptionalLikeConstructor<_QualUp>,
659667 __check_tuple_constructor_fail >;
......@@ -706,14 +714,14 @@ public:
706714 this->__construct_from(std::move(__v));
707715 }
708716
709# if _LIBCPP_STD_VER >= 23
717# if _LIBCPP_STD_VER >= 23
710718 template <class _Tag,
711719 class _Fp,
712720 class... _Args,
713721 __enable_if_t<_IsSame<_Tag, __optional_construct_from_invoke_tag>::value, int> = 0>
714722 _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_Tag, _Fp&& __f, _Args&&... __args)
715723 : __base(__optional_construct_from_invoke_tag{}, std::forward<_Fp>(__f), std::forward<_Args>(__args)...) {}
716# endif
724# endif
717725
718726 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(nullopt_t) noexcept {
719727 reset();
......@@ -859,7 +867,7 @@ public:
859867 return this->has_value() ? std::move(this->__get()) : static_cast<value_type>(std::forward<_Up>(__v));
860868 }
861869
862# if _LIBCPP_STD_VER >= 23
870# if _LIBCPP_STD_VER >= 23
863871 template <class _Func>
864872 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto and_then(_Func&& __f) & {
865873 using _Up = invoke_result_t<_Func, value_type&>;
......@@ -969,15 +977,15 @@ public:
969977 return std::move(*this);
970978 return std::forward<_Func>(__f)();
971979 }
972# endif // _LIBCPP_STD_VER >= 23
980# endif // _LIBCPP_STD_VER >= 23
973981
974982 using __base::reset;
975983};
976984
977# if _LIBCPP_STD_VER >= 17
985# if _LIBCPP_STD_VER >= 17
978986template <class _Tp>
979987optional(_Tp) -> optional<_Tp>;
980# endif
988# endif
981989
982990// Comparisons between optionals
983991template <class _Tp, class _Up>
......@@ -1052,7 +1060,7 @@ operator>=(const optional<_Tp>& __x, const optional<_Up>& __y) {
10521060 return *__x >= *__y;
10531061}
10541062
1055# if _LIBCPP_STD_VER >= 20
1063# if _LIBCPP_STD_VER >= 20
10561064
10571065template <class _Tp, three_way_comparable_with<_Tp> _Up>
10581066_LIBCPP_HIDE_FROM_ABI constexpr compare_three_way_result_t<_Tp, _Up>
......@@ -1062,7 +1070,7 @@ operator<=>(const optional<_Tp>& __x, const optional<_Up>& __y) {
10621070 return __x.has_value() <=> __y.has_value();
10631071}
10641072
1065# endif // _LIBCPP_STD_VER >= 20
1073# endif // _LIBCPP_STD_VER >= 20
10661074
10671075// Comparisons with nullopt
10681076template <class _Tp>
......@@ -1070,7 +1078,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, nullop
10701078 return !static_cast<bool>(__x);
10711079}
10721080
1073# if _LIBCPP_STD_VER <= 17
1081# if _LIBCPP_STD_VER <= 17
10741082
10751083template <class _Tp>
10761084_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(nullopt_t, const optional<_Tp>& __x) noexcept {
......@@ -1127,14 +1135,14 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(nullopt_t, const optional<_Tp>&
11271135 return !static_cast<bool>(__x);
11281136}
11291137
1130# else // _LIBCPP_STD_VER <= 17
1138# else // _LIBCPP_STD_VER <= 17
11311139
11321140template <class _Tp>
11331141_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const optional<_Tp>& __x, nullopt_t) noexcept {
11341142 return __x.has_value() <=> false;
11351143}
11361144
1137# endif // _LIBCPP_STD_VER <= 17
1145# endif // _LIBCPP_STD_VER <= 17
11381146
11391147// Comparisons with T
11401148template <class _Tp, class _Up>
......@@ -1233,7 +1241,7 @@ operator>=(const _Tp& __v, const optional<_Up>& __x) {
12331241 return static_cast<bool>(__x) ? __v >= *__x : true;
12341242}
12351243
1236# if _LIBCPP_STD_VER >= 20
1244# if _LIBCPP_STD_VER >= 20
12371245
12381246template <class _Tp, class _Up>
12391247 requires(!__is_derived_from_optional<_Up>) && three_way_comparable_with<_Tp, _Up>
......@@ -1242,7 +1250,7 @@ operator<=>(const optional<_Tp>& __x, const _Up& __v) {
12421250 return __x.has_value() ? *__x <=> __v : strong_ordering::less;
12431251}
12441252
1245# endif // _LIBCPP_STD_VER >= 20
1253# endif // _LIBCPP_STD_VER >= 20
12461254
12471255template <class _Tp>
12481256inline _LIBCPP_HIDE_FROM_ABI
......@@ -1268,10 +1276,10 @@ _LIBCPP_HIDE_FROM_ABI constexpr optional<_Tp> make_optional(initializer_list<_Up
12681276
12691277template <class _Tp>
12701278struct _LIBCPP_TEMPLATE_VIS hash< __enable_hash_helper<optional<_Tp>, remove_const_t<_Tp>> > {
1271# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1279# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
12721280 _LIBCPP_DEPRECATED_IN_CXX17 typedef optional<_Tp> argument_type;
12731281 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
1274# endif
1282# endif
12751283
12761284 _LIBCPP_HIDE_FROM_ABI size_t operator()(const optional<_Tp>& __opt) const {
12771285 return static_cast<bool>(__opt) ? hash<remove_const_t<_Tp>>()(*__opt) : 0;
......@@ -1280,25 +1288,26 @@ struct _LIBCPP_TEMPLATE_VIS hash< __enable_hash_helper<optional<_Tp>, remove_con
12801288
12811289_LIBCPP_END_NAMESPACE_STD
12821290
1283#endif // _LIBCPP_STD_VER >= 17
1291# endif // _LIBCPP_STD_VER >= 17
12841292
12851293_LIBCPP_POP_MACROS
12861294
1287#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1288# include <atomic>
1289# include <climits>
1290# include <concepts>
1291# include <ctime>
1292# include <iterator>
1293# include <limits>
1294# include <memory>
1295# include <ratio>
1296# include <stdexcept>
1297# include <tuple>
1298# include <type_traits>
1299# include <typeinfo>
1300# include <utility>
1301# include <variant>
1302#endif
1295# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1296# include <atomic>
1297# include <climits>
1298# include <concepts>
1299# include <ctime>
1300# include <iterator>
1301# include <limits>
1302# include <memory>
1303# include <ratio>
1304# include <stdexcept>
1305# include <tuple>
1306# include <type_traits>
1307# include <typeinfo>
1308# include <utility>
1309# include <variant>
1310# endif
1311#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
13031312
13041313#endif // _LIBCPP_OPTIONAL
lib/libcxx/include/ostream+34-26
......@@ -172,31 +172,39 @@ void vprint_nonunicode(ostream& os, string_view fmt, format_args args);
172172
173173*/
174174
175#include <__config>
176
177#include <__ostream/basic_ostream.h>
178
179#if _LIBCPP_STD_VER >= 23
180# include <__ostream/print.h>
181#endif
182
183#include <version>
184
185#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
186# pragma GCC system_header
187#endif
188
189#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
190# include <atomic>
191# include <concepts>
192# include <cstdio>
193# include <cstdlib>
194# include <format>
195# include <iosfwd>
196# include <iterator>
197# include <print>
198# include <stdexcept>
199# include <type_traits>
200#endif
175#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
176# include <__cxx03/ostream>
177#else
178# include <__config>
179
180# if _LIBCPP_HAS_LOCALIZATION
181
182# include <__ostream/basic_ostream.h>
183
184# if _LIBCPP_STD_VER >= 23
185# include <__ostream/print.h>
186# endif
187
188# include <version>
189
190# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
191# pragma GCC system_header
192# endif
193
194# endif // _LIBCPP_HAS_LOCALIZATION
195
196# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
197# include <atomic>
198# include <concepts>
199# include <cstdio>
200# include <cstdlib>
201# include <format>
202# include <iosfwd>
203# include <iterator>
204# include <print>
205# include <stdexcept>
206# include <type_traits>
207# endif
208#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
201209
202210#endif // _LIBCPP_OSTREAM
lib/libcxx/include/print+68-63
......@@ -33,28 +33,31 @@ namespace std {
3333}
3434*/
3535
36#include <__assert>
37#include <__concepts/same_as.h>
38#include <__config>
39#include <__system_error/system_error.h>
40#include <__utility/forward.h>
41#include <cerrno>
42#include <cstdio>
43#include <format>
44#include <string>
45#include <string_view>
46#include <version>
47
48#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
49# pragma GCC system_header
50#endif
36#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
37# include <__cxx03/print>
38#else
39# include <__assert>
40# include <__concepts/same_as.h>
41# include <__config>
42# include <__system_error/throw_system_error.h>
43# include <__utility/forward.h>
44# include <cerrno>
45# include <cstdio>
46# include <format>
47# include <string>
48# include <string_view>
49# include <version>
50
51# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
52# pragma GCC system_header
53# endif
5154
5255_LIBCPP_BEGIN_NAMESPACE_STD
5356
54#ifdef _LIBCPP_WIN32API
57# ifdef _LIBCPP_WIN32API
5558_LIBCPP_EXPORTED_FROM_ABI bool __is_windows_terminal(FILE* __stream);
5659
57# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
60# if _LIBCPP_HAS_WIDE_CHARACTERS
5861// A wrapper for WriteConsoleW which is used to write to the Windows
5962// console. This function is in the dylib to avoid pulling in windows.h
6063// in the library headers. The function itself uses some private parts
......@@ -65,14 +68,14 @@ _LIBCPP_EXPORTED_FROM_ABI bool __is_windows_terminal(FILE* __stream);
6568//
6669// Note the function is only implemented on the Windows platform.
6770_LIBCPP_EXPORTED_FROM_ABI void __write_to_windows_console(FILE* __stream, wstring_view __view);
68# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
69#elif __has_include(<unistd.h>)
71# endif // _LIBCPP_HAS_WIDE_CHARACTERS
72# elif __has_include(<unistd.h>)
7073_LIBCPP_EXPORTED_FROM_ABI bool __is_posix_terminal(FILE* __stream);
71#endif // _LIBCPP_WIN32API
74# endif // _LIBCPP_WIN32API
7275
73#if _LIBCPP_STD_VER >= 23
76# if _LIBCPP_STD_VER >= 23
7477
75# ifndef _LIBCPP_HAS_NO_UNICODE
78# if _LIBCPP_HAS_UNICODE
7679// This is the code to transcode UTF-8 to UTF-16. This is used on
7780// Windows for the native Unicode API. The code is modeled to make it
7881// easier to extend to
......@@ -86,27 +89,27 @@ namespace __unicode {
8689// The names of these concepts are modelled after P2728R0, but the
8790// implementation is not. char16_t may contain 32-bits so depending on the
8891// number of bits is an issue.
89# ifdef _LIBCPP_SHORT_WCHAR
92# ifdef _LIBCPP_SHORT_WCHAR
9093template <class _Tp>
9194concept __utf16_code_unit =
9295 same_as<_Tp, char16_t>
93# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
96# if _LIBCPP_HAS_WIDE_CHARACTERS
9497 || same_as<_Tp, wchar_t>
95# endif
98# endif
9699 ;
97100template <class _Tp>
98101concept __utf32_code_unit = same_as<_Tp, char32_t>;
99# else // _LIBCPP_SHORT_WCHAR
102# else // _LIBCPP_SHORT_WCHAR
100103template <class _Tp>
101104concept __utf16_code_unit = same_as<_Tp, char16_t>;
102105template <class _Tp>
103106concept __utf32_code_unit =
104107 same_as<_Tp, char32_t>
105# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
108# if _LIBCPP_HAS_WIDE_CHARACTERS
106109 || same_as<_Tp, wchar_t>
107# endif
110# endif
108111 ;
109# endif // _LIBCPP_SHORT_WCHAR
112# endif // _LIBCPP_SHORT_WCHAR
110113
111114// Pass by reference since an output_iterator may not be copyable.
112115template <class _OutIt>
......@@ -164,7 +167,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _OutIt __transcode(_InIt __first, _InIt __last,
164167
165168} // namespace __unicode
166169
167# endif // _LIBCPP_HAS_NO_UNICODE
170# endif // _LIBCPP_HAS_UNICODE
168171
169172namespace __print {
170173
......@@ -184,30 +187,30 @@ namespace __print {
184187// (note at the time of writing Clang is hard-coded to UTF-8.)
185188//
186189
187# ifdef _LIBCPP_HAS_NO_UNICODE
190# if !_LIBCPP_HAS_UNICODE
188191inline constexpr bool __use_unicode_execution_charset = false;
189# elif defined(_MSVC_EXECUTION_CHARACTER_SET)
192# elif defined(_MSVC_EXECUTION_CHARACTER_SET)
190193// This is the same test MSVC STL uses in their implementation of <print>
191194// See: https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
192195inline constexpr bool __use_unicode_execution_charset = _MSVC_EXECUTION_CHARACTER_SET == 65001;
193# else
196# else
194197inline constexpr bool __use_unicode_execution_charset = true;
195# endif
198# endif
196199
197200_LIBCPP_HIDE_FROM_ABI inline bool __is_terminal([[maybe_unused]] FILE* __stream) {
198201 // The macro _LIBCPP_TESTING_PRINT_IS_TERMINAL is used to change
199202 // the behavior in the test. This is not part of the public API.
200# ifdef _LIBCPP_TESTING_PRINT_IS_TERMINAL
203# ifdef _LIBCPP_TESTING_PRINT_IS_TERMINAL
201204 return _LIBCPP_TESTING_PRINT_IS_TERMINAL(__stream);
202# elif _LIBCPP_AVAILABILITY_HAS_PRINT == 0
205# elif _LIBCPP_AVAILABILITY_HAS_PRINT == 0 || !_LIBCPP_HAS_TERMINAL
203206 return false;
204# elif defined(_LIBCPP_WIN32API)
207# elif defined(_LIBCPP_WIN32API)
205208 return std::__is_windows_terminal(__stream);
206# elif __has_include(<unistd.h>)
209# elif __has_include(<unistd.h>)
207210 return std::__is_posix_terminal(__stream);
208# else
209# error "Provide a way to determine whether a FILE* is a terminal"
210# endif
211# else
212# error "Provide a way to determine whether a FILE* is a terminal"
213# endif
211214}
212215
213216template <class = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
......@@ -226,7 +229,7 @@ __vprint_nonunicode(FILE* __stream, string_view __fmt, format_args __args, bool
226229 }
227230}
228231
229# ifndef _LIBCPP_HAS_NO_UNICODE
232# if _LIBCPP_HAS_UNICODE
230233
231234// Note these helper functions are mainly used to aid testing.
232235// On POSIX systems and Windows the output is no longer considered a
......@@ -243,7 +246,7 @@ __vprint_unicode_posix(FILE* __stream, string_view __fmt, format_args __args, bo
243246 __print::__vprint_nonunicode(__stream, __fmt, __args, __write_nl);
244247}
245248
246# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
249# if _LIBCPP_HAS_WIDE_CHARACTERS
247250template <class = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
248251_LIBCPP_HIDE_FROM_ABI inline void
249252__vprint_unicode_windows(FILE* __stream, string_view __fmt, format_args __args, bool __write_nl, bool __is_terminal) {
......@@ -272,16 +275,16 @@ __vprint_unicode_windows(FILE* __stream, string_view __fmt, format_args __args,
272275
273276 // The macro _LIBCPP_TESTING_PRINT_WRITE_TO_WINDOWS_CONSOLE_FUNCTION is used to change
274277 // the behavior in the test. This is not part of the public API.
275# ifdef _LIBCPP_TESTING_PRINT_WRITE_TO_WINDOWS_CONSOLE_FUNCTION
278# ifdef _LIBCPP_TESTING_PRINT_WRITE_TO_WINDOWS_CONSOLE_FUNCTION
276279 _LIBCPP_TESTING_PRINT_WRITE_TO_WINDOWS_CONSOLE_FUNCTION(__stream, __view);
277# elif defined(_LIBCPP_WIN32API)
280# elif defined(_LIBCPP_WIN32API)
278281 std::__write_to_windows_console(__stream, __view);
279# else
282# else
280283 std::__throw_runtime_error("No defintion of _LIBCPP_TESTING_PRINT_WRITE_TO_WINDOWS_CONSOLE_FUNCTION and "
281284 "__write_to_windows_console is not available.");
282# endif
285# endif
283286}
284# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
287# endif // _LIBCPP_HAS_WIDE_CHARACTERS
285288
286289template <class = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
287290_LIBCPP_HIDE_FROM_ABI inline void
......@@ -312,29 +315,29 @@ __vprint_unicode([[maybe_unused]] FILE* __stream,
312315 // so there the call can be forwarded to the non_unicode API. On
313316 // Windows there is a different API. This API requires transcoding.
314317
315# ifndef _LIBCPP_WIN32API
318# ifndef _LIBCPP_WIN32API
316319 __print::__vprint_unicode_posix(__stream, __fmt, __args, __write_nl, __print::__is_terminal(__stream));
317# elif !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
320# elif _LIBCPP_HAS_WIDE_CHARACTERS
318321 __print::__vprint_unicode_windows(__stream, __fmt, __args, __write_nl, __print::__is_terminal(__stream));
319# else
320# error "Windows builds with wchar_t disabled are not supported."
321# endif
322# else
323# error "Windows builds with wchar_t disabled are not supported."
324# endif
322325}
323326
324# endif // _LIBCPP_HAS_NO_UNICODE
327# endif // _LIBCPP_HAS_UNICODE
325328
326329} // namespace __print
327330
328331template <class... _Args>
329332_LIBCPP_HIDE_FROM_ABI void print(FILE* __stream, format_string<_Args...> __fmt, _Args&&... __args) {
330# ifndef _LIBCPP_HAS_NO_UNICODE
333# if _LIBCPP_HAS_UNICODE
331334 if constexpr (__print::__use_unicode_execution_charset)
332335 __print::__vprint_unicode(__stream, __fmt.get(), std::make_format_args(__args...), false);
333336 else
334337 __print::__vprint_nonunicode(__stream, __fmt.get(), std::make_format_args(__args...), false);
335# else // _LIBCPP_HAS_NO_UNICODE
338# else // _LIBCPP_HAS_UNICODE
336339 __print::__vprint_nonunicode(__stream, __fmt.get(), std::make_format_args(__args...), false);
337# endif // _LIBCPP_HAS_NO_UNICODE
340# endif // _LIBCPP_HAS_UNICODE
338341}
339342
340343template <class... _Args>
......@@ -344,7 +347,7 @@ _LIBCPP_HIDE_FROM_ABI void print(format_string<_Args...> __fmt, _Args&&... __arg
344347
345348template <class... _Args>
346349_LIBCPP_HIDE_FROM_ABI void println(FILE* __stream, format_string<_Args...> __fmt, _Args&&... __args) {
347# ifndef _LIBCPP_HAS_NO_UNICODE
350# if _LIBCPP_HAS_UNICODE
348351 // Note the wording in the Standard is inefficient. The output of
349352 // std::format is a std::string which is then copied. This solution
350353 // just appends a newline at the end of the output.
......@@ -352,9 +355,9 @@ _LIBCPP_HIDE_FROM_ABI void println(FILE* __stream, format_string<_Args...> __fmt
352355 __print::__vprint_unicode(__stream, __fmt.get(), std::make_format_args(__args...), true);
353356 else
354357 __print::__vprint_nonunicode(__stream, __fmt.get(), std::make_format_args(__args...), true);
355# else // _LIBCPP_HAS_NO_UNICODE
358# else // _LIBCPP_HAS_UNICODE
356359 __print::__vprint_nonunicode(__stream, __fmt.get(), std::make_format_args(__args...), true);
357# endif // _LIBCPP_HAS_NO_UNICODE
360# endif // _LIBCPP_HAS_UNICODE
358361}
359362
360363template <class = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
......@@ -372,7 +375,7 @@ _LIBCPP_HIDE_FROM_ABI void println(format_string<_Args...> __fmt, _Args&&... __a
372375 std::println(stdout, __fmt, std::forward<_Args>(__args)...);
373376}
374377
375# ifndef _LIBCPP_HAS_NO_UNICODE
378# if _LIBCPP_HAS_UNICODE
376379template <class = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
377380_LIBCPP_HIDE_FROM_ABI inline void vprint_unicode(FILE* __stream, string_view __fmt, format_args __args) {
378381 __print::__vprint_unicode(__stream, __fmt, __args, false);
......@@ -383,7 +386,7 @@ _LIBCPP_HIDE_FROM_ABI inline void vprint_unicode(string_view __fmt, format_args
383386 std::vprint_unicode(stdout, __fmt, __args);
384387}
385388
386# endif // _LIBCPP_HAS_NO_UNICODE
389# endif // _LIBCPP_HAS_UNICODE
387390
388391template <class = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
389392_LIBCPP_HIDE_FROM_ABI inline void vprint_nonunicode(FILE* __stream, string_view __fmt, format_args __args) {
......@@ -395,8 +398,10 @@ _LIBCPP_HIDE_FROM_ABI inline void vprint_nonunicode(string_view __fmt, format_ar
395398 std::vprint_nonunicode(stdout, __fmt, __args);
396399}
397400
398#endif // _LIBCPP_STD_VER >= 23
401# endif // _LIBCPP_STD_VER >= 23
399402
400403_LIBCPP_END_NAMESPACE_STD
401404
405#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
406
402407#endif // _LIBCPP_PRINT
lib/libcxx/include/queue+92-88
......@@ -254,38 +254,41 @@ template <class T, class Container, class Compare>
254254
255255*/
256256
257#include <__algorithm/make_heap.h>
258#include <__algorithm/pop_heap.h>
259#include <__algorithm/push_heap.h>
260#include <__algorithm/ranges_copy.h>
261#include <__config>
262#include <__functional/operations.h>
263#include <__fwd/deque.h>
264#include <__fwd/queue.h>
265#include <__iterator/back_insert_iterator.h>
266#include <__iterator/iterator_traits.h>
267#include <__memory/uses_allocator.h>
268#include <__ranges/access.h>
269#include <__ranges/concepts.h>
270#include <__ranges/container_compatible_range.h>
271#include <__ranges/from_range.h>
272#include <__utility/forward.h>
273#include <deque>
274#include <vector>
275#include <version>
257#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
258# include <__cxx03/queue>
259#else
260# include <__algorithm/make_heap.h>
261# include <__algorithm/pop_heap.h>
262# include <__algorithm/push_heap.h>
263# include <__algorithm/ranges_copy.h>
264# include <__config>
265# include <__functional/operations.h>
266# include <__fwd/deque.h>
267# include <__fwd/queue.h>
268# include <__iterator/back_insert_iterator.h>
269# include <__iterator/iterator_traits.h>
270# include <__memory/uses_allocator.h>
271# include <__ranges/access.h>
272# include <__ranges/concepts.h>
273# include <__ranges/container_compatible_range.h>
274# include <__ranges/from_range.h>
275# include <__utility/forward.h>
276# include <deque>
277# include <vector>
278# include <version>
276279
277280// standard-mandated includes
278281
279282// [queue.syn]
280#include <compare>
281#include <initializer_list>
283# include <compare>
284# include <initializer_list>
282285
283#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
284# pragma GCC system_header
285#endif
286# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
287# pragma GCC system_header
288# endif
286289
287290_LIBCPP_PUSH_MACROS
288#include <__undef_macros>
291# include <__undef_macros>
289292
290293_LIBCPP_BEGIN_NAMESPACE_STD
291294
......@@ -313,7 +316,7 @@ public:
313316
314317 _LIBCPP_HIDE_FROM_ABI queue(const queue& __q) : c(__q.c) {}
315318
316#if _LIBCPP_STD_VER >= 23
319# if _LIBCPP_STD_VER >= 23
317320 template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
318321 _LIBCPP_HIDE_FROM_ABI queue(_InputIterator __first, _InputIterator __last) : c(__first, __last) {}
319322
......@@ -333,14 +336,14 @@ public:
333336 _LIBCPP_HIDE_FROM_ABI queue(from_range_t, _Range&& __range, const _Alloc& __alloc)
334337 : c(from_range, std::forward<_Range>(__range), __alloc) {}
335338
336#endif
339# endif
337340
338341 _LIBCPP_HIDE_FROM_ABI queue& operator=(const queue& __q) {
339342 c = __q.c;
340343 return *this;
341344 }
342345
343#ifndef _LIBCPP_CXX03_LANG
346# ifndef _LIBCPP_CXX03_LANG
344347 _LIBCPP_HIDE_FROM_ABI queue(queue&& __q) noexcept(is_nothrow_move_constructible<container_type>::value)
345348 : c(std::move(__q.c)) {}
346349
......@@ -348,12 +351,12 @@ public:
348351 c = std::move(__q.c);
349352 return *this;
350353 }
351#endif // _LIBCPP_CXX03_LANG
354# endif // _LIBCPP_CXX03_LANG
352355
353356 _LIBCPP_HIDE_FROM_ABI explicit queue(const container_type& __c) : c(__c) {}
354#ifndef _LIBCPP_CXX03_LANG
357# ifndef _LIBCPP_CXX03_LANG
355358 _LIBCPP_HIDE_FROM_ABI explicit queue(container_type&& __c) : c(std::move(__c)) {}
356#endif // _LIBCPP_CXX03_LANG
359# endif // _LIBCPP_CXX03_LANG
357360
358361 template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
359362 _LIBCPP_HIDE_FROM_ABI explicit queue(const _Alloc& __a) : c(__a) {}
......@@ -364,15 +367,15 @@ public:
364367 template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
365368 _LIBCPP_HIDE_FROM_ABI queue(const container_type& __c, const _Alloc& __a) : c(__c, __a) {}
366369
367#ifndef _LIBCPP_CXX03_LANG
370# ifndef _LIBCPP_CXX03_LANG
368371 template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
369372 _LIBCPP_HIDE_FROM_ABI queue(container_type&& __c, const _Alloc& __a) : c(std::move(__c), __a) {}
370373
371374 template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
372375 _LIBCPP_HIDE_FROM_ABI queue(queue&& __q, const _Alloc& __a) : c(std::move(__q.c), __a) {}
373#endif // _LIBCPP_CXX03_LANG
376# endif // _LIBCPP_CXX03_LANG
374377
375 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); }
378 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); }
376379 _LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); }
377380
378381 _LIBCPP_HIDE_FROM_ABI reference front() { return c.front(); }
......@@ -381,10 +384,10 @@ public:
381384 _LIBCPP_HIDE_FROM_ABI const_reference back() const { return c.back(); }
382385
383386 _LIBCPP_HIDE_FROM_ABI void push(const value_type& __v) { c.push_back(__v); }
384#ifndef _LIBCPP_CXX03_LANG
387# ifndef _LIBCPP_CXX03_LANG
385388 _LIBCPP_HIDE_FROM_ABI void push(value_type&& __v) { c.push_back(std::move(__v)); }
386389
387# if _LIBCPP_STD_VER >= 23
390# if _LIBCPP_STD_VER >= 23
388391 template <_ContainerCompatibleRange<_Tp> _Range>
389392 _LIBCPP_HIDE_FROM_ABI void push_range(_Range&& __range) {
390393 if constexpr (requires(container_type& __c) { __c.append_range(std::forward<_Range>(__range)); }) {
......@@ -393,22 +396,22 @@ public:
393396 ranges::copy(std::forward<_Range>(__range), std::back_inserter(c));
394397 }
395398 }
396# endif
399# endif
397400
398401 template <class... _Args>
399402 _LIBCPP_HIDE_FROM_ABI
400# if _LIBCPP_STD_VER >= 17
403# if _LIBCPP_STD_VER >= 17
401404 decltype(auto)
402405 emplace(_Args&&... __args) {
403406 return c.emplace_back(std::forward<_Args>(__args)...);
404407 }
405# else
408# else
406409 void
407410 emplace(_Args&&... __args) {
408411 c.emplace_back(std::forward<_Args>(__args)...);
409412 }
410# endif
411#endif // _LIBCPP_CXX03_LANG
413# endif
414# endif // _LIBCPP_CXX03_LANG
412415 _LIBCPP_HIDE_FROM_ABI void pop() { c.pop_front(); }
413416
414417 _LIBCPP_HIDE_FROM_ABI void swap(queue& __q) _NOEXCEPT_(__is_nothrow_swappable_v<container_type>) {
......@@ -416,7 +419,7 @@ public:
416419 swap(c, __q.c);
417420 }
418421
419 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; }
422 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; }
420423
421424 template <class _T1, class _OtherContainer>
422425 friend _LIBCPP_HIDE_FROM_ABI bool
......@@ -427,7 +430,7 @@ public:
427430 operator<(const queue<_T1, _OtherContainer>& __x, const queue<_T1, _OtherContainer>& __y);
428431};
429432
430#if _LIBCPP_STD_VER >= 17
433# if _LIBCPP_STD_VER >= 17
431434template <class _Container, class = enable_if_t<!__is_allocator<_Container>::value> >
432435queue(_Container) -> queue<typename _Container::value_type, _Container>;
433436
......@@ -436,9 +439,9 @@ template <class _Container,
436439 class = enable_if_t<!__is_allocator<_Container>::value>,
437440 class = enable_if_t<uses_allocator<_Container, _Alloc>::value> >
438441queue(_Container, _Alloc) -> queue<typename _Container::value_type, _Container>;
439#endif
442# endif
440443
441#if _LIBCPP_STD_VER >= 23
444# if _LIBCPP_STD_VER >= 23
442445template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
443446queue(_InputIterator, _InputIterator) -> queue<__iter_value_type<_InputIterator>>;
444447
......@@ -457,7 +460,7 @@ template <ranges::input_range _Range, class _Alloc, __enable_if_t<__is_allocator
457460queue(from_range_t,
458461 _Range&&,
459462 _Alloc) -> queue<ranges::range_value_t<_Range>, deque<ranges::range_value_t<_Range>, _Alloc>>;
460#endif
463# endif
461464
462465template <class _Tp, class _Container>
463466inline _LIBCPP_HIDE_FROM_ABI bool operator==(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) {
......@@ -489,7 +492,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const queue<_Tp, _Container>& __x,
489492 return !(__y < __x);
490493}
491494
492#if _LIBCPP_STD_VER >= 20
495# if _LIBCPP_STD_VER >= 20
493496
494497template <class _Tp, three_way_comparable _Container>
495498_LIBCPP_HIDE_FROM_ABI compare_three_way_result_t<_Container>
......@@ -498,7 +501,7 @@ operator<=>(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y
498501 return __x.__get_container() <=> __y.__get_container();
499502}
500503
501#endif
504# endif
502505
503506template <class _Tp, class _Container, __enable_if_t<__is_swappable_v<_Container>, int> = 0>
504507inline _LIBCPP_HIDE_FROM_ABI void swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
......@@ -538,7 +541,7 @@ public:
538541 return *this;
539542 }
540543
541#ifndef _LIBCPP_CXX03_LANG
544# ifndef _LIBCPP_CXX03_LANG
542545 _LIBCPP_HIDE_FROM_ABI priority_queue(priority_queue&& __q) noexcept(
543546 is_nothrow_move_constructible<container_type>::value && is_nothrow_move_constructible<value_compare>::value)
544547 : c(std::move(__q.c)), comp(std::move(__q.comp)) {}
......@@ -549,13 +552,13 @@ public:
549552 comp = std::move(__q.comp);
550553 return *this;
551554 }
552#endif // _LIBCPP_CXX03_LANG
555# endif // _LIBCPP_CXX03_LANG
553556
554557 _LIBCPP_HIDE_FROM_ABI explicit priority_queue(const value_compare& __comp) : c(), comp(__comp) {}
555558 _LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, const container_type& __c);
556#ifndef _LIBCPP_CXX03_LANG
559# ifndef _LIBCPP_CXX03_LANG
557560 _LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, container_type&& __c);
558#endif
561# endif
559562 template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
560563 _LIBCPP_HIDE_FROM_ABI priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp = value_compare());
561564
......@@ -563,19 +566,19 @@ public:
563566 _LIBCPP_HIDE_FROM_ABI
564567 priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, const container_type& __c);
565568
566#ifndef _LIBCPP_CXX03_LANG
569# ifndef _LIBCPP_CXX03_LANG
567570 template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
568571 _LIBCPP_HIDE_FROM_ABI
569572 priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c);
570#endif // _LIBCPP_CXX03_LANG
573# endif // _LIBCPP_CXX03_LANG
571574
572#if _LIBCPP_STD_VER >= 23
575# if _LIBCPP_STD_VER >= 23
573576 template <_ContainerCompatibleRange<_Tp> _Range>
574577 _LIBCPP_HIDE_FROM_ABI priority_queue(from_range_t, _Range&& __range, const value_compare& __comp = value_compare())
575578 : c(from_range, std::forward<_Range>(__range)), comp(__comp) {
576579 std::make_heap(c.begin(), c.end(), comp);
577580 }
578#endif
581# endif
579582
580583 template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
581584 _LIBCPP_HIDE_FROM_ABI explicit priority_queue(const _Alloc& __a);
......@@ -589,13 +592,13 @@ public:
589592 template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
590593 _LIBCPP_HIDE_FROM_ABI priority_queue(const priority_queue& __q, const _Alloc& __a);
591594
592#ifndef _LIBCPP_CXX03_LANG
595# ifndef _LIBCPP_CXX03_LANG
593596 template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
594597 _LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, container_type&& __c, const _Alloc& __a);
595598
596599 template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
597600 _LIBCPP_HIDE_FROM_ABI priority_queue(priority_queue&& __q, const _Alloc& __a);
598#endif // _LIBCPP_CXX03_LANG
601# endif // _LIBCPP_CXX03_LANG
599602
600603 template <
601604 class _InputIter,
......@@ -619,7 +622,7 @@ public:
619622 _LIBCPP_HIDE_FROM_ABI priority_queue(
620623 _InputIter __f, _InputIter __l, const value_compare& __comp, const container_type& __c, const _Alloc& __a);
621624
622#ifndef _LIBCPP_CXX03_LANG
625# ifndef _LIBCPP_CXX03_LANG
623626 template <
624627 class _InputIter,
625628 class _Alloc,
......@@ -627,9 +630,9 @@ public:
627630 int> = 0>
628631 _LIBCPP_HIDE_FROM_ABI
629632 priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c, const _Alloc& __a);
630#endif // _LIBCPP_CXX03_LANG
633# endif // _LIBCPP_CXX03_LANG
631634
632#if _LIBCPP_STD_VER >= 23
635# if _LIBCPP_STD_VER >= 23
633636
634637 template <_ContainerCompatibleRange<_Tp> _Range,
635638 class _Alloc,
......@@ -647,17 +650,17 @@ public:
647650 std::make_heap(c.begin(), c.end(), comp);
648651 }
649652
650#endif
653# endif
651654
652 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); }
655 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); }
653656 _LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); }
654657 _LIBCPP_HIDE_FROM_ABI const_reference top() const { return c.front(); }
655658
656659 _LIBCPP_HIDE_FROM_ABI void push(const value_type& __v);
657#ifndef _LIBCPP_CXX03_LANG
660# ifndef _LIBCPP_CXX03_LANG
658661 _LIBCPP_HIDE_FROM_ABI void push(value_type&& __v);
659662
660# if _LIBCPP_STD_VER >= 23
663# if _LIBCPP_STD_VER >= 23
661664 template <_ContainerCompatibleRange<_Tp> _Range>
662665 _LIBCPP_HIDE_FROM_ABI void push_range(_Range&& __range) {
663666 if constexpr (requires(container_type& __c) { __c.append_range(std::forward<_Range>(__range)); }) {
......@@ -668,20 +671,20 @@ public:
668671
669672 std::make_heap(c.begin(), c.end(), comp);
670673 }
671# endif
674# endif
672675
673676 template <class... _Args>
674677 _LIBCPP_HIDE_FROM_ABI void emplace(_Args&&... __args);
675#endif // _LIBCPP_CXX03_LANG
678# endif // _LIBCPP_CXX03_LANG
676679 _LIBCPP_HIDE_FROM_ABI void pop();
677680
678681 _LIBCPP_HIDE_FROM_ABI void swap(priority_queue& __q)
679682 _NOEXCEPT_(__is_nothrow_swappable_v<container_type>&& __is_nothrow_swappable_v<value_compare>);
680683
681 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; }
684 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; }
682685};
683686
684#if _LIBCPP_STD_VER >= 17
687# if _LIBCPP_STD_VER >= 17
685688template <class _Compare,
686689 class _Container,
687690 class = enable_if_t<!__is_allocator<_Compare>::value>,
......@@ -735,9 +738,9 @@ template <class _InputIterator,
735738 class = enable_if_t<uses_allocator<_Container, _Alloc>::value> >
736739priority_queue(_InputIterator, _InputIterator, _Compare, _Container, _Alloc)
737740 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
738#endif
741# endif
739742
740#if _LIBCPP_STD_VER >= 23
743# if _LIBCPP_STD_VER >= 23
741744
742745template <ranges::input_range _Range,
743746 class _Compare = less<ranges::range_value_t<_Range>>,
......@@ -757,7 +760,7 @@ template <ranges::input_range _Range, class _Alloc, class = enable_if_t<__is_all
757760priority_queue(from_range_t, _Range&&, _Alloc)
758761 -> priority_queue<ranges::range_value_t<_Range>, vector<ranges::range_value_t<_Range>, _Alloc>>;
759762
760#endif
763# endif
761764
762765template <class _Tp, class _Container, class _Compare>
763766inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp, const container_type& __c)
......@@ -765,7 +768,7 @@ inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare&
765768 std::make_heap(c.begin(), c.end(), comp);
766769}
767770
768#ifndef _LIBCPP_CXX03_LANG
771# ifndef _LIBCPP_CXX03_LANG
769772
770773template <class _Tp, class _Container, class _Compare>
771774inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, container_type&& __c)
......@@ -773,7 +776,7 @@ inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_com
773776 std::make_heap(c.begin(), c.end(), comp);
774777}
775778
776#endif // _LIBCPP_CXX03_LANG
779# endif // _LIBCPP_CXX03_LANG
777780
778781template <class _Tp, class _Container, class _Compare>
779782template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> >
......@@ -792,7 +795,7 @@ inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
792795 std::make_heap(c.begin(), c.end(), comp);
793796}
794797
795#ifndef _LIBCPP_CXX03_LANG
798# ifndef _LIBCPP_CXX03_LANG
796799
797800template <class _Tp, class _Container, class _Compare>
798801template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> >
......@@ -803,7 +806,7 @@ inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
803806 std::make_heap(c.begin(), c.end(), comp);
804807}
805808
806#endif // _LIBCPP_CXX03_LANG
809# endif // _LIBCPP_CXX03_LANG
807810
808811template <class _Tp, class _Container, class _Compare>
809812template <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> >
......@@ -827,7 +830,7 @@ template <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value,
827830inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q, const _Alloc& __a)
828831 : c(__q.c, __a), comp(__q.comp) {}
829832
830#ifndef _LIBCPP_CXX03_LANG
833# ifndef _LIBCPP_CXX03_LANG
831834
832835template <class _Tp, class _Container, class _Compare>
833836template <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> >
......@@ -842,7 +845,7 @@ template <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value,
842845inline priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q, const _Alloc& __a)
843846 : c(std::move(__q.c), __a), comp(std::move(__q.comp)) {}
844847
845#endif // _LIBCPP_CXX03_LANG
848# endif // _LIBCPP_CXX03_LANG
846849
847850template <class _Tp, class _Container, class _Compare>
848851template <
......@@ -877,7 +880,7 @@ inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
877880 std::make_heap(c.begin(), c.end(), comp);
878881}
879882
880#ifndef _LIBCPP_CXX03_LANG
883# ifndef _LIBCPP_CXX03_LANG
881884template <class _Tp, class _Container, class _Compare>
882885template <
883886 class _InputIter,
......@@ -889,7 +892,7 @@ inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
889892 c.insert(c.end(), __f, __l);
890893 std::make_heap(c.begin(), c.end(), comp);
891894}
892#endif // _LIBCPP_CXX03_LANG
895# endif // _LIBCPP_CXX03_LANG
893896
894897template <class _Tp, class _Container, class _Compare>
895898inline void priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v) {
......@@ -897,7 +900,7 @@ inline void priority_queue<_Tp, _Container, _Compare>::push(const value_type& __
897900 std::push_heap(c.begin(), c.end(), comp);
898901}
899902
900#ifndef _LIBCPP_CXX03_LANG
903# ifndef _LIBCPP_CXX03_LANG
901904
902905template <class _Tp, class _Container, class _Compare>
903906inline void priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v) {
......@@ -912,7 +915,7 @@ inline void priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args
912915 std::push_heap(c.begin(), c.end(), comp);
913916}
914917
915#endif // _LIBCPP_CXX03_LANG
918# endif // _LIBCPP_CXX03_LANG
916919
917920template <class _Tp, class _Container, class _Compare>
918921inline void priority_queue<_Tp, _Container, _Compare>::pop() {
......@@ -946,11 +949,12 @@ _LIBCPP_END_NAMESPACE_STD
946949
947950_LIBCPP_POP_MACROS
948951
949#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
950# include <concepts>
951# include <cstdlib>
952# include <functional>
953# include <type_traits>
954#endif
952# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
953# include <concepts>
954# include <cstdlib>
955# include <functional>
956# include <type_traits>
957# endif
958#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
955959
956960#endif // _LIBCPP_QUEUE
lib/libcxx/include/random+61-57
......@@ -1677,66 +1677,70 @@ class piecewise_linear_distribution
16771677} // std
16781678*/
16791679
1680#include <__config>
1681#include <__random/bernoulli_distribution.h>
1682#include <__random/binomial_distribution.h>
1683#include <__random/cauchy_distribution.h>
1684#include <__random/chi_squared_distribution.h>
1685#include <__random/default_random_engine.h>
1686#include <__random/discard_block_engine.h>
1687#include <__random/discrete_distribution.h>
1688#include <__random/exponential_distribution.h>
1689#include <__random/extreme_value_distribution.h>
1690#include <__random/fisher_f_distribution.h>
1691#include <__random/gamma_distribution.h>
1692#include <__random/generate_canonical.h>
1693#include <__random/geometric_distribution.h>
1694#include <__random/independent_bits_engine.h>
1695#include <__random/is_seed_sequence.h>
1696#include <__random/knuth_b.h>
1697#include <__random/linear_congruential_engine.h>
1698#include <__random/lognormal_distribution.h>
1699#include <__random/mersenne_twister_engine.h>
1700#include <__random/negative_binomial_distribution.h>
1701#include <__random/normal_distribution.h>
1702#include <__random/piecewise_constant_distribution.h>
1703#include <__random/piecewise_linear_distribution.h>
1704#include <__random/poisson_distribution.h>
1705#include <__random/random_device.h>
1706#include <__random/ranlux.h>
1707#include <__random/seed_seq.h>
1708#include <__random/shuffle_order_engine.h>
1709#include <__random/student_t_distribution.h>
1710#include <__random/subtract_with_carry_engine.h>
1711#include <__random/uniform_int_distribution.h>
1712#include <__random/uniform_random_bit_generator.h>
1713#include <__random/uniform_real_distribution.h>
1714#include <__random/weibull_distribution.h>
1715#include <version>
1680#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
1681# include <__cxx03/random>
1682#else
1683# include <__config>
1684# include <__random/bernoulli_distribution.h>
1685# include <__random/binomial_distribution.h>
1686# include <__random/cauchy_distribution.h>
1687# include <__random/chi_squared_distribution.h>
1688# include <__random/default_random_engine.h>
1689# include <__random/discard_block_engine.h>
1690# include <__random/discrete_distribution.h>
1691# include <__random/exponential_distribution.h>
1692# include <__random/extreme_value_distribution.h>
1693# include <__random/fisher_f_distribution.h>
1694# include <__random/gamma_distribution.h>
1695# include <__random/generate_canonical.h>
1696# include <__random/geometric_distribution.h>
1697# include <__random/independent_bits_engine.h>
1698# include <__random/is_seed_sequence.h>
1699# include <__random/knuth_b.h>
1700# include <__random/linear_congruential_engine.h>
1701# include <__random/lognormal_distribution.h>
1702# include <__random/mersenne_twister_engine.h>
1703# include <__random/negative_binomial_distribution.h>
1704# include <__random/normal_distribution.h>
1705# include <__random/piecewise_constant_distribution.h>
1706# include <__random/piecewise_linear_distribution.h>
1707# include <__random/poisson_distribution.h>
1708# include <__random/random_device.h>
1709# include <__random/ranlux.h>
1710# include <__random/seed_seq.h>
1711# include <__random/shuffle_order_engine.h>
1712# include <__random/student_t_distribution.h>
1713# include <__random/subtract_with_carry_engine.h>
1714# include <__random/uniform_int_distribution.h>
1715# include <__random/uniform_random_bit_generator.h>
1716# include <__random/uniform_real_distribution.h>
1717# include <__random/weibull_distribution.h>
1718# include <version>
17161719
17171720// standard-mandated includes
17181721
17191722// [rand.synopsis]
1720#include <initializer_list>
1721
1722#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1723# pragma GCC system_header
1724#endif
1725
1726#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1727# include <algorithm>
1728# include <climits>
1729# include <cmath>
1730# include <concepts>
1731# include <cstddef>
1732# include <cstdint>
1733# include <cstdlib>
1734# include <iosfwd>
1735# include <limits>
1736# include <numeric>
1737# include <string>
1738# include <type_traits>
1739# include <vector>
1740#endif
1723# include <initializer_list>
1724
1725# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1726# pragma GCC system_header
1727# endif
1728
1729# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1730# include <algorithm>
1731# include <climits>
1732# include <cmath>
1733# include <concepts>
1734# include <cstddef>
1735# include <cstdint>
1736# include <cstdlib>
1737# include <iosfwd>
1738# include <limits>
1739# include <numeric>
1740# include <string>
1741# include <type_traits>
1742# include <vector>
1743# endif
1744#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
17411745
17421746#endif // _LIBCPP_RANDOM
lib/libcxx/include/ranges+66-70
......@@ -380,84 +380,80 @@ namespace std {
380380}
381381*/
382382
383#include <__config>
384
385#if _LIBCPP_STD_VER >= 20
386# include <__ranges/access.h>
387# include <__ranges/all.h>
388# include <__ranges/common_view.h>
389# include <__ranges/concepts.h>
390# include <__ranges/counted.h>
391# include <__ranges/dangling.h>
392# include <__ranges/data.h>
393# include <__ranges/drop_view.h>
394# include <__ranges/drop_while_view.h>
395# include <__ranges/elements_view.h>
396# include <__ranges/empty.h>
397# include <__ranges/empty_view.h>
398# include <__ranges/enable_borrowed_range.h>
399# include <__ranges/enable_view.h>
400# include <__ranges/filter_view.h>
401# include <__ranges/iota_view.h>
402# include <__ranges/join_view.h>
403# include <__ranges/lazy_split_view.h>
404# include <__ranges/rbegin.h>
405# include <__ranges/ref_view.h>
406# include <__ranges/rend.h>
407# include <__ranges/reverse_view.h>
408# include <__ranges/single_view.h>
409# include <__ranges/size.h>
410# include <__ranges/split_view.h>
411# include <__ranges/subrange.h>
412# include <__ranges/take_view.h>
413# include <__ranges/take_while_view.h>
414# include <__ranges/transform_view.h>
415# include <__ranges/view_interface.h>
416# include <__ranges/views.h>
417
418# if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
419# include <__ranges/istream_view.h>
383#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
384# include <__cxx03/ranges>
385#else
386# include <__config>
387
388# if _LIBCPP_STD_VER >= 20
389# include <__ranges/access.h>
390# include <__ranges/all.h>
391# include <__ranges/common_view.h>
392# include <__ranges/concepts.h>
393# include <__ranges/counted.h>
394# include <__ranges/dangling.h>
395# include <__ranges/data.h>
396# include <__ranges/drop_view.h>
397# include <__ranges/drop_while_view.h>
398# include <__ranges/elements_view.h>
399# include <__ranges/empty.h>
400# include <__ranges/empty_view.h>
401# include <__ranges/enable_borrowed_range.h>
402# include <__ranges/enable_view.h>
403# include <__ranges/filter_view.h>
404# include <__ranges/iota_view.h>
405# include <__ranges/join_view.h>
406# include <__ranges/lazy_split_view.h>
407# include <__ranges/rbegin.h>
408# include <__ranges/ref_view.h>
409# include <__ranges/rend.h>
410# include <__ranges/reverse_view.h>
411# include <__ranges/single_view.h>
412# include <__ranges/size.h>
413# include <__ranges/split_view.h>
414# include <__ranges/subrange.h>
415# include <__ranges/take_view.h>
416# include <__ranges/take_while_view.h>
417# include <__ranges/transform_view.h>
418# include <__ranges/view_interface.h>
419# include <__ranges/views.h>
420
421# if _LIBCPP_HAS_LOCALIZATION
422# include <__ranges/istream_view.h>
423# endif
420424# endif
421#endif
422425
423#if _LIBCPP_STD_VER >= 23
424# include <__ranges/as_rvalue_view.h>
425# include <__ranges/chunk_by_view.h>
426# include <__ranges/from_range.h>
427# include <__ranges/repeat_view.h>
428# include <__ranges/to.h>
429# include <__ranges/zip_view.h>
430#endif
426# if _LIBCPP_STD_VER >= 23
427# include <__ranges/as_rvalue_view.h>
428# include <__ranges/chunk_by_view.h>
429# include <__ranges/from_range.h>
430# include <__ranges/repeat_view.h>
431# include <__ranges/to.h>
432# include <__ranges/zip_view.h>
433# endif
431434
432#include <version>
435# include <version>
433436
434437// standard-mandated includes
435438
436439// [ranges.syn]
437#include <compare>
438#include <initializer_list>
439#include <iterator>
440# include <compare>
441# include <initializer_list>
442# include <iterator>
440443
441444// [tuple.helper]
442#include <__tuple/tuple_element.h>
443#include <__tuple/tuple_size.h>
444
445#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
446# pragma GCC system_header
447#endif
448
449#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
450# include <cstddef>
451# include <limits>
452# include <optional>
453# include <span>
454# include <tuple>
455#endif
456
457#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
458# include <cstdlib>
459# include <iosfwd>
460# include <type_traits>
461#endif
445# include <__tuple/tuple_element.h>
446# include <__tuple/tuple_size.h>
447
448# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
449# pragma GCC system_header
450# endif
451
452# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
453# include <cstdlib>
454# include <iosfwd>
455# include <type_traits>
456# endif
457#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
462458
463459#endif // _LIBCPP_RANGES
lib/libcxx/include/ratio+82-100
......@@ -81,56 +81,47 @@ using quetta = ratio <1'000'000'000'000'000'000'000'000'000'000, 1>; // Since C+
8181}
8282*/
8383
84#include <__config>
85#include <__type_traits/integral_constant.h>
86#include <climits>
87#include <cstdint>
88#include <version>
89
90#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
91# pragma GCC system_header
92#endif
84#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
85# include <__cxx03/ratio>
86#else
87# include <__config>
88# include <__type_traits/integral_constant.h>
89# include <climits>
90# include <cstdint>
91# include <version>
92
93# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
94# pragma GCC system_header
95# endif
9396
9497_LIBCPP_PUSH_MACROS
95#include <__undef_macros>
98# include <__undef_macros>
9699
97100_LIBCPP_BEGIN_NAMESPACE_STD
98101
99102// __static_gcd
100103
101104template <intmax_t _Xp, intmax_t _Yp>
102struct __static_gcd {
103 static const intmax_t value = __static_gcd<_Yp, _Xp % _Yp>::value;
104};
105inline const intmax_t __static_gcd = __static_gcd<_Yp, _Xp % _Yp>;
105106
106107template <intmax_t _Xp>
107struct __static_gcd<_Xp, 0> {
108 static const intmax_t value = _Xp;
109};
108inline const intmax_t __static_gcd<_Xp, 0> = _Xp;
110109
111110template <>
112struct __static_gcd<0, 0> {
113 static const intmax_t value = 1;
114};
111inline const intmax_t __static_gcd<0, 0> = 1;
115112
116113// __static_lcm
117114
118115template <intmax_t _Xp, intmax_t _Yp>
119struct __static_lcm {
120 static const intmax_t value = _Xp / __static_gcd<_Xp, _Yp>::value * _Yp;
121};
116inline const intmax_t __static_lcm = _Xp / __static_gcd<_Xp, _Yp> * _Yp;
122117
123118template <intmax_t _Xp>
124struct __static_abs {
125 static const intmax_t value = _Xp < 0 ? -_Xp : _Xp;
126};
119inline const intmax_t __static_abs = _Xp < 0 ? -_Xp : _Xp;
127120
128121template <intmax_t _Xp>
129struct __static_sign {
130 static const intmax_t value = _Xp == 0 ? 0 : (_Xp < 0 ? -1 : 1);
131};
122inline const intmax_t __static_sign = _Xp == 0 ? 0 : (_Xp < 0 ? -1 : 1);
132123
133template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp>::value>
124template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp> >
134125class __ll_add;
135126
136127template <intmax_t _Xp, intmax_t _Yp>
......@@ -161,7 +152,7 @@ public:
161152 static const intmax_t value = _Xp + _Yp;
162153};
163154
164template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp>::value>
155template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp> >
165156class __ll_sub;
166157
167158template <intmax_t _Xp, intmax_t _Yp>
......@@ -197,8 +188,8 @@ class __ll_mul {
197188 static const intmax_t nan = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1));
198189 static const intmax_t min = nan + 1;
199190 static const intmax_t max = -min;
200 static const intmax_t __a_x = __static_abs<_Xp>::value;
201 static const intmax_t __a_y = __static_abs<_Yp>::value;
191 static const intmax_t __a_x = __static_abs<_Xp>;
192 static const intmax_t __a_y = __static_abs<_Yp>;
202193
203194 static_assert(_Xp != nan && _Yp != nan && __a_x <= max / __a_y, "overflow in __ll_mul");
204195
......@@ -239,31 +230,26 @@ public:
239230
240231template <intmax_t _Num, intmax_t _Den = 1>
241232class _LIBCPP_TEMPLATE_VIS ratio {
242 static_assert(__static_abs<_Num>::value >= 0, "ratio numerator is out of range");
233 static_assert(__static_abs<_Num> >= 0, "ratio numerator is out of range");
243234 static_assert(_Den != 0, "ratio divide by 0");
244 static_assert(__static_abs<_Den>::value > 0, "ratio denominator is out of range");
245 static _LIBCPP_CONSTEXPR const intmax_t __na = __static_abs<_Num>::value;
246 static _LIBCPP_CONSTEXPR const intmax_t __da = __static_abs<_Den>::value;
247 static _LIBCPP_CONSTEXPR const intmax_t __s = __static_sign<_Num>::value * __static_sign<_Den>::value;
248 static _LIBCPP_CONSTEXPR const intmax_t __gcd = __static_gcd<__na, __da>::value;
235 static_assert(__static_abs<_Den> > 0, "ratio denominator is out of range");
236 static _LIBCPP_CONSTEXPR const intmax_t __na = __static_abs<_Num>;
237 static _LIBCPP_CONSTEXPR const intmax_t __da = __static_abs<_Den>;
238 static _LIBCPP_CONSTEXPR const intmax_t __s = __static_sign<_Num> * __static_sign<_Den>;
239 static _LIBCPP_CONSTEXPR const intmax_t __gcd = __static_gcd<__na, __da>;
249240
250241public:
251 static _LIBCPP_CONSTEXPR const intmax_t num = __s * __na / __gcd;
252 static _LIBCPP_CONSTEXPR const intmax_t den = __da / __gcd;
242 static inline _LIBCPP_CONSTEXPR const intmax_t num = __s * __na / __gcd;
243 static inline _LIBCPP_CONSTEXPR const intmax_t den = __da / __gcd;
253244
254245 typedef ratio<num, den> type;
255246};
256247
257template <intmax_t _Num, intmax_t _Den>
258_LIBCPP_CONSTEXPR const intmax_t ratio<_Num, _Den>::num;
259
260template <intmax_t _Num, intmax_t _Den>
261_LIBCPP_CONSTEXPR const intmax_t ratio<_Num, _Den>::den;
262
263248template <class _Tp>
264struct __is_ratio : false_type {};
249inline const bool __is_ratio_v = false;
250
265251template <intmax_t _Num, intmax_t _Den>
266struct __is_ratio<ratio<_Num, _Den> > : true_type {};
252inline const bool __is_ratio_v<ratio<_Num, _Den> > = true;
267253
268254typedef ratio<1LL, 1000000000000000000LL> atto;
269255typedef ratio<1LL, 1000000000000000LL> femto;
......@@ -285,63 +271,63 @@ typedef ratio<1000000000000000000LL, 1LL> exa;
285271template <class _R1, class _R2>
286272struct __ratio_multiply {
287273private:
288 static const intmax_t __gcd_n1_d2 = __static_gcd<_R1::num, _R2::den>::value;
289 static const intmax_t __gcd_d1_n2 = __static_gcd<_R1::den, _R2::num>::value;
274 static const intmax_t __gcd_n1_d2 = __static_gcd<_R1::num, _R2::den>;
275 static const intmax_t __gcd_d1_n2 = __static_gcd<_R1::den, _R2::num>;
290276
291 static_assert(__is_ratio<_R1>::value, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
292 static_assert(__is_ratio<_R2>::value, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
277 static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
278 static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
293279
294280public:
295281 typedef typename ratio< __ll_mul<_R1::num / __gcd_n1_d2, _R2::num / __gcd_d1_n2>::value,
296282 __ll_mul<_R2::den / __gcd_n1_d2, _R1::den / __gcd_d1_n2>::value >::type type;
297283};
298284
299#ifndef _LIBCPP_CXX03_LANG
285# ifndef _LIBCPP_CXX03_LANG
300286
301287template <class _R1, class _R2>
302288using ratio_multiply = typename __ratio_multiply<_R1, _R2>::type;
303289
304#else // _LIBCPP_CXX03_LANG
290# else // _LIBCPP_CXX03_LANG
305291
306292template <class _R1, class _R2>
307293struct _LIBCPP_TEMPLATE_VIS ratio_multiply : public __ratio_multiply<_R1, _R2>::type {};
308294
309#endif // _LIBCPP_CXX03_LANG
295# endif // _LIBCPP_CXX03_LANG
310296
311297template <class _R1, class _R2>
312298struct __ratio_divide {
313299private:
314 static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
315 static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
300 static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>;
301 static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>;
316302
317 static_assert(__is_ratio<_R1>::value, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
318 static_assert(__is_ratio<_R2>::value, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
303 static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
304 static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
319305
320306public:
321307 typedef typename ratio< __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value,
322308 __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value >::type type;
323309};
324310
325#ifndef _LIBCPP_CXX03_LANG
311# ifndef _LIBCPP_CXX03_LANG
326312
327313template <class _R1, class _R2>
328314using ratio_divide = typename __ratio_divide<_R1, _R2>::type;
329315
330#else // _LIBCPP_CXX03_LANG
316# else // _LIBCPP_CXX03_LANG
331317
332318template <class _R1, class _R2>
333319struct _LIBCPP_TEMPLATE_VIS ratio_divide : public __ratio_divide<_R1, _R2>::type {};
334320
335#endif // _LIBCPP_CXX03_LANG
321# endif // _LIBCPP_CXX03_LANG
336322
337323template <class _R1, class _R2>
338324struct __ratio_add {
339325private:
340 static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
341 static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
326 static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>;
327 static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>;
342328
343 static_assert(__is_ratio<_R1>::value, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
344 static_assert(__is_ratio<_R2>::value, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
329 static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
330 static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
345331
346332public:
347333 typedef typename ratio_multiply<
......@@ -351,26 +337,26 @@ public:
351337 _R2::den > >::type type;
352338};
353339
354#ifndef _LIBCPP_CXX03_LANG
340# ifndef _LIBCPP_CXX03_LANG
355341
356342template <class _R1, class _R2>
357343using ratio_add = typename __ratio_add<_R1, _R2>::type;
358344
359#else // _LIBCPP_CXX03_LANG
345# else // _LIBCPP_CXX03_LANG
360346
361347template <class _R1, class _R2>
362348struct _LIBCPP_TEMPLATE_VIS ratio_add : public __ratio_add<_R1, _R2>::type {};
363349
364#endif // _LIBCPP_CXX03_LANG
350# endif // _LIBCPP_CXX03_LANG
365351
366352template <class _R1, class _R2>
367353struct __ratio_subtract {
368354private:
369 static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
370 static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
355 static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>;
356 static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>;
371357
372 static_assert(__is_ratio<_R1>::value, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
373 static_assert(__is_ratio<_R2>::value, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
358 static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
359 static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
374360
375361public:
376362 typedef typename ratio_multiply<
......@@ -380,30 +366,30 @@ public:
380366 _R2::den > >::type type;
381367};
382368
383#ifndef _LIBCPP_CXX03_LANG
369# ifndef _LIBCPP_CXX03_LANG
384370
385371template <class _R1, class _R2>
386372using ratio_subtract = typename __ratio_subtract<_R1, _R2>::type;
387373
388#else // _LIBCPP_CXX03_LANG
374# else // _LIBCPP_CXX03_LANG
389375
390376template <class _R1, class _R2>
391377struct _LIBCPP_TEMPLATE_VIS ratio_subtract : public __ratio_subtract<_R1, _R2>::type {};
392378
393#endif // _LIBCPP_CXX03_LANG
379# endif // _LIBCPP_CXX03_LANG
394380
395381// ratio_equal
396382
397383template <class _R1, class _R2>
398384struct _LIBCPP_TEMPLATE_VIS ratio_equal : _BoolConstant<(_R1::num == _R2::num && _R1::den == _R2::den)> {
399 static_assert(__is_ratio<_R1>::value, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
400 static_assert(__is_ratio<_R2>::value, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
385 static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
386 static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
401387};
402388
403389template <class _R1, class _R2>
404390struct _LIBCPP_TEMPLATE_VIS ratio_not_equal : _BoolConstant<!ratio_equal<_R1, _R2>::value> {
405 static_assert(__is_ratio<_R1>::value, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
406 static_assert(__is_ratio<_R2>::value, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
391 static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
392 static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
407393};
408394
409395// ratio_less
......@@ -439,10 +425,7 @@ struct __ratio_less1<_R1, _R2, _Odd, _Qp, _M1, _Qp, _M2> {
439425 static const bool value = __ratio_less1<ratio<_R1::den, _M1>, ratio<_R2::den, _M2>, !_Odd>::value;
440426};
441427
442template <class _R1,
443 class _R2,
444 intmax_t _S1 = __static_sign<_R1::num>::value,
445 intmax_t _S2 = __static_sign<_R2::num>::value>
428template <class _R1, class _R2, intmax_t _S1 = __static_sign<_R1::num>, intmax_t _S2 = __static_sign<_R2::num> >
446429struct __ratio_less {
447430 static const bool value = _S1 < _S2;
448431};
......@@ -459,34 +442,32 @@ struct __ratio_less<_R1, _R2, -1LL, -1LL> {
459442
460443template <class _R1, class _R2>
461444struct _LIBCPP_TEMPLATE_VIS ratio_less : _BoolConstant<__ratio_less<_R1, _R2>::value> {
462 static_assert(__is_ratio<_R1>::value, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
463 static_assert(__is_ratio<_R2>::value, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
445 static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
446 static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
464447};
465448
466449template <class _R1, class _R2>
467450struct _LIBCPP_TEMPLATE_VIS ratio_less_equal : _BoolConstant<!ratio_less<_R2, _R1>::value> {
468 static_assert(__is_ratio<_R1>::value, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
469 static_assert(__is_ratio<_R2>::value, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
451 static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
452 static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
470453};
471454
472455template <class _R1, class _R2>
473456struct _LIBCPP_TEMPLATE_VIS ratio_greater : _BoolConstant<ratio_less<_R2, _R1>::value> {
474 static_assert(__is_ratio<_R1>::value, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
475 static_assert(__is_ratio<_R2>::value, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
457 static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
458 static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
476459};
477460
478461template <class _R1, class _R2>
479462struct _LIBCPP_TEMPLATE_VIS ratio_greater_equal : _BoolConstant<!ratio_less<_R1, _R2>::value> {
480 static_assert(__is_ratio<_R1>::value, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
481 static_assert(__is_ratio<_R2>::value, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
463 static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
464 static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
482465};
483466
484467template <class _R1, class _R2>
485struct __ratio_gcd {
486 typedef ratio<__static_gcd<_R1::num, _R2::num>::value, __static_lcm<_R1::den, _R2::den>::value> type;
487};
468using __ratio_gcd _LIBCPP_NODEBUG = ratio<__static_gcd<_R1::num, _R2::num>, __static_lcm<_R1::den, _R2::den> >;
488469
489#if _LIBCPP_STD_VER >= 17
470# if _LIBCPP_STD_VER >= 17
490471template <class _R1, class _R2>
491472inline constexpr bool ratio_equal_v = ratio_equal<_R1, _R2>::value;
492473
......@@ -504,14 +485,15 @@ inline constexpr bool ratio_greater_v = ratio_greater<_R1, _R2>::value;
504485
505486template <class _R1, class _R2>
506487inline constexpr bool ratio_greater_equal_v = ratio_greater_equal<_R1, _R2>::value;
507#endif
488# endif
508489
509490_LIBCPP_END_NAMESPACE_STD
510491
511492_LIBCPP_POP_MACROS
512493
513#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
514# include <type_traits>
515#endif
494# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
495# include <type_traits>
496# endif
497#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
516498
517499#endif // _LIBCPP_RATIO
lib/libcxx/include/regex+164-161
......@@ -789,48 +789,51 @@ typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
789789} // std
790790*/
791791
792#include <__algorithm/find.h>
793#include <__algorithm/search.h>
794#include <__assert>
795#include <__config>
796#include <__iterator/back_insert_iterator.h>
797#include <__iterator/default_sentinel.h>
798#include <__iterator/wrap_iter.h>
799#include <__locale>
800#include <__memory/shared_ptr.h>
801#include <__memory_resource/polymorphic_allocator.h>
802#include <__type_traits/is_swappable.h>
803#include <__utility/move.h>
804#include <__utility/pair.h>
805#include <__utility/swap.h>
806#include <__verbose_abort>
807#include <deque>
808#include <stdexcept>
809#include <string>
810#include <vector>
811#include <version>
792#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
793# include <__cxx03/regex>
794#else
795# include <__algorithm/find.h>
796# include <__algorithm/search.h>
797# include <__assert>
798# include <__config>
799# include <__iterator/back_insert_iterator.h>
800# include <__iterator/default_sentinel.h>
801# include <__iterator/wrap_iter.h>
802# include <__locale>
803# include <__memory/shared_ptr.h>
804# include <__memory_resource/polymorphic_allocator.h>
805# include <__type_traits/is_swappable.h>
806# include <__utility/move.h>
807# include <__utility/pair.h>
808# include <__utility/swap.h>
809# include <__verbose_abort>
810# include <deque>
811# include <stdexcept>
812# include <string>
813# include <vector>
814# include <version>
812815
813816// standard-mandated includes
814817
815818// [iterator.range]
816#include <__iterator/access.h>
817#include <__iterator/data.h>
818#include <__iterator/empty.h>
819#include <__iterator/reverse_access.h>
820#include <__iterator/size.h>
819# include <__iterator/access.h>
820# include <__iterator/data.h>
821# include <__iterator/empty.h>
822# include <__iterator/reverse_access.h>
823# include <__iterator/size.h>
821824
822825// [re.syn]
823#include <compare>
824#include <initializer_list>
826# include <compare>
827# include <initializer_list>
825828
826#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
827# pragma GCC system_header
828#endif
829# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
830# pragma GCC system_header
831# endif
829832
830833_LIBCPP_PUSH_MACROS
831#include <__undef_macros>
834# include <__undef_macros>
832835
833#define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096
836# define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096
834837
835838_LIBCPP_BEGIN_NAMESPACE_STD
836839
......@@ -843,11 +846,11 @@ enum syntax_option_type {
843846 nosubs = 1 << 1,
844847 optimize = 1 << 2,
845848 collate = 1 << 3,
846#ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
849# ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
847850 ECMAScript = 1 << 9,
848#else
851# else
849852 ECMAScript = 0,
850#endif
853# endif
851854 basic = 1 << 4,
852855 extended = 1 << 5,
853856 awk = 1 << 6,
......@@ -858,11 +861,11 @@ enum syntax_option_type {
858861};
859862
860863_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR syntax_option_type __get_grammar(syntax_option_type __g) {
861#ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
864# ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
862865 return static_cast<syntax_option_type>(__g & 0x3F0);
863#else
866# else
864867 return static_cast<syntax_option_type>(__g & 0x1F0);
865#endif
868# endif
866869}
867870
868871inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR syntax_option_type operator~(syntax_option_type __x) {
......@@ -983,12 +986,12 @@ public:
983986};
984987
985988template <regex_constants::error_type _Ev>
986_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_regex_error() {
987#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
989[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_regex_error() {
990# if _LIBCPP_HAS_EXCEPTIONS
988991 throw regex_error(_Ev);
989#else
992# else
990993 _LIBCPP_VERBOSE_ABORT("regex_error was thrown in -fno-exceptions mode");
991#endif
994# endif
992995}
993996
994997template <class _CharT>
......@@ -997,7 +1000,7 @@ public:
9971000 typedef _CharT char_type;
9981001 typedef basic_string<char_type> string_type;
9991002 typedef locale locale_type;
1000#if defined(__BIONIC__) || defined(_NEWLIB_VERSION)
1003# if defined(__BIONIC__) || defined(_NEWLIB_VERSION)
10011004 // Originally bionic's ctype_base used its own ctype masks because the
10021005 // builtin ctype implementation wasn't in libc++ yet. Bionic's ctype mask
10031006 // was only 8 bits wide and already saturated, so it used a wider type here
......@@ -1012,9 +1015,9 @@ public:
10121015 // often used for space constrained environments, so it makes sense not to
10131016 // duplicate the ctype table.
10141017 typedef uint16_t char_class_type;
1015#else
1018# else
10161019 typedef ctype_base::mask char_class_type;
1017#endif
1020# endif
10181021
10191022 static const char_class_type __regex_word = ctype_base::__regex_word;
10201023
......@@ -1054,30 +1057,30 @@ private:
10541057
10551058 template <class _ForwardIterator>
10561059 string_type __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
1057#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1060# if _LIBCPP_HAS_WIDE_CHARACTERS
10581061 template <class _ForwardIterator>
10591062 string_type __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1060#endif
1063# endif
10611064 template <class _ForwardIterator>
10621065 string_type __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
1063#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1066# if _LIBCPP_HAS_WIDE_CHARACTERS
10641067 template <class _ForwardIterator>
10651068 string_type __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1066#endif
1069# endif
10671070 template <class _ForwardIterator>
10681071 char_class_type __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, char) const;
1069#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1072# if _LIBCPP_HAS_WIDE_CHARACTERS
10701073 template <class _ForwardIterator>
10711074 char_class_type __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, wchar_t) const;
1072#endif
1075# endif
10731076
10741077 static int __regex_traits_value(unsigned char __ch, int __radix);
10751078 _LIBCPP_HIDE_FROM_ABI int __regex_traits_value(char __ch, int __radix) const {
10761079 return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);
10771080 }
1078#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1081# if _LIBCPP_HAS_WIDE_CHARACTERS
10791082 _LIBCPP_HIDE_FROM_ABI int __regex_traits_value(wchar_t __ch, int __radix) const;
1080#endif
1083# endif
10811084};
10821085
10831086template <class _CharT>
......@@ -1136,7 +1139,7 @@ regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, _ForwardIterator
11361139 return __d;
11371140}
11381141
1139#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1142# if _LIBCPP_HAS_WIDE_CHARACTERS
11401143template <class _CharT>
11411144template <class _ForwardIterator>
11421145typename regex_traits<_CharT>::string_type
......@@ -1155,7 +1158,7 @@ regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, _ForwardIterator
11551158 }
11561159 return __d;
11571160}
1158#endif
1161# endif
11591162
11601163// lookup_collatename is very FreeBSD-specific
11611164
......@@ -1180,7 +1183,7 @@ regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, _ForwardIterato
11801183 return __r;
11811184}
11821185
1183#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1186# if _LIBCPP_HAS_WIDE_CHARACTERS
11841187template <class _CharT>
11851188template <class _ForwardIterator>
11861189typename regex_traits<_CharT>::string_type
......@@ -1208,7 +1211,7 @@ regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, _ForwardIterato
12081211 }
12091212 return __r;
12101213}
1211#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1214# endif // _LIBCPP_HAS_WIDE_CHARACTERS
12121215
12131216// lookup_classname
12141217
......@@ -1223,7 +1226,7 @@ regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, _ForwardIterator
12231226 return std::__get_classname(__s.c_str(), __icase);
12241227}
12251228
1226#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1229# if _LIBCPP_HAS_WIDE_CHARACTERS
12271230template <class _CharT>
12281231template <class _ForwardIterator>
12291232typename regex_traits<_CharT>::char_class_type
......@@ -1239,7 +1242,7 @@ regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, _ForwardIterator
12391242 }
12401243 return __get_classname(__n.c_str(), __icase);
12411244}
1242#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1245# endif // _LIBCPP_HAS_WIDE_CHARACTERS
12431246
12441247template <class _CharT>
12451248bool regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const {
......@@ -1250,28 +1253,28 @@ bool regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const {
12501253
12511254inline _LIBCPP_HIDE_FROM_ABI bool __is_07(unsigned char __c) {
12521255 return (__c & 0xF8u) ==
1253#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
1256# if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
12541257 0xF0;
1255#else
1258# else
12561259 0x30;
1257#endif
1260# endif
12581261}
12591262
12601263inline _LIBCPP_HIDE_FROM_ABI bool __is_89(unsigned char __c) {
12611264 return (__c & 0xFEu) ==
1262#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
1265# if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
12631266 0xF8;
1264#else
1267# else
12651268 0x38;
1266#endif
1269# endif
12671270}
12681271
12691272inline _LIBCPP_HIDE_FROM_ABI unsigned char __to_lower(unsigned char __c) {
1270#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
1273# if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
12711274 return __c & 0xBF;
1272#else
1275# else
12731276 return __c | 0x20;
1274#endif
1277# endif
12751278}
12761279
12771280template <class _CharT>
......@@ -1290,12 +1293,12 @@ int regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix)
12901293 return -1;
12911294}
12921295
1293#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1296# if _LIBCPP_HAS_WIDE_CHARACTERS
12941297template <class _CharT>
12951298inline int regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const {
12961299 return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
12971300}
1298#endif
1301# endif
12991302
13001303template <class _CharT>
13011304class __node;
......@@ -1938,10 +1941,10 @@ public:
19381941
19391942template <>
19401943_LIBCPP_EXPORTED_FROM_ABI void __match_any_but_newline<char>::__exec(__state&) const;
1941#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1944# if _LIBCPP_HAS_WIDE_CHARACTERS
19421945template <>
19431946_LIBCPP_EXPORTED_FROM_ABI void __match_any_but_newline<wchar_t>::__exec(__state&) const;
1944#endif
1947# endif
19451948
19461949// __match_char
19471950
......@@ -2262,9 +2265,9 @@ template <class _CharT, class _Traits = regex_traits<_CharT> >
22622265class _LIBCPP_TEMPLATE_VIS basic_regex;
22632266
22642267typedef basic_regex<char> regex;
2265#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2268# if _LIBCPP_HAS_WIDE_CHARACTERS
22662269typedef basic_regex<wchar_t> wregex;
2267#endif
2270# endif
22682271
22692272template <class _CharT, class _Traits>
22702273class _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(regex)
......@@ -2335,21 +2338,21 @@ public:
23352338 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
23362339 __init(__first, __last);
23372340 }
2338#ifndef _LIBCPP_CXX03_LANG
2341# ifndef _LIBCPP_CXX03_LANG
23392342 _LIBCPP_HIDE_FROM_ABI basic_regex(initializer_list<value_type> __il, flag_type __f = regex_constants::ECMAScript)
23402343 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
23412344 __init(__il.begin(), __il.end());
23422345 }
2343#endif // _LIBCPP_CXX03_LANG
2346# endif // _LIBCPP_CXX03_LANG
23442347
23452348 // ~basic_regex() = default;
23462349
23472350 // basic_regex& operator=(const basic_regex&) = default;
23482351 // basic_regex& operator=(basic_regex&&) = default;
23492352 _LIBCPP_HIDE_FROM_ABI basic_regex& operator=(const value_type* __p) { return assign(__p); }
2350#ifndef _LIBCPP_CXX03_LANG
2353# ifndef _LIBCPP_CXX03_LANG
23512354 _LIBCPP_HIDE_FROM_ABI basic_regex& operator=(initializer_list<value_type> __il) { return assign(__il); }
2352#endif // _LIBCPP_CXX03_LANG
2355# endif // _LIBCPP_CXX03_LANG
23532356 template <class _ST, class _SA>
23542357 _LIBCPP_HIDE_FROM_ABI basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p) {
23552358 return assign(__p);
......@@ -2357,9 +2360,9 @@ public:
23572360
23582361 // assign:
23592362 _LIBCPP_HIDE_FROM_ABI basic_regex& assign(const basic_regex& __that) { return *this = __that; }
2360#ifndef _LIBCPP_CXX03_LANG
2363# ifndef _LIBCPP_CXX03_LANG
23612364 _LIBCPP_HIDE_FROM_ABI basic_regex& assign(basic_regex&& __that) _NOEXCEPT { return *this = std::move(__that); }
2362#endif
2365# endif
23632366 _LIBCPP_HIDE_FROM_ABI basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript) {
23642367 return assign(__p, __p + __traits_.length(__p), __f);
23652368 }
......@@ -2396,14 +2399,14 @@ public:
23962399 return assign(basic_regex(__first, __last, __f));
23972400 }
23982401
2399#ifndef _LIBCPP_CXX03_LANG
2402# ifndef _LIBCPP_CXX03_LANG
24002403
24012404 _LIBCPP_HIDE_FROM_ABI basic_regex&
24022405 assign(initializer_list<value_type> __il, flag_type __f = regex_constants::ECMAScript) {
24032406 return assign(__il.begin(), __il.end(), __f);
24042407 }
24052408
2406#endif // _LIBCPP_CXX03_LANG
2409# endif // _LIBCPP_CXX03_LANG
24072410
24082411 // const operations:
24092412 _LIBCPP_HIDE_FROM_ABI unsigned mark_count() const { return __marked_count_; }
......@@ -2644,11 +2647,11 @@ private:
26442647 friend class __lookahead;
26452648};
26462649
2647#if _LIBCPP_STD_VER >= 17
2650# if _LIBCPP_STD_VER >= 17
26482651template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
26492652basic_regex(_ForwardIterator, _ForwardIterator, regex_constants::syntax_option_type = regex_constants::ECMAScript)
26502653 -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>;
2651#endif
2654# endif
26522655
26532656template <class _CharT, class _Traits>
26542657const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase;
......@@ -3921,7 +3924,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_character_escape(
39213924 if (__hd == -1)
39223925 __throw_regex_error<regex_constants::error_escape>();
39233926 __sum = 16 * __sum + static_cast<unsigned>(__hd);
3924 // fallthrough
3927 _LIBCPP_FALLTHROUGH();
39253928 case 'x':
39263929 ++__first;
39273930 if (__first == __last)
......@@ -4181,10 +4184,10 @@ void basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, bo
41814184
41824185typedef sub_match<const char*> csub_match;
41834186typedef sub_match<string::const_iterator> ssub_match;
4184#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4187# if _LIBCPP_HAS_WIDE_CHARACTERS
41854188typedef sub_match<const wchar_t*> wcsub_match;
41864189typedef sub_match<wstring::const_iterator> wssub_match;
4187#endif
4190# endif
41884191
41894192template <class _BidirectionalIterator>
41904193class _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(csub_match)
......@@ -4224,15 +4227,16 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator==(const sub_match<_BiIter>& __x, cons
42244227 return __x.compare(__y) == 0;
42254228}
42264229
4227#if _LIBCPP_STD_VER >= 20
4230# if _LIBCPP_STD_VER >= 20
42284231template <class _BiIter>
4229using __sub_match_cat = compare_three_way_result_t<basic_string<typename iterator_traits<_BiIter>::value_type>>;
4232using __sub_match_cat _LIBCPP_NODEBUG =
4233 compare_three_way_result_t<basic_string<typename iterator_traits<_BiIter>::value_type>>;
42304234
42314235template <class _BiIter>
42324236_LIBCPP_HIDE_FROM_ABI auto operator<=>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
42334237 return static_cast<__sub_match_cat<_BiIter>>(__x.compare(__y) <=> 0);
42344238}
4235#else // _LIBCPP_STD_VER >= 20
4239# else // _LIBCPP_STD_VER >= 20
42364240template <class _BiIter>
42374241inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
42384242 return !(__x == __y);
......@@ -4299,7 +4303,7 @@ operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST
42994303 const sub_match<_BiIter>& __y) {
43004304 return !(__y < __x);
43014305}
4302#endif // _LIBCPP_STD_VER >= 20
4306# endif // _LIBCPP_STD_VER >= 20
43034307
43044308template <class _BiIter, class _ST, class _SA>
43054309inline _LIBCPP_HIDE_FROM_ABI bool
......@@ -4308,7 +4312,7 @@ operator==(const sub_match<_BiIter>& __x,
43084312 return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0;
43094313}
43104314
4311#if _LIBCPP_STD_VER >= 20
4315# if _LIBCPP_STD_VER >= 20
43124316template <class _BiIter, class _ST, class _SA>
43134317_LIBCPP_HIDE_FROM_ABI auto
43144318operator<=>(const sub_match<_BiIter>& __x,
......@@ -4316,7 +4320,7 @@ operator<=>(const sub_match<_BiIter>& __x,
43164320 return static_cast<__sub_match_cat<_BiIter>>(
43174321 __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) <=> 0);
43184322}
4319#else // _LIBCPP_STD_VER >= 20
4323# else // _LIBCPP_STD_VER >= 20
43204324template <class _BiIter, class _ST, class _SA>
43214325inline _LIBCPP_HIDE_FROM_ABI bool
43224326operator!=(const sub_match<_BiIter>& __x,
......@@ -4387,7 +4391,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool
43874391operator<=(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
43884392 return !(__y < __x);
43894393}
4390#endif // _LIBCPP_STD_VER >= 20
4394# endif // _LIBCPP_STD_VER >= 20
43914395
43924396template <class _BiIter>
43934397inline _LIBCPP_HIDE_FROM_ABI bool
......@@ -4395,13 +4399,13 @@ operator==(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::val
43954399 return __x.compare(__y) == 0;
43964400}
43974401
4398#if _LIBCPP_STD_VER >= 20
4402# if _LIBCPP_STD_VER >= 20
43994403template <class _BiIter>
44004404_LIBCPP_HIDE_FROM_ABI auto
44014405operator<=>(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
44024406 return static_cast<__sub_match_cat<_BiIter>>(__x.compare(__y) <=> 0);
44034407}
4404#else // _LIBCPP_STD_VER >= 20
4408# else // _LIBCPP_STD_VER >= 20
44054409template <class _BiIter>
44064410inline _LIBCPP_HIDE_FROM_ABI bool
44074411operator!=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
......@@ -4469,7 +4473,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool
44694473operator<=(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
44704474 return !(__y < __x);
44714475}
4472#endif // _LIBCPP_STD_VER >= 20
4476# endif // _LIBCPP_STD_VER >= 20
44734477
44744478template <class _BiIter>
44754479inline _LIBCPP_HIDE_FROM_ABI bool
......@@ -4478,14 +4482,14 @@ operator==(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::val
44784482 return __x.compare(string_type(1, __y)) == 0;
44794483}
44804484
4481#if _LIBCPP_STD_VER >= 20
4485# if _LIBCPP_STD_VER >= 20
44824486template <class _BiIter>
44834487_LIBCPP_HIDE_FROM_ABI auto
44844488operator<=>(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
44854489 using string_type = basic_string<typename iterator_traits<_BiIter>::value_type>;
44864490 return static_cast<__sub_match_cat<_BiIter>>(__x.compare(string_type(1, __y)) <=> 0);
44874491}
4488#else // _LIBCPP_STD_VER >= 20
4492# else // _LIBCPP_STD_VER >= 20
44894493template <class _BiIter>
44904494inline _LIBCPP_HIDE_FROM_ABI bool
44914495operator!=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
......@@ -4516,7 +4520,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool
45164520operator<=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
45174521 return !(__y < __x);
45184522}
4519#endif // _LIBCPP_STD_VER >= 20
4523# endif // _LIBCPP_STD_VER >= 20
45204524
45214525template <class _CharT, class _ST, class _BiIter>
45224526inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _ST>&
......@@ -4526,10 +4530,10 @@ operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) {
45264530
45274531typedef match_results<const char*> cmatch;
45284532typedef match_results<string::const_iterator> smatch;
4529#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4533# if _LIBCPP_HAS_WIDE_CHARACTERS
45304534typedef match_results<const wchar_t*> wcmatch;
45314535typedef match_results<wstring::const_iterator> wsmatch;
4532#endif
4536# endif
45334537
45344538template <class _BidirectionalIterator, class _Allocator>
45354539class _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(cmatch) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcmatch))
......@@ -4559,12 +4563,12 @@ public:
45594563 typedef basic_string<char_type> string_type;
45604564
45614565 // construct/copy/destroy:
4562#ifndef _LIBCPP_CXX03_LANG
4566# ifndef _LIBCPP_CXX03_LANG
45634567 match_results() : match_results(allocator_type()) {}
45644568 explicit match_results(const allocator_type& __a);
4565#else
4569# else
45664570 explicit match_results(const allocator_type& __a = allocator_type());
4567#endif
4571# endif
45684572
45694573 // match_results(const match_results&) = default;
45704574 // match_results& operator=(const match_results&) = default;
......@@ -4577,7 +4581,7 @@ public:
45774581 // size:
45784582 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __matches_.size(); }
45794583 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __matches_.max_size(); }
4580 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return size() == 0; }
4584 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return size() == 0; }
45814585
45824586 // element access:
45834587 _LIBCPP_HIDE_FROM_ABI difference_type length(size_type __sub = 0) const {
......@@ -4814,13 +4818,13 @@ _LIBCPP_HIDE_FROM_ABI bool operator==(const match_results<_BidirectionalIterator
48144818 return __x.__matches_ == __y.__matches_ && __x.__prefix_ == __y.__prefix_ && __x.__suffix_ == __y.__suffix_;
48154819}
48164820
4817#if _LIBCPP_STD_VER < 20
4821# if _LIBCPP_STD_VER < 20
48184822template <class _BidirectionalIterator, class _Allocator>
48194823inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
48204824 const match_results<_BidirectionalIterator, _Allocator>& __y) {
48214825 return !(__x == __y);
48224826}
4823#endif
4827# endif
48244828
48254829template <class _BidirectionalIterator, class _Allocator>
48264830inline _LIBCPP_HIDE_FROM_ABI void
......@@ -5232,13 +5236,13 @@ regex_search(const basic_string<_CharT, _ST, _SA>& __s,
52325236 return __r;
52335237}
52345238
5235#if _LIBCPP_STD_VER >= 14
5239# if _LIBCPP_STD_VER >= 14
52365240template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
52375241bool regex_search(const basic_string<_Cp, _ST, _SA>&& __s,
52385242 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
52395243 const basic_regex<_Cp, _Tp>& __e,
52405244 regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
5241#endif
5245# endif
52425246
52435247// regex_match
52445248
......@@ -5287,14 +5291,14 @@ regex_match(const basic_string<_CharT, _ST, _SA>& __s,
52875291 return std::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
52885292}
52895293
5290#if _LIBCPP_STD_VER >= 14
5294# if _LIBCPP_STD_VER >= 14
52915295template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
52925296inline _LIBCPP_HIDE_FROM_ABI bool
52935297regex_match(const basic_string<_CharT, _ST, _SA>&& __s,
52945298 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
52955299 const basic_regex<_CharT, _Traits>& __e,
52965300 regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
5297#endif
5301# endif
52985302
52995303template <class _CharT, class _Traits>
53005304inline _LIBCPP_HIDE_FROM_ABI bool
......@@ -5321,10 +5325,10 @@ class _LIBCPP_TEMPLATE_VIS regex_iterator;
53215325
53225326typedef regex_iterator<const char*> cregex_iterator;
53235327typedef regex_iterator<string::const_iterator> sregex_iterator;
5324#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
5328# if _LIBCPP_HAS_WIDE_CHARACTERS
53255329typedef regex_iterator<const wchar_t*> wcregex_iterator;
53265330typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
5327#endif
5331# endif
53285332
53295333template <class _BidirectionalIterator, class _CharT, class _Traits>
53305334class _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(cregex_iterator)
......@@ -5337,9 +5341,9 @@ public:
53375341 typedef const value_type* pointer;
53385342 typedef const value_type& reference;
53395343 typedef forward_iterator_tag iterator_category;
5340#if _LIBCPP_STD_VER >= 20
5344# if _LIBCPP_STD_VER >= 20
53415345 typedef input_iterator_tag iterator_concept;
5342#endif
5346# endif
53435347
53445348private:
53455349 _BidirectionalIterator __begin_;
......@@ -5354,20 +5358,20 @@ public:
53545358 _BidirectionalIterator __b,
53555359 const regex_type& __re,
53565360 regex_constants::match_flag_type __m = regex_constants::match_default);
5357#if _LIBCPP_STD_VER >= 14
5361# if _LIBCPP_STD_VER >= 14
53585362 regex_iterator(_BidirectionalIterator __a,
53595363 _BidirectionalIterator __b,
53605364 const regex_type&& __re,
53615365 regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
5362#endif
5366# endif
53635367
53645368 _LIBCPP_HIDE_FROM_ABI bool operator==(const regex_iterator& __x) const;
5365#if _LIBCPP_STD_VER >= 20
5369# if _LIBCPP_STD_VER >= 20
53665370 _LIBCPP_HIDE_FROM_ABI bool operator==(default_sentinel_t) const { return *this == regex_iterator(); }
5367#endif
5368#if _LIBCPP_STD_VER < 20
5371# endif
5372# if _LIBCPP_STD_VER < 20
53695373 _LIBCPP_HIDE_FROM_ABI bool operator!=(const regex_iterator& __x) const { return !(*this == __x); }
5370#endif
5374# endif
53715375
53725376 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __match_; }
53735377 _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return std::addressof(__match_); }
......@@ -5451,10 +5455,10 @@ class _LIBCPP_TEMPLATE_VIS regex_token_iterator;
54515455
54525456typedef regex_token_iterator<const char*> cregex_token_iterator;
54535457typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
5454#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
5458# if _LIBCPP_HAS_WIDE_CHARACTERS
54555459typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
54565460typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
5457#endif
5461# endif
54585462
54595463template <class _BidirectionalIterator, class _CharT, class _Traits>
54605464class _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(cregex_token_iterator)
......@@ -5468,9 +5472,9 @@ public:
54685472 typedef const value_type* pointer;
54695473 typedef const value_type& reference;
54705474 typedef forward_iterator_tag iterator_category;
5471#if _LIBCPP_STD_VER >= 20
5475# if _LIBCPP_STD_VER >= 20
54725476 typedef input_iterator_tag iterator_concept;
5473#endif
5477# endif
54745478
54755479private:
54765480 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
......@@ -5488,69 +5492,67 @@ public:
54885492 const regex_type& __re,
54895493 int __submatch = 0,
54905494 regex_constants::match_flag_type __m = regex_constants::match_default);
5491#if _LIBCPP_STD_VER >= 14
5495# if _LIBCPP_STD_VER >= 14
54925496 regex_token_iterator(_BidirectionalIterator __a,
54935497 _BidirectionalIterator __b,
54945498 const regex_type&& __re,
54955499 int __submatch = 0,
54965500 regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
5497#endif
5501# endif
54985502
54995503 regex_token_iterator(_BidirectionalIterator __a,
55005504 _BidirectionalIterator __b,
55015505 const regex_type& __re,
55025506 const vector<int>& __submatches,
55035507 regex_constants::match_flag_type __m = regex_constants::match_default);
5504#if _LIBCPP_STD_VER >= 14
5508# if _LIBCPP_STD_VER >= 14
55055509 regex_token_iterator(_BidirectionalIterator __a,
55065510 _BidirectionalIterator __b,
55075511 const regex_type&& __re,
55085512 const vector<int>& __submatches,
55095513 regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
5510#endif
5514# endif
55115515
5512#ifndef _LIBCPP_CXX03_LANG
5516# ifndef _LIBCPP_CXX03_LANG
55135517 regex_token_iterator(_BidirectionalIterator __a,
55145518 _BidirectionalIterator __b,
55155519 const regex_type& __re,
55165520 initializer_list<int> __submatches,
55175521 regex_constants::match_flag_type __m = regex_constants::match_default);
55185522
5519# if _LIBCPP_STD_VER >= 14
5523# if _LIBCPP_STD_VER >= 14
55205524 regex_token_iterator(_BidirectionalIterator __a,
55215525 _BidirectionalIterator __b,
55225526 const regex_type&& __re,
55235527 initializer_list<int> __submatches,
55245528 regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
5525# endif
5526#endif // _LIBCPP_CXX03_LANG
5529# endif
5530# endif // _LIBCPP_CXX03_LANG
55275531 template <size_t _Np>
55285532 regex_token_iterator(_BidirectionalIterator __a,
55295533 _BidirectionalIterator __b,
55305534 const regex_type& __re,
55315535 const int (&__submatches)[_Np],
55325536 regex_constants::match_flag_type __m = regex_constants::match_default);
5533#if _LIBCPP_STD_VER >= 14
5537# if _LIBCPP_STD_VER >= 14
55345538 template <size_t _Np>
55355539 regex_token_iterator(_BidirectionalIterator __a,
55365540 _BidirectionalIterator __b,
55375541 const regex_type&& __re,
55385542 const int (&__submatches)[_Np],
55395543 regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
5540#endif
5544# endif
55415545
55425546 regex_token_iterator(const regex_token_iterator&);
55435547 regex_token_iterator& operator=(const regex_token_iterator&);
55445548
55455549 _LIBCPP_HIDE_FROM_ABI bool operator==(const regex_token_iterator& __x) const;
5546#if _LIBCPP_STD_VER >= 20
5547 _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool operator==(default_sentinel_t) const {
5548 return *this == regex_token_iterator();
5549 }
5550#endif
5551#if _LIBCPP_STD_VER < 20
5550# if _LIBCPP_STD_VER >= 20
5551 _LIBCPP_HIDE_FROM_ABI bool operator==(default_sentinel_t) const { return *this == regex_token_iterator(); }
5552# endif
5553# if _LIBCPP_STD_VER < 20
55525554 _LIBCPP_HIDE_FROM_ABI bool operator!=(const regex_token_iterator& __x) const { return !(*this == __x); }
5553#endif
5555# endif
55545556
55555557 _LIBCPP_HIDE_FROM_ABI const value_type& operator*() const { return *__result_; }
55565558 _LIBCPP_HIDE_FROM_ABI const value_type* operator->() const { return __result_; }
......@@ -5612,7 +5614,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_itera
56125614 __init(__a, __b);
56135615}
56145616
5615#ifndef _LIBCPP_CXX03_LANG
5617# ifndef _LIBCPP_CXX03_LANG
56165618
56175619template <class _BidirectionalIterator, class _CharT, class _Traits>
56185620regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator(
......@@ -5625,7 +5627,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_itera
56255627 __init(__a, __b);
56265628}
56275629
5628#endif // _LIBCPP_CXX03_LANG
5630# endif // _LIBCPP_CXX03_LANG
56295631
56305632template <class _BidirectionalIterator, class _CharT, class _Traits>
56315633template <size_t _Np>
......@@ -5800,7 +5802,7 @@ regex_replace(const _CharT* __s,
58005802
58015803_LIBCPP_END_NAMESPACE_STD
58025804
5803#if _LIBCPP_STD_VER >= 17
5805# if _LIBCPP_STD_VER >= 17
58045806_LIBCPP_BEGIN_NAMESPACE_STD
58055807namespace pmr {
58065808template <class _BidirT>
......@@ -5810,27 +5812,28 @@ using match_results _LIBCPP_AVAILABILITY_PMR =
58105812using cmatch _LIBCPP_AVAILABILITY_PMR = match_results<const char*>;
58115813using smatch _LIBCPP_AVAILABILITY_PMR = match_results<std::pmr::string::const_iterator>;
58125814
5813# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
5815# if _LIBCPP_HAS_WIDE_CHARACTERS
58145816using wcmatch _LIBCPP_AVAILABILITY_PMR = match_results<const wchar_t*>;
58155817using wsmatch _LIBCPP_AVAILABILITY_PMR = match_results<std::pmr::wstring::const_iterator>;
5816# endif
5818# endif
58175819} // namespace pmr
58185820_LIBCPP_END_NAMESPACE_STD
5819#endif
5821# endif
58205822
58215823_LIBCPP_POP_MACROS
58225824
5823#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
5824# include <atomic>
5825# include <concepts>
5826# include <cstdlib>
5827# include <iosfwd>
5828# include <iterator>
5829# include <mutex>
5830# include <new>
5831# include <type_traits>
5832# include <typeinfo>
5833# include <utility>
5834#endif
5825# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
5826# include <atomic>
5827# include <concepts>
5828# include <cstdlib>
5829# include <iosfwd>
5830# include <iterator>
5831# include <mutex>
5832# include <new>
5833# include <type_traits>
5834# include <typeinfo>
5835# include <utility>
5836# endif
5837#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
58355838
58365839#endif // _LIBCPP_REGEX
lib/libcxx/include/scoped_allocator+48-44
......@@ -109,32 +109,35 @@ template <class OuterA1, class OuterA2, class... InnerAllocs>
109109
110110*/
111111
112#include <__config>
113#include <__memory/allocator_traits.h>
114#include <__memory/uses_allocator_construction.h>
115#include <__type_traits/common_type.h>
116#include <__type_traits/enable_if.h>
117#include <__type_traits/integral_constant.h>
118#include <__type_traits/is_constructible.h>
119#include <__type_traits/remove_reference.h>
120#include <__utility/declval.h>
121#include <__utility/forward.h>
122#include <__utility/move.h>
123#include <__utility/pair.h>
124#include <__utility/piecewise_construct.h>
125#include <tuple>
126#include <version>
127
128#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
129# pragma GCC system_header
130#endif
112#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
113# include <__cxx03/scoped_allocator>
114#else
115# include <__config>
116# include <__memory/allocator_traits.h>
117# include <__memory/uses_allocator_construction.h>
118# include <__type_traits/common_type.h>
119# include <__type_traits/enable_if.h>
120# include <__type_traits/integral_constant.h>
121# include <__type_traits/is_constructible.h>
122# include <__type_traits/remove_reference.h>
123# include <__utility/declval.h>
124# include <__utility/forward.h>
125# include <__utility/move.h>
126# include <__utility/pair.h>
127# include <__utility/piecewise_construct.h>
128# include <tuple>
129# include <version>
130
131# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
132# pragma GCC system_header
133# endif
131134
132135_LIBCPP_PUSH_MACROS
133#include <__undef_macros>
136# include <__undef_macros>
134137
135138_LIBCPP_BEGIN_NAMESPACE_STD
136139
137#if !defined(_LIBCPP_CXX03_LANG)
140# if !defined(_LIBCPP_CXX03_LANG)
138141
139142// scoped_allocator_adaptor
140143
......@@ -389,10 +392,10 @@ public:
389392 return _Base::outer_allocator();
390393 }
391394
392 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI pointer allocate(size_type __n) {
395 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI pointer allocate(size_type __n) {
393396 return allocator_traits<outer_allocator_type>::allocate(outer_allocator(), __n);
394397 }
395 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI pointer allocate(size_type __n, const_void_pointer __hint) {
398 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI pointer allocate(size_type __n, const_void_pointer __hint) {
396399 return allocator_traits<outer_allocator_type>::allocate(outer_allocator(), __n, __hint);
397400 }
398401
......@@ -404,7 +407,7 @@ public:
404407 return allocator_traits<outer_allocator_type>::max_size(outer_allocator());
405408 }
406409
407# if _LIBCPP_STD_VER >= 20
410# if _LIBCPP_STD_VER >= 20
408411 template <class _Type, class... _Args>
409412 _LIBCPP_HIDE_FROM_ABI void construct(_Type* __ptr, _Args&&... __args) {
410413 using _OM = __outermost<outer_allocator_type>;
......@@ -415,7 +418,7 @@ public:
415418 },
416419 std::uses_allocator_construction_args<_Type>(inner_allocator(), std::forward<_Args>(__args)...));
417420 }
418# else
421# else
419422 template <class _Tp, class... _Args>
420423 _LIBCPP_HIDE_FROM_ABI void construct(_Tp* __p, _Args&&... __args) {
421424 __construct(__uses_alloc_ctor<_Tp, inner_allocator_type&, _Args...>(), __p, std::forward<_Args>(__args)...);
......@@ -462,7 +465,7 @@ public:
462465 std::forward_as_tuple(std::forward<_Up>(__x.first)),
463466 std::forward_as_tuple(std::forward<_Vp>(__x.second)));
464467 }
465# endif
468# endif
466469
467470 template <class _Tp>
468471 _LIBCPP_HIDE_FROM_ABI void destroy(_Tp* __p) {
......@@ -522,10 +525,10 @@ private:
522525 friend class __scoped_allocator_storage;
523526};
524527
525# if _LIBCPP_STD_VER >= 17
528# if _LIBCPP_STD_VER >= 17
526529template <class _OuterAlloc, class... _InnerAllocs>
527530scoped_allocator_adaptor(_OuterAlloc, _InnerAllocs...) -> scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>;
528# endif
531# endif
529532
530533template <class _OuterA1, class _OuterA2>
531534inline _LIBCPP_HIDE_FROM_ABI bool
......@@ -540,7 +543,7 @@ operator==(const scoped_allocator_adaptor<_OuterA1, _InnerA0, _InnerAllocs...>&
540543 return __a.outer_allocator() == __b.outer_allocator() && __a.inner_allocator() == __b.inner_allocator();
541544}
542545
543# if _LIBCPP_STD_VER <= 17
546# if _LIBCPP_STD_VER <= 17
544547
545548template <class _OuterA1, class _OuterA2, class... _InnerAllocs>
546549inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const scoped_allocator_adaptor<_OuterA1, _InnerAllocs...>& __a,
......@@ -548,26 +551,27 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const scoped_allocator_adaptor<_Out
548551 return !(__a == __b);
549552}
550553
551# endif // _LIBCPP_STD_VER <= 17
554# endif // _LIBCPP_STD_VER <= 17
552555
553#endif // !defined(_LIBCPP_CXX03_LANG)
556# endif // !defined(_LIBCPP_CXX03_LANG)
554557
555558_LIBCPP_END_NAMESPACE_STD
556559
557560_LIBCPP_POP_MACROS
558561
559#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
560# include <atomic>
561# include <climits>
562# include <concepts>
563# include <cstring>
564# include <ctime>
565# include <iterator>
566# include <memory>
567# include <ratio>
568# include <stdexcept>
569# include <type_traits>
570# include <variant>
571#endif
562# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
563# include <atomic>
564# include <climits>
565# include <concepts>
566# include <cstring>
567# include <ctime>
568# include <iterator>
569# include <memory>
570# include <ratio>
571# include <stdexcept>
572# include <type_traits>
573# include <variant>
574# endif
575#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
572576
573577#endif // _LIBCPP_SCOPED_ALLOCATOR
lib/libcxx/include/semaphore+41-37
......@@ -16,7 +16,7 @@
1616namespace std {
1717
1818template<ptrdiff_t least_max_value = implementation-defined>
19class counting_semaphore
19class counting_semaphore // since C++20
2020{
2121public:
2222static constexpr ptrdiff_t max() noexcept;
......@@ -39,36 +39,39 @@ private:
3939ptrdiff_t counter; // exposition only
4040};
4141
42using binary_semaphore = counting_semaphore<1>;
42using binary_semaphore = counting_semaphore<1>; // since C++20
4343
4444}
4545
4646*/
4747
48#include <__config>
49
50#if !defined(_LIBCPP_HAS_NO_THREADS)
51
52# include <__assert>
53# include <__atomic/atomic_base.h>
54# include <__atomic/atomic_sync.h>
55# include <__atomic/memory_order.h>
56# include <__chrono/time_point.h>
57# include <__thread/poll_with_backoff.h>
58# include <__thread/support.h>
59# include <__thread/timed_backoff_policy.h>
60# include <cstddef>
61# include <limits>
62# include <version>
63
64# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
65# pragma GCC system_header
66# endif
48#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
49# include <__cxx03/semaphore>
50#else
51# include <__config>
52
53# if _LIBCPP_HAS_THREADS
54
55# include <__assert>
56# include <__atomic/atomic.h>
57# include <__atomic/atomic_sync.h>
58# include <__atomic/memory_order.h>
59# include <__chrono/time_point.h>
60# include <__cstddef/ptrdiff_t.h>
61# include <__thread/poll_with_backoff.h>
62# include <__thread/support.h>
63# include <__thread/timed_backoff_policy.h>
64# include <limits>
65# include <version>
66
67# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
68# pragma GCC system_header
69# endif
6770
6871_LIBCPP_PUSH_MACROS
69# include <__undef_macros>
72# include <__undef_macros>
7073
71# if _LIBCPP_STD_VER >= 14
74# if _LIBCPP_STD_VER >= 20
7275
7376_LIBCPP_BEGIN_NAMESPACE_STD
7477
......@@ -80,10 +83,10 @@ functions. It avoids contention against users' own use of those facilities.
8083
8184*/
8285
83# define _LIBCPP_SEMAPHORE_MAX (numeric_limits<ptrdiff_t>::max())
86# define _LIBCPP_SEMAPHORE_MAX (numeric_limits<ptrdiff_t>::max())
8487
8588class __atomic_semaphore_base {
86 __atomic_base<ptrdiff_t> __a_;
89 atomic<ptrdiff_t> __a_;
8790
8891public:
8992 _LIBCPP_HIDE_FROM_ABI constexpr explicit __atomic_semaphore_base(ptrdiff_t __count) : __a_(__count) {}
......@@ -96,8 +99,9 @@ public:
9699 }
97100 }
98101 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void acquire() {
99 std::__atomic_wait_unless(
100 __a_, [this](ptrdiff_t& __old) { return __try_acquire_impl(__old); }, memory_order_relaxed);
102 std::__atomic_wait_unless(__a_, memory_order_relaxed, [this](ptrdiff_t& __old) {
103 return __try_acquire_impl(__old);
104 });
101105 }
102106 template <class _Rep, class _Period>
103107 _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI bool
......@@ -124,7 +128,7 @@ private:
124128};
125129
126130template <ptrdiff_t __least_max_value = _LIBCPP_SEMAPHORE_MAX>
127class _LIBCPP_DEPRECATED_ATOMIC_SYNC counting_semaphore {
131class counting_semaphore {
128132 __atomic_semaphore_base __semaphore_;
129133
130134public:
......@@ -169,20 +173,20 @@ public:
169173 }
170174};
171175
172_LIBCPP_SUPPRESS_DEPRECATED_PUSH
173using binary_semaphore _LIBCPP_DEPRECATED_ATOMIC_SYNC = counting_semaphore<1>;
174_LIBCPP_SUPPRESS_DEPRECATED_POP
176using binary_semaphore = counting_semaphore<1>;
175177
176178_LIBCPP_END_NAMESPACE_STD
177179
178# endif // _LIBCPP_STD_VER >= 14
180# endif // _LIBCPP_STD_VER >= 20
179181
180182_LIBCPP_POP_MACROS
181183
182#endif // !defined(_LIBCPP_HAS_NO_THREADS)
184# endif // _LIBCPP_HAS_THREADS
183185
184#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
185# include <atomic>
186#endif
186# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
187# include <atomic>
188# include <cstddef>
189# endif
190#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
187191
188#endif //_LIBCPP_SEMAPHORE
192#endif // _LIBCPP_SEMAPHORE
lib/libcxx/include/set+167-138
......@@ -512,47 +512,60 @@ erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
512512
513513*/
514514
515#include <__algorithm/equal.h>
516#include <__algorithm/lexicographical_compare.h>
517#include <__algorithm/lexicographical_compare_three_way.h>
518#include <__assert>
519#include <__config>
520#include <__functional/is_transparent.h>
521#include <__functional/operations.h>
522#include <__iterator/erase_if_container.h>
523#include <__iterator/iterator_traits.h>
524#include <__iterator/ranges_iterator_traits.h>
525#include <__iterator/reverse_iterator.h>
526#include <__memory/allocator.h>
527#include <__memory_resource/polymorphic_allocator.h>
528#include <__node_handle>
529#include <__ranges/concepts.h>
530#include <__ranges/container_compatible_range.h>
531#include <__ranges/from_range.h>
532#include <__tree>
533#include <__type_traits/is_allocator.h>
534#include <__utility/forward.h>
535#include <version>
515#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
516# include <__cxx03/set>
517#else
518# include <__algorithm/equal.h>
519# include <__algorithm/lexicographical_compare.h>
520# include <__algorithm/lexicographical_compare_three_way.h>
521# include <__assert>
522# include <__config>
523# include <__functional/is_transparent.h>
524# include <__functional/operations.h>
525# include <__iterator/erase_if_container.h>
526# include <__iterator/iterator_traits.h>
527# include <__iterator/ranges_iterator_traits.h>
528# include <__iterator/reverse_iterator.h>
529# include <__memory/allocator.h>
530# include <__memory/allocator_traits.h>
531# include <__memory_resource/polymorphic_allocator.h>
532# include <__node_handle>
533# include <__ranges/concepts.h>
534# include <__ranges/container_compatible_range.h>
535# include <__ranges/from_range.h>
536# include <__tree>
537# include <__type_traits/container_traits.h>
538# include <__type_traits/enable_if.h>
539# include <__type_traits/is_allocator.h>
540# include <__type_traits/is_nothrow_assignable.h>
541# include <__type_traits/is_nothrow_constructible.h>
542# include <__type_traits/is_same.h>
543# include <__type_traits/is_swappable.h>
544# include <__type_traits/type_identity.h>
545# include <__utility/forward.h>
546# include <__utility/move.h>
547# include <__utility/pair.h>
548# include <version>
536549
537550// standard-mandated includes
538551
539552// [iterator.range]
540#include <__iterator/access.h>
541#include <__iterator/data.h>
542#include <__iterator/empty.h>
543#include <__iterator/reverse_access.h>
544#include <__iterator/size.h>
553# include <__iterator/access.h>
554# include <__iterator/data.h>
555# include <__iterator/empty.h>
556# include <__iterator/reverse_access.h>
557# include <__iterator/size.h>
545558
546559// [associative.set.syn]
547#include <compare>
548#include <initializer_list>
560# include <compare>
561# include <initializer_list>
549562
550#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
551# pragma GCC system_header
552#endif
563# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
564# pragma GCC system_header
565# endif
553566
554567_LIBCPP_PUSH_MACROS
555#include <__undef_macros>
568# include <__undef_macros>
556569
557570_LIBCPP_BEGIN_NAMESPACE_STD
558571
......@@ -592,10 +605,10 @@ public:
592605 typedef std::reverse_iterator<iterator> reverse_iterator;
593606 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
594607
595#if _LIBCPP_STD_VER >= 17
608# if _LIBCPP_STD_VER >= 17
596609 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
597610 typedef __insert_return_type<iterator, node_type> insert_return_type;
598#endif
611# endif
599612
600613 template <class _Key2, class _Compare2, class _Alloc2>
601614 friend class _LIBCPP_TEMPLATE_VIS set;
......@@ -625,7 +638,7 @@ public:
625638 insert(__f, __l);
626639 }
627640
628#if _LIBCPP_STD_VER >= 23
641# if _LIBCPP_STD_VER >= 23
629642 template <_ContainerCompatibleRange<value_type> _Range>
630643 _LIBCPP_HIDE_FROM_ABI
631644 set(from_range_t,
......@@ -635,19 +648,19 @@ public:
635648 : __tree_(__comp, __a) {
636649 insert_range(std::forward<_Range>(__range));
637650 }
638#endif
651# endif
639652
640#if _LIBCPP_STD_VER >= 14
653# if _LIBCPP_STD_VER >= 14
641654 template <class _InputIterator>
642655 _LIBCPP_HIDE_FROM_ABI set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
643656 : set(__f, __l, key_compare(), __a) {}
644#endif
657# endif
645658
646#if _LIBCPP_STD_VER >= 23
659# if _LIBCPP_STD_VER >= 23
647660 template <_ContainerCompatibleRange<value_type> _Range>
648661 _LIBCPP_HIDE_FROM_ABI set(from_range_t, _Range&& __range, const allocator_type& __a)
649662 : set(from_range, std::forward<_Range>(__range), key_compare(), __a) {}
650#endif
663# endif
651664
652665 _LIBCPP_HIDE_FROM_ABI set(const set& __s) : __tree_(__s.__tree_) { insert(__s.begin(), __s.end()); }
653666
......@@ -656,10 +669,10 @@ public:
656669 return *this;
657670 }
658671
659#ifndef _LIBCPP_CXX03_LANG
672# ifndef _LIBCPP_CXX03_LANG
660673 _LIBCPP_HIDE_FROM_ABI set(set&& __s) noexcept(is_nothrow_move_constructible<__base>::value)
661674 : __tree_(std::move(__s.__tree_)) {}
662#endif // _LIBCPP_CXX03_LANG
675# endif // _LIBCPP_CXX03_LANG
663676
664677 _LIBCPP_HIDE_FROM_ABI explicit set(const allocator_type& __a) : __tree_(__a) {}
665678
......@@ -667,7 +680,7 @@ public:
667680 insert(__s.begin(), __s.end());
668681 }
669682
670#ifndef _LIBCPP_CXX03_LANG
683# ifndef _LIBCPP_CXX03_LANG
671684 _LIBCPP_HIDE_FROM_ABI set(set&& __s, const allocator_type& __a);
672685
673686 _LIBCPP_HIDE_FROM_ABI set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
......@@ -680,10 +693,10 @@ public:
680693 insert(__il.begin(), __il.end());
681694 }
682695
683# if _LIBCPP_STD_VER >= 14
696# if _LIBCPP_STD_VER >= 14
684697 _LIBCPP_HIDE_FROM_ABI set(initializer_list<value_type> __il, const allocator_type& __a)
685698 : set(__il, key_compare(), __a) {}
686# endif
699# endif
687700
688701 _LIBCPP_HIDE_FROM_ABI set& operator=(initializer_list<value_type> __il) {
689702 __tree_.__assign_unique(__il.begin(), __il.end());
......@@ -694,7 +707,7 @@ public:
694707 __tree_ = std::move(__s.__tree_);
695708 return *this;
696709 }
697#endif // _LIBCPP_CXX03_LANG
710# endif // _LIBCPP_CXX03_LANG
698711
699712 _LIBCPP_HIDE_FROM_ABI ~set() { static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); }
700713
......@@ -713,12 +726,12 @@ public:
713726 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return rbegin(); }
714727 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
715728
716 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __tree_.size() == 0; }
729 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __tree_.size() == 0; }
717730 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __tree_.size(); }
718731 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __tree_.max_size(); }
719732
720733 // modifiers:
721#ifndef _LIBCPP_CXX03_LANG
734# ifndef _LIBCPP_CXX03_LANG
722735 template <class... _Args>
723736 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> emplace(_Args&&... __args) {
724737 return __tree_.__emplace_unique(std::forward<_Args>(__args)...);
......@@ -727,7 +740,7 @@ public:
727740 _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __p, _Args&&... __args) {
728741 return __tree_.__emplace_hint_unique(__p, std::forward<_Args>(__args)...);
729742 }
730#endif // _LIBCPP_CXX03_LANG
743# endif // _LIBCPP_CXX03_LANG
731744
732745 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __v) { return __tree_.__insert_unique(__v); }
733746 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
......@@ -740,7 +753,7 @@ public:
740753 __tree_.__insert_unique(__e, *__f);
741754 }
742755
743#if _LIBCPP_STD_VER >= 23
756# if _LIBCPP_STD_VER >= 23
744757 template <_ContainerCompatibleRange<value_type> _Range>
745758 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
746759 const_iterator __end = cend();
......@@ -748,9 +761,9 @@ public:
748761 __tree_.__insert_unique(__end, std::forward<decltype(__element)>(__element));
749762 }
750763 }
751#endif
764# endif
752765
753#ifndef _LIBCPP_CXX03_LANG
766# ifndef _LIBCPP_CXX03_LANG
754767 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __v) {
755768 return __tree_.__insert_unique(std::move(__v));
756769 }
......@@ -760,14 +773,14 @@ public:
760773 }
761774
762775 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
763#endif // _LIBCPP_CXX03_LANG
776# endif // _LIBCPP_CXX03_LANG
764777
765778 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __tree_.erase(__p); }
766779 _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __tree_.__erase_unique(__k); }
767780 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l) { return __tree_.erase(__f, __l); }
768781 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __tree_.clear(); }
769782
770#if _LIBCPP_STD_VER >= 17
783# if _LIBCPP_STD_VER >= 17
771784 _LIBCPP_HIDE_FROM_ABI insert_return_type insert(node_type&& __nh) {
772785 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
773786 "node_type with incompatible allocator passed to set::insert()");
......@@ -808,7 +821,7 @@ public:
808821 __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
809822 __tree_.__node_handle_merge_unique(__source.__tree_);
810823 }
811#endif
824# endif
812825
813826 _LIBCPP_HIDE_FROM_ABI void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable_v<__base>) { __tree_.swap(__s.__tree_); }
814827
......@@ -819,7 +832,7 @@ public:
819832 // set operations:
820833 _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __tree_.find(__k); }
821834 _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __tree_.find(__k); }
822#if _LIBCPP_STD_VER >= 14
835# if _LIBCPP_STD_VER >= 14
823836 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
824837 _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
825838 return __tree_.find(__k);
......@@ -828,27 +841,27 @@ public:
828841 _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
829842 return __tree_.find(__k);
830843 }
831#endif
844# endif
832845
833846 _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __tree_.__count_unique(__k); }
834#if _LIBCPP_STD_VER >= 14
847# if _LIBCPP_STD_VER >= 14
835848 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
836849 _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
837850 return __tree_.__count_multi(__k);
838851 }
839#endif
852# endif
840853
841#if _LIBCPP_STD_VER >= 20
854# if _LIBCPP_STD_VER >= 20
842855 _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
843856 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
844857 _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
845858 return find(__k) != end();
846859 }
847#endif // _LIBCPP_STD_VER >= 20
860# endif // _LIBCPP_STD_VER >= 20
848861
849862 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __k) { return __tree_.lower_bound(__k); }
850863 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __k) const { return __tree_.lower_bound(__k); }
851#if _LIBCPP_STD_VER >= 14
864# if _LIBCPP_STD_VER >= 14
852865 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
853866 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _K2& __k) {
854867 return __tree_.lower_bound(__k);
......@@ -858,11 +871,11 @@ public:
858871 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _K2& __k) const {
859872 return __tree_.lower_bound(__k);
860873 }
861#endif
874# endif
862875
863876 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __k) { return __tree_.upper_bound(__k); }
864877 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __k) const { return __tree_.upper_bound(__k); }
865#if _LIBCPP_STD_VER >= 14
878# if _LIBCPP_STD_VER >= 14
866879 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
867880 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _K2& __k) {
868881 return __tree_.upper_bound(__k);
......@@ -871,7 +884,7 @@ public:
871884 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _K2& __k) const {
872885 return __tree_.upper_bound(__k);
873886 }
874#endif
887# endif
875888
876889 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
877890 return __tree_.__equal_range_unique(__k);
......@@ -879,7 +892,7 @@ public:
879892 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
880893 return __tree_.__equal_range_unique(__k);
881894 }
882#if _LIBCPP_STD_VER >= 14
895# if _LIBCPP_STD_VER >= 14
883896 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
884897 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
885898 return __tree_.__equal_range_multi(__k);
......@@ -888,10 +901,10 @@ public:
888901 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
889902 return __tree_.__equal_range_multi(__k);
890903 }
891#endif
904# endif
892905};
893906
894#if _LIBCPP_STD_VER >= 17
907# if _LIBCPP_STD_VER >= 17
895908template <class _InputIterator,
896909 class _Compare = less<__iter_value_type<_InputIterator>>,
897910 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
......@@ -901,7 +914,7 @@ template <class _InputIterator,
901914set(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
902915 -> set<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
903916
904# if _LIBCPP_STD_VER >= 23
917# if _LIBCPP_STD_VER >= 23
905918template <ranges::input_range _Range,
906919 class _Compare = less<ranges::range_value_t<_Range>>,
907920 class _Allocator = allocator<ranges::range_value_t<_Range>>,
......@@ -909,7 +922,7 @@ template <ranges::input_range _Range,
909922 class = enable_if_t<!__is_allocator<_Compare>::value, void>>
910923set(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator())
911924 -> set<ranges::range_value_t<_Range>, _Compare, _Allocator>;
912# endif
925# endif
913926
914927template <class _Key,
915928 class _Compare = less<_Key>,
......@@ -926,18 +939,18 @@ set(_InputIterator,
926939 _InputIterator,
927940 _Allocator) -> set<__iter_value_type<_InputIterator>, less<__iter_value_type<_InputIterator>>, _Allocator>;
928941
929# if _LIBCPP_STD_VER >= 23
942# if _LIBCPP_STD_VER >= 23
930943template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
931944set(from_range_t,
932945 _Range&&,
933946 _Allocator) -> set<ranges::range_value_t<_Range>, less<ranges::range_value_t<_Range>>, _Allocator>;
934# endif
947# endif
935948
936949template <class _Key, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
937950set(initializer_list<_Key>, _Allocator) -> set<_Key, less<_Key>, _Allocator>;
938#endif
951# endif
939952
940#ifndef _LIBCPP_CXX03_LANG
953# ifndef _LIBCPP_CXX03_LANG
941954
942955template <class _Key, class _Compare, class _Allocator>
943956set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a) : __tree_(std::move(__s.__tree_), __a) {
......@@ -948,7 +961,7 @@ set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a) : __t
948961 }
949962}
950963
951#endif // _LIBCPP_CXX03_LANG
964# endif // _LIBCPP_CXX03_LANG
952965
953966template <class _Key, class _Compare, class _Allocator>
954967inline _LIBCPP_HIDE_FROM_ABI bool
......@@ -956,7 +969,7 @@ operator==(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare,
956969 return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
957970}
958971
959#if _LIBCPP_STD_VER <= 17
972# if _LIBCPP_STD_VER <= 17
960973
961974template <class _Key, class _Compare, class _Allocator>
962975inline _LIBCPP_HIDE_FROM_ABI bool
......@@ -988,7 +1001,7 @@ operator<=(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare,
9881001 return !(__y < __x);
9891002}
9901003
991#else // _LIBCPP_STD_VER <= 17
1004# else // _LIBCPP_STD_VER <= 17
9921005
9931006template <class _Key, class _Allocator>
9941007_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Key>
......@@ -996,7 +1009,7 @@ operator<=>(const set<_Key, _Allocator>& __x, const set<_Key, _Allocator>& __y)
9961009 return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
9971010}
9981011
999#endif // _LIBCPP_STD_VER <= 17
1012# endif // _LIBCPP_STD_VER <= 17
10001013
10011014// specialized algorithms:
10021015template <class _Key, class _Compare, class _Allocator>
......@@ -1005,13 +1018,21 @@ inline _LIBCPP_HIDE_FROM_ABI void swap(set<_Key, _Compare, _Allocator>& __x, set
10051018 __x.swap(__y);
10061019}
10071020
1008#if _LIBCPP_STD_VER >= 20
1021# if _LIBCPP_STD_VER >= 20
10091022template <class _Key, class _Compare, class _Allocator, class _Predicate>
10101023inline _LIBCPP_HIDE_FROM_ABI typename set<_Key, _Compare, _Allocator>::size_type
10111024erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
10121025 return std::__libcpp_erase_if_container(__c, __pred);
10131026}
1014#endif
1027# endif
1028
1029template <class _Key, class _Compare, class _Allocator>
1030struct __container_traits<set<_Key, _Compare, _Allocator> > {
1031 // http://eel.is/c++draft/associative.reqmts.except#2
1032 // For associative containers, if an exception is thrown by any operation from within
1033 // an insert or emplace function inserting a single element, the insertion has no effect.
1034 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
1035};
10151036
10161037template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
10171038class _LIBCPP_TEMPLATE_VIS multiset {
......@@ -1046,9 +1067,9 @@ public:
10461067 typedef std::reverse_iterator<iterator> reverse_iterator;
10471068 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
10481069
1049#if _LIBCPP_STD_VER >= 17
1070# if _LIBCPP_STD_VER >= 17
10501071 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
1051#endif
1072# endif
10521073
10531074 template <class _Key2, class _Compare2, class _Alloc2>
10541075 friend class _LIBCPP_TEMPLATE_VIS set;
......@@ -1073,11 +1094,11 @@ public:
10731094 insert(__f, __l);
10741095 }
10751096
1076#if _LIBCPP_STD_VER >= 14
1097# if _LIBCPP_STD_VER >= 14
10771098 template <class _InputIterator>
10781099 _LIBCPP_HIDE_FROM_ABI multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
10791100 : multiset(__f, __l, key_compare(), __a) {}
1080#endif
1101# endif
10811102
10821103 template <class _InputIterator>
10831104 _LIBCPP_HIDE_FROM_ABI
......@@ -1086,7 +1107,7 @@ public:
10861107 insert(__f, __l);
10871108 }
10881109
1089#if _LIBCPP_STD_VER >= 23
1110# if _LIBCPP_STD_VER >= 23
10901111 template <_ContainerCompatibleRange<value_type> _Range>
10911112 _LIBCPP_HIDE_FROM_ABI
10921113 multiset(from_range_t,
......@@ -1100,7 +1121,7 @@ public:
11001121 template <_ContainerCompatibleRange<value_type> _Range>
11011122 _LIBCPP_HIDE_FROM_ABI multiset(from_range_t, _Range&& __range, const allocator_type& __a)
11021123 : multiset(from_range, std::forward<_Range>(__range), key_compare(), __a) {}
1103#endif
1124# endif
11041125
11051126 _LIBCPP_HIDE_FROM_ABI multiset(const multiset& __s)
11061127 : __tree_(__s.__tree_.value_comp(),
......@@ -1113,19 +1134,19 @@ public:
11131134 return *this;
11141135 }
11151136
1116#ifndef _LIBCPP_CXX03_LANG
1137# ifndef _LIBCPP_CXX03_LANG
11171138 _LIBCPP_HIDE_FROM_ABI multiset(multiset&& __s) noexcept(is_nothrow_move_constructible<__base>::value)
11181139 : __tree_(std::move(__s.__tree_)) {}
11191140
11201141 _LIBCPP_HIDE_FROM_ABI multiset(multiset&& __s, const allocator_type& __a);
1121#endif // _LIBCPP_CXX03_LANG
1142# endif // _LIBCPP_CXX03_LANG
11221143 _LIBCPP_HIDE_FROM_ABI explicit multiset(const allocator_type& __a) : __tree_(__a) {}
11231144 _LIBCPP_HIDE_FROM_ABI multiset(const multiset& __s, const allocator_type& __a)
11241145 : __tree_(__s.__tree_.value_comp(), __a) {
11251146 insert(__s.begin(), __s.end());
11261147 }
11271148
1128#ifndef _LIBCPP_CXX03_LANG
1149# ifndef _LIBCPP_CXX03_LANG
11291150 _LIBCPP_HIDE_FROM_ABI multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
11301151 : __tree_(__comp) {
11311152 insert(__il.begin(), __il.end());
......@@ -1137,10 +1158,10 @@ public:
11371158 insert(__il.begin(), __il.end());
11381159 }
11391160
1140# if _LIBCPP_STD_VER >= 14
1161# if _LIBCPP_STD_VER >= 14
11411162 _LIBCPP_HIDE_FROM_ABI multiset(initializer_list<value_type> __il, const allocator_type& __a)
11421163 : multiset(__il, key_compare(), __a) {}
1143# endif
1164# endif
11441165
11451166 _LIBCPP_HIDE_FROM_ABI multiset& operator=(initializer_list<value_type> __il) {
11461167 __tree_.__assign_multi(__il.begin(), __il.end());
......@@ -1151,7 +1172,7 @@ public:
11511172 __tree_ = std::move(__s.__tree_);
11521173 return *this;
11531174 }
1154#endif // _LIBCPP_CXX03_LANG
1175# endif // _LIBCPP_CXX03_LANG
11551176
11561177 _LIBCPP_HIDE_FROM_ABI ~multiset() { static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); }
11571178
......@@ -1170,12 +1191,12 @@ public:
11701191 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return rbegin(); }
11711192 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
11721193
1173 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __tree_.size() == 0; }
1194 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __tree_.size() == 0; }
11741195 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __tree_.size(); }
11751196 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __tree_.max_size(); }
11761197
11771198 // modifiers:
1178#ifndef _LIBCPP_CXX03_LANG
1199# ifndef _LIBCPP_CXX03_LANG
11791200 template <class... _Args>
11801201 _LIBCPP_HIDE_FROM_ABI iterator emplace(_Args&&... __args) {
11811202 return __tree_.__emplace_multi(std::forward<_Args>(__args)...);
......@@ -1184,7 +1205,7 @@ public:
11841205 _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __p, _Args&&... __args) {
11851206 return __tree_.__emplace_hint_multi(__p, std::forward<_Args>(__args)...);
11861207 }
1187#endif // _LIBCPP_CXX03_LANG
1208# endif // _LIBCPP_CXX03_LANG
11881209
11891210 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __v) { return __tree_.__insert_multi(__v); }
11901211 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
......@@ -1197,7 +1218,7 @@ public:
11971218 __tree_.__insert_multi(__e, *__f);
11981219 }
11991220
1200#if _LIBCPP_STD_VER >= 23
1221# if _LIBCPP_STD_VER >= 23
12011222 template <_ContainerCompatibleRange<value_type> _Range>
12021223 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
12031224 const_iterator __end = cend();
......@@ -1205,9 +1226,9 @@ public:
12051226 __tree_.__insert_multi(__end, std::forward<decltype(__element)>(__element));
12061227 }
12071228 }
1208#endif
1229# endif
12091230
1210#ifndef _LIBCPP_CXX03_LANG
1231# ifndef _LIBCPP_CXX03_LANG
12111232 _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __v) { return __tree_.__insert_multi(std::move(__v)); }
12121233
12131234 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
......@@ -1215,14 +1236,14 @@ public:
12151236 }
12161237
12171238 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
1218#endif // _LIBCPP_CXX03_LANG
1239# endif // _LIBCPP_CXX03_LANG
12191240
12201241 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __tree_.erase(__p); }
12211242 _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __tree_.__erase_multi(__k); }
12221243 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l) { return __tree_.erase(__f, __l); }
12231244 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __tree_.clear(); }
12241245
1225#if _LIBCPP_STD_VER >= 17
1246# if _LIBCPP_STD_VER >= 17
12261247 _LIBCPP_HIDE_FROM_ABI iterator insert(node_type&& __nh) {
12271248 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
12281249 "node_type with incompatible allocator passed to multiset::insert()");
......@@ -1263,7 +1284,7 @@ public:
12631284 __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
12641285 __tree_.__node_handle_merge_multi(__source.__tree_);
12651286 }
1266#endif
1287# endif
12671288
12681289 _LIBCPP_HIDE_FROM_ABI void swap(multiset& __s) _NOEXCEPT_(__is_nothrow_swappable_v<__base>) {
12691290 __tree_.swap(__s.__tree_);
......@@ -1276,7 +1297,7 @@ public:
12761297 // set operations:
12771298 _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __tree_.find(__k); }
12781299 _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __tree_.find(__k); }
1279#if _LIBCPP_STD_VER >= 14
1300# if _LIBCPP_STD_VER >= 14
12801301 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
12811302 _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
12821303 return __tree_.find(__k);
......@@ -1285,27 +1306,27 @@ public:
12851306 _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
12861307 return __tree_.find(__k);
12871308 }
1288#endif
1309# endif
12891310
12901311 _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __tree_.__count_multi(__k); }
1291#if _LIBCPP_STD_VER >= 14
1312# if _LIBCPP_STD_VER >= 14
12921313 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
12931314 _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
12941315 return __tree_.__count_multi(__k);
12951316 }
1296#endif
1317# endif
12971318
1298#if _LIBCPP_STD_VER >= 20
1319# if _LIBCPP_STD_VER >= 20
12991320 _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
13001321 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
13011322 _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
13021323 return find(__k) != end();
13031324 }
1304#endif // _LIBCPP_STD_VER >= 20
1325# endif // _LIBCPP_STD_VER >= 20
13051326
13061327 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __k) { return __tree_.lower_bound(__k); }
13071328 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __k) const { return __tree_.lower_bound(__k); }
1308#if _LIBCPP_STD_VER >= 14
1329# if _LIBCPP_STD_VER >= 14
13091330 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
13101331 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _K2& __k) {
13111332 return __tree_.lower_bound(__k);
......@@ -1315,11 +1336,11 @@ public:
13151336 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _K2& __k) const {
13161337 return __tree_.lower_bound(__k);
13171338 }
1318#endif
1339# endif
13191340
13201341 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __k) { return __tree_.upper_bound(__k); }
13211342 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __k) const { return __tree_.upper_bound(__k); }
1322#if _LIBCPP_STD_VER >= 14
1343# if _LIBCPP_STD_VER >= 14
13231344 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
13241345 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _K2& __k) {
13251346 return __tree_.upper_bound(__k);
......@@ -1328,7 +1349,7 @@ public:
13281349 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _K2& __k) const {
13291350 return __tree_.upper_bound(__k);
13301351 }
1331#endif
1352# endif
13321353
13331354 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
13341355 return __tree_.__equal_range_multi(__k);
......@@ -1336,7 +1357,7 @@ public:
13361357 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
13371358 return __tree_.__equal_range_multi(__k);
13381359 }
1339#if _LIBCPP_STD_VER >= 14
1360# if _LIBCPP_STD_VER >= 14
13401361 template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
13411362 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
13421363 return __tree_.__equal_range_multi(__k);
......@@ -1345,10 +1366,10 @@ public:
13451366 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
13461367 return __tree_.__equal_range_multi(__k);
13471368 }
1348#endif
1369# endif
13491370};
13501371
1351#if _LIBCPP_STD_VER >= 17
1372# if _LIBCPP_STD_VER >= 17
13521373template <class _InputIterator,
13531374 class _Compare = less<__iter_value_type<_InputIterator>>,
13541375 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
......@@ -1358,7 +1379,7 @@ template <class _InputIterator,
13581379multiset(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
13591380 -> multiset<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
13601381
1361# if _LIBCPP_STD_VER >= 23
1382# if _LIBCPP_STD_VER >= 23
13621383template <ranges::input_range _Range,
13631384 class _Compare = less<ranges::range_value_t<_Range>>,
13641385 class _Allocator = allocator<ranges::range_value_t<_Range>>,
......@@ -1366,7 +1387,7 @@ template <ranges::input_range _Range,
13661387 class = enable_if_t<!__is_allocator<_Compare>::value, void>>
13671388multiset(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator())
13681389 -> multiset<ranges::range_value_t<_Range>, _Compare, _Allocator>;
1369# endif
1390# endif
13701391
13711392template <class _Key,
13721393 class _Compare = less<_Key>,
......@@ -1384,18 +1405,18 @@ template <class _InputIterator,
13841405multiset(_InputIterator, _InputIterator, _Allocator)
13851406 -> multiset<__iter_value_type<_InputIterator>, less<__iter_value_type<_InputIterator>>, _Allocator>;
13861407
1387# if _LIBCPP_STD_VER >= 23
1408# if _LIBCPP_STD_VER >= 23
13881409template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
13891410multiset(from_range_t,
13901411 _Range&&,
13911412 _Allocator) -> multiset<ranges::range_value_t<_Range>, less<ranges::range_value_t<_Range>>, _Allocator>;
1392# endif
1413# endif
13931414
13941415template <class _Key, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
13951416multiset(initializer_list<_Key>, _Allocator) -> multiset<_Key, less<_Key>, _Allocator>;
1396#endif
1417# endif
13971418
1398#ifndef _LIBCPP_CXX03_LANG
1419# ifndef _LIBCPP_CXX03_LANG
13991420
14001421template <class _Key, class _Compare, class _Allocator>
14011422multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
......@@ -1407,7 +1428,7 @@ multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_t
14071428 }
14081429}
14091430
1410#endif // _LIBCPP_CXX03_LANG
1431# endif // _LIBCPP_CXX03_LANG
14111432
14121433template <class _Key, class _Compare, class _Allocator>
14131434inline _LIBCPP_HIDE_FROM_ABI bool
......@@ -1415,7 +1436,7 @@ operator==(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key,
14151436 return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
14161437}
14171438
1418#if _LIBCPP_STD_VER <= 17
1439# if _LIBCPP_STD_VER <= 17
14191440
14201441template <class _Key, class _Compare, class _Allocator>
14211442inline _LIBCPP_HIDE_FROM_ABI bool
......@@ -1447,16 +1468,15 @@ operator<=(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key,
14471468 return !(__y < __x);
14481469}
14491470
1450#else // _LIBCPP_STD_VER <= 17
1471# else // _LIBCPP_STD_VER <= 17
14511472
14521473template <class _Key, class _Allocator>
14531474_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Key>
14541475operator<=>(const multiset<_Key, _Allocator>& __x, const multiset<_Key, _Allocator>& __y) {
1455 return std::lexicographical_compare_three_way(
1456 __x.begin(), __x.end(), __y.begin(), __y.end(), __synth_three_way);
1476 return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), __synth_three_way);
14571477}
14581478
1459#endif // _LIBCPP_STD_VER <= 17
1479# endif // _LIBCPP_STD_VER <= 17
14601480
14611481template <class _Key, class _Compare, class _Allocator>
14621482inline _LIBCPP_HIDE_FROM_ABI void
......@@ -1465,17 +1485,25 @@ swap(multiset<_Key, _Compare, _Allocator>& __x, multiset<_Key, _Compare, _Alloca
14651485 __x.swap(__y);
14661486}
14671487
1468#if _LIBCPP_STD_VER >= 20
1488# if _LIBCPP_STD_VER >= 20
14691489template <class _Key, class _Compare, class _Allocator, class _Predicate>
14701490inline _LIBCPP_HIDE_FROM_ABI typename multiset<_Key, _Compare, _Allocator>::size_type
14711491erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
14721492 return std::__libcpp_erase_if_container(__c, __pred);
14731493}
1474#endif
1494# endif
1495
1496template <class _Key, class _Compare, class _Allocator>
1497struct __container_traits<multiset<_Key, _Compare, _Allocator> > {
1498 // http://eel.is/c++draft/associative.reqmts.except#2
1499 // For associative containers, if an exception is thrown by any operation from within
1500 // an insert or emplace function inserting a single element, the insertion has no effect.
1501 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
1502};
14751503
14761504_LIBCPP_END_NAMESPACE_STD
14771505
1478#if _LIBCPP_STD_VER >= 17
1506# if _LIBCPP_STD_VER >= 17
14791507_LIBCPP_BEGIN_NAMESPACE_STD
14801508namespace pmr {
14811509template <class _KeyT, class _CompareT = std::less<_KeyT>>
......@@ -1485,17 +1513,18 @@ template <class _KeyT, class _CompareT = std::less<_KeyT>>
14851513using multiset _LIBCPP_AVAILABILITY_PMR = std::multiset<_KeyT, _CompareT, polymorphic_allocator<_KeyT>>;
14861514} // namespace pmr
14871515_LIBCPP_END_NAMESPACE_STD
1488#endif
1516# endif
14891517
14901518_LIBCPP_POP_MACROS
14911519
1492#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1493# include <concepts>
1494# include <cstdlib>
1495# include <functional>
1496# include <iterator>
1497# include <stdexcept>
1498# include <type_traits>
1499#endif
1520# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1521# include <concepts>
1522# include <cstdlib>
1523# include <functional>
1524# include <iterator>
1525# include <stdexcept>
1526# include <type_traits>
1527# endif
1528#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
15001529
15011530#endif // _LIBCPP_SET
lib/libcxx/include/shared_mutex+32-28
......@@ -122,31 +122,34 @@ template <class Mutex>
122122
123123*/
124124
125#include <__config>
126
127#if !defined(_LIBCPP_HAS_NO_THREADS)
128
129# include <__chrono/duration.h>
130# include <__chrono/steady_clock.h>
131# include <__chrono/time_point.h>
132# include <__condition_variable/condition_variable.h>
133# include <__memory/addressof.h>
134# include <__mutex/mutex.h>
135# include <__mutex/tag_types.h>
136# include <__mutex/unique_lock.h>
137# include <__system_error/system_error.h>
138# include <__utility/swap.h>
139# include <cerrno>
140# include <version>
125#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
126# include <__cxx03/shared_mutex>
127#else
128# include <__config>
129
130# if _LIBCPP_HAS_THREADS
131
132# include <__chrono/duration.h>
133# include <__chrono/steady_clock.h>
134# include <__chrono/time_point.h>
135# include <__condition_variable/condition_variable.h>
136# include <__memory/addressof.h>
137# include <__mutex/mutex.h>
138# include <__mutex/tag_types.h>
139# include <__mutex/unique_lock.h>
140# include <__system_error/throw_system_error.h>
141# include <__utility/swap.h>
142# include <cerrno>
143# include <version>
141144
142145_LIBCPP_PUSH_MACROS
143# include <__undef_macros>
146# include <__undef_macros>
144147
145# if _LIBCPP_STD_VER >= 14
148# if _LIBCPP_STD_VER >= 14
146149
147# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
148# pragma GCC system_header
149# endif
150# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
151# pragma GCC system_header
152# endif
150153
151154_LIBCPP_BEGIN_NAMESPACE_STD
152155
......@@ -179,7 +182,7 @@ struct _LIBCPP_EXPORTED_FROM_ABI __shared_mutex_base {
179182 // native_handle_type native_handle(); // See 30.2.3
180183};
181184
182# if _LIBCPP_STD_VER >= 17
185# if _LIBCPP_STD_VER >= 17
183186class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_THREAD_SAFETY_ANNOTATION(__capability__("shared_mutex")) shared_mutex {
184187 __shared_mutex_base __base_;
185188
......@@ -216,7 +219,7 @@ public:
216219 // typedef __shared_mutex_base::native_handle_type native_handle_type;
217220 // _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() { return __base::unlock_shared(); }
218221};
219# endif
222# endif
220223
221224class _LIBCPP_EXPORTED_FROM_ABI
222225_LIBCPP_THREAD_SAFETY_ANNOTATION(__capability__("shared_timed_mutex")) shared_timed_mutex {
......@@ -451,14 +454,15 @@ inline _LIBCPP_HIDE_FROM_ABI void swap(shared_lock<_Mutex>& __x, shared_lock<_Mu
451454
452455_LIBCPP_END_NAMESPACE_STD
453456
454# endif // _LIBCPP_STD_VER >= 14
457# endif // _LIBCPP_STD_VER >= 14
455458
456459_LIBCPP_POP_MACROS
457460
458#endif // !defined(_LIBCPP_HAS_NO_THREADS)
461# endif // _LIBCPP_HAS_THREADS
459462
460#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
461# include <system_error>
462#endif
463# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
464# include <system_error>
465# endif
466#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
463467
464468#endif // _LIBCPP_SHARED_MUTEX
lib/libcxx/include/source_location+14-9
......@@ -25,17 +25,20 @@ namespace std {
2525}
2626*/
2727
28#include <__config>
29#include <cstdint>
30#include <version>
28#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
29# include <__cxx03/source_location>
30#else
31# include <__config>
32# include <cstdint>
33# include <version>
3134
32#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
33# pragma GCC system_header
34#endif
35# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
36# pragma GCC system_header
37# endif
3538
3639_LIBCPP_BEGIN_NAMESPACE_STD
3740
38#if _LIBCPP_STD_VER >= 20
41# if _LIBCPP_STD_VER >= 20
3942
4043class source_location {
4144 // The names source_location::__impl, _M_file_name, _M_function_name, _M_line, and _M_column
......@@ -52,7 +55,7 @@ class source_location {
5255 // in constant evaluation, so we don't want to use `void*` as the argument
5356 // type unless the builtin returned that, anyhow, and the invalid cast is
5457 // unavoidable.
55 using __bsl_ty = decltype(__builtin_source_location());
58 using __bsl_ty _LIBCPP_NODEBUG = decltype(__builtin_source_location());
5659
5760public:
5861 // The defaulted __ptr argument is necessary so that the builtin is evaluated
......@@ -78,8 +81,10 @@ public:
7881 }
7982};
8083
81#endif // _LIBCPP_STD_VER >= 20
84# endif // _LIBCPP_STD_VER >= 20
8285
8386_LIBCPP_END_NAMESPACE_STD
8487
88#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
89
8590#endif // _LIBCPP_SOURCE_LOCATION
lib/libcxx/include/span+93-83
......@@ -144,59 +144,63 @@ template<class R>
144144
145145*/
146146
147#include <__assert>
148#include <__concepts/convertible_to.h>
149#include <__concepts/equality_comparable.h>
150#include <__config>
151#include <__fwd/array.h>
152#include <__fwd/span.h>
153#include <__iterator/bounded_iter.h>
154#include <__iterator/concepts.h>
155#include <__iterator/iterator_traits.h>
156#include <__iterator/reverse_iterator.h>
157#include <__iterator/wrap_iter.h>
158#include <__memory/pointer_traits.h>
159#include <__ranges/concepts.h>
160#include <__ranges/data.h>
161#include <__ranges/enable_borrowed_range.h>
162#include <__ranges/enable_view.h>
163#include <__ranges/size.h>
164#include <__type_traits/integral_constant.h>
165#include <__type_traits/is_array.h>
166#include <__type_traits/is_const.h>
167#include <__type_traits/is_convertible.h>
168#include <__type_traits/is_integral.h>
169#include <__type_traits/is_same.h>
170#include <__type_traits/remove_const.h>
171#include <__type_traits/remove_cv.h>
172#include <__type_traits/remove_cvref.h>
173#include <__type_traits/remove_reference.h>
174#include <__type_traits/type_identity.h>
175#include <__utility/forward.h>
176#include <cstddef> // for byte
177#include <initializer_list>
178#include <stdexcept>
179#include <version>
147#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
148# include <__cxx03/span>
149#else
150# include <__assert>
151# include <__concepts/convertible_to.h>
152# include <__concepts/equality_comparable.h>
153# include <__config>
154# include <__cstddef/byte.h>
155# include <__cstddef/ptrdiff_t.h>
156# include <__fwd/array.h>
157# include <__fwd/span.h>
158# include <__iterator/bounded_iter.h>
159# include <__iterator/concepts.h>
160# include <__iterator/iterator_traits.h>
161# include <__iterator/reverse_iterator.h>
162# include <__iterator/wrap_iter.h>
163# include <__memory/pointer_traits.h>
164# include <__ranges/concepts.h>
165# include <__ranges/data.h>
166# include <__ranges/enable_borrowed_range.h>
167# include <__ranges/enable_view.h>
168# include <__ranges/size.h>
169# include <__type_traits/integral_constant.h>
170# include <__type_traits/is_array.h>
171# include <__type_traits/is_const.h>
172# include <__type_traits/is_convertible.h>
173# include <__type_traits/is_integral.h>
174# include <__type_traits/is_same.h>
175# include <__type_traits/remove_const.h>
176# include <__type_traits/remove_cv.h>
177# include <__type_traits/remove_cvref.h>
178# include <__type_traits/remove_reference.h>
179# include <__type_traits/type_identity.h>
180# include <__utility/forward.h>
181# include <initializer_list>
182# include <stdexcept>
183# include <version>
180184
181185// standard-mandated includes
182186
183187// [iterator.range]
184#include <__iterator/access.h>
185#include <__iterator/data.h>
186#include <__iterator/empty.h>
187#include <__iterator/reverse_access.h>
188#include <__iterator/size.h>
189
190#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
191# pragma GCC system_header
192#endif
188# include <__iterator/access.h>
189# include <__iterator/data.h>
190# include <__iterator/empty.h>
191# include <__iterator/reverse_access.h>
192# include <__iterator/size.h>
193
194# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
195# pragma GCC system_header
196# endif
193197
194198_LIBCPP_PUSH_MACROS
195#include <__undef_macros>
199# include <__undef_macros>
196200
197201_LIBCPP_BEGIN_NAMESPACE_STD
198202
199#if _LIBCPP_STD_VER >= 20
203# if _LIBCPP_STD_VER >= 20
200204
201205template <class _Tp>
202206struct __is_std_span : false_type {};
......@@ -210,7 +214,7 @@ concept __span_compatible_range =
210214 ranges::contiguous_range<_Range> && //
211215 ranges::sized_range<_Range> && //
212216 (ranges::borrowed_range<_Range> || is_const_v<_ElementType>) && //
213 !__is_std_array<remove_cvref_t<_Range>>::value && //
217 !__is_std_array_v<remove_cvref_t<_Range>> && //
214218 !is_array_v<remove_cvref_t<_Range>> && //
215219 is_convertible_v<remove_reference_t<ranges::range_reference_t<_Range>> (*)[], _ElementType (*)[]>;
216220
......@@ -236,11 +240,11 @@ public:
236240 using const_pointer = const _Tp*;
237241 using reference = _Tp&;
238242 using const_reference = const _Tp&;
239# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
243# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
240244 using iterator = __bounded_iter<pointer>;
241# else
245# else
242246 using iterator = __wrap_iter<pointer>;
243# endif
247# endif
244248 using reverse_iterator = std::reverse_iterator<iterator>;
245249
246250 static constexpr size_type extent = _Extent;
......@@ -250,14 +254,14 @@ public:
250254 requires(_Sz == 0)
251255 _LIBCPP_HIDE_FROM_ABI constexpr span() noexcept : __data_{nullptr} {}
252256
253# if _LIBCPP_STD_VER >= 26
257# if _LIBCPP_STD_VER >= 26
254258 _LIBCPP_HIDE_FROM_ABI constexpr explicit span(std::initializer_list<value_type> __il)
255259 requires is_const_v<element_type>
256260 : __data_{__il.begin()} {
257261 _LIBCPP_ASSERT_VALID_INPUT_RANGE(
258262 _Extent == __il.size(), "Size mismatch in span's constructor _Extent != __il.size().");
259263 }
260# endif
264# endif
261265
262266 constexpr span(const span&) noexcept = default;
263267 constexpr span& operator=(const span&) noexcept = default;
......@@ -266,6 +270,8 @@ public:
266270 _LIBCPP_HIDE_FROM_ABI constexpr explicit span(_It __first, size_type __count) : __data_{std::to_address(__first)} {
267271 (void)__count;
268272 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(_Extent == __count, "size mismatch in span's constructor (iterator, len)");
273 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__count == 0 || std::to_address(__first) != nullptr,
274 "passed nullptr with non-zero length in span's constructor (iterator, len)");
269275 }
270276
271277 template <__span_compatible_iterator<element_type> _It, __span_compatible_sentinel_for<_It> _End>
......@@ -355,13 +361,13 @@ public:
355361 return __data_[__idx];
356362 }
357363
358# if _LIBCPP_STD_VER >= 26
364# if _LIBCPP_STD_VER >= 26
359365 _LIBCPP_HIDE_FROM_ABI constexpr reference at(size_type __index) const {
360366 if (__index >= size())
361367 std::__throw_out_of_range("span");
362368 return __data_[__index];
363369 }
364# endif
370# endif
365371
366372 _LIBCPP_HIDE_FROM_ABI constexpr reference front() const noexcept {
367373 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span<T, N>::front() on empty span");
......@@ -377,18 +383,18 @@ public:
377383
378384 // [span.iter], span iterator support
379385 _LIBCPP_HIDE_FROM_ABI constexpr iterator begin() const noexcept {
380# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
386# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
381387 return std::__make_bounded_iter(data(), data(), data() + size());
382# else
388# else
383389 return iterator(data());
384# endif
390# endif
385391 }
386392 _LIBCPP_HIDE_FROM_ABI constexpr iterator end() const noexcept {
387# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
393# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
388394 return std::__make_bounded_iter(data() + size(), data(), data() + size());
389# else
395# else
390396 return iterator(data() + size());
391# endif
397# endif
392398 }
393399 _LIBCPP_HIDE_FROM_ABI constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); }
394400 _LIBCPP_HIDE_FROM_ABI constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); }
......@@ -417,11 +423,11 @@ public:
417423 using const_pointer = const _Tp*;
418424 using reference = _Tp&;
419425 using const_reference = const _Tp&;
420# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
426# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
421427 using iterator = __bounded_iter<pointer>;
422# else
428# else
423429 using iterator = __wrap_iter<pointer>;
424# endif
430# endif
425431 using reverse_iterator = std::reverse_iterator<iterator>;
426432
427433 static constexpr size_type extent = dynamic_extent;
......@@ -429,18 +435,21 @@ public:
429435 // [span.cons], span constructors, copy, assignment, and destructor
430436 _LIBCPP_HIDE_FROM_ABI constexpr span() noexcept : __data_{nullptr}, __size_{0} {}
431437
432# if _LIBCPP_STD_VER >= 26
438# if _LIBCPP_STD_VER >= 26
433439 _LIBCPP_HIDE_FROM_ABI constexpr span(std::initializer_list<value_type> __il)
434440 requires is_const_v<element_type>
435441 : __data_{__il.begin()}, __size_{__il.size()} {}
436# endif
442# endif
437443
438444 constexpr span(const span&) noexcept = default;
439445 constexpr span& operator=(const span&) noexcept = default;
440446
441447 template <__span_compatible_iterator<element_type> _It>
442448 _LIBCPP_HIDE_FROM_ABI constexpr span(_It __first, size_type __count)
443 : __data_{std::to_address(__first)}, __size_{__count} {}
449 : __data_{std::to_address(__first)}, __size_{__count} {
450 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__count == 0 || std::to_address(__first) != nullptr,
451 "passed nullptr with non-zero length in span's constructor (iterator, len)");
452 }
444453
445454 template <__span_compatible_iterator<element_type> _It, __span_compatible_sentinel_for<_It> _End>
446455 _LIBCPP_HIDE_FROM_ABI constexpr span(_It __first, _End __last)
......@@ -517,13 +526,13 @@ public:
517526 return __data_[__idx];
518527 }
519528
520# if _LIBCPP_STD_VER >= 26
529# if _LIBCPP_STD_VER >= 26
521530 _LIBCPP_HIDE_FROM_ABI constexpr reference at(size_type __index) const {
522531 if (__index >= size())
523532 std::__throw_out_of_range("span");
524533 return __data_[__index];
525534 }
526# endif
535# endif
527536
528537 _LIBCPP_HIDE_FROM_ABI constexpr reference front() const noexcept {
529538 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span<T>::front() on empty span");
......@@ -539,18 +548,18 @@ public:
539548
540549 // [span.iter], span iterator support
541550 _LIBCPP_HIDE_FROM_ABI constexpr iterator begin() const noexcept {
542# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
551# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
543552 return std::__make_bounded_iter(data(), data(), data() + size());
544# else
553# else
545554 return iterator(data());
546# endif
555# endif
547556 }
548557 _LIBCPP_HIDE_FROM_ABI constexpr iterator end() const noexcept {
549# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
558# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
550559 return std::__make_bounded_iter(data() + size(), data(), data() + size());
551# else
560# else
552561 return iterator(data() + size());
553# endif
562# endif
554563 }
555564 _LIBCPP_HIDE_FROM_ABI constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); }
556565 _LIBCPP_HIDE_FROM_ABI constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); }
......@@ -586,7 +595,7 @@ _LIBCPP_HIDE_FROM_ABI auto as_writable_bytes(span<_Tp, _Extent> __s) noexcept {
586595 return __s.__as_writable_bytes();
587596}
588597
589# if _LIBCPP_STD_VER >= 26
598# if _LIBCPP_STD_VER >= 26
590599template <class _Tp>
591600concept __integral_constant_like =
592601 is_integral_v<decltype(_Tp::value)> && !is_same_v<bool, remove_const_t<decltype(_Tp::value)>> &&
......@@ -602,10 +611,10 @@ inline constexpr size_t __maybe_static_ext<_Tp> = {_Tp::value};
602611
603612template <contiguous_iterator _It, class _EndOrSize>
604613span(_It, _EndOrSize) -> span<remove_reference_t<iter_reference_t<_It>>, __maybe_static_ext<_EndOrSize>>;
605# else
614# else
606615template <contiguous_iterator _It, class _EndOrSize>
607616span(_It, _EndOrSize) -> span<remove_reference_t<iter_reference_t<_It>>>;
608# endif
617# endif
609618
610619template <class _Tp, size_t _Sz>
611620span(_Tp (&)[_Sz]) -> span<_Tp, _Sz>;
......@@ -619,18 +628,19 @@ span(const array<_Tp, _Sz>&) -> span<const _Tp, _Sz>;
619628template <ranges::contiguous_range _Range>
620629span(_Range&&) -> span<remove_reference_t<ranges::range_reference_t<_Range>>>;
621630
622#endif // _LIBCPP_STD_VER >= 20
631# endif // _LIBCPP_STD_VER >= 20
623632
624633_LIBCPP_END_NAMESPACE_STD
625634
626635_LIBCPP_POP_MACROS
627636
628#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
629# include <array>
630# include <concepts>
631# include <functional>
632# include <iterator>
633# include <type_traits>
634#endif
637# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
638# include <array>
639# include <concepts>
640# include <functional>
641# include <iterator>
642# include <type_traits>
643# endif
644#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
635645
636646#endif // _LIBCPP_SPAN
lib/libcxx/include/sstream+129-108
......@@ -312,22 +312,30 @@ typedef basic_stringstream<wchar_t> wstringstream;
312312
313313// clang-format on
314314
315#include <__config>
316#include <__fwd/sstream.h>
317#include <__ostream/basic_ostream.h>
318#include <__type_traits/is_convertible.h>
319#include <__utility/swap.h>
320#include <istream>
321#include <string>
322#include <string_view>
323#include <version>
324
325#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
326# pragma GCC system_header
327#endif
315#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
316# include <__cxx03/sstream>
317#else
318# include <__config>
319
320# if _LIBCPP_HAS_LOCALIZATION
321
322# include <__fwd/sstream.h>
323# include <__ostream/basic_ostream.h>
324# include <__type_traits/is_convertible.h>
325# include <__utility/swap.h>
326# include <ios>
327# include <istream>
328# include <locale>
329# include <string>
330# include <string_view>
331# include <version>
332
333# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
334# pragma GCC system_header
335# endif
328336
329337_LIBCPP_PUSH_MACROS
330#include <__undef_macros>
338# include <__undef_macros>
331339
332340_LIBCPP_BEGIN_NAMESPACE_STD
333341
......@@ -354,9 +362,15 @@ private:
354362
355363public:
356364 // [stringbuf.cons] constructors:
357 _LIBCPP_HIDE_FROM_ABI basic_stringbuf() : __hm_(nullptr), __mode_(ios_base::in | ios_base::out) {}
365 _LIBCPP_HIDE_FROM_ABI basic_stringbuf() : __hm_(nullptr), __mode_(ios_base::in | ios_base::out) {
366 // it is implementation-defined whether we initialize eback() & friends to nullptr, and libc++ doesn't
367 __init_buf_ptrs();
368 }
358369
359 _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(ios_base::openmode __wch) : __hm_(nullptr), __mode_(__wch) {}
370 _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(ios_base::openmode __wch) : __hm_(nullptr), __mode_(__wch) {
371 // it is implementation-defined whether we initialize eback() & friends to nullptr, and libc++ doesn't
372 __init_buf_ptrs();
373 }
360374
361375 _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const string_type& __s,
362376 ios_base::openmode __wch = ios_base::in | ios_base::out)
......@@ -364,12 +378,14 @@ public:
364378 str(__s);
365379 }
366380
367#if _LIBCPP_STD_VER >= 20
381# if _LIBCPP_STD_VER >= 20
368382 _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const allocator_type& __a)
369383 : basic_stringbuf(ios_base::in | ios_base::out, __a) {}
370384
371385 _LIBCPP_HIDE_FROM_ABI basic_stringbuf(ios_base::openmode __wch, const allocator_type& __a)
372 : __str_(__a), __hm_(nullptr), __mode_(__wch) {}
386 : __str_(__a), __hm_(nullptr), __mode_(__wch) {
387 __init_buf_ptrs();
388 }
373389
374390 _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(string_type&& __s,
375391 ios_base::openmode __wch = ios_base::in | ios_base::out)
......@@ -396,9 +412,9 @@ public:
396412 : __str_(__s), __hm_(nullptr), __mode_(__wch) {
397413 __init_buf_ptrs();
398414 }
399#endif // _LIBCPP_STD_VER >= 20
415# endif // _LIBCPP_STD_VER >= 20
400416
401#if _LIBCPP_STD_VER >= 26
417# if _LIBCPP_STD_VER >= 26
402418
403419 template <class _Tp>
404420 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
......@@ -420,37 +436,37 @@ public:
420436 __init_buf_ptrs();
421437 }
422438
423#endif // _LIBCPP_STD_VER >= 26
439# endif // _LIBCPP_STD_VER >= 26
424440
425441 basic_stringbuf(const basic_stringbuf&) = delete;
426442 basic_stringbuf(basic_stringbuf&& __rhs) : __mode_(__rhs.__mode_) { __move_init(std::move(__rhs)); }
427443
428#if _LIBCPP_STD_VER >= 20
444# if _LIBCPP_STD_VER >= 20
429445 _LIBCPP_HIDE_FROM_ABI basic_stringbuf(basic_stringbuf&& __rhs, const allocator_type& __a)
430446 : basic_stringbuf(__rhs.__mode_, __a) {
431447 __move_init(std::move(__rhs));
432448 }
433#endif
449# endif
434450
435451 // [stringbuf.assign] Assign and swap:
436452 basic_stringbuf& operator=(const basic_stringbuf&) = delete;
437453 basic_stringbuf& operator=(basic_stringbuf&& __rhs);
438454 void swap(basic_stringbuf& __rhs)
439#if _LIBCPP_STD_VER >= 20
455# if _LIBCPP_STD_VER >= 20
440456 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
441457 allocator_traits<allocator_type>::is_always_equal::value)
442#endif
458# endif
443459 ;
444460
445461 // [stringbuf.members] Member functions:
446462
447#if _LIBCPP_STD_VER >= 20
463# if _LIBCPP_STD_VER >= 20
448464 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const noexcept { return __str_.get_allocator(); }
449#endif
465# endif
450466
451#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
467# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
452468 string_type str() const;
453#else
469# else
454470 _LIBCPP_HIDE_FROM_ABI string_type str() const& { return str(__str_.get_allocator()); }
455471
456472 _LIBCPP_HIDE_FROM_ABI string_type str() && {
......@@ -464,9 +480,9 @@ public:
464480 __init_buf_ptrs();
465481 return __result;
466482 }
467#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
483# endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
468484
469#if _LIBCPP_STD_VER >= 20
485# if _LIBCPP_STD_VER >= 20
470486 template <class _SAlloc>
471487 requires __is_allocator<_SAlloc>::value
472488 _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
......@@ -474,14 +490,14 @@ public:
474490 }
475491
476492 _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept;
477#endif // _LIBCPP_STD_VER >= 20
493# endif // _LIBCPP_STD_VER >= 20
478494
479495 void str(const string_type& __s) {
480496 __str_ = __s;
481497 __init_buf_ptrs();
482498 }
483499
484#if _LIBCPP_STD_VER >= 20
500# if _LIBCPP_STD_VER >= 20
485501 template <class _SAlloc>
486502 requires(!is_same_v<_SAlloc, allocator_type>)
487503 _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) {
......@@ -493,9 +509,9 @@ public:
493509 __str_ = std::move(__s);
494510 __init_buf_ptrs();
495511 }
496#endif // _LIBCPP_STD_VER >= 20
512# endif // _LIBCPP_STD_VER >= 20
497513
498#if _LIBCPP_STD_VER >= 26
514# if _LIBCPP_STD_VER >= 26
499515
500516 template <class _Tp>
501517 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
......@@ -505,7 +521,7 @@ public:
505521 __init_buf_ptrs();
506522 }
507523
508#endif // _LIBCPP_STD_VER >= 26
524# endif // _LIBCPP_STD_VER >= 26
509525
510526protected:
511527 // [stringbuf.virtuals] Overridden virtual functions:
......@@ -601,10 +617,10 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs)
601617
602618template <class _CharT, class _Traits, class _Allocator>
603619void basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs)
604#if _LIBCPP_STD_VER >= 20
620# if _LIBCPP_STD_VER >= 20
605621 noexcept(allocator_traits<_Allocator>::propagate_on_container_swap::value ||
606622 allocator_traits<_Allocator>::is_always_equal::value)
607#endif
623# endif
608624{
609625 char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
610626 ptrdiff_t __rbinp = -1;
......@@ -674,14 +690,14 @@ void basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs)
674690template <class _CharT, class _Traits, class _Allocator>
675691inline _LIBCPP_HIDE_FROM_ABI void
676692swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x, basic_stringbuf<_CharT, _Traits, _Allocator>& __y)
677#if _LIBCPP_STD_VER >= 20
693# if _LIBCPP_STD_VER >= 20
678694 noexcept(noexcept(__x.swap(__y)))
679#endif
695# endif
680696{
681697 __x.swap(__y);
682698}
683699
684#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
700# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
685701template <class _CharT, class _Traits, class _Allocator>
686702basic_string<_CharT, _Traits, _Allocator> basic_stringbuf<_CharT, _Traits, _Allocator>::str() const {
687703 if (__mode_ & ios_base::out) {
......@@ -692,7 +708,7 @@ basic_string<_CharT, _Traits, _Allocator> basic_stringbuf<_CharT, _Traits, _Allo
692708 return string_type(this->eback(), this->egptr(), __str_.get_allocator());
693709 return string_type(__str_.get_allocator());
694710}
695#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
711# endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
696712
697713template <class _CharT, class _Traits, class _Allocator>
698714_LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__init_buf_ptrs() {
......@@ -718,7 +734,7 @@ _LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__init_
718734 }
719735}
720736
721#if _LIBCPP_STD_VER >= 20
737# if _LIBCPP_STD_VER >= 20
722738template <class _CharT, class _Traits, class _Allocator>
723739_LIBCPP_HIDE_FROM_ABI basic_string_view<_CharT, _Traits>
724740basic_stringbuf<_CharT, _Traits, _Allocator>::view() const noexcept {
......@@ -730,7 +746,7 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::view() const noexcept {
730746 return basic_string_view<_CharT, _Traits>(this->eback(), this->egptr());
731747 return basic_string_view<_CharT, _Traits>();
732748}
733#endif // _LIBCPP_STD_VER >= 20
749# endif // _LIBCPP_STD_VER >= 20
734750
735751template <class _CharT, class _Traits, class _Allocator>
736752typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
......@@ -773,9 +789,9 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c) {
773789 if (this->pptr() == this->epptr()) {
774790 if (!(__mode_ & ios_base::out))
775791 return traits_type::eof();
776#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
792# if _LIBCPP_HAS_EXCEPTIONS
777793 try {
778#endif // _LIBCPP_HAS_NO_EXCEPTIONS
794# endif // _LIBCPP_HAS_EXCEPTIONS
779795 ptrdiff_t __nout = this->pptr() - this->pbase();
780796 ptrdiff_t __hm = __hm_ - this->pbase();
781797 __str_.push_back(char_type());
......@@ -784,11 +800,11 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c) {
784800 this->setp(__p, __p + __str_.size());
785801 this->__pbump(__nout);
786802 __hm_ = this->pbase() + __hm;
787#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
803# if _LIBCPP_HAS_EXCEPTIONS
788804 } catch (...) {
789805 return traits_type::eof();
790806 }
791#endif // _LIBCPP_HAS_NO_EXCEPTIONS
807# endif // _LIBCPP_HAS_EXCEPTIONS
792808 }
793809 __hm_ = std::max(this->pptr() + 1, __hm_);
794810 if (__mode_ & ios_base::in) {
......@@ -864,15 +880,16 @@ private:
864880
865881public:
866882 // [istringstream.cons] Constructors:
867 _LIBCPP_HIDE_FROM_ABI basic_istringstream() : basic_istream<_CharT, _Traits>(&__sb_), __sb_(ios_base::in) {}
883 _LIBCPP_HIDE_FROM_ABI basic_istringstream()
884 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::in) {}
868885
869886 _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(ios_base::openmode __wch)
870 : basic_istream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::in) {}
887 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::in) {}
871888
872889 _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const string_type& __s, ios_base::openmode __wch = ios_base::in)
873 : basic_istream<_CharT, _Traits>(&__sb_), __sb_(__s, __wch | ios_base::in) {}
890 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {}
874891
875#if _LIBCPP_STD_VER >= 20
892# if _LIBCPP_STD_VER >= 20
876893 _LIBCPP_HIDE_FROM_ABI basic_istringstream(ios_base::openmode __wch, const _Allocator& __a)
877894 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::in, __a) {}
878895
......@@ -892,9 +909,9 @@ public:
892909 _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s,
893910 ios_base::openmode __wch = ios_base::in)
894911 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {}
895#endif // _LIBCPP_STD_VER >= 20
912# endif // _LIBCPP_STD_VER >= 20
896913
897#if _LIBCPP_STD_VER >= 26
914# if _LIBCPP_STD_VER >= 26
898915
899916 template <class _Tp>
900917 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
......@@ -911,12 +928,12 @@ public:
911928 _LIBCPP_HIDE_FROM_ABI basic_istringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
912929 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::in, __a) {}
913930
914#endif // _LIBCPP_STD_VER >= 26
931# endif // _LIBCPP_STD_VER >= 26
915932
916933 basic_istringstream(const basic_istringstream&) = delete;
917934 _LIBCPP_HIDE_FROM_ABI basic_istringstream(basic_istringstream&& __rhs)
918935 : basic_istream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
919 basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_);
936 basic_istream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
920937 }
921938
922939 // [istringstream.assign] Assign and swap:
......@@ -933,18 +950,18 @@ public:
933950
934951 // [istringstream.members] Member functions:
935952 _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const {
936 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
953 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_));
937954 }
938955
939#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
956# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
940957 _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
941#else
958# else
942959 _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); }
943960
944961 _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); }
945#endif
962# endif
946963
947#if _LIBCPP_STD_VER >= 20
964# if _LIBCPP_STD_VER >= 20
948965 template <class _SAlloc>
949966 requires __is_allocator<_SAlloc>::value
950967 _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
......@@ -952,26 +969,26 @@ public:
952969 }
953970
954971 _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); }
955#endif // _LIBCPP_STD_VER >= 20
972# endif // _LIBCPP_STD_VER >= 20
956973
957974 _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); }
958975
959#if _LIBCPP_STD_VER >= 20
976# if _LIBCPP_STD_VER >= 20
960977 template <class _SAlloc>
961978 _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) {
962979 __sb_.str(__s);
963980 }
964981
965982 _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); }
966#endif // _LIBCPP_STD_VER >= 20
983# endif // _LIBCPP_STD_VER >= 20
967984
968#if _LIBCPP_STD_VER >= 26
985# if _LIBCPP_STD_VER >= 26
969986 template <class _Tp>
970987 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
971988 _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
972989 rdbuf()->str(__t);
973990 }
974#endif // _LIBCPP_STD_VER >= 26
991# endif // _LIBCPP_STD_VER >= 26
975992};
976993
977994template <class _CharT, class _Traits, class _Allocator>
......@@ -999,15 +1016,16 @@ private:
9991016
10001017public:
10011018 // [ostringstream.cons] Constructors:
1002 _LIBCPP_HIDE_FROM_ABI basic_ostringstream() : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(ios_base::out) {}
1019 _LIBCPP_HIDE_FROM_ABI basic_ostringstream()
1020 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::out) {}
10031021
10041022 _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(ios_base::openmode __wch)
1005 : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::out) {}
1023 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::out) {}
10061024
10071025 _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const string_type& __s, ios_base::openmode __wch = ios_base::out)
1008 : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(__s, __wch | ios_base::out) {}
1026 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {}
10091027
1010#if _LIBCPP_STD_VER >= 20
1028# if _LIBCPP_STD_VER >= 20
10111029 _LIBCPP_HIDE_FROM_ABI basic_ostringstream(ios_base::openmode __wch, const _Allocator& __a)
10121030 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::out, __a) {}
10131031
......@@ -1028,9 +1046,9 @@ public:
10281046 _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s,
10291047 ios_base::openmode __wch = ios_base::out)
10301048 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {}
1031#endif // _LIBCPP_STD_VER >= 20
1049# endif // _LIBCPP_STD_VER >= 20
10321050
1033#if _LIBCPP_STD_VER >= 26
1051# if _LIBCPP_STD_VER >= 26
10341052
10351053 template <class _Tp>
10361054 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
......@@ -1047,12 +1065,12 @@ public:
10471065 _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
10481066 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::out, __a) {}
10491067
1050#endif // _LIBCPP_STD_VER >= 26
1068# endif // _LIBCPP_STD_VER >= 26
10511069
10521070 basic_ostringstream(const basic_ostringstream&) = delete;
10531071 _LIBCPP_HIDE_FROM_ABI basic_ostringstream(basic_ostringstream&& __rhs)
10541072 : basic_ostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
1055 basic_ostream<_CharT, _Traits>::set_rdbuf(&__sb_);
1073 basic_ostream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
10561074 }
10571075
10581076 // [ostringstream.assign] Assign and swap:
......@@ -1070,18 +1088,18 @@ public:
10701088
10711089 // [ostringstream.members] Member functions:
10721090 _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const {
1073 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
1091 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_));
10741092 }
10751093
1076#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
1094# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
10771095 _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
1078#else
1096# else
10791097 _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); }
10801098
10811099 _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); }
1082#endif
1100# endif
10831101
1084#if _LIBCPP_STD_VER >= 20
1102# if _LIBCPP_STD_VER >= 20
10851103 template <class _SAlloc>
10861104 requires __is_allocator<_SAlloc>::value
10871105 _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
......@@ -1089,26 +1107,26 @@ public:
10891107 }
10901108
10911109 _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); }
1092#endif // _LIBCPP_STD_VER >= 20
1110# endif // _LIBCPP_STD_VER >= 20
10931111
10941112 _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); }
10951113
1096#if _LIBCPP_STD_VER >= 20
1114# if _LIBCPP_STD_VER >= 20
10971115 template <class _SAlloc>
10981116 _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) {
10991117 __sb_.str(__s);
11001118 }
11011119
11021120 _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); }
1103#endif // _LIBCPP_STD_VER >= 20
1121# endif // _LIBCPP_STD_VER >= 20
11041122
1105#if _LIBCPP_STD_VER >= 26
1123# if _LIBCPP_STD_VER >= 26
11061124 template <class _Tp>
11071125 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
11081126 _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
11091127 rdbuf()->str(__t);
11101128 }
1111#endif // _LIBCPP_STD_VER >= 26
1129# endif // _LIBCPP_STD_VER >= 26
11121130};
11131131
11141132template <class _CharT, class _Traits, class _Allocator>
......@@ -1137,16 +1155,16 @@ private:
11371155public:
11381156 // [stringstream.cons] constructors
11391157 _LIBCPP_HIDE_FROM_ABI basic_stringstream()
1140 : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(ios_base::in | ios_base::out) {}
1158 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::in | ios_base::out) {}
11411159
11421160 _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(ios_base::openmode __wch)
1143 : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(__wch) {}
1161 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch) {}
11441162
11451163 _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const string_type& __s,
11461164 ios_base::openmode __wch = ios_base::in | ios_base::out)
1147 : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(__s, __wch) {}
1165 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {}
11481166
1149#if _LIBCPP_STD_VER >= 20
1167# if _LIBCPP_STD_VER >= 20
11501168 _LIBCPP_HIDE_FROM_ABI basic_stringstream(ios_base::openmode __wch, const _Allocator& __a)
11511169 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch, __a) {}
11521170
......@@ -1168,9 +1186,9 @@ public:
11681186 _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s,
11691187 ios_base::openmode __wch = ios_base::out | ios_base::in)
11701188 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {}
1171#endif // _LIBCPP_STD_VER >= 20
1189# endif // _LIBCPP_STD_VER >= 20
11721190
1173#if _LIBCPP_STD_VER >= 26
1191# if _LIBCPP_STD_VER >= 26
11741192
11751193 template <class _Tp>
11761194 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
......@@ -1188,12 +1206,12 @@ public:
11881206 _LIBCPP_HIDE_FROM_ABI basic_stringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
11891207 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which, __a) {}
11901208
1191#endif // _LIBCPP_STD_VER >= 26
1209# endif // _LIBCPP_STD_VER >= 26
11921210
11931211 basic_stringstream(const basic_stringstream&) = delete;
11941212 _LIBCPP_HIDE_FROM_ABI basic_stringstream(basic_stringstream&& __rhs)
11951213 : basic_iostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
1196 basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_);
1214 basic_istream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
11971215 }
11981216
11991217 // [stringstream.assign] Assign and swap:
......@@ -1210,18 +1228,18 @@ public:
12101228
12111229 // [stringstream.members] Member functions:
12121230 _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const {
1213 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
1231 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_));
12141232 }
12151233
1216#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
1234# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
12171235 _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
1218#else
1236# else
12191237 _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); }
12201238
12211239 _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); }
1222#endif
1240# endif
12231241
1224#if _LIBCPP_STD_VER >= 20
1242# if _LIBCPP_STD_VER >= 20
12251243 template <class _SAlloc>
12261244 requires __is_allocator<_SAlloc>::value
12271245 _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
......@@ -1229,26 +1247,26 @@ public:
12291247 }
12301248
12311249 _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); }
1232#endif // _LIBCPP_STD_VER >= 20
1250# endif // _LIBCPP_STD_VER >= 20
12331251
12341252 _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); }
12351253
1236#if _LIBCPP_STD_VER >= 20
1254# if _LIBCPP_STD_VER >= 20
12371255 template <class _SAlloc>
12381256 _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) {
12391257 __sb_.str(__s);
12401258 }
12411259
12421260 _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); }
1243#endif // _LIBCPP_STD_VER >= 20
1261# endif // _LIBCPP_STD_VER >= 20
12441262
1245#if _LIBCPP_STD_VER >= 26
1263# if _LIBCPP_STD_VER >= 26
12461264 template <class _Tp>
12471265 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
12481266 _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
12491267 rdbuf()->str(__t);
12501268 }
1251#endif // _LIBCPP_STD_VER >= 26
1269# endif // _LIBCPP_STD_VER >= 26
12521270};
12531271
12541272template <class _CharT, class _Traits, class _Allocator>
......@@ -1257,20 +1275,23 @@ swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x, basic_stringstream<_C
12571275 __x.swap(__y);
12581276}
12591277
1260#if _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
1278# if _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
12611279extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringbuf<char>;
12621280extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringstream<char>;
12631281extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostringstream<char>;
12641282extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istringstream<char>;
1265#endif
1283# endif
12661284
12671285_LIBCPP_END_NAMESPACE_STD
12681286
12691287_LIBCPP_POP_MACROS
12701288
1271#if _LIBCPP_STD_VER <= 20 && !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
1272# include <ostream>
1273# include <type_traits>
1274#endif
1289# endif // _LIBCPP_HAS_LOCALIZATION
1290
1291# if _LIBCPP_STD_VER <= 20 && !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
1292# include <ostream>
1293# include <type_traits>
1294# endif
1295#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
12751296
12761297#endif // _LIBCPP_SSTREAM
lib/libcxx/include/stack+50-46
......@@ -113,33 +113,36 @@ template <class T, class Container>
113113
114114*/
115115
116#include <__algorithm/ranges_copy.h>
117#include <__config>
118#include <__fwd/stack.h>
119#include <__iterator/back_insert_iterator.h>
120#include <__iterator/iterator_traits.h>
121#include <__memory/uses_allocator.h>
122#include <__ranges/access.h>
123#include <__ranges/concepts.h>
124#include <__ranges/container_compatible_range.h>
125#include <__ranges/from_range.h>
126#include <__type_traits/is_same.h>
127#include <__utility/forward.h>
128#include <deque>
129#include <version>
116#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
117# include <__cxx03/stack>
118#else
119# include <__algorithm/ranges_copy.h>
120# include <__config>
121# include <__fwd/stack.h>
122# include <__iterator/back_insert_iterator.h>
123# include <__iterator/iterator_traits.h>
124# include <__memory/uses_allocator.h>
125# include <__ranges/access.h>
126# include <__ranges/concepts.h>
127# include <__ranges/container_compatible_range.h>
128# include <__ranges/from_range.h>
129# include <__type_traits/is_same.h>
130# include <__utility/forward.h>
131# include <deque>
132# include <version>
130133
131134// standard-mandated includes
132135
133136// [stack.syn]
134#include <compare>
135#include <initializer_list>
137# include <compare>
138# include <initializer_list>
136139
137#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
138# pragma GCC system_header
139#endif
140# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
141# pragma GCC system_header
142# endif
140143
141144_LIBCPP_PUSH_MACROS
142#include <__undef_macros>
145# include <__undef_macros>
143146
144147_LIBCPP_BEGIN_NAMESPACE_STD
145148
......@@ -172,7 +175,7 @@ public:
172175 return *this;
173176 }
174177
175#ifndef _LIBCPP_CXX03_LANG
178# ifndef _LIBCPP_CXX03_LANG
176179 _LIBCPP_HIDE_FROM_ABI stack(stack&& __q) noexcept(is_nothrow_move_constructible<container_type>::value)
177180 : c(std::move(__q.c)) {}
178181
......@@ -182,7 +185,7 @@ public:
182185 }
183186
184187 _LIBCPP_HIDE_FROM_ABI explicit stack(container_type&& __c) : c(std::move(__c)) {}
185#endif // _LIBCPP_CXX03_LANG
188# endif // _LIBCPP_CXX03_LANG
186189
187190 _LIBCPP_HIDE_FROM_ABI explicit stack(const container_type& __c) : c(__c) {}
188191
......@@ -198,7 +201,7 @@ public:
198201 _LIBCPP_HIDE_FROM_ABI
199202 stack(const stack& __s, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
200203 : c(__s.c, __a) {}
201#ifndef _LIBCPP_CXX03_LANG
204# ifndef _LIBCPP_CXX03_LANG
202205 template <class _Alloc>
203206 _LIBCPP_HIDE_FROM_ABI
204207 stack(container_type&& __c, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
......@@ -207,9 +210,9 @@ public:
207210 _LIBCPP_HIDE_FROM_ABI
208211 stack(stack&& __s, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
209212 : c(std::move(__s.c), __a) {}
210#endif // _LIBCPP_CXX03_LANG
213# endif // _LIBCPP_CXX03_LANG
211214
212#if _LIBCPP_STD_VER >= 23
215# if _LIBCPP_STD_VER >= 23
213216 template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
214217 _LIBCPP_HIDE_FROM_ABI stack(_InputIterator __first, _InputIterator __last) : c(__first, __last) {}
215218
......@@ -229,18 +232,18 @@ public:
229232 _LIBCPP_HIDE_FROM_ABI stack(from_range_t, _Range&& __range, const _Alloc& __alloc)
230233 : c(from_range, std::forward<_Range>(__range), __alloc) {}
231234
232#endif
235# endif
233236
234 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); }
237 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); }
235238 _LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); }
236239 _LIBCPP_HIDE_FROM_ABI reference top() { return c.back(); }
237240 _LIBCPP_HIDE_FROM_ABI const_reference top() const { return c.back(); }
238241
239242 _LIBCPP_HIDE_FROM_ABI void push(const value_type& __v) { c.push_back(__v); }
240#ifndef _LIBCPP_CXX03_LANG
243# ifndef _LIBCPP_CXX03_LANG
241244 _LIBCPP_HIDE_FROM_ABI void push(value_type&& __v) { c.push_back(std::move(__v)); }
242245
243# if _LIBCPP_STD_VER >= 23
246# if _LIBCPP_STD_VER >= 23
244247 template <_ContainerCompatibleRange<_Tp> _Range>
245248 _LIBCPP_HIDE_FROM_ABI void push_range(_Range&& __range) {
246249 if constexpr (requires(container_type& __c) { __c.append_range(std::forward<_Range>(__range)); }) {
......@@ -249,22 +252,22 @@ public:
249252 ranges::copy(std::forward<_Range>(__range), std::back_inserter(c));
250253 }
251254 }
252# endif
255# endif
253256
254257 template <class... _Args>
255258 _LIBCPP_HIDE_FROM_ABI
256# if _LIBCPP_STD_VER >= 17
259# if _LIBCPP_STD_VER >= 17
257260 decltype(auto)
258261 emplace(_Args&&... __args) {
259262 return c.emplace_back(std::forward<_Args>(__args)...);
260263 }
261# else
264# else
262265 void
263266 emplace(_Args&&... __args) {
264267 c.emplace_back(std::forward<_Args>(__args)...);
265268 }
266# endif
267#endif // _LIBCPP_CXX03_LANG
269# endif
270# endif // _LIBCPP_CXX03_LANG
268271
269272 _LIBCPP_HIDE_FROM_ABI void pop() { c.pop_back(); }
270273
......@@ -273,7 +276,7 @@ public:
273276 swap(c, __s.c);
274277 }
275278
276 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; }
279 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; }
277280
278281 template <class _T1, class _OtherContainer>
279282 friend bool operator==(const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y);
......@@ -282,7 +285,7 @@ public:
282285 friend bool operator<(const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y);
283286};
284287
285#if _LIBCPP_STD_VER >= 17
288# if _LIBCPP_STD_VER >= 17
286289template <class _Container, class = enable_if_t<!__is_allocator<_Container>::value> >
287290stack(_Container) -> stack<typename _Container::value_type, _Container>;
288291
......@@ -291,9 +294,9 @@ template <class _Container,
291294 class = enable_if_t<!__is_allocator<_Container>::value>,
292295 class = enable_if_t<uses_allocator<_Container, _Alloc>::value> >
293296stack(_Container, _Alloc) -> stack<typename _Container::value_type, _Container>;
294#endif
297# endif
295298
296#if _LIBCPP_STD_VER >= 23
299# if _LIBCPP_STD_VER >= 23
297300template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
298301stack(_InputIterator, _InputIterator) -> stack<__iter_value_type<_InputIterator>>;
299302
......@@ -313,7 +316,7 @@ stack(from_range_t,
313316 _Range&&,
314317 _Alloc) -> stack<ranges::range_value_t<_Range>, deque<ranges::range_value_t<_Range>, _Alloc>>;
315318
316#endif
319# endif
317320
318321template <class _Tp, class _Container>
319322inline _LIBCPP_HIDE_FROM_ABI bool operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) {
......@@ -345,7 +348,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const stack<_Tp, _Container>& __x,
345348 return !(__y < __x);
346349}
347350
348#if _LIBCPP_STD_VER >= 20
351# if _LIBCPP_STD_VER >= 20
349352
350353template <class _Tp, three_way_comparable _Container>
351354_LIBCPP_HIDE_FROM_ABI compare_three_way_result_t<_Container>
......@@ -354,7 +357,7 @@ operator<=>(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y
354357 return __x.__get_container() <=> __y.__get_container();
355358}
356359
357#endif
360# endif
358361
359362template <class _Tp, class _Container, __enable_if_t<__is_swappable_v<_Container>, int> = 0>
360363inline _LIBCPP_HIDE_FROM_ABI void swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y)
......@@ -370,10 +373,11 @@ _LIBCPP_END_NAMESPACE_STD
370373
371374_LIBCPP_POP_MACROS
372375
373#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
374# include <concepts>
375# include <functional>
376# include <type_traits>
377#endif
376# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
377# include <concepts>
378# include <functional>
379# include <type_traits>
380# endif
381#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
378382
379383#endif // _LIBCPP_STACK
lib/libcxx/include/stdatomic.h+28-16
......@@ -103,6 +103,8 @@ using std::atomic_fetch_sub // see below
103103using std::atomic_fetch_sub_explicit // see below
104104using std::atomic_fetch_or // see below
105105using std::atomic_fetch_or_explicit // see below
106using std::atomic_fetch_xor // see below
107using std::atomic_fetch_xor_explicit // see below
106108using std::atomic_fetch_and // see below
107109using std::atomic_fetch_and_explicit // see below
108110using std::atomic_flag_test_and_set // see below
......@@ -115,22 +117,25 @@ using std::atomic_signal_fence // see below
115117
116118*/
117119
118#include <__config>
120#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
121# include <__cxx03/stdatomic.h>
122#else
123# include <__config>
119124
120#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
121# pragma GCC system_header
122#endif
125# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
126# pragma GCC system_header
127# endif
123128
124#if defined(__cplusplus) && _LIBCPP_STD_VER >= 23
129# if defined(__cplusplus) && _LIBCPP_STD_VER >= 23
125130
126# include <atomic>
127# include <version>
131# include <atomic>
132# include <version>
128133
129# ifdef _Atomic
130# undef _Atomic
131# endif
134# ifdef _Atomic
135# undef _Atomic
136# endif
132137
133# define _Atomic(_Tp) ::std::atomic<_Tp>
138# define _Atomic(_Tp) ::std::atomic<_Tp>
134139
135140using std::memory_order _LIBCPP_USING_IF_EXISTS;
136141using std::memory_order_relaxed _LIBCPP_USING_IF_EXISTS;
......@@ -154,10 +159,14 @@ using std::atomic_long _LIBCPP_USING_IF_EXISTS;
154159using std::atomic_ulong _LIBCPP_USING_IF_EXISTS;
155160using std::atomic_llong _LIBCPP_USING_IF_EXISTS;
156161using std::atomic_ullong _LIBCPP_USING_IF_EXISTS;
162# if _LIBCPP_HAS_CHAR8_T
157163using std::atomic_char8_t _LIBCPP_USING_IF_EXISTS;
164# endif
158165using std::atomic_char16_t _LIBCPP_USING_IF_EXISTS;
159166using std::atomic_char32_t _LIBCPP_USING_IF_EXISTS;
167# if _LIBCPP_HAS_WIDE_CHARACTERS
160168using std::atomic_wchar_t _LIBCPP_USING_IF_EXISTS;
169# endif
161170
162171using std::atomic_int8_t _LIBCPP_USING_IF_EXISTS;
163172using std::atomic_uint8_t _LIBCPP_USING_IF_EXISTS;
......@@ -204,6 +213,8 @@ using std::atomic_fetch_add_explicit _LIBCPP_USING_IF_EXISTS;
204213using std::atomic_fetch_and _LIBCPP_USING_IF_EXISTS;
205214using std::atomic_fetch_and_explicit _LIBCPP_USING_IF_EXISTS;
206215using std::atomic_fetch_or _LIBCPP_USING_IF_EXISTS;
216using std::atomic_fetch_xor_explicit _LIBCPP_USING_IF_EXISTS;
217using std::atomic_fetch_xor _LIBCPP_USING_IF_EXISTS;
207218using std::atomic_fetch_or_explicit _LIBCPP_USING_IF_EXISTS;
208219using std::atomic_fetch_sub _LIBCPP_USING_IF_EXISTS;
209220using std::atomic_fetch_sub_explicit _LIBCPP_USING_IF_EXISTS;
......@@ -220,16 +231,17 @@ using std::atomic_store_explicit _LIBCPP_USING_IF_EXISTS;
220231using std::atomic_signal_fence _LIBCPP_USING_IF_EXISTS;
221232using std::atomic_thread_fence _LIBCPP_USING_IF_EXISTS;
222233
223#elif defined(_LIBCPP_COMPILER_CLANG_BASED)
234# elif defined(_LIBCPP_COMPILER_CLANG_BASED)
224235
225236// Before C++23, we include the next <stdatomic.h> on the path to avoid hijacking
226237// the header. We do this because Clang has historically shipped a <stdatomic.h>
227238// header that would be available in all Standard modes, and we don't want to
228239// break that use case.
229# if __has_include_next(<stdatomic.h>)
230# include_next <stdatomic.h>
231# endif
240# if __has_include_next(<stdatomic.h>)
241# include_next <stdatomic.h>
242# endif
232243
233#endif // defined(__cplusplus) && _LIBCPP_STD_VER >= 23
244# endif // defined(__cplusplus) && _LIBCPP_STD_VER >= 23
245#endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
234246
235247#endif // _LIBCPP_STDATOMIC_H
lib/libcxx/include/stdbool.h+21-17
......@@ -19,22 +19,26 @@ Macros:
1919
2020*/
2121
22#include <__config>
23
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26#endif
27
28#if __has_include_next(<stdbool.h>)
29# include_next <stdbool.h>
30#endif
31
32#ifdef __cplusplus
33# undef bool
34# undef true
35# undef false
36# undef __bool_true_false_are_defined
37# define __bool_true_false_are_defined 1
38#endif
22#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
23# include <__cxx03/stdbool.h>
24#else
25# include <__config>
26
27# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28# pragma GCC system_header
29# endif
30
31# if __has_include_next(<stdbool.h>)
32# include_next <stdbool.h>
33# endif
34
35# ifdef __cplusplus
36# undef bool
37# undef true
38# undef false
39# undef __bool_true_false_are_defined
40# define __bool_true_false_are_defined 1
41# endif
42#endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
3943
4044#endif // _LIBCPP_STDBOOL_H
lib/libcxx/include/stddef.h+13-9
......@@ -24,21 +24,25 @@ Types:
2424
2525*/
2626
27#include <__config>
27#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
28# include <__cxx03/stddef.h>
29#else
30# include <__config>
2831
29#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
30# pragma GCC system_header
31#endif
32# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
33# pragma GCC system_header
34# endif
3235
3336// Note: This include is outside of header guards because we sometimes get included multiple times
3437// with different defines and the underlying <stddef.h> will know how to deal with that.
35#include_next <stddef.h>
38# include_next <stddef.h>
3639
37#ifndef _LIBCPP_STDDEF_H
38# define _LIBCPP_STDDEF_H
40# ifndef _LIBCPP_STDDEF_H
41# define _LIBCPP_STDDEF_H
3942
40# ifdef __cplusplus
43# ifdef __cplusplus
4144typedef decltype(nullptr) nullptr_t;
42# endif
45# endif
46# endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
4347
4448#endif // _LIBCPP_STDDEF_H
lib/libcxx/include/stdexcept+73-67
......@@ -41,18 +41,21 @@ public:
4141
4242*/
4343
44#include <__config>
45#include <__exception/exception.h>
46#include <__fwd/string.h>
47#include <__verbose_abort>
44#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
45# include <__cxx03/stdexcept>
46#else
47# include <__config>
48# include <__exception/exception.h>
49# include <__fwd/string.h>
50# include <__verbose_abort>
4851
49#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
50# pragma GCC system_header
51#endif
52# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
53# pragma GCC system_header
54# endif
5255
5356_LIBCPP_BEGIN_NAMESPACE_STD
5457
55#ifndef _LIBCPP_ABI_VCRUNTIME
58# ifndef _LIBCPP_ABI_VCRUNTIME
5659class _LIBCPP_HIDDEN __libcpp_refstring {
5760 const char* __imp_;
5861
......@@ -66,7 +69,7 @@ public:
6669
6770 _LIBCPP_HIDE_FROM_ABI const char* c_str() const _NOEXCEPT { return __imp_; }
6871};
69#endif // !_LIBCPP_ABI_VCRUNTIME
72# endif // !_LIBCPP_ABI_VCRUNTIME
7073
7174_LIBCPP_END_NAMESPACE_STD
7275
......@@ -74,7 +77,7 @@ namespace std // purposefully not using versioning namespace
7477{
7578
7679class _LIBCPP_EXPORTED_FROM_ABI logic_error : public exception {
77#ifndef _LIBCPP_ABI_VCRUNTIME
80# ifndef _LIBCPP_ABI_VCRUNTIME
7881
7982private:
8083 std::__libcpp_refstring __imp_;
......@@ -89,16 +92,16 @@ public:
8992 ~logic_error() _NOEXCEPT override;
9093
9194 const char* what() const _NOEXCEPT override;
92#else
95# else
9396
9497public:
9598 explicit logic_error(const std::string&); // Symbol uses versioned std::string
9699 _LIBCPP_HIDE_FROM_ABI explicit logic_error(const char* __s) : exception(__s) {}
97#endif
100# endif
98101};
99102
100103class _LIBCPP_EXPORTED_FROM_ABI runtime_error : public exception {
101#ifndef _LIBCPP_ABI_VCRUNTIME
104# ifndef _LIBCPP_ABI_VCRUNTIME
102105
103106private:
104107 std::__libcpp_refstring __imp_;
......@@ -113,12 +116,12 @@ public:
113116 ~runtime_error() _NOEXCEPT override;
114117
115118 const char* what() const _NOEXCEPT override;
116#else
119# else
117120
118121public:
119122 explicit runtime_error(const std::string&); // Symbol uses versioned std::string
120123 _LIBCPP_HIDE_FROM_ABI explicit runtime_error(const char* __s) : exception(__s) {}
121#endif // _LIBCPP_ABI_VCRUNTIME
124# endif // _LIBCPP_ABI_VCRUNTIME
122125};
123126
124127class _LIBCPP_EXPORTED_FROM_ABI domain_error : public logic_error {
......@@ -126,11 +129,11 @@ public:
126129 _LIBCPP_HIDE_FROM_ABI explicit domain_error(const string& __s) : logic_error(__s) {}
127130 _LIBCPP_HIDE_FROM_ABI explicit domain_error(const char* __s) : logic_error(__s) {}
128131
129#ifndef _LIBCPP_ABI_VCRUNTIME
132# ifndef _LIBCPP_ABI_VCRUNTIME
130133 _LIBCPP_HIDE_FROM_ABI domain_error(const domain_error&) _NOEXCEPT = default;
131134 _LIBCPP_HIDE_FROM_ABI domain_error& operator=(const domain_error&) _NOEXCEPT = default;
132135 ~domain_error() _NOEXCEPT override;
133#endif
136# endif
134137};
135138
136139class _LIBCPP_EXPORTED_FROM_ABI invalid_argument : public logic_error {
......@@ -138,22 +141,22 @@ public:
138141 _LIBCPP_HIDE_FROM_ABI explicit invalid_argument(const string& __s) : logic_error(__s) {}
139142 _LIBCPP_HIDE_FROM_ABI explicit invalid_argument(const char* __s) : logic_error(__s) {}
140143
141#ifndef _LIBCPP_ABI_VCRUNTIME
144# ifndef _LIBCPP_ABI_VCRUNTIME
142145 _LIBCPP_HIDE_FROM_ABI invalid_argument(const invalid_argument&) _NOEXCEPT = default;
143146 _LIBCPP_HIDE_FROM_ABI invalid_argument& operator=(const invalid_argument&) _NOEXCEPT = default;
144147 ~invalid_argument() _NOEXCEPT override;
145#endif
148# endif
146149};
147150
148151class _LIBCPP_EXPORTED_FROM_ABI length_error : public logic_error {
149152public:
150153 _LIBCPP_HIDE_FROM_ABI explicit length_error(const string& __s) : logic_error(__s) {}
151154 _LIBCPP_HIDE_FROM_ABI explicit length_error(const char* __s) : logic_error(__s) {}
152#ifndef _LIBCPP_ABI_VCRUNTIME
155# ifndef _LIBCPP_ABI_VCRUNTIME
153156 _LIBCPP_HIDE_FROM_ABI length_error(const length_error&) _NOEXCEPT = default;
154157 _LIBCPP_HIDE_FROM_ABI length_error& operator=(const length_error&) _NOEXCEPT = default;
155158 ~length_error() _NOEXCEPT override;
156#endif
159# endif
157160};
158161
159162class _LIBCPP_EXPORTED_FROM_ABI out_of_range : public logic_error {
......@@ -161,11 +164,11 @@ public:
161164 _LIBCPP_HIDE_FROM_ABI explicit out_of_range(const string& __s) : logic_error(__s) {}
162165 _LIBCPP_HIDE_FROM_ABI explicit out_of_range(const char* __s) : logic_error(__s) {}
163166
164#ifndef _LIBCPP_ABI_VCRUNTIME
167# ifndef _LIBCPP_ABI_VCRUNTIME
165168 _LIBCPP_HIDE_FROM_ABI out_of_range(const out_of_range&) _NOEXCEPT = default;
166169 _LIBCPP_HIDE_FROM_ABI out_of_range& operator=(const out_of_range&) _NOEXCEPT = default;
167170 ~out_of_range() _NOEXCEPT override;
168#endif
171# endif
169172};
170173
171174class _LIBCPP_EXPORTED_FROM_ABI range_error : public runtime_error {
......@@ -173,11 +176,11 @@ public:
173176 _LIBCPP_HIDE_FROM_ABI explicit range_error(const string& __s) : runtime_error(__s) {}
174177 _LIBCPP_HIDE_FROM_ABI explicit range_error(const char* __s) : runtime_error(__s) {}
175178
176#ifndef _LIBCPP_ABI_VCRUNTIME
179# ifndef _LIBCPP_ABI_VCRUNTIME
177180 _LIBCPP_HIDE_FROM_ABI range_error(const range_error&) _NOEXCEPT = default;
178181 _LIBCPP_HIDE_FROM_ABI range_error& operator=(const range_error&) _NOEXCEPT = default;
179182 ~range_error() _NOEXCEPT override;
180#endif
183# endif
181184};
182185
183186class _LIBCPP_EXPORTED_FROM_ABI overflow_error : public runtime_error {
......@@ -185,11 +188,11 @@ public:
185188 _LIBCPP_HIDE_FROM_ABI explicit overflow_error(const string& __s) : runtime_error(__s) {}
186189 _LIBCPP_HIDE_FROM_ABI explicit overflow_error(const char* __s) : runtime_error(__s) {}
187190
188#ifndef _LIBCPP_ABI_VCRUNTIME
191# ifndef _LIBCPP_ABI_VCRUNTIME
189192 _LIBCPP_HIDE_FROM_ABI overflow_error(const overflow_error&) _NOEXCEPT = default;
190193 _LIBCPP_HIDE_FROM_ABI overflow_error& operator=(const overflow_error&) _NOEXCEPT = default;
191194 ~overflow_error() _NOEXCEPT override;
192#endif
195# endif
193196};
194197
195198class _LIBCPP_EXPORTED_FROM_ABI underflow_error : public runtime_error {
......@@ -197,11 +200,11 @@ public:
197200 _LIBCPP_HIDE_FROM_ABI explicit underflow_error(const string& __s) : runtime_error(__s) {}
198201 _LIBCPP_HIDE_FROM_ABI explicit underflow_error(const char* __s) : runtime_error(__s) {}
199202
200#ifndef _LIBCPP_ABI_VCRUNTIME
203# ifndef _LIBCPP_ABI_VCRUNTIME
201204 _LIBCPP_HIDE_FROM_ABI underflow_error(const underflow_error&) _NOEXCEPT = default;
202205 _LIBCPP_HIDE_FROM_ABI underflow_error& operator=(const underflow_error&) _NOEXCEPT = default;
203206 ~underflow_error() _NOEXCEPT override;
204#endif
207# endif
205208};
206209
207210} // namespace std
......@@ -209,78 +212,81 @@ public:
209212_LIBCPP_BEGIN_NAMESPACE_STD
210213
211214// in the dylib
212_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_runtime_error(const char*);
215[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_runtime_error(const char*);
213216
214_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_logic_error(const char* __msg) {
215#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
217[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_logic_error(const char* __msg) {
218# if _LIBCPP_HAS_EXCEPTIONS
216219 throw logic_error(__msg);
217#else
220# else
218221 _LIBCPP_VERBOSE_ABORT("logic_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
219#endif
222# endif
220223}
221224
222_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_domain_error(const char* __msg) {
223#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
225[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_domain_error(const char* __msg) {
226# if _LIBCPP_HAS_EXCEPTIONS
224227 throw domain_error(__msg);
225#else
228# else
226229 _LIBCPP_VERBOSE_ABORT("domain_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
227#endif
230# endif
228231}
229232
230_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_invalid_argument(const char* __msg) {
231#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
233[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_invalid_argument(const char* __msg) {
234# if _LIBCPP_HAS_EXCEPTIONS
232235 throw invalid_argument(__msg);
233#else
236# else
234237 _LIBCPP_VERBOSE_ABORT("invalid_argument was thrown in -fno-exceptions mode with message \"%s\"", __msg);
235#endif
238# endif
236239}
237240
238_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_length_error(const char* __msg) {
239#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
241[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_length_error(const char* __msg) {
242# if _LIBCPP_HAS_EXCEPTIONS
240243 throw length_error(__msg);
241#else
244# else
242245 _LIBCPP_VERBOSE_ABORT("length_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
243#endif
246# endif
244247}
245248
246_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range(const char* __msg) {
247#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
249[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range(const char* __msg) {
250# if _LIBCPP_HAS_EXCEPTIONS
248251 throw out_of_range(__msg);
249#else
252# else
250253 _LIBCPP_VERBOSE_ABORT("out_of_range was thrown in -fno-exceptions mode with message \"%s\"", __msg);
251#endif
254# endif
252255}
253256
254_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_range_error(const char* __msg) {
255#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
257[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_range_error(const char* __msg) {
258# if _LIBCPP_HAS_EXCEPTIONS
256259 throw range_error(__msg);
257#else
260# else
258261 _LIBCPP_VERBOSE_ABORT("range_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
259#endif
262# endif
260263}
261264
262_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_overflow_error(const char* __msg) {
263#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
265[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_overflow_error(const char* __msg) {
266# if _LIBCPP_HAS_EXCEPTIONS
264267 throw overflow_error(__msg);
265#else
268# else
266269 _LIBCPP_VERBOSE_ABORT("overflow_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
267#endif
270# endif
268271}
269272
270_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_underflow_error(const char* __msg) {
271#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
273[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_underflow_error(const char* __msg) {
274# if _LIBCPP_HAS_EXCEPTIONS
272275 throw underflow_error(__msg);
273#else
276# else
274277 _LIBCPP_VERBOSE_ABORT("underflow_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
275#endif
278# endif
276279}
277280
278281_LIBCPP_END_NAMESPACE_STD
279282
280#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
281# include <cstdlib>
282# include <exception>
283# include <iosfwd>
284#endif
283# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
284# include <cstddef>
285# include <cstdlib>
286# include <exception>
287# include <iosfwd>
288# include <new>
289# endif
290#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
285291
286292#endif // _LIBCPP_STDEXCEPT
lib/libcxx/include/stdint.h deleted-127
......@@ -1,127 +0,0 @@
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_STDINT_H
11// AIX system headers need stdint.h to be re-enterable while _STD_TYPES_T
12// is defined until an inclusion of it without _STD_TYPES_T occurs, in which
13// case the header guard macro is defined.
14#if !defined(_AIX) || !defined(_STD_TYPES_T)
15# define _LIBCPP_STDINT_H
16#endif // _STD_TYPES_T
17
18/*
19 stdint.h synopsis
20
21Macros:
22
23 INT8_MIN
24 INT16_MIN
25 INT32_MIN
26 INT64_MIN
27
28 INT8_MAX
29 INT16_MAX
30 INT32_MAX
31 INT64_MAX
32
33 UINT8_MAX
34 UINT16_MAX
35 UINT32_MAX
36 UINT64_MAX
37
38 INT_LEAST8_MIN
39 INT_LEAST16_MIN
40 INT_LEAST32_MIN
41 INT_LEAST64_MIN
42
43 INT_LEAST8_MAX
44 INT_LEAST16_MAX
45 INT_LEAST32_MAX
46 INT_LEAST64_MAX
47
48 UINT_LEAST8_MAX
49 UINT_LEAST16_MAX
50 UINT_LEAST32_MAX
51 UINT_LEAST64_MAX
52
53 INT_FAST8_MIN
54 INT_FAST16_MIN
55 INT_FAST32_MIN
56 INT_FAST64_MIN
57
58 INT_FAST8_MAX
59 INT_FAST16_MAX
60 INT_FAST32_MAX
61 INT_FAST64_MAX
62
63 UINT_FAST8_MAX
64 UINT_FAST16_MAX
65 UINT_FAST32_MAX
66 UINT_FAST64_MAX
67
68 INTPTR_MIN
69 INTPTR_MAX
70 UINTPTR_MAX
71
72 INTMAX_MIN
73 INTMAX_MAX
74
75 UINTMAX_MAX
76
77 PTRDIFF_MIN
78 PTRDIFF_MAX
79
80 SIG_ATOMIC_MIN
81 SIG_ATOMIC_MAX
82
83 SIZE_MAX
84
85 WCHAR_MIN
86 WCHAR_MAX
87
88 WINT_MIN
89 WINT_MAX
90
91 INT8_C(value)
92 INT16_C(value)
93 INT32_C(value)
94 INT64_C(value)
95
96 UINT8_C(value)
97 UINT16_C(value)
98 UINT32_C(value)
99 UINT64_C(value)
100
101 INTMAX_C(value)
102 UINTMAX_C(value)
103
104*/
105
106#include <__config>
107
108#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
109# pragma GCC system_header
110#endif
111
112/* C99 stdlib (e.g. glibc < 2.18) does not provide macros needed
113 for C++11 unless __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS
114 are defined
115*/
116#if defined(__cplusplus) && !defined(__STDC_LIMIT_MACROS)
117# define __STDC_LIMIT_MACROS
118#endif
119#if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS)
120# define __STDC_CONSTANT_MACROS
121#endif
122
123#if __has_include_next(<stdint.h>)
124# include_next <stdint.h>
125#endif
126
127#endif // _LIBCPP_STDINT_H
lib/libcxx/include/stdio.h+20-21
......@@ -7,17 +7,6 @@
77//
88//===----------------------------------------------------------------------===//
99
10#if defined(__need_FILE) || defined(__need___FILE)
11
12# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
13# pragma GCC system_header
14# endif
15
16# include_next <stdio.h>
17
18#elif !defined(_LIBCPP_STDIO_H)
19# define _LIBCPP_STDIO_H
20
2110/*
2211 stdio.h synopsis
2312
......@@ -98,26 +87,36 @@ int ferror(FILE* stream);
9887void perror(const char* s);
9988*/
10089
90#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
91# include <__cxx03/stdio.h>
92#else
10193# include <__config>
10294
10395# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
10496# pragma GCC system_header
10597# endif
10698
99// The inclusion of the system's <stdio.h> is intentionally done once outside of any include
100// guards because some code expects to be able to include the underlying system header multiple
101// times to get different definitions based on the macros that are set before inclusion.
107102# if __has_include_next(<stdio.h>)
108103# include_next <stdio.h>
109104# endif
110105
111# ifdef __cplusplus
106# ifndef _LIBCPP_STDIO_H
107# define _LIBCPP_STDIO_H
112108
113# undef getc
114# undef putc
115# undef clearerr
116# undef feof
117# undef ferror
118# undef putchar
119# undef getchar
109# ifdef __cplusplus
120110
121# endif
111# undef getc
112# undef putc
113# undef clearerr
114# undef feof
115# undef ferror
116# undef putchar
117# undef getchar
118
119# endif // __cplusplus
120# endif // _LIBCPP_STDIO_H
122121
123#endif // _LIBCPP_STDIO_H
122#endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
lib/libcxx/include/stdlib.h+42-43
......@@ -7,17 +7,6 @@
77//
88//===----------------------------------------------------------------------===//
99
10#if defined(__need_malloc_and_calloc)
11
12# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
13# pragma GCC system_header
14# endif
15
16# include_next <stdlib.h>
17
18#elif !defined(_LIBCPP_STDLIB_H)
19# define _LIBCPP_STDLIB_H
20
2110/*
2211 stdlib.h synopsis
2312
......@@ -84,68 +73,78 @@ void *aligned_alloc(size_t alignment, size_t size); // C11
8473
8574*/
8675
76#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
77# include <__cxx03/stdlib.h>
78#else
8779# include <__config>
8880
8981# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
9082# pragma GCC system_header
9183# endif
9284
85// The inclusion of the system's <stdlib.h> is intentionally done once outside of any include
86// guards because some code expects to be able to include the underlying system header multiple
87// times to get different definitions based on the macros that are set before inclusion.
9388# if __has_include_next(<stdlib.h>)
9489# include_next <stdlib.h>
9590# endif
9691
97# ifdef __cplusplus
92# if !defined(_LIBCPP_STDLIB_H)
93# define _LIBCPP_STDLIB_H
94
95# ifdef __cplusplus
9896extern "C++" {
9997// abs
10098
101# ifdef abs
102# undef abs
103# endif
104# ifdef labs
105# undef labs
106# endif
107# ifdef llabs
108# undef llabs
109# endif
99# ifdef abs
100# undef abs
101# endif
102# ifdef labs
103# undef labs
104# endif
105# ifdef llabs
106# undef llabs
107# endif
110108
111109// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
112# if !defined(_LIBCPP_MSVCRT)
113_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long abs(long __x) _NOEXCEPT { return __builtin_labs(__x); }
114_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long long abs(long long __x) _NOEXCEPT { return __builtin_llabs(__x); }
115# endif // !defined(_LIBCPP_MSVCRT)
110# if !defined(_LIBCPP_MSVCRT)
111[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long abs(long __x) _NOEXCEPT { return __builtin_labs(__x); }
112[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long long abs(long long __x) _NOEXCEPT { return __builtin_llabs(__x); }
113# endif // !defined(_LIBCPP_MSVCRT)
116114
117_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float abs(float __lcpp_x) _NOEXCEPT {
115[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float abs(float __lcpp_x) _NOEXCEPT {
118116 return __builtin_fabsf(__lcpp_x); // Use builtins to prevent needing math.h
119117}
120118
121_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double abs(double __lcpp_x) _NOEXCEPT {
119[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double abs(double __lcpp_x) _NOEXCEPT {
122120 return __builtin_fabs(__lcpp_x);
123121}
124122
125_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double abs(long double __lcpp_x) _NOEXCEPT {
123[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double abs(long double __lcpp_x) _NOEXCEPT {
126124 return __builtin_fabsl(__lcpp_x);
127125}
128126
129127// div
130128
131# ifdef div
132# undef div
133# endif
134# ifdef ldiv
135# undef ldiv
136# endif
137# ifdef lldiv
138# undef lldiv
139# endif
129# ifdef div
130# undef div
131# endif
132# ifdef ldiv
133# undef ldiv
134# endif
135# ifdef lldiv
136# undef lldiv
137# endif
140138
141139// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
142# if !defined(_LIBCPP_MSVCRT)
140# if !defined(_LIBCPP_MSVCRT)
143141inline _LIBCPP_HIDE_FROM_ABI ldiv_t div(long __x, long __y) _NOEXCEPT { return ::ldiv(__x, __y); }
144# if !(defined(__FreeBSD__) && !defined(__LONG_LONG_SUPPORTED))
142# if !(defined(__FreeBSD__) && !defined(__LONG_LONG_SUPPORTED))
145143inline _LIBCPP_HIDE_FROM_ABI lldiv_t div(long long __x, long long __y) _NOEXCEPT { return ::lldiv(__x, __y); }
146# endif
147# endif // _LIBCPP_MSVCRT
144# endif
145# endif // _LIBCPP_MSVCRT
148146} // extern "C++"
149# endif // __cplusplus
147# endif // __cplusplus
148# endif // _LIBCPP_STDLIB_H
150149
151#endif // _LIBCPP_STDLIB_H
150#endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
lib/libcxx/include/stop_token+20-15
......@@ -31,26 +31,31 @@ namespace std {
3131
3232*/
3333
34#include <__config>
34#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
35# include <__cxx03/stop_token>
36#else
37# include <__config>
3538
36#if !defined(_LIBCPP_HAS_NO_THREADS)
39# if _LIBCPP_HAS_THREADS
3740
38# if _LIBCPP_STD_VER >= 20
39# include <__stop_token/stop_callback.h>
40# include <__stop_token/stop_source.h>
41# include <__stop_token/stop_token.h>
42# endif
41# if _LIBCPP_STD_VER >= 20
42# include <__stop_token/stop_callback.h>
43# include <__stop_token/stop_source.h>
44# include <__stop_token/stop_token.h>
45# endif
4346
44# include <version>
47# include <version>
4548
46# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
47# pragma GCC system_header
48# endif
49# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
50# pragma GCC system_header
51# endif
4952
50#endif // !defined(_LIBCPP_HAS_NO_THREADS)
53# endif // _LIBCPP_HAS_THREADS
5154
52#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
53# include <iosfwd>
54#endif
55# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
56# include <cstddef>
57# include <iosfwd>
58# endif
59#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
5560
5661#endif // _LIBCPP_STOP_TOKEN
lib/libcxx/include/streambuf+126-179
......@@ -107,23 +107,29 @@ protected:
107107
108108*/
109109
110#include <__assert>
111#include <__config>
112#include <__fwd/streambuf.h>
113#include <__locale>
114#include <__type_traits/is_same.h>
115#include <__utility/is_valid_range.h>
116#include <climits>
117#include <ios>
118#include <iosfwd>
119#include <version>
120
121#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
122# pragma GCC system_header
123#endif
110#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
111# include <__cxx03/streambuf>
112#else
113# include <__config>
114
115# if _LIBCPP_HAS_LOCALIZATION
116
117# include <__assert>
118# include <__fwd/streambuf.h>
119# include <__locale>
120# include <__type_traits/is_same.h>
121# include <__utility/is_valid_range.h>
122# include <climits>
123# include <ios>
124# include <iosfwd>
125# include <version>
126
127# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
128# pragma GCC system_header
129# endif
124130
125131_LIBCPP_PUSH_MACROS
126#include <__undef_macros>
132# include <__undef_macros>
127133
128134_LIBCPP_BEGIN_NAMESPACE_STD
129135
......@@ -140,7 +146,7 @@ public:
140146 static_assert(is_same<_CharT, typename traits_type::char_type>::value,
141147 "traits_type::char_type must be the same type as CharT");
142148
143 virtual ~basic_streambuf();
149 virtual ~basic_streambuf() {}
144150
145151 // 27.6.2.2.1 locales:
146152 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 locale pubimbue(const locale& __loc) {
......@@ -223,10 +229,36 @@ public:
223229 }
224230
225231protected:
226 basic_streambuf();
227 basic_streambuf(const basic_streambuf& __rhs);
228 basic_streambuf& operator=(const basic_streambuf& __rhs);
229 void swap(basic_streambuf& __rhs);
232 basic_streambuf() {}
233 basic_streambuf(const basic_streambuf& __sb)
234 : __loc_(__sb.__loc_),
235 __binp_(__sb.__binp_),
236 __ninp_(__sb.__ninp_),
237 __einp_(__sb.__einp_),
238 __bout_(__sb.__bout_),
239 __nout_(__sb.__nout_),
240 __eout_(__sb.__eout_) {}
241
242 basic_streambuf& operator=(const basic_streambuf& __sb) {
243 __loc_ = __sb.__loc_;
244 __binp_ = __sb.__binp_;
245 __ninp_ = __sb.__ninp_;
246 __einp_ = __sb.__einp_;
247 __bout_ = __sb.__bout_;
248 __nout_ = __sb.__nout_;
249 __eout_ = __sb.__eout_;
250 return *this;
251 }
252
253 void swap(basic_streambuf& __sb) {
254 std::swap(__loc_, __sb.__loc_);
255 std::swap(__binp_, __sb.__binp_);
256 std::swap(__ninp_, __sb.__ninp_);
257 std::swap(__einp_, __sb.__einp_);
258 std::swap(__bout_, __sb.__bout_);
259 std::swap(__nout_, __sb.__nout_);
260 std::swap(__eout_, __sb.__eout_);
261 }
230262
231263 // 27.6.2.3.2 Get area:
232264 _LIBCPP_HIDE_FROM_ABI char_type* eback() const { return __binp_; }
......@@ -261,185 +293,100 @@ protected:
261293
262294 // 27.6.2.4 virtual functions:
263295 // 27.6.2.4.1 Locales:
264 virtual void imbue(const locale& __loc);
296 virtual void imbue(const locale&) {}
265297
266298 // 27.6.2.4.2 Buffer management and positioning:
267 virtual basic_streambuf* setbuf(char_type* __s, streamsize __n);
268 virtual pos_type
269 seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which = ios_base::in | ios_base::out);
270 virtual pos_type seekpos(pos_type __sp, ios_base::openmode __which = ios_base::in | ios_base::out);
271 virtual int sync();
299 virtual basic_streambuf* setbuf(char_type*, streamsize) { return this; }
300 virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out) {
301 return pos_type(off_type(-1));
302 }
303 virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out) {
304 return pos_type(off_type(-1));
305 }
306 virtual int sync() { return 0; }
272307
273308 // 27.6.2.4.3 Get area:
274 virtual streamsize showmanyc();
275 virtual streamsize xsgetn(char_type* __s, streamsize __n);
276 virtual int_type underflow();
277 virtual int_type uflow();
309 virtual streamsize showmanyc() { return 0; }
310
311 virtual streamsize xsgetn(char_type* __s, streamsize __n) {
312 const int_type __eof = traits_type::eof();
313 int_type __c;
314 streamsize __i = 0;
315 while (__i < __n) {
316 if (__ninp_ < __einp_) {
317 const streamsize __len = std::min(static_cast<streamsize>(INT_MAX), std::min(__einp_ - __ninp_, __n - __i));
318 traits_type::copy(__s, __ninp_, __len);
319 __s += __len;
320 __i += __len;
321 this->gbump(__len);
322 } else if ((__c = uflow()) != __eof) {
323 *__s = traits_type::to_char_type(__c);
324 ++__s;
325 ++__i;
326 } else
327 break;
328 }
329 return __i;
330 }
331
332 virtual int_type underflow() { return traits_type::eof(); }
333 virtual int_type uflow() {
334 if (underflow() == traits_type::eof())
335 return traits_type::eof();
336 return traits_type::to_int_type(*__ninp_++);
337 }
278338
279339 // 27.6.2.4.4 Putback:
280 virtual int_type pbackfail(int_type __c = traits_type::eof());
340 virtual int_type pbackfail(int_type = traits_type::eof()) { return traits_type::eof(); }
281341
282342 // 27.6.2.4.5 Put area:
283 virtual streamsize xsputn(const char_type* __s, streamsize __n);
284 virtual int_type overflow(int_type __c = traits_type::eof());
343 virtual streamsize xsputn(const char_type* __s, streamsize __n) {
344 streamsize __i = 0;
345 int_type __eof = traits_type::eof();
346 while (__i < __n) {
347 if (__nout_ >= __eout_) {
348 if (overflow(traits_type::to_int_type(*__s)) == __eof)
349 break;
350 ++__s;
351 ++__i;
352 } else {
353 streamsize __chunk_size = std::min(__eout_ - __nout_, __n - __i);
354 traits_type::copy(__nout_, __s, __chunk_size);
355 __nout_ += __chunk_size;
356 __s += __chunk_size;
357 __i += __chunk_size;
358 }
359 }
360 return __i;
361 }
362
363 virtual int_type overflow(int_type = traits_type::eof()) { return traits_type::eof(); }
285364
286365private:
287366 locale __loc_;
288 char_type* __binp_;
289 char_type* __ninp_;
290 char_type* __einp_;
291 char_type* __bout_;
292 char_type* __nout_;
293 char_type* __eout_;
367 char_type* __binp_ = nullptr;
368 char_type* __ninp_ = nullptr;
369 char_type* __einp_ = nullptr;
370 char_type* __bout_ = nullptr;
371 char_type* __nout_ = nullptr;
372 char_type* __eout_ = nullptr;
294373};
295374
296template <class _CharT, class _Traits>
297basic_streambuf<_CharT, _Traits>::~basic_streambuf() {}
298
299template <class _CharT, class _Traits>
300basic_streambuf<_CharT, _Traits>::basic_streambuf()
301 : __binp_(nullptr), __ninp_(nullptr), __einp_(nullptr), __bout_(nullptr), __nout_(nullptr), __eout_(nullptr) {}
302
303template <class _CharT, class _Traits>
304basic_streambuf<_CharT, _Traits>::basic_streambuf(const basic_streambuf& __sb)
305 : __loc_(__sb.__loc_),
306 __binp_(__sb.__binp_),
307 __ninp_(__sb.__ninp_),
308 __einp_(__sb.__einp_),
309 __bout_(__sb.__bout_),
310 __nout_(__sb.__nout_),
311 __eout_(__sb.__eout_) {}
312
313template <class _CharT, class _Traits>
314basic_streambuf<_CharT, _Traits>& basic_streambuf<_CharT, _Traits>::operator=(const basic_streambuf& __sb) {
315 __loc_ = __sb.__loc_;
316 __binp_ = __sb.__binp_;
317 __ninp_ = __sb.__ninp_;
318 __einp_ = __sb.__einp_;
319 __bout_ = __sb.__bout_;
320 __nout_ = __sb.__nout_;
321 __eout_ = __sb.__eout_;
322 return *this;
323}
324
325template <class _CharT, class _Traits>
326void basic_streambuf<_CharT, _Traits>::swap(basic_streambuf& __sb) {
327 std::swap(__loc_, __sb.__loc_);
328 std::swap(__binp_, __sb.__binp_);
329 std::swap(__ninp_, __sb.__ninp_);
330 std::swap(__einp_, __sb.__einp_);
331 std::swap(__bout_, __sb.__bout_);
332 std::swap(__nout_, __sb.__nout_);
333 std::swap(__eout_, __sb.__eout_);
334}
335
336template <class _CharT, class _Traits>
337void basic_streambuf<_CharT, _Traits>::imbue(const locale&) {}
338
339template <class _CharT, class _Traits>
340basic_streambuf<_CharT, _Traits>* basic_streambuf<_CharT, _Traits>::setbuf(char_type*, streamsize) {
341 return this;
342}
343
344template <class _CharT, class _Traits>
345typename basic_streambuf<_CharT, _Traits>::pos_type
346basic_streambuf<_CharT, _Traits>::seekoff(off_type, ios_base::seekdir, ios_base::openmode) {
347 return pos_type(off_type(-1));
348}
349
350template <class _CharT, class _Traits>
351typename basic_streambuf<_CharT, _Traits>::pos_type
352basic_streambuf<_CharT, _Traits>::seekpos(pos_type, ios_base::openmode) {
353 return pos_type(off_type(-1));
354}
355
356template <class _CharT, class _Traits>
357int basic_streambuf<_CharT, _Traits>::sync() {
358 return 0;
359}
360
361template <class _CharT, class _Traits>
362streamsize basic_streambuf<_CharT, _Traits>::showmanyc() {
363 return 0;
364}
365
366template <class _CharT, class _Traits>
367streamsize basic_streambuf<_CharT, _Traits>::xsgetn(char_type* __s, streamsize __n) {
368 const int_type __eof = traits_type::eof();
369 int_type __c;
370 streamsize __i = 0;
371 while (__i < __n) {
372 if (__ninp_ < __einp_) {
373 const streamsize __len = std::min(static_cast<streamsize>(INT_MAX), std::min(__einp_ - __ninp_, __n - __i));
374 traits_type::copy(__s, __ninp_, __len);
375 __s += __len;
376 __i += __len;
377 this->gbump(__len);
378 } else if ((__c = uflow()) != __eof) {
379 *__s = traits_type::to_char_type(__c);
380 ++__s;
381 ++__i;
382 } else
383 break;
384 }
385 return __i;
386}
387
388template <class _CharT, class _Traits>
389typename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>::underflow() {
390 return traits_type::eof();
391}
392
393template <class _CharT, class _Traits>
394typename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>::uflow() {
395 if (underflow() == traits_type::eof())
396 return traits_type::eof();
397 return traits_type::to_int_type(*__ninp_++);
398}
399
400template <class _CharT, class _Traits>
401typename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>::pbackfail(int_type) {
402 return traits_type::eof();
403}
404
405template <class _CharT, class _Traits>
406streamsize basic_streambuf<_CharT, _Traits>::xsputn(const char_type* __s, streamsize __n) {
407 streamsize __i = 0;
408 int_type __eof = traits_type::eof();
409 while (__i < __n) {
410 if (__nout_ >= __eout_) {
411 if (overflow(traits_type::to_int_type(*__s)) == __eof)
412 break;
413 ++__s;
414 ++__i;
415 } else {
416 streamsize __chunk_size = std::min(__eout_ - __nout_, __n - __i);
417 traits_type::copy(__nout_, __s, __chunk_size);
418 __nout_ += __chunk_size;
419 __s += __chunk_size;
420 __i += __chunk_size;
421 }
422 }
423 return __i;
424}
425
426template <class _CharT, class _Traits>
427typename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>::overflow(int_type) {
428 return traits_type::eof();
429}
430
431375extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<char>;
432376
433#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
377# if _LIBCPP_HAS_WIDE_CHARACTERS
434378extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<wchar_t>;
435#endif
379# endif
436380
437381_LIBCPP_END_NAMESPACE_STD
438382
439383_LIBCPP_POP_MACROS
440384
441#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
442# include <cstdint>
443#endif
385# endif // _LIBCPP_HAS_LOCALIZATION
386
387# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
388# include <cstdint>
389# endif
390#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
444391
445392#endif // _LIBCPP_STREAMBUF
lib/libcxx/include/string+463-461
......@@ -586,101 +586,106 @@ basic_string<char32_t> operator""s( const char32_t *str, size_t len );
586586
587587// clang-format on
588588
589#include <__algorithm/max.h>
590#include <__algorithm/min.h>
591#include <__algorithm/remove.h>
592#include <__algorithm/remove_if.h>
593#include <__assert>
594#include <__config>
595#include <__debug_utils/sanitizers.h>
596#include <__format/enable_insertable.h>
597#include <__functional/hash.h>
598#include <__functional/unary_function.h>
599#include <__fwd/string.h>
600#include <__ios/fpos.h>
601#include <__iterator/bounded_iter.h>
602#include <__iterator/distance.h>
603#include <__iterator/iterator_traits.h>
604#include <__iterator/reverse_iterator.h>
605#include <__iterator/wrap_iter.h>
606#include <__memory/addressof.h>
607#include <__memory/allocate_at_least.h>
608#include <__memory/allocator.h>
609#include <__memory/allocator_traits.h>
610#include <__memory/compressed_pair.h>
611#include <__memory/construct_at.h>
612#include <__memory/pointer_traits.h>
613#include <__memory/swap_allocator.h>
614#include <__memory_resource/polymorphic_allocator.h>
615#include <__ranges/access.h>
616#include <__ranges/concepts.h>
617#include <__ranges/container_compatible_range.h>
618#include <__ranges/from_range.h>
619#include <__ranges/size.h>
620#include <__string/char_traits.h>
621#include <__string/extern_template_lists.h>
622#include <__type_traits/conditional.h>
623#include <__type_traits/is_allocator.h>
624#include <__type_traits/is_array.h>
625#include <__type_traits/is_convertible.h>
626#include <__type_traits/is_nothrow_assignable.h>
627#include <__type_traits/is_nothrow_constructible.h>
628#include <__type_traits/is_same.h>
629#include <__type_traits/is_standard_layout.h>
630#include <__type_traits/is_trivial.h>
631#include <__type_traits/is_trivially_relocatable.h>
632#include <__type_traits/noexcept_move_assign_container.h>
633#include <__type_traits/remove_cvref.h>
634#include <__type_traits/void_t.h>
635#include <__utility/auto_cast.h>
636#include <__utility/declval.h>
637#include <__utility/forward.h>
638#include <__utility/is_pointer_in_range.h>
639#include <__utility/move.h>
640#include <__utility/swap.h>
641#include <__utility/unreachable.h>
642#include <climits>
643#include <cstdio> // EOF
644#include <cstring>
645#include <limits>
646#include <stdexcept>
647#include <string_view>
648#include <version>
649
650#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
651# include <cwchar>
652#endif
589#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
590# include <__cxx03/string>
591#else
592# include <__algorithm/max.h>
593# include <__algorithm/min.h>
594# include <__algorithm/remove.h>
595# include <__algorithm/remove_if.h>
596# include <__assert>
597# include <__config>
598# include <__debug_utils/sanitizers.h>
599# include <__format/enable_insertable.h>
600# include <__functional/hash.h>
601# include <__functional/unary_function.h>
602# include <__fwd/string.h>
603# include <__ios/fpos.h>
604# include <__iterator/bounded_iter.h>
605# include <__iterator/distance.h>
606# include <__iterator/iterator_traits.h>
607# include <__iterator/reverse_iterator.h>
608# include <__iterator/wrap_iter.h>
609# include <__memory/addressof.h>
610# include <__memory/allocate_at_least.h>
611# include <__memory/allocator.h>
612# include <__memory/allocator_traits.h>
613# include <__memory/compressed_pair.h>
614# include <__memory/construct_at.h>
615# include <__memory/noexcept_move_assign_container.h>
616# include <__memory/pointer_traits.h>
617# include <__memory/swap_allocator.h>
618# include <__memory_resource/polymorphic_allocator.h>
619# include <__ranges/access.h>
620# include <__ranges/concepts.h>
621# include <__ranges/container_compatible_range.h>
622# include <__ranges/from_range.h>
623# include <__ranges/size.h>
624# include <__string/char_traits.h>
625# include <__string/extern_template_lists.h>
626# include <__type_traits/conditional.h>
627# include <__type_traits/enable_if.h>
628# include <__type_traits/is_allocator.h>
629# include <__type_traits/is_array.h>
630# include <__type_traits/is_convertible.h>
631# include <__type_traits/is_nothrow_assignable.h>
632# include <__type_traits/is_nothrow_constructible.h>
633# include <__type_traits/is_same.h>
634# include <__type_traits/is_standard_layout.h>
635# include <__type_traits/is_trivial.h>
636# include <__type_traits/is_trivially_relocatable.h>
637# include <__type_traits/remove_cvref.h>
638# include <__type_traits/void_t.h>
639# include <__utility/auto_cast.h>
640# include <__utility/declval.h>
641# include <__utility/forward.h>
642# include <__utility/is_pointer_in_range.h>
643# include <__utility/move.h>
644# include <__utility/scope_guard.h>
645# include <__utility/swap.h>
646# include <__utility/unreachable.h>
647# include <climits>
648# include <cstdio> // EOF
649# include <cstring>
650# include <limits>
651# include <stdexcept>
652# include <string_view>
653# include <version>
654
655# if _LIBCPP_HAS_WIDE_CHARACTERS
656# include <cwchar>
657# endif
653658
654659// standard-mandated includes
655660
656661// [iterator.range]
657#include <__iterator/access.h>
658#include <__iterator/data.h>
659#include <__iterator/empty.h>
660#include <__iterator/reverse_access.h>
661#include <__iterator/size.h>
662# include <__iterator/access.h>
663# include <__iterator/data.h>
664# include <__iterator/empty.h>
665# include <__iterator/reverse_access.h>
666# include <__iterator/size.h>
662667
663668// [string.syn]
664#include <compare>
665#include <initializer_list>
669# include <compare>
670# include <initializer_list>
666671
667#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
668# pragma GCC system_header
669#endif
672# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
673# pragma GCC system_header
674# endif
670675
671676_LIBCPP_PUSH_MACROS
672#include <__undef_macros>
677# include <__undef_macros>
673678
674#if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN)
675# define _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS __attribute__((__no_sanitize__("address")))
679# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
680# define _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS __attribute__((__no_sanitize__("address")))
676681// This macro disables AddressSanitizer (ASan) instrumentation for a specific function,
677682// allowing memory accesses that would normally trigger ASan errors to proceed without crashing.
678683// This is useful for accessing parts of objects memory, which should not be accessed,
679684// such as unused bytes in short strings, that should never be accessed
680685// by other parts of the program.
681#else
682# define _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
683#endif
686# else
687# define _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
688# endif
684689
685690_LIBCPP_BEGIN_NAMESPACE_STD
686691
......@@ -706,7 +711,7 @@ template <class _CharT, class _Traits, class _Allocator>
706711_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>
707712operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
708713
709#if _LIBCPP_STD_VER >= 26
714# if _LIBCPP_STD_VER >= 26
710715
711716template <class _CharT, class _Traits, class _Allocator>
712717_LIBCPP_HIDE_FROM_ABI constexpr basic_string<_CharT, _Traits, _Allocator>
......@@ -726,7 +731,7 @@ template <class _CharT, class _Traits, class _Allocator>
726731_LIBCPP_HIDE_FROM_ABI constexpr basic_string<_CharT, _Traits, _Allocator>
727732operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs);
728733
729#endif
734# endif
730735
731736extern template _LIBCPP_EXPORTED_FROM_ABI string operator+
732737 <char, char_traits<char>, allocator<char> >(char const*, string const&);
......@@ -748,10 +753,18 @@ struct __can_be_converted_to_string_view
748753struct __uninitialized_size_tag {};
749754struct __init_with_sentinel_tag {};
750755
756template <size_t _PaddingSize>
757struct __padding {
758 char __padding_[_PaddingSize];
759};
760
761template <>
762struct __padding<0> {};
763
751764template <class _CharT, class _Traits, class _Allocator>
752765class basic_string {
753766private:
754 using __default_allocator_type = allocator<_CharT>;
767 using __default_allocator_type _LIBCPP_NODEBUG = allocator<_CharT>;
755768
756769public:
757770 typedef basic_string __self;
......@@ -776,7 +789,7 @@ public:
776789 //
777790 // This string implementation doesn't contain any references into itself. It only contains a bit that says whether
778791 // it is in small or large string mode, so the entire structure is trivially relocatable if its members are.
779#if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN)
792# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
780793 // When compiling with AddressSanitizer (ASan), basic_string cannot be trivially
781794 // relocatable. Because the object's memory might be poisoned when its content
782795 // is kept inside objects memory (short string optimization), instead of in allocated
......@@ -784,13 +797,14 @@ public:
784797 // the memory to avoid triggering false positives.
785798 // Therefore it's crucial to ensure the destructor is called.
786799 using __trivially_relocatable = void;
787#else
788 using __trivially_relocatable = __conditional_t<
800# else
801 using __trivially_relocatable _LIBCPP_NODEBUG = __conditional_t<
789802 __libcpp_is_trivially_relocatable<allocator_type>::value && __libcpp_is_trivially_relocatable<pointer>::value,
790803 basic_string,
791804 void>;
792#endif
793#if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN)
805# endif
806
807# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
794808 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pointer __asan_volatile_wrapper(pointer const& __ptr) const {
795809 if (__libcpp_is_constant_evaluated())
796810 return __ptr;
......@@ -809,10 +823,10 @@ public:
809823
810824 return const_cast<const_pointer&>(__copy_ptr);
811825 }
812# define _LIBCPP_ASAN_VOLATILE_WRAPPER(PTR) __asan_volatile_wrapper(PTR)
813#else
814# define _LIBCPP_ASAN_VOLATILE_WRAPPER(PTR) PTR
815#endif
826# define _LIBCPP_ASAN_VOLATILE_WRAPPER(PTR) __asan_volatile_wrapper(PTR)
827# else
828# define _LIBCPP_ASAN_VOLATILE_WRAPPER(PTR) PTR
829# endif
816830
817831 static_assert(!is_array<value_type>::value, "Character type of basic_string must not be an array");
818832 static_assert(is_standard_layout<value_type>::value, "Character type of basic_string must be standard-layout");
......@@ -823,23 +837,23 @@ public:
823837 "Allocator::value_type must be same type as value_type");
824838 static_assert(__check_valid_allocator<allocator_type>::value, "");
825839
826#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_STRING
840# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_STRING
827841 // Users might provide custom allocators, and prior to C++20 we have no existing way to detect whether the allocator's
828842 // pointer type is contiguous (though it has to be by the Standard). Using the wrapper type ensures the iterator is
829843 // considered contiguous.
830 typedef __bounded_iter<__wrap_iter<pointer>> iterator;
831 typedef __bounded_iter<__wrap_iter<const_pointer>> const_iterator;
832#else
844 typedef __bounded_iter<__wrap_iter<pointer> > iterator;
845 typedef __bounded_iter<__wrap_iter<const_pointer> > const_iterator;
846# else
833847 typedef __wrap_iter<pointer> iterator;
834848 typedef __wrap_iter<const_pointer> const_iterator;
835#endif
849# endif
836850 typedef std::reverse_iterator<iterator> reverse_iterator;
837851 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
838852
839853private:
840854 static_assert(CHAR_BIT == 8, "This implementation assumes that one byte contains 8 bits");
841855
842#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
856# ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
843857
844858 struct __long {
845859 pointer __data_;
......@@ -852,7 +866,7 @@ private:
852866
853867 struct __short {
854868 value_type __data_[__min_cap];
855 unsigned char __padding_[sizeof(value_type) - 1];
869 _LIBCPP_NO_UNIQUE_ADDRESS __padding<sizeof(value_type) - 1> __padding_;
856870 unsigned char __size_ : 7;
857871 unsigned char __is_long_ : 1;
858872 };
......@@ -870,19 +884,19 @@ private:
870884 // This does not impact the short string representation, since we never need the MSB
871885 // for representing the size of a short string anyway.
872886
873# ifdef _LIBCPP_BIG_ENDIAN
887# ifdef _LIBCPP_BIG_ENDIAN
874888 static const size_type __endian_factor = 2;
875# else
889# else
876890 static const size_type __endian_factor = 1;
877# endif
891# endif
878892
879#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
893# else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
880894
881# ifdef _LIBCPP_BIG_ENDIAN
895# ifdef _LIBCPP_BIG_ENDIAN
882896 static const size_type __endian_factor = 1;
883# else
897# else
884898 static const size_type __endian_factor = 2;
885# endif
899# endif
886900
887901 // Attribute 'packed' is used to keep the layout compatible with the
888902 // previous definition that did not use bit fields. This is because on
......@@ -904,11 +918,11 @@ private:
904918 unsigned char __is_long_ : 1;
905919 unsigned char __size_ : 7;
906920 };
907 char __padding_[sizeof(value_type) - 1];
921 _LIBCPP_NO_UNIQUE_ADDRESS __padding<sizeof(value_type) - 1> __padding_;
908922 value_type __data_[__min_cap];
909923 };
910924
911#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
925# endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
912926
913927 static_assert(sizeof(__short) == (sizeof(value_type) * (__min_cap + 1)), "__short has an unexpected size.");
914928
......@@ -917,22 +931,31 @@ private:
917931 __long __l;
918932 };
919933
920 __compressed_pair<__rep, allocator_type> __r_;
934 _LIBCPP_COMPRESSED_PAIR(__rep, __rep_, allocator_type, __alloc_);
935
936 // annotate the string with its size() at scope exit. The string has to be in a valid state at that point.
937 struct __annotate_new_size {
938 basic_string& __str_;
939
940 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __annotate_new_size(basic_string& __str) : __str_(__str) {}
941
942 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void operator()() { __str_.__annotate_new(__str_.size()); }
943 };
921944
922945 // Construct a string with the given allocator and enough storage to hold `__size` characters, but
923946 // don't initialize the characters. The contents of the string, including the null terminator, must be
924947 // initialized separately.
925948 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(
926949 __uninitialized_size_tag, size_type __size, const allocator_type& __a)
927 : __r_(__default_init_tag(), __a) {
950 : __alloc_(__a) {
928951 if (__size > max_size())
929952 __throw_length_error();
930953 if (__fits_in_sso(__size)) {
931 __r_.first() = __rep();
954 __rep_ = __rep();
932955 __set_short_size(__size);
933956 } else {
934957 auto __capacity = __recommend(__size) + 1;
935 auto __allocation = __alloc_traits::allocate(__alloc(), __capacity);
958 auto __allocation = __alloc_traits::allocate(__alloc_, __capacity);
936959 __begin_lifetime(__allocation, __capacity);
937960 __set_long_cap(__capacity);
938961 __set_long_pointer(__allocation);
......@@ -944,12 +967,12 @@ private:
944967 template <class _Iter, class _Sent>
945968 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
946969 basic_string(__init_with_sentinel_tag, _Iter __first, _Sent __last, const allocator_type& __a)
947 : __r_(__default_init_tag(), __a) {
970 : __alloc_(__a) {
948971 __init_with_sentinel(std::move(__first), std::move(__last));
949972 }
950973
951974 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator __make_iterator(pointer __p) {
952#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_STRING
975# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_STRING
953976 // Bound the iterator according to the size (and not the capacity, unlike vector).
954977 //
955978 // By the Standard, string iterators are generally not guaranteed to stay valid when the container is modified,
......@@ -960,21 +983,21 @@ private:
960983 std::__wrap_iter<pointer>(__p),
961984 std::__wrap_iter<pointer>(__get_pointer()),
962985 std::__wrap_iter<pointer>(__get_pointer() + size()));
963#else
986# else
964987 return iterator(__p);
965#endif // _LIBCPP_ABI_BOUNDED_ITERATORS_IN_STRING
988# endif // _LIBCPP_ABI_BOUNDED_ITERATORS_IN_STRING
966989 }
967990
968991 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator __make_const_iterator(const_pointer __p) const {
969#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_STRING
992# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_STRING
970993 // Bound the iterator according to the size (and not the capacity, unlike vector).
971994 return std::__make_bounded_iter(
972995 std::__wrap_iter<const_pointer>(__p),
973996 std::__wrap_iter<const_pointer>(__get_pointer()),
974997 std::__wrap_iter<const_pointer>(__get_pointer() + size()));
975#else
998# else
976999 return const_iterator(__p);
977#endif // _LIBCPP_ABI_BOUNDED_ITERATORS_IN_STRING
1000# endif // _LIBCPP_ABI_BOUNDED_ITERATORS_IN_STRING
9781001 }
9791002
9801003public:
......@@ -982,24 +1005,24 @@ public:
9821005
9831006 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string()
9841007 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
985 : __r_(__value_init_tag(), __default_init_tag()) {
1008 : __rep_() {
9861009 __annotate_new(0);
9871010 }
9881011
9891012 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const allocator_type& __a)
990#if _LIBCPP_STD_VER <= 14
1013# if _LIBCPP_STD_VER <= 14
9911014 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
992#else
1015# else
9931016 _NOEXCEPT
994#endif
995 : __r_(__value_init_tag(), __a) {
1017# endif
1018 : __rep_(), __alloc_(__a) {
9961019 __annotate_new(0);
9971020 }
9981021
9991022 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS basic_string(const basic_string& __str)
1000 : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc())) {
1023 : __alloc_(__alloc_traits::select_on_container_copy_construction(__str.__alloc_)) {
10011024 if (!__str.__is_long()) {
1002 __r_.first() = __str.__r_.first();
1025 __rep_ = __str.__rep_;
10031026 __annotate_new(__get_short_size());
10041027 } else
10051028 __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
......@@ -1007,119 +1030,115 @@ public:
10071030
10081031 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
10091032 basic_string(const basic_string& __str, const allocator_type& __a)
1010 : __r_(__default_init_tag(), __a) {
1033 : __alloc_(__a) {
10111034 if (!__str.__is_long()) {
1012 __r_.first() = __str.__r_.first();
1035 __rep_ = __str.__rep_;
10131036 __annotate_new(__get_short_size());
10141037 } else
10151038 __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
10161039 }
10171040
1018#ifndef _LIBCPP_CXX03_LANG
1041# ifndef _LIBCPP_CXX03_LANG
10191042 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(basic_string&& __str)
1020# if _LIBCPP_STD_VER <= 14
1043# if _LIBCPP_STD_VER <= 14
10211044 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1022# else
1045# else
10231046 _NOEXCEPT
1024# endif
1047# endif
10251048 // Turning off ASan instrumentation for variable initialization with _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS
10261049 // does not work consistently during initialization of __r_, so we instead unpoison __str's memory manually first.
10271050 // __str's memory needs to be unpoisoned only in the case where it's a short string.
1028 : __r_([](basic_string& __s) -> decltype(__s.__r_)&& {
1051 : __rep_([](basic_string& __s) -> decltype(__s.__rep_)&& {
10291052 if (!__s.__is_long())
10301053 __s.__annotate_delete();
1031 return std::move(__s.__r_);
1032 }(__str)) {
1033 __str.__r_.first() = __rep();
1054 return std::move(__s.__rep_);
1055 }(__str)),
1056 __alloc_(std::move(__str.__alloc_)) {
1057 __str.__rep_ = __rep();
10341058 __str.__annotate_new(0);
10351059 if (!__is_long())
10361060 __annotate_new(size());
10371061 }
10381062
10391063 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(basic_string&& __str, const allocator_type& __a)
1040 : __r_(__default_init_tag(), __a) {
1041 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
1064 : __alloc_(__a) {
1065 if (__str.__is_long() && __a != __str.__alloc_) // copy, not move
10421066 __init(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
10431067 else {
10441068 if (__libcpp_is_constant_evaluated())
1045 __r_.first() = __rep();
1069 __rep_ = __rep();
10461070 if (!__str.__is_long())
10471071 __str.__annotate_delete();
1048 __r_.first() = __str.__r_.first();
1049 __str.__r_.first() = __rep();
1072 __rep_ = __str.__rep_;
1073 __str.__rep_ = __rep();
10501074 __str.__annotate_new(0);
1051 if (!__is_long() && this != &__str)
1075 if (!__is_long() && this != std::addressof(__str))
10521076 __annotate_new(size());
10531077 }
10541078 }
1055#endif // _LIBCPP_CXX03_LANG
1079# endif // _LIBCPP_CXX03_LANG
10561080
10571081 template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0>
1058 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s)
1059 : __r_(__default_init_tag(), __default_init_tag()) {
1082 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s) {
10601083 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "basic_string(const char*) detected nullptr");
10611084 __init(__s, traits_type::length(__s));
10621085 }
10631086
10641087 template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0>
10651088 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, const _Allocator& __a)
1066 : __r_(__default_init_tag(), __a) {
1089 : __alloc_(__a) {
10671090 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
10681091 __init(__s, traits_type::length(__s));
10691092 }
10701093
1071#if _LIBCPP_STD_VER >= 23
1094# if _LIBCPP_STD_VER >= 23
10721095 basic_string(nullptr_t) = delete;
1073#endif
1096# endif
10741097
1075 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, size_type __n)
1076 : __r_(__default_init_tag(), __default_init_tag()) {
1098 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, size_type __n) {
10771099 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
10781100 __init(__s, __n);
10791101 }
10801102
10811103 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
10821104 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
1083 : __r_(__default_init_tag(), __a) {
1105 : __alloc_(__a) {
10841106 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
10851107 __init(__s, __n);
10861108 }
10871109
1088 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c)
1089 : __r_(__default_init_tag(), __default_init_tag()) {
1090 __init(__n, __c);
1091 }
1110 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c) { __init(__n, __c); }
10921111
1093#if _LIBCPP_STD_VER >= 23
1112# if _LIBCPP_STD_VER >= 23
10941113 _LIBCPP_HIDE_FROM_ABI constexpr basic_string(
10951114 basic_string&& __str, size_type __pos, const _Allocator& __alloc = _Allocator())
10961115 : basic_string(std::move(__str), __pos, npos, __alloc) {}
10971116
10981117 _LIBCPP_HIDE_FROM_ABI constexpr basic_string(
10991118 basic_string&& __str, size_type __pos, size_type __n, const _Allocator& __alloc = _Allocator())
1100 : __r_(__default_init_tag(), __alloc) {
1119 : __alloc_(__alloc) {
11011120 if (__pos > __str.size())
11021121 __throw_out_of_range();
11031122
11041123 auto __len = std::min<size_type>(__n, __str.size() - __pos);
1105 if (__alloc_traits::is_always_equal::value || __alloc == __str.__alloc()) {
1124 if (__alloc_traits::is_always_equal::value || __alloc == __str.__alloc_) {
11061125 __move_assign(std::move(__str), __pos, __len);
11071126 } else {
11081127 // Perform a copy because the allocators are not compatible.
11091128 __init(__str.data() + __pos, __len);
11101129 }
11111130 }
1112#endif
1131# endif
11131132
11141133 template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0>
11151134 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c, const _Allocator& __a)
1116 : __r_(__default_init_tag(), __a) {
1135 : __alloc_(__a) {
11171136 __init(__n, __c);
11181137 }
11191138
11201139 _LIBCPP_CONSTEXPR_SINCE_CXX20
11211140 basic_string(const basic_string& __str, size_type __pos, size_type __n, const _Allocator& __a = _Allocator())
1122 : __r_(__default_init_tag(), __a) {
1141 : __alloc_(__a) {
11231142 size_type __str_sz = __str.size();
11241143 if (__pos > __str_sz)
11251144 __throw_out_of_range();
......@@ -1128,7 +1147,7 @@ public:
11281147
11291148 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
11301149 basic_string(const basic_string& __str, size_type __pos, const _Allocator& __a = _Allocator())
1131 : __r_(__default_init_tag(), __a) {
1150 : __alloc_(__a) {
11321151 size_type __str_sz = __str.size();
11331152 if (__pos > __str_sz)
11341153 __throw_out_of_range();
......@@ -1141,7 +1160,7 @@ public:
11411160 int> = 0>
11421161 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
11431162 basic_string(const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a = allocator_type())
1144 : __r_(__default_init_tag(), __a) {
1163 : __alloc_(__a) {
11451164 __self_view __sv0 = __t;
11461165 __self_view __sv = __sv0.substr(__pos, __n);
11471166 __init(__sv.data(), __sv.size());
......@@ -1151,8 +1170,8 @@ public:
11511170 __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
11521171 !__is_same_uncvref<_Tp, basic_string>::value,
11531172 int> = 0>
1154 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const _Tp& __t)
1155 : __r_(__default_init_tag(), __default_init_tag()) {
1173 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1174 _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const _Tp& __t) {
11561175 __self_view __sv = __t;
11571176 __init(__sv.data(), __sv.size());
11581177 }
......@@ -1163,57 +1182,55 @@ public:
11631182 int> = 0>
11641183 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
11651184 _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const _Tp& __t, const allocator_type& __a)
1166 : __r_(__default_init_tag(), __a) {
1185 : __alloc_(__a) {
11671186 __self_view __sv = __t;
11681187 __init(__sv.data(), __sv.size());
11691188 }
11701189
11711190 template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
1172 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(_InputIterator __first, _InputIterator __last)
1173 : __r_(__default_init_tag(), __default_init_tag()) {
1191 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(_InputIterator __first, _InputIterator __last) {
11741192 __init(__first, __last);
11751193 }
11761194
11771195 template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
11781196 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
11791197 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a)
1180 : __r_(__default_init_tag(), __a) {
1198 : __alloc_(__a) {
11811199 __init(__first, __last);
11821200 }
11831201
1184#if _LIBCPP_STD_VER >= 23
1202# if _LIBCPP_STD_VER >= 23
11851203 template <_ContainerCompatibleRange<_CharT> _Range>
11861204 _LIBCPP_HIDE_FROM_ABI constexpr basic_string(
11871205 from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
1188 : __r_(__default_init_tag(), __a) {
1206 : __alloc_(__a) {
11891207 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
11901208 __init_with_size(ranges::begin(__range), ranges::end(__range), ranges::distance(__range));
11911209 } else {
11921210 __init_with_sentinel(ranges::begin(__range), ranges::end(__range));
11931211 }
11941212 }
1195#endif
1213# endif
11961214
1197#ifndef _LIBCPP_CXX03_LANG
1198 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il)
1199 : __r_(__default_init_tag(), __default_init_tag()) {
1215# ifndef _LIBCPP_CXX03_LANG
1216 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il) {
12001217 __init(__il.begin(), __il.end());
12011218 }
12021219
12031220 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il, const _Allocator& __a)
1204 : __r_(__default_init_tag(), __a) {
1221 : __alloc_(__a) {
12051222 __init(__il.begin(), __il.end());
12061223 }
1207#endif // _LIBCPP_CXX03_LANG
1224# endif // _LIBCPP_CXX03_LANG
12081225
12091226 inline _LIBCPP_CONSTEXPR_SINCE_CXX20 ~basic_string() {
12101227 __annotate_delete();
12111228 if (__is_long())
1212 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
1229 __alloc_traits::deallocate(__alloc_, __get_long_pointer(), __get_long_cap());
12131230 }
12141231
12151232 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 operator __self_view() const _NOEXCEPT {
1216 return __self_view(data(), size());
1233 return __self_view(typename __self_view::__assume_valid(), data(), size());
12171234 }
12181235
12191236 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS basic_string&
......@@ -1228,7 +1245,7 @@ public:
12281245 return assign(__sv);
12291246 }
12301247
1231#ifndef _LIBCPP_CXX03_LANG
1248# ifndef _LIBCPP_CXX03_LANG
12321249 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
12331250 operator=(basic_string&& __str) noexcept(__noexcept_move_assign_container<_Allocator, __alloc_traits>::value) {
12341251 __move_assign(__str, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());
......@@ -1238,13 +1255,13 @@ public:
12381255 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(initializer_list<value_type> __il) {
12391256 return assign(__il.begin(), __il.size());
12401257 }
1241#endif
1258# endif
12421259 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(const value_type* __s) {
12431260 return assign(__s);
12441261 }
1245#if _LIBCPP_STD_VER >= 23
1262# if _LIBCPP_STD_VER >= 23
12461263 basic_string& operator=(nullptr_t) = delete;
1247#endif
1264# endif
12481265 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(value_type __c);
12491266
12501267 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator begin() _NOEXCEPT {
......@@ -1286,7 +1303,7 @@ public:
12861303 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type length() const _NOEXCEPT { return size(); }
12871304
12881305 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT {
1289 size_type __m = __alloc_traits::max_size(__alloc());
1306 size_type __m = __alloc_traits::max_size(__alloc_);
12901307 if (__m <= std::numeric_limits<size_type>::max() / 2) {
12911308 return __m - __alignment;
12921309 } else {
......@@ -1304,23 +1321,23 @@ public:
13041321
13051322 _LIBCPP_CONSTEXPR_SINCE_CXX20 void reserve(size_type __requested_capacity);
13061323
1307#if _LIBCPP_STD_VER >= 23
1324# if _LIBCPP_STD_VER >= 23
13081325 template <class _Op>
13091326 _LIBCPP_HIDE_FROM_ABI constexpr void resize_and_overwrite(size_type __n, _Op __op) {
13101327 __resize_default_init(__n);
13111328 __erase_to_end(std::move(__op)(data(), _LIBCPP_AUTO_CAST(__n)));
13121329 }
1313#endif
1330# endif
13141331
13151332 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __resize_default_init(size_type __n);
13161333
1317#if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_STRING_RESERVE)
1334# if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_STRING_RESERVE)
13181335 _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve() _NOEXCEPT { shrink_to_fit(); }
1319#endif
1336# endif
13201337 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT;
13211338 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void clear() _NOEXCEPT;
13221339
1323 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool empty() const _NOEXCEPT {
1340 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool empty() const _NOEXCEPT {
13241341 return size() == 0;
13251342 }
13261343
......@@ -1366,11 +1383,11 @@ public:
13661383 return *this;
13671384 }
13681385
1369#ifndef _LIBCPP_CXX03_LANG
1386# ifndef _LIBCPP_CXX03_LANG
13701387 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator+=(initializer_list<value_type> __il) {
13711388 return append(__il);
13721389 }
1373#endif // _LIBCPP_CXX03_LANG
1390# endif // _LIBCPP_CXX03_LANG
13741391
13751392 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const basic_string& __str) {
13761393 return append(__str.data(), __str.size());
......@@ -1406,7 +1423,7 @@ public:
14061423 template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
14071424 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
14081425 append(_InputIterator __first, _InputIterator __last) {
1409 const basic_string __temp(__first, __last, __alloc());
1426 const basic_string __temp(__first, __last, __alloc_);
14101427 append(__temp.data(), __temp.size());
14111428 return *this;
14121429 }
......@@ -1415,19 +1432,19 @@ public:
14151432 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
14161433 append(_ForwardIterator __first, _ForwardIterator __last);
14171434
1418#if _LIBCPP_STD_VER >= 23
1435# if _LIBCPP_STD_VER >= 23
14191436 template <_ContainerCompatibleRange<_CharT> _Range>
14201437 _LIBCPP_HIDE_FROM_ABI constexpr basic_string& append_range(_Range&& __range) {
14211438 insert_range(end(), std::forward<_Range>(__range));
14221439 return *this;
14231440 }
1424#endif
1441# endif
14251442
1426#ifndef _LIBCPP_CXX03_LANG
1443# ifndef _LIBCPP_CXX03_LANG
14271444 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(initializer_list<value_type> __il) {
14281445 return append(__il.begin(), __il.size());
14291446 }
1430#endif // _LIBCPP_CXX03_LANG
1447# endif // _LIBCPP_CXX03_LANG
14311448
14321449 _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(value_type __c);
14331450 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back();
......@@ -1459,15 +1476,15 @@ public:
14591476 return assign(__sv.data(), __sv.size());
14601477 }
14611478
1462#if _LIBCPP_STD_VER >= 20
1479# if _LIBCPP_STD_VER >= 20
14631480 _LIBCPP_HIDE_FROM_ABI constexpr void __move_assign(basic_string&& __str, size_type __pos, size_type __len) {
14641481 // Pilfer the allocation from __str.
1465 _LIBCPP_ASSERT_INTERNAL(__alloc() == __str.__alloc(), "__move_assign called with wrong allocator");
1482 _LIBCPP_ASSERT_INTERNAL(__alloc_ == __str.__alloc_, "__move_assign called with wrong allocator");
14661483 size_type __old_sz = __str.size();
14671484 if (!__str.__is_long())
14681485 __str.__annotate_delete();
1469 __r_.first() = __str.__r_.first();
1470 __str.__r_.first() = __rep();
1486 __rep_ = __str.__rep_;
1487 __str.__rep_ = __rep();
14711488 __str.__annotate_new(0);
14721489
14731490 _Traits::move(data(), data() + __pos, __len);
......@@ -1480,18 +1497,18 @@ public:
14801497 __annotate_shrink(__old_sz);
14811498 }
14821499 }
1483#endif
1500# endif
14841501
14851502 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const basic_string& __str) {
14861503 return *this = __str;
14871504 }
1488#ifndef _LIBCPP_CXX03_LANG
1505# ifndef _LIBCPP_CXX03_LANG
14891506 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
14901507 assign(basic_string&& __str) noexcept(__noexcept_move_assign_container<_Allocator, __alloc_traits>::value) {
14911508 *this = std::move(__str);
14921509 return *this;
14931510 }
1494#endif
1511# endif
14951512 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n = npos);
14961513
14971514 template <class _Tp,
......@@ -1512,7 +1529,7 @@ public:
15121529 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
15131530 assign(_ForwardIterator __first, _ForwardIterator __last);
15141531
1515#if _LIBCPP_STD_VER >= 23
1532# if _LIBCPP_STD_VER >= 23
15161533 template <_ContainerCompatibleRange<_CharT> _Range>
15171534 _LIBCPP_HIDE_FROM_ABI constexpr basic_string& assign_range(_Range&& __range) {
15181535 if constexpr (__string_is_trivial_iterator<ranges::iterator_t<_Range>>::value &&
......@@ -1526,13 +1543,13 @@ public:
15261543
15271544 return *this;
15281545 }
1529#endif
1546# endif
15301547
1531#ifndef _LIBCPP_CXX03_LANG
1548# ifndef _LIBCPP_CXX03_LANG
15321549 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(initializer_list<value_type> __il) {
15331550 return assign(__il.begin(), __il.size());
15341551 }
1535#endif // _LIBCPP_CXX03_LANG
1552# endif // _LIBCPP_CXX03_LANG
15361553
15371554 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
15381555 insert(size_type __pos1, const basic_string& __str) {
......@@ -1560,7 +1577,7 @@ public:
15601577 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, size_type __n, value_type __c);
15611578 _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __pos, value_type __c);
15621579
1563#if _LIBCPP_STD_VER >= 23
1580# if _LIBCPP_STD_VER >= 23
15641581 template <_ContainerCompatibleRange<_CharT> _Range>
15651582 _LIBCPP_HIDE_FROM_ABI constexpr iterator insert_range(const_iterator __position, _Range&& __range) {
15661583 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
......@@ -1568,11 +1585,11 @@ public:
15681585 return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n);
15691586
15701587 } else {
1571 basic_string __temp(from_range, std::forward<_Range>(__range), __alloc());
1588 basic_string __temp(from_range, std::forward<_Range>(__range), __alloc_);
15721589 return insert(__position, __temp.data(), __temp.data() + __temp.size());
15731590 }
15741591 }
1575#endif
1592# endif
15761593
15771594 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
15781595 insert(const_iterator __pos, size_type __n, value_type __c) {
......@@ -1589,12 +1606,12 @@ public:
15891606 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
15901607 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
15911608
1592#ifndef _LIBCPP_CXX03_LANG
1609# ifndef _LIBCPP_CXX03_LANG
15931610 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
15941611 insert(const_iterator __pos, initializer_list<value_type> __il) {
15951612 return insert(__pos, __il.begin(), __il.end());
15961613 }
1597#endif // _LIBCPP_CXX03_LANG
1614# endif // _LIBCPP_CXX03_LANG
15981615
15991616 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& erase(size_type __pos = 0, size_type __n = npos);
16001617 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __pos);
......@@ -1659,30 +1676,30 @@ public:
16591676 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
16601677 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
16611678
1662#if _LIBCPP_STD_VER >= 23
1679# if _LIBCPP_STD_VER >= 23
16631680 template <_ContainerCompatibleRange<_CharT> _Range>
16641681 _LIBCPP_HIDE_FROM_ABI constexpr basic_string&
16651682 replace_with_range(const_iterator __i1, const_iterator __i2, _Range&& __range) {
1666 basic_string __temp(from_range, std::forward<_Range>(__range), __alloc());
1683 basic_string __temp(from_range, std::forward<_Range>(__range), __alloc_);
16671684 return replace(__i1, __i2, __temp);
16681685 }
1669#endif
1686# endif
16701687
1671#ifndef _LIBCPP_CXX03_LANG
1688# ifndef _LIBCPP_CXX03_LANG
16721689 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
16731690 replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il) {
16741691 return replace(__i1, __i2, __il.begin(), __il.end());
16751692 }
1676#endif // _LIBCPP_CXX03_LANG
1693# endif // _LIBCPP_CXX03_LANG
16771694
16781695 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
16791696
1680#if _LIBCPP_STD_VER <= 20
1697# if _LIBCPP_STD_VER <= 20
16811698 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string
16821699 substr(size_type __pos = 0, size_type __n = npos) const {
16831700 return basic_string(*this, __pos, __n);
16841701 }
1685#else
1702# else
16861703 _LIBCPP_HIDE_FROM_ABI constexpr basic_string substr(size_type __pos = 0, size_type __n = npos) const& {
16871704 return basic_string(*this, __pos, __n);
16881705 }
......@@ -1690,27 +1707,27 @@ public:
16901707 _LIBCPP_HIDE_FROM_ABI constexpr basic_string substr(size_type __pos = 0, size_type __n = npos) && {
16911708 return basic_string(std::move(*this), __pos, __n);
16921709 }
1693#endif
1710# endif
16941711
16951712 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(basic_string& __str)
1696#if _LIBCPP_STD_VER >= 14
1713# if _LIBCPP_STD_VER >= 14
16971714 _NOEXCEPT;
1698#else
1715# else
16991716 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>);
1700#endif
1717# endif
17011718
17021719 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const value_type* c_str() const _NOEXCEPT { return data(); }
17031720 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const value_type* data() const _NOEXCEPT {
17041721 return std::__to_address(__get_pointer());
17051722 }
1706#if _LIBCPP_STD_VER >= 17
1723# if _LIBCPP_STD_VER >= 17
17071724 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 value_type* data() _NOEXCEPT {
17081725 return std::__to_address(__get_pointer());
17091726 }
1710#endif
1727# endif
17111728
17121729 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator_type get_allocator() const _NOEXCEPT {
1713 return __alloc();
1730 return __alloc_;
17141731 }
17151732
17161733 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
......@@ -1820,9 +1837,9 @@ public:
18201837 _LIBCPP_CONSTEXPR_SINCE_CXX20 int
18211838 compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
18221839
1823#if _LIBCPP_STD_VER >= 20
1840# if _LIBCPP_STD_VER >= 20
18241841 constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(__self_view __sv) const noexcept {
1825 return __self_view(data(), size()).starts_with(__sv);
1842 return __self_view(typename __self_view::__assume_valid(), data(), size()).starts_with(__sv);
18261843 }
18271844
18281845 constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(value_type __c) const noexcept {
......@@ -1834,7 +1851,7 @@ public:
18341851 }
18351852
18361853 constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(__self_view __sv) const noexcept {
1837 return __self_view(data(), size()).ends_with(__sv);
1854 return __self_view(typename __self_view::__assume_valid(), data(), size()).ends_with(__sv);
18381855 }
18391856
18401857 constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(value_type __c) const noexcept {
......@@ -1844,52 +1861,47 @@ public:
18441861 constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(const value_type* __s) const noexcept {
18451862 return ends_with(__self_view(__s));
18461863 }
1847#endif
1864# endif
18481865
1849#if _LIBCPP_STD_VER >= 23
1866# if _LIBCPP_STD_VER >= 23
18501867 constexpr _LIBCPP_HIDE_FROM_ABI bool contains(__self_view __sv) const noexcept {
1851 return __self_view(data(), size()).contains(__sv);
1868 return __self_view(typename __self_view::__assume_valid(), data(), size()).contains(__sv);
18521869 }
18531870
18541871 constexpr _LIBCPP_HIDE_FROM_ABI bool contains(value_type __c) const noexcept {
1855 return __self_view(data(), size()).contains(__c);
1872 return __self_view(typename __self_view::__assume_valid(), data(), size()).contains(__c);
18561873 }
18571874
18581875 constexpr _LIBCPP_HIDE_FROM_ABI bool contains(const value_type* __s) const {
1859 return __self_view(data(), size()).contains(__s);
1876 return __self_view(typename __self_view::__assume_valid(), data(), size()).contains(__s);
18601877 }
1861#endif
1878# endif
18621879
18631880 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const;
18641881
18651882 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __clear_and_shrink() _NOEXCEPT;
18661883
18671884private:
1868 template <class _Alloc>
1869 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool friend
1870 operator==(const basic_string<char, char_traits<char>, _Alloc>& __lhs,
1871 const basic_string<char, char_traits<char>, _Alloc>& __rhs) _NOEXCEPT;
1872
18731885 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __shrink_or_extend(size_type __target_capacity);
18741886
18751887 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS bool
18761888 __is_long() const _NOEXCEPT {
1877 if (__libcpp_is_constant_evaluated() && __builtin_constant_p(__r_.first().__l.__is_long_)) {
1878 return __r_.first().__l.__is_long_;
1889 if (__libcpp_is_constant_evaluated() && __builtin_constant_p(__rep_.__l.__is_long_)) {
1890 return __rep_.__l.__is_long_;
18791891 }
1880 return __r_.first().__s.__is_long_;
1892 return __rep_.__s.__is_long_;
18811893 }
18821894
18831895 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __begin_lifetime(pointer __begin, size_type __n) {
1884#if _LIBCPP_STD_VER >= 20
1896# if _LIBCPP_STD_VER >= 20
18851897 if (__libcpp_is_constant_evaluated()) {
18861898 for (size_type __i = 0; __i != __n; ++__i)
18871899 std::construct_at(std::addressof(__begin[__i]));
18881900 }
1889#else
1901# else
18901902 (void)__begin;
18911903 (void)__n;
1892#endif // _LIBCPP_STD_VER >= 20
1904# endif // _LIBCPP_STD_VER >= 20
18931905 }
18941906
18951907 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI static bool __fits_in_sso(size_type __sz) { return __sz < __min_cap; }
......@@ -1905,13 +1917,17 @@ private:
19051917 template <class _ForwardIter, class _Sent>
19061918 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static value_type*
19071919 __copy_non_overlapping_range(_ForwardIter __first, _Sent __last, value_type* __dest) {
1908#ifndef _LIBCPP_CXX03_LANG
1920# ifndef _LIBCPP_CXX03_LANG
19091921 if constexpr (__libcpp_is_contiguous_iterator<_ForwardIter>::value &&
1910 is_same<value_type, __iter_value_type<_ForwardIter>>::value && is_same<_ForwardIter, _Sent>::value) {
1922 is_same<value_type, __remove_cvref_t<decltype(*__first)>>::value &&
1923 is_same<_ForwardIter, _Sent>::value) {
1924 _LIBCPP_ASSERT_INTERNAL(
1925 !std::__is_overlapping_range(std::__to_address(__first), std::__to_address(__last), __dest),
1926 "__copy_non_overlapping_range called with an overlapping range!");
19111927 traits_type::copy(__dest, std::__to_address(__first), __last - __first);
19121928 return __dest + (__last - __first);
19131929 }
1914#endif
1930# endif
19151931
19161932 for (; __first != __last; ++__first)
19171933 traits_type::assign(*__dest++, *__first);
......@@ -1937,7 +1953,7 @@ private:
19371953 __sz += __n;
19381954 __set_size(__sz);
19391955 traits_type::assign(__p[__sz], value_type());
1940 __copy_non_overlapping_range(__first, __last, __p + __ip);
1956 __copy_non_overlapping_range(std::move(__first), std::move(__last), __p + __ip);
19411957
19421958 return begin() + __ip;
19431959 }
......@@ -1946,28 +1962,28 @@ private:
19461962 _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
19471963 __insert_with_size(const_iterator __pos, _Iterator __first, _Sentinel __last, size_type __n);
19481964
1949 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 allocator_type& __alloc() _NOEXCEPT { return __r_.second(); }
1950 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const allocator_type& __alloc() const _NOEXCEPT { return __r_.second(); }
1951
19521965 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS void
19531966 __set_short_size(size_type __s) _NOEXCEPT {
19541967 _LIBCPP_ASSERT_INTERNAL(__s < __min_cap, "__s should never be greater than or equal to the short string capacity");
1955 __r_.first().__s.__size_ = __s;
1956 __r_.first().__s.__is_long_ = false;
1968 __rep_.__s.__size_ = __s;
1969 __rep_.__s.__is_long_ = false;
19571970 }
19581971
19591972 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS size_type
19601973 __get_short_size() const _NOEXCEPT {
1961 _LIBCPP_ASSERT_INTERNAL(!__r_.first().__s.__is_long_, "String has to be short when trying to get the short size");
1962 return __r_.first().__s.__size_;
1974 _LIBCPP_ASSERT_INTERNAL(!__rep_.__s.__is_long_, "String has to be short when trying to get the short size");
1975 return __rep_.__s.__size_;
19631976 }
19641977
19651978 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __set_long_size(size_type __s) _NOEXCEPT {
1966 __r_.first().__l.__size_ = __s;
1979 __rep_.__l.__size_ = __s;
19671980 }
1981
19681982 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __get_long_size() const _NOEXCEPT {
1969 return __r_.first().__l.__size_;
1983 _LIBCPP_ASSERT_INTERNAL(__rep_.__l.__is_long_, "String has to be long when trying to get the long size");
1984 return __rep_.__l.__size_;
19701985 }
1986
19711987 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __set_size(size_type __s) _NOEXCEPT {
19721988 if (__is_long())
19731989 __set_long_size(__s);
......@@ -1976,31 +1992,40 @@ private:
19761992 }
19771993
19781994 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __set_long_cap(size_type __s) _NOEXCEPT {
1979 __r_.first().__l.__cap_ = __s / __endian_factor;
1980 __r_.first().__l.__is_long_ = true;
1995 _LIBCPP_ASSERT_INTERNAL(!__fits_in_sso(__s), "Long capacity should always be larger than the SSO");
1996 __rep_.__l.__cap_ = __s / __endian_factor;
1997 __rep_.__l.__is_long_ = true;
19811998 }
19821999
19832000 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __get_long_cap() const _NOEXCEPT {
1984 return __r_.first().__l.__cap_ * __endian_factor;
2001 _LIBCPP_ASSERT_INTERNAL(__rep_.__l.__is_long_, "String has to be long when trying to get the long capacity");
2002 return __rep_.__l.__cap_ * __endian_factor;
19852003 }
19862004
19872005 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __set_long_pointer(pointer __p) _NOEXCEPT {
1988 __r_.first().__l.__data_ = __p;
2006 __rep_.__l.__data_ = __p;
19892007 }
2008
19902009 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pointer __get_long_pointer() _NOEXCEPT {
1991 return _LIBCPP_ASAN_VOLATILE_WRAPPER(__r_.first().__l.__data_);
2010 _LIBCPP_ASSERT_INTERNAL(__rep_.__l.__is_long_, "String has to be long when trying to get the long pointer");
2011 return _LIBCPP_ASAN_VOLATILE_WRAPPER(__rep_.__l.__data_);
19922012 }
2013
19932014 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_pointer __get_long_pointer() const _NOEXCEPT {
1994 return _LIBCPP_ASAN_VOLATILE_WRAPPER(__r_.first().__l.__data_);
2015 _LIBCPP_ASSERT_INTERNAL(__rep_.__l.__is_long_, "String has to be long when trying to get the long pointer");
2016 return _LIBCPP_ASAN_VOLATILE_WRAPPER(__rep_.__l.__data_);
19952017 }
2018
19962019 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS pointer
19972020 __get_short_pointer() _NOEXCEPT {
1998 return _LIBCPP_ASAN_VOLATILE_WRAPPER(pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]));
2021 return _LIBCPP_ASAN_VOLATILE_WRAPPER(pointer_traits<pointer>::pointer_to(__rep_.__s.__data_[0]));
19992022 }
2023
20002024 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS const_pointer
20012025 __get_short_pointer() const _NOEXCEPT {
2002 return _LIBCPP_ASAN_VOLATILE_WRAPPER(pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]));
2026 return _LIBCPP_ASAN_VOLATILE_WRAPPER(pointer_traits<const_pointer>::pointer_to(__rep_.__s.__data_[0]));
20032027 }
2028
20042029 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pointer __get_pointer() _NOEXCEPT {
20052030 return __is_long() ? __get_long_pointer() : __get_short_pointer();
20062031 }
......@@ -2013,45 +2038,45 @@ private:
20132038 __annotate_contiguous_container(const void* __old_mid, const void* __new_mid) const {
20142039 (void)__old_mid;
20152040 (void)__new_mid;
2016#if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN)
2017 #if defined(__APPLE__)
2041# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
2042# if defined(__APPLE__)
20182043 // TODO: remove after addressing issue #96099 (https://github.com/llvm/llvm-project/issues/96099)
2019 if(!__is_long())
2044 if (!__is_long())
20202045 return;
2021 #endif
2046# endif
20222047 std::__annotate_contiguous_container<_Allocator>(data(), data() + capacity() + 1, __old_mid, __new_mid);
2023#endif
2048# endif
20242049 }
20252050
20262051 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_new(size_type __current_size) const _NOEXCEPT {
20272052 (void)__current_size;
2028#if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN)
2053# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
20292054 if (!__libcpp_is_constant_evaluated())
20302055 __annotate_contiguous_container(data() + capacity() + 1, data() + __current_size + 1);
2031#endif
2056# endif
20322057 }
20332058
20342059 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_delete() const _NOEXCEPT {
2035#if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN)
2060# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
20362061 if (!__libcpp_is_constant_evaluated())
20372062 __annotate_contiguous_container(data() + size() + 1, data() + capacity() + 1);
2038#endif
2063# endif
20392064 }
20402065
20412066 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_increase(size_type __n) const _NOEXCEPT {
20422067 (void)__n;
2043#if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN)
2068# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
20442069 if (!__libcpp_is_constant_evaluated())
20452070 __annotate_contiguous_container(data() + size() + 1, data() + size() + 1 + __n);
2046#endif
2071# endif
20472072 }
20482073
20492074 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_shrink(size_type __old_size) const _NOEXCEPT {
20502075 (void)__old_size;
2051#if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN)
2076# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
20522077 if (!__libcpp_is_constant_evaluated())
20532078 __annotate_contiguous_container(data() + __old_size + 1, data() + size() + 1);
2054#endif
2079# endif
20552080 }
20562081
20572082 template <size_type __a>
......@@ -2067,6 +2092,8 @@ private:
20672092 size_type __guess = __align_it<__boundary>(__s + 1) - 1;
20682093 if (__guess == __min_cap)
20692094 __guess += __endian_factor;
2095
2096 _LIBCPP_ASSERT_INTERNAL(__guess >= __s, "recommendation is below the requested size");
20702097 return __guess;
20712098 }
20722099
......@@ -2098,9 +2125,9 @@ private:
20982125 __init_with_size(_InputIterator __first, _Sentinel __last, size_type __sz);
20992126
21002127 _LIBCPP_CONSTEXPR_SINCE_CXX20
2101#if _LIBCPP_ABI_VERSION >= 2 // We want to use the function in the dylib in ABIv1
2128# if _LIBCPP_ABI_VERSION >= 2 // We want to use the function in the dylib in ABIv1
21022129 _LIBCPP_HIDE_FROM_ABI
2103#endif
2130# endif
21042131 _LIBCPP_DEPRECATED_("use __grow_by_without_replace") void __grow_by(
21052132 size_type __old_cap,
21062133 size_type __delta_cap,
......@@ -2131,6 +2158,7 @@ private:
21312158 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NOINLINE basic_string& __assign_no_alias(const value_type* __s, size_type __n);
21322159
21332160 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __erase_to_end(size_type __pos) {
2161 _LIBCPP_ASSERT_INTERNAL(__pos <= capacity(), "Trying to erase at position outside the strings capacity!");
21342162 __null_terminate_at(std::__to_address(__get_pointer()), __pos);
21352163 }
21362164
......@@ -2144,24 +2172,24 @@ private:
21442172 }
21452173
21462174 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __copy_assign_alloc(const basic_string& __str, true_type) {
2147 if (__alloc() == __str.__alloc())
2148 __alloc() = __str.__alloc();
2175 if (__alloc_ == __str.__alloc_)
2176 __alloc_ = __str.__alloc_;
21492177 else {
21502178 if (!__str.__is_long()) {
21512179 __clear_and_shrink();
2152 __alloc() = __str.__alloc();
2180 __alloc_ = __str.__alloc_;
21532181 } else {
21542182 __annotate_delete();
2155 allocator_type __a = __str.__alloc();
2183 auto __guard = std::__make_scope_guard(__annotate_new_size(*this));
2184 allocator_type __a = __str.__alloc_;
21562185 auto __allocation = std::__allocate_at_least(__a, __str.__get_long_cap());
21572186 __begin_lifetime(__allocation.ptr, __allocation.count);
21582187 if (__is_long())
2159 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2160 __alloc() = std::move(__a);
2188 __alloc_traits::deallocate(__alloc_, __get_long_pointer(), __get_long_cap());
2189 __alloc_ = std::move(__a);
21612190 __set_long_pointer(__allocation.ptr);
21622191 __set_long_cap(__allocation.count);
21632192 __set_long_size(__str.size());
2164 __annotate_new(__get_long_size());
21652193 }
21662194 }
21672195 }
......@@ -2169,17 +2197,17 @@ private:
21692197 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
21702198 __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT {}
21712199
2172#ifndef _LIBCPP_CXX03_LANG
2200# ifndef _LIBCPP_CXX03_LANG
21732201 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
21742202 __move_assign(basic_string& __str, false_type) noexcept(__alloc_traits::is_always_equal::value);
21752203 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS void
21762204 __move_assign(basic_string& __str, true_type)
2177# if _LIBCPP_STD_VER >= 17
2205# if _LIBCPP_STD_VER >= 17
21782206 noexcept;
2179# else
2207# else
21802208 noexcept(is_nothrow_move_assignable<allocator_type>::value);
2209# endif
21812210# endif
2182#endif
21832211
21842212 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(basic_string& __str)
21852213 _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value ||
......@@ -2190,7 +2218,7 @@ private:
21902218
21912219 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(basic_string& __c, true_type)
21922220 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
2193 __alloc() = std::move(__c.__alloc());
2221 __alloc_ = std::move(__c.__alloc_);
21942222 }
21952223
21962224 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(basic_string&, false_type) _NOEXCEPT {}
......@@ -2229,11 +2257,11 @@ private:
22292257 return std::__is_pointer_in_range(data(), data() + size() + 1, std::addressof(__v));
22302258 }
22312259
2232 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_length_error() const {
2260 [[__noreturn__]] _LIBCPP_HIDE_FROM_ABI static void __throw_length_error() {
22332261 std::__throw_length_error("basic_string");
22342262 }
22352263
2236 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const {
2264 [[__noreturn__]] _LIBCPP_HIDE_FROM_ABI static void __throw_out_of_range() {
22372265 std::__throw_out_of_range("basic_string");
22382266 }
22392267
......@@ -2242,29 +2270,33 @@ private:
22422270 friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+ <>(value_type, const basic_string&);
22432271 friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+ <>(const basic_string&, const value_type*);
22442272 friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+ <>(const basic_string&, value_type);
2245#if _LIBCPP_STD_VER >= 26
2273# if _LIBCPP_STD_VER >= 26
22462274 friend constexpr basic_string operator+ <>(const basic_string&, type_identity_t<__self_view>);
22472275 friend constexpr basic_string operator+ <>(type_identity_t<__self_view>, const basic_string&);
2248#endif
2276# endif
2277
2278 template <class _CharT2, class _Traits2, class _Allocator2>
2279 friend inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool
2280 operator==(const basic_string<_CharT2, _Traits2, _Allocator2>&, const _CharT2*) _NOEXCEPT;
22492281};
22502282
22512283// These declarations must appear before any functions are implicitly used
22522284// so that they have the correct visibility specifier.
2253#define _LIBCPP_DECLARE(...) extern template __VA_ARGS__;
2254#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
2285# define _LIBCPP_DECLARE(...) extern template __VA_ARGS__;
2286# ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
22552287_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char)
2256# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2288# if _LIBCPP_HAS_WIDE_CHARACTERS
22572289_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t)
2258# endif
2259#else
2290# endif
2291# else
22602292_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char)
2261# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2293# if _LIBCPP_HAS_WIDE_CHARACTERS
22622294_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t)
2295# endif
22632296# endif
2264#endif
2265#undef _LIBCPP_DECLARE
2297# undef _LIBCPP_DECLARE
22662298
2267#if _LIBCPP_STD_VER >= 17
2299# if _LIBCPP_STD_VER >= 17
22682300template <class _InputIterator,
22692301 class _CharT = __iter_value_type<_InputIterator>,
22702302 class _Allocator = allocator<_CharT>,
......@@ -2287,21 +2319,21 @@ template <class _CharT,
22872319 class _Sz = typename allocator_traits<_Allocator>::size_type >
22882320basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
22892321 -> basic_string<_CharT, _Traits, _Allocator>;
2290#endif
2322# endif
22912323
2292#if _LIBCPP_STD_VER >= 23
2324# if _LIBCPP_STD_VER >= 23
22932325template <ranges::input_range _Range,
22942326 class _Allocator = allocator<ranges::range_value_t<_Range>>,
22952327 class = enable_if_t<__is_allocator<_Allocator>::value> >
22962328basic_string(from_range_t, _Range&&, _Allocator = _Allocator())
22972329 -> basic_string<ranges::range_value_t<_Range>, char_traits<ranges::range_value_t<_Range>>, _Allocator>;
2298#endif
2330# endif
22992331
23002332template <class _CharT, class _Traits, class _Allocator>
23012333_LIBCPP_CONSTEXPR_SINCE_CXX20 void
23022334basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve) {
23032335 if (__libcpp_is_constant_evaluated())
2304 __r_.first() = __rep();
2336 __rep_ = __rep();
23052337 if (__reserve > max_size())
23062338 __throw_length_error();
23072339 pointer __p;
......@@ -2309,7 +2341,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_ty
23092341 __set_short_size(__sz);
23102342 __p = __get_short_pointer();
23112343 } else {
2312 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__reserve) + 1);
2344 auto __allocation = std::__allocate_at_least(__alloc_, __recommend(__reserve) + 1);
23132345 __p = __allocation.ptr;
23142346 __begin_lifetime(__p, __allocation.count);
23152347 __set_long_pointer(__p);
......@@ -2325,7 +2357,7 @@ template <class _CharT, class _Traits, class _Allocator>
23252357_LIBCPP_CONSTEXPR_SINCE_CXX20 void
23262358basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz) {
23272359 if (__libcpp_is_constant_evaluated())
2328 __r_.first() = __rep();
2360 __rep_ = __rep();
23292361 if (__sz > max_size())
23302362 __throw_length_error();
23312363 pointer __p;
......@@ -2333,7 +2365,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_ty
23332365 __set_short_size(__sz);
23342366 __p = __get_short_pointer();
23352367 } else {
2336 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1);
2368 auto __allocation = std::__allocate_at_least(__alloc_, __recommend(__sz) + 1);
23372369 __p = __allocation.ptr;
23382370 __begin_lifetime(__p, __allocation.count);
23392371 __set_long_pointer(__p);
......@@ -2349,7 +2381,7 @@ template <class _CharT, class _Traits, class _Allocator>
23492381_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NOINLINE void
23502382basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(const value_type* __s, size_type __sz) {
23512383 if (__libcpp_is_constant_evaluated())
2352 __r_.first() = __rep();
2384 __rep_ = __rep();
23532385
23542386 pointer __p;
23552387 if (__fits_in_sso(__sz)) {
......@@ -2358,7 +2390,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(const value
23582390 } else {
23592391 if (__sz > max_size())
23602392 __throw_length_error();
2361 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1);
2393 auto __allocation = std::__allocate_at_least(__alloc_, __recommend(__sz) + 1);
23622394 __p = __allocation.ptr;
23632395 __begin_lifetime(__p, __allocation.count);
23642396 __set_long_pointer(__p);
......@@ -2372,7 +2404,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(const value
23722404template <class _CharT, class _Traits, class _Allocator>
23732405_LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c) {
23742406 if (__libcpp_is_constant_evaluated())
2375 __r_.first() = __rep();
2407 __rep_ = __rep();
23762408
23772409 if (__n > max_size())
23782410 __throw_length_error();
......@@ -2381,7 +2413,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
23812413 __set_short_size(__n);
23822414 __p = __get_short_pointer();
23832415 } else {
2384 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__n) + 1);
2416 auto __allocation = std::__allocate_at_least(__alloc_, __recommend(__n) + 1);
23852417 __p = __allocation.ptr;
23862418 __begin_lifetime(__p, __allocation.count);
23872419 __set_long_pointer(__p);
......@@ -2404,22 +2436,22 @@ template <class _CharT, class _Traits, class _Allocator>
24042436template <class _InputIterator, class _Sentinel>
24052437_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
24062438basic_string<_CharT, _Traits, _Allocator>::__init_with_sentinel(_InputIterator __first, _Sentinel __last) {
2407 __r_.first() = __rep();
2439 __rep_ = __rep();
24082440 __annotate_new(0);
24092441
2410#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2442# if _LIBCPP_HAS_EXCEPTIONS
24112443 try {
2412#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2444# endif // _LIBCPP_HAS_EXCEPTIONS
24132445 for (; __first != __last; ++__first)
24142446 push_back(*__first);
2415#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2447# if _LIBCPP_HAS_EXCEPTIONS
24162448 } catch (...) {
24172449 __annotate_delete();
24182450 if (__is_long())
2419 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2451 __alloc_traits::deallocate(__alloc_, __get_long_pointer(), __get_long_cap());
24202452 throw;
24212453 }
2422#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2454# endif // _LIBCPP_HAS_EXCEPTIONS
24232455}
24242456
24252457template <class _CharT, class _Traits, class _Allocator>
......@@ -2435,7 +2467,7 @@ template <class _InputIterator, class _Sentinel>
24352467_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
24362468basic_string<_CharT, _Traits, _Allocator>::__init_with_size(_InputIterator __first, _Sentinel __last, size_type __sz) {
24372469 if (__libcpp_is_constant_evaluated())
2438 __r_.first() = __rep();
2470 __rep_ = __rep();
24392471
24402472 if (__sz > max_size())
24412473 __throw_length_error();
......@@ -2446,7 +2478,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init_with_size(_InputIterator __fir
24462478 __p = __get_short_pointer();
24472479
24482480 } else {
2449 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1);
2481 auto __allocation = std::__allocate_at_least(__alloc_, __recommend(__sz) + 1);
24502482 __p = __allocation.ptr;
24512483 __begin_lifetime(__p, __allocation.count);
24522484 __set_long_pointer(__p);
......@@ -2454,18 +2486,18 @@ basic_string<_CharT, _Traits, _Allocator>::__init_with_size(_InputIterator __fir
24542486 __set_long_size(__sz);
24552487 }
24562488
2457#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2489# if _LIBCPP_HAS_EXCEPTIONS
24582490 try {
2459#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2460 auto __end = __copy_non_overlapping_range(__first, __last, std::__to_address(__p));
2491# endif // _LIBCPP_HAS_EXCEPTIONS
2492 auto __end = __copy_non_overlapping_range(std::move(__first), std::move(__last), std::__to_address(__p));
24612493 traits_type::assign(*__end, value_type());
2462#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2494# if _LIBCPP_HAS_EXCEPTIONS
24632495 } catch (...) {
24642496 if (__is_long())
2465 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2497 __alloc_traits::deallocate(__alloc_, __get_long_pointer(), __get_long_cap());
24662498 throw;
24672499 }
2468#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2500# endif // _LIBCPP_HAS_EXCEPTIONS
24692501 __annotate_new(__sz);
24702502}
24712503
......@@ -2485,7 +2517,8 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
24852517 size_type __cap =
24862518 __old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1;
24872519 __annotate_delete();
2488 auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
2520 auto __guard = std::__make_scope_guard(__annotate_new_size(*this));
2521 auto __allocation = std::__allocate_at_least(__alloc_, __cap + 1);
24892522 pointer __p = __allocation.ptr;
24902523 __begin_lifetime(__p, __allocation.count);
24912524 if (__n_copy != 0)
......@@ -2497,13 +2530,12 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
24972530 traits_type::copy(
24982531 std::__to_address(__p) + __n_copy + __n_add, std::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz);
24992532 if (__old_cap + 1 != __min_cap)
2500 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap + 1);
2533 __alloc_traits::deallocate(__alloc_, __old_p, __old_cap + 1);
25012534 __set_long_pointer(__p);
25022535 __set_long_cap(__allocation.count);
25032536 __old_sz = __n_copy + __n_add + __sec_cp_sz;
25042537 __set_long_size(__old_sz);
25052538 traits_type::assign(__p[__old_sz], value_type());
2506 __annotate_new(__old_sz);
25072539}
25082540
25092541// __grow_by is deprecated because it does not set the size. It may not update the size when the size is changed, and it
......@@ -2511,9 +2543,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
25112543// not removed or changed to avoid breaking the ABI.
25122544template <class _CharT, class _Traits, class _Allocator>
25132545void _LIBCPP_CONSTEXPR_SINCE_CXX20
2514#if _LIBCPP_ABI_VERSION >= 2 // We want to use the function in the dylib in ABIv1
2546# if _LIBCPP_ABI_VERSION >= 2 // We want to use the function in the dylib in ABIv1
25152547_LIBCPP_HIDE_FROM_ABI
2516#endif
2548# endif
25172549_LIBCPP_DEPRECATED_("use __grow_by_without_replace") basic_string<_CharT, _Traits, _Allocator>::__grow_by(
25182550 size_type __old_cap,
25192551 size_type __delta_cap,
......@@ -2527,8 +2559,7 @@ _LIBCPP_DEPRECATED_("use __grow_by_without_replace") basic_string<_CharT, _Trait
25272559 pointer __old_p = __get_pointer();
25282560 size_type __cap =
25292561 __old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1;
2530 __annotate_delete();
2531 auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
2562 auto __allocation = std::__allocate_at_least(__alloc_, __cap + 1);
25322563 pointer __p = __allocation.ptr;
25332564 __begin_lifetime(__p, __allocation.count);
25342565 if (__n_copy != 0)
......@@ -2538,7 +2569,7 @@ _LIBCPP_DEPRECATED_("use __grow_by_without_replace") basic_string<_CharT, _Trait
25382569 traits_type::copy(
25392570 std::__to_address(__p) + __n_copy + __n_add, std::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz);
25402571 if (__old_cap + 1 != __min_cap)
2541 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap + 1);
2572 __alloc_traits::deallocate(__alloc_, __old_p, __old_cap + 1);
25422573 __set_long_pointer(__p);
25432574 __set_long_cap(__allocation.count);
25442575}
......@@ -2552,11 +2583,12 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by_without_replace(
25522583 size_type __n_copy,
25532584 size_type __n_del,
25542585 size_type __n_add) {
2586 __annotate_delete();
2587 auto __guard = std::__make_scope_guard(__annotate_new_size(*this));
25552588 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
25562589 __grow_by(__old_cap, __delta_cap, __old_sz, __n_copy, __n_del, __n_add);
25572590 _LIBCPP_SUPPRESS_DEPRECATED_POP
25582591 __set_long_size(__old_sz - __n_del + __n_add);
2559 __annotate_new(__old_sz - __n_del + __n_add);
25602592}
25612593
25622594// assign
......@@ -2655,7 +2687,7 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
26552687 size_type __old_size = __get_short_size();
26562688 if (__get_short_size() < __str.__get_short_size())
26572689 __annotate_increase(__str.__get_short_size() - __get_short_size());
2658 __r_.first() = __str.__r_.first();
2690 __rep_ = __str.__rep_;
26592691 if (__old_size > __get_short_size())
26602692 __annotate_shrink(__old_size);
26612693 } else {
......@@ -2668,12 +2700,12 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
26682700 return *this;
26692701}
26702702
2671#ifndef _LIBCPP_CXX03_LANG
2703# ifndef _LIBCPP_CXX03_LANG
26722704
26732705template <class _CharT, class _Traits, class _Allocator>
26742706inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__move_assign(
26752707 basic_string& __str, false_type) noexcept(__alloc_traits::is_always_equal::value) {
2676 if (__alloc() != __str.__alloc())
2708 if (__alloc_ != __str.__alloc_)
26772709 assign(__str);
26782710 else
26792711 __move_assign(__str, true_type());
......@@ -2682,32 +2714,32 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocat
26822714template <class _CharT, class _Traits, class _Allocator>
26832715inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS void
26842716basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
2685# if _LIBCPP_STD_VER >= 17
2717# if _LIBCPP_STD_VER >= 17
26862718 noexcept
2687# else
2719# else
26882720 noexcept(is_nothrow_move_assignable<allocator_type>::value)
2689# endif
2721# endif
26902722{
26912723 __annotate_delete();
26922724 if (__is_long()) {
2693 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2694# if _LIBCPP_STD_VER <= 14
2725 __alloc_traits::deallocate(__alloc_, __get_long_pointer(), __get_long_cap());
2726# if _LIBCPP_STD_VER <= 14
26952727 if (!is_nothrow_move_assignable<allocator_type>::value) {
26962728 __set_short_size(0);
26972729 traits_type::assign(__get_short_pointer()[0], value_type());
26982730 __annotate_new(0);
26992731 }
2700# endif
2732# endif
27012733 }
27022734 size_type __str_old_size = __str.size();
27032735 bool __str_was_short = !__str.__is_long();
27042736
27052737 __move_assign_alloc(__str);
2706 __r_.first() = __str.__r_.first();
2738 __rep_ = __str.__rep_;
27072739 __str.__set_short_size(0);
27082740 traits_type::assign(__str.__get_short_pointer()[0], value_type());
27092741
2710 if (__str_was_short && this != &__str)
2742 if (__str_was_short && this != std::addressof(__str))
27112743 __str.__annotate_shrink(__str_old_size);
27122744 else
27132745 // ASan annotations: was long, so object memory is unpoisoned as new.
......@@ -2721,12 +2753,12 @@ basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, tr
27212753 // invariants hold (so functions without preconditions, such as the assignment operator,
27222754 // can be safely used on the object after it was moved from):"
27232755 // Quote: "v = std::move(v); // the value of v is unspecified"
2724 if (!__is_long() && &__str != this)
2756 if (!__is_long() && std::addressof(__str) != this)
27252757 // If it is long string, delete was never called on original __str's buffer.
27262758 __annotate_new(__get_short_size());
27272759}
27282760
2729#endif
2761# endif
27302762
27312763template <class _CharT, class _Traits, class _Allocator>
27322764template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
......@@ -2740,7 +2772,7 @@ template <class _CharT, class _Traits, class _Allocator>
27402772template <class _InputIterator, class _Sentinel>
27412773_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
27422774basic_string<_CharT, _Traits, _Allocator>::__assign_with_sentinel(_InputIterator __first, _Sentinel __last) {
2743 const basic_string __temp(__init_with_sentinel_tag(), std::move(__first), std::move(__last), __alloc());
2775 const basic_string __temp(__init_with_sentinel_tag(), std::move(__first), std::move(__last), __alloc_);
27442776 assign(__temp.data(), __temp.size());
27452777}
27462778
......@@ -2928,7 +2960,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _For
29282960 traits_type::assign(*__end, value_type());
29292961 __set_size(__sz + __n);
29302962 } else {
2931 const basic_string __temp(__first, __last, __alloc());
2963 const basic_string __temp(__first, __last, __alloc_);
29322964 append(__temp.data(), __temp.size());
29332965 }
29342966 }
......@@ -3026,7 +3058,7 @@ template <class _CharT, class _Traits, class _Allocator>
30263058template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
30273059_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::iterator
30283060basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last) {
3029 const basic_string __temp(__first, __last, __alloc());
3061 const basic_string __temp(__first, __last, __alloc_);
30303062 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
30313063}
30323064
......@@ -3049,9 +3081,9 @@ basic_string<_CharT, _Traits, _Allocator>::__insert_with_size(
30493081 return begin() + __ip;
30503082
30513083 if (__string_is_trivial_iterator<_Iterator>::value && !__addr_in_range(*__first)) {
3052 return __insert_from_safe_copy(__n, __ip, __first, __last);
3084 return __insert_from_safe_copy(__n, __ip, std::move(__first), std::move(__last));
30533085 } else {
3054 const basic_string __temp(__init_with_sentinel_tag(), __first, __last, __alloc());
3086 const basic_string __temp(__init_with_sentinel_tag(), std::move(__first), std::move(__last), __alloc_);
30553087 return __insert_from_safe_copy(__n, __ip, __temp.begin(), __temp.end());
30563088 }
30573089}
......@@ -3188,7 +3220,7 @@ template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_Inp
31883220_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
31893221basic_string<_CharT, _Traits, _Allocator>::replace(
31903222 const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2) {
3191 const basic_string __temp(__j1, __j2, __alloc());
3223 const basic_string __temp(__j1, __j2, __alloc_);
31923224 return replace(__i1, __i2, __temp);
31933225}
31943226
......@@ -3325,12 +3357,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::re
33253357 if (__requested_capacity <= capacity())
33263358 return;
33273359
3328 size_type __target_capacity = std::max(__requested_capacity, size());
3329 __target_capacity = __recommend(__target_capacity);
3330 if (__target_capacity == capacity())
3331 return;
3332
3333 __shrink_or_extend(__target_capacity);
3360 __shrink_or_extend(__recommend(__requested_capacity));
33343361}
33353362
33363363template <class _CharT, class _Traits, class _Allocator>
......@@ -3346,6 +3373,7 @@ template <class _CharT, class _Traits, class _Allocator>
33463373inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void
33473374basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity) {
33483375 __annotate_delete();
3376 auto __guard = std::__make_scope_guard(__annotate_new_size(*this));
33493377 size_type __cap = capacity();
33503378 size_type __sz = size();
33513379
......@@ -3360,33 +3388,32 @@ basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target
33603388 if (__target_capacity > __cap) {
33613389 // Extend
33623390 // - called from reserve should propagate the exception thrown.
3363 auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1);
3391 auto __allocation = std::__allocate_at_least(__alloc_, __target_capacity + 1);
33643392 __new_data = __allocation.ptr;
33653393 __target_capacity = __allocation.count - 1;
33663394 } else {
33673395 // Shrink
33683396 // - called from shrink_to_fit should not throw.
33693397 // - called from reserve may throw but is not required to.
3370#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
3398# if _LIBCPP_HAS_EXCEPTIONS
33713399 try {
3372#endif // _LIBCPP_HAS_NO_EXCEPTIONS
3373 auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1);
3400# endif // _LIBCPP_HAS_EXCEPTIONS
3401 auto __allocation = std::__allocate_at_least(__alloc_, __target_capacity + 1);
33743402
33753403 // The Standard mandates shrink_to_fit() does not increase the capacity.
33763404 // With equal capacity keep the existing buffer. This avoids extra work
33773405 // due to swapping the elements.
3378 if (__allocation.count - 1 > __target_capacity) {
3379 __alloc_traits::deallocate(__alloc(), __allocation.ptr, __allocation.count);
3380 __annotate_new(__sz); // Undoes the __annotate_delete()
3406 if (__allocation.count - 1 > capacity()) {
3407 __alloc_traits::deallocate(__alloc_, __allocation.ptr, __allocation.count);
33813408 return;
33823409 }
33833410 __new_data = __allocation.ptr;
33843411 __target_capacity = __allocation.count - 1;
3385#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
3412# if _LIBCPP_HAS_EXCEPTIONS
33863413 } catch (...) {
33873414 return;
33883415 }
3389#endif // _LIBCPP_HAS_NO_EXCEPTIONS
3416# endif // _LIBCPP_HAS_EXCEPTIONS
33903417 }
33913418 __begin_lifetime(__new_data, __target_capacity + 1);
33923419 __now_long = true;
......@@ -3395,14 +3422,13 @@ basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target
33953422 }
33963423 traits_type::copy(std::__to_address(__new_data), std::__to_address(__p), size() + 1);
33973424 if (__was_long)
3398 __alloc_traits::deallocate(__alloc(), __p, __cap + 1);
3425 __alloc_traits::deallocate(__alloc_, __p, __cap + 1);
33993426 if (__now_long) {
34003427 __set_long_cap(__target_capacity + 1);
34013428 __set_long_size(__sz);
34023429 __set_long_pointer(__new_data);
34033430 } else
34043431 __set_short_size(__sz);
3405 __annotate_new(__sz);
34063432}
34073433
34083434template <class _CharT, class _Traits, class _Allocator>
......@@ -3434,38 +3460,30 @@ basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n,
34343460
34353461template <class _CharT, class _Traits, class _Allocator>
34363462inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
3437#if _LIBCPP_STD_VER >= 14
3463# if _LIBCPP_STD_VER >= 14
34383464 _NOEXCEPT
3439#else
3465# else
34403466 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>)
3441#endif
3467# endif
34423468{
34433469 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
34443470 __alloc_traits::propagate_on_container_swap::value || __alloc_traits::is_always_equal::value ||
3445 __alloc() == __str.__alloc(),
3471 __alloc_ == __str.__alloc_,
34463472 "swapping non-equal allocators");
34473473 if (!__is_long())
34483474 __annotate_delete();
3449 if (this != &__str && !__str.__is_long())
3475 if (this != std::addressof(__str) && !__str.__is_long())
34503476 __str.__annotate_delete();
3451 std::swap(__r_.first(), __str.__r_.first());
3452 std::__swap_allocator(__alloc(), __str.__alloc());
3477 std::swap(__rep_, __str.__rep_);
3478 std::__swap_allocator(__alloc_, __str.__alloc_);
34533479 if (!__is_long())
34543480 __annotate_new(__get_short_size());
3455 if (this != &__str && !__str.__is_long())
3481 if (this != std::addressof(__str) && !__str.__is_long())
34563482 __str.__annotate_new(__str.__get_short_size());
34573483}
34583484
34593485// find
34603486
3461template <class _Traits>
3462struct _LIBCPP_HIDDEN __traits_eq {
3463 typedef typename _Traits::char_type char_type;
3464 _LIBCPP_HIDE_FROM_ABI bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT {
3465 return _Traits::eq(__x, __y);
3466 }
3467};
3468
34693487template <class _CharT, class _Traits, class _Allocator>
34703488_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
34713489basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
......@@ -3810,8 +3828,8 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocat
38103828 clear();
38113829 if (__is_long()) {
38123830 __annotate_delete();
3813 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
3814 __r_.first() = __rep();
3831 __alloc_traits::deallocate(__alloc_, __get_long_pointer(), capacity() + 1);
3832 __rep_ = __rep();
38153833 }
38163834}
38173835
......@@ -3821,53 +3839,36 @@ template <class _CharT, class _Traits, class _Allocator>
38213839inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool
38223840operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
38233841 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT {
3824#if _LIBCPP_STD_VER >= 20
3825 return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs);
3826#else
38273842 size_t __lhs_sz = __lhs.size();
38283843 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(), __rhs.data(), __lhs_sz) == 0;
3829#endif
38303844}
38313845
3832template <class _Allocator>
3833inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool
3834operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3835 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT {
3836 size_t __sz = __lhs.size();
3837 if (__sz != __rhs.size())
3838 return false;
3839 return char_traits<char>::compare(__lhs.data(), __rhs.data(), __sz) == 0;
3840}
3841
3842#if _LIBCPP_STD_VER <= 17
3843template <class _CharT, class _Traits, class _Allocator>
3844inline _LIBCPP_HIDE_FROM_ABI bool
3845operator==(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT {
3846 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3847 _LIBCPP_ASSERT_NON_NULL(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3848 size_t __lhs_len = _Traits::length(__lhs);
3849 if (__lhs_len != __rhs.size())
3850 return false;
3851 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
3852}
3853#endif // _LIBCPP_STD_VER <= 17
3854
38553846template <class _CharT, class _Traits, class _Allocator>
38563847inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool
38573848operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) _NOEXCEPT {
3858#if _LIBCPP_STD_VER >= 20
3859 return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs);
3860#else
3861 typedef basic_string<_CharT, _Traits, _Allocator> _String;
38623849 _LIBCPP_ASSERT_NON_NULL(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3850
3851 using _String = basic_string<_CharT, _Traits, _Allocator>;
3852
38633853 size_t __rhs_len = _Traits::length(__rhs);
3854 if (__builtin_constant_p(__rhs_len) && !_String::__fits_in_sso(__rhs_len)) {
3855 if (!__lhs.__is_long())
3856 return false;
3857 }
38643858 if (__rhs_len != __lhs.size())
38653859 return false;
38663860 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
3867#endif
38683861}
38693862
3870#if _LIBCPP_STD_VER >= 20
3863# if _LIBCPP_STD_VER <= 17
3864template <class _CharT, class _Traits, class _Allocator>
3865inline _LIBCPP_HIDE_FROM_ABI bool
3866operator==(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT {
3867 return __rhs == __lhs;
3868}
3869# endif // _LIBCPP_STD_VER <= 17
3870
3871# if _LIBCPP_STD_VER >= 20
38713872
38723873template <class _CharT, class _Traits, class _Allocator>
38733874_LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
......@@ -3881,7 +3882,7 @@ operator<=>(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT
38813882 return basic_string_view<_CharT, _Traits>(__lhs) <=> basic_string_view<_CharT, _Traits>(__rhs);
38823883}
38833884
3884#else // _LIBCPP_STD_VER >= 20
3885# else // _LIBCPP_STD_VER >= 20
38853886
38863887template <class _CharT, class _Traits, class _Allocator>
38873888inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
......@@ -3980,7 +3981,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool
39803981operator>=(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT {
39813982 return !(__lhs < __rhs);
39823983}
3983#endif // _LIBCPP_STD_VER >= 20
3984# endif // _LIBCPP_STD_VER >= 20
39843985
39853986// operator +
39863987
......@@ -4063,7 +4064,7 @@ operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
40634064 return __r;
40644065}
40654066
4066#ifndef _LIBCPP_CXX03_LANG
4067# ifndef _LIBCPP_CXX03_LANG
40674068
40684069template <class _CharT, class _Traits, class _Allocator>
40694070inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>
......@@ -4109,9 +4110,9 @@ operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs) {
41094110 return std::move(__lhs);
41104111}
41114112
4112#endif // _LIBCPP_CXX03_LANG
4113# endif // _LIBCPP_CXX03_LANG
41134114
4114#if _LIBCPP_STD_VER >= 26
4115# if _LIBCPP_STD_VER >= 26
41154116
41164117template <class _CharT, class _Traits, class _Allocator>
41174118_LIBCPP_HIDE_FROM_ABI constexpr basic_string<_CharT, _Traits, _Allocator>
......@@ -4163,7 +4164,7 @@ operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs,
41634164 return std::move(__rhs);
41644165}
41654166
4166#endif // _LIBCPP_STD_VER >= 26
4167# endif // _LIBCPP_STD_VER >= 26
41674168
41684169// swap
41694170
......@@ -4194,7 +4195,7 @@ _LIBCPP_EXPORTED_FROM_ABI string to_string(float __val);
41944195_LIBCPP_EXPORTED_FROM_ABI string to_string(double __val);
41954196_LIBCPP_EXPORTED_FROM_ABI string to_string(long double __val);
41964197
4197#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4198# if _LIBCPP_HAS_WIDE_CHARACTERS
41984199_LIBCPP_EXPORTED_FROM_ABI int stoi(const wstring& __str, size_t* __idx = nullptr, int __base = 10);
41994200_LIBCPP_EXPORTED_FROM_ABI long stol(const wstring& __str, size_t* __idx = nullptr, int __base = 10);
42004201_LIBCPP_EXPORTED_FROM_ABI unsigned long stoul(const wstring& __str, size_t* __idx = nullptr, int __base = 10);
......@@ -4214,7 +4215,7 @@ _LIBCPP_EXPORTED_FROM_ABI wstring to_wstring(unsigned long long __val);
42144215_LIBCPP_EXPORTED_FROM_ABI wstring to_wstring(float __val);
42154216_LIBCPP_EXPORTED_FROM_ABI wstring to_wstring(double __val);
42164217_LIBCPP_EXPORTED_FROM_ABI wstring to_wstring(long double __val);
4217#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
4218# endif // _LIBCPP_HAS_WIDE_CHARACTERS
42184219
42194220template <class _CharT, class _Traits, class _Allocator>
42204221_LIBCPP_TEMPLATE_DATA_VIS const typename basic_string<_CharT, _Traits, _Allocator>::size_type
......@@ -4231,10 +4232,10 @@ struct __string_hash : public __unary_function<basic_string<_CharT, char_traits<
42314232template <class _Allocator>
42324233struct hash<basic_string<char, char_traits<char>, _Allocator> > : __string_hash<char, _Allocator> {};
42334234
4234#ifndef _LIBCPP_HAS_NO_CHAR8_T
4235# if _LIBCPP_HAS_CHAR8_T
42354236template <class _Allocator>
42364237struct hash<basic_string<char8_t, char_traits<char8_t>, _Allocator> > : __string_hash<char8_t, _Allocator> {};
4237#endif
4238# endif
42384239
42394240template <class _Allocator>
42404241struct hash<basic_string<char16_t, char_traits<char16_t>, _Allocator> > : __string_hash<char16_t, _Allocator> {};
......@@ -4242,10 +4243,10 @@ struct hash<basic_string<char16_t, char_traits<char16_t>, _Allocator> > : __stri
42424243template <class _Allocator>
42434244struct hash<basic_string<char32_t, char_traits<char32_t>, _Allocator> > : __string_hash<char32_t, _Allocator> {};
42444245
4245#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4246# if _LIBCPP_HAS_WIDE_CHARACTERS
42464247template <class _Allocator>
42474248struct hash<basic_string<wchar_t, char_traits<wchar_t>, _Allocator> > : __string_hash<wchar_t, _Allocator> {};
4248#endif
4249# endif
42494250
42504251template <class _CharT, class _Traits, class _Allocator>
42514252_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
......@@ -4271,7 +4272,7 @@ template <class _CharT, class _Traits, class _Allocator>
42714272inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
42724273getline(basic_istream<_CharT, _Traits>&& __is, basic_string<_CharT, _Traits, _Allocator>& __str);
42734274
4274#if _LIBCPP_STD_VER >= 20
4275# if _LIBCPP_STD_VER >= 20
42754276template <class _CharT, class _Traits, class _Allocator, class _Up>
42764277inline _LIBCPP_HIDE_FROM_ABI typename basic_string<_CharT, _Traits, _Allocator>::size_type
42774278erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) {
......@@ -4287,9 +4288,9 @@ erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, _Predicate __pred) {
42874288 __str.erase(std::remove_if(__str.begin(), __str.end(), __pred), __str.end());
42884289 return __old_size - __str.size();
42894290}
4290#endif
4291# endif
42914292
4292#if _LIBCPP_STD_VER >= 14
4293# if _LIBCPP_STD_VER >= 14
42934294// Literal suffixes for basic_string [basic.string.literals]
42944295inline namespace literals {
42954296inline namespace string_literals {
......@@ -4298,18 +4299,18 @@ operator""s(const char* __str, size_t __len) {
42984299 return basic_string<char>(__str, __len);
42994300}
43004301
4301# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4302# if _LIBCPP_HAS_WIDE_CHARACTERS
43024303inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<wchar_t>
43034304operator""s(const wchar_t* __str, size_t __len) {
43044305 return basic_string<wchar_t>(__str, __len);
43054306}
4306# endif
4307# endif
43074308
4308# ifndef _LIBCPP_HAS_NO_CHAR8_T
4309# if _LIBCPP_HAS_CHAR8_T
43094310inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string<char8_t> operator""s(const char8_t* __str, size_t __len) {
43104311 return basic_string<char8_t>(__str, __len);
43114312}
4312# endif
4313# endif
43134314
43144315inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<char16_t>
43154316operator""s(const char16_t* __str, size_t __len) {
......@@ -4323,30 +4324,31 @@ operator""s(const char32_t* __str, size_t __len) {
43234324} // namespace string_literals
43244325} // namespace literals
43254326
4326# if _LIBCPP_STD_VER >= 20
4327# if _LIBCPP_STD_VER >= 20
43274328template <>
43284329inline constexpr bool __format::__enable_insertable<std::basic_string<char>> = true;
4329# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4330# if _LIBCPP_HAS_WIDE_CHARACTERS
43304331template <>
43314332inline constexpr bool __format::__enable_insertable<std::basic_string<wchar_t>> = true;
4333# endif
43324334# endif
4333# endif
43344335
4335#endif
4336# endif
43364337
43374338_LIBCPP_END_NAMESPACE_STD
43384339
43394340_LIBCPP_POP_MACROS
43404341
4341#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
4342# include <algorithm>
4343# include <concepts>
4344# include <cstdlib>
4345# include <iterator>
4346# include <new>
4347# include <type_traits>
4348# include <typeinfo>
4349# include <utility>
4350#endif
4342# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
4343# include <algorithm>
4344# include <concepts>
4345# include <cstdlib>
4346# include <iterator>
4347# include <new>
4348# include <type_traits>
4349# include <typeinfo>
4350# include <utility>
4351# endif
4352#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
43514353
43524354#endif // _LIBCPP_STRING
lib/libcxx/include/string.h+17-12
......@@ -51,24 +51,28 @@ size_t strlen(const char* s);
5151
5252*/
5353
54#include <__config>
54#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
55# include <__cxx03/string.h>
56#else
57# include <__config>
5558
56#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
57# pragma GCC system_header
58#endif
59# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
60# pragma GCC system_header
61# endif
5962
60#if __has_include_next(<string.h>)
61# include_next <string.h>
62#endif
63# if __has_include_next(<string.h>)
64# include_next <string.h>
65# endif
6366
6467// MSVCRT, GNU libc and its derivates may already have the correct prototype in
6568// <string.h>. This macro can be defined by users if their C library provides
6669// the right signature.
67#if defined(__CORRECT_ISO_CPP_STRING_H_PROTO) || defined(_LIBCPP_MSVCRT) || defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_)
68# define _LIBCPP_STRING_H_HAS_CONST_OVERLOADS
69#endif
70# if defined(__CORRECT_ISO_CPP_STRING_H_PROTO) || defined(_LIBCPP_MSVCRT) || \
71 defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_)
72# define _LIBCPP_STRING_H_HAS_CONST_OVERLOADS
73# endif
7074
71#if defined(__cplusplus) && !defined(_LIBCPP_STRING_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
75# if defined(__cplusplus) && !defined(_LIBCPP_STRING_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
7276extern "C++" {
7377inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strchr(const char* __s, int __c) {
7478 return __builtin_strchr(__s, __c);
......@@ -105,6 +109,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD char* strstr(char* __s1,
105109 return __builtin_strstr(__s1, __s2);
106110}
107111} // extern "C++"
108#endif
112# endif
113#endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
109114
110115#endif // _LIBCPP_STRING_H
lib/libcxx/include/string_view+126-119
......@@ -205,57 +205,63 @@ namespace std {
205205
206206// clang-format on
207207
208#include <__algorithm/min.h>
209#include <__assert>
210#include <__config>
211#include <__functional/hash.h>
212#include <__functional/unary_function.h>
213#include <__fwd/ostream.h>
214#include <__fwd/string_view.h>
215#include <__iterator/bounded_iter.h>
216#include <__iterator/concepts.h>
217#include <__iterator/iterator_traits.h>
218#include <__iterator/reverse_iterator.h>
219#include <__iterator/wrap_iter.h>
220#include <__memory/pointer_traits.h>
221#include <__ranges/concepts.h>
222#include <__ranges/data.h>
223#include <__ranges/enable_borrowed_range.h>
224#include <__ranges/enable_view.h>
225#include <__ranges/size.h>
226#include <__string/char_traits.h>
227#include <__type_traits/is_array.h>
228#include <__type_traits/is_convertible.h>
229#include <__type_traits/is_same.h>
230#include <__type_traits/is_standard_layout.h>
231#include <__type_traits/is_trivial.h>
232#include <__type_traits/remove_cvref.h>
233#include <__type_traits/remove_reference.h>
234#include <__type_traits/type_identity.h>
235#include <cstddef>
236#include <iosfwd>
237#include <limits>
238#include <stdexcept>
239#include <version>
208#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
209# include <__cxx03/string_view>
210#else
211# include <__algorithm/min.h>
212# include <__assert>
213# include <__config>
214# include <__cstddef/nullptr_t.h>
215# include <__cstddef/ptrdiff_t.h>
216# include <__cstddef/size_t.h>
217# include <__functional/hash.h>
218# include <__functional/unary_function.h>
219# include <__fwd/ostream.h>
220# include <__fwd/string.h>
221# include <__fwd/string_view.h>
222# include <__iterator/bounded_iter.h>
223# include <__iterator/concepts.h>
224# include <__iterator/iterator_traits.h>
225# include <__iterator/reverse_iterator.h>
226# include <__iterator/wrap_iter.h>
227# include <__memory/pointer_traits.h>
228# include <__ranges/concepts.h>
229# include <__ranges/data.h>
230# include <__ranges/enable_borrowed_range.h>
231# include <__ranges/enable_view.h>
232# include <__ranges/size.h>
233# include <__string/char_traits.h>
234# include <__type_traits/is_array.h>
235# include <__type_traits/is_convertible.h>
236# include <__type_traits/is_same.h>
237# include <__type_traits/is_standard_layout.h>
238# include <__type_traits/is_trivial.h>
239# include <__type_traits/remove_cvref.h>
240# include <__type_traits/remove_reference.h>
241# include <__type_traits/type_identity.h>
242# include <iosfwd>
243# include <limits>
244# include <stdexcept>
245# include <version>
240246
241247// standard-mandated includes
242248
243249// [iterator.range]
244#include <__iterator/access.h>
245#include <__iterator/data.h>
246#include <__iterator/empty.h>
247#include <__iterator/reverse_access.h>
248#include <__iterator/size.h>
250# include <__iterator/access.h>
251# include <__iterator/data.h>
252# include <__iterator/empty.h>
253# include <__iterator/reverse_access.h>
254# include <__iterator/size.h>
249255
250256// [string.view.synop]
251#include <compare>
257# include <compare>
252258
253#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
254# pragma GCC system_header
255#endif
259# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
260# pragma GCC system_header
261# endif
256262
257263_LIBCPP_PUSH_MACROS
258#include <__undef_macros>
264# include <__undef_macros>
259265
260266_LIBCPP_BEGIN_NAMESPACE_STD
261267
......@@ -280,13 +286,13 @@ public:
280286 using const_pointer = const _CharT*;
281287 using reference = _CharT&;
282288 using const_reference = const _CharT&;
283#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS)
289# if defined(_LIBCPP_ABI_BOUNDED_ITERATORS)
284290 using const_iterator = __bounded_iter<const_pointer>;
285#elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW)
291# elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW)
286292 using const_iterator = __wrap_iter<const_pointer>;
287#else
293# else
288294 using const_iterator = const_pointer;
289#endif
295# endif
290296 using iterator = const_iterator;
291297 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
292298 using reverse_iterator = const_reverse_iterator;
......@@ -310,7 +316,7 @@ public:
310316 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT
311317 : __data_(__s),
312318 __size_(__len) {
313#if _LIBCPP_STD_VER >= 14
319# if _LIBCPP_STD_VER >= 14
314320 // Allocations must fit in `ptrdiff_t` for pointer arithmetic to work. If `__len` exceeds it, the input
315321 // range could not have been valid. Most likely the caller underflowed some arithmetic and inadvertently
316322 // passed in a negative length.
......@@ -319,10 +325,10 @@ public:
319325 "string_view::string_view(_CharT *, size_t): length does not fit in difference_type");
320326 _LIBCPP_ASSERT_NON_NULL(
321327 __len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr");
322#endif
328# endif
323329 }
324330
325#if _LIBCPP_STD_VER >= 20
331# if _LIBCPP_STD_VER >= 20
326332 template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
327333 requires(is_same_v<iter_value_t<_It>, _CharT> && !is_convertible_v<_End, size_type>)
328334 constexpr _LIBCPP_HIDE_FROM_ABI basic_string_view(_It __begin, _End __end)
......@@ -330,9 +336,9 @@ public:
330336 _LIBCPP_ASSERT_VALID_INPUT_RANGE(
331337 (__end - __begin) >= 0, "std::string_view::string_view(iterator, sentinel) received invalid range");
332338 }
333#endif // _LIBCPP_STD_VER >= 20
339# endif // _LIBCPP_STD_VER >= 20
334340
335#if _LIBCPP_STD_VER >= 23
341# if _LIBCPP_STD_VER >= 23
336342 template <class _Range>
337343 requires(!is_same_v<remove_cvref_t<_Range>, basic_string_view> && ranges::contiguous_range<_Range> &&
338344 ranges::sized_range<_Range> && is_same_v<ranges::range_value_t<_Range>, _CharT> &&
......@@ -340,14 +346,14 @@ public:
340346 (!requires(remove_cvref_t<_Range>& __d) { __d.operator std::basic_string_view<_CharT, _Traits>(); }))
341347 constexpr explicit _LIBCPP_HIDE_FROM_ABI basic_string_view(_Range&& __r)
342348 : __data_(ranges::data(__r)), __size_(ranges::size(__r)) {}
343#endif // _LIBCPP_STD_VER >= 23
349# endif // _LIBCPP_STD_VER >= 23
344350
345351 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI basic_string_view(const _CharT* __s)
346352 : __data_(__s), __size_(std::__char_traits_length_checked<_Traits>(__s)) {}
347353
348#if _LIBCPP_STD_VER >= 23
354# if _LIBCPP_STD_VER >= 23
349355 basic_string_view(nullptr_t) = delete;
350#endif
356# endif
351357
352358 // [string.view.iterators], iterators
353359 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return cbegin(); }
......@@ -355,19 +361,19 @@ public:
355361 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return cend(); }
356362
357363 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT {
358#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
364# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
359365 return std::__make_bounded_iter(data(), data(), data() + size());
360#else
366# else
361367 return const_iterator(__data_);
362#endif
368# endif
363369 }
364370
365371 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT {
366#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
372# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
367373 return std::__make_bounded_iter(data() + size(), data(), data() + size());
368#else
374# else
369375 return const_iterator(__data_ + __size_);
370#endif
376# endif
371377 }
372378
373379 _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT {
......@@ -395,7 +401,7 @@ public:
395401 return numeric_limits<size_type>::max() / sizeof(value_type);
396402 }
397403
398 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return __size_ == 0; }
404 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return __size_ == 0; }
399405
400406 // [string.view.access], element access
401407 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __pos) const _NOEXCEPT {
......@@ -448,8 +454,11 @@ public:
448454 }
449455
450456 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI basic_string_view substr(size_type __pos = 0, size_type __n = npos) const {
457 // Use the `__assume_valid` form of the constructor to avoid an unnecessary check. Any substring of a view is a
458 // valid view. In particular, `size()` is known to be smaller than `numeric_limits<difference_type>::max()`, so the
459 // new size is also smaller. See also https://github.com/llvm/llvm-project/issues/91634.
451460 return __pos > size() ? (__throw_out_of_range("string_view::substr"), basic_string_view())
452 : basic_string_view(data() + __pos, std::min(__n, size() - __pos));
461 : basic_string_view(__assume_valid(), data() + __pos, std::min(__n, size() - __pos));
453462 }
454463
455464 _LIBCPP_CONSTEXPR_SINCE_CXX14 int compare(basic_string_view __sv) const _NOEXCEPT {
......@@ -639,7 +648,7 @@ public:
639648 data(), size(), __s, __pos, traits_type::length(__s));
640649 }
641650
642#if _LIBCPP_STD_VER >= 20
651# if _LIBCPP_STD_VER >= 20
643652 constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(basic_string_view __s) const noexcept {
644653 return size() >= __s.size() && compare(0, __s.size(), __s) == 0;
645654 }
......@@ -663,54 +672,70 @@ public:
663672 constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(const value_type* __s) const noexcept {
664673 return ends_with(basic_string_view(__s));
665674 }
666#endif
675# endif
667676
668#if _LIBCPP_STD_VER >= 23
677# if _LIBCPP_STD_VER >= 23
669678 constexpr _LIBCPP_HIDE_FROM_ABI bool contains(basic_string_view __sv) const noexcept { return find(__sv) != npos; }
670679
671680 constexpr _LIBCPP_HIDE_FROM_ABI bool contains(value_type __c) const noexcept { return find(__c) != npos; }
672681
673682 constexpr _LIBCPP_HIDE_FROM_ABI bool contains(const value_type* __s) const { return find(__s) != npos; }
674#endif
683# endif
675684
676685private:
686 struct __assume_valid {};
687
688 // This is the same as the pointer and length constructor, but without the additional hardening checks. It is intended
689 // for use within the class, when the class invariants already guarantee the resulting object is valid. The compiler
690 // usually cannot eliminate the redundant checks because it does not know class invariants.
691 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
692 basic_string_view(__assume_valid, const _CharT* __s, size_type __len) _NOEXCEPT
693 : __data_(__s),
694 __size_(__len) {}
695
677696 const value_type* __data_;
678697 size_type __size_;
698
699 template <class, class, class>
700 friend class basic_string;
679701};
680702_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(basic_string_view);
681703
682#if _LIBCPP_STD_VER >= 20
704# if _LIBCPP_STD_VER >= 20
683705template <class _CharT, class _Traits>
684706inline constexpr bool ranges::enable_view<basic_string_view<_CharT, _Traits>> = true;
685707
686708template <class _CharT, class _Traits>
687709inline constexpr bool ranges::enable_borrowed_range<basic_string_view<_CharT, _Traits> > = true;
688#endif // _LIBCPP_STD_VER >= 20
710# endif // _LIBCPP_STD_VER >= 20
689711
690712// [string.view.deduct]
691713
692#if _LIBCPP_STD_VER >= 20
714# if _LIBCPP_STD_VER >= 20
693715template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
694716basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>;
695#endif // _LIBCPP_STD_VER >= 20
717# endif // _LIBCPP_STD_VER >= 20
696718
697#if _LIBCPP_STD_VER >= 23
719# if _LIBCPP_STD_VER >= 23
698720template <ranges::contiguous_range _Range>
699721basic_string_view(_Range) -> basic_string_view<ranges::range_value_t<_Range>>;
700#endif
722# endif
701723
702724// [string.view.comparison]
703725
704#if _LIBCPP_STD_VER >= 20
705
706template <class _CharT, class _Traits>
707_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(basic_string_view<_CharT, _Traits> __lhs,
708 type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) noexcept {
726// The dummy default template parameters are used to work around a MSVC issue with mangling, see VSO-409326 for details.
727// This applies to the other sufficient overloads below for the other comparison operators.
728template <class _CharT, class _Traits, int = 1>
729_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
730operator==(basic_string_view<_CharT, _Traits> __lhs,
731 __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
709732 if (__lhs.size() != __rhs.size())
710733 return false;
711734 return __lhs.compare(__rhs) == 0;
712735}
713736
737# if _LIBCPP_STD_VER >= 20
738
714739template <class _CharT, class _Traits>
715740_LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(basic_string_view<_CharT, _Traits> __lhs,
716741 type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) noexcept {
......@@ -724,7 +749,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(basic_string_view<_CharT, _Trai
724749 }
725750}
726751
727#else
752# else
728753
729754// operator ==
730755
......@@ -736,51 +761,32 @@ operator==(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _
736761 return __lhs.compare(__rhs) == 0;
737762}
738763
739// The dummy default template parameters are used to work around a MSVC issue with mangling, see VSO-409326 for details.
740// This applies to the other sufficient overloads below for the other comparison operators.
741template <class _CharT, class _Traits, int = 1>
742_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
743operator==(basic_string_view<_CharT, _Traits> __lhs,
744 __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
745 if (__lhs.size() != __rhs.size())
746 return false;
747 return __lhs.compare(__rhs) == 0;
748}
749
750764template <class _CharT, class _Traits, int = 2>
751765_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
752766operator==(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
753767 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
754 if (__lhs.size() != __rhs.size())
755 return false;
756 return __lhs.compare(__rhs) == 0;
768 return __lhs == __rhs;
757769}
758770
759771// operator !=
760772template <class _CharT, class _Traits>
761773_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
762774operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
763 if (__lhs.size() != __rhs.size())
764 return true;
765 return __lhs.compare(__rhs) != 0;
775 return !(__lhs == __rhs);
766776}
767777
768778template <class _CharT, class _Traits, int = 1>
769779_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
770780operator!=(basic_string_view<_CharT, _Traits> __lhs,
771781 __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
772 if (__lhs.size() != __rhs.size())
773 return true;
774 return __lhs.compare(__rhs) != 0;
782 return !(__lhs == __rhs);
775783}
776784
777785template <class _CharT, class _Traits, int = 2>
778786_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
779787operator!=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
780788 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
781 if (__lhs.size() != __rhs.size())
782 return true;
783 return __lhs.compare(__rhs) != 0;
789 return !(__lhs == __rhs);
784790}
785791
786792// operator <
......@@ -867,7 +873,7 @@ operator>=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
867873 return __lhs.compare(__rhs) >= 0;
868874}
869875
870#endif // _LIBCPP_STD_VER >= 20
876# endif // _LIBCPP_STD_VER >= 20
871877
872878template <class _CharT, class _Traits>
873879_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
......@@ -884,10 +890,10 @@ struct __string_view_hash : public __unary_function<basic_string_view<_CharT, ch
884890template <>
885891struct hash<basic_string_view<char, char_traits<char> > > : __string_view_hash<char> {};
886892
887#ifndef _LIBCPP_HAS_NO_CHAR8_T
893# if _LIBCPP_HAS_CHAR8_T
888894template <>
889895struct hash<basic_string_view<char8_t, char_traits<char8_t> > > : __string_view_hash<char8_t> {};
890#endif
896# endif
891897
892898template <>
893899struct hash<basic_string_view<char16_t, char_traits<char16_t> > > : __string_view_hash<char16_t> {};
......@@ -895,31 +901,31 @@ struct hash<basic_string_view<char16_t, char_traits<char16_t> > > : __string_vie
895901template <>
896902struct hash<basic_string_view<char32_t, char_traits<char32_t> > > : __string_view_hash<char32_t> {};
897903
898#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
904# if _LIBCPP_HAS_WIDE_CHARACTERS
899905template <>
900906struct hash<basic_string_view<wchar_t, char_traits<wchar_t> > > : __string_view_hash<wchar_t> {};
901#endif
907# endif
902908
903#if _LIBCPP_STD_VER >= 14
909# if _LIBCPP_STD_VER >= 14
904910inline namespace literals {
905911inline namespace string_view_literals {
906912inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<char> operator""sv(const char* __str, size_t __len) noexcept {
907913 return basic_string_view<char>(__str, __len);
908914}
909915
910# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
916# if _LIBCPP_HAS_WIDE_CHARACTERS
911917inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<wchar_t>
912918operator""sv(const wchar_t* __str, size_t __len) noexcept {
913919 return basic_string_view<wchar_t>(__str, __len);
914920}
915# endif
921# endif
916922
917# ifndef _LIBCPP_HAS_NO_CHAR8_T
923# if _LIBCPP_HAS_CHAR8_T
918924inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<char8_t>
919925operator""sv(const char8_t* __str, size_t __len) noexcept {
920926 return basic_string_view<char8_t>(__str, __len);
921927}
922# endif
928# endif
923929
924930inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<char16_t>
925931operator""sv(const char16_t* __str, size_t __len) noexcept {
......@@ -932,17 +938,18 @@ operator""sv(const char32_t* __str, size_t __len) noexcept {
932938}
933939} // namespace string_view_literals
934940} // namespace literals
935#endif
941# endif
936942_LIBCPP_END_NAMESPACE_STD
937943
938944_LIBCPP_POP_MACROS
939945
940#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
941# include <algorithm>
942# include <concepts>
943# include <cstdlib>
944# include <iterator>
945# include <type_traits>
946#endif
946# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
947# include <algorithm>
948# include <concepts>
949# include <cstdlib>
950# include <iterator>
951# include <type_traits>
952# endif
953#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
947954
948955#endif // _LIBCPP_STRING_VIEW
lib/libcxx/include/strstream+29-24
......@@ -129,30 +129,34 @@ private:
129129
130130*/
131131
132#include <__config>
133#include <istream>
134#include <ostream>
135#include <version>
136
137#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
138# pragma GCC system_header
139#endif
132#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
133# include <__cxx03/strstream>
134#else
135# include <__config>
136# include <__ostream/basic_ostream.h>
137# include <istream>
138# include <streambuf>
139# include <version>
140
141# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
142# pragma GCC system_header
143# endif
140144
141#if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM) || defined(_LIBCPP_BUILDING_LIBRARY)
145# if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM) || defined(_LIBCPP_BUILDING_LIBRARY)
142146
143147_LIBCPP_PUSH_MACROS
144# include <__undef_macros>
148# include <__undef_macros>
145149
146150_LIBCPP_BEGIN_NAMESPACE_STD
147151
148152class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI strstreambuf : public streambuf {
149153public:
150# ifndef _LIBCPP_CXX03_LANG
154# ifndef _LIBCPP_CXX03_LANG
151155 _LIBCPP_HIDE_FROM_ABI strstreambuf() : strstreambuf(0) {}
152156 explicit strstreambuf(streamsize __alsize);
153# else
157# else
154158 explicit strstreambuf(streamsize __alsize = 0);
155# endif
159# endif
156160 strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*));
157161 strstreambuf(char* __gnext, streamsize __n, char* __pbeg = nullptr);
158162 strstreambuf(const char* __gnext, streamsize __n);
......@@ -162,10 +166,10 @@ public:
162166 strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg = nullptr);
163167 strstreambuf(const unsigned char* __gnext, streamsize __n);
164168
165# ifndef _LIBCPP_CXX03_LANG
169# ifndef _LIBCPP_CXX03_LANG
166170 _LIBCPP_HIDE_FROM_ABI strstreambuf(strstreambuf&& __rhs);
167171 _LIBCPP_HIDE_FROM_ABI strstreambuf& operator=(strstreambuf&& __rhs);
168# endif // _LIBCPP_CXX03_LANG
172# endif // _LIBCPP_CXX03_LANG
169173
170174 ~strstreambuf() override;
171175
......@@ -199,7 +203,7 @@ private:
199203 void __init(char* __gnext, streamsize __n, char* __pbeg);
200204};
201205
202# ifndef _LIBCPP_CXX03_LANG
206# ifndef _LIBCPP_CXX03_LANG
203207
204208inline _LIBCPP_HIDE_FROM_ABI strstreambuf::strstreambuf(strstreambuf&& __rhs)
205209 : streambuf(__rhs),
......@@ -228,7 +232,7 @@ inline _LIBCPP_HIDE_FROM_ABI strstreambuf& strstreambuf::operator=(strstreambuf&
228232 return *this;
229233}
230234
231# endif // _LIBCPP_CXX03_LANG
235# endif // _LIBCPP_CXX03_LANG
232236
233237class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI istrstream : public istream {
234238public:
......@@ -237,7 +241,7 @@ public:
237241 _LIBCPP_HIDE_FROM_ABI istrstream(const char* __s, streamsize __n) : istream(&__sb_), __sb_(__s, __n) {}
238242 _LIBCPP_HIDE_FROM_ABI istrstream(char* __s, streamsize __n) : istream(&__sb_), __sb_(__s, __n) {}
239243
240# ifndef _LIBCPP_CXX03_LANG
244# ifndef _LIBCPP_CXX03_LANG
241245 _LIBCPP_HIDE_FROM_ABI istrstream(istrstream&& __rhs) // extension
242246 : istream(std::move(static_cast<istream&>(__rhs))), __sb_(std::move(__rhs.__sb_)) {
243247 istream::set_rdbuf(&__sb_);
......@@ -248,7 +252,7 @@ public:
248252 istream::operator=(std::move(__rhs));
249253 return *this;
250254 }
251# endif // _LIBCPP_CXX03_LANG
255# endif // _LIBCPP_CXX03_LANG
252256
253257 ~istrstream() override;
254258
......@@ -270,7 +274,7 @@ public:
270274 _LIBCPP_HIDE_FROM_ABI ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out)
271275 : ostream(&__sb_), __sb_(__s, __n, __s + (__mode & ios::app ? std::strlen(__s) : 0)) {}
272276
273# ifndef _LIBCPP_CXX03_LANG
277# ifndef _LIBCPP_CXX03_LANG
274278 _LIBCPP_HIDE_FROM_ABI ostrstream(ostrstream&& __rhs) // extension
275279 : ostream(std::move(static_cast<ostream&>(__rhs))), __sb_(std::move(__rhs.__sb_)) {
276280 ostream::set_rdbuf(&__sb_);
......@@ -281,7 +285,7 @@ public:
281285 ostream::operator=(std::move(__rhs));
282286 return *this;
283287 }
284# endif // _LIBCPP_CXX03_LANG
288# endif // _LIBCPP_CXX03_LANG
285289
286290 ~ostrstream() override;
287291
......@@ -312,7 +316,7 @@ public:
312316 _LIBCPP_HIDE_FROM_ABI strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out)
313317 : iostream(&__sb_), __sb_(__s, __n, __s + (__mode & ios::app ? std::strlen(__s) : 0)) {}
314318
315# ifndef _LIBCPP_CXX03_LANG
319# ifndef _LIBCPP_CXX03_LANG
316320 _LIBCPP_HIDE_FROM_ABI strstream(strstream&& __rhs) // extension
317321 : iostream(std::move(static_cast<iostream&>(__rhs))), __sb_(std::move(__rhs.__sb_)) {
318322 iostream::set_rdbuf(&__sb_);
......@@ -323,7 +327,7 @@ public:
323327 iostream::operator=(std::move(__rhs));
324328 return *this;
325329 }
326# endif // _LIBCPP_CXX03_LANG
330# endif // _LIBCPP_CXX03_LANG
327331
328332 ~strstream() override;
329333
......@@ -346,6 +350,7 @@ _LIBCPP_END_NAMESPACE_STD
346350
347351_LIBCPP_POP_MACROS
348352
349#endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM) || defined(_LIBCPP_BUILDING_LIBRARY)
353# endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM) || defined(_LIBCPP_BUILDING_LIBRARY)
354#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
350355
351356#endif // _LIBCPP_STRSTREAM
lib/libcxx/include/syncstream+58-46
......@@ -46,7 +46,9 @@ namespace std {
4646 using streambuf_type = basic_streambuf<charT, traits>;
4747
4848 // [syncstream.syncbuf.cons], construction and destruction
49 explicit basic_syncbuf(streambuf_type* obuf = nullptr)
49 basic_syncbuf()
50 : basic_syncbuf(nullptr) {}
51 explicit basic_syncbuf(streambuf_type* obuf)
5052 : basic_syncbuf(obuf, Allocator()) {}
5153 basic_syncbuf(streambuf_type*, const Allocator&);
5254 basic_syncbuf(basic_syncbuf&&);
......@@ -115,34 +117,40 @@ namespace std {
115117
116118*/
117119
118#include <__config>
119#include <__utility/move.h>
120#include <ios>
121#include <iosfwd> // required for declaration of default arguments
122#include <streambuf>
123#include <string>
120#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
121# include <__cxx03/syncstream>
122#else
123# include <__config>
124124
125#ifndef _LIBCPP_HAS_NO_THREADS
126# include <map>
127# include <mutex>
128# include <shared_mutex>
129#endif
125# if _LIBCPP_HAS_LOCALIZATION
126
127# include <__mutex/lock_guard.h>
128# include <__utility/move.h>
129# include <ios>
130# include <iosfwd> // required for declaration of default arguments
131# include <streambuf>
132# include <string>
133
134# if _LIBCPP_HAS_THREADS
135# include <map>
136# include <shared_mutex>
137# endif
130138
131139// standard-mandated includes
132140
133141// [syncstream.syn]
134#include <ostream>
142# include <ostream>
135143
136#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
137# pragma GCC system_header
138#endif
144# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
145# pragma GCC system_header
146# endif
139147
140148_LIBCPP_PUSH_MACROS
141#include <__undef_macros>
149# include <__undef_macros>
142150
143151_LIBCPP_BEGIN_NAMESPACE_STD
144152
145#if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM)
153# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_EXPERIMENTAL_SYNCSTREAM
146154
147155// [syncstream.syncbuf.overview]/1
148156// Class template basic_syncbuf stores character data written to it,
......@@ -155,7 +163,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
155163//
156164// This helper singleton is used to implement the required
157165// synchronisation guarantees.
158# ifndef _LIBCPP_HAS_NO_THREADS
166# if _LIBCPP_HAS_THREADS
159167class __wrapped_streambuf_mutex {
160168 _LIBCPP_HIDE_FROM_ABI __wrapped_streambuf_mutex() = default;
161169
......@@ -228,7 +236,7 @@ private:
228236 return __it;
229237 }
230238};
231# endif // _LIBCPP_HAS_NO_THREADS
239# endif // _LIBCPP_HAS_THREADS
232240
233241// basic_syncbuf
234242
......@@ -253,8 +261,9 @@ public:
253261
254262 // [syncstream.syncbuf.cons], construction and destruction
255263
256 _LIBCPP_HIDE_FROM_ABI explicit basic_syncbuf(streambuf_type* __obuf = nullptr)
257 : basic_syncbuf(__obuf, _Allocator()) {}
264 _LIBCPP_HIDE_FROM_ABI basic_syncbuf() : basic_syncbuf(nullptr) {}
265
266 _LIBCPP_HIDE_FROM_ABI explicit basic_syncbuf(streambuf_type* __obuf) : basic_syncbuf(__obuf, _Allocator()) {}
258267
259268 _LIBCPP_HIDE_FROM_ABI basic_syncbuf(streambuf_type* __obuf, _Allocator const& __alloc)
260269 : __wrapped_(__obuf), __str_(__alloc) {
......@@ -267,14 +276,14 @@ public:
267276 }
268277
269278 _LIBCPP_HIDE_FROM_ABI ~basic_syncbuf() {
270# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
279# if _LIBCPP_HAS_EXCEPTIONS
271280 try {
272# endif // _LIBCPP_HAS_NO_EXCEPTIONS
281# endif // _LIBCPP_HAS_EXCEPTIONS
273282 emit();
274# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
283# if _LIBCPP_HAS_EXCEPTIONS
275284 } catch (...) {
276285 }
277# endif // _LIBCPP_HAS_NO_EXCEPTIONS
286# endif // _LIBCPP_HAS_EXCEPTIONS
278287 __dec_reference();
279288 }
280289
......@@ -331,9 +340,9 @@ protected:
331340 return traits_type::not_eof(__c);
332341
333342 if (this->pptr() == this->epptr()) {
334# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
343# if _LIBCPP_HAS_EXCEPTIONS
335344 try {
336# endif
345# endif
337346 size_t __size = __str_.size();
338347 __str_.resize(__str_.capacity() + 1);
339348 _LIBCPP_ASSERT_INTERNAL(__str_.size() > __size, "the buffer hasn't grown");
......@@ -342,11 +351,11 @@ protected:
342351 this->setp(__p, __p + __str_.size());
343352 this->pbump(__size);
344353
345# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
354# if _LIBCPP_HAS_EXCEPTIONS
346355 } catch (...) {
347356 return traits_type::eof();
348357 }
349# endif
358# endif
350359 }
351360
352361 return this->sputc(traits_type::to_char_type(__c));
......@@ -358,7 +367,7 @@ private:
358367 // TODO Use a more generic buffer.
359368 // That buffer should be light with almost no additional headers. Then
360369 // it can be use here, the __retarget_buffer, and place that use
361 // the now deprecated get_temporary_buffer
370 // the now removed get_temporary_buffer
362371
363372 basic_string<_CharT, _Traits, _Allocator> __str_;
364373 bool __emit_on_sync_{false};
......@@ -367,9 +376,9 @@ private:
367376 if (!__wrapped_)
368377 return false;
369378
370# ifndef _LIBCPP_HAS_NO_THREADS
379# if _LIBCPP_HAS_THREADS
371380 lock_guard<mutex> __lock = __wrapped_streambuf_mutex::__instance().__get_lock(__wrapped_);
372# endif
381# endif
373382
374383 bool __result = true;
375384 if (this->pptr() != this->pbase()) {
......@@ -401,24 +410,24 @@ private:
401410 }
402411
403412 _LIBCPP_HIDE_FROM_ABI void __inc_reference() {
404# ifndef _LIBCPP_HAS_NO_THREADS
413# if _LIBCPP_HAS_THREADS
405414 if (__wrapped_)
406415 __wrapped_streambuf_mutex::__instance().__inc_reference(__wrapped_);
407# endif
416# endif
408417 }
409418
410419 _LIBCPP_HIDE_FROM_ABI void __dec_reference() noexcept {
411# ifndef _LIBCPP_HAS_NO_THREADS
420# if _LIBCPP_HAS_THREADS
412421 if (__wrapped_)
413422 __wrapped_streambuf_mutex::__instance().__dec_reference(__wrapped_);
414# endif
423# endif
415424 }
416425};
417426
418427using std::syncbuf;
419# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
428# if _LIBCPP_HAS_WIDE_CHARACTERS
420429using std::wsyncbuf;
421# endif
430# endif
422431
423432// [syncstream.syncbuf.special], specialized algorithms
424433template <class _CharT, class _Traits, class _Allocator>
......@@ -474,17 +483,17 @@ public:
474483 // TODO validate other unformatted output functions.
475484 typename basic_ostream<char_type, traits_type>::sentry __s(*this);
476485 if (__s) {
477# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
486# if _LIBCPP_HAS_EXCEPTIONS
478487 try {
479# endif
488# endif
480489
481490 if (__sb_.emit() == false)
482491 this->setstate(ios::badbit);
483# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
492# if _LIBCPP_HAS_EXCEPTIONS
484493 } catch (...) {
485494 this->__set_badbit_and_consider_rethrow();
486495 }
487# endif
496# endif
488497 }
489498 }
490499
......@@ -499,14 +508,17 @@ private:
499508};
500509
501510using std::osyncstream;
502# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
511# if _LIBCPP_HAS_WIDE_CHARACTERS
503512using std::wosyncstream;
504# endif
513# endif
505514
506#endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM)
515# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_EXPERIMENTAL_SYNCSTREAM
507516
508517_LIBCPP_END_NAMESPACE_STD
509518
510519_LIBCPP_POP_MACROS
511520
521# endif // _LIBCPP_HAS_LOCALIZATION
522#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
523
512524#endif // _LIBCPP_SYNCSTREAM
lib/libcxx/include/system_error+23-19
......@@ -144,28 +144,32 @@ template <> struct hash<std::error_condition>;
144144
145145*/
146146
147#include <__config>
148#include <__system_error/errc.h>
149#include <__system_error/error_category.h>
150#include <__system_error/error_code.h>
151#include <__system_error/error_condition.h>
152#include <__system_error/system_error.h>
153#include <version>
147#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
148# include <__cxx03/system_error>
149#else
150# include <__config>
151# include <__system_error/errc.h>
152# include <__system_error/error_category.h>
153# include <__system_error/error_code.h>
154# include <__system_error/error_condition.h>
155# include <__system_error/system_error.h>
156# include <version>
154157
155158// standard-mandated includes
156159
157160// [system.error.syn]
158#include <compare>
159
160#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
161# pragma GCC system_header
162#endif
163
164#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
165# include <cstdint>
166# include <cstring>
167# include <limits>
168# include <type_traits>
169#endif
161# include <compare>
162
163# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
164# pragma GCC system_header
165# endif
166
167# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
168# include <cstdint>
169# include <cstring>
170# include <limits>
171# include <type_traits>
172# endif
173#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
170174
171175#endif // _LIBCPP_SYSTEM_ERROR
lib/libcxx/include/tgmath.h+15-10
......@@ -17,18 +17,23 @@
1717
1818*/
1919
20#include <__config>
20#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
21# include <__cxx03/tgmath.h>
22#else
23# include <__config>
2124
22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23# pragma GCC system_header
24#endif
25# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26# pragma GCC system_header
27# endif
2528
26#ifdef __cplusplus
27# include <ctgmath>
28#else
29# if __has_include_next(<tgmath.h>)
30# include_next <tgmath.h>
29# ifdef __cplusplus
30# include <cmath>
31# include <complex>
32# else
33# if __has_include_next(<tgmath.h>)
34# include_next <tgmath.h>
35# endif
3136# endif
32#endif
37#endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
3338
3439#endif // _LIBCPP_TGMATH_H
lib/libcxx/include/thread+34-31
......@@ -86,45 +86,48 @@ void sleep_for(const chrono::duration<Rep, Period>& rel_time);
8686
8787*/
8888
89#include <__config>
89#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
90# include <__cxx03/thread>
91#else
92# include <__config>
9093
91#if !defined(_LIBCPP_HAS_NO_THREADS)
94# if _LIBCPP_HAS_THREADS
9295
93# include <__thread/formatter.h>
94# include <__thread/jthread.h>
95# include <__thread/support.h>
96# include <__thread/this_thread.h>
97# include <__thread/thread.h>
98# include <version>
96# include <__thread/this_thread.h>
97# include <__thread/thread.h>
98
99# if _LIBCPP_STD_VER >= 20
100# include <__thread/jthread.h>
101# endif
102
103# if _LIBCPP_STD_VER >= 23
104# include <__thread/formatter.h>
105# endif
106
107# include <version>
99108
100109// standard-mandated includes
101110
102111// [thread.syn]
103# include <compare>
112# include <compare>
104113
105# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
106# pragma GCC system_header
114# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
115# pragma GCC system_header
116# endif
117
118# endif // _LIBCPP_HAS_THREADS
119
120# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
121# include <chrono>
107122# endif
108123
109#endif // !defined(_LIBCPP_HAS_NO_THREADS)
110
111#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
112# include <cstddef>
113# include <ctime>
114# include <iosfwd>
115# include <ratio>
116#endif
117
118#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
119# include <chrono>
120#endif
121
122#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
123# include <cstring>
124# include <functional>
125# include <new>
126# include <system_error>
127# include <type_traits>
128#endif
124# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
125# include <cstring>
126# include <functional>
127# include <new>
128# include <system_error>
129# include <type_traits>
130# endif
131#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
129132
130133#endif // _LIBCPP_THREAD
lib/libcxx/include/tuple+159-136
......@@ -210,73 +210,80 @@ template <class... Types>
210210
211211// clang-format on
212212
213#include <__compare/common_comparison_category.h>
214#include <__compare/synth_three_way.h>
215#include <__config>
216#include <__functional/invoke.h>
217#include <__fwd/array.h>
218#include <__fwd/pair.h>
219#include <__fwd/tuple.h>
220#include <__memory/allocator_arg_t.h>
221#include <__memory/uses_allocator.h>
222#include <__tuple/find_index.h>
223#include <__tuple/ignore.h>
224#include <__tuple/make_tuple_types.h>
225#include <__tuple/sfinae_helpers.h>
226#include <__tuple/tuple_element.h>
227#include <__tuple/tuple_indices.h>
228#include <__tuple/tuple_like_ext.h>
229#include <__tuple/tuple_size.h>
230#include <__tuple/tuple_types.h>
231#include <__type_traits/common_reference.h>
232#include <__type_traits/common_type.h>
233#include <__type_traits/conditional.h>
234#include <__type_traits/conjunction.h>
235#include <__type_traits/copy_cvref.h>
236#include <__type_traits/disjunction.h>
237#include <__type_traits/is_arithmetic.h>
238#include <__type_traits/is_assignable.h>
239#include <__type_traits/is_constructible.h>
240#include <__type_traits/is_convertible.h>
241#include <__type_traits/is_empty.h>
242#include <__type_traits/is_final.h>
243#include <__type_traits/is_implicitly_default_constructible.h>
244#include <__type_traits/is_nothrow_assignable.h>
245#include <__type_traits/is_nothrow_constructible.h>
246#include <__type_traits/is_reference.h>
247#include <__type_traits/is_same.h>
248#include <__type_traits/is_swappable.h>
249#include <__type_traits/is_trivially_relocatable.h>
250#include <__type_traits/lazy.h>
251#include <__type_traits/maybe_const.h>
252#include <__type_traits/nat.h>
253#include <__type_traits/negation.h>
254#include <__type_traits/remove_cvref.h>
255#include <__type_traits/remove_reference.h>
256#include <__type_traits/unwrap_ref.h>
257#include <__utility/forward.h>
258#include <__utility/integer_sequence.h>
259#include <__utility/move.h>
260#include <__utility/piecewise_construct.h>
261#include <__utility/swap.h>
262#include <cstddef>
263#include <version>
213#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
214# include <__cxx03/tuple>
215#else
216# include <__compare/common_comparison_category.h>
217# include <__compare/ordering.h>
218# include <__compare/synth_three_way.h>
219# include <__config>
220# include <__cstddef/size_t.h>
221# include <__fwd/array.h>
222# include <__fwd/pair.h>
223# include <__fwd/tuple.h>
224# include <__memory/allocator_arg_t.h>
225# include <__memory/uses_allocator.h>
226# include <__tuple/find_index.h>
227# include <__tuple/ignore.h>
228# include <__tuple/make_tuple_types.h>
229# include <__tuple/sfinae_helpers.h>
230# include <__tuple/tuple_element.h>
231# include <__tuple/tuple_indices.h>
232# include <__tuple/tuple_like_ext.h>
233# include <__tuple/tuple_size.h>
234# include <__tuple/tuple_types.h>
235# include <__type_traits/common_reference.h>
236# include <__type_traits/common_type.h>
237# include <__type_traits/conditional.h>
238# include <__type_traits/conjunction.h>
239# include <__type_traits/copy_cvref.h>
240# include <__type_traits/disjunction.h>
241# include <__type_traits/enable_if.h>
242# include <__type_traits/invoke.h>
243# include <__type_traits/is_arithmetic.h>
244# include <__type_traits/is_assignable.h>
245# include <__type_traits/is_constructible.h>
246# include <__type_traits/is_convertible.h>
247# include <__type_traits/is_empty.h>
248# include <__type_traits/is_final.h>
249# include <__type_traits/is_implicitly_default_constructible.h>
250# include <__type_traits/is_nothrow_assignable.h>
251# include <__type_traits/is_nothrow_constructible.h>
252# include <__type_traits/is_reference.h>
253# include <__type_traits/is_same.h>
254# include <__type_traits/is_swappable.h>
255# include <__type_traits/is_trivially_relocatable.h>
256# include <__type_traits/lazy.h>
257# include <__type_traits/maybe_const.h>
258# include <__type_traits/nat.h>
259# include <__type_traits/negation.h>
260# include <__type_traits/remove_cv.h>
261# include <__type_traits/remove_cvref.h>
262# include <__type_traits/remove_reference.h>
263# include <__type_traits/unwrap_ref.h>
264# include <__utility/declval.h>
265# include <__utility/forward.h>
266# include <__utility/integer_sequence.h>
267# include <__utility/move.h>
268# include <__utility/piecewise_construct.h>
269# include <__utility/swap.h>
270# include <version>
264271
265272// standard-mandated includes
266273
267274// [tuple.syn]
268#include <compare>
275# include <compare>
269276
270#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
271# pragma GCC system_header
272#endif
277# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
278# pragma GCC system_header
279# endif
273280
274281_LIBCPP_PUSH_MACROS
275#include <__undef_macros>
282# include <__undef_macros>
276283
277284_LIBCPP_BEGIN_NAMESPACE_STD
278285
279#ifndef _LIBCPP_CXX03_LANG
286# ifndef _LIBCPP_CXX03_LANG
280287
281288// __tuple_leaf
282289
......@@ -302,11 +309,11 @@ class __tuple_leaf {
302309
303310 template <class _Tp>
304311 static _LIBCPP_HIDE_FROM_ABI constexpr bool __can_bind_reference() {
305# if __has_keyword(__reference_binds_to_temporary)
312# if __has_keyword(__reference_binds_to_temporary)
306313 return !__reference_binds_to_temporary(_Hp, _Tp);
307# else
314# else
308315 return true;
309# endif
316# endif
310317 }
311318
312319public:
......@@ -384,7 +391,7 @@ public:
384391};
385392
386393template <size_t _Ip, class _Hp>
387class __tuple_leaf<_Ip, _Hp, true> : private _Hp {
394class __tuple_leaf<_Ip, _Hp, true> : private __remove_cv_t<_Hp> {
388395public:
389396 _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_leaf& operator=(const __tuple_leaf&) = delete;
390397
......@@ -546,7 +553,8 @@ class _LIBCPP_TEMPLATE_VIS tuple {
546553 get(const tuple<_Up...>&&) _NOEXCEPT;
547554
548555public:
549 using __trivially_relocatable = __conditional_t<_And<__libcpp_is_trivially_relocatable<_Tp>...>::value, tuple, void>;
556 using __trivially_relocatable _LIBCPP_NODEBUG =
557 __conditional_t<_And<__libcpp_is_trivially_relocatable<_Tp>...>::value, tuple, void>;
550558
551559 // [tuple.cnstr]
552560
......@@ -690,7 +698,7 @@ public:
690698 tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t)
691699 : __base_(allocator_arg_t(), __a, __t) {}
692700
693# if _LIBCPP_STD_VER >= 23
701# if _LIBCPP_STD_VER >= 23
694702 // tuple(tuple<U...>&) constructors (including allocator_arg_t variants)
695703
696704 template <class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
......@@ -701,7 +709,7 @@ public:
701709 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<_Up&, _Tp>...>::value)
702710 tuple(allocator_arg_t, const _Alloc& __alloc, tuple<_Up...>& __t)
703711 : __base_(allocator_arg_t(), __alloc, __t) {}
704# endif // _LIBCPP_STD_VER >= 23
712# endif // _LIBCPP_STD_VER >= 23
705713
706714 // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants)
707715 template <class... _Up, __enable_if_t< _And< _EnableCtorFromUTypesTuple<tuple<_Up...>&&> >::value, int> = 0>
......@@ -716,7 +724,7 @@ public:
716724 tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t)
717725 : __base_(allocator_arg_t(), __a, std::move(__t)) {}
718726
719# if _LIBCPP_STD_VER >= 23
727# if _LIBCPP_STD_VER >= 23
720728 // tuple(const tuple<U...>&&) constructors (including allocator_arg_t variants)
721729
722730 template <class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
......@@ -730,7 +738,7 @@ public:
730738 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<const _Up&&, _Tp>...>::value)
731739 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple<_Up...>&& __t)
732740 : __base_(allocator_arg_t(), __alloc, std::move(__t)) {}
733# endif // _LIBCPP_STD_VER >= 23
741# endif // _LIBCPP_STD_VER >= 23
734742
735743 // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants)
736744
......@@ -776,7 +784,7 @@ public:
776784 tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p)
777785 : __base_(allocator_arg_t(), __a, __p) {}
778786
779# if _LIBCPP_STD_VER >= 23
787# if _LIBCPP_STD_VER >= 23
780788 // tuple(pair<U1, U2>&) constructors (including allocator_arg_t variants)
781789
782790 template <class _U1, class _U2, enable_if_t< _EnableCtorFromPair<pair<_U1, _U2>&>::value>* = nullptr>
......@@ -791,7 +799,7 @@ public:
791799 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value)
792800 tuple(allocator_arg_t, const _Alloc& __alloc, pair<_U1, _U2>& __p)
793801 : __base_(allocator_arg_t(), __alloc, __p) {}
794# endif
802# endif
795803
796804 // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants)
797805
......@@ -814,7 +822,7 @@ public:
814822 tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p)
815823 : __base_(allocator_arg_t(), __a, std::move(__p)) {}
816824
817# if _LIBCPP_STD_VER >= 23
825# if _LIBCPP_STD_VER >= 23
818826 // tuple(const pair<U1, U2>&&) constructors (including allocator_arg_t variants)
819827
820828 template <class _U1, class _U2, enable_if_t< _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr>
......@@ -829,17 +837,17 @@ public:
829837 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value)
830838 tuple(allocator_arg_t, const _Alloc& __alloc, const pair<_U1, _U2>&& __p)
831839 : __base_(allocator_arg_t(), __alloc, std::move(__p)) {}
832# endif // _LIBCPP_STD_VER >= 23
840# endif // _LIBCPP_STD_VER >= 23
833841
834842 // [tuple.assign]
835843 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
836 operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple)
837 noexcept(_And<is_nothrow_copy_assignable<_Tp>...>::value) {
844 operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple) noexcept(
845 _And<is_nothrow_copy_assignable<_Tp>...>::value) {
838846 std::__memberwise_copy_assign(*this, __tuple, typename __make_tuple_indices<sizeof...(_Tp)>::type());
839847 return *this;
840848 }
841849
842# if _LIBCPP_STD_VER >= 23
850# if _LIBCPP_STD_VER >= 23
843851 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple const& __tuple) const
844852 requires(_And<is_copy_assignable<const _Tp>...>::value)
845853 {
......@@ -854,11 +862,11 @@ public:
854862 *this, std::move(__tuple), __tuple_types<_Tp...>(), typename __make_tuple_indices<sizeof...(_Tp)>::type());
855863 return *this;
856864 }
857# endif // _LIBCPP_STD_VER >= 23
865# endif // _LIBCPP_STD_VER >= 23
858866
859867 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
860 operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple)
861 noexcept(_And<is_nothrow_move_assignable<_Tp>...>::value) {
868 operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple) noexcept(
869 _And<is_nothrow_move_assignable<_Tp>...>::value) {
862870 std::__memberwise_forward_assign(
863871 *this, std::move(__tuple), __tuple_types<_Tp...>(), typename __make_tuple_indices<sizeof...(_Tp)>::type());
864872 return *this;
......@@ -868,8 +876,8 @@ public:
868876 class... _Up,
869877 __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>, is_assignable<_Tp&, _Up const&>... >::value,
870878 int> = 0>
871 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(tuple<_Up...> const& __tuple)
872 noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) {
879 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
880 operator=(tuple<_Up...> const& __tuple) noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) {
873881 std::__memberwise_copy_assign(*this, __tuple, typename __make_tuple_indices<sizeof...(_Tp)>::type());
874882 return *this;
875883 }
......@@ -877,14 +885,14 @@ public:
877885 template <class... _Up,
878886 __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>, is_assignable<_Tp&, _Up>... >::value,
879887 int> = 0>
880 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(tuple<_Up...>&& __tuple)
881 noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {
888 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
889 operator=(tuple<_Up...>&& __tuple) noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {
882890 std::__memberwise_forward_assign(
883891 *this, std::move(__tuple), __tuple_types<_Up...>(), typename __make_tuple_indices<sizeof...(_Tp)>::type());
884892 return *this;
885893 }
886894
887# if _LIBCPP_STD_VER >= 23
895# if _LIBCPP_STD_VER >= 23
888896 template <class... _UTypes,
889897 enable_if_t< _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>,
890898 is_assignable<const _Tp&, const _UTypes&>...>::value>* = nullptr>
......@@ -901,7 +909,7 @@ public:
901909 *this, __u, __tuple_types<_UTypes...>(), typename __make_tuple_indices<sizeof...(_Tp)>::type());
902910 return *this;
903911 }
904# endif // _LIBCPP_STD_VER >= 23
912# endif // _LIBCPP_STD_VER >= 23
905913
906914 template <template <class...> class _Pred,
907915 bool _Const,
......@@ -921,7 +929,7 @@ public:
921929 template <bool _Const, class _Pair>
922930 struct _NothrowAssignFromPair : _AssignPredicateFromPair<is_nothrow_assignable, _Const, _Pair> {};
923931
924# if _LIBCPP_STD_VER >= 23
932# if _LIBCPP_STD_VER >= 23
925933 template <class _U1, class _U2, enable_if_t< _EnableAssignFromPair<true, const pair<_U1, _U2>&>::value>* = nullptr>
926934 _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(const pair<_U1, _U2>& __pair) const
927935 noexcept(_NothrowAssignFromPair<true, const pair<_U1, _U2>&>::value) {
......@@ -937,21 +945,21 @@ public:
937945 std::get<1>(*this) = std::move(__pair.second);
938946 return *this;
939947 }
940# endif // _LIBCPP_STD_VER >= 23
948# endif // _LIBCPP_STD_VER >= 23
941949
942950 template <class _Up1,
943951 class _Up2,
944952 __enable_if_t< _EnableAssignFromPair<false, pair<_Up1, _Up2> const&>::value, int> = 0>
945 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(pair<_Up1, _Up2> const& __pair)
946 noexcept(_NothrowAssignFromPair<false, pair<_Up1, _Up2> const&>::value) {
953 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
954 operator=(pair<_Up1, _Up2> const& __pair) noexcept(_NothrowAssignFromPair<false, pair<_Up1, _Up2> const&>::value) {
947955 std::get<0>(*this) = __pair.first;
948956 std::get<1>(*this) = __pair.second;
949957 return *this;
950958 }
951959
952960 template <class _Up1, class _Up2, __enable_if_t< _EnableAssignFromPair<false, pair<_Up1, _Up2>&&>::value, int> = 0>
953 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(pair<_Up1, _Up2>&& __pair)
954 noexcept(_NothrowAssignFromPair<false, pair<_Up1, _Up2>&&>::value) {
961 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
962 operator=(pair<_Up1, _Up2>&& __pair) noexcept(_NothrowAssignFromPair<false, pair<_Up1, _Up2>&&>::value) {
955963 std::get<0>(*this) = std::forward<_Up1>(__pair.first);
956964 std::get<1>(*this) = std::forward<_Up2>(__pair.second);
957965 return *this;
......@@ -962,8 +970,8 @@ public:
962970 class _Up,
963971 size_t _Np,
964972 __enable_if_t< _And< _BoolConstant<_Np == sizeof...(_Tp)>, is_assignable<_Tp&, _Up const&>... >::value, int> = 0>
965 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(array<_Up, _Np> const& __array)
966 noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) {
973 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
974 operator=(array<_Up, _Np> const& __array) noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) {
967975 std::__memberwise_copy_assign(*this, __array, typename __make_tuple_indices<sizeof...(_Tp)>::type());
968976 return *this;
969977 }
......@@ -973,8 +981,8 @@ public:
973981 size_t _Np,
974982 class = void,
975983 __enable_if_t< _And< _BoolConstant<_Np == sizeof...(_Tp)>, is_assignable<_Tp&, _Up>... >::value, int> = 0>
976 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(array<_Up, _Np>&& __array)
977 noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {
984 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple&
985 operator=(array<_Up, _Np>&& __array) noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) {
978986 std::__memberwise_forward_assign(
979987 *this,
980988 std::move(__array),
......@@ -984,17 +992,17 @@ public:
984992 }
985993
986994 // [tuple.swap]
987 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(tuple& __t)
988 noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {
995 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
996 swap(tuple& __t) noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {
989997 __base_.swap(__t.__base_);
990998 }
991999
992# if _LIBCPP_STD_VER >= 23
1000# if _LIBCPP_STD_VER >= 23
9931001 _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple& __t) const
9941002 noexcept(__all<is_nothrow_swappable_v<const _Tp&>...>::value) {
9951003 __base_.swap(__t.__base_);
9961004 }
997# endif // _LIBCPP_STD_VER >= 23
1005# endif // _LIBCPP_STD_VER >= 23
9981006};
9991007
10001008template <>
......@@ -1010,12 +1018,12 @@ public:
10101018 template <class _Alloc, class _Up>
10111019 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
10121020 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(tuple&) _NOEXCEPT {}
1013# if _LIBCPP_STD_VER >= 23
1021# if _LIBCPP_STD_VER >= 23
10141022 _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple&) const noexcept {}
1015# endif
1023# endif
10161024};
10171025
1018# if _LIBCPP_STD_VER >= 23
1026# if _LIBCPP_STD_VER >= 23
10191027template <class... _TTypes, class... _UTypes, template <class> class _TQual, template <class> class _UQual>
10201028 requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
10211029struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
......@@ -1027,9 +1035,9 @@ template <class... _TTypes, class... _UTypes>
10271035struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
10281036 using type = tuple<common_type_t<_TTypes, _UTypes>...>;
10291037};
1030# endif // _LIBCPP_STD_VER >= 23
1038# endif // _LIBCPP_STD_VER >= 23
10311039
1032# if _LIBCPP_STD_VER >= 17
1040# if _LIBCPP_STD_VER >= 17
10331041template <class... _Tp>
10341042tuple(_Tp...) -> tuple<_Tp...>;
10351043template <class _Tp1, class _Tp2>
......@@ -1040,54 +1048,54 @@ template <class _Alloc, class _Tp1, class _Tp2>
10401048tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
10411049template <class _Alloc, class... _Tp>
10421050tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
1043# endif
1051# endif
10441052
10451053template <class... _Tp, __enable_if_t<__all<__is_swappable_v<_Tp>...>::value, int> = 0>
1046inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
1047 noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {
1054inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
1055swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) {
10481056 __t.swap(__u);
10491057}
10501058
1051# if _LIBCPP_STD_VER >= 23
1059# if _LIBCPP_STD_VER >= 23
10521060template <class... _Tp>
10531061_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<__all<is_swappable_v<const _Tp>...>::value, void>
10541062swap(const tuple<_Tp...>& __lhs,
10551063 const tuple<_Tp...>& __rhs) noexcept(__all<is_nothrow_swappable_v<const _Tp>...>::value) {
10561064 __lhs.swap(__rhs);
10571065}
1058# endif
1066# endif
10591067
10601068// get
10611069
10621070template <size_t _Ip, class... _Tp>
10631071inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Ip, tuple<_Tp...> >::type&
10641072get(tuple<_Tp...>& __t) _NOEXCEPT {
1065 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
1073 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;
10661074 return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
10671075}
10681076
10691077template <size_t _Ip, class... _Tp>
10701078inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, tuple<_Tp...> >::type&
10711079get(const tuple<_Tp...>& __t) _NOEXCEPT {
1072 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
1080 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;
10731081 return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
10741082}
10751083
10761084template <size_t _Ip, class... _Tp>
10771085inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Ip, tuple<_Tp...> >::type&&
10781086get(tuple<_Tp...>&& __t) _NOEXCEPT {
1079 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
1087 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;
10801088 return static_cast<type&&>(static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
10811089}
10821090
10831091template <size_t _Ip, class... _Tp>
10841092inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
10851093get(const tuple<_Tp...>&& __t) _NOEXCEPT {
1086 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type;
1094 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, tuple<_Tp...> >::type;
10871095 return static_cast<const type&&>(static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
10881096}
10891097
1090# if _LIBCPP_STD_VER >= 14
1098# if _LIBCPP_STD_VER >= 14
10911099
10921100template <class _T1, class... _Args>
10931101inline _LIBCPP_HIDE_FROM_ABI constexpr _T1& get(tuple<_Args...>& __tup) noexcept {
......@@ -1109,7 +1117,7 @@ inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const&& get(tuple<_Args...> const&& _
11091117 return std::get<__find_exactly_one_t<_T1, _Args...>::value>(std::move(__tup));
11101118}
11111119
1112# endif
1120# endif
11131121
11141122// tie
11151123
......@@ -1119,9 +1127,9 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<_Tp&...> tie(_T
11191127}
11201128
11211129template <class... _Tp>
1122inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<typename __unwrap_ref_decay<_Tp>::type...>
1130inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<__unwrap_ref_decay_t<_Tp>...>
11231131make_tuple(_Tp&&... __t) {
1124 return tuple<typename __unwrap_ref_decay<_Tp>::type...>(std::forward<_Tp>(__t)...);
1132 return tuple<__unwrap_ref_decay_t<_Tp>...>(std::forward<_Tp>(__t)...);
11251133}
11261134
11271135template <class... _Tp>
......@@ -1152,7 +1160,7 @@ operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
11521160 return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
11531161}
11541162
1155# if _LIBCPP_STD_VER >= 20
1163# if _LIBCPP_STD_VER >= 20
11561164
11571165// operator<=>
11581166
......@@ -1172,7 +1180,7 @@ operator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
11721180 return std::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{});
11731181}
11741182
1175# else // _LIBCPP_STD_VER >= 20
1183# else // _LIBCPP_STD_VER >= 20
11761184
11771185template <class... _Tp, class... _Up>
11781186inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
......@@ -1226,7 +1234,7 @@ operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
12261234 return !(__y < __x);
12271235}
12281236
1229# endif // _LIBCPP_STD_VER >= 20
1237# endif // _LIBCPP_STD_VER >= 20
12301238
12311239// tuple_cat
12321240
......@@ -1235,7 +1243,7 @@ struct __tuple_cat_type;
12351243
12361244template <class... _Ttypes, class... _Utypes>
12371245struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> > {
1238 typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type;
1246 using type _LIBCPP_NODEBUG = tuple<_Ttypes..., _Utypes...>;
12391247};
12401248
12411249template <class _ResultTuple, bool _Is_Tuple0TupleLike, class... _Tuples>
......@@ -1269,7 +1277,7 @@ struct __tuple_cat_return<_Tuple0, _Tuples...>
12691277
12701278template <>
12711279struct __tuple_cat_return<> {
1272 typedef _LIBCPP_NODEBUG tuple<> type;
1280 using type _LIBCPP_NODEBUG = tuple<>;
12731281};
12741282
12751283inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<> tuple_cat() { return tuple<>(); }
......@@ -1279,7 +1287,7 @@ struct __tuple_cat_return_ref_imp;
12791287
12801288template <class... _Types, size_t... _I0, class _Tuple0>
12811289struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0> {
1282 typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple0> _T0;
1290 using _T0 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple0>;
12831291 typedef tuple<_Types..., __copy_cvref_t<_Tuple0, typename tuple_element<_I0, _T0>::type>&&...> type;
12841292};
12851293
......@@ -1319,8 +1327,8 @@ struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J
13191327 typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
13201328 operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&&... __tpls) {
13211329 (void)__t; // avoid unused parameter warning on GCC when _I0 is empty
1322 typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple0> _T0;
1323 typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple1> _T1;
1330 using _T0 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple0>;
1331 using _T1 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple1>;
13241332 return __tuple_cat<tuple<_Types..., __copy_cvref_t<_Tuple0, typename tuple_element<_J0, _T0>::type>&&...>,
13251333 typename __make_tuple_indices<sizeof...(_Types) + tuple_size<_T0>::value>::type,
13261334 typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
......@@ -1331,20 +1339,33 @@ struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J
13311339 }
13321340};
13331341
1342template <class _TupleDst, class _TupleSrc, size_t... _Indices>
1343inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _TupleDst
1344__tuple_cat_select_element_wise(_TupleSrc&& __src, __tuple_indices<_Indices...>) {
1345 static_assert(tuple_size<_TupleDst>::value == tuple_size<_TupleSrc>::value,
1346 "misuse of __tuple_cat_select_element_wise with tuples of different sizes");
1347 return _TupleDst(std::get<_Indices>(std::forward<_TupleSrc>(__src))...);
1348}
1349
13341350template <class _Tuple0, class... _Tuples>
13351351inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename __tuple_cat_return<_Tuple0, _Tuples...>::type
13361352tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) {
1337 typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple0> _T0;
1338 return __tuple_cat<tuple<>, __tuple_indices<>, typename __make_tuple_indices<tuple_size<_T0>::value>::type>()(
1339 tuple<>(), std::forward<_Tuple0>(__t0), std::forward<_Tuples>(__tpls)...);
1353 using _T0 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple0>;
1354 using _TRet _LIBCPP_NODEBUG = typename __tuple_cat_return<_Tuple0, _Tuples...>::type;
1355 using _T0Indices _LIBCPP_NODEBUG = typename __make_tuple_indices<tuple_size<_T0>::value>::type;
1356 using _TRetIndices _LIBCPP_NODEBUG = typename __make_tuple_indices<tuple_size<_TRet>::value>::type;
1357 return std::__tuple_cat_select_element_wise<_TRet>(
1358 __tuple_cat<tuple<>, __tuple_indices<>, _T0Indices>()(
1359 tuple<>(), std::forward<_Tuple0>(__t0), std::forward<_Tuples>(__tpls)...),
1360 _TRetIndices());
13401361}
13411362
13421363template <class... _Tp, class _Alloc>
13431364struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc> : true_type {};
13441365
1345# if _LIBCPP_STD_VER >= 17
1346# define _LIBCPP_NOEXCEPT_RETURN(...) \
1347 noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
1366# if _LIBCPP_STD_VER >= 17
1367# define _LIBCPP_NOEXCEPT_RETURN(...) \
1368 noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
13481369
13491370// The _LIBCPP_NOEXCEPT_RETURN macro breaks formatting.
13501371// clang-format off
......@@ -1407,13 +1428,15 @@ _LIBCPP_POP_MACROS
14071428
14081429// clang-format on
14091430
1410#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1411# include <exception>
1412# include <iosfwd>
1413# include <new>
1414# include <type_traits>
1415# include <typeinfo>
1416# include <utility>
1417#endif
1431# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1432# include <cstddef>
1433# include <exception>
1434# include <iosfwd>
1435# include <new>
1436# include <type_traits>
1437# include <typeinfo>
1438# include <utility>
1439# endif
1440#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
14181441
14191442#endif // _LIBCPP_TUPLE
lib/libcxx/include/type_traits+114-102
......@@ -137,6 +137,8 @@ namespace std
137137 template <class T> struct is_nothrow_swappable; // C++17
138138 template <class T> struct is_nothrow_destructible;
139139
140 template<class T> struct is_implicit_lifetime; // Since C++23
141
140142 template <class T> struct has_virtual_destructor;
141143
142144 template<class T> struct has_unique_object_representations; // C++17
......@@ -144,6 +146,7 @@ namespace std
144146 // Relationships between types:
145147 template <class T, class U> struct is_same;
146148 template <class Base, class Derived> struct is_base_of;
149 template <class Base, class Derived> struct is_virtual_base_of; // C++26
147150
148151 template <class From, class To> struct is_convertible;
149152 template <typename From, typename To> struct is_nothrow_convertible; // C++20
......@@ -373,6 +376,8 @@ namespace std
373376 = is_nothrow_swappable<T>::value; // C++17
374377 template <class T> inline constexpr bool is_nothrow_destructible_v
375378 = is_nothrow_destructible<T>::value; // C++17
379 template<class T>
380 constexpr bool is_implicit_lifetime_v = is_implicit_lifetime<T>::value; // Since C++23
376381 template <class T> inline constexpr bool has_virtual_destructor_v
377382 = has_virtual_destructor<T>::value; // C++17
378383 template<class T> inline constexpr bool has_unique_object_representations_v // C++17
......@@ -391,6 +396,8 @@ namespace std
391396 = is_same<T, U>::value; // C++17
392397 template <class Base, class Derived> inline constexpr bool is_base_of_v
393398 = is_base_of<Base, Derived>::value; // C++17
399 template <class Base, class Derived> inline constexpr bool is_virtual_base_of_v
400 = is_virtual_base_of<Base, Derived>::value; // C++26
394401 template <class From, class To> inline constexpr bool is_convertible_v
395402 = is_convertible<From, To>::value; // C++17
396403 template <class Fn, class... ArgTypes> inline constexpr bool is_invocable_v
......@@ -417,107 +424,112 @@ namespace std
417424
418425*/
419426
420#include <__config>
421#include <__fwd/functional.h> // This is https://llvm.org/PR56938
422#include <__type_traits/add_const.h>
423#include <__type_traits/add_cv.h>
424#include <__type_traits/add_lvalue_reference.h>
425#include <__type_traits/add_pointer.h>
426#include <__type_traits/add_rvalue_reference.h>
427#include <__type_traits/add_volatile.h>
428#include <__type_traits/aligned_storage.h>
429#include <__type_traits/aligned_union.h>
430#include <__type_traits/alignment_of.h>
431#include <__type_traits/common_type.h>
432#include <__type_traits/conditional.h>
433#include <__type_traits/decay.h>
434#include <__type_traits/enable_if.h>
435#include <__type_traits/extent.h>
436#include <__type_traits/has_virtual_destructor.h>
437#include <__type_traits/integral_constant.h>
438#include <__type_traits/is_abstract.h>
439#include <__type_traits/is_arithmetic.h>
440#include <__type_traits/is_array.h>
441#include <__type_traits/is_assignable.h>
442#include <__type_traits/is_base_of.h>
443#include <__type_traits/is_class.h>
444#include <__type_traits/is_compound.h>
445#include <__type_traits/is_const.h>
446#include <__type_traits/is_constructible.h>
447#include <__type_traits/is_convertible.h>
448#include <__type_traits/is_destructible.h>
449#include <__type_traits/is_empty.h>
450#include <__type_traits/is_enum.h>
451#include <__type_traits/is_floating_point.h>
452#include <__type_traits/is_function.h>
453#include <__type_traits/is_fundamental.h>
454#include <__type_traits/is_integral.h>
455#include <__type_traits/is_literal_type.h>
456#include <__type_traits/is_member_pointer.h>
457#include <__type_traits/is_nothrow_assignable.h>
458#include <__type_traits/is_nothrow_constructible.h>
459#include <__type_traits/is_nothrow_destructible.h>
460#include <__type_traits/is_object.h>
461#include <__type_traits/is_pod.h>
462#include <__type_traits/is_pointer.h>
463#include <__type_traits/is_polymorphic.h>
464#include <__type_traits/is_reference.h>
465#include <__type_traits/is_same.h>
466#include <__type_traits/is_scalar.h>
467#include <__type_traits/is_signed.h>
468#include <__type_traits/is_standard_layout.h>
469#include <__type_traits/is_trivial.h>
470#include <__type_traits/is_trivially_assignable.h>
471#include <__type_traits/is_trivially_constructible.h>
472#include <__type_traits/is_trivially_copyable.h>
473#include <__type_traits/is_trivially_destructible.h>
474#include <__type_traits/is_union.h>
475#include <__type_traits/is_unsigned.h>
476#include <__type_traits/is_void.h>
477#include <__type_traits/is_volatile.h>
478#include <__type_traits/make_signed.h>
479#include <__type_traits/make_unsigned.h>
480#include <__type_traits/rank.h>
481#include <__type_traits/remove_all_extents.h>
482#include <__type_traits/remove_const.h>
483#include <__type_traits/remove_cv.h>
484#include <__type_traits/remove_extent.h>
485#include <__type_traits/remove_pointer.h>
486#include <__type_traits/remove_reference.h>
487#include <__type_traits/remove_volatile.h>
488#include <__type_traits/result_of.h>
489#include <__type_traits/underlying_type.h>
490
491#if _LIBCPP_STD_VER >= 14
492# include <__type_traits/is_final.h>
493# include <__type_traits/is_null_pointer.h>
494#endif
495
496#if _LIBCPP_STD_VER >= 17
497# include <__type_traits/conjunction.h>
498# include <__type_traits/disjunction.h>
499# include <__type_traits/has_unique_object_representation.h>
500# include <__type_traits/invoke.h>
501# include <__type_traits/is_aggregate.h>
502# include <__type_traits/is_swappable.h>
503# include <__type_traits/negation.h>
504# include <__type_traits/void_t.h>
505#endif
506
507#if _LIBCPP_STD_VER >= 20
508# include <__type_traits/common_reference.h>
509# include <__type_traits/is_bounded_array.h>
510# include <__type_traits/is_constant_evaluated.h>
511# include <__type_traits/is_nothrow_convertible.h>
512# include <__type_traits/is_unbounded_array.h>
513# include <__type_traits/type_identity.h>
514# include <__type_traits/unwrap_ref.h>
515#endif
516
517#include <version>
518
519#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
520# pragma GCC system_header
521#endif
427#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
428# include <__cxx03/type_traits>
429#else
430# include <__config>
431# include <__type_traits/add_cv_quals.h>
432# include <__type_traits/add_lvalue_reference.h>
433# include <__type_traits/add_pointer.h>
434# include <__type_traits/add_rvalue_reference.h>
435# include <__type_traits/aligned_storage.h>
436# include <__type_traits/aligned_union.h>
437# include <__type_traits/alignment_of.h>
438# include <__type_traits/common_type.h>
439# include <__type_traits/conditional.h>
440# include <__type_traits/decay.h>
441# include <__type_traits/enable_if.h>
442# include <__type_traits/extent.h>
443# include <__type_traits/has_virtual_destructor.h>
444# include <__type_traits/integral_constant.h>
445# include <__type_traits/is_abstract.h>
446# include <__type_traits/is_arithmetic.h>
447# include <__type_traits/is_array.h>
448# include <__type_traits/is_assignable.h>
449# include <__type_traits/is_base_of.h>
450# include <__type_traits/is_class.h>
451# include <__type_traits/is_compound.h>
452# include <__type_traits/is_const.h>
453# include <__type_traits/is_constructible.h>
454# include <__type_traits/is_convertible.h>
455# include <__type_traits/is_destructible.h>
456# include <__type_traits/is_empty.h>
457# include <__type_traits/is_enum.h>
458# include <__type_traits/is_floating_point.h>
459# include <__type_traits/is_function.h>
460# include <__type_traits/is_fundamental.h>
461# include <__type_traits/is_integral.h>
462# include <__type_traits/is_literal_type.h>
463# include <__type_traits/is_member_pointer.h>
464# include <__type_traits/is_nothrow_assignable.h>
465# include <__type_traits/is_nothrow_constructible.h>
466# include <__type_traits/is_nothrow_destructible.h>
467# include <__type_traits/is_object.h>
468# include <__type_traits/is_pod.h>
469# include <__type_traits/is_pointer.h>
470# include <__type_traits/is_polymorphic.h>
471# include <__type_traits/is_reference.h>
472# include <__type_traits/is_same.h>
473# include <__type_traits/is_scalar.h>
474# include <__type_traits/is_signed.h>
475# include <__type_traits/is_standard_layout.h>
476# include <__type_traits/is_trivial.h>
477# include <__type_traits/is_trivially_assignable.h>
478# include <__type_traits/is_trivially_constructible.h>
479# include <__type_traits/is_trivially_copyable.h>
480# include <__type_traits/is_trivially_destructible.h>
481# include <__type_traits/is_union.h>
482# include <__type_traits/is_unsigned.h>
483# include <__type_traits/is_void.h>
484# include <__type_traits/is_volatile.h>
485# include <__type_traits/make_signed.h>
486# include <__type_traits/make_unsigned.h>
487# include <__type_traits/rank.h>
488# include <__type_traits/remove_all_extents.h>
489# include <__type_traits/remove_const.h>
490# include <__type_traits/remove_cv.h>
491# include <__type_traits/remove_extent.h>
492# include <__type_traits/remove_pointer.h>
493# include <__type_traits/remove_reference.h>
494# include <__type_traits/remove_volatile.h>
495# include <__type_traits/result_of.h>
496# include <__type_traits/underlying_type.h>
497
498# if _LIBCPP_STD_VER >= 14
499# include <__type_traits/is_final.h>
500# include <__type_traits/is_null_pointer.h>
501# endif
502
503# if _LIBCPP_STD_VER >= 17
504# include <__type_traits/conjunction.h>
505# include <__type_traits/disjunction.h>
506# include <__type_traits/has_unique_object_representation.h>
507# include <__type_traits/invoke.h>
508# include <__type_traits/is_aggregate.h>
509# include <__type_traits/is_swappable.h>
510# include <__type_traits/negation.h>
511# include <__type_traits/void_t.h>
512# endif
513
514# if _LIBCPP_STD_VER >= 20
515# include <__type_traits/common_reference.h>
516# include <__type_traits/is_bounded_array.h>
517# include <__type_traits/is_constant_evaluated.h>
518# include <__type_traits/is_nothrow_convertible.h>
519# include <__type_traits/is_unbounded_array.h>
520# include <__type_traits/type_identity.h>
521# include <__type_traits/unwrap_ref.h>
522# endif
523
524# if _LIBCPP_STD_VER >= 23
525# include <__type_traits/is_implicit_lifetime.h>
526# endif
527
528# include <version>
529
530# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
531# pragma GCC system_header
532# endif
533#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
522534
523535#endif // _LIBCPP_TYPE_TRAITS
lib/libcxx/include/typeindex+22-17
......@@ -45,17 +45,20 @@ struct hash<type_index>
4545
4646*/
4747
48#include <__config>
49#include <__functional/unary_function.h>
50#include <typeinfo>
51#include <version>
48#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
49# include <__cxx03/typeindex>
50#else
51# include <__config>
52# include <__functional/unary_function.h>
53# include <typeinfo>
54# include <version>
5255
5356// standard-mandated includes
54#include <compare>
57# include <compare>
5558
56#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
57# pragma GCC system_header
58#endif
59# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
60# pragma GCC system_header
61# endif
5962
6063_LIBCPP_BEGIN_NAMESPACE_STD
6164
......@@ -66,14 +69,14 @@ public:
6669 _LIBCPP_HIDE_FROM_ABI type_index(const type_info& __y) _NOEXCEPT : __t_(&__y) {}
6770
6871 _LIBCPP_HIDE_FROM_ABI bool operator==(const type_index& __y) const _NOEXCEPT { return *__t_ == *__y.__t_; }
69#if _LIBCPP_STD_VER <= 17
72# if _LIBCPP_STD_VER <= 17
7073 _LIBCPP_HIDE_FROM_ABI bool operator!=(const type_index& __y) const _NOEXCEPT { return *__t_ != *__y.__t_; }
71#endif
74# endif
7275 _LIBCPP_HIDE_FROM_ABI bool operator<(const type_index& __y) const _NOEXCEPT { return __t_->before(*__y.__t_); }
7376 _LIBCPP_HIDE_FROM_ABI bool operator<=(const type_index& __y) const _NOEXCEPT { return !__y.__t_->before(*__t_); }
7477 _LIBCPP_HIDE_FROM_ABI bool operator>(const type_index& __y) const _NOEXCEPT { return __y.__t_->before(*__t_); }
7578 _LIBCPP_HIDE_FROM_ABI bool operator>=(const type_index& __y) const _NOEXCEPT { return !__t_->before(*__y.__t_); }
76#if _LIBCPP_STD_VER >= 20
79# if _LIBCPP_STD_VER >= 20
7780 _LIBCPP_HIDE_FROM_ABI strong_ordering operator<=>(const type_index& __y) const noexcept {
7881 if (*__t_ == *__y.__t_)
7982 return strong_ordering::equal;
......@@ -81,7 +84,7 @@ public:
8184 return strong_ordering::less;
8285 return strong_ordering::greater;
8386 }
84#endif
87# endif
8588
8689 _LIBCPP_HIDE_FROM_ABI size_t hash_code() const _NOEXCEPT { return __t_->hash_code(); }
8790 _LIBCPP_HIDE_FROM_ABI const char* name() const _NOEXCEPT { return __t_->name(); }
......@@ -97,10 +100,12 @@ struct _LIBCPP_TEMPLATE_VIS hash<type_index> : public __unary_function<type_inde
97100
98101_LIBCPP_END_NAMESPACE_STD
99102
100#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
101# include <iosfwd>
102# include <new>
103# include <utility>
104#endif
103# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
104# include <cstddef>
105# include <iosfwd>
106# include <new>
107# include <utility>
108# endif
109#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
105110
106111#endif // _LIBCPP_TYPEINDEX
lib/libcxx/include/typeinfo+62-55
......@@ -56,25 +56,30 @@ public:
5656
5757*/
5858
59#include <__config>
60#include <__exception/exception.h>
61#include <__type_traits/is_constant_evaluated.h>
62#include <__verbose_abort>
63#include <cstddef>
64#include <cstdint>
65
66#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
67# pragma GCC system_header
68#endif
69
70#if defined(_LIBCPP_ABI_VCRUNTIME)
71# include <vcruntime_typeinfo.h>
59#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
60# include <__cxx03/typeinfo>
7261#else
62# include <__config>
63# include <__cstddef/size_t.h>
64# include <__exception/exception.h>
65# include <__type_traits/integral_constant.h>
66# include <__type_traits/is_constant_evaluated.h>
67# include <__verbose_abort>
68# include <cstdint>
69# include <version>
70
71# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
72# pragma GCC system_header
73# endif
74
75# if defined(_LIBCPP_ABI_VCRUNTIME)
76# include <vcruntime_typeinfo.h>
77# else
7378
7479namespace std // purposefully not using versioning namespace
7580{
7681
77# if defined(_LIBCPP_ABI_MICROSOFT)
82# if defined(_LIBCPP_ABI_MICROSOFT)
7883
7984class _LIBCPP_EXPORTED_FROM_ABI type_info {
8085 type_info& operator=(const type_info&);
......@@ -105,12 +110,12 @@ public:
105110 return __compare(__arg) == 0;
106111 }
107112
108# if _LIBCPP_STD_VER <= 17
113# if _LIBCPP_STD_VER <= 17
109114 _LIBCPP_HIDE_FROM_ABI bool operator!=(const type_info& __arg) const _NOEXCEPT { return !operator==(__arg); }
110# endif
115# endif
111116};
112117
113# else // !defined(_LIBCPP_ABI_MICROSOFT)
118# else // !defined(_LIBCPP_ABI_MICROSOFT)
114119
115120// ========================================================================== //
116121// Implementations
......@@ -165,21 +170,21 @@ public:
165170
166171// This value can be overriden in the __config_site. When it's not overriden,
167172// we pick a default implementation based on the platform here.
168# ifndef _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION
173# ifndef _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION
169174
170175// Windows and AIX binaries can't merge typeinfos, so use the NonUnique implementation.
171# if defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF)
172# define _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION 2
176# if defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF)
177# define _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION 2
173178
174179// On arm64 on Apple platforms, use the special NonUniqueARMRTTIBit implementation.
175# elif defined(__APPLE__) && defined(__LP64__) && !defined(__x86_64__)
176# define _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION 3
180# elif defined(__APPLE__) && defined(__LP64__) && !defined(__x86_64__)
181# define _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION 3
177182
178183// On all other platforms, assume the Itanium C++ ABI and use the Unique implementation.
179# else
180# define _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION 1
184# else
185# define _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION 1
186# endif
181187# endif
182# endif
183188
184189struct __type_info_implementations {
185190 struct __string_impl_base {
......@@ -263,30 +268,30 @@ struct __type_info_implementations {
263268 };
264269
265270 typedef
266# if _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION == 1
271# if _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION == 1
267272 __unique_impl
268# elif _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION == 2
273# elif _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION == 2
269274 __non_unique_impl
270# elif _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION == 3
275# elif _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION == 3
271276 __non_unique_arm_rtti_bit_impl
272# else
273# error invalid configuration for _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION
274# endif
277# else
278# error invalid configuration for _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION
279# endif
275280 __impl;
276281};
277282
278# if __has_cpp_attribute(_Clang::__ptrauth_vtable_pointer__)
279# if __has_feature(ptrauth_type_info_vtable_pointer_discrimination)
280# define _LIBCPP_TYPE_INFO_VTABLE_POINTER_AUTH \
281 [[_Clang::__ptrauth_vtable_pointer__(process_independent, address_discrimination, type_discrimination)]]
283# if __has_cpp_attribute(_Clang::__ptrauth_vtable_pointer__)
284# if __has_feature(ptrauth_type_info_vtable_pointer_discrimination)
285# define _LIBCPP_TYPE_INFO_VTABLE_POINTER_AUTH \
286 [[_Clang::__ptrauth_vtable_pointer__(process_independent, address_discrimination, type_discrimination)]]
287# else
288# define _LIBCPP_TYPE_INFO_VTABLE_POINTER_AUTH \
289 [[_Clang::__ptrauth_vtable_pointer__( \
290 process_independent, no_address_discrimination, no_extra_discrimination)]]
291# endif
282292# else
283# define _LIBCPP_TYPE_INFO_VTABLE_POINTER_AUTH \
284 [[_Clang::__ptrauth_vtable_pointer__( \
285 process_independent, no_address_discrimination, no_extra_discrimination)]]
293# define _LIBCPP_TYPE_INFO_VTABLE_POINTER_AUTH
286294# endif
287# else
288# define _LIBCPP_TYPE_INFO_VTABLE_POINTER_AUTH
289# endif
290295
291296class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_TYPE_INFO_VTABLE_POINTER_AUTH type_info {
292297 type_info& operator=(const type_info&);
......@@ -319,11 +324,11 @@ public:
319324 return __impl::__eq(__type_name, __arg.__type_name);
320325 }
321326
322# if _LIBCPP_STD_VER <= 17
327# if _LIBCPP_STD_VER <= 17
323328 _LIBCPP_HIDE_FROM_ABI bool operator!=(const type_info& __arg) const _NOEXCEPT { return !operator==(__arg); }
324# endif
329# endif
325330};
326# endif // defined(_LIBCPP_ABI_MICROSOFT)
331# endif // defined(_LIBCPP_ABI_MICROSOFT)
327332
328333class _LIBCPP_EXPORTED_FROM_ABI bad_cast : public exception {
329334public:
......@@ -345,9 +350,9 @@ public:
345350
346351} // namespace std
347352
348#endif // defined(_LIBCPP_ABI_VCRUNTIME)
353# endif // defined(_LIBCPP_ABI_VCRUNTIME)
349354
350#if defined(_LIBCPP_ABI_VCRUNTIME) && _HAS_EXCEPTIONS == 0
355# if defined(_LIBCPP_ABI_VCRUNTIME) && _HAS_EXCEPTIONS == 0
351356
352357namespace std {
353358
......@@ -369,21 +374,23 @@ private:
369374
370375} // namespace std
371376
372#endif // defined(_LIBCPP_ABI_VCRUNTIME) && _HAS_EXCEPTIONS == 0
377# endif // defined(_LIBCPP_ABI_VCRUNTIME) && _HAS_EXCEPTIONS == 0
373378
374379_LIBCPP_BEGIN_NAMESPACE_STD
375_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_cast() {
376#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
380[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_cast() {
381# if _LIBCPP_HAS_EXCEPTIONS
377382 throw bad_cast();
378#else
383# else
379384 _LIBCPP_VERBOSE_ABORT("bad_cast was thrown in -fno-exceptions mode");
380#endif
385# endif
381386}
382387_LIBCPP_END_NAMESPACE_STD
383388
384#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
385# include <cstdlib>
386# include <type_traits>
387#endif
389# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
390# include <cstddef>
391# include <cstdlib>
392# include <type_traits>
393# endif
394#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
388395
389396#endif // _LIBCPP_TYPEINFO
lib/libcxx/include/uchar.h+17-13
......@@ -32,25 +32,29 @@ size_t c32rtomb(char* s, char32_t c32, mbstate_t* ps);
3232
3333*/
3434
35#include <__config>
35#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
36# include <__cxx03/uchar.h>
37#else
38# include <__config>
3639
37#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
38# pragma GCC system_header
39#endif
40# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
41# pragma GCC system_header
42# endif
4043
41#if !defined(_LIBCPP_CXX03_LANG)
44# if !defined(_LIBCPP_CXX03_LANG)
4245
4346// Some platforms don't implement <uchar.h> and we don't want to give a hard
4447// error on those platforms. When the platform doesn't provide <uchar.h>, at
4548// least include <stddef.h> so we get the declaration for size_t, and try to
4649// get the declaration of mbstate_t too.
47# if __has_include_next(<uchar.h>)
48# include_next <uchar.h>
49# else
50# include <__mbstate_t.h>
51# include <stddef.h>
52# endif
53
54#endif // _LIBCPP_CXX03_LANG
50# if __has_include_next(<uchar.h>)
51# include_next <uchar.h>
52# else
53# include <__mbstate_t.h>
54# include <stddef.h>
55# endif
56
57# endif // _LIBCPP_CXX03_LANG
58#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
5559
5660#endif // _LIBCPP_UCHAR_H
lib/libcxx/include/unordered_map+197-161
......@@ -583,49 +583,63 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
583583
584584*/
585585
586#include <__algorithm/is_permutation.h>
587#include <__assert>
588#include <__config>
589#include <__functional/is_transparent.h>
590#include <__functional/operations.h>
591#include <__hash_table>
592#include <__iterator/distance.h>
593#include <__iterator/erase_if_container.h>
594#include <__iterator/iterator_traits.h>
595#include <__iterator/ranges_iterator_traits.h>
596#include <__memory/addressof.h>
597#include <__memory/allocator.h>
598#include <__memory_resource/polymorphic_allocator.h>
599#include <__node_handle>
600#include <__ranges/concepts.h>
601#include <__ranges/container_compatible_range.h>
602#include <__ranges/from_range.h>
603#include <__type_traits/is_allocator.h>
604#include <__type_traits/type_identity.h>
605#include <__utility/forward.h>
606#include <stdexcept>
607#include <tuple>
608#include <version>
586#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
587# include <__cxx03/unordered_map>
588#else
589# include <__algorithm/is_permutation.h>
590# include <__assert>
591# include <__config>
592# include <__functional/hash.h>
593# include <__functional/is_transparent.h>
594# include <__functional/operations.h>
595# include <__hash_table>
596# include <__iterator/distance.h>
597# include <__iterator/erase_if_container.h>
598# include <__iterator/iterator_traits.h>
599# include <__iterator/ranges_iterator_traits.h>
600# include <__memory/addressof.h>
601# include <__memory/allocator.h>
602# include <__memory/allocator_traits.h>
603# include <__memory/pointer_traits.h>
604# include <__memory/unique_ptr.h>
605# include <__memory_resource/polymorphic_allocator.h>
606# include <__new/launder.h>
607# include <__node_handle>
608# include <__ranges/concepts.h>
609# include <__ranges/container_compatible_range.h>
610# include <__ranges/from_range.h>
611# include <__type_traits/container_traits.h>
612# include <__type_traits/enable_if.h>
613# include <__type_traits/invoke.h>
614# include <__type_traits/is_allocator.h>
615# include <__type_traits/is_integral.h>
616# include <__type_traits/remove_const.h>
617# include <__type_traits/type_identity.h>
618# include <__utility/forward.h>
619# include <__utility/pair.h>
620# include <stdexcept>
621# include <tuple>
622# include <version>
609623
610624// standard-mandated includes
611625
612626// [iterator.range]
613#include <__iterator/access.h>
614#include <__iterator/data.h>
615#include <__iterator/empty.h>
616#include <__iterator/reverse_access.h>
617#include <__iterator/size.h>
627# include <__iterator/access.h>
628# include <__iterator/data.h>
629# include <__iterator/empty.h>
630# include <__iterator/reverse_access.h>
631# include <__iterator/size.h>
618632
619633// [unord.map.syn]
620#include <compare>
621#include <initializer_list>
634# include <compare>
635# include <initializer_list>
622636
623#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
624# pragma GCC system_header
625#endif
637# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
638# pragma GCC system_header
639# endif
626640
627641_LIBCPP_PUSH_MACROS
628#include <__undef_macros>
642# include <__undef_macros>
629643
630644_LIBCPP_BEGIN_NAMESPACE_STD
631645
......@@ -644,12 +658,12 @@ public:
644658 return static_cast<const _Hash&>(*this)(__x.__get_value().first);
645659 }
646660 _LIBCPP_HIDE_FROM_ABI size_t operator()(const _Key& __x) const { return static_cast<const _Hash&>(*this)(__x); }
647#if _LIBCPP_STD_VER >= 20
661# if _LIBCPP_STD_VER >= 20
648662 template <typename _K2>
649663 _LIBCPP_HIDE_FROM_ABI size_t operator()(const _K2& __x) const {
650664 return static_cast<const _Hash&>(*this)(__x);
651665 }
652#endif
666# endif
653667 _LIBCPP_HIDE_FROM_ABI void swap(__unordered_map_hasher& __y) _NOEXCEPT_(__is_nothrow_swappable_v<_Hash>) {
654668 using std::swap;
655669 swap(static_cast<_Hash&>(*this), static_cast<_Hash&>(__y));
......@@ -668,12 +682,12 @@ public:
668682 _LIBCPP_HIDE_FROM_ABI const _Hash& hash_function() const _NOEXCEPT { return __hash_; }
669683 _LIBCPP_HIDE_FROM_ABI size_t operator()(const _Cp& __x) const { return __hash_(__x.__get_value().first); }
670684 _LIBCPP_HIDE_FROM_ABI size_t operator()(const _Key& __x) const { return __hash_(__x); }
671#if _LIBCPP_STD_VER >= 20
685# if _LIBCPP_STD_VER >= 20
672686 template <typename _K2>
673687 _LIBCPP_HIDE_FROM_ABI size_t operator()(const _K2& __x) const {
674688 return __hash_(__x);
675689 }
676#endif
690# endif
677691 _LIBCPP_HIDE_FROM_ABI void swap(__unordered_map_hasher& __y) _NOEXCEPT_(__is_nothrow_swappable_v<_Hash>) {
678692 using std::swap;
679693 swap(__hash_, __y.__hash_);
......@@ -707,7 +721,7 @@ public:
707721 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _Cp& __y) const {
708722 return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);
709723 }
710#if _LIBCPP_STD_VER >= 20
724# if _LIBCPP_STD_VER >= 20
711725 template <typename _K2>
712726 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Cp& __x, const _K2& __y) const {
713727 return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);
......@@ -724,7 +738,7 @@ public:
724738 _LIBCPP_HIDE_FROM_ABI bool operator()(const _K2& __x, const _Key& __y) const {
725739 return static_cast<const _Pred&>(*this)(__x, __y);
726740 }
727#endif
741# endif
728742 _LIBCPP_HIDE_FROM_ABI void swap(__unordered_map_equal& __y) _NOEXCEPT_(__is_nothrow_swappable_v<_Pred>) {
729743 using std::swap;
730744 swap(static_cast<_Pred&>(*this), static_cast<_Pred&>(__y));
......@@ -750,7 +764,7 @@ public:
750764 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _Cp& __y) const {
751765 return __pred_(__x, __y.__get_value().first);
752766 }
753#if _LIBCPP_STD_VER >= 20
767# if _LIBCPP_STD_VER >= 20
754768 template <typename _K2>
755769 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Cp& __x, const _K2& __y) const {
756770 return __pred_(__x.__get_value().first, __y);
......@@ -767,7 +781,7 @@ public:
767781 _LIBCPP_HIDE_FROM_ABI bool operator()(const _K2& __x, const _Key& __y) const {
768782 return __pred_(__x, __y);
769783 }
770#endif
784# endif
771785 _LIBCPP_HIDE_FROM_ABI void swap(__unordered_map_equal& __y) _NOEXCEPT_(__is_nothrow_swappable_v<_Pred>) {
772786 using std::swap;
773787 swap(__pred_, __y.__pred_);
......@@ -803,19 +817,19 @@ public:
803817 __first_constructed(false),
804818 __second_constructed(false) {}
805819
806#ifndef _LIBCPP_CXX03_LANG
820# ifndef _LIBCPP_CXX03_LANG
807821 _LIBCPP_HIDE_FROM_ABI __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x) _NOEXCEPT
808822 : __na_(__x.__na_),
809823 __first_constructed(__x.__value_constructed),
810824 __second_constructed(__x.__value_constructed) {
811825 __x.__value_constructed = false;
812826 }
813#else // _LIBCPP_CXX03_LANG
827# else // _LIBCPP_CXX03_LANG
814828 _LIBCPP_HIDE_FROM_ABI __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
815829 : __na_(__x.__na_), __first_constructed(__x.__value_constructed), __second_constructed(__x.__value_constructed) {
816830 const_cast<bool&>(__x.__value_constructed) = false;
817831 }
818#endif // _LIBCPP_CXX03_LANG
832# endif // _LIBCPP_CXX03_LANG
819833
820834 _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT {
821835 if (__second_constructed)
......@@ -827,7 +841,7 @@ public:
827841 }
828842};
829843
830#ifndef _LIBCPP_CXX03_LANG
844# ifndef _LIBCPP_CXX03_LANG
831845template <class _Key, class _Tp>
832846struct _LIBCPP_STANDALONE_DEBUG __hash_value_type {
833847 typedef _Key key_type;
......@@ -841,19 +855,19 @@ private:
841855
842856public:
843857 _LIBCPP_HIDE_FROM_ABI value_type& __get_value() {
844# if _LIBCPP_STD_VER >= 17
858# if _LIBCPP_STD_VER >= 17
845859 return *std::launder(std::addressof(__cc_));
846# else
860# else
847861 return __cc_;
848# endif
862# endif
849863 }
850864
851865 _LIBCPP_HIDE_FROM_ABI const value_type& __get_value() const {
852# if _LIBCPP_STD_VER >= 17
866# if _LIBCPP_STD_VER >= 17
853867 return *std::launder(std::addressof(__cc_));
854# else
868# else
855869 return __cc_;
856# endif
870# endif
857871 }
858872
859873 _LIBCPP_HIDE_FROM_ABI __nc_ref_pair_type __ref() {
......@@ -890,7 +904,7 @@ public:
890904 ~__hash_value_type() = delete;
891905};
892906
893#else
907# else
894908
895909template <class _Key, class _Tp>
896910struct __hash_value_type {
......@@ -908,7 +922,7 @@ public:
908922 ~__hash_value_type() = delete;
909923};
910924
911#endif
925# endif
912926
913927template <class _HashIterator>
914928class _LIBCPP_TEMPLATE_VIS __hash_map_iterator {
......@@ -943,11 +957,11 @@ public:
943957 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y) {
944958 return __x.__i_ == __y.__i_;
945959 }
946#if _LIBCPP_STD_VER <= 17
960# if _LIBCPP_STD_VER <= 17
947961 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y) {
948962 return __x.__i_ != __y.__i_;
949963 }
950#endif
964# endif
951965
952966 template <class, class, class, class, class>
953967 friend class _LIBCPP_TEMPLATE_VIS unordered_map;
......@@ -998,12 +1012,12 @@ public:
9981012 operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) {
9991013 return __x.__i_ == __y.__i_;
10001014 }
1001#if _LIBCPP_STD_VER <= 17
1015# if _LIBCPP_STD_VER <= 17
10021016 friend _LIBCPP_HIDE_FROM_ABI bool
10031017 operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) {
10041018 return __x.__i_ != __y.__i_;
10051019 }
1006#endif
1020# endif
10071021
10081022 template <class, class, class, class, class>
10091023 friend class _LIBCPP_TEMPLATE_VIS unordered_map;
......@@ -1073,10 +1087,10 @@ public:
10731087 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
10741088 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
10751089
1076#if _LIBCPP_STD_VER >= 17
1090# if _LIBCPP_STD_VER >= 17
10771091 typedef __map_node_handle<__node, allocator_type> node_type;
10781092 typedef __insert_return_type<iterator, node_type> insert_return_type;
1079#endif
1093# endif
10801094
10811095 template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
10821096 friend class _LIBCPP_TEMPLATE_VIS unordered_map;
......@@ -1106,7 +1120,7 @@ public:
11061120 const key_equal& __eql,
11071121 const allocator_type& __a);
11081122
1109#if _LIBCPP_STD_VER >= 23
1123# if _LIBCPP_STD_VER >= 23
11101124 template <_ContainerCompatibleRange<value_type> _Range>
11111125 _LIBCPP_HIDE_FROM_ABI unordered_map(
11121126 from_range_t,
......@@ -1121,12 +1135,12 @@ public:
11211135 }
11221136 insert_range(std::forward<_Range>(__range));
11231137 }
1124#endif
1138# endif
11251139
11261140 _LIBCPP_HIDE_FROM_ABI explicit unordered_map(const allocator_type& __a);
11271141 _LIBCPP_HIDE_FROM_ABI unordered_map(const unordered_map& __u);
11281142 _LIBCPP_HIDE_FROM_ABI unordered_map(const unordered_map& __u, const allocator_type& __a);
1129#ifndef _LIBCPP_CXX03_LANG
1143# ifndef _LIBCPP_CXX03_LANG
11301144 _LIBCPP_HIDE_FROM_ABI unordered_map(unordered_map&& __u) _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
11311145 _LIBCPP_HIDE_FROM_ABI unordered_map(unordered_map&& __u, const allocator_type& __a);
11321146 _LIBCPP_HIDE_FROM_ABI unordered_map(initializer_list<value_type> __il);
......@@ -1141,8 +1155,8 @@ public:
11411155 const hasher& __hf,
11421156 const key_equal& __eql,
11431157 const allocator_type& __a);
1144#endif // _LIBCPP_CXX03_LANG
1145#if _LIBCPP_STD_VER >= 14
1158# endif // _LIBCPP_CXX03_LANG
1159# if _LIBCPP_STD_VER >= 14
11461160 _LIBCPP_HIDE_FROM_ABI unordered_map(size_type __n, const allocator_type& __a)
11471161 : unordered_map(__n, hasher(), key_equal(), __a) {}
11481162 _LIBCPP_HIDE_FROM_ABI unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
......@@ -1156,7 +1170,7 @@ public:
11561170 _InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const allocator_type& __a)
11571171 : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
11581172
1159# if _LIBCPP_STD_VER >= 23
1173# if _LIBCPP_STD_VER >= 23
11601174 template <_ContainerCompatibleRange<value_type> _Range>
11611175 _LIBCPP_HIDE_FROM_ABI unordered_map(from_range_t, _Range&& __range, size_type __n, const allocator_type& __a)
11621176 : unordered_map(from_range, std::forward<_Range>(__range), __n, hasher(), key_equal(), __a) {}
......@@ -1165,22 +1179,22 @@ public:
11651179 _LIBCPP_HIDE_FROM_ABI
11661180 unordered_map(from_range_t, _Range&& __range, size_type __n, const hasher& __hf, const allocator_type& __a)
11671181 : unordered_map(from_range, std::forward<_Range>(__range), __n, __hf, key_equal(), __a) {}
1168# endif
1182# endif
11691183
11701184 _LIBCPP_HIDE_FROM_ABI unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
11711185 : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
11721186 _LIBCPP_HIDE_FROM_ABI
11731187 unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a)
11741188 : unordered_map(__il, __n, __hf, key_equal(), __a) {}
1175#endif
1189# endif
11761190 _LIBCPP_HIDE_FROM_ABI ~unordered_map() {
11771191 static_assert(sizeof(std::__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), "");
11781192 }
11791193
11801194 _LIBCPP_HIDE_FROM_ABI unordered_map& operator=(const unordered_map& __u) {
1181#ifndef _LIBCPP_CXX03_LANG
1195# ifndef _LIBCPP_CXX03_LANG
11821196 __table_ = __u.__table_;
1183#else
1197# else
11841198 if (this != std::addressof(__u)) {
11851199 __table_.clear();
11861200 __table_.hash_function() = __u.__table_.hash_function();
......@@ -1189,20 +1203,20 @@ public:
11891203 __table_.__copy_assign_alloc(__u.__table_);
11901204 insert(__u.begin(), __u.end());
11911205 }
1192#endif
1206# endif
11931207 return *this;
11941208 }
1195#ifndef _LIBCPP_CXX03_LANG
1209# ifndef _LIBCPP_CXX03_LANG
11961210 _LIBCPP_HIDE_FROM_ABI unordered_map& operator=(unordered_map&& __u)
11971211 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
11981212 _LIBCPP_HIDE_FROM_ABI unordered_map& operator=(initializer_list<value_type> __il);
1199#endif // _LIBCPP_CXX03_LANG
1213# endif // _LIBCPP_CXX03_LANG
12001214
12011215 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT {
12021216 return allocator_type(__table_.__node_alloc());
12031217 }
12041218
1205 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __table_.size() == 0; }
1219 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __table_.size() == 0; }
12061220 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __table_.size(); }
12071221 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __table_.max_size(); }
12081222
......@@ -1220,16 +1234,16 @@ public:
12201234 template <class _InputIterator>
12211235 _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last);
12221236
1223#if _LIBCPP_STD_VER >= 23
1237# if _LIBCPP_STD_VER >= 23
12241238 template <_ContainerCompatibleRange<value_type> _Range>
12251239 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
12261240 for (auto&& __element : __range) {
12271241 __table_.__insert_unique(std::forward<decltype(__element)>(__element));
12281242 }
12291243 }
1230#endif
1244# endif
12311245
1232#ifndef _LIBCPP_CXX03_LANG
1246# ifndef _LIBCPP_CXX03_LANG
12331247 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
12341248
12351249 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __x) {
......@@ -1260,9 +1274,9 @@ public:
12601274 return __table_.__emplace_unique(std::forward<_Args>(__args)...).first;
12611275 }
12621276
1263#endif // _LIBCPP_CXX03_LANG
1277# endif // _LIBCPP_CXX03_LANG
12641278
1265#if _LIBCPP_STD_VER >= 17
1279# if _LIBCPP_STD_VER >= 17
12661280 template <class... _Args>
12671281 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args) {
12681282 return __table_.__emplace_unique_key_args(
......@@ -1315,7 +1329,7 @@ public:
13151329 _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator, key_type&& __k, _Vp&& __v) {
13161330 return insert_or_assign(std::move(__k), std::forward<_Vp>(__v)).first;
13171331 }
1318#endif // _LIBCPP_STD_VER >= 17
1332# endif // _LIBCPP_STD_VER >= 17
13191333
13201334 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __table_.erase(__p.__i_); }
13211335 _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __p) { return __table_.erase(__p.__i_); }
......@@ -1325,7 +1339,7 @@ public:
13251339 }
13261340 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __table_.clear(); }
13271341
1328#if _LIBCPP_STD_VER >= 17
1342# if _LIBCPP_STD_VER >= 17
13291343 _LIBCPP_HIDE_FROM_ABI insert_return_type insert(node_type&& __nh) {
13301344 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
13311345 "node_type with incompatible allocator passed to unordered_map::insert()");
......@@ -1367,7 +1381,7 @@ public:
13671381 __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
13681382 return __table_.__node_handle_merge_unique(__source.__table_);
13691383 }
1370#endif
1384# endif
13711385
13721386 _LIBCPP_HIDE_FROM_ABI void swap(unordered_map& __u) _NOEXCEPT_(__is_nothrow_swappable_v<__table>) {
13731387 __table_.swap(__u.__table_);
......@@ -1378,7 +1392,7 @@ public:
13781392
13791393 _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __table_.find(__k); }
13801394 _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __table_.find(__k); }
1381#if _LIBCPP_STD_VER >= 20
1395# if _LIBCPP_STD_VER >= 20
13821396 template <class _K2, enable_if_t<__is_transparent_v<hasher, _K2> && __is_transparent_v<key_equal, _K2>>* = nullptr>
13831397 _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
13841398 return __table_.find(__k);
......@@ -1387,24 +1401,24 @@ public:
13871401 _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
13881402 return __table_.find(__k);
13891403 }
1390#endif // _LIBCPP_STD_VER >= 20
1404# endif // _LIBCPP_STD_VER >= 20
13911405
13921406 _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __table_.__count_unique(__k); }
1393#if _LIBCPP_STD_VER >= 20
1407# if _LIBCPP_STD_VER >= 20
13941408 template <class _K2, enable_if_t<__is_transparent_v<hasher, _K2> && __is_transparent_v<key_equal, _K2>>* = nullptr>
13951409 _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
13961410 return __table_.__count_unique(__k);
13971411 }
1398#endif // _LIBCPP_STD_VER >= 20
1412# endif // _LIBCPP_STD_VER >= 20
13991413
1400#if _LIBCPP_STD_VER >= 20
1414# if _LIBCPP_STD_VER >= 20
14011415 _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
14021416
14031417 template <class _K2, enable_if_t<__is_transparent_v<hasher, _K2> && __is_transparent_v<key_equal, _K2>>* = nullptr>
14041418 _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
14051419 return find(__k) != end();
14061420 }
1407#endif // _LIBCPP_STD_VER >= 20
1421# endif // _LIBCPP_STD_VER >= 20
14081422
14091423 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
14101424 return __table_.__equal_range_unique(__k);
......@@ -1412,7 +1426,7 @@ public:
14121426 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
14131427 return __table_.__equal_range_unique(__k);
14141428 }
1415#if _LIBCPP_STD_VER >= 20
1429# if _LIBCPP_STD_VER >= 20
14161430 template <class _K2, enable_if_t<__is_transparent_v<hasher, _K2> && __is_transparent_v<key_equal, _K2>>* = nullptr>
14171431 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
14181432 return __table_.__equal_range_unique(__k);
......@@ -1421,12 +1435,12 @@ public:
14211435 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
14221436 return __table_.__equal_range_unique(__k);
14231437 }
1424#endif // _LIBCPP_STD_VER >= 20
1438# endif // _LIBCPP_STD_VER >= 20
14251439
14261440 _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](const key_type& __k);
1427#ifndef _LIBCPP_CXX03_LANG
1441# ifndef _LIBCPP_CXX03_LANG
14281442 _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](key_type&& __k);
1429#endif
1443# endif
14301444
14311445 _LIBCPP_HIDE_FROM_ABI mapped_type& at(const key_type& __k);
14321446 _LIBCPP_HIDE_FROM_ABI const mapped_type& at(const key_type& __k) const;
......@@ -1451,12 +1465,12 @@ public:
14511465 _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n) { __table_.__reserve_unique(__n); }
14521466
14531467private:
1454#ifdef _LIBCPP_CXX03_LANG
1468# ifdef _LIBCPP_CXX03_LANG
14551469 _LIBCPP_HIDE_FROM_ABI __node_holder __construct_node_with_key(const key_type& __k);
1456#endif
1470# endif
14571471};
14581472
1459#if _LIBCPP_STD_VER >= 17
1473# if _LIBCPP_STD_VER >= 17
14601474template <class _InputIterator,
14611475 class _Hash = hash<__iter_key_type<_InputIterator>>,
14621476 class _Pred = equal_to<__iter_key_type<_InputIterator>>,
......@@ -1474,7 +1488,7 @@ unordered_map(_InputIterator,
14741488 _Allocator = _Allocator())
14751489 -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>;
14761490
1477# if _LIBCPP_STD_VER >= 23
1491# if _LIBCPP_STD_VER >= 23
14781492template <ranges::input_range _Range,
14791493 class _Hash = hash<__range_key_type<_Range>>,
14801494 class _Pred = equal_to<__range_key_type<_Range>>,
......@@ -1490,7 +1504,7 @@ unordered_map(from_range_t,
14901504 _Pred = _Pred(),
14911505 _Allocator = _Allocator())
14921506 -> unordered_map<__range_key_type<_Range>, __range_mapped_type<_Range>, _Hash, _Pred, _Allocator>; // C++23
1493# endif
1507# endif
14941508
14951509template <class _Key,
14961510 class _Tp,
......@@ -1543,7 +1557,7 @@ unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocat
15431557 equal_to<__iter_key_type<_InputIterator>>,
15441558 _Allocator>;
15451559
1546# if _LIBCPP_STD_VER >= 23
1560# if _LIBCPP_STD_VER >= 23
15471561
15481562template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value>>
15491563unordered_map(from_range_t, _Range&&, typename allocator_traits<_Allocator>::size_type, _Allocator)
......@@ -1574,7 +1588,7 @@ unordered_map(from_range_t, _Range&&, typename allocator_traits<_Allocator>::siz
15741588 equal_to<__range_key_type<_Range>>,
15751589 _Allocator>;
15761590
1577# endif
1591# endif
15781592
15791593template <class _Key, class _Tp, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value>>
15801594unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator)
......@@ -1593,7 +1607,7 @@ template <class _Key,
15931607 class = enable_if_t<__is_allocator<_Allocator>::value>>
15941608unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
15951609 -> unordered_map<remove_const_t<_Key>, _Tp, _Hash, equal_to<remove_const_t<_Key>>, _Allocator>;
1596#endif
1610# endif
15971611
15981612template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
15991613unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(size_type __n, const hasher& __hf, const key_equal& __eql)
......@@ -1654,7 +1668,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(const unordered_ma
16541668 insert(__u.begin(), __u.end());
16551669}
16561670
1657#ifndef _LIBCPP_CXX03_LANG
1671# ifndef _LIBCPP_CXX03_LANG
16581672
16591673template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
16601674inline unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(unordered_map&& __u)
......@@ -1712,7 +1726,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(initializer_list<value
17121726 return *this;
17131727}
17141728
1715#endif // _LIBCPP_CXX03_LANG
1729# endif // _LIBCPP_CXX03_LANG
17161730
17171731template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
17181732template <class _InputIterator>
......@@ -1721,7 +1735,7 @@ inline void unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterato
17211735 __table_.__insert_unique(*__first);
17221736}
17231737
1724#ifndef _LIBCPP_CXX03_LANG
1738# ifndef _LIBCPP_CXX03_LANG
17251739
17261740template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
17271741_Tp& unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) {
......@@ -1739,7 +1753,7 @@ _Tp& unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
17391753 .first->__get_value()
17401754 .second;
17411755}
1742#else // _LIBCPP_CXX03_LANG
1756# else // _LIBCPP_CXX03_LANG
17431757
17441758template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
17451759typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
......@@ -1764,7 +1778,7 @@ _Tp& unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type&
17641778 return __r.first->second;
17651779}
17661780
1767#endif // _LIBCPP_CXX03_LANG
1781# endif // _LIBCPP_CXX03_LANG
17681782
17691783template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
17701784_Tp& unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) {
......@@ -1789,13 +1803,13 @@ swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, unordered_map<_Key, _T
17891803 __x.swap(__y);
17901804}
17911805
1792#if _LIBCPP_STD_VER >= 20
1806# if _LIBCPP_STD_VER >= 20
17931807template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc, class _Predicate>
17941808inline _LIBCPP_HIDE_FROM_ABI typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type
17951809erase_if(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __c, _Predicate __pred) {
17961810 return std::__libcpp_erase_if_container(__c, __pred);
17971811}
1798#endif
1812# endif
17991813
18001814template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
18011815_LIBCPP_HIDE_FROM_ABI bool operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
......@@ -1811,7 +1825,7 @@ _LIBCPP_HIDE_FROM_ABI bool operator==(const unordered_map<_Key, _Tp, _Hash, _Pre
18111825 return true;
18121826}
18131827
1814#if _LIBCPP_STD_VER <= 17
1828# if _LIBCPP_STD_VER <= 17
18151829
18161830template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
18171831inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
......@@ -1819,7 +1833,17 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const unordered_map<_Key, _Tp, _Has
18191833 return !(__x == __y);
18201834}
18211835
1822#endif
1836# endif
1837
1838template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1839struct __container_traits<unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc> > {
1840 // http://eel.is/c++draft/unord.req.except#2
1841 // For unordered associative containers, if an exception is thrown by any operation
1842 // other than the container's hash function from within an insert or emplace function
1843 // inserting a single element, the insertion has no effect.
1844 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
1845 __is_nothrow_invocable_v<_Hash, const _Key&>;
1846};
18231847
18241848template <class _Key,
18251849 class _Tp,
......@@ -1872,9 +1896,9 @@ public:
18721896 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
18731897 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
18741898
1875#if _LIBCPP_STD_VER >= 17
1899# if _LIBCPP_STD_VER >= 17
18761900 typedef __map_node_handle<__node, allocator_type> node_type;
1877#endif
1901# endif
18781902
18791903 template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
18801904 friend class _LIBCPP_TEMPLATE_VIS unordered_map;
......@@ -1904,7 +1928,7 @@ public:
19041928 const key_equal& __eql,
19051929 const allocator_type& __a);
19061930
1907#if _LIBCPP_STD_VER >= 23
1931# if _LIBCPP_STD_VER >= 23
19081932 template <_ContainerCompatibleRange<value_type> _Range>
19091933 _LIBCPP_HIDE_FROM_ABI unordered_multimap(
19101934 from_range_t,
......@@ -1919,12 +1943,12 @@ public:
19191943 }
19201944 insert_range(std::forward<_Range>(__range));
19211945 }
1922#endif
1946# endif
19231947
19241948 _LIBCPP_HIDE_FROM_ABI explicit unordered_multimap(const allocator_type& __a);
19251949 _LIBCPP_HIDE_FROM_ABI unordered_multimap(const unordered_multimap& __u);
19261950 _LIBCPP_HIDE_FROM_ABI unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
1927#ifndef _LIBCPP_CXX03_LANG
1951# ifndef _LIBCPP_CXX03_LANG
19281952 _LIBCPP_HIDE_FROM_ABI unordered_multimap(unordered_multimap&& __u)
19291953 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
19301954 _LIBCPP_HIDE_FROM_ABI unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
......@@ -1940,8 +1964,8 @@ public:
19401964 const hasher& __hf,
19411965 const key_equal& __eql,
19421966 const allocator_type& __a);
1943#endif // _LIBCPP_CXX03_LANG
1944#if _LIBCPP_STD_VER >= 14
1967# endif // _LIBCPP_CXX03_LANG
1968# if _LIBCPP_STD_VER >= 14
19451969 _LIBCPP_HIDE_FROM_ABI unordered_multimap(size_type __n, const allocator_type& __a)
19461970 : unordered_multimap(__n, hasher(), key_equal(), __a) {}
19471971 _LIBCPP_HIDE_FROM_ABI unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
......@@ -1955,7 +1979,7 @@ public:
19551979 _InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const allocator_type& __a)
19561980 : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
19571981
1958# if _LIBCPP_STD_VER >= 23
1982# if _LIBCPP_STD_VER >= 23
19591983 template <_ContainerCompatibleRange<value_type> _Range>
19601984 _LIBCPP_HIDE_FROM_ABI unordered_multimap(from_range_t, _Range&& __range, size_type __n, const allocator_type& __a)
19611985 : unordered_multimap(from_range, std::forward<_Range>(__range), __n, hasher(), key_equal(), __a) {}
......@@ -1964,22 +1988,22 @@ public:
19641988 _LIBCPP_HIDE_FROM_ABI
19651989 unordered_multimap(from_range_t, _Range&& __range, size_type __n, const hasher& __hf, const allocator_type& __a)
19661990 : unordered_multimap(from_range, std::forward<_Range>(__range), __n, __hf, key_equal(), __a) {}
1967# endif
1991# endif
19681992
19691993 _LIBCPP_HIDE_FROM_ABI unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
19701994 : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
19711995 _LIBCPP_HIDE_FROM_ABI
19721996 unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a)
19731997 : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
1974#endif
1998# endif
19751999 _LIBCPP_HIDE_FROM_ABI ~unordered_multimap() {
19762000 static_assert(sizeof(std::__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), "");
19772001 }
19782002
19792003 _LIBCPP_HIDE_FROM_ABI unordered_multimap& operator=(const unordered_multimap& __u) {
1980#ifndef _LIBCPP_CXX03_LANG
2004# ifndef _LIBCPP_CXX03_LANG
19812005 __table_ = __u.__table_;
1982#else
2006# else
19832007 if (this != std::addressof(__u)) {
19842008 __table_.clear();
19852009 __table_.hash_function() = __u.__table_.hash_function();
......@@ -1988,20 +2012,20 @@ public:
19882012 __table_.__copy_assign_alloc(__u.__table_);
19892013 insert(__u.begin(), __u.end());
19902014 }
1991#endif
2015# endif
19922016 return *this;
19932017 }
1994#ifndef _LIBCPP_CXX03_LANG
2018# ifndef _LIBCPP_CXX03_LANG
19952019 _LIBCPP_HIDE_FROM_ABI unordered_multimap& operator=(unordered_multimap&& __u)
19962020 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
19972021 _LIBCPP_HIDE_FROM_ABI unordered_multimap& operator=(initializer_list<value_type> __il);
1998#endif // _LIBCPP_CXX03_LANG
2022# endif // _LIBCPP_CXX03_LANG
19992023
20002024 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT {
20012025 return allocator_type(__table_.__node_alloc());
20022026 }
20032027
2004 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __table_.size() == 0; }
2028 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __table_.size() == 0; }
20052029 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __table_.size(); }
20062030 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __table_.max_size(); }
20072031
......@@ -2021,16 +2045,16 @@ public:
20212045 template <class _InputIterator>
20222046 _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last);
20232047
2024#if _LIBCPP_STD_VER >= 23
2048# if _LIBCPP_STD_VER >= 23
20252049 template <_ContainerCompatibleRange<value_type> _Range>
20262050 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
20272051 for (auto&& __element : __range) {
20282052 __table_.__insert_multi(std::forward<decltype(__element)>(__element));
20292053 }
20302054 }
2031#endif
2055# endif
20322056
2033#ifndef _LIBCPP_CXX03_LANG
2057# ifndef _LIBCPP_CXX03_LANG
20342058 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
20352059 _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __x) { return __table_.__insert_multi(std::move(__x)); }
20362060
......@@ -2057,7 +2081,7 @@ public:
20572081 _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __p, _Args&&... __args) {
20582082 return __table_.__emplace_hint_multi(__p.__i_, std::forward<_Args>(__args)...);
20592083 }
2060#endif // _LIBCPP_CXX03_LANG
2084# endif // _LIBCPP_CXX03_LANG
20612085
20622086 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __table_.erase(__p.__i_); }
20632087 _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __p) { return __table_.erase(__p.__i_); }
......@@ -2067,7 +2091,7 @@ public:
20672091 }
20682092 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __table_.clear(); }
20692093
2070#if _LIBCPP_STD_VER >= 17
2094# if _LIBCPP_STD_VER >= 17
20712095 _LIBCPP_HIDE_FROM_ABI iterator insert(node_type&& __nh) {
20722096 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
20732097 "node_type with incompatible allocator passed to unordered_multimap::insert()");
......@@ -2109,7 +2133,7 @@ public:
21092133 __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
21102134 return __table_.__node_handle_merge_multi(__source.__table_);
21112135 }
2112#endif
2136# endif
21132137
21142138 _LIBCPP_HIDE_FROM_ABI void swap(unordered_multimap& __u) _NOEXCEPT_(__is_nothrow_swappable_v<__table>) {
21152139 __table_.swap(__u.__table_);
......@@ -2120,7 +2144,7 @@ public:
21202144
21212145 _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __table_.find(__k); }
21222146 _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __table_.find(__k); }
2123#if _LIBCPP_STD_VER >= 20
2147# if _LIBCPP_STD_VER >= 20
21242148 template <class _K2, enable_if_t<__is_transparent_v<hasher, _K2> && __is_transparent_v<key_equal, _K2>>* = nullptr>
21252149 _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
21262150 return __table_.find(__k);
......@@ -2129,24 +2153,24 @@ public:
21292153 _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
21302154 return __table_.find(__k);
21312155 }
2132#endif // _LIBCPP_STD_VER >= 20
2156# endif // _LIBCPP_STD_VER >= 20
21332157
21342158 _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __table_.__count_multi(__k); }
2135#if _LIBCPP_STD_VER >= 20
2159# if _LIBCPP_STD_VER >= 20
21362160 template <class _K2, enable_if_t<__is_transparent_v<hasher, _K2> && __is_transparent_v<key_equal, _K2>>* = nullptr>
21372161 _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
21382162 return __table_.__count_multi(__k);
21392163 }
2140#endif // _LIBCPP_STD_VER >= 20
2164# endif // _LIBCPP_STD_VER >= 20
21412165
2142#if _LIBCPP_STD_VER >= 20
2166# if _LIBCPP_STD_VER >= 20
21432167 _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
21442168
21452169 template <class _K2, enable_if_t<__is_transparent_v<hasher, _K2> && __is_transparent_v<key_equal, _K2>>* = nullptr>
21462170 _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
21472171 return find(__k) != end();
21482172 }
2149#endif // _LIBCPP_STD_VER >= 20
2173# endif // _LIBCPP_STD_VER >= 20
21502174
21512175 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
21522176 return __table_.__equal_range_multi(__k);
......@@ -2154,7 +2178,7 @@ public:
21542178 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
21552179 return __table_.__equal_range_multi(__k);
21562180 }
2157#if _LIBCPP_STD_VER >= 20
2181# if _LIBCPP_STD_VER >= 20
21582182 template <class _K2, enable_if_t<__is_transparent_v<hasher, _K2> && __is_transparent_v<key_equal, _K2>>* = nullptr>
21592183 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
21602184 return __table_.__equal_range_multi(__k);
......@@ -2163,7 +2187,7 @@ public:
21632187 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
21642188 return __table_.__equal_range_multi(__k);
21652189 }
2166#endif // _LIBCPP_STD_VER >= 20
2190# endif // _LIBCPP_STD_VER >= 20
21672191
21682192 _LIBCPP_HIDE_FROM_ABI size_type bucket_count() const _NOEXCEPT { return __table_.bucket_count(); }
21692193 _LIBCPP_HIDE_FROM_ABI size_type max_bucket_count() const _NOEXCEPT { return __table_.max_bucket_count(); }
......@@ -2185,7 +2209,7 @@ public:
21852209 _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n) { __table_.__reserve_multi(__n); }
21862210};
21872211
2188#if _LIBCPP_STD_VER >= 17
2212# if _LIBCPP_STD_VER >= 17
21892213template <class _InputIterator,
21902214 class _Hash = hash<__iter_key_type<_InputIterator>>,
21912215 class _Pred = equal_to<__iter_key_type<_InputIterator>>,
......@@ -2207,7 +2231,7 @@ unordered_multimap(_InputIterator,
22072231 _Pred,
22082232 _Allocator>;
22092233
2210# if _LIBCPP_STD_VER >= 23
2234# if _LIBCPP_STD_VER >= 23
22112235template <ranges::input_range _Range,
22122236 class _Hash = hash<__range_key_type<_Range>>,
22132237 class _Pred = equal_to<__range_key_type<_Range>>,
......@@ -2223,7 +2247,7 @@ unordered_multimap(from_range_t,
22232247 _Pred = _Pred(),
22242248 _Allocator = _Allocator())
22252249 -> unordered_multimap<__range_key_type<_Range>, __range_mapped_type<_Range>, _Hash, _Pred, _Allocator>;
2226# endif
2250# endif
22272251
22282252template <class _Key,
22292253 class _Tp,
......@@ -2277,7 +2301,7 @@ unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Al
22772301 equal_to<__iter_key_type<_InputIterator>>,
22782302 _Allocator>;
22792303
2280# if _LIBCPP_STD_VER >= 23
2304# if _LIBCPP_STD_VER >= 23
22812305
22822306template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value>>
22832307unordered_multimap(from_range_t, _Range&&, typename allocator_traits<_Allocator>::size_type, _Allocator)
......@@ -2308,7 +2332,7 @@ unordered_multimap(from_range_t, _Range&&, typename allocator_traits<_Allocator>
23082332 equal_to<__range_key_type<_Range>>,
23092333 _Allocator>;
23102334
2311# endif
2335# endif
23122336
23132337template <class _Key, class _Tp, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value>>
23142338unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator)
......@@ -2336,7 +2360,7 @@ template <class _Key,
23362360unordered_multimap(
23372361 initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
23382362 -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash, equal_to<remove_const_t<_Key>>, _Allocator>;
2339#endif
2363# endif
23402364
23412365template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
23422366unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
......@@ -2400,7 +2424,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
24002424 insert(__u.begin(), __u.end());
24012425}
24022426
2403#ifndef _LIBCPP_CXX03_LANG
2427# ifndef _LIBCPP_CXX03_LANG
24042428
24052429template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
24062430inline unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(unordered_multimap&& __u)
......@@ -2459,7 +2483,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(initializer_list<
24592483 return *this;
24602484}
24612485
2462#endif // _LIBCPP_CXX03_LANG
2486# endif // _LIBCPP_CXX03_LANG
24632487
24642488template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
24652489template <class _InputIterator>
......@@ -2475,13 +2499,13 @@ swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, unordered_multima
24752499 __x.swap(__y);
24762500}
24772501
2478#if _LIBCPP_STD_VER >= 20
2502# if _LIBCPP_STD_VER >= 20
24792503template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc, class _Predicate>
24802504inline _LIBCPP_HIDE_FROM_ABI typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type
24812505erase_if(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __c, _Predicate __pred) {
24822506 return std::__libcpp_erase_if_container(__c, __pred);
24832507}
2484#endif
2508# endif
24852509
24862510template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
24872511_LIBCPP_HIDE_FROM_ABI bool operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
......@@ -2501,7 +2525,7 @@ _LIBCPP_HIDE_FROM_ABI bool operator==(const unordered_multimap<_Key, _Tp, _Hash,
25012525 return true;
25022526}
25032527
2504#if _LIBCPP_STD_VER <= 17
2528# if _LIBCPP_STD_VER <= 17
25052529
25062530template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
25072531inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
......@@ -2509,11 +2533,21 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const unordered_multimap<_Key, _Tp,
25092533 return !(__x == __y);
25102534}
25112535
2512#endif
2536# endif
2537
2538template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2539struct __container_traits<unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc> > {
2540 // http://eel.is/c++draft/unord.req.except#2
2541 // For unordered associative containers, if an exception is thrown by any operation
2542 // other than the container's hash function from within an insert or emplace function
2543 // inserting a single element, the insertion has no effect.
2544 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
2545 __is_nothrow_invocable_v<_Hash, const _Key&>;
2546};
25132547
25142548_LIBCPP_END_NAMESPACE_STD
25152549
2516#if _LIBCPP_STD_VER >= 17
2550# if _LIBCPP_STD_VER >= 17
25172551_LIBCPP_BEGIN_NAMESPACE_STD
25182552namespace pmr {
25192553template <class _KeyT, class _ValueT, class _HashT = std::hash<_KeyT>, class _PredT = std::equal_to<_KeyT>>
......@@ -2525,17 +2559,19 @@ using unordered_multimap _LIBCPP_AVAILABILITY_PMR =
25252559 std::unordered_multimap<_KeyT, _ValueT, _HashT, _PredT, polymorphic_allocator<std::pair<const _KeyT, _ValueT>>>;
25262560} // namespace pmr
25272561_LIBCPP_END_NAMESPACE_STD
2528#endif
2562# endif
25292563
25302564_LIBCPP_POP_MACROS
25312565
2532#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
2533# include <algorithm>
2534# include <bit>
2535# include <concepts>
2536# include <cstdlib>
2537# include <iterator>
2538# include <type_traits>
2539#endif
2566# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
2567# include <algorithm>
2568# include <bit>
2569# include <cmath>
2570# include <concepts>
2571# include <cstdlib>
2572# include <iterator>
2573# include <type_traits>
2574# endif
2575#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
25402576
25412577#endif // _LIBCPP_UNORDERED_MAP
lib/libcxx/include/unordered_set+165-127
......@@ -531,46 +531,62 @@ template <class Value, class Hash, class Pred, class Alloc>
531531
532532// clang-format on
533533
534#include <__algorithm/is_permutation.h>
535#include <__assert>
536#include <__config>
537#include <__functional/is_transparent.h>
538#include <__functional/operations.h>
539#include <__hash_table>
540#include <__iterator/distance.h>
541#include <__iterator/erase_if_container.h>
542#include <__iterator/iterator_traits.h>
543#include <__iterator/ranges_iterator_traits.h>
544#include <__memory/addressof.h>
545#include <__memory/allocator.h>
546#include <__memory_resource/polymorphic_allocator.h>
547#include <__node_handle>
548#include <__ranges/concepts.h>
549#include <__ranges/container_compatible_range.h>
550#include <__ranges/from_range.h>
551#include <__type_traits/is_allocator.h>
552#include <__utility/forward.h>
553#include <version>
534#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
535# include <__cxx03/unordered_set>
536#else
537# include <__algorithm/is_permutation.h>
538# include <__assert>
539# include <__config>
540# include <__functional/hash.h>
541# include <__functional/is_transparent.h>
542# include <__functional/operations.h>
543# include <__hash_table>
544# include <__iterator/distance.h>
545# include <__iterator/erase_if_container.h>
546# include <__iterator/iterator_traits.h>
547# include <__iterator/ranges_iterator_traits.h>
548# include <__memory/addressof.h>
549# include <__memory/allocator.h>
550# include <__memory/allocator_traits.h>
551# include <__memory_resource/polymorphic_allocator.h>
552# include <__node_handle>
553# include <__ranges/concepts.h>
554# include <__ranges/container_compatible_range.h>
555# include <__ranges/from_range.h>
556# include <__type_traits/container_traits.h>
557# include <__type_traits/enable_if.h>
558# include <__type_traits/invoke.h>
559# include <__type_traits/is_allocator.h>
560# include <__type_traits/is_integral.h>
561# include <__type_traits/is_nothrow_assignable.h>
562# include <__type_traits/is_nothrow_constructible.h>
563# include <__type_traits/is_same.h>
564# include <__type_traits/is_swappable.h>
565# include <__type_traits/type_identity.h>
566# include <__utility/forward.h>
567# include <__utility/move.h>
568# include <__utility/pair.h>
569# include <version>
554570
555571// standard-mandated includes
556572
557573// [iterator.range]
558#include <__iterator/access.h>
559#include <__iterator/data.h>
560#include <__iterator/empty.h>
561#include <__iterator/reverse_access.h>
562#include <__iterator/size.h>
574# include <__iterator/access.h>
575# include <__iterator/data.h>
576# include <__iterator/empty.h>
577# include <__iterator/reverse_access.h>
578# include <__iterator/size.h>
563579
564580// [unord.set.syn]
565#include <compare>
566#include <initializer_list>
581# include <compare>
582# include <initializer_list>
567583
568#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
569# pragma GCC system_header
570#endif
584# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
585# pragma GCC system_header
586# endif
571587
572588_LIBCPP_PUSH_MACROS
573#include <__undef_macros>
589# include <__undef_macros>
574590
575591_LIBCPP_BEGIN_NAMESPACE_STD
576592
......@@ -608,10 +624,10 @@ public:
608624 typedef typename __table::const_local_iterator local_iterator;
609625 typedef typename __table::const_local_iterator const_local_iterator;
610626
611#if _LIBCPP_STD_VER >= 17
627# if _LIBCPP_STD_VER >= 17
612628 typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
613629 typedef __insert_return_type<iterator, node_type> insert_return_type;
614#endif
630# endif
615631
616632 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
617633 friend class _LIBCPP_TEMPLATE_VIS unordered_set;
......@@ -621,12 +637,12 @@ public:
621637 _LIBCPP_HIDE_FROM_ABI unordered_set() _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) {}
622638 explicit _LIBCPP_HIDE_FROM_ABI
623639 unordered_set(size_type __n, const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
624#if _LIBCPP_STD_VER >= 14
640# if _LIBCPP_STD_VER >= 14
625641 inline _LIBCPP_HIDE_FROM_ABI unordered_set(size_type __n, const allocator_type& __a)
626642 : unordered_set(__n, hasher(), key_equal(), __a) {}
627643 inline _LIBCPP_HIDE_FROM_ABI unordered_set(size_type __n, const hasher& __hf, const allocator_type& __a)
628644 : unordered_set(__n, __hf, key_equal(), __a) {}
629#endif
645# endif
630646 _LIBCPP_HIDE_FROM_ABI
631647 unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a);
632648 template <class _InputIterator>
......@@ -647,7 +663,7 @@ public:
647663 const key_equal& __eql,
648664 const allocator_type& __a);
649665
650#if _LIBCPP_STD_VER >= 23
666# if _LIBCPP_STD_VER >= 23
651667 template <_ContainerCompatibleRange<value_type> _Range>
652668 _LIBCPP_HIDE_FROM_ABI unordered_set(
653669 from_range_t,
......@@ -662,9 +678,9 @@ public:
662678 }
663679 insert_range(std::forward<_Range>(__range));
664680 }
665#endif
681# endif
666682
667#if _LIBCPP_STD_VER >= 14
683# if _LIBCPP_STD_VER >= 14
668684 template <class _InputIterator>
669685 inline _LIBCPP_HIDE_FROM_ABI
670686 unordered_set(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
......@@ -673,9 +689,9 @@ public:
673689 _LIBCPP_HIDE_FROM_ABI unordered_set(
674690 _InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const allocator_type& __a)
675691 : unordered_set(__first, __last, __n, __hf, key_equal(), __a) {}
676#endif
692# endif
677693
678#if _LIBCPP_STD_VER >= 23
694# if _LIBCPP_STD_VER >= 23
679695 template <_ContainerCompatibleRange<value_type> _Range>
680696 _LIBCPP_HIDE_FROM_ABI unordered_set(from_range_t, _Range&& __range, size_type __n, const allocator_type& __a)
681697 : unordered_set(from_range, std::forward<_Range>(__range), __n, hasher(), key_equal(), __a) {}
......@@ -684,12 +700,12 @@ public:
684700 _LIBCPP_HIDE_FROM_ABI
685701 unordered_set(from_range_t, _Range&& __range, size_type __n, const hasher& __hf, const allocator_type& __a)
686702 : unordered_set(from_range, std::forward<_Range>(__range), __n, __hf, key_equal(), __a) {}
687#endif
703# endif
688704
689705 _LIBCPP_HIDE_FROM_ABI explicit unordered_set(const allocator_type& __a);
690706 _LIBCPP_HIDE_FROM_ABI unordered_set(const unordered_set& __u);
691707 _LIBCPP_HIDE_FROM_ABI unordered_set(const unordered_set& __u, const allocator_type& __a);
692#ifndef _LIBCPP_CXX03_LANG
708# ifndef _LIBCPP_CXX03_LANG
693709 _LIBCPP_HIDE_FROM_ABI unordered_set(unordered_set&& __u) _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
694710 _LIBCPP_HIDE_FROM_ABI unordered_set(unordered_set&& __u, const allocator_type& __a);
695711 _LIBCPP_HIDE_FROM_ABI unordered_set(initializer_list<value_type> __il);
......@@ -704,15 +720,15 @@ public:
704720 const hasher& __hf,
705721 const key_equal& __eql,
706722 const allocator_type& __a);
707# if _LIBCPP_STD_VER >= 14
723# if _LIBCPP_STD_VER >= 14
708724 inline _LIBCPP_HIDE_FROM_ABI
709725 unordered_set(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
710726 : unordered_set(__il, __n, hasher(), key_equal(), __a) {}
711727 inline _LIBCPP_HIDE_FROM_ABI
712728 unordered_set(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a)
713729 : unordered_set(__il, __n, __hf, key_equal(), __a) {}
714# endif
715#endif // _LIBCPP_CXX03_LANG
730# endif
731# endif // _LIBCPP_CXX03_LANG
716732 _LIBCPP_HIDE_FROM_ABI ~unordered_set() {
717733 static_assert(sizeof(std::__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), "");
718734 }
......@@ -721,17 +737,17 @@ public:
721737 __table_ = __u.__table_;
722738 return *this;
723739 }
724#ifndef _LIBCPP_CXX03_LANG
740# ifndef _LIBCPP_CXX03_LANG
725741 _LIBCPP_HIDE_FROM_ABI unordered_set& operator=(unordered_set&& __u)
726742 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
727743 _LIBCPP_HIDE_FROM_ABI unordered_set& operator=(initializer_list<value_type> __il);
728#endif // _LIBCPP_CXX03_LANG
744# endif // _LIBCPP_CXX03_LANG
729745
730746 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT {
731747 return allocator_type(__table_.__node_alloc());
732748 }
733749
734 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __table_.size() == 0; }
750 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __table_.size() == 0; }
735751 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __table_.size(); }
736752 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __table_.max_size(); }
737753
......@@ -742,7 +758,7 @@ public:
742758 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return __table_.begin(); }
743759 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return __table_.end(); }
744760
745#ifndef _LIBCPP_CXX03_LANG
761# ifndef _LIBCPP_CXX03_LANG
746762 template <class... _Args>
747763 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> emplace(_Args&&... __args) {
748764 return __table_.__emplace_unique(std::forward<_Args>(__args)...);
......@@ -758,21 +774,21 @@ public:
758774 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, value_type&& __x) { return insert(std::move(__x)).first; }
759775
760776 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
761#endif // _LIBCPP_CXX03_LANG
777# endif // _LIBCPP_CXX03_LANG
762778 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __x) { return __table_.__insert_unique(__x); }
763779
764780 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x).first; }
765781 template <class _InputIterator>
766782 _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last);
767783
768#if _LIBCPP_STD_VER >= 23
784# if _LIBCPP_STD_VER >= 23
769785 template <_ContainerCompatibleRange<value_type> _Range>
770786 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
771787 for (auto&& __element : __range) {
772788 __table_.__insert_unique(std::forward<decltype(__element)>(__element));
773789 }
774790 }
775#endif
791# endif
776792
777793 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __table_.erase(__p); }
778794 _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __table_.__erase_unique(__k); }
......@@ -781,7 +797,7 @@ public:
781797 }
782798 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __table_.clear(); }
783799
784#if _LIBCPP_STD_VER >= 17
800# if _LIBCPP_STD_VER >= 17
785801 _LIBCPP_HIDE_FROM_ABI insert_return_type insert(node_type&& __nh) {
786802 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
787803 "node_type with incompatible allocator passed to unordered_set::insert()");
......@@ -823,7 +839,7 @@ public:
823839 __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
824840 __table_.__node_handle_merge_unique(__source.__table_);
825841 }
826#endif
842# endif
827843
828844 _LIBCPP_HIDE_FROM_ABI void swap(unordered_set& __u) _NOEXCEPT_(__is_nothrow_swappable_v<__table>) {
829845 __table_.swap(__u.__table_);
......@@ -834,7 +850,7 @@ public:
834850
835851 _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __table_.find(__k); }
836852 _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __table_.find(__k); }
837#if _LIBCPP_STD_VER >= 20
853# if _LIBCPP_STD_VER >= 20
838854 template <class _K2, enable_if_t<__is_transparent_v<hasher, _K2> && __is_transparent_v<key_equal, _K2>>* = nullptr>
839855 _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
840856 return __table_.find(__k);
......@@ -843,24 +859,24 @@ public:
843859 _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
844860 return __table_.find(__k);
845861 }
846#endif // _LIBCPP_STD_VER >= 20
862# endif // _LIBCPP_STD_VER >= 20
847863
848864 _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __table_.__count_unique(__k); }
849#if _LIBCPP_STD_VER >= 20
865# if _LIBCPP_STD_VER >= 20
850866 template <class _K2, enable_if_t<__is_transparent_v<hasher, _K2> && __is_transparent_v<key_equal, _K2>>* = nullptr>
851867 _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
852868 return __table_.__count_unique(__k);
853869 }
854#endif // _LIBCPP_STD_VER >= 20
870# endif // _LIBCPP_STD_VER >= 20
855871
856#if _LIBCPP_STD_VER >= 20
872# if _LIBCPP_STD_VER >= 20
857873 _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
858874
859875 template <class _K2, enable_if_t<__is_transparent_v<hasher, _K2> && __is_transparent_v<key_equal, _K2>>* = nullptr>
860876 _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
861877 return find(__k) != end();
862878 }
863#endif // _LIBCPP_STD_VER >= 20
879# endif // _LIBCPP_STD_VER >= 20
864880
865881 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
866882 return __table_.__equal_range_unique(__k);
......@@ -868,7 +884,7 @@ public:
868884 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
869885 return __table_.__equal_range_unique(__k);
870886 }
871#if _LIBCPP_STD_VER >= 20
887# if _LIBCPP_STD_VER >= 20
872888 template <class _K2, enable_if_t<__is_transparent_v<hasher, _K2> && __is_transparent_v<key_equal, _K2>>* = nullptr>
873889 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
874890 return __table_.__equal_range_unique(__k);
......@@ -877,7 +893,7 @@ public:
877893 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
878894 return __table_.__equal_range_unique(__k);
879895 }
880#endif // _LIBCPP_STD_VER >= 20
896# endif // _LIBCPP_STD_VER >= 20
881897
882898 _LIBCPP_HIDE_FROM_ABI size_type bucket_count() const _NOEXCEPT { return __table_.bucket_count(); }
883899 _LIBCPP_HIDE_FROM_ABI size_type max_bucket_count() const _NOEXCEPT { return __table_.max_bucket_count(); }
......@@ -899,7 +915,7 @@ public:
899915 _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n) { __table_.__reserve_unique(__n); }
900916};
901917
902#if _LIBCPP_STD_VER >= 17
918# if _LIBCPP_STD_VER >= 17
903919template <class _InputIterator,
904920 class _Hash = hash<__iter_value_type<_InputIterator>>,
905921 class _Pred = equal_to<__iter_value_type<_InputIterator>>,
......@@ -916,7 +932,7 @@ unordered_set(_InputIterator,
916932 _Pred = _Pred(),
917933 _Allocator = _Allocator()) -> unordered_set<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
918934
919# if _LIBCPP_STD_VER >= 23
935# if _LIBCPP_STD_VER >= 23
920936template <ranges::input_range _Range,
921937 class _Hash = hash<ranges::range_value_t<_Range>>,
922938 class _Pred = equal_to<ranges::range_value_t<_Range>>,
......@@ -932,7 +948,7 @@ unordered_set(
932948 _Hash = _Hash(),
933949 _Pred = _Pred(),
934950 _Allocator = _Allocator()) -> unordered_set<ranges::range_value_t<_Range>, _Hash, _Pred, _Allocator>; // C++23
935# endif
951# endif
936952
937953template <class _Tp,
938954 class _Hash = hash<_Tp>,
......@@ -968,7 +984,7 @@ template <class _InputIterator,
968984unordered_set(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
969985 -> unordered_set<__iter_value_type<_InputIterator>, _Hash, equal_to<__iter_value_type<_InputIterator>>, _Allocator>;
970986
971# if _LIBCPP_STD_VER >= 23
987# if _LIBCPP_STD_VER >= 23
972988
973989template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value>>
974990unordered_set(from_range_t, _Range&&, typename allocator_traits<_Allocator>::size_type, _Allocator)
......@@ -993,7 +1009,7 @@ template <ranges::input_range _Range,
9931009unordered_set(from_range_t, _Range&&, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
9941010 -> unordered_set<ranges::range_value_t<_Range>, _Hash, equal_to<ranges::range_value_t<_Range>>, _Allocator>;
9951011
996# endif
1012# endif
9971013
9981014template <class _Tp, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value>>
9991015unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
......@@ -1007,7 +1023,7 @@ template <class _Tp,
10071023 class = enable_if_t<__is_allocator<_Allocator>::value>>
10081024unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
10091025 -> unordered_set<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
1010#endif
1026# endif
10111027
10121028template <class _Value, class _Hash, class _Pred, class _Alloc>
10131029unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql)
......@@ -1067,7 +1083,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(const unordered_set&
10671083 insert(__u.begin(), __u.end());
10681084}
10691085
1070#ifndef _LIBCPP_CXX03_LANG
1086# ifndef _LIBCPP_CXX03_LANG
10711087
10721088template <class _Value, class _Hash, class _Pred, class _Alloc>
10731089inline unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(unordered_set&& __u)
......@@ -1124,7 +1140,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(initializer_list<value_ty
11241140 return *this;
11251141}
11261142
1127#endif // _LIBCPP_CXX03_LANG
1143# endif // _LIBCPP_CXX03_LANG
11281144
11291145template <class _Value, class _Hash, class _Pred, class _Alloc>
11301146template <class _InputIterator>
......@@ -1140,13 +1156,13 @@ swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, unordered_set<_Value, _Ha
11401156 __x.swap(__y);
11411157}
11421158
1143#if _LIBCPP_STD_VER >= 20
1159# if _LIBCPP_STD_VER >= 20
11441160template <class _Value, class _Hash, class _Pred, class _Alloc, class _Predicate>
11451161inline _LIBCPP_HIDE_FROM_ABI typename unordered_set<_Value, _Hash, _Pred, _Alloc>::size_type
11461162erase_if(unordered_set<_Value, _Hash, _Pred, _Alloc>& __c, _Predicate __pred) {
11471163 return std::__libcpp_erase_if_container(__c, __pred);
11481164}
1149#endif
1165# endif
11501166
11511167template <class _Value, class _Hash, class _Pred, class _Alloc>
11521168_LIBCPP_HIDE_FROM_ABI bool operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
......@@ -1162,7 +1178,7 @@ _LIBCPP_HIDE_FROM_ABI bool operator==(const unordered_set<_Value, _Hash, _Pred,
11621178 return true;
11631179}
11641180
1165#if _LIBCPP_STD_VER <= 17
1181# if _LIBCPP_STD_VER <= 17
11661182
11671183template <class _Value, class _Hash, class _Pred, class _Alloc>
11681184inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
......@@ -1170,7 +1186,17 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const unordered_set<_Value, _Hash,
11701186 return !(__x == __y);
11711187}
11721188
1173#endif
1189# endif
1190
1191template <class _Value, class _Hash, class _Pred, class _Alloc>
1192struct __container_traits<unordered_set<_Value, _Hash, _Pred, _Alloc> > {
1193 // http://eel.is/c++draft/unord.req.except#2
1194 // For unordered associative containers, if an exception is thrown by any operation
1195 // other than the container's hash function from within an insert or emplace function
1196 // inserting a single element, the insertion has no effect.
1197 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
1198 __is_nothrow_invocable_v<_Hash, const _Value&>;
1199};
11741200
11751201template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, class _Alloc = allocator<_Value> >
11761202class _LIBCPP_TEMPLATE_VIS unordered_multiset {
......@@ -1202,9 +1228,9 @@ public:
12021228 typedef typename __table::const_local_iterator local_iterator;
12031229 typedef typename __table::const_local_iterator const_local_iterator;
12041230
1205#if _LIBCPP_STD_VER >= 17
1231# if _LIBCPP_STD_VER >= 17
12061232 typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
1207#endif
1233# endif
12081234
12091235 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
12101236 friend class _LIBCPP_TEMPLATE_VIS unordered_set;
......@@ -1216,12 +1242,12 @@ public:
12161242 unordered_multiset(size_type __n, const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
12171243 _LIBCPP_HIDE_FROM_ABI
12181244 unordered_multiset(size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a);
1219#if _LIBCPP_STD_VER >= 14
1245# if _LIBCPP_STD_VER >= 14
12201246 inline _LIBCPP_HIDE_FROM_ABI unordered_multiset(size_type __n, const allocator_type& __a)
12211247 : unordered_multiset(__n, hasher(), key_equal(), __a) {}
12221248 inline _LIBCPP_HIDE_FROM_ABI unordered_multiset(size_type __n, const hasher& __hf, const allocator_type& __a)
12231249 : unordered_multiset(__n, __hf, key_equal(), __a) {}
1224#endif
1250# endif
12251251 template <class _InputIterator>
12261252 _LIBCPP_HIDE_FROM_ABI unordered_multiset(_InputIterator __first, _InputIterator __last);
12271253 template <class _InputIterator>
......@@ -1240,7 +1266,7 @@ public:
12401266 const key_equal& __eql,
12411267 const allocator_type& __a);
12421268
1243#if _LIBCPP_STD_VER >= 23
1269# if _LIBCPP_STD_VER >= 23
12441270 template <_ContainerCompatibleRange<value_type> _Range>
12451271 _LIBCPP_HIDE_FROM_ABI unordered_multiset(
12461272 from_range_t,
......@@ -1255,9 +1281,9 @@ public:
12551281 }
12561282 insert_range(std::forward<_Range>(__range));
12571283 }
1258#endif
1284# endif
12591285
1260#if _LIBCPP_STD_VER >= 14
1286# if _LIBCPP_STD_VER >= 14
12611287 template <class _InputIterator>
12621288 inline _LIBCPP_HIDE_FROM_ABI
12631289 unordered_multiset(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
......@@ -1266,9 +1292,9 @@ public:
12661292 inline _LIBCPP_HIDE_FROM_ABI unordered_multiset(
12671293 _InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const allocator_type& __a)
12681294 : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {}
1269#endif
1295# endif
12701296
1271#if _LIBCPP_STD_VER >= 23
1297# if _LIBCPP_STD_VER >= 23
12721298 template <_ContainerCompatibleRange<value_type> _Range>
12731299 _LIBCPP_HIDE_FROM_ABI unordered_multiset(from_range_t, _Range&& __range, size_type __n, const allocator_type& __a)
12741300 : unordered_multiset(from_range, std::forward<_Range>(__range), __n, hasher(), key_equal(), __a) {}
......@@ -1277,12 +1303,12 @@ public:
12771303 _LIBCPP_HIDE_FROM_ABI
12781304 unordered_multiset(from_range_t, _Range&& __range, size_type __n, const hasher& __hf, const allocator_type& __a)
12791305 : unordered_multiset(from_range, std::forward<_Range>(__range), __n, __hf, key_equal(), __a) {}
1280#endif
1306# endif
12811307
12821308 _LIBCPP_HIDE_FROM_ABI explicit unordered_multiset(const allocator_type& __a);
12831309 _LIBCPP_HIDE_FROM_ABI unordered_multiset(const unordered_multiset& __u);
12841310 _LIBCPP_HIDE_FROM_ABI unordered_multiset(const unordered_multiset& __u, const allocator_type& __a);
1285#ifndef _LIBCPP_CXX03_LANG
1311# ifndef _LIBCPP_CXX03_LANG
12861312 _LIBCPP_HIDE_FROM_ABI unordered_multiset(unordered_multiset&& __u)
12871313 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
12881314 _LIBCPP_HIDE_FROM_ABI unordered_multiset(unordered_multiset&& __u, const allocator_type& __a);
......@@ -1298,15 +1324,15 @@ public:
12981324 const hasher& __hf,
12991325 const key_equal& __eql,
13001326 const allocator_type& __a);
1301# if _LIBCPP_STD_VER >= 14
1327# if _LIBCPP_STD_VER >= 14
13021328 inline _LIBCPP_HIDE_FROM_ABI
13031329 unordered_multiset(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
13041330 : unordered_multiset(__il, __n, hasher(), key_equal(), __a) {}
13051331 inline _LIBCPP_HIDE_FROM_ABI
13061332 unordered_multiset(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a)
13071333 : unordered_multiset(__il, __n, __hf, key_equal(), __a) {}
1308# endif
1309#endif // _LIBCPP_CXX03_LANG
1334# endif
1335# endif // _LIBCPP_CXX03_LANG
13101336 _LIBCPP_HIDE_FROM_ABI ~unordered_multiset() {
13111337 static_assert(sizeof(std::__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), "");
13121338 }
......@@ -1315,17 +1341,17 @@ public:
13151341 __table_ = __u.__table_;
13161342 return *this;
13171343 }
1318#ifndef _LIBCPP_CXX03_LANG
1344# ifndef _LIBCPP_CXX03_LANG
13191345 _LIBCPP_HIDE_FROM_ABI unordered_multiset& operator=(unordered_multiset&& __u)
13201346 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
13211347 _LIBCPP_HIDE_FROM_ABI unordered_multiset& operator=(initializer_list<value_type> __il);
1322#endif // _LIBCPP_CXX03_LANG
1348# endif // _LIBCPP_CXX03_LANG
13231349
13241350 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT {
13251351 return allocator_type(__table_.__node_alloc());
13261352 }
13271353
1328 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __table_.size() == 0; }
1354 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __table_.size() == 0; }
13291355 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __table_.size(); }
13301356 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __table_.max_size(); }
13311357
......@@ -1336,7 +1362,7 @@ public:
13361362 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return __table_.begin(); }
13371363 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return __table_.end(); }
13381364
1339#ifndef _LIBCPP_CXX03_LANG
1365# ifndef _LIBCPP_CXX03_LANG
13401366 template <class... _Args>
13411367 _LIBCPP_HIDE_FROM_ABI iterator emplace(_Args&&... __args) {
13421368 return __table_.__emplace_multi(std::forward<_Args>(__args)...);
......@@ -1351,7 +1377,7 @@ public:
13511377 return __table_.__insert_multi(__p, std::move(__x));
13521378 }
13531379 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
1354#endif // _LIBCPP_CXX03_LANG
1380# endif // _LIBCPP_CXX03_LANG
13551381
13561382 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__insert_multi(__x); }
13571383
......@@ -1362,16 +1388,16 @@ public:
13621388 template <class _InputIterator>
13631389 _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last);
13641390
1365#if _LIBCPP_STD_VER >= 23
1391# if _LIBCPP_STD_VER >= 23
13661392 template <_ContainerCompatibleRange<value_type> _Range>
13671393 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
13681394 for (auto&& __element : __range) {
13691395 __table_.__insert_multi(std::forward<decltype(__element)>(__element));
13701396 }
13711397 }
1372#endif
1398# endif
13731399
1374#if _LIBCPP_STD_VER >= 17
1400# if _LIBCPP_STD_VER >= 17
13751401 _LIBCPP_HIDE_FROM_ABI iterator insert(node_type&& __nh) {
13761402 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
13771403 "node_type with incompatible allocator passed to unordered_multiset::insert()");
......@@ -1413,7 +1439,7 @@ public:
14131439 __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
14141440 return __table_.__node_handle_merge_multi(__source.__table_);
14151441 }
1416#endif
1442# endif
14171443
14181444 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __table_.erase(__p); }
14191445 _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __table_.__erase_multi(__k); }
......@@ -1431,7 +1457,7 @@ public:
14311457
14321458 _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __table_.find(__k); }
14331459 _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __table_.find(__k); }
1434#if _LIBCPP_STD_VER >= 20
1460# if _LIBCPP_STD_VER >= 20
14351461 template <class _K2, enable_if_t<__is_transparent_v<hasher, _K2> && __is_transparent_v<key_equal, _K2>>* = nullptr>
14361462 _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
14371463 return __table_.find(__k);
......@@ -1440,24 +1466,24 @@ public:
14401466 _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
14411467 return __table_.find(__k);
14421468 }
1443#endif // _LIBCPP_STD_VER >= 20
1469# endif // _LIBCPP_STD_VER >= 20
14441470
14451471 _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __table_.__count_multi(__k); }
1446#if _LIBCPP_STD_VER >= 20
1472# if _LIBCPP_STD_VER >= 20
14471473 template <class _K2, enable_if_t<__is_transparent_v<hasher, _K2> && __is_transparent_v<key_equal, _K2>>* = nullptr>
14481474 _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
14491475 return __table_.__count_multi(__k);
14501476 }
1451#endif // _LIBCPP_STD_VER >= 20
1477# endif // _LIBCPP_STD_VER >= 20
14521478
1453#if _LIBCPP_STD_VER >= 20
1479# if _LIBCPP_STD_VER >= 20
14541480 _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
14551481
14561482 template <class _K2, enable_if_t<__is_transparent_v<hasher, _K2> && __is_transparent_v<key_equal, _K2>>* = nullptr>
14571483 _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
14581484 return find(__k) != end();
14591485 }
1460#endif // _LIBCPP_STD_VER >= 20
1486# endif // _LIBCPP_STD_VER >= 20
14611487
14621488 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
14631489 return __table_.__equal_range_multi(__k);
......@@ -1465,7 +1491,7 @@ public:
14651491 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
14661492 return __table_.__equal_range_multi(__k);
14671493 }
1468#if _LIBCPP_STD_VER >= 20
1494# if _LIBCPP_STD_VER >= 20
14691495 template <class _K2, enable_if_t<__is_transparent_v<hasher, _K2> && __is_transparent_v<key_equal, _K2>>* = nullptr>
14701496 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
14711497 return __table_.__equal_range_multi(__k);
......@@ -1474,7 +1500,7 @@ public:
14741500 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
14751501 return __table_.__equal_range_multi(__k);
14761502 }
1477#endif // _LIBCPP_STD_VER >= 20
1503# endif // _LIBCPP_STD_VER >= 20
14781504
14791505 _LIBCPP_HIDE_FROM_ABI size_type bucket_count() const _NOEXCEPT { return __table_.bucket_count(); }
14801506 _LIBCPP_HIDE_FROM_ABI size_type max_bucket_count() const _NOEXCEPT { return __table_.max_bucket_count(); }
......@@ -1496,7 +1522,7 @@ public:
14961522 _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n) { __table_.__reserve_multi(__n); }
14971523};
14981524
1499#if _LIBCPP_STD_VER >= 17
1525# if _LIBCPP_STD_VER >= 17
15001526template <class _InputIterator,
15011527 class _Hash = hash<__iter_value_type<_InputIterator>>,
15021528 class _Pred = equal_to<__iter_value_type<_InputIterator>>,
......@@ -1514,7 +1540,7 @@ unordered_multiset(
15141540 _Pred = _Pred(),
15151541 _Allocator = _Allocator()) -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
15161542
1517# if _LIBCPP_STD_VER >= 23
1543# if _LIBCPP_STD_VER >= 23
15181544template <ranges::input_range _Range,
15191545 class _Hash = hash<ranges::range_value_t<_Range>>,
15201546 class _Pred = equal_to<ranges::range_value_t<_Range>>,
......@@ -1530,7 +1556,7 @@ unordered_multiset(
15301556 _Hash = _Hash(),
15311557 _Pred = _Pred(),
15321558 _Allocator = _Allocator()) -> unordered_multiset<ranges::range_value_t<_Range>, _Hash, _Pred, _Allocator>; // C++23
1533# endif
1559# endif
15341560
15351561template <class _Tp,
15361562 class _Hash = hash<_Tp>,
......@@ -1569,7 +1595,7 @@ unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Al
15691595 equal_to<__iter_value_type<_InputIterator>>,
15701596 _Allocator>;
15711597
1572# if _LIBCPP_STD_VER >= 23
1598# if _LIBCPP_STD_VER >= 23
15731599
15741600template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value>>
15751601unordered_multiset(from_range_t, _Range&&, typename allocator_traits<_Allocator>::size_type, _Allocator)
......@@ -1594,7 +1620,7 @@ template <ranges::input_range _Range,
15941620unordered_multiset(from_range_t, _Range&&, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
15951621 -> unordered_multiset<ranges::range_value_t<_Range>, _Hash, equal_to<ranges::range_value_t<_Range>>, _Allocator>;
15961622
1597# endif
1623# endif
15981624
15991625template <class _Tp, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value>>
16001626unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
......@@ -1608,7 +1634,7 @@ template <class _Tp,
16081634 class = enable_if_t<__is_allocator<_Allocator>::value>>
16091635unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
16101636 -> unordered_multiset<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
1611#endif
1637# endif
16121638
16131639template <class _Value, class _Hash, class _Pred, class _Alloc>
16141640unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
......@@ -1672,7 +1698,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
16721698 insert(__u.begin(), __u.end());
16731699}
16741700
1675#ifndef _LIBCPP_CXX03_LANG
1701# ifndef _LIBCPP_CXX03_LANG
16761702
16771703template <class _Value, class _Hash, class _Pred, class _Alloc>
16781704inline unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(unordered_multiset&& __u)
......@@ -1730,7 +1756,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(initializer_list<val
17301756 return *this;
17311757}
17321758
1733#endif // _LIBCPP_CXX03_LANG
1759# endif // _LIBCPP_CXX03_LANG
17341760
17351761template <class _Value, class _Hash, class _Pred, class _Alloc>
17361762template <class _InputIterator>
......@@ -1746,13 +1772,13 @@ swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, unordered_multiset<_
17461772 __x.swap(__y);
17471773}
17481774
1749#if _LIBCPP_STD_VER >= 20
1775# if _LIBCPP_STD_VER >= 20
17501776template <class _Value, class _Hash, class _Pred, class _Alloc, class _Predicate>
17511777inline _LIBCPP_HIDE_FROM_ABI typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::size_type
17521778erase_if(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __c, _Predicate __pred) {
17531779 return std::__libcpp_erase_if_container(__c, __pred);
17541780}
1755#endif
1781# endif
17561782
17571783template <class _Value, class _Hash, class _Pred, class _Alloc>
17581784_LIBCPP_HIDE_FROM_ABI bool operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
......@@ -1772,7 +1798,7 @@ _LIBCPP_HIDE_FROM_ABI bool operator==(const unordered_multiset<_Value, _Hash, _P
17721798 return true;
17731799}
17741800
1775#if _LIBCPP_STD_VER <= 17
1801# if _LIBCPP_STD_VER <= 17
17761802
17771803template <class _Value, class _Hash, class _Pred, class _Alloc>
17781804inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
......@@ -1780,11 +1806,21 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const unordered_multiset<_Value, _H
17801806 return !(__x == __y);
17811807}
17821808
1783#endif
1809# endif
1810
1811template <class _Value, class _Hash, class _Pred, class _Alloc>
1812struct __container_traits<unordered_multiset<_Value, _Hash, _Pred, _Alloc> > {
1813 // http://eel.is/c++draft/unord.req.except#2
1814 // For unordered associative containers, if an exception is thrown by any operation
1815 // other than the container's hash function from within an insert or emplace function
1816 // inserting a single element, the insertion has no effect.
1817 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
1818 __is_nothrow_invocable_v<_Hash, const _Value&>;
1819};
17841820
17851821_LIBCPP_END_NAMESPACE_STD
17861822
1787#if _LIBCPP_STD_VER >= 17
1823# if _LIBCPP_STD_VER >= 17
17881824_LIBCPP_BEGIN_NAMESPACE_STD
17891825namespace pmr {
17901826template <class _KeyT, class _HashT = std::hash<_KeyT>, class _PredT = std::equal_to<_KeyT>>
......@@ -1795,17 +1831,19 @@ using unordered_multiset _LIBCPP_AVAILABILITY_PMR =
17951831 std::unordered_multiset<_KeyT, _HashT, _PredT, polymorphic_allocator<_KeyT>>;
17961832} // namespace pmr
17971833_LIBCPP_END_NAMESPACE_STD
1798#endif
1834# endif
17991835
18001836_LIBCPP_POP_MACROS
18011837
1802#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1803# include <concepts>
1804# include <cstdlib>
1805# include <functional>
1806# include <iterator>
1807# include <stdexcept>
1808# include <type_traits>
1809#endif
1838# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1839# include <cmath>
1840# include <concepts>
1841# include <cstdlib>
1842# include <functional>
1843# include <iterator>
1844# include <stdexcept>
1845# include <type_traits>
1846# endif
1847#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
18101848
18111849#endif // _LIBCPP_UNORDERED_SET
lib/libcxx/include/utility+55-50
......@@ -246,64 +246,69 @@ template <class T>
246246
247247*/
248248
249#include <__config>
250
251#include <__utility/declval.h>
252#include <__utility/forward.h>
253#include <__utility/move.h>
254#include <__utility/pair.h>
255#include <__utility/piecewise_construct.h>
256#include <__utility/rel_ops.h>
257#include <__utility/swap.h>
258
259#if _LIBCPP_STD_VER >= 14
260# include <__utility/exchange.h>
261# include <__utility/integer_sequence.h>
262#endif
263
264#if _LIBCPP_STD_VER >= 17
265# include <__utility/as_const.h>
266# include <__utility/in_place.h>
267#endif
268
269#if _LIBCPP_STD_VER >= 20
270# include <__utility/cmp.h>
271#endif
272
273#if _LIBCPP_STD_VER >= 23
274# include <__utility/forward_like.h>
275# include <__utility/to_underlying.h>
276# include <__utility/unreachable.h>
277#endif
278
279#include <version>
249#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
250# include <__cxx03/utility>
251#else
252# include <__config>
253
254# include <__utility/declval.h>
255# include <__utility/forward.h>
256# include <__utility/move.h>
257# include <__utility/pair.h>
258# include <__utility/piecewise_construct.h>
259# include <__utility/rel_ops.h>
260# include <__utility/swap.h>
261
262# if _LIBCPP_STD_VER >= 14
263# include <__utility/exchange.h>
264# include <__utility/integer_sequence.h>
265# endif
266
267# if _LIBCPP_STD_VER >= 17
268# include <__utility/as_const.h>
269# include <__utility/in_place.h>
270# endif
271
272# if _LIBCPP_STD_VER >= 20
273# include <__utility/cmp.h>
274# endif
275
276# if _LIBCPP_STD_VER >= 23
277# include <__utility/forward_like.h>
278# include <__utility/to_underlying.h>
279# include <__utility/unreachable.h>
280# endif
281
282# include <version>
280283
281284// standard-mandated includes
282285
283286// [utility.syn]
284#include <compare>
285#include <initializer_list>
287# include <compare>
288# include <initializer_list>
286289
287290// [tuple.creation]
288291
289#include <__tuple/ignore.h>
292# include <__tuple/ignore.h>
290293
291294// [tuple.helper]
292#include <__tuple/tuple_element.h>
293#include <__tuple/tuple_size.h>
294
295#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
296# pragma GCC system_header
297#endif
298
299#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
300# include <limits>
301#endif
302
303#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
304# include <cstdlib>
305# include <iosfwd>
306# include <type_traits>
307#endif
295# include <__tuple/tuple_element.h>
296# include <__tuple/tuple_size.h>
297
298# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
299# pragma GCC system_header
300# endif
301
302# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
303# include <limits>
304# endif
305
306# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
307# include <cstddef>
308# include <cstdlib>
309# include <iosfwd>
310# include <type_traits>
311# endif
312#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
308313
309314#endif // _LIBCPP_UTILITY
lib/libcxx/include/valarray+114-105
......@@ -343,39 +343,41 @@ template <class T> unspecified2 end(const valarray<T>& v);
343343
344344*/
345345
346#include <__algorithm/copy.h>
347#include <__algorithm/count.h>
348#include <__algorithm/fill.h>
349#include <__algorithm/max_element.h>
350#include <__algorithm/min.h>
351#include <__algorithm/min_element.h>
352#include <__algorithm/unwrap_iter.h>
353#include <__assert>
354#include <__config>
355#include <__functional/operations.h>
356#include <__memory/addressof.h>
357#include <__memory/allocator.h>
358#include <__memory/uninitialized_algorithms.h>
359#include <__type_traits/decay.h>
360#include <__type_traits/remove_reference.h>
361#include <__utility/move.h>
362#include <__utility/swap.h>
363#include <cmath>
364#include <cstddef>
365#include <new>
366#include <version>
346#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
347# include <__cxx03/valarray>
348#else
349# include <__algorithm/copy.h>
350# include <__algorithm/count.h>
351# include <__algorithm/fill.h>
352# include <__algorithm/max_element.h>
353# include <__algorithm/min.h>
354# include <__algorithm/min_element.h>
355# include <__algorithm/unwrap_iter.h>
356# include <__assert>
357# include <__config>
358# include <__cstddef/ptrdiff_t.h>
359# include <__functional/operations.h>
360# include <__memory/addressof.h>
361# include <__memory/allocator.h>
362# include <__memory/uninitialized_algorithms.h>
363# include <__type_traits/decay.h>
364# include <__type_traits/remove_reference.h>
365# include <__utility/move.h>
366# include <__utility/swap.h>
367# include <cmath>
368# include <version>
367369
368370// standard-mandated includes
369371
370372// [valarray.syn]
371#include <initializer_list>
373# include <initializer_list>
372374
373#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
374# pragma GCC system_header
375#endif
375# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
376# pragma GCC system_header
377# endif
376378
377379_LIBCPP_PUSH_MACROS
378#include <__undef_macros>
380# include <__undef_macros>
379381
380382_LIBCPP_BEGIN_NAMESPACE_STD
381383
......@@ -397,13 +399,13 @@ public:
397399 _LIBCPP_HIDE_FROM_ABI size_t size() const { return __size_; }
398400 _LIBCPP_HIDE_FROM_ABI size_t stride() const { return __stride_; }
399401
400#if _LIBCPP_STD_VER >= 20
402# if _LIBCPP_STD_VER >= 20
401403
402404 _LIBCPP_HIDE_FROM_ABI friend bool operator==(const slice& __x, const slice& __y) {
403405 return __x.start() == __y.start() && __x.size() == __y.size() && __x.stride() == __y.stride();
404406 }
405407
406#endif
408# endif
407409};
408410
409411template <class _Tp>
......@@ -794,10 +796,10 @@ public:
794796 _LIBCPP_HIDE_FROM_ABI valarray(const value_type& __x, size_t __n);
795797 valarray(const value_type* __p, size_t __n);
796798 valarray(const valarray& __v);
797#ifndef _LIBCPP_CXX03_LANG
799# ifndef _LIBCPP_CXX03_LANG
798800 _LIBCPP_HIDE_FROM_ABI valarray(valarray&& __v) _NOEXCEPT;
799801 valarray(initializer_list<value_type> __il);
800#endif // _LIBCPP_CXX03_LANG
802# endif // _LIBCPP_CXX03_LANG
801803 valarray(const slice_array<value_type>& __sa);
802804 valarray(const gslice_array<value_type>& __ga);
803805 valarray(const mask_array<value_type>& __ma);
......@@ -806,10 +808,10 @@ public:
806808
807809 // assignment:
808810 valarray& operator=(const valarray& __v);
809#ifndef _LIBCPP_CXX03_LANG
811# ifndef _LIBCPP_CXX03_LANG
810812 _LIBCPP_HIDE_FROM_ABI valarray& operator=(valarray&& __v) _NOEXCEPT;
811813 _LIBCPP_HIDE_FROM_ABI valarray& operator=(initializer_list<value_type>);
812#endif // _LIBCPP_CXX03_LANG
814# endif // _LIBCPP_CXX03_LANG
813815 _LIBCPP_HIDE_FROM_ABI valarray& operator=(const value_type& __x);
814816 _LIBCPP_HIDE_FROM_ABI valarray& operator=(const slice_array<value_type>& __sa);
815817 _LIBCPP_HIDE_FROM_ABI valarray& operator=(const gslice_array<value_type>& __ga);
......@@ -819,31 +821,37 @@ public:
819821 _LIBCPP_HIDE_FROM_ABI valarray& operator=(const __val_expr<_ValExpr>& __v);
820822
821823 // element access:
822 _LIBCPP_HIDE_FROM_ABI const value_type& operator[](size_t __i) const { return __begin_[__i]; }
824 _LIBCPP_HIDE_FROM_ABI const value_type& operator[](size_t __i) const {
825 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < size(), "valarray::operator[] index out of bounds");
826 return __begin_[__i];
827 }
823828
824 _LIBCPP_HIDE_FROM_ABI value_type& operator[](size_t __i) { return __begin_[__i]; }
829 _LIBCPP_HIDE_FROM_ABI value_type& operator[](size_t __i) {
830 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < size(), "valarray::operator[] index out of bounds");
831 return __begin_[__i];
832 }
825833
826834 // subset operations:
827835 _LIBCPP_HIDE_FROM_ABI __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const;
828836 _LIBCPP_HIDE_FROM_ABI slice_array<value_type> operator[](slice __s);
829837 _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
830838 _LIBCPP_HIDE_FROM_ABI gslice_array<value_type> operator[](const gslice& __gs);
831#ifndef _LIBCPP_CXX03_LANG
839# ifndef _LIBCPP_CXX03_LANG
832840 _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
833841 _LIBCPP_HIDE_FROM_ABI gslice_array<value_type> operator[](gslice&& __gs);
834#endif // _LIBCPP_CXX03_LANG
842# endif // _LIBCPP_CXX03_LANG
835843 _LIBCPP_HIDE_FROM_ABI __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const;
836844 _LIBCPP_HIDE_FROM_ABI mask_array<value_type> operator[](const valarray<bool>& __vb);
837#ifndef _LIBCPP_CXX03_LANG
845# ifndef _LIBCPP_CXX03_LANG
838846 _LIBCPP_HIDE_FROM_ABI __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const;
839847 _LIBCPP_HIDE_FROM_ABI mask_array<value_type> operator[](valarray<bool>&& __vb);
840#endif // _LIBCPP_CXX03_LANG
848# endif // _LIBCPP_CXX03_LANG
841849 _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
842850 _LIBCPP_HIDE_FROM_ABI indirect_array<value_type> operator[](const valarray<size_t>& __vs);
843#ifndef _LIBCPP_CXX03_LANG
851# ifndef _LIBCPP_CXX03_LANG
844852 _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
845853 _LIBCPP_HIDE_FROM_ABI indirect_array<value_type> operator[](valarray<size_t>&& __vs);
846#endif // _LIBCPP_CXX03_LANG
854# endif // _LIBCPP_CXX03_LANG
847855
848856 // unary operators:
849857 _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__unary_plus<_Tp>, const valarray&> > operator+() const;
......@@ -942,10 +950,10 @@ private:
942950 valarray& __assign_range(const value_type* __f, const value_type* __l);
943951};
944952
945#if _LIBCPP_STD_VER >= 17
953# if _LIBCPP_STD_VER >= 17
946954template <class _Tp, size_t _Size>
947955valarray(const _Tp (&)[_Size], size_t) -> valarray<_Tp>;
948#endif
956# endif
949957
950958template <class _Expr,
951959 __enable_if_t<__is_val_expr<_Expr>::value && __val_expr_use_member_functions<_Expr>::value, int> = 0>
......@@ -1221,7 +1229,7 @@ public:
12211229 __init(__start);
12221230 }
12231231
1224#ifndef _LIBCPP_CXX03_LANG
1232# ifndef _LIBCPP_CXX03_LANG
12251233
12261234 _LIBCPP_HIDE_FROM_ABI gslice(size_t __start, const valarray<size_t>& __size, valarray<size_t>&& __stride)
12271235 : __size_(__size), __stride_(std::move(__stride)) {
......@@ -1238,7 +1246,7 @@ public:
12381246 __init(__start);
12391247 }
12401248
1241#endif // _LIBCPP_CXX03_LANG
1249# endif // _LIBCPP_CXX03_LANG
12421250
12431251 _LIBCPP_HIDE_FROM_ABI size_t start() const { return __1d_.size() ? __1d_[0] : 0; }
12441252
......@@ -1318,10 +1326,10 @@ private:
13181326 gslice_array(const gslice& __gs, const valarray<value_type>& __v)
13191327 : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(__gs.__1d_) {}
13201328
1321#ifndef _LIBCPP_CXX03_LANG
1329# ifndef _LIBCPP_CXX03_LANG
13221330 gslice_array(gslice&& __gs, const valarray<value_type>& __v)
13231331 : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(std::move(__gs.__1d_)) {}
1324#endif // _LIBCPP_CXX03_LANG
1332# endif // _LIBCPP_CXX03_LANG
13251333
13261334 template <class>
13271335 friend class valarray;
......@@ -1708,12 +1716,12 @@ private:
17081716 _LIBCPP_HIDE_FROM_ABI indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
17091717 : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(__ia) {}
17101718
1711#ifndef _LIBCPP_CXX03_LANG
1719# ifndef _LIBCPP_CXX03_LANG
17121720
17131721 _LIBCPP_HIDE_FROM_ABI indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
17141722 : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(std::move(__ia)) {}
17151723
1716#endif // _LIBCPP_CXX03_LANG
1724# endif // _LIBCPP_CXX03_LANG
17171725
17181726 template <class>
17191727 friend class valarray;
......@@ -1837,12 +1845,12 @@ private:
18371845
18381846 _LIBCPP_HIDE_FROM_ABI __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e) : __expr_(__e), __1d_(__ia) {}
18391847
1840#ifndef _LIBCPP_CXX03_LANG
1848# ifndef _LIBCPP_CXX03_LANG
18411849
18421850 _LIBCPP_HIDE_FROM_ABI __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
18431851 : __expr_(__e), __1d_(std::move(__ia)) {}
18441852
1845#endif // _LIBCPP_CXX03_LANG
1853# endif // _LIBCPP_CXX03_LANG
18461854
18471855public:
18481856 _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __expr_[__1d_[__i]]; }
......@@ -1984,17 +1992,17 @@ template <class _Tp>
19841992inline valarray<_Tp>::valarray(size_t __n) : __begin_(nullptr), __end_(nullptr) {
19851993 if (__n) {
19861994 __begin_ = __end_ = allocator<value_type>().allocate(__n);
1987#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1995# if _LIBCPP_HAS_EXCEPTIONS
19881996 try {
1989#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1997# endif // _LIBCPP_HAS_EXCEPTIONS
19901998 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
19911999 ::new ((void*)__end_) value_type();
1992#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2000# if _LIBCPP_HAS_EXCEPTIONS
19932001 } catch (...) {
19942002 __clear(__n);
19952003 throw;
19962004 }
1997#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2005# endif // _LIBCPP_HAS_EXCEPTIONS
19982006 }
19992007}
20002008
......@@ -2007,17 +2015,17 @@ template <class _Tp>
20072015valarray<_Tp>::valarray(const value_type* __p, size_t __n) : __begin_(nullptr), __end_(nullptr) {
20082016 if (__n) {
20092017 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2010#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2018# if _LIBCPP_HAS_EXCEPTIONS
20112019 try {
2012#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2020# endif // _LIBCPP_HAS_EXCEPTIONS
20132021 for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left)
20142022 ::new ((void*)__end_) value_type(*__p);
2015#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2023# if _LIBCPP_HAS_EXCEPTIONS
20162024 } catch (...) {
20172025 __clear(__n);
20182026 throw;
20192027 }
2020#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2028# endif // _LIBCPP_HAS_EXCEPTIONS
20212029 }
20222030}
20232031
......@@ -2025,21 +2033,21 @@ template <class _Tp>
20252033valarray<_Tp>::valarray(const valarray& __v) : __begin_(nullptr), __end_(nullptr) {
20262034 if (__v.size()) {
20272035 __begin_ = __end_ = allocator<value_type>().allocate(__v.size());
2028#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2036# if _LIBCPP_HAS_EXCEPTIONS
20292037 try {
2030#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2038# endif // _LIBCPP_HAS_EXCEPTIONS
20312039 for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
20322040 ::new ((void*)__end_) value_type(*__p);
2033#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2041# if _LIBCPP_HAS_EXCEPTIONS
20342042 } catch (...) {
20352043 __clear(__v.size());
20362044 throw;
20372045 }
2038#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2046# endif // _LIBCPP_HAS_EXCEPTIONS
20392047 }
20402048}
20412049
2042#ifndef _LIBCPP_CXX03_LANG
2050# ifndef _LIBCPP_CXX03_LANG
20432051
20442052template <class _Tp>
20452053inline valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT : __begin_(__v.__begin_), __end_(__v.__end_) {
......@@ -2051,40 +2059,40 @@ valarray<_Tp>::valarray(initializer_list<value_type> __il) : __begin_(nullptr),
20512059 const size_t __n = __il.size();
20522060 if (__n) {
20532061 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2054# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2062# if _LIBCPP_HAS_EXCEPTIONS
20552063 try {
2056# endif // _LIBCPP_HAS_NO_EXCEPTIONS
2064# endif // _LIBCPP_HAS_EXCEPTIONS
20572065 size_t __n_left = __n;
20582066 for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left)
20592067 ::new ((void*)__end_) value_type(*__p);
2060# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2068# if _LIBCPP_HAS_EXCEPTIONS
20612069 } catch (...) {
20622070 __clear(__n);
20632071 throw;
20642072 }
2065# endif // _LIBCPP_HAS_NO_EXCEPTIONS
2073# endif // _LIBCPP_HAS_EXCEPTIONS
20662074 }
20672075}
20682076
2069#endif // _LIBCPP_CXX03_LANG
2077# endif // _LIBCPP_CXX03_LANG
20702078
20712079template <class _Tp>
20722080valarray<_Tp>::valarray(const slice_array<value_type>& __sa) : __begin_(nullptr), __end_(nullptr) {
20732081 const size_t __n = __sa.__size_;
20742082 if (__n) {
20752083 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2076#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2084# if _LIBCPP_HAS_EXCEPTIONS
20772085 try {
2078#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2086# endif // _LIBCPP_HAS_EXCEPTIONS
20792087 size_t __n_left = __n;
20802088 for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left)
20812089 ::new ((void*)__end_) value_type(*__p);
2082#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2090# if _LIBCPP_HAS_EXCEPTIONS
20832091 } catch (...) {
20842092 __clear(__n);
20852093 throw;
20862094 }
2087#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2095# endif // _LIBCPP_HAS_EXCEPTIONS
20882096 }
20892097}
20902098
......@@ -2093,19 +2101,19 @@ valarray<_Tp>::valarray(const gslice_array<value_type>& __ga) : __begin_(nullptr
20932101 const size_t __n = __ga.__1d_.size();
20942102 if (__n) {
20952103 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2096#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2104# if _LIBCPP_HAS_EXCEPTIONS
20972105 try {
2098#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2106# endif // _LIBCPP_HAS_EXCEPTIONS
20992107 typedef const size_t* _Ip;
21002108 const value_type* __s = __ga.__vp_;
21012109 for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; __i != __e; ++__i, ++__end_)
21022110 ::new ((void*)__end_) value_type(__s[*__i]);
2103#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2111# if _LIBCPP_HAS_EXCEPTIONS
21042112 } catch (...) {
21052113 __clear(__n);
21062114 throw;
21072115 }
2108#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2116# endif // _LIBCPP_HAS_EXCEPTIONS
21092117 }
21102118}
21112119
......@@ -2114,19 +2122,19 @@ valarray<_Tp>::valarray(const mask_array<value_type>& __ma) : __begin_(nullptr),
21142122 const size_t __n = __ma.__1d_.size();
21152123 if (__n) {
21162124 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2117#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2125# if _LIBCPP_HAS_EXCEPTIONS
21182126 try {
2119#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2127# endif // _LIBCPP_HAS_EXCEPTIONS
21202128 typedef const size_t* _Ip;
21212129 const value_type* __s = __ma.__vp_;
21222130 for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; __i != __e; ++__i, ++__end_)
21232131 ::new ((void*)__end_) value_type(__s[*__i]);
2124#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2132# if _LIBCPP_HAS_EXCEPTIONS
21252133 } catch (...) {
21262134 __clear(__n);
21272135 throw;
21282136 }
2129#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2137# endif // _LIBCPP_HAS_EXCEPTIONS
21302138 }
21312139}
21322140
......@@ -2135,19 +2143,19 @@ valarray<_Tp>::valarray(const indirect_array<value_type>& __ia) : __begin_(nullp
21352143 const size_t __n = __ia.__1d_.size();
21362144 if (__n) {
21372145 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2138#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2146# if _LIBCPP_HAS_EXCEPTIONS
21392147 try {
2140#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2148# endif // _LIBCPP_HAS_EXCEPTIONS
21412149 typedef const size_t* _Ip;
21422150 const value_type* __s = __ia.__vp_;
21432151 for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; __i != __e; ++__i, ++__end_)
21442152 ::new ((void*)__end_) value_type(__s[*__i]);
2145#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2153# if _LIBCPP_HAS_EXCEPTIONS
21462154 } catch (...) {
21472155 __clear(__n);
21482156 throw;
21492157 }
2150#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2158# endif // _LIBCPP_HAS_EXCEPTIONS
21512159 }
21522160}
21532161
......@@ -2177,7 +2185,7 @@ valarray<_Tp>& valarray<_Tp>::operator=(const valarray& __v) {
21772185 return *this;
21782186}
21792187
2180#ifndef _LIBCPP_CXX03_LANG
2188# ifndef _LIBCPP_CXX03_LANG
21812189
21822190template <class _Tp>
21832191inline valarray<_Tp>& valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT {
......@@ -2194,7 +2202,7 @@ inline valarray<_Tp>& valarray<_Tp>::operator=(initializer_list<value_type> __il
21942202 return __assign_range(__il.begin(), __il.end());
21952203}
21962204
2197#endif // _LIBCPP_CXX03_LANG
2205# endif // _LIBCPP_CXX03_LANG
21982206
21992207template <class _Tp>
22002208inline valarray<_Tp>& valarray<_Tp>::operator=(const value_type& __x) {
......@@ -2273,7 +2281,7 @@ inline gslice_array<_Tp> valarray<_Tp>::operator[](const gslice& __gs) {
22732281 return gslice_array<value_type>(__gs, *this);
22742282}
22752283
2276#ifndef _LIBCPP_CXX03_LANG
2284# ifndef _LIBCPP_CXX03_LANG
22772285
22782286template <class _Tp>
22792287inline __val_expr<__indirect_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](gslice&& __gs) const {
......@@ -2285,7 +2293,7 @@ inline gslice_array<_Tp> valarray<_Tp>::operator[](gslice&& __gs) {
22852293 return gslice_array<value_type>(std::move(__gs), *this);
22862294}
22872295
2288#endif // _LIBCPP_CXX03_LANG
2296# endif // _LIBCPP_CXX03_LANG
22892297
22902298template <class _Tp>
22912299inline __val_expr<__mask_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](const valarray<bool>& __vb) const {
......@@ -2297,7 +2305,7 @@ inline mask_array<_Tp> valarray<_Tp>::operator[](const valarray<bool>& __vb) {
22972305 return mask_array<value_type>(__vb, *this);
22982306}
22992307
2300#ifndef _LIBCPP_CXX03_LANG
2308# ifndef _LIBCPP_CXX03_LANG
23012309
23022310template <class _Tp>
23032311inline __val_expr<__mask_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](valarray<bool>&& __vb) const {
......@@ -2309,7 +2317,7 @@ inline mask_array<_Tp> valarray<_Tp>::operator[](valarray<bool>&& __vb) {
23092317 return mask_array<value_type>(std::move(__vb), *this);
23102318}
23112319
2312#endif // _LIBCPP_CXX03_LANG
2320# endif // _LIBCPP_CXX03_LANG
23132321
23142322template <class _Tp>
23152323inline __val_expr<__indirect_expr<const valarray<_Tp>&> >
......@@ -2322,7 +2330,7 @@ inline indirect_array<_Tp> valarray<_Tp>::operator[](const valarray<size_t>& __v
23222330 return indirect_array<value_type>(__vs, *this);
23232331}
23242332
2325#ifndef _LIBCPP_CXX03_LANG
2333# ifndef _LIBCPP_CXX03_LANG
23262334
23272335template <class _Tp>
23282336inline __val_expr<__indirect_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](valarray<size_t>&& __vs) const {
......@@ -2334,7 +2342,7 @@ inline indirect_array<_Tp> valarray<_Tp>::operator[](valarray<size_t>&& __vs) {
23342342 return indirect_array<value_type>(std::move(__vs), *this);
23352343}
23362344
2337#endif // _LIBCPP_CXX03_LANG
2345# endif // _LIBCPP_CXX03_LANG
23382346
23392347template <class _Tp>
23402348inline __val_expr<_UnaryOp<__unary_plus<_Tp>, const valarray<_Tp>&> > valarray<_Tp>::operator+() const {
......@@ -2636,17 +2644,17 @@ void valarray<_Tp>::resize(size_t __n, value_type __x) {
26362644 __clear(size());
26372645 if (__n) {
26382646 __begin_ = __end_ = allocator<value_type>().allocate(__n);
2639#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2647# if _LIBCPP_HAS_EXCEPTIONS
26402648 try {
2641#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2649# endif // _LIBCPP_HAS_EXCEPTIONS
26422650 for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
26432651 ::new ((void*)__end_) value_type(__x);
2644#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2652# if _LIBCPP_HAS_EXCEPTIONS
26452653 } catch (...) {
26462654 __clear(__n);
26472655 throw;
26482656 }
2649#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2657# endif // _LIBCPP_HAS_EXCEPTIONS
26502658 }
26512659}
26522660
......@@ -3351,14 +3359,15 @@ _LIBCPP_END_NAMESPACE_STD
33513359
33523360_LIBCPP_POP_MACROS
33533361
3354#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
3355# include <algorithm>
3356# include <concepts>
3357# include <cstdlib>
3358# include <cstring>
3359# include <functional>
3360# include <stdexcept>
3361# include <type_traits>
3362#endif
3362# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
3363# include <algorithm>
3364# include <concepts>
3365# include <cstdlib>
3366# include <cstring>
3367# include <functional>
3368# include <stdexcept>
3369# include <type_traits>
3370# endif
3371#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
33633372
33643373#endif // _LIBCPP_VALARRAY
lib/libcxx/include/variant+215-223
......@@ -212,66 +212,76 @@ namespace std {
212212
213213*/
214214
215#include <__compare/common_comparison_category.h>
216#include <__compare/compare_three_way_result.h>
217#include <__compare/three_way_comparable.h>
218#include <__config>
219#include <__exception/exception.h>
220#include <__functional/hash.h>
221#include <__functional/invoke.h>
222#include <__functional/operations.h>
223#include <__functional/unary_function.h>
224#include <__memory/addressof.h>
225#include <__memory/construct_at.h>
226#include <__tuple/find_index.h>
227#include <__tuple/sfinae_helpers.h>
228#include <__type_traits/add_const.h>
229#include <__type_traits/add_cv.h>
230#include <__type_traits/add_pointer.h>
231#include <__type_traits/add_volatile.h>
232#include <__type_traits/common_type.h>
233#include <__type_traits/conjunction.h>
234#include <__type_traits/dependent_type.h>
235#include <__type_traits/is_array.h>
236#include <__type_traits/is_constructible.h>
237#include <__type_traits/is_destructible.h>
238#include <__type_traits/is_nothrow_assignable.h>
239#include <__type_traits/is_nothrow_constructible.h>
240#include <__type_traits/is_reference.h>
241#include <__type_traits/is_trivially_assignable.h>
242#include <__type_traits/is_trivially_constructible.h>
243#include <__type_traits/is_trivially_destructible.h>
244#include <__type_traits/is_trivially_relocatable.h>
245#include <__type_traits/is_void.h>
246#include <__type_traits/remove_const.h>
247#include <__type_traits/remove_cvref.h>
248#include <__type_traits/type_identity.h>
249#include <__type_traits/void_t.h>
250#include <__utility/declval.h>
251#include <__utility/forward.h>
252#include <__utility/forward_like.h>
253#include <__utility/in_place.h>
254#include <__utility/integer_sequence.h>
255#include <__utility/move.h>
256#include <__utility/swap.h>
257#include <__variant/monostate.h>
258#include <__verbose_abort>
259#include <initializer_list>
260#include <limits>
261#include <new>
262#include <version>
215#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
216# include <__cxx03/variant>
217#else
218# include <__compare/common_comparison_category.h>
219# include <__compare/compare_three_way_result.h>
220# include <__compare/ordering.h>
221# include <__compare/three_way_comparable.h>
222# include <__config>
223# include <__exception/exception.h>
224# include <__functional/hash.h>
225# include <__functional/operations.h>
226# include <__functional/unary_function.h>
227# include <__fwd/variant.h>
228# include <__memory/addressof.h>
229# include <__memory/construct_at.h>
230# include <__tuple/find_index.h>
231# include <__tuple/sfinae_helpers.h>
232# include <__type_traits/add_cv_quals.h>
233# include <__type_traits/add_pointer.h>
234# include <__type_traits/common_type.h>
235# include <__type_traits/conditional.h>
236# include <__type_traits/conjunction.h>
237# include <__type_traits/decay.h>
238# include <__type_traits/dependent_type.h>
239# include <__type_traits/enable_if.h>
240# include <__type_traits/invoke.h>
241# include <__type_traits/is_array.h>
242# include <__type_traits/is_assignable.h>
243# include <__type_traits/is_constructible.h>
244# include <__type_traits/is_convertible.h>
245# include <__type_traits/is_destructible.h>
246# include <__type_traits/is_nothrow_assignable.h>
247# include <__type_traits/is_nothrow_constructible.h>
248# include <__type_traits/is_reference.h>
249# include <__type_traits/is_same.h>
250# include <__type_traits/is_swappable.h>
251# include <__type_traits/is_trivially_assignable.h>
252# include <__type_traits/is_trivially_constructible.h>
253# include <__type_traits/is_trivially_destructible.h>
254# include <__type_traits/is_trivially_relocatable.h>
255# include <__type_traits/is_void.h>
256# include <__type_traits/remove_const.h>
257# include <__type_traits/remove_cvref.h>
258# include <__type_traits/remove_reference.h>
259# include <__type_traits/type_identity.h>
260# include <__type_traits/void_t.h>
261# include <__utility/declval.h>
262# include <__utility/forward.h>
263# include <__utility/forward_like.h>
264# include <__utility/in_place.h>
265# include <__utility/integer_sequence.h>
266# include <__utility/move.h>
267# include <__utility/swap.h>
268# include <__variant/monostate.h>
269# include <__verbose_abort>
270# include <initializer_list>
271# include <limits>
272# include <version>
263273
264274// standard-mandated includes
265275
266276// [variant.syn]
267#include <compare>
277# include <compare>
268278
269#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
270# pragma GCC system_header
271#endif
279# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
280# pragma GCC system_header
281# endif
272282
273283_LIBCPP_PUSH_MACROS
274#include <__undef_macros>
284# include <__undef_macros>
275285
276286namespace std { // explicitly not using versioning namespace
277287
......@@ -284,7 +294,7 @@ public:
284294
285295_LIBCPP_BEGIN_NAMESPACE_STD
286296
287#if _LIBCPP_STD_VER >= 17
297# if _LIBCPP_STD_VER >= 17
288298
289299// Light N-dimensional array of function pointers. Used in place of std::array to avoid
290300// adding a dependency.
......@@ -296,24 +306,16 @@ struct __farray {
296306 _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& operator[](size_t __n) const noexcept { return __buf_[__n]; }
297307};
298308
299_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS void
309[[noreturn]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS void
300310__throw_bad_variant_access() {
301# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
311# if _LIBCPP_HAS_EXCEPTIONS
302312 throw bad_variant_access();
303# else
313# else
304314 _LIBCPP_VERBOSE_ABORT("bad_variant_access was thrown in -fno-exceptions mode");
305# endif
315# endif
306316}
307317
308template <class... _Types>
309class _LIBCPP_TEMPLATE_VIS variant;
310
311template <class _Tp>
312struct _LIBCPP_TEMPLATE_VIS variant_size;
313
314template <class _Tp>
315inline constexpr size_t variant_size_v = variant_size<_Tp>::value;
316
318// variant_size
317319template <class _Tp>
318320struct _LIBCPP_TEMPLATE_VIS variant_size<const _Tp> : variant_size<_Tp> {};
319321
......@@ -326,12 +328,7 @@ struct _LIBCPP_TEMPLATE_VIS variant_size<const volatile _Tp> : variant_size<_Tp>
326328template <class... _Types>
327329struct _LIBCPP_TEMPLATE_VIS variant_size<variant<_Types...>> : integral_constant<size_t, sizeof...(_Types)> {};
328330
329template <size_t _Ip, class _Tp>
330struct _LIBCPP_TEMPLATE_VIS variant_alternative;
331
332template <size_t _Ip, class _Tp>
333using variant_alternative_t = typename variant_alternative<_Ip, _Tp>::type;
334
331// variant_alternative
335332template <size_t _Ip, class _Tp>
336333struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const _Tp> : add_const<variant_alternative_t<_Ip, _Tp>> {};
337334
......@@ -347,29 +344,24 @@ struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, variant<_Types...>> {
347344 using type = __type_pack_element<_Ip, _Types...>;
348345};
349346
350inline constexpr size_t variant_npos = static_cast<size_t>(-1);
351
352347template <size_t _NumAlternatives>
353348_LIBCPP_HIDE_FROM_ABI constexpr auto __choose_index_type() {
354# ifdef _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
349# ifdef _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
355350 if constexpr (_NumAlternatives < numeric_limits<unsigned char>::max())
356351 return static_cast<unsigned char>(0);
357352 else if constexpr (_NumAlternatives < numeric_limits<unsigned short>::max())
358353 return static_cast<unsigned short>(0);
359354 else
360# endif // _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
355# endif // _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
361356 return static_cast<unsigned int>(0);
362357}
363358
364359template <size_t _NumAlts>
365using __variant_index_t = decltype(std::__choose_index_type<_NumAlts>());
360using __variant_index_t _LIBCPP_NODEBUG = decltype(std::__choose_index_type<_NumAlts>());
366361
367362template <class _IndexType>
368363constexpr _IndexType __variant_npos = static_cast<_IndexType>(-1);
369364
370template <class... _Types>
371class _LIBCPP_TEMPLATE_VIS variant;
372
373365template <class... _Types>
374366_LIBCPP_HIDE_FROM_ABI constexpr variant<_Types...>& __as_variant(variant<_Types...>& __vs) noexcept {
375367 return __vs;
......@@ -605,12 +597,12 @@ struct __variant {
605597 return __visit_alt(__make_value_visitor(std::forward<_Visitor>(__visitor)), std::forward<_Vs>(__vs)...);
606598 }
607599
608# if _LIBCPP_STD_VER >= 20
600# if _LIBCPP_STD_VER >= 20
609601 template <class _Rp, class _Visitor, class... _Vs>
610602 _LIBCPP_HIDE_FROM_ABI static constexpr _Rp __visit_value(_Visitor&& __visitor, _Vs&&... __vs) {
611603 return __visit_alt(__make_value_visitor<_Rp>(std::forward<_Visitor>(__visitor)), std::forward<_Vs>(__vs)...);
612604 }
613# endif
605# endif
614606
615607private:
616608 template <class _Visitor, class... _Values>
......@@ -628,7 +620,7 @@ private:
628620 _Visitor&& __visitor;
629621 };
630622
631# if _LIBCPP_STD_VER >= 20
623# if _LIBCPP_STD_VER >= 20
632624 template <class _Rp, class _Visitor>
633625 struct __value_visitor_return_type {
634626 template <class... _Alts>
......@@ -643,31 +635,31 @@ private:
643635
644636 _Visitor&& __visitor;
645637 };
646# endif
638# endif
647639
648640 template <class _Visitor>
649641 _LIBCPP_HIDE_FROM_ABI static constexpr auto __make_value_visitor(_Visitor&& __visitor) {
650642 return __value_visitor<_Visitor>{std::forward<_Visitor>(__visitor)};
651643 }
652644
653# if _LIBCPP_STD_VER >= 20
645# if _LIBCPP_STD_VER >= 20
654646 template <class _Rp, class _Visitor>
655647 _LIBCPP_HIDE_FROM_ABI static constexpr auto __make_value_visitor(_Visitor&& __visitor) {
656648 return __value_visitor_return_type<_Rp, _Visitor>{std::forward<_Visitor>(__visitor)};
657649 }
658# endif
650# endif
659651};
660652
661653} // namespace __visitation
662654
663655// Adding semi-colons in macro expansions helps clang-format to do a better job.
664656// This macro is used to avoid compilation errors due to "stray" semi-colons.
665# define _LIBCPP_EAT_SEMICOLON static_assert(true, "")
657# define _LIBCPP_EAT_SEMICOLON static_assert(true, "")
666658
667659template <size_t _Index, class _Tp>
668660struct _LIBCPP_TEMPLATE_VIS __alt {
669 using __value_type = _Tp;
670 static constexpr size_t __index = _Index;
661 using __value_type _LIBCPP_NODEBUG = _Tp;
662 static constexpr size_t __index = _Index;
671663
672664 template <class... _Args>
673665 _LIBCPP_HIDE_FROM_ABI explicit constexpr __alt(in_place_t, _Args&&... __args)
......@@ -682,33 +674,33 @@ union _LIBCPP_TEMPLATE_VIS __union;
682674template <_Trait _DestructibleTrait, size_t _Index>
683675union _LIBCPP_TEMPLATE_VIS __union<_DestructibleTrait, _Index> {};
684676
685# define _LIBCPP_VARIANT_UNION(destructible_trait, destructor_definition) \
686 template <size_t _Index, class _Tp, class... _Types> \
687 union _LIBCPP_TEMPLATE_VIS __union<destructible_trait, _Index, _Tp, _Types...> { \
688 public: \
689 _LIBCPP_HIDE_FROM_ABI explicit constexpr __union(__valueless_t) noexcept : __dummy{} {} \
677# define _LIBCPP_VARIANT_UNION(destructible_trait, destructor_definition) \
678 template <size_t _Index, class _Tp, class... _Types> \
679 union _LIBCPP_TEMPLATE_VIS __union<destructible_trait, _Index, _Tp, _Types...> { \
680 public: \
681 _LIBCPP_HIDE_FROM_ABI explicit constexpr __union(__valueless_t) noexcept : __dummy{} {} \
690682 \
691 template <class... _Args> \
692 _LIBCPP_HIDE_FROM_ABI explicit constexpr __union(in_place_index_t<0>, _Args&&... __args) \
693 : __head(in_place, std::forward<_Args>(__args)...) {} \
683 template <class... _Args> \
684 _LIBCPP_HIDE_FROM_ABI explicit constexpr __union(in_place_index_t<0>, _Args&&... __args) \
685 : __head(in_place, std::forward<_Args>(__args)...) {} \
694686 \
695 template <size_t _Ip, class... _Args> \
696 _LIBCPP_HIDE_FROM_ABI explicit constexpr __union(in_place_index_t<_Ip>, _Args&&... __args) \
697 : __tail(in_place_index<_Ip - 1>, std::forward<_Args>(__args)...) {} \
687 template <size_t _Ip, class... _Args> \
688 _LIBCPP_HIDE_FROM_ABI explicit constexpr __union(in_place_index_t<_Ip>, _Args&&... __args) \
689 : __tail(in_place_index<_Ip - 1>, std::forward<_Args>(__args)...) {} \
698690 \
699 _LIBCPP_HIDE_FROM_ABI __union(const __union&) = default; \
700 _LIBCPP_HIDE_FROM_ABI __union(__union&&) = default; \
701 _LIBCPP_HIDE_FROM_ABI __union& operator=(const __union&) = default; \
702 _LIBCPP_HIDE_FROM_ABI __union& operator=(__union&&) = default; \
703 destructor_definition; \
691 _LIBCPP_HIDE_FROM_ABI __union(const __union&) = default; \
692 _LIBCPP_HIDE_FROM_ABI __union(__union&&) = default; \
693 _LIBCPP_HIDE_FROM_ABI __union& operator=(const __union&) = default; \
694 _LIBCPP_HIDE_FROM_ABI __union& operator=(__union&&) = default; \
695 destructor_definition; \
704696 \
705 private: \
706 char __dummy; \
707 __alt<_Index, _Tp> __head; \
708 __union<destructible_trait, _Index + 1, _Types...> __tail; \
697 private: \
698 char __dummy; \
699 __alt<_Index, _Tp> __head; \
700 __union<destructible_trait, _Index + 1, _Types...> __tail; \
709701 \
710 friend struct __access::__union; \
711 }
702 friend struct __access::__union; \
703 }
712704
713705_LIBCPP_VARIANT_UNION(_Trait::_TriviallyAvailable,
714706 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__union() = default);
......@@ -716,12 +708,12 @@ _LIBCPP_VARIANT_UNION(
716708 _Trait::_Available, _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__union() {} _LIBCPP_EAT_SEMICOLON);
717709_LIBCPP_VARIANT_UNION(_Trait::_Unavailable, _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__union() = delete);
718710
719# undef _LIBCPP_VARIANT_UNION
711# undef _LIBCPP_VARIANT_UNION
720712
721713template <_Trait _DestructibleTrait, class... _Types>
722714class _LIBCPP_TEMPLATE_VIS __base {
723715public:
724 using __index_t = __variant_index_t<sizeof...(_Types)>;
716 using __index_t _LIBCPP_NODEBUG = __variant_index_t<sizeof...(_Types)>;
725717
726718 _LIBCPP_HIDE_FROM_ABI explicit constexpr __base(__valueless_t __tag) noexcept
727719 : __data(__tag), __index(__variant_npos<__index_t>) {}
......@@ -757,25 +749,25 @@ protected:
757749template <class _Traits, _Trait = _Traits::__destructible_trait>
758750class _LIBCPP_TEMPLATE_VIS __dtor;
759751
760# define _LIBCPP_VARIANT_DESTRUCTOR(destructible_trait, destructor_definition, destroy) \
761 template <class... _Types> \
762 class _LIBCPP_TEMPLATE_VIS __dtor<__traits<_Types...>, destructible_trait> \
763 : public __base<destructible_trait, _Types...> { \
764 using __base_type = __base<destructible_trait, _Types...>; \
765 using __index_t = typename __base_type::__index_t; \
752# define _LIBCPP_VARIANT_DESTRUCTOR(destructible_trait, destructor_definition, destroy) \
753 template <class... _Types> \
754 class _LIBCPP_TEMPLATE_VIS __dtor<__traits<_Types...>, destructible_trait> \
755 : public __base<destructible_trait, _Types...> { \
756 using __base_type _LIBCPP_NODEBUG = __base<destructible_trait, _Types...>; \
757 using __index_t _LIBCPP_NODEBUG = typename __base_type::__index_t; \
766758 \
767 public: \
768 using __base_type::__base_type; \
769 using __base_type::operator=; \
770 _LIBCPP_HIDE_FROM_ABI __dtor(const __dtor&) = default; \
771 _LIBCPP_HIDE_FROM_ABI __dtor(__dtor&&) = default; \
772 _LIBCPP_HIDE_FROM_ABI __dtor& operator=(const __dtor&) = default; \
773 _LIBCPP_HIDE_FROM_ABI __dtor& operator=(__dtor&&) = default; \
774 destructor_definition; \
759 public: \
760 using __base_type::__base_type; \
761 using __base_type::operator=; \
762 _LIBCPP_HIDE_FROM_ABI __dtor(const __dtor&) = default; \
763 _LIBCPP_HIDE_FROM_ABI __dtor(__dtor&&) = default; \
764 _LIBCPP_HIDE_FROM_ABI __dtor& operator=(const __dtor&) = default; \
765 _LIBCPP_HIDE_FROM_ABI __dtor& operator=(__dtor&&) = default; \
766 destructor_definition; \
775767 \
776 protected: \
777 destroy; \
778 }
768 protected: \
769 destroy; \
770 }
779771
780772_LIBCPP_VARIANT_DESTRUCTOR(
781773 _Trait::_TriviallyAvailable,
......@@ -803,11 +795,11 @@ _LIBCPP_VARIANT_DESTRUCTOR(_Trait::_Unavailable,
803795 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__dtor() = delete,
804796 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __destroy() noexcept = delete);
805797
806# undef _LIBCPP_VARIANT_DESTRUCTOR
798# undef _LIBCPP_VARIANT_DESTRUCTOR
807799
808800template <class _Traits>
809801class _LIBCPP_TEMPLATE_VIS __ctor : public __dtor<_Traits> {
810 using __base_type = __dtor<_Traits>;
802 using __base_type _LIBCPP_NODEBUG = __dtor<_Traits>;
811803
812804public:
813805 using __base_type::__base_type;
......@@ -835,22 +827,22 @@ protected:
835827template <class _Traits, _Trait = _Traits::__move_constructible_trait>
836828class _LIBCPP_TEMPLATE_VIS __move_constructor;
837829
838# define _LIBCPP_VARIANT_MOVE_CONSTRUCTOR(move_constructible_trait, move_constructor_definition) \
839 template <class... _Types> \
840 class _LIBCPP_TEMPLATE_VIS __move_constructor<__traits<_Types...>, move_constructible_trait> \
841 : public __ctor<__traits<_Types...>> { \
842 using __base_type = __ctor<__traits<_Types...>>; \
830# define _LIBCPP_VARIANT_MOVE_CONSTRUCTOR(move_constructible_trait, move_constructor_definition) \
831 template <class... _Types> \
832 class _LIBCPP_TEMPLATE_VIS __move_constructor<__traits<_Types...>, move_constructible_trait> \
833 : public __ctor<__traits<_Types...>> { \
834 using __base_type _LIBCPP_NODEBUG = __ctor<__traits<_Types...>>; \
843835 \
844 public: \
845 using __base_type::__base_type; \
846 using __base_type::operator=; \
836 public: \
837 using __base_type::__base_type; \
838 using __base_type::operator=; \
847839 \
848 _LIBCPP_HIDE_FROM_ABI __move_constructor(const __move_constructor&) = default; \
849 _LIBCPP_HIDE_FROM_ABI ~__move_constructor() = default; \
850 _LIBCPP_HIDE_FROM_ABI __move_constructor& operator=(const __move_constructor&) = default; \
851 _LIBCPP_HIDE_FROM_ABI __move_constructor& operator=(__move_constructor&&) = default; \
852 move_constructor_definition; \
853 }
840 _LIBCPP_HIDE_FROM_ABI __move_constructor(const __move_constructor&) = default; \
841 _LIBCPP_HIDE_FROM_ABI ~__move_constructor() = default; \
842 _LIBCPP_HIDE_FROM_ABI __move_constructor& operator=(const __move_constructor&) = default; \
843 _LIBCPP_HIDE_FROM_ABI __move_constructor& operator=(__move_constructor&&) = default; \
844 move_constructor_definition; \
845 }
854846
855847_LIBCPP_VARIANT_MOVE_CONSTRUCTOR(
856848 _Trait::_TriviallyAvailable,
......@@ -868,27 +860,27 @@ _LIBCPP_VARIANT_MOVE_CONSTRUCTOR(
868860 _Trait::_Unavailable,
869861 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __move_constructor(__move_constructor&&) = delete);
870862
871# undef _LIBCPP_VARIANT_MOVE_CONSTRUCTOR
863# undef _LIBCPP_VARIANT_MOVE_CONSTRUCTOR
872864
873865template <class _Traits, _Trait = _Traits::__copy_constructible_trait>
874866class _LIBCPP_TEMPLATE_VIS __copy_constructor;
875867
876# define _LIBCPP_VARIANT_COPY_CONSTRUCTOR(copy_constructible_trait, copy_constructor_definition) \
877 template <class... _Types> \
878 class _LIBCPP_TEMPLATE_VIS __copy_constructor<__traits<_Types...>, copy_constructible_trait> \
879 : public __move_constructor<__traits<_Types...>> { \
880 using __base_type = __move_constructor<__traits<_Types...>>; \
868# define _LIBCPP_VARIANT_COPY_CONSTRUCTOR(copy_constructible_trait, copy_constructor_definition) \
869 template <class... _Types> \
870 class _LIBCPP_TEMPLATE_VIS __copy_constructor<__traits<_Types...>, copy_constructible_trait> \
871 : public __move_constructor<__traits<_Types...>> { \
872 using __base_type _LIBCPP_NODEBUG = __move_constructor<__traits<_Types...>>; \
881873 \
882 public: \
883 using __base_type::__base_type; \
884 using __base_type::operator=; \
874 public: \
875 using __base_type::__base_type; \
876 using __base_type::operator=; \
885877 \
886 _LIBCPP_HIDE_FROM_ABI __copy_constructor(__copy_constructor&&) = default; \
887 _LIBCPP_HIDE_FROM_ABI ~__copy_constructor() = default; \
888 _LIBCPP_HIDE_FROM_ABI __copy_constructor& operator=(const __copy_constructor&) = default; \
889 _LIBCPP_HIDE_FROM_ABI __copy_constructor& operator=(__copy_constructor&&) = default; \
890 copy_constructor_definition; \
891 }
878 _LIBCPP_HIDE_FROM_ABI __copy_constructor(__copy_constructor&&) = default; \
879 _LIBCPP_HIDE_FROM_ABI ~__copy_constructor() = default; \
880 _LIBCPP_HIDE_FROM_ABI __copy_constructor& operator=(const __copy_constructor&) = default; \
881 _LIBCPP_HIDE_FROM_ABI __copy_constructor& operator=(__copy_constructor&&) = default; \
882 copy_constructor_definition; \
883 }
892884
893885_LIBCPP_VARIANT_COPY_CONSTRUCTOR(
894886 _Trait::_TriviallyAvailable,
......@@ -903,11 +895,11 @@ _LIBCPP_VARIANT_COPY_CONSTRUCTOR(
903895 _Trait::_Unavailable,
904896 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __copy_constructor(const __copy_constructor&) = delete);
905897
906# undef _LIBCPP_VARIANT_COPY_CONSTRUCTOR
898# undef _LIBCPP_VARIANT_COPY_CONSTRUCTOR
907899
908900template <class _Traits>
909901class _LIBCPP_TEMPLATE_VIS __assignment : public __copy_constructor<_Traits> {
910 using __base_type = __copy_constructor<_Traits>;
902 using __base_type _LIBCPP_NODEBUG = __copy_constructor<_Traits>;
911903
912904public:
913905 using __base_type::__base_type;
......@@ -962,22 +954,22 @@ protected:
962954template <class _Traits, _Trait = _Traits::__move_assignable_trait>
963955class _LIBCPP_TEMPLATE_VIS __move_assignment;
964956
965# define _LIBCPP_VARIANT_MOVE_ASSIGNMENT(move_assignable_trait, move_assignment_definition) \
966 template <class... _Types> \
967 class _LIBCPP_TEMPLATE_VIS __move_assignment<__traits<_Types...>, move_assignable_trait> \
968 : public __assignment<__traits<_Types...>> { \
969 using __base_type = __assignment<__traits<_Types...>>; \
957# define _LIBCPP_VARIANT_MOVE_ASSIGNMENT(move_assignable_trait, move_assignment_definition) \
958 template <class... _Types> \
959 class _LIBCPP_TEMPLATE_VIS __move_assignment<__traits<_Types...>, move_assignable_trait> \
960 : public __assignment<__traits<_Types...>> { \
961 using __base_type _LIBCPP_NODEBUG = __assignment<__traits<_Types...>>; \
970962 \
971 public: \
972 using __base_type::__base_type; \
973 using __base_type::operator=; \
963 public: \
964 using __base_type::__base_type; \
965 using __base_type::operator=; \
974966 \
975 _LIBCPP_HIDE_FROM_ABI __move_assignment(const __move_assignment&) = default; \
976 _LIBCPP_HIDE_FROM_ABI __move_assignment(__move_assignment&&) = default; \
977 _LIBCPP_HIDE_FROM_ABI ~__move_assignment() = default; \
978 _LIBCPP_HIDE_FROM_ABI __move_assignment& operator=(const __move_assignment&) = default; \
979 move_assignment_definition; \
980 }
967 _LIBCPP_HIDE_FROM_ABI __move_assignment(const __move_assignment&) = default; \
968 _LIBCPP_HIDE_FROM_ABI __move_assignment(__move_assignment&&) = default; \
969 _LIBCPP_HIDE_FROM_ABI ~__move_assignment() = default; \
970 _LIBCPP_HIDE_FROM_ABI __move_assignment& operator=(const __move_assignment&) = default; \
971 move_assignment_definition; \
972 }
981973
982974_LIBCPP_VARIANT_MOVE_ASSIGNMENT(_Trait::_TriviallyAvailable,
983975 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __move_assignment& operator=(
......@@ -996,27 +988,27 @@ _LIBCPP_VARIANT_MOVE_ASSIGNMENT(
996988 _Trait::_Unavailable,
997989 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __move_assignment& operator=(__move_assignment&&) = delete);
998990
999# undef _LIBCPP_VARIANT_MOVE_ASSIGNMENT
991# undef _LIBCPP_VARIANT_MOVE_ASSIGNMENT
1000992
1001993template <class _Traits, _Trait = _Traits::__copy_assignable_trait>
1002994class _LIBCPP_TEMPLATE_VIS __copy_assignment;
1003995
1004# define _LIBCPP_VARIANT_COPY_ASSIGNMENT(copy_assignable_trait, copy_assignment_definition) \
1005 template <class... _Types> \
1006 class _LIBCPP_TEMPLATE_VIS __copy_assignment<__traits<_Types...>, copy_assignable_trait> \
1007 : public __move_assignment<__traits<_Types...>> { \
1008 using __base_type = __move_assignment<__traits<_Types...>>; \
996# define _LIBCPP_VARIANT_COPY_ASSIGNMENT(copy_assignable_trait, copy_assignment_definition) \
997 template <class... _Types> \
998 class _LIBCPP_TEMPLATE_VIS __copy_assignment<__traits<_Types...>, copy_assignable_trait> \
999 : public __move_assignment<__traits<_Types...>> { \
1000 using __base_type _LIBCPP_NODEBUG = __move_assignment<__traits<_Types...>>; \
10091001 \
1010 public: \
1011 using __base_type::__base_type; \
1012 using __base_type::operator=; \
1002 public: \
1003 using __base_type::__base_type; \
1004 using __base_type::operator=; \
10131005 \
1014 _LIBCPP_HIDE_FROM_ABI __copy_assignment(const __copy_assignment&) = default; \
1015 _LIBCPP_HIDE_FROM_ABI __copy_assignment(__copy_assignment&&) = default; \
1016 _LIBCPP_HIDE_FROM_ABI ~__copy_assignment() = default; \
1017 _LIBCPP_HIDE_FROM_ABI __copy_assignment& operator=(__copy_assignment&&) = default; \
1018 copy_assignment_definition; \
1019 }
1006 _LIBCPP_HIDE_FROM_ABI __copy_assignment(const __copy_assignment&) = default; \
1007 _LIBCPP_HIDE_FROM_ABI __copy_assignment(__copy_assignment&&) = default; \
1008 _LIBCPP_HIDE_FROM_ABI ~__copy_assignment() = default; \
1009 _LIBCPP_HIDE_FROM_ABI __copy_assignment& operator=(__copy_assignment&&) = default; \
1010 copy_assignment_definition; \
1011 }
10201012
10211013_LIBCPP_VARIANT_COPY_ASSIGNMENT(_Trait::_TriviallyAvailable,
10221014 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __copy_assignment& operator=(
......@@ -1034,11 +1026,11 @@ _LIBCPP_VARIANT_COPY_ASSIGNMENT(_Trait::_Unavailable,
10341026 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __copy_assignment& operator=(
10351027 const __copy_assignment&) = delete);
10361028
1037# undef _LIBCPP_VARIANT_COPY_ASSIGNMENT
1029# undef _LIBCPP_VARIANT_COPY_ASSIGNMENT
10381030
10391031template <class... _Types>
10401032class _LIBCPP_TEMPLATE_VIS __impl : public __copy_assignment<__traits<_Types...>> {
1041 using __base_type = __copy_assignment<__traits<_Types...>>;
1033 using __base_type _LIBCPP_NODEBUG = __copy_assignment<__traits<_Types...>>;
10421034
10431035public:
10441036 using __base_type::__base_type; // get in_place_index_t constructor & friends
......@@ -1071,7 +1063,7 @@ public:
10711063 std::swap(__lhs, __rhs);
10721064 }
10731065 __impl __tmp(std::move(*__rhs));
1074# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1066# if _LIBCPP_HAS_EXCEPTIONS
10751067 if constexpr (__all<is_nothrow_move_constructible_v<_Types>...>::value) {
10761068 this->__generic_construct(*__rhs, std::move(*__lhs));
10771069 } else {
......@@ -1087,11 +1079,11 @@ public:
10871079 throw;
10881080 }
10891081 }
1090# else
1082# else
10911083 // this isn't consolidated with the `if constexpr` branch above due to
10921084 // `throw` being ill-formed with exceptions disabled even when discarded.
10931085 this->__generic_construct(*__rhs, std::move(*__lhs));
1094# endif
1086# endif
10951087 this->__generic_construct(*__lhs, std::move(__tmp));
10961088 }
10971089 }
......@@ -1105,7 +1097,7 @@ private:
11051097
11061098struct __no_narrowing_check {
11071099 template <class _Dest, class _Source>
1108 using _Apply = __type_identity<_Dest>;
1100 using _Apply _LIBCPP_NODEBUG = __type_identity<_Dest>;
11091101};
11101102
11111103struct __narrowing_check {
......@@ -1146,7 +1138,7 @@ using _MakeOverloads _LIBCPP_NODEBUG =
11461138 typename __make_overloads_imp< __make_indices_imp<sizeof...(_Types), 0> >::template _Apply<_Types...>;
11471139
11481140template <class _Tp, class... _Types>
1149using __best_match_t = typename invoke_result_t<_MakeOverloads<_Types...>, _Tp, _Tp>::type;
1141using __best_match_t _LIBCPP_NODEBUG = typename invoke_result_t<_MakeOverloads<_Types...>, _Tp, _Tp>::type;
11501142
11511143} // namespace __variant_detail
11521144
......@@ -1154,17 +1146,17 @@ template <class _Visitor, class... _Vs, typename = void_t<decltype(std::__as_var
11541146_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr decltype(auto)
11551147visit(_Visitor&& __visitor, _Vs&&... __vs);
11561148
1157# if _LIBCPP_STD_VER >= 20
1149# if _LIBCPP_STD_VER >= 20
11581150template <class _Rp,
11591151 class _Visitor,
11601152 class... _Vs,
11611153 typename = void_t<decltype(std::__as_variant(std::declval<_Vs>()))...>>
11621154_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Rp
11631155visit(_Visitor&& __visitor, _Vs&&... __vs);
1164# endif
1156# endif
11651157
11661158template <class... _Types>
1167class _LIBCPP_TEMPLATE_VIS _LIBCPP_DECLSPEC_EMPTY_BASES variant
1159class _LIBCPP_TEMPLATE_VIS _LIBCPP_DECLSPEC_EMPTY_BASES _LIBCPP_NO_SPECIALIZATIONS variant
11681160 : private __sfinae_ctor_base< __all<is_copy_constructible_v<_Types>...>::value,
11691161 __all<is_move_constructible_v<_Types>...>::value>,
11701162 private __sfinae_assign_base<
......@@ -1178,10 +1170,10 @@ class _LIBCPP_TEMPLATE_VIS _LIBCPP_DECLSPEC_EMPTY_BASES variant
11781170
11791171 static_assert(__all<!is_void_v<_Types>...>::value, "variant can not have a void type as an alternative.");
11801172
1181 using __first_type = variant_alternative_t<0, variant>;
1173 using __first_type _LIBCPP_NODEBUG = variant_alternative_t<0, variant>;
11821174
11831175public:
1184 using __trivially_relocatable =
1176 using __trivially_relocatable _LIBCPP_NODEBUG =
11851177 conditional_t<_And<__libcpp_is_trivially_relocatable<_Types>...>::value, variant, void>;
11861178
11871179 template <bool _Dummy = true,
......@@ -1309,7 +1301,7 @@ public:
13091301 __impl_.__swap(__that.__impl_);
13101302 }
13111303
1312# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
1304# if _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
13131305 // Helper class to implement [variant.visit]/10
13141306 // Constraints: The call to visit does not use an explicit template-argument-list
13151307 // that begins with a type template-argument.
......@@ -1319,16 +1311,14 @@ public:
13191311
13201312 template <__variant_visit_barrier_tag = __variant_visit_barrier_tag{}, class _Self, class _Visitor>
13211313 _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) visit(this _Self&& __self, _Visitor&& __visitor) {
1322 using _VariantT = _OverrideRef<_Self&&, _CopyConst<remove_reference_t<_Self>, variant>>;
1323 return std::visit(std::forward<_Visitor>(__visitor), (_VariantT)__self);
1314 return std::visit(std::forward<_Visitor>(__visitor), std::__forward_as<_Self, variant>(__self));
13241315 }
13251316
13261317 template <class _Rp, class _Self, class _Visitor>
13271318 _LIBCPP_HIDE_FROM_ABI constexpr _Rp visit(this _Self&& __self, _Visitor&& __visitor) {
1328 using _VariantT = _OverrideRef<_Self&&, _CopyConst<remove_reference_t<_Self>, variant>>;
1329 return std::visit<_Rp>(std::forward<_Visitor>(__visitor), (_VariantT)__self);
1319 return std::visit<_Rp>(std::forward<_Visitor>(__visitor), std::__forward_as<_Self, variant>(__self));
13301320 }
1331# endif
1321# endif
13321322
13331323private:
13341324 __variant_detail::__impl<_Types...> __impl_;
......@@ -1472,7 +1462,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const variant<_Types...>& __lhs,
14721462 return __variant::__visit_value_at(__lhs.index(), __convert_to_bool<equal_to<>>{}, __lhs, __rhs);
14731463}
14741464
1475# if _LIBCPP_STD_VER >= 20
1465# if _LIBCPP_STD_VER >= 20
14761466
14771467template <class... _Types>
14781468 requires(three_way_comparable<_Types> && ...)
......@@ -1492,7 +1482,7 @@ operator<=>(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) {
14921482 return __variant::__visit_value_at(__lhs.index(), __three_way, __lhs, __rhs);
14931483}
14941484
1495# endif // _LIBCPP_STD_VER >= 20
1485# endif // _LIBCPP_STD_VER >= 20
14961486
14971487template <class... _Types>
14981488_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) {
......@@ -1576,7 +1566,7 @@ visit(_Visitor&& __visitor, _Vs&&... __vs) {
15761566 return __variant::__visit_value(std::forward<_Visitor>(__visitor), std::forward<_Vs>(__vs)...);
15771567}
15781568
1579# if _LIBCPP_STD_VER >= 20
1569# if _LIBCPP_STD_VER >= 20
15801570template < class _Rp, class _Visitor, class... _Vs, typename>
15811571_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Rp
15821572visit(_Visitor&& __visitor, _Vs&&... __vs) {
......@@ -1584,7 +1574,7 @@ visit(_Visitor&& __visitor, _Vs&&... __vs) {
15841574 std::__throw_if_valueless(std::forward<_Vs>(__vs)...);
15851575 return __variant::__visit_value<_Rp>(std::forward<_Visitor>(__visitor), std::forward<_Vs>(__vs)...);
15861576}
1587# endif
1577# endif
15881578
15891579template <class... _Types>
15901580_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 auto
......@@ -1633,18 +1623,20 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto&& __unchecked_get(variant<_Types...>& __v)
16331623 return std::__unchecked_get<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
16341624}
16351625
1636#endif // _LIBCPP_STD_VER >= 17
1626# endif // _LIBCPP_STD_VER >= 17
16371627
16381628_LIBCPP_END_NAMESPACE_STD
16391629
16401630_LIBCPP_POP_MACROS
16411631
1642#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1643# include <exception>
1644# include <tuple>
1645# include <type_traits>
1646# include <typeinfo>
1647# include <utility>
1648#endif
1632# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1633# include <cstddef>
1634# include <exception>
1635# include <tuple>
1636# include <type_traits>
1637# include <typeinfo>
1638# include <utility>
1639# endif
1640#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
16491641
16501642#endif // _LIBCPP_VARIANT
lib/libcxx/include/vector+54-2711
......@@ -170,7 +170,7 @@ public:
170170
171171 vector()
172172 noexcept(is_nothrow_default_constructible<allocator_type>::value);
173 explicit vector(const allocator_type&);
173 explicit vector(const allocator_type&) noexcept;
174174 explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14
175175 vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
176176 template <class InputIterator>
......@@ -178,8 +178,7 @@ public:
178178 template<container-compatible-range<bool> R>
179179 constexpr vector(from_range_t, R&& rg, const Allocator& = Allocator());
180180 vector(const vector& x);
181 vector(vector&& x)
182 noexcept(is_nothrow_move_constructible<allocator_type>::value);
181 vector(vector&& x) noexcept;
183182 vector(initializer_list<value_type> il);
184183 vector(initializer_list<value_type> il, const allocator_type& a);
185184 ~vector();
......@@ -305,2727 +304,71 @@ template<class T, class charT> requires is-vector-bool-reference<T> // Since C++
305304
306305// clang-format on
307306
308#include <__algorithm/copy.h>
309#include <__algorithm/equal.h>
310#include <__algorithm/fill_n.h>
311#include <__algorithm/iterator_operations.h>
312#include <__algorithm/lexicographical_compare.h>
313#include <__algorithm/lexicographical_compare_three_way.h>
314#include <__algorithm/remove.h>
315#include <__algorithm/remove_if.h>
316#include <__algorithm/rotate.h>
317#include <__algorithm/unwrap_iter.h>
318#include <__assert>
319#include <__bit_reference>
320#include <__concepts/same_as.h>
321#include <__config>
322#include <__debug_utils/sanitizers.h>
323#include <__format/enable_insertable.h>
324#include <__format/formatter.h>
325#include <__format/formatter_bool.h>
326#include <__functional/hash.h>
327#include <__functional/unary_function.h>
328#include <__fwd/vector.h>
329#include <__iterator/advance.h>
330#include <__iterator/bounded_iter.h>
331#include <__iterator/distance.h>
332#include <__iterator/iterator_traits.h>
333#include <__iterator/reverse_iterator.h>
334#include <__iterator/wrap_iter.h>
335#include <__memory/addressof.h>
336#include <__memory/allocate_at_least.h>
337#include <__memory/allocator_traits.h>
338#include <__memory/pointer_traits.h>
339#include <__memory/swap_allocator.h>
340#include <__memory/temp_value.h>
341#include <__memory/uninitialized_algorithms.h>
342#include <__memory_resource/polymorphic_allocator.h>
343#include <__ranges/access.h>
344#include <__ranges/concepts.h>
345#include <__ranges/container_compatible_range.h>
346#include <__ranges/from_range.h>
347#include <__ranges/size.h>
348#include <__split_buffer>
349#include <__type_traits/is_allocator.h>
350#include <__type_traits/is_constructible.h>
351#include <__type_traits/is_nothrow_assignable.h>
352#include <__type_traits/noexcept_move_assign_container.h>
353#include <__type_traits/type_identity.h>
354#include <__utility/exception_guard.h>
355#include <__utility/forward.h>
356#include <__utility/is_pointer_in_range.h>
357#include <__utility/move.h>
358#include <__utility/pair.h>
359#include <__utility/swap.h>
360#include <climits>
361#include <cstring>
362#include <limits>
363#include <stdexcept>
364#include <version>
365
366// standard-mandated includes
367
368// [iterator.range]
369#include <__iterator/access.h>
370#include <__iterator/data.h>
371#include <__iterator/empty.h>
372#include <__iterator/reverse_access.h>
373#include <__iterator/size.h>
374
375// [vector.syn]
376#include <compare>
377#include <initializer_list>
378
379#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
380# pragma GCC system_header
381#endif
382
383_LIBCPP_PUSH_MACROS
384#include <__undef_macros>
385
386_LIBCPP_BEGIN_NAMESPACE_STD
387
388template <class _Tp, class _Allocator /* = allocator<_Tp> */>
389class _LIBCPP_TEMPLATE_VIS vector {
390private:
391 typedef allocator<_Tp> __default_allocator_type;
392
393public:
394 typedef vector __self;
395 typedef _Tp value_type;
396 typedef _Allocator allocator_type;
397 typedef allocator_traits<allocator_type> __alloc_traits;
398 typedef value_type& reference;
399 typedef const value_type& const_reference;
400 typedef typename __alloc_traits::size_type size_type;
401 typedef typename __alloc_traits::difference_type difference_type;
402 typedef typename __alloc_traits::pointer pointer;
403 typedef typename __alloc_traits::const_pointer const_pointer;
404#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
405 // Users might provide custom allocators, and prior to C++20 we have no existing way to detect whether the allocator's
406 // pointer type is contiguous (though it has to be by the Standard). Using the wrapper type ensures the iterator is
407 // considered contiguous.
408 typedef __bounded_iter<__wrap_iter<pointer>> iterator;
409 typedef __bounded_iter<__wrap_iter<const_pointer>> const_iterator;
410#else
411 typedef __wrap_iter<pointer> iterator;
412 typedef __wrap_iter<const_pointer> const_iterator;
413#endif
414 typedef std::reverse_iterator<iterator> reverse_iterator;
415 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
416
417 // A vector containers the following members which may be trivially relocatable:
418 // - pointer: may be trivially relocatable, so it's checked
419 // - allocator_type: may be trivially relocatable, so it's checked
420 // vector doesn't contain any self-references, so it's trivially relocatable if its members are.
421 using __trivially_relocatable = __conditional_t<
422 __libcpp_is_trivially_relocatable<pointer>::value && __libcpp_is_trivially_relocatable<allocator_type>::value,
423 vector,
424 void>;
425
426 static_assert(__check_valid_allocator<allocator_type>::value, "");
427 static_assert(is_same<typename allocator_type::value_type, value_type>::value,
428 "Allocator::value_type must be same type as value_type");
429
430 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector()
431 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) {}
432 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(const allocator_type& __a)
433#if _LIBCPP_STD_VER <= 14
434 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
435#else
436 _NOEXCEPT
437#endif
438 : __end_cap_(nullptr, __a) {
439 }
440
441 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n) {
442 auto __guard = std::__make_exception_guard(__destroy_vector(*this));
443 if (__n > 0) {
444 __vallocate(__n);
445 __construct_at_end(__n);
446 }
447 __guard.__complete();
448 }
449
450#if _LIBCPP_STD_VER >= 14
451 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n, const allocator_type& __a)
452 : __end_cap_(nullptr, __a) {
453 auto __guard = std::__make_exception_guard(__destroy_vector(*this));
454 if (__n > 0) {
455 __vallocate(__n);
456 __construct_at_end(__n);
457 }
458 __guard.__complete();
459 }
460#endif
461
462 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __x) {
463 auto __guard = std::__make_exception_guard(__destroy_vector(*this));
464 if (__n > 0) {
465 __vallocate(__n);
466 __construct_at_end(__n, __x);
467 }
468 __guard.__complete();
469 }
470
471 template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0>
472 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
473 vector(size_type __n, const value_type& __x, const allocator_type& __a)
474 : __end_cap_(nullptr, __a) {
475 if (__n > 0) {
476 __vallocate(__n);
477 __construct_at_end(__n, __x);
478 }
479 }
480
481 template <class _InputIterator,
482 __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
483 is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
484 int> = 0>
485 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_InputIterator __first, _InputIterator __last);
486 template <class _InputIterator,
487 __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
488 is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
489 int> = 0>
490 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
491 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
492
493 template <
494 class _ForwardIterator,
495 __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
496 is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
497 int> = 0>
498 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_ForwardIterator __first, _ForwardIterator __last);
499
500 template <
501 class _ForwardIterator,
502 __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
503 is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
504 int> = 0>
505 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
506 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a);
507
508#if _LIBCPP_STD_VER >= 23
509 template <_ContainerCompatibleRange<_Tp> _Range>
510 _LIBCPP_HIDE_FROM_ABI constexpr vector(
511 from_range_t, _Range&& __range, const allocator_type& __alloc = allocator_type())
512 : __end_cap_(nullptr, __alloc) {
513 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
514 auto __n = static_cast<size_type>(ranges::distance(__range));
515 __init_with_size(ranges::begin(__range), ranges::end(__range), __n);
516
517 } else {
518 __init_with_sentinel(ranges::begin(__range), ranges::end(__range));
519 }
520 }
521#endif
522
523private:
524 class __destroy_vector {
525 public:
526 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __destroy_vector(vector& __vec) : __vec_(__vec) {}
527
528 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() {
529 if (__vec_.__begin_ != nullptr) {
530 __vec_.__clear();
531 __vec_.__annotate_delete();
532 __alloc_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.capacity());
533 }
534 }
535
536 private:
537 vector& __vec_;
538 };
539
540public:
541 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector (*this)(); }
542
543 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x);
544 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
545 vector(const vector& __x, const __type_identity_t<allocator_type>& __a);
546 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector& operator=(const vector& __x);
547
548#ifndef _LIBCPP_CXX03_LANG
549 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(initializer_list<value_type> __il);
550
551 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
552 vector(initializer_list<value_type> __il, const allocator_type& __a);
553
554 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector& operator=(initializer_list<value_type> __il) {
555 assign(__il.begin(), __il.end());
556 return *this;
557 }
558#endif // !_LIBCPP_CXX03_LANG
559
560 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(vector&& __x)
561#if _LIBCPP_STD_VER >= 17
562 noexcept;
563#else
564 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
565#endif
566
567 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
568 vector(vector&& __x, const __type_identity_t<allocator_type>& __a);
569 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector& operator=(vector&& __x)
570 _NOEXCEPT_(__noexcept_move_assign_container<_Allocator, __alloc_traits>::value);
571
572 template <class _InputIterator,
573 __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
574 is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
575 int> = 0>
576 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_InputIterator __first, _InputIterator __last);
577 template <
578 class _ForwardIterator,
579 __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
580 is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
581 int> = 0>
582 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_ForwardIterator __first, _ForwardIterator __last);
583
584#if _LIBCPP_STD_VER >= 23
585 template <_ContainerCompatibleRange<_Tp> _Range>
586 _LIBCPP_HIDE_FROM_ABI constexpr void assign_range(_Range&& __range) {
587 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
588 auto __n = static_cast<size_type>(ranges::distance(__range));
589 __assign_with_size(ranges::begin(__range), ranges::end(__range), __n);
590
591 } else {
592 __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
593 }
594 }
595#endif
596
597 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const_reference __u);
598
599#ifndef _LIBCPP_CXX03_LANG
600 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<value_type> __il) {
601 assign(__il.begin(), __il.end());
602 }
603#endif
604
605 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT {
606 return this->__alloc();
607 }
608
609 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT;
610 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT;
611 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT;
612 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT;
613
614 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT {
615 return reverse_iterator(end());
616 }
617 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT {
618 return const_reverse_iterator(end());
619 }
620 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT {
621 return reverse_iterator(begin());
622 }
623 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT {
624 return const_reverse_iterator(begin());
625 }
626
627 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return begin(); }
628 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return end(); }
629 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT {
630 return rbegin();
631 }
632 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
633
634 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT {
635 return static_cast<size_type>(this->__end_ - this->__begin_);
636 }
637 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type capacity() const _NOEXCEPT {
638 return static_cast<size_type>(__end_cap() - this->__begin_);
639 }
640 _LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT {
641 return this->__begin_ == this->__end_;
642 }
643 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT;
644 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n);
645 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void shrink_to_fit() _NOEXCEPT;
646
647 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference operator[](size_type __n) _NOEXCEPT;
648 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __n) const _NOEXCEPT;
649 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference at(size_type __n);
650 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const;
651
652 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference front() _NOEXCEPT {
653 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "front() called on an empty vector");
654 return *this->__begin_;
655 }
656 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference front() const _NOEXCEPT {
657 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "front() called on an empty vector");
658 return *this->__begin_;
659 }
660 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference back() _NOEXCEPT {
661 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "back() called on an empty vector");
662 return *(this->__end_ - 1);
663 }
664 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference back() const _NOEXCEPT {
665 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "back() called on an empty vector");
666 return *(this->__end_ - 1);
667 }
668
669 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI value_type* data() _NOEXCEPT {
670 return std::__to_address(this->__begin_);
671 }
672
673 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const value_type* data() const _NOEXCEPT {
674 return std::__to_address(this->__begin_);
675 }
676
677 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(const_reference __x);
678
679 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x);
680
681 template <class... _Args>
682 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
683#if _LIBCPP_STD_VER >= 17
684 reference
685 emplace_back(_Args&&... __args);
686#else
687 void
688 emplace_back(_Args&&... __args);
689#endif
690
691#if _LIBCPP_STD_VER >= 23
692 template <_ContainerCompatibleRange<_Tp> _Range>
693 _LIBCPP_HIDE_FROM_ABI constexpr void append_range(_Range&& __range) {
694 insert_range(end(), std::forward<_Range>(__range));
695 }
696#endif
697
698 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void pop_back();
699
700 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, const_reference __x);
701
702 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, value_type&& __x);
703 template <class... _Args>
704 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __position, _Args&&... __args);
705
706 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
707 insert(const_iterator __position, size_type __n, const_reference __x);
708
709 template <class _InputIterator,
710 __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
711 is_constructible< value_type, typename iterator_traits<_InputIterator>::reference>::value,
712 int> = 0>
713 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
714 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
715
716#if _LIBCPP_STD_VER >= 23
717 template <_ContainerCompatibleRange<_Tp> _Range>
718 _LIBCPP_HIDE_FROM_ABI constexpr iterator insert_range(const_iterator __position, _Range&& __range) {
719 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
720 auto __n = static_cast<size_type>(ranges::distance(__range));
721 return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n);
722
723 } else {
724 return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
725 }
726 }
727#endif
728
729 template <
730 class _ForwardIterator,
731 __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
732 is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
733 int> = 0>
734 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
735 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
736
737#ifndef _LIBCPP_CXX03_LANG
738 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
739 insert(const_iterator __position, initializer_list<value_type> __il) {
740 return insert(__position, __il.begin(), __il.end());
741 }
742#endif
743
744 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position);
745 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last);
746
747 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT {
748 size_type __old_size = size();
749 __clear();
750 __annotate_shrink(__old_size);
751 }
752
753 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz);
754 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz, const_reference __x);
755
756 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void swap(vector&)
757#if _LIBCPP_STD_VER >= 14
758 _NOEXCEPT;
759#else
760 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>);
761#endif
762
763 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool __invariants() const;
764
765private:
766 pointer __begin_ = nullptr;
767 pointer __end_ = nullptr;
768 __compressed_pair<pointer, allocator_type> __end_cap_ =
769 __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag());
770
771 // Allocate space for __n objects
772 // throws length_error if __n > max_size()
773 // throws (probably bad_alloc) if memory run out
774 // Precondition: __begin_ == __end_ == __end_cap() == 0
775 // Precondition: __n > 0
776 // Postcondition: capacity() >= __n
777 // Postcondition: size() == 0
778 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
779 if (__n > max_size())
780 __throw_length_error();
781 auto __allocation = std::__allocate_at_least(__alloc(), __n);
782 __begin_ = __allocation.ptr;
783 __end_ = __allocation.ptr;
784 __end_cap() = __begin_ + __allocation.count;
785 __annotate_new(0);
786 }
787
788 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vdeallocate() _NOEXCEPT;
789 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type __recommend(size_type __new_size) const;
790 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n);
791 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n, const_reference __x);
792
793 template <class _InputIterator, class _Sentinel>
794 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
795 __init_with_size(_InputIterator __first, _Sentinel __last, size_type __n) {
796 auto __guard = std::__make_exception_guard(__destroy_vector(*this));
797
798 if (__n > 0) {
799 __vallocate(__n);
800 __construct_at_end(__first, __last, __n);
801 }
802
803 __guard.__complete();
804 }
805
806 template <class _InputIterator, class _Sentinel>
807 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
808 __init_with_sentinel(_InputIterator __first, _Sentinel __last) {
809 auto __guard = std::__make_exception_guard(__destroy_vector(*this));
810
811 for (; __first != __last; ++__first)
812 emplace_back(*__first);
813
814 __guard.__complete();
815 }
816
817 template <class _Iterator, class _Sentinel>
818 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iterator __first, _Sentinel __last);
819
820 template <class _ForwardIterator, class _Sentinel>
821 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
822 __assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __n);
823
824 template <class _InputIterator, class _Sentinel>
825 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
826 __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last);
827
828 template <class _Iterator, class _Sentinel>
829 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
830 __insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n);
831
832 template <class _InputIterator, class _Sentinel>
833 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
834 __construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n);
835
836 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n);
837 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n, const_reference __x);
838
839 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator __make_iter(pointer __p) _NOEXCEPT {
840#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
841 // Bound the iterator according to the capacity, rather than the size.
842 //
843 // Vector guarantees that iterators stay valid as long as no reallocation occurs even if new elements are inserted
844 // into the container; for these cases, we need to make sure that the newly-inserted elements can be accessed
845 // through the bounded iterator without failing checks. The downside is that the bounded iterator won't catch
846 // access that is logically out-of-bounds, i.e., goes beyond the size, but is still within the capacity. With the
847 // current implementation, there is no connection between a bounded iterator and its associated container, so we
848 // don't have a way to update existing valid iterators when the container is resized and thus have to go with
849 // a laxer approach.
850 return std::__make_bounded_iter(
851 std::__wrap_iter<pointer>(__p),
852 std::__wrap_iter<pointer>(this->__begin_),
853 std::__wrap_iter<pointer>(this->__end_cap()));
854#else
855 return iterator(__p);
856#endif // _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
857 }
858
859 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator __make_iter(const_pointer __p) const _NOEXCEPT {
860#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
861 // Bound the iterator according to the capacity, rather than the size.
862 return std::__make_bounded_iter(
863 std::__wrap_iter<const_pointer>(__p),
864 std::__wrap_iter<const_pointer>(this->__begin_),
865 std::__wrap_iter<const_pointer>(this->__end_cap()));
866#else
867 return const_iterator(__p);
868#endif // _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
869 }
870
871 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
872 __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
873 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer
874 __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
875 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
876 __move_range(pointer __from_s, pointer __from_e, pointer __to);
877 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, true_type)
878 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
879 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, false_type)
880 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
881 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __destruct_at_end(pointer __new_last) _NOEXCEPT {
882 size_type __old_size = size();
883 __base_destruct_at_end(__new_last);
884 __annotate_shrink(__old_size);
885 }
886
887 template <class _Up>
888 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI inline pointer __push_back_slow_path(_Up&& __x);
889
890 template <class... _Args>
891 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI inline pointer __emplace_back_slow_path(_Args&&... __args);
892
893 // The following functions are no-ops outside of AddressSanitizer mode.
894 // We call annotations for every allocator, unless explicitly disabled.
895 //
896 // To disable annotations for a particular allocator, change value of
897 // __asan_annotate_container_with_allocator to false.
898 // For more details, see the "Using libc++" documentation page or
899 // the documentation for __sanitizer_annotate_contiguous_container.
900
901 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
902 __annotate_contiguous_container(const void* __old_mid, const void* __new_mid) const {
903 std::__annotate_contiguous_container<_Allocator>(data(), data() + capacity(), __old_mid, __new_mid);
904 }
905
906 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_new(size_type __current_size) const _NOEXCEPT {
907 (void)__current_size;
908#ifndef _LIBCPP_HAS_NO_ASAN
909 __annotate_contiguous_container(data() + capacity(), data() + __current_size);
910#endif
911 }
912
913 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_delete() const _NOEXCEPT {
914#ifndef _LIBCPP_HAS_NO_ASAN
915 __annotate_contiguous_container(data() + size(), data() + capacity());
916#endif
917 }
918
919 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_increase(size_type __n) const _NOEXCEPT {
920 (void)__n;
921#ifndef _LIBCPP_HAS_NO_ASAN
922 __annotate_contiguous_container(data() + size(), data() + size() + __n);
923#endif
924 }
925
926 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_shrink(size_type __old_size) const _NOEXCEPT {
927 (void)__old_size;
928#ifndef _LIBCPP_HAS_NO_ASAN
929 __annotate_contiguous_container(data() + __old_size, data() + size());
930#endif
931 }
932
933 struct _ConstructTransaction {
934 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit _ConstructTransaction(vector& __v, size_type __n)
935 : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
936#ifndef _LIBCPP_HAS_NO_ASAN
937 __v_.__annotate_increase(__n);
938#endif
939 }
940
941 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~_ConstructTransaction() {
942 __v_.__end_ = __pos_;
943#ifndef _LIBCPP_HAS_NO_ASAN
944 if (__pos_ != __new_end_) {
945 __v_.__annotate_shrink(__new_end_ - __v_.__begin_);
946 }
947#endif
948 }
949
950 vector& __v_;
951 pointer __pos_;
952 const_pointer const __new_end_;
953
954 _ConstructTransaction(_ConstructTransaction const&) = delete;
955 _ConstructTransaction& operator=(_ConstructTransaction const&) = delete;
956 };
957
958 template <class... _Args>
959 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_one_at_end(_Args&&... __args) {
960 _ConstructTransaction __tx(*this, 1);
961 __alloc_traits::construct(this->__alloc(), std::__to_address(__tx.__pos_), std::forward<_Args>(__args)...);
962 ++__tx.__pos_;
963 }
964
965 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT {
966 return this->__end_cap_.second();
967 }
968 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT {
969 return this->__end_cap_.second();
970 }
971 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer& __end_cap() _NOEXCEPT {
972 return this->__end_cap_.first();
973 }
974 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const pointer& __end_cap() const _NOEXCEPT {
975 return this->__end_cap_.first();
976 }
977
978 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __clear() _NOEXCEPT {
979 __base_destruct_at_end(this->__begin_);
980 }
981
982 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __base_destruct_at_end(pointer __new_last) _NOEXCEPT {
983 pointer __soon_to_be_end = this->__end_;
984 while (__new_last != __soon_to_be_end)
985 __alloc_traits::destroy(__alloc(), std::__to_address(--__soon_to_be_end));
986 this->__end_ = __new_last;
987 }
988
989 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector& __c) {
990 __copy_assign_alloc(__c, integral_constant<bool, __alloc_traits::propagate_on_container_copy_assignment::value>());
991 }
992
993 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector& __c)
994 _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value ||
995 is_nothrow_move_assignable<allocator_type>::value) {
996 __move_assign_alloc(__c, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());
997 }
998
999 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_length_error() const { std::__throw_length_error("vector"); }
1000
1001 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { std::__throw_out_of_range("vector"); }
1002
1003 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector& __c, true_type) {
1004 if (__alloc() != __c.__alloc()) {
1005 __clear();
1006 __annotate_delete();
1007 __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
1008 this->__begin_ = this->__end_ = __end_cap() = nullptr;
1009 }
1010 __alloc() = __c.__alloc();
1011 }
1012
1013 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector&, false_type) {}
1014
1015 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector& __c, true_type)
1016 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
1017 __alloc() = std::move(__c.__alloc());
1018 }
1019
1020 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector&, false_type) _NOEXCEPT {}
1021};
1022
1023#if _LIBCPP_STD_VER >= 17
1024template <class _InputIterator,
1025 class _Alloc = allocator<__iter_value_type<_InputIterator>>,
1026 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
1027 class = enable_if_t<__is_allocator<_Alloc>::value> >
1028vector(_InputIterator, _InputIterator) -> vector<__iter_value_type<_InputIterator>, _Alloc>;
1029
1030template <class _InputIterator,
1031 class _Alloc,
1032 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
1033 class = enable_if_t<__is_allocator<_Alloc>::value> >
1034vector(_InputIterator, _InputIterator, _Alloc) -> vector<__iter_value_type<_InputIterator>, _Alloc>;
1035#endif
1036
1037#if _LIBCPP_STD_VER >= 23
1038template <ranges::input_range _Range,
1039 class _Alloc = allocator<ranges::range_value_t<_Range>>,
1040 class = enable_if_t<__is_allocator<_Alloc>::value> >
1041vector(from_range_t, _Range&&, _Alloc = _Alloc()) -> vector<ranges::range_value_t<_Range>, _Alloc>;
1042#endif
1043
1044// __swap_out_circular_buffer relocates the objects in [__begin_, __end_) into the front of __v and swaps the buffers of
1045// *this and __v. It is assumed that __v provides space for exactly (__end_ - __begin_) objects in the front. This
1046// function has a strong exception guarantee.
1047template <class _Tp, class _Allocator>
1048_LIBCPP_CONSTEXPR_SINCE_CXX20 void
1049vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) {
1050 __annotate_delete();
1051 auto __new_begin = __v.__begin_ - (__end_ - __begin_);
1052 std::__uninitialized_allocator_relocate(
1053 __alloc(), std::__to_address(__begin_), std::__to_address(__end_), std::__to_address(__new_begin));
1054 __v.__begin_ = __new_begin;
1055 __end_ = __begin_; // All the objects have been destroyed by relocating them.
1056 std::swap(this->__begin_, __v.__begin_);
1057 std::swap(this->__end_, __v.__end_);
1058 std::swap(this->__end_cap(), __v.__end_cap());
1059 __v.__first_ = __v.__begin_;
1060 __annotate_new(size());
1061}
1062
1063// __swap_out_circular_buffer relocates the objects in [__begin_, __p) into the front of __v, the objects in
1064// [__p, __end_) into the back of __v and swaps the buffers of *this and __v. It is assumed that __v provides space for
1065// exactly (__p - __begin_) objects in the front and space for at least (__end_ - __p) objects in the back. This
1066// function has a strong exception guarantee if __begin_ == __p || __end_ == __p.
1067template <class _Tp, class _Allocator>
1068_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::pointer
1069vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) {
1070 __annotate_delete();
1071 pointer __ret = __v.__begin_;
1072
1073 // Relocate [__p, __end_) first to avoid having a hole in [__begin_, __end_)
1074 // in case something in [__begin_, __p) throws.
1075 std::__uninitialized_allocator_relocate(
1076 __alloc(), std::__to_address(__p), std::__to_address(__end_), std::__to_address(__v.__end_));
1077 __v.__end_ += (__end_ - __p);
1078 __end_ = __p; // The objects in [__p, __end_) have been destroyed by relocating them.
1079 auto __new_begin = __v.__begin_ - (__p - __begin_);
1080
1081 std::__uninitialized_allocator_relocate(
1082 __alloc(), std::__to_address(__begin_), std::__to_address(__p), std::__to_address(__new_begin));
1083 __v.__begin_ = __new_begin;
1084 __end_ = __begin_; // All the objects have been destroyed by relocating them.
1085
1086 std::swap(this->__begin_, __v.__begin_);
1087 std::swap(this->__end_, __v.__end_);
1088 std::swap(this->__end_cap(), __v.__end_cap());
1089 __v.__first_ = __v.__begin_;
1090 __annotate_new(size());
1091 return __ret;
1092}
1093
1094template <class _Tp, class _Allocator>
1095_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT {
1096 if (this->__begin_ != nullptr) {
1097 clear();
1098 __annotate_delete();
1099 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
1100 this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
1101 }
1102}
1103
1104template <class _Tp, class _Allocator>
1105_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::size_type
1106vector<_Tp, _Allocator>::max_size() const _NOEXCEPT {
1107 return std::min<size_type>(__alloc_traits::max_size(this->__alloc()), numeric_limits<difference_type>::max());
1108}
1109
1110// Precondition: __new_size > capacity()
1111template <class _Tp, class _Allocator>
1112_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
1113vector<_Tp, _Allocator>::__recommend(size_type __new_size) const {
1114 const size_type __ms = max_size();
1115 if (__new_size > __ms)
1116 this->__throw_length_error();
1117 const size_type __cap = capacity();
1118 if (__cap >= __ms / 2)
1119 return __ms;
1120 return std::max<size_type>(2 * __cap, __new_size);
1121}
1122
1123// Default constructs __n objects starting at __end_
1124// throws if construction throws
1125// Precondition: __n > 0
1126// Precondition: size() + __n <= capacity()
1127// Postcondition: size() == size() + __n
1128template <class _Tp, class _Allocator>
1129_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__construct_at_end(size_type __n) {
1130 _ConstructTransaction __tx(*this, __n);
1131 const_pointer __new_end = __tx.__new_end_;
1132 for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
1133 __alloc_traits::construct(this->__alloc(), std::__to_address(__pos));
1134 }
1135}
1136
1137// Copy constructs __n objects starting at __end_ from __x
1138// throws if construction throws
1139// Precondition: __n > 0
1140// Precondition: size() + __n <= capacity()
1141// Postcondition: size() == old size() + __n
1142// Postcondition: [i] == __x for all i in [size() - __n, __n)
1143template <class _Tp, class _Allocator>
1144_LIBCPP_CONSTEXPR_SINCE_CXX20 inline void
1145vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) {
1146 _ConstructTransaction __tx(*this, __n);
1147 const_pointer __new_end = __tx.__new_end_;
1148 for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
1149 __alloc_traits::construct(this->__alloc(), std::__to_address(__pos), __x);
1150 }
1151}
1152
1153template <class _Tp, class _Allocator>
1154template <class _InputIterator, class _Sentinel>
1155_LIBCPP_CONSTEXPR_SINCE_CXX20 void
1156vector<_Tp, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
1157 _ConstructTransaction __tx(*this, __n);
1158 __tx.__pos_ = std::__uninitialized_allocator_copy(__alloc(), __first, __last, __tx.__pos_);
1159}
1160
1161// Default constructs __n objects starting at __end_
1162// throws if construction throws
1163// Postcondition: size() == size() + __n
1164// Exception safety: strong.
1165template <class _Tp, class _Allocator>
1166_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__append(size_type __n) {
1167 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1168 this->__construct_at_end(__n);
1169 else {
1170 allocator_type& __a = this->__alloc();
1171 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1172 __v.__construct_at_end(__n);
1173 __swap_out_circular_buffer(__v);
1174 }
1175}
1176
1177// Default constructs __n objects starting at __end_
1178// throws if construction throws
1179// Postcondition: size() == size() + __n
1180// Exception safety: strong.
1181template <class _Tp, class _Allocator>
1182_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) {
1183 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1184 this->__construct_at_end(__n, __x);
1185 else {
1186 allocator_type& __a = this->__alloc();
1187 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1188 __v.__construct_at_end(__n, __x);
1189 __swap_out_circular_buffer(__v);
1190 }
1191}
1192
1193template <class _Tp, class _Allocator>
1194template <class _InputIterator,
1195 __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
1196 is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
1197 int> >
1198_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last) {
1199 __init_with_sentinel(__first, __last);
1200}
1201
1202template <class _Tp, class _Allocator>
1203template <class _InputIterator,
1204 __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
1205 is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
1206 int> >
1207_LIBCPP_CONSTEXPR_SINCE_CXX20
1208vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a)
1209 : __end_cap_(nullptr, __a) {
1210 __init_with_sentinel(__first, __last);
1211}
1212
1213template <class _Tp, class _Allocator>
1214template <class _ForwardIterator,
1215 __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
1216 is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
1217 int> >
1218_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last) {
1219 size_type __n = static_cast<size_type>(std::distance(__first, __last));
1220 __init_with_size(__first, __last, __n);
1221}
1222
1223template <class _Tp, class _Allocator>
1224template <class _ForwardIterator,
1225 __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
1226 is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
1227 int> >
1228_LIBCPP_CONSTEXPR_SINCE_CXX20
1229vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a)
1230 : __end_cap_(nullptr, __a) {
1231 size_type __n = static_cast<size_type>(std::distance(__first, __last));
1232 __init_with_size(__first, __last, __n);
1233}
1234
1235template <class _Tp, class _Allocator>
1236_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(const vector& __x)
1237 : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc())) {
1238 __init_with_size(__x.__begin_, __x.__end_, __x.size());
1239}
1240
1241template <class _Tp, class _Allocator>
1242_LIBCPP_CONSTEXPR_SINCE_CXX20
1243vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
1244 : __end_cap_(nullptr, __a) {
1245 __init_with_size(__x.__begin_, __x.__end_, __x.size());
1246}
1247
1248template <class _Tp, class _Allocator>
1249_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(vector&& __x)
1250#if _LIBCPP_STD_VER >= 17
1251 noexcept
1252#else
1253 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1254#endif
1255 : __end_cap_(nullptr, std::move(__x.__alloc())) {
1256 this->__begin_ = __x.__begin_;
1257 this->__end_ = __x.__end_;
1258 this->__end_cap() = __x.__end_cap();
1259 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1260}
1261
1262template <class _Tp, class _Allocator>
1263_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI
1264vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
1265 : __end_cap_(nullptr, __a) {
1266 if (__a == __x.__alloc()) {
1267 this->__begin_ = __x.__begin_;
1268 this->__end_ = __x.__end_;
1269 this->__end_cap() = __x.__end_cap();
1270 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1271 } else {
1272 typedef move_iterator<iterator> _Ip;
1273 auto __guard = std::__make_exception_guard(__destroy_vector(*this));
1274 assign(_Ip(__x.begin()), _Ip(__x.end()));
1275 __guard.__complete();
1276 }
1277}
1278
1279#ifndef _LIBCPP_CXX03_LANG
1280
1281template <class _Tp, class _Allocator>
1282_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI
1283vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) {
1284 auto __guard = std::__make_exception_guard(__destroy_vector(*this));
1285 if (__il.size() > 0) {
1286 __vallocate(__il.size());
1287 __construct_at_end(__il.begin(), __il.end(), __il.size());
1288 }
1289 __guard.__complete();
1290}
1291
1292template <class _Tp, class _Allocator>
1293_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI
1294vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1295 : __end_cap_(nullptr, __a) {
1296 auto __guard = std::__make_exception_guard(__destroy_vector(*this));
1297 if (__il.size() > 0) {
1298 __vallocate(__il.size());
1299 __construct_at_end(__il.begin(), __il.end(), __il.size());
1300 }
1301 __guard.__complete();
1302}
1303
1304#endif // _LIBCPP_CXX03_LANG
1305
1306template <class _Tp, class _Allocator>
1307_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>&
1308vector<_Tp, _Allocator>::operator=(vector&& __x)
1309 _NOEXCEPT_(__noexcept_move_assign_container<_Allocator, __alloc_traits>::value) {
1310 __move_assign(__x, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());
1311 return *this;
1312}
1313
1314template <class _Tp, class _Allocator>
1315_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1316 _NOEXCEPT_(__alloc_traits::is_always_equal::value) {
1317 if (__alloc() != __c.__alloc()) {
1318 typedef move_iterator<iterator> _Ip;
1319 assign(_Ip(__c.begin()), _Ip(__c.end()));
1320 } else
1321 __move_assign(__c, true_type());
1322}
1323
1324template <class _Tp, class _Allocator>
1325_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
1326 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
1327 __vdeallocate();
1328 __move_assign_alloc(__c); // this can throw
1329 this->__begin_ = __c.__begin_;
1330 this->__end_ = __c.__end_;
1331 this->__end_cap() = __c.__end_cap();
1332 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
1333}
1334
1335template <class _Tp, class _Allocator>
1336_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>&
1337vector<_Tp, _Allocator>::operator=(const vector& __x) {
1338 if (this != std::addressof(__x)) {
1339 __copy_assign_alloc(__x);
1340 assign(__x.__begin_, __x.__end_);
1341 }
1342 return *this;
1343}
1344
1345template <class _Tp, class _Allocator>
1346template <class _InputIterator,
1347 __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
1348 is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
1349 int> >
1350_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last) {
1351 __assign_with_sentinel(__first, __last);
1352}
1353
1354template <class _Tp, class _Allocator>
1355template <class _Iterator, class _Sentinel>
1356_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
1357vector<_Tp, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __last) {
1358 clear();
1359 for (; __first != __last; ++__first)
1360 emplace_back(*__first);
1361}
1362
1363template <class _Tp, class _Allocator>
1364template <class _ForwardIterator,
1365 __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
1366 is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
1367 int> >
1368_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) {
1369 __assign_with_size(__first, __last, std::distance(__first, __last));
1370}
1371
1372template <class _Tp, class _Allocator>
1373template <class _ForwardIterator, class _Sentinel>
1374_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
1375vector<_Tp, _Allocator>::__assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __n) {
1376 size_type __new_size = static_cast<size_type>(__n);
1377 if (__new_size <= capacity()) {
1378 if (__new_size > size()) {
1379 _ForwardIterator __mid = std::next(__first, size());
1380 std::copy(__first, __mid, this->__begin_);
1381 __construct_at_end(__mid, __last, __new_size - size());
1382 } else {
1383 pointer __m = std::__copy<_ClassicAlgPolicy>(__first, __last, this->__begin_).second;
1384 this->__destruct_at_end(__m);
1385 }
1386 } else {
1387 __vdeallocate();
1388 __vallocate(__recommend(__new_size));
1389 __construct_at_end(__first, __last, __new_size);
1390 }
1391}
1392
1393template <class _Tp, class _Allocator>
1394_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) {
1395 if (__n <= capacity()) {
1396 size_type __s = size();
1397 std::fill_n(this->__begin_, std::min(__n, __s), __u);
1398 if (__n > __s)
1399 __construct_at_end(__n - __s, __u);
1400 else
1401 this->__destruct_at_end(this->__begin_ + __n);
1402 } else {
1403 __vdeallocate();
1404 __vallocate(__recommend(static_cast<size_type>(__n)));
1405 __construct_at_end(__n, __u);
1406 }
1407}
1408
1409template <class _Tp, class _Allocator>
1410_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator
1411vector<_Tp, _Allocator>::begin() _NOEXCEPT {
1412 return __make_iter(this->__begin_);
1413}
1414
1415template <class _Tp, class _Allocator>
1416_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::const_iterator
1417vector<_Tp, _Allocator>::begin() const _NOEXCEPT {
1418 return __make_iter(this->__begin_);
1419}
1420
1421template <class _Tp, class _Allocator>
1422_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator
1423vector<_Tp, _Allocator>::end() _NOEXCEPT {
1424 return __make_iter(this->__end_);
1425}
1426
1427template <class _Tp, class _Allocator>
1428_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::const_iterator
1429vector<_Tp, _Allocator>::end() const _NOEXCEPT {
1430 return __make_iter(this->__end_);
1431}
1432
1433template <class _Tp, class _Allocator>
1434_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::reference
1435vector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT {
1436 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector[] index out of bounds");
1437 return this->__begin_[__n];
1438}
1439
1440template <class _Tp, class _Allocator>
1441_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::const_reference
1442vector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT {
1443 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector[] index out of bounds");
1444 return this->__begin_[__n];
1445}
1446
1447template <class _Tp, class _Allocator>
1448_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::reference vector<_Tp, _Allocator>::at(size_type __n) {
1449 if (__n >= size())
1450 this->__throw_out_of_range();
1451 return this->__begin_[__n];
1452}
1453
1454template <class _Tp, class _Allocator>
1455_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::const_reference
1456vector<_Tp, _Allocator>::at(size_type __n) const {
1457 if (__n >= size())
1458 this->__throw_out_of_range();
1459 return this->__begin_[__n];
1460}
1461
1462template <class _Tp, class _Allocator>
1463_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::reserve(size_type __n) {
1464 if (__n > capacity()) {
1465 if (__n > max_size())
1466 this->__throw_length_error();
1467 allocator_type& __a = this->__alloc();
1468 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
1469 __swap_out_circular_buffer(__v);
1470 }
1471}
1472
1473template <class _Tp, class _Allocator>
1474_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT {
1475 if (capacity() > size()) {
1476#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1477 try {
1478#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1479 allocator_type& __a = this->__alloc();
1480 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
1481 // The Standard mandates shrink_to_fit() does not increase the capacity.
1482 // With equal capacity keep the existing buffer. This avoids extra work
1483 // due to swapping the elements.
1484 if (__v.capacity() < capacity())
1485 __swap_out_circular_buffer(__v);
1486#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1487 } catch (...) {
1488 }
1489#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1490 }
1491}
1492
1493template <class _Tp, class _Allocator>
1494template <class _Up>
1495_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::pointer
1496vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) {
1497 allocator_type& __a = this->__alloc();
1498 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1499 // __v.push_back(std::forward<_Up>(__x));
1500 __alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Up>(__x));
1501 __v.__end_++;
1502 __swap_out_circular_buffer(__v);
1503 return this->__end_;
1504}
1505
1506template <class _Tp, class _Allocator>
1507_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void
1508vector<_Tp, _Allocator>::push_back(const_reference __x) {
1509 pointer __end = this->__end_;
1510 if (__end < this->__end_cap()) {
1511 __construct_one_at_end(__x);
1512 ++__end;
1513 } else {
1514 __end = __push_back_slow_path(__x);
1515 }
1516 this->__end_ = __end;
1517}
1518
1519template <class _Tp, class _Allocator>
1520_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void vector<_Tp, _Allocator>::push_back(value_type&& __x) {
1521 pointer __end = this->__end_;
1522 if (__end < this->__end_cap()) {
1523 __construct_one_at_end(std::move(__x));
1524 ++__end;
1525 } else {
1526 __end = __push_back_slow_path(std::move(__x));
1527 }
1528 this->__end_ = __end;
1529}
1530
1531template <class _Tp, class _Allocator>
1532template <class... _Args>
1533_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::pointer
1534vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) {
1535 allocator_type& __a = this->__alloc();
1536 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1537 // __v.emplace_back(std::forward<_Args>(__args)...);
1538 __alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Args>(__args)...);
1539 __v.__end_++;
1540 __swap_out_circular_buffer(__v);
1541 return this->__end_;
1542}
1543
1544template <class _Tp, class _Allocator>
1545template <class... _Args>
1546_LIBCPP_CONSTEXPR_SINCE_CXX20 inline
1547#if _LIBCPP_STD_VER >= 17
1548 typename vector<_Tp, _Allocator>::reference
307#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
308# include <__cxx03/vector>
1549309#else
1550 void
1551#endif
1552 vector<_Tp, _Allocator>::emplace_back(_Args&&... __args) {
1553 pointer __end = this->__end_;
1554 if (__end < this->__end_cap()) {
1555 __construct_one_at_end(std::forward<_Args>(__args)...);
1556 ++__end;
1557 } else {
1558 __end = __emplace_back_slow_path(std::forward<_Args>(__args)...);
1559 }
1560 this->__end_ = __end;
1561#if _LIBCPP_STD_VER >= 17
1562 return *(__end - 1);
1563#endif
1564}
1565
1566template <class _Tp, class _Allocator>
1567_LIBCPP_CONSTEXPR_SINCE_CXX20 inline void vector<_Tp, _Allocator>::pop_back() {
1568 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector::pop_back called on an empty vector");
1569 this->__destruct_at_end(this->__end_ - 1);
1570}
1571
1572template <class _Tp, class _Allocator>
1573_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator
1574vector<_Tp, _Allocator>::erase(const_iterator __position) {
1575 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
1576 __position != end(), "vector::erase(iterator) called with a non-dereferenceable iterator");
1577 difference_type __ps = __position - cbegin();
1578 pointer __p = this->__begin_ + __ps;
1579 this->__destruct_at_end(std::move(__p + 1, this->__end_, __p));
1580 return __make_iter(__p);
1581}
1582
1583template <class _Tp, class _Allocator>
1584_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1585vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) {
1586 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__first <= __last, "vector::erase(first, last) called with invalid range");
1587 pointer __p = this->__begin_ + (__first - begin());
1588 if (__first != __last) {
1589 this->__destruct_at_end(std::move(__p + (__last - __first), this->__end_, __p));
1590 }
1591 return __make_iter(__p);
1592}
1593
1594template <class _Tp, class _Allocator>
1595_LIBCPP_CONSTEXPR_SINCE_CXX20 void
1596vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) {
1597 pointer __old_last = this->__end_;
1598 difference_type __n = __old_last - __to;
1599 {
1600 pointer __i = __from_s + __n;
1601 _ConstructTransaction __tx(*this, __from_e - __i);
1602 for (pointer __pos = __tx.__pos_; __i < __from_e; ++__i, (void)++__pos, __tx.__pos_ = __pos) {
1603 __alloc_traits::construct(this->__alloc(), std::__to_address(__pos), std::move(*__i));
1604 }
1605 }
1606 std::move_backward(__from_s, __from_s + __n, __old_last);
1607}
1608
1609template <class _Tp, class _Allocator>
1610_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1611vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) {
1612 pointer __p = this->__begin_ + (__position - begin());
1613 if (this->__end_ < this->__end_cap()) {
1614 if (__p == this->__end_) {
1615 __construct_one_at_end(__x);
1616 } else {
1617 __move_range(__p, this->__end_, __p + 1);
1618 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1619 if (std::__is_pointer_in_range(std::__to_address(__p), std::__to_address(__end_), std::addressof(__x)))
1620 ++__xr;
1621 *__p = *__xr;
1622 }
1623 } else {
1624 allocator_type& __a = this->__alloc();
1625 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1626 __v.push_back(__x);
1627 __p = __swap_out_circular_buffer(__v, __p);
1628 }
1629 return __make_iter(__p);
1630}
1631
1632template <class _Tp, class _Allocator>
1633_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1634vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) {
1635 pointer __p = this->__begin_ + (__position - begin());
1636 if (this->__end_ < this->__end_cap()) {
1637 if (__p == this->__end_) {
1638 __construct_one_at_end(std::move(__x));
1639 } else {
1640 __move_range(__p, this->__end_, __p + 1);
1641 *__p = std::move(__x);
1642 }
1643 } else {
1644 allocator_type& __a = this->__alloc();
1645 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1646 __v.push_back(std::move(__x));
1647 __p = __swap_out_circular_buffer(__v, __p);
1648 }
1649 return __make_iter(__p);
1650}
1651
1652template <class _Tp, class _Allocator>
1653template <class... _Args>
1654_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1655vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) {
1656 pointer __p = this->__begin_ + (__position - begin());
1657 if (this->__end_ < this->__end_cap()) {
1658 if (__p == this->__end_) {
1659 __construct_one_at_end(std::forward<_Args>(__args)...);
1660 } else {
1661 __temp_value<value_type, _Allocator> __tmp(this->__alloc(), std::forward<_Args>(__args)...);
1662 __move_range(__p, this->__end_, __p + 1);
1663 *__p = std::move(__tmp.get());
1664 }
1665 } else {
1666 allocator_type& __a = this->__alloc();
1667 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1668 __v.emplace_back(std::forward<_Args>(__args)...);
1669 __p = __swap_out_circular_buffer(__v, __p);
1670 }
1671 return __make_iter(__p);
1672}
1673
1674template <class _Tp, class _Allocator>
1675_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1676vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) {
1677 pointer __p = this->__begin_ + (__position - begin());
1678 if (__n > 0) {
1679 // We can't compare unrelated pointers inside constant expressions
1680 if (!__libcpp_is_constant_evaluated() && __n <= static_cast<size_type>(this->__end_cap() - this->__end_)) {
1681 size_type __old_n = __n;
1682 pointer __old_last = this->__end_;
1683 if (__n > static_cast<size_type>(this->__end_ - __p)) {
1684 size_type __cx = __n - (this->__end_ - __p);
1685 __construct_at_end(__cx, __x);
1686 __n -= __cx;
1687 }
1688 if (__n > 0) {
1689 __move_range(__p, __old_last, __p + __old_n);
1690 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1691 if (__p <= __xr && __xr < this->__end_)
1692 __xr += __old_n;
1693 std::fill_n(__p, __n, *__xr);
1694 }
1695 } else {
1696 allocator_type& __a = this->__alloc();
1697 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1698 __v.__construct_at_end(__n, __x);
1699 __p = __swap_out_circular_buffer(__v, __p);
1700 }
1701 }
1702 return __make_iter(__p);
1703}
1704template <class _Tp, class _Allocator>
1705template <class _InputIterator,
1706 __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
1707 is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
1708 int> >
1709_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1710vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) {
1711 return __insert_with_sentinel(__position, __first, __last);
1712}
1713
1714template <class _Tp, class _Allocator>
1715template <class _InputIterator, class _Sentinel>
1716_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator
1717vector<_Tp, _Allocator>::__insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last) {
1718 difference_type __off = __position - begin();
1719 pointer __p = this->__begin_ + __off;
1720 allocator_type& __a = this->__alloc();
1721 pointer __old_last = this->__end_;
1722 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first) {
1723 __construct_one_at_end(*__first);
1724 }
1725 __split_buffer<value_type, allocator_type&> __v(__a);
1726 if (__first != __last) {
1727#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1728 try {
1729#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1730 __v.__construct_at_end_with_sentinel(std::move(__first), std::move(__last));
1731 difference_type __old_size = __old_last - this->__begin_;
1732 difference_type __old_p = __p - this->__begin_;
1733 reserve(__recommend(size() + __v.size()));
1734 __p = this->__begin_ + __old_p;
1735 __old_last = this->__begin_ + __old_size;
1736#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1737 } catch (...) {
1738 erase(__make_iter(__old_last), end());
1739 throw;
1740 }
1741#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1742 }
1743 __p = std::rotate(__p, __old_last, this->__end_);
1744 insert(__make_iter(__p), std::make_move_iterator(__v.begin()), std::make_move_iterator(__v.end()));
1745 return begin() + __off;
1746}
1747
1748template <class _Tp, class _Allocator>
1749template <class _ForwardIterator,
1750 __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
1751 is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
1752 int> >
1753_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1754vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) {
1755 return __insert_with_size(__position, __first, __last, std::distance(__first, __last));
1756}
1757
1758template <class _Tp, class _Allocator>
1759template <class _Iterator, class _Sentinel>
1760_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator
1761vector<_Tp, _Allocator>::__insert_with_size(
1762 const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n) {
1763 auto __insertion_size = __n;
1764 pointer __p = this->__begin_ + (__position - begin());
1765 if (__n > 0) {
1766 if (__n <= this->__end_cap() - this->__end_) {
1767 size_type __old_n = __n;
1768 pointer __old_last = this->__end_;
1769 _Iterator __m = std::next(__first, __n);
1770 difference_type __dx = this->__end_ - __p;
1771 if (__n > __dx) {
1772 __m = __first;
1773 difference_type __diff = this->__end_ - __p;
1774 std::advance(__m, __diff);
1775 __construct_at_end(__m, __last, __n - __diff);
1776 __n = __dx;
1777 }
1778 if (__n > 0) {
1779 __move_range(__p, __old_last, __p + __old_n);
1780 std::copy(__first, __m, __p);
1781 }
1782 } else {
1783 allocator_type& __a = this->__alloc();
1784 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1785 __v.__construct_at_end_with_size(__first, __insertion_size);
1786 __p = __swap_out_circular_buffer(__v, __p);
1787 }
1788 }
1789 return __make_iter(__p);
1790}
1791
1792template <class _Tp, class _Allocator>
1793_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::resize(size_type __sz) {
1794 size_type __cs = size();
1795 if (__cs < __sz)
1796 this->__append(__sz - __cs);
1797 else if (__cs > __sz)
1798 this->__destruct_at_end(this->__begin_ + __sz);
1799}
1800
1801template <class _Tp, class _Allocator>
1802_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x) {
1803 size_type __cs = size();
1804 if (__cs < __sz)
1805 this->__append(__sz - __cs, __x);
1806 else if (__cs > __sz)
1807 this->__destruct_at_end(this->__begin_ + __sz);
1808}
1809
1810template <class _Tp, class _Allocator>
1811_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::swap(vector& __x)
1812#if _LIBCPP_STD_VER >= 14
1813 _NOEXCEPT
1814#else
1815 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>)
1816#endif
1817{
1818 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1819 __alloc_traits::propagate_on_container_swap::value || this->__alloc() == __x.__alloc(),
1820 "vector::swap: Either propagate_on_container_swap must be true"
1821 " or the allocators must compare equal");
1822 std::swap(this->__begin_, __x.__begin_);
1823 std::swap(this->__end_, __x.__end_);
1824 std::swap(this->__end_cap(), __x.__end_cap());
1825 std::__swap_allocator(
1826 this->__alloc(), __x.__alloc(), integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
1827}
1828
1829template <class _Tp, class _Allocator>
1830_LIBCPP_CONSTEXPR_SINCE_CXX20 bool vector<_Tp, _Allocator>::__invariants() const {
1831 if (this->__begin_ == nullptr) {
1832 if (this->__end_ != nullptr || this->__end_cap() != nullptr)
1833 return false;
1834 } else {
1835 if (this->__begin_ > this->__end_)
1836 return false;
1837 if (this->__begin_ == this->__end_cap())
1838 return false;
1839 if (this->__end_ > this->__end_cap())
1840 return false;
1841 }
1842 return true;
1843}
1844
1845// vector<bool>
1846
1847template <class _Allocator>
1848class vector<bool, _Allocator>;
1849
1850template <class _Allocator>
1851struct hash<vector<bool, _Allocator> >;
1852
1853template <class _Allocator>
1854struct __has_storage_type<vector<bool, _Allocator> > {
1855 static const bool value = true;
1856};
310# include <__config>
1857311
1858template <class _Allocator>
1859class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> {
1860public:
1861 typedef vector __self;
1862 typedef bool value_type;
1863 typedef _Allocator allocator_type;
1864 typedef allocator_traits<allocator_type> __alloc_traits;
1865 typedef typename __alloc_traits::size_type size_type;
1866 typedef typename __alloc_traits::difference_type difference_type;
1867 typedef size_type __storage_type;
1868 typedef __bit_iterator<vector, false> pointer;
1869 typedef __bit_iterator<vector, true> const_pointer;
1870 typedef pointer iterator;
1871 typedef const_pointer const_iterator;
1872 typedef std::reverse_iterator<iterator> reverse_iterator;
1873 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
1874
1875private:
1876 typedef __rebind_alloc<__alloc_traits, __storage_type> __storage_allocator;
1877 typedef allocator_traits<__storage_allocator> __storage_traits;
1878 typedef typename __storage_traits::pointer __storage_pointer;
1879 typedef typename __storage_traits::const_pointer __const_storage_pointer;
1880
1881 __storage_pointer __begin_;
1882 size_type __size_;
1883 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
312# include <__vector/comparison.h>
313# include <__vector/swap.h>
314# include <__vector/vector.h>
315# include <__vector/vector_bool.h>
1884316
1885public:
1886 typedef __bit_reference<vector> reference;
1887#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
1888 using const_reference = bool;
1889#else
1890 typedef __bit_const_reference<vector> const_reference;
1891#endif
1892
1893private:
1894 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type& __cap() _NOEXCEPT { return __cap_alloc_.first(); }
1895 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const size_type& __cap() const _NOEXCEPT {
1896 return __cap_alloc_.first();
1897 }
1898 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __storage_allocator& __alloc() _NOEXCEPT {
1899 return __cap_alloc_.second();
1900 }
1901 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const __storage_allocator& __alloc() const _NOEXCEPT {
1902 return __cap_alloc_.second();
1903 }
1904
1905 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
1906
1907 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type
1908 __internal_cap_to_external(size_type __n) _NOEXCEPT {
1909 return __n * __bits_per_word;
1910 }
1911 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type
1912 __external_cap_to_internal(size_type __n) _NOEXCEPT {
1913 return (__n - 1) / __bits_per_word + 1;
1914 }
317# if _LIBCPP_STD_VER >= 17
318# include <__vector/pmr.h>
319# endif
1915320
1916public:
1917 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector()
1918 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
321# if _LIBCPP_STD_VER >= 20
322# include <__vector/erase.h>
323# endif
1919324
1920 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(const allocator_type& __a)
1921#if _LIBCPP_STD_VER <= 14
1922 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
1923#else
1924 _NOEXCEPT;
1925#endif
325# if _LIBCPP_STD_VER >= 23
326# include <__vector/vector_bool_formatter.h>
327# endif
1926328
1927private:
1928 class __destroy_vector {
1929 public:
1930 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __destroy_vector(vector& __vec) : __vec_(__vec) {}
329# include <version>
1931330
1932 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() {
1933 if (__vec_.__begin_ != nullptr)
1934 __storage_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.__cap());
1935 }
331// standard-mandated includes
1936332
1937 private:
1938 vector& __vec_;
1939 };
333// [iterator.range]
334# include <__iterator/access.h>
335# include <__iterator/data.h>
336# include <__iterator/empty.h>
337# include <__iterator/reverse_access.h>
338# include <__iterator/size.h>
1940339
1941public:
1942 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~vector() { __destroy_vector (*this)(); }
1943
1944 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n);
1945#if _LIBCPP_STD_VER >= 14
1946 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n, const allocator_type& __a);
1947#endif
1948 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(size_type __n, const value_type& __v);
1949 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1950 vector(size_type __n, const value_type& __v, const allocator_type& __a);
1951 template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
1952 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_InputIterator __first, _InputIterator __last);
1953 template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
1954 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1955 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
1956 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
1957 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_ForwardIterator __first, _ForwardIterator __last);
1958 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
1959 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1960 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a);
1961
1962#if _LIBCPP_STD_VER >= 23
1963 template <_ContainerCompatibleRange<bool> _Range>
1964 _LIBCPP_HIDE_FROM_ABI constexpr vector(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
1965 : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
1966 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
1967 auto __n = static_cast<size_type>(ranges::distance(__range));
1968 __init_with_size(ranges::begin(__range), ranges::end(__range), __n);
1969
1970 } else {
1971 __init_with_sentinel(ranges::begin(__range), ranges::end(__range));
1972 }
1973 }
1974#endif
1975
1976 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v);
1977 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v, const allocator_type& __a);
1978 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(const vector& __v);
1979
1980#ifndef _LIBCPP_CXX03_LANG
1981 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(initializer_list<value_type> __il);
1982 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1983 vector(initializer_list<value_type> __il, const allocator_type& __a);
1984
1985 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(initializer_list<value_type> __il) {
1986 assign(__il.begin(), __il.end());
1987 return *this;
1988 }
1989
1990#endif // !_LIBCPP_CXX03_LANG
1991
1992 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(vector&& __v)
1993#if _LIBCPP_STD_VER >= 17
1994 noexcept;
1995#else
1996 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
1997#endif
1998 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1999 vector(vector&& __v, const __type_identity_t<allocator_type>& __a);
2000 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(vector&& __v)
2001 _NOEXCEPT_(__noexcept_move_assign_container<_Allocator, __alloc_traits>::value);
2002
2003 template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
2004 void _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_InputIterator __first, _InputIterator __last);
2005 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
2006 void _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_ForwardIterator __first, _ForwardIterator __last);
2007
2008#if _LIBCPP_STD_VER >= 23
2009 template <_ContainerCompatibleRange<bool> _Range>
2010 _LIBCPP_HIDE_FROM_ABI constexpr void assign_range(_Range&& __range) {
2011 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
2012 auto __n = static_cast<size_type>(ranges::distance(__range));
2013 __assign_with_size(ranges::begin(__range), ranges::end(__range), __n);
2014
2015 } else {
2016 __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
2017 }
2018 }
2019#endif
2020
2021 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void assign(size_type __n, const value_type& __x);
2022
2023#ifndef _LIBCPP_CXX03_LANG
2024 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void assign(initializer_list<value_type> __il) {
2025 assign(__il.begin(), __il.end());
2026 }
2027#endif
2028
2029 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator_type get_allocator() const _NOEXCEPT {
2030 return allocator_type(this->__alloc());
2031 }
2032
2033 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT;
2034 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type capacity() const _NOEXCEPT {
2035 return __internal_cap_to_external(__cap());
2036 }
2037 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type size() const _NOEXCEPT { return __size_; }
2038 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool empty() const _NOEXCEPT {
2039 return __size_ == 0;
2040 }
2041 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void reserve(size_type __n);
2042 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT;
2043
2044 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator begin() _NOEXCEPT { return __make_iter(0); }
2045 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator begin() const _NOEXCEPT { return __make_iter(0); }
2046 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator end() _NOEXCEPT { return __make_iter(__size_); }
2047 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator end() const _NOEXCEPT {
2048 return __make_iter(__size_);
2049 }
2050
2051 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator rbegin() _NOEXCEPT {
2052 return reverse_iterator(end());
2053 }
2054 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator rbegin() const _NOEXCEPT {
2055 return const_reverse_iterator(end());
2056 }
2057 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator rend() _NOEXCEPT {
2058 return reverse_iterator(begin());
2059 }
2060 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator rend() const _NOEXCEPT {
2061 return const_reverse_iterator(begin());
2062 }
2063
2064 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator cbegin() const _NOEXCEPT { return __make_iter(0); }
2065 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator cend() const _NOEXCEPT {
2066 return __make_iter(__size_);
2067 }
2068 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator crbegin() const _NOEXCEPT {
2069 return rbegin();
2070 }
2071 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
2072
2073 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator[](size_type __n) { return __make_ref(__n); }
2074 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference operator[](size_type __n) const {
2075 return __make_ref(__n);
2076 }
2077 _LIBCPP_HIDE_FROM_ABI reference at(size_type __n);
2078 _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const;
2079
2080 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference front() { return __make_ref(0); }
2081 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front() const { return __make_ref(0); }
2082 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference back() { return __make_ref(__size_ - 1); }
2083 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference back() const { return __make_ref(__size_ - 1); }
2084
2085 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(const value_type& __x);
2086#if _LIBCPP_STD_VER >= 14
2087 template <class... _Args>
2088# if _LIBCPP_STD_VER >= 17
2089 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference emplace_back(_Args&&... __args)
2090# else
2091 _LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args)
2092# endif
2093 {
2094 push_back(value_type(std::forward<_Args>(__args)...));
2095# if _LIBCPP_STD_VER >= 17
2096 return this->back();
2097# endif
2098 }
2099#endif
2100
2101#if _LIBCPP_STD_VER >= 23
2102 template <_ContainerCompatibleRange<bool> _Range>
2103 _LIBCPP_HIDE_FROM_ABI constexpr void append_range(_Range&& __range) {
2104 insert_range(end(), std::forward<_Range>(__range));
2105 }
2106#endif
2107
2108 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back() { --__size_; }
2109
2110#if _LIBCPP_STD_VER >= 14
2111 template <class... _Args>
2112 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator emplace(const_iterator __position, _Args&&... __args) {
2113 return insert(__position, value_type(std::forward<_Args>(__args)...));
2114 }
2115#endif
2116
2117 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, const value_type& __x);
2118 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
2119 insert(const_iterator __position, size_type __n, const value_type& __x);
2120 template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
2121 iterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
2122 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2123 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
2124 iterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
2125 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
2126
2127#if _LIBCPP_STD_VER >= 23
2128 template <_ContainerCompatibleRange<bool> _Range>
2129 _LIBCPP_HIDE_FROM_ABI constexpr iterator insert_range(const_iterator __position, _Range&& __range) {
2130 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
2131 auto __n = static_cast<size_type>(ranges::distance(__range));
2132 return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n);
2133
2134 } else {
2135 return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
2136 }
2137 }
2138#endif
2139
2140#ifndef _LIBCPP_CXX03_LANG
2141 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
2142 insert(const_iterator __position, initializer_list<value_type> __il) {
2143 return insert(__position, __il.begin(), __il.end());
2144 }
2145#endif
2146
2147 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __position);
2148 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __first, const_iterator __last);
2149
2150 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void clear() _NOEXCEPT { __size_ = 0; }
2151
2152 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(vector&)
2153#if _LIBCPP_STD_VER >= 14
2154 _NOEXCEPT;
2155#else
2156 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>);
2157#endif
2158 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void swap(reference __x, reference __y) _NOEXCEPT {
2159 std::swap(__x, __y);
2160 }
2161
2162 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __sz, value_type __x = false);
2163 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void flip() _NOEXCEPT;
2164
2165 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const;
2166
2167private:
2168 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_length_error() const { std::__throw_length_error("vector"); }
2169
2170 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { std::__throw_out_of_range("vector"); }
2171
2172 template <class _InputIterator, class _Sentinel>
2173 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
2174 __init_with_size(_InputIterator __first, _Sentinel __last, size_type __n) {
2175 auto __guard = std::__make_exception_guard(__destroy_vector(*this));
2176
2177 if (__n > 0) {
2178 __vallocate(__n);
2179 __construct_at_end(std::move(__first), std::move(__last), __n);
2180 }
2181
2182 __guard.__complete();
2183 }
2184
2185 template <class _InputIterator, class _Sentinel>
2186 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
2187 __init_with_sentinel(_InputIterator __first, _Sentinel __last) {
2188#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2189 try {
2190#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2191 for (; __first != __last; ++__first)
2192 push_back(*__first);
2193#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2194 } catch (...) {
2195 if (__begin_ != nullptr)
2196 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2197 throw;
2198 }
2199#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2200 }
2201
2202 template <class _Iterator, class _Sentinel>
2203 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iterator __first, _Sentinel __last);
2204
2205 template <class _ForwardIterator, class _Sentinel>
2206 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
2207 __assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __ns);
2208
2209 template <class _InputIterator, class _Sentinel>
2210 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
2211 __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last);
2212
2213 template <class _Iterator, class _Sentinel>
2214 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
2215 __insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n);
2216
2217 // Allocate space for __n objects
2218 // throws length_error if __n > max_size()
2219 // throws (probably bad_alloc) if memory run out
2220 // Precondition: __begin_ == __end_ == __cap() == 0
2221 // Precondition: __n > 0
2222 // Postcondition: capacity() >= __n
2223 // Postcondition: size() == 0
2224 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vallocate(size_type __n) {
2225 if (__n > max_size())
2226 __throw_length_error();
2227 auto __allocation = std::__allocate_at_least(__alloc(), __external_cap_to_internal(__n));
2228 __begin_ = __allocation.ptr;
2229 __size_ = 0;
2230 __cap() = __allocation.count;
2231 if (__libcpp_is_constant_evaluated()) {
2232 for (size_type __i = 0; __i != __cap(); ++__i)
2233 std::__construct_at(std::__to_address(__begin_) + __i);
2234 }
2235 }
2236
2237 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vdeallocate() _NOEXCEPT;
2238 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type __align_it(size_type __new_size) _NOEXCEPT {
2239 return (__new_size + (__bits_per_word - 1)) & ~((size_type)__bits_per_word - 1);
2240 }
2241 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __recommend(size_type __new_size) const;
2242 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __construct_at_end(size_type __n, bool __x);
2243 template <class _InputIterator, class _Sentinel>
2244 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
2245 __construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n);
2246 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __append(size_type __n, const_reference __x);
2247 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference __make_ref(size_type __pos) _NOEXCEPT {
2248 return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
2249 }
2250 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference __make_ref(size_type __pos) const _NOEXCEPT {
2251 return __bit_const_reference<vector>(
2252 __begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
2253 }
2254 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator __make_iter(size_type __pos) _NOEXCEPT {
2255 return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));
2256 }
2257 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator __make_iter(size_type __pos) const _NOEXCEPT {
2258 return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));
2259 }
2260 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT {
2261 return begin() + (__p - cbegin());
2262 }
2263
2264 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __copy_assign_alloc(const vector& __v) {
2265 __copy_assign_alloc(
2266 __v, integral_constant<bool, __storage_traits::propagate_on_container_copy_assignment::value>());
2267 }
2268 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __copy_assign_alloc(const vector& __c, true_type) {
2269 if (__alloc() != __c.__alloc())
2270 __vdeallocate();
2271 __alloc() = __c.__alloc();
2272 }
2273
2274 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __copy_assign_alloc(const vector&, false_type) {}
2275
2276 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, false_type);
2277 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, true_type)
2278 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
2279 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(vector& __c)
2280 _NOEXCEPT_(!__storage_traits::propagate_on_container_move_assignment::value ||
2281 is_nothrow_move_assignable<allocator_type>::value) {
2282 __move_assign_alloc(
2283 __c, integral_constant<bool, __storage_traits::propagate_on_container_move_assignment::value>());
2284 }
2285 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(vector& __c, true_type)
2286 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
2287 __alloc() = std::move(__c.__alloc());
2288 }
2289
2290 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(vector&, false_type) _NOEXCEPT {}
2291
2292 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t __hash_code() const _NOEXCEPT;
2293
2294 friend class __bit_reference<vector>;
2295 friend class __bit_const_reference<vector>;
2296 friend class __bit_iterator<vector, false>;
2297 friend class __bit_iterator<vector, true>;
2298 friend struct __bit_array<vector>;
2299 friend struct _LIBCPP_TEMPLATE_VIS hash<vector>;
2300};
340// [vector.syn]
341# include <compare>
342# include <initializer_list>
2301343
2302template <class _Allocator>
2303_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::__vdeallocate() _NOEXCEPT {
2304 if (this->__begin_ != nullptr) {
2305 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2306 this->__begin_ = nullptr;
2307 this->__size_ = this->__cap() = 0;
2308 }
2309}
2310
2311template <class _Allocator>
2312_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::size_type
2313vector<bool, _Allocator>::max_size() const _NOEXCEPT {
2314 size_type __amax = __storage_traits::max_size(__alloc());
2315 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2316 if (__nmax / __bits_per_word <= __amax)
2317 return __nmax;
2318 return __internal_cap_to_external(__amax);
2319}
2320
2321// Precondition: __new_size > capacity()
2322template <class _Allocator>
2323inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::size_type
2324vector<bool, _Allocator>::__recommend(size_type __new_size) const {
2325 const size_type __ms = max_size();
2326 if (__new_size > __ms)
2327 this->__throw_length_error();
2328 const size_type __cap = capacity();
2329 if (__cap >= __ms / 2)
2330 return __ms;
2331 return std::max(2 * __cap, __align_it(__new_size));
2332}
2333
2334// Default constructs __n objects starting at __end_
2335// Precondition: __n > 0
2336// Precondition: size() + __n <= capacity()
2337// Postcondition: size() == size() + __n
2338template <class _Allocator>
2339inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
2340vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) {
2341 size_type __old_size = this->__size_;
2342 this->__size_ += __n;
2343 if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) {
2344 if (this->__size_ <= __bits_per_word)
2345 this->__begin_[0] = __storage_type(0);
2346 else
2347 this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
2348 }
2349 std::fill_n(__make_iter(__old_size), __n, __x);
2350}
2351
2352template <class _Allocator>
2353template <class _InputIterator, class _Sentinel>
2354_LIBCPP_CONSTEXPR_SINCE_CXX20 void
2355vector<bool, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
2356 size_type __old_size = this->__size_;
2357 this->__size_ += __n;
2358 if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) {
2359 if (this->__size_ <= __bits_per_word)
2360 this->__begin_[0] = __storage_type(0);
2361 else
2362 this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
2363 }
2364 std::__copy<_ClassicAlgPolicy>(__first, __last, __make_iter(__old_size));
2365}
2366
2367template <class _Allocator>
2368inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector()
2369 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
2370 : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {}
2371
2372template <class _Allocator>
2373inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(const allocator_type& __a)
2374#if _LIBCPP_STD_VER <= 14
2375 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
2376#else
2377 _NOEXCEPT
2378#endif
2379 : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
2380}
2381
2382template <class _Allocator>
2383_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(size_type __n)
2384 : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {
2385 if (__n > 0) {
2386 __vallocate(__n);
2387 __construct_at_end(__n, false);
2388 }
2389}
2390
2391#if _LIBCPP_STD_VER >= 14
2392template <class _Allocator>
2393_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
2394 : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
2395 if (__n > 0) {
2396 __vallocate(__n);
2397 __construct_at_end(__n, false);
2398 }
2399}
2400#endif
2401
2402template <class _Allocator>
2403_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
2404 : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {
2405 if (__n > 0) {
2406 __vallocate(__n);
2407 __construct_at_end(__n, __x);
2408 }
2409}
2410
2411template <class _Allocator>
2412_LIBCPP_CONSTEXPR_SINCE_CXX20
2413vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2414 : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
2415 if (__n > 0) {
2416 __vallocate(__n);
2417 __construct_at_end(__n, __x);
2418 }
2419}
2420
2421template <class _Allocator>
2422template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
2423_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last)
2424 : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {
2425 __init_with_sentinel(__first, __last);
2426}
2427
2428template <class _Allocator>
2429template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
2430_LIBCPP_CONSTEXPR_SINCE_CXX20
2431vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a)
2432 : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
2433 __init_with_sentinel(__first, __last);
2434}
2435
2436template <class _Allocator>
2437template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
2438_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last)
2439 : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {
2440 auto __n = static_cast<size_type>(std::distance(__first, __last));
2441 __init_with_size(__first, __last, __n);
2442}
2443
2444template <class _Allocator>
2445template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
2446_LIBCPP_CONSTEXPR_SINCE_CXX20
2447vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a)
2448 : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
2449 auto __n = static_cast<size_type>(std::distance(__first, __last));
2450 __init_with_size(__first, __last, __n);
2451}
2452
2453#ifndef _LIBCPP_CXX03_LANG
2454
2455template <class _Allocator>
2456_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
2457 : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {
2458 size_type __n = static_cast<size_type>(__il.size());
2459 if (__n > 0) {
2460 __vallocate(__n);
2461 __construct_at_end(__il.begin(), __il.end(), __n);
2462 }
2463}
2464
2465template <class _Allocator>
2466_LIBCPP_CONSTEXPR_SINCE_CXX20
2467vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2468 : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
2469 size_type __n = static_cast<size_type>(__il.size());
2470 if (__n > 0) {
2471 __vallocate(__n);
2472 __construct_at_end(__il.begin(), __il.end(), __n);
2473 }
2474}
2475
2476#endif // _LIBCPP_CXX03_LANG
2477
2478template <class _Allocator>
2479_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(const vector& __v)
2480 : __begin_(nullptr),
2481 __size_(0),
2482 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) {
2483 if (__v.size() > 0) {
2484 __vallocate(__v.size());
2485 __construct_at_end(__v.begin(), __v.end(), __v.size());
2486 }
2487}
2488
2489template <class _Allocator>
2490_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2491 : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) {
2492 if (__v.size() > 0) {
2493 __vallocate(__v.size());
2494 __construct_at_end(__v.begin(), __v.end(), __v.size());
2495 }
2496}
2497
2498template <class _Allocator>
2499_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>& vector<bool, _Allocator>::operator=(const vector& __v) {
2500 if (this != std::addressof(__v)) {
2501 __copy_assign_alloc(__v);
2502 if (__v.__size_) {
2503 if (__v.__size_ > capacity()) {
2504 __vdeallocate();
2505 __vallocate(__v.__size_);
2506 }
2507 std::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
2508 }
2509 __size_ = __v.__size_;
2510 }
2511 return *this;
2512}
2513
2514template <class _Allocator>
2515inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(vector&& __v)
2516#if _LIBCPP_STD_VER >= 17
2517 _NOEXCEPT
2518#else
2519 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
2520#endif
2521 : __begin_(__v.__begin_),
2522 __size_(__v.__size_),
2523 __cap_alloc_(std::move(__v.__cap_alloc_)) {
2524 __v.__begin_ = nullptr;
2525 __v.__size_ = 0;
2526 __v.__cap() = 0;
2527}
2528
2529template <class _Allocator>
2530_LIBCPP_CONSTEXPR_SINCE_CXX20
2531vector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a)
2532 : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) {
2533 if (__a == allocator_type(__v.__alloc())) {
2534 this->__begin_ = __v.__begin_;
2535 this->__size_ = __v.__size_;
2536 this->__cap() = __v.__cap();
2537 __v.__begin_ = nullptr;
2538 __v.__cap() = __v.__size_ = 0;
2539 } else if (__v.size() > 0) {
2540 __vallocate(__v.size());
2541 __construct_at_end(__v.begin(), __v.end(), __v.size());
2542 }
2543}
2544
2545template <class _Allocator>
2546inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>&
2547vector<bool, _Allocator>::operator=(vector&& __v)
2548 _NOEXCEPT_(__noexcept_move_assign_container<_Allocator, __alloc_traits>::value) {
2549 __move_assign(__v, integral_constant<bool, __storage_traits::propagate_on_container_move_assignment::value>());
2550 return *this;
2551}
2552
2553template <class _Allocator>
2554_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::__move_assign(vector& __c, false_type) {
2555 if (__alloc() != __c.__alloc())
2556 assign(__c.begin(), __c.end());
2557 else
2558 __move_assign(__c, true_type());
2559}
2560
2561template <class _Allocator>
2562_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
2563 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
2564 __vdeallocate();
2565 __move_assign_alloc(__c);
2566 this->__begin_ = __c.__begin_;
2567 this->__size_ = __c.__size_;
2568 this->__cap() = __c.__cap();
2569 __c.__begin_ = nullptr;
2570 __c.__cap() = __c.__size_ = 0;
2571}
2572
2573template <class _Allocator>
2574_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::assign(size_type __n, const value_type& __x) {
2575 __size_ = 0;
2576 if (__n > 0) {
2577 size_type __c = capacity();
2578 if (__n <= __c)
2579 __size_ = __n;
2580 else {
2581 vector __v(get_allocator());
2582 __v.reserve(__recommend(__n));
2583 __v.__size_ = __n;
2584 swap(__v);
2585 }
2586 std::fill_n(begin(), __n, __x);
2587 }
2588}
2589
2590template <class _Allocator>
2591template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
2592_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last) {
2593 __assign_with_sentinel(__first, __last);
2594}
2595
2596template <class _Allocator>
2597template <class _Iterator, class _Sentinel>
2598_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
2599vector<bool, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __last) {
2600 clear();
2601 for (; __first != __last; ++__first)
2602 push_back(*__first);
2603}
2604
2605template <class _Allocator>
2606template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
2607_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) {
2608 __assign_with_size(__first, __last, std::distance(__first, __last));
2609}
2610
2611template <class _Allocator>
2612template <class _ForwardIterator, class _Sentinel>
2613_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
2614vector<bool, _Allocator>::__assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __ns) {
2615 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__ns >= 0, "invalid range specified");
2616
2617 clear();
2618
2619 const size_t __n = static_cast<size_type>(__ns);
2620 if (__n) {
2621 if (__n > capacity()) {
2622 __vdeallocate();
2623 __vallocate(__n);
2624 }
2625 __construct_at_end(__first, __last, __n);
2626 }
2627}
2628
2629template <class _Allocator>
2630_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::reserve(size_type __n) {
2631 if (__n > capacity()) {
2632 if (__n > max_size())
2633 this->__throw_length_error();
2634 vector __v(this->get_allocator());
2635 __v.__vallocate(__n);
2636 __v.__construct_at_end(this->begin(), this->end(), this->size());
2637 swap(__v);
2638 }
2639}
2640
2641template <class _Allocator>
2642_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT {
2643 if (__external_cap_to_internal(size()) > __cap()) {
2644#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2645 try {
2646#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2647 vector(*this, allocator_type(__alloc())).swap(*this);
2648#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2649 } catch (...) {
2650 }
2651#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2652 }
2653}
2654
2655template <class _Allocator>
2656typename vector<bool, _Allocator>::reference vector<bool, _Allocator>::at(size_type __n) {
2657 if (__n >= size())
2658 this->__throw_out_of_range();
2659 return (*this)[__n];
2660}
2661
2662template <class _Allocator>
2663typename vector<bool, _Allocator>::const_reference vector<bool, _Allocator>::at(size_type __n) const {
2664 if (__n >= size())
2665 this->__throw_out_of_range();
2666 return (*this)[__n];
2667}
2668
2669template <class _Allocator>
2670_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::push_back(const value_type& __x) {
2671 if (this->__size_ == this->capacity())
2672 reserve(__recommend(this->__size_ + 1));
2673 ++this->__size_;
2674 back() = __x;
2675}
2676
2677template <class _Allocator>
2678_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
2679vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x) {
2680 iterator __r;
2681 if (size() < capacity()) {
2682 const_iterator __old_end = end();
2683 ++__size_;
2684 std::copy_backward(__position, __old_end, end());
2685 __r = __const_iterator_cast(__position);
2686 } else {
2687 vector __v(get_allocator());
2688 __v.reserve(__recommend(__size_ + 1));
2689 __v.__size_ = __size_ + 1;
2690 __r = std::copy(cbegin(), __position, __v.begin());
2691 std::copy_backward(__position, cend(), __v.end());
2692 swap(__v);
2693 }
2694 *__r = __x;
2695 return __r;
2696}
2697
2698template <class _Allocator>
2699_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
2700vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x) {
2701 iterator __r;
2702 size_type __c = capacity();
2703 if (__n <= __c && size() <= __c - __n) {
2704 const_iterator __old_end = end();
2705 __size_ += __n;
2706 std::copy_backward(__position, __old_end, end());
2707 __r = __const_iterator_cast(__position);
2708 } else {
2709 vector __v(get_allocator());
2710 __v.reserve(__recommend(__size_ + __n));
2711 __v.__size_ = __size_ + __n;
2712 __r = std::copy(cbegin(), __position, __v.begin());
2713 std::copy_backward(__position, cend(), __v.end());
2714 swap(__v);
2715 }
2716 std::fill_n(__r, __n, __x);
2717 return __r;
2718}
2719
2720template <class _Allocator>
2721template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
2722_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
2723vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) {
2724 return __insert_with_sentinel(__position, __first, __last);
2725}
2726
2727template <class _Allocator>
2728template <class _InputIterator, class _Sentinel>
2729_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<bool, _Allocator>::iterator
2730vector<bool, _Allocator>::__insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last) {
2731 difference_type __off = __position - begin();
2732 iterator __p = __const_iterator_cast(__position);
2733 iterator __old_end = end();
2734 for (; size() != capacity() && __first != __last; ++__first) {
2735 ++this->__size_;
2736 back() = *__first;
2737 }
2738 vector __v(get_allocator());
2739 if (__first != __last) {
2740#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2741 try {
2742#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2743 __v.__assign_with_sentinel(std::move(__first), std::move(__last));
2744 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
2745 difference_type __old_p = __p - begin();
2746 reserve(__recommend(size() + __v.size()));
2747 __p = begin() + __old_p;
2748 __old_end = begin() + __old_size;
2749#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2750 } catch (...) {
2751 erase(__old_end, end());
2752 throw;
2753 }
2754#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2755 }
2756 __p = std::rotate(__p, __old_end, end());
2757 insert(__p, __v.begin(), __v.end());
2758 return begin() + __off;
2759}
2760
2761template <class _Allocator>
2762template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
2763_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
2764vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) {
2765 return __insert_with_size(__position, __first, __last, std::distance(__first, __last));
2766}
2767
2768template <class _Allocator>
2769template <class _ForwardIterator, class _Sentinel>
2770_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<bool, _Allocator>::iterator
2771vector<bool, _Allocator>::__insert_with_size(
2772 const_iterator __position, _ForwardIterator __first, _Sentinel __last, difference_type __n_signed) {
2773 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__n_signed >= 0, "invalid range specified");
2774 const size_type __n = static_cast<size_type>(__n_signed);
2775 iterator __r;
2776 size_type __c = capacity();
2777 if (__n <= __c && size() <= __c - __n) {
2778 const_iterator __old_end = end();
2779 __size_ += __n;
2780 std::copy_backward(__position, __old_end, end());
2781 __r = __const_iterator_cast(__position);
2782 } else {
2783 vector __v(get_allocator());
2784 __v.reserve(__recommend(__size_ + __n));
2785 __v.__size_ = __size_ + __n;
2786 __r = std::copy(cbegin(), __position, __v.begin());
2787 std::copy_backward(__position, cend(), __v.end());
2788 swap(__v);
2789 }
2790 std::__copy<_ClassicAlgPolicy>(__first, __last, __r);
2791 return __r;
2792}
2793
2794template <class _Allocator>
2795inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
2796vector<bool, _Allocator>::erase(const_iterator __position) {
2797 iterator __r = __const_iterator_cast(__position);
2798 std::copy(__position + 1, this->cend(), __r);
2799 --__size_;
2800 return __r;
2801}
2802
2803template <class _Allocator>
2804_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
2805vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last) {
2806 iterator __r = __const_iterator_cast(__first);
2807 difference_type __d = __last - __first;
2808 std::copy(__last, this->cend(), __r);
2809 __size_ -= __d;
2810 return __r;
2811}
2812
2813template <class _Allocator>
2814_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::swap(vector& __x)
2815#if _LIBCPP_STD_VER >= 14
2816 _NOEXCEPT
2817#else
2818 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>)
2819#endif
2820{
2821 std::swap(this->__begin_, __x.__begin_);
2822 std::swap(this->__size_, __x.__size_);
2823 std::swap(this->__cap(), __x.__cap());
2824 std::__swap_allocator(
2825 this->__alloc(), __x.__alloc(), integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
2826}
2827
2828template <class _Allocator>
2829_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::resize(size_type __sz, value_type __x) {
2830 size_type __cs = size();
2831 if (__cs < __sz) {
2832 iterator __r;
2833 size_type __c = capacity();
2834 size_type __n = __sz - __cs;
2835 if (__n <= __c && __cs <= __c - __n) {
2836 __r = end();
2837 __size_ += __n;
2838 } else {
2839 vector __v(get_allocator());
2840 __v.reserve(__recommend(__size_ + __n));
2841 __v.__size_ = __size_ + __n;
2842 __r = std::copy(cbegin(), cend(), __v.begin());
2843 swap(__v);
2844 }
2845 std::fill_n(__r, __n, __x);
2846 } else
2847 __size_ = __sz;
2848}
2849
2850template <class _Allocator>
2851_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::flip() _NOEXCEPT {
2852 // do middle whole words
2853 size_type __n = __size_;
2854 __storage_pointer __p = __begin_;
2855 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
2856 *__p = ~*__p;
2857 // do last partial word
2858 if (__n > 0) {
2859 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
2860 __storage_type __b = *__p & __m;
2861 *__p &= ~__m;
2862 *__p |= ~__b & __m;
2863 }
2864}
2865
2866template <class _Allocator>
2867_LIBCPP_CONSTEXPR_SINCE_CXX20 bool vector<bool, _Allocator>::__invariants() const {
2868 if (this->__begin_ == nullptr) {
2869 if (this->__size_ != 0 || this->__cap() != 0)
2870 return false;
2871 } else {
2872 if (this->__cap() == 0)
2873 return false;
2874 if (this->__size_ > this->capacity())
2875 return false;
2876 }
2877 return true;
2878}
2879
2880template <class _Allocator>
2881_LIBCPP_CONSTEXPR_SINCE_CXX20 size_t vector<bool, _Allocator>::__hash_code() const _NOEXCEPT {
2882 size_t __h = 0;
2883 // do middle whole words
2884 size_type __n = __size_;
2885 __storage_pointer __p = __begin_;
2886 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
2887 __h ^= *__p;
2888 // do last partial word
2889 if (__n > 0) {
2890 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
2891 __h ^= *__p & __m;
2892 }
2893 return __h;
2894}
2895
2896template <class _Allocator>
2897struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
2898 : public __unary_function<vector<bool, _Allocator>, size_t> {
2899 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t
2900 operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT {
2901 return __vec.__hash_code();
2902 }
2903};
344// [vector.syn], [unord.hash]
345# include <__functional/hash.h>
2904346
2905template <class _Tp, class _Allocator>
2906_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI bool
2907operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
2908 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
2909 return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
2910}
2911
2912#if _LIBCPP_STD_VER <= 17
2913
2914template <class _Tp, class _Allocator>
2915inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
2916 return !(__x == __y);
2917}
2918
2919template <class _Tp, class _Allocator>
2920inline _LIBCPP_HIDE_FROM_ABI bool operator<(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
2921 return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
2922}
2923
2924template <class _Tp, class _Allocator>
2925inline _LIBCPP_HIDE_FROM_ABI bool operator>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
2926 return __y < __x;
2927}
2928
2929template <class _Tp, class _Allocator>
2930inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
2931 return !(__x < __y);
2932}
2933
2934template <class _Tp, class _Allocator>
2935inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
2936 return !(__y < __x);
2937}
2938
2939#else // _LIBCPP_STD_VER <= 17
2940
2941template <class _Tp, class _Allocator>
2942_LIBCPP_HIDE_FROM_ABI constexpr __synth_three_way_result<_Tp>
2943operator<=>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
2944 return std::lexicographical_compare_three_way(
2945 __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
2946}
2947
2948#endif // _LIBCPP_STD_VER <= 17
2949
2950template <class _Tp, class _Allocator>
2951_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void
2952swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
2953 __x.swap(__y);
2954}
2955
2956#if _LIBCPP_STD_VER >= 20
2957template <class _Tp, class _Allocator, class _Up>
2958_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
2959erase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
2960 auto __old_size = __c.size();
2961 __c.erase(std::remove(__c.begin(), __c.end(), __v), __c.end());
2962 return __old_size - __c.size();
2963}
2964
2965template <class _Tp, class _Allocator, class _Predicate>
2966_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
2967erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) {
2968 auto __old_size = __c.size();
2969 __c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end());
2970 return __old_size - __c.size();
2971}
2972
2973template <>
2974inline constexpr bool __format::__enable_insertable<vector<char>> = true;
2975# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2976template <>
2977inline constexpr bool __format::__enable_insertable<vector<wchar_t>> = true;
347# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
348# pragma GCC system_header
2978349# endif
2979350
2980#endif // _LIBCPP_STD_VER >= 20
2981
2982#if _LIBCPP_STD_VER >= 23
2983template <class _Tp, class _CharT>
2984// Since is-vector-bool-reference is only used once it's inlined here.
2985 requires same_as<typename _Tp::__container, vector<bool, typename _Tp::__container::allocator_type>>
2986struct _LIBCPP_TEMPLATE_VIS formatter<_Tp, _CharT> {
2987private:
2988 formatter<bool, _CharT> __underlying_;
2989
2990public:
2991 template <class _ParseContext>
2992 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
2993 return __underlying_.parse(__ctx);
2994 }
2995
2996 template <class _FormatContext>
2997 _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(const _Tp& __ref, _FormatContext& __ctx) const {
2998 return __underlying_.format(__ref, __ctx);
2999 }
3000};
3001#endif // _LIBCPP_STD_VER >= 23
3002
3003_LIBCPP_END_NAMESPACE_STD
3004
3005#if _LIBCPP_STD_VER >= 17
3006_LIBCPP_BEGIN_NAMESPACE_STD
3007namespace pmr {
3008template <class _ValueT>
3009using vector _LIBCPP_AVAILABILITY_PMR = std::vector<_ValueT, polymorphic_allocator<_ValueT>>;
3010} // namespace pmr
3011_LIBCPP_END_NAMESPACE_STD
3012#endif
3013
3014_LIBCPP_POP_MACROS
3015
3016#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
3017# include <algorithm>
3018# include <atomic>
3019# include <concepts>
3020# include <cstdlib>
3021# include <iosfwd>
3022# if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
3023# include <locale>
351# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
352# include <algorithm>
353# include <array>
354# include <atomic>
355# include <cctype>
356# include <cerrno>
357# include <clocale>
358# include <concepts>
359# include <cstdint>
360# include <cstdlib>
361# include <iosfwd>
362# if _LIBCPP_HAS_LOCALIZATION
363# include <locale>
364# endif
365# include <string>
366# include <string_view>
367# include <tuple>
368# include <type_traits>
369# include <typeinfo>
370# include <utility>
3024371# endif
3025# include <tuple>
3026# include <type_traits>
3027# include <typeinfo>
3028# include <utility>
3029#endif
372#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
3030373
3031374#endif // _LIBCPP_VECTOR
lib/libcxx/include/version+62-26
......@@ -101,6 +101,8 @@ __cpp_lib_execution 201902L <execution>
101101 201603L // C++17
102102__cpp_lib_expected 202211L <expected>
103103__cpp_lib_filesystem 201703L <filesystem>
104__cpp_lib_flat_map 202207L <flat_map>
105__cpp_lib_flat_set 202207L <flat_set>
104106__cpp_lib_format 202110L <format>
105107__cpp_lib_format_path 202403L <filesystem>
106108__cpp_lib_format_ranges 202207L <format>
......@@ -138,6 +140,7 @@ __cpp_lib_ios_noreplace 202207L <ios>
138140__cpp_lib_is_aggregate 201703L <type_traits>
139141__cpp_lib_is_constant_evaluated 201811L <type_traits>
140142__cpp_lib_is_final 201402L <type_traits>
143__cpp_lib_is_implicit_lifetime 202302L <type_traits>
141144__cpp_lib_is_invocable 201703L <type_traits>
142145__cpp_lib_is_layout_compatible 201907L <type_traits>
143146__cpp_lib_is_nothrow_convertible 201806L <type_traits>
......@@ -170,9 +173,11 @@ __cpp_lib_nonmember_container_access 201411L <array> <deque>
170173 <iterator> <list> <map>
171174 <regex> <set> <string>
172175 <unordered_map> <unordered_set> <vector>
173__cpp_lib_not_fn 201603L <functional>
176__cpp_lib_not_fn 202306L <functional>
177 201603L // C++17
174178__cpp_lib_null_iterators 201304L <iterator>
175179__cpp_lib_optional 202110L <optional>
180 202106L // C++20
176181 201606L // C++17
177182__cpp_lib_optional_range_support 202406L <optional>
178183__cpp_lib_out_ptr 202311L <memory>
......@@ -182,8 +187,9 @@ __cpp_lib_philox_engine 202406L <random>
182187__cpp_lib_polymorphic_allocator 201902L <memory_resource>
183188__cpp_lib_print 202207L <ostream> <print>
184189__cpp_lib_quoted_string_io 201304L <iomanip>
185__cpp_lib_ranges 202207L <algorithm> <functional> <iterator>
190__cpp_lib_ranges 202406L <algorithm> <functional> <iterator>
186191 <memory> <ranges>
192 202110L // C++20
187193__cpp_lib_ranges_as_const 202207L <ranges>
188194__cpp_lib_ranges_as_rvalue 202207L <ranges>
189195__cpp_lib_ranges_chunk 202202L <ranges>
......@@ -259,16 +265,21 @@ __cpp_lib_uncaught_exceptions 201411L <exception>
259265__cpp_lib_unordered_map_try_emplace 201411L <unordered_map>
260266__cpp_lib_unreachable 202202L <utility>
261267__cpp_lib_unwrap_ref 201811L <functional>
262__cpp_lib_variant 202102L <variant>
268__cpp_lib_variant 202306L <variant>
269 202106L // C++20
270 202102L // C++17
263271__cpp_lib_void_t 201411L <type_traits>
264272
265273*/
266274
267#include <__config>
275#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
276# include <__cxx03/version>
277#else
278# include <__config>
268279
269#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
270# pragma GCC system_header
271#endif
280# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
281# pragma GCC system_header
282# endif
272283
273284// clang-format off
274285
......@@ -284,12 +295,12 @@ __cpp_lib_void_t 201411L <type_traits>
284295# define __cpp_lib_make_reverse_iterator 201402L
285296# define __cpp_lib_make_unique 201304L
286297# define __cpp_lib_null_iterators 201304L
287# if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
298# if _LIBCPP_HAS_LOCALIZATION
288299# define __cpp_lib_quoted_string_io 201304L
289300# endif
290301# define __cpp_lib_result_of_sfinae 201210L
291302# define __cpp_lib_robust_nonmodifying_seq_ops 201304L
292# if !defined(_LIBCPP_HAS_NO_THREADS)
303# if _LIBCPP_HAS_THREADS
293304# define __cpp_lib_shared_timed_mutex 201402L
294305# endif
295306# define __cpp_lib_string_udls 201304L
......@@ -314,7 +325,7 @@ __cpp_lib_void_t 201411L <type_traits>
314325# define __cpp_lib_clamp 201603L
315326# define __cpp_lib_enable_shared_from_this 201603L
316327// # define __cpp_lib_execution 201603L
317# if !defined(_LIBCPP_HAS_NO_FILESYSTEM) && _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY
328# if _LIBCPP_HAS_FILESYSTEM && _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY
318329# define __cpp_lib_filesystem 201703L
319330# endif
320331# define __cpp_lib_gcd_lcm 201606L
......@@ -343,10 +354,10 @@ __cpp_lib_void_t 201411L <type_traits>
343354// # define __cpp_lib_parallel_algorithm 201603L
344355# define __cpp_lib_raw_memory_algorithms 201606L
345356# define __cpp_lib_sample 201603L
346# if !defined(_LIBCPP_HAS_NO_THREADS)
357# if _LIBCPP_HAS_THREADS
347358# define __cpp_lib_scoped_lock 201703L
348359# endif
349# if !defined(_LIBCPP_HAS_NO_THREADS)
360# if _LIBCPP_HAS_THREADS
350361# define __cpp_lib_shared_mutex 201505L
351362# endif
352363# define __cpp_lib_shared_ptr_arrays 201611L
......@@ -367,7 +378,7 @@ __cpp_lib_void_t 201411L <type_traits>
367378# define __cpp_lib_array_constexpr 201811L
368379# define __cpp_lib_assume_aligned 201811L
369380# define __cpp_lib_atomic_flag_test 201907L
370// # define __cpp_lib_atomic_float 201711L
381# define __cpp_lib_atomic_float 201711L
371382# define __cpp_lib_atomic_lock_free_type_aliases 201907L
372383# define __cpp_lib_atomic_ref 201806L
373384// # define __cpp_lib_atomic_shared_ptr 201711L
......@@ -375,14 +386,14 @@ __cpp_lib_void_t 201411L <type_traits>
375386# if _LIBCPP_AVAILABILITY_HAS_SYNC
376387# define __cpp_lib_atomic_wait 201907L
377388# endif
378# if !defined(_LIBCPP_HAS_NO_THREADS) && _LIBCPP_AVAILABILITY_HAS_SYNC
389# if _LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_SYNC
379390# define __cpp_lib_barrier 201907L
380391# endif
381392# define __cpp_lib_bind_front 201907L
382393# define __cpp_lib_bit_cast 201806L
383394# define __cpp_lib_bitops 201907L
384395# define __cpp_lib_bounded_array_traits 201902L
385# if !defined(_LIBCPP_HAS_NO_CHAR8_T)
396# if _LIBCPP_HAS_CHAR8_T
386397# define __cpp_lib_char8_t 201907L
387398# endif
388399# define __cpp_lib_concepts 202002L
......@@ -406,7 +417,9 @@ __cpp_lib_void_t 201411L <type_traits>
406417# define __cpp_lib_erase_if 202002L
407418# undef __cpp_lib_execution
408419// # define __cpp_lib_execution 201902L
409# define __cpp_lib_format 202110L
420# if _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT
421# define __cpp_lib_format 202110L
422# endif
410423# define __cpp_lib_format_uchar 202311L
411424# define __cpp_lib_generic_unordered_lookup 201811L
412425# define __cpp_lib_int_pow2 202002L
......@@ -416,34 +429,36 @@ __cpp_lib_void_t 201411L <type_traits>
416429// # define __cpp_lib_is_layout_compatible 201907L
417430# define __cpp_lib_is_nothrow_convertible 201806L
418431// # define __cpp_lib_is_pointer_interconvertible 201907L
419# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN) && _LIBCPP_AVAILABILITY_HAS_SYNC
432# if _LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_SYNC
420433# define __cpp_lib_jthread 201911L
421434# endif
422# if !defined(_LIBCPP_HAS_NO_THREADS) && _LIBCPP_AVAILABILITY_HAS_SYNC
435# if _LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_SYNC
423436# define __cpp_lib_latch 201907L
424437# endif
425438# define __cpp_lib_list_remove_return_type 201806L
426439# define __cpp_lib_math_constants 201907L
427440# define __cpp_lib_move_iterator_concept 202207L
441# undef __cpp_lib_optional
442# define __cpp_lib_optional 202106L
428443# if _LIBCPP_AVAILABILITY_HAS_PMR
429444# define __cpp_lib_polymorphic_allocator 201902L
430445# endif
431# define __cpp_lib_ranges 202207L
446# define __cpp_lib_ranges 202110L
432447# define __cpp_lib_remove_cvref 201711L
433# if !defined(_LIBCPP_HAS_NO_THREADS) && _LIBCPP_AVAILABILITY_HAS_SYNC
448# if _LIBCPP_HAS_THREADS && _LIBCPP_AVAILABILITY_HAS_SYNC
434449# define __cpp_lib_semaphore 201907L
435450# endif
436451# undef __cpp_lib_shared_ptr_arrays
437452# define __cpp_lib_shared_ptr_arrays 201707L
438453# define __cpp_lib_shift 201806L
439// # define __cpp_lib_smart_ptr_for_overwrite 202002L
454# define __cpp_lib_smart_ptr_for_overwrite 202002L
440455# define __cpp_lib_source_location 201907L
441456# define __cpp_lib_span 202002L
442457# define __cpp_lib_ssize 201902L
443458# define __cpp_lib_starts_ends_with 201711L
444459# undef __cpp_lib_string_view
445460# define __cpp_lib_string_view 201803L
446# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM)
461# if _LIBCPP_HAS_EXPERIMENTAL_SYNCSTREAM
447462# define __cpp_lib_syncbuf 201803L
448463# endif
449464# define __cpp_lib_three_way_comparison 201907L
......@@ -451,6 +466,8 @@ __cpp_lib_void_t 201411L <type_traits>
451466# define __cpp_lib_to_array 201907L
452467# define __cpp_lib_type_identity 201806L
453468# define __cpp_lib_unwrap_ref 201811L
469# undef __cpp_lib_variant
470# define __cpp_lib_variant 202106L
454471#endif
455472
456473#if _LIBCPP_STD_VER >= 23
......@@ -467,11 +484,16 @@ __cpp_lib_void_t 201411L <type_traits>
467484# define __cpp_lib_constexpr_typeinfo 202106L
468485# define __cpp_lib_containers_ranges 202202L
469486# define __cpp_lib_expected 202211L
487# define __cpp_lib_flat_map 202207L
488// # define __cpp_lib_flat_set 202207L
470489# define __cpp_lib_format_ranges 202207L
471490// # define __cpp_lib_formatters 202302L
472491# define __cpp_lib_forward_like 202207L
473492# define __cpp_lib_invoke_r 202106L
474493# define __cpp_lib_ios_noreplace 202207L
494# if __has_builtin(__builtin_is_implicit_lifetime)
495# define __cpp_lib_is_implicit_lifetime 202302L
496# endif
475497# define __cpp_lib_is_scoped_enum 202011L
476498# define __cpp_lib_mdspan 202207L
477499# define __cpp_lib_modules 202207L
......@@ -479,7 +501,11 @@ __cpp_lib_void_t 201411L <type_traits>
479501# undef __cpp_lib_optional
480502# define __cpp_lib_optional 202110L
481503# define __cpp_lib_out_ptr 202106L
482# define __cpp_lib_print 202207L
504# if _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT
505# define __cpp_lib_print 202207L
506# endif
507# undef __cpp_lib_ranges
508# define __cpp_lib_ranges 202406L
483509// # define __cpp_lib_ranges_as_const 202207L
484510# define __cpp_lib_ranges_as_rvalue 202207L
485511// # define __cpp_lib_ranges_chunk 202202L
......@@ -510,7 +536,9 @@ __cpp_lib_void_t 201411L <type_traits>
510536# undef __cpp_lib_bind_front
511537# define __cpp_lib_bind_front 202306L
512538# define __cpp_lib_bitset 202306L
513// # define __cpp_lib_constexpr_new 202406L
539# if !defined(_LIBCPP_ABI_VCRUNTIME)
540# define __cpp_lib_constexpr_new 202406L
541# endif
514542// # define __cpp_lib_constrained_equality 202403L
515543// # define __cpp_lib_copyable_function 202306L
516544// # define __cpp_lib_debugging 202311L
......@@ -524,18 +552,22 @@ __cpp_lib_void_t 201411L <type_traits>
524552// # define __cpp_lib_freestanding_optional 202311L
525553// # define __cpp_lib_freestanding_string_view 202311L
526554// # define __cpp_lib_freestanding_variant 202311L
527# if !defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
555# if _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
528556# define __cpp_lib_fstream_native_handle 202306L
529557# endif
530558// # define __cpp_lib_function_ref 202306L
531559// # define __cpp_lib_generate_random 202403L
532560// # define __cpp_lib_hazard_pointer 202306L
533561// # define __cpp_lib_inplace_vector 202406L
534// # define __cpp_lib_is_virtual_base_of 202406L
562# if __has_builtin(__builtin_is_virtual_base_of)
563# define __cpp_lib_is_virtual_base_of 202406L
564# endif
535565// # define __cpp_lib_is_within_lifetime 202306L
536566// # define __cpp_lib_linalg 202311L
537567# undef __cpp_lib_mdspan
538568# define __cpp_lib_mdspan 202406L
569# undef __cpp_lib_not_fn
570# define __cpp_lib_not_fn 202306L
539571// # define __cpp_lib_optional_range_support 202406L
540572# undef __cpp_lib_out_ptr
541573# define __cpp_lib_out_ptr 202311L
......@@ -559,8 +591,12 @@ __cpp_lib_void_t 201411L <type_traits>
559591// # define __cpp_lib_to_string 202306L
560592# undef __cpp_lib_tuple_like
561593// # define __cpp_lib_tuple_like 202311L
594# undef __cpp_lib_variant
595# define __cpp_lib_variant 202306L
562596#endif
563597
598#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
599
564600// clang-format on
565601
566602#endif // _LIBCPP_VERSIONH
lib/libcxx/include/wchar.h+30-34
......@@ -7,17 +7,6 @@
77//
88//===----------------------------------------------------------------------===//
99
10#if defined(__need_wint_t) || defined(__need_mbstate_t)
11
12# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
13# pragma GCC system_header
14# endif
15
16# include_next <wchar.h>
17
18#elif !defined(_LIBCPP_WCHAR_H)
19# define _LIBCPP_WCHAR_H
20
2110/*
2211 wchar.h synopsis
2312
......@@ -105,13 +94,10 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
10594
10695*/
10796
97#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
98# include <__cxx03/wchar.h>
99#else
108100# include <__config>
109# include <stddef.h>
110
111# if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
112# error \
113 "The <wchar.h> header is not supported since libc++ has been configured with LIBCXX_ENABLE_WIDE_CHARACTERS disabled"
114# endif
115101
116102# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
117103# pragma GCC system_header
......@@ -119,30 +105,38 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
119105
120106// We define this here to support older versions of glibc <wchar.h> that do
121107// not define this for clang.
122# ifdef __cplusplus
108# if defined(__cplusplus) && !defined(__CORRECT_ISO_CPP_WCHAR_H_PROTO)
123109# define __CORRECT_ISO_CPP_WCHAR_H_PROTO
124110# endif
125111
112// The inclusion of the system's <wchar.h> is intentionally done once outside of any include
113// guards because some code expects to be able to include the underlying system header multiple
114// times to get different definitions based on the macros that are set before inclusion.
126115# if __has_include_next(<wchar.h>)
127116# include_next <wchar.h>
128# else
129# include <__mbstate_t.h> // make sure we have mbstate_t regardless of the existence of <wchar.h>
130117# endif
131118
119# ifndef _LIBCPP_WCHAR_H
120# define _LIBCPP_WCHAR_H
121
122# include <__mbstate_t.h> // provide mbstate_t
123# include <stddef.h> // provide size_t
124
132125// Determine whether we have const-correct overloads for wcschr and friends.
133# if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)
134# define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
135# elif defined(__GLIBC_PREREQ)
136# if __GLIBC_PREREQ(2, 10)
126# if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)
137127# define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
128# elif defined(__GLIBC_PREREQ)
129# if __GLIBC_PREREQ(2, 10)
130# define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
131# endif
132# elif defined(_LIBCPP_MSVCRT)
133# if defined(_CRT_CONST_CORRECT_OVERLOADS)
134# define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
135# endif
138136# endif
139# elif defined(_LIBCPP_MSVCRT)
140# if defined(_CRT_CONST_CORRECT_OVERLOADS)
141# define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
142# endif
143# endif
144137
145# if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
138# if _LIBCPP_HAS_WIDE_CHARACTERS
139# if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
146140extern "C++" {
147141inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wcschr(const wchar_t* __s, wchar_t __c) {
148142 return (wchar_t*)wcschr(__s, __c);
......@@ -197,15 +191,17 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wmemchr(wchar_t
197191 return __libcpp_wmemchr(__s, __c, __n);
198192}
199193}
200# endif
194# endif
201195
202# if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT_LIKE) || defined(__MVS__))
196# if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT_LIKE) || defined(__MVS__))
203197extern "C" {
204198size_t mbsnrtowcs(
205199 wchar_t* __restrict __dst, const char** __restrict __src, size_t __nmc, size_t __len, mbstate_t* __restrict __ps);
206200size_t wcsnrtombs(
207201 char* __restrict __dst, const wchar_t** __restrict __src, size_t __nwc, size_t __len, mbstate_t* __restrict __ps);
208202} // extern "C"
209# endif // __cplusplus && (_LIBCPP_MSVCRT || __MVS__)
203# endif // __cplusplus && (_LIBCPP_MSVCRT || __MVS__)
204# endif // _LIBCPP_HAS_WIDE_CHARACTERS
205# endif // _LIBCPP_WCHAR_H
210206
211#endif // _LIBCPP_WCHAR_H
207#endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
lib/libcxx/include/wctype.h+35-36
......@@ -44,16 +44,14 @@ wctrans_t wctrans(const char* property);
4444
4545*/
4646
47#include <__config>
47#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
48# include <__cxx03/wctype.h>
49#else
50# include <__config>
4851
49#if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
50# error \
51 "The <wctype.h> header is not supported since libc++ has been configured with LIBCXX_ENABLE_WIDE_CHARACTERS disabled"
52#endif
53
54#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
55# pragma GCC system_header
56#endif
52# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
53# pragma GCC system_header
54# endif
5755
5856// TODO:
5957// In the future, we should unconditionally include_next <wctype.h> here and instead
......@@ -64,32 +62,33 @@ wctrans_t wctrans(const char* property);
6462// nothing (with using_if_exists), and if we include another header that defines one
6563// of these declarations (e.g. <wchar.h>), the second `using ::wint_t` with using_if_exists
6664// will fail because it does not refer to the same declaration.
67#if __has_include_next(<wctype.h>)
68# include_next <wctype.h>
69# define _LIBCPP_INCLUDED_C_LIBRARY_WCTYPE_H
70#endif
71
72#ifdef __cplusplus
73
74# undef iswalnum
75# undef iswalpha
76# undef iswblank
77# undef iswcntrl
78# undef iswdigit
79# undef iswgraph
80# undef iswlower
81# undef iswprint
82# undef iswpunct
83# undef iswspace
84# undef iswupper
85# undef iswxdigit
86# undef iswctype
87# undef wctype
88# undef towlower
89# undef towupper
90# undef towctrans
91# undef wctrans
92
93#endif // __cplusplus
65# if __has_include_next(<wctype.h>)
66# include_next <wctype.h>
67# define _LIBCPP_INCLUDED_C_LIBRARY_WCTYPE_H
68# endif
69
70# ifdef __cplusplus
71
72# undef iswalnum
73# undef iswalpha
74# undef iswblank
75# undef iswcntrl
76# undef iswdigit
77# undef iswgraph
78# undef iswlower
79# undef iswprint
80# undef iswpunct
81# undef iswspace
82# undef iswupper
83# undef iswxdigit
84# undef iswctype
85# undef wctype
86# undef towlower
87# undef towupper
88# undef towctrans
89# undef wctrans
90
91# endif // __cplusplus
92#endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
9493
9594#endif // _LIBCPP_WCTYPE_H
lib/libcxx/libc/hdr/errno_macros.h created+28
......@@ -0,0 +1,28 @@
1//===-- Definition of macros from errno.h ---------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_HDR_ERRNO_MACROS_H
10#define LLVM_LIBC_HDR_ERRNO_MACROS_H
11
12#ifdef LIBC_FULL_BUILD
13
14#ifdef __linux__
15#include <linux/errno.h>
16
17#include "include/llvm-libc-macros/error-number-macros.h"
18#else // __linux__
19#include "include/llvm-libc-macros/generic-error-number-macros.h"
20#endif
21
22#else // Overlay mode
23
24#include <errno.h>
25
26#endif // LLVM_LIBC_FULL_BUILD
27
28#endif // LLVM_LIBC_HDR_ERRNO_MACROS_H
lib/libcxx/libc/hdr/fenv_macros.h created+61
......@@ -0,0 +1,61 @@
1//===-- Definition of macros from fenv.h ----------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_HDR_FENV_MACROS_H
10#define LLVM_LIBC_HDR_FENV_MACROS_H
11
12#ifdef LIBC_FULL_BUILD
13
14#include "include/llvm-libc-macros/fenv-macros.h"
15
16#else // Overlay mode
17
18#include <fenv.h>
19
20// In some environment, FE_ALL_EXCEPT is set to 0 and the remaining exceptions
21// FE_* are missing.
22#ifndef FE_DIVBYZERO
23#define FE_DIVBYZERO 0
24#endif // FE_DIVBYZERO
25
26#ifndef FE_INEXACT
27#define FE_INEXACT 0
28#endif // FE_INEXACT
29
30#ifndef FE_INVALID
31#define FE_INVALID 0
32#endif // FE_INVALID
33
34#ifndef FE_OVERFLOW
35#define FE_OVERFLOW 0
36#endif // FE_OVERFLOW
37
38#ifndef FE_UNDERFLOW
39#define FE_UNDERFLOW 0
40#endif // FE_UNDERFLOW
41
42// Rounding mode macros might be missing.
43#ifndef FE_DOWNWARD
44#define FE_DOWNWARD 0x400
45#endif // FE_DOWNWARD
46
47#ifndef FE_TONEAREST
48#define FE_TONEAREST 0
49#endif // FE_TONEAREST
50
51#ifndef FE_TOWARDZERO
52#define FE_TOWARDZERO 0xC00
53#endif // FE_TOWARDZERO
54
55#ifndef FE_UPWARD
56#define FE_UPWARD 0x800
57#endif // FE_UPWARD
58
59#endif // LLVM_LIBC_FULL_BUILD
60
61#endif // LLVM_LIBC_HDR_FENV_MACROS_H
lib/libcxx/libc/hdr/float_macros.h created+22
......@@ -0,0 +1,22 @@
1//===-- Definition of macros from math.h ----------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_HDR_FLOAT_MACROS_H
10#define LLVM_LIBC_HDR_FLOAT_MACROS_H
11
12#ifdef LIBC_FULL_BUILD
13
14#include "include/llvm-libc-macros/float-macros.h"
15
16#else // Overlay mode
17
18#include <float.h>
19
20#endif // LLVM_LIBC_FULL_BUILD
21
22#endif // LLVM_LIBC_HDR_FLOAT_MACROS_H
lib/libcxx/libc/hdr/limits_macros.h created+22
......@@ -0,0 +1,22 @@
1//===-- Definition of macros from limits.h --------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_HDR_LIMITS_MACROS_H
10#define LLVM_LIBC_HDR_LIMITS_MACROS_H
11
12#ifdef LIBC_FULL_BUILD
13
14#include "include/llvm-libc-macros/limits-macros.h"
15
16#else // Overlay mode
17
18#include <limits.h>
19
20#endif // LLVM_LIBC_FULL_BUILD
21
22#endif // LLVM_LIBC_HDR_LIMITS_MACROS_H
lib/libcxx/libc/include/llvm-libc-macros/float-macros.h created+178
......@@ -0,0 +1,178 @@
1//===-- Definition of macros from float.h ---------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_MACROS_FLOAT_MACROS_H
10#define LLVM_LIBC_MACROS_FLOAT_MACROS_H
11
12#ifndef FLT_RADIX
13#define FLT_RADIX __FLT_RADIX__
14#endif // FLT_RADIX
15
16#ifndef FLT_EVAL_METHOD
17#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
18#endif // FLT_EVAL_METHOD
19
20#ifndef FLT_ROUNDS
21#if __has_builtin(__builtin_flt_rounds)
22#define FLT_ROUNDS __builtin_flt_rounds()
23#else
24#define FLT_ROUNDS 1
25#endif
26#endif // FLT_ROUNDS
27
28#ifndef FLT_DECIMAL_DIG
29#define FLT_DECIMAL_DIG __FLT_DECIMAL_DIG__
30#endif // FLT_DECIMAL_DIG
31
32#ifndef DBL_DECIMAL_DIG
33#define DBL_DECIMAL_DIG __DBL_DECIMAL_DIG__
34#endif // DBL_DECIMAL_DIG
35
36#ifndef LDBL_DECIMAL_DIG
37#define LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__
38#endif // LDBL_DECIMAL_DIG
39
40#ifndef DECIMAL_DIG
41#define DECIMAL_DIG __DECIMAL_DIG__
42#endif // DECIMAL_DIG
43
44#ifndef FLT_DIG
45#define FLT_DIG __FLT_DIG__
46#endif // FLT_DIG
47
48#ifndef DBL_DIG
49#define DBL_DIG __DBL_DIG__
50#endif // DBL_DIG
51
52#ifndef LDBL_DIG
53#define LDBL_DIG __LDBL_DIG__
54#endif // LDBL_DIG
55
56#ifndef FLT_MANT_DIG
57#define FLT_MANT_DIG __FLT_MANT_DIG__
58#endif // FLT_MANT_DIG
59
60#ifndef DBL_MANT_DIG
61#define DBL_MANT_DIG __DBL_MANT_DIG__
62#endif // DBL_MANT_DIG
63
64#ifndef LDBL_MANT_DIG
65#define LDBL_MANT_DIG __LDBL_MANT_DIG__
66#endif // LDBL_MANT_DIG
67
68#ifndef FLT_MIN
69#define FLT_MIN __FLT_MIN__
70#endif // FLT_MIN
71
72#ifndef DBL_MIN
73#define DBL_MIN __DBL_MIN__
74#endif // DBL_MIN
75
76#ifndef LDBL_MIN
77#define LDBL_MIN __LDBL_MIN__
78#endif // LDBL_MIN
79
80#ifndef FLT_MAX
81#define FLT_MAX __FLT_MAX__
82#endif // FLT_MAX
83
84#ifndef DBL_MAX
85#define DBL_MAX __DBL_MAX__
86#endif // DBL_MAX
87
88#ifndef LDBL_MAX
89#define LDBL_MAX __LDBL_MAX__
90#endif // LDBL_MAX
91
92#ifndef FLT_TRUE_MIN
93#define FLT_TRUE_MIN __FLT_DENORM_MIN__
94#endif // FLT_TRUE_MIN
95
96#ifndef DBL_TRUE_MIN
97#define DBL_TRUE_MIN __DBL_DENORM_MIN__
98#endif // DBL_TRUE_MIN
99
100#ifndef LDBL_TRUE_MIN
101#define LDBL_TRUE_MIN __LDBL_DENORM_MIN__
102#endif // LDBL_TRUE_MIN
103
104#ifndef FLT_EPSILON
105#define FLT_EPSILON __FLT_EPSILON__
106#endif // FLT_EPSILON
107
108#ifndef DBL_EPSILON
109#define DBL_EPSILON __DBL_EPSILON__
110#endif // DBL_EPSILON
111
112#ifndef LDBL_EPSILON
113#define LDBL_EPSILON __LDBL_EPSILON__
114#endif // LDBL_EPSILON
115
116#ifndef FLT_MIN_EXP
117#define FLT_MIN_EXP __FLT_MIN_EXP__
118#endif // FLT_MIN_EXP
119
120#ifndef DBL_MIN_EXP
121#define DBL_MIN_EXP __DBL_MIN_EXP__
122#endif // DBL_MIN_EXP
123
124#ifndef LDBL_MIN_EXP
125#define LDBL_MIN_EXP __LDBL_MIN_EXP__
126#endif // LDBL_MIN_EXP
127
128#ifndef FLT_MIN_10_EXP
129#define FLT_MIN_10_EXP __FLT_MIN_10_EXP__
130#endif // FLT_MIN_10_EXP
131
132#ifndef DBL_MIN_10_EXP
133#define DBL_MIN_10_EXP __DBL_MIN_10_EXP__
134#endif // DBL_MIN_10_EXP
135
136#ifndef LDBL_MIN_10_EXP
137#define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__
138#endif // LDBL_MIN_10_EXP
139
140#ifndef FLT_MAX_EXP
141#define FLT_MAX_EXP __FLT_MAX_EXP__
142#endif // FLT_MAX_EXP
143
144#ifndef DBL_MAX_EXP
145#define DBL_MAX_EXP __DBL_MAX_EXP__
146#endif // DBL_MAX_EXP
147
148#ifndef LDBL_MAX_EXP
149#define LDBL_MAX_EXP __LDBL_MAX_EXP__
150#endif // LDBL_MAX_EXP
151
152#ifndef FLT_MAX_10_EXP
153#define FLT_MAX_10_EXP __FLT_MAX_10_EXP__
154#endif // FLT_MAX_10_EXP
155
156#ifndef DBL_MAX_10_EXP
157#define DBL_MAX_10_EXP __DBL_MAX_10_EXP__
158#endif // DBL_MAX_10_EXP
159
160#ifndef LDBL_MAX_10_EXP
161#define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__
162#endif // LDBL_MAX_10_EXP
163
164#ifndef FLT_HAS_SUBNORM
165#define FLT_HAS_SUBNORM __FLT_HAS_DENORM__
166#endif // FLT_HAS_SUBNORM
167
168#ifndef DBL_HAS_SUBNORM
169#define DBL_HAS_SUBNORM __DBL_HAS_DENORM__
170#endif // DBL_HAS_SUBNORM
171
172#ifndef LDBL_HAS_SUBNORM
173#define LDBL_HAS_SUBNORM __LDBL_HAS_DENORM__
174#endif // LDBL_HAS_SUBNORM
175
176// TODO: Add FLT16 and FLT128 constants.
177
178#endif // LLVM_LIBC_MACROS_FLOAT_MACROS_H
lib/libcxx/libc/include/llvm-libc-macros/float16-macros.h created+27
......@@ -0,0 +1,27 @@
1//===-- Detection of _Float16 compiler builtin type -----------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_MACROS_FLOAT16_MACROS_H
10#define LLVM_LIBC_MACROS_FLOAT16_MACROS_H
11
12#include "../llvm-libc-types/float128.h"
13
14#if defined(__FLT16_MANT_DIG__) && \
15 (!defined(__GNUC__) || __GNUC__ >= 13 || defined(__clang__)) && \
16 !defined(__arm__) && !defined(_M_ARM) && !defined(__riscv) && \
17 !defined(_WIN32)
18#define LIBC_TYPES_HAS_FLOAT16
19
20// TODO: This would no longer be required if HdrGen let us guard function
21// declarations with multiple macros.
22#ifdef LIBC_TYPES_HAS_FLOAT128
23#define LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128
24#endif // LIBC_TYPES_HAS_FLOAT128
25#endif
26
27#endif // LLVM_LIBC_MACROS_FLOAT16_MACROS_H
lib/libcxx/libc/include/llvm-libc-macros/stdfix-macros.h created+328
......@@ -0,0 +1,328 @@
1//===-- Definitions from stdfix.h -----------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_MACROS_STDFIX_MACROS_H
10#define LLVM_LIBC_MACROS_STDFIX_MACROS_H
11
12#ifdef __FRACT_FBIT__
13// _Fract and _Accum types are available
14#define LIBC_COMPILER_HAS_FIXED_POINT
15#endif // __FRACT_FBIT__
16
17#ifdef LIBC_COMPILER_HAS_FIXED_POINT
18
19#define fract _Fract
20#define accum _Accum
21#define sat _Sat
22
23// Default values: from ISO/IEC TR 18037:2008 standard - Annex A.3 - Typical
24// desktop processor.
25
26#ifdef __SFRACT_FBIT__
27#define SFRACT_FBIT __SFRACT_FBIT__
28#else
29#define SFRACT_FBIT 7
30#endif // SFRACT_FBIT
31
32#ifdef __SFRACT_MIN__
33#define SFRACT_MIN __SFRACT_MIN__
34#else
35#define SFRACT_MIN (-0.5HR - 0.5HR)
36#endif // SFRACT_MIN
37
38#ifdef __SFRACT_MAX__
39#define SFRACT_MAX __SFRACT_MAX__
40#else
41#define SFRACT_MAX 0x1.FCp-1HR
42#endif // SFRACT_MAX
43
44#ifdef __SFRACT_EPSILON__
45#define SFRACT_EPSILON __SFRACT_EPSILON__
46#else
47#define SFRACT_EPSILON 0x1.0p-7HR
48#endif // SFRACT_EPSILON
49
50#ifdef __USFRACT_FBIT__
51#define USFRACT_FBIT __USFRACT_FBIT__
52#else
53#define USFRACT_FBIT 8
54#endif // USFRACT_FBIT
55
56#define USFRACT_MIN 0.0UHR
57
58#ifdef __USFRACT_MAX__
59#define USFRACT_MAX __USFRACT_MAX__
60#else
61#define USFRACT_MAX 0x1.FEp-1UHR
62#endif // USFRACT_MAX
63
64#ifdef __USFRACT_EPSILON__
65#define USFRACT_EPSILON __USFRACT_EPSILON__
66#else
67#define USFRACT_EPSILON 0x1.0p-8UHR
68#endif // USFRACT_EPSILON
69
70#ifdef __FRACT_FBIT__
71#define FRACT_FBIT __FRACT_FBIT__
72#else
73#define FRACT_FBIT 15
74#endif // FRACT_FBIT
75
76#ifdef __FRACT_MIN__
77#define FRACT_MIN __FRACT_MIN__
78#else
79#define FRACT_MIN (-0.5R - 0.5R)
80#endif // FRACT_MIN
81
82#ifdef __FRACT_MAX__
83#define FRACT_MAX __FRACT_MAX__
84#else
85#define FRACT_MAX 0x1.FFFCp-1R
86#endif // FRACT_MAX
87
88#ifdef __FRACT_EPSILON__
89#define FRACT_EPSILON __FRACT_EPSILON__
90#else
91#define FRACT_EPSILON 0x1.0p-15R
92#endif // FRACT_EPSILON
93
94#ifdef __UFRACT_FBIT__
95#define UFRACT_FBIT __UFRACT_FBIT__
96#else
97#define UFRACT_FBIT 16
98#endif // UFRACT_FBIT
99
100#define UFRACT_MIN 0.0UR
101
102#ifdef __UFRACT_MAX__
103#define UFRACT_MAX __UFRACT_MAX__
104#else
105#define UFRACT_MAX 0x1.FFFEp-1UR
106#endif // UFRACT_MAX
107
108#ifdef __UFRACT_EPSILON__
109#define UFRACT_EPSILON __UFRACT_EPSILON__
110#else
111#define UFRACT_EPSILON 0x1.0p-16UR
112#endif // UFRACT_EPSILON
113
114#ifdef __LFRACT_FBIT__
115#define LFRACT_FBIT __LFRACT_FBIT__
116#else
117#define LFRACT_FBIT 31
118#endif // LFRACT_FBIT
119
120#ifdef __LFRACT_MIN__
121#define LFRACT_MIN __LFRACT_MIN__
122#else
123#define LFRACT_MIN (-0.5LR - 0.5LR)
124#endif // LFRACT_MIN
125
126#ifdef __LFRACT_MAX__
127#define LFRACT_MAX __LFRACT_MAX__
128#else
129#define LFRACT_MAX 0x1.FFFFFFFCp-1LR
130#endif // LFRACT_MAX
131
132#ifdef __LFRACT_EPSILON__
133#define LFRACT_EPSILON __LFRACT_EPSILON__
134#else
135#define LFRACT_EPSILON 0x1.0p-31LR
136#endif // LFRACT_EPSILON
137
138#ifdef __ULFRACT_FBIT__
139#define ULFRACT_FBIT __ULFRACT_FBIT__
140#else
141#define ULFRACT_FBIT 32
142#endif // ULFRACT_FBIT
143
144#define ULFRACT_MIN 0.0ULR
145
146#ifdef __ULFRACT_MAX__
147#define ULFRACT_MAX __ULFRACT_MAX__
148#else
149#define ULFRACT_MAX 0x1.FFFFFFFEp-1ULR
150#endif // ULFRACT_MAX
151
152#ifdef __ULFRACT_EPSILON__
153#define ULFRACT_EPSILON __ULFRACT_EPSILON__
154#else
155#define ULFRACT_EPSILON 0x1.0p-32ULR
156#endif // ULFRACT_EPSILON
157
158#ifdef __SACCUM_FBIT__
159#define SACCUM_FBIT __SACCUM_FBIT__
160#else
161#define SACCUM_FBIT 7
162#endif // SACCUM_FBIT
163
164#ifdef __SACCUM_IBIT__
165#define SACCUM_IBIT __SACCUM_IBIT__
166#else
167#define SACCUM_IBIT 8
168#endif // SACCUM_IBIT
169
170#ifdef __SACCUM_MIN__
171#define SACCUM_MIN __SACCUM_MIN__
172#else
173#define SACCUM_MIN (-0x1.0p+7HK - 0x1.0p+7HK)
174#endif // SACCUM_MIN
175
176#ifdef __SACCUM_MAX__
177#define SACCUM_MAX __SACCUM_MAX__
178#else
179#define SACCUM_MAX 0x1.FFFCp+7HK
180#endif // SACCUM_MAX
181
182#ifdef __SACCUM_EPSILON__
183#define SACCUM_EPSILON __SACCUM_EPSILON__
184#else
185#define SACCUM_EPSILON 0x1.0p-7HK
186#endif // SACCUM_EPSILON
187
188#ifdef __USACCUM_FBIT__
189#define USACCUM_FBIT __USACCUM_FBIT__
190#else
191#define USACCUM_FBIT 8
192#endif // USACCUM_FBIT
193
194#ifdef __USACCUM_IBIT__
195#define USACCUM_IBIT __USACCUM_IBIT__
196#else
197#define USACCUM_IBIT 8
198#endif // USACCUM_IBIT
199
200#define USACCUM_MIN 0.0UHK
201
202#ifdef __USACCUM_MAX__
203#define USACCUM_MAX __USACCUM_MAX__
204#else
205#define USACCUM_MAX 0x1.FFFEp+7UHK
206#endif // USACCUM_MAX
207
208#ifdef __USACCUM_EPSILON__
209#define USACCUM_EPSILON __USACCUM_EPSILON__
210#else
211#define USACCUM_EPSILON 0x1.0p-8UHK
212#endif // USACCUM_EPSILON
213
214#ifdef __ACCUM_FBIT__
215#define ACCUM_FBIT __ACCUM_FBIT__
216#else
217#define ACCUM_FBIT 15
218#endif // ACCUM_FBIT
219
220#ifdef __ACCUM_IBIT__
221#define ACCUM_IBIT __ACCUM_IBIT__
222#else
223#define ACCUM_IBIT 16
224#endif // ACCUM_IBIT
225
226#ifdef __ACCUM_MIN__
227#define ACCUM_MIN __ACCUM_MIN__
228#else
229#define ACCUM_MIN (-0x1.0p+15K - 0x1.0p+15K)
230#endif // ACCUM_MIN
231
232#ifdef __ACCUM_MAX__
233#define ACCUM_MAX __ACCUM_MAX__
234#else
235#define ACCUM_MAX 0x1.FFFFFFFCp+15K
236#endif // ACCUM_MAX
237
238#ifdef __ACCUM_EPSILON__
239#define ACCUM_EPSILON __ACCUM_EPSILON__
240#else
241#define ACCUM_EPSILON 0x1.0p-15K
242#endif // ACCUM_EPSILON
243
244#ifdef __UACCUM_FBIT__
245#define UACCUM_FBIT __UACCUM_FBIT__
246#else
247#define UACCUM_FBIT 16
248#endif // UACCUM_FBIT
249
250#ifdef __UACCUM_IBIT__
251#define UACCUM_IBIT __UACCUM_IBIT__
252#else
253#define UACCUM_IBIT 16
254#endif // UACCUM_IBIT
255
256#define UACCUM_MIN 0.0UK
257
258#ifdef __UACCUM_MAX__
259#define UACCUM_MAX __UACCUM_MAX__
260#else
261#define UACCUM_MAX 0x1.FFFFFFFEp+15UK
262#endif // UACCUM_MAX
263
264#ifdef __UACCUM_EPSILON__
265#define UACCUM_EPSILON __UACCUM_EPSILON__
266#else
267#define UACCUM_EPSILON 0x1.0p-16UK
268#endif // UACCUM_EPSILON
269
270#ifdef __LACCUM_FBIT__
271#define LACCUM_FBIT __LACCUM_FBIT__
272#else
273#define LACCUM_FBIT 31
274#endif // LACCUM_FBIT
275
276#ifdef __LACCUM_IBIT__
277#define LACCUM_IBIT __LACCUM_IBIT__
278#else
279#define LACCUM_IBIT 32
280#endif // LACCUM_IBIT
281
282#ifdef __LACCUM_MIN__
283#define LACCUM_MIN __LACCUM_MIN__
284#else
285#define LACCUM_MIN (-0x1.0p+31LK - 0x1.0p+31LK)
286#endif // LACCUM_MIN
287
288#ifdef __LACCUM_MAX__
289#define LACCUM_MAX __LACCUM_MAX__
290#else
291#define LACCUM_MAX 0x1.FFFFFFFFFFFFFFFCp+31LK
292#endif // LACCUM_MAX
293
294#ifdef __LACCUM_EPSILON__
295#define LACCUM_EPSILON __LACCUM_EPSILON__
296#else
297#define LACCUM_EPSILON 0x1.0p-31LK
298#endif // LACCUM_EPSILON
299
300#ifdef __ULACCUM_FBIT__
301#define ULACCUM_FBIT __ULACCUM_FBIT__
302#else
303#define ULACCUM_FBIT 32
304#endif // ULACCUM_FBIT
305
306#ifdef __ULACCUM_IBIT__
307#define ULACCUM_IBIT __ULACCUM_IBIT__
308#else
309#define ULACCUM_IBIT 32
310#endif // ULACCUM_IBIT
311
312#define ULACCUM_MIN 0.0ULK
313
314#ifdef __ULACCUM_MAX__
315#define ULACCUM_MAX __ULACCUM_MAX__
316#else
317#define ULACCUM_MAX 0x1.FFFFFFFFFFFFFFFEp+31ULK
318#endif // ULACCUM_MAX
319
320#ifdef __ULACCUM_EPSILON__
321#define ULACCUM_EPSILON __ULACCUM_EPSILON__
322#else
323#define ULACCUM_EPSILON 0x1.0p-32ULK
324#endif // ULACCUM_EPSILON
325
326#endif // LIBC_COMPILER_HAS_FIXED_POINT
327
328#endif // LLVM_LIBC_MACROS_STDFIX_MACROS_H
lib/libcxx/libc/include/llvm-libc-types/cfloat128.h created+44
......@@ -0,0 +1,44 @@
1//===-- Definition of cfloat128 type --------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_TYPES_CFLOAT128_H
10#define LLVM_LIBC_TYPES_CFLOAT128_H
11
12#include "../llvm-libc-macros/float-macros.h" // LDBL_MANT_DIG
13
14// Currently, the complex variant of C23 `_Float128` type is only defined as a
15// built-in type in GCC 7 or later, for C and in GCC 13 or later, for C++. For
16// clang, the complex variant of `__float128` is defined instead, and only on
17// x86-64 targets for clang 11 or later.
18//
19// TODO: Update the complex variant of C23 `_Float128` type detection again when
20// clang supports it.
21#ifdef __clang__
22#if (__clang_major__ >= 11) && \
23 (defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__))
24// Use _Complex __float128 type. clang uses __SIZEOF_FLOAT128__ or __FLOAT128__
25// macro to notify the availability of __float128 type:
26// https://reviews.llvm.org/D15120
27#define LIBC_TYPES_HAS_CFLOAT128
28typedef _Complex __float128 cfloat128;
29#endif
30#elif defined(__GNUC__)
31#if (defined(__STDC_IEC_60559_COMPLEX__) || defined(__SIZEOF_FLOAT128__)) && \
32 (__GNUC__ >= 13 || (!defined(__cplusplus)))
33#define LIBC_TYPES_HAS_CFLOAT128
34typedef _Complex _Float128 cfloat128;
35#endif
36#endif
37
38#if !defined(LIBC_TYPES_HAS_CFLOAT128) && (LDBL_MANT_DIG == 113)
39#define LIBC_TYPES_HAS_CFLOAT128
40#define LIBC_TYPES_CFLOAT128_IS_COMPLEX_LONG_DOUBLE
41typedef _Complex long double cfloat128;
42#endif
43
44#endif // LLVM_LIBC_TYPES_CFLOAT128_H
lib/libcxx/libc/include/llvm-libc-types/cfloat16.h created+21
......@@ -0,0 +1,21 @@
1//===-- Definition of cfloat16 type ---------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_TYPES_CFLOAT16_H
10#define LLVM_LIBC_TYPES_CFLOAT16_H
11
12#if defined(__FLT16_MANT_DIG__) && \
13 (!defined(__GNUC__) || __GNUC__ >= 13 || \
14 (defined(__clang__) && __clang_major__ >= 14)) && \
15 !defined(__arm__) && !defined(_M_ARM) && !defined(__riscv) && \
16 !defined(_WIN32)
17#define LIBC_TYPES_HAS_CFLOAT16
18typedef _Complex _Float16 cfloat16;
19#endif
20
21#endif // LLVM_LIBC_TYPES_CFLOAT16_H
lib/libcxx/libc/include/llvm-libc-types/float128.h created+36
......@@ -0,0 +1,36 @@
1//===-- Definition of float128 type ---------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_TYPES_FLOAT128_H
10#define LLVM_LIBC_TYPES_FLOAT128_H
11
12#include "../llvm-libc-macros/float-macros.h" // LDBL_MANT_DIG
13
14// Currently, C23 `_Float128` type is only defined as a built-in type in GCC 7
15// or later, and only for C. For C++, or for clang, `__float128` is defined
16// instead, and only on x86-64 targets.
17//
18// TODO: Update C23 `_Float128` type detection again when clang supports it.
19// https://github.com/llvm/llvm-project/issues/80195
20#if defined(__STDC_IEC_60559_BFP__) && !defined(__clang__) && \
21 !defined(__cplusplus)
22#define LIBC_TYPES_HAS_FLOAT128
23typedef _Float128 float128;
24#elif defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)
25// Use __float128 type. gcc and clang sometime use __SIZEOF_FLOAT128__ to
26// notify the availability of __float128.
27// clang also uses __FLOAT128__ macro to notify the availability of __float128
28// type: https://reviews.llvm.org/D15120
29#define LIBC_TYPES_HAS_FLOAT128
30typedef __float128 float128;
31#elif (LDBL_MANT_DIG == 113)
32#define LIBC_TYPES_HAS_FLOAT128
33typedef long double float128;
34#endif
35
36#endif // LLVM_LIBC_TYPES_FLOAT128_H
lib/libcxx/libc/shared/fp_bits.h created+22
......@@ -0,0 +1,22 @@
1//===-- Floating point number utils -----------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SHARED_FP_BITS_H
10#define LLVM_LIBC_SHARED_FP_BITS_H
11
12#include "src/__support/FPUtil/FPBits.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace shared {
16
17using fputil::FPBits;
18
19} // namespace shared
20} // namespace LIBC_NAMESPACE_DECL
21
22#endif // LLVM_LIBC_SHARED_FP_BITS_H
lib/libcxx/libc/shared/str_to_float.h created+27
......@@ -0,0 +1,27 @@
1//===-- String to float conversion utils ------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SHARED_STR_TO_FLOAT_H
10#define LLVM_LIBC_SHARED_STR_TO_FLOAT_H
11
12#include "src/__support/str_to_float.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace shared {
16
17using internal::ExpandedFloat;
18using internal::FloatConvertReturn;
19using internal::RoundDirection;
20
21using internal::binary_exp_to_float;
22using internal::decimal_exp_to_float;
23
24} // namespace shared
25} // namespace LIBC_NAMESPACE_DECL
26
27#endif // LLVM_LIBC_SHARED_STR_TO_FLOAT_H
lib/libcxx/libc/shared/str_to_integer.h created+24
......@@ -0,0 +1,24 @@
1//===-- String to int conversion utils --------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SHARED_STR_TO_INTEGER_H
10#define LLVM_LIBC_SHARED_STR_TO_INTEGER_H
11
12#include "src/__support/str_to_integer.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace shared {
16
17using LIBC_NAMESPACE::StrToNumResult;
18
19using internal::strtointeger;
20
21} // namespace shared
22} // namespace LIBC_NAMESPACE_DECL
23
24#endif // LLVM_LIBC_SHARED_STR_TO_INTEGER_H
lib/libcxx/libc/src/__support/CPP/array.h created+80
......@@ -0,0 +1,80 @@
1//===-- A self contained equivalent of std::array ---------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_ARRAY_H
10#define LLVM_LIBC_SRC___SUPPORT_CPP_ARRAY_H
11
12#include "src/__support/CPP/iterator.h" // reverse_iterator
13#include "src/__support/macros/attributes.h"
14#include "src/__support/macros/config.h"
15#include <stddef.h> // For size_t.
16
17namespace LIBC_NAMESPACE_DECL {
18namespace cpp {
19
20template <class T, size_t N> struct array {
21 static_assert(N != 0,
22 "Cannot create a LIBC_NAMESPACE::cpp::array of size 0.");
23
24 T Data[N];
25 using value_type = T;
26 using iterator = T *;
27 using const_iterator = const T *;
28 using reverse_iterator = cpp::reverse_iterator<iterator>;
29 using const_reverse_iterator = cpp::reverse_iterator<const_iterator>;
30
31 LIBC_INLINE constexpr T *data() { return Data; }
32 LIBC_INLINE constexpr const T *data() const { return Data; }
33
34 LIBC_INLINE constexpr T &front() { return Data[0]; }
35 LIBC_INLINE constexpr const T &front() const { return Data[0]; }
36
37 LIBC_INLINE constexpr T &back() { return Data[N - 1]; }
38 LIBC_INLINE constexpr const T &back() const { return Data[N - 1]; }
39
40 LIBC_INLINE constexpr T &operator[](size_t Index) { return Data[Index]; }
41
42 LIBC_INLINE constexpr const T &operator[](size_t Index) const {
43 return Data[Index];
44 }
45
46 LIBC_INLINE constexpr size_t size() const { return N; }
47
48 LIBC_INLINE constexpr bool empty() const { return N == 0; }
49
50 LIBC_INLINE constexpr iterator begin() { return Data; }
51 LIBC_INLINE constexpr const_iterator begin() const { return Data; }
52 LIBC_INLINE constexpr const_iterator cbegin() const { return begin(); }
53
54 LIBC_INLINE constexpr iterator end() { return Data + N; }
55 LIBC_INLINE constexpr const_iterator end() const { return Data + N; }
56 LIBC_INLINE constexpr const_iterator cend() const { return end(); }
57
58 LIBC_INLINE constexpr reverse_iterator rbegin() {
59 return reverse_iterator{end()};
60 }
61 LIBC_INLINE constexpr const_reverse_iterator rbegin() const {
62 return const_reverse_iterator{end()};
63 }
64 LIBC_INLINE constexpr const_reverse_iterator crbegin() const {
65 return rbegin();
66 }
67
68 LIBC_INLINE constexpr reverse_iterator rend() {
69 return reverse_iterator{begin()};
70 }
71 LIBC_INLINE constexpr const_reverse_iterator rend() const {
72 return const_reverse_iterator{begin()};
73 }
74 LIBC_INLINE constexpr const_reverse_iterator crend() const { return rend(); }
75};
76
77} // namespace cpp
78} // namespace LIBC_NAMESPACE_DECL
79
80#endif // LLVM_LIBC_SRC___SUPPORT_CPP_ARRAY_H
lib/libcxx/libc/src/__support/CPP/bit.h created+298
......@@ -0,0 +1,298 @@
1//===-- Implementation of the C++20 bit header -----------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8// This is inspired by LLVM ADT/bit.h header.
9// Some functions are missing, we can add them as needed (popcount, byteswap).
10
11#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_BIT_H
12#define LLVM_LIBC_SRC___SUPPORT_CPP_BIT_H
13
14#include "src/__support/CPP/limits.h" // numeric_limits
15#include "src/__support/CPP/type_traits.h"
16#include "src/__support/macros/attributes.h"
17#include "src/__support/macros/config.h"
18#include "src/__support/macros/sanitizer.h"
19
20#include <stdint.h>
21
22namespace LIBC_NAMESPACE_DECL {
23namespace cpp {
24
25#if __has_builtin(__builtin_memcpy_inline)
26#define LLVM_LIBC_HAS_BUILTIN_MEMCPY_INLINE
27#endif
28
29// This implementation of bit_cast requires trivially-constructible To, to avoid
30// UB in the implementation.
31template <typename To, typename From>
32LIBC_INLINE constexpr cpp::enable_if_t<
33 (sizeof(To) == sizeof(From)) &&
34 cpp::is_trivially_constructible<To>::value &&
35 cpp::is_trivially_copyable<To>::value &&
36 cpp::is_trivially_copyable<From>::value,
37 To>
38bit_cast(const From &from) {
39 MSAN_UNPOISON(&from, sizeof(From));
40#if __has_builtin(__builtin_bit_cast)
41 return __builtin_bit_cast(To, from);
42#else
43 To to;
44 char *dst = reinterpret_cast<char *>(&to);
45 const char *src = reinterpret_cast<const char *>(&from);
46#if __has_builtin(__builtin_memcpy_inline)
47 __builtin_memcpy_inline(dst, src, sizeof(To));
48#else
49 for (unsigned i = 0; i < sizeof(To); ++i)
50 dst[i] = src[i];
51#endif // __has_builtin(__builtin_memcpy_inline)
52 return to;
53#endif // __has_builtin(__builtin_bit_cast)
54}
55
56template <typename T>
57[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>,
58 bool>
59has_single_bit(T value) {
60 return (value != 0) && ((value & (value - 1)) == 0);
61}
62
63// A temporary macro to add template function specialization when compiler
64// builtin is available.
65#define ADD_SPECIALIZATION(NAME, TYPE, BUILTIN) \
66 template <> [[nodiscard]] LIBC_INLINE constexpr int NAME<TYPE>(TYPE value) { \
67 static_assert(cpp::is_unsigned_v<TYPE>); \
68 return value == 0 ? cpp::numeric_limits<TYPE>::digits : BUILTIN(value); \
69 }
70
71/// Count number of 0's from the least significant bit to the most
72/// stopping at the first 1.
73///
74/// Only unsigned integral types are allowed.
75///
76/// Returns cpp::numeric_limits<T>::digits on an input of 0.
77// clang-19+, gcc-14+
78#if __has_builtin(__builtin_ctzg)
79template <typename T>
80[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
81countr_zero(T value) {
82 return __builtin_ctzg(value, cpp::numeric_limits<T>::digits);
83}
84#else
85template <typename T>
86[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
87countr_zero(T value) {
88 if (!value)
89 return cpp::numeric_limits<T>::digits;
90 if (value & 0x1)
91 return 0;
92 // Bisection method.
93 unsigned zero_bits = 0;
94 unsigned shift = cpp::numeric_limits<T>::digits >> 1;
95 T mask = cpp::numeric_limits<T>::max() >> shift;
96 while (shift) {
97 if ((value & mask) == 0) {
98 value >>= shift;
99 zero_bits |= shift;
100 }
101 shift >>= 1;
102 mask >>= shift;
103 }
104 return zero_bits;
105}
106#if __has_builtin(__builtin_ctzs)
107ADD_SPECIALIZATION(countr_zero, unsigned short, __builtin_ctzs)
108#endif
109ADD_SPECIALIZATION(countr_zero, unsigned int, __builtin_ctz)
110ADD_SPECIALIZATION(countr_zero, unsigned long, __builtin_ctzl)
111ADD_SPECIALIZATION(countr_zero, unsigned long long, __builtin_ctzll)
112#endif // __has_builtin(__builtin_ctzg)
113
114/// Count number of 0's from the most significant bit to the least
115/// stopping at the first 1.
116///
117/// Only unsigned integral types are allowed.
118///
119/// Returns cpp::numeric_limits<T>::digits on an input of 0.
120// clang-19+, gcc-14+
121#if __has_builtin(__builtin_clzg)
122template <typename T>
123[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
124countl_zero(T value) {
125 return __builtin_clzg(value, cpp::numeric_limits<T>::digits);
126}
127#else
128template <typename T>
129[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
130countl_zero(T value) {
131 if (!value)
132 return cpp::numeric_limits<T>::digits;
133 // Bisection method.
134 unsigned zero_bits = 0;
135 for (unsigned shift = cpp::numeric_limits<T>::digits >> 1; shift;
136 shift >>= 1) {
137 T tmp = value >> shift;
138 if (tmp)
139 value = tmp;
140 else
141 zero_bits |= shift;
142 }
143 return zero_bits;
144}
145#if __has_builtin(__builtin_clzs)
146ADD_SPECIALIZATION(countl_zero, unsigned short, __builtin_clzs)
147#endif
148ADD_SPECIALIZATION(countl_zero, unsigned int, __builtin_clz)
149ADD_SPECIALIZATION(countl_zero, unsigned long, __builtin_clzl)
150ADD_SPECIALIZATION(countl_zero, unsigned long long, __builtin_clzll)
151#endif // __has_builtin(__builtin_clzg)
152
153#undef ADD_SPECIALIZATION
154
155/// Count the number of ones from the most significant bit to the first
156/// zero bit.
157///
158/// Ex. countl_one(0xFF0FFF00) == 8.
159/// Only unsigned integral types are allowed.
160///
161/// Returns cpp::numeric_limits<T>::digits on an input of all ones.
162template <typename T>
163[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
164countl_one(T value) {
165 return cpp::countl_zero<T>(~value);
166}
167
168/// Count the number of ones from the least significant bit to the first
169/// zero bit.
170///
171/// Ex. countr_one(0x00FF00FF) == 8.
172/// Only unsigned integral types are allowed.
173///
174/// Returns cpp::numeric_limits<T>::digits on an input of all ones.
175template <typename T>
176[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
177countr_one(T value) {
178 return cpp::countr_zero<T>(~value);
179}
180
181/// Returns the number of bits needed to represent value if value is nonzero.
182/// Returns 0 otherwise.
183///
184/// Ex. bit_width(5) == 3.
185template <typename T>
186[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
187bit_width(T value) {
188 return cpp::numeric_limits<T>::digits - cpp::countl_zero(value);
189}
190
191/// Returns the largest integral power of two no greater than value if value is
192/// nonzero. Returns 0 otherwise.
193///
194/// Ex. bit_floor(5) == 4.
195template <typename T>
196[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T>
197bit_floor(T value) {
198 if (!value)
199 return 0;
200 return static_cast<T>(T(1) << (cpp::bit_width(value) - 1));
201}
202
203/// Returns the smallest integral power of two no smaller than value if value is
204/// nonzero. Returns 1 otherwise.
205///
206/// Ex. bit_ceil(5) == 8.
207///
208/// The return value is undefined if the input is larger than the largest power
209/// of two representable in T.
210template <typename T>
211[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T>
212bit_ceil(T value) {
213 if (value < 2)
214 return 1;
215 return static_cast<T>(T(1) << cpp::bit_width(value - 1U));
216}
217
218// Rotate algorithms make use of "Safe, Efficient, and Portable Rotate in C/C++"
219// from https://blog.regehr.org/archives/1063.
220
221// Forward-declare rotr so that rotl can use it.
222template <typename T>
223[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T>
224rotr(T value, int rotate);
225
226template <typename T>
227[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T>
228rotl(T value, int rotate) {
229 constexpr unsigned N = cpp::numeric_limits<T>::digits;
230 rotate = rotate % N;
231 if (!rotate)
232 return value;
233 if (rotate < 0)
234 return cpp::rotr<T>(value, -rotate);
235 return (value << rotate) | (value >> (N - rotate));
236}
237
238template <typename T>
239[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T>
240rotr(T value, int rotate) {
241 constexpr unsigned N = cpp::numeric_limits<T>::digits;
242 rotate = rotate % N;
243 if (!rotate)
244 return value;
245 if (rotate < 0)
246 return cpp::rotl<T>(value, -rotate);
247 return (value >> rotate) | (value << (N - rotate));
248}
249
250// TODO: Do we need this function at all? How is it different from
251// 'static_cast'?
252template <class To, class From>
253LIBC_INLINE constexpr To bit_or_static_cast(const From &from) {
254 if constexpr (sizeof(To) == sizeof(From)) {
255 return bit_cast<To>(from);
256 } else {
257 return static_cast<To>(from);
258 }
259}
260
261/// Count number of 1's aka population count or Hamming weight.
262///
263/// Only unsigned integral types are allowed.
264// clang-19+, gcc-14+
265#if __has_builtin(__builtin_popcountg)
266template <typename T>
267[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
268popcount(T value) {
269 return __builtin_popcountg(value);
270}
271#else // !__has_builtin(__builtin_popcountg)
272template <typename T>
273[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
274popcount(T value) {
275 int count = 0;
276 while (value) {
277 value &= value - 1;
278 ++count;
279 }
280 return count;
281}
282#define ADD_SPECIALIZATION(TYPE, BUILTIN) \
283 template <> \
284 [[nodiscard]] LIBC_INLINE constexpr int popcount<TYPE>(TYPE value) { \
285 return BUILTIN(value); \
286 }
287ADD_SPECIALIZATION(unsigned char, __builtin_popcount)
288ADD_SPECIALIZATION(unsigned short, __builtin_popcount)
289ADD_SPECIALIZATION(unsigned, __builtin_popcount)
290ADD_SPECIALIZATION(unsigned long, __builtin_popcountl)
291ADD_SPECIALIZATION(unsigned long long, __builtin_popcountll)
292#endif // __builtin_popcountg
293#undef ADD_SPECIALIZATION
294
295} // namespace cpp
296} // namespace LIBC_NAMESPACE_DECL
297
298#endif // LLVM_LIBC_SRC___SUPPORT_CPP_BIT_H
lib/libcxx/libc/src/__support/CPP/iterator.h created+99
......@@ -0,0 +1,99 @@
1//===-- Standalone implementation of iterator -------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_ITERATOR_H
10#define LLVM_LIBC_SRC___SUPPORT_CPP_ITERATOR_H
11
12#include "src/__support/CPP/type_traits/enable_if.h"
13#include "src/__support/CPP/type_traits/is_convertible.h"
14#include "src/__support/CPP/type_traits/is_same.h"
15#include "src/__support/macros/attributes.h"
16#include "src/__support/macros/config.h"
17
18namespace LIBC_NAMESPACE_DECL {
19namespace cpp {
20
21template <typename T> struct iterator_traits;
22template <typename T> struct iterator_traits<T *> {
23 using reference = T &;
24 using value_type = T;
25};
26
27template <typename Iter> class reverse_iterator {
28 Iter current;
29
30public:
31 using reference = typename iterator_traits<Iter>::reference;
32 using value_type = typename iterator_traits<Iter>::value_type;
33 using iterator_type = Iter;
34
35 LIBC_INLINE reverse_iterator() : current() {}
36 LIBC_INLINE constexpr explicit reverse_iterator(Iter it) : current(it) {}
37
38 template <typename Other,
39 cpp::enable_if_t<!cpp::is_same_v<Iter, Other> &&
40 cpp::is_convertible_v<const Other &, Iter>,
41 int> = 0>
42 LIBC_INLINE constexpr explicit reverse_iterator(const Other &it)
43 : current(it) {}
44
45 LIBC_INLINE friend constexpr bool operator==(const reverse_iterator &lhs,
46 const reverse_iterator &rhs) {
47 return lhs.base() == rhs.base();
48 }
49
50 LIBC_INLINE friend constexpr bool operator!=(const reverse_iterator &lhs,
51 const reverse_iterator &rhs) {
52 return lhs.base() != rhs.base();
53 }
54
55 LIBC_INLINE friend constexpr bool operator<(const reverse_iterator &lhs,
56 const reverse_iterator &rhs) {
57 return lhs.base() > rhs.base();
58 }
59
60 LIBC_INLINE friend constexpr bool operator<=(const reverse_iterator &lhs,
61 const reverse_iterator &rhs) {
62 return lhs.base() >= rhs.base();
63 }
64
65 LIBC_INLINE friend constexpr bool operator>(const reverse_iterator &lhs,
66 const reverse_iterator &rhs) {
67 return lhs.base() < rhs.base();
68 }
69
70 LIBC_INLINE friend constexpr bool operator>=(const reverse_iterator &lhs,
71 const reverse_iterator &rhs) {
72 return lhs.base() <= rhs.base();
73 }
74
75 LIBC_INLINE constexpr iterator_type base() const { return current; }
76
77 LIBC_INLINE constexpr reference operator*() const {
78 Iter tmp = current;
79 return *--tmp;
80 }
81 LIBC_INLINE constexpr reverse_iterator operator--() {
82 ++current;
83 return *this;
84 }
85 LIBC_INLINE constexpr reverse_iterator &operator++() {
86 --current;
87 return *this;
88 }
89 LIBC_INLINE constexpr reverse_iterator operator++(int) {
90 reverse_iterator tmp(*this);
91 --current;
92 return tmp;
93 }
94};
95
96} // namespace cpp
97} // namespace LIBC_NAMESPACE_DECL
98
99#endif // LLVM_LIBC_SRC___SUPPORT_CPP_ITERATOR_H
lib/libcxx/libc/src/__support/CPP/limits.h created+92
......@@ -0,0 +1,92 @@
1//===-- A self contained equivalent of std::limits --------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_LIMITS_H
10#define LLVM_LIBC_SRC___SUPPORT_CPP_LIMITS_H
11
12#include "hdr/limits_macros.h" // CHAR_BIT
13#include "src/__support/CPP/type_traits/is_integral.h"
14#include "src/__support/CPP/type_traits/is_signed.h"
15#include "src/__support/macros/attributes.h" // LIBC_INLINE
16#include "src/__support/macros/config.h"
17#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
18
19namespace LIBC_NAMESPACE_DECL {
20namespace cpp {
21
22namespace internal {
23
24template <typename T, T min_value, T max_value> struct integer_impl {
25 static_assert(cpp::is_integral_v<T>);
26 LIBC_INLINE static constexpr T max() { return max_value; }
27 LIBC_INLINE static constexpr T min() { return min_value; }
28 LIBC_INLINE_VAR static constexpr int digits =
29 CHAR_BIT * sizeof(T) - cpp::is_signed_v<T>;
30};
31
32} // namespace internal
33
34template <class T> struct numeric_limits {};
35
36// TODO: Add numeric_limits specializations as needed for new types.
37template <>
38struct numeric_limits<short>
39 : public internal::integer_impl<short, SHRT_MIN, SHRT_MAX> {};
40
41template <>
42struct numeric_limits<unsigned short>
43 : public internal::integer_impl<unsigned short, 0, USHRT_MAX> {};
44
45template <>
46struct numeric_limits<int>
47 : public internal::integer_impl<int, INT_MIN, INT_MAX> {};
48
49template <>
50struct numeric_limits<unsigned int>
51 : public internal::integer_impl<unsigned int, 0, UINT_MAX> {};
52
53template <>
54struct numeric_limits<long>
55 : public internal::integer_impl<long, LONG_MIN, LONG_MAX> {};
56
57template <>
58struct numeric_limits<unsigned long>
59 : public internal::integer_impl<unsigned long, 0, ULONG_MAX> {};
60
61template <>
62struct numeric_limits<long long>
63 : public internal::integer_impl<long long, LLONG_MIN, LLONG_MAX> {};
64
65template <>
66struct numeric_limits<unsigned long long>
67 : public internal::integer_impl<unsigned long long, 0, ULLONG_MAX> {};
68
69template <>
70struct numeric_limits<char>
71 : public internal::integer_impl<char, CHAR_MIN, CHAR_MAX> {};
72
73template <>
74struct numeric_limits<signed char>
75 : public internal::integer_impl<signed char, SCHAR_MIN, SCHAR_MAX> {};
76
77template <>
78struct numeric_limits<unsigned char>
79 : public internal::integer_impl<unsigned char, 0, UCHAR_MAX> {};
80
81#ifdef LIBC_TYPES_HAS_INT128
82// On platform where UInt128 resolves to __uint128_t, this specialization
83// provides the limits of UInt128.
84template <>
85struct numeric_limits<__uint128_t>
86 : public internal::integer_impl<__uint128_t, 0, ~__uint128_t(0)> {};
87#endif
88
89} // namespace cpp
90} // namespace LIBC_NAMESPACE_DECL
91
92#endif // LLVM_LIBC_SRC___SUPPORT_CPP_LIMITS_H
lib/libcxx/libc/src/__support/CPP/optional.h created+139
......@@ -0,0 +1,139 @@
1//===-- Standalone implementation of std::optional --------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_OPTIONAL_H
10#define LLVM_LIBC_SRC___SUPPORT_CPP_OPTIONAL_H
11
12#include "src/__support/CPP/type_traits.h"
13#include "src/__support/CPP/utility.h"
14#include "src/__support/macros/attributes.h"
15#include "src/__support/macros/config.h"
16
17namespace LIBC_NAMESPACE_DECL {
18namespace cpp {
19
20// Trivial nullopt_t struct.
21struct nullopt_t {
22 LIBC_INLINE constexpr explicit nullopt_t() = default;
23};
24
25// nullopt that can be used and returned.
26LIBC_INLINE_VAR constexpr nullopt_t nullopt{};
27
28// This is very simple implementation of the std::optional class. It makes
29// several assumptions that the underlying type is trivially constructible,
30// copyable, or movable.
31template <typename T> class optional {
32 template <typename U, bool = !is_trivially_destructible<U>::value>
33 struct OptionalStorage {
34 union {
35 char empty;
36 U stored_value;
37 };
38
39 bool in_use = false;
40
41 LIBC_INLINE ~OptionalStorage() { reset(); }
42
43 LIBC_INLINE constexpr OptionalStorage() : empty() {}
44
45 template <typename... Args>
46 LIBC_INLINE constexpr explicit OptionalStorage(in_place_t, Args &&...args)
47 : stored_value(forward<Args>(args)...) {}
48
49 LIBC_INLINE constexpr void reset() {
50 if (in_use)
51 stored_value.~U();
52 in_use = false;
53 }
54 };
55
56 // The only difference is that this type U doesn't have a nontrivial
57 // destructor.
58 template <typename U> struct OptionalStorage<U, false> {
59 union {
60 char empty;
61 U stored_value;
62 };
63
64 bool in_use = false;
65
66 LIBC_INLINE constexpr OptionalStorage() : empty() {}
67
68 template <typename... Args>
69 LIBC_INLINE constexpr explicit OptionalStorage(in_place_t, Args &&...args)
70 : stored_value(forward<Args>(args)...) {}
71
72 LIBC_INLINE constexpr void reset() { in_use = false; }
73 };
74
75 OptionalStorage<T> storage;
76
77public:
78 LIBC_INLINE constexpr optional() = default;
79 LIBC_INLINE constexpr optional(nullopt_t) {}
80
81 LIBC_INLINE constexpr optional(const T &t) : storage(in_place, t) {
82 storage.in_use = true;
83 }
84 LIBC_INLINE constexpr optional(const optional &) = default;
85
86 LIBC_INLINE constexpr optional(T &&t) : storage(in_place, move(t)) {
87 storage.in_use = true;
88 }
89 LIBC_INLINE constexpr optional(optional &&O) = default;
90
91 template <typename... ArgTypes>
92 LIBC_INLINE constexpr optional(in_place_t, ArgTypes &&...Args)
93 : storage(in_place, forward<ArgTypes>(Args)...) {
94 storage.in_use = true;
95 }
96
97 LIBC_INLINE constexpr optional &operator=(T &&t) {
98 storage = move(t);
99 return *this;
100 }
101 LIBC_INLINE constexpr optional &operator=(optional &&) = default;
102
103 LIBC_INLINE constexpr optional &operator=(const T &t) {
104 storage = t;
105 return *this;
106 }
107 LIBC_INLINE constexpr optional &operator=(const optional &) = default;
108
109 LIBC_INLINE constexpr void reset() { storage.reset(); }
110
111 LIBC_INLINE constexpr const T &value() const & {
112 return storage.stored_value;
113 }
114
115 LIBC_INLINE constexpr T &value() & { return storage.stored_value; }
116
117 LIBC_INLINE constexpr explicit operator bool() const {
118 return storage.in_use;
119 }
120 LIBC_INLINE constexpr bool has_value() const { return storage.in_use; }
121 LIBC_INLINE constexpr const T *operator->() const {
122 return &storage.stored_value;
123 }
124 LIBC_INLINE constexpr T *operator->() { return &storage.stored_value; }
125 LIBC_INLINE constexpr const T &operator*() const & {
126 return storage.stored_value;
127 }
128 LIBC_INLINE constexpr T &operator*() & { return storage.stored_value; }
129
130 LIBC_INLINE constexpr T &&value() && { return move(storage.stored_value); }
131 LIBC_INLINE constexpr T &&operator*() && {
132 return move(storage.stored_value);
133 }
134};
135
136} // namespace cpp
137} // namespace LIBC_NAMESPACE_DECL
138
139#endif // LLVM_LIBC_SRC___SUPPORT_CPP_OPTIONAL_H
lib/libcxx/libc/src/__support/CPP/string_view.h created+220
......@@ -0,0 +1,220 @@
1//===-- Standalone implementation std::string_view --------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_STRING_VIEW_H
10#define LLVM_LIBC_SRC___SUPPORT_CPP_STRING_VIEW_H
11
12#include "src/__support/common.h"
13#include "src/__support/macros/config.h"
14
15#include <stddef.h>
16
17namespace LIBC_NAMESPACE_DECL {
18namespace cpp {
19
20// This is very simple alternate of the std::string_view class. There is no
21// bounds check performed in any of the methods. The callers are expected to
22// do the checks before invoking the methods.
23//
24// This class will be extended as needed in future.
25class string_view {
26private:
27 const char *Data;
28 size_t Len;
29
30 LIBC_INLINE static size_t min(size_t A, size_t B) { return A <= B ? A : B; }
31
32 LIBC_INLINE static int compareMemory(const char *Lhs, const char *Rhs,
33 size_t Length) {
34 for (size_t i = 0; i < Length; ++i)
35 if (int Diff = (int)Lhs[i] - (int)Rhs[i])
36 return Diff;
37 return 0;
38 }
39
40 LIBC_INLINE static constexpr size_t length(const char *Str) {
41 for (const char *End = Str;; ++End)
42 if (*End == '\0')
43 return End - Str;
44 }
45
46 LIBC_INLINE bool equals(string_view Other) const {
47 return (Len == Other.Len &&
48 compareMemory(Data, Other.Data, Other.Len) == 0);
49 }
50
51public:
52 using value_type = char;
53 using size_type = size_t;
54 using difference_type = ptrdiff_t;
55 using pointer = char *;
56 using const_pointer = const char *;
57 using reference = char &;
58 using const_reference = const char &;
59 using const_iterator = char *;
60 using iterator = const_iterator;
61
62 // special value equal to the maximum value representable by the type
63 // size_type.
64 LIBC_INLINE_VAR static constexpr size_t npos = -1;
65
66 LIBC_INLINE constexpr string_view() : Data(nullptr), Len(0) {}
67
68 // Assumes Str is a null-terminated string. The length of the string does
69 // not include the terminating null character.
70 // Preconditions: [Str, Str + ​length(Str)) is a valid range.
71 LIBC_INLINE constexpr string_view(const char *Str)
72 : Data(Str), Len(length(Str)) {}
73
74 // Preconditions: [Str, Str + N) is a valid range.
75 LIBC_INLINE constexpr string_view(const char *Str, size_t N)
76 : Data(Str), Len(N) {}
77
78 LIBC_INLINE constexpr const char *data() const { return Data; }
79
80 // Returns the size of the string_view.
81 LIBC_INLINE constexpr size_t size() const { return Len; }
82
83 // Returns whether the string_view is empty.
84 LIBC_INLINE constexpr bool empty() const { return Len == 0; }
85
86 // Returns an iterator to the first character of the view.
87 LIBC_INLINE const char *begin() const { return Data; }
88
89 // Returns an iterator to the character following the last character of the
90 // view.
91 LIBC_INLINE const char *end() const { return Data + Len; }
92
93 // Returns a const reference to the character at specified location pos.
94 // No bounds checking is performed: the behavior is undefined if pos >=
95 // size().
96 LIBC_INLINE constexpr const char &operator[](size_t Index) const {
97 return Data[Index];
98 }
99
100 /// compare - Compare two strings; the result is -1, 0, or 1 if this string
101 /// is lexicographically less than, equal to, or greater than the \p Other.
102 LIBC_INLINE int compare(string_view Other) const {
103 // Check the prefix for a mismatch.
104 if (int Res = compareMemory(Data, Other.Data, min(Len, Other.Len)))
105 return Res < 0 ? -1 : 1;
106 // Otherwise the prefixes match, so we only need to check the lengths.
107 if (Len == Other.Len)
108 return 0;
109 return Len < Other.Len ? -1 : 1;
110 }
111
112 LIBC_INLINE bool operator==(string_view Other) const { return equals(Other); }
113 LIBC_INLINE bool operator!=(string_view Other) const {
114 return !(*this == Other);
115 }
116 LIBC_INLINE bool operator<(string_view Other) const {
117 return compare(Other) == -1;
118 }
119 LIBC_INLINE bool operator<=(string_view Other) const {
120 return compare(Other) != 1;
121 }
122 LIBC_INLINE bool operator>(string_view Other) const {
123 return compare(Other) == 1;
124 }
125 LIBC_INLINE bool operator>=(string_view Other) const {
126 return compare(Other) != -1;
127 }
128
129 // Moves the start of the view forward by n characters.
130 // The behavior is undefined if n > size().
131 LIBC_INLINE void remove_prefix(size_t N) {
132 Len -= N;
133 Data += N;
134 }
135
136 // Moves the end of the view back by n characters.
137 // The behavior is undefined if n > size().
138 LIBC_INLINE void remove_suffix(size_t N) { Len -= N; }
139
140 // Check if this string starts with the given Prefix.
141 LIBC_INLINE bool starts_with(string_view Prefix) const {
142 return Len >= Prefix.Len &&
143 compareMemory(Data, Prefix.Data, Prefix.Len) == 0;
144 }
145
146 // Check if this string starts with the given Prefix.
147 LIBC_INLINE bool starts_with(const char Prefix) const {
148 return !empty() && front() == Prefix;
149 }
150
151 // Check if this string ends with the given Prefix.
152 LIBC_INLINE bool ends_with(const char Suffix) const {
153 return !empty() && back() == Suffix;
154 }
155
156 // Check if this string ends with the given Suffix.
157 LIBC_INLINE bool ends_with(string_view Suffix) const {
158 return Len >= Suffix.Len &&
159 compareMemory(end() - Suffix.Len, Suffix.Data, Suffix.Len) == 0;
160 }
161
162 // Return a reference to the substring from [Start, Start + N).
163 //
164 // Start The index of the starting character in the substring; if the index is
165 // npos or greater than the length of the string then the empty substring will
166 // be returned.
167 //
168 // N The number of characters to included in the substring. If N exceeds the
169 // number of characters remaining in the string, the string suffix (starting
170 // with Start) will be returned.
171 LIBC_INLINE string_view substr(size_t Start, size_t N = npos) const {
172 Start = min(Start, Len);
173 return string_view(Data + Start, min(N, Len - Start));
174 }
175
176 // front - Get the first character in the string.
177 LIBC_INLINE char front() const { return Data[0]; }
178
179 // back - Get the last character in the string.
180 LIBC_INLINE char back() const { return Data[Len - 1]; }
181
182 // Finds the first occurence of c in this view, starting at position From.
183 LIBC_INLINE constexpr size_t find_first_of(const char c,
184 size_t From = 0) const {
185 for (size_t Pos = From; Pos < size(); ++Pos)
186 if ((*this)[Pos] == c)
187 return Pos;
188 return npos;
189 }
190
191 // Finds the last occurence of c in this view, ending at position End.
192 LIBC_INLINE constexpr size_t find_last_of(const char c,
193 size_t End = npos) const {
194 End = End >= size() ? size() : End + 1;
195 for (; End > 0; --End)
196 if ((*this)[End - 1] == c)
197 return End - 1;
198 return npos;
199 }
200
201 // Finds the first character not equal to c in this view, starting at position
202 // From.
203 LIBC_INLINE constexpr size_t find_first_not_of(const char c,
204 size_t From = 0) const {
205 for (size_t Pos = From; Pos < size(); ++Pos)
206 if ((*this)[Pos] != c)
207 return Pos;
208 return npos;
209 }
210
211 // Check if this view contains the given character.
212 LIBC_INLINE constexpr bool contains(char c) const {
213 return find_first_of(c) != npos;
214 }
215};
216
217} // namespace cpp
218} // namespace LIBC_NAMESPACE_DECL
219
220#endif // LLVM_LIBC_SRC___SUPPORT_CPP_STRING_VIEW_H
lib/libcxx/libc/src/__support/CPP/type_traits.h created+70
......@@ -0,0 +1,70 @@
1//===-- Self contained C++ type_traits --------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_H
10#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_H
11
12#include "src/__support/CPP/type_traits/add_lvalue_reference.h"
13#include "src/__support/CPP/type_traits/add_pointer.h"
14#include "src/__support/CPP/type_traits/add_rvalue_reference.h"
15#include "src/__support/CPP/type_traits/aligned_storage.h"
16#include "src/__support/CPP/type_traits/bool_constant.h"
17#include "src/__support/CPP/type_traits/conditional.h"
18#include "src/__support/CPP/type_traits/decay.h"
19#include "src/__support/CPP/type_traits/enable_if.h"
20#include "src/__support/CPP/type_traits/false_type.h"
21#include "src/__support/CPP/type_traits/has_unique_object_representations.h"
22#include "src/__support/CPP/type_traits/integral_constant.h"
23#include "src/__support/CPP/type_traits/invoke.h"
24#include "src/__support/CPP/type_traits/invoke_result.h"
25#include "src/__support/CPP/type_traits/is_arithmetic.h"
26#include "src/__support/CPP/type_traits/is_array.h"
27#include "src/__support/CPP/type_traits/is_base_of.h"
28#include "src/__support/CPP/type_traits/is_class.h"
29#include "src/__support/CPP/type_traits/is_complex.h"
30#include "src/__support/CPP/type_traits/is_const.h"
31#include "src/__support/CPP/type_traits/is_constant_evaluated.h"
32#include "src/__support/CPP/type_traits/is_convertible.h"
33#include "src/__support/CPP/type_traits/is_copy_assignable.h"
34#include "src/__support/CPP/type_traits/is_copy_constructible.h"
35#include "src/__support/CPP/type_traits/is_destructible.h"
36#include "src/__support/CPP/type_traits/is_enum.h"
37#include "src/__support/CPP/type_traits/is_fixed_point.h"
38#include "src/__support/CPP/type_traits/is_floating_point.h"
39#include "src/__support/CPP/type_traits/is_function.h"
40#include "src/__support/CPP/type_traits/is_integral.h"
41#include "src/__support/CPP/type_traits/is_lvalue_reference.h"
42#include "src/__support/CPP/type_traits/is_member_pointer.h"
43#include "src/__support/CPP/type_traits/is_move_assignable.h"
44#include "src/__support/CPP/type_traits/is_move_constructible.h"
45#include "src/__support/CPP/type_traits/is_null_pointer.h"
46#include "src/__support/CPP/type_traits/is_object.h"
47#include "src/__support/CPP/type_traits/is_pointer.h"
48#include "src/__support/CPP/type_traits/is_reference.h"
49#include "src/__support/CPP/type_traits/is_rvalue_reference.h"
50#include "src/__support/CPP/type_traits/is_same.h"
51#include "src/__support/CPP/type_traits/is_scalar.h"
52#include "src/__support/CPP/type_traits/is_signed.h"
53#include "src/__support/CPP/type_traits/is_trivially_constructible.h"
54#include "src/__support/CPP/type_traits/is_trivially_copyable.h"
55#include "src/__support/CPP/type_traits/is_trivially_destructible.h"
56#include "src/__support/CPP/type_traits/is_union.h"
57#include "src/__support/CPP/type_traits/is_unsigned.h"
58#include "src/__support/CPP/type_traits/is_void.h"
59#include "src/__support/CPP/type_traits/make_signed.h"
60#include "src/__support/CPP/type_traits/make_unsigned.h"
61#include "src/__support/CPP/type_traits/remove_all_extents.h"
62#include "src/__support/CPP/type_traits/remove_cv.h"
63#include "src/__support/CPP/type_traits/remove_cvref.h"
64#include "src/__support/CPP/type_traits/remove_extent.h"
65#include "src/__support/CPP/type_traits/remove_reference.h"
66#include "src/__support/CPP/type_traits/true_type.h"
67#include "src/__support/CPP/type_traits/type_identity.h"
68#include "src/__support/CPP/type_traits/void_t.h"
69
70#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_H
lib/libcxx/libc/src/__support/CPP/type_traits/add_lvalue_reference.h created+33
......@@ -0,0 +1,33 @@
1//===-- add_lvalue_reference type_traits ------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_LVALUE_REFERENCE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_LVALUE_REFERENCE_H
10
11#include "src/__support/CPP/type_traits/type_identity.h"
12#include "src/__support/macros/config.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace cpp {
16
17// add_lvalue_reference
18namespace detail {
19template <class T> // Note that `cv void&` is a substitution failure
20auto try_add_lvalue_reference(int) -> cpp::type_identity<T &>;
21template <class T> // Handle T = cv void case
22auto try_add_lvalue_reference(...) -> cpp::type_identity<T>;
23} // namespace detail
24template <class T>
25struct add_lvalue_reference : decltype(detail::try_add_lvalue_reference<T>(0)) {
26};
27template <class T>
28using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;
29
30} // namespace cpp
31} // namespace LIBC_NAMESPACE_DECL
32
33#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_LVALUE_REFERENCE_H
lib/libcxx/libc/src/__support/CPP/type_traits/add_pointer.h created+30
......@@ -0,0 +1,30 @@
1//===-- add_pointer type_traits ---------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_POINTER_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_POINTER_H
10
11#include "src/__support/CPP/type_traits/remove_reference.h"
12#include "src/__support/CPP/type_traits/type_identity.h"
13#include "src/__support/macros/config.h"
14
15namespace LIBC_NAMESPACE_DECL {
16namespace cpp {
17
18// add_pointer
19namespace detail {
20template <class T>
21auto try_add_pointer(int) -> cpp::type_identity<cpp::remove_reference_t<T> *>;
22template <class T> auto try_add_pointer(...) -> cpp::type_identity<T>;
23} // namespace detail
24template <class T>
25struct add_pointer : decltype(detail::try_add_pointer<T>(0)) {};
26template <class T> using add_pointer_t = typename add_pointer<T>::type;
27} // namespace cpp
28} // namespace LIBC_NAMESPACE_DECL
29
30#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_POINTER_H
lib/libcxx/libc/src/__support/CPP/type_traits/add_rvalue_reference.h created+32
......@@ -0,0 +1,32 @@
1//===-- add_rvalue_reference type_traits ------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_RVALUE_REFERENCE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_RVALUE_REFERENCE_H
10
11#include "src/__support/CPP/type_traits/type_identity.h"
12#include "src/__support/macros/config.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace cpp {
16
17// add_rvalue_reference
18namespace detail {
19template <class T>
20auto try_add_rvalue_reference(int) -> cpp::type_identity<T &&>;
21template <class T> auto try_add_rvalue_reference(...) -> cpp::type_identity<T>;
22} // namespace detail
23template <class T>
24struct add_rvalue_reference : decltype(detail::try_add_rvalue_reference<T>(0)) {
25};
26template <class T>
27using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;
28
29} // namespace cpp
30} // namespace LIBC_NAMESPACE_DECL
31
32#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_RVALUE_REFERENCE_H
lib/libcxx/libc/src/__support/CPP/type_traits/aligned_storage.h created+30
......@@ -0,0 +1,30 @@
1//===-- aligned_storage type_traits --------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ALIGNED_STORAGE_H
10#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ALIGNED_STORAGE_H
11
12#include "src/__support/macros/config.h"
13#include <stddef.h> // size_t
14
15namespace LIBC_NAMESPACE_DECL {
16namespace cpp {
17
18template <size_t Len, size_t Align> struct aligned_storage {
19 struct type {
20 alignas(Align) unsigned char data[Len];
21 };
22};
23
24template <size_t Len, size_t Align>
25using aligned_storage_t = typename aligned_storage<Len, Align>::type;
26
27} // namespace cpp
28} // namespace LIBC_NAMESPACE_DECL
29
30#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ALIGNED_STORAGE_H
lib/libcxx/libc/src/__support/CPP/type_traits/always_false.h created+32
......@@ -0,0 +1,32 @@
1//===-- convenient static_assert(false) helper ------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ALWAYS_FALSE_H
10#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ALWAYS_FALSE_H
11
12#include "src/__support/macros/attributes.h"
13#include "src/__support/macros/config.h"
14
15namespace LIBC_NAMESPACE_DECL {
16namespace cpp {
17
18// This is technically not part of the standard but it come often enough that
19// it's convenient to have around.
20//
21// https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2593r0.html#valid-workaround
22//
23// This will be fixed in C++23 according to [CWG
24// 2518](https://cplusplus.github.io/CWG/issues/2518.html).
25
26// Usage `static_assert(cpp::always_false<T>, "error message");`
27template <typename...> LIBC_INLINE_VAR constexpr bool always_false = false;
28
29} // namespace cpp
30} // namespace LIBC_NAMESPACE_DECL
31
32#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ALWAYS_FALSE_H
lib/libcxx/libc/src/__support/CPP/type_traits/bool_constant.h created+23
......@@ -0,0 +1,23 @@
1//===-- bool_constant type_traits -------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_BOOL_CONSTANT_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_BOOL_CONSTANT_H
10
11#include "src/__support/CPP/type_traits/integral_constant.h"
12#include "src/__support/macros/config.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace cpp {
16
17// bool_constant
18template <bool V> using bool_constant = cpp::integral_constant<bool, V>;
19
20} // namespace cpp
21} // namespace LIBC_NAMESPACE_DECL
22
23#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_BOOL_CONSTANT_H
lib/libcxx/libc/src/__support/CPP/type_traits/conditional.h created+28
......@@ -0,0 +1,28 @@
1//===-- conditional type_traits ---------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_CONDITIONAL_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_CONDITIONAL_H
10
11#include "src/__support/CPP/type_traits/type_identity.h"
12#include "src/__support/macros/config.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace cpp {
16
17// conditional
18template <bool B, typename T, typename F>
19struct conditional : type_identity<T> {};
20template <typename T, typename F>
21struct conditional<false, T, F> : type_identity<F> {};
22template <bool B, typename T, typename F>
23using conditional_t = typename conditional<B, T, F>::type;
24
25} // namespace cpp
26} // namespace LIBC_NAMESPACE_DECL
27
28#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_CONDITIONAL_H
lib/libcxx/libc/src/__support/CPP/type_traits/decay.h created+40
......@@ -0,0 +1,40 @@
1//===-- decay type_traits ---------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_DECAY_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_DECAY_H
10
11#include "src/__support/macros/attributes.h"
12
13#include "src/__support/CPP/type_traits/add_pointer.h"
14#include "src/__support/CPP/type_traits/conditional.h"
15#include "src/__support/CPP/type_traits/is_array.h"
16#include "src/__support/CPP/type_traits/is_function.h"
17#include "src/__support/CPP/type_traits/remove_cv.h"
18#include "src/__support/CPP/type_traits/remove_extent.h"
19#include "src/__support/CPP/type_traits/remove_reference.h"
20#include "src/__support/macros/config.h"
21
22namespace LIBC_NAMESPACE_DECL {
23namespace cpp {
24
25// decay
26template <class T> class decay {
27 using U = cpp::remove_reference_t<T>;
28
29public:
30 using type = conditional_t<
31 cpp::is_array_v<U>, cpp::add_pointer_t<cpp::remove_extent_t<U>>,
32 cpp::conditional_t<cpp::is_function_v<U>, cpp::add_pointer_t<U>,
33 cpp::remove_cv_t<U>>>;
34};
35template <class T> using decay_t = typename decay<T>::type;
36
37} // namespace cpp
38} // namespace LIBC_NAMESPACE_DECL
39
40#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_DECAY_H
lib/libcxx/libc/src/__support/CPP/type_traits/enable_if.h created+26
......@@ -0,0 +1,26 @@
1//===-- enable_if type_traits -----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ENABLE_IF_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ENABLE_IF_H
10
11#include "src/__support/CPP/type_traits/type_identity.h"
12#include "src/__support/macros/config.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace cpp {
16
17// enable_if
18template <bool B, typename T = void> struct enable_if;
19template <typename T> struct enable_if<true, T> : type_identity<T> {};
20template <bool B, typename T = void>
21using enable_if_t = typename enable_if<B, T>::type;
22
23} // namespace cpp
24} // namespace LIBC_NAMESPACE_DECL
25
26#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ENABLE_IF_H
lib/libcxx/libc/src/__support/CPP/type_traits/false_type.h created+23
......@@ -0,0 +1,23 @@
1//===-- false_type type_traits ----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_FALSE_TYPE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_FALSE_TYPE_H
10
11#include "src/__support/CPP/type_traits/bool_constant.h"
12#include "src/__support/macros/config.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace cpp {
16
17// false_type
18using false_type = cpp::bool_constant<false>;
19
20} // namespace cpp
21} // namespace LIBC_NAMESPACE_DECL
22
23#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_FALSE_TYPE_H
lib/libcxx/libc/src/__support/CPP/type_traits/has_unique_object_representations.h created+30
......@@ -0,0 +1,30 @@
1//===-- has_unique_object_representations type_traits ------------*- C++-*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_HAS_UNIQUE_OBJECT_REPRESENTATIONS_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_HAS_UNIQUE_OBJECT_REPRESENTATIONS_H
10
11#include "src/__support/CPP/type_traits/integral_constant.h"
12#include "src/__support/CPP/type_traits/remove_all_extents.h"
13#include "src/__support/macros/config.h"
14
15namespace LIBC_NAMESPACE_DECL {
16namespace cpp {
17
18template <class T>
19struct has_unique_object_representations
20 : public integral_constant<bool, __has_unique_object_representations(
21 remove_all_extents_t<T>)> {};
22
23template <class T>
24LIBC_INLINE_VAR constexpr bool has_unique_object_representations_v =
25 has_unique_object_representations<T>::value;
26
27} // namespace cpp
28} // namespace LIBC_NAMESPACE_DECL
29
30#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_HAS_UNIQUE_OBJECT_REPRESENTATIONS_H
lib/libcxx/libc/src/__support/CPP/type_traits/integral_constant.h created+26
......@@ -0,0 +1,26 @@
1//===-- integral_constant type_traits ---------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INTEGRAL_CONSTANT_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INTEGRAL_CONSTANT_H
10
11#include "src/__support/macros/attributes.h" // LIBC_INLINE_VAR
12#include "src/__support/macros/config.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace cpp {
16
17// integral_constant
18template <typename T, T v> struct integral_constant {
19 using value_type = T;
20 LIBC_INLINE_VAR static constexpr T value = v;
21};
22
23} // namespace cpp
24} // namespace LIBC_NAMESPACE_DECL
25
26#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INTEGRAL_CONSTANT_H
lib/libcxx/libc/src/__support/CPP/type_traits/invoke.h created+67
......@@ -0,0 +1,67 @@
1//===-- invoke type_traits --------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INVOKE_H
10#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INVOKE_H
11
12#include "src/__support/CPP/type_traits/always_false.h"
13#include "src/__support/CPP/type_traits/decay.h"
14#include "src/__support/CPP/type_traits/enable_if.h"
15#include "src/__support/CPP/type_traits/is_base_of.h"
16#include "src/__support/CPP/type_traits/is_pointer.h"
17#include "src/__support/CPP/type_traits/is_same.h"
18#include "src/__support/CPP/utility/forward.h"
19#include "src/__support/macros/attributes.h" // LIBC_INLINE
20#include "src/__support/macros/config.h"
21
22namespace LIBC_NAMESPACE_DECL {
23namespace cpp {
24
25namespace detail {
26
27// Catch all function and functor types.
28template <class FunctionPtrType> struct invoke_dispatcher {
29 template <class T, class... Args,
30 typename = cpp::enable_if_t<
31 cpp::is_same_v<cpp::decay_t<T>, FunctionPtrType>>>
32 LIBC_INLINE static decltype(auto) call(T &&fun, Args &&...args) {
33 return cpp::forward<T>(fun)(cpp::forward<Args>(args)...);
34 }
35};
36
37// Catch pointer to member function types.
38template <class Class, class FunctionReturnType>
39struct invoke_dispatcher<FunctionReturnType Class::*> {
40 using FunctionPtrType = FunctionReturnType Class::*;
41
42 template <class T, class... Args, class DecayT = cpp::decay_t<T>>
43 LIBC_INLINE static decltype(auto) call(FunctionPtrType fun, T &&t1,
44 Args &&...args) {
45 if constexpr (cpp::is_base_of_v<Class, DecayT>) {
46 // T is a (possibly cv ref) type.
47 return (cpp::forward<T>(t1).*fun)(cpp::forward<Args>(args)...);
48 } else if constexpr (cpp::is_pointer_v<T>) {
49 // T is a pointer type.
50 return (*cpp::forward<T>(t1).*fun)(cpp::forward<Args>(args)...);
51 } else {
52 static_assert(cpp::always_false<T>);
53 }
54 }
55};
56
57} // namespace detail
58template <class Function, class... Args>
59decltype(auto) invoke(Function &&fun, Args &&...args) {
60 return detail::invoke_dispatcher<cpp::decay_t<Function>>::call(
61 cpp::forward<Function>(fun), cpp::forward<Args>(args)...);
62}
63
64} // namespace cpp
65} // namespace LIBC_NAMESPACE_DECL
66
67#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INVOKE_H
lib/libcxx/libc/src/__support/CPP/type_traits/invoke_result.h created+29
......@@ -0,0 +1,29 @@
1//===-- invoke_result type_traits -------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INVOKE_RESULT_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INVOKE_RESULT_H
10
11#include "src/__support/CPP/type_traits/invoke.h"
12#include "src/__support/CPP/type_traits/type_identity.h"
13#include "src/__support/CPP/utility/declval.h"
14#include "src/__support/macros/config.h"
15
16namespace LIBC_NAMESPACE_DECL {
17namespace cpp {
18
19template <class F, class... Args>
20struct invoke_result : cpp::type_identity<decltype(cpp::invoke(
21 cpp::declval<F>(), cpp::declval<Args>()...))> {};
22
23template <class F, class... Args>
24using invoke_result_t = typename invoke_result<F, Args...>::type;
25
26} // namespace cpp
27} // namespace LIBC_NAMESPACE_DECL
28
29#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INVOKE_RESULT_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_arithmetic.h created+30
......@@ -0,0 +1,30 @@
1//===-- is_arithmetic type_traits -------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ARITHMETIC_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ARITHMETIC_H
10
11#include "src/__support/CPP/type_traits/bool_constant.h"
12#include "src/__support/CPP/type_traits/is_floating_point.h"
13#include "src/__support/CPP/type_traits/is_integral.h"
14#include "src/__support/macros/attributes.h"
15#include "src/__support/macros/config.h"
16
17namespace LIBC_NAMESPACE_DECL {
18namespace cpp {
19
20// is_arithmetic
21template <typename T>
22struct is_arithmetic : cpp::bool_constant<(cpp::is_integral_v<T> ||
23 cpp::is_floating_point_v<T>)> {};
24template <typename T>
25LIBC_INLINE_VAR constexpr bool is_arithmetic_v = is_arithmetic<T>::value;
26
27} // namespace cpp
28} // namespace LIBC_NAMESPACE_DECL
29
30#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ARITHMETIC_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_array.h created+31
......@@ -0,0 +1,31 @@
1//===-- is_array type_traits ------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ARRAY_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ARRAY_H
10
11#include "src/__support/CPP/type_traits/false_type.h"
12#include "src/__support/CPP/type_traits/true_type.h"
13#include "src/__support/macros/attributes.h"
14#include "src/__support/macros/config.h"
15
16#include <stddef.h> // For size_t
17
18namespace LIBC_NAMESPACE_DECL {
19namespace cpp {
20
21// is_array
22template <class T> struct is_array : false_type {};
23template <class T> struct is_array<T[]> : true_type {};
24template <class T, size_t N> struct is_array<T[N]> : true_type {};
25template <class T>
26LIBC_INLINE_VAR constexpr bool is_array_v = is_array<T>::value;
27
28} // namespace cpp
29} // namespace LIBC_NAMESPACE_DECL
30
31#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ARRAY_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_base_of.h created+47
......@@ -0,0 +1,47 @@
1//===-- is_base_of type_traits ----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_BASE_OF_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_BASE_OF_H
10
11#include "src/__support/CPP/type_traits/add_rvalue_reference.h"
12#include "src/__support/CPP/type_traits/false_type.h"
13#include "src/__support/CPP/type_traits/is_class.h"
14#include "src/__support/CPP/type_traits/remove_all_extents.h"
15#include "src/__support/CPP/type_traits/true_type.h"
16#include "src/__support/macros/attributes.h"
17#include "src/__support/macros/config.h"
18
19namespace LIBC_NAMESPACE_DECL {
20namespace cpp {
21
22// is_base_of
23namespace detail {
24template <typename B> cpp::true_type __test_ptr_conv(const volatile B *);
25template <typename> cpp::false_type __test_ptr_conv(const volatile void *);
26
27template <typename B, typename D>
28auto is_base_of(int) -> decltype(__test_ptr_conv<B>(static_cast<D *>(nullptr)));
29
30template <typename, typename>
31auto is_base_of(...) -> cpp::true_type; // private or ambiguous base
32
33} // namespace detail
34
35template <typename Base, typename Derived>
36struct is_base_of
37 : cpp::bool_constant<
38 cpp::is_class_v<Base> &&
39 cpp::is_class_v<Derived> &&decltype(detail::is_base_of<Base, Derived>(
40 0))::value> {};
41template <typename Base, typename Derived>
42LIBC_INLINE_VAR constexpr bool is_base_of_v = is_base_of<Base, Derived>::value;
43
44} // namespace cpp
45} // namespace LIBC_NAMESPACE_DECL
46
47#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_BASE_OF_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_class.h created+32
......@@ -0,0 +1,32 @@
1//===-- is_class type_traits ------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CLASS_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CLASS_H
10
11#include "src/__support/CPP/type_traits/bool_constant.h"
12#include "src/__support/CPP/type_traits/false_type.h"
13#include "src/__support/CPP/type_traits/is_union.h"
14#include "src/__support/macros/attributes.h"
15#include "src/__support/macros/config.h"
16
17namespace LIBC_NAMESPACE_DECL {
18namespace cpp {
19
20// is_class
21namespace detail {
22template <class T> cpp::bool_constant<!cpp::is_union_v<T>> test(int T::*);
23template <class> cpp::false_type test(...);
24} // namespace detail
25template <class T> struct is_class : decltype(detail::test<T>(nullptr)) {};
26template <typename T>
27LIBC_INLINE_VAR constexpr bool is_class_v = is_class<T>::value;
28
29} // namespace cpp
30} // namespace LIBC_NAMESPACE_DECL
31
32#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CLASS_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_complex.h created+53
......@@ -0,0 +1,53 @@
1//===-- is_complex type_traits ----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COMPLEX_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COMPLEX_H
10
11#include "src/__support/CPP/type_traits/is_same.h"
12#include "src/__support/CPP/type_traits/remove_cv.h"
13#include "src/__support/macros/attributes.h"
14#include "src/__support/macros/config.h"
15// LIBC_TYPES_HAS_CFLOAT16 && LIBC_TYPES_HAS_CFLOAT128
16#include "src/__support/macros/properties/complex_types.h"
17
18namespace LIBC_NAMESPACE_DECL {
19namespace cpp {
20
21// is_complex
22template <typename T> struct is_complex {
23private:
24 template <typename Head, typename... Args>
25 LIBC_INLINE_VAR static constexpr bool __is_unqualified_any_of() {
26 return (... || is_same_v<remove_cv_t<Head>, Args>);
27 }
28
29public:
30 LIBC_INLINE_VAR static constexpr bool value =
31 __is_unqualified_any_of<T, _Complex float, _Complex double,
32 _Complex long double
33#ifdef LIBC_TYPES_HAS_CFLOAT16
34 ,
35 cfloat16
36#endif
37#ifdef LIBC_TYPES_HAS_CFLOAT128
38 ,
39 cfloat128
40#endif
41 >();
42};
43template <typename T>
44LIBC_INLINE_VAR constexpr bool is_complex_v = is_complex<T>::value;
45template <typename T1, typename T2>
46LIBC_INLINE_VAR constexpr bool is_complex_type_same() {
47 return is_same_v<remove_cv_t<T1>, T2>;
48}
49
50} // namespace cpp
51} // namespace LIBC_NAMESPACE_DECL
52
53#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COMPLEX_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_const.h created+28
......@@ -0,0 +1,28 @@
1//===-- is_const type_traits ------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONST_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONST_H
10
11#include "src/__support/CPP/type_traits/false_type.h"
12#include "src/__support/CPP/type_traits/true_type.h"
13#include "src/__support/macros/attributes.h"
14#include "src/__support/macros/config.h"
15
16namespace LIBC_NAMESPACE_DECL {
17namespace cpp {
18
19// is_const
20template <class T> struct is_const : cpp::false_type {};
21template <class T> struct is_const<const T> : cpp::true_type {};
22template <class T>
23LIBC_INLINE_VAR constexpr bool is_const_v = is_const<T>::value;
24
25} // namespace cpp
26} // namespace LIBC_NAMESPACE_DECL
27
28#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONST_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_constant_evaluated.h created+24
......@@ -0,0 +1,24 @@
1//===-- is_constant_evaluated type_traits -----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONSTANT_EVALUATED_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONSTANT_EVALUATED_H
10
11#include "src/__support/macros/attributes.h"
12#include "src/__support/macros/config.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace cpp {
16
17LIBC_INLINE constexpr bool is_constant_evaluated() {
18 return __builtin_is_constant_evaluated();
19}
20
21} // namespace cpp
22} // namespace LIBC_NAMESPACE_DECL
23
24#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONSTANT_EVALUATED_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_convertible.h created+48
......@@ -0,0 +1,48 @@
1//===-- is_convertible type_traits ------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONVERTIBLE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONVERTIBLE_H
10
11#include "src/__support/CPP/type_traits/is_void.h"
12#include "src/__support/CPP/utility/declval.h"
13#include "src/__support/macros/attributes.h"
14#include "src/__support/macros/config.h"
15
16namespace LIBC_NAMESPACE_DECL {
17namespace cpp {
18
19// is_convertible
20namespace detail {
21template <class T>
22auto test_returnable(int)
23 -> decltype(void(static_cast<T (*)()>(nullptr)), cpp::true_type{});
24template <class> auto test_returnable(...) -> cpp::false_type;
25
26template <class From, class To>
27auto test_implicitly_convertible(int)
28 -> decltype(void(cpp::declval<void (&)(To)>()(cpp::declval<From>())),
29 cpp::true_type{});
30template <class, class>
31auto test_implicitly_convertible(...) -> cpp::false_type;
32} // namespace detail
33
34template <class From, class To>
35struct is_convertible
36 : cpp::bool_constant<
37 (decltype(detail::test_returnable<To>(0))::value &&
38 decltype(detail::test_implicitly_convertible<From, To>(0))::value) ||
39 (cpp::is_void_v<From> && cpp::is_void_v<To>)> {};
40
41template <class From, class To>
42LIBC_INLINE_VAR constexpr bool is_convertible_v =
43 is_convertible<From, To>::value;
44
45} // namespace cpp
46} // namespace LIBC_NAMESPACE_DECL
47
48#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONVERTIBLE_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_copy_assignable.h created+32
......@@ -0,0 +1,32 @@
1//===-- is_copy_assignable type_traits --------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COPY_ASSIGNABLE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COPY_ASSIGNABLE_H
10
11#include "src/__support/CPP/type_traits/add_lvalue_reference.h"
12#include "src/__support/CPP/type_traits/integral_constant.h"
13#include "src/__support/macros/config.h"
14
15namespace LIBC_NAMESPACE_DECL {
16namespace cpp {
17
18// is copy assignable
19template <class T>
20struct is_copy_assignable
21 : public integral_constant<
22 bool, __is_assignable(cpp::add_lvalue_reference_t<T>,
23 cpp::add_lvalue_reference_t<const T>)> {};
24
25template <class T>
26LIBC_INLINE_VAR constexpr bool is_copy_assignable_v =
27 is_copy_assignable<T>::value;
28
29} // namespace cpp
30} // namespace LIBC_NAMESPACE_DECL
31
32#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COPY_ASSIGNABLE_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_copy_constructible.h created+31
......@@ -0,0 +1,31 @@
1//===-- is_copy_constructible type_traits -----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COPY_CONSTRUCTIBLE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COPY_CONSTRUCTIBLE_H
10
11#include "src/__support/CPP/type_traits/add_lvalue_reference.h"
12#include "src/__support/CPP/type_traits/integral_constant.h"
13#include "src/__support/macros/config.h"
14
15namespace LIBC_NAMESPACE_DECL {
16namespace cpp {
17
18// is copy constructible
19template <class T>
20struct is_copy_constructible
21 : public integral_constant<
22 bool, __is_constructible(T, cpp::add_lvalue_reference_t<const T>)> {};
23
24template <class T>
25LIBC_INLINE_VAR constexpr bool is_copy_constructible_v =
26 is_copy_constructible<T>::value;
27
28} // namespace cpp
29} // namespace LIBC_NAMESPACE_DECL
30
31#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COPY_CONSTRUCTIBLE_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_destructible.h created+68
......@@ -0,0 +1,68 @@
1//===-- is_destructible type_traits -----------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_DESTRUCTIBLE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_DESTRUCTIBLE_H
10
11#include "src/__support/CPP/type_traits/bool_constant.h"
12#include "src/__support/CPP/type_traits/false_type.h"
13#include "src/__support/CPP/type_traits/is_function.h"
14#include "src/__support/CPP/type_traits/is_reference.h"
15#include "src/__support/CPP/type_traits/remove_all_extents.h"
16#include "src/__support/CPP/type_traits/true_type.h"
17#include "src/__support/CPP/type_traits/type_identity.h"
18#include "src/__support/macros/attributes.h"
19#include "src/__support/macros/config.h"
20
21namespace LIBC_NAMESPACE_DECL {
22namespace cpp {
23
24// is_destructible
25#if __has_builtin(__is_destructible)
26template <typename T>
27struct is_destructible : bool_constant<__is_destructible(T)> {};
28#else
29// if it's a reference, return true
30// if it's a function, return false
31// if it's void, return false
32// if it's an array of unknown bound, return false
33// Otherwise, return "declval<T&>().~T()" is well-formed
34// where T is remove_all_extents<T>::type
35template <typename> struct __is_destructible_apply : cpp::type_identity<int> {};
36template <typename T> struct __is_destructor_wellformed {
37 template <typename T1>
38 static cpp::true_type __test(
39 typename __is_destructible_apply<decltype(declval<T1 &>().~T1())>::type);
40 template <typename T1> static cpp::false_type __test(...);
41 static const bool value = decltype(__test<T>(12))::value;
42};
43template <typename T, bool> struct __destructible_imp;
44template <typename T>
45struct __destructible_imp<T, false>
46 : public bool_constant<
47 __is_destructor_wellformed<cpp::remove_all_extents_t<T>>::value> {};
48template <typename T>
49struct __destructible_imp<T, true> : public cpp::true_type {};
50template <typename T, bool> struct __destructible_false;
51template <typename T>
52struct __destructible_false<T, false>
53 : public __destructible_imp<T, is_reference<T>::value> {};
54template <typename T>
55struct __destructible_false<T, true> : public cpp::false_type {};
56template <typename T>
57struct is_destructible : public __destructible_false<T, is_function<T>::value> {
58};
59template <typename T> struct is_destructible<T[]> : public false_type {};
60template <> struct is_destructible<void> : public false_type {};
61#endif
62template <class T>
63LIBC_INLINE_VAR constexpr bool is_destructible_v = is_destructible<T>::value;
64
65} // namespace cpp
66} // namespace LIBC_NAMESPACE_DECL
67
68#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_DESTRUCTIBLE_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_enum.h created+26
......@@ -0,0 +1,26 @@
1//===-- is_enum type_traits -------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ENUM_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ENUM_H
10
11#include "src/__support/CPP/type_traits/bool_constant.h"
12#include "src/__support/macros/attributes.h"
13#include "src/__support/macros/config.h"
14
15namespace LIBC_NAMESPACE_DECL {
16namespace cpp {
17
18// is_enum
19template <typename T> struct is_enum : bool_constant<__is_enum(T)> {};
20template <typename T>
21LIBC_INLINE_VAR constexpr bool is_enum_v = is_enum<T>::value;
22
23} // namespace cpp
24} // namespace LIBC_NAMESPACE_DECL
25
26#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ENUM_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_fixed_point.h created+49
......@@ -0,0 +1,49 @@
1//===-- is_fixed_point type_traits ------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FIXED_POINT_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FIXED_POINT_H
10
11#include "src/__support/CPP/type_traits/is_same.h"
12#include "src/__support/CPP/type_traits/remove_cv.h"
13#include "src/__support/macros/attributes.h"
14
15#include "include/llvm-libc-macros/stdfix-macros.h"
16#include "src/__support/macros/config.h"
17
18namespace LIBC_NAMESPACE_DECL {
19namespace cpp {
20
21// is_fixed_point
22#ifdef LIBC_COMPILER_HAS_FIXED_POINT
23template <typename T> struct is_fixed_point {
24private:
25 template <typename Head, typename... Args>
26 LIBC_INLINE static constexpr bool __is_unqualified_any_of() {
27 return (... || is_same_v<remove_cv_t<Head>, Args>);
28 }
29
30public:
31 LIBC_INLINE_VAR static constexpr bool value = __is_unqualified_any_of<
32 T, short fract, fract, long fract, unsigned short fract, unsigned fract,
33 unsigned long fract, short accum, accum, long accum, unsigned short accum,
34 unsigned accum, unsigned long accum, short sat fract, sat fract,
35 long sat fract, unsigned short sat fract, unsigned sat fract,
36 unsigned long sat fract, short sat accum, sat accum, long sat accum,
37 unsigned short sat accum, unsigned sat accum, unsigned long sat accum>();
38};
39#else
40template <typename T> struct is_fixed_point : false_type {};
41#endif // LIBC_COMPILER_HAS_FIXED_POINT
42
43template <typename T>
44LIBC_INLINE_VAR constexpr bool is_fixed_point_v = is_fixed_point<T>::value;
45
46} // namespace cpp
47} // namespace LIBC_NAMESPACE_DECL
48
49#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FIXED_POINT_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_floating_point.h created+48
......@@ -0,0 +1,48 @@
1//===-- is_floating_point type_traits ---------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
10
11#include "src/__support/CPP/type_traits/is_same.h"
12#include "src/__support/CPP/type_traits/remove_cv.h"
13#include "src/__support/macros/attributes.h"
14#include "src/__support/macros/config.h"
15#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_FLOAT128
16
17namespace LIBC_NAMESPACE_DECL {
18namespace cpp {
19
20// is_floating_point
21template <typename T> struct is_floating_point {
22private:
23 template <typename Head, typename... Args>
24 LIBC_INLINE_VAR static constexpr bool __is_unqualified_any_of() {
25 return (... || is_same_v<remove_cv_t<Head>, Args>);
26 }
27
28public:
29 LIBC_INLINE_VAR static constexpr bool value =
30 __is_unqualified_any_of<T, float, double, long double
31#ifdef LIBC_TYPES_HAS_FLOAT16
32 ,
33 float16
34#endif
35#ifdef LIBC_TYPES_HAS_FLOAT128
36 ,
37 float128
38#endif
39 >();
40};
41template <typename T>
42LIBC_INLINE_VAR constexpr bool is_floating_point_v =
43 is_floating_point<T>::value;
44
45} // namespace cpp
46} // namespace LIBC_NAMESPACE_DECL
47
48#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_function.h created+35
......@@ -0,0 +1,35 @@
1//===-- is_function type_traits ---------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FUNCTION_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FUNCTION_H
10
11#include "src/__support/CPP/type_traits/bool_constant.h"
12#include "src/__support/CPP/type_traits/is_const.h"
13#include "src/__support/CPP/type_traits/is_reference.h"
14#include "src/__support/macros/attributes.h"
15#include "src/__support/macros/config.h"
16
17namespace LIBC_NAMESPACE_DECL {
18namespace cpp {
19
20// is_function
21#if __has_builtin(__is_function)
22template <typename T>
23struct is_function : integral_constant<bool, __is_function(T)> {};
24#else
25template <typename T>
26struct is_function
27 : public bool_constant<!(is_reference_v<T> || is_const_v<const T>)> {};
28#endif
29template <class T>
30LIBC_INLINE_VAR constexpr bool is_function_v = is_function<T>::value;
31
32} // namespace cpp
33} // namespace LIBC_NAMESPACE_DECL
34
35#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FUNCTION_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_integral.h created+43
......@@ -0,0 +1,43 @@
1//===-- is_integral type_traits ---------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_INTEGRAL_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_INTEGRAL_H
10
11#include "src/__support/CPP/type_traits/is_same.h"
12#include "src/__support/CPP/type_traits/remove_cv.h"
13#include "src/__support/macros/attributes.h"
14#include "src/__support/macros/config.h"
15#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
16
17namespace LIBC_NAMESPACE_DECL {
18namespace cpp {
19
20// is_integral
21template <typename T> struct is_integral {
22private:
23 template <typename Head, typename... Args>
24 LIBC_INLINE_VAR static constexpr bool __is_unqualified_any_of() {
25 return (... || is_same_v<remove_cv_t<Head>, Args>);
26 }
27
28public:
29 LIBC_INLINE_VAR static constexpr bool value = __is_unqualified_any_of<
30 T,
31#ifdef LIBC_TYPES_HAS_INT128
32 __int128_t, __uint128_t,
33#endif
34 char, signed char, unsigned char, short, unsigned short, int,
35 unsigned int, long, unsigned long, long long, unsigned long long, bool>();
36};
37template <typename T>
38LIBC_INLINE_VAR constexpr bool is_integral_v = is_integral<T>::value;
39
40} // namespace cpp
41} // namespace LIBC_NAMESPACE_DECL
42
43#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_INTEGRAL_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_lvalue_reference.h created+35
......@@ -0,0 +1,35 @@
1//===-- is_lvalue_reference type_traits -------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_LVALUE_REFERENCE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_LVALUE_REFERENCE_H
10
11#include "src/__support/CPP/type_traits/bool_constant.h"
12#include "src/__support/CPP/type_traits/false_type.h"
13#include "src/__support/CPP/type_traits/true_type.h"
14#include "src/__support/macros/attributes.h"
15#include "src/__support/macros/config.h"
16
17namespace LIBC_NAMESPACE_DECL {
18namespace cpp {
19
20// is_lvalue_reference
21#if __has_builtin(__is_lvalue_reference)
22template <typename T>
23struct is_lvalue_reference : bool_constant<__is_lvalue_reference(T)> {};
24#else
25template <typename T> struct is_lvalue_reference : public false_type {};
26template <typename T> struct is_lvalue_reference<T &> : public true_type {};
27#endif
28template <class T>
29LIBC_INLINE_VAR constexpr bool is_lvalue_reference_v =
30 is_lvalue_reference<T>::value;
31
32} // namespace cpp
33} // namespace LIBC_NAMESPACE_DECL
34
35#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_LVALUE_REFERENCE_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_member_pointer.h created+33
......@@ -0,0 +1,33 @@
1//===-- is_member_pointer type_traits ---------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MEMBER_POINTER_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MEMBER_POINTER_H
10
11#include "src/__support/CPP/type_traits/false_type.h"
12#include "src/__support/CPP/type_traits/remove_cv.h"
13#include "src/__support/CPP/type_traits/true_type.h"
14#include "src/__support/macros/attributes.h"
15#include "src/__support/macros/config.h"
16
17namespace LIBC_NAMESPACE_DECL {
18namespace cpp {
19
20// is_member_pointer
21template <class T> struct is_member_pointer_helper : cpp::false_type {};
22template <class T, class U>
23struct is_member_pointer_helper<T U::*> : cpp::true_type {};
24template <class T>
25struct is_member_pointer : is_member_pointer_helper<cpp::remove_cv_t<T>> {};
26template <class T>
27LIBC_INLINE_VAR constexpr bool is_member_pointer_v =
28 is_member_pointer<T>::value;
29
30} // namespace cpp
31} // namespace LIBC_NAMESPACE_DECL
32
33#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MEMBER_POINTER_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_move_assignable.h created+33
......@@ -0,0 +1,33 @@
1//===-- is_move_assignable type_traits --------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MOVE_ASSIGNABLE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MOVE_ASSIGNABLE_H
10
11#include "src/__support/CPP/type_traits/add_lvalue_reference.h"
12#include "src/__support/CPP/type_traits/add_rvalue_reference.h"
13#include "src/__support/CPP/type_traits/integral_constant.h"
14#include "src/__support/macros/config.h"
15
16namespace LIBC_NAMESPACE_DECL {
17namespace cpp {
18
19// is move assignable
20template <class T>
21struct is_move_assignable
22 : public integral_constant<bool, __is_assignable(
23 cpp::add_lvalue_reference_t<T>,
24 cpp::add_rvalue_reference_t<T>)> {};
25
26template <class T>
27LIBC_INLINE_VAR constexpr bool is_move_assignable_v =
28 is_move_assignable<T>::value;
29
30} // namespace cpp
31} // namespace LIBC_NAMESPACE_DECL
32
33#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MOVE_ASSIGNABLE_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_move_constructible.h created+31
......@@ -0,0 +1,31 @@
1//===-- is_move_constructible type_traits ------------------------*- C++-*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MOVE_CONSTRUCTIBLE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MOVE_CONSTRUCTIBLE_H
10
11#include "src/__support/CPP/type_traits/add_rvalue_reference.h"
12#include "src/__support/CPP/type_traits/integral_constant.h"
13#include "src/__support/macros/config.h"
14
15namespace LIBC_NAMESPACE_DECL {
16namespace cpp {
17
18// is move constructible
19template <class T>
20struct is_move_constructible
21 : public integral_constant<bool, __is_constructible(
22 T, cpp::add_rvalue_reference_t<T>)> {};
23
24template <class T>
25LIBC_INLINE_VAR constexpr bool is_move_constructible_v =
26 is_move_constructible<T>::value;
27
28} // namespace cpp
29} // namespace LIBC_NAMESPACE_DECL
30
31#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MOVE_CONSTRUCTIBLE_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_null_pointer.h created+29
......@@ -0,0 +1,29 @@
1//===-- is_null_pointer type_traits -----------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_NULL_POINTER_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_NULL_POINTER_H
10
11#include "src/__support/CPP/type_traits/is_same.h"
12#include "src/__support/CPP/type_traits/remove_cv.h"
13#include "src/__support/macros/attributes.h"
14#include "src/__support/macros/config.h"
15
16namespace LIBC_NAMESPACE_DECL {
17namespace cpp {
18
19// is_null_pointer
20using nullptr_t = decltype(nullptr);
21template <class T>
22struct is_null_pointer : cpp::is_same<cpp::nullptr_t, cpp::remove_cv_t<T>> {};
23template <class T>
24LIBC_INLINE_VAR constexpr bool is_null_pointer_v = is_null_pointer<T>::value;
25
26} // namespace cpp
27} // namespace LIBC_NAMESPACE_DECL
28
29#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_NULL_POINTER_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_object.h created+33
......@@ -0,0 +1,33 @@
1//===-- is_object type_traits -----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_OBJECT_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_OBJECT_H
10
11#include "src/__support/CPP/type_traits/bool_constant.h"
12#include "src/__support/CPP/type_traits/is_array.h"
13#include "src/__support/CPP/type_traits/is_class.h"
14#include "src/__support/CPP/type_traits/is_scalar.h"
15#include "src/__support/CPP/type_traits/is_union.h"
16#include "src/__support/macros/attributes.h"
17#include "src/__support/macros/config.h"
18
19namespace LIBC_NAMESPACE_DECL {
20namespace cpp {
21
22// is_object
23template <class T>
24struct is_object
25 : cpp::bool_constant<cpp::is_scalar_v<T> || cpp::is_array_v<T> ||
26 cpp::is_union_v<T> || cpp::is_class_v<T>> {};
27template <class T>
28LIBC_INLINE_VAR constexpr bool is_object_v = is_object<T>::value;
29
30} // namespace cpp
31} // namespace LIBC_NAMESPACE_DECL
32
33#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_OBJECT_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_pointer.h created+31
......@@ -0,0 +1,31 @@
1//===-- is_pointer type_traits ----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_POINTER_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_POINTER_H
10
11#include "src/__support/CPP/type_traits/false_type.h"
12#include "src/__support/CPP/type_traits/true_type.h"
13#include "src/__support/macros/attributes.h"
14#include "src/__support/macros/config.h"
15
16namespace LIBC_NAMESPACE_DECL {
17namespace cpp {
18
19// is_pointer
20template <typename T> struct is_pointer : cpp::false_type {};
21template <typename T> struct is_pointer<T *> : cpp::true_type {};
22template <typename T> struct is_pointer<T *const> : cpp::true_type {};
23template <typename T> struct is_pointer<T *volatile> : cpp::true_type {};
24template <typename T> struct is_pointer<T *const volatile> : cpp::true_type {};
25template <typename T>
26LIBC_INLINE_VAR constexpr bool is_pointer_v = is_pointer<T>::value;
27
28} // namespace cpp
29} // namespace LIBC_NAMESPACE_DECL
30
31#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_POINTER_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_reference.h created+34
......@@ -0,0 +1,34 @@
1//===-- is_reference type_traits --------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_REFERENCE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_REFERENCE_H
10
11#include "src/__support/CPP/type_traits/bool_constant.h"
12#include "src/__support/CPP/type_traits/false_type.h"
13#include "src/__support/CPP/type_traits/true_type.h"
14#include "src/__support/macros/attributes.h"
15#include "src/__support/macros/config.h"
16
17namespace LIBC_NAMESPACE_DECL {
18namespace cpp {
19
20// is_reference
21#if __has_builtin(__is_reference)
22template <typename T> struct is_reference : bool_constant<__is_reference(T)> {};
23#else
24template <typename T> struct is_reference : public false_type {};
25template <typename T> struct is_reference<T &> : public true_type {};
26template <typename T> struct is_reference<T &&> : public true_type {};
27#endif
28template <class T>
29LIBC_INLINE_VAR constexpr bool is_reference_v = is_reference<T>::value;
30
31} // namespace cpp
32} // namespace LIBC_NAMESPACE_DECL
33
34#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_REFERENCE_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_rvalue_reference.h created+35
......@@ -0,0 +1,35 @@
1//===-- is_rvalue_reference type_traits -------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_RVALUE_REFERENCE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_RVALUE_REFERENCE_H
10
11#include "src/__support/CPP/type_traits/bool_constant.h"
12#include "src/__support/CPP/type_traits/false_type.h"
13#include "src/__support/CPP/type_traits/true_type.h"
14#include "src/__support/macros/attributes.h"
15#include "src/__support/macros/config.h"
16
17namespace LIBC_NAMESPACE_DECL {
18namespace cpp {
19
20// is_rvalue_reference
21#if __has_builtin(__is_rvalue_reference)
22template <typename T>
23struct is_rvalue_reference : bool_constant<__is_rvalue_reference(T)> {};
24#else
25template <typename T> struct is_rvalue_reference : public false_type {};
26template <typename T> struct is_rvalue_reference<T &&> : public true_type {};
27#endif
28template <class T>
29LIBC_INLINE_VAR constexpr bool is_rvalue_reference_v =
30 is_rvalue_reference<T>::value;
31
32} // namespace cpp
33} // namespace LIBC_NAMESPACE_DECL
34
35#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_RVALUE_REFERENCE_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_same.h created+28
......@@ -0,0 +1,28 @@
1//===-- is_same type_traits -------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SAME_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SAME_H
10
11#include "src/__support/CPP/type_traits/false_type.h"
12#include "src/__support/CPP/type_traits/true_type.h"
13#include "src/__support/macros/attributes.h"
14#include "src/__support/macros/config.h"
15
16namespace LIBC_NAMESPACE_DECL {
17namespace cpp {
18
19// is_same
20template <typename T, typename U> struct is_same : cpp::false_type {};
21template <typename T> struct is_same<T, T> : cpp::true_type {};
22template <typename T, typename U>
23LIBC_INLINE_VAR constexpr bool is_same_v = is_same<T, U>::value;
24
25} // namespace cpp
26} // namespace LIBC_NAMESPACE_DECL
27
28#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SAME_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_scalar.h created+35
......@@ -0,0 +1,35 @@
1//===-- is_scalar type_traits -----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SCALAR_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SCALAR_H
10
11#include "src/__support/CPP/type_traits/bool_constant.h"
12#include "src/__support/CPP/type_traits/is_arithmetic.h"
13#include "src/__support/CPP/type_traits/is_enum.h"
14#include "src/__support/CPP/type_traits/is_member_pointer.h"
15#include "src/__support/CPP/type_traits/is_null_pointer.h"
16#include "src/__support/CPP/type_traits/is_pointer.h"
17#include "src/__support/macros/attributes.h"
18#include "src/__support/macros/config.h"
19
20namespace LIBC_NAMESPACE_DECL {
21namespace cpp {
22
23// is_scalar
24template <class T>
25struct is_scalar
26 : cpp::bool_constant<cpp::is_arithmetic_v<T> || cpp::is_enum_v<T> ||
27 cpp::is_pointer_v<T> || cpp::is_member_pointer_v<T> ||
28 cpp::is_null_pointer_v<T>> {};
29template <class T>
30LIBC_INLINE_VAR constexpr bool is_scalar_v = is_scalar<T>::value;
31
32} // namespace cpp
33} // namespace LIBC_NAMESPACE_DECL
34
35#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SCALAR_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_signed.h created+31
......@@ -0,0 +1,31 @@
1//===-- is_signed type_traits -----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H
10
11#include "src/__support/CPP/type_traits/bool_constant.h"
12#include "src/__support/CPP/type_traits/is_arithmetic.h"
13#include "src/__support/macros/attributes.h"
14#include "src/__support/macros/config.h"
15
16namespace LIBC_NAMESPACE_DECL {
17namespace cpp {
18
19// is_signed
20template <typename T>
21struct is_signed : bool_constant<(is_arithmetic_v<T> && (T(-1) < T(0)))> {
22 LIBC_INLINE constexpr operator bool() const { return is_signed::value; }
23 LIBC_INLINE constexpr bool operator()() const { return is_signed::value; }
24};
25template <typename T>
26LIBC_INLINE_VAR constexpr bool is_signed_v = is_signed<T>::value;
27
28} // namespace cpp
29} // namespace LIBC_NAMESPACE_DECL
30
31#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_trivially_constructible.h created+25
......@@ -0,0 +1,25 @@
1//===-- is_trivially_constructible type_traits ------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_CONSTRUCTIBLE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_CONSTRUCTIBLE_H
10
11#include "src/__support/CPP/type_traits/integral_constant.h"
12#include "src/__support/macros/config.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace cpp {
16
17// is_trivially_constructible
18template <class T, class... Args>
19struct is_trivially_constructible
20 : integral_constant<bool, __is_trivially_constructible(T, Args...)> {};
21
22} // namespace cpp
23} // namespace LIBC_NAMESPACE_DECL
24
25#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_CONSTRUCTIBLE_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_trivially_copyable.h created+29
......@@ -0,0 +1,29 @@
1//===-- is_trivially_copyable type_traits -----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_COPYABLE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_COPYABLE_H
10
11#include "src/__support/CPP/type_traits/integral_constant.h"
12#include "src/__support/macros/config.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace cpp {
16
17// is_trivially_copyable
18template <class T>
19struct is_trivially_copyable
20 : public integral_constant<bool, __is_trivially_copyable(T)> {};
21
22template <class T>
23LIBC_INLINE_VAR constexpr bool is_trivially_copyable_v =
24 is_trivially_copyable<T>::value;
25
26} // namespace cpp
27} // namespace LIBC_NAMESPACE_DECL
28
29#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_COPYABLE_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_trivially_destructible.h created+37
......@@ -0,0 +1,37 @@
1//===-- is_trivially_destructible type_traits -------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_DESTRUCTIBLE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_DESTRUCTIBLE_H
10
11#include "src/__support/CPP/type_traits/bool_constant.h"
12#include "src/__support/CPP/type_traits/is_destructible.h"
13#include "src/__support/macros/attributes.h"
14#include "src/__support/macros/config.h"
15
16namespace LIBC_NAMESPACE_DECL {
17namespace cpp {
18
19// is_trivially_destructible
20#if __has_builtin(__is_trivially_destructible)
21template <typename T>
22struct is_trivially_destructible
23 : public bool_constant<__is_trivially_destructible(T)> {};
24#else
25template <typename T>
26struct is_trivially_destructible
27 : public bool_constant<cpp::is_destructible_v<T> &&__has_trivial_destructor(
28 T)> {};
29#endif // __has_builtin(__is_trivially_destructible)
30template <typename T>
31LIBC_INLINE_VAR constexpr bool is_trivially_destructible_v =
32 is_trivially_destructible<T>::value;
33
34} // namespace cpp
35} // namespace LIBC_NAMESPACE_DECL
36
37#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_DESTRUCTIBLE_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_union.h created+26
......@@ -0,0 +1,26 @@
1//===-- is_union type_traits ------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_UNION_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_UNION_H
10
11#include "src/__support/CPP/type_traits/bool_constant.h"
12#include "src/__support/macros/attributes.h"
13#include "src/__support/macros/config.h"
14
15namespace LIBC_NAMESPACE_DECL {
16namespace cpp {
17
18// is_union
19template <class T> struct is_union : bool_constant<__is_union(T)> {};
20template <typename T>
21LIBC_INLINE_VAR constexpr bool is_union_v = is_union<T>::value;
22
23} // namespace cpp
24} // namespace LIBC_NAMESPACE_DECL
25
26#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_UNION_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_unsigned.h created+31
......@@ -0,0 +1,31 @@
1//===-- is_unsigned type_traits ---------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_UNSIGNED_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_UNSIGNED_H
10
11#include "src/__support/CPP/type_traits/bool_constant.h"
12#include "src/__support/CPP/type_traits/is_arithmetic.h"
13#include "src/__support/macros/attributes.h"
14#include "src/__support/macros/config.h"
15
16namespace LIBC_NAMESPACE_DECL {
17namespace cpp {
18
19// is_unsigned
20template <typename T>
21struct is_unsigned : bool_constant<(is_arithmetic_v<T> && (T(-1) > T(0)))> {
22 LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; }
23 LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; }
24};
25template <typename T>
26LIBC_INLINE_VAR constexpr bool is_unsigned_v = is_unsigned<T>::value;
27
28} // namespace cpp
29} // namespace LIBC_NAMESPACE_DECL
30
31#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_UNSIGNED_H
lib/libcxx/libc/src/__support/CPP/type_traits/is_void.h created+27
......@@ -0,0 +1,27 @@
1//===-- is_void type_traits -------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_VOID_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_VOID_H
10
11#include "src/__support/CPP/type_traits/is_same.h"
12#include "src/__support/CPP/type_traits/remove_cv.h"
13#include "src/__support/macros/attributes.h"
14#include "src/__support/macros/config.h"
15
16namespace LIBC_NAMESPACE_DECL {
17namespace cpp {
18
19// is_void
20template <typename T> struct is_void : is_same<void, remove_cv_t<T>> {};
21template <typename T>
22LIBC_INLINE_VAR constexpr bool is_void_v = is_void<T>::value;
23
24} // namespace cpp
25} // namespace LIBC_NAMESPACE_DECL
26
27#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_VOID_H
lib/libcxx/libc/src/__support/CPP/type_traits/make_signed.h created+41
......@@ -0,0 +1,41 @@
1//===-- make_signed type_traits ---------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_MAKE_SIGNED_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_MAKE_SIGNED_H
10
11#include "src/__support/CPP/type_traits/type_identity.h"
12#include "src/__support/macros/config.h"
13#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
14
15namespace LIBC_NAMESPACE_DECL {
16namespace cpp {
17
18// make_signed
19template <typename T> struct make_signed;
20template <> struct make_signed<char> : type_identity<char> {};
21template <> struct make_signed<signed char> : type_identity<char> {};
22template <> struct make_signed<short> : type_identity<short> {};
23template <> struct make_signed<int> : type_identity<int> {};
24template <> struct make_signed<long> : type_identity<long> {};
25template <> struct make_signed<long long> : type_identity<long long> {};
26template <> struct make_signed<unsigned char> : type_identity<char> {};
27template <> struct make_signed<unsigned short> : type_identity<short> {};
28template <> struct make_signed<unsigned int> : type_identity<int> {};
29template <> struct make_signed<unsigned long> : type_identity<long> {};
30template <>
31struct make_signed<unsigned long long> : type_identity<long long> {};
32#ifdef LIBC_TYPES_HAS_INT128
33template <> struct make_signed<__int128_t> : type_identity<__int128_t> {};
34template <> struct make_signed<__uint128_t> : type_identity<__int128_t> {};
35#endif
36template <typename T> using make_signed_t = typename make_signed<T>::type;
37
38} // namespace cpp
39} // namespace LIBC_NAMESPACE_DECL
40
41#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_MAKE_SIGNED_H
lib/libcxx/libc/src/__support/CPP/type_traits/make_unsigned.h created+46
......@@ -0,0 +1,46 @@
1//===-- make_unsigned type_traits -------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_MAKE_UNSIGNED_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_MAKE_UNSIGNED_H
10
11#include "src/__support/CPP/type_traits/type_identity.h"
12#include "src/__support/macros/config.h"
13#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
14
15namespace LIBC_NAMESPACE_DECL {
16namespace cpp {
17
18// make_unsigned
19
20template <typename T> struct make_unsigned;
21template <> struct make_unsigned<char> : type_identity<unsigned char> {};
22template <> struct make_unsigned<signed char> : type_identity<unsigned char> {};
23template <> struct make_unsigned<short> : type_identity<unsigned short> {};
24template <> struct make_unsigned<int> : type_identity<unsigned int> {};
25template <> struct make_unsigned<long> : type_identity<unsigned long> {};
26template <>
27struct make_unsigned<long long> : type_identity<unsigned long long> {};
28template <>
29struct make_unsigned<unsigned char> : type_identity<unsigned char> {};
30template <>
31struct make_unsigned<unsigned short> : type_identity<unsigned short> {};
32template <> struct make_unsigned<unsigned int> : type_identity<unsigned int> {};
33template <>
34struct make_unsigned<unsigned long> : type_identity<unsigned long> {};
35template <>
36struct make_unsigned<unsigned long long> : type_identity<unsigned long long> {};
37#ifdef LIBC_TYPES_HAS_INT128
38template <> struct make_unsigned<__int128_t> : type_identity<__uint128_t> {};
39template <> struct make_unsigned<__uint128_t> : type_identity<__uint128_t> {};
40#endif
41template <typename T> using make_unsigned_t = typename make_unsigned<T>::type;
42
43} // namespace cpp
44} // namespace LIBC_NAMESPACE_DECL
45
46#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_MAKE_UNSIGNED_H
lib/libcxx/libc/src/__support/CPP/type_traits/remove_all_extents.h created+41
......@@ -0,0 +1,41 @@
1//===-- remove_all_extents type_traits --------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_ALL_EXTENTS_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_ALL_EXTENTS_H
10
11#include "src/__support/CPP/type_traits/type_identity.h"
12#include "src/__support/macros/config.h"
13
14#include <stddef.h> // size_t
15
16namespace LIBC_NAMESPACE_DECL {
17namespace cpp {
18
19// remove_all_extents
20#if __has_builtin(__remove_all_extents)
21template <typename T> using remove_all_extents_t = __remove_all_extents(T);
22template <typename T>
23struct remove_all_extents : cpp::type_identity<remove_all_extents_t<T>> {};
24#else
25template <typename T> struct remove_all_extents {
26 using type = T;
27};
28template <typename T> struct remove_all_extents<T[]> {
29 using type = typename remove_all_extents<T>::type;
30};
31template <typename T, size_t _Np> struct remove_all_extents<T[_Np]> {
32 using type = typename remove_all_extents<T>::type;
33};
34template <typename T>
35using remove_all_extents_t = typename remove_all_extents<T>::type;
36#endif
37
38} // namespace cpp
39} // namespace LIBC_NAMESPACE_DECL
40
41#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_ALL_EXTENTS_H
lib/libcxx/libc/src/__support/CPP/type_traits/remove_cv.h created+28
......@@ -0,0 +1,28 @@
1//===-- remove_cv type_traits -----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_CV_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_CV_H
10
11#include "src/__support/CPP/type_traits/type_identity.h"
12#include "src/__support/macros/config.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace cpp {
16
17// remove_cv
18template <class T> struct remove_cv : cpp::type_identity<T> {};
19template <class T> struct remove_cv<const T> : cpp::type_identity<T> {};
20template <class T> struct remove_cv<volatile T> : cpp::type_identity<T> {};
21template <class T>
22struct remove_cv<const volatile T> : cpp::type_identity<T> {};
23template <class T> using remove_cv_t = typename remove_cv<T>::type;
24
25} // namespace cpp
26} // namespace LIBC_NAMESPACE_DECL
27
28#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_CV_H
lib/libcxx/libc/src/__support/CPP/type_traits/remove_cvref.h created+27
......@@ -0,0 +1,27 @@
1//===-- remove_cvref type_traits --------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_CVREF_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_CVREF_H
10
11#include "src/__support/CPP/type_traits/remove_cv.h"
12#include "src/__support/CPP/type_traits/remove_reference.h"
13#include "src/__support/macros/config.h"
14
15namespace LIBC_NAMESPACE_DECL {
16namespace cpp {
17
18// remove_cvref
19template <typename T> struct remove_cvref {
20 using type = remove_cv_t<remove_reference_t<T>>;
21};
22template <typename T> using remove_cvref_t = typename remove_cvref<T>::type;
23
24} // namespace cpp
25} // namespace LIBC_NAMESPACE_DECL
26
27#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_CVREF_H
lib/libcxx/libc/src/__support/CPP/type_traits/remove_extent.h created+28
......@@ -0,0 +1,28 @@
1//===-- remove_extent type_traits -------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_EXTENT_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_EXTENT_H
10
11#include "src/__support/CPP/type_traits/type_identity.h"
12#include "src/__support/macros/config.h"
13#include "stddef.h" // size_t
14
15namespace LIBC_NAMESPACE_DECL {
16namespace cpp {
17
18// remove_extent
19template <class T> struct remove_extent : cpp::type_identity<T> {};
20template <class T> struct remove_extent<T[]> : cpp::type_identity<T> {};
21template <class T, size_t N>
22struct remove_extent<T[N]> : cpp::type_identity<T> {};
23template <class T> using remove_extent_t = typename remove_extent<T>::type;
24
25} // namespace cpp
26} // namespace LIBC_NAMESPACE_DECL
27
28#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_EXTENT_H
lib/libcxx/libc/src/__support/CPP/type_traits/remove_reference.h created+27
......@@ -0,0 +1,27 @@
1//===-- remove_reference type_traits ----------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_REFERENCE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_REFERENCE_H
10
11#include "src/__support/CPP/type_traits/type_identity.h"
12#include "src/__support/macros/config.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace cpp {
16
17// remove_reference
18template <class T> struct remove_reference : cpp::type_identity<T> {};
19template <class T> struct remove_reference<T &> : cpp::type_identity<T> {};
20template <class T> struct remove_reference<T &&> : cpp::type_identity<T> {};
21template <class T>
22using remove_reference_t = typename remove_reference<T>::type;
23
24} // namespace cpp
25} // namespace LIBC_NAMESPACE_DECL
26
27#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_REFERENCE_H
lib/libcxx/libc/src/__support/CPP/type_traits/true_type.h created+23
......@@ -0,0 +1,23 @@
1//===-- true_type type_traits -----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_TRUE_TYPE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_TRUE_TYPE_H
10
11#include "src/__support/CPP/type_traits/bool_constant.h"
12#include "src/__support/macros/config.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace cpp {
16
17// true_type
18using true_type = cpp::bool_constant<true>;
19
20} // namespace cpp
21} // namespace LIBC_NAMESPACE_DECL
22
23#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_TRUE_TYPE_H
lib/libcxx/libc/src/__support/CPP/type_traits/type_identity.h created+24
......@@ -0,0 +1,24 @@
1//===-- type_identity type_traits -------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_TYPE_IDENTITY_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_TYPE_IDENTITY_H
10
11#include "src/__support/macros/config.h"
12
13namespace LIBC_NAMESPACE_DECL {
14namespace cpp {
15
16// type_identity
17template <typename T> struct type_identity {
18 using type = T;
19};
20
21} // namespace cpp
22} // namespace LIBC_NAMESPACE_DECL
23
24#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_TYPE_IDENTITY_H
lib/libcxx/libc/src/__support/CPP/type_traits/void_t.h created+29
......@@ -0,0 +1,29 @@
1//===-- void_t type_traits --------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_VOID_T_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_VOID_T_H
10
11#include "src/__support/CPP/type_traits/type_identity.h"
12#include "src/__support/macros/config.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace cpp {
16
17// void_t
18
19namespace detail {
20template <typename... Ts> struct make_void : cpp::type_identity<void> {};
21} // namespace detail
22
23template <typename... Ts>
24using void_t = typename detail::make_void<Ts...>::type;
25
26} // namespace cpp
27} // namespace LIBC_NAMESPACE_DECL
28
29#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_VOID_T_H
lib/libcxx/libc/src/__support/CPP/utility.h created+18
......@@ -0,0 +1,18 @@
1//===-- Analogous to <utility> ----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_H
10#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_H
11
12#include "src/__support/CPP/utility/declval.h"
13#include "src/__support/CPP/utility/forward.h"
14#include "src/__support/CPP/utility/in_place.h"
15#include "src/__support/CPP/utility/integer_sequence.h"
16#include "src/__support/CPP/utility/move.h"
17
18#endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_H
lib/libcxx/libc/src/__support/CPP/utility/declval.h created+27
......@@ -0,0 +1,27 @@
1//===-- declval utility -----------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_DECLVAL_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_DECLVAL_H
10
11#include "src/__support/CPP/type_traits/add_rvalue_reference.h"
12#include "src/__support/CPP/type_traits/always_false.h"
13#include "src/__support/macros/config.h"
14
15namespace LIBC_NAMESPACE_DECL {
16namespace cpp {
17
18// declval
19template <typename T> cpp::add_rvalue_reference_t<T> declval() {
20 static_assert(cpp::always_false<T>,
21 "declval not allowed in an evaluated context");
22}
23
24} // namespace cpp
25} // namespace LIBC_NAMESPACE_DECL
26
27#endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_DECLVAL_H
lib/libcxx/libc/src/__support/CPP/utility/forward.h created+35
......@@ -0,0 +1,35 @@
1//===-- forward utility -----------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_FORWARD_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_FORWARD_H
10
11#include "src/__support/CPP/type_traits/is_lvalue_reference.h"
12#include "src/__support/CPP/type_traits/remove_reference.h"
13#include "src/__support/macros/attributes.h"
14#include "src/__support/macros/config.h"
15
16namespace LIBC_NAMESPACE_DECL {
17namespace cpp {
18
19// forward
20template <typename T>
21LIBC_INLINE constexpr T &&forward(remove_reference_t<T> &value) {
22 return static_cast<T &&>(value);
23}
24
25template <typename T>
26LIBC_INLINE constexpr T &&forward(remove_reference_t<T> &&value) {
27 static_assert(!is_lvalue_reference_v<T>,
28 "cannot forward an rvalue as an lvalue");
29 return static_cast<T &&>(value);
30}
31
32} // namespace cpp
33} // namespace LIBC_NAMESPACE_DECL
34
35#endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_FORWARD_H
lib/libcxx/libc/src/__support/CPP/utility/in_place.h created+39
......@@ -0,0 +1,39 @@
1//===-- in_place utility ----------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_IN_PLACE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_IN_PLACE_H
10
11#include "src/__support/macros/attributes.h" // LIBC_INLINE, LIBC_INLINE_VAR
12#include "src/__support/macros/config.h"
13
14#include <stddef.h> // size_t
15
16namespace LIBC_NAMESPACE_DECL {
17namespace cpp {
18
19// in_place
20struct in_place_t {
21 LIBC_INLINE explicit in_place_t() = default;
22};
23LIBC_INLINE_VAR constexpr in_place_t in_place{};
24
25template <class T> struct in_place_type_t {
26 LIBC_INLINE explicit in_place_type_t() = default;
27};
28template <class T> LIBC_INLINE_VAR constexpr in_place_type_t<T> in_place_type{};
29
30template <size_t IDX> struct in_place_index_t {
31 LIBC_INLINE explicit in_place_index_t() = default;
32};
33template <size_t IDX>
34LIBC_INLINE_VAR constexpr in_place_index_t<IDX> in_place_index{};
35
36} // namespace cpp
37} // namespace LIBC_NAMESPACE_DECL
38
39#endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_IN_PLACE_H
lib/libcxx/libc/src/__support/CPP/utility/integer_sequence.h created+40
......@@ -0,0 +1,40 @@
1//===-- integer_sequence utility --------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_INTEGER_SEQUENCE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_INTEGER_SEQUENCE_H
10
11#include "src/__support/CPP/type_traits/is_integral.h"
12#include "src/__support/macros/config.h"
13
14namespace LIBC_NAMESPACE_DECL {
15namespace cpp {
16
17// integer_sequence
18template <typename T, T... Ints> struct integer_sequence {
19 static_assert(cpp::is_integral_v<T>);
20 template <T Next> using append = integer_sequence<T, Ints..., Next>;
21};
22
23namespace detail {
24template <typename T, int N> struct make_integer_sequence {
25 using type =
26 typename make_integer_sequence<T, N - 1>::type::template append<N>;
27};
28template <typename T> struct make_integer_sequence<T, -1> {
29 using type = integer_sequence<T>;
30};
31} // namespace detail
32
33template <typename T, int N>
34using make_integer_sequence =
35 typename detail::make_integer_sequence<T, N - 1>::type;
36
37} // namespace cpp
38} // namespace LIBC_NAMESPACE_DECL
39
40#endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_INTEGER_SEQUENCE_H
lib/libcxx/libc/src/__support/CPP/utility/move.h created+27
......@@ -0,0 +1,27 @@
1//===-- move utility --------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_MOVE_H
9#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_MOVE_H
10
11#include "src/__support/CPP/type_traits/remove_reference.h"
12#include "src/__support/macros/attributes.h" // LIBC_INLINE
13#include "src/__support/macros/config.h"
14
15namespace LIBC_NAMESPACE_DECL {
16namespace cpp {
17
18// move
19template <class T>
20LIBC_INLINE constexpr cpp::remove_reference_t<T> &&move(T &&t) {
21 return static_cast<typename cpp::remove_reference_t<T> &&>(t);
22}
23
24} // namespace cpp
25} // namespace LIBC_NAMESPACE_DECL
26
27#endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_MOVE_H
lib/libcxx/libc/src/__support/FPUtil/FPBits.h created+846
......@@ -0,0 +1,846 @@
1//===-- Abstract class for bit manipulation of float numbers. ---*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// -----------------------------------------------------------------------------
10// **** WARNING ****
11// This file is shared with libc++. You should also be careful when adding
12// dependencies to this file, since it needs to build for all libc++ targets.
13// -----------------------------------------------------------------------------
14
15#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FPBITS_H
16#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FPBITS_H
17
18#include "src/__support/CPP/bit.h"
19#include "src/__support/CPP/type_traits.h"
20#include "src/__support/common.h"
21#include "src/__support/libc_assert.h" // LIBC_ASSERT
22#include "src/__support/macros/attributes.h" // LIBC_INLINE, LIBC_INLINE_VAR
23#include "src/__support/macros/config.h"
24#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_FLOAT128
25#include "src/__support/math_extras.h" // mask_trailing_ones
26#include "src/__support/sign.h" // Sign
27#include "src/__support/uint128.h"
28
29#include <stdint.h>
30
31namespace LIBC_NAMESPACE_DECL {
32namespace fputil {
33
34// The supported floating point types.
35enum class FPType {
36 IEEE754_Binary16,
37 IEEE754_Binary32,
38 IEEE754_Binary64,
39 IEEE754_Binary128,
40 X86_Binary80,
41};
42
43// The classes hierarchy is as follows:
44//
45// ┌───────────────────┐
46// │ FPLayout<FPType> │
47// └─────────â–²─────────┘
48// │
49// ┌─────────┴─────────┐
50// │ FPStorage<FPType> │
51// └─────────â–²─────────┘
52// │
53// ┌────────────┴─────────────┐
54// │ │
55// ┌────────┴─────────┐ ┌──────────────┴──────────────────┐
56// │ FPRepSem<FPType> │ │ FPRepSem<FPType::X86_Binary80 │
57// └────────â–²─────────┘ └──────────────â–²──────────────────┘
58// │ │
59// └────────────┬─────────────┘
60// │
61// ┌───────┴───────┐
62// │ FPRepImpl<T> │
63// └───────â–²───────┘
64// │
65// ┌────────┴────────┐
66// ┌─────┴─────┐ ┌─────┴─────┐
67// │ FPRep<T> │ │ FPBits<T> │
68// └───────────┘ └───────────┘
69//
70// - 'FPLayout' defines only a few constants, namely the 'StorageType' and
71// length of the sign, the exponent, fraction and significand parts.
72// - 'FPStorage' builds more constants on top of those from 'FPLayout' like
73// exponent bias and masks. It also holds the bit representation of the
74// floating point as a 'StorageType' type and defines tools to assemble or
75// test these parts.
76// - 'FPRepSem' defines functions to interact semantically with the floating
77// point representation. The default implementation is the one for 'IEEE754',
78// a specialization is provided for X86 Extended Precision.
79// - 'FPRepImpl' derives from 'FPRepSem' and adds functions that are common to
80// all implementations or build on the ones in 'FPRepSem'.
81// - 'FPRep' exposes all functions from 'FPRepImpl' and returns 'FPRep'
82// instances when using Builders (static functions to create values).
83// - 'FPBits' exposes all the functions from 'FPRepImpl' but operates on the
84// native C++ floating point type instead of 'FPType'. An additional 'get_val'
85// function allows getting the C++ floating point type value back. Builders
86// called from 'FPBits' return 'FPBits' instances.
87
88namespace internal {
89
90// Defines the layout (sign, exponent, significand) of a floating point type in
91// memory. It also defines its associated StorageType, i.e., the unsigned
92// integer type used to manipulate its representation.
93// Additionally we provide the fractional part length, i.e., the number of bits
94// after the decimal dot when the number is in normal form.
95template <FPType> struct FPLayout {};
96
97template <> struct FPLayout<FPType::IEEE754_Binary16> {
98 using StorageType = uint16_t;
99 LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
100 LIBC_INLINE_VAR static constexpr int EXP_LEN = 5;
101 LIBC_INLINE_VAR static constexpr int SIG_LEN = 10;
102 LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SIG_LEN;
103};
104
105template <> struct FPLayout<FPType::IEEE754_Binary32> {
106 using StorageType = uint32_t;
107 LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
108 LIBC_INLINE_VAR static constexpr int EXP_LEN = 8;
109 LIBC_INLINE_VAR static constexpr int SIG_LEN = 23;
110 LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SIG_LEN;
111};
112
113template <> struct FPLayout<FPType::IEEE754_Binary64> {
114 using StorageType = uint64_t;
115 LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
116 LIBC_INLINE_VAR static constexpr int EXP_LEN = 11;
117 LIBC_INLINE_VAR static constexpr int SIG_LEN = 52;
118 LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SIG_LEN;
119};
120
121template <> struct FPLayout<FPType::IEEE754_Binary128> {
122 using StorageType = UInt128;
123 LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
124 LIBC_INLINE_VAR static constexpr int EXP_LEN = 15;
125 LIBC_INLINE_VAR static constexpr int SIG_LEN = 112;
126 LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SIG_LEN;
127};
128
129template <> struct FPLayout<FPType::X86_Binary80> {
130#if __SIZEOF_LONG_DOUBLE__ == 12
131 using StorageType = UInt<__SIZEOF_LONG_DOUBLE__ * CHAR_BIT>;
132#else
133 using StorageType = UInt128;
134#endif
135 LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
136 LIBC_INLINE_VAR static constexpr int EXP_LEN = 15;
137 LIBC_INLINE_VAR static constexpr int SIG_LEN = 64;
138 LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SIG_LEN - 1;
139};
140
141// FPStorage derives useful constants from the FPLayout above.
142template <FPType fp_type> struct FPStorage : public FPLayout<fp_type> {
143 using UP = FPLayout<fp_type>;
144
145 using UP::EXP_LEN; // The number of bits for the *exponent* part
146 using UP::SIG_LEN; // The number of bits for the *significand* part
147 using UP::SIGN_LEN; // The number of bits for the *sign* part
148 // For convenience, the sum of `SIG_LEN`, `EXP_LEN`, and `SIGN_LEN`.
149 LIBC_INLINE_VAR static constexpr int TOTAL_LEN = SIGN_LEN + EXP_LEN + SIG_LEN;
150
151 // The number of bits after the decimal dot when the number is in normal form.
152 using UP::FRACTION_LEN;
153
154 // An unsigned integer that is wide enough to contain all of the floating
155 // point bits.
156 using StorageType = typename UP::StorageType;
157
158 // The number of bits in StorageType.
159 LIBC_INLINE_VAR static constexpr int STORAGE_LEN =
160 sizeof(StorageType) * CHAR_BIT;
161 static_assert(STORAGE_LEN >= TOTAL_LEN);
162
163 // The exponent bias. Always positive.
164 LIBC_INLINE_VAR static constexpr int32_t EXP_BIAS =
165 (1U << (EXP_LEN - 1U)) - 1U;
166 static_assert(EXP_BIAS > 0);
167
168 // The bit pattern that keeps only the *significand* part.
169 LIBC_INLINE_VAR static constexpr StorageType SIG_MASK =
170 mask_trailing_ones<StorageType, SIG_LEN>();
171 // The bit pattern that keeps only the *exponent* part.
172 LIBC_INLINE_VAR static constexpr StorageType EXP_MASK =
173 mask_trailing_ones<StorageType, EXP_LEN>() << SIG_LEN;
174 // The bit pattern that keeps only the *sign* part.
175 LIBC_INLINE_VAR static constexpr StorageType SIGN_MASK =
176 mask_trailing_ones<StorageType, SIGN_LEN>() << (EXP_LEN + SIG_LEN);
177 // The bit pattern that keeps only the *exponent + significand* part.
178 LIBC_INLINE_VAR static constexpr StorageType EXP_SIG_MASK =
179 mask_trailing_ones<StorageType, EXP_LEN + SIG_LEN>();
180 // The bit pattern that keeps only the *sign + exponent + significand* part.
181 LIBC_INLINE_VAR static constexpr StorageType FP_MASK =
182 mask_trailing_ones<StorageType, TOTAL_LEN>();
183 // The bit pattern that keeps only the *fraction* part.
184 // i.e., the *significand* without the leading one.
185 LIBC_INLINE_VAR static constexpr StorageType FRACTION_MASK =
186 mask_trailing_ones<StorageType, FRACTION_LEN>();
187
188 static_assert((SIG_MASK & EXP_MASK & SIGN_MASK) == 0, "masks disjoint");
189 static_assert((SIG_MASK | EXP_MASK | SIGN_MASK) == FP_MASK, "masks cover");
190
191protected:
192 // Merge bits from 'a' and 'b' values according to 'mask'.
193 // Use 'a' bits when corresponding 'mask' bits are zeroes and 'b' bits when
194 // corresponding bits are ones.
195 LIBC_INLINE static constexpr StorageType merge(StorageType a, StorageType b,
196 StorageType mask) {
197 // https://graphics.stanford.edu/~seander/bithacks.html#MaskedMerge
198 return a ^ ((a ^ b) & mask);
199 }
200
201 // A stongly typed integer that prevents mixing and matching integers with
202 // different semantics.
203 template <typename T> struct TypedInt {
204 using value_type = T;
205 LIBC_INLINE constexpr explicit TypedInt(T value) : value(value) {}
206 LIBC_INLINE constexpr TypedInt(const TypedInt &value) = default;
207 LIBC_INLINE constexpr TypedInt &operator=(const TypedInt &value) = default;
208
209 LIBC_INLINE constexpr explicit operator T() const { return value; }
210
211 LIBC_INLINE constexpr StorageType to_storage_type() const {
212 return StorageType(value);
213 }
214
215 LIBC_INLINE friend constexpr bool operator==(TypedInt a, TypedInt b) {
216 return a.value == b.value;
217 }
218 LIBC_INLINE friend constexpr bool operator!=(TypedInt a, TypedInt b) {
219 return a.value != b.value;
220 }
221
222 protected:
223 T value;
224 };
225
226 // An opaque type to store a floating point exponent.
227 // We define special values but it is valid to create arbitrary values as long
228 // as they are in the range [min, max].
229 struct Exponent : public TypedInt<int32_t> {
230 using UP = TypedInt<int32_t>;
231 using UP::UP;
232 LIBC_INLINE static constexpr auto subnormal() {
233 return Exponent(-EXP_BIAS);
234 }
235 LIBC_INLINE static constexpr auto min() { return Exponent(1 - EXP_BIAS); }
236 LIBC_INLINE static constexpr auto zero() { return Exponent(0); }
237 LIBC_INLINE static constexpr auto max() { return Exponent(EXP_BIAS); }
238 LIBC_INLINE static constexpr auto inf() { return Exponent(EXP_BIAS + 1); }
239 };
240
241 // An opaque type to store a floating point biased exponent.
242 // We define special values but it is valid to create arbitrary values as long
243 // as they are in the range [zero, bits_all_ones].
244 // Values greater than bits_all_ones are truncated.
245 struct BiasedExponent : public TypedInt<uint32_t> {
246 using UP = TypedInt<uint32_t>;
247 using UP::UP;
248
249 LIBC_INLINE constexpr BiasedExponent(Exponent exp)
250 : UP(static_cast<int32_t>(exp) + EXP_BIAS) {}
251
252 // Cast operator to get convert from BiasedExponent to Exponent.
253 LIBC_INLINE constexpr operator Exponent() const {
254 return Exponent(UP::value - EXP_BIAS);
255 }
256
257 LIBC_INLINE constexpr BiasedExponent &operator++() {
258 LIBC_ASSERT(*this != BiasedExponent(Exponent::inf()));
259 ++UP::value;
260 return *this;
261 }
262
263 LIBC_INLINE constexpr BiasedExponent &operator--() {
264 LIBC_ASSERT(*this != BiasedExponent(Exponent::subnormal()));
265 --UP::value;
266 return *this;
267 }
268 };
269
270 // An opaque type to store a floating point significand.
271 // We define special values but it is valid to create arbitrary values as long
272 // as they are in the range [zero, bits_all_ones].
273 // Note that the semantics of the Significand are implementation dependent.
274 // Values greater than bits_all_ones are truncated.
275 struct Significand : public TypedInt<StorageType> {
276 using UP = TypedInt<StorageType>;
277 using UP::UP;
278
279 LIBC_INLINE friend constexpr Significand operator|(const Significand a,
280 const Significand b) {
281 return Significand(
282 StorageType(a.to_storage_type() | b.to_storage_type()));
283 }
284 LIBC_INLINE friend constexpr Significand operator^(const Significand a,
285 const Significand b) {
286 return Significand(
287 StorageType(a.to_storage_type() ^ b.to_storage_type()));
288 }
289 LIBC_INLINE friend constexpr Significand operator>>(const Significand a,
290 int shift) {
291 return Significand(StorageType(a.to_storage_type() >> shift));
292 }
293
294 LIBC_INLINE static constexpr auto zero() {
295 return Significand(StorageType(0));
296 }
297 LIBC_INLINE static constexpr auto lsb() {
298 return Significand(StorageType(1));
299 }
300 LIBC_INLINE static constexpr auto msb() {
301 return Significand(StorageType(1) << (SIG_LEN - 1));
302 }
303 LIBC_INLINE static constexpr auto bits_all_ones() {
304 return Significand(SIG_MASK);
305 }
306 };
307
308 LIBC_INLINE static constexpr StorageType encode(BiasedExponent exp) {
309 return (exp.to_storage_type() << SIG_LEN) & EXP_MASK;
310 }
311
312 LIBC_INLINE static constexpr StorageType encode(Significand value) {
313 return value.to_storage_type() & SIG_MASK;
314 }
315
316 LIBC_INLINE static constexpr StorageType encode(BiasedExponent exp,
317 Significand sig) {
318 return encode(exp) | encode(sig);
319 }
320
321 LIBC_INLINE static constexpr StorageType encode(Sign sign, BiasedExponent exp,
322 Significand sig) {
323 if (sign.is_neg())
324 return SIGN_MASK | encode(exp, sig);
325 return encode(exp, sig);
326 }
327
328 // The floating point number representation as an unsigned integer.
329 StorageType bits{};
330
331 LIBC_INLINE constexpr FPStorage() : bits(0) {}
332 LIBC_INLINE constexpr FPStorage(StorageType value) : bits(value) {}
333
334 // Observers
335 LIBC_INLINE constexpr StorageType exp_bits() const { return bits & EXP_MASK; }
336 LIBC_INLINE constexpr StorageType sig_bits() const { return bits & SIG_MASK; }
337 LIBC_INLINE constexpr StorageType exp_sig_bits() const {
338 return bits & EXP_SIG_MASK;
339 }
340
341 // Parts
342 LIBC_INLINE constexpr BiasedExponent biased_exponent() const {
343 return BiasedExponent(static_cast<uint32_t>(exp_bits() >> SIG_LEN));
344 }
345 LIBC_INLINE constexpr void set_biased_exponent(BiasedExponent biased) {
346 bits = merge(bits, encode(biased), EXP_MASK);
347 }
348
349public:
350 LIBC_INLINE constexpr Sign sign() const {
351 return (bits & SIGN_MASK) ? Sign::NEG : Sign::POS;
352 }
353 LIBC_INLINE constexpr void set_sign(Sign signVal) {
354 if (sign() != signVal)
355 bits ^= SIGN_MASK;
356 }
357};
358
359// This layer defines all functions that are specific to how the the floating
360// point type is encoded. It enables constructions, modification and observation
361// of values manipulated as 'StorageType'.
362template <FPType fp_type, typename RetT>
363struct FPRepSem : public FPStorage<fp_type> {
364 using UP = FPStorage<fp_type>;
365 using typename UP::StorageType;
366 using UP::FRACTION_LEN;
367 using UP::FRACTION_MASK;
368
369protected:
370 using typename UP::Exponent;
371 using typename UP::Significand;
372 using UP::bits;
373 using UP::encode;
374 using UP::exp_bits;
375 using UP::exp_sig_bits;
376 using UP::sig_bits;
377 using UP::UP;
378
379public:
380 // Builders
381 LIBC_INLINE static constexpr RetT zero(Sign sign = Sign::POS) {
382 return RetT(encode(sign, Exponent::subnormal(), Significand::zero()));
383 }
384 LIBC_INLINE static constexpr RetT one(Sign sign = Sign::POS) {
385 return RetT(encode(sign, Exponent::zero(), Significand::zero()));
386 }
387 LIBC_INLINE static constexpr RetT min_subnormal(Sign sign = Sign::POS) {
388 return RetT(encode(sign, Exponent::subnormal(), Significand::lsb()));
389 }
390 LIBC_INLINE static constexpr RetT max_subnormal(Sign sign = Sign::POS) {
391 return RetT(
392 encode(sign, Exponent::subnormal(), Significand::bits_all_ones()));
393 }
394 LIBC_INLINE static constexpr RetT min_normal(Sign sign = Sign::POS) {
395 return RetT(encode(sign, Exponent::min(), Significand::zero()));
396 }
397 LIBC_INLINE static constexpr RetT max_normal(Sign sign = Sign::POS) {
398 return RetT(encode(sign, Exponent::max(), Significand::bits_all_ones()));
399 }
400 LIBC_INLINE static constexpr RetT inf(Sign sign = Sign::POS) {
401 return RetT(encode(sign, Exponent::inf(), Significand::zero()));
402 }
403 LIBC_INLINE static constexpr RetT signaling_nan(Sign sign = Sign::POS,
404 StorageType v = 0) {
405 return RetT(encode(sign, Exponent::inf(),
406 (v ? Significand(v) : (Significand::msb() >> 1))));
407 }
408 LIBC_INLINE static constexpr RetT quiet_nan(Sign sign = Sign::POS,
409 StorageType v = 0) {
410 return RetT(
411 encode(sign, Exponent::inf(), Significand::msb() | Significand(v)));
412 }
413
414 // Observers
415 LIBC_INLINE constexpr bool is_zero() const { return exp_sig_bits() == 0; }
416 LIBC_INLINE constexpr bool is_nan() const {
417 return exp_sig_bits() > encode(Exponent::inf(), Significand::zero());
418 }
419 LIBC_INLINE constexpr bool is_quiet_nan() const {
420 return exp_sig_bits() >= encode(Exponent::inf(), Significand::msb());
421 }
422 LIBC_INLINE constexpr bool is_signaling_nan() const {
423 return is_nan() && !is_quiet_nan();
424 }
425 LIBC_INLINE constexpr bool is_inf() const {
426 return exp_sig_bits() == encode(Exponent::inf(), Significand::zero());
427 }
428 LIBC_INLINE constexpr bool is_finite() const {
429 return exp_bits() != encode(Exponent::inf());
430 }
431 LIBC_INLINE
432 constexpr bool is_subnormal() const {
433 return exp_bits() == encode(Exponent::subnormal());
434 }
435 LIBC_INLINE constexpr bool is_normal() const {
436 return is_finite() && !is_subnormal();
437 }
438 LIBC_INLINE constexpr RetT next_toward_inf() const {
439 if (is_finite())
440 return RetT(bits + StorageType(1));
441 return RetT(bits);
442 }
443
444 // Returns the mantissa with the implicit bit set iff the current
445 // value is a valid normal number.
446 LIBC_INLINE constexpr StorageType get_explicit_mantissa() const {
447 if (is_subnormal())
448 return sig_bits();
449 return (StorageType(1) << UP::SIG_LEN) | sig_bits();
450 }
451};
452
453// Specialization for the X86 Extended Precision type.
454template <typename RetT>
455struct FPRepSem<FPType::X86_Binary80, RetT>
456 : public FPStorage<FPType::X86_Binary80> {
457 using UP = FPStorage<FPType::X86_Binary80>;
458 using typename UP::StorageType;
459 using UP::FRACTION_LEN;
460 using UP::FRACTION_MASK;
461
462 // The x86 80 bit float represents the leading digit of the mantissa
463 // explicitly. This is the mask for that bit.
464 static constexpr StorageType EXPLICIT_BIT_MASK = StorageType(1)
465 << FRACTION_LEN;
466 // The X80 significand is made of an explicit bit and the fractional part.
467 static_assert((EXPLICIT_BIT_MASK & FRACTION_MASK) == 0,
468 "the explicit bit and the fractional part should not overlap");
469 static_assert((EXPLICIT_BIT_MASK | FRACTION_MASK) == SIG_MASK,
470 "the explicit bit and the fractional part should cover the "
471 "whole significand");
472
473protected:
474 using typename UP::Exponent;
475 using typename UP::Significand;
476 using UP::encode;
477 using UP::UP;
478
479public:
480 // Builders
481 LIBC_INLINE static constexpr RetT zero(Sign sign = Sign::POS) {
482 return RetT(encode(sign, Exponent::subnormal(), Significand::zero()));
483 }
484 LIBC_INLINE static constexpr RetT one(Sign sign = Sign::POS) {
485 return RetT(encode(sign, Exponent::zero(), Significand::msb()));
486 }
487 LIBC_INLINE static constexpr RetT min_subnormal(Sign sign = Sign::POS) {
488 return RetT(encode(sign, Exponent::subnormal(), Significand::lsb()));
489 }
490 LIBC_INLINE static constexpr RetT max_subnormal(Sign sign = Sign::POS) {
491 return RetT(encode(sign, Exponent::subnormal(),
492 Significand::bits_all_ones() ^ Significand::msb()));
493 }
494 LIBC_INLINE static constexpr RetT min_normal(Sign sign = Sign::POS) {
495 return RetT(encode(sign, Exponent::min(), Significand::msb()));
496 }
497 LIBC_INLINE static constexpr RetT max_normal(Sign sign = Sign::POS) {
498 return RetT(encode(sign, Exponent::max(), Significand::bits_all_ones()));
499 }
500 LIBC_INLINE static constexpr RetT inf(Sign sign = Sign::POS) {
501 return RetT(encode(sign, Exponent::inf(), Significand::msb()));
502 }
503 LIBC_INLINE static constexpr RetT signaling_nan(Sign sign = Sign::POS,
504 StorageType v = 0) {
505 return RetT(encode(sign, Exponent::inf(),
506 Significand::msb() |
507 (v ? Significand(v) : (Significand::msb() >> 2))));
508 }
509 LIBC_INLINE static constexpr RetT quiet_nan(Sign sign = Sign::POS,
510 StorageType v = 0) {
511 return RetT(encode(sign, Exponent::inf(),
512 Significand::msb() | (Significand::msb() >> 1) |
513 Significand(v)));
514 }
515
516 // Observers
517 LIBC_INLINE constexpr bool is_zero() const { return exp_sig_bits() == 0; }
518 LIBC_INLINE constexpr bool is_nan() const {
519 // Most encoding forms from the table found in
520 // https://en.wikipedia.org/wiki/Extended_precision#x86_extended_precision_format
521 // are interpreted as NaN.
522 // More precisely :
523 // - Pseudo-Infinity
524 // - Pseudo Not a Number
525 // - Signalling Not a Number
526 // - Floating-point Indefinite
527 // - Quiet Not a Number
528 // - Unnormal
529 // This can be reduced to the following logic:
530 if (exp_bits() == encode(Exponent::inf()))
531 return !is_inf();
532 if (exp_bits() != encode(Exponent::subnormal()))
533 return (sig_bits() & encode(Significand::msb())) == 0;
534 return false;
535 }
536 LIBC_INLINE constexpr bool is_quiet_nan() const {
537 return exp_sig_bits() >=
538 encode(Exponent::inf(),
539 Significand::msb() | (Significand::msb() >> 1));
540 }
541 LIBC_INLINE constexpr bool is_signaling_nan() const {
542 return is_nan() && !is_quiet_nan();
543 }
544 LIBC_INLINE constexpr bool is_inf() const {
545 return exp_sig_bits() == encode(Exponent::inf(), Significand::msb());
546 }
547 LIBC_INLINE constexpr bool is_finite() const {
548 return !is_inf() && !is_nan();
549 }
550 LIBC_INLINE
551 constexpr bool is_subnormal() const {
552 return exp_bits() == encode(Exponent::subnormal());
553 }
554 LIBC_INLINE constexpr bool is_normal() const {
555 const auto exp = exp_bits();
556 if (exp == encode(Exponent::subnormal()) || exp == encode(Exponent::inf()))
557 return false;
558 return get_implicit_bit();
559 }
560 LIBC_INLINE constexpr RetT next_toward_inf() const {
561 if (is_finite()) {
562 if (exp_sig_bits() == max_normal().uintval()) {
563 return inf(sign());
564 } else if (exp_sig_bits() == max_subnormal().uintval()) {
565 return min_normal(sign());
566 } else if (sig_bits() == SIG_MASK) {
567 return RetT(encode(sign(), ++biased_exponent(), Significand::zero()));
568 } else {
569 return RetT(bits + StorageType(1));
570 }
571 }
572 return RetT(bits);
573 }
574
575 LIBC_INLINE constexpr StorageType get_explicit_mantissa() const {
576 return sig_bits();
577 }
578
579 // This functions is specific to FPRepSem<FPType::X86_Binary80>.
580 // TODO: Remove if possible.
581 LIBC_INLINE constexpr bool get_implicit_bit() const {
582 return static_cast<bool>(bits & EXPLICIT_BIT_MASK);
583 }
584
585 // This functions is specific to FPRepSem<FPType::X86_Binary80>.
586 // TODO: Remove if possible.
587 LIBC_INLINE constexpr void set_implicit_bit(bool implicitVal) {
588 if (get_implicit_bit() != implicitVal)
589 bits ^= EXPLICIT_BIT_MASK;
590 }
591};
592
593// 'FPRepImpl' is the bottom of the class hierarchy that only deals with
594// 'FPType'. The operations dealing with specific float semantics are
595// implemented by 'FPRepSem' above and specialized when needed.
596//
597// The 'RetT' type is being propagated up to 'FPRepSem' so that the functions
598// creating new values (Builders) can return the appropriate type. That is, when
599// creating a value through 'FPBits' below the builder will return an 'FPBits'
600// value.
601// FPBits<float>::zero(); // returns an FPBits<>
602//
603// When we don't care about specific C++ floating point type we can use
604// 'FPRep' and specify the 'FPType' directly.
605// FPRep<FPType::IEEE754_Binary32:>::zero() // returns an FPRep<>
606template <FPType fp_type, typename RetT>
607struct FPRepImpl : public FPRepSem<fp_type, RetT> {
608 using UP = FPRepSem<fp_type, RetT>;
609 using StorageType = typename UP::StorageType;
610
611protected:
612 using UP::bits;
613 using UP::encode;
614 using UP::exp_bits;
615 using UP::exp_sig_bits;
616
617 using typename UP::BiasedExponent;
618 using typename UP::Exponent;
619 using typename UP::Significand;
620
621 using UP::FP_MASK;
622
623public:
624 // Constants.
625 using UP::EXP_BIAS;
626 using UP::EXP_MASK;
627 using UP::FRACTION_MASK;
628 using UP::SIG_LEN;
629 using UP::SIG_MASK;
630 using UP::SIGN_MASK;
631 LIBC_INLINE_VAR static constexpr int MAX_BIASED_EXPONENT =
632 (1 << UP::EXP_LEN) - 1;
633
634 // CTors
635 LIBC_INLINE constexpr FPRepImpl() = default;
636 LIBC_INLINE constexpr explicit FPRepImpl(StorageType x) : UP(x) {}
637
638 // Comparison
639 LIBC_INLINE constexpr friend bool operator==(FPRepImpl a, FPRepImpl b) {
640 return a.uintval() == b.uintval();
641 }
642 LIBC_INLINE constexpr friend bool operator!=(FPRepImpl a, FPRepImpl b) {
643 return a.uintval() != b.uintval();
644 }
645
646 // Representation
647 LIBC_INLINE constexpr StorageType uintval() const { return bits & FP_MASK; }
648 LIBC_INLINE constexpr void set_uintval(StorageType value) {
649 bits = (value & FP_MASK);
650 }
651
652 // Builders
653 using UP::inf;
654 using UP::max_normal;
655 using UP::max_subnormal;
656 using UP::min_normal;
657 using UP::min_subnormal;
658 using UP::one;
659 using UP::quiet_nan;
660 using UP::signaling_nan;
661 using UP::zero;
662
663 // Modifiers
664 LIBC_INLINE constexpr RetT abs() const {
665 return RetT(static_cast<StorageType>(bits & UP::EXP_SIG_MASK));
666 }
667
668 // Observers
669 using UP::get_explicit_mantissa;
670 using UP::is_finite;
671 using UP::is_inf;
672 using UP::is_nan;
673 using UP::is_normal;
674 using UP::is_quiet_nan;
675 using UP::is_signaling_nan;
676 using UP::is_subnormal;
677 using UP::is_zero;
678 using UP::next_toward_inf;
679 using UP::sign;
680 LIBC_INLINE constexpr bool is_inf_or_nan() const { return !is_finite(); }
681 LIBC_INLINE constexpr bool is_neg() const { return sign().is_neg(); }
682 LIBC_INLINE constexpr bool is_pos() const { return sign().is_pos(); }
683
684 LIBC_INLINE constexpr uint16_t get_biased_exponent() const {
685 return static_cast<uint16_t>(static_cast<uint32_t>(UP::biased_exponent()));
686 }
687
688 LIBC_INLINE constexpr void set_biased_exponent(StorageType biased) {
689 UP::set_biased_exponent(BiasedExponent((int32_t)biased));
690 }
691
692 LIBC_INLINE constexpr int get_exponent() const {
693 return static_cast<int32_t>(Exponent(UP::biased_exponent()));
694 }
695
696 // If the number is subnormal, the exponent is treated as if it were the
697 // minimum exponent for a normal number. This is to keep continuity between
698 // the normal and subnormal ranges, but it causes problems for functions where
699 // values are calculated from the exponent, since just subtracting the bias
700 // will give a slightly incorrect result. Additionally, zero has an exponent
701 // of zero, and that should actually be treated as zero.
702 LIBC_INLINE constexpr int get_explicit_exponent() const {
703 Exponent exponent(UP::biased_exponent());
704 if (is_zero())
705 exponent = Exponent::zero();
706 if (exponent == Exponent::subnormal())
707 exponent = Exponent::min();
708 return static_cast<int32_t>(exponent);
709 }
710
711 LIBC_INLINE constexpr StorageType get_mantissa() const {
712 return bits & FRACTION_MASK;
713 }
714
715 LIBC_INLINE constexpr void set_mantissa(StorageType mantVal) {
716 bits = UP::merge(bits, mantVal, FRACTION_MASK);
717 }
718
719 LIBC_INLINE constexpr void set_significand(StorageType sigVal) {
720 bits = UP::merge(bits, sigVal, SIG_MASK);
721 }
722 // Unsafe function to create a floating point representation.
723 // It simply packs the sign, biased exponent and mantissa values without
724 // checking bound nor normalization.
725 //
726 // WARNING: For X86 Extended Precision, implicit bit needs to be set correctly
727 // in the 'mantissa' by the caller. This function will not check for its
728 // validity.
729 //
730 // FIXME: Use an uint32_t for 'biased_exp'.
731 LIBC_INLINE static constexpr RetT
732 create_value(Sign sign, StorageType biased_exp, StorageType mantissa) {
733 return RetT(encode(sign, BiasedExponent(static_cast<uint32_t>(biased_exp)),
734 Significand(mantissa)));
735 }
736
737 // The function converts integer number and unbiased exponent to proper
738 // float T type:
739 // Result = number * 2^(ep+1 - exponent_bias)
740 // Be careful!
741 // 1) "ep" is the raw exponent value.
742 // 2) The function adds +1 to ep for seamless normalized to denormalized
743 // transition.
744 // 3) The function does not check exponent high limit.
745 // 4) "number" zero value is not processed correctly.
746 // 5) Number is unsigned, so the result can be only positive.
747 LIBC_INLINE static constexpr RetT make_value(StorageType number, int ep) {
748 FPRepImpl result(0);
749 int lz =
750 UP::FRACTION_LEN + 1 - (UP::STORAGE_LEN - cpp::countl_zero(number));
751
752 number <<= lz;
753 ep -= lz;
754
755 if (LIBC_LIKELY(ep >= 0)) {
756 // Implicit number bit will be removed by mask
757 result.set_significand(number);
758 result.set_biased_exponent(static_cast<StorageType>(ep + 1));
759 } else {
760 result.set_significand(number >> -ep);
761 }
762 return RetT(result.uintval());
763 }
764};
765
766// A generic class to manipulate floating point formats.
767// It derives its functionality to FPRepImpl above.
768template <FPType fp_type>
769struct FPRep : public FPRepImpl<fp_type, FPRep<fp_type>> {
770 using UP = FPRepImpl<fp_type, FPRep<fp_type>>;
771 using StorageType = typename UP::StorageType;
772 using UP::UP;
773
774 LIBC_INLINE constexpr explicit operator StorageType() const {
775 return UP::uintval();
776 }
777};
778
779} // namespace internal
780
781// Returns the FPType corresponding to C++ type T on the host.
782template <typename T> LIBC_INLINE static constexpr FPType get_fp_type() {
783 using UnqualT = cpp::remove_cv_t<T>;
784 if constexpr (cpp::is_same_v<UnqualT, float> && __FLT_MANT_DIG__ == 24)
785 return FPType::IEEE754_Binary32;
786 else if constexpr (cpp::is_same_v<UnqualT, double> && __DBL_MANT_DIG__ == 53)
787 return FPType::IEEE754_Binary64;
788 else if constexpr (cpp::is_same_v<UnqualT, long double>) {
789 if constexpr (__LDBL_MANT_DIG__ == 53)
790 return FPType::IEEE754_Binary64;
791 else if constexpr (__LDBL_MANT_DIG__ == 64)
792 return FPType::X86_Binary80;
793 else if constexpr (__LDBL_MANT_DIG__ == 113)
794 return FPType::IEEE754_Binary128;
795 }
796#if defined(LIBC_TYPES_HAS_FLOAT16)
797 else if constexpr (cpp::is_same_v<UnqualT, float16>)
798 return FPType::IEEE754_Binary16;
799#endif
800#if defined(LIBC_TYPES_HAS_FLOAT128)
801 else if constexpr (cpp::is_same_v<UnqualT, float128>)
802 return FPType::IEEE754_Binary128;
803#endif
804 else
805 static_assert(cpp::always_false<UnqualT>, "Unsupported type");
806}
807
808// -----------------------------------------------------------------------------
809// **** WARNING ****
810// This interface is shared with libc++, if you change this interface you need
811// to update it in both libc and libc++. You should also be careful when adding
812// dependencies to this file, since it needs to build for all libc++ targets.
813// -----------------------------------------------------------------------------
814// A generic class to manipulate C++ floating point formats.
815// It derives its functionality to FPRepImpl above.
816template <typename T>
817struct FPBits final : public internal::FPRepImpl<get_fp_type<T>(), FPBits<T>> {
818 static_assert(cpp::is_floating_point_v<T>,
819 "FPBits instantiated with invalid type.");
820 using UP = internal::FPRepImpl<get_fp_type<T>(), FPBits<T>>;
821 using StorageType = typename UP::StorageType;
822
823 // Constructors.
824 LIBC_INLINE constexpr FPBits() = default;
825
826 template <typename XType> LIBC_INLINE constexpr explicit FPBits(XType x) {
827 using Unqual = typename cpp::remove_cv_t<XType>;
828 if constexpr (cpp::is_same_v<Unqual, T>) {
829 UP::bits = cpp::bit_cast<StorageType>(x);
830 } else if constexpr (cpp::is_same_v<Unqual, StorageType>) {
831 UP::bits = x;
832 } else {
833 // We don't want accidental type promotions/conversions, so we require
834 // exact type match.
835 static_assert(cpp::always_false<XType>);
836 }
837 }
838
839 // Floating-point conversions.
840 LIBC_INLINE constexpr T get_val() const { return cpp::bit_cast<T>(UP::bits); }
841};
842
843} // namespace fputil
844} // namespace LIBC_NAMESPACE_DECL
845
846#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FPBITS_H
lib/libcxx/libc/src/__support/FPUtil/rounding_mode.h created+81
......@@ -0,0 +1,81 @@
1//===---- Free-standing function to detect rounding mode --------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_ROUNDING_MODE_H
10#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_ROUNDING_MODE_H
11
12#include "hdr/fenv_macros.h"
13#include "src/__support/macros/attributes.h" // LIBC_INLINE
14#include "src/__support/macros/config.h"
15
16namespace LIBC_NAMESPACE_DECL {
17namespace fputil {
18
19// Quick free-standing test whether fegetround() == FE_UPWARD.
20// Using the following observation:
21// 1.0f + 2^-25 = 1.0f for FE_TONEAREST, FE_DOWNWARD, FE_TOWARDZERO
22// = 0x1.000002f for FE_UPWARD.
23LIBC_INLINE bool fenv_is_round_up() {
24 volatile float x = 0x1.0p-25f;
25 return (1.0f + x != 1.0f);
26}
27
28// Quick free-standing test whether fegetround() == FE_DOWNWARD.
29// Using the following observation:
30// -1.0f - 2^-25 = -1.0f for FE_TONEAREST, FE_UPWARD, FE_TOWARDZERO
31// = -0x1.000002f for FE_DOWNWARD.
32LIBC_INLINE bool fenv_is_round_down() {
33 volatile float x = 0x1.0p-25f;
34 return (-1.0f - x != -1.0f);
35}
36
37// Quick free-standing test whether fegetround() == FE_TONEAREST.
38// Using the following observation:
39// 1.5f + 2^-24 = 1.5f for FE_TONEAREST, FE_DOWNWARD, FE_TOWARDZERO
40// = 0x1.100002p0f for FE_UPWARD,
41// 1.5f - 2^-24 = 1.5f for FE_TONEAREST, FE_UPWARD
42// = 0x1.0ffffep-1f for FE_DOWNWARD, FE_TOWARDZERO
43LIBC_INLINE bool fenv_is_round_to_nearest() {
44 static volatile float x = 0x1.0p-24f;
45 float y = x;
46 return (1.5f + y == 1.5f - y);
47}
48
49// Quick free-standing test whether fegetround() == FE_TOWARDZERO.
50// Using the following observation:
51// 1.0f + 2^-23 + 2^-24 = 0x1.000002p0f for FE_DOWNWARD, FE_TOWARDZERO
52// = 0x1.000004p0f for FE_TONEAREST, FE_UPWARD,
53// -1.0f - 2^-24 = -1.0f for FE_TONEAREST, FE_UPWARD, FE_TOWARDZERO
54// = -0x1.000002p0f for FE_DOWNWARD
55// So:
56// (0x1.000002p0f + 2^-24) + (-1.0f - 2^-24) = 2^-23 for FE_TOWARDZERO
57// = 2^-22 for FE_TONEAREST, FE_UPWARD
58// = 0 for FE_DOWNWARD
59LIBC_INLINE bool fenv_is_round_to_zero() {
60 static volatile float x = 0x1.0p-24f;
61 float y = x;
62 return ((0x1.000002p0f + y) + (-1.0f - y) == 0x1.0p-23f);
63}
64
65// Quick free standing get rounding mode based on the above observations.
66LIBC_INLINE int quick_get_round() {
67 static volatile float x = 0x1.0p-24f;
68 float y = x;
69 float z = (0x1.000002p0f + y) + (-1.0f - y);
70
71 if (z == 0.0f)
72 return FE_DOWNWARD;
73 if (z == 0x1.0p-23f)
74 return FE_TOWARDZERO;
75 return (2.0f + y == 2.0f) ? FE_TONEAREST : FE_UPWARD;
76}
77
78} // namespace fputil
79} // namespace LIBC_NAMESPACE_DECL
80
81#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_ROUNDING_MODE_H
lib/libcxx/libc/src/__support/big_int.h created+1384
......@@ -0,0 +1,1384 @@
1//===-- A class to manipulate wide integers. --------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_BIG_INT_H
10#define LLVM_LIBC_SRC___SUPPORT_BIG_INT_H
11
12#include "src/__support/CPP/array.h"
13#include "src/__support/CPP/bit.h" // countl_zero
14#include "src/__support/CPP/limits.h"
15#include "src/__support/CPP/optional.h"
16#include "src/__support/CPP/type_traits.h"
17#include "src/__support/macros/attributes.h" // LIBC_INLINE
18#include "src/__support/macros/config.h"
19#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
20#include "src/__support/macros/properties/compiler.h" // LIBC_COMPILER_IS_CLANG
21#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128, LIBC_TYPES_HAS_INT64
22#include "src/__support/math_extras.h" // add_with_carry, sub_with_borrow
23#include "src/__support/number_pair.h"
24
25#include <stddef.h> // For size_t
26#include <stdint.h>
27
28namespace LIBC_NAMESPACE_DECL {
29
30namespace multiword {
31
32// A type trait mapping unsigned integers to their half-width unsigned
33// counterparts.
34template <typename T> struct half_width;
35template <> struct half_width<uint16_t> : cpp::type_identity<uint8_t> {};
36template <> struct half_width<uint32_t> : cpp::type_identity<uint16_t> {};
37#ifdef LIBC_TYPES_HAS_INT64
38template <> struct half_width<uint64_t> : cpp::type_identity<uint32_t> {};
39#ifdef LIBC_TYPES_HAS_INT128
40template <> struct half_width<__uint128_t> : cpp::type_identity<uint64_t> {};
41#endif // LIBC_TYPES_HAS_INT128
42#endif // LIBC_TYPES_HAS_INT64
43template <typename T> using half_width_t = typename half_width<T>::type;
44
45// An array of two elements that can be used in multiword operations.
46template <typename T> struct DoubleWide final : cpp::array<T, 2> {
47 using UP = cpp::array<T, 2>;
48 using UP::UP;
49 LIBC_INLINE constexpr DoubleWide(T lo, T hi) : UP({lo, hi}) {}
50};
51
52// Converts an unsigned value into a DoubleWide<half_width_t<T>>.
53template <typename T> LIBC_INLINE constexpr auto split(T value) {
54 static_assert(cpp::is_unsigned_v<T>);
55 using half_type = half_width_t<T>;
56 return DoubleWide<half_type>(
57 half_type(value),
58 half_type(value >> cpp::numeric_limits<half_type>::digits));
59}
60
61// The low part of a DoubleWide value.
62template <typename T> LIBC_INLINE constexpr T lo(const DoubleWide<T> &value) {
63 return value[0];
64}
65// The high part of a DoubleWide value.
66template <typename T> LIBC_INLINE constexpr T hi(const DoubleWide<T> &value) {
67 return value[1];
68}
69// The low part of an unsigned value.
70template <typename T> LIBC_INLINE constexpr half_width_t<T> lo(T value) {
71 return lo(split(value));
72}
73// The high part of an unsigned value.
74template <typename T> LIBC_INLINE constexpr half_width_t<T> hi(T value) {
75 return hi(split(value));
76}
77
78// Returns 'a' times 'b' in a DoubleWide<word>. Cannot overflow by construction.
79template <typename word>
80LIBC_INLINE constexpr DoubleWide<word> mul2(word a, word b) {
81 if constexpr (cpp::is_same_v<word, uint8_t>) {
82 return split<uint16_t>(uint16_t(a) * uint16_t(b));
83 } else if constexpr (cpp::is_same_v<word, uint16_t>) {
84 return split<uint32_t>(uint32_t(a) * uint32_t(b));
85 }
86#ifdef LIBC_TYPES_HAS_INT64
87 else if constexpr (cpp::is_same_v<word, uint32_t>) {
88 return split<uint64_t>(uint64_t(a) * uint64_t(b));
89 }
90#endif
91#ifdef LIBC_TYPES_HAS_INT128
92 else if constexpr (cpp::is_same_v<word, uint64_t>) {
93 return split<__uint128_t>(__uint128_t(a) * __uint128_t(b));
94 }
95#endif
96 else {
97 using half_word = half_width_t<word>;
98 const auto shiftl = [](word value) -> word {
99 return value << cpp::numeric_limits<half_word>::digits;
100 };
101 const auto shiftr = [](word value) -> word {
102 return value >> cpp::numeric_limits<half_word>::digits;
103 };
104 // Here we do a one digit multiplication where 'a' and 'b' are of type
105 // word. We split 'a' and 'b' into half words and perform the classic long
106 // multiplication with 'a' and 'b' being two-digit numbers.
107
108 // a a_hi a_lo
109 // x b => x b_hi b_lo
110 // ---- -----------
111 // c result
112 // We convert 'lo' and 'hi' from 'half_word' to 'word' so multiplication
113 // doesn't overflow.
114 const word a_lo = lo(a);
115 const word b_lo = lo(b);
116 const word a_hi = hi(a);
117 const word b_hi = hi(b);
118 const word step1 = b_lo * a_lo; // no overflow;
119 const word step2 = b_lo * a_hi; // no overflow;
120 const word step3 = b_hi * a_lo; // no overflow;
121 const word step4 = b_hi * a_hi; // no overflow;
122 word lo_digit = step1;
123 word hi_digit = step4;
124 const word no_carry = 0;
125 word carry;
126 word _; // unused carry variable.
127 lo_digit = add_with_carry<word>(lo_digit, shiftl(step2), no_carry, carry);
128 hi_digit = add_with_carry<word>(hi_digit, shiftr(step2), carry, _);
129 lo_digit = add_with_carry<word>(lo_digit, shiftl(step3), no_carry, carry);
130 hi_digit = add_with_carry<word>(hi_digit, shiftr(step3), carry, _);
131 return DoubleWide<word>(lo_digit, hi_digit);
132 }
133}
134
135// In-place 'dst op= rhs' with operation with carry propagation. Returns carry.
136template <typename Function, typename word, size_t N, size_t M>
137LIBC_INLINE constexpr word inplace_binop(Function op_with_carry,
138 cpp::array<word, N> &dst,
139 const cpp::array<word, M> &rhs) {
140 static_assert(N >= M);
141 word carry_out = 0;
142 for (size_t i = 0; i < N; ++i) {
143 const bool has_rhs_value = i < M;
144 const word rhs_value = has_rhs_value ? rhs[i] : 0;
145 const word carry_in = carry_out;
146 dst[i] = op_with_carry(dst[i], rhs_value, carry_in, carry_out);
147 // stop early when rhs is over and no carry is to be propagated.
148 if (!has_rhs_value && carry_out == 0)
149 break;
150 }
151 return carry_out;
152}
153
154// In-place addition. Returns carry.
155template <typename word, size_t N, size_t M>
156LIBC_INLINE constexpr word add_with_carry(cpp::array<word, N> &dst,
157 const cpp::array<word, M> &rhs) {
158 return inplace_binop(LIBC_NAMESPACE::add_with_carry<word>, dst, rhs);
159}
160
161// In-place subtraction. Returns borrow.
162template <typename word, size_t N, size_t M>
163LIBC_INLINE constexpr word sub_with_borrow(cpp::array<word, N> &dst,
164 const cpp::array<word, M> &rhs) {
165 return inplace_binop(LIBC_NAMESPACE::sub_with_borrow<word>, dst, rhs);
166}
167
168// In-place multiply-add. Returns carry.
169// i.e., 'dst += b * c'
170template <typename word, size_t N>
171LIBC_INLINE constexpr word mul_add_with_carry(cpp::array<word, N> &dst, word b,
172 word c) {
173 return add_with_carry(dst, mul2(b, c));
174}
175
176// An array of two elements serving as an accumulator during multiword
177// computations.
178template <typename T> struct Accumulator final : cpp::array<T, 2> {
179 using UP = cpp::array<T, 2>;
180 LIBC_INLINE constexpr Accumulator() : UP({0, 0}) {}
181 LIBC_INLINE constexpr T advance(T carry_in) {
182 auto result = UP::front();
183 UP::front() = UP::back();
184 UP::back() = carry_in;
185 return result;
186 }
187 LIBC_INLINE constexpr T sum() const { return UP::front(); }
188 LIBC_INLINE constexpr T carry() const { return UP::back(); }
189};
190
191// In-place multiplication by a single word. Returns carry.
192template <typename word, size_t N>
193LIBC_INLINE constexpr word scalar_multiply_with_carry(cpp::array<word, N> &dst,
194 word x) {
195 Accumulator<word> acc;
196 for (auto &val : dst) {
197 const word carry = mul_add_with_carry(acc, val, x);
198 val = acc.advance(carry);
199 }
200 return acc.carry();
201}
202
203// Multiplication of 'lhs' by 'rhs' into 'dst'. Returns carry.
204// This function is safe to use for signed numbers.
205// https://stackoverflow.com/a/20793834
206// https://pages.cs.wisc.edu/%7Emarkhill/cs354/Fall2008/beyond354/int.mult.html
207template <typename word, size_t O, size_t M, size_t N>
208LIBC_INLINE constexpr word multiply_with_carry(cpp::array<word, O> &dst,
209 const cpp::array<word, M> &lhs,
210 const cpp::array<word, N> &rhs) {
211 static_assert(O >= M + N);
212 Accumulator<word> acc;
213 for (size_t i = 0; i < O; ++i) {
214 const size_t lower_idx = i < N ? 0 : i - N + 1;
215 const size_t upper_idx = i < M ? i : M - 1;
216 word carry = 0;
217 for (size_t j = lower_idx; j <= upper_idx; ++j)
218 carry += mul_add_with_carry(acc, lhs[j], rhs[i - j]);
219 dst[i] = acc.advance(carry);
220 }
221 return acc.carry();
222}
223
224template <typename word, size_t N>
225LIBC_INLINE constexpr void quick_mul_hi(cpp::array<word, N> &dst,
226 const cpp::array<word, N> &lhs,
227 const cpp::array<word, N> &rhs) {
228 Accumulator<word> acc;
229 word carry = 0;
230 // First round of accumulation for those at N - 1 in the full product.
231 for (size_t i = 0; i < N; ++i)
232 carry += mul_add_with_carry(acc, lhs[i], rhs[N - 1 - i]);
233 for (size_t i = N; i < 2 * N - 1; ++i) {
234 acc.advance(carry);
235 carry = 0;
236 for (size_t j = i - N + 1; j < N; ++j)
237 carry += mul_add_with_carry(acc, lhs[j], rhs[i - j]);
238 dst[i - N] = acc.sum();
239 }
240 dst.back() = acc.carry();
241}
242
243template <typename word, size_t N>
244LIBC_INLINE constexpr bool is_negative(cpp::array<word, N> &array) {
245 using signed_word = cpp::make_signed_t<word>;
246 return cpp::bit_cast<signed_word>(array.back()) < 0;
247}
248
249// An enum for the shift function below.
250enum Direction { LEFT, RIGHT };
251
252// A bitwise shift on an array of elements.
253// 'offset' must be less than TOTAL_BITS (i.e., sizeof(word) * CHAR_BIT * N)
254// otherwise the behavior is undefined.
255template <Direction direction, bool is_signed, typename word, size_t N>
256LIBC_INLINE constexpr cpp::array<word, N> shift(cpp::array<word, N> array,
257 size_t offset) {
258 static_assert(direction == LEFT || direction == RIGHT);
259 constexpr size_t WORD_BITS = cpp::numeric_limits<word>::digits;
260#ifdef LIBC_TYPES_HAS_INT128
261 constexpr size_t TOTAL_BITS = N * WORD_BITS;
262 if constexpr (TOTAL_BITS == 128) {
263 using type = cpp::conditional_t<is_signed, __int128_t, __uint128_t>;
264 auto tmp = cpp::bit_cast<type>(array);
265 if constexpr (direction == LEFT)
266 tmp <<= offset;
267 else
268 tmp >>= offset;
269 return cpp::bit_cast<cpp::array<word, N>>(tmp);
270 }
271#endif
272 if (LIBC_UNLIKELY(offset == 0))
273 return array;
274 const bool is_neg = is_signed && is_negative(array);
275 constexpr auto at = [](size_t index) -> int {
276 // reverse iteration when direction == LEFT.
277 if constexpr (direction == LEFT)
278 return int(N) - int(index) - 1;
279 return int(index);
280 };
281 const auto safe_get_at = [&](size_t index) -> word {
282 // return appropriate value when accessing out of bound elements.
283 const int i = at(index);
284 if (i < 0)
285 return 0;
286 if (i >= int(N))
287 return is_neg ? -1 : 0;
288 return array[i];
289 };
290 const size_t index_offset = offset / WORD_BITS;
291 const size_t bit_offset = offset % WORD_BITS;
292#ifdef LIBC_COMPILER_IS_CLANG
293 __builtin_assume(index_offset < N);
294#endif
295 cpp::array<word, N> out = {};
296 for (size_t index = 0; index < N; ++index) {
297 const word part1 = safe_get_at(index + index_offset);
298 const word part2 = safe_get_at(index + index_offset + 1);
299 word &dst = out[at(index)];
300 if (bit_offset == 0)
301 dst = part1; // no crosstalk between parts.
302 else if constexpr (direction == LEFT)
303 dst = static_cast<word>((part1 << bit_offset) |
304 (part2 >> (WORD_BITS - bit_offset)));
305 else
306 dst = static_cast<word>((part1 >> bit_offset) |
307 (part2 << (WORD_BITS - bit_offset)));
308 }
309 return out;
310}
311
312#define DECLARE_COUNTBIT(NAME, INDEX_EXPR) \
313 template <typename word, size_t N> \
314 LIBC_INLINE constexpr int NAME(const cpp::array<word, N> &val) { \
315 int bit_count = 0; \
316 for (size_t i = 0; i < N; ++i) { \
317 const int word_count = cpp::NAME<word>(val[INDEX_EXPR]); \
318 bit_count += word_count; \
319 if (word_count != cpp::numeric_limits<word>::digits) \
320 break; \
321 } \
322 return bit_count; \
323 }
324
325DECLARE_COUNTBIT(countr_zero, i) // iterating forward
326DECLARE_COUNTBIT(countr_one, i) // iterating forward
327DECLARE_COUNTBIT(countl_zero, N - i - 1) // iterating backward
328DECLARE_COUNTBIT(countl_one, N - i - 1) // iterating backward
329
330} // namespace multiword
331
332template <size_t Bits, bool Signed, typename WordType = uint64_t>
333struct BigInt {
334private:
335 static_assert(cpp::is_integral_v<WordType> && cpp::is_unsigned_v<WordType>,
336 "WordType must be unsigned integer.");
337
338 struct Division {
339 BigInt quotient;
340 BigInt remainder;
341 };
342
343public:
344 using word_type = WordType;
345 using unsigned_type = BigInt<Bits, false, word_type>;
346 using signed_type = BigInt<Bits, true, word_type>;
347
348 LIBC_INLINE_VAR static constexpr bool SIGNED = Signed;
349 LIBC_INLINE_VAR static constexpr size_t BITS = Bits;
350 LIBC_INLINE_VAR
351 static constexpr size_t WORD_SIZE = sizeof(WordType) * CHAR_BIT;
352
353 static_assert(Bits > 0 && Bits % WORD_SIZE == 0,
354 "Number of bits in BigInt should be a multiple of WORD_SIZE.");
355
356 LIBC_INLINE_VAR static constexpr size_t WORD_COUNT = Bits / WORD_SIZE;
357
358 cpp::array<WordType, WORD_COUNT> val{}; // zero initialized.
359
360 LIBC_INLINE constexpr BigInt() = default;
361
362 LIBC_INLINE constexpr BigInt(const BigInt &other) = default;
363
364 template <size_t OtherBits, bool OtherSigned, typename OtherWordType>
365 LIBC_INLINE constexpr BigInt(
366 const BigInt<OtherBits, OtherSigned, OtherWordType> &other) {
367 using BigIntOther = BigInt<OtherBits, OtherSigned, OtherWordType>;
368 const bool should_sign_extend = Signed && other.is_neg();
369
370 static_assert(!(Bits == OtherBits && WORD_SIZE != BigIntOther::WORD_SIZE) &&
371 "This is currently untested for casting between bigints with "
372 "the same bit width but different word sizes.");
373
374 if constexpr (BigIntOther::WORD_SIZE < WORD_SIZE) {
375 // OtherWordType is smaller
376 constexpr size_t WORD_SIZE_RATIO = WORD_SIZE / BigIntOther::WORD_SIZE;
377 static_assert(
378 (WORD_SIZE % BigIntOther::WORD_SIZE) == 0 &&
379 "Word types must be multiples of each other for correct conversion.");
380 if constexpr (OtherBits >= Bits) { // truncate
381 // for each big word
382 for (size_t i = 0; i < WORD_COUNT; ++i) {
383 WordType cur_word = 0;
384 // combine WORD_SIZE_RATIO small words into a big word
385 for (size_t j = 0; j < WORD_SIZE_RATIO; ++j)
386 cur_word |= static_cast<WordType>(other[(i * WORD_SIZE_RATIO) + j])
387 << (BigIntOther::WORD_SIZE * j);
388
389 val[i] = cur_word;
390 }
391 } else { // zero or sign extend
392 size_t i = 0;
393 WordType cur_word = 0;
394 // for each small word
395 for (; i < BigIntOther::WORD_COUNT; ++i) {
396 // combine WORD_SIZE_RATIO small words into a big word
397 cur_word |= static_cast<WordType>(other[i])
398 << (BigIntOther::WORD_SIZE * (i % WORD_SIZE_RATIO));
399 // if we've completed a big word, copy it into place and reset
400 if ((i % WORD_SIZE_RATIO) == WORD_SIZE_RATIO - 1) {
401 val[i / WORD_SIZE_RATIO] = cur_word;
402 cur_word = 0;
403 }
404 }
405 // Pretend there are extra words of the correct sign extension as needed
406
407 const WordType extension_bits =
408 should_sign_extend ? cpp::numeric_limits<WordType>::max()
409 : cpp::numeric_limits<WordType>::min();
410 if ((i % WORD_SIZE_RATIO) != 0) {
411 cur_word |= static_cast<WordType>(extension_bits)
412 << (BigIntOther::WORD_SIZE * (i % WORD_SIZE_RATIO));
413 }
414 // Copy the last word into place.
415 val[(i / WORD_SIZE_RATIO)] = cur_word;
416 extend((i / WORD_SIZE_RATIO) + 1, should_sign_extend);
417 }
418 } else if constexpr (BigIntOther::WORD_SIZE == WORD_SIZE) {
419 if constexpr (OtherBits >= Bits) { // truncate
420 for (size_t i = 0; i < WORD_COUNT; ++i)
421 val[i] = other[i];
422 } else { // zero or sign extend
423 size_t i = 0;
424 for (; i < BigIntOther::WORD_COUNT; ++i)
425 val[i] = other[i];
426 extend(i, should_sign_extend);
427 }
428 } else {
429 // OtherWordType is bigger.
430 constexpr size_t WORD_SIZE_RATIO = BigIntOther::WORD_SIZE / WORD_SIZE;
431 static_assert(
432 (BigIntOther::WORD_SIZE % WORD_SIZE) == 0 &&
433 "Word types must be multiples of each other for correct conversion.");
434 if constexpr (OtherBits >= Bits) { // truncate
435 // for each small word
436 for (size_t i = 0; i < WORD_COUNT; ++i) {
437 // split each big word into WORD_SIZE_RATIO small words
438 val[i] = static_cast<WordType>(other[i / WORD_SIZE_RATIO] >>
439 ((i % WORD_SIZE_RATIO) * WORD_SIZE));
440 }
441 } else { // zero or sign extend
442 size_t i = 0;
443 // for each big word
444 for (; i < BigIntOther::WORD_COUNT; ++i) {
445 // split each big word into WORD_SIZE_RATIO small words
446 for (size_t j = 0; j < WORD_SIZE_RATIO; ++j)
447 val[(i * WORD_SIZE_RATIO) + j] =
448 static_cast<WordType>(other[i] >> (j * WORD_SIZE));
449 }
450 extend(i * WORD_SIZE_RATIO, should_sign_extend);
451 }
452 }
453 }
454
455 // Construct a BigInt from a C array.
456 template <size_t N> LIBC_INLINE constexpr BigInt(const WordType (&nums)[N]) {
457 static_assert(N == WORD_COUNT);
458 for (size_t i = 0; i < WORD_COUNT; ++i)
459 val[i] = nums[i];
460 }
461
462 LIBC_INLINE constexpr explicit BigInt(
463 const cpp::array<WordType, WORD_COUNT> &words) {
464 val = words;
465 }
466
467 // Initialize the first word to |v| and the rest to 0.
468 template <typename T, typename = cpp::enable_if_t<cpp::is_integral_v<T> &&
469 !cpp::is_same_v<T, bool>>>
470 LIBC_INLINE constexpr BigInt(T v) {
471 constexpr size_t T_SIZE = sizeof(T) * CHAR_BIT;
472 const bool is_neg = v < 0;
473 for (size_t i = 0; i < WORD_COUNT; ++i) {
474 if (v == 0) {
475 extend(i, is_neg);
476 return;
477 }
478 val[i] = static_cast<WordType>(v);
479 if constexpr (T_SIZE > WORD_SIZE)
480 v >>= WORD_SIZE;
481 else
482 v = 0;
483 }
484 }
485 LIBC_INLINE constexpr BigInt &operator=(const BigInt &other) = default;
486
487 // constants
488 LIBC_INLINE static constexpr BigInt zero() { return BigInt(); }
489 LIBC_INLINE static constexpr BigInt one() { return BigInt(1); }
490 LIBC_INLINE static constexpr BigInt all_ones() { return ~zero(); }
491 LIBC_INLINE static constexpr BigInt min() {
492 BigInt out;
493 if constexpr (SIGNED)
494 out.set_msb();
495 return out;
496 }
497 LIBC_INLINE static constexpr BigInt max() {
498 BigInt out = all_ones();
499 if constexpr (SIGNED)
500 out.clear_msb();
501 return out;
502 }
503
504 // TODO: Reuse the Sign type.
505 LIBC_INLINE constexpr bool is_neg() const { return SIGNED && get_msb(); }
506
507 template <size_t OtherBits, bool OtherSigned, typename OtherWordType>
508 LIBC_INLINE constexpr explicit
509 operator BigInt<OtherBits, OtherSigned, OtherWordType>() const {
510 return BigInt<OtherBits, OtherSigned, OtherWordType>(this);
511 }
512
513 template <typename T> LIBC_INLINE constexpr explicit operator T() const {
514 return to<T>();
515 }
516
517 template <typename T>
518 LIBC_INLINE constexpr cpp::enable_if_t<
519 cpp::is_integral_v<T> && !cpp::is_same_v<T, bool>, T>
520 to() const {
521 constexpr size_t T_SIZE = sizeof(T) * CHAR_BIT;
522 T lo = static_cast<T>(val[0]);
523 if constexpr (T_SIZE <= WORD_SIZE)
524 return lo;
525 constexpr size_t MAX_COUNT =
526 T_SIZE > Bits ? WORD_COUNT : T_SIZE / WORD_SIZE;
527 for (size_t i = 1; i < MAX_COUNT; ++i)
528 lo += static_cast<T>(static_cast<T>(val[i]) << (WORD_SIZE * i));
529 if constexpr (Signed && (T_SIZE > Bits)) {
530 // Extend sign for negative numbers.
531 constexpr T MASK = (~T(0) << Bits);
532 if (is_neg())
533 lo |= MASK;
534 }
535 return lo;
536 }
537
538 LIBC_INLINE constexpr explicit operator bool() const { return !is_zero(); }
539
540 LIBC_INLINE constexpr bool is_zero() const {
541 for (auto part : val)
542 if (part != 0)
543 return false;
544 return true;
545 }
546
547 // Add 'rhs' to this number and store the result in this number.
548 // Returns the carry value produced by the addition operation.
549 LIBC_INLINE constexpr WordType add_overflow(const BigInt &rhs) {
550 return multiword::add_with_carry(val, rhs.val);
551 }
552
553 LIBC_INLINE constexpr BigInt operator+(const BigInt &other) const {
554 BigInt result = *this;
555 result.add_overflow(other);
556 return result;
557 }
558
559 // This will only apply when initializing a variable from constant values, so
560 // it will always use the constexpr version of add_with_carry.
561 LIBC_INLINE constexpr BigInt operator+(BigInt &&other) const {
562 // We use addition commutativity to reuse 'other' and prevent allocation.
563 other.add_overflow(*this); // Returned carry value is ignored.
564 return other;
565 }
566
567 LIBC_INLINE constexpr BigInt &operator+=(const BigInt &other) {
568 add_overflow(other); // Returned carry value is ignored.
569 return *this;
570 }
571
572 // Subtract 'rhs' to this number and store the result in this number.
573 // Returns the carry value produced by the subtraction operation.
574 LIBC_INLINE constexpr WordType sub_overflow(const BigInt &rhs) {
575 return multiword::sub_with_borrow(val, rhs.val);
576 }
577
578 LIBC_INLINE constexpr BigInt operator-(const BigInt &other) const {
579 BigInt result = *this;
580 result.sub_overflow(other); // Returned carry value is ignored.
581 return result;
582 }
583
584 LIBC_INLINE constexpr BigInt operator-(BigInt &&other) const {
585 BigInt result = *this;
586 result.sub_overflow(other); // Returned carry value is ignored.
587 return result;
588 }
589
590 LIBC_INLINE constexpr BigInt &operator-=(const BigInt &other) {
591 // TODO(lntue): Set overflow flag / errno when carry is true.
592 sub_overflow(other); // Returned carry value is ignored.
593 return *this;
594 }
595
596 // Multiply this number with x and store the result in this number.
597 LIBC_INLINE constexpr WordType mul(WordType x) {
598 return multiword::scalar_multiply_with_carry(val, x);
599 }
600
601 // Return the full product.
602 template <size_t OtherBits>
603 LIBC_INLINE constexpr auto
604 ful_mul(const BigInt<OtherBits, Signed, WordType> &other) const {
605 BigInt<Bits + OtherBits, Signed, WordType> result;
606 multiword::multiply_with_carry(result.val, val, other.val);
607 return result;
608 }
609
610 LIBC_INLINE constexpr BigInt operator*(const BigInt &other) const {
611 // Perform full mul and truncate.
612 return BigInt(ful_mul(other));
613 }
614
615 // Fast hi part of the full product. The normal product `operator*` returns
616 // `Bits` least significant bits of the full product, while this function will
617 // approximate `Bits` most significant bits of the full product with errors
618 // bounded by:
619 // 0 <= (a.full_mul(b) >> Bits) - a.quick_mul_hi(b)) <= WORD_COUNT - 1.
620 //
621 // An example usage of this is to quickly (but less accurately) compute the
622 // product of (normalized) mantissas of floating point numbers:
623 // (mant_1, mant_2) -> quick_mul_hi -> normalize leading bit
624 // is much more efficient than:
625 // (mant_1, mant_2) -> ful_mul -> normalize leading bit
626 // -> convert back to same Bits width by shifting/rounding,
627 // especially for higher precisions.
628 //
629 // Performance summary:
630 // Number of 64-bit x 64-bit -> 128-bit multiplications performed.
631 // Bits WORD_COUNT ful_mul quick_mul_hi Error bound
632 // 128 2 4 3 1
633 // 196 3 9 6 2
634 // 256 4 16 10 3
635 // 512 8 64 36 7
636 LIBC_INLINE constexpr BigInt quick_mul_hi(const BigInt &other) const {
637 BigInt result;
638 multiword::quick_mul_hi(result.val, val, other.val);
639 return result;
640 }
641
642 // BigInt(x).pow_n(n) computes x ^ n.
643 // Note 0 ^ 0 == 1.
644 LIBC_INLINE constexpr void pow_n(uint64_t power) {
645 static_assert(!Signed);
646 BigInt result = one();
647 BigInt cur_power = *this;
648 while (power > 0) {
649 if ((power % 2) > 0)
650 result *= cur_power;
651 power >>= 1;
652 cur_power *= cur_power;
653 }
654 *this = result;
655 }
656
657 // Performs inplace signed / unsigned division. Returns remainder if not
658 // dividing by zero.
659 // For signed numbers it behaves like C++ signed integer division.
660 // That is by truncating the fractionnal part
661 // https://stackoverflow.com/a/3602857
662 LIBC_INLINE constexpr cpp::optional<BigInt> div(const BigInt &divider) {
663 if (LIBC_UNLIKELY(divider.is_zero()))
664 return cpp::nullopt;
665 if (LIBC_UNLIKELY(divider == BigInt::one()))
666 return BigInt::zero();
667 Division result;
668 if constexpr (SIGNED)
669 result = divide_signed(*this, divider);
670 else
671 result = divide_unsigned(*this, divider);
672 *this = result.quotient;
673 return result.remainder;
674 }
675
676 // Efficiently perform BigInt / (x * 2^e), where x is a half-word-size
677 // unsigned integer, and return the remainder. The main idea is as follow:
678 // Let q = y / (x * 2^e) be the quotient, and
679 // r = y % (x * 2^e) be the remainder.
680 // First, notice that:
681 // r % (2^e) = y % (2^e),
682 // so we just need to focus on all the bits of y that is >= 2^e.
683 // To speed up the shift-and-add steps, we only use x as the divisor, and
684 // performing 32-bit shiftings instead of bit-by-bit shiftings.
685 // Since the remainder of each division step < x < 2^(WORD_SIZE / 2), the
686 // computation of each step is now properly contained within WordType.
687 // And finally we perform some extra alignment steps for the remaining bits.
688 LIBC_INLINE constexpr cpp::optional<BigInt>
689 div_uint_half_times_pow_2(multiword::half_width_t<WordType> x, size_t e) {
690 BigInt remainder;
691 if (x == 0)
692 return cpp::nullopt;
693 if (e >= Bits) {
694 remainder = *this;
695 *this = BigInt<Bits, false, WordType>();
696 return remainder;
697 }
698 BigInt quotient;
699 WordType x_word = static_cast<WordType>(x);
700 constexpr size_t LOG2_WORD_SIZE = cpp::bit_width(WORD_SIZE) - 1;
701 constexpr size_t HALF_WORD_SIZE = WORD_SIZE >> 1;
702 constexpr WordType HALF_MASK = ((WordType(1) << HALF_WORD_SIZE) - 1);
703 // lower = smallest multiple of WORD_SIZE that is >= e.
704 size_t lower = ((e >> LOG2_WORD_SIZE) + ((e & (WORD_SIZE - 1)) != 0))
705 << LOG2_WORD_SIZE;
706 // lower_pos is the index of the closest WORD_SIZE-bit chunk >= 2^e.
707 size_t lower_pos = lower / WORD_SIZE;
708 // Keep track of current remainder mod x * 2^(32*i)
709 WordType rem = 0;
710 // pos is the index of the current 64-bit chunk that we are processing.
711 size_t pos = WORD_COUNT;
712
713 // TODO: look into if constexpr(Bits > 256) skip leading zeroes.
714
715 for (size_t q_pos = WORD_COUNT - lower_pos; q_pos > 0; --q_pos) {
716 // q_pos is 1 + the index of the current WORD_SIZE-bit chunk of the
717 // quotient being processed. Performing the division / modulus with
718 // divisor:
719 // x * 2^(WORD_SIZE*q_pos - WORD_SIZE/2),
720 // i.e. using the upper (WORD_SIZE/2)-bit of the current WORD_SIZE-bit
721 // chunk.
722 rem <<= HALF_WORD_SIZE;
723 rem += val[--pos] >> HALF_WORD_SIZE;
724 WordType q_tmp = rem / x_word;
725 rem %= x_word;
726
727 // Performing the division / modulus with divisor:
728 // x * 2^(WORD_SIZE*(q_pos - 1)),
729 // i.e. using the lower (WORD_SIZE/2)-bit of the current WORD_SIZE-bit
730 // chunk.
731 rem <<= HALF_WORD_SIZE;
732 rem += val[pos] & HALF_MASK;
733 quotient.val[q_pos - 1] = (q_tmp << HALF_WORD_SIZE) + rem / x_word;
734 rem %= x_word;
735 }
736
737 // So far, what we have is:
738 // quotient = y / (x * 2^lower), and
739 // rem = (y % (x * 2^lower)) / 2^lower.
740 // If (lower > e), we will need to perform an extra adjustment of the
741 // quotient and remainder, namely:
742 // y / (x * 2^e) = [ y / (x * 2^lower) ] * 2^(lower - e) +
743 // + (rem * 2^(lower - e)) / x
744 // (y % (x * 2^e)) / 2^e = (rem * 2^(lower - e)) % x
745 size_t last_shift = lower - e;
746
747 if (last_shift > 0) {
748 // quotient * 2^(lower - e)
749 quotient <<= last_shift;
750 WordType q_tmp = 0;
751 WordType d = val[--pos];
752 if (last_shift >= HALF_WORD_SIZE) {
753 // The shifting (rem * 2^(lower - e)) might overflow WordTyoe, so we
754 // perform a HALF_WORD_SIZE-bit shift first.
755 rem <<= HALF_WORD_SIZE;
756 rem += d >> HALF_WORD_SIZE;
757 d &= HALF_MASK;
758 q_tmp = rem / x_word;
759 rem %= x_word;
760 last_shift -= HALF_WORD_SIZE;
761 } else {
762 // Only use the upper HALF_WORD_SIZE-bit of the current WORD_SIZE-bit
763 // chunk.
764 d >>= HALF_WORD_SIZE;
765 }
766
767 if (last_shift > 0) {
768 rem <<= HALF_WORD_SIZE;
769 rem += d;
770 q_tmp <<= last_shift;
771 x_word <<= HALF_WORD_SIZE - last_shift;
772 q_tmp += rem / x_word;
773 rem %= x_word;
774 }
775
776 quotient.val[0] += q_tmp;
777
778 if (lower - e <= HALF_WORD_SIZE) {
779 // The remainder rem * 2^(lower - e) might overflow to the higher
780 // WORD_SIZE-bit chunk.
781 if (pos < WORD_COUNT - 1) {
782 remainder[pos + 1] = rem >> HALF_WORD_SIZE;
783 }
784 remainder[pos] = (rem << HALF_WORD_SIZE) + (val[pos] & HALF_MASK);
785 } else {
786 remainder[pos] = rem;
787 }
788
789 } else {
790 remainder[pos] = rem;
791 }
792
793 // Set the remaining lower bits of the remainder.
794 for (; pos > 0; --pos) {
795 remainder[pos - 1] = val[pos - 1];
796 }
797
798 *this = quotient;
799 return remainder;
800 }
801
802 LIBC_INLINE constexpr BigInt operator/(const BigInt &other) const {
803 BigInt result(*this);
804 result.div(other);
805 return result;
806 }
807
808 LIBC_INLINE constexpr BigInt &operator/=(const BigInt &other) {
809 div(other);
810 return *this;
811 }
812
813 LIBC_INLINE constexpr BigInt operator%(const BigInt &other) const {
814 BigInt result(*this);
815 return *result.div(other);
816 }
817
818 LIBC_INLINE constexpr BigInt operator%=(const BigInt &other) {
819 *this = *this % other;
820 return *this;
821 }
822
823 LIBC_INLINE constexpr BigInt &operator*=(const BigInt &other) {
824 *this = *this * other;
825 return *this;
826 }
827
828 LIBC_INLINE constexpr BigInt &operator<<=(size_t s) {
829 val = multiword::shift<multiword::LEFT, SIGNED>(val, s);
830 return *this;
831 }
832
833 LIBC_INLINE constexpr BigInt operator<<(size_t s) const {
834 return BigInt(multiword::shift<multiword::LEFT, SIGNED>(val, s));
835 }
836
837 LIBC_INLINE constexpr BigInt &operator>>=(size_t s) {
838 val = multiword::shift<multiword::RIGHT, SIGNED>(val, s);
839 return *this;
840 }
841
842 LIBC_INLINE constexpr BigInt operator>>(size_t s) const {
843 return BigInt(multiword::shift<multiword::RIGHT, SIGNED>(val, s));
844 }
845
846#define DEFINE_BINOP(OP) \
847 LIBC_INLINE friend constexpr BigInt operator OP(const BigInt &lhs, \
848 const BigInt &rhs) { \
849 BigInt result; \
850 for (size_t i = 0; i < WORD_COUNT; ++i) \
851 result[i] = lhs[i] OP rhs[i]; \
852 return result; \
853 } \
854 LIBC_INLINE friend constexpr BigInt operator OP##=(BigInt &lhs, \
855 const BigInt &rhs) { \
856 for (size_t i = 0; i < WORD_COUNT; ++i) \
857 lhs[i] OP## = rhs[i]; \
858 return lhs; \
859 }
860
861 DEFINE_BINOP(&) // & and &=
862 DEFINE_BINOP(|) // | and |=
863 DEFINE_BINOP(^) // ^ and ^=
864#undef DEFINE_BINOP
865
866 LIBC_INLINE constexpr BigInt operator~() const {
867 BigInt result;
868 for (size_t i = 0; i < WORD_COUNT; ++i)
869 result[i] = ~val[i];
870 return result;
871 }
872
873 LIBC_INLINE constexpr BigInt operator-() const {
874 BigInt result(*this);
875 result.negate();
876 return result;
877 }
878
879 LIBC_INLINE friend constexpr bool operator==(const BigInt &lhs,
880 const BigInt &rhs) {
881 for (size_t i = 0; i < WORD_COUNT; ++i)
882 if (lhs.val[i] != rhs.val[i])
883 return false;
884 return true;
885 }
886
887 LIBC_INLINE friend constexpr bool operator!=(const BigInt &lhs,
888 const BigInt &rhs) {
889 return !(lhs == rhs);
890 }
891
892 LIBC_INLINE friend constexpr bool operator>(const BigInt &lhs,
893 const BigInt &rhs) {
894 return cmp(lhs, rhs) > 0;
895 }
896 LIBC_INLINE friend constexpr bool operator>=(const BigInt &lhs,
897 const BigInt &rhs) {
898 return cmp(lhs, rhs) >= 0;
899 }
900 LIBC_INLINE friend constexpr bool operator<(const BigInt &lhs,
901 const BigInt &rhs) {
902 return cmp(lhs, rhs) < 0;
903 }
904 LIBC_INLINE friend constexpr bool operator<=(const BigInt &lhs,
905 const BigInt &rhs) {
906 return cmp(lhs, rhs) <= 0;
907 }
908
909 LIBC_INLINE constexpr BigInt &operator++() {
910 increment();
911 return *this;
912 }
913
914 LIBC_INLINE constexpr BigInt operator++(int) {
915 BigInt oldval(*this);
916 increment();
917 return oldval;
918 }
919
920 LIBC_INLINE constexpr BigInt &operator--() {
921 decrement();
922 return *this;
923 }
924
925 LIBC_INLINE constexpr BigInt operator--(int) {
926 BigInt oldval(*this);
927 decrement();
928 return oldval;
929 }
930
931 // Return the i-th word of the number.
932 LIBC_INLINE constexpr const WordType &operator[](size_t i) const {
933 return val[i];
934 }
935
936 // Return the i-th word of the number.
937 LIBC_INLINE constexpr WordType &operator[](size_t i) { return val[i]; }
938
939private:
940 LIBC_INLINE friend constexpr int cmp(const BigInt &lhs, const BigInt &rhs) {
941 constexpr auto compare = [](WordType a, WordType b) {
942 return a == b ? 0 : a > b ? 1 : -1;
943 };
944 if constexpr (Signed) {
945 const bool lhs_is_neg = lhs.is_neg();
946 const bool rhs_is_neg = rhs.is_neg();
947 if (lhs_is_neg != rhs_is_neg)
948 return rhs_is_neg ? 1 : -1;
949 }
950 for (size_t i = WORD_COUNT; i-- > 0;)
951 if (auto cmp = compare(lhs[i], rhs[i]); cmp != 0)
952 return cmp;
953 return 0;
954 }
955
956 LIBC_INLINE constexpr void bitwise_not() {
957 for (auto &part : val)
958 part = ~part;
959 }
960
961 LIBC_INLINE constexpr void negate() {
962 bitwise_not();
963 increment();
964 }
965
966 LIBC_INLINE constexpr void increment() {
967 multiword::add_with_carry(val, cpp::array<WordType, 1>{1});
968 }
969
970 LIBC_INLINE constexpr void decrement() {
971 multiword::add_with_carry(val, cpp::array<WordType, 1>{1});
972 }
973
974 LIBC_INLINE constexpr void extend(size_t index, bool is_neg) {
975 const WordType value = is_neg ? cpp::numeric_limits<WordType>::max()
976 : cpp::numeric_limits<WordType>::min();
977 for (size_t i = index; i < WORD_COUNT; ++i)
978 val[i] = value;
979 }
980
981 LIBC_INLINE constexpr bool get_msb() const {
982 return val.back() >> (WORD_SIZE - 1);
983 }
984
985 LIBC_INLINE constexpr void set_msb() {
986 val.back() |= mask_leading_ones<WordType, 1>();
987 }
988
989 LIBC_INLINE constexpr void clear_msb() {
990 val.back() &= mask_trailing_ones<WordType, WORD_SIZE - 1>();
991 }
992
993 LIBC_INLINE constexpr void set_bit(size_t i) {
994 const size_t word_index = i / WORD_SIZE;
995 val[word_index] |= WordType(1) << (i % WORD_SIZE);
996 }
997
998 LIBC_INLINE constexpr static Division divide_unsigned(const BigInt &dividend,
999 const BigInt &divider) {
1000 BigInt remainder = dividend;
1001 BigInt quotient;
1002 if (remainder >= divider) {
1003 BigInt subtractor = divider;
1004 int cur_bit = multiword::countl_zero(subtractor.val) -
1005 multiword::countl_zero(remainder.val);
1006 subtractor <<= cur_bit;
1007 for (; cur_bit >= 0 && remainder > 0; --cur_bit, subtractor >>= 1) {
1008 if (remainder < subtractor)
1009 continue;
1010 remainder -= subtractor;
1011 quotient.set_bit(cur_bit);
1012 }
1013 }
1014 return Division{quotient, remainder};
1015 }
1016
1017 LIBC_INLINE constexpr static Division divide_signed(const BigInt &dividend,
1018 const BigInt &divider) {
1019 // Special case because it is not possible to negate the min value of a
1020 // signed integer.
1021 if (dividend == min() && divider == min())
1022 return Division{one(), zero()};
1023 // 1. Convert the dividend and divisor to unsigned representation.
1024 unsigned_type udividend(dividend);
1025 unsigned_type udivider(divider);
1026 // 2. Negate the dividend if it's negative, and similarly for the divisor.
1027 const bool dividend_is_neg = dividend.is_neg();
1028 const bool divider_is_neg = divider.is_neg();
1029 if (dividend_is_neg)
1030 udividend.negate();
1031 if (divider_is_neg)
1032 udivider.negate();
1033 // 3. Use unsigned multiword division algorithm.
1034 const auto unsigned_result = divide_unsigned(udividend, udivider);
1035 // 4. Convert the quotient and remainder to signed representation.
1036 Division result;
1037 result.quotient = signed_type(unsigned_result.quotient);
1038 result.remainder = signed_type(unsigned_result.remainder);
1039 // 5. Negate the quotient if the dividend and divisor had opposite signs.
1040 if (dividend_is_neg != divider_is_neg)
1041 result.quotient.negate();
1042 // 6. Negate the remainder if the dividend was negative.
1043 if (dividend_is_neg)
1044 result.remainder.negate();
1045 return result;
1046 }
1047
1048 friend signed_type;
1049 friend unsigned_type;
1050};
1051
1052namespace internal {
1053// We default BigInt's WordType to 'uint64_t' or 'uint32_t' depending on type
1054// availability.
1055template <size_t Bits>
1056struct WordTypeSelector : cpp::type_identity<
1057#ifdef LIBC_TYPES_HAS_INT64
1058 uint64_t
1059#else
1060 uint32_t
1061#endif // LIBC_TYPES_HAS_INT64
1062 > {
1063};
1064// Except if we request 16 or 32 bits explicitly.
1065template <> struct WordTypeSelector<16> : cpp::type_identity<uint16_t> {};
1066template <> struct WordTypeSelector<32> : cpp::type_identity<uint32_t> {};
1067template <> struct WordTypeSelector<96> : cpp::type_identity<uint32_t> {};
1068
1069template <size_t Bits>
1070using WordTypeSelectorT = typename WordTypeSelector<Bits>::type;
1071} // namespace internal
1072
1073template <size_t Bits>
1074using UInt = BigInt<Bits, false, internal::WordTypeSelectorT<Bits>>;
1075
1076template <size_t Bits>
1077using Int = BigInt<Bits, true, internal::WordTypeSelectorT<Bits>>;
1078
1079// Provides limits of BigInt.
1080template <size_t Bits, bool Signed, typename T>
1081struct cpp::numeric_limits<BigInt<Bits, Signed, T>> {
1082 LIBC_INLINE static constexpr BigInt<Bits, Signed, T> max() {
1083 return BigInt<Bits, Signed, T>::max();
1084 }
1085 LIBC_INLINE static constexpr BigInt<Bits, Signed, T> min() {
1086 return BigInt<Bits, Signed, T>::min();
1087 }
1088 // Meant to match std::numeric_limits interface.
1089 // NOLINTNEXTLINE(readability-identifier-naming)
1090 LIBC_INLINE_VAR static constexpr int digits = Bits - Signed;
1091};
1092
1093// type traits to determine whether a T is a BigInt.
1094template <typename T> struct is_big_int : cpp::false_type {};
1095
1096template <size_t Bits, bool Signed, typename T>
1097struct is_big_int<BigInt<Bits, Signed, T>> : cpp::true_type {};
1098
1099template <class T>
1100LIBC_INLINE_VAR constexpr bool is_big_int_v = is_big_int<T>::value;
1101
1102// extensions of type traits to include BigInt
1103
1104// is_integral_or_big_int
1105template <typename T>
1106struct is_integral_or_big_int
1107 : cpp::bool_constant<(cpp::is_integral_v<T> || is_big_int_v<T>)> {};
1108
1109template <typename T>
1110LIBC_INLINE_VAR constexpr bool is_integral_or_big_int_v =
1111 is_integral_or_big_int<T>::value;
1112
1113// make_big_int_unsigned
1114template <typename T> struct make_big_int_unsigned;
1115
1116template <size_t Bits, bool Signed, typename T>
1117struct make_big_int_unsigned<BigInt<Bits, Signed, T>>
1118 : cpp::type_identity<BigInt<Bits, false, T>> {};
1119
1120template <typename T>
1121using make_big_int_unsigned_t = typename make_big_int_unsigned<T>::type;
1122
1123// make_big_int_signed
1124template <typename T> struct make_big_int_signed;
1125
1126template <size_t Bits, bool Signed, typename T>
1127struct make_big_int_signed<BigInt<Bits, Signed, T>>
1128 : cpp::type_identity<BigInt<Bits, true, T>> {};
1129
1130template <typename T>
1131using make_big_int_signed_t = typename make_big_int_signed<T>::type;
1132
1133// make_integral_or_big_int_unsigned
1134template <typename T, class = void> struct make_integral_or_big_int_unsigned;
1135
1136template <typename T>
1137struct make_integral_or_big_int_unsigned<
1138 T, cpp::enable_if_t<cpp::is_integral_v<T>>> : cpp::make_unsigned<T> {};
1139
1140template <typename T>
1141struct make_integral_or_big_int_unsigned<T, cpp::enable_if_t<is_big_int_v<T>>>
1142 : make_big_int_unsigned<T> {};
1143
1144template <typename T>
1145using make_integral_or_big_int_unsigned_t =
1146 typename make_integral_or_big_int_unsigned<T>::type;
1147
1148// make_integral_or_big_int_signed
1149template <typename T, class = void> struct make_integral_or_big_int_signed;
1150
1151template <typename T>
1152struct make_integral_or_big_int_signed<T,
1153 cpp::enable_if_t<cpp::is_integral_v<T>>>
1154 : cpp::make_signed<T> {};
1155
1156template <typename T>
1157struct make_integral_or_big_int_signed<T, cpp::enable_if_t<is_big_int_v<T>>>
1158 : make_big_int_signed<T> {};
1159
1160template <typename T>
1161using make_integral_or_big_int_signed_t =
1162 typename make_integral_or_big_int_signed<T>::type;
1163
1164// is_unsigned_integral_or_big_int
1165template <typename T>
1166struct is_unsigned_integral_or_big_int
1167 : cpp::bool_constant<
1168 cpp::is_same_v<T, make_integral_or_big_int_unsigned_t<T>>> {};
1169
1170template <typename T>
1171// Meant to look like <type_traits> helper variable templates.
1172// NOLINTNEXTLINE(readability-identifier-naming)
1173LIBC_INLINE_VAR constexpr bool is_unsigned_integral_or_big_int_v =
1174 is_unsigned_integral_or_big_int<T>::value;
1175
1176namespace cpp {
1177
1178// Specialization of cpp::bit_cast ('bit.h') from T to BigInt.
1179template <typename To, typename From>
1180LIBC_INLINE constexpr cpp::enable_if_t<
1181 (sizeof(To) == sizeof(From)) && cpp::is_trivially_copyable<To>::value &&
1182 cpp::is_trivially_copyable<From>::value && is_big_int<To>::value,
1183 To>
1184bit_cast(const From &from) {
1185 To out;
1186 using Storage = decltype(out.val);
1187 out.val = cpp::bit_cast<Storage>(from);
1188 return out;
1189}
1190
1191// Specialization of cpp::bit_cast ('bit.h') from BigInt to T.
1192template <typename To, size_t Bits>
1193LIBC_INLINE constexpr cpp::enable_if_t<
1194 sizeof(To) == sizeof(UInt<Bits>) &&
1195 cpp::is_trivially_constructible<To>::value &&
1196 cpp::is_trivially_copyable<To>::value &&
1197 cpp::is_trivially_copyable<UInt<Bits>>::value,
1198 To>
1199bit_cast(const UInt<Bits> &from) {
1200 return cpp::bit_cast<To>(from.val);
1201}
1202
1203// Specialization of cpp::popcount ('bit.h') for BigInt.
1204template <typename T>
1205[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, int>
1206popcount(T value) {
1207 int bits = 0;
1208 for (auto word : value.val)
1209 if (word)
1210 bits += popcount(word);
1211 return bits;
1212}
1213
1214// Specialization of cpp::has_single_bit ('bit.h') for BigInt.
1215template <typename T>
1216[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, bool>
1217has_single_bit(T value) {
1218 int bits = 0;
1219 for (auto word : value.val) {
1220 if (word == 0)
1221 continue;
1222 bits += popcount(word);
1223 if (bits > 1)
1224 return false;
1225 }
1226 return bits == 1;
1227}
1228
1229// Specialization of cpp::countr_zero ('bit.h') for BigInt.
1230template <typename T>
1231[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, int>
1232countr_zero(const T &value) {
1233 return multiword::countr_zero(value.val);
1234}
1235
1236// Specialization of cpp::countl_zero ('bit.h') for BigInt.
1237template <typename T>
1238[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, int>
1239countl_zero(const T &value) {
1240 return multiword::countl_zero(value.val);
1241}
1242
1243// Specialization of cpp::countl_one ('bit.h') for BigInt.
1244template <typename T>
1245[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, int>
1246countl_one(T value) {
1247 return multiword::countl_one(value.val);
1248}
1249
1250// Specialization of cpp::countr_one ('bit.h') for BigInt.
1251template <typename T>
1252[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, int>
1253countr_one(T value) {
1254 return multiword::countr_one(value.val);
1255}
1256
1257// Specialization of cpp::bit_width ('bit.h') for BigInt.
1258template <typename T>
1259[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, int>
1260bit_width(T value) {
1261 return cpp::numeric_limits<T>::digits - cpp::countl_zero(value);
1262}
1263
1264// Forward-declare rotr so that rotl can use it.
1265template <typename T>
1266[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, T>
1267rotr(T value, int rotate);
1268
1269// Specialization of cpp::rotl ('bit.h') for BigInt.
1270template <typename T>
1271[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, T>
1272rotl(T value, int rotate) {
1273 constexpr unsigned N = cpp::numeric_limits<T>::digits;
1274 rotate = rotate % N;
1275 if (!rotate)
1276 return value;
1277 if (rotate < 0)
1278 return cpp::rotr<T>(value, -rotate);
1279 return (value << rotate) | (value >> (N - rotate));
1280}
1281
1282// Specialization of cpp::rotr ('bit.h') for BigInt.
1283template <typename T>
1284[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, T>
1285rotr(T value, int rotate) {
1286 constexpr unsigned N = cpp::numeric_limits<T>::digits;
1287 rotate = rotate % N;
1288 if (!rotate)
1289 return value;
1290 if (rotate < 0)
1291 return cpp::rotl<T>(value, -rotate);
1292 return (value >> rotate) | (value << (N - rotate));
1293}
1294
1295} // namespace cpp
1296
1297// Specialization of mask_trailing_ones ('math_extras.h') for BigInt.
1298template <typename T, size_t count>
1299LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, T>
1300mask_trailing_ones() {
1301 static_assert(!T::SIGNED && count <= T::BITS);
1302 if (count == T::BITS)
1303 return T::all_ones();
1304 constexpr size_t QUOTIENT = count / T::WORD_SIZE;
1305 constexpr size_t REMAINDER = count % T::WORD_SIZE;
1306 T out; // zero initialized
1307 for (size_t i = 0; i <= QUOTIENT; ++i)
1308 out[i] = i < QUOTIENT
1309 ? -1
1310 : mask_trailing_ones<typename T::word_type, REMAINDER>();
1311 return out;
1312}
1313
1314// Specialization of mask_leading_ones ('math_extras.h') for BigInt.
1315template <typename T, size_t count>
1316LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, T> mask_leading_ones() {
1317 static_assert(!T::SIGNED && count <= T::BITS);
1318 if (count == T::BITS)
1319 return T::all_ones();
1320 constexpr size_t QUOTIENT = (T::BITS - count - 1U) / T::WORD_SIZE;
1321 constexpr size_t REMAINDER = count % T::WORD_SIZE;
1322 T out; // zero initialized
1323 for (size_t i = QUOTIENT; i < T::WORD_COUNT; ++i)
1324 out[i] = i > QUOTIENT
1325 ? -1
1326 : mask_leading_ones<typename T::word_type, REMAINDER>();
1327 return out;
1328}
1329
1330// Specialization of mask_trailing_zeros ('math_extras.h') for BigInt.
1331template <typename T, size_t count>
1332LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, T>
1333mask_trailing_zeros() {
1334 return mask_leading_ones<T, T::BITS - count>();
1335}
1336
1337// Specialization of mask_leading_zeros ('math_extras.h') for BigInt.
1338template <typename T, size_t count>
1339LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, T>
1340mask_leading_zeros() {
1341 return mask_trailing_ones<T, T::BITS - count>();
1342}
1343
1344// Specialization of count_zeros ('math_extras.h') for BigInt.
1345template <typename T>
1346[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, int>
1347count_zeros(T value) {
1348 return cpp::popcount(~value);
1349}
1350
1351// Specialization of first_leading_zero ('math_extras.h') for BigInt.
1352template <typename T>
1353[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, int>
1354first_leading_zero(T value) {
1355 return value == cpp::numeric_limits<T>::max() ? 0
1356 : cpp::countl_one(value) + 1;
1357}
1358
1359// Specialization of first_leading_one ('math_extras.h') for BigInt.
1360template <typename T>
1361[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, int>
1362first_leading_one(T value) {
1363 return first_leading_zero(~value);
1364}
1365
1366// Specialization of first_trailing_zero ('math_extras.h') for BigInt.
1367template <typename T>
1368[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, int>
1369first_trailing_zero(T value) {
1370 return value == cpp::numeric_limits<T>::max() ? 0
1371 : cpp::countr_zero(~value) + 1;
1372}
1373
1374// Specialization of first_trailing_one ('math_extras.h') for BigInt.
1375template <typename T>
1376[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, int>
1377first_trailing_one(T value) {
1378 return value == cpp::numeric_limits<T>::max() ? 0
1379 : cpp::countr_zero(value) + 1;
1380}
1381
1382} // namespace LIBC_NAMESPACE_DECL
1383
1384#endif // LLVM_LIBC_SRC___SUPPORT_BIG_INT_H
lib/libcxx/libc/src/__support/common.h created+82
......@@ -0,0 +1,82 @@
1//===-- Common internal contructs -------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_COMMON_H
10#define LLVM_LIBC_SRC___SUPPORT_COMMON_H
11
12#ifndef LIBC_NAMESPACE
13#error "LIBC_NAMESPACE macro is not defined."
14#endif
15
16#include "src/__support/macros/attributes.h"
17#include "src/__support/macros/config.h"
18#include "src/__support/macros/properties/architectures.h"
19
20#ifndef LLVM_LIBC_FUNCTION_ATTR
21#define LLVM_LIBC_FUNCTION_ATTR
22#endif
23
24// clang-format off
25// Allow each function `func` to have extra attributes specified by defining:
26// `LLVM_LIBC_FUNCTION_ATTR_func` macro, which should always start with
27// "LLVM_LIBC_EMPTY, "
28//
29// For examples:
30// #define LLVM_LIBC_FUNCTION_ATTR_memcpy LLVM_LIBC_EMPTY, [[gnu::weak]]
31// #define LLVM_LIBC_FUNCTION_ATTR_memchr LLVM_LIBC_EMPTY, [[gnu::weak]] [[gnu::visibility("default")]]
32// clang-format on
33#define LLVM_LIBC_EMPTY
34
35#define GET_SECOND(first, second, ...) second
36#define EXPAND_THEN_SECOND(name) GET_SECOND(name, LLVM_LIBC_EMPTY)
37
38#define LLVM_LIBC_ATTR(name) EXPAND_THEN_SECOND(LLVM_LIBC_FUNCTION_ATTR_##name)
39
40// MacOS needs to be excluded because it does not support aliasing.
41#if defined(LIBC_COPT_PUBLIC_PACKAGING) && (!defined(__APPLE__))
42#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) \
43 LLVM_LIBC_ATTR(name) \
44 LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name) \
45 __##name##_impl__ __asm__(#name); \
46 decltype(LIBC_NAMESPACE::name) name [[gnu::alias(#name)]]; \
47 type __##name##_impl__ arglist
48#else
49#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) type name arglist
50#endif
51
52// This extra layer of macro allows `name` to be a macro to rename a function.
53#define LLVM_LIBC_FUNCTION(type, name, arglist) \
54 LLVM_LIBC_FUNCTION_IMPL(type, name, arglist)
55
56namespace LIBC_NAMESPACE_DECL {
57namespace internal {
58LIBC_INLINE constexpr bool same_string(char const *lhs, char const *rhs) {
59 for (; *lhs || *rhs; ++lhs, ++rhs)
60 if (*lhs != *rhs)
61 return false;
62 return true;
63}
64} // namespace internal
65} // namespace LIBC_NAMESPACE_DECL
66
67#define __LIBC_MACRO_TO_STRING(str) #str
68#define LIBC_MACRO_TO_STRING(str) __LIBC_MACRO_TO_STRING(str)
69
70// LLVM_LIBC_IS_DEFINED checks whether a particular macro is defined.
71// Usage: constexpr bool kUseAvx = LLVM_LIBC_IS_DEFINED(__AVX__);
72//
73// This works by comparing the stringified version of the macro with and without
74// evaluation. If FOO is not undefined both stringifications yield "FOO". If FOO
75// is defined, one stringification yields "FOO" while the other yields its
76// stringified value "1".
77#define LLVM_LIBC_IS_DEFINED(macro) \
78 !LIBC_NAMESPACE::internal::same_string( \
79 LLVM_LIBC_IS_DEFINED__EVAL_AND_STRINGIZE(macro), #macro)
80#define LLVM_LIBC_IS_DEFINED__EVAL_AND_STRINGIZE(s) #s
81
82#endif // LLVM_LIBC_SRC___SUPPORT_COMMON_H
lib/libcxx/libc/src/__support/ctype_utils.h created+584
......@@ -0,0 +1,584 @@
1//===-- Collection of utils for implementing ctype functions-------*-C++-*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_CTYPE_UTILS_H
10#define LLVM_LIBC_SRC___SUPPORT_CTYPE_UTILS_H
11
12#include "src/__support/macros/attributes.h"
13#include "src/__support/macros/config.h"
14
15namespace LIBC_NAMESPACE_DECL {
16namespace internal {
17
18// -----------------------------------------------------------------------------
19// ****************** WARNING ******************
20// ****************** DO NOT TRY TO OPTIMIZE THESE FUNCTIONS! ******************
21// -----------------------------------------------------------------------------
22// This switch/case form is easier for the compiler to understand, and is
23// optimized into a form that is almost always the same as or better than
24// versions written by hand (see https://godbolt.org/z/qvrebqvvr). Also this
25// form makes these functions encoding independent. If you want to rewrite these
26// functions, make sure you have benchmarks to show your new solution is faster,
27// as well as a way to support non-ASCII character encodings.
28
29// Similarly, do not change these functions to use case ranges. e.g.
30// bool islower(int ch) {
31// switch(ch) {
32// case 'a'...'z':
33// return true;
34// }
35// }
36// This assumes the character ranges are contiguous, which they aren't in
37// EBCDIC. Technically we could use some smaller ranges, but that's even harder
38// to read.
39
40LIBC_INLINE static constexpr bool islower(int ch) {
41 switch (ch) {
42 case 'a':
43 case 'b':
44 case 'c':
45 case 'd':
46 case 'e':
47 case 'f':
48 case 'g':
49 case 'h':
50 case 'i':
51 case 'j':
52 case 'k':
53 case 'l':
54 case 'm':
55 case 'n':
56 case 'o':
57 case 'p':
58 case 'q':
59 case 'r':
60 case 's':
61 case 't':
62 case 'u':
63 case 'v':
64 case 'w':
65 case 'x':
66 case 'y':
67 case 'z':
68 return true;
69 default:
70 return false;
71 }
72}
73
74LIBC_INLINE static constexpr bool isupper(int ch) {
75 switch (ch) {
76 case 'A':
77 case 'B':
78 case 'C':
79 case 'D':
80 case 'E':
81 case 'F':
82 case 'G':
83 case 'H':
84 case 'I':
85 case 'J':
86 case 'K':
87 case 'L':
88 case 'M':
89 case 'N':
90 case 'O':
91 case 'P':
92 case 'Q':
93 case 'R':
94 case 'S':
95 case 'T':
96 case 'U':
97 case 'V':
98 case 'W':
99 case 'X':
100 case 'Y':
101 case 'Z':
102 return true;
103 default:
104 return false;
105 }
106}
107
108LIBC_INLINE static constexpr bool isdigit(int ch) {
109 switch (ch) {
110 case '0':
111 case '1':
112 case '2':
113 case '3':
114 case '4':
115 case '5':
116 case '6':
117 case '7':
118 case '8':
119 case '9':
120 return true;
121 default:
122 return false;
123 }
124}
125
126LIBC_INLINE static constexpr int tolower(int ch) {
127 switch (ch) {
128 case 'A':
129 return 'a';
130 case 'B':
131 return 'b';
132 case 'C':
133 return 'c';
134 case 'D':
135 return 'd';
136 case 'E':
137 return 'e';
138 case 'F':
139 return 'f';
140 case 'G':
141 return 'g';
142 case 'H':
143 return 'h';
144 case 'I':
145 return 'i';
146 case 'J':
147 return 'j';
148 case 'K':
149 return 'k';
150 case 'L':
151 return 'l';
152 case 'M':
153 return 'm';
154 case 'N':
155 return 'n';
156 case 'O':
157 return 'o';
158 case 'P':
159 return 'p';
160 case 'Q':
161 return 'q';
162 case 'R':
163 return 'r';
164 case 'S':
165 return 's';
166 case 'T':
167 return 't';
168 case 'U':
169 return 'u';
170 case 'V':
171 return 'v';
172 case 'W':
173 return 'w';
174 case 'X':
175 return 'x';
176 case 'Y':
177 return 'y';
178 case 'Z':
179 return 'z';
180 default:
181 return ch;
182 }
183}
184
185LIBC_INLINE static constexpr int toupper(int ch) {
186 switch (ch) {
187 case 'a':
188 return 'A';
189 case 'b':
190 return 'B';
191 case 'c':
192 return 'C';
193 case 'd':
194 return 'D';
195 case 'e':
196 return 'E';
197 case 'f':
198 return 'F';
199 case 'g':
200 return 'G';
201 case 'h':
202 return 'H';
203 case 'i':
204 return 'I';
205 case 'j':
206 return 'J';
207 case 'k':
208 return 'K';
209 case 'l':
210 return 'L';
211 case 'm':
212 return 'M';
213 case 'n':
214 return 'N';
215 case 'o':
216 return 'O';
217 case 'p':
218 return 'P';
219 case 'q':
220 return 'Q';
221 case 'r':
222 return 'R';
223 case 's':
224 return 'S';
225 case 't':
226 return 'T';
227 case 'u':
228 return 'U';
229 case 'v':
230 return 'V';
231 case 'w':
232 return 'W';
233 case 'x':
234 return 'X';
235 case 'y':
236 return 'Y';
237 case 'z':
238 return 'Z';
239 default:
240 return ch;
241 }
242}
243
244LIBC_INLINE static constexpr bool isalpha(int ch) {
245 switch (ch) {
246 case 'a':
247 case 'b':
248 case 'c':
249 case 'd':
250 case 'e':
251 case 'f':
252 case 'g':
253 case 'h':
254 case 'i':
255 case 'j':
256 case 'k':
257 case 'l':
258 case 'm':
259 case 'n':
260 case 'o':
261 case 'p':
262 case 'q':
263 case 'r':
264 case 's':
265 case 't':
266 case 'u':
267 case 'v':
268 case 'w':
269 case 'x':
270 case 'y':
271 case 'z':
272 case 'A':
273 case 'B':
274 case 'C':
275 case 'D':
276 case 'E':
277 case 'F':
278 case 'G':
279 case 'H':
280 case 'I':
281 case 'J':
282 case 'K':
283 case 'L':
284 case 'M':
285 case 'N':
286 case 'O':
287 case 'P':
288 case 'Q':
289 case 'R':
290 case 'S':
291 case 'T':
292 case 'U':
293 case 'V':
294 case 'W':
295 case 'X':
296 case 'Y':
297 case 'Z':
298 return true;
299 default:
300 return false;
301 }
302}
303
304LIBC_INLINE static constexpr bool isalnum(int ch) {
305 switch (ch) {
306 case 'a':
307 case 'b':
308 case 'c':
309 case 'd':
310 case 'e':
311 case 'f':
312 case 'g':
313 case 'h':
314 case 'i':
315 case 'j':
316 case 'k':
317 case 'l':
318 case 'm':
319 case 'n':
320 case 'o':
321 case 'p':
322 case 'q':
323 case 'r':
324 case 's':
325 case 't':
326 case 'u':
327 case 'v':
328 case 'w':
329 case 'x':
330 case 'y':
331 case 'z':
332 case 'A':
333 case 'B':
334 case 'C':
335 case 'D':
336 case 'E':
337 case 'F':
338 case 'G':
339 case 'H':
340 case 'I':
341 case 'J':
342 case 'K':
343 case 'L':
344 case 'M':
345 case 'N':
346 case 'O':
347 case 'P':
348 case 'Q':
349 case 'R':
350 case 'S':
351 case 'T':
352 case 'U':
353 case 'V':
354 case 'W':
355 case 'X':
356 case 'Y':
357 case 'Z':
358 case '0':
359 case '1':
360 case '2':
361 case '3':
362 case '4':
363 case '5':
364 case '6':
365 case '7':
366 case '8':
367 case '9':
368 return true;
369 default:
370 return false;
371 }
372}
373
374LIBC_INLINE static constexpr int b36_char_to_int(int ch) {
375 switch (ch) {
376 case '0':
377 return 0;
378 case '1':
379 return 1;
380 case '2':
381 return 2;
382 case '3':
383 return 3;
384 case '4':
385 return 4;
386 case '5':
387 return 5;
388 case '6':
389 return 6;
390 case '7':
391 return 7;
392 case '8':
393 return 8;
394 case '9':
395 return 9;
396 case 'a':
397 case 'A':
398 return 10;
399 case 'b':
400 case 'B':
401 return 11;
402 case 'c':
403 case 'C':
404 return 12;
405 case 'd':
406 case 'D':
407 return 13;
408 case 'e':
409 case 'E':
410 return 14;
411 case 'f':
412 case 'F':
413 return 15;
414 case 'g':
415 case 'G':
416 return 16;
417 case 'h':
418 case 'H':
419 return 17;
420 case 'i':
421 case 'I':
422 return 18;
423 case 'j':
424 case 'J':
425 return 19;
426 case 'k':
427 case 'K':
428 return 20;
429 case 'l':
430 case 'L':
431 return 21;
432 case 'm':
433 case 'M':
434 return 22;
435 case 'n':
436 case 'N':
437 return 23;
438 case 'o':
439 case 'O':
440 return 24;
441 case 'p':
442 case 'P':
443 return 25;
444 case 'q':
445 case 'Q':
446 return 26;
447 case 'r':
448 case 'R':
449 return 27;
450 case 's':
451 case 'S':
452 return 28;
453 case 't':
454 case 'T':
455 return 29;
456 case 'u':
457 case 'U':
458 return 30;
459 case 'v':
460 case 'V':
461 return 31;
462 case 'w':
463 case 'W':
464 return 32;
465 case 'x':
466 case 'X':
467 return 33;
468 case 'y':
469 case 'Y':
470 return 34;
471 case 'z':
472 case 'Z':
473 return 35;
474 default:
475 return 0;
476 }
477}
478
479LIBC_INLINE static constexpr int int_to_b36_char(int num) {
480 // Can't actually use LIBC_ASSERT here because it depends on integer_to_string
481 // which depends on this.
482
483 // LIBC_ASSERT(num < 36);
484 switch (num) {
485 case 0:
486 return '0';
487 case 1:
488 return '1';
489 case 2:
490 return '2';
491 case 3:
492 return '3';
493 case 4:
494 return '4';
495 case 5:
496 return '5';
497 case 6:
498 return '6';
499 case 7:
500 return '7';
501 case 8:
502 return '8';
503 case 9:
504 return '9';
505 case 10:
506 return 'a';
507 case 11:
508 return 'b';
509 case 12:
510 return 'c';
511 case 13:
512 return 'd';
513 case 14:
514 return 'e';
515 case 15:
516 return 'f';
517 case 16:
518 return 'g';
519 case 17:
520 return 'h';
521 case 18:
522 return 'i';
523 case 19:
524 return 'j';
525 case 20:
526 return 'k';
527 case 21:
528 return 'l';
529 case 22:
530 return 'm';
531 case 23:
532 return 'n';
533 case 24:
534 return 'o';
535 case 25:
536 return 'p';
537 case 26:
538 return 'q';
539 case 27:
540 return 'r';
541 case 28:
542 return 's';
543 case 29:
544 return 't';
545 case 30:
546 return 'u';
547 case 31:
548 return 'v';
549 case 32:
550 return 'w';
551 case 33:
552 return 'x';
553 case 34:
554 return 'y';
555 case 35:
556 return 'z';
557 default:
558 return '!';
559 }
560}
561
562LIBC_INLINE static constexpr bool isspace(int ch) {
563 switch (ch) {
564 case ' ':
565 case '\t':
566 case '\n':
567 case '\v':
568 case '\f':
569 case '\r':
570 return true;
571 default:
572 return false;
573 }
574}
575
576// not yet encoding independent.
577LIBC_INLINE static constexpr bool isgraph(int ch) {
578 return 0x20 < ch && ch < 0x7f;
579}
580
581} // namespace internal
582} // namespace LIBC_NAMESPACE_DECL
583
584#endif // LLVM_LIBC_SRC___SUPPORT_CTYPE_UTILS_H
lib/libcxx/libc/src/__support/detailed_powers_of_ten.h created+740
......@@ -0,0 +1,740 @@
1//===-- detailed powers of ten ----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_DETAILED_POWERS_OF_TEN_H
10#define LLVM_LIBC_SRC___SUPPORT_DETAILED_POWERS_OF_TEN_H
11
12#include "src/__support/common.h"
13#include "src/__support/macros/config.h"
14
15#include <stdint.h>
16
17namespace LIBC_NAMESPACE_DECL {
18namespace internal {
19
20// TODO(michaelrj): write a script that will generate this table.
21
22// This table was generated by
23// https://github.com/google/wuffs/blob/788479dd64f35cb6b4e998a851acb06ee962435b/script/print-mpb-powers-of-10.go
24// and contains the 128 bit mantissa approximations of the powers of 10 from
25// -348 to 347. The exponents are implied by a linear expression with slope
26// 217706.0/65536.0 ≈ log(10)/log(2). This is used by the Eisel-Lemire algorithm
27// in str_to_float.h.
28
29constexpr int32_t DETAILED_POWERS_OF_TEN_MIN_EXP_10 = -348;
30constexpr int32_t DETAILED_POWERS_OF_TEN_MAX_EXP_10 = 347;
31
32// This rescales the base 10 exponent by a factor of log(10)/log(2).
33LIBC_INLINE int32_t exp10_to_exp2(int32_t exp10) {
34 // Valid if exp10 < 646 456 636.
35 return static_cast<int32_t>((217706 * static_cast<int64_t>(exp10)) >> 16);
36}
37
38static constexpr uint64_t DETAILED_POWERS_OF_TEN[696][2] = {
39 {0x1732C869CD60E453, 0xFA8FD5A0081C0288}, // 1e-348
40 {0x0E7FBD42205C8EB4, 0x9C99E58405118195}, // 1e-347
41 {0x521FAC92A873B261, 0xC3C05EE50655E1FA}, // 1e-346
42 {0xE6A797B752909EF9, 0xF4B0769E47EB5A78}, // 1e-345
43 {0x9028BED2939A635C, 0x98EE4A22ECF3188B}, // 1e-344
44 {0x7432EE873880FC33, 0xBF29DCABA82FDEAE}, // 1e-343
45 {0x113FAA2906A13B3F, 0xEEF453D6923BD65A}, // 1e-342
46 {0x4AC7CA59A424C507, 0x9558B4661B6565F8}, // 1e-341
47 {0x5D79BCF00D2DF649, 0xBAAEE17FA23EBF76}, // 1e-340
48 {0xF4D82C2C107973DC, 0xE95A99DF8ACE6F53}, // 1e-339
49 {0x79071B9B8A4BE869, 0x91D8A02BB6C10594}, // 1e-338
50 {0x9748E2826CDEE284, 0xB64EC836A47146F9}, // 1e-337
51 {0xFD1B1B2308169B25, 0xE3E27A444D8D98B7}, // 1e-336
52 {0xFE30F0F5E50E20F7, 0x8E6D8C6AB0787F72}, // 1e-335
53 {0xBDBD2D335E51A935, 0xB208EF855C969F4F}, // 1e-334
54 {0xAD2C788035E61382, 0xDE8B2B66B3BC4723}, // 1e-333
55 {0x4C3BCB5021AFCC31, 0x8B16FB203055AC76}, // 1e-332
56 {0xDF4ABE242A1BBF3D, 0xADDCB9E83C6B1793}, // 1e-331
57 {0xD71D6DAD34A2AF0D, 0xD953E8624B85DD78}, // 1e-330
58 {0x8672648C40E5AD68, 0x87D4713D6F33AA6B}, // 1e-329
59 {0x680EFDAF511F18C2, 0xA9C98D8CCB009506}, // 1e-328
60 {0x0212BD1B2566DEF2, 0xD43BF0EFFDC0BA48}, // 1e-327
61 {0x014BB630F7604B57, 0x84A57695FE98746D}, // 1e-326
62 {0x419EA3BD35385E2D, 0xA5CED43B7E3E9188}, // 1e-325
63 {0x52064CAC828675B9, 0xCF42894A5DCE35EA}, // 1e-324
64 {0x7343EFEBD1940993, 0x818995CE7AA0E1B2}, // 1e-323
65 {0x1014EBE6C5F90BF8, 0xA1EBFB4219491A1F}, // 1e-322
66 {0xD41A26E077774EF6, 0xCA66FA129F9B60A6}, // 1e-321
67 {0x8920B098955522B4, 0xFD00B897478238D0}, // 1e-320
68 {0x55B46E5F5D5535B0, 0x9E20735E8CB16382}, // 1e-319
69 {0xEB2189F734AA831D, 0xC5A890362FDDBC62}, // 1e-318
70 {0xA5E9EC7501D523E4, 0xF712B443BBD52B7B}, // 1e-317
71 {0x47B233C92125366E, 0x9A6BB0AA55653B2D}, // 1e-316
72 {0x999EC0BB696E840A, 0xC1069CD4EABE89F8}, // 1e-315
73 {0xC00670EA43CA250D, 0xF148440A256E2C76}, // 1e-314
74 {0x380406926A5E5728, 0x96CD2A865764DBCA}, // 1e-313
75 {0xC605083704F5ECF2, 0xBC807527ED3E12BC}, // 1e-312
76 {0xF7864A44C633682E, 0xEBA09271E88D976B}, // 1e-311
77 {0x7AB3EE6AFBE0211D, 0x93445B8731587EA3}, // 1e-310
78 {0x5960EA05BAD82964, 0xB8157268FDAE9E4C}, // 1e-309
79 {0x6FB92487298E33BD, 0xE61ACF033D1A45DF}, // 1e-308
80 {0xA5D3B6D479F8E056, 0x8FD0C16206306BAB}, // 1e-307
81 {0x8F48A4899877186C, 0xB3C4F1BA87BC8696}, // 1e-306
82 {0x331ACDABFE94DE87, 0xE0B62E2929ABA83C}, // 1e-305
83 {0x9FF0C08B7F1D0B14, 0x8C71DCD9BA0B4925}, // 1e-304
84 {0x07ECF0AE5EE44DD9, 0xAF8E5410288E1B6F}, // 1e-303
85 {0xC9E82CD9F69D6150, 0xDB71E91432B1A24A}, // 1e-302
86 {0xBE311C083A225CD2, 0x892731AC9FAF056E}, // 1e-301
87 {0x6DBD630A48AAF406, 0xAB70FE17C79AC6CA}, // 1e-300
88 {0x092CBBCCDAD5B108, 0xD64D3D9DB981787D}, // 1e-299
89 {0x25BBF56008C58EA5, 0x85F0468293F0EB4E}, // 1e-298
90 {0xAF2AF2B80AF6F24E, 0xA76C582338ED2621}, // 1e-297
91 {0x1AF5AF660DB4AEE1, 0xD1476E2C07286FAA}, // 1e-296
92 {0x50D98D9FC890ED4D, 0x82CCA4DB847945CA}, // 1e-295
93 {0xE50FF107BAB528A0, 0xA37FCE126597973C}, // 1e-294
94 {0x1E53ED49A96272C8, 0xCC5FC196FEFD7D0C}, // 1e-293
95 {0x25E8E89C13BB0F7A, 0xFF77B1FCBEBCDC4F}, // 1e-292
96 {0x77B191618C54E9AC, 0x9FAACF3DF73609B1}, // 1e-291
97 {0xD59DF5B9EF6A2417, 0xC795830D75038C1D}, // 1e-290
98 {0x4B0573286B44AD1D, 0xF97AE3D0D2446F25}, // 1e-289
99 {0x4EE367F9430AEC32, 0x9BECCE62836AC577}, // 1e-288
100 {0x229C41F793CDA73F, 0xC2E801FB244576D5}, // 1e-287
101 {0x6B43527578C1110F, 0xF3A20279ED56D48A}, // 1e-286
102 {0x830A13896B78AAA9, 0x9845418C345644D6}, // 1e-285
103 {0x23CC986BC656D553, 0xBE5691EF416BD60C}, // 1e-284
104 {0x2CBFBE86B7EC8AA8, 0xEDEC366B11C6CB8F}, // 1e-283
105 {0x7BF7D71432F3D6A9, 0x94B3A202EB1C3F39}, // 1e-282
106 {0xDAF5CCD93FB0CC53, 0xB9E08A83A5E34F07}, // 1e-281
107 {0xD1B3400F8F9CFF68, 0xE858AD248F5C22C9}, // 1e-280
108 {0x23100809B9C21FA1, 0x91376C36D99995BE}, // 1e-279
109 {0xABD40A0C2832A78A, 0xB58547448FFFFB2D}, // 1e-278
110 {0x16C90C8F323F516C, 0xE2E69915B3FFF9F9}, // 1e-277
111 {0xAE3DA7D97F6792E3, 0x8DD01FAD907FFC3B}, // 1e-276
112 {0x99CD11CFDF41779C, 0xB1442798F49FFB4A}, // 1e-275
113 {0x40405643D711D583, 0xDD95317F31C7FA1D}, // 1e-274
114 {0x482835EA666B2572, 0x8A7D3EEF7F1CFC52}, // 1e-273
115 {0xDA3243650005EECF, 0xAD1C8EAB5EE43B66}, // 1e-272
116 {0x90BED43E40076A82, 0xD863B256369D4A40}, // 1e-271
117 {0x5A7744A6E804A291, 0x873E4F75E2224E68}, // 1e-270
118 {0x711515D0A205CB36, 0xA90DE3535AAAE202}, // 1e-269
119 {0x0D5A5B44CA873E03, 0xD3515C2831559A83}, // 1e-268
120 {0xE858790AFE9486C2, 0x8412D9991ED58091}, // 1e-267
121 {0x626E974DBE39A872, 0xA5178FFF668AE0B6}, // 1e-266
122 {0xFB0A3D212DC8128F, 0xCE5D73FF402D98E3}, // 1e-265
123 {0x7CE66634BC9D0B99, 0x80FA687F881C7F8E}, // 1e-264
124 {0x1C1FFFC1EBC44E80, 0xA139029F6A239F72}, // 1e-263
125 {0xA327FFB266B56220, 0xC987434744AC874E}, // 1e-262
126 {0x4BF1FF9F0062BAA8, 0xFBE9141915D7A922}, // 1e-261
127 {0x6F773FC3603DB4A9, 0x9D71AC8FADA6C9B5}, // 1e-260
128 {0xCB550FB4384D21D3, 0xC4CE17B399107C22}, // 1e-259
129 {0x7E2A53A146606A48, 0xF6019DA07F549B2B}, // 1e-258
130 {0x2EDA7444CBFC426D, 0x99C102844F94E0FB}, // 1e-257
131 {0xFA911155FEFB5308, 0xC0314325637A1939}, // 1e-256
132 {0x793555AB7EBA27CA, 0xF03D93EEBC589F88}, // 1e-255
133 {0x4BC1558B2F3458DE, 0x96267C7535B763B5}, // 1e-254
134 {0x9EB1AAEDFB016F16, 0xBBB01B9283253CA2}, // 1e-253
135 {0x465E15A979C1CADC, 0xEA9C227723EE8BCB}, // 1e-252
136 {0x0BFACD89EC191EC9, 0x92A1958A7675175F}, // 1e-251
137 {0xCEF980EC671F667B, 0xB749FAED14125D36}, // 1e-250
138 {0x82B7E12780E7401A, 0xE51C79A85916F484}, // 1e-249
139 {0xD1B2ECB8B0908810, 0x8F31CC0937AE58D2}, // 1e-248
140 {0x861FA7E6DCB4AA15, 0xB2FE3F0B8599EF07}, // 1e-247
141 {0x67A791E093E1D49A, 0xDFBDCECE67006AC9}, // 1e-246
142 {0xE0C8BB2C5C6D24E0, 0x8BD6A141006042BD}, // 1e-245
143 {0x58FAE9F773886E18, 0xAECC49914078536D}, // 1e-244
144 {0xAF39A475506A899E, 0xDA7F5BF590966848}, // 1e-243
145 {0x6D8406C952429603, 0x888F99797A5E012D}, // 1e-242
146 {0xC8E5087BA6D33B83, 0xAAB37FD7D8F58178}, // 1e-241
147 {0xFB1E4A9A90880A64, 0xD5605FCDCF32E1D6}, // 1e-240
148 {0x5CF2EEA09A55067F, 0x855C3BE0A17FCD26}, // 1e-239
149 {0xF42FAA48C0EA481E, 0xA6B34AD8C9DFC06F}, // 1e-238
150 {0xF13B94DAF124DA26, 0xD0601D8EFC57B08B}, // 1e-237
151 {0x76C53D08D6B70858, 0x823C12795DB6CE57}, // 1e-236
152 {0x54768C4B0C64CA6E, 0xA2CB1717B52481ED}, // 1e-235
153 {0xA9942F5DCF7DFD09, 0xCB7DDCDDA26DA268}, // 1e-234
154 {0xD3F93B35435D7C4C, 0xFE5D54150B090B02}, // 1e-233
155 {0xC47BC5014A1A6DAF, 0x9EFA548D26E5A6E1}, // 1e-232
156 {0x359AB6419CA1091B, 0xC6B8E9B0709F109A}, // 1e-231
157 {0xC30163D203C94B62, 0xF867241C8CC6D4C0}, // 1e-230
158 {0x79E0DE63425DCF1D, 0x9B407691D7FC44F8}, // 1e-229
159 {0x985915FC12F542E4, 0xC21094364DFB5636}, // 1e-228
160 {0x3E6F5B7B17B2939D, 0xF294B943E17A2BC4}, // 1e-227
161 {0xA705992CEECF9C42, 0x979CF3CA6CEC5B5A}, // 1e-226
162 {0x50C6FF782A838353, 0xBD8430BD08277231}, // 1e-225
163 {0xA4F8BF5635246428, 0xECE53CEC4A314EBD}, // 1e-224
164 {0x871B7795E136BE99, 0x940F4613AE5ED136}, // 1e-223
165 {0x28E2557B59846E3F, 0xB913179899F68584}, // 1e-222
166 {0x331AEADA2FE589CF, 0xE757DD7EC07426E5}, // 1e-221
167 {0x3FF0D2C85DEF7621, 0x9096EA6F3848984F}, // 1e-220
168 {0x0FED077A756B53A9, 0xB4BCA50B065ABE63}, // 1e-219
169 {0xD3E8495912C62894, 0xE1EBCE4DC7F16DFB}, // 1e-218
170 {0x64712DD7ABBBD95C, 0x8D3360F09CF6E4BD}, // 1e-217
171 {0xBD8D794D96AACFB3, 0xB080392CC4349DEC}, // 1e-216
172 {0xECF0D7A0FC5583A0, 0xDCA04777F541C567}, // 1e-215
173 {0xF41686C49DB57244, 0x89E42CAAF9491B60}, // 1e-214
174 {0x311C2875C522CED5, 0xAC5D37D5B79B6239}, // 1e-213
175 {0x7D633293366B828B, 0xD77485CB25823AC7}, // 1e-212
176 {0xAE5DFF9C02033197, 0x86A8D39EF77164BC}, // 1e-211
177 {0xD9F57F830283FDFC, 0xA8530886B54DBDEB}, // 1e-210
178 {0xD072DF63C324FD7B, 0xD267CAA862A12D66}, // 1e-209
179 {0x4247CB9E59F71E6D, 0x8380DEA93DA4BC60}, // 1e-208
180 {0x52D9BE85F074E608, 0xA46116538D0DEB78}, // 1e-207
181 {0x67902E276C921F8B, 0xCD795BE870516656}, // 1e-206
182 {0x00BA1CD8A3DB53B6, 0x806BD9714632DFF6}, // 1e-205
183 {0x80E8A40ECCD228A4, 0xA086CFCD97BF97F3}, // 1e-204
184 {0x6122CD128006B2CD, 0xC8A883C0FDAF7DF0}, // 1e-203
185 {0x796B805720085F81, 0xFAD2A4B13D1B5D6C}, // 1e-202
186 {0xCBE3303674053BB0, 0x9CC3A6EEC6311A63}, // 1e-201
187 {0xBEDBFC4411068A9C, 0xC3F490AA77BD60FC}, // 1e-200
188 {0xEE92FB5515482D44, 0xF4F1B4D515ACB93B}, // 1e-199
189 {0x751BDD152D4D1C4A, 0x991711052D8BF3C5}, // 1e-198
190 {0xD262D45A78A0635D, 0xBF5CD54678EEF0B6}, // 1e-197
191 {0x86FB897116C87C34, 0xEF340A98172AACE4}, // 1e-196
192 {0xD45D35E6AE3D4DA0, 0x9580869F0E7AAC0E}, // 1e-195
193 {0x8974836059CCA109, 0xBAE0A846D2195712}, // 1e-194
194 {0x2BD1A438703FC94B, 0xE998D258869FACD7}, // 1e-193
195 {0x7B6306A34627DDCF, 0x91FF83775423CC06}, // 1e-192
196 {0x1A3BC84C17B1D542, 0xB67F6455292CBF08}, // 1e-191
197 {0x20CABA5F1D9E4A93, 0xE41F3D6A7377EECA}, // 1e-190
198 {0x547EB47B7282EE9C, 0x8E938662882AF53E}, // 1e-189
199 {0xE99E619A4F23AA43, 0xB23867FB2A35B28D}, // 1e-188
200 {0x6405FA00E2EC94D4, 0xDEC681F9F4C31F31}, // 1e-187
201 {0xDE83BC408DD3DD04, 0x8B3C113C38F9F37E}, // 1e-186
202 {0x9624AB50B148D445, 0xAE0B158B4738705E}, // 1e-185
203 {0x3BADD624DD9B0957, 0xD98DDAEE19068C76}, // 1e-184
204 {0xE54CA5D70A80E5D6, 0x87F8A8D4CFA417C9}, // 1e-183
205 {0x5E9FCF4CCD211F4C, 0xA9F6D30A038D1DBC}, // 1e-182
206 {0x7647C3200069671F, 0xD47487CC8470652B}, // 1e-181
207 {0x29ECD9F40041E073, 0x84C8D4DFD2C63F3B}, // 1e-180
208 {0xF468107100525890, 0xA5FB0A17C777CF09}, // 1e-179
209 {0x7182148D4066EEB4, 0xCF79CC9DB955C2CC}, // 1e-178
210 {0xC6F14CD848405530, 0x81AC1FE293D599BF}, // 1e-177
211 {0xB8ADA00E5A506A7C, 0xA21727DB38CB002F}, // 1e-176
212 {0xA6D90811F0E4851C, 0xCA9CF1D206FDC03B}, // 1e-175
213 {0x908F4A166D1DA663, 0xFD442E4688BD304A}, // 1e-174
214 {0x9A598E4E043287FE, 0x9E4A9CEC15763E2E}, // 1e-173
215 {0x40EFF1E1853F29FD, 0xC5DD44271AD3CDBA}, // 1e-172
216 {0xD12BEE59E68EF47C, 0xF7549530E188C128}, // 1e-171
217 {0x82BB74F8301958CE, 0x9A94DD3E8CF578B9}, // 1e-170
218 {0xE36A52363C1FAF01, 0xC13A148E3032D6E7}, // 1e-169
219 {0xDC44E6C3CB279AC1, 0xF18899B1BC3F8CA1}, // 1e-168
220 {0x29AB103A5EF8C0B9, 0x96F5600F15A7B7E5}, // 1e-167
221 {0x7415D448F6B6F0E7, 0xBCB2B812DB11A5DE}, // 1e-166
222 {0x111B495B3464AD21, 0xEBDF661791D60F56}, // 1e-165
223 {0xCAB10DD900BEEC34, 0x936B9FCEBB25C995}, // 1e-164
224 {0x3D5D514F40EEA742, 0xB84687C269EF3BFB}, // 1e-163
225 {0x0CB4A5A3112A5112, 0xE65829B3046B0AFA}, // 1e-162
226 {0x47F0E785EABA72AB, 0x8FF71A0FE2C2E6DC}, // 1e-161
227 {0x59ED216765690F56, 0xB3F4E093DB73A093}, // 1e-160
228 {0x306869C13EC3532C, 0xE0F218B8D25088B8}, // 1e-159
229 {0x1E414218C73A13FB, 0x8C974F7383725573}, // 1e-158
230 {0xE5D1929EF90898FA, 0xAFBD2350644EEACF}, // 1e-157
231 {0xDF45F746B74ABF39, 0xDBAC6C247D62A583}, // 1e-156
232 {0x6B8BBA8C328EB783, 0x894BC396CE5DA772}, // 1e-155
233 {0x066EA92F3F326564, 0xAB9EB47C81F5114F}, // 1e-154
234 {0xC80A537B0EFEFEBD, 0xD686619BA27255A2}, // 1e-153
235 {0xBD06742CE95F5F36, 0x8613FD0145877585}, // 1e-152
236 {0x2C48113823B73704, 0xA798FC4196E952E7}, // 1e-151
237 {0xF75A15862CA504C5, 0xD17F3B51FCA3A7A0}, // 1e-150
238 {0x9A984D73DBE722FB, 0x82EF85133DE648C4}, // 1e-149
239 {0xC13E60D0D2E0EBBA, 0xA3AB66580D5FDAF5}, // 1e-148
240 {0x318DF905079926A8, 0xCC963FEE10B7D1B3}, // 1e-147
241 {0xFDF17746497F7052, 0xFFBBCFE994E5C61F}, // 1e-146
242 {0xFEB6EA8BEDEFA633, 0x9FD561F1FD0F9BD3}, // 1e-145
243 {0xFE64A52EE96B8FC0, 0xC7CABA6E7C5382C8}, // 1e-144
244 {0x3DFDCE7AA3C673B0, 0xF9BD690A1B68637B}, // 1e-143
245 {0x06BEA10CA65C084E, 0x9C1661A651213E2D}, // 1e-142
246 {0x486E494FCFF30A62, 0xC31BFA0FE5698DB8}, // 1e-141
247 {0x5A89DBA3C3EFCCFA, 0xF3E2F893DEC3F126}, // 1e-140
248 {0xF89629465A75E01C, 0x986DDB5C6B3A76B7}, // 1e-139
249 {0xF6BBB397F1135823, 0xBE89523386091465}, // 1e-138
250 {0x746AA07DED582E2C, 0xEE2BA6C0678B597F}, // 1e-137
251 {0xA8C2A44EB4571CDC, 0x94DB483840B717EF}, // 1e-136
252 {0x92F34D62616CE413, 0xBA121A4650E4DDEB}, // 1e-135
253 {0x77B020BAF9C81D17, 0xE896A0D7E51E1566}, // 1e-134
254 {0x0ACE1474DC1D122E, 0x915E2486EF32CD60}, // 1e-133
255 {0x0D819992132456BA, 0xB5B5ADA8AAFF80B8}, // 1e-132
256 {0x10E1FFF697ED6C69, 0xE3231912D5BF60E6}, // 1e-131
257 {0xCA8D3FFA1EF463C1, 0x8DF5EFABC5979C8F}, // 1e-130
258 {0xBD308FF8A6B17CB2, 0xB1736B96B6FD83B3}, // 1e-129
259 {0xAC7CB3F6D05DDBDE, 0xDDD0467C64BCE4A0}, // 1e-128
260 {0x6BCDF07A423AA96B, 0x8AA22C0DBEF60EE4}, // 1e-127
261 {0x86C16C98D2C953C6, 0xAD4AB7112EB3929D}, // 1e-126
262 {0xE871C7BF077BA8B7, 0xD89D64D57A607744}, // 1e-125
263 {0x11471CD764AD4972, 0x87625F056C7C4A8B}, // 1e-124
264 {0xD598E40D3DD89BCF, 0xA93AF6C6C79B5D2D}, // 1e-123
265 {0x4AFF1D108D4EC2C3, 0xD389B47879823479}, // 1e-122
266 {0xCEDF722A585139BA, 0x843610CB4BF160CB}, // 1e-121
267 {0xC2974EB4EE658828, 0xA54394FE1EEDB8FE}, // 1e-120
268 {0x733D226229FEEA32, 0xCE947A3DA6A9273E}, // 1e-119
269 {0x0806357D5A3F525F, 0x811CCC668829B887}, // 1e-118
270 {0xCA07C2DCB0CF26F7, 0xA163FF802A3426A8}, // 1e-117
271 {0xFC89B393DD02F0B5, 0xC9BCFF6034C13052}, // 1e-116
272 {0xBBAC2078D443ACE2, 0xFC2C3F3841F17C67}, // 1e-115
273 {0xD54B944B84AA4C0D, 0x9D9BA7832936EDC0}, // 1e-114
274 {0x0A9E795E65D4DF11, 0xC5029163F384A931}, // 1e-113
275 {0x4D4617B5FF4A16D5, 0xF64335BCF065D37D}, // 1e-112
276 {0x504BCED1BF8E4E45, 0x99EA0196163FA42E}, // 1e-111
277 {0xE45EC2862F71E1D6, 0xC06481FB9BCF8D39}, // 1e-110
278 {0x5D767327BB4E5A4C, 0xF07DA27A82C37088}, // 1e-109
279 {0x3A6A07F8D510F86F, 0x964E858C91BA2655}, // 1e-108
280 {0x890489F70A55368B, 0xBBE226EFB628AFEA}, // 1e-107
281 {0x2B45AC74CCEA842E, 0xEADAB0ABA3B2DBE5}, // 1e-106
282 {0x3B0B8BC90012929D, 0x92C8AE6B464FC96F}, // 1e-105
283 {0x09CE6EBB40173744, 0xB77ADA0617E3BBCB}, // 1e-104
284 {0xCC420A6A101D0515, 0xE55990879DDCAABD}, // 1e-103
285 {0x9FA946824A12232D, 0x8F57FA54C2A9EAB6}, // 1e-102
286 {0x47939822DC96ABF9, 0xB32DF8E9F3546564}, // 1e-101
287 {0x59787E2B93BC56F7, 0xDFF9772470297EBD}, // 1e-100
288 {0x57EB4EDB3C55B65A, 0x8BFBEA76C619EF36}, // 1e-99
289 {0xEDE622920B6B23F1, 0xAEFAE51477A06B03}, // 1e-98
290 {0xE95FAB368E45ECED, 0xDAB99E59958885C4}, // 1e-97
291 {0x11DBCB0218EBB414, 0x88B402F7FD75539B}, // 1e-96
292 {0xD652BDC29F26A119, 0xAAE103B5FCD2A881}, // 1e-95
293 {0x4BE76D3346F0495F, 0xD59944A37C0752A2}, // 1e-94
294 {0x6F70A4400C562DDB, 0x857FCAE62D8493A5}, // 1e-93
295 {0xCB4CCD500F6BB952, 0xA6DFBD9FB8E5B88E}, // 1e-92
296 {0x7E2000A41346A7A7, 0xD097AD07A71F26B2}, // 1e-91
297 {0x8ED400668C0C28C8, 0x825ECC24C873782F}, // 1e-90
298 {0x728900802F0F32FA, 0xA2F67F2DFA90563B}, // 1e-89
299 {0x4F2B40A03AD2FFB9, 0xCBB41EF979346BCA}, // 1e-88
300 {0xE2F610C84987BFA8, 0xFEA126B7D78186BC}, // 1e-87
301 {0x0DD9CA7D2DF4D7C9, 0x9F24B832E6B0F436}, // 1e-86
302 {0x91503D1C79720DBB, 0xC6EDE63FA05D3143}, // 1e-85
303 {0x75A44C6397CE912A, 0xF8A95FCF88747D94}, // 1e-84
304 {0xC986AFBE3EE11ABA, 0x9B69DBE1B548CE7C}, // 1e-83
305 {0xFBE85BADCE996168, 0xC24452DA229B021B}, // 1e-82
306 {0xFAE27299423FB9C3, 0xF2D56790AB41C2A2}, // 1e-81
307 {0xDCCD879FC967D41A, 0x97C560BA6B0919A5}, // 1e-80
308 {0x5400E987BBC1C920, 0xBDB6B8E905CB600F}, // 1e-79
309 {0x290123E9AAB23B68, 0xED246723473E3813}, // 1e-78
310 {0xF9A0B6720AAF6521, 0x9436C0760C86E30B}, // 1e-77
311 {0xF808E40E8D5B3E69, 0xB94470938FA89BCE}, // 1e-76
312 {0xB60B1D1230B20E04, 0xE7958CB87392C2C2}, // 1e-75
313 {0xB1C6F22B5E6F48C2, 0x90BD77F3483BB9B9}, // 1e-74
314 {0x1E38AEB6360B1AF3, 0xB4ECD5F01A4AA828}, // 1e-73
315 {0x25C6DA63C38DE1B0, 0xE2280B6C20DD5232}, // 1e-72
316 {0x579C487E5A38AD0E, 0x8D590723948A535F}, // 1e-71
317 {0x2D835A9DF0C6D851, 0xB0AF48EC79ACE837}, // 1e-70
318 {0xF8E431456CF88E65, 0xDCDB1B2798182244}, // 1e-69
319 {0x1B8E9ECB641B58FF, 0x8A08F0F8BF0F156B}, // 1e-68
320 {0xE272467E3D222F3F, 0xAC8B2D36EED2DAC5}, // 1e-67
321 {0x5B0ED81DCC6ABB0F, 0xD7ADF884AA879177}, // 1e-66
322 {0x98E947129FC2B4E9, 0x86CCBB52EA94BAEA}, // 1e-65
323 {0x3F2398D747B36224, 0xA87FEA27A539E9A5}, // 1e-64
324 {0x8EEC7F0D19A03AAD, 0xD29FE4B18E88640E}, // 1e-63
325 {0x1953CF68300424AC, 0x83A3EEEEF9153E89}, // 1e-62
326 {0x5FA8C3423C052DD7, 0xA48CEAAAB75A8E2B}, // 1e-61
327 {0x3792F412CB06794D, 0xCDB02555653131B6}, // 1e-60
328 {0xE2BBD88BBEE40BD0, 0x808E17555F3EBF11}, // 1e-59
329 {0x5B6ACEAEAE9D0EC4, 0xA0B19D2AB70E6ED6}, // 1e-58
330 {0xF245825A5A445275, 0xC8DE047564D20A8B}, // 1e-57
331 {0xEED6E2F0F0D56712, 0xFB158592BE068D2E}, // 1e-56
332 {0x55464DD69685606B, 0x9CED737BB6C4183D}, // 1e-55
333 {0xAA97E14C3C26B886, 0xC428D05AA4751E4C}, // 1e-54
334 {0xD53DD99F4B3066A8, 0xF53304714D9265DF}, // 1e-53
335 {0xE546A8038EFE4029, 0x993FE2C6D07B7FAB}, // 1e-52
336 {0xDE98520472BDD033, 0xBF8FDB78849A5F96}, // 1e-51
337 {0x963E66858F6D4440, 0xEF73D256A5C0F77C}, // 1e-50
338 {0xDDE7001379A44AA8, 0x95A8637627989AAD}, // 1e-49
339 {0x5560C018580D5D52, 0xBB127C53B17EC159}, // 1e-48
340 {0xAAB8F01E6E10B4A6, 0xE9D71B689DDE71AF}, // 1e-47
341 {0xCAB3961304CA70E8, 0x9226712162AB070D}, // 1e-46
342 {0x3D607B97C5FD0D22, 0xB6B00D69BB55C8D1}, // 1e-45
343 {0x8CB89A7DB77C506A, 0xE45C10C42A2B3B05}, // 1e-44
344 {0x77F3608E92ADB242, 0x8EB98A7A9A5B04E3}, // 1e-43
345 {0x55F038B237591ED3, 0xB267ED1940F1C61C}, // 1e-42
346 {0x6B6C46DEC52F6688, 0xDF01E85F912E37A3}, // 1e-41
347 {0x2323AC4B3B3DA015, 0x8B61313BBABCE2C6}, // 1e-40
348 {0xABEC975E0A0D081A, 0xAE397D8AA96C1B77}, // 1e-39
349 {0x96E7BD358C904A21, 0xD9C7DCED53C72255}, // 1e-38
350 {0x7E50D64177DA2E54, 0x881CEA14545C7575}, // 1e-37
351 {0xDDE50BD1D5D0B9E9, 0xAA242499697392D2}, // 1e-36
352 {0x955E4EC64B44E864, 0xD4AD2DBFC3D07787}, // 1e-35
353 {0xBD5AF13BEF0B113E, 0x84EC3C97DA624AB4}, // 1e-34
354 {0xECB1AD8AEACDD58E, 0xA6274BBDD0FADD61}, // 1e-33
355 {0x67DE18EDA5814AF2, 0xCFB11EAD453994BA}, // 1e-32
356 {0x80EACF948770CED7, 0x81CEB32C4B43FCF4}, // 1e-31
357 {0xA1258379A94D028D, 0xA2425FF75E14FC31}, // 1e-30
358 {0x096EE45813A04330, 0xCAD2F7F5359A3B3E}, // 1e-29
359 {0x8BCA9D6E188853FC, 0xFD87B5F28300CA0D}, // 1e-28
360 {0x775EA264CF55347D, 0x9E74D1B791E07E48}, // 1e-27
361 {0x95364AFE032A819D, 0xC612062576589DDA}, // 1e-26
362 {0x3A83DDBD83F52204, 0xF79687AED3EEC551}, // 1e-25
363 {0xC4926A9672793542, 0x9ABE14CD44753B52}, // 1e-24
364 {0x75B7053C0F178293, 0xC16D9A0095928A27}, // 1e-23
365 {0x5324C68B12DD6338, 0xF1C90080BAF72CB1}, // 1e-22
366 {0xD3F6FC16EBCA5E03, 0x971DA05074DA7BEE}, // 1e-21
367 {0x88F4BB1CA6BCF584, 0xBCE5086492111AEA}, // 1e-20
368 {0x2B31E9E3D06C32E5, 0xEC1E4A7DB69561A5}, // 1e-19
369 {0x3AFF322E62439FCF, 0x9392EE8E921D5D07}, // 1e-18
370 {0x09BEFEB9FAD487C2, 0xB877AA3236A4B449}, // 1e-17
371 {0x4C2EBE687989A9B3, 0xE69594BEC44DE15B}, // 1e-16
372 {0x0F9D37014BF60A10, 0x901D7CF73AB0ACD9}, // 1e-15
373 {0x538484C19EF38C94, 0xB424DC35095CD80F}, // 1e-14
374 {0x2865A5F206B06FB9, 0xE12E13424BB40E13}, // 1e-13
375 {0xF93F87B7442E45D3, 0x8CBCCC096F5088CB}, // 1e-12
376 {0xF78F69A51539D748, 0xAFEBFF0BCB24AAFE}, // 1e-11
377 {0xB573440E5A884D1B, 0xDBE6FECEBDEDD5BE}, // 1e-10
378 {0x31680A88F8953030, 0x89705F4136B4A597}, // 1e-9
379 {0xFDC20D2B36BA7C3D, 0xABCC77118461CEFC}, // 1e-8
380 {0x3D32907604691B4C, 0xD6BF94D5E57A42BC}, // 1e-7
381 {0xA63F9A49C2C1B10F, 0x8637BD05AF6C69B5}, // 1e-6
382 {0x0FCF80DC33721D53, 0xA7C5AC471B478423}, // 1e-5
383 {0xD3C36113404EA4A8, 0xD1B71758E219652B}, // 1e-4
384 {0x645A1CAC083126E9, 0x83126E978D4FDF3B}, // 1e-3
385 {0x3D70A3D70A3D70A3, 0xA3D70A3D70A3D70A}, // 1e-2
386 {0xCCCCCCCCCCCCCCCC, 0xCCCCCCCCCCCCCCCC}, // 1e-1
387 {0x0000000000000000, 0x8000000000000000}, // 1e0
388 {0x0000000000000000, 0xA000000000000000}, // 1e1
389 {0x0000000000000000, 0xC800000000000000}, // 1e2
390 {0x0000000000000000, 0xFA00000000000000}, // 1e3
391 {0x0000000000000000, 0x9C40000000000000}, // 1e4
392 {0x0000000000000000, 0xC350000000000000}, // 1e5
393 {0x0000000000000000, 0xF424000000000000}, // 1e6
394 {0x0000000000000000, 0x9896800000000000}, // 1e7
395 {0x0000000000000000, 0xBEBC200000000000}, // 1e8
396 {0x0000000000000000, 0xEE6B280000000000}, // 1e9
397 {0x0000000000000000, 0x9502F90000000000}, // 1e10
398 {0x0000000000000000, 0xBA43B74000000000}, // 1e11
399 {0x0000000000000000, 0xE8D4A51000000000}, // 1e12
400 {0x0000000000000000, 0x9184E72A00000000}, // 1e13
401 {0x0000000000000000, 0xB5E620F480000000}, // 1e14
402 {0x0000000000000000, 0xE35FA931A0000000}, // 1e15
403 {0x0000000000000000, 0x8E1BC9BF04000000}, // 1e16
404 {0x0000000000000000, 0xB1A2BC2EC5000000}, // 1e17
405 {0x0000000000000000, 0xDE0B6B3A76400000}, // 1e18
406 {0x0000000000000000, 0x8AC7230489E80000}, // 1e19
407 {0x0000000000000000, 0xAD78EBC5AC620000}, // 1e20
408 {0x0000000000000000, 0xD8D726B7177A8000}, // 1e21
409 {0x0000000000000000, 0x878678326EAC9000}, // 1e22
410 {0x0000000000000000, 0xA968163F0A57B400}, // 1e23
411 {0x0000000000000000, 0xD3C21BCECCEDA100}, // 1e24
412 {0x0000000000000000, 0x84595161401484A0}, // 1e25
413 {0x0000000000000000, 0xA56FA5B99019A5C8}, // 1e26
414 {0x0000000000000000, 0xCECB8F27F4200F3A}, // 1e27
415 {0x4000000000000000, 0x813F3978F8940984}, // 1e28
416 {0x5000000000000000, 0xA18F07D736B90BE5}, // 1e29
417 {0xA400000000000000, 0xC9F2C9CD04674EDE}, // 1e30
418 {0x4D00000000000000, 0xFC6F7C4045812296}, // 1e31
419 {0xF020000000000000, 0x9DC5ADA82B70B59D}, // 1e32
420 {0x6C28000000000000, 0xC5371912364CE305}, // 1e33
421 {0xC732000000000000, 0xF684DF56C3E01BC6}, // 1e34
422 {0x3C7F400000000000, 0x9A130B963A6C115C}, // 1e35
423 {0x4B9F100000000000, 0xC097CE7BC90715B3}, // 1e36
424 {0x1E86D40000000000, 0xF0BDC21ABB48DB20}, // 1e37
425 {0x1314448000000000, 0x96769950B50D88F4}, // 1e38
426 {0x17D955A000000000, 0xBC143FA4E250EB31}, // 1e39
427 {0x5DCFAB0800000000, 0xEB194F8E1AE525FD}, // 1e40
428 {0x5AA1CAE500000000, 0x92EFD1B8D0CF37BE}, // 1e41
429 {0xF14A3D9E40000000, 0xB7ABC627050305AD}, // 1e42
430 {0x6D9CCD05D0000000, 0xE596B7B0C643C719}, // 1e43
431 {0xE4820023A2000000, 0x8F7E32CE7BEA5C6F}, // 1e44
432 {0xDDA2802C8A800000, 0xB35DBF821AE4F38B}, // 1e45
433 {0xD50B2037AD200000, 0xE0352F62A19E306E}, // 1e46
434 {0x4526F422CC340000, 0x8C213D9DA502DE45}, // 1e47
435 {0x9670B12B7F410000, 0xAF298D050E4395D6}, // 1e48
436 {0x3C0CDD765F114000, 0xDAF3F04651D47B4C}, // 1e49
437 {0xA5880A69FB6AC800, 0x88D8762BF324CD0F}, // 1e50
438 {0x8EEA0D047A457A00, 0xAB0E93B6EFEE0053}, // 1e51
439 {0x72A4904598D6D880, 0xD5D238A4ABE98068}, // 1e52
440 {0x47A6DA2B7F864750, 0x85A36366EB71F041}, // 1e53
441 {0x999090B65F67D924, 0xA70C3C40A64E6C51}, // 1e54
442 {0xFFF4B4E3F741CF6D, 0xD0CF4B50CFE20765}, // 1e55
443 {0xBFF8F10E7A8921A4, 0x82818F1281ED449F}, // 1e56
444 {0xAFF72D52192B6A0D, 0xA321F2D7226895C7}, // 1e57
445 {0x9BF4F8A69F764490, 0xCBEA6F8CEB02BB39}, // 1e58
446 {0x02F236D04753D5B4, 0xFEE50B7025C36A08}, // 1e59
447 {0x01D762422C946590, 0x9F4F2726179A2245}, // 1e60
448 {0x424D3AD2B7B97EF5, 0xC722F0EF9D80AAD6}, // 1e61
449 {0xD2E0898765A7DEB2, 0xF8EBAD2B84E0D58B}, // 1e62
450 {0x63CC55F49F88EB2F, 0x9B934C3B330C8577}, // 1e63
451 {0x3CBF6B71C76B25FB, 0xC2781F49FFCFA6D5}, // 1e64
452 {0x8BEF464E3945EF7A, 0xF316271C7FC3908A}, // 1e65
453 {0x97758BF0E3CBB5AC, 0x97EDD871CFDA3A56}, // 1e66
454 {0x3D52EEED1CBEA317, 0xBDE94E8E43D0C8EC}, // 1e67
455 {0x4CA7AAA863EE4BDD, 0xED63A231D4C4FB27}, // 1e68
456 {0x8FE8CAA93E74EF6A, 0x945E455F24FB1CF8}, // 1e69
457 {0xB3E2FD538E122B44, 0xB975D6B6EE39E436}, // 1e70
458 {0x60DBBCA87196B616, 0xE7D34C64A9C85D44}, // 1e71
459 {0xBC8955E946FE31CD, 0x90E40FBEEA1D3A4A}, // 1e72
460 {0x6BABAB6398BDBE41, 0xB51D13AEA4A488DD}, // 1e73
461 {0xC696963C7EED2DD1, 0xE264589A4DCDAB14}, // 1e74
462 {0xFC1E1DE5CF543CA2, 0x8D7EB76070A08AEC}, // 1e75
463 {0x3B25A55F43294BCB, 0xB0DE65388CC8ADA8}, // 1e76
464 {0x49EF0EB713F39EBE, 0xDD15FE86AFFAD912}, // 1e77
465 {0x6E3569326C784337, 0x8A2DBF142DFCC7AB}, // 1e78
466 {0x49C2C37F07965404, 0xACB92ED9397BF996}, // 1e79
467 {0xDC33745EC97BE906, 0xD7E77A8F87DAF7FB}, // 1e80
468 {0x69A028BB3DED71A3, 0x86F0AC99B4E8DAFD}, // 1e81
469 {0xC40832EA0D68CE0C, 0xA8ACD7C0222311BC}, // 1e82
470 {0xF50A3FA490C30190, 0xD2D80DB02AABD62B}, // 1e83
471 {0x792667C6DA79E0FA, 0x83C7088E1AAB65DB}, // 1e84
472 {0x577001B891185938, 0xA4B8CAB1A1563F52}, // 1e85
473 {0xED4C0226B55E6F86, 0xCDE6FD5E09ABCF26}, // 1e86
474 {0x544F8158315B05B4, 0x80B05E5AC60B6178}, // 1e87
475 {0x696361AE3DB1C721, 0xA0DC75F1778E39D6}, // 1e88
476 {0x03BC3A19CD1E38E9, 0xC913936DD571C84C}, // 1e89
477 {0x04AB48A04065C723, 0xFB5878494ACE3A5F}, // 1e90
478 {0x62EB0D64283F9C76, 0x9D174B2DCEC0E47B}, // 1e91
479 {0x3BA5D0BD324F8394, 0xC45D1DF942711D9A}, // 1e92
480 {0xCA8F44EC7EE36479, 0xF5746577930D6500}, // 1e93
481 {0x7E998B13CF4E1ECB, 0x9968BF6ABBE85F20}, // 1e94
482 {0x9E3FEDD8C321A67E, 0xBFC2EF456AE276E8}, // 1e95
483 {0xC5CFE94EF3EA101E, 0xEFB3AB16C59B14A2}, // 1e96
484 {0xBBA1F1D158724A12, 0x95D04AEE3B80ECE5}, // 1e97
485 {0x2A8A6E45AE8EDC97, 0xBB445DA9CA61281F}, // 1e98
486 {0xF52D09D71A3293BD, 0xEA1575143CF97226}, // 1e99
487 {0x593C2626705F9C56, 0x924D692CA61BE758}, // 1e100
488 {0x6F8B2FB00C77836C, 0xB6E0C377CFA2E12E}, // 1e101
489 {0x0B6DFB9C0F956447, 0xE498F455C38B997A}, // 1e102
490 {0x4724BD4189BD5EAC, 0x8EDF98B59A373FEC}, // 1e103
491 {0x58EDEC91EC2CB657, 0xB2977EE300C50FE7}, // 1e104
492 {0x2F2967B66737E3ED, 0xDF3D5E9BC0F653E1}, // 1e105
493 {0xBD79E0D20082EE74, 0x8B865B215899F46C}, // 1e106
494 {0xECD8590680A3AA11, 0xAE67F1E9AEC07187}, // 1e107
495 {0xE80E6F4820CC9495, 0xDA01EE641A708DE9}, // 1e108
496 {0x3109058D147FDCDD, 0x884134FE908658B2}, // 1e109
497 {0xBD4B46F0599FD415, 0xAA51823E34A7EEDE}, // 1e110
498 {0x6C9E18AC7007C91A, 0xD4E5E2CDC1D1EA96}, // 1e111
499 {0x03E2CF6BC604DDB0, 0x850FADC09923329E}, // 1e112
500 {0x84DB8346B786151C, 0xA6539930BF6BFF45}, // 1e113
501 {0xE612641865679A63, 0xCFE87F7CEF46FF16}, // 1e114
502 {0x4FCB7E8F3F60C07E, 0x81F14FAE158C5F6E}, // 1e115
503 {0xE3BE5E330F38F09D, 0xA26DA3999AEF7749}, // 1e116
504 {0x5CADF5BFD3072CC5, 0xCB090C8001AB551C}, // 1e117
505 {0x73D9732FC7C8F7F6, 0xFDCB4FA002162A63}, // 1e118
506 {0x2867E7FDDCDD9AFA, 0x9E9F11C4014DDA7E}, // 1e119
507 {0xB281E1FD541501B8, 0xC646D63501A1511D}, // 1e120
508 {0x1F225A7CA91A4226, 0xF7D88BC24209A565}, // 1e121
509 {0x3375788DE9B06958, 0x9AE757596946075F}, // 1e122
510 {0x0052D6B1641C83AE, 0xC1A12D2FC3978937}, // 1e123
511 {0xC0678C5DBD23A49A, 0xF209787BB47D6B84}, // 1e124
512 {0xF840B7BA963646E0, 0x9745EB4D50CE6332}, // 1e125
513 {0xB650E5A93BC3D898, 0xBD176620A501FBFF}, // 1e126
514 {0xA3E51F138AB4CEBE, 0xEC5D3FA8CE427AFF}, // 1e127
515 {0xC66F336C36B10137, 0x93BA47C980E98CDF}, // 1e128
516 {0xB80B0047445D4184, 0xB8A8D9BBE123F017}, // 1e129
517 {0xA60DC059157491E5, 0xE6D3102AD96CEC1D}, // 1e130
518 {0x87C89837AD68DB2F, 0x9043EA1AC7E41392}, // 1e131
519 {0x29BABE4598C311FB, 0xB454E4A179DD1877}, // 1e132
520 {0xF4296DD6FEF3D67A, 0xE16A1DC9D8545E94}, // 1e133
521 {0x1899E4A65F58660C, 0x8CE2529E2734BB1D}, // 1e134
522 {0x5EC05DCFF72E7F8F, 0xB01AE745B101E9E4}, // 1e135
523 {0x76707543F4FA1F73, 0xDC21A1171D42645D}, // 1e136
524 {0x6A06494A791C53A8, 0x899504AE72497EBA}, // 1e137
525 {0x0487DB9D17636892, 0xABFA45DA0EDBDE69}, // 1e138
526 {0x45A9D2845D3C42B6, 0xD6F8D7509292D603}, // 1e139
527 {0x0B8A2392BA45A9B2, 0x865B86925B9BC5C2}, // 1e140
528 {0x8E6CAC7768D7141E, 0xA7F26836F282B732}, // 1e141
529 {0x3207D795430CD926, 0xD1EF0244AF2364FF}, // 1e142
530 {0x7F44E6BD49E807B8, 0x8335616AED761F1F}, // 1e143
531 {0x5F16206C9C6209A6, 0xA402B9C5A8D3A6E7}, // 1e144
532 {0x36DBA887C37A8C0F, 0xCD036837130890A1}, // 1e145
533 {0xC2494954DA2C9789, 0x802221226BE55A64}, // 1e146
534 {0xF2DB9BAA10B7BD6C, 0xA02AA96B06DEB0FD}, // 1e147
535 {0x6F92829494E5ACC7, 0xC83553C5C8965D3D}, // 1e148
536 {0xCB772339BA1F17F9, 0xFA42A8B73ABBF48C}, // 1e149
537 {0xFF2A760414536EFB, 0x9C69A97284B578D7}, // 1e150
538 {0xFEF5138519684ABA, 0xC38413CF25E2D70D}, // 1e151
539 {0x7EB258665FC25D69, 0xF46518C2EF5B8CD1}, // 1e152
540 {0xEF2F773FFBD97A61, 0x98BF2F79D5993802}, // 1e153
541 {0xAAFB550FFACFD8FA, 0xBEEEFB584AFF8603}, // 1e154
542 {0x95BA2A53F983CF38, 0xEEAABA2E5DBF6784}, // 1e155
543 {0xDD945A747BF26183, 0x952AB45CFA97A0B2}, // 1e156
544 {0x94F971119AEEF9E4, 0xBA756174393D88DF}, // 1e157
545 {0x7A37CD5601AAB85D, 0xE912B9D1478CEB17}, // 1e158
546 {0xAC62E055C10AB33A, 0x91ABB422CCB812EE}, // 1e159
547 {0x577B986B314D6009, 0xB616A12B7FE617AA}, // 1e160
548 {0xED5A7E85FDA0B80B, 0xE39C49765FDF9D94}, // 1e161
549 {0x14588F13BE847307, 0x8E41ADE9FBEBC27D}, // 1e162
550 {0x596EB2D8AE258FC8, 0xB1D219647AE6B31C}, // 1e163
551 {0x6FCA5F8ED9AEF3BB, 0xDE469FBD99A05FE3}, // 1e164
552 {0x25DE7BB9480D5854, 0x8AEC23D680043BEE}, // 1e165
553 {0xAF561AA79A10AE6A, 0xADA72CCC20054AE9}, // 1e166
554 {0x1B2BA1518094DA04, 0xD910F7FF28069DA4}, // 1e167
555 {0x90FB44D2F05D0842, 0x87AA9AFF79042286}, // 1e168
556 {0x353A1607AC744A53, 0xA99541BF57452B28}, // 1e169
557 {0x42889B8997915CE8, 0xD3FA922F2D1675F2}, // 1e170
558 {0x69956135FEBADA11, 0x847C9B5D7C2E09B7}, // 1e171
559 {0x43FAB9837E699095, 0xA59BC234DB398C25}, // 1e172
560 {0x94F967E45E03F4BB, 0xCF02B2C21207EF2E}, // 1e173
561 {0x1D1BE0EEBAC278F5, 0x8161AFB94B44F57D}, // 1e174
562 {0x6462D92A69731732, 0xA1BA1BA79E1632DC}, // 1e175
563 {0x7D7B8F7503CFDCFE, 0xCA28A291859BBF93}, // 1e176
564 {0x5CDA735244C3D43E, 0xFCB2CB35E702AF78}, // 1e177
565 {0x3A0888136AFA64A7, 0x9DEFBF01B061ADAB}, // 1e178
566 {0x088AAA1845B8FDD0, 0xC56BAEC21C7A1916}, // 1e179
567 {0x8AAD549E57273D45, 0xF6C69A72A3989F5B}, // 1e180
568 {0x36AC54E2F678864B, 0x9A3C2087A63F6399}, // 1e181
569 {0x84576A1BB416A7DD, 0xC0CB28A98FCF3C7F}, // 1e182
570 {0x656D44A2A11C51D5, 0xF0FDF2D3F3C30B9F}, // 1e183
571 {0x9F644AE5A4B1B325, 0x969EB7C47859E743}, // 1e184
572 {0x873D5D9F0DDE1FEE, 0xBC4665B596706114}, // 1e185
573 {0xA90CB506D155A7EA, 0xEB57FF22FC0C7959}, // 1e186
574 {0x09A7F12442D588F2, 0x9316FF75DD87CBD8}, // 1e187
575 {0x0C11ED6D538AEB2F, 0xB7DCBF5354E9BECE}, // 1e188
576 {0x8F1668C8A86DA5FA, 0xE5D3EF282A242E81}, // 1e189
577 {0xF96E017D694487BC, 0x8FA475791A569D10}, // 1e190
578 {0x37C981DCC395A9AC, 0xB38D92D760EC4455}, // 1e191
579 {0x85BBE253F47B1417, 0xE070F78D3927556A}, // 1e192
580 {0x93956D7478CCEC8E, 0x8C469AB843B89562}, // 1e193
581 {0x387AC8D1970027B2, 0xAF58416654A6BABB}, // 1e194
582 {0x06997B05FCC0319E, 0xDB2E51BFE9D0696A}, // 1e195
583 {0x441FECE3BDF81F03, 0x88FCF317F22241E2}, // 1e196
584 {0xD527E81CAD7626C3, 0xAB3C2FDDEEAAD25A}, // 1e197
585 {0x8A71E223D8D3B074, 0xD60B3BD56A5586F1}, // 1e198
586 {0xF6872D5667844E49, 0x85C7056562757456}, // 1e199
587 {0xB428F8AC016561DB, 0xA738C6BEBB12D16C}, // 1e200
588 {0xE13336D701BEBA52, 0xD106F86E69D785C7}, // 1e201
589 {0xECC0024661173473, 0x82A45B450226B39C}, // 1e202
590 {0x27F002D7F95D0190, 0xA34D721642B06084}, // 1e203
591 {0x31EC038DF7B441F4, 0xCC20CE9BD35C78A5}, // 1e204
592 {0x7E67047175A15271, 0xFF290242C83396CE}, // 1e205
593 {0x0F0062C6E984D386, 0x9F79A169BD203E41}, // 1e206
594 {0x52C07B78A3E60868, 0xC75809C42C684DD1}, // 1e207
595 {0xA7709A56CCDF8A82, 0xF92E0C3537826145}, // 1e208
596 {0x88A66076400BB691, 0x9BBCC7A142B17CCB}, // 1e209
597 {0x6ACFF893D00EA435, 0xC2ABF989935DDBFE}, // 1e210
598 {0x0583F6B8C4124D43, 0xF356F7EBF83552FE}, // 1e211
599 {0xC3727A337A8B704A, 0x98165AF37B2153DE}, // 1e212
600 {0x744F18C0592E4C5C, 0xBE1BF1B059E9A8D6}, // 1e213
601 {0x1162DEF06F79DF73, 0xEDA2EE1C7064130C}, // 1e214
602 {0x8ADDCB5645AC2BA8, 0x9485D4D1C63E8BE7}, // 1e215
603 {0x6D953E2BD7173692, 0xB9A74A0637CE2EE1}, // 1e216
604 {0xC8FA8DB6CCDD0437, 0xE8111C87C5C1BA99}, // 1e217
605 {0x1D9C9892400A22A2, 0x910AB1D4DB9914A0}, // 1e218
606 {0x2503BEB6D00CAB4B, 0xB54D5E4A127F59C8}, // 1e219
607 {0x2E44AE64840FD61D, 0xE2A0B5DC971F303A}, // 1e220
608 {0x5CEAECFED289E5D2, 0x8DA471A9DE737E24}, // 1e221
609 {0x7425A83E872C5F47, 0xB10D8E1456105DAD}, // 1e222
610 {0xD12F124E28F77719, 0xDD50F1996B947518}, // 1e223
611 {0x82BD6B70D99AAA6F, 0x8A5296FFE33CC92F}, // 1e224
612 {0x636CC64D1001550B, 0xACE73CBFDC0BFB7B}, // 1e225
613 {0x3C47F7E05401AA4E, 0xD8210BEFD30EFA5A}, // 1e226
614 {0x65ACFAEC34810A71, 0x8714A775E3E95C78}, // 1e227
615 {0x7F1839A741A14D0D, 0xA8D9D1535CE3B396}, // 1e228
616 {0x1EDE48111209A050, 0xD31045A8341CA07C}, // 1e229
617 {0x934AED0AAB460432, 0x83EA2B892091E44D}, // 1e230
618 {0xF81DA84D5617853F, 0xA4E4B66B68B65D60}, // 1e231
619 {0x36251260AB9D668E, 0xCE1DE40642E3F4B9}, // 1e232
620 {0xC1D72B7C6B426019, 0x80D2AE83E9CE78F3}, // 1e233
621 {0xB24CF65B8612F81F, 0xA1075A24E4421730}, // 1e234
622 {0xDEE033F26797B627, 0xC94930AE1D529CFC}, // 1e235
623 {0x169840EF017DA3B1, 0xFB9B7CD9A4A7443C}, // 1e236
624 {0x8E1F289560EE864E, 0x9D412E0806E88AA5}, // 1e237
625 {0xF1A6F2BAB92A27E2, 0xC491798A08A2AD4E}, // 1e238
626 {0xAE10AF696774B1DB, 0xF5B5D7EC8ACB58A2}, // 1e239
627 {0xACCA6DA1E0A8EF29, 0x9991A6F3D6BF1765}, // 1e240
628 {0x17FD090A58D32AF3, 0xBFF610B0CC6EDD3F}, // 1e241
629 {0xDDFC4B4CEF07F5B0, 0xEFF394DCFF8A948E}, // 1e242
630 {0x4ABDAF101564F98E, 0x95F83D0A1FB69CD9}, // 1e243
631 {0x9D6D1AD41ABE37F1, 0xBB764C4CA7A4440F}, // 1e244
632 {0x84C86189216DC5ED, 0xEA53DF5FD18D5513}, // 1e245
633 {0x32FD3CF5B4E49BB4, 0x92746B9BE2F8552C}, // 1e246
634 {0x3FBC8C33221DC2A1, 0xB7118682DBB66A77}, // 1e247
635 {0x0FABAF3FEAA5334A, 0xE4D5E82392A40515}, // 1e248
636 {0x29CB4D87F2A7400E, 0x8F05B1163BA6832D}, // 1e249
637 {0x743E20E9EF511012, 0xB2C71D5BCA9023F8}, // 1e250
638 {0x914DA9246B255416, 0xDF78E4B2BD342CF6}, // 1e251
639 {0x1AD089B6C2F7548E, 0x8BAB8EEFB6409C1A}, // 1e252
640 {0xA184AC2473B529B1, 0xAE9672ABA3D0C320}, // 1e253
641 {0xC9E5D72D90A2741E, 0xDA3C0F568CC4F3E8}, // 1e254
642 {0x7E2FA67C7A658892, 0x8865899617FB1871}, // 1e255
643 {0xDDBB901B98FEEAB7, 0xAA7EEBFB9DF9DE8D}, // 1e256
644 {0x552A74227F3EA565, 0xD51EA6FA85785631}, // 1e257
645 {0xD53A88958F87275F, 0x8533285C936B35DE}, // 1e258
646 {0x8A892ABAF368F137, 0xA67FF273B8460356}, // 1e259
647 {0x2D2B7569B0432D85, 0xD01FEF10A657842C}, // 1e260
648 {0x9C3B29620E29FC73, 0x8213F56A67F6B29B}, // 1e261
649 {0x8349F3BA91B47B8F, 0xA298F2C501F45F42}, // 1e262
650 {0x241C70A936219A73, 0xCB3F2F7642717713}, // 1e263
651 {0xED238CD383AA0110, 0xFE0EFB53D30DD4D7}, // 1e264
652 {0xF4363804324A40AA, 0x9EC95D1463E8A506}, // 1e265
653 {0xB143C6053EDCD0D5, 0xC67BB4597CE2CE48}, // 1e266
654 {0xDD94B7868E94050A, 0xF81AA16FDC1B81DA}, // 1e267
655 {0xCA7CF2B4191C8326, 0x9B10A4E5E9913128}, // 1e268
656 {0xFD1C2F611F63A3F0, 0xC1D4CE1F63F57D72}, // 1e269
657 {0xBC633B39673C8CEC, 0xF24A01A73CF2DCCF}, // 1e270
658 {0xD5BE0503E085D813, 0x976E41088617CA01}, // 1e271
659 {0x4B2D8644D8A74E18, 0xBD49D14AA79DBC82}, // 1e272
660 {0xDDF8E7D60ED1219E, 0xEC9C459D51852BA2}, // 1e273
661 {0xCABB90E5C942B503, 0x93E1AB8252F33B45}, // 1e274
662 {0x3D6A751F3B936243, 0xB8DA1662E7B00A17}, // 1e275
663 {0x0CC512670A783AD4, 0xE7109BFBA19C0C9D}, // 1e276
664 {0x27FB2B80668B24C5, 0x906A617D450187E2}, // 1e277
665 {0xB1F9F660802DEDF6, 0xB484F9DC9641E9DA}, // 1e278
666 {0x5E7873F8A0396973, 0xE1A63853BBD26451}, // 1e279
667 {0xDB0B487B6423E1E8, 0x8D07E33455637EB2}, // 1e280
668 {0x91CE1A9A3D2CDA62, 0xB049DC016ABC5E5F}, // 1e281
669 {0x7641A140CC7810FB, 0xDC5C5301C56B75F7}, // 1e282
670 {0xA9E904C87FCB0A9D, 0x89B9B3E11B6329BA}, // 1e283
671 {0x546345FA9FBDCD44, 0xAC2820D9623BF429}, // 1e284
672 {0xA97C177947AD4095, 0xD732290FBACAF133}, // 1e285
673 {0x49ED8EABCCCC485D, 0x867F59A9D4BED6C0}, // 1e286
674 {0x5C68F256BFFF5A74, 0xA81F301449EE8C70}, // 1e287
675 {0x73832EEC6FFF3111, 0xD226FC195C6A2F8C}, // 1e288
676 {0xC831FD53C5FF7EAB, 0x83585D8FD9C25DB7}, // 1e289
677 {0xBA3E7CA8B77F5E55, 0xA42E74F3D032F525}, // 1e290
678 {0x28CE1BD2E55F35EB, 0xCD3A1230C43FB26F}, // 1e291
679 {0x7980D163CF5B81B3, 0x80444B5E7AA7CF85}, // 1e292
680 {0xD7E105BCC332621F, 0xA0555E361951C366}, // 1e293
681 {0x8DD9472BF3FEFAA7, 0xC86AB5C39FA63440}, // 1e294
682 {0xB14F98F6F0FEB951, 0xFA856334878FC150}, // 1e295
683 {0x6ED1BF9A569F33D3, 0x9C935E00D4B9D8D2}, // 1e296
684 {0x0A862F80EC4700C8, 0xC3B8358109E84F07}, // 1e297
685 {0xCD27BB612758C0FA, 0xF4A642E14C6262C8}, // 1e298
686 {0x8038D51CB897789C, 0x98E7E9CCCFBD7DBD}, // 1e299
687 {0xE0470A63E6BD56C3, 0xBF21E44003ACDD2C}, // 1e300
688 {0x1858CCFCE06CAC74, 0xEEEA5D5004981478}, // 1e301
689 {0x0F37801E0C43EBC8, 0x95527A5202DF0CCB}, // 1e302
690 {0xD30560258F54E6BA, 0xBAA718E68396CFFD}, // 1e303
691 {0x47C6B82EF32A2069, 0xE950DF20247C83FD}, // 1e304
692 {0x4CDC331D57FA5441, 0x91D28B7416CDD27E}, // 1e305
693 {0xE0133FE4ADF8E952, 0xB6472E511C81471D}, // 1e306
694 {0x58180FDDD97723A6, 0xE3D8F9E563A198E5}, // 1e307
695 {0x570F09EAA7EA7648, 0x8E679C2F5E44FF8F}, // 1e308
696 {0x2CD2CC6551E513DA, 0xB201833B35D63F73}, // 1e309
697 {0xF8077F7EA65E58D1, 0xDE81E40A034BCF4F}, // 1e310
698 {0xFB04AFAF27FAF782, 0x8B112E86420F6191}, // 1e311
699 {0x79C5DB9AF1F9B563, 0xADD57A27D29339F6}, // 1e312
700 {0x18375281AE7822BC, 0xD94AD8B1C7380874}, // 1e313
701 {0x8F2293910D0B15B5, 0x87CEC76F1C830548}, // 1e314
702 {0xB2EB3875504DDB22, 0xA9C2794AE3A3C69A}, // 1e315
703 {0x5FA60692A46151EB, 0xD433179D9C8CB841}, // 1e316
704 {0xDBC7C41BA6BCD333, 0x849FEEC281D7F328}, // 1e317
705 {0x12B9B522906C0800, 0xA5C7EA73224DEFF3}, // 1e318
706 {0xD768226B34870A00, 0xCF39E50FEAE16BEF}, // 1e319
707 {0xE6A1158300D46640, 0x81842F29F2CCE375}, // 1e320
708 {0x60495AE3C1097FD0, 0xA1E53AF46F801C53}, // 1e321
709 {0x385BB19CB14BDFC4, 0xCA5E89B18B602368}, // 1e322
710 {0x46729E03DD9ED7B5, 0xFCF62C1DEE382C42}, // 1e323
711 {0x6C07A2C26A8346D1, 0x9E19DB92B4E31BA9}, // 1e324
712 {0xC7098B7305241885, 0xC5A05277621BE293}, // 1e325
713 {0xB8CBEE4FC66D1EA7, 0xF70867153AA2DB38}, // 1e326
714 {0x737F74F1DC043328, 0x9A65406D44A5C903}, // 1e327
715 {0x505F522E53053FF2, 0xC0FE908895CF3B44}, // 1e328
716 {0x647726B9E7C68FEF, 0xF13E34AABB430A15}, // 1e329
717 {0x5ECA783430DC19F5, 0x96C6E0EAB509E64D}, // 1e330
718 {0xB67D16413D132072, 0xBC789925624C5FE0}, // 1e331
719 {0xE41C5BD18C57E88F, 0xEB96BF6EBADF77D8}, // 1e332
720 {0x8E91B962F7B6F159, 0x933E37A534CBAAE7}, // 1e333
721 {0x723627BBB5A4ADB0, 0xB80DC58E81FE95A1}, // 1e334
722 {0xCEC3B1AAA30DD91C, 0xE61136F2227E3B09}, // 1e335
723 {0x213A4F0AA5E8A7B1, 0x8FCAC257558EE4E6}, // 1e336
724 {0xA988E2CD4F62D19D, 0xB3BD72ED2AF29E1F}, // 1e337
725 {0x93EB1B80A33B8605, 0xE0ACCFA875AF45A7}, // 1e338
726 {0xBC72F130660533C3, 0x8C6C01C9498D8B88}, // 1e339
727 {0xEB8FAD7C7F8680B4, 0xAF87023B9BF0EE6A}, // 1e340
728 {0xA67398DB9F6820E1, 0xDB68C2CA82ED2A05}, // 1e341
729 {0x88083F8943A1148C, 0x892179BE91D43A43}, // 1e342
730 {0x6A0A4F6B948959B0, 0xAB69D82E364948D4}, // 1e343
731 {0x848CE34679ABB01C, 0xD6444E39C3DB9B09}, // 1e344
732 {0xF2D80E0C0C0B4E11, 0x85EAB0E41A6940E5}, // 1e345
733 {0x6F8E118F0F0E2195, 0xA7655D1D2103911F}, // 1e346
734 {0x4B7195F2D2D1A9FB, 0xD13EB46469447567}, // 1e347
735};
736
737} // namespace internal
738} // namespace LIBC_NAMESPACE_DECL
739
740#endif // LLVM_LIBC_SRC___SUPPORT_DETAILED_POWERS_OF_TEN_H
lib/libcxx/libc/src/__support/high_precision_decimal.h created+442
......@@ -0,0 +1,442 @@
1//===-- High Precision Decimal ----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See httpss//llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// -----------------------------------------------------------------------------
10// **** WARNING ****
11// This file is shared with libc++. You should also be careful when adding
12// dependencies to this file, since it needs to build for all libc++ targets.
13// -----------------------------------------------------------------------------
14
15#ifndef LLVM_LIBC_SRC___SUPPORT_HIGH_PRECISION_DECIMAL_H
16#define LLVM_LIBC_SRC___SUPPORT_HIGH_PRECISION_DECIMAL_H
17
18#include "src/__support/CPP/limits.h"
19#include "src/__support/ctype_utils.h"
20#include "src/__support/macros/config.h"
21#include "src/__support/str_to_integer.h"
22#include <stdint.h>
23
24namespace LIBC_NAMESPACE_DECL {
25namespace internal {
26
27struct LShiftTableEntry {
28 uint32_t new_digits;
29 char const *power_of_five;
30};
31
32// -----------------------------------------------------------------------------
33// **** WARNING ****
34// This interface is shared with libc++, if you change this interface you need
35// to update it in both libc and libc++.
36// -----------------------------------------------------------------------------
37// This is used in both this file and in the main str_to_float.h.
38// TODO: Figure out where to put this.
39enum class RoundDirection { Up, Down, Nearest };
40
41// This is based on the HPD data structure described as part of the Simple
42// Decimal Conversion algorithm by Nigel Tao, described at this link:
43// https://nigeltao.github.io/blog/2020/parse-number-f64-simple.html
44class HighPrecisionDecimal {
45
46 // This precomputed table speeds up left shifts by having the number of new
47 // digits that will be added by multiplying 5^i by 2^i. If the number is less
48 // than 5^i then it will add one fewer digit. There are only 60 entries since
49 // that's the max shift amount.
50 // This table was generated by the script at
51 // libc/utils/mathtools/GenerateHPDConstants.py
52 static constexpr LShiftTableEntry LEFT_SHIFT_DIGIT_TABLE[] = {
53 {0, ""},
54 {1, "5"},
55 {1, "25"},
56 {1, "125"},
57 {2, "625"},
58 {2, "3125"},
59 {2, "15625"},
60 {3, "78125"},
61 {3, "390625"},
62 {3, "1953125"},
63 {4, "9765625"},
64 {4, "48828125"},
65 {4, "244140625"},
66 {4, "1220703125"},
67 {5, "6103515625"},
68 {5, "30517578125"},
69 {5, "152587890625"},
70 {6, "762939453125"},
71 {6, "3814697265625"},
72 {6, "19073486328125"},
73 {7, "95367431640625"},
74 {7, "476837158203125"},
75 {7, "2384185791015625"},
76 {7, "11920928955078125"},
77 {8, "59604644775390625"},
78 {8, "298023223876953125"},
79 {8, "1490116119384765625"},
80 {9, "7450580596923828125"},
81 {9, "37252902984619140625"},
82 {9, "186264514923095703125"},
83 {10, "931322574615478515625"},
84 {10, "4656612873077392578125"},
85 {10, "23283064365386962890625"},
86 {10, "116415321826934814453125"},
87 {11, "582076609134674072265625"},
88 {11, "2910383045673370361328125"},
89 {11, "14551915228366851806640625"},
90 {12, "72759576141834259033203125"},
91 {12, "363797880709171295166015625"},
92 {12, "1818989403545856475830078125"},
93 {13, "9094947017729282379150390625"},
94 {13, "45474735088646411895751953125"},
95 {13, "227373675443232059478759765625"},
96 {13, "1136868377216160297393798828125"},
97 {14, "5684341886080801486968994140625"},
98 {14, "28421709430404007434844970703125"},
99 {14, "142108547152020037174224853515625"},
100 {15, "710542735760100185871124267578125"},
101 {15, "3552713678800500929355621337890625"},
102 {15, "17763568394002504646778106689453125"},
103 {16, "88817841970012523233890533447265625"},
104 {16, "444089209850062616169452667236328125"},
105 {16, "2220446049250313080847263336181640625"},
106 {16, "11102230246251565404236316680908203125"},
107 {17, "55511151231257827021181583404541015625"},
108 {17, "277555756156289135105907917022705078125"},
109 {17, "1387778780781445675529539585113525390625"},
110 {18, "6938893903907228377647697925567626953125"},
111 {18, "34694469519536141888238489627838134765625"},
112 {18, "173472347597680709441192448139190673828125"},
113 {19, "867361737988403547205962240695953369140625"},
114 };
115
116 // The maximum amount we can shift is the number of bits used in the
117 // accumulator, minus the number of bits needed to represent the base (in this
118 // case 4).
119 static constexpr uint32_t MAX_SHIFT_AMOUNT = sizeof(uint64_t) - 4;
120
121 // 800 is an arbitrary number of digits, but should be
122 // large enough for any practical number.
123 static constexpr uint32_t MAX_NUM_DIGITS = 800;
124
125 uint32_t num_digits = 0;
126 int32_t decimal_point = 0;
127 bool truncated = false;
128 uint8_t digits[MAX_NUM_DIGITS];
129
130private:
131 LIBC_INLINE bool should_round_up(int32_t round_to_digit,
132 RoundDirection round) {
133 if (round_to_digit < 0 ||
134 static_cast<uint32_t>(round_to_digit) >= this->num_digits) {
135 return false;
136 }
137
138 // The above condition handles all cases where all of the trailing digits
139 // are zero. In that case, if the rounding mode is up, then this number
140 // should be rounded up. Similarly, if the rounding mode is down, then it
141 // should always round down.
142 if (round == RoundDirection::Up) {
143 return true;
144 } else if (round == RoundDirection::Down) {
145 return false;
146 }
147 // Else round to nearest.
148
149 // If we're right in the middle and there are no extra digits
150 if (this->digits[round_to_digit] == 5 &&
151 static_cast<uint32_t>(round_to_digit + 1) == this->num_digits) {
152
153 // Round up if we've truncated (since that means the result is slightly
154 // higher than what's represented.)
155 if (this->truncated) {
156 return true;
157 }
158
159 // If this exactly halfway, round to even.
160 if (round_to_digit == 0)
161 // When the input is ".5".
162 return false;
163 return this->digits[round_to_digit - 1] % 2 != 0;
164 }
165 // If there are digits after round_to_digit, they must be non-zero since we
166 // trim trailing zeroes after all operations that change digits.
167 return this->digits[round_to_digit] >= 5;
168 }
169
170 // Takes an amount to left shift and returns the number of new digits needed
171 // to store the result based on LEFT_SHIFT_DIGIT_TABLE.
172 LIBC_INLINE uint32_t get_num_new_digits(uint32_t lshift_amount) {
173 const char *power_of_five =
174 LEFT_SHIFT_DIGIT_TABLE[lshift_amount].power_of_five;
175 uint32_t new_digits = LEFT_SHIFT_DIGIT_TABLE[lshift_amount].new_digits;
176 uint32_t digit_index = 0;
177 while (power_of_five[digit_index] != 0) {
178 if (digit_index >= this->num_digits) {
179 return new_digits - 1;
180 }
181 if (this->digits[digit_index] !=
182 internal::b36_char_to_int(power_of_five[digit_index])) {
183 return new_digits -
184 ((this->digits[digit_index] <
185 internal::b36_char_to_int(power_of_five[digit_index]))
186 ? 1
187 : 0);
188 }
189 ++digit_index;
190 }
191 return new_digits;
192 }
193
194 // Trim all trailing 0s
195 LIBC_INLINE void trim_trailing_zeroes() {
196 while (this->num_digits > 0 && this->digits[this->num_digits - 1] == 0) {
197 --this->num_digits;
198 }
199 if (this->num_digits == 0) {
200 this->decimal_point = 0;
201 }
202 }
203
204 // Perform a digitwise binary non-rounding right shift on this value by
205 // shift_amount. The shift_amount can't be more than MAX_SHIFT_AMOUNT to
206 // prevent overflow.
207 LIBC_INLINE void right_shift(uint32_t shift_amount) {
208 uint32_t read_index = 0;
209 uint32_t write_index = 0;
210
211 uint64_t accumulator = 0;
212
213 const uint64_t shift_mask = (uint64_t(1) << shift_amount) - 1;
214
215 // Warm Up phase: we don't have enough digits to start writing, so just
216 // read them into the accumulator.
217 while (accumulator >> shift_amount == 0) {
218 uint64_t read_digit = 0;
219 // If there are still digits to read, read the next one, else the digit is
220 // assumed to be 0.
221 if (read_index < this->num_digits) {
222 read_digit = this->digits[read_index];
223 }
224 accumulator = accumulator * 10 + read_digit;
225 ++read_index;
226 }
227
228 // Shift the decimal point by the number of digits it took to fill the
229 // accumulator.
230 this->decimal_point -= read_index - 1;
231
232 // Middle phase: we have enough digits to write, as well as more digits to
233 // read. Keep reading until we run out of digits.
234 while (read_index < this->num_digits) {
235 uint64_t read_digit = this->digits[read_index];
236 uint64_t write_digit = accumulator >> shift_amount;
237 accumulator &= shift_mask;
238 this->digits[write_index] = static_cast<uint8_t>(write_digit);
239 accumulator = accumulator * 10 + read_digit;
240 ++read_index;
241 ++write_index;
242 }
243
244 // Cool Down phase: All of the readable digits have been read, so just write
245 // the remainder, while treating any more digits as 0.
246 while (accumulator > 0) {
247 uint64_t write_digit = accumulator >> shift_amount;
248 accumulator &= shift_mask;
249 if (write_index < MAX_NUM_DIGITS) {
250 this->digits[write_index] = static_cast<uint8_t>(write_digit);
251 ++write_index;
252 } else if (write_digit > 0) {
253 this->truncated = true;
254 }
255 accumulator = accumulator * 10;
256 }
257 this->num_digits = write_index;
258 this->trim_trailing_zeroes();
259 }
260
261 // Perform a digitwise binary non-rounding left shift on this value by
262 // shift_amount. The shift_amount can't be more than MAX_SHIFT_AMOUNT to
263 // prevent overflow.
264 LIBC_INLINE void left_shift(uint32_t shift_amount) {
265 uint32_t new_digits = this->get_num_new_digits(shift_amount);
266
267 int32_t read_index = this->num_digits - 1;
268 uint32_t write_index = this->num_digits + new_digits;
269
270 uint64_t accumulator = 0;
271
272 // No Warm Up phase. Since we're putting digits in at the top and taking
273 // digits from the bottom we don't have to wait for the accumulator to fill.
274
275 // Middle phase: while we have more digits to read, keep reading as well as
276 // writing.
277 while (read_index >= 0) {
278 accumulator += static_cast<uint64_t>(this->digits[read_index])
279 << shift_amount;
280 uint64_t next_accumulator = accumulator / 10;
281 uint64_t write_digit = accumulator - (10 * next_accumulator);
282 --write_index;
283 if (write_index < MAX_NUM_DIGITS) {
284 this->digits[write_index] = static_cast<uint8_t>(write_digit);
285 } else if (write_digit != 0) {
286 this->truncated = true;
287 }
288 accumulator = next_accumulator;
289 --read_index;
290 }
291
292 // Cool Down phase: there are no more digits to read, so just write the
293 // remaining digits in the accumulator.
294 while (accumulator > 0) {
295 uint64_t next_accumulator = accumulator / 10;
296 uint64_t write_digit = accumulator - (10 * next_accumulator);
297 --write_index;
298 if (write_index < MAX_NUM_DIGITS) {
299 this->digits[write_index] = static_cast<uint8_t>(write_digit);
300 } else if (write_digit != 0) {
301 this->truncated = true;
302 }
303 accumulator = next_accumulator;
304 }
305
306 this->num_digits += new_digits;
307 if (this->num_digits > MAX_NUM_DIGITS) {
308 this->num_digits = MAX_NUM_DIGITS;
309 }
310 this->decimal_point += new_digits;
311 this->trim_trailing_zeroes();
312 }
313
314public:
315 // num_string is assumed to be a string of numeric characters. It doesn't
316 // handle leading spaces.
317 LIBC_INLINE
318 HighPrecisionDecimal(
319 const char *__restrict num_string,
320 const size_t num_len = cpp::numeric_limits<size_t>::max()) {
321 bool saw_dot = false;
322 size_t num_cur = 0;
323 // This counts the digits in the number, even if there isn't space to store
324 // them all.
325 uint32_t total_digits = 0;
326 while (num_cur < num_len &&
327 (isdigit(num_string[num_cur]) || num_string[num_cur] == '.')) {
328 if (num_string[num_cur] == '.') {
329 if (saw_dot) {
330 break;
331 }
332 this->decimal_point = total_digits;
333 saw_dot = true;
334 } else {
335 if (num_string[num_cur] == '0' && this->num_digits == 0) {
336 --this->decimal_point;
337 ++num_cur;
338 continue;
339 }
340 ++total_digits;
341 if (this->num_digits < MAX_NUM_DIGITS) {
342 this->digits[this->num_digits] = static_cast<uint8_t>(
343 internal::b36_char_to_int(num_string[num_cur]));
344 ++this->num_digits;
345 } else if (num_string[num_cur] != '0') {
346 this->truncated = true;
347 }
348 }
349 ++num_cur;
350 }
351
352 if (!saw_dot)
353 this->decimal_point = total_digits;
354
355 if (num_cur < num_len &&
356 (num_string[num_cur] == 'e' || num_string[num_cur] == 'E')) {
357 ++num_cur;
358 if (isdigit(num_string[num_cur]) || num_string[num_cur] == '+' ||
359 num_string[num_cur] == '-') {
360 auto result =
361 strtointeger<int32_t>(num_string + num_cur, 10, num_len - num_cur);
362 if (result.has_error()) {
363 // TODO: handle error
364 }
365 int32_t add_to_exponent = result.value;
366
367 // Here we do this operation as int64 to avoid overflow.
368 int64_t temp_exponent = static_cast<int64_t>(this->decimal_point) +
369 static_cast<int64_t>(add_to_exponent);
370
371 // Theoretically these numbers should be MAX_BIASED_EXPONENT for long
372 // double, but that should be ~16,000 which is much less than 1 << 30.
373 if (temp_exponent > (1 << 30)) {
374 temp_exponent = (1 << 30);
375 } else if (temp_exponent < -(1 << 30)) {
376 temp_exponent = -(1 << 30);
377 }
378 this->decimal_point = static_cast<int32_t>(temp_exponent);
379 }
380 }
381
382 this->trim_trailing_zeroes();
383 }
384
385 // Binary shift left (shift_amount > 0) or right (shift_amount < 0)
386 LIBC_INLINE void shift(int shift_amount) {
387 if (shift_amount == 0) {
388 return;
389 }
390 // Left
391 else if (shift_amount > 0) {
392 while (static_cast<uint32_t>(shift_amount) > MAX_SHIFT_AMOUNT) {
393 this->left_shift(MAX_SHIFT_AMOUNT);
394 shift_amount -= MAX_SHIFT_AMOUNT;
395 }
396 this->left_shift(shift_amount);
397 }
398 // Right
399 else {
400 while (static_cast<uint32_t>(shift_amount) < -MAX_SHIFT_AMOUNT) {
401 this->right_shift(MAX_SHIFT_AMOUNT);
402 shift_amount += MAX_SHIFT_AMOUNT;
403 }
404 this->right_shift(-shift_amount);
405 }
406 }
407
408 // Round the number represented to the closest value of unsigned int type T.
409 // This is done ignoring overflow.
410 template <class T>
411 LIBC_INLINE T
412 round_to_integer_type(RoundDirection round = RoundDirection::Nearest) {
413 T result = 0;
414 uint32_t cur_digit = 0;
415
416 while (static_cast<int32_t>(cur_digit) < this->decimal_point &&
417 cur_digit < this->num_digits) {
418 result = result * 10 + (this->digits[cur_digit]);
419 ++cur_digit;
420 }
421
422 // If there are implicit 0s at the end of the number, include those.
423 while (static_cast<int32_t>(cur_digit) < this->decimal_point) {
424 result *= 10;
425 ++cur_digit;
426 }
427 return result + static_cast<unsigned int>(
428 this->should_round_up(this->decimal_point, round));
429 }
430
431 // Extra functions for testing.
432
433 LIBC_INLINE uint8_t *get_digits() { return this->digits; }
434 LIBC_INLINE uint32_t get_num_digits() { return this->num_digits; }
435 LIBC_INLINE int32_t get_decimal_point() { return this->decimal_point; }
436 LIBC_INLINE void set_truncated(bool trunc) { this->truncated = trunc; }
437};
438
439} // namespace internal
440} // namespace LIBC_NAMESPACE_DECL
441
442#endif // LLVM_LIBC_SRC___SUPPORT_HIGH_PRECISION_DECIMAL_H
lib/libcxx/libc/src/__support/libc_assert.h created+88
......@@ -0,0 +1,88 @@
1//===-- Definition of a libc internal assert macro --------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_LIBC_ASSERT_H
10#define LLVM_LIBC_SRC___SUPPORT_LIBC_ASSERT_H
11
12#include "src/__support/macros/config.h"
13#if defined(LIBC_COPT_USE_C_ASSERT) || !defined(LIBC_FULL_BUILD)
14
15// The build is configured to just use the public <assert.h> API
16// for libc's internal assertions.
17
18#include <assert.h>
19
20#define LIBC_ASSERT(COND) assert(COND)
21
22#else // Not LIBC_COPT_USE_C_ASSERT
23
24#include "src/__support/OSUtil/exit.h"
25#include "src/__support/OSUtil/io.h"
26#include "src/__support/integer_to_string.h"
27#include "src/__support/macros/attributes.h" // For LIBC_INLINE
28#include "src/__support/macros/optimization.h" // For LIBC_UNLIKELY
29
30namespace LIBC_NAMESPACE_DECL {
31
32// This is intended to be removed in a future patch to use a similar design to
33// below, but it's necessary for the external assert.
34LIBC_INLINE void report_assertion_failure(const char *assertion,
35 const char *filename, unsigned line,
36 const char *funcname) {
37 const IntegerToString<unsigned> line_buffer(line);
38 write_to_stderr(filename);
39 write_to_stderr(":");
40 write_to_stderr(line_buffer.view());
41 write_to_stderr(": Assertion failed: '");
42 write_to_stderr(assertion);
43 write_to_stderr("' in function: '");
44 write_to_stderr(funcname);
45 write_to_stderr("'\n");
46}
47
48} // namespace LIBC_NAMESPACE_DECL
49
50#ifdef LIBC_ASSERT
51#error "Unexpected: LIBC_ASSERT macro already defined"
52#endif
53
54// The public "assert" macro calls abort on failure. Should it be same here?
55// The libc internal assert can fire from anywhere inside the libc. So, to
56// avoid potential chicken-and-egg problems, it is simple to do an exit
57// on assertion failure instead of calling abort. We also don't want to use
58// __builtin_trap as it could potentially be implemented using illegal
59// instructions which can be very misleading when debugging.
60#ifdef NDEBUG
61#define LIBC_ASSERT(COND) \
62 do { \
63 } while (false)
64#else
65
66// Convert __LINE__ to a string using macros. The indirection is necessary
67// because otherwise it will turn "__LINE__" into a string, not its value. The
68// value is evaluated in the indirection step.
69#define __LIBC_MACRO_TO_STR(x) #x
70#define __LIBC_MACRO_TO_STR_INDIR(y) __LIBC_MACRO_TO_STR(y)
71#define __LIBC_LINE_STR__ __LIBC_MACRO_TO_STR_INDIR(__LINE__)
72
73#define LIBC_ASSERT(COND) \
74 do { \
75 if (LIBC_UNLIKELY(!(COND))) { \
76 LIBC_NAMESPACE::write_to_stderr(__FILE__ ":" __LIBC_LINE_STR__ \
77 ": Assertion failed: '" #COND \
78 "' in function: '"); \
79 LIBC_NAMESPACE::write_to_stderr(__PRETTY_FUNCTION__); \
80 LIBC_NAMESPACE::write_to_stderr("'\n"); \
81 LIBC_NAMESPACE::internal::exit(0xFF); \
82 } \
83 } while (false)
84#endif // NDEBUG
85
86#endif // LIBC_COPT_USE_C_ASSERT
87
88#endif // LLVM_LIBC_SRC___SUPPORT_LIBC_ASSERT_H
lib/libcxx/libc/src/__support/macros/attributes.h created+51
......@@ -0,0 +1,51 @@
1//===-- Portable attributes -------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8// This header file defines macros for declaring attributes for functions,
9// types, and variables.
10//
11// These macros are used within llvm-libc and allow the compiler to optimize,
12// where applicable, certain function calls.
13//
14// Most macros here are exposing GCC or Clang features, and are stubbed out for
15// other compilers.
16
17#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_ATTRIBUTES_H
18#define LLVM_LIBC_SRC___SUPPORT_MACROS_ATTRIBUTES_H
19
20#include "properties/architectures.h"
21
22#ifndef __has_attribute
23#define __has_attribute(x) 0
24#endif
25
26#define LIBC_INLINE inline
27#define LIBC_INLINE_VAR inline
28#define LIBC_INLINE_ASM __asm__ __volatile__
29#define LIBC_UNUSED __attribute__((unused))
30
31#ifdef LIBC_TARGET_ARCH_IS_GPU
32#define LIBC_THREAD_LOCAL
33#else
34#define LIBC_THREAD_LOCAL thread_local
35#endif
36
37#if __cplusplus >= 202002L
38#define LIBC_CONSTINIT constinit
39#elif __has_attribute(__require_constant_initialization__)
40#define LIBC_CONSTINIT __attribute__((__require_constant_initialization__))
41#else
42#define LIBC_CONSTINIT
43#endif
44
45#if defined(__clang__) && __has_attribute(preferred_type)
46#define LIBC_PREFERED_TYPE(TYPE) [[clang::preferred_type(TYPE)]]
47#else
48#define LIBC_PREFERED_TYPE(TYPE)
49#endif
50
51#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_ATTRIBUTES_H
lib/libcxx/libc/src/__support/macros/config.h created+46
......@@ -0,0 +1,46 @@
1//===-- Portable attributes -------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8// This header file defines a set of macros for checking the presence of
9// important compiler and platform features. Such macros can be used to
10// produce portable code by parameterizing compilation based on the presence or
11// lack of a given feature.
12
13#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_CONFIG_H
14#define LLVM_LIBC_SRC___SUPPORT_MACROS_CONFIG_H
15
16// Workaround for compilers that do not support builtin detection.
17// FIXME: This is only required for the GPU portion which should be moved.
18#ifndef __has_builtin
19#define __has_builtin(b) 0
20#endif
21
22// Compiler feature-detection.
23// clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension
24#ifdef __has_feature
25#define LIBC_HAS_FEATURE(f) __has_feature(f)
26#else
27#define LIBC_HAS_FEATURE(f) 0
28#endif
29
30#ifdef __clang__
31// Declare a LIBC_NAMESPACE with hidden visibility. `namespace
32// LIBC_NAMESPACE_DECL {` should be used around all declarations and definitions
33// for libc internals as opposed to just `namespace LIBC_NAMESPACE {`. This
34// ensures that all declarations within this namespace have hidden
35// visibility, which optimizes codegen for uses of symbols defined in other
36// translation units in ways that can be necessary for correctness by avoiding
37// dynamic relocations. This does not affect the public C symbols which are
38// controlled independently via `LLVM_LIBC_FUNCTION_ATTR`.
39#define LIBC_NAMESPACE_DECL [[gnu::visibility("hidden")]] LIBC_NAMESPACE
40#else
41// TODO(#98548): GCC emits a warning when using the visibility attribute which
42// needs to be diagnosed and addressed.
43#define LIBC_NAMESPACE_DECL LIBC_NAMESPACE
44#endif
45
46#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_CONFIG_H
lib/libcxx/libc/src/__support/macros/null_check.h created+28
......@@ -0,0 +1,28 @@
1//===-- Safe nullptr check --------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_NULL_CHECK_H
10#define LLVM_LIBC_SRC___SUPPORT_MACROS_NULL_CHECK_H
11
12#include "src/__support/macros/config.h"
13#include "src/__support/macros/optimization.h"
14#include "src/__support/macros/sanitizer.h"
15
16#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
17#define LIBC_CRASH_ON_NULLPTR(ptr) \
18 do { \
19 if (LIBC_UNLIKELY((ptr) == nullptr)) \
20 __builtin_trap(); \
21 } while (0)
22#else
23#define LIBC_CRASH_ON_NULLPTR(ptr) \
24 do { \
25 } while (0)
26#endif
27
28#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_NULL_CHECK_H
lib/libcxx/libc/src/__support/macros/optimization.h created+61
......@@ -0,0 +1,61 @@
1//===-- Portable optimization macros ----------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8// This header file defines portable macros for performance optimization.
9
10#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_OPTIMIZATION_H
11#define LLVM_LIBC_SRC___SUPPORT_MACROS_OPTIMIZATION_H
12
13#include "src/__support/macros/attributes.h" // LIBC_INLINE
14#include "src/__support/macros/config.h"
15#include "src/__support/macros/properties/compiler.h" // LIBC_COMPILER_IS_CLANG
16
17// We use a template to implement likely/unlikely to make sure that we don't
18// accidentally pass an integer.
19namespace LIBC_NAMESPACE_DECL {
20namespace details {
21template <typename T>
22LIBC_INLINE constexpr bool expects_bool_condition(T value, T expected) {
23 return __builtin_expect(value, expected);
24}
25} // namespace details
26} // namespace LIBC_NAMESPACE_DECL
27#define LIBC_LIKELY(x) LIBC_NAMESPACE::details::expects_bool_condition(x, true)
28#define LIBC_UNLIKELY(x) \
29 LIBC_NAMESPACE::details::expects_bool_condition(x, false)
30
31#if defined(LIBC_COMPILER_IS_CLANG)
32#define LIBC_LOOP_NOUNROLL _Pragma("nounroll")
33#elif defined(LIBC_COMPILER_IS_GCC)
34#define LIBC_LOOP_NOUNROLL _Pragma("GCC unroll 0")
35#else
36#error "Unhandled compiler"
37#endif
38
39// Defining optimization options for math functions.
40// TODO: Exporting this to public generated headers?
41#define LIBC_MATH_SKIP_ACCURATE_PASS 0x01
42#define LIBC_MATH_SMALL_TABLES 0x02
43#define LIBC_MATH_NO_ERRNO 0x04
44#define LIBC_MATH_NO_EXCEPT 0x08
45#define LIBC_MATH_FAST \
46 (LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES | \
47 LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)
48
49#ifndef LIBC_MATH
50#define LIBC_MATH 0
51#endif // LIBC_MATH
52
53#if (LIBC_MATH & LIBC_MATH_SKIP_ACCURATE_PASS)
54#define LIBC_MATH_HAS_SKIP_ACCURATE_PASS
55#endif
56
57#if (LIBC_MATH & LIBC_MATH_SMALL_TABLES)
58#define LIBC_MATH_HAS_SMALL_TABLES
59#endif
60
61#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_OPTIMIZATION_H
lib/libcxx/libc/src/__support/macros/properties/architectures.h created+64
......@@ -0,0 +1,64 @@
1//===-- Compile time architecture detection ---------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_ARCHITECTURES_H
10#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_ARCHITECTURES_H
11
12#if defined(__AMDGPU__)
13#define LIBC_TARGET_ARCH_IS_AMDGPU
14#endif
15
16#if defined(__NVPTX__)
17#define LIBC_TARGET_ARCH_IS_NVPTX
18#endif
19
20#if defined(LIBC_TARGET_ARCH_IS_NVPTX) || defined(LIBC_TARGET_ARCH_IS_AMDGPU)
21#define LIBC_TARGET_ARCH_IS_GPU
22#endif
23
24#if defined(__pnacl__) || defined(__CLR_VER) || defined(LIBC_TARGET_ARCH_IS_GPU)
25#define LIBC_TARGET_ARCH_IS_VM
26#endif
27
28#if (defined(_M_IX86) || defined(__i386__)) && !defined(LIBC_TARGET_ARCH_IS_VM)
29#define LIBC_TARGET_ARCH_IS_X86_32
30#endif
31
32#if (defined(_M_X64) || defined(__x86_64__)) && !defined(LIBC_TARGET_ARCH_IS_VM)
33#define LIBC_TARGET_ARCH_IS_X86_64
34#endif
35
36#if defined(LIBC_TARGET_ARCH_IS_X86_32) || defined(LIBC_TARGET_ARCH_IS_X86_64)
37#define LIBC_TARGET_ARCH_IS_X86
38#endif
39
40#if (defined(__arm__) || defined(_M_ARM))
41#define LIBC_TARGET_ARCH_IS_ARM
42#endif
43
44#if defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
45#define LIBC_TARGET_ARCH_IS_AARCH64
46#endif
47
48#if defined(LIBC_TARGET_ARCH_IS_AARCH64) || defined(LIBC_TARGET_ARCH_IS_ARM)
49#define LIBC_TARGET_ARCH_IS_ANY_ARM
50#endif
51
52#if defined(__riscv) && (__riscv_xlen == 64)
53#define LIBC_TARGET_ARCH_IS_RISCV64
54#endif
55
56#if defined(__riscv) && (__riscv_xlen == 32)
57#define LIBC_TARGET_ARCH_IS_RISCV32
58#endif
59
60#if defined(LIBC_TARGET_ARCH_IS_RISCV64) || defined(LIBC_TARGET_ARCH_IS_RISCV32)
61#define LIBC_TARGET_ARCH_IS_ANY_RISCV
62#endif
63
64#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_ARCHITECTURES_H
lib/libcxx/libc/src/__support/macros/properties/compiler.h created+43
......@@ -0,0 +1,43 @@
1//===-- Compile time compiler detection -------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_COMPILER_H
10#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_COMPILER_H
11
12// Example usage of compiler version checks
13// #if defined(LIBC_COMPILER_CLANG_VER)
14// # if LIBC_COMPILER_CLANG_VER < 1500
15// # warning "Libc only supports Clang 15 and later"
16// # endif
17// #elif defined(LIBC_COMPILER_GCC_VER)
18// # if LIBC_COMPILER_GCC_VER < 1500
19// # warning "Libc only supports GCC 15 and later"
20// # endif
21// #elif defined(LIBC_COMPILER_MSC_VER)
22// # if LIBC_COMPILER_MSC_VER < 1930
23// # warning "Libc only supports Visual Studio 2022 RTW (17.0) and later"
24// # endif
25// #endif
26
27#if defined(__clang__)
28#define LIBC_COMPILER_IS_CLANG
29#define LIBC_COMPILER_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
30#endif
31
32#if defined(__GNUC__) && !defined(__clang__)
33#define LIBC_COMPILER_IS_GCC
34#define LIBC_COMPILER_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
35#endif
36
37#if defined(_MSC_VER)
38#define LIBC_COMPILER_IS_MSC
39// https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros
40#define LIBC_COMPILER_MSC_VER (_MSC_VER)
41#endif
42
43#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_COMPILER_H
lib/libcxx/libc/src/__support/macros/properties/complex_types.h created+30
......@@ -0,0 +1,30 @@
1//===-- Complex Types support -----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8// Complex Types detection and support.
9
10#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_CTYPES_H
11#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_CTYPES_H
12
13#include "include/llvm-libc-types/cfloat128.h"
14#include "include/llvm-libc-types/cfloat16.h"
15#include "types.h"
16
17// -- cfloat16 support --------------------------------------------------------
18// LIBC_TYPES_HAS_CFLOAT16 and 'cfloat16' type is provided by
19// "include/llvm-libc-types/cfloat16.h"
20
21// -- cfloat128 support -------------------------------------------------------
22// LIBC_TYPES_HAS_CFLOAT128 and 'cfloat128' type are provided by
23// "include/llvm-libc-types/cfloat128.h"
24
25#if defined(LIBC_TYPES_HAS_CFLOAT128) && \
26 !defined(LIBC_TYPES_CFLOAT128_IS_COMPLEX_LONG_DOUBLE)
27#define LIBC_TYPES_CFLOAT128_IS_NOT_COMPLEX_LONG_DOUBLE
28#endif
29
30#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_CTYPES_H
lib/libcxx/libc/src/__support/macros/properties/cpu_features.h created+60
......@@ -0,0 +1,60 @@
1//===-- Compile time cpu feature detection ----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8// This file lists target cpu features by introspecting compiler enabled
9// preprocessor definitions.
10//===----------------------------------------------------------------------===//
11
12#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_CPU_FEATURES_H
13#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_CPU_FEATURES_H
14
15#include "architectures.h"
16
17#if defined(__ARM_FEATURE_FP16_SCALAR_ARITHMETIC)
18#define LIBC_TARGET_CPU_HAS_FULLFP16
19#endif
20
21#if defined(__SSE2__)
22#define LIBC_TARGET_CPU_HAS_SSE2
23#endif
24
25#if defined(__SSE4_2__)
26#define LIBC_TARGET_CPU_HAS_SSE4_2
27#endif
28
29#if defined(__AVX__)
30#define LIBC_TARGET_CPU_HAS_AVX
31#endif
32
33#if defined(__AVX2__)
34#define LIBC_TARGET_CPU_HAS_AVX2
35#endif
36
37#if defined(__AVX512F__)
38#define LIBC_TARGET_CPU_HAS_AVX512F
39#endif
40
41#if defined(__AVX512BW__)
42#define LIBC_TARGET_CPU_HAS_AVX512BW
43#endif
44
45#if defined(__ARM_FEATURE_FMA) || (defined(__AVX2__) && defined(__FMA__)) || \
46 defined(__NVPTX__) || defined(__AMDGPU__) || defined(__LIBC_RISCV_USE_FMA)
47#define LIBC_TARGET_CPU_HAS_FMA
48#endif
49
50#if defined(LIBC_TARGET_ARCH_IS_AARCH64) || \
51 (defined(LIBC_TARGET_ARCH_IS_X86_64) && \
52 defined(LIBC_TARGET_CPU_HAS_SSE4_2))
53#define LIBC_TARGET_CPU_HAS_NEAREST_INT
54#endif
55
56#if defined(LIBC_TARGET_ARCH_IS_AARCH64) || defined(LIBC_TARGET_ARCH_IS_GPU)
57#define LIBC_TARGET_CPU_HAS_FAST_FLOAT16_OPS
58#endif
59
60#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_CPU_FEATURES_H
lib/libcxx/libc/src/__support/macros/properties/os.h created+32
......@@ -0,0 +1,32 @@
1//===-- Target OS detection -------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_OS_H
9#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_OS_H
10
11#if (defined(__freebsd__) || defined(__FreeBSD__))
12#define LIBC_TARGET_OS_IS_FREEBSD
13#endif
14
15#if defined(__ANDROID__)
16#define LIBC_TARGET_OS_IS_ANDROID
17#endif
18
19#if defined(__linux__) && !defined(LIBC_TARGET_OS_IS_FREEBSD) && \
20 !defined(LIBC_TARGET_OS_IS_ANDROID)
21#define LIBC_TARGET_OS_IS_LINUX
22#endif
23
24#if (defined(_WIN64) || defined(_WIN32))
25#define LIBC_TARGET_OS_IS_WINDOWS
26#endif
27
28#if defined(__Fuchsia__)
29#define LIBC_TARGET_OS_IS_FUCHSIA
30#endif
31
32#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_OS_H
lib/libcxx/libc/src/__support/macros/properties/types.h created+61
......@@ -0,0 +1,61 @@
1//===-- Types support -------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8// Types detection and support.
9
10#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
11#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
12
13#include "hdr/float_macros.h" // LDBL_MANT_DIG
14#include "include/llvm-libc-macros/float16-macros.h" // LIBC_TYPES_HAS_FLOAT16
15#include "include/llvm-libc-types/float128.h" // float128
16#include "src/__support/macros/properties/architectures.h"
17#include "src/__support/macros/properties/compiler.h"
18#include "src/__support/macros/properties/cpu_features.h"
19#include "src/__support/macros/properties/os.h"
20
21#include <stdint.h> // UINT64_MAX, __SIZEOF_INT128__
22
23// 'long double' properties.
24#if (LDBL_MANT_DIG == 53)
25#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64
26#elif (LDBL_MANT_DIG == 64)
27#define LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
28#elif (LDBL_MANT_DIG == 113)
29#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128
30#elif (LDBL_MANT_DIG == 106)
31#define LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
32#endif
33
34#if defined(LIBC_TYPES_HAS_FLOAT128) && \
35 !defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128)
36#define LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
37#endif
38
39// int64 / uint64 support
40#if defined(UINT64_MAX)
41#define LIBC_TYPES_HAS_INT64
42#endif // UINT64_MAX
43
44// int128 / uint128 support
45#if defined(__SIZEOF_INT128__) && !defined(LIBC_TARGET_OS_IS_WINDOWS)
46#define LIBC_TYPES_HAS_INT128
47#endif // defined(__SIZEOF_INT128__)
48
49// -- float16 support ---------------------------------------------------------
50// LIBC_TYPES_HAS_FLOAT16 is provided by
51// "include/llvm-libc-macros/float16-macros.h"
52#ifdef LIBC_TYPES_HAS_FLOAT16
53// Type alias for internal use.
54using float16 = _Float16;
55#endif // LIBC_TYPES_HAS_FLOAT16
56
57// -- float128 support --------------------------------------------------------
58// LIBC_TYPES_HAS_FLOAT128 and 'float128' type are provided by
59// "include/llvm-libc-types/float128.h"
60
61#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
lib/libcxx/libc/src/__support/macros/sanitizer.h created+59
......@@ -0,0 +1,59 @@
1//===-- Convenient sanitizer macros -----------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_SANITIZER_H
10#define LLVM_LIBC_SRC___SUPPORT_MACROS_SANITIZER_H
11
12#include "src/__support/macros/config.h" //LIBC_HAS_FEATURE
13
14//-----------------------------------------------------------------------------
15// Functions to unpoison memory
16//-----------------------------------------------------------------------------
17
18#if LIBC_HAS_FEATURE(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
19#define LIBC_HAS_ADDRESS_SANITIZER
20#endif
21
22#if LIBC_HAS_FEATURE(memory_sanitizer)
23#define LIBC_HAS_MEMORY_SANITIZER
24#endif
25
26#if LIBC_HAS_FEATURE(undefined_behavior_sanitizer)
27#define LIBC_HAS_UNDEFINED_BEHAVIOR_SANITIZER
28#endif
29
30#if defined(LIBC_HAS_ADDRESS_SANITIZER) || \
31 defined(LIBC_HAS_MEMORY_SANITIZER) || \
32 defined(LIBC_HAS_UNDEFINED_BEHAVIOR_SANITIZER)
33#define LIBC_HAS_SANITIZER
34#endif
35
36#ifdef LIBC_HAS_MEMORY_SANITIZER
37// Only perform MSAN unpoison in non-constexpr context.
38#include <sanitizer/msan_interface.h>
39#define MSAN_UNPOISON(addr, size) \
40 do { \
41 if (!__builtin_is_constant_evaluated()) \
42 __msan_unpoison(addr, size); \
43 } while (0)
44#else
45#define MSAN_UNPOISON(ptr, size)
46#endif
47
48#ifdef LIBC_HAS_ADDRESS_SANITIZER
49#include <sanitizer/asan_interface.h>
50#define ASAN_POISON_MEMORY_REGION(addr, size) \
51 __asan_poison_memory_region((addr), (size))
52#define ASAN_UNPOISON_MEMORY_REGION(addr, size) \
53 __asan_unpoison_memory_region((addr), (size))
54#else
55#define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
56#define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
57#endif
58
59#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_SANITIZER_H
lib/libcxx/libc/src/__support/math_extras.h created+161
......@@ -0,0 +1,161 @@
1//===-- Mimics llvm/Support/MathExtras.h ------------------------*- C++ -*-===//
2// Provides useful math functions.
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_EXTRAS_H
11#define LLVM_LIBC_SRC___SUPPORT_MATH_EXTRAS_H
12
13#include "src/__support/CPP/bit.h" // countl_one, countr_zero
14#include "src/__support/CPP/limits.h" // CHAR_BIT, numeric_limits
15#include "src/__support/CPP/type_traits.h" // is_unsigned_v, is_constant_evaluated
16#include "src/__support/macros/attributes.h" // LIBC_INLINE
17#include "src/__support/macros/config.h"
18
19namespace LIBC_NAMESPACE_DECL {
20
21// Create a bitmask with the count right-most bits set to 1, and all other bits
22// set to 0. Only unsigned types are allowed.
23template <typename T, size_t count>
24LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T>
25mask_trailing_ones() {
26 constexpr unsigned T_BITS = CHAR_BIT * sizeof(T);
27 static_assert(count <= T_BITS && "Invalid bit index");
28 return count == 0 ? 0 : (T(-1) >> (T_BITS - count));
29}
30
31// Create a bitmask with the count left-most bits set to 1, and all other bits
32// set to 0. Only unsigned types are allowed.
33template <typename T, size_t count>
34LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T>
35mask_leading_ones() {
36 return T(~mask_trailing_ones<T, CHAR_BIT * sizeof(T) - count>());
37}
38
39// Create a bitmask with the count right-most bits set to 0, and all other bits
40// set to 1. Only unsigned types are allowed.
41template <typename T, size_t count>
42LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T>
43mask_trailing_zeros() {
44 return mask_leading_ones<T, CHAR_BIT * sizeof(T) - count>();
45}
46
47// Create a bitmask with the count left-most bits set to 0, and all other bits
48// set to 1. Only unsigned types are allowed.
49template <typename T, size_t count>
50LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T>
51mask_leading_zeros() {
52 return mask_trailing_ones<T, CHAR_BIT * sizeof(T) - count>();
53}
54
55// Returns whether 'a + b' overflows, the result is stored in 'res'.
56template <typename T>
57[[nodiscard]] LIBC_INLINE constexpr bool add_overflow(T a, T b, T &res) {
58 return __builtin_add_overflow(a, b, &res);
59}
60
61// Returns whether 'a - b' overflows, the result is stored in 'res'.
62template <typename T>
63[[nodiscard]] LIBC_INLINE constexpr bool sub_overflow(T a, T b, T &res) {
64 return __builtin_sub_overflow(a, b, &res);
65}
66
67#define RETURN_IF(TYPE, BUILTIN) \
68 if constexpr (cpp::is_same_v<T, TYPE>) \
69 return BUILTIN(a, b, carry_in, carry_out);
70
71// Returns the result of 'a + b' taking into account 'carry_in'.
72// The carry out is stored in 'carry_out' it not 'nullptr', dropped otherwise.
73// We keep the pass by pointer interface for consistency with the intrinsic.
74template <typename T>
75[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T>
76add_with_carry(T a, T b, T carry_in, T &carry_out) {
77 if constexpr (!cpp::is_constant_evaluated()) {
78#if __has_builtin(__builtin_addcb)
79 RETURN_IF(unsigned char, __builtin_addcb)
80#elif __has_builtin(__builtin_addcs)
81 RETURN_IF(unsigned short, __builtin_addcs)
82#elif __has_builtin(__builtin_addc)
83 RETURN_IF(unsigned int, __builtin_addc)
84#elif __has_builtin(__builtin_addcl)
85 RETURN_IF(unsigned long, __builtin_addcl)
86#elif __has_builtin(__builtin_addcll)
87 RETURN_IF(unsigned long long, __builtin_addcll)
88#endif
89 }
90 T sum = {};
91 T carry1 = add_overflow(a, b, sum);
92 T carry2 = add_overflow(sum, carry_in, sum);
93 carry_out = carry1 | carry2;
94 return sum;
95}
96
97// Returns the result of 'a - b' taking into account 'carry_in'.
98// The carry out is stored in 'carry_out' it not 'nullptr', dropped otherwise.
99// We keep the pass by pointer interface for consistency with the intrinsic.
100template <typename T>
101[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T>
102sub_with_borrow(T a, T b, T carry_in, T &carry_out) {
103 if constexpr (!cpp::is_constant_evaluated()) {
104#if __has_builtin(__builtin_subcb)
105 RETURN_IF(unsigned char, __builtin_subcb)
106#elif __has_builtin(__builtin_subcs)
107 RETURN_IF(unsigned short, __builtin_subcs)
108#elif __has_builtin(__builtin_subc)
109 RETURN_IF(unsigned int, __builtin_subc)
110#elif __has_builtin(__builtin_subcl)
111 RETURN_IF(unsigned long, __builtin_subcl)
112#elif __has_builtin(__builtin_subcll)
113 RETURN_IF(unsigned long long, __builtin_subcll)
114#endif
115 }
116 T sub = {};
117 T carry1 = sub_overflow(a, b, sub);
118 T carry2 = sub_overflow(sub, carry_in, sub);
119 carry_out = carry1 | carry2;
120 return sub;
121}
122
123#undef RETURN_IF
124
125template <typename T>
126[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
127first_leading_zero(T value) {
128 return value == cpp::numeric_limits<T>::max() ? 0
129 : cpp::countl_one(value) + 1;
130}
131
132template <typename T>
133[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
134first_leading_one(T value) {
135 return first_leading_zero(static_cast<T>(~value));
136}
137
138template <typename T>
139[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
140first_trailing_zero(T value) {
141 return value == cpp::numeric_limits<T>::max()
142 ? 0
143 : cpp::countr_zero(static_cast<T>(~value)) + 1;
144}
145
146template <typename T>
147[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
148first_trailing_one(T value) {
149 return value == cpp::numeric_limits<T>::max() ? 0
150 : cpp::countr_zero(value) + 1;
151}
152
153template <typename T>
154[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int>
155count_zeros(T value) {
156 return cpp::popcount<T>(static_cast<T>(~value));
157}
158
159} // namespace LIBC_NAMESPACE_DECL
160
161#endif // LLVM_LIBC_SRC___SUPPORT_MATH_EXTRAS_H
lib/libcxx/libc/src/__support/number_pair.h created+26
......@@ -0,0 +1,26 @@
1//===-- Utilities for pairs of numbers. -------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_NUMBER_PAIR_H
10#define LLVM_LIBC_SRC___SUPPORT_NUMBER_PAIR_H
11
12#include "CPP/type_traits.h"
13#include "src/__support/macros/config.h"
14
15#include <stddef.h>
16
17namespace LIBC_NAMESPACE_DECL {
18
19template <typename T> struct NumberPair {
20 T lo = T(0);
21 T hi = T(0);
22};
23
24} // namespace LIBC_NAMESPACE_DECL
25
26#endif // LLVM_LIBC_SRC___SUPPORT_NUMBER_PAIR_H
lib/libcxx/libc/src/__support/sign.h created+43
......@@ -0,0 +1,43 @@
1//===-- A simple sign type --------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_SIGN_H
10#define LLVM_LIBC_SRC___SUPPORT_SIGN_H
11
12#include "src/__support/macros/attributes.h" // LIBC_INLINE, LIBC_INLINE_VAR
13
14namespace LIBC_NAMESPACE_DECL {
15
16// A type to interact with signed arithmetic types.
17struct Sign {
18 LIBC_INLINE constexpr bool is_pos() const { return !is_negative; }
19 LIBC_INLINE constexpr bool is_neg() const { return is_negative; }
20
21 LIBC_INLINE friend constexpr bool operator==(Sign a, Sign b) {
22 return a.is_negative == b.is_negative;
23 }
24
25 LIBC_INLINE friend constexpr bool operator!=(Sign a, Sign b) {
26 return !(a == b);
27 }
28
29 static const Sign POS;
30 static const Sign NEG;
31
32private:
33 LIBC_INLINE constexpr explicit Sign(bool is_negative)
34 : is_negative(is_negative) {}
35
36 bool is_negative;
37};
38
39LIBC_INLINE_VAR constexpr Sign Sign::NEG = Sign(true);
40LIBC_INLINE_VAR constexpr Sign Sign::POS = Sign(false);
41
42} // namespace LIBC_NAMESPACE_DECL
43#endif // LLVM_LIBC_SRC___SUPPORT_SIGN_H
lib/libcxx/libc/src/__support/str_to_float.h created+1275
......@@ -0,0 +1,1275 @@
1//===-- String to float conversion utils ------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// -----------------------------------------------------------------------------
10// **** WARNING ****
11// This file is shared with libc++. You should also be careful when adding
12// dependencies to this file, since it needs to build for all libc++ targets.
13// -----------------------------------------------------------------------------
14
15#ifndef LLVM_LIBC_SRC___SUPPORT_STR_TO_FLOAT_H
16#define LLVM_LIBC_SRC___SUPPORT_STR_TO_FLOAT_H
17
18#include "src/__support/CPP/bit.h"
19#include "src/__support/CPP/limits.h"
20#include "src/__support/CPP/optional.h"
21#include "src/__support/CPP/string_view.h"
22#include "src/__support/FPUtil/FPBits.h"
23#include "src/__support/FPUtil/rounding_mode.h"
24#include "src/__support/common.h"
25#include "src/__support/ctype_utils.h"
26#include "src/__support/detailed_powers_of_ten.h"
27#include "src/__support/high_precision_decimal.h"
28#include "src/__support/macros/config.h"
29#include "src/__support/macros/null_check.h"
30#include "src/__support/macros/optimization.h"
31#include "src/__support/str_to_integer.h"
32#include "src/__support/str_to_num_result.h"
33#include "src/__support/uint128.h"
34#include "src/errno/libc_errno.h" // For ERANGE
35
36#include <stdint.h>
37
38namespace LIBC_NAMESPACE_DECL {
39namespace internal {
40
41// -----------------------------------------------------------------------------
42// **** WARNING ****
43// This interface is shared with libc++, if you change this interface you need
44// to update it in both libc and libc++.
45// -----------------------------------------------------------------------------
46template <class T> struct ExpandedFloat {
47 typename fputil::FPBits<T>::StorageType mantissa;
48 int32_t exponent;
49};
50
51// -----------------------------------------------------------------------------
52// **** WARNING ****
53// This interface is shared with libc++, if you change this interface you need
54// to update it in both libc and libc++.
55// -----------------------------------------------------------------------------
56template <class T> struct FloatConvertReturn {
57 ExpandedFloat<T> num = {0, 0};
58 int error = 0;
59};
60
61LIBC_INLINE uint64_t low64(const UInt128 &num) {
62 return static_cast<uint64_t>(num & 0xffffffffffffffff);
63}
64
65LIBC_INLINE uint64_t high64(const UInt128 &num) {
66 return static_cast<uint64_t>(num >> 64);
67}
68
69template <class T> LIBC_INLINE void set_implicit_bit(fputil::FPBits<T> &) {
70 return;
71}
72
73#if defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80)
74template <>
75LIBC_INLINE void
76set_implicit_bit<long double>(fputil::FPBits<long double> &result) {
77 result.set_implicit_bit(result.get_biased_exponent() != 0);
78}
79#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
80
81// This Eisel-Lemire implementation is based on the algorithm described in the
82// paper Number Parsing at a Gigabyte per Second, Software: Practice and
83// Experience 51 (8), 2021 (https://arxiv.org/abs/2101.11408), as well as the
84// description by Nigel Tao
85// (https://nigeltao.github.io/blog/2020/eisel-lemire.html) and the golang
86// implementation, also by Nigel Tao
87// (https://github.com/golang/go/blob/release-branch.go1.16/src/strconv/eisel_lemire.go#L25)
88// for some optimizations as well as handling 32 bit floats.
89template <class T>
90LIBC_INLINE cpp::optional<ExpandedFloat<T>>
91eisel_lemire(ExpandedFloat<T> init_num,
92 RoundDirection round = RoundDirection::Nearest) {
93 using FPBits = typename fputil::FPBits<T>;
94 using StorageType = typename FPBits::StorageType;
95
96 StorageType mantissa = init_num.mantissa;
97 int32_t exp10 = init_num.exponent;
98
99 if (sizeof(T) > 8) { // This algorithm cannot handle anything longer than a
100 // double, so we skip straight to the fallback.
101 return cpp::nullopt;
102 }
103
104 // Exp10 Range
105 if (exp10 < DETAILED_POWERS_OF_TEN_MIN_EXP_10 ||
106 exp10 > DETAILED_POWERS_OF_TEN_MAX_EXP_10) {
107 return cpp::nullopt;
108 }
109
110 // Normalization
111 uint32_t clz = cpp::countl_zero<StorageType>(mantissa);
112 mantissa <<= clz;
113
114 int32_t exp2 =
115 exp10_to_exp2(exp10) + FPBits::STORAGE_LEN + FPBits::EXP_BIAS - clz;
116
117 // Multiplication
118 const uint64_t *power_of_ten =
119 DETAILED_POWERS_OF_TEN[exp10 - DETAILED_POWERS_OF_TEN_MIN_EXP_10];
120
121 UInt128 first_approx =
122 static_cast<UInt128>(mantissa) * static_cast<UInt128>(power_of_ten[1]);
123
124 // Wider Approximation
125 UInt128 final_approx;
126 // The halfway constant is used to check if the bits that will be shifted away
127 // intially are all 1. For doubles this is 64 (bitstype size) - 52 (final
128 // mantissa size) - 3 (we shift away the last two bits separately for
129 // accuracy, and the most significant bit is ignored.) = 9 bits. Similarly,
130 // it's 6 bits for floats in this case.
131 const uint64_t halfway_constant =
132 (uint64_t(1) << (FPBits::STORAGE_LEN - (FPBits::FRACTION_LEN + 3))) - 1;
133 if ((high64(first_approx) & halfway_constant) == halfway_constant &&
134 low64(first_approx) + mantissa < mantissa) {
135 UInt128 low_bits =
136 static_cast<UInt128>(mantissa) * static_cast<UInt128>(power_of_ten[0]);
137 UInt128 second_approx =
138 first_approx + static_cast<UInt128>(high64(low_bits));
139
140 if ((high64(second_approx) & halfway_constant) == halfway_constant &&
141 low64(second_approx) + 1 == 0 &&
142 low64(low_bits) + mantissa < mantissa) {
143 return cpp::nullopt;
144 }
145 final_approx = second_approx;
146 } else {
147 final_approx = first_approx;
148 }
149
150 // Shifting to 54 bits for doubles and 25 bits for floats
151 StorageType msb = static_cast<StorageType>(high64(final_approx) >>
152 (FPBits::STORAGE_LEN - 1));
153 StorageType final_mantissa = static_cast<StorageType>(
154 high64(final_approx) >>
155 (msb + FPBits::STORAGE_LEN - (FPBits::FRACTION_LEN + 3)));
156 exp2 -= static_cast<uint32_t>(1 ^ msb); // same as !msb
157
158 if (round == RoundDirection::Nearest) {
159 // Half-way ambiguity
160 if (low64(final_approx) == 0 &&
161 (high64(final_approx) & halfway_constant) == 0 &&
162 (final_mantissa & 3) == 1) {
163 return cpp::nullopt;
164 }
165
166 // Round to even.
167 final_mantissa += final_mantissa & 1;
168
169 } else if (round == RoundDirection::Up) {
170 // If any of the bits being rounded away are non-zero, then round up.
171 if (low64(final_approx) > 0 ||
172 (high64(final_approx) & halfway_constant) > 0) {
173 // Add two since the last current lowest bit is about to be shifted away.
174 final_mantissa += 2;
175 }
176 }
177 // else round down, which has no effect.
178
179 // From 54 to 53 bits for doubles and 25 to 24 bits for floats
180 final_mantissa >>= 1;
181 if ((final_mantissa >> (FPBits::FRACTION_LEN + 1)) > 0) {
182 final_mantissa >>= 1;
183 ++exp2;
184 }
185
186 // The if block is equivalent to (but has fewer branches than):
187 // if exp2 <= 0 || exp2 >= 0x7FF { etc }
188 if (static_cast<uint32_t>(exp2) - 1 >= (1 << FPBits::EXP_LEN) - 2) {
189 return cpp::nullopt;
190 }
191
192 ExpandedFloat<T> output;
193 output.mantissa = final_mantissa;
194 output.exponent = exp2;
195 return output;
196}
197
198// TODO: Re-enable eisel-lemire for long double is double double once it's
199// properly supported.
200#if !defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64) && \
201 !defined(LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE)
202template <>
203LIBC_INLINE cpp::optional<ExpandedFloat<long double>>
204eisel_lemire<long double>(ExpandedFloat<long double> init_num,
205 RoundDirection round) {
206 using FPBits = typename fputil::FPBits<long double>;
207 using StorageType = typename FPBits::StorageType;
208
209 UInt128 mantissa = init_num.mantissa;
210 int32_t exp10 = init_num.exponent;
211
212 // Exp10 Range
213 // This doesn't reach very far into the range for long doubles, since it's
214 // sized for doubles and their 11 exponent bits, and not for long doubles and
215 // their 15 exponent bits (max exponent of ~300 for double vs ~5000 for long
216 // double). This is a known tradeoff, and was made because a proper long
217 // double table would be approximately 16 times larger. This would have
218 // significant memory and storage costs all the time to speed up a relatively
219 // uncommon path. In addition the exp10_to_exp2 function only approximates
220 // multiplying by log(10)/log(2), and that approximation may not be accurate
221 // out to the full long double range.
222 if (exp10 < DETAILED_POWERS_OF_TEN_MIN_EXP_10 ||
223 exp10 > DETAILED_POWERS_OF_TEN_MAX_EXP_10) {
224 return cpp::nullopt;
225 }
226
227 // Normalization
228 uint32_t clz = cpp::countl_zero(mantissa) -
229 ((sizeof(UInt128) - sizeof(StorageType)) * CHAR_BIT);
230 mantissa <<= clz;
231
232 int32_t exp2 =
233 exp10_to_exp2(exp10) + FPBits::STORAGE_LEN + FPBits::EXP_BIAS - clz;
234
235 // Multiplication
236 const uint64_t *power_of_ten =
237 DETAILED_POWERS_OF_TEN[exp10 - DETAILED_POWERS_OF_TEN_MIN_EXP_10];
238
239 // Since the input mantissa is more than 64 bits, we have to multiply with the
240 // full 128 bits of the power of ten to get an approximation with the same
241 // number of significant bits. This means that we only get the one
242 // approximation, and that approximation is 256 bits long.
243 UInt128 approx_upper = static_cast<UInt128>(high64(mantissa)) *
244 static_cast<UInt128>(power_of_ten[1]);
245
246 UInt128 approx_middle_a = static_cast<UInt128>(high64(mantissa)) *
247 static_cast<UInt128>(power_of_ten[0]);
248 UInt128 approx_middle_b = static_cast<UInt128>(low64(mantissa)) *
249 static_cast<UInt128>(power_of_ten[1]);
250
251 UInt128 approx_middle = approx_middle_a + approx_middle_b;
252
253 // Handle overflow in the middle
254 approx_upper += (approx_middle < approx_middle_a) ? UInt128(1) << 64 : 0;
255
256 UInt128 approx_lower = static_cast<UInt128>(low64(mantissa)) *
257 static_cast<UInt128>(power_of_ten[0]);
258
259 UInt128 final_approx_lower =
260 approx_lower + (static_cast<UInt128>(low64(approx_middle)) << 64);
261 UInt128 final_approx_upper = approx_upper + high64(approx_middle) +
262 (final_approx_lower < approx_lower ? 1 : 0);
263
264 // The halfway constant is used to check if the bits that will be shifted away
265 // intially are all 1. For 80 bit floats this is 128 (bitstype size) - 64
266 // (final mantissa size) - 3 (we shift away the last two bits separately for
267 // accuracy, and the most significant bit is ignored.) = 61 bits. Similarly,
268 // it's 12 bits for 128 bit floats in this case.
269 constexpr UInt128 HALFWAY_CONSTANT =
270 (UInt128(1) << (FPBits::STORAGE_LEN - (FPBits::FRACTION_LEN + 3))) - 1;
271
272 if ((final_approx_upper & HALFWAY_CONSTANT) == HALFWAY_CONSTANT &&
273 final_approx_lower + mantissa < mantissa) {
274 return cpp::nullopt;
275 }
276
277 // Shifting to 65 bits for 80 bit floats and 113 bits for 128 bit floats
278 uint32_t msb =
279 static_cast<uint32_t>(final_approx_upper >> (FPBits::STORAGE_LEN - 1));
280 UInt128 final_mantissa = final_approx_upper >> (msb + FPBits::STORAGE_LEN -
281 (FPBits::FRACTION_LEN + 3));
282 exp2 -= static_cast<uint32_t>(1 ^ msb); // same as !msb
283
284 if (round == RoundDirection::Nearest) {
285 // Half-way ambiguity
286 if (final_approx_lower == 0 &&
287 (final_approx_upper & HALFWAY_CONSTANT) == 0 &&
288 (final_mantissa & 3) == 1) {
289 return cpp::nullopt;
290 }
291 // Round to even.
292 final_mantissa += final_mantissa & 1;
293
294 } else if (round == RoundDirection::Up) {
295 // If any of the bits being rounded away are non-zero, then round up.
296 if (final_approx_lower > 0 || (final_approx_upper & HALFWAY_CONSTANT) > 0) {
297 // Add two since the last current lowest bit is about to be shifted away.
298 final_mantissa += 2;
299 }
300 }
301 // else round down, which has no effect.
302
303 // From 65 to 64 bits for 80 bit floats and 113 to 112 bits for 128 bit
304 // floats
305 final_mantissa >>= 1;
306 if ((final_mantissa >> (FPBits::FRACTION_LEN + 1)) > 0) {
307 final_mantissa >>= 1;
308 ++exp2;
309 }
310
311 // The if block is equivalent to (but has fewer branches than):
312 // if exp2 <= 0 || exp2 >= MANTISSA_MAX { etc }
313 if (exp2 - 1 >= (1 << FPBits::EXP_LEN) - 2) {
314 return cpp::nullopt;
315 }
316
317 ExpandedFloat<long double> output;
318 output.mantissa = static_cast<StorageType>(final_mantissa);
319 output.exponent = exp2;
320 return output;
321}
322#endif // !defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64) &&
323 // !defined(LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE)
324
325// The nth item in POWERS_OF_TWO represents the greatest power of two less than
326// 10^n. This tells us how much we can safely shift without overshooting.
327constexpr uint8_t POWERS_OF_TWO[19] = {
328 0, 3, 6, 9, 13, 16, 19, 23, 26, 29, 33, 36, 39, 43, 46, 49, 53, 56, 59,
329};
330constexpr int32_t NUM_POWERS_OF_TWO =
331 sizeof(POWERS_OF_TWO) / sizeof(POWERS_OF_TWO[0]);
332
333// Takes a mantissa and base 10 exponent and converts it into its closest
334// floating point type T equivalent. This is the fallback algorithm used when
335// the Eisel-Lemire algorithm fails, it's slower but more accurate. It's based
336// on the Simple Decimal Conversion algorithm by Nigel Tao, described at this
337// link: https://nigeltao.github.io/blog/2020/parse-number-f64-simple.html
338template <class T>
339LIBC_INLINE FloatConvertReturn<T> simple_decimal_conversion(
340 const char *__restrict numStart,
341 const size_t num_len = cpp::numeric_limits<size_t>::max(),
342 RoundDirection round = RoundDirection::Nearest) {
343 using FPBits = typename fputil::FPBits<T>;
344 using StorageType = typename FPBits::StorageType;
345
346 int32_t exp2 = 0;
347 HighPrecisionDecimal hpd = HighPrecisionDecimal(numStart, num_len);
348
349 FloatConvertReturn<T> output;
350
351 if (hpd.get_num_digits() == 0) {
352 output.num = {0, 0};
353 return output;
354 }
355
356 // If the exponent is too large and can't be represented in this size of
357 // float, return inf.
358 if (hpd.get_decimal_point() > 0 &&
359 exp10_to_exp2(hpd.get_decimal_point() - 1) > FPBits::EXP_BIAS) {
360 output.num = {0, fputil::FPBits<T>::MAX_BIASED_EXPONENT};
361 output.error = ERANGE;
362 return output;
363 }
364 // If the exponent is too small even for a subnormal, return 0.
365 if (hpd.get_decimal_point() < 0 &&
366 exp10_to_exp2(-hpd.get_decimal_point()) >
367 (FPBits::EXP_BIAS + static_cast<int32_t>(FPBits::FRACTION_LEN))) {
368 output.num = {0, 0};
369 output.error = ERANGE;
370 return output;
371 }
372
373 // Right shift until the number is smaller than 1.
374 while (hpd.get_decimal_point() > 0) {
375 int32_t shift_amount = 0;
376 if (hpd.get_decimal_point() >= NUM_POWERS_OF_TWO) {
377 shift_amount = 60;
378 } else {
379 shift_amount = POWERS_OF_TWO[hpd.get_decimal_point()];
380 }
381 exp2 += shift_amount;
382 hpd.shift(-shift_amount);
383 }
384
385 // Left shift until the number is between 1/2 and 1
386 while (hpd.get_decimal_point() < 0 ||
387 (hpd.get_decimal_point() == 0 && hpd.get_digits()[0] < 5)) {
388 int32_t shift_amount = 0;
389
390 if (-hpd.get_decimal_point() >= NUM_POWERS_OF_TWO) {
391 shift_amount = 60;
392 } else if (hpd.get_decimal_point() != 0) {
393 shift_amount = POWERS_OF_TWO[-hpd.get_decimal_point()];
394 } else { // This handles the case of the number being between .1 and .5
395 shift_amount = 1;
396 }
397 exp2 -= shift_amount;
398 hpd.shift(shift_amount);
399 }
400
401 // Left shift once so that the number is between 1 and 2
402 --exp2;
403 hpd.shift(1);
404
405 // Get the biased exponent
406 exp2 += FPBits::EXP_BIAS;
407
408 // Handle the exponent being too large (and return inf).
409 if (exp2 >= FPBits::MAX_BIASED_EXPONENT) {
410 output.num = {0, FPBits::MAX_BIASED_EXPONENT};
411 output.error = ERANGE;
412 return output;
413 }
414
415 // Shift left to fill the mantissa
416 hpd.shift(FPBits::FRACTION_LEN);
417 StorageType final_mantissa = hpd.round_to_integer_type<StorageType>();
418
419 // Handle subnormals
420 if (exp2 <= 0) {
421 // Shift right until there is a valid exponent
422 while (exp2 < 0) {
423 hpd.shift(-1);
424 ++exp2;
425 }
426 // Shift right one more time to compensate for the left shift to get it
427 // between 1 and 2.
428 hpd.shift(-1);
429 final_mantissa = hpd.round_to_integer_type<StorageType>(round);
430
431 // Check if by shifting right we've caused this to round to a normal number.
432 if ((final_mantissa >> FPBits::FRACTION_LEN) != 0) {
433 ++exp2;
434 }
435 }
436
437 // Check if rounding added a bit, and shift down if that's the case.
438 if (final_mantissa == StorageType(2) << FPBits::FRACTION_LEN) {
439 final_mantissa >>= 1;
440 ++exp2;
441
442 // Check if this rounding causes exp2 to go out of range and make the result
443 // INF. If this is the case, then finalMantissa and exp2 are already the
444 // correct values for an INF result.
445 if (exp2 >= FPBits::MAX_BIASED_EXPONENT) {
446 output.error = ERANGE;
447 }
448 }
449
450 if (exp2 == 0) {
451 output.error = ERANGE;
452 }
453
454 output.num = {final_mantissa, exp2};
455 return output;
456}
457
458// This class is used for templating the constants for Clinger's Fast Path,
459// described as a method of approximation in
460// Clinger WD. How to Read Floating Point Numbers Accurately. SIGPLAN Not 1990
461// Jun;25(6):92–101. https://doi.org/10.1145/93548.93557.
462// As well as the additions by Gay that extend the useful range by the number of
463// exact digits stored by the float type, described in
464// Gay DM, Correctly rounded binary-decimal and decimal-binary conversions;
465// 1990. AT&T Bell Laboratories Numerical Analysis Manuscript 90-10.
466template <class T> class ClingerConsts;
467
468template <> class ClingerConsts<float> {
469public:
470 static constexpr float POWERS_OF_TEN_ARRAY[] = {1e0, 1e1, 1e2, 1e3, 1e4, 1e5,
471 1e6, 1e7, 1e8, 1e9, 1e10};
472 static constexpr int32_t EXACT_POWERS_OF_TEN = 10;
473 static constexpr int32_t DIGITS_IN_MANTISSA = 7;
474 static constexpr float MAX_EXACT_INT = 16777215.0;
475};
476
477template <> class ClingerConsts<double> {
478public:
479 static constexpr double POWERS_OF_TEN_ARRAY[] = {
480 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11,
481 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22};
482 static constexpr int32_t EXACT_POWERS_OF_TEN = 22;
483 static constexpr int32_t DIGITS_IN_MANTISSA = 15;
484 static constexpr double MAX_EXACT_INT = 9007199254740991.0;
485};
486
487#if defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64)
488template <> class ClingerConsts<long double> {
489public:
490 static constexpr long double POWERS_OF_TEN_ARRAY[] = {
491 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11,
492 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22};
493 static constexpr int32_t EXACT_POWERS_OF_TEN =
494 ClingerConsts<double>::EXACT_POWERS_OF_TEN;
495 static constexpr int32_t DIGITS_IN_MANTISSA =
496 ClingerConsts<double>::DIGITS_IN_MANTISSA;
497 static constexpr long double MAX_EXACT_INT =
498 ClingerConsts<double>::MAX_EXACT_INT;
499};
500#elif defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80)
501template <> class ClingerConsts<long double> {
502public:
503 static constexpr long double POWERS_OF_TEN_ARRAY[] = {
504 1e0L, 1e1L, 1e2L, 1e3L, 1e4L, 1e5L, 1e6L, 1e7L, 1e8L, 1e9L,
505 1e10L, 1e11L, 1e12L, 1e13L, 1e14L, 1e15L, 1e16L, 1e17L, 1e18L, 1e19L,
506 1e20L, 1e21L, 1e22L, 1e23L, 1e24L, 1e25L, 1e26L, 1e27L};
507 static constexpr int32_t EXACT_POWERS_OF_TEN = 27;
508 static constexpr int32_t DIGITS_IN_MANTISSA = 21;
509 static constexpr long double MAX_EXACT_INT = 18446744073709551615.0L;
510};
511#elif defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128)
512template <> class ClingerConsts<long double> {
513public:
514 static constexpr long double POWERS_OF_TEN_ARRAY[] = {
515 1e0L, 1e1L, 1e2L, 1e3L, 1e4L, 1e5L, 1e6L, 1e7L, 1e8L, 1e9L,
516 1e10L, 1e11L, 1e12L, 1e13L, 1e14L, 1e15L, 1e16L, 1e17L, 1e18L, 1e19L,
517 1e20L, 1e21L, 1e22L, 1e23L, 1e24L, 1e25L, 1e26L, 1e27L, 1e28L, 1e29L,
518 1e30L, 1e31L, 1e32L, 1e33L, 1e34L, 1e35L, 1e36L, 1e37L, 1e38L, 1e39L,
519 1e40L, 1e41L, 1e42L, 1e43L, 1e44L, 1e45L, 1e46L, 1e47L, 1e48L};
520 static constexpr int32_t EXACT_POWERS_OF_TEN = 48;
521 static constexpr int32_t DIGITS_IN_MANTISSA = 33;
522 static constexpr long double MAX_EXACT_INT =
523 10384593717069655257060992658440191.0L;
524};
525#elif defined(LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE)
526// TODO: Add proper double double type support here, currently using constants
527// for double since it should be safe.
528template <> class ClingerConsts<long double> {
529public:
530 static constexpr double POWERS_OF_TEN_ARRAY[] = {
531 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11,
532 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22};
533 static constexpr int32_t EXACT_POWERS_OF_TEN = 22;
534 static constexpr int32_t DIGITS_IN_MANTISSA = 15;
535 static constexpr double MAX_EXACT_INT = 9007199254740991.0;
536};
537#else
538#error "Unknown long double type"
539#endif
540
541// Take an exact mantissa and exponent and attempt to convert it using only
542// exact floating point arithmetic. This only handles numbers with low
543// exponents, but handles them quickly. This is an implementation of Clinger's
544// Fast Path, as described above.
545template <class T>
546LIBC_INLINE cpp::optional<ExpandedFloat<T>>
547clinger_fast_path(ExpandedFloat<T> init_num,
548 RoundDirection round = RoundDirection::Nearest) {
549 using FPBits = typename fputil::FPBits<T>;
550 using StorageType = typename FPBits::StorageType;
551
552 StorageType mantissa = init_num.mantissa;
553 int32_t exp10 = init_num.exponent;
554
555 if ((mantissa >> FPBits::FRACTION_LEN) > 0) {
556 return cpp::nullopt;
557 }
558
559 FPBits result;
560 T float_mantissa;
561 if constexpr (is_big_int_v<StorageType> || sizeof(T) > sizeof(uint64_t)) {
562 float_mantissa =
563 (static_cast<T>(uint64_t(mantissa >> 64)) * static_cast<T>(0x1.0p64)) +
564 static_cast<T>(uint64_t(mantissa));
565 } else {
566 float_mantissa = static_cast<T>(mantissa);
567 }
568
569 if (exp10 == 0) {
570 result = FPBits(float_mantissa);
571 }
572 if (exp10 > 0) {
573 if (exp10 > ClingerConsts<T>::EXACT_POWERS_OF_TEN +
574 ClingerConsts<T>::DIGITS_IN_MANTISSA) {
575 return cpp::nullopt;
576 }
577 if (exp10 > ClingerConsts<T>::EXACT_POWERS_OF_TEN) {
578 float_mantissa = float_mantissa *
579 ClingerConsts<T>::POWERS_OF_TEN_ARRAY
580 [exp10 - ClingerConsts<T>::EXACT_POWERS_OF_TEN];
581 exp10 = ClingerConsts<T>::EXACT_POWERS_OF_TEN;
582 }
583 if (float_mantissa > ClingerConsts<T>::MAX_EXACT_INT) {
584 return cpp::nullopt;
585 }
586 result =
587 FPBits(float_mantissa * ClingerConsts<T>::POWERS_OF_TEN_ARRAY[exp10]);
588 } else if (exp10 < 0) {
589 if (-exp10 > ClingerConsts<T>::EXACT_POWERS_OF_TEN) {
590 return cpp::nullopt;
591 }
592 result =
593 FPBits(float_mantissa / ClingerConsts<T>::POWERS_OF_TEN_ARRAY[-exp10]);
594 }
595
596 // If the rounding mode is not nearest, then the sign of the number may affect
597 // the result. To make sure the rounding mode is respected properly, the
598 // calculation is redone with a negative result, and the rounding mode is used
599 // to select the correct result.
600 if (round != RoundDirection::Nearest) {
601 FPBits negative_result;
602 // I'm 99% sure this will break under fast math optimizations.
603 negative_result = FPBits((-float_mantissa) *
604 ClingerConsts<T>::POWERS_OF_TEN_ARRAY[exp10]);
605
606 // If the results are equal, then we don't need to use the rounding mode.
607 if (result.get_val() != -negative_result.get_val()) {
608 FPBits lower_result;
609 FPBits higher_result;
610
611 if (result.get_val() < -negative_result.get_val()) {
612 lower_result = result;
613 higher_result = negative_result;
614 } else {
615 lower_result = negative_result;
616 higher_result = result;
617 }
618
619 if (round == RoundDirection::Up) {
620 result = higher_result;
621 } else {
622 result = lower_result;
623 }
624 }
625 }
626
627 ExpandedFloat<T> output;
628 output.mantissa = result.get_explicit_mantissa();
629 output.exponent = result.get_biased_exponent();
630 return output;
631}
632
633// The upper bound is the highest base-10 exponent that could possibly give a
634// non-inf result for this size of float. The value is
635// log10(2^(exponent bias)).
636// The generic approximation uses the fact that log10(2^x) ~= x/3
637template <typename T> LIBC_INLINE constexpr int32_t get_upper_bound() {
638 return fputil::FPBits<T>::EXP_BIAS / 3;
639}
640
641template <> LIBC_INLINE constexpr int32_t get_upper_bound<float>() {
642 return 39;
643}
644
645template <> LIBC_INLINE constexpr int32_t get_upper_bound<double>() {
646 return 309;
647}
648
649// The lower bound is the largest negative base-10 exponent that could possibly
650// give a non-zero result for this size of float. The value is
651// log10(2^(exponent bias + final mantissa width + intermediate mantissa width))
652// The intermediate mantissa is the integer that's been parsed from the string,
653// and the final mantissa is the fractional part of the output number. A very
654// low base 10 exponent with a very high intermediate mantissa can cancel each
655// other out, and subnormal numbers allow for the result to be at the very low
656// end of the final mantissa.
657template <typename T> LIBC_INLINE constexpr int32_t get_lower_bound() {
658 using FPBits = typename fputil::FPBits<T>;
659 return -((FPBits::EXP_BIAS +
660 static_cast<int32_t>(FPBits::FRACTION_LEN + FPBits::STORAGE_LEN)) /
661 3);
662}
663
664template <> LIBC_INLINE constexpr int32_t get_lower_bound<float>() {
665 return -(39 + 6 + 10);
666}
667
668template <> LIBC_INLINE constexpr int32_t get_lower_bound<double>() {
669 return -(309 + 15 + 20);
670}
671
672// -----------------------------------------------------------------------------
673// **** WARNING ****
674// This interface is shared with libc++, if you change this interface you need
675// to update it in both libc and libc++.
676// -----------------------------------------------------------------------------
677// Takes a mantissa and base 10 exponent and converts it into its closest
678// floating point type T equivalient. First we try the Eisel-Lemire algorithm,
679// then if that fails then we fall back to a more accurate algorithm for
680// accuracy. The resulting mantissa and exponent are placed in outputMantissa
681// and outputExp2.
682template <class T>
683LIBC_INLINE FloatConvertReturn<T> decimal_exp_to_float(
684 ExpandedFloat<T> init_num, bool truncated, RoundDirection round,
685 const char *__restrict numStart,
686 const size_t num_len = cpp::numeric_limits<size_t>::max()) {
687 using FPBits = typename fputil::FPBits<T>;
688 using StorageType = typename FPBits::StorageType;
689
690 StorageType mantissa = init_num.mantissa;
691 int32_t exp10 = init_num.exponent;
692
693 FloatConvertReturn<T> output;
694 cpp::optional<ExpandedFloat<T>> opt_output;
695
696 // If the exponent is too large and can't be represented in this size of
697 // float, return inf. These bounds are relatively loose, but are mostly
698 // serving as a first pass. Some close numbers getting through is okay.
699 if (exp10 > get_upper_bound<T>()) {
700 output.num = {0, FPBits::MAX_BIASED_EXPONENT};
701 output.error = ERANGE;
702 return output;
703 }
704 // If the exponent is too small even for a subnormal, return 0.
705 if (exp10 < get_lower_bound<T>()) {
706 output.num = {0, 0};
707 output.error = ERANGE;
708 return output;
709 }
710
711 // Clinger's Fast Path and Eisel-Lemire can't set errno, but they can fail.
712 // For this reason the "error" field in their return values is used to
713 // represent whether they've failed as opposed to the errno value. Any
714 // non-zero value represents a failure.
715
716#ifndef LIBC_COPT_STRTOFLOAT_DISABLE_CLINGER_FAST_PATH
717 if (!truncated) {
718 opt_output = clinger_fast_path<T>(init_num, round);
719 // If the algorithm succeeded the error will be 0, else it will be a
720 // non-zero number.
721 if (opt_output.has_value()) {
722 return {opt_output.value(), 0};
723 }
724 }
725#endif // LIBC_COPT_STRTOFLOAT_DISABLE_CLINGER_FAST_PATH
726
727#ifndef LIBC_COPT_STRTOFLOAT_DISABLE_EISEL_LEMIRE
728 // Try Eisel-Lemire
729 opt_output = eisel_lemire<T>(init_num, round);
730 if (opt_output.has_value()) {
731 if (!truncated) {
732 return {opt_output.value(), 0};
733 }
734 // If the mantissa is truncated, then the result may be off by the LSB, so
735 // check if rounding the mantissa up changes the result. If not, then it's
736 // safe, else use the fallback.
737 auto second_output = eisel_lemire<T>({mantissa + 1, exp10}, round);
738 if (second_output.has_value()) {
739 if (opt_output->mantissa == second_output->mantissa &&
740 opt_output->exponent == second_output->exponent) {
741 return {opt_output.value(), 0};
742 }
743 }
744 }
745#endif // LIBC_COPT_STRTOFLOAT_DISABLE_EISEL_LEMIRE
746
747#ifndef LIBC_COPT_STRTOFLOAT_DISABLE_SIMPLE_DECIMAL_CONVERSION
748 output = simple_decimal_conversion<T>(numStart, num_len, round);
749#else
750#warning "Simple decimal conversion is disabled, result may not be correct."
751#endif // LIBC_COPT_STRTOFLOAT_DISABLE_SIMPLE_DECIMAL_CONVERSION
752
753 return output;
754}
755
756// -----------------------------------------------------------------------------
757// **** WARNING ****
758// This interface is shared with libc++, if you change this interface you need
759// to update it in both libc and libc++.
760// -----------------------------------------------------------------------------
761// Takes a mantissa and base 2 exponent and converts it into its closest
762// floating point type T equivalient. Since the exponent is already in the right
763// form, this is mostly just shifting and rounding. This is used for hexadecimal
764// numbers since a base 16 exponent multiplied by 4 is the base 2 exponent.
765template <class T>
766LIBC_INLINE FloatConvertReturn<T> binary_exp_to_float(ExpandedFloat<T> init_num,
767 bool truncated,
768 RoundDirection round) {
769 using FPBits = typename fputil::FPBits<T>;
770 using StorageType = typename FPBits::StorageType;
771
772 StorageType mantissa = init_num.mantissa;
773 int32_t exp2 = init_num.exponent;
774
775 FloatConvertReturn<T> output;
776
777 // This is the number of leading zeroes a properly normalized float of type T
778 // should have.
779 constexpr int32_t INF_EXP = (1 << FPBits::EXP_LEN) - 1;
780
781 // Normalization step 1: Bring the leading bit to the highest bit of
782 // StorageType.
783 uint32_t amount_to_shift_left = cpp::countl_zero<StorageType>(mantissa);
784 mantissa <<= amount_to_shift_left;
785
786 // Keep exp2 representing the exponent of the lowest bit of StorageType.
787 exp2 -= amount_to_shift_left;
788
789 // biased_exponent represents the biased exponent of the most significant bit.
790 int32_t biased_exponent = exp2 + FPBits::STORAGE_LEN + FPBits::EXP_BIAS - 1;
791
792 // Handle numbers that're too large and get squashed to inf
793 if (biased_exponent >= INF_EXP) {
794 // This indicates an overflow, so we make the result INF and set errno.
795 output.num = {0, (1 << FPBits::EXP_LEN) - 1};
796 output.error = ERANGE;
797 return output;
798 }
799
800 uint32_t amount_to_shift_right =
801 FPBits::STORAGE_LEN - FPBits::FRACTION_LEN - 1;
802
803 // Handle subnormals.
804 if (biased_exponent <= 0) {
805 amount_to_shift_right += 1 - biased_exponent;
806 biased_exponent = 0;
807
808 if (amount_to_shift_right > FPBits::STORAGE_LEN) {
809 // Return 0 if the exponent is too small.
810 output.num = {0, 0};
811 output.error = ERANGE;
812 return output;
813 }
814 }
815
816 StorageType round_bit_mask = StorageType(1) << (amount_to_shift_right - 1);
817 StorageType sticky_mask = round_bit_mask - 1;
818 bool round_bit = static_cast<bool>(mantissa & round_bit_mask);
819 bool sticky_bit = static_cast<bool>(mantissa & sticky_mask) || truncated;
820
821 if (amount_to_shift_right < FPBits::STORAGE_LEN) {
822 // Shift the mantissa and clear the implicit bit.
823 mantissa >>= amount_to_shift_right;
824 mantissa &= FPBits::FRACTION_MASK;
825 } else {
826 mantissa = 0;
827 }
828 bool least_significant_bit = static_cast<bool>(mantissa & StorageType(1));
829
830 // TODO: check that this rounding behavior is correct.
831
832 if (round == RoundDirection::Nearest) {
833 // Perform rounding-to-nearest, tie-to-even.
834 if (round_bit && (least_significant_bit || sticky_bit)) {
835 ++mantissa;
836 }
837 } else if (round == RoundDirection::Up) {
838 if (round_bit || sticky_bit) {
839 ++mantissa;
840 }
841 } else /* (round == RoundDirection::Down)*/ {
842 if (round_bit && sticky_bit) {
843 ++mantissa;
844 }
845 }
846
847 if (mantissa > FPBits::FRACTION_MASK) {
848 // Rounding causes the exponent to increase.
849 ++biased_exponent;
850
851 if (biased_exponent == INF_EXP) {
852 output.error = ERANGE;
853 }
854 }
855
856 if (biased_exponent == 0) {
857 output.error = ERANGE;
858 }
859
860 output.num = {mantissa & FPBits::FRACTION_MASK, biased_exponent};
861 return output;
862}
863
864// checks if the next 4 characters of the string pointer are the start of a
865// hexadecimal floating point number. Does not advance the string pointer.
866LIBC_INLINE bool is_float_hex_start(const char *__restrict src,
867 const char decimalPoint) {
868 if (!(src[0] == '0' && tolower(src[1]) == 'x')) {
869 return false;
870 }
871 size_t first_digit = 2;
872 if (src[2] == decimalPoint) {
873 ++first_digit;
874 }
875 return isalnum(src[first_digit]) && b36_char_to_int(src[first_digit]) < 16;
876}
877
878// Takes the start of a string representing a decimal float, as well as the
879// local decimalPoint. It returns if it suceeded in parsing any digits, and if
880// the return value is true then the outputs are pointer to the end of the
881// number, and the mantissa and exponent for the closest float T representation.
882// If the return value is false, then it is assumed that there is no number
883// here.
884template <class T>
885LIBC_INLINE StrToNumResult<ExpandedFloat<T>>
886decimal_string_to_float(const char *__restrict src, const char DECIMAL_POINT,
887 RoundDirection round) {
888 using FPBits = typename fputil::FPBits<T>;
889 using StorageType = typename FPBits::StorageType;
890
891 constexpr uint32_t BASE = 10;
892 constexpr char EXPONENT_MARKER = 'e';
893
894 bool truncated = false;
895 bool seen_digit = false;
896 bool after_decimal = false;
897 StorageType mantissa = 0;
898 int32_t exponent = 0;
899
900 size_t index = 0;
901
902 StrToNumResult<ExpandedFloat<T>> output({0, 0});
903
904 // The goal for the first step of parsing is to convert the number in src to
905 // the format mantissa * (base ^ exponent)
906
907 // The loop fills the mantissa with as many digits as it can hold
908 const StorageType bitstype_max_div_by_base =
909 cpp::numeric_limits<StorageType>::max() / BASE;
910 while (true) {
911 if (isdigit(src[index])) {
912 uint32_t digit = b36_char_to_int(src[index]);
913 seen_digit = true;
914
915 if (mantissa < bitstype_max_div_by_base) {
916 mantissa = (mantissa * BASE) + digit;
917 if (after_decimal) {
918 --exponent;
919 }
920 } else {
921 if (digit > 0)
922 truncated = true;
923 if (!after_decimal)
924 ++exponent;
925 }
926
927 ++index;
928 continue;
929 }
930 if (src[index] == DECIMAL_POINT) {
931 if (after_decimal) {
932 break; // this means that src[index] points to a second decimal point,
933 // ending the number.
934 }
935 after_decimal = true;
936 ++index;
937 continue;
938 }
939 // The character is neither a digit nor a decimal point.
940 break;
941 }
942
943 if (!seen_digit)
944 return output;
945
946 // TODO: When adding max length argument, handle the case of a trailing
947 // EXPONENT MARKER, see scanf for more details.
948 if (tolower(src[index]) == EXPONENT_MARKER) {
949 bool has_sign = false;
950 if (src[index + 1] == '+' || src[index + 1] == '-') {
951 has_sign = true;
952 }
953 if (isdigit(src[index + 1 + static_cast<size_t>(has_sign)])) {
954 ++index;
955 auto result = strtointeger<int32_t>(src + index, 10);
956 if (result.has_error())
957 output.error = result.error;
958 int32_t add_to_exponent = result.value;
959 index += result.parsed_len;
960
961 // Here we do this operation as int64 to avoid overflow.
962 int64_t temp_exponent = static_cast<int64_t>(exponent) +
963 static_cast<int64_t>(add_to_exponent);
964
965 // If the result is in the valid range, then we use it. The valid range is
966 // also within the int32 range, so this prevents overflow issues.
967 if (temp_exponent > FPBits::MAX_BIASED_EXPONENT) {
968 exponent = FPBits::MAX_BIASED_EXPONENT;
969 } else if (temp_exponent < -FPBits::MAX_BIASED_EXPONENT) {
970 exponent = -FPBits::MAX_BIASED_EXPONENT;
971 } else {
972 exponent = static_cast<int32_t>(temp_exponent);
973 }
974 }
975 }
976
977 output.parsed_len = index;
978 if (mantissa == 0) { // if we have a 0, then also 0 the exponent.
979 output.value = {0, 0};
980 } else {
981 auto temp =
982 decimal_exp_to_float<T>({mantissa, exponent}, truncated, round, src);
983 output.value = temp.num;
984 output.error = temp.error;
985 }
986 return output;
987}
988
989// Takes the start of a string representing a hexadecimal float, as well as the
990// local decimal point. It returns if it suceeded in parsing any digits, and if
991// the return value is true then the outputs are pointer to the end of the
992// number, and the mantissa and exponent for the closest float T representation.
993// If the return value is false, then it is assumed that there is no number
994// here.
995template <class T>
996LIBC_INLINE StrToNumResult<ExpandedFloat<T>>
997hexadecimal_string_to_float(const char *__restrict src,
998 const char DECIMAL_POINT, RoundDirection round) {
999 using FPBits = typename fputil::FPBits<T>;
1000 using StorageType = typename FPBits::StorageType;
1001
1002 constexpr uint32_t BASE = 16;
1003 constexpr char EXPONENT_MARKER = 'p';
1004
1005 bool truncated = false;
1006 bool seen_digit = false;
1007 bool after_decimal = false;
1008 StorageType mantissa = 0;
1009 int32_t exponent = 0;
1010
1011 size_t index = 0;
1012
1013 StrToNumResult<ExpandedFloat<T>> output({0, 0});
1014
1015 // The goal for the first step of parsing is to convert the number in src to
1016 // the format mantissa * (base ^ exponent)
1017
1018 // The loop fills the mantissa with as many digits as it can hold
1019 const StorageType bitstype_max_div_by_base =
1020 cpp::numeric_limits<StorageType>::max() / BASE;
1021 while (true) {
1022 if (isalnum(src[index])) {
1023 uint32_t digit = b36_char_to_int(src[index]);
1024 if (digit < BASE)
1025 seen_digit = true;
1026 else
1027 break;
1028
1029 if (mantissa < bitstype_max_div_by_base) {
1030 mantissa = (mantissa * BASE) + digit;
1031 if (after_decimal)
1032 --exponent;
1033 } else {
1034 if (digit > 0)
1035 truncated = true;
1036 if (!after_decimal)
1037 ++exponent;
1038 }
1039 ++index;
1040 continue;
1041 }
1042 if (src[index] == DECIMAL_POINT) {
1043 if (after_decimal) {
1044 break; // this means that src[index] points to a second decimal point,
1045 // ending the number.
1046 }
1047 after_decimal = true;
1048 ++index;
1049 continue;
1050 }
1051 // The character is neither a hexadecimal digit nor a decimal point.
1052 break;
1053 }
1054
1055 if (!seen_digit)
1056 return output;
1057
1058 // Convert the exponent from having a base of 16 to having a base of 2.
1059 exponent *= 4;
1060
1061 if (tolower(src[index]) == EXPONENT_MARKER) {
1062 bool has_sign = false;
1063 if (src[index + 1] == '+' || src[index + 1] == '-') {
1064 has_sign = true;
1065 }
1066 if (isdigit(src[index + 1 + static_cast<size_t>(has_sign)])) {
1067 ++index;
1068 auto result = strtointeger<int32_t>(src + index, 10);
1069 if (result.has_error())
1070 output.error = result.error;
1071
1072 int32_t add_to_exponent = result.value;
1073 index += result.parsed_len;
1074
1075 // Here we do this operation as int64 to avoid overflow.
1076 int64_t temp_exponent = static_cast<int64_t>(exponent) +
1077 static_cast<int64_t>(add_to_exponent);
1078
1079 // If the result is in the valid range, then we use it. The valid range is
1080 // also within the int32 range, so this prevents overflow issues.
1081 if (temp_exponent > FPBits::MAX_BIASED_EXPONENT) {
1082 exponent = FPBits::MAX_BIASED_EXPONENT;
1083 } else if (temp_exponent < -FPBits::MAX_BIASED_EXPONENT) {
1084 exponent = -FPBits::MAX_BIASED_EXPONENT;
1085 } else {
1086 exponent = static_cast<int32_t>(temp_exponent);
1087 }
1088 }
1089 }
1090 output.parsed_len = index;
1091 if (mantissa == 0) { // if we have a 0, then also 0 the exponent.
1092 output.value.exponent = 0;
1093 output.value.mantissa = 0;
1094 } else {
1095 auto temp = binary_exp_to_float<T>({mantissa, exponent}, truncated, round);
1096 output.error = temp.error;
1097 output.value = temp.num;
1098 }
1099 return output;
1100}
1101
1102template <class T>
1103LIBC_INLINE typename fputil::FPBits<T>::StorageType
1104nan_mantissa_from_ncharseq(const cpp::string_view ncharseq) {
1105 using FPBits = typename fputil::FPBits<T>;
1106 using StorageType = typename FPBits::StorageType;
1107
1108 StorageType nan_mantissa = 0;
1109
1110 if (ncharseq.data() != nullptr && isdigit(ncharseq[0])) {
1111 StrToNumResult<StorageType> strtoint_result =
1112 strtointeger<StorageType>(ncharseq.data(), 0);
1113 if (!strtoint_result.has_error())
1114 nan_mantissa = strtoint_result.value;
1115
1116 if (strtoint_result.parsed_len != static_cast<ptrdiff_t>(ncharseq.size()))
1117 nan_mantissa = 0;
1118 }
1119
1120 return nan_mantissa;
1121}
1122
1123// Takes a pointer to a string and a pointer to a string pointer. This function
1124// is used as the backend for all of the string to float functions.
1125// TODO: Add src_len member to match strtointeger.
1126// TODO: Next, move from char* and length to string_view
1127template <class T>
1128LIBC_INLINE StrToNumResult<T> strtofloatingpoint(const char *__restrict src) {
1129 using FPBits = typename fputil::FPBits<T>;
1130 using StorageType = typename FPBits::StorageType;
1131
1132 FPBits result = FPBits();
1133 bool seen_digit = false;
1134 char sign = '+';
1135
1136 int error = 0;
1137
1138 ptrdiff_t index = first_non_whitespace(src) - src;
1139
1140 if (src[index] == '+' || src[index] == '-') {
1141 sign = src[index];
1142 ++index;
1143 }
1144
1145 if (sign == '-') {
1146 result.set_sign(Sign::NEG);
1147 }
1148
1149 static constexpr char DECIMAL_POINT = '.';
1150 static const char *inf_string = "infinity";
1151 static const char *nan_string = "nan";
1152
1153 if (isdigit(src[index]) || src[index] == DECIMAL_POINT) { // regular number
1154 int base = 10;
1155 if (is_float_hex_start(src + index, DECIMAL_POINT)) {
1156 base = 16;
1157 index += 2;
1158 seen_digit = true;
1159 }
1160
1161 RoundDirection round_direction = RoundDirection::Nearest;
1162
1163 switch (fputil::quick_get_round()) {
1164 case FE_TONEAREST:
1165 round_direction = RoundDirection::Nearest;
1166 break;
1167 case FE_UPWARD:
1168 if (sign == '+') {
1169 round_direction = RoundDirection::Up;
1170 } else {
1171 round_direction = RoundDirection::Down;
1172 }
1173 break;
1174 case FE_DOWNWARD:
1175 if (sign == '+') {
1176 round_direction = RoundDirection::Down;
1177 } else {
1178 round_direction = RoundDirection::Up;
1179 }
1180 break;
1181 case FE_TOWARDZERO:
1182 round_direction = RoundDirection::Down;
1183 break;
1184 }
1185
1186 StrToNumResult<ExpandedFloat<T>> parse_result({0, 0});
1187 if (base == 16) {
1188 parse_result = hexadecimal_string_to_float<T>(src + index, DECIMAL_POINT,
1189 round_direction);
1190 } else { // base is 10
1191 parse_result = decimal_string_to_float<T>(src + index, DECIMAL_POINT,
1192 round_direction);
1193 }
1194 seen_digit = parse_result.parsed_len != 0;
1195 result.set_mantissa(parse_result.value.mantissa);
1196 result.set_biased_exponent(parse_result.value.exponent);
1197 index += parse_result.parsed_len;
1198 error = parse_result.error;
1199 } else if (tolower(src[index]) == 'n') { // NaN
1200 if (tolower(src[index + 1]) == nan_string[1] &&
1201 tolower(src[index + 2]) == nan_string[2]) {
1202 seen_digit = true;
1203 index += 3;
1204 StorageType nan_mantissa = 0;
1205 // this handles the case of `NaN(n-character-sequence)`, where the
1206 // n-character-sequence is made of 0 or more letters, numbers, or
1207 // underscore characters in any order.
1208 if (src[index] == '(') {
1209 size_t left_paren = index;
1210 ++index;
1211 while (isalnum(src[index]) || src[index] == '_')
1212 ++index;
1213 if (src[index] == ')') {
1214 ++index;
1215 nan_mantissa = nan_mantissa_from_ncharseq<T>(
1216 cpp::string_view(src + (left_paren + 1), index - left_paren - 2));
1217 } else {
1218 index = left_paren;
1219 }
1220 }
1221 result = FPBits(result.quiet_nan(result.sign(), nan_mantissa));
1222 }
1223 } else if (tolower(src[index]) == 'i') { // INF
1224 if (tolower(src[index + 1]) == inf_string[1] &&
1225 tolower(src[index + 2]) == inf_string[2]) {
1226 seen_digit = true;
1227 result = FPBits(result.inf(result.sign()));
1228 if (tolower(src[index + 3]) == inf_string[3] &&
1229 tolower(src[index + 4]) == inf_string[4] &&
1230 tolower(src[index + 5]) == inf_string[5] &&
1231 tolower(src[index + 6]) == inf_string[6] &&
1232 tolower(src[index + 7]) == inf_string[7]) {
1233 // if the string is "INFINITY" then consume 8 characters.
1234 index += 8;
1235 } else {
1236 index += 3;
1237 }
1238 }
1239 }
1240 if (!seen_digit) { // If there is nothing to actually parse, then return 0.
1241 return {T(0), 0, error};
1242 }
1243
1244 // This function only does something if T is long double and the platform uses
1245 // special 80 bit long doubles. Otherwise it should be inlined out.
1246 set_implicit_bit<T>(result);
1247
1248 return {result.get_val(), index, error};
1249}
1250
1251template <class T> LIBC_INLINE StrToNumResult<T> strtonan(const char *arg) {
1252 using FPBits = typename fputil::FPBits<T>;
1253 using StorageType = typename FPBits::StorageType;
1254
1255 LIBC_CRASH_ON_NULLPTR(arg);
1256
1257 FPBits result;
1258 int error = 0;
1259 StorageType nan_mantissa = 0;
1260
1261 ptrdiff_t index = 0;
1262 while (isalnum(arg[index]) || arg[index] == '_')
1263 ++index;
1264
1265 if (arg[index] == '\0')
1266 nan_mantissa = nan_mantissa_from_ncharseq<T>(cpp::string_view(arg, index));
1267
1268 result = FPBits::quiet_nan(Sign::POS, nan_mantissa);
1269 return {result.get_val(), 0, error};
1270}
1271
1272} // namespace internal
1273} // namespace LIBC_NAMESPACE_DECL
1274
1275#endif // LLVM_LIBC_SRC___SUPPORT_STR_TO_FLOAT_H
lib/libcxx/libc/src/__support/str_to_integer.h created+169
......@@ -0,0 +1,169 @@
1//===-- String to integer conversion utils ----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// -----------------------------------------------------------------------------
10// **** WARNING ****
11// This file is shared with libc++. You should also be careful when adding
12// dependencies to this file, since it needs to build for all libc++ targets.
13// -----------------------------------------------------------------------------
14
15#ifndef LLVM_LIBC_SRC___SUPPORT_STR_TO_INTEGER_H
16#define LLVM_LIBC_SRC___SUPPORT_STR_TO_INTEGER_H
17
18#include "src/__support/CPP/limits.h"
19#include "src/__support/CPP/type_traits.h"
20#include "src/__support/CPP/type_traits/make_unsigned.h"
21#include "src/__support/big_int.h"
22#include "src/__support/common.h"
23#include "src/__support/ctype_utils.h"
24#include "src/__support/macros/config.h"
25#include "src/__support/str_to_num_result.h"
26#include "src/__support/uint128.h"
27#include "src/errno/libc_errno.h" // For ERANGE
28
29namespace LIBC_NAMESPACE_DECL {
30namespace internal {
31
32// Returns a pointer to the first character in src that is not a whitespace
33// character (as determined by isspace())
34// TODO: Change from returning a pointer to returning a length.
35LIBC_INLINE const char *
36first_non_whitespace(const char *__restrict src,
37 size_t src_len = cpp::numeric_limits<size_t>::max()) {
38 size_t src_cur = 0;
39 while (src_cur < src_len && internal::isspace(src[src_cur])) {
40 ++src_cur;
41 }
42 return src + src_cur;
43}
44
45// checks if the next 3 characters of the string pointer are the start of a
46// hexadecimal number. Does not advance the string pointer.
47LIBC_INLINE bool
48is_hex_start(const char *__restrict src,
49 size_t src_len = cpp::numeric_limits<size_t>::max()) {
50 if (src_len < 3)
51 return false;
52 return *src == '0' && tolower(*(src + 1)) == 'x' && isalnum(*(src + 2)) &&
53 b36_char_to_int(*(src + 2)) < 16;
54}
55
56// Takes the address of the string pointer and parses the base from the start of
57// it.
58LIBC_INLINE int infer_base(const char *__restrict src, size_t src_len) {
59 // A hexadecimal number is defined as "the prefix 0x or 0X followed by a
60 // sequence of the decimal digits and the letters a (or A) through f (or F)
61 // with values 10 through 15 respectively." (C standard 6.4.4.1)
62 if (is_hex_start(src, src_len))
63 return 16;
64 // An octal number is defined as "the prefix 0 optionally followed by a
65 // sequence of the digits 0 through 7 only" (C standard 6.4.4.1) and so any
66 // number that starts with 0, including just 0, is an octal number.
67 if (src_len > 0 && src[0] == '0')
68 return 8;
69 // A decimal number is defined as beginning "with a nonzero digit and
70 // consist[ing] of a sequence of decimal digits." (C standard 6.4.4.1)
71 return 10;
72}
73
74// -----------------------------------------------------------------------------
75// **** WARNING ****
76// This interface is shared with libc++, if you change this interface you need
77// to update it in both libc and libc++.
78// -----------------------------------------------------------------------------
79// Takes a pointer to a string and the base to convert to. This function is used
80// as the backend for all of the string to int functions.
81template <class T>
82LIBC_INLINE StrToNumResult<T>
83strtointeger(const char *__restrict src, int base,
84 const size_t src_len = cpp::numeric_limits<size_t>::max()) {
85 using ResultType = make_integral_or_big_int_unsigned_t<T>;
86
87 ResultType result = 0;
88
89 bool is_number = false;
90 size_t src_cur = 0;
91 int error_val = 0;
92
93 if (src_len == 0)
94 return {0, 0, 0};
95
96 if (base < 0 || base == 1 || base > 36)
97 return {0, 0, EINVAL};
98
99 src_cur = first_non_whitespace(src, src_len) - src;
100
101 char result_sign = '+';
102 if (src[src_cur] == '+' || src[src_cur] == '-') {
103 result_sign = src[src_cur];
104 ++src_cur;
105 }
106
107 if (base == 0)
108 base = infer_base(src + src_cur, src_len - src_cur);
109
110 if (base == 16 && is_hex_start(src + src_cur, src_len - src_cur))
111 src_cur = src_cur + 2;
112
113 constexpr bool IS_UNSIGNED = cpp::is_unsigned_v<T>;
114 const bool is_positive = (result_sign == '+');
115
116 ResultType constexpr NEGATIVE_MAX =
117 !IS_UNSIGNED ? static_cast<ResultType>(cpp::numeric_limits<T>::max()) + 1
118 : cpp::numeric_limits<T>::max();
119 ResultType const abs_max =
120 (is_positive ? cpp::numeric_limits<T>::max() : NEGATIVE_MAX);
121 ResultType const abs_max_div_by_base =
122 static_cast<ResultType>(abs_max / base);
123
124 while (src_cur < src_len && isalnum(src[src_cur])) {
125 int cur_digit = b36_char_to_int(src[src_cur]);
126 if (cur_digit >= base)
127 break;
128
129 is_number = true;
130 ++src_cur;
131
132 // If the number has already hit the maximum value for the current type then
133 // the result cannot change, but we still need to advance src to the end of
134 // the number.
135 if (result == abs_max) {
136 error_val = ERANGE;
137 continue;
138 }
139
140 if (result > abs_max_div_by_base) {
141 result = abs_max;
142 error_val = ERANGE;
143 } else {
144 result = static_cast<ResultType>(result * base);
145 }
146 if (result > abs_max - cur_digit) {
147 result = abs_max;
148 error_val = ERANGE;
149 } else {
150 result = static_cast<ResultType>(result + cur_digit);
151 }
152 }
153
154 ptrdiff_t str_len = is_number ? (src_cur) : 0;
155
156 if (error_val == ERANGE) {
157 if (is_positive || IS_UNSIGNED)
158 return {cpp::numeric_limits<T>::max(), str_len, error_val};
159 else // T is signed and there is a negative overflow
160 return {cpp::numeric_limits<T>::min(), str_len, error_val};
161 }
162
163 return {static_cast<T>(is_positive ? result : -result), str_len, error_val};
164}
165
166} // namespace internal
167} // namespace LIBC_NAMESPACE_DECL
168
169#endif // LLVM_LIBC_SRC___SUPPORT_STR_TO_INTEGER_H
lib/libcxx/libc/src/__support/str_to_num_result.h created+48
......@@ -0,0 +1,48 @@
1//===-- A data structure for str_to_number to return ------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// -----------------------------------------------------------------------------
10// **** WARNING ****
11// This file is shared with libc++. You should also be careful when adding
12// dependencies to this file, since it needs to build for all libc++ targets.
13// -----------------------------------------------------------------------------
14
15#ifndef LLVM_LIBC_SRC___SUPPORT_STR_TO_NUM_RESULT_H
16#define LLVM_LIBC_SRC___SUPPORT_STR_TO_NUM_RESULT_H
17
18#include "src/__support/macros/attributes.h" // LIBC_INLINE
19#include "src/__support/macros/config.h"
20
21#include <stddef.h>
22
23namespace LIBC_NAMESPACE_DECL {
24
25// -----------------------------------------------------------------------------
26// **** WARNING ****
27// This interface is shared with libc++, if you change this interface you need
28// to update it in both libc and libc++.
29// -----------------------------------------------------------------------------
30template <typename T> struct StrToNumResult {
31 T value;
32 int error;
33 ptrdiff_t parsed_len;
34
35 LIBC_INLINE constexpr StrToNumResult(T value)
36 : value(value), error(0), parsed_len(0) {}
37 LIBC_INLINE constexpr StrToNumResult(T value, ptrdiff_t parsed_len)
38 : value(value), error(0), parsed_len(parsed_len) {}
39 LIBC_INLINE constexpr StrToNumResult(T value, ptrdiff_t parsed_len, int error)
40 : value(value), error(error), parsed_len(parsed_len) {}
41
42 LIBC_INLINE constexpr bool has_error() { return error != 0; }
43
44 LIBC_INLINE constexpr operator T() { return value; }
45};
46} // namespace LIBC_NAMESPACE_DECL
47
48#endif // LLVM_LIBC_SRC___SUPPORT_STR_TO_NUM_RESULT_H
lib/libcxx/libc/src/__support/uint128.h created+23
......@@ -0,0 +1,23 @@
1//===-- 128-bit signed and unsigned int types -------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_UINT128_H
10#define LLVM_LIBC_SRC___SUPPORT_UINT128_H
11
12#include "big_int.h"
13#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
14
15#ifdef LIBC_TYPES_HAS_INT128
16using UInt128 = __uint128_t;
17using Int128 = __int128_t;
18#else
19using UInt128 = LIBC_NAMESPACE::UInt<128>;
20using Int128 = LIBC_NAMESPACE::Int<128>;
21#endif // LIBC_TYPES_HAS_INT128
22
23#endif // LLVM_LIBC_SRC___SUPPORT_UINT128_H
lib/libcxx/libc/src/errno/libc_errno.h created+47
......@@ -0,0 +1,47 @@
1//===-- Implementation header for libc_errno --------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC_ERRNO_LIBC_ERRNO_H
10#define LLVM_LIBC_SRC_ERRNO_LIBC_ERRNO_H
11
12#include "src/__support/macros/attributes.h"
13#include "src/__support/macros/config.h"
14#include "src/__support/macros/properties/architectures.h"
15
16#include "hdr/errno_macros.h"
17
18// This header is to be consumed by internal implementations, in which all of
19// them should refer to `libc_errno` instead of using `errno` directly from
20// <errno.h> header.
21
22// Unit and hermetic tests should:
23// - #include "src/errno/libc_errno.h"
24// - NOT #include <errno.h>
25// - Only use `libc_errno` in the code
26// - Depend on libc.src.errno.errno
27
28// Integration tests should:
29// - NOT #include "src/errno/libc_errno.h"
30// - #include <errno.h>
31// - Use regular `errno` in the code
32// - Still depend on libc.src.errno.errno
33
34namespace LIBC_NAMESPACE_DECL {
35
36extern "C" int *__llvm_libc_errno() noexcept;
37
38struct Errno {
39 void operator=(int);
40 operator int();
41};
42
43extern Errno libc_errno;
44
45} // namespace LIBC_NAMESPACE_DECL
46
47#endif // LLVM_LIBC_SRC_ERRNO_LIBC_ERRNO_H
lib/libcxx/src/algorithm.cpp+2-3
......@@ -21,13 +21,12 @@ void __sort(RandomAccessIterator first, RandomAccessIterator last, Comp comp) {
2121 std::__introsort<_ClassicAlgPolicy,
2222 ranges::less,
2323 RandomAccessIterator,
24 __use_branchless_sort<ranges::less, RandomAccessIterator>::value>(
25 first, last, ranges::less{}, depth_limit);
24 __use_branchless_sort<ranges::less, RandomAccessIterator>>(first, last, ranges::less{}, depth_limit);
2625}
2726
2827// clang-format off
2928template void __sort<__less<char>&, char*>(char*, char*, __less<char>&);
30#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
29#if _LIBCPP_HAS_WIDE_CHARACTERS
3130template void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
3231#endif
3332template void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
lib/libcxx/src/any.cpp+1-1
......@@ -12,7 +12,7 @@ namespace std {
1212const char* bad_any_cast::what() const noexcept { return "bad any cast"; }
1313} // namespace std
1414
15#include <experimental/__config>
15#include <__config>
1616
1717// Preserve std::experimental::any_bad_cast for ABI compatibility
1818// Even though it no longer exists in a header file
lib/libcxx/src/atomic.cpp+2-2
......@@ -94,11 +94,11 @@ static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const vo
9494
9595static void
9696__libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr, __cxx_contention_t __val) {
97 _umtx_op(const_cast<__cxx_atomic_contention_t*>(__ptr), UMTX_OP_WAIT, __val, NULL, NULL);
97 _umtx_op(const_cast<__cxx_atomic_contention_t*>(__ptr), UMTX_OP_WAIT, __val, nullptr, nullptr);
9898}
9999
100100static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile* __ptr, bool __notify_one) {
101 _umtx_op(const_cast<__cxx_atomic_contention_t*>(__ptr), UMTX_OP_WAKE, __notify_one ? 1 : INT_MAX, NULL, NULL);
101 _umtx_op(const_cast<__cxx_atomic_contention_t*>(__ptr), UMTX_OP_WAKE, __notify_one ? 1 : INT_MAX, nullptr, nullptr);
102102}
103103
104104#else // <- Add other operating systems here
lib/libcxx/src/barrier.cpp+1-5
......@@ -11,13 +11,11 @@
1111
1212_LIBCPP_BEGIN_NAMESPACE_STD
1313
14#if !defined(_LIBCPP_HAS_NO_TREE_BARRIER)
15
1614class __barrier_algorithm_base {
1715public:
1816 struct alignas(64) /* naturally-align the heap state */ __state_t {
1917 struct {
20 __atomic_base<__barrier_phase_t> __phase{0};
18 atomic<__barrier_phase_t> __phase{0};
2119 } __tickets[64];
2220 };
2321
......@@ -70,6 +68,4 @@ _LIBCPP_EXPORTED_FROM_ABI void __destroy_barrier_algorithm_base(__barrier_algori
7068 delete __barrier;
7169}
7270
73#endif // !defined(_LIBCPP_HAS_NO_TREE_BARRIER)
74
7571_LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/call_once.cpp+5-5
......@@ -9,7 +9,7 @@
99#include <__mutex/once_flag.h>
1010#include <__utility/exception_guard.h>
1111
12#ifndef _LIBCPP_HAS_NO_THREADS
12#if _LIBCPP_HAS_THREADS
1313# include <__thread/support.h>
1414#endif
1515
......@@ -23,13 +23,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2323// call into dispatch_once_f instead of here. Relevant radar this code needs to
2424// keep in sync with: 7741191.
2525
26#ifndef _LIBCPP_HAS_NO_THREADS
26#if _LIBCPP_HAS_THREADS
2727static constinit __libcpp_mutex_t mut = _LIBCPP_MUTEX_INITIALIZER;
2828static constinit __libcpp_condvar_t cv = _LIBCPP_CONDVAR_INITIALIZER;
2929#endif
3030
3131void __call_once(volatile once_flag::_State_type& flag, void* arg, void (*func)(void*)) {
32#if defined(_LIBCPP_HAS_NO_THREADS)
32#if !_LIBCPP_HAS_THREADS
3333
3434 if (flag == once_flag::_Unset) {
3535 auto guard = std::__make_exception_guard([&flag] { flag = once_flag::_Unset; });
......@@ -39,7 +39,7 @@ void __call_once(volatile once_flag::_State_type& flag, void* arg, void (*func)(
3939 guard.__complete();
4040 }
4141
42#else // !_LIBCPP_HAS_NO_THREADS
42#else // !_LIBCPP_HAS_THREADS
4343
4444 __libcpp_mutex_lock(&mut);
4545 while (flag == once_flag::_Pending)
......@@ -64,7 +64,7 @@ void __call_once(volatile once_flag::_State_type& flag, void* arg, void (*func)(
6464 __libcpp_mutex_unlock(&mut);
6565 }
6666
67#endif // !_LIBCPP_HAS_NO_THREADS
67#endif // !_LIBCPP_HAS_THREADS
6868}
6969
7070_LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/charconv.cpp+12
......@@ -9,6 +9,7 @@
99#include <charconv>
1010#include <string.h>
1111
12#include "include/from_chars_floating_point.h"
1213#include "include/to_chars_floating_point.h"
1314
1415_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -74,4 +75,15 @@ to_chars_result to_chars(char* __first, char* __last, long double __value, chars
7475 __first, __last, static_cast<double>(__value), __fmt, __precision);
7576}
7677
78template <class _Fp>
79__from_chars_result<_Fp> __from_chars_floating_point(
80 _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt) {
81 return std::__from_chars_floating_point_impl<_Fp>(__first, __last, __fmt);
82}
83
84template __from_chars_result<float> __from_chars_floating_point(
85 _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt);
86
87template __from_chars_result<double> __from_chars_floating_point(
88 _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt);
7789_LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/chrono.cpp+34-5
......@@ -12,7 +12,7 @@
1212# define _LARGE_TIME_API
1313#endif
1414
15#include <__system_error/system_error.h>
15#include <__system_error/throw_system_error.h>
1616#include <cerrno> // errno
1717#include <chrono>
1818
......@@ -31,9 +31,14 @@
3131# include <sys/time.h> // for gettimeofday and timeval
3232#endif
3333
34// OpenBSD does not have a fully conformant suite of POSIX timers, but
34#if defined(__LLVM_LIBC__)
35# define _LIBCPP_HAS_TIMESPEC_GET
36#endif
37
38// OpenBSD and GPU do not have a fully conformant suite of POSIX timers, but
3539// it does have clock_gettime and CLOCK_MONOTONIC which is all we need.
36#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__OpenBSD__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
40#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__OpenBSD__) || defined(__AMDGPU__) || \
41 defined(__NVPTX__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
3742# define _LIBCPP_HAS_CLOCK_GETTIME
3843#endif
3944
......@@ -114,6 +119,15 @@ static system_clock::time_point __libcpp_system_clock_now() {
114119 return system_clock::time_point(duration_cast<system_clock::duration>(d - nt_to_unix_epoch));
115120}
116121
122#elif defined(_LIBCPP_HAS_TIMESPEC_GET)
123
124static system_clock::time_point __libcpp_system_clock_now() {
125 struct timespec ts;
126 if (timespec_get(&ts, TIME_UTC) != TIME_UTC)
127 __throw_system_error(errno, "timespec_get(TIME_UTC) failed");
128 return system_clock::time_point(seconds(ts.tv_sec) + microseconds(ts.tv_nsec / 1000));
129}
130
117131#elif defined(_LIBCPP_HAS_CLOCK_GETTIME)
118132
119133static system_clock::time_point __libcpp_system_clock_now() {
......@@ -133,7 +147,10 @@ static system_clock::time_point __libcpp_system_clock_now() {
133147
134148#endif
135149
150_LIBCPP_DIAGNOSTIC_PUSH
151_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated")
136152const bool system_clock::is_steady;
153_LIBCPP_DIAGNOSTIC_POP
137154
138155system_clock::time_point system_clock::now() noexcept { return __libcpp_system_clock_now(); }
139156
......@@ -151,7 +168,7 @@ system_clock::time_point system_clock::from_time_t(time_t t) noexcept { return s
151168// instead.
152169//
153170
154#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
171#if _LIBCPP_HAS_MONOTONIC_CLOCK
155172
156173# if defined(__APPLE__)
157174
......@@ -212,6 +229,15 @@ static steady_clock::time_point __libcpp_steady_clock_now() noexcept {
212229 return steady_clock::time_point(nanoseconds(_zx_clock_get_monotonic()));
213230}
214231
232# elif defined(_LIBCPP_HAS_TIMESPEC_GET)
233
234static steady_clock::time_point __libcpp_steady_clock_now() {
235 struct timespec ts;
236 if (timespec_get(&ts, TIME_MONOTONIC) != TIME_MONOTONIC)
237 __throw_system_error(errno, "timespec_get(TIME_MONOTONIC) failed");
238 return steady_clock::time_point(seconds(ts.tv_sec) + microseconds(ts.tv_nsec / 1000));
239}
240
215241# elif defined(_LIBCPP_HAS_CLOCK_GETTIME)
216242
217243static steady_clock::time_point __libcpp_steady_clock_now() {
......@@ -225,11 +251,14 @@ static steady_clock::time_point __libcpp_steady_clock_now() {
225251# error "Monotonic clock not implemented on this platform"
226252# endif
227253
254_LIBCPP_DIAGNOSTIC_PUSH
255_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated")
228256const bool steady_clock::is_steady;
257_LIBCPP_DIAGNOSTIC_POP
229258
230259steady_clock::time_point steady_clock::now() noexcept { return __libcpp_steady_clock_now(); }
231260
232#endif // !_LIBCPP_HAS_NO_MONOTONIC_CLOCK
261#endif // _LIBCPP_HAS_MONOTONIC_CLOCK
233262
234263} // namespace chrono
235264
lib/libcxx/src/condition_variable_destructor.cpp+1-1
......@@ -14,7 +14,7 @@
1414#include <__config>
1515#include <__thread/support.h>
1616
17#if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION)
17#if _LIBCPP_ABI_VERSION == 1 || !_LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
1818# define NEEDS_CONDVAR_DESTRUCTOR
1919#endif
2020
lib/libcxx/src/exception.cpp+3
......@@ -6,6 +6,9 @@
66//
77//===----------------------------------------------------------------------===//
88
9#define _LIBCPP_ENABLE_CXX20_REMOVED_UNCAUGHT_EXCEPTION
10#define _LIBCPP_DISABLE_DEPRECATION_WARNINGS
11
912#include <exception>
1013#include <new>
1114#include <typeinfo>
lib/libcxx/src/experimental/include/tzdb/tzdb_list_private.h+6-6
......@@ -18,7 +18,7 @@
1818// When threads are available, we use std::mutex over std::shared_mutex
1919// due to the increased overhead of std::shared_mutex.
2020// See shared_mutex_vs_mutex.bench.cpp
21#ifndef _LIBCPP_HAS_NO_THREADS
21#if _LIBCPP_HAS_THREADS
2222# include <mutex>
2323#endif
2424
......@@ -48,7 +48,7 @@ public:
4848 __impl() { __load_no_lock(); }
4949
5050 [[nodiscard]] const tzdb& __load() {
51#ifndef _LIBCPP_HAS_NO_THREADS
51#if _LIBCPP_HAS_THREADS
5252 unique_lock __lock{__mutex_};
5353#endif
5454 __load_no_lock();
......@@ -58,14 +58,14 @@ public:
5858 using const_iterator = tzdb_list::const_iterator;
5959
6060 const tzdb& __front() const noexcept {
61#ifndef _LIBCPP_HAS_NO_THREADS
61#if _LIBCPP_HAS_THREADS
6262 unique_lock __lock{__mutex_};
6363#endif
6464 return __tzdb_.front();
6565 }
6666
6767 const_iterator __erase_after(const_iterator __p) {
68#ifndef _LIBCPP_HAS_NO_THREADS
68#if _LIBCPP_HAS_THREADS
6969 unique_lock __lock{__mutex_};
7070#endif
7171
......@@ -74,7 +74,7 @@ public:
7474 }
7575
7676 const_iterator __begin() const noexcept {
77#ifndef _LIBCPP_HAS_NO_THREADS
77#if _LIBCPP_HAS_THREADS
7878 unique_lock __lock{__mutex_};
7979#endif
8080 return __tzdb_.begin();
......@@ -89,7 +89,7 @@ private:
8989 // pre: The caller ensures the locking, if needed, is done.
9090 void __load_no_lock() { chrono::__init_tzdb(__tzdb_.emplace_front(), __rules_.emplace_front()); }
9191
92#ifndef _LIBCPP_HAS_NO_THREADS
92#if _LIBCPP_HAS_THREADS
9393 mutable mutex __mutex_;
9494#endif
9595 forward_list<tzdb> __tzdb_;
lib/libcxx/src/experimental/time_zone.cpp+4-4
......@@ -199,7 +199,7 @@ __format(const __tz::__continuation& __continuation, const string& __letters, se
199199 // active at the end. This should be determined separately.
200200 return chrono::seconds{0};
201201 else
202 static_assert(sizeof(_Tp) == 0); // TODO TZDB static_assert(false); after droping clang-16 support
202 static_assert(false);
203203
204204 std::__libcpp_unreachable();
205205 },
......@@ -225,7 +225,7 @@ __format(const __tz::__continuation& __continuation, const string& __letters, se
225225 else if constexpr (same_as<_Tp, __tz::__constrained_weekday>)
226226 return __value(__year, __month);
227227 else
228 static_assert(sizeof(_Tp) == 0); // TODO TZDB static_assert(false); after droping clang-16 support
228 static_assert(false);
229229
230230 std::__libcpp_unreachable();
231231 },
......@@ -668,7 +668,7 @@ __first_rule(seconds __stdoff, const vector<__tz::__rule>& __rules) {
668668 __continuation_end,
669669 __continuation.__stdoff + __save,
670670 chrono::duration_cast<minutes>(__save),
671 __continuation.__format},
671 chrono::__format(__continuation, __continuation.__format, __save)},
672672 true};
673673}
674674
......@@ -688,7 +688,7 @@ __get_sys_info(sys_seconds __time,
688688 else if constexpr (same_as<_Tp, __tz::__save>)
689689 return chrono::__get_sys_info_basic(__time, __continuation_begin, __continuation, __value.__time);
690690 else
691 static_assert(sizeof(_Tp) == 0); // TODO TZDB static_assert(false); after droping clang-16 support
691 static_assert(false);
692692
693693 std::__libcpp_unreachable();
694694 },
lib/libcxx/src/experimental/tzdb.cpp+19-7
......@@ -8,12 +8,16 @@
88
99// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html
1010
11#include <__assert>
1112#include <algorithm>
13#include <cctype>
1214#include <chrono>
1315#include <filesystem>
1416#include <fstream>
1517#include <stdexcept>
1618#include <string>
19#include <string_view>
20#include <vector>
1721
1822#include "include/tzdb/time_zone_private.h"
1923#include "include/tzdb/types_private.h"
......@@ -51,8 +55,7 @@ _LIBCPP_WEAK string_view __libcpp_tzdb_directory() {
5155#if defined(__linux__)
5256 return "/usr/share/zoneinfo/";
5357#else
54// Zig patch: change this compilation error into a runtime crash.
55//# error "unknown path to the IANA Time Zone Database"
58 // zig patch: change this compilation error into a runtime crash
5659 abort();
5760#endif
5861}
......@@ -96,14 +99,23 @@ static void __skip(istream& __input, string_view __suffix) {
9699}
97100
98101static void __matches(istream& __input, char __expected) {
99 if (std::tolower(__input.get()) != __expected)
100 std::__throw_runtime_error((string("corrupt tzdb: expected character '") + __expected + '\'').c_str());
102 _LIBCPP_ASSERT_INTERNAL(!std::isalpha(__expected) || std::islower(__expected), "lowercase characters only here!");
103 char __c = __input.get();
104 if (std::tolower(__c) != __expected)
105 std::__throw_runtime_error(
106 (string("corrupt tzdb: expected character '") + __expected + "', got '" + __c + "' instead").c_str());
101107}
102108
103109static void __matches(istream& __input, string_view __expected) {
104 for (auto __c : __expected)
105 if (std::tolower(__input.get()) != __c)
106 std::__throw_runtime_error((string("corrupt tzdb: expected string '") + string(__expected) + '\'').c_str());
110 for (auto __c : __expected) {
111 _LIBCPP_ASSERT_INTERNAL(!std::isalpha(__c) || std::islower(__c), "lowercase strings only here!");
112 char __actual = __input.get();
113 if (std::tolower(__actual) != __c)
114 std::__throw_runtime_error(
115 (string("corrupt tzdb: expected character '") + __c + "' from string '" + string(__expected) + "', got '" +
116 __actual + "' instead")
117 .c_str());
118 }
107119}
108120
109121[[nodiscard]] static string __parse_string(istream& __input) {
lib/libcxx/src/filesystem/directory_iterator.cpp+11-11
......@@ -47,9 +47,9 @@ public:
4747 }
4848 __stream_ = ::FindFirstFileW((root / "*").c_str(), &__data_);
4949 if (__stream_ == INVALID_HANDLE_VALUE) {
50 ec = detail::make_windows_error(GetLastError());
50 ec = detail::get_last_error();
5151 const bool ignore_permission_denied = bool(opts & directory_options::skip_permission_denied);
52 if (ignore_permission_denied && ec.value() == static_cast<int>(errc::permission_denied))
52 if (ignore_permission_denied && ec == errc::permission_denied)
5353 ec.clear();
5454 return;
5555 }
......@@ -77,13 +77,13 @@ public:
7777 bool assign() {
7878 if (!wcscmp(__data_.cFileName, L".") || !wcscmp(__data_.cFileName, L".."))
7979 return false;
80 // FIXME: Cache more of this
81 // directory_entry::__cached_data cdata;
82 // cdata.__type_ = get_file_type(__data_);
83 // cdata.__size_ = get_file_size(__data_);
84 // cdata.__write_time_ = get_write_time(__data_);
8580 __entry_.__assign_iter_entry(
86 __root_ / __data_.cFileName, directory_entry::__create_iter_result(detail::get_file_type(__data_)));
81 __root_ / __data_.cFileName,
82 directory_entry::__create_iter_cached_result(
83 detail::get_file_type(__data_),
84 detail::get_file_size(__data_),
85 detail::get_file_perm(__data_),
86 detail::get_write_time(__data_)));
8787 return true;
8888 }
8989
......@@ -91,7 +91,7 @@ private:
9191 error_code close() noexcept {
9292 error_code ec;
9393 if (!::FindClose(__stream_))
94 ec = detail::make_windows_error(GetLastError());
94 ec = detail::get_last_error();
9595 __stream_ = INVALID_HANDLE_VALUE;
9696 return ec;
9797 }
......@@ -118,7 +118,7 @@ public:
118118 if ((__stream_ = ::opendir(root.c_str())) == nullptr) {
119119 ec = detail::capture_errno();
120120 const bool allow_eacces = bool(opts & directory_options::skip_permission_denied);
121 if (allow_eacces && ec.value() == EACCES)
121 if (allow_eacces && ec == errc::permission_denied)
122122 ec.clear();
123123 return;
124124 }
......@@ -307,7 +307,7 @@ bool recursive_directory_iterator::__try_recursion(error_code* ec) {
307307 }
308308 if (m_ec) {
309309 const bool allow_eacess = bool(__imp_->__options_ & directory_options::skip_permission_denied);
310 if (m_ec.value() == EACCES && allow_eacess) {
310 if (m_ec == errc::permission_denied && allow_eacess) {
311311 if (ec)
312312 ec->clear();
313313 } else {
lib/libcxx/src/filesystem/error.h+16-75
......@@ -32,80 +32,21 @@ _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
3232
3333namespace detail {
3434
35#if defined(_LIBCPP_WIN32API)
36
37inline errc __win_err_to_errc(int err) {
38 constexpr struct {
39 DWORD win;
40 errc errc;
41 } win_error_mapping[] = {
42 {ERROR_ACCESS_DENIED, errc::permission_denied},
43 {ERROR_ALREADY_EXISTS, errc::file_exists},
44 {ERROR_BAD_NETPATH, errc::no_such_file_or_directory},
45 {ERROR_BAD_PATHNAME, errc::no_such_file_or_directory},
46 {ERROR_BAD_UNIT, errc::no_such_device},
47 {ERROR_BROKEN_PIPE, errc::broken_pipe},
48 {ERROR_BUFFER_OVERFLOW, errc::filename_too_long},
49 {ERROR_BUSY, errc::device_or_resource_busy},
50 {ERROR_BUSY_DRIVE, errc::device_or_resource_busy},
51 {ERROR_CANNOT_MAKE, errc::permission_denied},
52 {ERROR_CANTOPEN, errc::io_error},
53 {ERROR_CANTREAD, errc::io_error},
54 {ERROR_CANTWRITE, errc::io_error},
55 {ERROR_CURRENT_DIRECTORY, errc::permission_denied},
56 {ERROR_DEV_NOT_EXIST, errc::no_such_device},
57 {ERROR_DEVICE_IN_USE, errc::device_or_resource_busy},
58 {ERROR_DIR_NOT_EMPTY, errc::directory_not_empty},
59 {ERROR_DIRECTORY, errc::invalid_argument},
60 {ERROR_DISK_FULL, errc::no_space_on_device},
61 {ERROR_FILE_EXISTS, errc::file_exists},
62 {ERROR_FILE_NOT_FOUND, errc::no_such_file_or_directory},
63 {ERROR_HANDLE_DISK_FULL, errc::no_space_on_device},
64 {ERROR_INVALID_ACCESS, errc::permission_denied},
65 {ERROR_INVALID_DRIVE, errc::no_such_device},
66 {ERROR_INVALID_FUNCTION, errc::function_not_supported},
67 {ERROR_INVALID_HANDLE, errc::invalid_argument},
68 {ERROR_INVALID_NAME, errc::no_such_file_or_directory},
69 {ERROR_INVALID_PARAMETER, errc::invalid_argument},
70 {ERROR_LOCK_VIOLATION, errc::no_lock_available},
71 {ERROR_LOCKED, errc::no_lock_available},
72 {ERROR_NEGATIVE_SEEK, errc::invalid_argument},
73 {ERROR_NOACCESS, errc::permission_denied},
74 {ERROR_NOT_ENOUGH_MEMORY, errc::not_enough_memory},
75 {ERROR_NOT_READY, errc::resource_unavailable_try_again},
76 {ERROR_NOT_SAME_DEVICE, errc::cross_device_link},
77 {ERROR_NOT_SUPPORTED, errc::not_supported},
78 {ERROR_OPEN_FAILED, errc::io_error},
79 {ERROR_OPEN_FILES, errc::device_or_resource_busy},
80 {ERROR_OPERATION_ABORTED, errc::operation_canceled},
81 {ERROR_OUTOFMEMORY, errc::not_enough_memory},
82 {ERROR_PATH_NOT_FOUND, errc::no_such_file_or_directory},
83 {ERROR_READ_FAULT, errc::io_error},
84 {ERROR_REPARSE_TAG_INVALID, errc::invalid_argument},
85 {ERROR_RETRY, errc::resource_unavailable_try_again},
86 {ERROR_SEEK, errc::io_error},
87 {ERROR_SHARING_VIOLATION, errc::permission_denied},
88 {ERROR_TOO_MANY_OPEN_FILES, errc::too_many_files_open},
89 {ERROR_WRITE_FAULT, errc::io_error},
90 {ERROR_WRITE_PROTECT, errc::permission_denied},
91 };
92
93 for (const auto& pair : win_error_mapping)
94 if (pair.win == static_cast<DWORD>(err))
95 return pair.errc;
96 return errc::invalid_argument;
97}
98
99#endif // _LIBCPP_WIN32API
35// On windows, libc functions use errno, but system functions use GetLastError.
36// So, callers need to be careful which of these next functions they call!
10037
10138inline error_code capture_errno() {
10239 _LIBCPP_ASSERT_INTERNAL(errno != 0, "Expected errno to be non-zero");
10340 return error_code(errno, generic_category());
10441}
10542
43inline error_code get_last_error() {
10644#if defined(_LIBCPP_WIN32API)
107inline error_code make_windows_error(int err) { return make_error_code(__win_err_to_errc(err)); }
45 return std::error_code(GetLastError(), std::system_category());
46#else
47 return capture_errno();
10848#endif
49}
10950
11051template <class T>
11152T error_value();
......@@ -186,16 +127,16 @@ struct ErrorHandler {
186127 T report(const error_code& ec, const char* msg, ...) const {
187128 va_list ap;
188129 va_start(ap, msg);
189#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
130#if _LIBCPP_HAS_EXCEPTIONS
190131 try {
191#endif // _LIBCPP_HAS_NO_EXCEPTIONS
132#endif // _LIBCPP_HAS_EXCEPTIONS
192133 report_impl(ec, msg, ap);
193#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
134#if _LIBCPP_HAS_EXCEPTIONS
194135 } catch (...) {
195136 va_end(ap);
196137 throw;
197138 }
198#endif // _LIBCPP_HAS_NO_EXCEPTIONS
139#endif // _LIBCPP_HAS_EXCEPTIONS
199140 va_end(ap);
200141 return error_value<T>();
201142 }
......@@ -206,16 +147,16 @@ struct ErrorHandler {
206147 T report(errc const& err, const char* msg, ...) const {
207148 va_list ap;
208149 va_start(ap, msg);
209#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
150#if _LIBCPP_HAS_EXCEPTIONS
210151 try {
211#endif // _LIBCPP_HAS_NO_EXCEPTIONS
152#endif // _LIBCPP_HAS_EXCEPTIONS
212153 report_impl(make_error_code(err), msg, ap);
213#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
154#if _LIBCPP_HAS_EXCEPTIONS
214155 } catch (...) {
215156 va_end(ap);
216157 throw;
217158 }
218#endif // _LIBCPP_HAS_NO_EXCEPTIONS
159#endif // _LIBCPP_HAS_EXCEPTIONS
219160 va_end(ap);
220161 return error_value<T>();
221162 }
......@@ -225,7 +166,7 @@ private:
225166 ErrorHandler& operator=(ErrorHandler const&) = delete;
226167};
227168
228} // end namespace detail
169} // namespace detail
229170
230171_LIBCPP_END_NAMESPACE_FILESYSTEM
231172
lib/libcxx/src/filesystem/file_descriptor.h+18-11
......@@ -97,11 +97,18 @@ inline uintmax_t get_file_size(const WIN32_FIND_DATAW& data) {
9797 return (static_cast<uint64_t>(data.nFileSizeHigh) << 32) + data.nFileSizeLow;
9898}
9999inline file_time_type get_write_time(const WIN32_FIND_DATAW& data) {
100 ULARGE_INTEGER tmp;
100 using detail::fs_time;
101101 const FILETIME& time = data.ftLastWriteTime;
102 tmp.u.LowPart = time.dwLowDateTime;
103 tmp.u.HighPart = time.dwHighDateTime;
104 return file_time_type(file_time_type::duration(tmp.QuadPart));
102 auto ts = filetime_to_timespec(time);
103 if (!fs_time::is_representable(ts))
104 return file_time_type::min();
105 return fs_time::convert_from_timespec(ts);
106}
107inline perms get_file_perm(const WIN32_FIND_DATAW& data) {
108 unsigned st_mode = 0555; // Read-only
109 if (!(data.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
110 st_mode |= 0222; // Write
111 return static_cast<perms>(st_mode) & perms::mask;
105112}
106113
107114#endif // !_LIBCPP_WIN32API
......@@ -194,7 +201,7 @@ inline perms posix_get_perms(const StatT& st) noexcept { return static_cast<perm
194201inline file_status create_file_status(error_code& m_ec, path const& p, const StatT& path_stat, error_code* ec) {
195202 if (ec)
196203 *ec = m_ec;
197 if (m_ec && (m_ec.value() == ENOENT || m_ec.value() == ENOTDIR)) {
204 if (m_ec && (m_ec == errc::no_such_file_or_directory || m_ec == errc::not_a_directory)) {
198205 return file_status(file_type::not_found);
199206 } else if (m_ec) {
200207 ErrorHandler<void> err("posix_stat", ec, &p);
......@@ -229,7 +236,7 @@ inline file_status create_file_status(error_code& m_ec, path const& p, const Sta
229236inline file_status posix_stat(path const& p, StatT& path_stat, error_code* ec) {
230237 error_code m_ec;
231238 if (detail::stat(p.c_str(), &path_stat) == -1)
232 m_ec = detail::capture_errno();
239 m_ec = detail::get_last_error();
233240 return create_file_status(m_ec, p, path_stat, ec);
234241}
235242
......@@ -241,7 +248,7 @@ inline file_status posix_stat(path const& p, error_code* ec) {
241248inline file_status posix_lstat(path const& p, StatT& path_stat, error_code* ec) {
242249 error_code m_ec;
243250 if (detail::lstat(p.c_str(), &path_stat) == -1)
244 m_ec = detail::capture_errno();
251 m_ec = detail::get_last_error();
245252 return create_file_status(m_ec, p, path_stat, ec);
246253}
247254
......@@ -253,7 +260,7 @@ inline file_status posix_lstat(path const& p, error_code* ec) {
253260// http://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html
254261inline bool posix_ftruncate(const FileDescriptor& fd, off_t to_size, error_code& ec) {
255262 if (detail::ftruncate(fd.fd, to_size) == -1) {
256 ec = capture_errno();
263 ec = get_last_error();
257264 return true;
258265 }
259266 ec.clear();
......@@ -262,7 +269,7 @@ inline bool posix_ftruncate(const FileDescriptor& fd, off_t to_size, error_code&
262269
263270inline bool posix_fchmod(const FileDescriptor& fd, const StatT& st, error_code& ec) {
264271 if (detail::fchmod(fd.fd, st.st_mode) == -1) {
265 ec = capture_errno();
272 ec = get_last_error();
266273 return true;
267274 }
268275 ec.clear();
......@@ -279,12 +286,12 @@ inline file_status FileDescriptor::refresh_status(error_code& ec) {
279286 m_stat = {};
280287 error_code m_ec;
281288 if (detail::fstat(fd, &m_stat) == -1)
282 m_ec = capture_errno();
289 m_ec = get_last_error();
283290 m_status = create_file_status(m_ec, name, m_stat, &ec);
284291 return m_status;
285292}
286293
287} // end namespace detail
294} // namespace detail
288295
289296_LIBCPP_END_NAMESPACE_FILESYSTEM
290297
lib/libcxx/src/filesystem/filesystem_clock.cpp+16-1
......@@ -7,6 +7,7 @@
77//===----------------------------------------------------------------------===//
88
99#include <__config>
10#include <__system_error/throw_system_error.h>
1011#include <chrono>
1112#include <filesystem>
1213#include <time.h>
......@@ -29,13 +30,21 @@
2930# include <sys/time.h> // for gettimeofday and timeval
3031#endif
3132
32#if defined(__APPLE__) || defined(__gnu_hurd__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
33#if defined(__LLVM_LIBC__)
34# define _LIBCPP_HAS_TIMESPEC_GET
35#endif
36
37#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__AMDGPU__) || defined(__NVPTX__) || \
38 (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
3339# define _LIBCPP_HAS_CLOCK_GETTIME
3440#endif
3541
3642_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
3743
44_LIBCPP_DIAGNOSTIC_PUSH
45_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated")
3846const bool _FilesystemClock::is_steady;
47_LIBCPP_DIAGNOSTIC_POP
3948
4049_FilesystemClock::time_point _FilesystemClock::now() noexcept {
4150 typedef chrono::duration<rep> __secs;
......@@ -45,6 +54,12 @@ _FilesystemClock::time_point _FilesystemClock::now() noexcept {
4554 GetSystemTimeAsFileTime(&time);
4655 detail::TimeSpec tp = detail::filetime_to_timespec(time);
4756 return time_point(__secs(tp.tv_sec) + chrono::duration_cast<duration>(__nsecs(tp.tv_nsec)));
57#elif defined(_LIBCPP_HAS_TIMESPEC_GET)
58 typedef chrono::duration<rep, nano> __nsecs;
59 struct timespec ts;
60 if (timespec_get(&ts, TIME_UTC) != TIME_UTC)
61 __throw_system_error(errno, "timespec_get(TIME_UTC) failed");
62 return time_point(__secs(ts.tv_sec) + chrono::duration_cast<duration>(__nsecs(ts.tv_nsec)));
4863#elif defined(_LIBCPP_HAS_CLOCK_GETTIME)
4964 typedef chrono::duration<rep, nano> __nsecs;
5065 struct timespec tp;
lib/libcxx/src/filesystem/format_string.h+5-5
......@@ -56,21 +56,21 @@ inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2) string format_string(const cha
5656 string ret;
5757 va_list ap;
5858 va_start(ap, msg);
59#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
59#if _LIBCPP_HAS_EXCEPTIONS
6060 try {
61#endif // _LIBCPP_HAS_NO_EXCEPTIONS
61#endif // _LIBCPP_HAS_EXCEPTIONS
6262 ret = detail::vformat_string(msg, ap);
63#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
63#if _LIBCPP_HAS_EXCEPTIONS
6464 } catch (...) {
6565 va_end(ap);
6666 throw;
6767 }
68#endif // _LIBCPP_HAS_NO_EXCEPTIONS
68#endif // _LIBCPP_HAS_EXCEPTIONS
6969 va_end(ap);
7070 return ret;
7171}
7272
73} // end namespace detail
73} // namespace detail
7474
7575_LIBCPP_END_NAMESPACE_FILESYSTEM
7676
lib/libcxx/src/filesystem/int128_builtins.cpp+1-1
......@@ -16,7 +16,7 @@
1616#include <__config>
1717#include <climits>
1818
19#if !defined(_LIBCPP_HAS_NO_INT128)
19#if _LIBCPP_HAS_INT128
2020
2121extern "C" __attribute__((no_sanitize("undefined"))) _LIBCPP_EXPORTED_FROM_ABI __int128_t
2222__muloti4(__int128_t a, __int128_t b, int* overflow) {
lib/libcxx/src/filesystem/operations.cpp+181-60
......@@ -15,6 +15,7 @@
1515#include <filesystem>
1616#include <iterator>
1717#include <string_view>
18#include <system_error>
1819#include <type_traits>
1920#include <vector>
2021
......@@ -32,11 +33,24 @@
3233# include <dirent.h>
3334# include <sys/stat.h>
3435# include <sys/statvfs.h>
36# include <sys/types.h>
3537# include <unistd.h>
3638#endif
3739#include <fcntl.h> /* values for fchmodat */
3840#include <time.h>
3941
42// since Linux 4.5 and FreeBSD 13, but the Linux libc wrapper is only provided by glibc >= 2.27 and musl
43#if defined(__linux__)
44# if defined(_LIBCPP_GLIBC_PREREQ)
45# if _LIBCPP_GLIBC_PREREQ(2, 27)
46# define _LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE
47# endif
48# elif _LIBCPP_HAS_MUSL_LIBC
49# define _LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE
50# endif
51#elif defined(__FreeBSD__)
52# define _LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE
53#endif
4054#if __has_include(<sys/sendfile.h>)
4155# include <sys/sendfile.h>
4256# define _LIBCPP_FILESYSTEM_USE_SENDFILE
......@@ -44,10 +58,18 @@
4458# include <copyfile.h>
4559# define _LIBCPP_FILESYSTEM_USE_COPYFILE
4660#else
47# include <fstream>
4861# define _LIBCPP_FILESYSTEM_USE_FSTREAM
4962#endif
5063
64// sendfile and copy_file_range need to fall back
65// to the fstream implementation for special files
66#if (defined(_LIBCPP_FILESYSTEM_USE_SENDFILE) || defined(_LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE) || \
67 defined(_LIBCPP_FILESYSTEM_USE_FSTREAM)) && \
68 _LIBCPP_HAS_LOCALIZATION
69# include <fstream>
70# define _LIBCPP_FILESYSTEM_NEED_FSTREAM
71#endif
72
5173#if defined(__ELF__) && defined(_LIBCPP_LINK_RT_LIB)
5274# pragma comment(lib, "rt")
5375#endif
......@@ -86,7 +108,7 @@ path __canonical(path const& orig_p, error_code* ec) {
86108#if (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112) || defined(_LIBCPP_WIN32API)
87109 std::unique_ptr<path::value_type, decltype(&::free)> hold(detail::realpath(p.c_str(), nullptr), &::free);
88110 if (hold.get() == nullptr)
89 return err.report(capture_errno());
111 return err.report(detail::get_last_error());
90112 return {hold.get()};
91113#else
92114# if defined(__MVS__) && !defined(PATH_MAX)
......@@ -96,7 +118,7 @@ path __canonical(path const& orig_p, error_code* ec) {
96118# endif
97119 path::value_type* ret;
98120 if ((ret = detail::realpath(p.c_str(), buff)) == nullptr)
99 return err.report(capture_errno());
121 return err.report(detail::get_last_error());
100122 return {ret};
101123#endif
102124}
......@@ -178,9 +200,89 @@ void __copy(const path& from, const path& to, copy_options options, error_code*
178200namespace detail {
179201namespace {
180202
203#if defined(_LIBCPP_FILESYSTEM_NEED_FSTREAM)
204bool copy_file_impl_fstream(FileDescriptor& read_fd, FileDescriptor& write_fd, error_code& ec) {
205 ifstream in;
206 in.__open(read_fd.fd, ios::binary);
207 if (!in.is_open()) {
208 // This assumes that __open didn't reset the error code.
209 ec = capture_errno();
210 return false;
211 }
212 read_fd.fd = -1;
213 ofstream out;
214 out.__open(write_fd.fd, ios::binary);
215 if (!out.is_open()) {
216 ec = capture_errno();
217 return false;
218 }
219 write_fd.fd = -1;
220
221 if (in.good() && out.good()) {
222 using InIt = istreambuf_iterator<char>;
223 using OutIt = ostreambuf_iterator<char>;
224 InIt bin(in);
225 InIt ein;
226 OutIt bout(out);
227 copy(bin, ein, bout);
228 }
229 if (out.fail() || in.fail()) {
230 ec = make_error_code(errc::io_error);
231 return false;
232 }
233
234 ec.clear();
235 return true;
236}
237#endif
238
239#if defined(_LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE)
240bool copy_file_impl_copy_file_range(FileDescriptor& read_fd, FileDescriptor& write_fd, error_code& ec) {
241 size_t count = read_fd.get_stat().st_size;
242 // a zero-length file is either empty, or not copyable by this syscall
243 // return early to avoid the syscall cost
244 if (count == 0) {
245 ec = {EINVAL, generic_category()};
246 return false;
247 }
248 // do not modify the fd positions as copy_file_impl_sendfile may be called after a partial copy
249# if defined(__linux__)
250 loff_t off_in = 0;
251 loff_t off_out = 0;
252# else
253 off_t off_in = 0;
254 off_t off_out = 0;
255# endif
256
257 do {
258 ssize_t res;
259
260 if ((res = ::copy_file_range(read_fd.fd, &off_in, write_fd.fd, &off_out, count, 0)) == -1) {
261 ec = capture_errno();
262 return false;
263 }
264 count -= res;
265 } while (count > 0);
266
267 ec.clear();
268
269 return true;
270}
271#endif
272
181273#if defined(_LIBCPP_FILESYSTEM_USE_SENDFILE)
182bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_code& ec) {
274bool copy_file_impl_sendfile(FileDescriptor& read_fd, FileDescriptor& write_fd, error_code& ec) {
183275 size_t count = read_fd.get_stat().st_size;
276 // a zero-length file is either empty, or not copyable by this syscall
277 // return early to avoid the syscall cost
278 // however, we can't afford this luxury in the no-locale build,
279 // as we can't utilize the fstream impl to copy empty files
280# if _LIBCPP_HAS_LOCALIZATION
281 if (count == 0) {
282 ec = {EINVAL, generic_category()};
283 return false;
284 }
285# endif
184286 do {
185287 ssize_t res;
186288 if ((res = ::sendfile(write_fd.fd, read_fd.fd, nullptr, count)) == -1) {
......@@ -194,6 +296,54 @@ bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_cod
194296
195297 return true;
196298}
299#endif
300
301#if defined(_LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE) || defined(_LIBCPP_FILESYSTEM_USE_SENDFILE)
302// If we have copy_file_range or sendfile, try both in succession (if available).
303// If both fail, fall back to using fstream.
304bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_code& ec) {
305# if defined(_LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE)
306 if (copy_file_impl_copy_file_range(read_fd, write_fd, ec)) {
307 return true;
308 }
309 // EINVAL: src and dst are the same file (this is not cheaply
310 // detectable from userspace)
311 // EINVAL: copy_file_range is unsupported for this file type by the
312 // underlying filesystem
313 // ENOTSUP: undocumented, can arise with old kernels and NFS
314 // EOPNOTSUPP: filesystem does not implement copy_file_range
315 // ETXTBSY: src or dst is an active swapfile (nonsensical, but allowed
316 // with normal copying)
317 // EXDEV: src and dst are on different filesystems that do not support
318 // cross-fs copy_file_range
319 // ENOENT: undocumented, can arise with CIFS
320 // ENOSYS: unsupported by kernel or blocked by seccomp
321 if (ec.value() != EINVAL && ec.value() != ENOTSUP && ec.value() != EOPNOTSUPP && ec.value() != ETXTBSY &&
322 ec.value() != EXDEV && ec.value() != ENOENT && ec.value() != ENOSYS) {
323 return false;
324 }
325 ec.clear();
326# endif
327
328# if defined(_LIBCPP_FILESYSTEM_USE_SENDFILE)
329 if (copy_file_impl_sendfile(read_fd, write_fd, ec)) {
330 return true;
331 }
332 // EINVAL: unsupported file type
333 if (ec.value() != EINVAL) {
334 return false;
335 }
336 ec.clear();
337# endif
338
339# if defined(_LIBCPP_FILESYSTEM_NEED_FSTREAM)
340 return copy_file_impl_fstream(read_fd, write_fd, ec);
341# else
342 // since iostreams are unavailable in the no-locale build, just fail after a failed sendfile
343 ec.assign(EINVAL, std::system_category());
344 return false;
345# endif
346}
197347#elif defined(_LIBCPP_FILESYSTEM_USE_COPYFILE)
198348bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_code& ec) {
199349 struct CopyFileState {
......@@ -217,44 +367,14 @@ bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_cod
217367}
218368#elif defined(_LIBCPP_FILESYSTEM_USE_FSTREAM)
219369bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_code& ec) {
220 ifstream in;
221 in.__open(read_fd.fd, ios::binary);
222 if (!in.is_open()) {
223 // This assumes that __open didn't reset the error code.
224 ec = capture_errno();
225 return false;
226 }
227 read_fd.fd = -1;
228 ofstream out;
229 out.__open(write_fd.fd, ios::binary);
230 if (!out.is_open()) {
231 ec = capture_errno();
232 return false;
233 }
234 write_fd.fd = -1;
235
236 if (in.good() && out.good()) {
237 using InIt = istreambuf_iterator<char>;
238 using OutIt = ostreambuf_iterator<char>;
239 InIt bin(in);
240 InIt ein;
241 OutIt bout(out);
242 copy(bin, ein, bout);
243 }
244 if (out.fail() || in.fail()) {
245 ec = make_error_code(errc::io_error);
246 return false;
247 }
248
249 ec.clear();
250 return true;
370 return copy_file_impl_fstream(read_fd, write_fd, ec);
251371}
252372#else
253373# error "Unknown implementation for copy_file_impl"
254374#endif // copy_file_impl implementation
255375
256376} // end anonymous namespace
257} // end namespace detail
377} // namespace detail
258378
259379bool __copy_file(const path& from, const path& to, copy_options options, error_code* ec) {
260380 using detail::FileDescriptor;
......@@ -393,9 +513,9 @@ bool __create_directory(const path& p, error_code* ec) {
393513 if (detail::mkdir(p.c_str(), static_cast<int>(perms::all)) == 0)
394514 return true;
395515
396 if (errno != EEXIST)
397 return err.report(capture_errno());
398 error_code mec = capture_errno();
516 error_code mec = detail::get_last_error();
517 if (mec != errc::file_exists)
518 return err.report(mec);
399519 error_code ignored_ec;
400520 const file_status st = status(p, ignored_ec);
401521 if (!is_directory(st))
......@@ -417,10 +537,10 @@ bool __create_directory(path const& p, path const& attributes, error_code* ec) {
417537 if (detail::mkdir(p.c_str(), attr_stat.st_mode) == 0)
418538 return true;
419539
420 if (errno != EEXIST)
421 return err.report(capture_errno());
540 mec = detail::get_last_error();
541 if (mec != errc::file_exists)
542 return err.report(mec);
422543
423 mec = capture_errno();
424544 error_code ignored_ec;
425545 st = status(p, ignored_ec);
426546 if (!is_directory(st))
......@@ -431,19 +551,19 @@ bool __create_directory(path const& p, path const& attributes, error_code* ec) {
431551void __create_directory_symlink(path const& from, path const& to, error_code* ec) {
432552 ErrorHandler<void> err("create_directory_symlink", ec, &from, &to);
433553 if (detail::symlink_dir(from.c_str(), to.c_str()) == -1)
434 return err.report(capture_errno());
554 return err.report(detail::get_last_error());
435555}
436556
437557void __create_hard_link(const path& from, const path& to, error_code* ec) {
438558 ErrorHandler<void> err("create_hard_link", ec, &from, &to);
439559 if (detail::link(from.c_str(), to.c_str()) == -1)
440 return err.report(capture_errno());
560 return err.report(detail::get_last_error());
441561}
442562
443563void __create_symlink(path const& from, path const& to, error_code* ec) {
444564 ErrorHandler<void> err("create_symlink", ec, &from, &to);
445565 if (detail::symlink_file(from.c_str(), to.c_str()) == -1)
446 return err.report(capture_errno());
566 return err.report(detail::get_last_error());
447567}
448568
449569path __current_path(error_code* ec) {
......@@ -486,7 +606,7 @@ path __current_path(error_code* ec) {
486606
487607 unique_ptr<path::value_type, Deleter> hold(detail::getcwd(ptr, size), deleter);
488608 if (hold.get() == nullptr)
489 return err.report(capture_errno(), "call to getcwd failed");
609 return err.report(detail::get_last_error(), "call to getcwd failed");
490610
491611 return {hold.get()};
492612}
......@@ -494,7 +614,7 @@ path __current_path(error_code* ec) {
494614void __current_path(const path& p, error_code* ec) {
495615 ErrorHandler<void> err("current_path", ec, &p);
496616 if (detail::chdir(p.c_str()) == -1)
497 err.report(capture_errno());
617 err.report(detail::get_last_error());
498618}
499619
500620bool __equivalent(const path& p1, const path& p2, error_code* ec) {
......@@ -582,10 +702,10 @@ void __last_write_time(const path& p, file_time_type new_time, error_code* ec) {
582702 return err.report(errc::value_too_large);
583703 detail::WinHandle h(p.c_str(), FILE_WRITE_ATTRIBUTES, 0);
584704 if (!h)
585 return err.report(detail::make_windows_error(GetLastError()));
705 return err.report(detail::get_last_error());
586706 FILETIME last_write = timespec_to_filetime(ts);
587707 if (!SetFileTime(h, nullptr, nullptr, &last_write))
588 return err.report(detail::make_windows_error(GetLastError()));
708 return err.report(detail::get_last_error());
589709#else
590710 error_code m_ec;
591711 array<TimeSpec, 2> tbuf;
......@@ -643,7 +763,7 @@ void __permissions(const path& p, perms prms, perm_options opts, error_code* ec)
643763#if defined(AT_SYMLINK_NOFOLLOW) && defined(AT_FDCWD)
644764 const int flags = set_sym_perms ? AT_SYMLINK_NOFOLLOW : 0;
645765 if (detail::fchmodat(AT_FDCWD, p.c_str(), real_perms, flags) == -1) {
646 return err.report(capture_errno());
766 return err.report(detail::get_last_error());
647767 }
648768#else
649769 if (set_sym_perms)
......@@ -671,14 +791,14 @@ path __read_symlink(const path& p, error_code* ec) {
671791#else
672792 StatT sb;
673793 if (detail::lstat(p.c_str(), &sb) == -1) {
674 return err.report(capture_errno());
794 return err.report(detail::get_last_error());
675795 }
676796 const size_t size = sb.st_size + 1;
677797 auto buff = unique_ptr<path::value_type[]>(new path::value_type[size]);
678798#endif
679799 detail::SSizeT ret;
680800 if ((ret = detail::readlink(p.c_str(), buff.get(), size)) == -1)
681 return err.report(capture_errno());
801 return err.report(detail::get_last_error());
682802 // Note that `ret` returning `0` would work, resulting in a valid empty string being returned.
683803 if (static_cast<size_t>(ret) >= size)
684804 return err.report(errc::value_too_large);
......@@ -689,8 +809,9 @@ path __read_symlink(const path& p, error_code* ec) {
689809bool __remove(const path& p, error_code* ec) {
690810 ErrorHandler<bool> err("remove", ec, &p);
691811 if (detail::remove(p.c_str()) == -1) {
692 if (errno != ENOENT)
693 err.report(capture_errno());
812 error_code mec = detail::get_last_error();
813 if (mec != errc::no_such_file_or_directory)
814 err.report(mec);
694815 return false;
695816 }
696817 return true;
......@@ -732,7 +853,7 @@ uintmax_t remove_all_impl(path const& p, error_code& ec) {
732853 return count;
733854}
734855
735} // end namespace
856} // namespace
736857
737858uintmax_t __remove_all(const path& p, error_code* ec) {
738859 ErrorHandler<uintmax_t> err("remove_all", ec, &p);
......@@ -827,7 +948,7 @@ uintmax_t remove_all_impl(int parent_directory, const path& p, error_code& ec) {
827948 return 0;
828949}
829950
830} // end namespace
951} // namespace
831952
832953uintmax_t __remove_all(const path& p, error_code* ec) {
833954 ErrorHandler<uintmax_t> err("remove_all", ec, &p);
......@@ -843,13 +964,13 @@ uintmax_t __remove_all(const path& p, error_code* ec) {
843964void __rename(const path& from, const path& to, error_code* ec) {
844965 ErrorHandler<void> err("rename", ec, &from, &to);
845966 if (detail::rename(from.c_str(), to.c_str()) == -1)
846 err.report(capture_errno());
967 err.report(detail::get_last_error());
847968}
848969
849970void __resize_file(const path& p, uintmax_t size, error_code* ec) {
850971 ErrorHandler<void> err("resize_file", ec, &p);
851972 if (detail::truncate(p.c_str(), static_cast< ::off_t>(size)) == -1)
852 return err.report(capture_errno());
973 return err.report(detail::get_last_error());
853974}
854975
855976space_info __space(const path& p, error_code* ec) {
......@@ -857,7 +978,7 @@ space_info __space(const path& p, error_code* ec) {
857978 space_info si;
858979 detail::StatVFS m_svfs = {};
859980 if (detail::statvfs(p.c_str(), &m_svfs) == -1) {
860 err.report(capture_errno());
981 err.report(detail::get_last_error());
861982 si.capacity = si.free = si.available = static_cast<uintmax_t>(-1);
862983 return si;
863984 }
......@@ -884,7 +1005,7 @@ path __temp_directory_path(error_code* ec) {
8841005 wchar_t buf[MAX_PATH];
8851006 DWORD retval = GetTempPathW(MAX_PATH, buf);
8861007 if (!retval)
887 return err.report(detail::make_windows_error(GetLastError()));
1008 return err.report(detail::get_last_error());
8881009 if (retval > MAX_PATH)
8891010 return err.report(errc::filename_too_long);
8901011 // GetTempPathW returns a path with a trailing slash, which we
lib/libcxx/src/filesystem/path.cpp+6-2
......@@ -24,7 +24,10 @@ using parser::string_view_t;
2424// path definitions
2525///////////////////////////////////////////////////////////////////////////////
2626
27_LIBCPP_DIAGNOSTIC_PUSH
28_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated")
2729constexpr path::value_type path::preferred_separator;
30_LIBCPP_DIAGNOSTIC_POP
2831
2932path& path::replace_extension(path const& replacement) {
3033 path p = extension();
......@@ -267,7 +270,7 @@ path path::lexically_relative(const path& base) const {
267270 // Find the first mismatching element
268271 auto PP = PathParser::CreateBegin(__pn_);
269272 auto PPBase = PathParser::CreateBegin(base.__pn_);
270 while (PP && PPBase && PP.State_ == PPBase.State_ && *PP == *PPBase) {
273 while (PP && PPBase && PP.State_ == PPBase.State_ && (*PP == *PPBase || PP.inRootDir())) {
271274 ++PP;
272275 ++PPBase;
273276 }
......@@ -368,7 +371,8 @@ size_t hash_value(const path& __p) noexcept {
368371 size_t hash_value = 0;
369372 hash<string_view_t> hasher;
370373 while (PP) {
371 hash_value = __hash_combine(hash_value, hasher(*PP));
374 string_view_t Part = PP.inRootDir() ? PATHSTR("/") : *PP;
375 hash_value = __hash_combine(hash_value, hasher(Part));
372376 ++PP;
373377 }
374378 return hash_value;
lib/libcxx/src/filesystem/posix_compat.h+34-41
......@@ -11,9 +11,10 @@
1111//
1212// These generally behave like the proper posix functions, with these
1313// exceptions:
14// On Windows, they take paths in wchar_t* form, instead of char* form.
15// The symlink() function is split into two frontends, symlink_file()
16// and symlink_dir().
14// - On Windows, they take paths in wchar_t* form, instead of char* form.
15// - The symlink() function is split into two frontends, symlink_file()
16// and symlink_dir().
17// - Errors should be retrieved with get_last_error, not errno.
1718//
1819// These are provided within an anonymous namespace within the detail
1920// namespace - callers need to include this header and call them as
......@@ -122,11 +123,6 @@ namespace detail {
122123
123124# define O_NONBLOCK 0
124125
125inline int set_errno(int e = GetLastError()) {
126 errno = static_cast<int>(__win_err_to_errc(e));
127 return -1;
128}
129
130126class WinHandle {
131127public:
132128 WinHandle(const wchar_t* p, DWORD access, DWORD flags) {
......@@ -153,7 +149,7 @@ private:
153149inline int stat_handle(HANDLE h, StatT* buf) {
154150 FILE_BASIC_INFO basic;
155151 if (!GetFileInformationByHandleEx(h, FileBasicInfo, &basic, sizeof(basic)))
156 return set_errno();
152 return -1;
157153 memset(buf, 0, sizeof(*buf));
158154 buf->st_mtim = filetime_to_timespec(basic.LastWriteTime);
159155 buf->st_atim = filetime_to_timespec(basic.LastAccessTime);
......@@ -168,18 +164,18 @@ inline int stat_handle(HANDLE h, StatT* buf) {
168164 if (basic.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
169165 FILE_ATTRIBUTE_TAG_INFO tag;
170166 if (!GetFileInformationByHandleEx(h, FileAttributeTagInfo, &tag, sizeof(tag)))
171 return set_errno();
167 return -1;
172168 if (tag.ReparseTag == IO_REPARSE_TAG_SYMLINK)
173169 buf->st_mode = (buf->st_mode & ~_S_IFMT) | _S_IFLNK;
174170 }
175171 FILE_STANDARD_INFO standard;
176172 if (!GetFileInformationByHandleEx(h, FileStandardInfo, &standard, sizeof(standard)))
177 return set_errno();
173 return -1;
178174 buf->st_nlink = standard.NumberOfLinks;
179175 buf->st_size = standard.EndOfFile.QuadPart;
180176 BY_HANDLE_FILE_INFORMATION info;
181177 if (!GetFileInformationByHandle(h, &info))
182 return set_errno();
178 return -1;
183179 buf->st_dev = info.dwVolumeSerialNumber;
184180 memcpy(&buf->st_ino.id[0], &info.nFileIndexHigh, 4);
185181 memcpy(&buf->st_ino.id[4], &info.nFileIndexLow, 4);
......@@ -189,7 +185,7 @@ inline int stat_handle(HANDLE h, StatT* buf) {
189185inline int stat_file(const wchar_t* path, StatT* buf, DWORD flags) {
190186 WinHandle h(path, FILE_READ_ATTRIBUTES, flags);
191187 if (!h)
192 return set_errno();
188 return -1;
193189 int ret = stat_handle(h, buf);
194190 return ret;
195191}
......@@ -206,7 +202,7 @@ inline int fstat(int fd, StatT* buf) {
206202inline int mkdir(const wchar_t* path, int permissions) {
207203 (void)permissions;
208204 if (!CreateDirectoryW(path, nullptr))
209 return set_errno();
205 return -1;
210206 return 0;
211207}
212208
......@@ -219,10 +215,10 @@ inline int symlink_file_dir(const wchar_t* oldname, const wchar_t* newname, bool
219215 return 0;
220216 int e = GetLastError();
221217 if (e != ERROR_INVALID_PARAMETER)
222 return set_errno(e);
218 return -1;
223219 if (CreateSymbolicLinkW(newname, oldname, flags))
224220 return 0;
225 return set_errno();
221 return -1;
226222}
227223
228224inline int symlink_file(const wchar_t* oldname, const wchar_t* newname) {
......@@ -236,17 +232,17 @@ inline int symlink_dir(const wchar_t* oldname, const wchar_t* newname) {
236232inline int link(const wchar_t* oldname, const wchar_t* newname) {
237233 if (CreateHardLinkW(newname, oldname, nullptr))
238234 return 0;
239 return set_errno();
235 return -1;
240236}
241237
242238inline int remove(const wchar_t* path) {
243239 detail::WinHandle h(path, DELETE, FILE_FLAG_OPEN_REPARSE_POINT);
244240 if (!h)
245 return set_errno();
241 return -1;
246242 FILE_DISPOSITION_INFO info;
247243 info.DeleteFile = TRUE;
248244 if (!SetFileInformationByHandle(h, FileDispositionInfo, &info, sizeof(info)))
249 return set_errno();
245 return -1;
250246 return 0;
251247}
252248
......@@ -254,9 +250,9 @@ inline int truncate_handle(HANDLE h, off_t length) {
254250 LARGE_INTEGER size_param;
255251 size_param.QuadPart = length;
256252 if (!SetFilePointerEx(h, size_param, 0, FILE_BEGIN))
257 return set_errno();
253 return -1;
258254 if (!SetEndOfFile(h))
259 return set_errno();
255 return -1;
260256 return 0;
261257}
262258
......@@ -268,19 +264,19 @@ inline int ftruncate(int fd, off_t length) {
268264inline int truncate(const wchar_t* path, off_t length) {
269265 detail::WinHandle h(path, GENERIC_WRITE, 0);
270266 if (!h)
271 return set_errno();
267 return -1;
272268 return truncate_handle(h, length);
273269}
274270
275271inline int rename(const wchar_t* from, const wchar_t* to) {
276272 if (!(MoveFileExW(from, to, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)))
277 return set_errno();
273 return -1;
278274 return 0;
279275}
280276
281277inline int chdir(const wchar_t* path) {
282278 if (!SetCurrentDirectoryW(path))
283 return set_errno();
279 return -1;
284280 return 0;
285281}
286282
......@@ -300,7 +296,7 @@ inline int statvfs(const wchar_t* p, StatVFS* buf) {
300296 break;
301297 path parent = dir.parent_path();
302298 if (parent == dir) {
303 errno = ENOENT;
299 SetLastError(ERROR_PATH_NOT_FOUND);
304300 return -1;
305301 }
306302 dir = parent;
......@@ -308,7 +304,7 @@ inline int statvfs(const wchar_t* p, StatVFS* buf) {
308304 ULARGE_INTEGER free_bytes_available_to_caller, total_number_of_bytes, total_number_of_free_bytes;
309305 if (!GetDiskFreeSpaceExW(
310306 dir.c_str(), &free_bytes_available_to_caller, &total_number_of_bytes, &total_number_of_free_bytes))
311 return set_errno();
307 return -1;
312308 buf->f_frsize = 1;
313309 buf->f_blocks = total_number_of_bytes.QuadPart;
314310 buf->f_bfree = total_number_of_free_bytes.QuadPart;
......@@ -330,7 +326,6 @@ inline wchar_t* getcwd([[maybe_unused]] wchar_t* in_buf, [[maybe_unused]] size_t
330326 retval = GetCurrentDirectoryW(buff_size, buff.get());
331327 }
332328 if (!retval) {
333 set_errno();
334329 return nullptr;
335330 }
336331 return buff.release();
......@@ -342,7 +337,6 @@ inline wchar_t* realpath(const wchar_t* path, [[maybe_unused]] wchar_t* resolved
342337
343338 WinHandle h(path, FILE_READ_ATTRIBUTES, 0);
344339 if (!h) {
345 set_errno();
346340 return nullptr;
347341 }
348342 size_t buff_size = MAX_PATH + 10;
......@@ -354,7 +348,6 @@ inline wchar_t* realpath(const wchar_t* path, [[maybe_unused]] wchar_t* resolved
354348 retval = GetFinalPathNameByHandleW(h, buff.get(), buff_size, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
355349 }
356350 if (!retval) {
357 set_errno();
358351 return nullptr;
359352 }
360353 wchar_t* ptr = buff.get();
......@@ -376,20 +369,20 @@ using ModeT = int;
376369inline int fchmod_handle(HANDLE h, int perms) {
377370 FILE_BASIC_INFO basic;
378371 if (!GetFileInformationByHandleEx(h, FileBasicInfo, &basic, sizeof(basic)))
379 return set_errno();
372 return -1;
380373 DWORD orig_attributes = basic.FileAttributes;
381374 basic.FileAttributes &= ~FILE_ATTRIBUTE_READONLY;
382375 if ((perms & 0222) == 0)
383376 basic.FileAttributes |= FILE_ATTRIBUTE_READONLY;
384377 if (basic.FileAttributes != orig_attributes && !SetFileInformationByHandle(h, FileBasicInfo, &basic, sizeof(basic)))
385 return set_errno();
378 return -1;
386379 return 0;
387380}
388381
389382inline int fchmodat(int /*fd*/, const wchar_t* path, int perms, int flag) {
390383 DWORD attributes = GetFileAttributesW(path);
391384 if (attributes == INVALID_FILE_ATTRIBUTES)
392 return set_errno();
385 return -1;
393386 if (attributes & FILE_ATTRIBUTE_REPARSE_POINT && !(flag & AT_SYMLINK_NOFOLLOW)) {
394387 // If the file is a symlink, and we are supposed to operate on the target
395388 // of the symlink, we need to open a handle to it, without the
......@@ -397,7 +390,7 @@ inline int fchmodat(int /*fd*/, const wchar_t* path, int perms, int flag) {
397390 // symlink, and operate on it via the handle.
398391 detail::WinHandle h(path, FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES, 0);
399392 if (!h)
400 return set_errno();
393 return -1;
401394 return fchmod_handle(h, perms);
402395 } else {
403396 // For a non-symlink, or if operating on the symlink itself instead of
......@@ -407,7 +400,7 @@ inline int fchmodat(int /*fd*/, const wchar_t* path, int perms, int flag) {
407400 if ((perms & 0222) == 0)
408401 attributes |= FILE_ATTRIBUTE_READONLY;
409402 if (attributes != orig_attributes && !SetFileAttributesW(path, attributes))
410 return set_errno();
403 return -1;
411404 }
412405 return 0;
413406}
......@@ -424,18 +417,18 @@ inline SSizeT readlink(const wchar_t* path, wchar_t* ret_buf, size_t bufsize) {
424417 uint8_t buf[MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
425418 detail::WinHandle h(path, FILE_READ_ATTRIBUTES, FILE_FLAG_OPEN_REPARSE_POINT);
426419 if (!h)
427 return set_errno();
420 return -1;
428421 DWORD out;
429422 if (!DeviceIoControl(h, FSCTL_GET_REPARSE_POINT, nullptr, 0, buf, sizeof(buf), &out, 0))
430 return set_errno();
423 return -1;
431424 const auto* reparse = reinterpret_cast<LIBCPP_REPARSE_DATA_BUFFER*>(buf);
432425 size_t path_buf_offset = offsetof(LIBCPP_REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer[0]);
433426 if (out < path_buf_offset) {
434 errno = EINVAL;
427 SetLastError(ERROR_REPARSE_TAG_INVALID);
435428 return -1;
436429 }
437430 if (reparse->ReparseTag != IO_REPARSE_TAG_SYMLINK) {
438 errno = EINVAL;
431 SetLastError(ERROR_REPARSE_TAG_INVALID);
439432 return -1;
440433 }
441434 const auto& symlink = reparse->SymbolicLinkReparseBuffer;
......@@ -449,11 +442,11 @@ inline SSizeT readlink(const wchar_t* path, wchar_t* ret_buf, size_t bufsize) {
449442 }
450443 // name_offset/length are expressed in bytes, not in wchar_t
451444 if (path_buf_offset + name_offset + name_length > out) {
452 errno = EINVAL;
445 SetLastError(ERROR_REPARSE_TAG_INVALID);
453446 return -1;
454447 }
455448 if (name_length / sizeof(wchar_t) > bufsize) {
456 errno = ENOMEM;
449 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
457450 return -1;
458451 }
459452 memcpy(ret_buf, &symlink.PathBuffer[name_offset / sizeof(wchar_t)], name_length);
......@@ -490,7 +483,7 @@ using SSizeT = ::ssize_t;
490483
491484#endif
492485
493} // end namespace detail
486} // namespace detail
494487
495488_LIBCPP_END_NAMESPACE_FILESYSTEM
496489
lib/libcxx/src/filesystem/time_utils.h+3-3
......@@ -299,7 +299,7 @@ inline TimeSpec extract_mtime(StatT const& st) { return st.st_mtim; }
299299inline TimeSpec extract_atime(StatT const& st) { return st.st_atim; }
300300#endif
301301
302#ifndef _LIBCPP_HAS_NO_FILESYSTEM
302#if _LIBCPP_HAS_FILESYSTEM
303303
304304# if !defined(_LIBCPP_WIN32API)
305305inline bool posix_utimes(const path& p, std::array<TimeSpec, 2> const& TS, error_code& ec) {
......@@ -342,9 +342,9 @@ inline file_time_type __extract_last_write_time(const path& p, const StatT& st,
342342 return fs_time::convert_from_timespec(ts);
343343}
344344
345#endif // !_LIBCPP_HAS_NO_FILESYSTEM
345#endif // _LIBCPP_HAS_FILESYSTEM
346346
347} // end namespace detail
347} // namespace detail
348348
349349_LIBCPP_END_NAMESPACE_FILESYSTEM
350350
lib/libcxx/src/future.cpp+2-2
......@@ -142,10 +142,10 @@ promise<void>::promise() : __state_(new __assoc_sub_state) {}
142142
143143promise<void>::~promise() {
144144 if (__state_) {
145#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
145#if _LIBCPP_HAS_EXCEPTIONS
146146 if (!__state_->__has_value() && __state_->use_count() > 1)
147147 __state_->set_exception(make_exception_ptr(future_error(future_errc::broken_promise)));
148#endif // _LIBCPP_HAS_NO_EXCEPTIONS
148#endif // _LIBCPP_HAS_EXCEPTIONS
149149 __state_->__release_shared();
150150 }
151151}
lib/libcxx/src/include/atomic_support.h+5-5
......@@ -21,7 +21,7 @@
2121# define _LIBCPP_HAS_ATOMIC_BUILTINS
2222#endif
2323
24#if !defined(_LIBCPP_HAS_ATOMIC_BUILTINS) && !defined(_LIBCPP_HAS_NO_THREADS)
24#if !defined(_LIBCPP_HAS_ATOMIC_BUILTINS) && _LIBCPP_HAS_THREADS
2525# if defined(_LIBCPP_WARNING)
2626_LIBCPP_WARNING("Building libc++ without __atomic builtins is unsupported")
2727# else
......@@ -33,7 +33,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3333
3434namespace {
3535
36#if defined(_LIBCPP_HAS_ATOMIC_BUILTINS) && !defined(_LIBCPP_HAS_NO_THREADS)
36#if defined(_LIBCPP_HAS_ATOMIC_BUILTINS) && _LIBCPP_HAS_THREADS
3737
3838enum __libcpp_atomic_order {
3939 _AO_Relaxed = __ATOMIC_RELAXED,
......@@ -80,7 +80,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool __libcpp_atomic_compare_exchange(
8080 return __atomic_compare_exchange_n(__val, __expected, __after, true, __success_order, __fail_order);
8181}
8282
83#else // _LIBCPP_HAS_NO_THREADS
83#else // _LIBCPP_HAS_THREADS
8484
8585enum __libcpp_atomic_order { _AO_Relaxed, _AO_Consume, _AO_Acquire, _AO_Release, _AO_Acq_Rel, _AO_Seq };
8686
......@@ -123,9 +123,9 @@ __libcpp_atomic_compare_exchange(_ValueType* __val, _ValueType* __expected, _Val
123123 return false;
124124}
125125
126#endif // _LIBCPP_HAS_NO_THREADS
126#endif // _LIBCPP_HAS_THREADS
127127
128} // end namespace
128} // namespace
129129
130130_LIBCPP_END_NAMESPACE_STD
131131
lib/libcxx/src/include/config_elast.h+3-1
......@@ -21,6 +21,8 @@
2121// where strerror/strerror_r can't handle out-of-range errno values.
2222#if defined(ELAST)
2323# define _LIBCPP_ELAST ELAST
24#elif defined(__LLVM_LIBC__)
25// No _LIBCPP_ELAST needed for LLVM libc
2426#elif defined(_NEWLIB_VERSION)
2527# define _LIBCPP_ELAST __ELASTERROR
2628#elif defined(__NuttX__)
......@@ -31,7 +33,7 @@
3133// No _LIBCPP_ELAST needed on WASI
3234#elif defined(__EMSCRIPTEN__)
3335// No _LIBCPP_ELAST needed on Emscripten
34#elif defined(__linux__) || defined(_LIBCPP_HAS_MUSL_LIBC)
36#elif defined(__linux__) || _LIBCPP_HAS_MUSL_LIBC
3537# define _LIBCPP_ELAST 4095
3638#elif defined(__APPLE__)
3739// No _LIBCPP_ELAST needed on Apple
lib/libcxx/src/include/from_chars_floating_point.h created+457
......@@ -0,0 +1,457 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP_SRC_INCLUDE_FROM_CHARS_FLOATING_POINT_H
10#define _LIBCPP_SRC_INCLUDE_FROM_CHARS_FLOATING_POINT_H
11
12// These headers are in the shared LLVM-libc header library.
13#include "shared/fp_bits.h"
14#include "shared/str_to_float.h"
15#include "shared/str_to_integer.h"
16
17#include <__assert>
18#include <__config>
19#include <cctype>
20#include <charconv>
21#include <concepts>
22#include <limits>
23
24// Included for the _Floating_type_traits class
25#include "to_chars_floating_point.h"
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29// Parses an infinity string.
30// Valid strings are case insensitive and contain INF or INFINITY.
31//
32// - __first is the first argument to std::from_chars. When the string is invalid
33// this value is returned as ptr in the result.
34// - __last is the last argument of std::from_chars.
35// - __value is the value argument of std::from_chars,
36// - __ptr is the current position is the input string. This is points beyond
37// the initial I character.
38// - __negative whether a valid string represents -inf or +inf.
39template <floating_point _Fp>
40__from_chars_result<_Fp>
41__from_chars_floating_point_inf(const char* const __first, const char* __last, const char* __ptr, bool __negative) {
42 if (__last - __ptr < 2) [[unlikely]]
43 return {_Fp{0}, 0, errc::invalid_argument};
44
45 if (std::tolower(__ptr[0]) != 'n' || std::tolower(__ptr[1]) != 'f') [[unlikely]]
46 return {_Fp{0}, 0, errc::invalid_argument};
47
48 __ptr += 2;
49
50 // At this point the result is valid and contains INF.
51 // When the remaining part contains INITY this will be consumed. Otherwise
52 // only INF is consumed. For example INFINITZ will consume INF and ignore
53 // INITZ.
54
55 if (__last - __ptr >= 5 //
56 && std::tolower(__ptr[0]) == 'i' //
57 && std::tolower(__ptr[1]) == 'n' //
58 && std::tolower(__ptr[2]) == 'i' //
59 && std::tolower(__ptr[3]) == 't' //
60 && std::tolower(__ptr[4]) == 'y')
61 __ptr += 5;
62
63 if constexpr (numeric_limits<_Fp>::has_infinity) {
64 if (__negative)
65 return {-std::numeric_limits<_Fp>::infinity(), __ptr - __first, std::errc{}};
66
67 return {std::numeric_limits<_Fp>::infinity(), __ptr - __first, std::errc{}};
68 } else {
69 return {_Fp{0}, __ptr - __first, errc::result_out_of_range};
70 }
71}
72
73// Parses a nan string.
74// Valid strings are case insensitive and contain INF or INFINITY.
75//
76// - __first is the first argument to std::from_chars. When the string is invalid
77// this value is returned as ptr in the result.
78// - __last is the last argument of std::from_chars.
79// - __value is the value argument of std::from_chars,
80// - __ptr is the current position is the input string. This is points beyond
81// the initial N character.
82// - __negative whether a valid string represents -nan or +nan.
83template <floating_point _Fp>
84__from_chars_result<_Fp>
85__from_chars_floating_point_nan(const char* const __first, const char* __last, const char* __ptr, bool __negative) {
86 if (__last - __ptr < 2) [[unlikely]]
87 return {_Fp{0}, 0, errc::invalid_argument};
88
89 if (std::tolower(__ptr[0]) != 'a' || std::tolower(__ptr[1]) != 'n') [[unlikely]]
90 return {_Fp{0}, 0, errc::invalid_argument};
91
92 __ptr += 2;
93
94 // At this point the result is valid and contains NAN. When the remaining
95 // part contains ( n-char-sequence_opt ) this will be consumed. Otherwise
96 // only NAN is consumed. For example NAN(abcd will consume NAN and ignore
97 // (abcd.
98 if (__last - __ptr >= 2 && __ptr[0] == '(') {
99 size_t __offset = 1;
100 do {
101 if (__ptr[__offset] == ')') {
102 __ptr += __offset + 1;
103 break;
104 }
105 if (__ptr[__offset] != '_' && !std::isalnum(__ptr[__offset]))
106 break;
107 ++__offset;
108 } while (__ptr + __offset != __last);
109 }
110
111 if (__negative)
112 return {-std::numeric_limits<_Fp>::quiet_NaN(), __ptr - __first, std::errc{}};
113
114 return {std::numeric_limits<_Fp>::quiet_NaN(), __ptr - __first, std::errc{}};
115}
116
117template <class _Tp>
118struct __fractional_constant_result {
119 size_t __offset{size_t(-1)};
120 _Tp __mantissa{0};
121 int __exponent{0};
122 bool __truncated{false};
123 bool __is_valid{false};
124};
125
126// Parses the hex constant part of the hexadecimal floating-point value.
127// - input start of buffer given to from_chars
128// - __n the number of elements in the buffer
129// - __offset where to start parsing. The input can have an optional sign, the
130// offset starts after this sign.
131template <class _Tp>
132__fractional_constant_result<_Tp> __parse_fractional_hex_constant(const char* __input, size_t __n, size_t __offset) {
133 __fractional_constant_result<_Tp> __result;
134
135 const _Tp __mantissa_truncate_threshold = numeric_limits<_Tp>::max() / 16;
136 bool __fraction = false;
137 for (; __offset < __n; ++__offset) {
138 if (std::isxdigit(__input[__offset])) {
139 __result.__is_valid = true;
140
141 uint32_t __digit = __input[__offset] - '0';
142 switch (std::tolower(__input[__offset])) {
143 case 'a':
144 __digit = 10;
145 break;
146 case 'b':
147 __digit = 11;
148 break;
149 case 'c':
150 __digit = 12;
151 break;
152 case 'd':
153 __digit = 13;
154 break;
155 case 'e':
156 __digit = 14;
157 break;
158 case 'f':
159 __digit = 15;
160 break;
161 }
162
163 if (__result.__mantissa < __mantissa_truncate_threshold) {
164 __result.__mantissa = (__result.__mantissa * 16) + __digit;
165 if (__fraction)
166 __result.__exponent -= 4;
167 } else {
168 if (__digit > 0)
169 __result.__truncated = true;
170 if (!__fraction)
171 __result.__exponent += 4;
172 }
173 } else if (__input[__offset] == '.') {
174 if (__fraction)
175 break; // this means that __input[__offset] points to a second decimal point, ending the number.
176
177 __fraction = true;
178 } else
179 break;
180 }
181
182 __result.__offset = __offset;
183 return __result;
184}
185
186struct __exponent_result {
187 size_t __offset{size_t(-1)};
188 int __value{0};
189 bool __present{false};
190};
191
192// When the exponent is not present the result of the struct contains
193// __offset, 0, false. This allows using the results unconditionally, the
194// __present is important for the scientific notation, where the value is
195// mandatory.
196__exponent_result __parse_exponent(const char* __input, size_t __n, size_t __offset, char __marker) {
197 if (__offset + 1 < __n && // an exponent always needs at least one digit.
198 std::tolower(__input[__offset]) == __marker && //
199 !std::isspace(__input[__offset + 1]) // leading whitespace is not allowed.
200 ) {
201 ++__offset;
202 LIBC_NAMESPACE::shared::StrToNumResult<int32_t> __e =
203 LIBC_NAMESPACE::shared::strtointeger<int32_t>(__input + __offset, 10, __n - __offset);
204 // __result.error contains the errno value, 0 or ERANGE these are not interesting.
205 // If the number of characters parsed is 0 it means there was no number.
206 if (__e.parsed_len != 0)
207 return {__offset + __e.parsed_len, __e.value, true};
208 else
209 --__offset; // the assumption of a valid exponent was not true, undo eating the exponent character.
210 }
211
212 return {__offset, 0, false};
213}
214
215// Here we do this operation as int64 to avoid overflow.
216int32_t __merge_exponents(int64_t __fractional, int64_t __exponent, int __max_biased_exponent) {
217 int64_t __sum = __fractional + __exponent;
218
219 if (__sum > __max_biased_exponent)
220 return __max_biased_exponent;
221
222 if (__sum < -__max_biased_exponent)
223 return -__max_biased_exponent;
224
225 return __sum;
226}
227
228template <class _Fp, class _Tp>
229__from_chars_result<_Fp>
230__calculate_result(_Tp __mantissa, int __exponent, bool __negative, __from_chars_result<_Fp> __result) {
231 auto __r = LIBC_NAMESPACE::shared::FPBits<_Fp>();
232 __r.set_mantissa(__mantissa);
233 __r.set_biased_exponent(__exponent);
234
235 // C17 7.12.1/6
236 // The result underflows if the magnitude of the mathematical result is so
237 // small that the mathematical result cannot be represented, without
238 // extraordinary roundoff error, in an object of the specified type.237) If
239 // the result underflows, the function returns an implementation-defined
240 // value whose magnitude is no greater than the smallest normalized positive
241 // number in the specified type; if the integer expression math_errhandling
242 // & MATH_ERRNO is nonzero, whether errno acquires the value ERANGE is
243 // implementation-defined; if the integer expression math_errhandling &
244 // MATH_ERREXCEPT is nonzero, whether the "underflow" floating-point
245 // exception is raised is implementation-defined.
246 //
247 // LLVM-LIBC sets ERAGNE for subnormal values
248 //
249 // [charconv.from.chars]/1
250 // ... If the parsed value is not in the range representable by the type of
251 // value, value is unmodified and the member ec of the return value is
252 // equal to errc::result_out_of_range. ...
253 //
254 // Undo the ERANGE for subnormal values.
255 if (__result.__ec == errc::result_out_of_range && __r.is_subnormal() && !__r.is_zero())
256 __result.__ec = errc{};
257
258 if (__negative)
259 __result.__value = -__r.get_val();
260 else
261 __result.__value = __r.get_val();
262
263 return __result;
264}
265
266// Implements from_chars for decimal floating-point values.
267// __first forwarded from from_chars
268// __last forwarded from from_chars
269// __value forwarded from from_chars
270// __fmt forwarded from from_chars
271// __ptr the start of the buffer to parse. This is after the optional sign character.
272// __negative should __value be set to a negative value?
273//
274// This function and __from_chars_floating_point_decimal are similar. However
275// the similar parts are all in helper functions. So the amount of code
276// duplication is minimal.
277template <floating_point _Fp>
278__from_chars_result<_Fp>
279__from_chars_floating_point_hex(const char* const __first, const char* __last, const char* __ptr, bool __negative) {
280 size_t __n = __last - __first;
281 ptrdiff_t __offset = __ptr - __first;
282
283 auto __fractional =
284 std::__parse_fractional_hex_constant<typename _Floating_type_traits<_Fp>::_Uint_type>(__first, __n, __offset);
285 if (!__fractional.__is_valid)
286 return {_Fp{0}, 0, errc::invalid_argument};
287
288 auto __parsed_exponent = std::__parse_exponent(__first, __n, __fractional.__offset, 'p');
289 __offset = __parsed_exponent.__offset;
290 int __exponent = std::__merge_exponents(
291 __fractional.__exponent, __parsed_exponent.__value, LIBC_NAMESPACE::shared::FPBits<_Fp>::MAX_BIASED_EXPONENT);
292
293 __from_chars_result<_Fp> __result{_Fp{0}, __offset, {}};
294 LIBC_NAMESPACE::shared::ExpandedFloat<_Fp> __expanded_float = {0, 0};
295 if (__fractional.__mantissa != 0) {
296 auto __temp = LIBC_NAMESPACE::shared::binary_exp_to_float<_Fp>(
297 {__fractional.__mantissa, __exponent},
298 __fractional.__truncated,
299 LIBC_NAMESPACE::shared::RoundDirection::Nearest);
300 __expanded_float = __temp.num;
301 if (__temp.error == ERANGE) {
302 __result.__ec = errc::result_out_of_range;
303 }
304 }
305
306 return std::__calculate_result<_Fp>(__expanded_float.mantissa, __expanded_float.exponent, __negative, __result);
307}
308
309// Parses the hex constant part of the decimal float value.
310// - input start of buffer given to from_chars
311// - __n the number of elements in the buffer
312// - __offset where to start parsing. The input can have an optional sign, the
313// offset starts after this sign.
314template <class _Tp>
315__fractional_constant_result<_Tp>
316__parse_fractional_decimal_constant(const char* __input, ptrdiff_t __n, ptrdiff_t __offset) {
317 __fractional_constant_result<_Tp> __result;
318
319 const _Tp __mantissa_truncate_threshold = numeric_limits<_Tp>::max() / 10;
320 bool __fraction = false;
321 for (; __offset < __n; ++__offset) {
322 if (std::isdigit(__input[__offset])) {
323 __result.__is_valid = true;
324
325 uint32_t __digit = __input[__offset] - '0';
326 if (__result.__mantissa < __mantissa_truncate_threshold) {
327 __result.__mantissa = (__result.__mantissa * 10) + __digit;
328 if (__fraction)
329 --__result.__exponent;
330 } else {
331 if (__digit > 0)
332 __result.__truncated = true;
333 if (!__fraction)
334 ++__result.__exponent;
335 }
336 } else if (__input[__offset] == '.') {
337 if (__fraction)
338 break; // this means that __input[__offset] points to a second decimal point, ending the number.
339
340 __fraction = true;
341 } else
342 break;
343 }
344
345 __result.__offset = __offset;
346 return __result;
347}
348
349// Implements from_chars for decimal floating-point values.
350// __first forwarded from from_chars
351// __last forwarded from from_chars
352// __value forwarded from from_chars
353// __fmt forwarded from from_chars
354// __ptr the start of the buffer to parse. This is after the optional sign character.
355// __negative should __value be set to a negative value?
356template <floating_point _Fp>
357__from_chars_result<_Fp> __from_chars_floating_point_decimal(
358 const char* const __first, const char* __last, chars_format __fmt, const char* __ptr, bool __negative) {
359 ptrdiff_t __n = __last - __first;
360 ptrdiff_t __offset = __ptr - __first;
361
362 auto __fractional =
363 std::__parse_fractional_decimal_constant<typename _Floating_type_traits<_Fp>::_Uint_type>(__first, __n, __offset);
364 if (!__fractional.__is_valid)
365 return {_Fp{0}, 0, errc::invalid_argument};
366
367 __offset = __fractional.__offset;
368
369 // LWG3456 Pattern used by std::from_chars is underspecified
370 // This changes fixed to ignore a possible exponent instead of making its
371 // existance an error.
372 int __exponent;
373 if (__fmt == chars_format::fixed) {
374 __exponent =
375 std::__merge_exponents(__fractional.__exponent, 0, LIBC_NAMESPACE::shared::FPBits<_Fp>::MAX_BIASED_EXPONENT);
376 } else {
377 auto __parsed_exponent = std::__parse_exponent(__first, __n, __offset, 'e');
378 if (__fmt == chars_format::scientific && !__parsed_exponent.__present) {
379 // [charconv.from.chars]/6.2 if fmt has chars_format::scientific set but not chars_format::fixed,
380 // the otherwise optional exponent part shall appear;
381 return {_Fp{0}, 0, errc::invalid_argument};
382 }
383
384 __offset = __parsed_exponent.__offset;
385 __exponent = std::__merge_exponents(
386 __fractional.__exponent, __parsed_exponent.__value, LIBC_NAMESPACE::shared::FPBits<_Fp>::MAX_BIASED_EXPONENT);
387 }
388
389 __from_chars_result<_Fp> __result{_Fp{0}, __offset, {}};
390 LIBC_NAMESPACE::shared::ExpandedFloat<_Fp> __expanded_float = {0, 0};
391 if (__fractional.__mantissa != 0) {
392 // This function expects to parse a positive value. This means it does not
393 // take a __first, __n as arguments, since __first points to '-' for
394 // negative values.
395 auto __temp = LIBC_NAMESPACE::shared::decimal_exp_to_float<_Fp>(
396 {__fractional.__mantissa, __exponent},
397 __fractional.__truncated,
398 LIBC_NAMESPACE::shared::RoundDirection::Nearest,
399 __ptr,
400 __last - __ptr);
401 __expanded_float = __temp.num;
402 if (__temp.error == ERANGE) {
403 __result.__ec = errc::result_out_of_range;
404 }
405 }
406
407 return std::__calculate_result(__expanded_float.mantissa, __expanded_float.exponent, __negative, __result);
408}
409
410template <floating_point _Fp>
411__from_chars_result<_Fp>
412__from_chars_floating_point_impl(const char* const __first, const char* __last, chars_format __fmt) {
413 if (__first == __last) [[unlikely]]
414 return {_Fp{0}, 0, errc::invalid_argument};
415
416 const char* __ptr = __first;
417 bool __negative = *__ptr == '-';
418 if (__negative) {
419 ++__ptr;
420 if (__ptr == __last) [[unlikely]]
421 return {_Fp{0}, 0, errc::invalid_argument};
422 }
423
424 // [charconv.from.chars]
425 // [Note 1: If the pattern allows for an optional sign, but the string has
426 // no digit characters following the sign, no characters match the pattern.
427 // -- end note]
428 // This is true for integrals, floating point allows -.0
429
430 // [charconv.from.chars]/6.2
431 // if fmt has chars_format::scientific set but not chars_format::fixed, the
432 // otherwise optional exponent part shall appear;
433 // Since INF/NAN do not have an exponent this value is not valid.
434 //
435 // LWG3456 Pattern used by std::from_chars is underspecified
436 // Does not address this point, but proposed option B does solve this issue,
437 // Both MSVC STL and libstdc++ implement this this behaviour.
438 switch (std::tolower(*__ptr)) {
439 case 'i':
440 return std::__from_chars_floating_point_inf<_Fp>(__first, __last, __ptr + 1, __negative);
441 case 'n':
442 if constexpr (numeric_limits<_Fp>::has_quiet_NaN)
443 // NOTE: The pointer passed here will be parsed in the default C locale.
444 // This is standard behavior (see https://eel.is/c++draft/charconv.from.chars), but may be unexpected.
445 return std::__from_chars_floating_point_nan<_Fp>(__first, __last, __ptr + 1, __negative);
446 return {_Fp{0}, 0, errc::invalid_argument};
447 }
448
449 if (__fmt == chars_format::hex)
450 return std::__from_chars_floating_point_hex<_Fp>(__first, __last, __ptr, __negative);
451
452 return std::__from_chars_floating_point_decimal<_Fp>(__first, __last, __fmt, __ptr, __negative);
453}
454
455_LIBCPP_END_NAMESPACE_STD
456
457#endif //_LIBCPP_SRC_INCLUDE_FROM_CHARS_FLOATING_POINT_H
lib/libcxx/src/include/overridable_function.h+7-1
......@@ -96,7 +96,8 @@ _LIBCPP_HIDE_FROM_ABI bool __is_function_overridden(_Ret (*__fptr)(_Args...)) no
9696}
9797_LIBCPP_END_NAMESPACE_STD
9898
99#elif defined(_LIBCPP_OBJECT_FORMAT_ELF)
99// The NVPTX linker cannot create '__start/__stop' sections.
100#elif defined(_LIBCPP_OBJECT_FORMAT_ELF) && !defined(__NVPTX__)
100101
101102# define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 1
102103# define _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE __attribute__((__section__("__lcxx_override")))
......@@ -115,6 +116,11 @@ _LIBCPP_HIDE_FROM_ABI bool __is_function_overridden(_Ret (*__fptr)(_Args...)) no
115116 uintptr_t __end = reinterpret_cast<uintptr_t>(&__stop___lcxx_override);
116117 uintptr_t __ptr = reinterpret_cast<uintptr_t>(__fptr);
117118
119# if __has_feature(ptrauth_calls)
120 // We must pass a void* to ptrauth_strip since it only accepts a pointer type. See full explanation above.
121 __ptr = reinterpret_cast<uintptr_t>(ptrauth_strip(reinterpret_cast<void*>(__ptr), ptrauth_key_function_pointer));
122# endif
123
118124 return __ptr < __start || __ptr > __end;
119125}
120126_LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/include/refstring.h+1-1
......@@ -124,4 +124,4 @@ inline bool __libcpp_refstring::__uses_refcount() const {
124124
125125_LIBCPP_END_NAMESPACE_STD
126126
127#endif //_LIBCPP_REFSTRING_H
127#endif // _LIBCPP_REFSTRING_H
lib/libcxx/src/ios.cpp+5-5
......@@ -116,7 +116,7 @@ locale ios_base::getloc() const {
116116}
117117
118118// xalloc
119#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
119#if _LIBCPP_HAS_C_ATOMIC_IMP && _LIBCPP_HAS_THREADS
120120atomic<int> ios_base::__xindex_{0};
121121#else
122122int ios_base::__xindex_ = 0;
......@@ -361,18 +361,18 @@ void ios_base::swap(ios_base& rhs) noexcept {
361361
362362void ios_base::__set_badbit_and_consider_rethrow() {
363363 __rdstate_ |= badbit;
364#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
364#if _LIBCPP_HAS_EXCEPTIONS
365365 if (__exceptions_ & badbit)
366366 throw;
367#endif // _LIBCPP_HAS_NO_EXCEPTIONS
367#endif // _LIBCPP_HAS_EXCEPTIONS
368368}
369369
370370void ios_base::__set_failbit_and_consider_rethrow() {
371371 __rdstate_ |= failbit;
372#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
372#if _LIBCPP_HAS_EXCEPTIONS
373373 if (__exceptions_ & failbit)
374374 throw;
375#endif // _LIBCPP_HAS_NO_EXCEPTIONS
375#endif // _LIBCPP_HAS_EXCEPTIONS
376376}
377377
378378bool ios_base::sync_with_stdio(bool sync) {
lib/libcxx/src/ios.instantiations.cpp+2-2
......@@ -23,7 +23,7 @@ template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istream<char>;
2323template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostream<char>;
2424template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_iostream<char>;
2525
26#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
26#if _LIBCPP_HAS_WIDE_CHARACTERS
2727template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ios<wchar_t>;
2828template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_streambuf<wchar_t>;
2929template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istream<wchar_t>;
......@@ -37,7 +37,7 @@ template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_stringstream<char>
3737template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostringstream<char>;
3838template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istringstream<char>;
3939
40#ifndef _LIBCPP_HAS_NO_FILESYSTEM
40#if _LIBCPP_HAS_FILESYSTEM
4141template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ifstream<char>;
4242template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ofstream<char>;
4343template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_filebuf<char>;
lib/libcxx/src/iostream.cpp+13-17
......@@ -11,10 +11,6 @@
1111#include <new>
1212#include <string>
1313
14#ifdef _LIBCPP_MSVCRT_LIKE
15# include <__locale_dir/locale_base_api/locale_guard.h>
16#endif
17
1814#define _str(s) #s
1915#define str(s) _str(s)
2016#define _LIBCPP_ABI_NAMESPACE_STR str(_LIBCPP_ABI_NAMESPACE)
......@@ -30,7 +26,7 @@ alignas(istream) _LIBCPP_EXPORTED_FROM_ABI char cin[sizeof(istream)]
3026alignas(__stdinbuf<char>) static char __cin[sizeof(__stdinbuf<char>)];
3127static mbstate_t mb_cin;
3228
33#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
29#if _LIBCPP_HAS_WIDE_CHARACTERS
3430alignas(wistream) _LIBCPP_EXPORTED_FROM_ABI char wcin[sizeof(wistream)]
3531# if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
3632 __asm__("?wcin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR
......@@ -39,7 +35,7 @@ alignas(wistream) _LIBCPP_EXPORTED_FROM_ABI char wcin[sizeof(wistream)]
3935 ;
4036alignas(__stdinbuf<wchar_t>) static char __wcin[sizeof(__stdinbuf<wchar_t>)];
4137static mbstate_t mb_wcin;
42#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
38#endif // _LIBCPP_HAS_WIDE_CHARACTERS
4339
4440alignas(ostream) _LIBCPP_EXPORTED_FROM_ABI char cout[sizeof(ostream)]
4541#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
......@@ -50,7 +46,7 @@ alignas(ostream) _LIBCPP_EXPORTED_FROM_ABI char cout[sizeof(ostream)]
5046alignas(__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
5147static mbstate_t mb_cout;
5248
53#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
49#if _LIBCPP_HAS_WIDE_CHARACTERS
5450alignas(wostream) _LIBCPP_EXPORTED_FROM_ABI char wcout[sizeof(wostream)]
5551# if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
5652 __asm__("?wcout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR
......@@ -59,7 +55,7 @@ alignas(wostream) _LIBCPP_EXPORTED_FROM_ABI char wcout[sizeof(wostream)]
5955 ;
6056alignas(__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
6157static mbstate_t mb_wcout;
62#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
58#endif // _LIBCPP_HAS_WIDE_CHARACTERS
6359
6460alignas(ostream) _LIBCPP_EXPORTED_FROM_ABI char cerr[sizeof(ostream)]
6561#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
......@@ -70,7 +66,7 @@ alignas(ostream) _LIBCPP_EXPORTED_FROM_ABI char cerr[sizeof(ostream)]
7066alignas(__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
7167static mbstate_t mb_cerr;
7268
73#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
69#if _LIBCPP_HAS_WIDE_CHARACTERS
7470alignas(wostream) _LIBCPP_EXPORTED_FROM_ABI char wcerr[sizeof(wostream)]
7571# if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
7672 __asm__("?wcerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR
......@@ -79,7 +75,7 @@ alignas(wostream) _LIBCPP_EXPORTED_FROM_ABI char wcerr[sizeof(wostream)]
7975 ;
8076alignas(__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
8177static mbstate_t mb_wcerr;
82#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
78#endif // _LIBCPP_HAS_WIDE_CHARACTERS
8379
8480alignas(ostream) _LIBCPP_EXPORTED_FROM_ABI char clog[sizeof(ostream)]
8581#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
......@@ -88,14 +84,14 @@ alignas(ostream) _LIBCPP_EXPORTED_FROM_ABI char clog[sizeof(ostream)]
8884#endif
8985 ;
9086
91#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
87#if _LIBCPP_HAS_WIDE_CHARACTERS
9288alignas(wostream) _LIBCPP_EXPORTED_FROM_ABI char wclog[sizeof(wostream)]
9389# if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
9490 __asm__("?wclog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR
9591 "@std@@@12@A")
9692# endif
9793 ;
98#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
94#endif // _LIBCPP_HAS_WIDE_CHARACTERS
9995
10096// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority
10197// attribute with a value that's reserved for the implementation (we're the implementation).
......@@ -107,12 +103,12 @@ alignas(wostream) _LIBCPP_EXPORTED_FROM_ABI char wclog[sizeof(wostream)]
107103static void force_locale_initialization() {
108104#if defined(_LIBCPP_MSVCRT_LIKE)
109105 static bool once = []() {
110 auto loc = newlocale(LC_ALL_MASK, "C", 0);
106 auto loc = __locale::__newlocale(_LIBCPP_ALL_MASK, "C", 0);
111107 {
112 __libcpp_locale_guard g(loc); // forces initialization of locale TLS
108 __locale::__locale_guard g(loc); // forces initialization of locale TLS
113109 ((void)g);
114110 }
115 freelocale(loc);
111 __locale::__freelocale(loc);
116112 return true;
117113 }();
118114 ((void)once);
......@@ -136,7 +132,7 @@ DoIOSInit::DoIOSInit() {
136132 std::unitbuf(*cerr_ptr);
137133 cerr_ptr->tie(cout_ptr);
138134
139#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
135#if _LIBCPP_HAS_WIDE_CHARACTERS
140136 wistream* wcin_ptr = ::new (wcin) wistream(::new (__wcin) __stdinbuf<wchar_t>(stdin, &mb_wcin));
141137 wostream* wcout_ptr = ::new (wcout) wostream(::new (__wcout) __stdoutbuf<wchar_t>(stdout, &mb_wcout));
142138 wostream* wcerr_ptr = ::new (wcerr) wostream(::new (__wcerr) __stdoutbuf<wchar_t>(stderr, &mb_wcerr));
......@@ -154,7 +150,7 @@ DoIOSInit::~DoIOSInit() {
154150 ostream* clog_ptr = reinterpret_cast<ostream*>(clog);
155151 clog_ptr->flush();
156152
157#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
153#if _LIBCPP_HAS_WIDE_CHARACTERS
158154 wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout);
159155 wcout_ptr->flush();
160156 wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog);
lib/libcxx/src/legacy_pointer_safety.cpp deleted-23
......@@ -1,23 +0,0 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include <__config>
10#include <memory>
11
12// Support for garbage collection was removed in C++23 by https://wg21.link/P2186R2. Libc++ implements
13// that removal as an extension in all Standard versions. However, we still define the functions that
14// were once part of the library's ABI for backwards compatibility.
15
16_LIBCPP_BEGIN_NAMESPACE_STD
17
18_LIBCPP_EXPORTED_FROM_ABI void declare_reachable(void*) {}
19_LIBCPP_EXPORTED_FROM_ABI void declare_no_pointers(char*, size_t) {}
20_LIBCPP_EXPORTED_FROM_ABI void undeclare_no_pointers(char*, size_t) {}
21_LIBCPP_EXPORTED_FROM_ABI void* __undeclare_reachable(void* p) { return p; }
22
23_LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/locale.cpp+294-289
......@@ -22,7 +22,7 @@
2222#include <utility>
2323#include <vector>
2424
25#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
25#if _LIBCPP_HAS_WIDE_CHARACTERS
2626# include <cwctype>
2727#endif
2828
......@@ -34,7 +34,7 @@
3434# define _CTYPE_DISABLE_MACROS
3535#endif
3636
37#if !defined(_LIBCPP_MSVCRT) && !defined(__MINGW32__) && !defined(__BIONIC__) && !defined(__NuttX__)
37#if __has_include("<langinfo.h>")
3838# include <langinfo.h>
3939#endif
4040
......@@ -51,18 +51,18 @@ _LIBCPP_PUSH_MACROS
5151_LIBCPP_BEGIN_NAMESPACE_STD
5252
5353struct __libcpp_unique_locale {
54 __libcpp_unique_locale(const char* nm) : __loc_(newlocale(LC_ALL_MASK, nm, 0)) {}
54 __libcpp_unique_locale(const char* nm) : __loc_(__locale::__newlocale(_LIBCPP_ALL_MASK, nm, 0)) {}
5555
5656 ~__libcpp_unique_locale() {
5757 if (__loc_)
58 freelocale(__loc_);
58 __locale::__freelocale(__loc_);
5959 }
6060
6161 explicit operator bool() const { return __loc_; }
6262
63 locale_t& get() { return __loc_; }
63 __locale::__locale_t& get() { return __loc_; }
6464
65 locale_t __loc_;
65 __locale::__locale_t __loc_;
6666
6767private:
6868 __libcpp_unique_locale(__libcpp_unique_locale const&);
......@@ -70,11 +70,11 @@ private:
7070};
7171
7272#ifdef __cloc_defined
73locale_t __cloc() {
73__locale::__locale_t __cloc() {
7474 // In theory this could create a race condition. In practice
7575 // the race condition is non-fatal since it will just create
7676 // a little resource leak. Better approach would be appreciated.
77 static locale_t result = newlocale(LC_ALL_MASK, "C", 0);
77 static __locale::__locale_t result = __locale::__newlocale(_LIBCPP_ALL_MASK, "C", 0);
7878 return result;
7979}
8080#endif // __cloc_defined
......@@ -159,123 +159,123 @@ private:
159159locale::__imp::__imp(size_t refs) : facet(refs), facets_(N), name_("C") {
160160 facets_.clear();
161161 install(&make<std::collate<char> >(1u));
162#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
162#if _LIBCPP_HAS_WIDE_CHARACTERS
163163 install(&make<std::collate<wchar_t> >(1u));
164164#endif
165165 install(&make<std::ctype<char> >(nullptr, false, 1u));
166#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
166#if _LIBCPP_HAS_WIDE_CHARACTERS
167167 install(&make<std::ctype<wchar_t> >(1u));
168168#endif
169169 install(&make<codecvt<char, char, mbstate_t> >(1u));
170#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
170#if _LIBCPP_HAS_WIDE_CHARACTERS
171171 install(&make<codecvt<wchar_t, char, mbstate_t> >(1u));
172172#endif
173173 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
174174 install(&make<codecvt<char16_t, char, mbstate_t> >(1u));
175175 install(&make<codecvt<char32_t, char, mbstate_t> >(1u));
176176 _LIBCPP_SUPPRESS_DEPRECATED_POP
177#ifndef _LIBCPP_HAS_NO_CHAR8_T
177#if _LIBCPP_HAS_CHAR8_T
178178 install(&make<codecvt<char16_t, char8_t, mbstate_t> >(1u));
179179 install(&make<codecvt<char32_t, char8_t, mbstate_t> >(1u));
180180#endif
181181 install(&make<numpunct<char> >(1u));
182#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
182#if _LIBCPP_HAS_WIDE_CHARACTERS
183183 install(&make<numpunct<wchar_t> >(1u));
184184#endif
185185 install(&make<num_get<char> >(1u));
186#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
186#if _LIBCPP_HAS_WIDE_CHARACTERS
187187 install(&make<num_get<wchar_t> >(1u));
188188#endif
189189 install(&make<num_put<char> >(1u));
190#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
190#if _LIBCPP_HAS_WIDE_CHARACTERS
191191 install(&make<num_put<wchar_t> >(1u));
192192#endif
193193 install(&make<moneypunct<char, false> >(1u));
194194 install(&make<moneypunct<char, true> >(1u));
195#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
195#if _LIBCPP_HAS_WIDE_CHARACTERS
196196 install(&make<moneypunct<wchar_t, false> >(1u));
197197 install(&make<moneypunct<wchar_t, true> >(1u));
198198#endif
199199 install(&make<money_get<char> >(1u));
200#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
200#if _LIBCPP_HAS_WIDE_CHARACTERS
201201 install(&make<money_get<wchar_t> >(1u));
202202#endif
203203 install(&make<money_put<char> >(1u));
204#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
204#if _LIBCPP_HAS_WIDE_CHARACTERS
205205 install(&make<money_put<wchar_t> >(1u));
206206#endif
207207 install(&make<time_get<char> >(1u));
208#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
208#if _LIBCPP_HAS_WIDE_CHARACTERS
209209 install(&make<time_get<wchar_t> >(1u));
210210#endif
211211 install(&make<time_put<char> >(1u));
212#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
212#if _LIBCPP_HAS_WIDE_CHARACTERS
213213 install(&make<time_put<wchar_t> >(1u));
214214#endif
215215 install(&make<std::messages<char> >(1u));
216#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
216#if _LIBCPP_HAS_WIDE_CHARACTERS
217217 install(&make<std::messages<wchar_t> >(1u));
218218#endif
219219}
220220
221221locale::__imp::__imp(const string& name, size_t refs) : facet(refs), facets_(N), name_(name) {
222#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
222#if _LIBCPP_HAS_EXCEPTIONS
223223 try {
224#endif // _LIBCPP_HAS_NO_EXCEPTIONS
224#endif // _LIBCPP_HAS_EXCEPTIONS
225225 facets_ = locale::classic().__locale_->facets_;
226226 for (unsigned i = 0; i < facets_.size(); ++i)
227227 if (facets_[i])
228228 facets_[i]->__add_shared();
229229 install(new collate_byname<char>(name_));
230#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
230#if _LIBCPP_HAS_WIDE_CHARACTERS
231231 install(new collate_byname<wchar_t>(name_));
232232#endif
233233 install(new ctype_byname<char>(name_));
234#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
234#if _LIBCPP_HAS_WIDE_CHARACTERS
235235 install(new ctype_byname<wchar_t>(name_));
236236#endif
237237 install(new codecvt_byname<char, char, mbstate_t>(name_));
238#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
238#if _LIBCPP_HAS_WIDE_CHARACTERS
239239 install(new codecvt_byname<wchar_t, char, mbstate_t>(name_));
240240#endif
241241 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
242242 install(new codecvt_byname<char16_t, char, mbstate_t>(name_));
243243 install(new codecvt_byname<char32_t, char, mbstate_t>(name_));
244244 _LIBCPP_SUPPRESS_DEPRECATED_POP
245#ifndef _LIBCPP_HAS_NO_CHAR8_T
245#if _LIBCPP_HAS_CHAR8_T
246246 install(new codecvt_byname<char16_t, char8_t, mbstate_t>(name_));
247247 install(new codecvt_byname<char32_t, char8_t, mbstate_t>(name_));
248248#endif
249249 install(new numpunct_byname<char>(name_));
250#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
250#if _LIBCPP_HAS_WIDE_CHARACTERS
251251 install(new numpunct_byname<wchar_t>(name_));
252252#endif
253253 install(new moneypunct_byname<char, false>(name_));
254254 install(new moneypunct_byname<char, true>(name_));
255#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
255#if _LIBCPP_HAS_WIDE_CHARACTERS
256256 install(new moneypunct_byname<wchar_t, false>(name_));
257257 install(new moneypunct_byname<wchar_t, true>(name_));
258258#endif
259259 install(new time_get_byname<char>(name_));
260#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
260#if _LIBCPP_HAS_WIDE_CHARACTERS
261261 install(new time_get_byname<wchar_t>(name_));
262262#endif
263263 install(new time_put_byname<char>(name_));
264#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
264#if _LIBCPP_HAS_WIDE_CHARACTERS
265265 install(new time_put_byname<wchar_t>(name_));
266266#endif
267267 install(new messages_byname<char>(name_));
268#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
268#if _LIBCPP_HAS_WIDE_CHARACTERS
269269 install(new messages_byname<wchar_t>(name_));
270270#endif
271#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
271#if _LIBCPP_HAS_EXCEPTIONS
272272 } catch (...) {
273273 for (unsigned i = 0; i < facets_.size(); ++i)
274274 if (facets_[i])
275275 facets_[i]->__release_shared();
276276 throw;
277277 }
278#endif // _LIBCPP_HAS_NO_EXCEPTIONS
278#endif // _LIBCPP_HAS_EXCEPTIONS
279279}
280280
281281locale::__imp::__imp(const __imp& other) : facets_(max<size_t>(N, other.facets_.size())), name_(other.name_) {
......@@ -291,29 +291,29 @@ locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
291291 for (unsigned i = 0; i < facets_.size(); ++i)
292292 if (facets_[i])
293293 facets_[i]->__add_shared();
294#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
294#if _LIBCPP_HAS_EXCEPTIONS
295295 try {
296#endif // _LIBCPP_HAS_NO_EXCEPTIONS
296#endif // _LIBCPP_HAS_EXCEPTIONS
297297 if (c & locale::collate) {
298298 install(new collate_byname<char>(name));
299#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
299#if _LIBCPP_HAS_WIDE_CHARACTERS
300300 install(new collate_byname<wchar_t>(name));
301301#endif
302302 }
303303 if (c & locale::ctype) {
304304 install(new ctype_byname<char>(name));
305#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
305#if _LIBCPP_HAS_WIDE_CHARACTERS
306306 install(new ctype_byname<wchar_t>(name));
307307#endif
308308 install(new codecvt_byname<char, char, mbstate_t>(name));
309#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
309#if _LIBCPP_HAS_WIDE_CHARACTERS
310310 install(new codecvt_byname<wchar_t, char, mbstate_t>(name));
311311#endif
312312 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
313313 install(new codecvt_byname<char16_t, char, mbstate_t>(name));
314314 install(new codecvt_byname<char32_t, char, mbstate_t>(name));
315315 _LIBCPP_SUPPRESS_DEPRECATED_POP
316#ifndef _LIBCPP_HAS_NO_CHAR8_T
316#if _LIBCPP_HAS_CHAR8_T
317317 install(new codecvt_byname<char16_t, char8_t, mbstate_t>(name));
318318 install(new codecvt_byname<char32_t, char8_t, mbstate_t>(name));
319319#endif
......@@ -321,41 +321,41 @@ locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
321321 if (c & locale::monetary) {
322322 install(new moneypunct_byname<char, false>(name));
323323 install(new moneypunct_byname<char, true>(name));
324#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
324#if _LIBCPP_HAS_WIDE_CHARACTERS
325325 install(new moneypunct_byname<wchar_t, false>(name));
326326 install(new moneypunct_byname<wchar_t, true>(name));
327327#endif
328328 }
329329 if (c & locale::numeric) {
330330 install(new numpunct_byname<char>(name));
331#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
331#if _LIBCPP_HAS_WIDE_CHARACTERS
332332 install(new numpunct_byname<wchar_t>(name));
333333#endif
334334 }
335335 if (c & locale::time) {
336336 install(new time_get_byname<char>(name));
337#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
337#if _LIBCPP_HAS_WIDE_CHARACTERS
338338 install(new time_get_byname<wchar_t>(name));
339339#endif
340340 install(new time_put_byname<char>(name));
341#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
341#if _LIBCPP_HAS_WIDE_CHARACTERS
342342 install(new time_put_byname<wchar_t>(name));
343343#endif
344344 }
345345 if (c & locale::messages) {
346346 install(new messages_byname<char>(name));
347#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
347#if _LIBCPP_HAS_WIDE_CHARACTERS
348348 install(new messages_byname<wchar_t>(name));
349349#endif
350350 }
351#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
351#if _LIBCPP_HAS_EXCEPTIONS
352352 } catch (...) {
353353 for (unsigned i = 0; i < facets_.size(); ++i)
354354 if (facets_[i])
355355 facets_[i]->__release_shared();
356356 throw;
357357 }
358#endif // _LIBCPP_HAS_NO_EXCEPTIONS
358#endif // _LIBCPP_HAS_EXCEPTIONS
359359}
360360
361361template <class F>
......@@ -370,18 +370,18 @@ locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c)
370370 for (unsigned i = 0; i < facets_.size(); ++i)
371371 if (facets_[i])
372372 facets_[i]->__add_shared();
373#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
373#if _LIBCPP_HAS_EXCEPTIONS
374374 try {
375#endif // _LIBCPP_HAS_NO_EXCEPTIONS
375#endif // _LIBCPP_HAS_EXCEPTIONS
376376 if (c & locale::collate) {
377377 install_from<std::collate<char> >(one);
378#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
378#if _LIBCPP_HAS_WIDE_CHARACTERS
379379 install_from<std::collate<wchar_t> >(one);
380380#endif
381381 }
382382 if (c & locale::ctype) {
383383 install_from<std::ctype<char> >(one);
384#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
384#if _LIBCPP_HAS_WIDE_CHARACTERS
385385 install_from<std::ctype<wchar_t> >(one);
386386#endif
387387 install_from<std::codecvt<char, char, mbstate_t> >(one);
......@@ -389,68 +389,68 @@ locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c)
389389 install_from<std::codecvt<char16_t, char, mbstate_t> >(one);
390390 install_from<std::codecvt<char32_t, char, mbstate_t> >(one);
391391 _LIBCPP_SUPPRESS_DEPRECATED_POP
392#ifndef _LIBCPP_HAS_NO_CHAR8_T
392#if _LIBCPP_HAS_CHAR8_T
393393 install_from<std::codecvt<char16_t, char8_t, mbstate_t> >(one);
394394 install_from<std::codecvt<char32_t, char8_t, mbstate_t> >(one);
395395#endif
396#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
396#if _LIBCPP_HAS_WIDE_CHARACTERS
397397 install_from<std::codecvt<wchar_t, char, mbstate_t> >(one);
398398#endif
399399 }
400400 if (c & locale::monetary) {
401401 install_from<moneypunct<char, false> >(one);
402402 install_from<moneypunct<char, true> >(one);
403#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
403#if _LIBCPP_HAS_WIDE_CHARACTERS
404404 install_from<moneypunct<wchar_t, false> >(one);
405405 install_from<moneypunct<wchar_t, true> >(one);
406406#endif
407407 install_from<money_get<char> >(one);
408#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
408#if _LIBCPP_HAS_WIDE_CHARACTERS
409409 install_from<money_get<wchar_t> >(one);
410410#endif
411411 install_from<money_put<char> >(one);
412#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
412#if _LIBCPP_HAS_WIDE_CHARACTERS
413413 install_from<money_put<wchar_t> >(one);
414414#endif
415415 }
416416 if (c & locale::numeric) {
417417 install_from<numpunct<char> >(one);
418#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
418#if _LIBCPP_HAS_WIDE_CHARACTERS
419419 install_from<numpunct<wchar_t> >(one);
420420#endif
421421 install_from<num_get<char> >(one);
422#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
422#if _LIBCPP_HAS_WIDE_CHARACTERS
423423 install_from<num_get<wchar_t> >(one);
424424#endif
425425 install_from<num_put<char> >(one);
426#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
426#if _LIBCPP_HAS_WIDE_CHARACTERS
427427 install_from<num_put<wchar_t> >(one);
428428#endif
429429 }
430430 if (c & locale::time) {
431431 install_from<time_get<char> >(one);
432#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
432#if _LIBCPP_HAS_WIDE_CHARACTERS
433433 install_from<time_get<wchar_t> >(one);
434434#endif
435435 install_from<time_put<char> >(one);
436#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
436#if _LIBCPP_HAS_WIDE_CHARACTERS
437437 install_from<time_put<wchar_t> >(one);
438438#endif
439439 }
440440 if (c & locale::messages) {
441441 install_from<std::messages<char> >(one);
442#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
442#if _LIBCPP_HAS_WIDE_CHARACTERS
443443 install_from<std::messages<wchar_t> >(one);
444444#endif
445445 }
446#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
446#if _LIBCPP_HAS_EXCEPTIONS
447447 } catch (...) {
448448 for (unsigned i = 0; i < facets_.size(); ++i)
449449 if (facets_[i])
450450 facets_[i]->__release_shared();
451451 throw;
452452 }
453#endif // _LIBCPP_HAS_NO_EXCEPTIONS
453#endif // _LIBCPP_HAS_EXCEPTIONS
454454}
455455
456456locale::__imp::__imp(const __imp& other, facet* f, long id)
......@@ -570,7 +570,7 @@ locale locale::global(const locale& loc) {
570570 locale r = g;
571571 g = loc;
572572 if (g.name() != "*")
573 setlocale(LC_ALL, g.name().c_str());
573 __locale::__setlocale(_LIBCPP_LC_ALL, g.name().c_str());
574574 return r;
575575}
576576
......@@ -600,7 +600,7 @@ long locale::id::__get() {
600600// template <> class collate_byname<char>
601601
602602collate_byname<char>::collate_byname(const char* n, size_t refs)
603 : collate<char>(refs), __l_(newlocale(LC_ALL_MASK, n, 0)) {
603 : collate<char>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, n, 0)) {
604604 if (__l_ == 0)
605605 __throw_runtime_error(
606606 ("collate_byname<char>::collate_byname"
......@@ -610,7 +610,7 @@ collate_byname<char>::collate_byname(const char* n, size_t refs)
610610}
611611
612612collate_byname<char>::collate_byname(const string& name, size_t refs)
613 : collate<char>(refs), __l_(newlocale(LC_ALL_MASK, name.c_str(), 0)) {
613 : collate<char>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name.c_str(), 0)) {
614614 if (__l_ == 0)
615615 __throw_runtime_error(
616616 ("collate_byname<char>::collate_byname"
......@@ -619,13 +619,13 @@ collate_byname<char>::collate_byname(const string& name, size_t refs)
619619 .c_str());
620620}
621621
622collate_byname<char>::~collate_byname() { freelocale(__l_); }
622collate_byname<char>::~collate_byname() { __locale::__freelocale(__l_); }
623623
624624int collate_byname<char>::do_compare(
625625 const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const {
626626 string_type lhs(__lo1, __hi1);
627627 string_type rhs(__lo2, __hi2);
628 int r = strcoll_l(lhs.c_str(), rhs.c_str(), __l_);
628 int r = __locale::__strcoll(lhs.c_str(), rhs.c_str(), __l_);
629629 if (r < 0)
630630 return -1;
631631 if (r > 0)
......@@ -635,16 +635,16 @@ int collate_byname<char>::do_compare(
635635
636636collate_byname<char>::string_type collate_byname<char>::do_transform(const char_type* lo, const char_type* hi) const {
637637 const string_type in(lo, hi);
638 string_type out(strxfrm_l(0, in.c_str(), 0, __l_), char());
639 strxfrm_l(const_cast<char*>(out.c_str()), in.c_str(), out.size() + 1, __l_);
638 string_type out(__locale::__strxfrm(0, in.c_str(), 0, __l_), char());
639 __locale::__strxfrm(const_cast<char*>(out.c_str()), in.c_str(), out.size() + 1, __l_);
640640 return out;
641641}
642642
643643// template <> class collate_byname<wchar_t>
644644
645#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
645#if _LIBCPP_HAS_WIDE_CHARACTERS
646646collate_byname<wchar_t>::collate_byname(const char* n, size_t refs)
647 : collate<wchar_t>(refs), __l_(newlocale(LC_ALL_MASK, n, 0)) {
647 : collate<wchar_t>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, n, 0)) {
648648 if (__l_ == 0)
649649 __throw_runtime_error(
650650 ("collate_byname<wchar_t>::collate_byname(size_t refs)"
......@@ -654,7 +654,7 @@ collate_byname<wchar_t>::collate_byname(const char* n, size_t refs)
654654}
655655
656656collate_byname<wchar_t>::collate_byname(const string& name, size_t refs)
657 : collate<wchar_t>(refs), __l_(newlocale(LC_ALL_MASK, name.c_str(), 0)) {
657 : collate<wchar_t>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name.c_str(), 0)) {
658658 if (__l_ == 0)
659659 __throw_runtime_error(
660660 ("collate_byname<wchar_t>::collate_byname(size_t refs)"
......@@ -663,13 +663,13 @@ collate_byname<wchar_t>::collate_byname(const string& name, size_t refs)
663663 .c_str());
664664}
665665
666collate_byname<wchar_t>::~collate_byname() { freelocale(__l_); }
666collate_byname<wchar_t>::~collate_byname() { __locale::__freelocale(__l_); }
667667
668668int collate_byname<wchar_t>::do_compare(
669669 const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const {
670670 string_type lhs(__lo1, __hi1);
671671 string_type rhs(__lo2, __hi2);
672 int r = wcscoll_l(lhs.c_str(), rhs.c_str(), __l_);
672 int r = __locale::__wcscoll(lhs.c_str(), rhs.c_str(), __l_);
673673 if (r < 0)
674674 return -1;
675675 if (r > 0)
......@@ -680,11 +680,11 @@ int collate_byname<wchar_t>::do_compare(
680680collate_byname<wchar_t>::string_type
681681collate_byname<wchar_t>::do_transform(const char_type* lo, const char_type* hi) const {
682682 const string_type in(lo, hi);
683 string_type out(wcsxfrm_l(0, in.c_str(), 0, __l_), wchar_t());
684 wcsxfrm_l(const_cast<wchar_t*>(out.c_str()), in.c_str(), out.size() + 1, __l_);
683 string_type out(__locale::__wcsxfrm(0, in.c_str(), 0, __l_), wchar_t());
684 __locale::__wcsxfrm(const_cast<wchar_t*>(out.c_str()), in.c_str(), out.size() + 1, __l_);
685685 return out;
686686}
687#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
687#endif // _LIBCPP_HAS_WIDE_CHARACTERS
688688
689689const ctype_base::mask ctype_base::space;
690690const ctype_base::mask ctype_base::print;
......@@ -701,75 +701,76 @@ const ctype_base::mask ctype_base::graph;
701701
702702// template <> class ctype<wchar_t>;
703703
704#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
704#if _LIBCPP_HAS_WIDE_CHARACTERS
705705constinit locale::id ctype<wchar_t>::id;
706706
707707ctype<wchar_t>::~ctype() {}
708708
709709bool ctype<wchar_t>::do_is(mask m, char_type c) const {
710 return isascii(c) ? (ctype<char>::classic_table()[c] & m) != 0 : false;
710 return std::__libcpp_isascii(c) ? (ctype<char>::classic_table()[c] & m) != 0 : false;
711711}
712712
713713const wchar_t* ctype<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const {
714714 for (; low != high; ++low, ++vec)
715 *vec = static_cast<mask>(isascii(*low) ? ctype<char>::classic_table()[*low] : 0);
715 *vec = static_cast<mask>(std::__libcpp_isascii(*low) ? ctype<char>::classic_table()[*low] : 0);
716716 return low;
717717}
718718
719719const wchar_t* ctype<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const {
720720 for (; low != high; ++low)
721 if (isascii(*low) && (ctype<char>::classic_table()[*low] & m))
721 if (std::__libcpp_isascii(*low) && (ctype<char>::classic_table()[*low] & m))
722722 break;
723723 return low;
724724}
725725
726726const wchar_t* ctype<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const {
727727 for (; low != high; ++low)
728 if (!(isascii(*low) && (ctype<char>::classic_table()[*low] & m)))
728 if (!(std::__libcpp_isascii(*low) && (ctype<char>::classic_table()[*low] & m)))
729729 break;
730730 return low;
731731}
732732
733733wchar_t ctype<wchar_t>::do_toupper(char_type c) const {
734734# ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
735 return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
735 return std::__libcpp_isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
736736# elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__MVS__)
737 return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
737 return std::__libcpp_isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
738738# else
739 return (isascii(c) && iswlower_l(c, _LIBCPP_GET_C_LOCALE)) ? c - L'a' + L'A' : c;
739 return (std::__libcpp_isascii(c) && __locale::__iswlower(c, _LIBCPP_GET_C_LOCALE)) ? c - L'a' + L'A' : c;
740740# endif
741741}
742742
743743const wchar_t* ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const {
744744 for (; low != high; ++low)
745745# ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
746 *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
746 *low = std::__libcpp_isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
747747# elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__MVS__)
748 *low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low] : *low;
748 *low = std::__libcpp_isascii(*low) ? ctype<char>::__classic_upper_table()[*low] : *low;
749749# else
750 *low = (isascii(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? (*low - L'a' + L'A') : *low;
750 *low =
751 (std::__libcpp_isascii(*low) && __locale::__islower(*low, _LIBCPP_GET_C_LOCALE)) ? (*low - L'a' + L'A') : *low;
751752# endif
752753 return low;
753754}
754755
755756wchar_t ctype<wchar_t>::do_tolower(char_type c) const {
756757# ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
757 return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
758 return std::__libcpp_isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
758759# elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__MVS__)
759 return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
760 return std::__libcpp_isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
760761# else
761 return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c - L'A' + 'a' : c;
762 return (std::__libcpp_isascii(c) && __locale::__isupper(c, _LIBCPP_GET_C_LOCALE)) ? c - L'A' + 'a' : c;
762763# endif
763764}
764765
765766const wchar_t* ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const {
766767 for (; low != high; ++low)
767768# ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
768 *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
769 *low = std::__libcpp_isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
769770# elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__MVS__)
770 *low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low] : *low;
771 *low = std::__libcpp_isascii(*low) ? ctype<char>::__classic_lower_table()[*low] : *low;
771772# else
772 *low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low - L'A' + L'a' : *low;
773 *low = (std::__libcpp_isascii(*low) && __locale::__isupper(*low, _LIBCPP_GET_C_LOCALE)) ? *low - L'A' + L'a' : *low;
773774# endif
774775 return low;
775776}
......@@ -783,20 +784,20 @@ const char* ctype<wchar_t>::do_widen(const char* low, const char* high, char_typ
783784}
784785
785786char ctype<wchar_t>::do_narrow(char_type c, char dfault) const {
786 if (isascii(c))
787 if (std::__libcpp_isascii(c))
787788 return static_cast<char>(c);
788789 return dfault;
789790}
790791
791792const wchar_t* ctype<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const {
792793 for (; low != high; ++low, ++dest)
793 if (isascii(*low))
794 if (std::__libcpp_isascii(*low))
794795 *dest = static_cast<char>(*low);
795796 else
796797 *dest = dfault;
797798 return low;
798799}
799#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
800#endif // _LIBCPP_HAS_WIDE_CHARACTERS
800801
801802// template <> class ctype<char>;
802803
......@@ -816,52 +817,56 @@ ctype<char>::~ctype() {
816817
817818char ctype<char>::do_toupper(char_type c) const {
818819#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
819 return isascii(c) ? static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
820 return std::__libcpp_isascii(c) ? static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
820821#elif defined(__NetBSD__)
821822 return static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]);
822823#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
823 return isascii(c) ? static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]) : c;
824 return std::__libcpp_isascii(c) ? static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]) : c;
824825#else
825 return (isascii(c) && islower_l(c, _LIBCPP_GET_C_LOCALE)) ? c - 'a' + 'A' : c;
826 return (std::__libcpp_isascii(c) && __locale::__islower(c, _LIBCPP_GET_C_LOCALE)) ? c - 'a' + 'A' : c;
826827#endif
827828}
828829
829830const char* ctype<char>::do_toupper(char_type* low, const char_type* high) const {
830831 for (; low != high; ++low)
831832#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
832 *low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;
833 *low = std::__libcpp_isascii(*low)
834 ? static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)])
835 : *low;
833836#elif defined(__NetBSD__)
834837 *low = static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(*low)]);
835838#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
836 *low = isascii(*low) ? static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
839 *low = std::__libcpp_isascii(*low) ? static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
837840#else
838 *low = (isascii(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low - 'a' + 'A' : *low;
841 *low = (std::__libcpp_isascii(*low) && __locale::__islower(*low, _LIBCPP_GET_C_LOCALE)) ? *low - 'a' + 'A' : *low;
839842#endif
840843 return low;
841844}
842845
843846char ctype<char>::do_tolower(char_type c) const {
844847#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
845 return isascii(c) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
848 return std::__libcpp_isascii(c) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
846849#elif defined(__NetBSD__)
847850 return static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(c)]);
848851#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
849 return isascii(c) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
852 return std::__libcpp_isascii(c) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
850853#else
851 return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c - 'A' + 'a' : c;
854 return (std::__libcpp_isascii(c) && __locale::__isupper(c, _LIBCPP_GET_C_LOCALE)) ? c - 'A' + 'a' : c;
852855#endif
853856}
854857
855858const char* ctype<char>::do_tolower(char_type* low, const char_type* high) const {
856859 for (; low != high; ++low)
857860#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
858 *low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)]) : *low;
861 *low = std::__libcpp_isascii(*low)
862 ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)])
863 : *low;
859864#elif defined(__NetBSD__)
860865 *low = static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(*low)]);
861866#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
862 *low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
867 *low = std::__libcpp_isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
863868#else
864 *low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low - 'A' + 'a' : *low;
869 *low = (std::__libcpp_isascii(*low) && __locale::__isupper(*low, _LIBCPP_GET_C_LOCALE)) ? *low - 'A' + 'a' : *low;
865870#endif
866871 return low;
867872}
......@@ -875,14 +880,14 @@ const char* ctype<char>::do_widen(const char* low, const char* high, char_type*
875880}
876881
877882char ctype<char>::do_narrow(char_type c, char dfault) const {
878 if (isascii(c))
883 if (std::__libcpp_isascii(c))
879884 return static_cast<char>(c);
880885 return dfault;
881886}
882887
883888const char* ctype<char>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const {
884889 for (; low != high; ++low, ++dest)
885 if (isascii(*low))
890 if (std::__libcpp_isascii(*low))
886891 *dest = *low;
887892 else
888893 *dest = dfault;
......@@ -1004,7 +1009,7 @@ const ctype<char>::mask* ctype<char>::classic_table() noexcept {
10041009# warning ctype<char>::classic_table() is not implemented
10051010 printf("ctype<char>::classic_table() is not implemented\n");
10061011 abort();
1007 return NULL;
1012 return nullptr;
10081013# endif
10091014}
10101015#endif
......@@ -1042,7 +1047,7 @@ const unsigned short* ctype<char>::__classic_upper_table() _NOEXCEPT {
10421047// template <> class ctype_byname<char>
10431048
10441049ctype_byname<char>::ctype_byname(const char* name, size_t refs)
1045 : ctype<char>(0, false, refs), __l_(newlocale(LC_ALL_MASK, name, 0)) {
1050 : ctype<char>(0, false, refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name, 0)) {
10461051 if (__l_ == 0)
10471052 __throw_runtime_error(
10481053 ("ctype_byname<char>::ctype_byname"
......@@ -1052,7 +1057,7 @@ ctype_byname<char>::ctype_byname(const char* name, size_t refs)
10521057}
10531058
10541059ctype_byname<char>::ctype_byname(const string& name, size_t refs)
1055 : ctype<char>(0, false, refs), __l_(newlocale(LC_ALL_MASK, name.c_str(), 0)) {
1060 : ctype<char>(0, false, refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name.c_str(), 0)) {
10561061 if (__l_ == 0)
10571062 __throw_runtime_error(
10581063 ("ctype_byname<char>::ctype_byname"
......@@ -1061,33 +1066,33 @@ ctype_byname<char>::ctype_byname(const string& name, size_t refs)
10611066 .c_str());
10621067}
10631068
1064ctype_byname<char>::~ctype_byname() { freelocale(__l_); }
1069ctype_byname<char>::~ctype_byname() { __locale::__freelocale(__l_); }
10651070
10661071char ctype_byname<char>::do_toupper(char_type c) const {
1067 return static_cast<char>(toupper_l(static_cast<unsigned char>(c), __l_));
1072 return static_cast<char>(__locale::__toupper(static_cast<unsigned char>(c), __l_));
10681073}
10691074
10701075const char* ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const {
10711076 for (; low != high; ++low)
1072 *low = static_cast<char>(toupper_l(static_cast<unsigned char>(*low), __l_));
1077 *low = static_cast<char>(__locale::__toupper(static_cast<unsigned char>(*low), __l_));
10731078 return low;
10741079}
10751080
10761081char ctype_byname<char>::do_tolower(char_type c) const {
1077 return static_cast<char>(tolower_l(static_cast<unsigned char>(c), __l_));
1082 return static_cast<char>(__locale::__tolower(static_cast<unsigned char>(c), __l_));
10781083}
10791084
10801085const char* ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const {
10811086 for (; low != high; ++low)
1082 *low = static_cast<char>(tolower_l(static_cast<unsigned char>(*low), __l_));
1087 *low = static_cast<char>(__locale::__tolower(static_cast<unsigned char>(*low), __l_));
10831088 return low;
10841089}
10851090
10861091// template <> class ctype_byname<wchar_t>
10871092
1088#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1093#if _LIBCPP_HAS_WIDE_CHARACTERS
10891094ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)
1090 : ctype<wchar_t>(refs), __l_(newlocale(LC_ALL_MASK, name, 0)) {
1095 : ctype<wchar_t>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name, 0)) {
10911096 if (__l_ == 0)
10921097 __throw_runtime_error(
10931098 ("ctype_byname<wchar_t>::ctype_byname"
......@@ -1097,7 +1102,7 @@ ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)
10971102}
10981103
10991104ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs)
1100 : ctype<wchar_t>(refs), __l_(newlocale(LC_ALL_MASK, name.c_str(), 0)) {
1105 : ctype<wchar_t>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name.c_str(), 0)) {
11011106 if (__l_ == 0)
11021107 __throw_runtime_error(
11031108 ("ctype_byname<wchar_t>::ctype_byname"
......@@ -1106,70 +1111,70 @@ ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs)
11061111 .c_str());
11071112}
11081113
1109ctype_byname<wchar_t>::~ctype_byname() { freelocale(__l_); }
1114ctype_byname<wchar_t>::~ctype_byname() { __locale::__freelocale(__l_); }
11101115
11111116bool ctype_byname<wchar_t>::do_is(mask m, char_type c) const {
1117 wint_t ch = static_cast<wint_t>(c);
11121118# ifdef _LIBCPP_WCTYPE_IS_MASK
1113 return static_cast<bool>(iswctype_l(c, m, __l_));
1119 return static_cast<bool>(__locale::__iswctype(ch, m, __l_));
11141120# else
11151121 bool result = false;
1116 wint_t ch = static_cast<wint_t>(c);
11171122 if ((m & space) == space)
1118 result |= (iswspace_l(ch, __l_) != 0);
1123 result |= (__locale::__iswspace(ch, __l_) != 0);
11191124 if ((m & print) == print)
1120 result |= (iswprint_l(ch, __l_) != 0);
1125 result |= (__locale::__iswprint(ch, __l_) != 0);
11211126 if ((m & cntrl) == cntrl)
1122 result |= (iswcntrl_l(ch, __l_) != 0);
1127 result |= (__locale::__iswcntrl(ch, __l_) != 0);
11231128 if ((m & upper) == upper)
1124 result |= (iswupper_l(ch, __l_) != 0);
1129 result |= (__locale::__iswupper(ch, __l_) != 0);
11251130 if ((m & lower) == lower)
1126 result |= (iswlower_l(ch, __l_) != 0);
1131 result |= (__locale::__iswlower(ch, __l_) != 0);
11271132 if ((m & alpha) == alpha)
1128 result |= (iswalpha_l(ch, __l_) != 0);
1133 result |= (__locale::__iswalpha(ch, __l_) != 0);
11291134 if ((m & digit) == digit)
1130 result |= (iswdigit_l(ch, __l_) != 0);
1135 result |= (__locale::__iswdigit(ch, __l_) != 0);
11311136 if ((m & punct) == punct)
1132 result |= (iswpunct_l(ch, __l_) != 0);
1137 result |= (__locale::__iswpunct(ch, __l_) != 0);
11331138 if ((m & xdigit) == xdigit)
1134 result |= (iswxdigit_l(ch, __l_) != 0);
1139 result |= (__locale::__iswxdigit(ch, __l_) != 0);
11351140 if ((m & blank) == blank)
1136 result |= (iswblank_l(ch, __l_) != 0);
1141 result |= (__locale::__iswblank(ch, __l_) != 0);
11371142 return result;
11381143# endif
11391144}
11401145
11411146const wchar_t* ctype_byname<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const {
11421147 for (; low != high; ++low, ++vec) {
1143 if (isascii(*low))
1148 if (std::__libcpp_isascii(*low))
11441149 *vec = static_cast<mask>(ctype<char>::classic_table()[*low]);
11451150 else {
11461151 *vec = 0;
11471152 wint_t ch = static_cast<wint_t>(*low);
1148 if (iswspace_l(ch, __l_))
1153 if (__locale::__iswspace(ch, __l_))
11491154 *vec |= space;
11501155# ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
1151 if (iswprint_l(ch, __l_))
1156 if (__locale::__iswprint(ch, __l_))
11521157 *vec |= print;
11531158# endif
1154 if (iswcntrl_l(ch, __l_))
1159 if (__locale::__iswcntrl(ch, __l_))
11551160 *vec |= cntrl;
1156 if (iswupper_l(ch, __l_))
1161 if (__locale::__iswupper(ch, __l_))
11571162 *vec |= upper;
1158 if (iswlower_l(ch, __l_))
1163 if (__locale::__iswlower(ch, __l_))
11591164 *vec |= lower;
11601165# ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
1161 if (iswalpha_l(ch, __l_))
1166 if (__locale::__iswalpha(ch, __l_))
11621167 *vec |= alpha;
11631168# endif
1164 if (iswdigit_l(ch, __l_))
1169 if (__locale::__iswdigit(ch, __l_))
11651170 *vec |= digit;
1166 if (iswpunct_l(ch, __l_))
1171 if (__locale::__iswpunct(ch, __l_))
11671172 *vec |= punct;
11681173# ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
1169 if (iswxdigit_l(ch, __l_))
1174 if (__locale::__iswxdigit(ch, __l_))
11701175 *vec |= xdigit;
11711176# endif
1172 if (iswblank_l(ch, __l_))
1177 if (__locale::__iswblank(ch, __l_))
11731178 *vec |= blank;
11741179 }
11751180 }
......@@ -1179,29 +1184,29 @@ const wchar_t* ctype_byname<wchar_t>::do_is(const char_type* low, const char_typ
11791184const wchar_t* ctype_byname<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const {
11801185 for (; low != high; ++low) {
11811186# ifdef _LIBCPP_WCTYPE_IS_MASK
1182 if (iswctype_l(*low, m, __l_))
1187 if (__locale::__iswctype(static_cast<wint_t>(*low), m, __l_))
11831188 break;
11841189# else
11851190 wint_t ch = static_cast<wint_t>(*low);
1186 if ((m & space) == space && iswspace_l(ch, __l_))
1191 if ((m & space) == space && __locale::__iswspace(ch, __l_))
11871192 break;
1188 if ((m & print) == print && iswprint_l(ch, __l_))
1193 if ((m & print) == print && __locale::__iswprint(ch, __l_))
11891194 break;
1190 if ((m & cntrl) == cntrl && iswcntrl_l(ch, __l_))
1195 if ((m & cntrl) == cntrl && __locale::__iswcntrl(ch, __l_))
11911196 break;
1192 if ((m & upper) == upper && iswupper_l(ch, __l_))
1197 if ((m & upper) == upper && __locale::__iswupper(ch, __l_))
11931198 break;
1194 if ((m & lower) == lower && iswlower_l(ch, __l_))
1199 if ((m & lower) == lower && __locale::__iswlower(ch, __l_))
11951200 break;
1196 if ((m & alpha) == alpha && iswalpha_l(ch, __l_))
1201 if ((m & alpha) == alpha && __locale::__iswalpha(ch, __l_))
11971202 break;
1198 if ((m & digit) == digit && iswdigit_l(ch, __l_))
1203 if ((m & digit) == digit && __locale::__iswdigit(ch, __l_))
11991204 break;
1200 if ((m & punct) == punct && iswpunct_l(ch, __l_))
1205 if ((m & punct) == punct && __locale::__iswpunct(ch, __l_))
12011206 break;
1202 if ((m & xdigit) == xdigit && iswxdigit_l(ch, __l_))
1207 if ((m & xdigit) == xdigit && __locale::__iswxdigit(ch, __l_))
12031208 break;
1204 if ((m & blank) == blank && iswblank_l(ch, __l_))
1209 if ((m & blank) == blank && __locale::__iswblank(ch, __l_))
12051210 break;
12061211# endif
12071212 }
......@@ -1210,30 +1215,30 @@ const wchar_t* ctype_byname<wchar_t>::do_scan_is(mask m, const char_type* low, c
12101215
12111216const wchar_t* ctype_byname<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const {
12121217 for (; low != high; ++low) {
1218 wint_t ch = static_cast<wint_t>(*low);
12131219# ifdef _LIBCPP_WCTYPE_IS_MASK
1214 if (!iswctype_l(*low, m, __l_))
1220 if (!__locale::__iswctype(ch, m, __l_))
12151221 break;
12161222# else
1217 wint_t ch = static_cast<wint_t>(*low);
1218 if ((m & space) == space && iswspace_l(ch, __l_))
1223 if ((m & space) == space && __locale::__iswspace(ch, __l_))
12191224 continue;
1220 if ((m & print) == print && iswprint_l(ch, __l_))
1225 if ((m & print) == print && __locale::__iswprint(ch, __l_))
12211226 continue;
1222 if ((m & cntrl) == cntrl && iswcntrl_l(ch, __l_))
1227 if ((m & cntrl) == cntrl && __locale::__iswcntrl(ch, __l_))
12231228 continue;
1224 if ((m & upper) == upper && iswupper_l(ch, __l_))
1229 if ((m & upper) == upper && __locale::__iswupper(ch, __l_))
12251230 continue;
1226 if ((m & lower) == lower && iswlower_l(ch, __l_))
1231 if ((m & lower) == lower && __locale::__iswlower(ch, __l_))
12271232 continue;
1228 if ((m & alpha) == alpha && iswalpha_l(ch, __l_))
1233 if ((m & alpha) == alpha && __locale::__iswalpha(ch, __l_))
12291234 continue;
1230 if ((m & digit) == digit && iswdigit_l(ch, __l_))
1235 if ((m & digit) == digit && __locale::__iswdigit(ch, __l_))
12311236 continue;
1232 if ((m & punct) == punct && iswpunct_l(ch, __l_))
1237 if ((m & punct) == punct && __locale::__iswpunct(ch, __l_))
12331238 continue;
1234 if ((m & xdigit) == xdigit && iswxdigit_l(ch, __l_))
1239 if ((m & xdigit) == xdigit && __locale::__iswxdigit(ch, __l_))
12351240 continue;
1236 if ((m & blank) == blank && iswblank_l(ch, __l_))
1241 if ((m & blank) == blank && __locale::__iswblank(ch, __l_))
12371242 continue;
12381243 break;
12391244# endif
......@@ -1241,44 +1246,44 @@ const wchar_t* ctype_byname<wchar_t>::do_scan_not(mask m, const char_type* low,
12411246 return low;
12421247}
12431248
1244wchar_t ctype_byname<wchar_t>::do_toupper(char_type c) const { return towupper_l(c, __l_); }
1249wchar_t ctype_byname<wchar_t>::do_toupper(char_type c) const { return __locale::__towupper(c, __l_); }
12451250
12461251const wchar_t* ctype_byname<wchar_t>::do_toupper(char_type* low, const char_type* high) const {
12471252 for (; low != high; ++low)
1248 *low = towupper_l(*low, __l_);
1253 *low = __locale::__towupper(*low, __l_);
12491254 return low;
12501255}
12511256
1252wchar_t ctype_byname<wchar_t>::do_tolower(char_type c) const { return towlower_l(c, __l_); }
1257wchar_t ctype_byname<wchar_t>::do_tolower(char_type c) const { return __locale::__towlower(c, __l_); }
12531258
12541259const wchar_t* ctype_byname<wchar_t>::do_tolower(char_type* low, const char_type* high) const {
12551260 for (; low != high; ++low)
1256 *low = towlower_l(*low, __l_);
1261 *low = __locale::__towlower(*low, __l_);
12571262 return low;
12581263}
12591264
1260wchar_t ctype_byname<wchar_t>::do_widen(char c) const { return __libcpp_btowc_l(c, __l_); }
1265wchar_t ctype_byname<wchar_t>::do_widen(char c) const { return __locale::__btowc(c, __l_); }
12611266
12621267const char* ctype_byname<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const {
12631268 for (; low != high; ++low, ++dest)
1264 *dest = __libcpp_btowc_l(*low, __l_);
1269 *dest = __locale::__btowc(*low, __l_);
12651270 return low;
12661271}
12671272
12681273char ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const {
1269 int r = __libcpp_wctob_l(c, __l_);
1274 int r = __locale::__wctob(c, __l_);
12701275 return (r != EOF) ? static_cast<char>(r) : dfault;
12711276}
12721277
12731278const wchar_t*
12741279ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const {
12751280 for (; low != high; ++low, ++dest) {
1276 int r = __libcpp_wctob_l(*low, __l_);
1281 int r = __locale::__wctob(*low, __l_);
12771282 *dest = (r != EOF) ? static_cast<char>(r) : dfault;
12781283 }
12791284 return low;
12801285}
1281#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1286#endif // _LIBCPP_HAS_WIDE_CHARACTERS
12821287
12831288// template <> class codecvt<char, char, mbstate_t>
12841289
......@@ -1331,13 +1336,13 @@ int codecvt<char, char, mbstate_t>::do_max_length() const noexcept { return 1; }
13311336
13321337// template <> class codecvt<wchar_t, char, mbstate_t>
13331338
1334#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1339#if _LIBCPP_HAS_WIDE_CHARACTERS
13351340constinit locale::id codecvt<wchar_t, char, mbstate_t>::id;
13361341
13371342codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs) : locale::facet(refs), __l_(_LIBCPP_GET_C_LOCALE) {}
13381343
13391344codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs)
1340 : locale::facet(refs), __l_(newlocale(LC_ALL_MASK, nm, 0)) {
1345 : locale::facet(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, nm, 0)) {
13411346 if (__l_ == 0)
13421347 __throw_runtime_error(
13431348 ("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname"
......@@ -1348,7 +1353,7 @@ codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs)
13481353
13491354codecvt<wchar_t, char, mbstate_t>::~codecvt() {
13501355 if (__l_ != _LIBCPP_GET_C_LOCALE)
1351 freelocale(__l_);
1356 __locale::__freelocale(__l_);
13521357}
13531358
13541359codecvt<wchar_t, char, mbstate_t>::result codecvt<wchar_t, char, mbstate_t>::do_out(
......@@ -1369,12 +1374,12 @@ codecvt<wchar_t, char, mbstate_t>::result codecvt<wchar_t, char, mbstate_t>::do_
13691374 for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt) {
13701375 // save state in case it is needed to recover to_nxt on error
13711376 mbstate_t save_state = st;
1372 size_t n = __libcpp_wcsnrtombs_l(
1377 size_t n = __locale::__wcsnrtombs(
13731378 to, &frm_nxt, static_cast<size_t>(fend - frm), static_cast<size_t>(to_end - to), &st, __l_);
13741379 if (n == size_t(-1)) {
13751380 // need to recover to_nxt
13761381 for (to_nxt = to; frm != frm_nxt; ++frm) {
1377 n = __libcpp_wcrtomb_l(to_nxt, *frm, &save_state, __l_);
1382 n = __locale::__wcrtomb(to_nxt, *frm, &save_state, __l_);
13781383 if (n == size_t(-1))
13791384 break;
13801385 to_nxt += n;
......@@ -1391,7 +1396,7 @@ codecvt<wchar_t, char, mbstate_t>::result codecvt<wchar_t, char, mbstate_t>::do_
13911396 {
13921397 // Try to write the terminating null
13931398 extern_type tmp[MB_LEN_MAX];
1394 n = __libcpp_wcrtomb_l(tmp, intern_type(), &st, __l_);
1399 n = __locale::__wcrtomb(tmp, intern_type(), &st, __l_);
13951400 if (n == size_t(-1)) // on error
13961401 return error;
13971402 if (n > static_cast<size_t>(to_end - to_nxt)) // is there room?
......@@ -1426,12 +1431,12 @@ codecvt<wchar_t, char, mbstate_t>::result codecvt<wchar_t, char, mbstate_t>::do_
14261431 for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt) {
14271432 // save state in case it is needed to recover to_nxt on error
14281433 mbstate_t save_state = st;
1429 size_t n = __libcpp_mbsnrtowcs_l(
1434 size_t n = __locale::__mbsnrtowcs(
14301435 to, &frm_nxt, static_cast<size_t>(fend - frm), static_cast<size_t>(to_end - to), &st, __l_);
14311436 if (n == size_t(-1)) {
14321437 // need to recover to_nxt
14331438 for (to_nxt = to; frm != frm_nxt; ++to_nxt) {
1434 n = __libcpp_mbrtowc_l(to_nxt, frm, static_cast<size_t>(fend - frm), &save_state, __l_);
1439 n = __locale::__mbrtowc(to_nxt, frm, static_cast<size_t>(fend - frm), &save_state, __l_);
14351440 switch (n) {
14361441 case 0:
14371442 ++frm;
......@@ -1458,7 +1463,7 @@ codecvt<wchar_t, char, mbstate_t>::result codecvt<wchar_t, char, mbstate_t>::do_
14581463 if (fend != frm_end) // set up next null terminated sequence
14591464 {
14601465 // Try to write the terminating null
1461 n = __libcpp_mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l_);
1466 n = __locale::__mbrtowc(to_nxt, frm_nxt, 1, &st, __l_);
14621467 if (n != 0) // on error
14631468 return error;
14641469 ++to_nxt;
......@@ -1476,7 +1481,7 @@ codecvt<wchar_t, char, mbstate_t>::result codecvt<wchar_t, char, mbstate_t>::do_
14761481 state_type& st, extern_type* to, extern_type* to_end, extern_type*& to_nxt) const {
14771482 to_nxt = to;
14781483 extern_type tmp[MB_LEN_MAX];
1479 size_t n = __libcpp_wcrtomb_l(tmp, intern_type(), &st, __l_);
1484 size_t n = __locale::__wcrtomb(tmp, intern_type(), &st, __l_);
14801485 if (n == size_t(-1) || n == 0) // on error
14811486 return error;
14821487 --n;
......@@ -1488,12 +1493,12 @@ codecvt<wchar_t, char, mbstate_t>::result codecvt<wchar_t, char, mbstate_t>::do_
14881493}
14891494
14901495int codecvt<wchar_t, char, mbstate_t>::do_encoding() const noexcept {
1491 if (__libcpp_mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l_) != 0)
1496 if (__locale::__mbtowc(nullptr, nullptr, MB_LEN_MAX, __l_) != 0)
14921497 return -1;
14931498
14941499 // stateless encoding
1495 if (__l_ == 0 || __libcpp_mb_cur_max_l(__l_) == 1) // there are no known constant length encodings
1496 return 1; // which take more than 1 char to form a wchar_t
1500 if (__l_ == 0 || __locale::__mb_len_max(__l_) == 1) // there are no known constant length encodings
1501 return 1; // which take more than 1 char to form a wchar_t
14971502 return 0;
14981503}
14991504
......@@ -1503,7 +1508,7 @@ int codecvt<wchar_t, char, mbstate_t>::do_length(
15031508 state_type& st, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
15041509 int nbytes = 0;
15051510 for (size_t nwchar_t = 0; nwchar_t < mx && frm != frm_end; ++nwchar_t) {
1506 size_t n = __libcpp_mbrlen_l(frm, static_cast<size_t>(frm_end - frm), &st, __l_);
1511 size_t n = __locale::__mbrlen(frm, static_cast<size_t>(frm_end - frm), &st, __l_);
15071512 switch (n) {
15081513 case 0:
15091514 ++nbytes;
......@@ -1522,9 +1527,9 @@ int codecvt<wchar_t, char, mbstate_t>::do_length(
15221527}
15231528
15241529int codecvt<wchar_t, char, mbstate_t>::do_max_length() const noexcept {
1525 return __l_ == 0 ? 1 : static_cast<int>(__libcpp_mb_cur_max_l(__l_));
1530 return __l_ == 0 ? 1 : static_cast<int>(__locale::__mb_len_max(__l_));
15261531}
1527#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1532#endif // _LIBCPP_HAS_WIDE_CHARACTERS
15281533
15291534// Valid UTF ranges
15301535// UTF-32 UTF-16 UTF-8 # of code points
......@@ -2815,7 +2820,7 @@ int codecvt<char16_t, char, mbstate_t>::do_length(
28152820
28162821int codecvt<char16_t, char, mbstate_t>::do_max_length() const noexcept { return 4; }
28172822
2818#ifndef _LIBCPP_HAS_NO_CHAR8_T
2823#if _LIBCPP_HAS_CHAR8_T
28192824
28202825// template <> class codecvt<char16_t, char8_t, mbstate_t>
28212826
......@@ -2949,7 +2954,7 @@ int codecvt<char32_t, char, mbstate_t>::do_length(
29492954
29502955int codecvt<char32_t, char, mbstate_t>::do_max_length() const noexcept { return 4; }
29512956
2952#ifndef _LIBCPP_HAS_NO_CHAR8_T
2957#if _LIBCPP_HAS_CHAR8_T
29532958
29542959// template <> class codecvt<char32_t, char8_t, mbstate_t>
29552960
......@@ -3020,7 +3025,7 @@ int codecvt<char32_t, char8_t, mbstate_t>::do_max_length() const noexcept { retu
30203025
30213026// __codecvt_utf8<wchar_t>
30223027
3023#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3028#if _LIBCPP_HAS_WIDE_CHARACTERS
30243029__codecvt_utf8<wchar_t>::result __codecvt_utf8<wchar_t>::do_out(
30253030 state_type&,
30263031 const intern_type* frm,
......@@ -3111,7 +3116,7 @@ int __codecvt_utf8<wchar_t>::do_max_length() const noexcept {
31113116 return 4;
31123117# endif
31133118}
3114#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
3119#endif // _LIBCPP_HAS_WIDE_CHARACTERS
31153120
31163121// __codecvt_utf8<char16_t>
31173122
......@@ -3249,7 +3254,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
32493254
32503255// __codecvt_utf16<wchar_t, false>
32513256
3252#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3257#if _LIBCPP_HAS_WIDE_CHARACTERS
32533258__codecvt_utf16<wchar_t, false>::result __codecvt_utf16<wchar_t, false>::do_out(
32543259 state_type&,
32553260 const intern_type* frm,
......@@ -3431,7 +3436,7 @@ int __codecvt_utf16<wchar_t, true>::do_max_length() const noexcept {
34313436 return 4;
34323437# endif
34333438}
3434#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
3439#endif // _LIBCPP_HAS_WIDE_CHARACTERS
34353440
34363441// __codecvt_utf16<char16_t, false>
34373442
......@@ -3703,7 +3708,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
37033708
37043709// __codecvt_utf8_utf16<wchar_t>
37053710
3706#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3711#if _LIBCPP_HAS_WIDE_CHARACTERS
37073712__codecvt_utf8_utf16<wchar_t>::result __codecvt_utf8_utf16<wchar_t>::do_out(
37083713 state_type&,
37093714 const intern_type* frm,
......@@ -3778,7 +3783,7 @@ int __codecvt_utf8_utf16<wchar_t>::do_max_length() const noexcept {
37783783 return 7;
37793784 return 4;
37803785}
3781#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
3786#endif // _LIBCPP_HAS_WIDE_CHARACTERS
37823787
37833788// __codecvt_utf8_utf16<char16_t>
37843789
......@@ -3930,22 +3935,22 @@ __widen_from_utf8<16>::~__widen_from_utf8() {}
39303935
39313936__widen_from_utf8<32>::~__widen_from_utf8() {}
39323937
3933#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3934static bool checked_string_to_wchar_convert(wchar_t& dest, const char* ptr, locale_t loc) {
3938#if _LIBCPP_HAS_WIDE_CHARACTERS
3939static bool checked_string_to_wchar_convert(wchar_t& dest, const char* ptr, __locale::__locale_t loc) {
39353940 if (*ptr == '\0')
39363941 return false;
39373942 mbstate_t mb = {};
39383943 wchar_t out;
3939 size_t ret = __libcpp_mbrtowc_l(&out, ptr, strlen(ptr), &mb, loc);
3944 size_t ret = __locale::__mbrtowc(&out, ptr, strlen(ptr), &mb, loc);
39403945 if (ret == static_cast<size_t>(-1) || ret == static_cast<size_t>(-2)) {
39413946 return false;
39423947 }
39433948 dest = out;
39443949 return true;
39453950}
3946#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
3951#endif // _LIBCPP_HAS_WIDE_CHARACTERS
39473952
3948#ifdef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3953#if !_LIBCPP_HAS_WIDE_CHARACTERS
39493954static bool is_narrow_non_breaking_space(const char* ptr) {
39503955 // https://www.fileformat.info/info/unicode/char/202f/index.htm
39513956 return ptr[0] == '\xe2' && ptr[1] == '\x80' && ptr[2] == '\xaf';
......@@ -3955,9 +3960,9 @@ static bool is_non_breaking_space(const char* ptr) {
39553960 // https://www.fileformat.info/info/unicode/char/0a/index.htm
39563961 return ptr[0] == '\xc2' && ptr[1] == '\xa0';
39573962}
3958#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
3963#endif // _LIBCPP_HAS_WIDE_CHARACTERS
39593964
3960static bool checked_string_to_char_convert(char& dest, const char* ptr, locale_t __loc) {
3965static bool checked_string_to_char_convert(char& dest, const char* ptr, __locale::__locale_t __loc) {
39613966 if (*ptr == '\0')
39623967 return false;
39633968 if (!ptr[1]) {
......@@ -3965,14 +3970,14 @@ static bool checked_string_to_char_convert(char& dest, const char* ptr, locale_t
39653970 return true;
39663971 }
39673972
3968#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3973#if _LIBCPP_HAS_WIDE_CHARACTERS
39693974 // First convert the MBS into a wide char then attempt to narrow it using
39703975 // wctob_l.
39713976 wchar_t wout;
39723977 if (!checked_string_to_wchar_convert(wout, ptr, __loc))
39733978 return false;
39743979 int res;
3975 if ((res = __libcpp_wctob_l(wout, __loc)) != char_traits<char>::eof()) {
3980 if ((res = __locale::__wctob(wout, __loc)) != char_traits<char>::eof()) {
39763981 dest = res;
39773982 return true;
39783983 }
......@@ -3986,7 +3991,7 @@ static bool checked_string_to_char_convert(char& dest, const char* ptr, locale_t
39863991 default:
39873992 return false;
39883993 }
3989#else // _LIBCPP_HAS_NO_WIDE_CHARACTERS
3994#else // _LIBCPP_HAS_WIDE_CHARACTERS
39903995 // FIXME: Work around specific multibyte sequences that we can reasonably
39913996 // translate into a different single byte.
39923997 if (is_narrow_non_breaking_space(ptr) || is_non_breaking_space(ptr)) {
......@@ -3995,51 +4000,51 @@ static bool checked_string_to_char_convert(char& dest, const char* ptr, locale_t
39954000 }
39964001
39974002 return false;
3998#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
4003#endif // _LIBCPP_HAS_WIDE_CHARACTERS
39994004 __libcpp_unreachable();
40004005}
40014006
40024007// numpunct<char> && numpunct<wchar_t>
40034008
40044009constinit locale::id numpunct<char>::id;
4005#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4010#if _LIBCPP_HAS_WIDE_CHARACTERS
40064011constinit locale::id numpunct<wchar_t>::id;
40074012#endif
40084013
40094014numpunct<char>::numpunct(size_t refs) : locale::facet(refs), __decimal_point_('.'), __thousands_sep_(',') {}
40104015
4011#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4016#if _LIBCPP_HAS_WIDE_CHARACTERS
40124017numpunct<wchar_t>::numpunct(size_t refs) : locale::facet(refs), __decimal_point_(L'.'), __thousands_sep_(L',') {}
40134018#endif
40144019
40154020numpunct<char>::~numpunct() {}
40164021
4017#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4022#if _LIBCPP_HAS_WIDE_CHARACTERS
40184023numpunct<wchar_t>::~numpunct() {}
40194024#endif
40204025
40214026char numpunct< char >::do_decimal_point() const { return __decimal_point_; }
4022#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4027#if _LIBCPP_HAS_WIDE_CHARACTERS
40234028wchar_t numpunct<wchar_t>::do_decimal_point() const { return __decimal_point_; }
40244029#endif
40254030
40264031char numpunct< char >::do_thousands_sep() const { return __thousands_sep_; }
4027#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4032#if _LIBCPP_HAS_WIDE_CHARACTERS
40284033wchar_t numpunct<wchar_t>::do_thousands_sep() const { return __thousands_sep_; }
40294034#endif
40304035
40314036string numpunct< char >::do_grouping() const { return __grouping_; }
4032#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4037#if _LIBCPP_HAS_WIDE_CHARACTERS
40334038string numpunct<wchar_t>::do_grouping() const { return __grouping_; }
40344039#endif
40354040
40364041string numpunct< char >::do_truename() const { return "true"; }
4037#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4042#if _LIBCPP_HAS_WIDE_CHARACTERS
40384043wstring numpunct<wchar_t>::do_truename() const { return L"true"; }
40394044#endif
40404045
40414046string numpunct< char >::do_falsename() const { return "false"; }
4042#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4047#if _LIBCPP_HAS_WIDE_CHARACTERS
40434048wstring numpunct<wchar_t>::do_falsename() const { return L"false"; }
40444049#endif
40454050
......@@ -4062,7 +4067,7 @@ void numpunct_byname<char>::__init(const char* nm) {
40624067 string(nm))
40634068 .c_str());
40644069
4065 lconv* lc = __libcpp_localeconv_l(loc.get());
4070 __locale::__lconv_t* lc = __locale::__localeconv(loc.get());
40664071 if (!checked_string_to_char_convert(__decimal_point_, lc->decimal_point, loc.get()))
40674072 __decimal_point_ = base::do_decimal_point();
40684073 if (!checked_string_to_char_convert(__thousands_sep_, lc->thousands_sep, loc.get()))
......@@ -4074,7 +4079,7 @@ void numpunct_byname<char>::__init(const char* nm) {
40744079
40754080// numpunct_byname<wchar_t>
40764081
4077#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4082#if _LIBCPP_HAS_WIDE_CHARACTERS
40784083numpunct_byname<wchar_t>::numpunct_byname(const char* nm, size_t refs) : numpunct<wchar_t>(refs) { __init(nm); }
40794084
40804085numpunct_byname<wchar_t>::numpunct_byname(const string& nm, size_t refs) : numpunct<wchar_t>(refs) {
......@@ -4093,14 +4098,14 @@ void numpunct_byname<wchar_t>::__init(const char* nm) {
40934098 string(nm))
40944099 .c_str());
40954100
4096 lconv* lc = __libcpp_localeconv_l(loc.get());
4101 __locale::__lconv_t* lc = __locale::__localeconv(loc.get());
40974102 checked_string_to_wchar_convert(__decimal_point_, lc->decimal_point, loc.get());
40984103 checked_string_to_wchar_convert(__thousands_sep_, lc->thousands_sep, loc.get());
40994104 __grouping_ = lc->grouping;
41004105 // localization for truename and falsename is not available
41014106 }
41024107}
4103#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
4108#endif // _LIBCPP_HAS_WIDE_CHARACTERS
41044109
41054110// num_get helpers
41064111
......@@ -4240,7 +4245,7 @@ static string* init_weeks() {
42404245 return weeks;
42414246}
42424247
4243#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4248#if _LIBCPP_HAS_WIDE_CHARACTERS
42444249static wstring* init_wweeks() {
42454250 static wstring weeks[14];
42464251 weeks[0] = L"Sunday";
......@@ -4267,7 +4272,7 @@ const string* __time_get_c_storage<char>::__weeks() const {
42674272 return weeks;
42684273}
42694274
4270#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4275#if _LIBCPP_HAS_WIDE_CHARACTERS
42714276template <>
42724277const wstring* __time_get_c_storage<wchar_t>::__weeks() const {
42734278 static const wstring* weeks = init_wweeks();
......@@ -4304,7 +4309,7 @@ static string* init_months() {
43044309 return months;
43054310}
43064311
4307#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4312#if _LIBCPP_HAS_WIDE_CHARACTERS
43084313static wstring* init_wmonths() {
43094314 static wstring months[24];
43104315 months[0] = L"January";
......@@ -4341,7 +4346,7 @@ const string* __time_get_c_storage<char>::__months() const {
43414346 return months;
43424347}
43434348
4344#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4349#if _LIBCPP_HAS_WIDE_CHARACTERS
43454350template <>
43464351const wstring* __time_get_c_storage<wchar_t>::__months() const {
43474352 static const wstring* months = init_wmonths();
......@@ -4356,7 +4361,7 @@ static string* init_am_pm() {
43564361 return am_pm;
43574362}
43584363
4359#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4364#if _LIBCPP_HAS_WIDE_CHARACTERS
43604365static wstring* init_wam_pm() {
43614366 static wstring am_pm[2];
43624367 am_pm[0] = L"AM";
......@@ -4371,7 +4376,7 @@ const string* __time_get_c_storage<char>::__am_pm() const {
43714376 return am_pm;
43724377}
43734378
4374#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4379#if _LIBCPP_HAS_WIDE_CHARACTERS
43754380template <>
43764381const wstring* __time_get_c_storage<wchar_t>::__am_pm() const {
43774382 static const wstring* am_pm = init_wam_pm();
......@@ -4385,7 +4390,7 @@ const string& __time_get_c_storage<char>::__x() const {
43854390 return s;
43864391}
43874392
4388#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4393#if _LIBCPP_HAS_WIDE_CHARACTERS
43894394template <>
43904395const wstring& __time_get_c_storage<wchar_t>::__x() const {
43914396 static wstring s(L"%m/%d/%y");
......@@ -4399,7 +4404,7 @@ const string& __time_get_c_storage<char>::__X() const {
43994404 return s;
44004405}
44014406
4402#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4407#if _LIBCPP_HAS_WIDE_CHARACTERS
44034408template <>
44044409const wstring& __time_get_c_storage<wchar_t>::__X() const {
44054410 static wstring s(L"%H:%M:%S");
......@@ -4413,7 +4418,7 @@ const string& __time_get_c_storage<char>::__c() const {
44134418 return s;
44144419}
44154420
4416#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4421#if _LIBCPP_HAS_WIDE_CHARACTERS
44174422template <>
44184423const wstring& __time_get_c_storage<wchar_t>::__c() const {
44194424 static wstring s(L"%a %b %d %H:%M:%S %Y");
......@@ -4427,7 +4432,7 @@ const string& __time_get_c_storage<char>::__r() const {
44274432 return s;
44284433}
44294434
4430#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4435#if _LIBCPP_HAS_WIDE_CHARACTERS
44314436template <>
44324437const wstring& __time_get_c_storage<wchar_t>::__r() const {
44334438 static wstring s(L"%I:%M:%S %p");
......@@ -4437,17 +4442,17 @@ const wstring& __time_get_c_storage<wchar_t>::__r() const {
44374442
44384443// time_get_byname
44394444
4440__time_get::__time_get(const char* nm) : __loc_(newlocale(LC_ALL_MASK, nm, 0)) {
4445__time_get::__time_get(const char* nm) : __loc_(__locale::__newlocale(_LIBCPP_ALL_MASK, nm, 0)) {
44414446 if (__loc_ == 0)
44424447 __throw_runtime_error(("time_get_byname failed to construct for " + string(nm)).c_str());
44434448}
44444449
4445__time_get::__time_get(const string& nm) : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0)) {
4450__time_get::__time_get(const string& nm) : __loc_(__locale::__newlocale(_LIBCPP_ALL_MASK, nm.c_str(), 0)) {
44464451 if (__loc_ == 0)
44474452 __throw_runtime_error(("time_get_byname failed to construct for " + nm).c_str());
44484453}
44494454
4450__time_get::~__time_get() { freelocale(__loc_); }
4455__time_get::~__time_get() { __locale::__freelocale(__loc_); }
44514456
44524457_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
44534458
......@@ -4467,7 +4472,7 @@ string __time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct) {
44674472 char f[3] = {0};
44684473 f[0] = '%';
44694474 f[1] = fmt;
4470 size_t n = strftime_l(buf, countof(buf), f, &t, __loc_);
4475 size_t n = __locale::__strftime(buf, countof(buf), f, &t, __loc_);
44714476 char* bb = buf;
44724477 char* be = buf + n;
44734478 string result;
......@@ -4581,7 +4586,7 @@ string __time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct) {
45814586
45824587_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-braces")
45834588
4584#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4589#if _LIBCPP_HAS_WIDE_CHARACTERS
45854590template <>
45864591wstring __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct) {
45874592 tm t = {0};
......@@ -4598,12 +4603,12 @@ wstring __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& c
45984603 char f[3] = {0};
45994604 f[0] = '%';
46004605 f[1] = fmt;
4601 strftime_l(buf, countof(buf), f, &t, __loc_);
4606 __locale::__strftime(buf, countof(buf), f, &t, __loc_);
46024607 wchar_t wbuf[100];
46034608 wchar_t* wbb = wbuf;
46044609 mbstate_t mb = {0};
46054610 const char* bb = buf;
4606 size_t j = __libcpp_mbsrtowcs_l(wbb, &bb, countof(wbuf), &mb, __loc_);
4611 size_t j = __locale::__mbsrtowcs(wbb, &bb, countof(wbuf), &mb, __loc_);
46074612 if (j == size_t(-1))
46084613 __throw_runtime_error("locale not supported");
46094614 wchar_t* wbe = wbb + j;
......@@ -4715,7 +4720,7 @@ wstring __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& c
47154720 }
47164721 return result;
47174722}
4718#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
4723#endif // _LIBCPP_HAS_WIDE_CHARACTERS
47194724
47204725template <>
47214726void __time_get_storage<char>::init(const ctype<char>& ct) {
......@@ -4724,25 +4729,25 @@ void __time_get_storage<char>::init(const ctype<char>& ct) {
47244729 // __weeks_
47254730 for (int i = 0; i < 7; ++i) {
47264731 t.tm_wday = i;
4727 strftime_l(buf, countof(buf), "%A", &t, __loc_);
4732 __locale::__strftime(buf, countof(buf), "%A", &t, __loc_);
47284733 __weeks_[i] = buf;
4729 strftime_l(buf, countof(buf), "%a", &t, __loc_);
4734 __locale::__strftime(buf, countof(buf), "%a", &t, __loc_);
47304735 __weeks_[i + 7] = buf;
47314736 }
47324737 // __months_
47334738 for (int i = 0; i < 12; ++i) {
47344739 t.tm_mon = i;
4735 strftime_l(buf, countof(buf), "%B", &t, __loc_);
4740 __locale::__strftime(buf, countof(buf), "%B", &t, __loc_);
47364741 __months_[i] = buf;
4737 strftime_l(buf, countof(buf), "%b", &t, __loc_);
4742 __locale::__strftime(buf, countof(buf), "%b", &t, __loc_);
47384743 __months_[i + 12] = buf;
47394744 }
47404745 // __am_pm_
47414746 t.tm_hour = 1;
4742 strftime_l(buf, countof(buf), "%p", &t, __loc_);
4747 __locale::__strftime(buf, countof(buf), "%p", &t, __loc_);
47434748 __am_pm_[0] = buf;
47444749 t.tm_hour = 13;
4745 strftime_l(buf, countof(buf), "%p", &t, __loc_);
4750 __locale::__strftime(buf, countof(buf), "%p", &t, __loc_);
47464751 __am_pm_[1] = buf;
47474752 __c_ = __analyze('c', ct);
47484753 __r_ = __analyze('r', ct);
......@@ -4750,7 +4755,7 @@ void __time_get_storage<char>::init(const ctype<char>& ct) {
47504755 __X_ = __analyze('X', ct);
47514756}
47524757
4753#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4758#if _LIBCPP_HAS_WIDE_CHARACTERS
47544759template <>
47554760void __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) {
47564761 tm t = {0};
......@@ -4761,18 +4766,18 @@ void __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) {
47614766 // __weeks_
47624767 for (int i = 0; i < 7; ++i) {
47634768 t.tm_wday = i;
4764 strftime_l(buf, countof(buf), "%A", &t, __loc_);
4769 __locale::__strftime(buf, countof(buf), "%A", &t, __loc_);
47654770 mb = mbstate_t();
47664771 const char* bb = buf;
4767 size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
4772 size_t j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);
47684773 if (j == size_t(-1) || j == 0)
47694774 __throw_runtime_error("locale not supported");
47704775 wbe = wbuf + j;
47714776 __weeks_[i].assign(wbuf, wbe);
4772 strftime_l(buf, countof(buf), "%a", &t, __loc_);
4777 __locale::__strftime(buf, countof(buf), "%a", &t, __loc_);
47734778 mb = mbstate_t();
47744779 bb = buf;
4775 j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
4780 j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);
47764781 if (j == size_t(-1) || j == 0)
47774782 __throw_runtime_error("locale not supported");
47784783 wbe = wbuf + j;
......@@ -4781,18 +4786,18 @@ void __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) {
47814786 // __months_
47824787 for (int i = 0; i < 12; ++i) {
47834788 t.tm_mon = i;
4784 strftime_l(buf, countof(buf), "%B", &t, __loc_);
4789 __locale::__strftime(buf, countof(buf), "%B", &t, __loc_);
47854790 mb = mbstate_t();
47864791 const char* bb = buf;
4787 size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
4792 size_t j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);
47884793 if (j == size_t(-1) || j == 0)
47894794 __throw_runtime_error("locale not supported");
47904795 wbe = wbuf + j;
47914796 __months_[i].assign(wbuf, wbe);
4792 strftime_l(buf, countof(buf), "%b", &t, __loc_);
4797 __locale::__strftime(buf, countof(buf), "%b", &t, __loc_);
47934798 mb = mbstate_t();
47944799 bb = buf;
4795 j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
4800 j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);
47964801 if (j == size_t(-1) || j == 0)
47974802 __throw_runtime_error("locale not supported");
47984803 wbe = wbuf + j;
......@@ -4800,19 +4805,19 @@ void __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) {
48004805 }
48014806 // __am_pm_
48024807 t.tm_hour = 1;
4803 strftime_l(buf, countof(buf), "%p", &t, __loc_);
4808 __locale::__strftime(buf, countof(buf), "%p", &t, __loc_);
48044809 mb = mbstate_t();
48054810 const char* bb = buf;
4806 size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
4811 size_t j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);
48074812 if (j == size_t(-1))
48084813 __throw_runtime_error("locale not supported");
48094814 wbe = wbuf + j;
48104815 __am_pm_[0].assign(wbuf, wbe);
48114816 t.tm_hour = 13;
4812 strftime_l(buf, countof(buf), "%p", &t, __loc_);
4817 __locale::__strftime(buf, countof(buf), "%p", &t, __loc_);
48134818 mb = mbstate_t();
48144819 bb = buf;
4815 j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
4820 j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);
48164821 if (j == size_t(-1))
48174822 __throw_runtime_error("locale not supported");
48184823 wbe = wbuf + j;
......@@ -4822,7 +4827,7 @@ void __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) {
48224827 __x_ = __analyze('x', ct);
48234828 __X_ = __analyze('X', ct);
48244829}
4825#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
4830#endif // _LIBCPP_HAS_WIDE_CHARACTERS
48264831
48274832template <class CharT>
48284833struct _LIBCPP_HIDDEN __time_get_temp : public ctype_byname<CharT> {
......@@ -4842,7 +4847,7 @@ __time_get_storage<char>::__time_get_storage(const string& __nm) : __time_get(__
48424847 init(ct);
48434848}
48444849
4845#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4850#if _LIBCPP_HAS_WIDE_CHARACTERS
48464851template <>
48474852__time_get_storage<wchar_t>::__time_get_storage(const char* __nm) : __time_get(__nm) {
48484853 const __time_get_temp<wchar_t> ct(__nm);
......@@ -4854,7 +4859,7 @@ __time_get_storage<wchar_t>::__time_get_storage(const string& __nm) : __time_get
48544859 const __time_get_temp<wchar_t> ct(__nm);
48554860 init(ct);
48564861}
4857#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
4862#endif // _LIBCPP_HAS_WIDE_CHARACTERS
48584863
48594864template <>
48604865time_base::dateorder __time_get_storage<char>::__do_date_order() const {
......@@ -4937,7 +4942,7 @@ time_base::dateorder __time_get_storage<char>::__do_date_order() const {
49374942 return time_base::no_order;
49384943}
49394944
4940#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4945#if _LIBCPP_HAS_WIDE_CHARACTERS
49414946template <>
49424947time_base::dateorder __time_get_storage<wchar_t>::__do_date_order() const {
49434948 unsigned i;
......@@ -5018,46 +5023,46 @@ time_base::dateorder __time_get_storage<wchar_t>::__do_date_order() const {
50185023 }
50195024 return time_base::no_order;
50205025}
5021#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
5026#endif // _LIBCPP_HAS_WIDE_CHARACTERS
50225027
50235028// time_put
50245029
5025__time_put::__time_put(const char* nm) : __loc_(newlocale(LC_ALL_MASK, nm, 0)) {
5030__time_put::__time_put(const char* nm) : __loc_(__locale::__newlocale(_LIBCPP_ALL_MASK, nm, 0)) {
50265031 if (__loc_ == 0)
50275032 __throw_runtime_error(("time_put_byname failed to construct for " + string(nm)).c_str());
50285033}
50295034
5030__time_put::__time_put(const string& nm) : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0)) {
5035__time_put::__time_put(const string& nm) : __loc_(__locale::__newlocale(_LIBCPP_ALL_MASK, nm.c_str(), 0)) {
50315036 if (__loc_ == 0)
50325037 __throw_runtime_error(("time_put_byname failed to construct for " + nm).c_str());
50335038}
50345039
50355040__time_put::~__time_put() {
50365041 if (__loc_ != _LIBCPP_GET_C_LOCALE)
5037 freelocale(__loc_);
5042 __locale::__freelocale(__loc_);
50385043}
50395044
50405045void __time_put::__do_put(char* __nb, char*& __ne, const tm* __tm, char __fmt, char __mod) const {
50415046 char fmt[] = {'%', __fmt, __mod, 0};
50425047 if (__mod != 0)
50435048 swap(fmt[1], fmt[2]);
5044 size_t n = strftime_l(__nb, countof(__nb, __ne), fmt, __tm, __loc_);
5049 size_t n = __locale::__strftime(__nb, countof(__nb, __ne), fmt, __tm, __loc_);
50455050 __ne = __nb + n;
50465051}
50475052
5048#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
5053#if _LIBCPP_HAS_WIDE_CHARACTERS
50495054void __time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm, char __fmt, char __mod) const {
50505055 char __nar[100];
50515056 char* __ne = __nar + 100;
50525057 __do_put(__nar, __ne, __tm, __fmt, __mod);
50535058 mbstate_t mb = {0};
50545059 const char* __nb = __nar;
5055 size_t j = __libcpp_mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_);
5060 size_t j = __locale::__mbsrtowcs(__wb, &__nb, countof(__wb, __we), &mb, __loc_);
50565061 if (j == size_t(-1))
50575062 __throw_runtime_error("locale not supported");
50585063 __we = __wb + j;
50595064}
5060#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
5065#endif // _LIBCPP_HAS_WIDE_CHARACTERS
50615066
50625067// moneypunct_byname
50635068
......@@ -5428,7 +5433,7 @@ void moneypunct_byname<char, false>::init(const char* nm) {
54285433 if (!loc)
54295434 __throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());
54305435
5431 lconv* lc = __libcpp_localeconv_l(loc.get());
5436 __locale::__lconv_t* lc = __locale::__localeconv(loc.get());
54325437 if (!checked_string_to_char_convert(__decimal_point_, lc->mon_decimal_point, loc.get()))
54335438 __decimal_point_ = base::do_decimal_point();
54345439 if (!checked_string_to_char_convert(__thousands_sep_, lc->mon_thousands_sep, loc.get()))
......@@ -5463,7 +5468,7 @@ void moneypunct_byname<char, true>::init(const char* nm) {
54635468 if (!loc)
54645469 __throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());
54655470
5466 lconv* lc = __libcpp_localeconv_l(loc.get());
5471 __locale::__lconv_t* lc = __locale::__localeconv(loc.get());
54675472 if (!checked_string_to_char_convert(__decimal_point_, lc->mon_decimal_point, loc.get()))
54685473 __decimal_point_ = base::do_decimal_point();
54695474 if (!checked_string_to_char_convert(__thousands_sep_, lc->mon_thousands_sep, loc.get()))
......@@ -5511,14 +5516,14 @@ void moneypunct_byname<char, true>::init(const char* nm) {
55115516#endif // !_LIBCPP_MSVCRT
55125517}
55135518
5514#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
5519#if _LIBCPP_HAS_WIDE_CHARACTERS
55155520template <>
55165521void moneypunct_byname<wchar_t, false>::init(const char* nm) {
55175522 typedef moneypunct<wchar_t, false> base;
55185523 __libcpp_unique_locale loc(nm);
55195524 if (!loc)
55205525 __throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());
5521 lconv* lc = __libcpp_localeconv_l(loc.get());
5526 __locale::__lconv_t* lc = __locale::__localeconv(loc.get());
55225527 if (!checked_string_to_wchar_convert(__decimal_point_, lc->mon_decimal_point, loc.get()))
55235528 __decimal_point_ = base::do_decimal_point();
55245529 if (!checked_string_to_wchar_convert(__thousands_sep_, lc->mon_thousands_sep, loc.get()))
......@@ -5527,7 +5532,7 @@ void moneypunct_byname<wchar_t, false>::init(const char* nm) {
55275532 wchar_t wbuf[100];
55285533 mbstate_t mb = {0};
55295534 const char* bb = lc->currency_symbol;
5530 size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5535 size_t j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());
55315536 if (j == size_t(-1))
55325537 __throw_runtime_error("locale not supported");
55335538 wchar_t* wbe = wbuf + j;
......@@ -5541,7 +5546,7 @@ void moneypunct_byname<wchar_t, false>::init(const char* nm) {
55415546 else {
55425547 mb = mbstate_t();
55435548 bb = lc->positive_sign;
5544 j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5549 j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());
55455550 if (j == size_t(-1))
55465551 __throw_runtime_error("locale not supported");
55475552 wbe = wbuf + j;
......@@ -5552,7 +5557,7 @@ void moneypunct_byname<wchar_t, false>::init(const char* nm) {
55525557 else {
55535558 mb = mbstate_t();
55545559 bb = lc->negative_sign;
5555 j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5560 j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());
55565561 if (j == size_t(-1))
55575562 __throw_runtime_error("locale not supported");
55585563 wbe = wbuf + j;
......@@ -5573,7 +5578,7 @@ void moneypunct_byname<wchar_t, true>::init(const char* nm) {
55735578 if (!loc)
55745579 __throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());
55755580
5576 lconv* lc = __libcpp_localeconv_l(loc.get());
5581 __locale::__lconv_t* lc = __locale::__localeconv(loc.get());
55775582 if (!checked_string_to_wchar_convert(__decimal_point_, lc->mon_decimal_point, loc.get()))
55785583 __decimal_point_ = base::do_decimal_point();
55795584 if (!checked_string_to_wchar_convert(__thousands_sep_, lc->mon_thousands_sep, loc.get()))
......@@ -5582,7 +5587,7 @@ void moneypunct_byname<wchar_t, true>::init(const char* nm) {
55825587 wchar_t wbuf[100];
55835588 mbstate_t mb = {0};
55845589 const char* bb = lc->int_curr_symbol;
5585 size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5590 size_t j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());
55865591 if (j == size_t(-1))
55875592 __throw_runtime_error("locale not supported");
55885593 wchar_t* wbe = wbuf + j;
......@@ -5600,7 +5605,7 @@ void moneypunct_byname<wchar_t, true>::init(const char* nm) {
56005605 else {
56015606 mb = mbstate_t();
56025607 bb = lc->positive_sign;
5603 j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5608 j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());
56045609 if (j == size_t(-1))
56055610 __throw_runtime_error("locale not supported");
56065611 wbe = wbuf + j;
......@@ -5615,7 +5620,7 @@ void moneypunct_byname<wchar_t, true>::init(const char* nm) {
56155620 else {
56165621 mb = mbstate_t();
56175622 bb = lc->negative_sign;
5618 j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5623 j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());
56195624 if (j == size_t(-1))
56205625 __throw_runtime_error("locale not supported");
56215626 wbe = wbuf + j;
......@@ -5641,7 +5646,7 @@ void moneypunct_byname<wchar_t, true>::init(const char* nm) {
56415646 __neg_format_, __curr_symbol_, true, lc->int_n_cs_precedes, lc->int_n_sep_by_space, lc->int_n_sign_posn, L' ');
56425647# endif // !_LIBCPP_MSVCRT
56435648}
5644#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
5649#endif // _LIBCPP_HAS_WIDE_CHARACTERS
56455650
56465651void __do_nothing(void*) {}
56475652
......@@ -5707,7 +5712,7 @@ template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_
57075712 codecvt_byname<char16_t, char, mbstate_t>;
57085713template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
57095714 codecvt_byname<char32_t, char, mbstate_t>;
5710#ifndef _LIBCPP_HAS_NO_CHAR8_T
5715#if _LIBCPP_HAS_CHAR8_T
57115716template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char16_t, char8_t, mbstate_t>;
57125717template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char32_t, char8_t, mbstate_t>;
57135718#endif
lib/libcxx/src/memory.cpp+3-3
......@@ -13,7 +13,7 @@
1313
1414#include <memory>
1515
16#ifndef _LIBCPP_HAS_NO_THREADS
16#if _LIBCPP_HAS_THREADS
1717# include <mutex>
1818# include <thread>
1919# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
......@@ -96,7 +96,7 @@ __shared_weak_count* __shared_weak_count::lock() noexcept {
9696
9797const void* __shared_weak_count::__get_deleter(const type_info&) const noexcept { return nullptr; }
9898
99#if !defined(_LIBCPP_HAS_NO_THREADS)
99#if _LIBCPP_HAS_THREADS
100100
101101static constexpr std::size_t __sp_mut_count = 32;
102102static constinit __libcpp_mutex_t mut_back[__sp_mut_count] = {
......@@ -128,7 +128,7 @@ __sp_mut& __get_sp_mut(const void* p) {
128128 return muts[hash<const void*>()(p) & (__sp_mut_count - 1)];
129129}
130130
131#endif // !defined(_LIBCPP_HAS_NO_THREADS)
131#endif // _LIBCPP_HAS_THREADS
132132
133133void* align(size_t alignment, size_t size, void*& ptr, size_t& space) {
134134 void* r = nullptr;
lib/libcxx/src/memory_resource.cpp+32-30
......@@ -6,12 +6,13 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include <cstddef>
910#include <memory>
1011#include <memory_resource>
1112
12#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
13#if _LIBCPP_HAS_ATOMIC_HEADER
1314# include <atomic>
14#elif !defined(_LIBCPP_HAS_NO_THREADS)
15#elif _LIBCPP_HAS_THREADS
1516# include <mutex>
1617# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
1718# pragma comment(lib, "pthread")
......@@ -28,7 +29,7 @@ memory_resource::~memory_resource() = default;
2829
2930// new_delete_resource()
3031
31#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
32#if !_LIBCPP_HAS_ALIGNED_ALLOCATION
3233static bool is_aligned_to(void* ptr, size_t align) {
3334 void* p2 = ptr;
3435 size_t space = 1;
......@@ -39,21 +40,23 @@ static bool is_aligned_to(void* ptr, size_t align) {
3940
4041class _LIBCPP_EXPORTED_FROM_ABI __new_delete_memory_resource_imp : public memory_resource {
4142 void* do_allocate(size_t bytes, size_t align) override {
42#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
43 return std::__libcpp_allocate(bytes, align);
43#if _LIBCPP_HAS_ALIGNED_ALLOCATION
44 return std::__libcpp_allocate<std::byte>(__element_count(bytes), align);
4445#else
4546 if (bytes == 0)
4647 bytes = 1;
47 void* result = std::__libcpp_allocate(bytes, align);
48 std::byte* result = std::__libcpp_allocate<std::byte>(__element_count(bytes), align);
4849 if (!is_aligned_to(result, align)) {
49 std::__libcpp_deallocate(result, bytes, align);
50 std::__libcpp_deallocate<std::byte>(result, __element_count(bytes), align);
5051 __throw_bad_alloc();
5152 }
5253 return result;
5354#endif
5455 }
5556
56 void do_deallocate(void* p, size_t bytes, size_t align) override { std::__libcpp_deallocate(p, bytes, align); }
57 void do_deallocate(void* p, size_t bytes, size_t align) override {
58 std::__libcpp_deallocate<std::byte>(static_cast<std::byte*>(p), __element_count(bytes), align);
59 }
5760
5861 bool do_is_equal(const memory_resource& other) const noexcept override { return &other == this; }
5962};
......@@ -82,7 +85,7 @@ union ResourceInitHelper {
8285// attribute with a value that's reserved for the implementation (we're the implementation).
8386#include "memory_resource_init_helper.h"
8487
85} // end namespace
88} // namespace
8689
8790memory_resource* new_delete_resource() noexcept { return &res_init.resources.new_delete_res; }
8891
......@@ -91,7 +94,7 @@ memory_resource* null_memory_resource() noexcept { return &res_init.resources.nu
9194// default_memory_resource()
9295
9396static memory_resource* __default_memory_resource(bool set = false, memory_resource* new_res = nullptr) noexcept {
94#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
97#if _LIBCPP_HAS_ATOMIC_HEADER
9598 static constinit atomic<memory_resource*> __res{&res_init.resources.new_delete_res};
9699 if (set) {
97100 new_res = new_res ? new_res : new_delete_resource();
......@@ -100,7 +103,7 @@ static memory_resource* __default_memory_resource(bool set = false, memory_resou
100103 } else {
101104 return std::atomic_load_explicit(&__res, memory_order_acquire);
102105 }
103#elif !defined(_LIBCPP_HAS_NO_THREADS)
106#elif _LIBCPP_HAS_THREADS
104107 static constinit memory_resource* res = &res_init.resources.new_delete_res;
105108 static mutex res_lock;
106109 if (set) {
......@@ -412,6 +415,8 @@ bool synchronized_pool_resource::do_is_equal(const memory_resource& other) const
412415
413416// 23.12.6, mem.res.monotonic.buffer
414417
418constexpr size_t __default_growth_factor = 2;
419
415420static void* align_down(size_t align, size_t size, void*& ptr, size_t& space) {
416421 if (size > space)
417422 return nullptr;
......@@ -428,23 +433,20 @@ static void* align_down(size_t align, size_t size, void*& ptr, size_t& space) {
428433 return ptr;
429434}
430435
431void* monotonic_buffer_resource::__initial_descriptor::__try_allocate_from_chunk(size_t bytes, size_t align) {
432 if (!__cur_)
433 return nullptr;
434 void* new_ptr = static_cast<void*>(__cur_);
435 size_t new_capacity = (__cur_ - __start_);
436 void* aligned_ptr = align_down(align, bytes, new_ptr, new_capacity);
437 if (aligned_ptr != nullptr)
438 __cur_ = static_cast<char*>(new_ptr);
439 return aligned_ptr;
440}
441
442void* monotonic_buffer_resource::__chunk_footer::__try_allocate_from_chunk(size_t bytes, size_t align) {
443 void* new_ptr = static_cast<void*>(__cur_);
444 size_t new_capacity = (__cur_ - __start_);
436template <bool is_initial, typename Chunk>
437void* __try_allocate_from_chunk(Chunk& self, size_t bytes, size_t align) {
438 if constexpr (is_initial) {
439 // only for __initial_descriptor.
440 // if __initial_descriptor.__cur_ equals nullptr, means no available buffer given when ctor.
441 // here we just return nullptr, let the caller do the next handling.
442 if (!self.__cur_)
443 return nullptr;
444 }
445 void* new_ptr = static_cast<void*>(self.__cur_);
446 size_t new_capacity = (self.__cur_ - self.__start_);
445447 void* aligned_ptr = align_down(align, bytes, new_ptr, new_capacity);
446448 if (aligned_ptr != nullptr)
447 __cur_ = static_cast<char*>(new_ptr);
449 self.__cur_ = static_cast<char*>(new_ptr);
448450 return aligned_ptr;
449451}
450452
......@@ -461,10 +463,10 @@ void* monotonic_buffer_resource::do_allocate(size_t bytes, size_t align) {
461463 return roundup(newsize, footer_align) + footer_size;
462464 };
463465
464 if (void* result = __initial_.__try_allocate_from_chunk(bytes, align))
466 if (void* result = __try_allocate_from_chunk<true, __initial_descriptor>(__initial_, bytes, align))
465467 return result;
466468 if (__chunks_ != nullptr) {
467 if (void* result = __chunks_->__try_allocate_from_chunk(bytes, align))
469 if (void* result = __try_allocate_from_chunk<false, __chunk_footer>(*__chunks_, bytes, align))
468470 return result;
469471 }
470472
......@@ -477,7 +479,7 @@ void* monotonic_buffer_resource::do_allocate(size_t bytes, size_t align) {
477479 size_t previous_capacity = previous_allocation_size();
478480
479481 if (aligned_capacity <= previous_capacity) {
480 size_t newsize = 2 * (previous_capacity - footer_size);
482 size_t newsize = __default_growth_factor * (previous_capacity - footer_size);
481483 aligned_capacity = roundup(newsize, footer_align) + footer_size;
482484 }
483485
......@@ -490,7 +492,7 @@ void* monotonic_buffer_resource::do_allocate(size_t bytes, size_t align) {
490492 footer->__align_ = align;
491493 __chunks_ = footer;
492494
493 return __chunks_->__try_allocate_from_chunk(bytes, align);
495 return __try_allocate_from_chunk<false, __chunk_footer>(*__chunks_, bytes, align);
494496}
495497
496498} // namespace pmr
lib/libcxx/src/mutex_destructor.cpp+1-1
......@@ -19,7 +19,7 @@
1919#include <__config>
2020#include <__thread/support.h>
2121
22#if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION)
22#if _LIBCPP_ABI_VERSION == 1 || !_LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
2323# define NEEDS_MUTEX_DESTRUCTOR
2424#endif
2525
lib/libcxx/src/new.cpp+6-6
......@@ -51,7 +51,7 @@ _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void* operator new(std
5151}
5252
5353_LIBCPP_WEAK void* operator new(size_t size, const std::nothrow_t&) noexcept {
54# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
54# if !_LIBCPP_HAS_EXCEPTIONS
5555# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
5656 _LIBCPP_ASSERT_SHIM(
5757 !std::__is_function_overridden(static_cast<void* (*)(std::size_t)>(&operator new)),
......@@ -79,7 +79,7 @@ _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void* operator new[](s
7979}
8080
8181_LIBCPP_WEAK void* operator new[](size_t size, const std::nothrow_t&) noexcept {
82# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
82# if !_LIBCPP_HAS_EXCEPTIONS
8383# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
8484 _LIBCPP_ASSERT_SHIM(
8585 !std::__is_function_overridden(static_cast<void* (*)(std::size_t)>(&operator new[])),
......@@ -114,7 +114,7 @@ _LIBCPP_WEAK void operator delete[](void* ptr, const std::nothrow_t&) noexcept {
114114
115115_LIBCPP_WEAK void operator delete[](void* ptr, size_t) noexcept { ::operator delete[](ptr); }
116116
117# if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION)
117# if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
118118
119119static void* operator_new_aligned_impl(std::size_t size, std::align_val_t alignment) {
120120 if (size == 0)
......@@ -145,7 +145,7 @@ operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
145145}
146146
147147_LIBCPP_WEAK void* operator new(size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept {
148# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
148# if !_LIBCPP_HAS_EXCEPTIONS
149149# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
150150 _LIBCPP_ASSERT_SHIM(
151151 !std::__is_function_overridden(static_cast<void* (*)(std::size_t, std::align_val_t)>(&operator new)),
......@@ -174,7 +174,7 @@ operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
174174}
175175
176176_LIBCPP_WEAK void* operator new[](size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept {
177# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
177# if !_LIBCPP_HAS_EXCEPTIONS
178178# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
179179 _LIBCPP_ASSERT_SHIM(
180180 !std::__is_function_overridden(static_cast<void* (*)(std::size_t, std::align_val_t)>(&operator new[])),
......@@ -220,7 +220,7 @@ _LIBCPP_WEAK void operator delete[](void* ptr, size_t, std::align_val_t alignmen
220220 ::operator delete[](ptr, alignment);
221221}
222222
223# endif // !_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
223# endif // _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
224224// ------------------ END COPY ------------------
225225
226226#endif // !__GLIBCXX__ && !_LIBCPP_ABI_VCRUNTIME
lib/libcxx/src/new_helpers.cpp+1-1
......@@ -18,7 +18,7 @@ const nothrow_t nothrow{};
1818#ifndef LIBSTDCXX
1919
2020void __throw_bad_alloc() {
21# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
21# if _LIBCPP_HAS_EXCEPTIONS
2222 throw bad_alloc();
2323# else
2424 _LIBCPP_VERBOSE_ABORT("bad_alloc was thrown in -fno-exceptions mode");
lib/libcxx/src/optional.cpp+1-1
......@@ -17,7 +17,7 @@ const char* bad_optional_access::what() const noexcept { return "bad_optional_ac
1717
1818} // namespace std
1919
20#include <experimental/__config>
20#include <__config>
2121
2222// Preserve std::experimental::bad_optional_access for ABI compatibility
2323// Even though it no longer exists in a header file
lib/libcxx/src/ostream.cpp+4-4
......@@ -7,7 +7,7 @@
77//===----------------------------------------------------------------------===//
88
99#include <__config>
10#ifndef _LIBCPP_HAS_NO_FILESYSTEM
10#if _LIBCPP_HAS_FILESYSTEM
1111# include <fstream>
1212#endif
1313#include <ostream>
......@@ -24,16 +24,16 @@ _LIBCPP_EXPORTED_FROM_ABI FILE* __get_ostream_file(ostream& __os) {
2424 // Returning a nullptr means the stream is not considered a terminal and the
2525 // special terminal handling is not done. The terminal handling is mainly of
2626 // importance on Windows.
27#ifndef _LIBCPP_HAS_NO_RTTI
27#if _LIBCPP_HAS_RTTI
2828 auto* __rdbuf = __os.rdbuf();
29# ifndef _LIBCPP_HAS_NO_FILESYSTEM
29# if _LIBCPP_HAS_FILESYSTEM
3030 if (auto* __buffer = dynamic_cast<filebuf*>(__rdbuf))
3131 return __buffer->__file_;
3232# endif
3333
3434 if (auto* __buffer = dynamic_cast<__stdoutbuf<char>*>(__rdbuf))
3535 return __buffer->__file_;
36#endif // _LIBCPP_HAS_NO_RTTI
36#endif // _LIBCPP_HAS_RTTI
3737
3838 return nullptr;
3939}
lib/libcxx/src/print.cpp+3-3
......@@ -42,7 +42,7 @@ _LIBCPP_EXPORTED_FROM_ABI bool __is_windows_terminal(FILE* __stream) {
4242 return GetConsoleMode(reinterpret_cast<void*>(__handle), &__mode);
4343}
4444
45# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
45# if _LIBCPP_HAS_WIDE_CHARACTERS
4646_LIBCPP_EXPORTED_FROM_ABI void
4747__write_to_windows_console([[maybe_unused]] FILE* __stream, [[maybe_unused]] wstring_view __view) {
4848 // https://learn.microsoft.com/en-us/windows/console/writeconsole
......@@ -51,10 +51,10 @@ __write_to_windows_console([[maybe_unused]] FILE* __stream, [[maybe_unused]] wst
5151 __view.size(),
5252 nullptr,
5353 nullptr) == 0) {
54 __throw_system_error(filesystem::detail::make_windows_error(GetLastError()), "failed to write formatted output");
54 __throw_system_error(filesystem::detail::get_last_error(), "failed to write formatted output");
5555 }
5656}
57# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
57# endif // _LIBCPP_HAS_WIDE_CHARACTERS
5858
5959#elif __has_include(<unistd.h>) // !_LIBCPP_WIN32API
6060
lib/libcxx/src/random.cpp+1-1
......@@ -13,7 +13,7 @@
1313# define _CRT_RAND_S
1414#endif // defined(_LIBCPP_USING_WIN32_RANDOM)
1515
16#include <__system_error/system_error.h>
16#include <__system_error/throw_system_error.h>
1717#include <limits>
1818#include <random>
1919
lib/libcxx/src/random_shuffle.cpp+4-4
......@@ -9,7 +9,7 @@
99#include <algorithm>
1010#include <random>
1111
12#ifndef _LIBCPP_HAS_NO_THREADS
12#if _LIBCPP_HAS_THREADS
1313# include <mutex>
1414# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
1515# pragma comment(lib, "pthread")
......@@ -18,13 +18,13 @@
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
21#ifndef _LIBCPP_HAS_NO_THREADS
21#if _LIBCPP_HAS_THREADS
2222static constinit __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;
2323#endif
2424unsigned __rs_default::__c_ = 0;
2525
2626__rs_default::__rs_default() {
27#ifndef _LIBCPP_HAS_NO_THREADS
27#if _LIBCPP_HAS_THREADS
2828 __libcpp_mutex_lock(&__rs_mut);
2929#endif
3030 __c_ = 1;
......@@ -33,7 +33,7 @@ __rs_default::__rs_default() {
3333__rs_default::__rs_default(const __rs_default&) { ++__c_; }
3434
3535__rs_default::~__rs_default() {
36#ifndef _LIBCPP_HAS_NO_THREADS
36#if _LIBCPP_HAS_THREADS
3737 if (--__c_ == 0)
3838 __libcpp_mutex_unlock(&__rs_mut);
3939#else
lib/libcxx/src/regex.cpp+2-2
......@@ -323,8 +323,8 @@ const classnames ClassNames[] = {
323323 {"xdigit", ctype_base::xdigit}};
324324
325325struct use_strcmp {
326 bool operator()(const collationnames& x, const char* y) { return strcmp(x.elem_, y) < 0; }
327 bool operator()(const classnames& x, const char* y) { return strcmp(x.elem_, y) < 0; }
326 bool operator()(const collationnames& x, const char* y) const { return strcmp(x.elem_, y) < 0; }
327 bool operator()(const classnames& x, const char* y) const { return strcmp(x.elem_, y) < 0; }
328328};
329329
330330} // namespace
lib/libcxx/src/ryu/d2s.cpp+1-1
......@@ -478,7 +478,7 @@ struct __floating_decimal_64 {
478478 36893488u, 7378697u, 1475739u, 295147u, 59029u, 11805u, 2361u, 472u, 94u, 18u, 3u };
479479
480480 unsigned long _Trailing_zero_bits;
481#ifdef _LIBCPP_HAS_BITSCAN64
481#if _LIBCPP_HAS_BITSCAN64
482482 (void) _BitScanForward64(&_Trailing_zero_bits, __v.__mantissa); // __v.__mantissa is guaranteed nonzero
483483#else // ^^^ 64-bit ^^^ / vvv 32-bit vvv
484484 const uint32_t _Low_mantissa = static_cast<uint32_t>(__v.__mantissa);
lib/libcxx/src/shared_mutex.cpp+11-5
......@@ -38,8 +38,10 @@ bool __shared_mutex_base::try_lock() {
3838}
3939
4040void __shared_mutex_base::unlock() {
41 lock_guard<mutex> _(__mut_);
42 __state_ = 0;
41 {
42 lock_guard<mutex> _(__mut_);
43 __state_ = 0;
44 }
4345 __gate1_.notify_all();
4446}
4547
......@@ -67,16 +69,20 @@ bool __shared_mutex_base::try_lock_shared() {
6769}
6870
6971void __shared_mutex_base::unlock_shared() {
70 lock_guard<mutex> _(__mut_);
72 unique_lock<mutex> lk(__mut_);
7173 unsigned num_readers = (__state_ & __n_readers_) - 1;
7274 __state_ &= ~__n_readers_;
7375 __state_ |= num_readers;
7476 if (__state_ & __write_entered_) {
75 if (num_readers == 0)
77 if (num_readers == 0) {
78 lk.unlock();
7679 __gate2_.notify_one();
80 }
7781 } else {
78 if (num_readers == __n_readers_ - 1)
82 if (num_readers == __n_readers_ - 1) {
83 lk.unlock();
7984 __gate1_.notify_one();
85 }
8086 }
8187}
8288
lib/libcxx/src/std_stream.h+3-3
......@@ -106,7 +106,7 @@ inline bool __do_getc(FILE* __fp, char* __pbuf) {
106106 *__pbuf = static_cast<char>(__c);
107107 return true;
108108}
109#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
109#if _LIBCPP_HAS_WIDE_CHARACTERS
110110inline bool __do_getc(FILE* __fp, wchar_t* __pbuf) {
111111 wint_t __c = getwc(__fp);
112112 if (__c == WEOF)
......@@ -121,7 +121,7 @@ inline bool __do_ungetc(int __c, FILE* __fp, char __dummy) {
121121 return false;
122122 return true;
123123}
124#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
124#if _LIBCPP_HAS_WIDE_CHARACTERS
125125inline bool __do_ungetc(std::wint_t __c, FILE* __fp, wchar_t __dummy) {
126126 if (ungetwc(__c, __fp) == WEOF)
127127 return false;
......@@ -293,7 +293,7 @@ inline bool __do_fputc(char __c, FILE* __fp) {
293293 return false;
294294 return true;
295295}
296#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
296#if _LIBCPP_HAS_WIDE_CHARACTERS
297297inline bool __do_fputc(wchar_t __c, FILE* __fp) {
298298 // fputwc works regardless of wide/narrow mode of stdout, while
299299 // fwrite of wchar_t only works if the stream actually has been set
lib/libcxx/src/stdexcept.cpp+2-2
......@@ -19,8 +19,8 @@
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
22_LIBCPP_NORETURN void __throw_runtime_error(const char* msg) {
23#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
22void __throw_runtime_error(const char* msg) {
23#if _LIBCPP_HAS_EXCEPTIONS
2424 throw runtime_error(msg);
2525#else
2626 _LIBCPP_VERBOSE_ABORT("runtime_error was thrown in -fno-exceptions mode with message \"%s\"", msg);
lib/libcxx/src/string.cpp+15-15
......@@ -14,7 +14,7 @@
1414#include <stdexcept>
1515#include <string>
1616
17#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
17#if _LIBCPP_HAS_WIDE_CHARACTERS
1818# include <cwchar>
1919#endif
2020
......@@ -28,8 +28,8 @@ struct __basic_string_common;
2828// The struct isn't declared anymore in the headers. It's only here for ABI compatibility.
2929template <>
3030struct __basic_string_common<true> {
31 _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
32 _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
31 [[noreturn]] _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
32 [[noreturn]] _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
3333};
3434
3535void __basic_string_common<true>::__throw_length_error() const { std::__throw_length_error("basic_string"); }
......@@ -40,12 +40,12 @@ void __basic_string_common<true>::__throw_out_of_range() const { std::__throw_ou
4040#define _LIBCPP_EXTERN_TEMPLATE_DEFINE(...) template __VA_ARGS__;
4141#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
4242_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
43# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
43# if _LIBCPP_HAS_WIDE_CHARACTERS
4444_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
4545# endif
4646#else
4747_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
48# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
48# if _LIBCPP_HAS_WIDE_CHARACTERS
4949_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
5050# endif
5151#endif
......@@ -115,7 +115,7 @@ inline unsigned long long as_integer(const string& func, const string& s, size_t
115115 return as_integer_helper<unsigned long long>(func, s, idx, base, strtoull);
116116}
117117
118#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
118#if _LIBCPP_HAS_WIDE_CHARACTERS
119119// wstring
120120template <>
121121inline int as_integer(const string& func, const wstring& s, size_t* idx, int base) {
......@@ -145,7 +145,7 @@ template <>
145145inline unsigned long long as_integer(const string& func, const wstring& s, size_t* idx, int base) {
146146 return as_integer_helper<unsigned long long>(func, s, idx, base, wcstoull);
147147}
148#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
148#endif // _LIBCPP_HAS_WIDE_CHARACTERS
149149
150150// as_float
151151
......@@ -184,7 +184,7 @@ inline long double as_float(const string& func, const string& s, size_t* idx) {
184184 return as_float_helper<long double>(func, s, idx, strtold);
185185}
186186
187#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
187#if _LIBCPP_HAS_WIDE_CHARACTERS
188188template <>
189189inline float as_float(const string& func, const wstring& s, size_t* idx) {
190190 return as_float_helper<float>(func, s, idx, wcstof);
......@@ -199,7 +199,7 @@ template <>
199199inline long double as_float(const string& func, const wstring& s, size_t* idx) {
200200 return as_float_helper<long double>(func, s, idx, wcstold);
201201}
202#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
202#endif // _LIBCPP_HAS_WIDE_CHARACTERS
203203
204204} // unnamed namespace
205205
......@@ -223,7 +223,7 @@ double stod(const string& str, size_t* idx) { return as_float<double>("stod", st
223223
224224long double stold(const string& str, size_t* idx) { return as_float<long double>("stold", str, idx); }
225225
226#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
226#if _LIBCPP_HAS_WIDE_CHARACTERS
227227int stoi(const wstring& str, size_t* idx, int base) { return as_integer<int>("stoi", str, idx, base); }
228228
229229long stol(const wstring& str, size_t* idx, int base) { return as_integer<long>("stol", str, idx, base); }
......@@ -243,7 +243,7 @@ float stof(const wstring& str, size_t* idx) { return as_float<float>("stof", str
243243double stod(const wstring& str, size_t* idx) { return as_float<double>("stod", str, idx); }
244244
245245long double stold(const wstring& str, size_t* idx) { return as_float<long double>("stold", str, idx); }
246#endif // !_LIBCPP_HAS_NO_WIDE_CHARACTERS
246#endif // _LIBCPP_HAS_WIDE_CHARACTERS
247247
248248// to_string
249249
......@@ -283,7 +283,7 @@ struct initial_string<string> {
283283 }
284284};
285285
286#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
286#if _LIBCPP_HAS_WIDE_CHARACTERS
287287template <>
288288struct initial_string<wstring> {
289289 wstring operator()() const {
......@@ -302,7 +302,7 @@ inline wide_printf get_swprintf() {
302302 return static_cast<int(__cdecl*)(wchar_t* __restrict, size_t, const wchar_t* __restrict, ...)>(_snwprintf);
303303# endif
304304}
305#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
305#endif // _LIBCPP_HAS_WIDE_CHARACTERS
306306
307307template <typename S, typename V>
308308S i_to_string(V v) {
......@@ -325,7 +325,7 @@ string to_string(unsigned val) { return i_to_string< string>(val); }
325325string to_string(unsigned long val) { return i_to_string< string>(val); }
326326string to_string(unsigned long long val) { return i_to_string< string>(val); }
327327
328#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
328#if _LIBCPP_HAS_WIDE_CHARACTERS
329329wstring to_wstring(int val) { return i_to_string<wstring>(val); }
330330wstring to_wstring(long val) { return i_to_string<wstring>(val); }
331331wstring to_wstring(long long val) { return i_to_string<wstring>(val); }
......@@ -338,7 +338,7 @@ string to_string(float val) { return as_string(snprintf, initial_string< string>
338338string to_string(double val) { return as_string(snprintf, initial_string< string>()(), "%f", val); }
339339string to_string(long double val) { return as_string(snprintf, initial_string< string>()(), "%Lf", val); }
340340
341#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
341#if _LIBCPP_HAS_WIDE_CHARACTERS
342342wstring to_wstring(float val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); }
343343wstring to_wstring(double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); }
344344wstring to_wstring(long double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%Lf", val); }
lib/libcxx/src/support/ibm/mbsnrtowcs.cpp+2-2
......@@ -48,7 +48,7 @@ _LIBCPP_EXPORTED_FROM_ABI size_t mbsnrtowcs(
4848 size_t dest_remaining = max_dest_chars - dest_converted;
4949
5050 if (dst == nullptr) {
51 result = mbrtowc(NULL, *src + source_converted, source_remaining, ps);
51 result = mbrtowc(nullptr, *src + source_converted, source_remaining, ps);
5252 } else if (dest_remaining >= source_remaining) {
5353 // dst has enough space to translate in-place.
5454 result = mbrtowc(dst + dest_converted, *src + source_converted, source_remaining, ps);
......@@ -86,7 +86,7 @@ _LIBCPP_EXPORTED_FROM_ABI size_t mbsnrtowcs(
8686
8787 if (dst) {
8888 if (result == terminated_sequence)
89 *src = NULL;
89 *src = nullptr;
9090 else
9191 *src += source_converted;
9292 }
lib/libcxx/src/support/ibm/wcsnrtombs.cpp+2-2
......@@ -41,7 +41,7 @@ _LIBCPP_EXPORTED_FROM_ABI size_t wcsnrtombs(
4141 size_t dest_remaining = dst_size_bytes - dest_converted;
4242
4343 if (dst == nullptr) {
44 result = wcrtomb(NULL, c, ps);
44 result = wcrtomb(nullptr, c, ps);
4545 } else if (dest_remaining >= static_cast<size_t>(MB_CUR_MAX)) {
4646 // dst has enough space to translate in-place.
4747 result = wcrtomb(dst + dest_converted, c, ps);
......@@ -82,7 +82,7 @@ _LIBCPP_EXPORTED_FROM_ABI size_t wcsnrtombs(
8282
8383 if (c == L'\0') {
8484 if (dst)
85 *src = NULL;
85 *src = nullptr;
8686 return dest_converted;
8787 }
8888 }
lib/libcxx/src/support/ibm/xlocale_zos.cpp+8-8
......@@ -20,12 +20,12 @@ locale_t newlocale(int category_mask, const char* locale, locale_t base) {
2020 std::string current_loc_name(setlocale(LC_ALL, 0));
2121
2222 // Check for errors.
23 if (category_mask == LC_ALL_MASK && setlocale(LC_ALL, locale) == NULL) {
23 if (category_mask == LC_ALL_MASK && setlocale(LC_ALL, locale) == nullptr) {
2424 errno = EINVAL;
2525 return (locale_t)0;
2626 } else {
2727 for (int _Cat = 0; _Cat <= _LC_MAX; ++_Cat) {
28 if ((_CATMASK(_Cat) & category_mask) != 0 && setlocale(_Cat, locale) == NULL) {
28 if ((_CATMASK(_Cat) & category_mask) != 0 && setlocale(_Cat, locale) == nullptr) {
2929 setlocale(LC_ALL, current_loc_name.c_str());
3030 errno = EINVAL;
3131 return (locale_t)0;
......@@ -74,12 +74,12 @@ locale_t uselocale(locale_t newloc) {
7474 if (newloc) {
7575 // Set locales and check for errors.
7676 bool is_error =
77 (newloc->category_mask & LC_COLLATE_MASK && setlocale(LC_COLLATE, newloc->lc_collate.c_str()) == NULL) ||
78 (newloc->category_mask & LC_CTYPE_MASK && setlocale(LC_CTYPE, newloc->lc_ctype.c_str()) == NULL) ||
79 (newloc->category_mask & LC_MONETARY_MASK && setlocale(LC_MONETARY, newloc->lc_monetary.c_str()) == NULL) ||
80 (newloc->category_mask & LC_NUMERIC_MASK && setlocale(LC_NUMERIC, newloc->lc_numeric.c_str()) == NULL) ||
81 (newloc->category_mask & LC_TIME_MASK && setlocale(LC_TIME, newloc->lc_time.c_str()) == NULL) ||
82 (newloc->category_mask & LC_MESSAGES_MASK && setlocale(LC_MESSAGES, newloc->lc_messages.c_str()) == NULL);
77 (newloc->category_mask & LC_COLLATE_MASK && setlocale(LC_COLLATE, newloc->lc_collate.c_str()) == nullptr) ||
78 (newloc->category_mask & LC_CTYPE_MASK && setlocale(LC_CTYPE, newloc->lc_ctype.c_str()) == nullptr) ||
79 (newloc->category_mask & LC_MONETARY_MASK && setlocale(LC_MONETARY, newloc->lc_monetary.c_str()) == nullptr) ||
80 (newloc->category_mask & LC_NUMERIC_MASK && setlocale(LC_NUMERIC, newloc->lc_numeric.c_str()) == nullptr) ||
81 (newloc->category_mask & LC_TIME_MASK && setlocale(LC_TIME, newloc->lc_time.c_str()) == nullptr) ||
82 (newloc->category_mask & LC_MESSAGES_MASK && setlocale(LC_MESSAGES, newloc->lc_messages.c_str()) == nullptr);
8383
8484 if (is_error) {
8585 setlocale(LC_ALL, current_loc_name.c_str());
lib/libcxx/src/support/runtime/exception_fallback.ipp+10-13
......@@ -7,7 +7,7 @@
77//
88//===----------------------------------------------------------------------===//
99
10#include <cstdio>
10#include <__verbose_abort>
1111
1212namespace std {
1313
......@@ -21,7 +21,7 @@ unexpected_handler set_unexpected(unexpected_handler func) noexcept {
2121
2222unexpected_handler get_unexpected() noexcept { return __libcpp_atomic_load(&__unexpected_handler); }
2323
24_LIBCPP_NORETURN void unexpected() {
24[[noreturn]] void unexpected() {
2525 (*get_unexpected())();
2626 // unexpected handler should not return
2727 terminate();
......@@ -33,29 +33,26 @@ terminate_handler set_terminate(terminate_handler func) noexcept {
3333
3434terminate_handler get_terminate() noexcept { return __libcpp_atomic_load(&__terminate_handler); }
3535
36_LIBCPP_NORETURN void terminate() noexcept {
37#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
36[[noreturn]] void terminate() noexcept {
37#if _LIBCPP_HAS_EXCEPTIONS
3838 try {
39#endif // _LIBCPP_HAS_NO_EXCEPTIONS
39#endif // _LIBCPP_HAS_EXCEPTIONS
4040 (*get_terminate())();
4141 // handler should not return
42 fprintf(stderr, "terminate_handler unexpectedly returned\n");
43 ::abort();
44#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
42 __libcpp_verbose_abort("terminate_handler unexpectedly returned\n");
43#if _LIBCPP_HAS_EXCEPTIONS
4544 } catch (...) {
4645 // handler should not throw exception
47 fprintf(stderr, "terminate_handler unexpectedly threw an exception\n");
48 ::abort();
46 __libcpp_verbose_abort("terminate_handler unexpectedly threw an exception\n");
4947 }
50#endif // _LIBCPP_HAS_NO_EXCEPTIONS
48#endif // _LIBCPP_HAS_EXCEPTIONS
5149}
5250
5351bool uncaught_exception() noexcept { return uncaught_exceptions() > 0; }
5452
5553int uncaught_exceptions() noexcept {
5654#warning uncaught_exception not yet implemented
57 fprintf(stderr, "uncaught_exceptions not yet implemented\n");
58 ::abort();
55 __libcpp_verbose_abort("uncaught_exceptions not yet implemented\n");
5956}
6057
6158exception::~exception() noexcept {}
lib/libcxx/src/support/runtime/exception_msvc.ipp+9-12
......@@ -11,8 +11,7 @@
1111# error this header can only be used when targeting the MSVC ABI
1212#endif
1313
14#include <stdio.h>
15#include <stdlib.h>
14#include <__verbose_abort>
1615
1716extern "C" {
1817typedef void(__cdecl* terminate_handler)();
......@@ -32,7 +31,7 @@ unexpected_handler set_unexpected(unexpected_handler func) noexcept { return ::s
3231
3332unexpected_handler get_unexpected() noexcept { return ::_get_unexpected(); }
3433
35_LIBCPP_NORETURN void unexpected() {
34[[noreturn]] void unexpected() {
3635 (*get_unexpected())();
3736 // unexpected handler should not return
3837 terminate();
......@@ -42,21 +41,19 @@ terminate_handler set_terminate(terminate_handler func) noexcept { return ::set_
4241
4342terminate_handler get_terminate() noexcept { return ::_get_terminate(); }
4443
45_LIBCPP_NORETURN void terminate() noexcept {
46#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
44[[noreturn]] void terminate() noexcept {
45#if _LIBCPP_HAS_EXCEPTIONS
4746 try {
48#endif // _LIBCPP_HAS_NO_EXCEPTIONS
47#endif // _LIBCPP_HAS_EXCEPTIONS
4948 (*get_terminate())();
5049 // handler should not return
51 fprintf(stderr, "terminate_handler unexpectedly returned\n");
52 ::abort();
53#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
50 __libcpp_verbose_abort("terminate_handler unexpectedly returned\n");
51#if _LIBCPP_HAS_EXCEPTIONS
5452 } catch (...) {
5553 // handler should not throw exception
56 fprintf(stderr, "terminate_handler unexpectedly threw an exception\n");
57 ::abort();
54 __libcpp_verbose_abort("terminate_handler unexpectedly threw an exception\n");
5855 }
59#endif // _LIBCPP_HAS_NO_EXCEPTIONS
56#endif // _LIBCPP_HAS_EXCEPTIONS
6057}
6158
6259bool uncaught_exception() noexcept { return uncaught_exceptions() > 0; }
lib/libcxx/src/support/runtime/exception_pointer_cxxabi.ipp+2-2
......@@ -40,7 +40,7 @@ nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {}
4040
4141nested_exception::~nested_exception() noexcept {}
4242
43_LIBCPP_NORETURN void nested_exception::rethrow_nested() const {
43void nested_exception::rethrow_nested() const {
4444 if (__ptr_ == nullptr)
4545 terminate();
4646 rethrow_exception(__ptr_);
......@@ -55,7 +55,7 @@ exception_ptr current_exception() noexcept {
5555 return ptr;
5656}
5757
58_LIBCPP_NORETURN void rethrow_exception(exception_ptr p) {
58void rethrow_exception(exception_ptr p) {
5959 __cxa_rethrow_primary_exception(p.__ptr_);
6060 // if p.__ptr_ is NULL, above returns so we terminate
6161 terminate();
lib/libcxx/src/support/runtime/exception_pointer_glibcxx.ipp+3-3
......@@ -31,7 +31,7 @@ struct exception_ptr {
3131
3232} // namespace __exception_ptr
3333
34_LIBCPP_NORETURN void rethrow_exception(__exception_ptr::exception_ptr);
34[[noreturn]] void rethrow_exception(__exception_ptr::exception_ptr);
3535
3636exception_ptr::~exception_ptr() noexcept { reinterpret_cast<__exception_ptr::exception_ptr*>(this)->~exception_ptr(); }
3737
......@@ -55,13 +55,13 @@ exception_ptr exception_ptr::__from_native_exception_pointer(void* __e) noexcept
5555
5656nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {}
5757
58_LIBCPP_NORETURN void nested_exception::rethrow_nested() const {
58[[noreturn]] void nested_exception::rethrow_nested() const {
5959 if (__ptr_ == nullptr)
6060 terminate();
6161 rethrow_exception(__ptr_);
6262}
6363
64_LIBCPP_NORETURN void rethrow_exception(exception_ptr p) {
64[[noreturn]] void rethrow_exception(exception_ptr p) {
6565 rethrow_exception(reinterpret_cast<__exception_ptr::exception_ptr&>(p));
6666}
6767
lib/libcxx/src/support/runtime/exception_pointer_msvc.ipp+2-2
......@@ -61,13 +61,13 @@ exception_ptr current_exception() noexcept {
6161 return __ret;
6262}
6363
64_LIBCPP_NORETURN void rethrow_exception(exception_ptr p) { __ExceptionPtrRethrow(&p); }
64[[noreturn]] void rethrow_exception(exception_ptr p) { __ExceptionPtrRethrow(&p); }
6565
6666nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {}
6767
6868nested_exception::~nested_exception() noexcept {}
6969
70_LIBCPP_NORETURN void nested_exception::rethrow_nested() const {
70[[noreturn]] void nested_exception::rethrow_nested() const {
7171 if (__ptr_ == nullptr)
7272 terminate();
7373 rethrow_exception(__ptr_);
lib/libcxx/src/support/runtime/exception_pointer_unimplemented.ipp+10-18
......@@ -7,33 +7,28 @@
77//
88//===----------------------------------------------------------------------===//
99
10#include <stdio.h>
11#include <stdlib.h>
10#include <__verbose_abort>
1211
1312namespace std {
1413
1514exception_ptr::~exception_ptr() noexcept {
1615#warning exception_ptr not yet implemented
17 fprintf(stderr, "exception_ptr not yet implemented\n");
18 ::abort();
16 __libcpp_verbose_abort("exception_ptr not yet implemented\n");
1917}
2018
2119exception_ptr::exception_ptr(const exception_ptr& other) noexcept : __ptr_(other.__ptr_) {
2220#warning exception_ptr not yet implemented
23 fprintf(stderr, "exception_ptr not yet implemented\n");
24 ::abort();
21 __libcpp_verbose_abort("exception_ptr not yet implemented\n");
2522}
2623
2724exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept {
2825#warning exception_ptr not yet implemented
29 fprintf(stderr, "exception_ptr not yet implemented\n");
30 ::abort();
26 __libcpp_verbose_abort("exception_ptr not yet implemented\n");
3127}
3228
3329exception_ptr exception_ptr::__from_native_exception_pointer(void *__e) noexcept {
3430#warning exception_ptr not yet implemented
35 fprintf(stderr, "exception_ptr not yet implemented\n");
36 ::abort();
31 __libcpp_verbose_abort("exception_ptr not yet implemented\n");
3732}
3833
3934nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {}
......@@ -44,10 +39,9 @@ nested_exception::~nested_exception() noexcept {}
4439
4540#endif
4641
47_LIBCPP_NORETURN void nested_exception::rethrow_nested() const {
42[[noreturn]] void nested_exception::rethrow_nested() const {
4843#warning exception_ptr not yet implemented
49 fprintf(stderr, "exception_ptr not yet implemented\n");
50 ::abort();
44 __libcpp_verbose_abort("exception_ptr not yet implemented\n");
5145#if 0
5246 if (__ptr_ == nullptr)
5347 terminate();
......@@ -57,14 +51,12 @@ _LIBCPP_NORETURN void nested_exception::rethrow_nested() const {
5751
5852exception_ptr current_exception() noexcept {
5953#warning exception_ptr not yet implemented
60 fprintf(stderr, "exception_ptr not yet implemented\n");
61 ::abort();
54 __libcpp_verbose_abort("exception_ptr not yet implemented\n");
6255}
6356
64_LIBCPP_NORETURN void rethrow_exception(exception_ptr p) {
57[[noreturn]] void rethrow_exception(exception_ptr p) {
6558#warning exception_ptr not yet implemented
66 fprintf(stderr, "exception_ptr not yet implemented\n");
67 ::abort();
59 __libcpp_verbose_abort("exception_ptr not yet implemented\n");
6860}
6961
7062} // namespace std
lib/libcxx/src/support/win32/locale_win32.cpp+133-80
......@@ -6,127 +6,180 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include <cstdarg> // va_start, va_end
10#include <locale>
11#include <memory>
12#include <type_traits>
9#include <__locale_dir/support/windows.h>
10#include <clocale> // std::localeconv() & friends
11#include <cstdarg> // va_start & friends
12#include <cstddef>
13#include <cstdio> // std::vsnprintf & friends
14#include <cstdlib> // std::strtof & friends
15#include <ctime> // std::strftime
16#include <cwchar> // wide char manipulation
1317
14#include <__locale_dir/locale_base_api/locale_guard.h>
18_LIBCPP_BEGIN_NAMESPACE_STD
19namespace __locale {
1520
16int __libcpp_vasprintf(char** sptr, const char* __restrict fmt, va_list ap);
21//
22// Locale management
23//
24// FIXME: base and mask currently unused. Needs manual work to construct the new locale
25__locale_t __newlocale(int /*mask*/, const char* locale, __locale_t /*base*/) {
26 return {::_create_locale(LC_ALL, locale), locale};
27}
28
29__lconv_t* __localeconv(__locale_t& loc) {
30 __locale_guard __current(loc);
31 lconv* lc = std::localeconv();
32 if (!lc)
33 return lc;
34 return loc.__store_lconv(lc);
35}
1736
18using std::__libcpp_locale_guard;
37//
38// Strtonum functions
39//
40#if !defined(_LIBCPP_MSVCRT)
41float __strtof(const char* nptr, char** endptr, __locale_t loc) {
42 __locale_guard __current(loc);
43 return std::strtof(nptr, endptr);
44}
1945
20// FIXME: base and mask currently unused. Needs manual work to construct the new locale
21locale_t newlocale(int /*mask*/, const char* locale, locale_t /*base*/) {
22 return {_create_locale(LC_ALL, locale), locale};
46long double __strtold(const char* nptr, char** endptr, __locale_t loc) {
47 __locale_guard __current(loc);
48 return std::strtold(nptr, endptr);
49}
50#endif
51
52//
53// Character manipulation functions
54//
55#if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800
56size_t __strftime(char* ret, size_t n, const char* format, const struct tm* tm, __locale_t loc) {
57 __locale_guard __current(loc);
58 return std::strftime(ret, n, format, tm);
2359}
60#endif
2461
25decltype(MB_CUR_MAX) MB_CUR_MAX_L(locale_t __l) {
62//
63// Other functions
64//
65decltype(MB_CUR_MAX) __mb_len_max(__locale_t __l) {
2666#if defined(_LIBCPP_MSVCRT)
27 return ___mb_cur_max_l_func(__l);
67 return ::___mb_cur_max_l_func(__l);
2868#else
29 __libcpp_locale_guard __current(__l);
69 __locale_guard __current(__l);
3070 return MB_CUR_MAX;
3171#endif
3272}
3373
34lconv* localeconv_l(locale_t& loc) {
35 __libcpp_locale_guard __current(loc);
36 lconv* lc = localeconv();
37 if (!lc)
38 return lc;
39 return loc.__store_lconv(lc);
74wint_t __btowc(int c, __locale_t loc) {
75 __locale_guard __current(loc);
76 return std::btowc(c);
4077}
41size_t mbrlen_l(const char* __restrict s, size_t n, mbstate_t* __restrict ps, locale_t loc) {
42 __libcpp_locale_guard __current(loc);
43 return mbrlen(s, n, ps);
44}
45size_t
46mbsrtowcs_l(wchar_t* __restrict dst, const char** __restrict src, size_t len, mbstate_t* __restrict ps, locale_t loc) {
47 __libcpp_locale_guard __current(loc);
48 return mbsrtowcs(dst, src, len, ps);
78
79int __wctob(wint_t c, __locale_t loc) {
80 __locale_guard __current(loc);
81 return std::wctob(c);
4982}
50size_t wcrtomb_l(char* __restrict s, wchar_t wc, mbstate_t* __restrict ps, locale_t loc) {
51 __libcpp_locale_guard __current(loc);
52 return wcrtomb(s, wc, ps);
83
84size_t __wcsnrtombs(char* __restrict dst,
85 const wchar_t** __restrict src,
86 size_t nwc,
87 size_t len,
88 mbstate_t* __restrict ps,
89 __locale_t loc) {
90 __locale_guard __current(loc);
91 return ::wcsnrtombs(dst, src, nwc, len, ps);
5392}
54size_t mbrtowc_l(wchar_t* __restrict pwc, const char* __restrict s, size_t n, mbstate_t* __restrict ps, locale_t loc) {
55 __libcpp_locale_guard __current(loc);
56 return mbrtowc(pwc, s, n, ps);
93
94size_t __wcrtomb(char* __restrict s, wchar_t wc, mbstate_t* __restrict ps, __locale_t loc) {
95 __locale_guard __current(loc);
96 return std::wcrtomb(s, wc, ps);
5797}
58size_t mbsnrtowcs_l(wchar_t* __restrict dst,
98
99size_t __mbsnrtowcs(wchar_t* __restrict dst,
59100 const char** __restrict src,
60101 size_t nms,
61102 size_t len,
62103 mbstate_t* __restrict ps,
63 locale_t loc) {
64 __libcpp_locale_guard __current(loc);
65 return mbsnrtowcs(dst, src, nms, len, ps);
104 __locale_t loc) {
105 __locale_guard __current(loc);
106 return ::mbsnrtowcs(dst, src, nms, len, ps);
66107}
67size_t wcsnrtombs_l(char* __restrict dst,
68 const wchar_t** __restrict src,
69 size_t nwc,
70 size_t len,
71 mbstate_t* __restrict ps,
72 locale_t loc) {
73 __libcpp_locale_guard __current(loc);
74 return wcsnrtombs(dst, src, nwc, len, ps);
108
109size_t
110__mbrtowc(wchar_t* __restrict pwc, const char* __restrict s, size_t n, mbstate_t* __restrict ps, __locale_t loc) {
111 __locale_guard __current(loc);
112 return std::mbrtowc(pwc, s, n, ps);
75113}
76wint_t btowc_l(int c, locale_t loc) {
77 __libcpp_locale_guard __current(loc);
78 return btowc(c);
114
115size_t __mbrlen(const char* __restrict s, size_t n, mbstate_t* __restrict ps, __locale_t loc) {
116 __locale_guard __current(loc);
117 return std::mbrlen(s, n, ps);
79118}
80int wctob_l(wint_t c, locale_t loc) {
81 __libcpp_locale_guard __current(loc);
82 return wctob(c);
119
120size_t __mbsrtowcs(
121 wchar_t* __restrict dst, const char** __restrict src, size_t len, mbstate_t* __restrict ps, __locale_t loc) {
122 __locale_guard __current(loc);
123 return std::mbsrtowcs(dst, src, len, ps);
83124}
84125
85int snprintf_l(char* ret, size_t n, locale_t loc, const char* format, ...) {
126int __snprintf(char* ret, size_t n, __locale_t loc, const char* format, ...) {
86127 va_list ap;
87128 va_start(ap, format);
88129#if defined(_LIBCPP_MSVCRT)
89130 // FIXME: Remove usage of internal CRT function and globals.
90 int result = __stdio_common_vsprintf(
131 int result = ::__stdio_common_vsprintf(
91132 _CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR, ret, n, format, loc, ap);
92133#else
93 __libcpp_locale_guard __current(loc);
134 __locale_guard __current(loc);
94135 _LIBCPP_DIAGNOSTIC_PUSH
95136 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
96 int result = vsnprintf(ret, n, format, ap);
137 int result = std::vsnprintf(ret, n, format, ap);
97138 _LIBCPP_DIAGNOSTIC_POP
98139#endif
99140 va_end(ap);
100141 return result;
101142}
102143
103int asprintf_l(char** ret, locale_t loc, const char* format, ...) {
144// Like sprintf, but when return value >= 0 it returns
145// a pointer to a malloc'd string in *sptr.
146// If return >= 0, use free to delete *sptr.
147int __libcpp_vasprintf(char** sptr, const char* __restrict format, va_list ap) {
148 *sptr = nullptr;
149 // Query the count required.
150 va_list ap_copy;
151 va_copy(ap_copy, ap);
152 _LIBCPP_DIAGNOSTIC_PUSH
153 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
154 int count = vsnprintf(nullptr, 0, format, ap_copy);
155 _LIBCPP_DIAGNOSTIC_POP
156 va_end(ap_copy);
157 if (count < 0)
158 return count;
159 size_t buffer_size = static_cast<size_t>(count) + 1;
160 char* p = static_cast<char*>(malloc(buffer_size));
161 if (!p)
162 return -1;
163 // If we haven't used exactly what was required, something is wrong.
164 // Maybe bug in vsnprintf. Report the error and return.
165 _LIBCPP_DIAGNOSTIC_PUSH
166 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
167 if (vsnprintf(p, buffer_size, format, ap) != count) {
168 _LIBCPP_DIAGNOSTIC_POP
169 free(p);
170 return -1;
171 }
172 // All good. This is returning memory to the caller not freeing it.
173 *sptr = p;
174 return count;
175}
176
177int __asprintf(char** ret, __locale_t loc, const char* format, ...) {
104178 va_list ap;
105179 va_start(ap, format);
106 int result = vasprintf_l(ret, loc, format, ap);
107 va_end(ap);
108 return result;
109}
110int vasprintf_l(char** ret, locale_t loc, const char* format, va_list ap) {
111 __libcpp_locale_guard __current(loc);
180 __locale_guard __current(loc);
112181 return __libcpp_vasprintf(ret, format, ap);
113182}
114183
115#if !defined(_LIBCPP_MSVCRT)
116float strtof_l(const char* nptr, char** endptr, locale_t loc) {
117 __libcpp_locale_guard __current(loc);
118 return strtof(nptr, endptr);
119}
120
121long double strtold_l(const char* nptr, char** endptr, locale_t loc) {
122 __libcpp_locale_guard __current(loc);
123 return strtold(nptr, endptr);
124}
125#endif
126
127#if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800
128size_t strftime_l(char* ret, size_t n, const char* format, const struct tm* tm, locale_t loc) {
129 __libcpp_locale_guard __current(loc);
130 return strftime(ret, n, format, tm);
131}
132#endif
184} // namespace __locale
185_LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/support/win32/support.cpp+4-37
......@@ -13,39 +13,6 @@
1313#include <cstring> // strcpy, wcsncpy
1414#include <cwchar> // mbstate_t
1515
16// Like sprintf, but when return value >= 0 it returns
17// a pointer to a malloc'd string in *sptr.
18// If return >= 0, use free to delete *sptr.
19int __libcpp_vasprintf(char** sptr, const char* __restrict format, va_list ap) {
20 *sptr = NULL;
21 // Query the count required.
22 va_list ap_copy;
23 va_copy(ap_copy, ap);
24 _LIBCPP_DIAGNOSTIC_PUSH
25 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
26 int count = vsnprintf(NULL, 0, format, ap_copy);
27 _LIBCPP_DIAGNOSTIC_POP
28 va_end(ap_copy);
29 if (count < 0)
30 return count;
31 size_t buffer_size = static_cast<size_t>(count) + 1;
32 char* p = static_cast<char*>(malloc(buffer_size));
33 if (!p)
34 return -1;
35 // If we haven't used exactly what was required, something is wrong.
36 // Maybe bug in vsnprintf. Report the error and return.
37 _LIBCPP_DIAGNOSTIC_PUSH
38 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
39 if (vsnprintf(p, buffer_size, format, ap) != count) {
40 _LIBCPP_DIAGNOSTIC_POP
41 free(p);
42 return -1;
43 }
44 // All good. This is returning memory to the caller not freeing it.
45 *sptr = p;
46 return count;
47}
48
4916// Returns >= 0: the number of wide characters found in the
5017// multi byte sequence src (of src_size_bytes), that fit in the buffer dst
5118// (of max_dest_chars elements size). The count returned excludes the
......@@ -81,7 +48,7 @@ size_t mbsnrtowcs(wchar_t* __restrict dst,
8148 // if result > 0, it's the size in bytes of that character.
8249 // othewise if result is zero it indicates the null character has been found.
8350 // otherwise it's an error and errno may be set.
84 size_t char_size = mbrtowc(dst ? dst + dest_converted : NULL, *src + source_converted, source_remaining, ps);
51 size_t char_size = mbrtowc(dst ? dst + dest_converted : nullptr, *src + source_converted, source_remaining, ps);
8552 // Don't do anything to change errno from here on.
8653 if (char_size > 0) {
8754 source_remaining -= char_size;
......@@ -95,7 +62,7 @@ size_t mbsnrtowcs(wchar_t* __restrict dst,
9562 }
9663 if (dst) {
9764 if (have_result && result == terminated_sequence)
98 *src = NULL;
65 *src = nullptr;
9966 else
10067 *src += source_converted;
10168 }
......@@ -141,7 +108,7 @@ size_t wcsnrtombs(char* __restrict dst,
141108 if (dst)
142109 result = wcrtomb_s(&char_size, dst + dest_converted, dest_remaining, c, ps);
143110 else
144 result = wcrtomb_s(&char_size, NULL, 0, c, ps);
111 result = wcrtomb_s(&char_size, nullptr, 0, c, ps);
145112 // If result is zero there is no error and char_size contains the
146113 // size of the multi-byte-sequence converted.
147114 // Otherwise result indicates an errno type error.
......@@ -161,7 +128,7 @@ size_t wcsnrtombs(char* __restrict dst,
161128 }
162129 if (dst) {
163130 if (terminator_found)
164 *src = NULL;
131 *src = nullptr;
165132 else
166133 *src = *src + source_converted;
167134 }
lib/libcxx/src/support/win32/thread_win32.cpp+1-1
......@@ -129,7 +129,7 @@ __libcpp_init_once_execute_once_thunk(PINIT_ONCE __init_once, PVOID __parameter,
129129
130130int __libcpp_execute_once(__libcpp_exec_once_flag* __flag, void (*__init_routine)(void)) {
131131 if (!InitOnceExecuteOnce(
132 (PINIT_ONCE)__flag, __libcpp_init_once_execute_once_thunk, reinterpret_cast<void*>(__init_routine), NULL))
132 (PINIT_ONCE)__flag, __libcpp_init_once_execute_once_thunk, reinterpret_cast<void*>(__init_routine), nullptr))
133133 return GetLastError();
134134 return 0;
135135}
lib/libcxx/src/system_error.cpp+158-12
......@@ -8,25 +8,138 @@
88
99#include <__assert>
1010#include <__config>
11#include <__system_error/throw_system_error.h>
1112#include <__verbose_abort>
1213#include <cerrno>
1314#include <cstdio>
1415#include <cstdlib>
1516#include <cstring>
17#include <optional>
1618#include <string.h>
1719#include <string>
1820#include <system_error>
1921
2022#include "include/config_elast.h"
2123
22#if defined(__ANDROID__)
23# include <android/api-level.h>
24#if defined(_LIBCPP_WIN32API)
25# include <windows.h>
26# include <winerror.h>
2427#endif
2528
2629_LIBCPP_BEGIN_NAMESPACE_STD
2730
31#if defined(_LIBCPP_WIN32API)
32
2833namespace {
29#if !defined(_LIBCPP_HAS_NO_THREADS)
34std::optional<errc> __win_err_to_errc(int err) {
35 switch (err) {
36 case ERROR_ACCESS_DENIED:
37 return errc::permission_denied;
38 case ERROR_ALREADY_EXISTS:
39 return errc::file_exists;
40 case ERROR_BAD_NETPATH:
41 return errc::no_such_file_or_directory;
42 case ERROR_BAD_PATHNAME:
43 return errc::no_such_file_or_directory;
44 case ERROR_BAD_UNIT:
45 return errc::no_such_device;
46 case ERROR_BROKEN_PIPE:
47 return errc::broken_pipe;
48 case ERROR_BUFFER_OVERFLOW:
49 return errc::filename_too_long;
50 case ERROR_BUSY:
51 return errc::device_or_resource_busy;
52 case ERROR_BUSY_DRIVE:
53 return errc::device_or_resource_busy;
54 case ERROR_CANNOT_MAKE:
55 return errc::permission_denied;
56 case ERROR_CANTOPEN:
57 return errc::io_error;
58 case ERROR_CANTREAD:
59 return errc::io_error;
60 case ERROR_CANTWRITE:
61 return errc::io_error;
62 case ERROR_CURRENT_DIRECTORY:
63 return errc::permission_denied;
64 case ERROR_DEV_NOT_EXIST:
65 return errc::no_such_device;
66 case ERROR_DEVICE_IN_USE:
67 return errc::device_or_resource_busy;
68 case ERROR_DIR_NOT_EMPTY:
69 return errc::directory_not_empty;
70 case ERROR_DIRECTORY:
71 return errc::invalid_argument;
72 case ERROR_DISK_FULL:
73 return errc::no_space_on_device;
74 case ERROR_FILE_EXISTS:
75 return errc::file_exists;
76 case ERROR_FILE_NOT_FOUND:
77 return errc::no_such_file_or_directory;
78 case ERROR_HANDLE_DISK_FULL:
79 return errc::no_space_on_device;
80 case ERROR_INVALID_ACCESS:
81 return errc::permission_denied;
82 case ERROR_INVALID_DRIVE:
83 return errc::no_such_device;
84 case ERROR_INVALID_FUNCTION:
85 return errc::function_not_supported;
86 case ERROR_INVALID_HANDLE:
87 return errc::invalid_argument;
88 case ERROR_INVALID_NAME:
89 return errc::no_such_file_or_directory;
90 case ERROR_INVALID_PARAMETER:
91 return errc::invalid_argument;
92 case ERROR_LOCK_VIOLATION:
93 return errc::no_lock_available;
94 case ERROR_LOCKED:
95 return errc::no_lock_available;
96 case ERROR_NEGATIVE_SEEK:
97 return errc::invalid_argument;
98 case ERROR_NOACCESS:
99 return errc::permission_denied;
100 case ERROR_NOT_ENOUGH_MEMORY:
101 return errc::not_enough_memory;
102 case ERROR_NOT_READY:
103 return errc::resource_unavailable_try_again;
104 case ERROR_NOT_SAME_DEVICE:
105 return errc::cross_device_link;
106 case ERROR_NOT_SUPPORTED:
107 return errc::not_supported;
108 case ERROR_OPEN_FAILED:
109 return errc::io_error;
110 case ERROR_OPEN_FILES:
111 return errc::device_or_resource_busy;
112 case ERROR_OPERATION_ABORTED:
113 return errc::operation_canceled;
114 case ERROR_OUTOFMEMORY:
115 return errc::not_enough_memory;
116 case ERROR_PATH_NOT_FOUND:
117 return errc::no_such_file_or_directory;
118 case ERROR_READ_FAULT:
119 return errc::io_error;
120 case ERROR_REPARSE_TAG_INVALID:
121 return errc::invalid_argument;
122 case ERROR_RETRY:
123 return errc::resource_unavailable_try_again;
124 case ERROR_SEEK:
125 return errc::io_error;
126 case ERROR_SHARING_VIOLATION:
127 return errc::permission_denied;
128 case ERROR_TOO_MANY_OPEN_FILES:
129 return errc::too_many_files_open;
130 case ERROR_WRITE_FAULT:
131 return errc::io_error;
132 case ERROR_WRITE_PROTECT:
133 return errc::permission_denied;
134 default:
135 return {};
136 }
137}
138} // namespace
139#endif
140
141namespace {
142#if _LIBCPP_HAS_THREADS
30143
31144// GLIBC also uses 1024 as the maximum buffer size internally.
32145constexpr size_t strerror_buff_size = 1024;
......@@ -92,7 +205,7 @@ string do_strerror_r(int ev) {
92205}
93206# endif
94207
95#endif // !defined(_LIBCPP_HAS_NO_THREADS)
208#endif // _LIBCPP_HAS_THREADS
96209
97210string make_error_str(const error_code& ec, string what_arg) {
98211 if (ec) {
......@@ -110,10 +223,10 @@ string make_error_str(const error_code& ec) {
110223 }
111224 return string();
112225}
113} // end namespace
226} // namespace
114227
115228string __do_message::message(int ev) const {
116#if defined(_LIBCPP_HAS_NO_THREADS)
229#if !_LIBCPP_HAS_THREADS
117230 return string(::strerror(ev));
118231#else
119232 return do_strerror_r(ev);
......@@ -156,19 +269,52 @@ public:
156269const char* __system_error_category::name() const noexcept { return "system"; }
157270
158271string __system_error_category::message(int ev) const {
159#ifdef _LIBCPP_ELAST
272#ifdef _LIBCPP_WIN32API
273 std::string result;
274 char* str = nullptr;
275 unsigned long num_chars = ::FormatMessageA(
276 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
277 nullptr,
278 ev,
279 0,
280 reinterpret_cast<char*>(&str),
281 0,
282 nullptr);
283 auto is_whitespace = [](char ch) { return ch == '\n' || ch == '\r' || ch == ' '; };
284 while (num_chars > 0 && is_whitespace(str[num_chars - 1]))
285 --num_chars;
286
287 if (num_chars)
288 result = std::string(str, num_chars);
289 else
290 result = "Unknown error";
291
292 LocalFree(str);
293 return result;
294#else
295# ifdef _LIBCPP_ELAST
160296 if (ev > _LIBCPP_ELAST)
161297 return string("unspecified system_category error");
162#endif // _LIBCPP_ELAST
298# endif // _LIBCPP_ELAST
163299 return __do_message::message(ev);
300#endif
164301}
165302
166303error_condition __system_error_category::default_error_condition(int ev) const noexcept {
167#ifdef _LIBCPP_ELAST
304#ifdef _LIBCPP_WIN32API
305 // Remap windows error codes to generic error codes if possible.
306 if (ev == 0)
307 return error_condition(0, generic_category());
308 if (auto maybe_errc = __win_err_to_errc(ev))
309 return error_condition(static_cast<int>(*maybe_errc), generic_category());
310 return error_condition(ev, system_category());
311#else
312# ifdef _LIBCPP_ELAST
168313 if (ev > _LIBCPP_ELAST)
169314 return error_condition(ev, system_category());
170#endif // _LIBCPP_ELAST
315# endif // _LIBCPP_ELAST
171316 return error_condition(ev, generic_category());
317#endif
172318}
173319
174320const error_category& system_category() noexcept {
......@@ -211,8 +357,8 @@ system_error::system_error(int ev, const error_category& ecat)
211357system_error::~system_error() noexcept {}
212358
213359void __throw_system_error(int ev, const char* what_arg) {
214#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
215 std::__throw_system_error(error_code(ev, system_category()), what_arg);
360#if _LIBCPP_HAS_EXCEPTIONS
361 std::__throw_system_error(error_code(ev, generic_category()), what_arg);
216362#else
217363 // The above could also handle the no-exception case, but for size, avoid referencing system_category() unnecessarily.
218364 _LIBCPP_VERBOSE_ABORT(
lib/libcxx/src/vector.cpp+2-2
......@@ -17,8 +17,8 @@ struct __vector_base_common;
1717
1818template <>
1919struct __vector_base_common<true> {
20 _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
21 _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
20 [[noreturn]] _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
21 [[noreturn]] _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
2222};
2323
2424void __vector_base_common<true>::__throw_length_error() const { std::__throw_length_error("vector"); }
lib/libcxx/src/verbose_abort.cpp+2-14
......@@ -13,13 +13,8 @@
1313#include <cstdlib>
1414
1515#ifdef __BIONIC__
16# include <android/api-level.h>
17# if __ANDROID_API__ >= 21
18# include <syslog.h>
16# include <syslog.h>
1917extern "C" void android_set_abort_message(const char* msg);
20# else
21# include <assert.h>
22# endif // __ANDROID_API__ >= 21
2318#endif // __BIONIC__
2419
2520#if defined(__APPLE__) && __has_include(<CrashReporterClient.h>)
......@@ -28,7 +23,7 @@ extern "C" void android_set_abort_message(const char* msg);
2823
2924_LIBCPP_BEGIN_NAMESPACE_STD
3025
31_LIBCPP_WEAK void __libcpp_verbose_abort(char const* format, ...) {
26_LIBCPP_WEAK void __libcpp_verbose_abort(char const* format, ...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT {
3227 // Write message to stderr. We do this before formatting into a
3328 // buffer so that we still get some information out if that fails.
3429 {
......@@ -54,7 +49,6 @@ _LIBCPP_WEAK void __libcpp_verbose_abort(char const* format, ...) {
5449#elif defined(__BIONIC__)
5550 vasprintf(&buffer, format, list);
5651
57# if __ANDROID_API__ >= 21
5852 // Show error in tombstone.
5953 android_set_abort_message(buffer);
6054
......@@ -62,12 +56,6 @@ _LIBCPP_WEAK void __libcpp_verbose_abort(char const* format, ...) {
6256 openlog("libc++", 0, 0);
6357 syslog(LOG_CRIT, "%s", buffer);
6458 closelog();
65# else
66 // The good error reporting wasn't available in Android until L. Since we're
67 // about to abort anyway, just call __assert2, which will log _somewhere_
68 // (tombstone and/or logcat) in older releases.
69 __assert2(__FILE__, __LINE__, __func__, buffer);
70# endif // __ANDROID_API__ >= 21
7159#endif
7260 va_end(list);
7361
src/Compilation.zig+1-23
......@@ -5776,29 +5776,7 @@ pub fn addCCArgs(
57765776 comp.zig_lib_directory.path.?, "libcxxabi", "include",
57775777 }));
57785778
5779 if (target.abi.isMusl()) {
5780 try argv.append("-D_LIBCPP_HAS_MUSL_LIBC");
5781 }
5782
5783 try argv.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
5784 try argv.append("-D_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS");
5785 try argv.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
5786
5787 if (!comp.config.any_non_single_threaded) {
5788 try argv.append("-D_LIBCPP_HAS_NO_THREADS");
5789 }
5790
5791 // See the comment in libcxx.zig for more details about this.
5792 try argv.append("-D_LIBCPP_PSTL_BACKEND_SERIAL");
5793
5794 try argv.append(try std.fmt.allocPrint(arena, "-D_LIBCPP_ABI_VERSION={d}", .{
5795 @intFromEnum(comp.libcxx_abi_version),
5796 }));
5797 try argv.append(try std.fmt.allocPrint(arena, "-D_LIBCPP_ABI_NAMESPACE=__{d}", .{
5798 @intFromEnum(comp.libcxx_abi_version),
5799 }));
5800
5801 try argv.append(libcxx.hardeningModeFlag(mod.optimize_mode));
5779 try libcxx.addCxxArgs(comp, arena, argv);
58025780 }
58035781
58045782 // According to Rich Felker libc headers are supposed to go before C language headers.
src/libcxx.zig+72-90
......@@ -62,7 +62,6 @@ const libcxx_base_files = [_][]const u8{
6262 "src/ios.cpp",
6363 "src/ios.instantiations.cpp",
6464 "src/iostream.cpp",
65 "src/legacy_pointer_safety.cpp",
6665 "src/locale.cpp",
6766 "src/memory.cpp",
6867 "src/memory_resource.cpp",
......@@ -145,12 +144,7 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError!
145144 const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" });
146145 const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" });
147146 const cxx_src_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "src" });
148 const abi_version_arg = try std.fmt.allocPrint(arena, "-D_LIBCPP_ABI_VERSION={d}", .{
149 @intFromEnum(comp.libcxx_abi_version),
150 });
151 const abi_namespace_arg = try std.fmt.allocPrint(arena, "-D_LIBCPP_ABI_NAMESPACE=__{d}", .{
152 @intFromEnum(comp.libcxx_abi_version),
153 });
147 const cxx_libc_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "libc" });
154148
155149 const optimize_mode = comp.compilerRtOptMode();
156150 const strip = comp.compilerRtStrip();
......@@ -220,59 +214,27 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError!
220214 var c_source_files = try std.ArrayList(Compilation.CSourceFile).initCapacity(arena, libcxx_files.len);
221215
222216 for (libcxx_files) |cxx_src| {
223 var cflags = std.ArrayList([]const u8).init(arena);
224
225 if ((target.os.tag == .windows and (target.abi == .msvc or target.abi == .itanium)) or target.os.tag == .wasi) {
226 // Filesystem stuff isn't supported on WASI and Windows (MSVC).
227 if (std.mem.startsWith(u8, cxx_src, "src/filesystem/"))
228 continue;
229 }
230
217 // These don't compile on WASI due to e.g. `fchmod` usage.
218 if (std.mem.startsWith(u8, cxx_src, "src/filesystem/") and target.os.tag == .wasi)
219 continue;
231220 if (std.mem.startsWith(u8, cxx_src, "src/support/win32/") and target.os.tag != .windows)
232221 continue;
233222 if (std.mem.startsWith(u8, cxx_src, "src/support/ibm/") and target.os.tag != .zos)
234223 continue;
235 if (!comp.config.any_non_single_threaded)
236 try cflags.append("-D_LIBCPP_HAS_NO_THREADS");
224
225 var cflags = std.ArrayList([]const u8).init(arena);
226
227 try addCxxArgs(comp, arena, &cflags);
237228
238229 try cflags.append("-DNDEBUG");
239 try cflags.append(hardeningModeFlag(optimize_mode));
230 try cflags.append("-DLIBC_NAMESPACE=__llvm_libc_common_utils");
240231 try cflags.append("-D_LIBCPP_BUILDING_LIBRARY");
241 try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
242 try cflags.append("-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER");
243 try cflags.append("-D_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS");
244232 try cflags.append("-DLIBCXX_BUILDING_LIBCXXABI");
245 try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
246
247 // See libcxx/include/__algorithm/pstl_backends/cpu_backends/backend.h
248 // for potentially enabling some fancy features here, which would
249 // require corresponding changes in libcxx.zig, as well as
250 // Compilation.addCCArgs. This option makes it use serial backend which
251 // is simple and works everywhere.
252 try cflags.append("-D_LIBCPP_PSTL_BACKEND_SERIAL");
253
254 try cflags.append(abi_version_arg);
255 try cflags.append(abi_namespace_arg);
233 try cflags.append("-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER");
256234
257235 try cflags.append("-fvisibility=hidden");
258236 try cflags.append("-fvisibility-inlines-hidden");
259237
260 if (target.abi.isMusl()) {
261 try cflags.append("-D_LIBCPP_HAS_MUSL_LIBC");
262 }
263
264 if (target.isGnuLibC()) {
265 // glibc 2.16 introduced aligned_alloc
266 if (target.os.versionRange().gnuLibCVersion().?.order(.{ .major = 2, .minor = 16, .patch = 0 }) == .lt) {
267 try cflags.append("-D_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION");
268 }
269 }
270
271 if (target.os.tag == .wasi) {
272 // WASI doesn't support exceptions yet.
273 try cflags.append("-fno-exceptions");
274 }
275
276238 if (target.os.tag == .zos) {
277239 try cflags.append("-fno-aligned-allocation");
278240 } else {
......@@ -299,6 +261,9 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError!
299261 try cache_exempt_flags.append("-I");
300262 try cache_exempt_flags.append(cxx_src_include_path);
301263
264 try cache_exempt_flags.append("-I");
265 try cache_exempt_flags.append(cxx_libc_include_path);
266
302267 c_source_files.appendAssumeCapacity(.{
303268 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", cxx_src }),
304269 .extra_flags = cflags.items,
......@@ -389,12 +354,6 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
389354 const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" });
390355 const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" });
391356 const cxx_src_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "src" });
392 const abi_version_arg = try std.fmt.allocPrint(arena, "-D_LIBCPP_ABI_VERSION={d}", .{
393 @intFromEnum(comp.libcxx_abi_version),
394 });
395 const abi_namespace_arg = try std.fmt.allocPrint(arena, "-D_LIBCPP_ABI_NAMESPACE=__{d}", .{
396 @intFromEnum(comp.libcxx_abi_version),
397 });
398357
399358 const optimize_mode = comp.compilerRtOptMode();
400359 const strip = comp.compilerRtStrip();
......@@ -465,51 +424,26 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
465424 var c_source_files = try std.ArrayList(Compilation.CSourceFile).initCapacity(arena, libcxxabi_files.len);
466425
467426 for (libcxxabi_files) |cxxabi_src| {
427 if (!comp.config.any_non_single_threaded and std.mem.startsWith(u8, cxxabi_src, "src/cxa_thread_atexit.cpp"))
428 continue;
429
468430 var cflags = std.ArrayList([]const u8).init(arena);
469431
470 if (target.os.tag == .wasi) {
471 // WASI doesn't support exceptions yet.
472 if (std.mem.startsWith(u8, cxxabi_src, "src/cxa_exception.cpp") or
473 std.mem.startsWith(u8, cxxabi_src, "src/cxa_personality.cpp"))
474 continue;
475 try cflags.append("-fno-exceptions");
476 }
432 try addCxxArgs(comp, arena, &cflags);
477433
478 // WASM targets are single threaded.
434 try cflags.append("-DNDEBUG");
435 try cflags.append("-D_LIBCXXABI_BUILDING_LIBRARY");
479436 if (!comp.config.any_non_single_threaded) {
480 if (std.mem.startsWith(u8, cxxabi_src, "src/cxa_thread_atexit.cpp")) {
481 continue;
482 }
483437 try cflags.append("-D_LIBCXXABI_HAS_NO_THREADS");
484 } else if (target.abi.isGnu()) {
438 }
439 if (target.abi.isGnu()) {
485440 if (target.os.tag != .linux or !(target.os.versionRange().gnuLibCVersion().?.order(.{ .major = 2, .minor = 18, .patch = 0 }) == .lt))
486441 try cflags.append("-DHAVE___CXA_THREAD_ATEXIT_IMPL");
487442 }
488443
489 try cflags.append("-DNDEBUG");
490 try cflags.append(hardeningModeFlag(optimize_mode));
491 try cflags.append("-D_LIBCXXABI_BUILDING_LIBRARY");
492 try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
493 try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
494 try cflags.append("-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS");
495
496 try cflags.append(abi_version_arg);
497 try cflags.append(abi_namespace_arg);
498
499444 try cflags.append("-fvisibility=hidden");
500445 try cflags.append("-fvisibility-inlines-hidden");
501446
502 if (target.abi.isMusl()) {
503 try cflags.append("-D_LIBCPP_HAS_MUSL_LIBC");
504 }
505
506 if (target.isGnuLibC()) {
507 // glibc 2.16 introduced aligned_alloc
508 if (target.os.versionRange().gnuLibCVersion().?.order(.{ .major = 2, .minor = 16, .patch = 0 }) == .lt) {
509 try cflags.append("-D_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION");
510 }
511 }
512
513447 if (target_util.supports_fpic(target)) {
514448 try cflags.append("-fPIC");
515449 }
......@@ -593,10 +527,58 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
593527 comp.queueLinkTaskMode(crt_file.full_object_path, output_mode);
594528}
595529
596pub fn hardeningModeFlag(optimize_mode: std.builtin.OptimizeMode) []const u8 {
597 return switch (optimize_mode) {
530pub fn addCxxArgs(
531 comp: *const Compilation,
532 arena: std.mem.Allocator,
533 cflags: *std.ArrayList([]const u8),
534) error{OutOfMemory}!void {
535 const target = comp.getTarget();
536 const optimize_mode = comp.compilerRtOptMode();
537
538 try cflags.append(try std.fmt.allocPrint(arena, "-D_LIBCPP_ABI_VERSION={d}", .{
539 @intFromEnum(comp.libcxx_abi_version),
540 }));
541 try cflags.append(try std.fmt.allocPrint(arena, "-D_LIBCPP_ABI_NAMESPACE=__{d}", .{
542 @intFromEnum(comp.libcxx_abi_version),
543 }));
544 try cflags.append(try std.fmt.allocPrint(arena, "-D_LIBCPP_HAS_{s}THREADS", .{
545 if (!comp.config.any_non_single_threaded) "NO_" else "",
546 }));
547 try cflags.append("-D_LIBCPP_HAS_MONOTONIC_CLOCK");
548 try cflags.append("-D_LIBCPP_HAS_TERMINAL");
549 try cflags.append(try std.fmt.allocPrint(arena, "-D_LIBCPP_HAS_{s}MUSL_LIBC", .{
550 if (!target.abi.isMusl()) "NO_" else "",
551 }));
552 try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
553 try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
554 try cflags.append("-D_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS");
555 try cflags.append(try std.fmt.allocPrint(arena, "-D_LIBCPP_HAS_{s}FILESYSTEM", .{
556 if (target.os.tag == .wasi) "NO_" else "",
557 }));
558 try cflags.append("-D_LIBCPP_HAS_RANDOM_DEVICE");
559 try cflags.append("-D_LIBCPP_HAS_LOCALIZATION");
560 try cflags.append("-D_LIBCPP_HAS_UNICODE");
561 try cflags.append("-D_LIBCPP_HAS_WIDE_CHARACTERS");
562 try cflags.append("-D_LIBCPP_HAS_NO_STD_MODULES");
563 if (target.os.tag == .linux) {
564 try cflags.append("-D_LIBCPP_HAS_TIME_ZONE_DATABASE");
565 }
566 // See libcxx/include/__algorithm/pstl_backends/cpu_backends/backend.h
567 // for potentially enabling some fancy features here, which would
568 // require corresponding changes in libcxx.zig, as well as
569 // Compilation.addCCArgs. This option makes it use serial backend which
570 // is simple and works everywhere.
571 try cflags.append("-D_LIBCPP_PSTL_BACKEND_SERIAL");
572 try cflags.append(switch (optimize_mode) {
598573 .Debug => "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG",
599574 .ReleaseFast, .ReleaseSmall => "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE",
600575 .ReleaseSafe => "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST",
601 };
576 });
577 if (target.isGnuLibC()) {
578 // glibc 2.16 introduced aligned_alloc
579 if (target.os.versionRange().gnuLibCVersion().?.order(.{ .major = 2, .minor = 16, .patch = 0 }) == .lt) {
580 try cflags.append("-D_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION");
581 }
582 }
583 try cflags.append("-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS");
602584}