authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-07-16 10:46:24+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-08-30 06:36:40+02:00
logd9f0fbf9838060b1e8c2ec0df21b43e75430350f
tree1ad5976b5e0233a964a7c7381b3ccac8bbc9697e
parente84e9d3a01e4332ad6b7a239c74d823f283d7f8f
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

libcxx: update to LLVM 21


563 files changed, 16838 insertions(+), 12945 deletions(-)

lib/libcxx/include/__algorithm/copy.h+133-1
......@@ -13,8 +13,10 @@
1313#include <__algorithm/for_each_segment.h>
1414#include <__algorithm/min.h>
1515#include <__config>
16#include <__fwd/bit_reference.h>
1617#include <__iterator/iterator_traits.h>
1718#include <__iterator/segmented_iterator.h>
19#include <__memory/pointer_traits.h>
1820#include <__type_traits/common_type.h>
1921#include <__type_traits/enable_if.h>
2022#include <__utility/move.h>
......@@ -29,9 +31,129 @@ _LIBCPP_PUSH_MACROS
2931
3032_LIBCPP_BEGIN_NAMESPACE_STD
3133
34template <class _InputIterator, class _OutputIterator>
35inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
36copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result);
37
3238template <class _InIter, class _Sent, class _OutIter>
3339inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> __copy(_InIter, _Sent, _OutIter);
3440
41template <class _Cp, bool _IsConst>
42_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_aligned(
43 __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) {
44 using _In = __bit_iterator<_Cp, _IsConst>;
45 using difference_type = typename _In::difference_type;
46 using __storage_type = typename _In::__storage_type;
47
48 const int __bits_per_word = _In::__bits_per_word;
49 difference_type __n = __last - __first;
50 if (__n > 0) {
51 // do first word
52 if (__first.__ctz_ != 0) {
53 unsigned __clz = __bits_per_word - __first.__ctz_;
54 difference_type __dn = std::min(static_cast<difference_type>(__clz), __n);
55 __n -= __dn;
56 __storage_type __m = std::__middle_mask<__storage_type>(__clz - __dn, __first.__ctz_);
57 __storage_type __b = *__first.__seg_ & __m;
58 *__result.__seg_ &= ~__m;
59 *__result.__seg_ |= __b;
60 __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
61 __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
62 ++__first.__seg_;
63 // __first.__ctz_ = 0;
64 }
65 // __first.__ctz_ == 0;
66 // do middle words
67 __storage_type __nw = __n / __bits_per_word;
68 std::copy(std::__to_address(__first.__seg_),
69 std::__to_address(__first.__seg_ + __nw),
70 std::__to_address(__result.__seg_));
71 __n -= __nw * __bits_per_word;
72 __result.__seg_ += __nw;
73 // do last word
74 if (__n > 0) {
75 __first.__seg_ += __nw;
76 __storage_type __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n);
77 __storage_type __b = *__first.__seg_ & __m;
78 *__result.__seg_ &= ~__m;
79 *__result.__seg_ |= __b;
80 __result.__ctz_ = static_cast<unsigned>(__n);
81 }
82 }
83 return __result;
84}
85
86template <class _Cp, bool _IsConst>
87_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_unaligned(
88 __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) {
89 using _In = __bit_iterator<_Cp, _IsConst>;
90 using difference_type = typename _In::difference_type;
91 using __storage_type = typename _In::__storage_type;
92
93 const int __bits_per_word = _In::__bits_per_word;
94 difference_type __n = __last - __first;
95 if (__n > 0) {
96 // do first word
97 if (__first.__ctz_ != 0) {
98 unsigned __clz_f = __bits_per_word - __first.__ctz_;
99 difference_type __dn = std::min(static_cast<difference_type>(__clz_f), __n);
100 __n -= __dn;
101 __storage_type __m = std::__middle_mask<__storage_type>(__clz_f - __dn, __first.__ctz_);
102 __storage_type __b = *__first.__seg_ & __m;
103 unsigned __clz_r = __bits_per_word - __result.__ctz_;
104 __storage_type __ddn = std::min<__storage_type>(__dn, __clz_r);
105 __m = std::__middle_mask<__storage_type>(__clz_r - __ddn, __result.__ctz_);
106 *__result.__seg_ &= ~__m;
107 if (__result.__ctz_ > __first.__ctz_)
108 *__result.__seg_ |= __b << (__result.__ctz_ - __first.__ctz_);
109 else
110 *__result.__seg_ |= __b >> (__first.__ctz_ - __result.__ctz_);
111 __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word;
112 __result.__ctz_ = static_cast<unsigned>((__ddn + __result.__ctz_) % __bits_per_word);
113 __dn -= __ddn;
114 if (__dn > 0) {
115 __m = std::__trailing_mask<__storage_type>(__bits_per_word - __dn);
116 *__result.__seg_ &= ~__m;
117 *__result.__seg_ |= __b >> (__first.__ctz_ + __ddn);
118 __result.__ctz_ = static_cast<unsigned>(__dn);
119 }
120 ++__first.__seg_;
121 // __first.__ctz_ = 0;
122 }
123 // __first.__ctz_ == 0;
124 // do middle words
125 unsigned __clz_r = __bits_per_word - __result.__ctz_;
126 __storage_type __m = std::__leading_mask<__storage_type>(__result.__ctz_);
127 for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) {
128 __storage_type __b = *__first.__seg_;
129 *__result.__seg_ &= ~__m;
130 *__result.__seg_ |= __b << __result.__ctz_;
131 ++__result.__seg_;
132 *__result.__seg_ &= __m;
133 *__result.__seg_ |= __b >> __clz_r;
134 }
135 // do last word
136 if (__n > 0) {
137 __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n);
138 __storage_type __b = *__first.__seg_ & __m;
139 __storage_type __dn = std::min(__n, static_cast<difference_type>(__clz_r));
140 __m = std::__middle_mask<__storage_type>(__clz_r - __dn, __result.__ctz_);
141 *__result.__seg_ &= ~__m;
142 *__result.__seg_ |= __b << __result.__ctz_;
143 __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
144 __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
145 __n -= __dn;
146 if (__n > 0) {
147 __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n);
148 *__result.__seg_ &= ~__m;
149 *__result.__seg_ |= __b >> __dn;
150 __result.__ctz_ = static_cast<unsigned>(__n);
151 }
152 }
153 }
154 return __result;
155}
156
35157struct __copy_impl {
36158 template <class _InIter, class _Sent, class _OutIter>
37159 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
......@@ -95,6 +217,16 @@ struct __copy_impl {
95217 }
96218 }
97219
220 template <class _Cp, bool _IsConst>
221 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> >
222 operator()(__bit_iterator<_Cp, _IsConst> __first,
223 __bit_iterator<_Cp, _IsConst> __last,
224 __bit_iterator<_Cp, false> __result) const {
225 if (__first.__ctz_ == __result.__ctz_)
226 return std::make_pair(__last, std::__copy_aligned(__first, __last, __result));
227 return std::make_pair(__last, std::__copy_unaligned(__first, __last, __result));
228 }
229
98230 // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
99231 template <class _In, class _Out, __enable_if_t<__can_lower_copy_assignment_to_memmove<_In, _Out>::value, int> = 0>
100232 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
......@@ -110,7 +242,7 @@ __copy(_InIter __first, _Sent __last, _OutIter __result) {
110242}
111243
112244template <class _InputIterator, class _OutputIterator>
113inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
245_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
114246copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
115247 return std::__copy(__first, __last, __result).second;
116248}
lib/libcxx/include/__algorithm/copy_backward.h+131
......@@ -10,11 +10,14 @@
1010#define _LIBCPP___ALGORITHM_COPY_BACKWARD_H
1111
1212#include <__algorithm/copy_move_common.h>
13#include <__algorithm/copy_n.h>
1314#include <__algorithm/iterator_operations.h>
1415#include <__algorithm/min.h>
1516#include <__config>
17#include <__fwd/bit_reference.h>
1618#include <__iterator/iterator_traits.h>
1719#include <__iterator/segmented_iterator.h>
20#include <__memory/pointer_traits.h>
1821#include <__type_traits/common_type.h>
1922#include <__type_traits/enable_if.h>
2023#include <__type_traits/is_constructible.h>
......@@ -34,6 +37,124 @@ template <class _AlgPolicy, class _InIter, class _Sent, class _OutIter>
3437_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InIter, _OutIter>
3538__copy_backward(_InIter __first, _Sent __last, _OutIter __result);
3639
40template <class _Cp, bool _IsConst>
41_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_backward_aligned(
42 __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) {
43 using _In = __bit_iterator<_Cp, _IsConst>;
44 using difference_type = typename _In::difference_type;
45 using __storage_type = typename _In::__storage_type;
46
47 const int __bits_per_word = _In::__bits_per_word;
48 difference_type __n = __last - __first;
49 if (__n > 0) {
50 // do first word
51 if (__last.__ctz_ != 0) {
52 difference_type __dn = std::min(static_cast<difference_type>(__last.__ctz_), __n);
53 __n -= __dn;
54 unsigned __clz = __bits_per_word - __last.__ctz_;
55 __storage_type __m = std::__middle_mask<__storage_type>(__clz, __last.__ctz_ - __dn);
56 __storage_type __b = *__last.__seg_ & __m;
57 *__result.__seg_ &= ~__m;
58 *__result.__seg_ |= __b;
59 __result.__ctz_ = static_cast<unsigned>(((-__dn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word);
60 // __last.__ctz_ = 0
61 }
62 // __last.__ctz_ == 0 || __n == 0
63 // __result.__ctz_ == 0 || __n == 0
64 // do middle words
65 __storage_type __nw = __n / __bits_per_word;
66 __result.__seg_ -= __nw;
67 __last.__seg_ -= __nw;
68 std::copy_n(std::__to_address(__last.__seg_), __nw, std::__to_address(__result.__seg_));
69 __n -= __nw * __bits_per_word;
70 // do last word
71 if (__n > 0) {
72 __storage_type __m = std::__leading_mask<__storage_type>(__bits_per_word - __n);
73 __storage_type __b = *--__last.__seg_ & __m;
74 *--__result.__seg_ &= ~__m;
75 *__result.__seg_ |= __b;
76 __result.__ctz_ = static_cast<unsigned>(-__n & (__bits_per_word - 1));
77 }
78 }
79 return __result;
80}
81
82template <class _Cp, bool _IsConst>
83_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_backward_unaligned(
84 __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) {
85 using _In = __bit_iterator<_Cp, _IsConst>;
86 using difference_type = typename _In::difference_type;
87 using __storage_type = typename _In::__storage_type;
88
89 const int __bits_per_word = _In::__bits_per_word;
90 difference_type __n = __last - __first;
91 if (__n > 0) {
92 // do first word
93 if (__last.__ctz_ != 0) {
94 difference_type __dn = std::min(static_cast<difference_type>(__last.__ctz_), __n);
95 __n -= __dn;
96 unsigned __clz_l = __bits_per_word - __last.__ctz_;
97 __storage_type __m = std::__middle_mask<__storage_type>(__clz_l, __last.__ctz_ - __dn);
98 __storage_type __b = *__last.__seg_ & __m;
99 unsigned __clz_r = __bits_per_word - __result.__ctz_;
100 __storage_type __ddn = std::min(__dn, static_cast<difference_type>(__result.__ctz_));
101 if (__ddn > 0) {
102 __m = std::__middle_mask<__storage_type>(__clz_r, __result.__ctz_ - __ddn);
103 *__result.__seg_ &= ~__m;
104 if (__result.__ctz_ > __last.__ctz_)
105 *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_);
106 else
107 *__result.__seg_ |= __b >> (__last.__ctz_ - __result.__ctz_);
108 __result.__ctz_ = static_cast<unsigned>(((-__ddn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word);
109 __dn -= __ddn;
110 }
111 if (__dn > 0) {
112 // __result.__ctz_ == 0
113 --__result.__seg_;
114 __result.__ctz_ = static_cast<unsigned>(-__dn & (__bits_per_word - 1));
115 __m = std::__leading_mask<__storage_type>(__result.__ctz_);
116 *__result.__seg_ &= ~__m;
117 __last.__ctz_ -= __dn + __ddn;
118 *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_);
119 }
120 // __last.__ctz_ = 0
121 }
122 // __last.__ctz_ == 0 || __n == 0
123 // __result.__ctz_ != 0 || __n == 0
124 // do middle words
125 unsigned __clz_r = __bits_per_word - __result.__ctz_;
126 __storage_type __m = std::__trailing_mask<__storage_type>(__clz_r);
127 for (; __n >= __bits_per_word; __n -= __bits_per_word) {
128 __storage_type __b = *--__last.__seg_;
129 *__result.__seg_ &= ~__m;
130 *__result.__seg_ |= __b >> __clz_r;
131 *--__result.__seg_ &= __m;
132 *__result.__seg_ |= __b << __result.__ctz_;
133 }
134 // do last word
135 if (__n > 0) {
136 __m = std::__leading_mask<__storage_type>(__bits_per_word - __n);
137 __storage_type __b = *--__last.__seg_ & __m;
138 __clz_r = __bits_per_word - __result.__ctz_;
139 __storage_type __dn = std::min(__n, static_cast<difference_type>(__result.__ctz_));
140 __m = std::__middle_mask<__storage_type>(__clz_r, __result.__ctz_ - __dn);
141 *__result.__seg_ &= ~__m;
142 *__result.__seg_ |= __b >> (__bits_per_word - __result.__ctz_);
143 __result.__ctz_ = static_cast<unsigned>(((-__dn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word);
144 __n -= __dn;
145 if (__n > 0) {
146 // __result.__ctz_ == 0
147 --__result.__seg_;
148 __result.__ctz_ = static_cast<unsigned>(-__n & (__bits_per_word - 1));
149 __m = std::__leading_mask<__storage_type>(__result.__ctz_);
150 *__result.__seg_ &= ~__m;
151 *__result.__seg_ |= __b << (__result.__ctz_ - (__bits_per_word - __n - __dn));
152 }
153 }
154 }
155 return __result;
156}
157
37158template <class _AlgPolicy>
38159struct __copy_backward_impl {
39160 template <class _InIter, class _Sent, class _OutIter>
......@@ -107,6 +228,16 @@ struct __copy_backward_impl {
107228 }
108229 }
109230
231 template <class _Cp, bool _IsConst>
232 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> >
233 operator()(__bit_iterator<_Cp, _IsConst> __first,
234 __bit_iterator<_Cp, _IsConst> __last,
235 __bit_iterator<_Cp, false> __result) {
236 if (__last.__ctz_ == __result.__ctz_)
237 return std::make_pair(__last, std::__copy_backward_aligned(__first, __last, __result));
238 return std::make_pair(__last, std::__copy_backward_unaligned(__first, __last, __result));
239 }
240
110241 // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
111242 template <class _In, class _Out, __enable_if_t<__can_lower_copy_assignment_to_memmove<_In, _Out>::value, int> = 0>
112243 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
lib/libcxx/include/__algorithm/count.h+5-5
......@@ -55,18 +55,18 @@ __count_bool(__bit_iterator<_Cp, _IsConst> __first, typename __size_difference_t
5555 if (__first.__ctz_ != 0) {
5656 __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
5757 __storage_type __dn = std::min(__clz_f, __n);
58 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
59 __r = std::__libcpp_popcount(std::__invert_if<!_ToCount>(*__first.__seg_) & __m);
58 __storage_type __m = std::__middle_mask<__storage_type>(__clz_f - __dn, __first.__ctz_);
59 __r = std::__popcount(__storage_type(std::__invert_if<!_ToCount>(*__first.__seg_) & __m));
6060 __n -= __dn;
6161 ++__first.__seg_;
6262 }
6363 // do middle whole words
6464 for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word)
65 __r += std::__libcpp_popcount(std::__invert_if<!_ToCount>(*__first.__seg_));
65 __r += std::__popcount(std::__invert_if<!_ToCount>(*__first.__seg_));
6666 // do last partial word
6767 if (__n > 0) {
68 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
69 __r += std::__libcpp_popcount(std::__invert_if<!_ToCount>(*__first.__seg_) & __m);
68 __storage_type __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n);
69 __r += std::__popcount(__storage_type(std::__invert_if<!_ToCount>(*__first.__seg_) & __m));
7070 }
7171 return __r;
7272}
lib/libcxx/include/__algorithm/equal.h+160
......@@ -11,16 +11,20 @@
1111#define _LIBCPP___ALGORITHM_EQUAL_H
1212
1313#include <__algorithm/comp.h>
14#include <__algorithm/min.h>
1415#include <__algorithm/unwrap_iter.h>
1516#include <__config>
1617#include <__functional/identity.h>
18#include <__fwd/bit_reference.h>
1719#include <__iterator/distance.h>
1820#include <__iterator/iterator_traits.h>
21#include <__memory/pointer_traits.h>
1922#include <__string/constexpr_c_functions.h>
2023#include <__type_traits/desugars_to.h>
2124#include <__type_traits/enable_if.h>
2225#include <__type_traits/invoke.h>
2326#include <__type_traits/is_equality_comparable.h>
27#include <__type_traits/is_same.h>
2428#include <__type_traits/is_volatile.h>
2529#include <__utility/move.h>
2630
......@@ -33,6 +37,140 @@ _LIBCPP_PUSH_MACROS
3337
3438_LIBCPP_BEGIN_NAMESPACE_STD
3539
40template <class _Cp, bool _IsConst1, bool _IsConst2>
41[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool
42__equal_unaligned(__bit_iterator<_Cp, _IsConst1> __first1,
43 __bit_iterator<_Cp, _IsConst1> __last1,
44 __bit_iterator<_Cp, _IsConst2> __first2) {
45 using _It = __bit_iterator<_Cp, _IsConst1>;
46 using difference_type = typename _It::difference_type;
47 using __storage_type = typename _It::__storage_type;
48
49 const int __bits_per_word = _It::__bits_per_word;
50 difference_type __n = __last1 - __first1;
51 if (__n > 0) {
52 // do first word
53 if (__first1.__ctz_ != 0) {
54 unsigned __clz_f = __bits_per_word - __first1.__ctz_;
55 difference_type __dn = std::min(static_cast<difference_type>(__clz_f), __n);
56 __n -= __dn;
57 __storage_type __m = std::__middle_mask<__storage_type>(__clz_f - __dn, __first1.__ctz_);
58 __storage_type __b = *__first1.__seg_ & __m;
59 unsigned __clz_r = __bits_per_word - __first2.__ctz_;
60 __storage_type __ddn = std::min<__storage_type>(__dn, __clz_r);
61 __m = std::__middle_mask<__storage_type>(__clz_r - __ddn, __first2.__ctz_);
62 if (__first2.__ctz_ > __first1.__ctz_) {
63 if (static_cast<__storage_type>(*__first2.__seg_ & __m) !=
64 static_cast<__storage_type>(__b << (__first2.__ctz_ - __first1.__ctz_)))
65 return false;
66 } else {
67 if (static_cast<__storage_type>(*__first2.__seg_ & __m) !=
68 static_cast<__storage_type>(__b >> (__first1.__ctz_ - __first2.__ctz_)))
69 return false;
70 }
71 __first2.__seg_ += (__ddn + __first2.__ctz_) / __bits_per_word;
72 __first2.__ctz_ = static_cast<unsigned>((__ddn + __first2.__ctz_) % __bits_per_word);
73 __dn -= __ddn;
74 if (__dn > 0) {
75 __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n);
76 if (static_cast<__storage_type>(*__first2.__seg_ & __m) !=
77 static_cast<__storage_type>(__b >> (__first1.__ctz_ + __ddn)))
78 return false;
79 __first2.__ctz_ = static_cast<unsigned>(__dn);
80 }
81 ++__first1.__seg_;
82 // __first1.__ctz_ = 0;
83 }
84 // __first1.__ctz_ == 0;
85 // do middle words
86 unsigned __clz_r = __bits_per_word - __first2.__ctz_;
87 __storage_type __m = std::__leading_mask<__storage_type>(__first2.__ctz_);
88 for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_) {
89 __storage_type __b = *__first1.__seg_;
90 if (static_cast<__storage_type>(*__first2.__seg_ & __m) != static_cast<__storage_type>(__b << __first2.__ctz_))
91 return false;
92 ++__first2.__seg_;
93 if (static_cast<__storage_type>(*__first2.__seg_ & static_cast<__storage_type>(~__m)) !=
94 static_cast<__storage_type>(__b >> __clz_r))
95 return false;
96 }
97 // do last word
98 if (__n > 0) {
99 __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n);
100 __storage_type __b = *__first1.__seg_ & __m;
101 __storage_type __dn = std::min(__n, static_cast<difference_type>(__clz_r));
102 __m = std::__middle_mask<__storage_type>(__clz_r - __dn, __first2.__ctz_);
103 if (static_cast<__storage_type>(*__first2.__seg_ & __m) != static_cast<__storage_type>(__b << __first2.__ctz_))
104 return false;
105 __first2.__seg_ += (__dn + __first2.__ctz_) / __bits_per_word;
106 __first2.__ctz_ = static_cast<unsigned>((__dn + __first2.__ctz_) % __bits_per_word);
107 __n -= __dn;
108 if (__n > 0) {
109 __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n);
110 if (static_cast<__storage_type>(*__first2.__seg_ & __m) != static_cast<__storage_type>(__b >> __dn))
111 return false;
112 }
113 }
114 }
115 return true;
116}
117
118template <class _Cp, bool _IsConst1, bool _IsConst2>
119[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool
120__equal_aligned(__bit_iterator<_Cp, _IsConst1> __first1,
121 __bit_iterator<_Cp, _IsConst1> __last1,
122 __bit_iterator<_Cp, _IsConst2> __first2) {
123 using _It = __bit_iterator<_Cp, _IsConst1>;
124 using difference_type = typename _It::difference_type;
125 using __storage_type = typename _It::__storage_type;
126
127 const int __bits_per_word = _It::__bits_per_word;
128 difference_type __n = __last1 - __first1;
129 if (__n > 0) {
130 // do first word
131 if (__first1.__ctz_ != 0) {
132 unsigned __clz = __bits_per_word - __first1.__ctz_;
133 difference_type __dn = std::min(static_cast<difference_type>(__clz), __n);
134 __n -= __dn;
135 __storage_type __m = std::__middle_mask<__storage_type>(__clz - __dn, __first1.__ctz_);
136 if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m))
137 return false;
138 ++__first2.__seg_;
139 ++__first1.__seg_;
140 // __first1.__ctz_ = 0;
141 // __first2.__ctz_ = 0;
142 }
143 // __first1.__ctz_ == 0;
144 // __first2.__ctz_ == 0;
145 // do middle words
146 for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_, ++__first2.__seg_)
147 if (*__first2.__seg_ != *__first1.__seg_)
148 return false;
149 // do last word
150 if (__n > 0) {
151 __storage_type __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n);
152 if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m))
153 return false;
154 }
155 }
156 return true;
157}
158
159template <class _Cp,
160 bool _IsConst1,
161 bool _IsConst2,
162 class _BinaryPredicate,
163 __enable_if_t<__desugars_to_v<__equal_tag, _BinaryPredicate, bool, bool>, int> = 0>
164[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_iter_impl(
165 __bit_iterator<_Cp, _IsConst1> __first1,
166 __bit_iterator<_Cp, _IsConst1> __last1,
167 __bit_iterator<_Cp, _IsConst2> __first2,
168 _BinaryPredicate) {
169 if (__first1.__ctz_ == __first2.__ctz_)
170 return std::__equal_aligned(__first1, __last1, __first2);
171 return std::__equal_unaligned(__first1, __last1, __first2);
172}
173
36174template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
37175[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_iter_impl(
38176 _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate& __pred) {
......@@ -94,6 +232,28 @@ __equal_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, _Up*, _Pred&, _Proj1&,
94232 return std::__constexpr_memcmp_equal(__first1, __first2, __element_count(__last1 - __first1));
95233}
96234
235template <class _Cp,
236 bool _IsConst1,
237 bool _IsConst2,
238 class _Pred,
239 class _Proj1,
240 class _Proj2,
241 __enable_if_t<__desugars_to_v<__equal_tag, _Pred, bool, bool> && __is_identity<_Proj1>::value &&
242 __is_identity<_Proj2>::value,
243 int> = 0>
244[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_impl(
245 __bit_iterator<_Cp, _IsConst1> __first1,
246 __bit_iterator<_Cp, _IsConst1> __last1,
247 __bit_iterator<_Cp, _IsConst2> __first2,
248 __bit_iterator<_Cp, _IsConst2>,
249 _Pred&,
250 _Proj1&,
251 _Proj2&) {
252 if (__first1.__ctz_ == __first2.__ctz_)
253 return std::__equal_aligned(__first1, __last1, __first2);
254 return std::__equal_unaligned(__first1, __last1, __first2);
255}
256
97257template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
98258[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
99259equal(_InputIterator1 __first1,
lib/libcxx/include/__algorithm/fill_n.h+2-10
......@@ -41,11 +41,7 @@ __fill_n_bool(__bit_iterator<_Cp, false> __first, typename __size_difference_typ
4141 if (__first.__ctz_ != 0) {
4242 __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
4343 __storage_type __dn = std::min(__clz_f, __n);
44 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
45 if (_FillVal)
46 *__first.__seg_ |= __m;
47 else
48 *__first.__seg_ &= ~__m;
44 std::__fill_masked_range(std::__to_address(__first.__seg_), __clz_f - __dn, __first.__ctz_, _FillVal);
4945 __n -= __dn;
5046 ++__first.__seg_;
5147 }
......@@ -56,11 +52,7 @@ __fill_n_bool(__bit_iterator<_Cp, false> __first, typename __size_difference_typ
5652 // do last partial word
5753 if (__n > 0) {
5854 __first.__seg_ += __nw;
59 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
60 if (_FillVal)
61 *__first.__seg_ |= __m;
62 else
63 *__first.__seg_ &= ~__m;
55 std::__fill_masked_range(std::__to_address(__first.__seg_), __bits_per_word - __n, 0u, _FillVal);
6456 }
6557}
6658
lib/libcxx/include/__algorithm/find.h+5-5
......@@ -106,10 +106,10 @@ __find_bool(__bit_iterator<_Cp, _IsConst> __first, typename __size_difference_ty
106106 if (__first.__ctz_ != 0) {
107107 __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
108108 __storage_type __dn = std::min(__clz_f, __n);
109 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
109 __storage_type __m = std::__middle_mask<__storage_type>(__clz_f - __dn, __first.__ctz_);
110110 __storage_type __b = std::__invert_if<!_ToFind>(*__first.__seg_) & __m;
111111 if (__b)
112 return _It(__first.__seg_, static_cast<unsigned>(std::__libcpp_ctz(__b)));
112 return _It(__first.__seg_, static_cast<unsigned>(std::__countr_zero(__b)));
113113 if (__n == __dn)
114114 return __first + __n;
115115 __n -= __dn;
......@@ -119,14 +119,14 @@ __find_bool(__bit_iterator<_Cp, _IsConst> __first, typename __size_difference_ty
119119 for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) {
120120 __storage_type __b = std::__invert_if<!_ToFind>(*__first.__seg_);
121121 if (__b)
122 return _It(__first.__seg_, static_cast<unsigned>(std::__libcpp_ctz(__b)));
122 return _It(__first.__seg_, static_cast<unsigned>(std::__countr_zero(__b)));
123123 }
124124 // do last partial word
125125 if (__n > 0) {
126 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
126 __storage_type __m = std::__trailing_mask<__storage_type>(__bits_per_word - __n);
127127 __storage_type __b = std::__invert_if<!_ToFind>(*__first.__seg_) & __m;
128128 if (__b)
129 return _It(__first.__seg_, static_cast<unsigned>(std::__libcpp_ctz(__b)));
129 return _It(__first.__seg_, static_cast<unsigned>(std::__countr_zero(__b)));
130130 }
131131 return _It(__first.__seg_, static_cast<unsigned>(__n));
132132}
lib/libcxx/include/__algorithm/for_each.h+28-19
......@@ -12,9 +12,10 @@
1212
1313#include <__algorithm/for_each_segment.h>
1414#include <__config>
15#include <__functional/identity.h>
1516#include <__iterator/segmented_iterator.h>
16#include <__ranges/movable_box.h>
17#include <__utility/in_place.h>
17#include <__type_traits/enable_if.h>
18#include <__type_traits/invoke.h>
1819#include <__utility/move.h>
1920
2021#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -26,28 +27,36 @@ _LIBCPP_PUSH_MACROS
2627
2728_LIBCPP_BEGIN_NAMESPACE_STD
2829
29template <class _InputIterator, class _Function>
30_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Function
31for_each(_InputIterator __first, _InputIterator __last, _Function __f) {
30template <class _InputIterator, class _Sent, class _Func, class _Proj>
31_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
32__for_each(_InputIterator __first, _Sent __last, _Func& __f, _Proj& __proj) {
3233 for (; __first != __last; ++__first)
33 __f(*__first);
34 return __f;
34 std::__invoke(__f, std::__invoke(__proj, *__first));
35 return __first;
3536}
3637
37// __movable_box is available in C++20, but is actually a copyable-box, so optimization is only correct in C++23
38#if _LIBCPP_STD_VER >= 23
39template <class _SegmentedIterator, class _Function>
40 requires __is_segmented_iterator<_SegmentedIterator>::value
41_LIBCPP_HIDE_FROM_ABI constexpr _Function
42for_each(_SegmentedIterator __first, _SegmentedIterator __last, _Function __func) {
43 ranges::__movable_box<_Function> __wrapped_func(in_place, std::move(__func));
44 std::__for_each_segment(__first, __last, [&](auto __lfirst, auto __llast) {
45 __wrapped_func =
46 ranges::__movable_box<_Function>(in_place, std::for_each(__lfirst, __llast, std::move(*__wrapped_func)));
38#ifndef _LIBCPP_CXX03_LANG
39template <class _SegmentedIterator,
40 class _Func,
41 class _Proj,
42 __enable_if_t<__is_segmented_iterator<_SegmentedIterator>::value, int> = 0>
43_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _SegmentedIterator
44__for_each(_SegmentedIterator __first, _SegmentedIterator __last, _Func& __func, _Proj& __proj) {
45 using __local_iterator_t = typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator;
46 std::__for_each_segment(__first, __last, [&](__local_iterator_t __lfirst, __local_iterator_t __llast) {
47 std::__for_each(__lfirst, __llast, __func, __proj);
4748 });
48 return std::move(*__wrapped_func);
49 return __last;
50}
51#endif // !_LIBCPP_CXX03_LANG
52
53template <class _InputIterator, class _Func>
54_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Func
55for_each(_InputIterator __first, _InputIterator __last, _Func __f) {
56 __identity __proj;
57 std::__for_each(__first, __last, __f, __proj);
58 return __f;
4959}
50#endif // _LIBCPP_STD_VER >= 23
5160
5261_LIBCPP_END_NAMESPACE_STD
5362
lib/libcxx/include/__algorithm/for_each_n.h+69-8
......@@ -10,32 +10,93 @@
1010#ifndef _LIBCPP___ALGORITHM_FOR_EACH_N_H
1111#define _LIBCPP___ALGORITHM_FOR_EACH_N_H
1212
13#include <__algorithm/for_each.h>
14#include <__algorithm/for_each_n_segment.h>
1315#include <__config>
16#include <__functional/identity.h>
17#include <__iterator/iterator_traits.h>
18#include <__iterator/segmented_iterator.h>
19#include <__type_traits/disjunction.h>
20#include <__type_traits/enable_if.h>
21#include <__type_traits/invoke.h>
22#include <__type_traits/negation.h>
1423#include <__utility/convert_to_integral.h>
24#include <__utility/move.h>
1525
1626#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1727# pragma GCC system_header
1828#endif
1929
20_LIBCPP_BEGIN_NAMESPACE_STD
30_LIBCPP_PUSH_MACROS
31#include <__undef_macros>
2132
22#if _LIBCPP_STD_VER >= 17
33_LIBCPP_BEGIN_NAMESPACE_STD
2334
24template <class _InputIterator, class _Size, class _Function>
25inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
26for_each_n(_InputIterator __first, _Size __orig_n, _Function __f) {
35template <class _InputIterator,
36 class _Size,
37 class _Func,
38 class _Proj,
39 __enable_if_t<!__has_random_access_iterator_category<_InputIterator>::value &&
40 _Or< _Not<__is_segmented_iterator<_InputIterator> >,
41 _Not<__has_random_access_local_iterator<_InputIterator> > >::value,
42 int> = 0>
43_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
44__for_each_n(_InputIterator __first, _Size __orig_n, _Func& __f, _Proj& __proj) {
2745 typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
2846 _IntegralSize __n = __orig_n;
2947 while (__n > 0) {
30 __f(*__first);
48 std::__invoke(__f, std::__invoke(__proj, *__first));
3149 ++__first;
3250 --__n;
3351 }
34 return __first;
52 return std::move(__first);
3553}
3654
37#endif
55template <class _RandIter,
56 class _Size,
57 class _Func,
58 class _Proj,
59 __enable_if_t<__has_random_access_iterator_category<_RandIter>::value, int> = 0>
60_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandIter
61__for_each_n(_RandIter __first, _Size __orig_n, _Func& __f, _Proj& __proj) {
62 typename std::iterator_traits<_RandIter>::difference_type __n = __orig_n;
63 auto __last = __first + __n;
64 std::__for_each(__first, __last, __f, __proj);
65 return __last;
66}
67
68#ifndef _LIBCPP_CXX03_LANG
69template <class _SegmentedIterator,
70 class _Size,
71 class _Func,
72 class _Proj,
73 __enable_if_t<!__has_random_access_iterator_category<_SegmentedIterator>::value &&
74 __is_segmented_iterator<_SegmentedIterator>::value &&
75 __has_random_access_iterator_category<
76 typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator>::value,
77 int> = 0>
78_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _SegmentedIterator
79__for_each_n(_SegmentedIterator __first, _Size __orig_n, _Func& __f, _Proj& __proj) {
80 using __local_iterator_t = typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator;
81 return std::__for_each_n_segment(__first, __orig_n, [&](__local_iterator_t __lfirst, __local_iterator_t __llast) {
82 std::__for_each(__lfirst, __llast, __f, __proj);
83 });
84}
85#endif // !_LIBCPP_CXX03_LANG
86
87#if _LIBCPP_STD_VER >= 17
88
89template <class _InputIterator, class _Size, class _Func>
90inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
91for_each_n(_InputIterator __first, _Size __orig_n, _Func __f) {
92 __identity __proj;
93 return std::__for_each_n(__first, __orig_n, __f, __proj);
94}
95
96#endif // _LIBCPP_STD_VER >= 17
3897
3998_LIBCPP_END_NAMESPACE_STD
4099
100_LIBCPP_POP_MACROS
101
41102#endif // _LIBCPP___ALGORITHM_FOR_EACH_N_H
lib/libcxx/include/__algorithm/for_each_n_segment.h created+63
......@@ -0,0 +1,63 @@
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___ALGORITHM_FOR_EACH_N_SEGMENT_H
10#define _LIBCPP___ALGORITHM_FOR_EACH_N_SEGMENT_H
11
12#include <__config>
13#include <__iterator/iterator_traits.h>
14#include <__iterator/segmented_iterator.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
22// __for_each_n_segment optimizes linear iteration over segmented iterators. It processes a segmented
23// input range [__first, __first + __n) by applying the functor __func to each element within the segment.
24// The return value of __func is ignored, and the function returns an iterator pointing to one past the
25// last processed element in the input range.
26
27template <class _SegmentedIterator, class _Size, class _Functor>
28_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _SegmentedIterator
29__for_each_n_segment(_SegmentedIterator __first, _Size __orig_n, _Functor __func) {
30 static_assert(__is_segmented_iterator<_SegmentedIterator>::value &&
31 __has_random_access_iterator_category<
32 typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator>::value,
33 "__for_each_n_segment only works with segmented iterators with random-access local iterators");
34 if (__orig_n <= 0)
35 return __first;
36
37 using _Traits = __segmented_iterator_traits<_SegmentedIterator>;
38 using __local_iter_t = typename _Traits::__local_iterator;
39 using __difference_t = typename std::iterator_traits<__local_iter_t>::difference_type;
40 __difference_t __n = __orig_n;
41 auto __seg = _Traits::__segment(__first);
42 auto __local_first = _Traits::__local(__first);
43 __local_iter_t __local_last;
44
45 while (__n > 0) {
46 __local_last = _Traits::__end(__seg);
47 auto __seg_size = __local_last - __local_first;
48 if (__n <= __seg_size) {
49 __local_last = __local_first + __n;
50 __func(__local_first, __local_last);
51 break;
52 }
53 __func(__local_first, __local_last);
54 __n -= __seg_size;
55 __local_first = _Traits::__begin(++__seg);
56 }
57
58 return _Traits::__compose(__seg, __local_last);
59}
60
61_LIBCPP_END_NAMESPACE_STD
62
63#endif // _LIBCPP___ALGORITHM_FOR_EACH_N_SEGMENT_H
lib/libcxx/include/__algorithm/inplace_merge.h+6-5
......@@ -22,6 +22,7 @@
2222#include <__functional/identity.h>
2323#include <__iterator/iterator_traits.h>
2424#include <__iterator/reverse_iterator.h>
25#include <__memory/construct_at.h>
2526#include <__memory/destruct_n.h>
2627#include <__memory/unique_ptr.h>
2728#include <__memory/unique_temporary_buffer.h>
......@@ -106,13 +107,13 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __buffered_inplace_merg
106107 value_type* __p = __buff;
107108 for (_BidirectionalIterator __i = __first; __i != __middle;
108109 __d.template __incr<value_type>(), (void)++__i, (void)++__p)
109 ::new ((void*)__p) value_type(_IterOps<_AlgPolicy>::__iter_move(__i));
110 std::__construct_at(__p, _IterOps<_AlgPolicy>::__iter_move(__i));
110111 std::__half_inplace_merge<_AlgPolicy>(__buff, __p, __middle, __last, __first, __comp);
111112 } else {
112113 value_type* __p = __buff;
113114 for (_BidirectionalIterator __i = __middle; __i != __last;
114115 __d.template __incr<value_type>(), (void)++__i, (void)++__p)
115 ::new ((void*)__p) value_type(_IterOps<_AlgPolicy>::__iter_move(__i));
116 std::__construct_at(__p, _IterOps<_AlgPolicy>::__iter_move(__i));
116117 typedef reverse_iterator<_BidirectionalIterator> _RBi;
117118 typedef reverse_iterator<value_type*> _Rv;
118119 typedef __invert<_Compare> _Inverted;
......@@ -203,7 +204,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX26 void __inplace_merge(
203204}
204205
205206template <class _AlgPolicy, class _BidirectionalIterator, class _Compare>
206_LIBCPP_HIDE_FROM_ABI void __inplace_merge(
207_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __inplace_merge(
207208 _BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare&& __comp) {
208209 typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
209210 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
......@@ -223,14 +224,14 @@ _LIBCPP_HIDE_FROM_ABI void __inplace_merge(
223224}
224225
225226template <class _BidirectionalIterator, class _Compare>
226inline _LIBCPP_HIDE_FROM_ABI void inplace_merge(
227inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void inplace_merge(
227228 _BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare __comp) {
228229 std::__inplace_merge<_ClassicAlgPolicy>(
229230 std::move(__first), std::move(__middle), std::move(__last), static_cast<__comp_ref_type<_Compare> >(__comp));
230231}
231232
232233template <class _BidirectionalIterator>
233inline _LIBCPP_HIDE_FROM_ABI void
234inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
234235inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last) {
235236 std::inplace_merge(std::move(__first), std::move(__middle), std::move(__last), __less<>());
236237}
lib/libcxx/include/__algorithm/min_element.h+1-1
......@@ -29,7 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2929
3030template <class _Comp, class _Iter, class _Sent, class _Proj>
3131inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter
32__min_element(_Iter __first, _Sent __last, _Comp __comp, _Proj& __proj) {
32__min_element(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
3333 if (__first == __last)
3434 return __first;
3535
lib/libcxx/include/__algorithm/move.h+10
......@@ -9,11 +9,13 @@
99#ifndef _LIBCPP___ALGORITHM_MOVE_H
1010#define _LIBCPP___ALGORITHM_MOVE_H
1111
12#include <__algorithm/copy.h>
1213#include <__algorithm/copy_move_common.h>
1314#include <__algorithm/for_each_segment.h>
1415#include <__algorithm/iterator_operations.h>
1516#include <__algorithm/min.h>
1617#include <__config>
18#include <__fwd/bit_reference.h>
1719#include <__iterator/iterator_traits.h>
1820#include <__iterator/segmented_iterator.h>
1921#include <__type_traits/common_type.h>
......@@ -98,6 +100,14 @@ struct __move_impl {
98100 }
99101 }
100102
103 template <class _Cp, bool _IsConst>
104 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> >
105 operator()(__bit_iterator<_Cp, _IsConst> __first,
106 __bit_iterator<_Cp, _IsConst> __last,
107 __bit_iterator<_Cp, false> __result) {
108 return std::__copy(__first, __last, __result);
109 }
110
101111 // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
102112 template <class _In, class _Out, __enable_if_t<__can_lower_move_assignment_to_memmove<_In, _Out>::value, int> = 0>
103113 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
lib/libcxx/include/__algorithm/move_backward.h+10
......@@ -9,10 +9,12 @@
99#ifndef _LIBCPP___ALGORITHM_MOVE_BACKWARD_H
1010#define _LIBCPP___ALGORITHM_MOVE_BACKWARD_H
1111
12#include <__algorithm/copy_backward.h>
1213#include <__algorithm/copy_move_common.h>
1314#include <__algorithm/iterator_operations.h>
1415#include <__algorithm/min.h>
1516#include <__config>
17#include <__fwd/bit_reference.h>
1618#include <__iterator/iterator_traits.h>
1719#include <__iterator/segmented_iterator.h>
1820#include <__type_traits/common_type.h>
......@@ -107,6 +109,14 @@ struct __move_backward_impl {
107109 }
108110 }
109111
112 template <class _Cp, bool _IsConst>
113 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> >
114 operator()(__bit_iterator<_Cp, _IsConst> __first,
115 __bit_iterator<_Cp, _IsConst> __last,
116 __bit_iterator<_Cp, false> __result) {
117 return std::__copy_backward<_ClassicAlgPolicy>(__first, __last, __result);
118 }
119
110120 // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
111121 template <class _In, class _Out, __enable_if_t<__can_lower_move_assignment_to_memmove<_In, _Out>::value, int> = 0>
112122 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
lib/libcxx/include/__algorithm/out_value_result.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___ALGORITHM_OUT_VALUE_RESULT_H
11#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
12
13#include <__concepts/convertible_to.h>
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
26#if _LIBCPP_STD_VER >= 23
27
28namespace ranges {
29
30template <class _OutIter1, class _ValType1>
31struct out_value_result {
32 _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
33 _LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value;
34
35 template <class _OutIter2, class _ValType2>
36 requires convertible_to<const _OutIter1&, _OutIter2> && convertible_to<const _ValType1&, _ValType2>
37 _LIBCPP_HIDE_FROM_ABI constexpr operator out_value_result<_OutIter2, _ValType2>() const& {
38 return {out, value};
39 }
40
41 template <class _OutIter2, class _ValType2>
42 requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, _ValType2>
43 _LIBCPP_HIDE_FROM_ABI constexpr operator out_value_result<_OutIter2, _ValType2>() && {
44 return {std::move(out), std::move(value)};
45 }
46};
47
48} // namespace ranges
49
50#endif // _LIBCPP_STD_VER >= 23
51
52_LIBCPP_END_NAMESPACE_STD
53
54_LIBCPP_POP_MACROS
55
56#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
lib/libcxx/include/__algorithm/radix_sort.h+111-14
......@@ -29,10 +29,12 @@
2929
3030#include <__algorithm/for_each.h>
3131#include <__algorithm/move.h>
32#include <__bit/bit_cast.h>
3233#include <__bit/bit_log2.h>
33#include <__bit/countl.h>
3434#include <__config>
35#include <__cstddef/size_t.h>
3536#include <__functional/identity.h>
37#include <__iterator/access.h>
3638#include <__iterator/distance.h>
3739#include <__iterator/iterator_traits.h>
3840#include <__iterator/move_iterator.h>
......@@ -43,9 +45,12 @@
4345#include <__type_traits/enable_if.h>
4446#include <__type_traits/invoke.h>
4547#include <__type_traits/is_assignable.h>
48#include <__type_traits/is_enum.h>
4649#include <__type_traits/is_integral.h>
4750#include <__type_traits/is_unsigned.h>
4851#include <__type_traits/make_unsigned.h>
52#include <__type_traits/void_t.h>
53#include <__utility/declval.h>
4954#include <__utility/forward.h>
5055#include <__utility/integer_sequence.h>
5156#include <__utility/move.h>
......@@ -67,7 +72,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
6772#if _LIBCPP_STD_VER >= 14
6873
6974template <class _InputIterator, class _OutputIterator>
70_LIBCPP_HIDE_FROM_ABI pair<_OutputIterator, __iter_value_type<_InputIterator>>
75_LIBCPP_HIDE_FROM_ABI constexpr pair<_OutputIterator, __iter_value_type<_InputIterator>>
7176__partial_sum_max(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
7277 if (__first == __last)
7378 return {__result, 0};
......@@ -109,7 +114,7 @@ struct __counting_sort_traits {
109114};
110115
111116template <class _Radix, class _Integer>
112_LIBCPP_HIDE_FROM_ABI auto __nth_radix(size_t __radix_number, _Radix __radix, _Integer __n) {
117_LIBCPP_HIDE_FROM_ABI constexpr auto __nth_radix(size_t __radix_number, _Radix __radix, _Integer __n) {
113118 static_assert(is_unsigned<_Integer>::value);
114119 using __traits = __counting_sort_traits<_Integer, _Radix>;
115120
......@@ -117,7 +122,7 @@ _LIBCPP_HIDE_FROM_ABI auto __nth_radix(size_t __radix_number, _Radix __radix, _I
117122}
118123
119124template <class _ForwardIterator, class _Map, class _RandomAccessIterator>
120_LIBCPP_HIDE_FROM_ABI void
125_LIBCPP_HIDE_FROM_ABI constexpr void
121126__collect(_ForwardIterator __first, _ForwardIterator __last, _Map __map, _RandomAccessIterator __counters) {
122127 using __value_type = __iter_value_type<_ForwardIterator>;
123128 using __traits = __counting_sort_traits<__value_type, _Map>;
......@@ -129,7 +134,7 @@ __collect(_ForwardIterator __first, _ForwardIterator __last, _Map __map, _Random
129134}
130135
131136template <class _ForwardIterator, class _RandomAccessIterator1, class _Map, class _RandomAccessIterator2>
132_LIBCPP_HIDE_FROM_ABI void
137_LIBCPP_HIDE_FROM_ABI constexpr void
133138__dispose(_ForwardIterator __first,
134139 _ForwardIterator __last,
135140 _RandomAccessIterator1 __result,
......@@ -147,7 +152,7 @@ template <class _ForwardIterator,
147152 class _RandomAccessIterator1,
148153 class _RandomAccessIterator2,
149154 size_t... _Radices>
150_LIBCPP_HIDE_FROM_ABI bool __collect_impl(
155_LIBCPP_HIDE_FROM_ABI constexpr bool __collect_impl(
151156 _ForwardIterator __first,
152157 _ForwardIterator __last,
153158 _Map __map,
......@@ -177,7 +182,7 @@ _LIBCPP_HIDE_FROM_ABI bool __collect_impl(
177182}
178183
179184template <class _ForwardIterator, class _Map, class _Radix, class _RandomAccessIterator1, class _RandomAccessIterator2>
180_LIBCPP_HIDE_FROM_ABI bool
185_LIBCPP_HIDE_FROM_ABI constexpr bool
181186__collect(_ForwardIterator __first,
182187 _ForwardIterator __last,
183188 _Map __map,
......@@ -191,7 +196,7 @@ __collect(_ForwardIterator __first,
191196}
192197
193198template <class _BidirectionalIterator, class _RandomAccessIterator1, class _Map, class _RandomAccessIterator2>
194_LIBCPP_HIDE_FROM_ABI void __dispose_backward(
199_LIBCPP_HIDE_FROM_ABI constexpr void __dispose_backward(
195200 _BidirectionalIterator __first,
196201 _BidirectionalIterator __last,
197202 _RandomAccessIterator1 __result,
......@@ -206,7 +211,7 @@ _LIBCPP_HIDE_FROM_ABI void __dispose_backward(
206211}
207212
208213template <class _ForwardIterator, class _RandomAccessIterator, class _Map>
209_LIBCPP_HIDE_FROM_ABI _RandomAccessIterator
214_LIBCPP_HIDE_FROM_ABI constexpr _RandomAccessIterator
210215__counting_sort_impl(_ForwardIterator __first, _ForwardIterator __last, _RandomAccessIterator __result, _Map __map) {
211216 using __value_type = __iter_value_type<_ForwardIterator>;
212217 using __traits = __counting_sort_traits<__value_type, _Map>;
......@@ -225,7 +230,7 @@ template <class _RandomAccessIterator1,
225230 class _Radix,
226231 enable_if_t< __radix_sort_traits<__iter_value_type<_RandomAccessIterator1>, _Map, _Radix>::__radix_count == 1,
227232 int> = 0>
228_LIBCPP_HIDE_FROM_ABI void __radix_sort_impl(
233_LIBCPP_HIDE_FROM_ABI constexpr void __radix_sort_impl(
229234 _RandomAccessIterator1 __first,
230235 _RandomAccessIterator1 __last,
231236 _RandomAccessIterator2 __buffer,
......@@ -245,7 +250,7 @@ template <
245250 class _Radix,
246251 enable_if_t< __radix_sort_traits<__iter_value_type<_RandomAccessIterator1>, _Map, _Radix>::__radix_count % 2 == 0,
247252 int> = 0 >
248_LIBCPP_HIDE_FROM_ABI void __radix_sort_impl(
253_LIBCPP_HIDE_FROM_ABI constexpr void __radix_sort_impl(
249254 _RandomAccessIterator1 __first,
250255 _RandomAccessIterator1 __last,
251256 _RandomAccessIterator2 __buffer_begin,
......@@ -297,6 +302,96 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto __shift_to_unsigned(_Ip __n) {
297302 return static_cast<make_unsigned_t<_Ip> >(__n ^ __min_value);
298303}
299304
305template <size_t _Size>
306struct __unsigned_integer_of_size;
307
308template <>
309struct __unsigned_integer_of_size<1> {
310 using type _LIBCPP_NODEBUG = uint8_t;
311};
312
313template <>
314struct __unsigned_integer_of_size<2> {
315 using type _LIBCPP_NODEBUG = uint16_t;
316};
317
318template <>
319struct __unsigned_integer_of_size<4> {
320 using type _LIBCPP_NODEBUG = uint32_t;
321};
322
323template <>
324struct __unsigned_integer_of_size<8> {
325 using type _LIBCPP_NODEBUG = uint64_t;
326};
327
328# if _LIBCPP_HAS_INT128
329template <>
330struct __unsigned_integer_of_size<16> {
331 using type _LIBCPP_NODEBUG = unsigned __int128;
332};
333# endif
334
335template <size_t _Size>
336using __unsigned_integer_of_size_t _LIBCPP_NODEBUG = typename __unsigned_integer_of_size<_Size>::type;
337
338template <class _Sc>
339using __unsigned_representation_for_t _LIBCPP_NODEBUG = __unsigned_integer_of_size_t<sizeof(_Sc)>;
340
341// The function `__to_ordered_integral` is defined for integers and IEEE 754 floating-point numbers.
342// Returns an integer representation such that for any `x` and `y` such that `x < y`, the expression
343// `__to_ordered_integral(x) < __to_ordered_integral(y)` is true, where `x`, `y` are integers or IEEE 754 floats.
344template <class _Integral, enable_if_t< is_integral<_Integral>::value, int> = 0>
345_LIBCPP_HIDE_FROM_ABI constexpr auto __to_ordered_integral(_Integral __n) {
346 return __n;
347}
348
349// An overload for IEEE 754 floating-point numbers
350
351// For the floats conforming to IEEE 754 (IEC 559) standard, we know that:
352// 1. The bit representation of positive floats directly reflects their order:
353// When comparing floats by magnitude, the number with the larger exponent is greater, and if the exponents are
354// equal, the one with the larger mantissa is greater.
355// 2. The bit representation of negative floats reflects their reverse order (for the same reasons).
356// 3. The most significant bit (sign bit) is zero for positive floats and one for negative floats. Therefore, in the raw
357// bit representation, any negative number will be greater than any positive number.
358
359// The only exception from this rule is `NaN`, which is unordered by definition.
360
361// Based on the above, to obtain correctly ordered integral representation of floating-point numbers, we need to:
362// 1. Invert the bit representation (including the sign bit) of negative floats to switch from reverse order to direct
363// order;
364// 2. Invert the sign bit for positive floats.
365
366// Thus, in final integral representation, we have reversed the order for negative floats and made all negative floats
367// smaller than all positive numbers (by inverting the sign bit).
368template <class _Floating, enable_if_t< numeric_limits<_Floating>::is_iec559, int> = 0>
369_LIBCPP_HIDE_FROM_ABI constexpr auto __to_ordered_integral(_Floating __f) {
370 using __integral_type = __unsigned_representation_for_t<_Floating>;
371 constexpr auto __bit_count = std::numeric_limits<__integral_type>::digits;
372 constexpr auto __sign_bit_mask = static_cast<__integral_type>(__integral_type{1} << (__bit_count - 1));
373
374 const auto __u = std::__bit_cast<__integral_type>(__f);
375
376 return static_cast<__integral_type>(__u & __sign_bit_mask ? ~__u : __u ^ __sign_bit_mask);
377}
378
379// There may exist user-defined comparison for enum, so we cannot compare enums just like integers.
380template <class _Enum, enable_if_t< is_enum<_Enum>::value, int> = 0>
381_LIBCPP_HIDE_FROM_ABI constexpr auto __to_ordered_integral(_Enum __e) = delete;
382
383// `long double` varies significantly across platforms and compilers, making it practically
384// impossible to determine its actual bit width for conversion to an ordered integer.
385inline _LIBCPP_HIDE_FROM_ABI constexpr auto __to_ordered_integral(long double) = delete;
386
387template <class _Tp, class = void>
388inline const bool __is_ordered_integer_representable_v = false;
389
390template <class _Tp>
391inline const bool
392 __is_ordered_integer_representable_v<_Tp, __void_t<decltype(std::__to_ordered_integral(std::declval<_Tp>()))>> =
393 true;
394
300395struct __low_byte_fn {
301396 template <class _Ip>
302397 _LIBCPP_HIDE_FROM_ABI constexpr uint8_t operator()(_Ip __integer) const {
......@@ -307,18 +402,20 @@ struct __low_byte_fn {
307402};
308403
309404template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _Map, class _Radix>
310_LIBCPP_HIDE_FROM_ABI void
405_LIBCPP_HIDE_FROM_ABI constexpr void
311406__radix_sort(_RandomAccessIterator1 __first,
312407 _RandomAccessIterator1 __last,
313408 _RandomAccessIterator2 __buffer,
314409 _Map __map,
315410 _Radix __radix) {
316 auto __map_to_unsigned = [__map = std::move(__map)](const auto& __x) { return std::__shift_to_unsigned(__map(__x)); };
411 auto __map_to_unsigned = [__map = std::move(__map)](const auto& __x) {
412 return std::__shift_to_unsigned(__map(std::__to_ordered_integral(__x)));
413 };
317414 std::__radix_sort_impl(__first, __last, __buffer, __map_to_unsigned, __radix);
318415}
319416
320417template <class _RandomAccessIterator1, class _RandomAccessIterator2>
321_LIBCPP_HIDE_FROM_ABI void
418_LIBCPP_HIDE_FROM_ABI constexpr void
322419__radix_sort(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __buffer) {
323420 std::__radix_sort(__first, __last, __buffer, __identity{}, __low_byte_fn{});
324421}
lib/libcxx/include/__algorithm/ranges_for_each.h+14-4
......@@ -9,10 +9,12 @@
99#ifndef _LIBCPP___ALGORITHM_RANGES_FOR_EACH_H
1010#define _LIBCPP___ALGORITHM_RANGES_FOR_EACH_H
1111
12#include <__algorithm/for_each.h>
13#include <__algorithm/for_each_n.h>
1214#include <__algorithm/in_fun_result.h>
15#include <__concepts/assignable.h>
1316#include <__config>
1417#include <__functional/identity.h>
15#include <__functional/invoke.h>
1618#include <__iterator/concepts.h>
1719#include <__iterator/projected.h>
1820#include <__ranges/access.h>
......@@ -41,9 +43,17 @@ private:
4143 template <class _Iter, class _Sent, class _Proj, class _Func>
4244 _LIBCPP_HIDE_FROM_ABI constexpr static for_each_result<_Iter, _Func>
4345 __for_each_impl(_Iter __first, _Sent __last, _Func& __func, _Proj& __proj) {
44 for (; __first != __last; ++__first)
45 std::invoke(__func, std::invoke(__proj, *__first));
46 return {std::move(__first), std::move(__func)};
46 // In the case where we have different iterator and sentinel types, the segmented iterator optimization
47 // in std::for_each will not kick in. Therefore, we prefer std::for_each_n in that case (whenever we can
48 // obtain the `n`).
49 if constexpr (!std::assignable_from<_Iter&, _Sent> && std::sized_sentinel_for<_Sent, _Iter>) {
50 auto __n = __last - __first;
51 auto __end = std::__for_each_n(std::move(__first), __n, __func, __proj);
52 return {std::move(__end), std::move(__func)};
53 } else {
54 auto __end = std::__for_each(std::move(__first), std::move(__last), __func, __proj);
55 return {std::move(__end), std::move(__func)};
56 }
4757 }
4858
4959public:
lib/libcxx/include/__algorithm/ranges_for_each_n.h+3-6
......@@ -9,10 +9,10 @@
99#ifndef _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H
1010#define _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H
1111
12#include <__algorithm/for_each_n.h>
1213#include <__algorithm/in_fun_result.h>
1314#include <__config>
1415#include <__functional/identity.h>
15#include <__functional/invoke.h>
1616#include <__iterator/concepts.h>
1717#include <__iterator/incrementable_traits.h>
1818#include <__iterator/iterator_traits.h>
......@@ -40,11 +40,8 @@ struct __for_each_n {
4040 template <input_iterator _Iter, class _Proj = identity, indirectly_unary_invocable<projected<_Iter, _Proj>> _Func>
4141 _LIBCPP_HIDE_FROM_ABI constexpr for_each_n_result<_Iter, _Func>
4242 operator()(_Iter __first, iter_difference_t<_Iter> __count, _Func __func, _Proj __proj = {}) const {
43 while (__count-- > 0) {
44 std::invoke(__func, std::invoke(__proj, *__first));
45 ++__first;
46 }
47 return {std::move(__first), std::move(__func)};
43 auto __last = std::__for_each_n(std::move(__first), __count, __func, __proj);
44 return {std::move(__last), std::move(__func)};
4845 }
4946};
5047
lib/libcxx/include/__algorithm/ranges_inplace_merge.h+3-3
......@@ -41,7 +41,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4141namespace ranges {
4242struct __inplace_merge {
4343 template <class _Iter, class _Sent, class _Comp, class _Proj>
44 _LIBCPP_HIDE_FROM_ABI static constexpr auto
44 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX26 auto
4545 __inplace_merge_impl(_Iter __first, _Iter __middle, _Sent __last, _Comp&& __comp, _Proj&& __proj) {
4646 auto __last_iter = ranges::next(__middle, __last);
4747 std::__inplace_merge<_RangeAlgPolicy>(
......@@ -51,7 +51,7 @@ struct __inplace_merge {
5151
5252 template <bidirectional_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
5353 requires sortable<_Iter, _Comp, _Proj>
54 _LIBCPP_HIDE_FROM_ABI _Iter
54 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _Iter
5555 operator()(_Iter __first, _Iter __middle, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
5656 return __inplace_merge_impl(
5757 std::move(__first), std::move(__middle), std::move(__last), std::move(__comp), std::move(__proj));
......@@ -59,7 +59,7 @@ struct __inplace_merge {
5959
6060 template <bidirectional_range _Range, class _Comp = ranges::less, class _Proj = identity>
6161 requires sortable<iterator_t<_Range>, _Comp, _Proj>
62 _LIBCPP_HIDE_FROM_ABI borrowed_iterator_t<_Range>
62 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 borrowed_iterator_t<_Range>
6363 operator()(_Range&& __range, iterator_t<_Range> __middle, _Comp __comp = {}, _Proj __proj = {}) const {
6464 return __inplace_merge_impl(
6565 ranges::begin(__range), std::move(__middle), ranges::end(__range), std::move(__comp), std::move(__proj));
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 _LIBCPP_NODEBUG = decltype(__get_iterator_concept<_Iter>());
47using __iterator_concept _LIBCPP_NODEBUG = decltype(ranges::__get_iterator_concept<_Iter>());
4848
4949} // namespace ranges
5050_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__algorithm/ranges_max.h+3-3
......@@ -9,7 +9,7 @@
99#ifndef _LIBCPP___ALGORITHM_RANGES_MAX_H
1010#define _LIBCPP___ALGORITHM_RANGES_MAX_H
1111
12#include <__algorithm/ranges_min_element.h>
12#include <__algorithm/min_element.h>
1313#include <__assert>
1414#include <__concepts/copyable.h>
1515#include <__config>
......@@ -57,7 +57,7 @@ struct __max {
5757 __il.begin() != __il.end(), "initializer_list must contain at least one element");
5858
5959 auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) -> bool { return std::invoke(__comp, __rhs, __lhs); };
60 return *ranges::__min_element_impl(__il.begin(), __il.end(), __comp_lhs_rhs_swapped, __proj);
60 return *std::__min_element(__il.begin(), __il.end(), __comp_lhs_rhs_swapped, __proj);
6161 }
6262
6363 template <input_range _Rp,
......@@ -75,7 +75,7 @@ struct __max {
7575 auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) -> bool {
7676 return std::invoke(__comp, __rhs, __lhs);
7777 };
78 return *ranges::__min_element_impl(std::move(__first), std::move(__last), __comp_lhs_rhs_swapped, __proj);
78 return *std::__min_element(std::move(__first), std::move(__last), __comp_lhs_rhs_swapped, __proj);
7979 } else {
8080 range_value_t<_Rp> __result = *__first;
8181 while (++__first != __last) {
lib/libcxx/include/__algorithm/ranges_max_element.h+3-3
......@@ -9,7 +9,7 @@
99#ifndef _LIBCPP___ALGORITHM_RANGES_MAX_ELEMENT_H
1010#define _LIBCPP___ALGORITHM_RANGES_MAX_ELEMENT_H
1111
12#include <__algorithm/ranges_min_element.h>
12#include <__algorithm/min_element.h>
1313#include <__config>
1414#include <__functional/identity.h>
1515#include <__functional/invoke.h>
......@@ -40,7 +40,7 @@ struct __max_element {
4040 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip
4141 operator()(_Ip __first, _Sp __last, _Comp __comp = {}, _Proj __proj = {}) const {
4242 auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) -> bool { return std::invoke(__comp, __rhs, __lhs); };
43 return ranges::__min_element_impl(__first, __last, __comp_lhs_rhs_swapped, __proj);
43 return std::__min_element(__first, __last, __comp_lhs_rhs_swapped, __proj);
4444 }
4545
4646 template <forward_range _Rp,
......@@ -49,7 +49,7 @@ struct __max_element {
4949 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Rp>
5050 operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
5151 auto __comp_lhs_rhs_swapped = [&](auto&& __lhs, auto&& __rhs) -> bool { return std::invoke(__comp, __rhs, __lhs); };
52 return ranges::__min_element_impl(ranges::begin(__r), ranges::end(__r), __comp_lhs_rhs_swapped, __proj);
52 return std::__min_element(ranges::begin(__r), ranges::end(__r), __comp_lhs_rhs_swapped, __proj);
5353 }
5454};
5555
lib/libcxx/include/__algorithm/ranges_min.h+3-3
......@@ -9,7 +9,7 @@
99#ifndef _LIBCPP___ALGORITHM_RANGES_MIN_H
1010#define _LIBCPP___ALGORITHM_RANGES_MIN_H
1111
12#include <__algorithm/ranges_min_element.h>
12#include <__algorithm/min_element.h>
1313#include <__assert>
1414#include <__concepts/copyable.h>
1515#include <__config>
......@@ -54,7 +54,7 @@ struct __min {
5454 operator()(initializer_list<_Tp> __il, _Comp __comp = {}, _Proj __proj = {}) const {
5555 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
5656 __il.begin() != __il.end(), "initializer_list must contain at least one element");
57 return *ranges::__min_element_impl(__il.begin(), __il.end(), __comp, __proj);
57 return *std::__min_element(__il.begin(), __il.end(), __comp, __proj);
5858 }
5959
6060 template <input_range _Rp,
......@@ -67,7 +67,7 @@ struct __min {
6767 auto __last = ranges::end(__r);
6868 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__first != __last, "range must contain at least one element");
6969 if constexpr (forward_range<_Rp> && !__is_cheap_to_copy<range_value_t<_Rp>>) {
70 return *ranges::__min_element_impl(__first, __last, __comp, __proj);
70 return *std::__min_element(__first, __last, __comp, __proj);
7171 } else {
7272 range_value_t<_Rp> __result = *__first;
7373 while (++__first != __last) {
lib/libcxx/include/__algorithm/ranges_min_element.h+3-16
......@@ -9,6 +9,7 @@
99#ifndef _LIBCPP___ALGORITHM_RANGES_MIN_ELEMENT_H
1010#define _LIBCPP___ALGORITHM_RANGES_MIN_ELEMENT_H
1111
12#include <__algorithm/min_element.h>
1213#include <__config>
1314#include <__functional/identity.h>
1415#include <__functional/invoke.h>
......@@ -32,20 +33,6 @@ _LIBCPP_PUSH_MACROS
3233_LIBCPP_BEGIN_NAMESPACE_STD
3334
3435namespace ranges {
35
36// TODO(ranges): `ranges::min_element` can now simply delegate to `std::__min_element`.
37template <class _Ip, class _Sp, class _Proj, class _Comp>
38_LIBCPP_HIDE_FROM_ABI constexpr _Ip __min_element_impl(_Ip __first, _Sp __last, _Comp& __comp, _Proj& __proj) {
39 if (__first == __last)
40 return __first;
41
42 _Ip __i = __first;
43 while (++__i != __last)
44 if (std::invoke(__comp, std::invoke(__proj, *__i), std::invoke(__proj, *__first)))
45 __first = __i;
46 return __first;
47}
48
4936struct __min_element {
5037 template <forward_iterator _Ip,
5138 sentinel_for<_Ip> _Sp,
......@@ -53,7 +40,7 @@ struct __min_element {
5340 indirect_strict_weak_order<projected<_Ip, _Proj>> _Comp = ranges::less>
5441 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip
5542 operator()(_Ip __first, _Sp __last, _Comp __comp = {}, _Proj __proj = {}) const {
56 return ranges::__min_element_impl(__first, __last, __comp, __proj);
43 return std::__min_element(__first, __last, __comp, __proj);
5744 }
5845
5946 template <forward_range _Rp,
......@@ -61,7 +48,7 @@ struct __min_element {
6148 indirect_strict_weak_order<projected<iterator_t<_Rp>, _Proj>> _Comp = ranges::less>
6249 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Rp>
6350 operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
64 return ranges::__min_element_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj);
51 return std::__min_element(ranges::begin(__r), ranges::end(__r), __comp, __proj);
6552 }
6653};
6754
lib/libcxx/include/__algorithm/ranges_stable_partition.h+4-3
......@@ -44,7 +44,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4444namespace ranges {
4545struct __stable_partition {
4646 template <class _Iter, class _Sent, class _Proj, class _Pred>
47 _LIBCPP_HIDE_FROM_ABI static subrange<__remove_cvref_t<_Iter>>
47 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX26 subrange<__remove_cvref_t<_Iter>>
4848 __stable_partition_fn_impl(_Iter&& __first, _Sent&& __last, _Pred&& __pred, _Proj&& __proj) {
4949 auto __last_iter = ranges::next(__first, __last);
5050
......@@ -60,7 +60,8 @@ struct __stable_partition {
6060 class _Proj = identity,
6161 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
6262 requires permutable<_Iter>
63 _LIBCPP_HIDE_FROM_ABI subrange<_Iter> operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const {
63 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 subrange<_Iter>
64 operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const {
6465 return __stable_partition_fn_impl(__first, __last, __pred, __proj);
6566 }
6667
......@@ -68,7 +69,7 @@ struct __stable_partition {
6869 class _Proj = identity,
6970 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
7071 requires permutable<iterator_t<_Range>>
71 _LIBCPP_HIDE_FROM_ABI borrowed_subrange_t<_Range>
72 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 borrowed_subrange_t<_Range>
7273 operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
7374 return __stable_partition_fn_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
7475 }
lib/libcxx/include/__algorithm/ranges_stable_sort.h+5-3
......@@ -41,7 +41,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4141namespace ranges {
4242struct __stable_sort {
4343 template <class _Iter, class _Sent, class _Comp, class _Proj>
44 _LIBCPP_HIDE_FROM_ABI static _Iter __stable_sort_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
44 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX26 _Iter
45 __stable_sort_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
4546 auto __last_iter = ranges::next(__first, __last);
4647
4748 auto&& __projected_comp = std::__make_projected(__comp, __proj);
......@@ -52,13 +53,14 @@ struct __stable_sort {
5253
5354 template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
5455 requires sortable<_Iter, _Comp, _Proj>
55 _LIBCPP_HIDE_FROM_ABI _Iter operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
56 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _Iter
57 operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
5658 return __stable_sort_fn_impl(std::move(__first), std::move(__last), __comp, __proj);
5759 }
5860
5961 template <random_access_range _Range, class _Comp = ranges::less, class _Proj = identity>
6062 requires sortable<iterator_t<_Range>, _Comp, _Proj>
61 _LIBCPP_HIDE_FROM_ABI borrowed_iterator_t<_Range>
63 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 borrowed_iterator_t<_Range>
6264 operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
6365 return __stable_sort_fn_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj);
6466 }
lib/libcxx/include/__algorithm/rotate.h+45
......@@ -9,12 +9,19 @@
99#ifndef _LIBCPP___ALGORITHM_ROTATE_H
1010#define _LIBCPP___ALGORITHM_ROTATE_H
1111
12#include <__algorithm/copy.h>
13#include <__algorithm/copy_backward.h>
1214#include <__algorithm/iterator_operations.h>
1315#include <__algorithm/move.h>
1416#include <__algorithm/move_backward.h>
1517#include <__algorithm/swap_ranges.h>
1618#include <__config>
19#include <__cstddef/size_t.h>
20#include <__fwd/bit_reference.h>
1721#include <__iterator/iterator_traits.h>
22#include <__memory/construct_at.h>
23#include <__memory/pointer_traits.h>
24#include <__type_traits/is_constant_evaluated.h>
1825#include <__type_traits/is_trivially_assignable.h>
1926#include <__utility/move.h>
2027#include <__utility/pair.h>
......@@ -185,6 +192,44 @@ __rotate(_Iterator __first, _Iterator __middle, _Sentinel __last) {
185192 return _Ret(std::move(__result), std::move(__last_iter));
186193}
187194
195template <class, class _Cp>
196_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cp, false>, __bit_iterator<_Cp, false> >
197__rotate(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __middle, __bit_iterator<_Cp, false> __last) {
198 using _I1 = __bit_iterator<_Cp, false>;
199 using difference_type = typename _I1::difference_type;
200 difference_type __d1 = __middle - __first;
201 difference_type __d2 = __last - __middle;
202 _I1 __r = __first + __d2;
203 while (__d1 != 0 && __d2 != 0) {
204 if (__d1 <= __d2) {
205 if (__d1 <= __bit_array<_Cp>::capacity()) {
206 __bit_array<_Cp> __b(__d1);
207 std::copy(__first, __middle, __b.begin());
208 std::copy(__b.begin(), __b.end(), std::copy(__middle, __last, __first));
209 break;
210 } else {
211 __bit_iterator<_Cp, false> __mp = std::swap_ranges(__first, __middle, __middle);
212 __first = __middle;
213 __middle = __mp;
214 __d2 -= __d1;
215 }
216 } else {
217 if (__d2 <= __bit_array<_Cp>::capacity()) {
218 __bit_array<_Cp> __b(__d2);
219 std::copy(__middle, __last, __b.begin());
220 std::copy_backward(__b.begin(), __b.end(), std::copy_backward(__first, __middle, __last));
221 break;
222 } else {
223 __bit_iterator<_Cp, false> __mp = __first + __d2;
224 std::swap_ranges(__first, __mp, __middle);
225 __first = __mp;
226 __d1 -= __d2;
227 }
228 }
229 }
230 return std::make_pair(__r, __last);
231}
232
188233template <class _ForwardIterator>
189234inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
190235rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) {
lib/libcxx/include/__algorithm/simd_utils.h+8-8
......@@ -15,8 +15,6 @@
1515#include <__bit/countr.h>
1616#include <__config>
1717#include <__cstddef/size_t.h>
18#include <__type_traits/is_arithmetic.h>
19#include <__type_traits/is_same.h>
2018#include <__utility/integer_sequence.h>
2119#include <cstdint>
2220
......@@ -28,7 +26,9 @@ _LIBCPP_PUSH_MACROS
2826#include <__undef_macros>
2927
3028// TODO: Find out how altivec changes things and allow vectorizations there too.
31#if _LIBCPP_STD_VER >= 14 && defined(_LIBCPP_CLANG_VER) && !defined(__ALTIVEC__)
29// TODO: Simplify this condition once we stop building with AppleClang 15 in the CI.
30#if _LIBCPP_STD_VER >= 14 && defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(__ALTIVEC__) && \
31 !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1600)
3232# define _LIBCPP_HAS_ALGORITHM_VECTOR_UTILS 1
3333#else
3434# define _LIBCPP_HAS_ALGORITHM_VECTOR_UTILS 0
......@@ -53,20 +53,20 @@ struct __get_as_integer_type_impl;
5353
5454template <>
5555struct __get_as_integer_type_impl<1> {
56 using type = uint8_t;
56 using type _LIBCPP_NODEBUG = uint8_t;
5757};
5858
5959template <>
6060struct __get_as_integer_type_impl<2> {
61 using type = uint16_t;
61 using type _LIBCPP_NODEBUG = uint16_t;
6262};
6363template <>
6464struct __get_as_integer_type_impl<4> {
65 using type = uint32_t;
65 using type _LIBCPP_NODEBUG = uint32_t;
6666};
6767template <>
6868struct __get_as_integer_type_impl<8> {
69 using type = uint64_t;
69 using type _LIBCPP_NODEBUG = uint64_t;
7070};
7171
7272template <class _Tp>
......@@ -78,7 +78,7 @@ using __get_as_integer_type_t _LIBCPP_NODEBUG = typename __get_as_integer_type_i
7878# if defined(__AVX__) || defined(__MVS__)
7979template <class _Tp>
8080inline constexpr size_t __native_vector_size = 32 / sizeof(_Tp);
81# elif defined(__SSE__) || defined(__ARM_NEON__)
81# elif defined(__SSE__) || defined(__ARM_NEON)
8282template <class _Tp>
8383inline constexpr size_t __native_vector_size = 16 / sizeof(_Tp);
8484# elif defined(__MMX__)
lib/libcxx/include/__algorithm/sort.h+10-29
......@@ -17,6 +17,7 @@
1717#include <__algorithm/partial_sort.h>
1818#include <__algorithm/unwrap_iter.h>
1919#include <__assert>
20#include <__bit/bit_log2.h>
2021#include <__bit/blsr.h>
2122#include <__bit/countl.h>
2223#include <__bit/countr.h>
......@@ -34,7 +35,7 @@
3435#include <__type_traits/is_constant_evaluated.h>
3536#include <__type_traits/is_same.h>
3637#include <__type_traits/is_trivially_copyable.h>
37#include <__type_traits/remove_cvref.h>
38#include <__type_traits/make_unsigned.h>
3839#include <__utility/move.h>
3940#include <__utility/pair.h>
4041#include <climits>
......@@ -52,8 +53,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
5253template <class _Compare, class _Iter, class _Tp = typename iterator_traits<_Iter>::value_type>
5354inline const bool __use_branchless_sort =
5455 __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>);
56 (__desugars_to_v<__less_tag, _Compare, _Tp, _Tp> || __desugars_to_v<__greater_tag, _Compare, _Tp, _Tp>);
5757
5858namespace __detail {
5959
......@@ -359,10 +359,10 @@ inline _LIBCPP_HIDE_FROM_ABI void __swap_bitmap_pos(
359359 // Swap one pair on each iteration as long as both bitsets have at least one
360360 // element for swapping.
361361 while (__left_bitset != 0 && __right_bitset != 0) {
362 difference_type __tz_left = __libcpp_ctz(__left_bitset);
363 __left_bitset = __libcpp_blsr(__left_bitset);
364 difference_type __tz_right = __libcpp_ctz(__right_bitset);
365 __right_bitset = __libcpp_blsr(__right_bitset);
362 difference_type __tz_left = std::__countr_zero(__left_bitset);
363 __left_bitset = std::__libcpp_blsr(__left_bitset);
364 difference_type __tz_right = std::__countr_zero(__right_bitset);
365 __right_bitset = std::__libcpp_blsr(__right_bitset);
366366 _Ops::iter_swap(__first + __tz_left, __last - __tz_right);
367367 }
368368}
......@@ -458,7 +458,7 @@ inline _LIBCPP_HIDE_FROM_ABI void __swap_bitmap_pos_within(
458458 // Swap within the left side. Need to find set positions in the reverse
459459 // order.
460460 while (__left_bitset != 0) {
461 difference_type __tz_left = __detail::__block_size - 1 - __libcpp_clz(__left_bitset);
461 difference_type __tz_left = __detail::__block_size - 1 - std::__countl_zero(__left_bitset);
462462 __left_bitset &= (static_cast<uint64_t>(1) << __tz_left) - 1;
463463 _RandomAccessIterator __it = __first + __tz_left;
464464 if (__it != __lm1) {
......@@ -471,7 +471,7 @@ inline _LIBCPP_HIDE_FROM_ABI void __swap_bitmap_pos_within(
471471 // Swap within the right side. Need to find set positions in the reverse
472472 // order.
473473 while (__right_bitset != 0) {
474 difference_type __tz_right = __detail::__block_size - 1 - __libcpp_clz(__right_bitset);
474 difference_type __tz_right = __detail::__block_size - 1 - std::__countl_zero(__right_bitset);
475475 __right_bitset &= (static_cast<uint64_t>(1) << __tz_right) - 1;
476476 _RandomAccessIterator __it = __lm1 - __tz_right;
477477 if (__it != __first) {
......@@ -828,25 +828,6 @@ void __introsort(_RandomAccessIterator __first,
828828 }
829829}
830830
831template <typename _Number>
832inline _LIBCPP_HIDE_FROM_ABI _Number __log2i(_Number __n) {
833 if (__n == 0)
834 return 0;
835 if (sizeof(__n) <= sizeof(unsigned))
836 return sizeof(unsigned) * CHAR_BIT - 1 - __libcpp_clz(static_cast<unsigned>(__n));
837 if (sizeof(__n) <= sizeof(unsigned long))
838 return sizeof(unsigned long) * CHAR_BIT - 1 - __libcpp_clz(static_cast<unsigned long>(__n));
839 if (sizeof(__n) <= sizeof(unsigned long long))
840 return sizeof(unsigned long long) * CHAR_BIT - 1 - __libcpp_clz(static_cast<unsigned long long>(__n));
841
842 _Number __log2 = 0;
843 while (__n > 1) {
844 __log2++;
845 __n >>= 1;
846 }
847 return __log2;
848}
849
850831template <class _Comp, class _RandomAccessIterator>
851832void __sort(_RandomAccessIterator, _RandomAccessIterator, _Comp);
852833
......@@ -880,7 +861,7 @@ template <class _AlgPolicy, class _RandomAccessIterator, class _Comp>
880861_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
881862__sort_dispatch(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) {
882863 typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
883 difference_type __depth_limit = 2 * std::__log2i(__last - __first);
864 difference_type __depth_limit = 2 * std::__bit_log2(std::__to_unsigned_like(__last - __first));
884865
885866 // Only use bitset partitioning for arithmetic types. We should also check
886867 // that the default comparator is in use so that we are sure that there are no
lib/libcxx/include/__algorithm/stable_partition.h+11-10
......@@ -16,6 +16,7 @@
1616#include <__iterator/advance.h>
1717#include <__iterator/distance.h>
1818#include <__iterator/iterator_traits.h>
19#include <__memory/construct_at.h>
1920#include <__memory/destruct_n.h>
2021#include <__memory/unique_ptr.h>
2122#include <__memory/unique_temporary_buffer.h>
......@@ -33,7 +34,7 @@ _LIBCPP_PUSH_MACROS
3334_LIBCPP_BEGIN_NAMESPACE_STD
3435
3536template <class _AlgPolicy, class _Predicate, class _ForwardIterator, class _Distance, class _Pair>
36_LIBCPP_HIDE_FROM_ABI _ForwardIterator __stable_partition_impl(
37_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator __stable_partition_impl(
3738 _ForwardIterator __first,
3839 _ForwardIterator __last,
3940 _Predicate __pred,
......@@ -61,7 +62,7 @@ _LIBCPP_HIDE_FROM_ABI _ForwardIterator __stable_partition_impl(
6162 // Move the falses into the temporary buffer, and the trues to the front of the line
6263 // Update __first to always point to the end of the trues
6364 value_type* __t = __p.first;
64 ::new ((void*)__t) value_type(_Ops::__iter_move(__first));
65 std::__construct_at(__t, _Ops::__iter_move(__first));
6566 __d.template __incr<value_type>();
6667 ++__t;
6768 _ForwardIterator __i = __first;
......@@ -70,7 +71,7 @@ _LIBCPP_HIDE_FROM_ABI _ForwardIterator __stable_partition_impl(
7071 *__first = _Ops::__iter_move(__i);
7172 ++__first;
7273 } else {
73 ::new ((void*)__t) value_type(_Ops::__iter_move(__i));
74 std::__construct_at(__t, _Ops::__iter_move(__i));
7475 __d.template __incr<value_type>();
7576 ++__t;
7677 }
......@@ -116,7 +117,7 @@ __second_half_done:
116117}
117118
118119template <class _AlgPolicy, class _Predicate, class _ForwardIterator>
119_LIBCPP_HIDE_FROM_ABI _ForwardIterator
120_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator
120121__stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag) {
121122 typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
122123 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
......@@ -145,7 +146,7 @@ __stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Pred
145146}
146147
147148template <class _AlgPolicy, class _Predicate, class _BidirectionalIterator, class _Distance, class _Pair>
148_BidirectionalIterator __stable_partition_impl(
149_LIBCPP_CONSTEXPR_SINCE_CXX26 _BidirectionalIterator __stable_partition_impl(
149150 _BidirectionalIterator __first,
150151 _BidirectionalIterator __last,
151152 _Predicate __pred,
......@@ -179,7 +180,7 @@ _BidirectionalIterator __stable_partition_impl(
179180 // Move the falses into the temporary buffer, and the trues to the front of the line
180181 // Update __first to always point to the end of the trues
181182 value_type* __t = __p.first;
182 ::new ((void*)__t) value_type(_Ops::__iter_move(__first));
183 std::__construct_at(__t, _Ops::__iter_move(__first));
183184 __d.template __incr<value_type>();
184185 ++__t;
185186 _BidirectionalIterator __i = __first;
......@@ -188,7 +189,7 @@ _BidirectionalIterator __stable_partition_impl(
188189 *__first = _Ops::__iter_move(__i);
189190 ++__first;
190191 } else {
191 ::new ((void*)__t) value_type(_Ops::__iter_move(__i));
192 std::__construct_at(__t, _Ops::__iter_move(__i));
192193 __d.template __incr<value_type>();
193194 ++__t;
194195 }
......@@ -247,7 +248,7 @@ __second_half_done:
247248}
248249
249250template <class _AlgPolicy, class _Predicate, class _BidirectionalIterator>
250_LIBCPP_HIDE_FROM_ABI _BidirectionalIterator __stable_partition_impl(
251_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _BidirectionalIterator __stable_partition_impl(
251252 _BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, bidirectional_iterator_tag) {
252253 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
253254 typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
......@@ -283,14 +284,14 @@ _LIBCPP_HIDE_FROM_ABI _BidirectionalIterator __stable_partition_impl(
283284}
284285
285286template <class _AlgPolicy, class _Predicate, class _ForwardIterator, class _IterCategory>
286_LIBCPP_HIDE_FROM_ABI _ForwardIterator __stable_partition(
287_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator __stable_partition(
287288 _ForwardIterator __first, _ForwardIterator __last, _Predicate&& __pred, _IterCategory __iter_category) {
288289 return std::__stable_partition_impl<_AlgPolicy, __remove_cvref_t<_Predicate>&>(
289290 std::move(__first), std::move(__last), __pred, __iter_category);
290291}
291292
292293template <class _ForwardIterator, class _Predicate>
293inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator
294_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX26 _ForwardIterator
294295stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
295296 using _IterCategory = typename iterator_traits<_ForwardIterator>::iterator_category;
296297 return std::__stable_partition<_ClassicAlgPolicy, _Predicate&>(
lib/libcxx/include/__algorithm/stable_sort.h+16-12
......@@ -25,10 +25,9 @@
2525#include <__memory/unique_temporary_buffer.h>
2626#include <__type_traits/desugars_to.h>
2727#include <__type_traits/enable_if.h>
28#include <__type_traits/is_integral.h>
28#include <__type_traits/is_constant_evaluated.h>
2929#include <__type_traits/is_same.h>
3030#include <__type_traits/is_trivially_assignable.h>
31#include <__type_traits/remove_cvref.h>
3231#include <__utility/move.h>
3332#include <__utility/pair.h>
3433
......@@ -201,7 +200,7 @@ struct __stable_sort_switch {
201200#if _LIBCPP_STD_VER >= 17
202201template <class _Tp>
203202_LIBCPP_HIDE_FROM_ABI constexpr unsigned __radix_sort_min_bound() {
204 static_assert(is_integral<_Tp>::value);
203 static_assert(__is_ordered_integer_representable_v<_Tp>);
205204 if constexpr (sizeof(_Tp) == 1) {
206205 return 1 << 8;
207206 }
......@@ -211,7 +210,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr unsigned __radix_sort_min_bound() {
211210
212211template <class _Tp>
213212_LIBCPP_HIDE_FROM_ABI constexpr unsigned __radix_sort_max_bound() {
214 static_assert(is_integral<_Tp>::value);
213 static_assert(__is_ordered_integer_representable_v<_Tp>);
215214 if constexpr (sizeof(_Tp) >= 8) {
216215 return 1 << 15;
217216 }
......@@ -245,14 +244,19 @@ _LIBCPP_CONSTEXPR_SINCE_CXX26 void __stable_sort(
245244 }
246245
247246#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>())) {
247 constexpr auto __default_comp = __desugars_to_v<__less_tag, _Compare, value_type, value_type >;
248 constexpr auto __radix_sortable =
249 __is_ordered_integer_representable_v<value_type> &&
250 is_same_v< value_type&, __iter_reference<_RandomAccessIterator>>;
251 if constexpr (__default_comp && __radix_sortable) {
252 if (__len <= __buff_size && __len >= static_cast<difference_type>(std::__radix_sort_min_bound<value_type>()) &&
253 __len <= static_cast<difference_type>(std::__radix_sort_max_bound<value_type>())) {
254 if (__libcpp_is_constant_evaluated()) {
255 for (auto* __p = __buff; __p < __buff + __buff_size; ++__p) {
256 std::__construct_at(__p);
257 }
258 }
259
256260 std::__radix_sort(__first, __last, __buff);
257261 return;
258262 }
lib/libcxx/include/__algorithm/swap_ranges.h+162
......@@ -10,9 +10,12 @@
1010#define _LIBCPP___ALGORITHM_SWAP_RANGES_H
1111
1212#include <__algorithm/iterator_operations.h>
13#include <__algorithm/min.h>
1314#include <__config>
15#include <__fwd/bit_reference.h>
1416#include <__utility/move.h>
1517#include <__utility/pair.h>
18#include <__utility/swap.h>
1619
1720#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1821# pragma GCC system_header
......@@ -23,6 +26,165 @@ _LIBCPP_PUSH_MACROS
2326
2427_LIBCPP_BEGIN_NAMESPACE_STD
2528
29template <class _Cl, class _Cr>
30_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cr, false> __swap_ranges_aligned(
31 __bit_iterator<_Cl, false> __first, __bit_iterator<_Cl, false> __last, __bit_iterator<_Cr, false> __result) {
32 using _I1 = __bit_iterator<_Cl, false>;
33 using difference_type = typename _I1::difference_type;
34 using __storage_type = typename _I1::__storage_type;
35
36 const int __bits_per_word = _I1::__bits_per_word;
37 difference_type __n = __last - __first;
38 if (__n > 0) {
39 // do first word
40 if (__first.__ctz_ != 0) {
41 unsigned __clz = __bits_per_word - __first.__ctz_;
42 difference_type __dn = std::min(static_cast<difference_type>(__clz), __n);
43 __n -= __dn;
44 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn));
45 __storage_type __b1 = *__first.__seg_ & __m;
46 *__first.__seg_ &= ~__m;
47 __storage_type __b2 = *__result.__seg_ & __m;
48 *__result.__seg_ &= ~__m;
49 *__result.__seg_ |= __b1;
50 *__first.__seg_ |= __b2;
51 __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
52 __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
53 ++__first.__seg_;
54 // __first.__ctz_ = 0;
55 }
56 // __first.__ctz_ == 0;
57 // do middle words
58 for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_, ++__result.__seg_)
59 swap(*__first.__seg_, *__result.__seg_);
60 // do last word
61 if (__n > 0) {
62 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
63 __storage_type __b1 = *__first.__seg_ & __m;
64 *__first.__seg_ &= ~__m;
65 __storage_type __b2 = *__result.__seg_ & __m;
66 *__result.__seg_ &= ~__m;
67 *__result.__seg_ |= __b1;
68 *__first.__seg_ |= __b2;
69 __result.__ctz_ = static_cast<unsigned>(__n);
70 }
71 }
72 return __result;
73}
74
75template <class _Cl, class _Cr>
76_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cr, false> __swap_ranges_unaligned(
77 __bit_iterator<_Cl, false> __first, __bit_iterator<_Cl, false> __last, __bit_iterator<_Cr, false> __result) {
78 using _I1 = __bit_iterator<_Cl, false>;
79 using difference_type = typename _I1::difference_type;
80 using __storage_type = typename _I1::__storage_type;
81
82 const int __bits_per_word = _I1::__bits_per_word;
83 difference_type __n = __last - __first;
84 if (__n > 0) {
85 // do first word
86 if (__first.__ctz_ != 0) {
87 unsigned __clz_f = __bits_per_word - __first.__ctz_;
88 difference_type __dn = std::min(static_cast<difference_type>(__clz_f), __n);
89 __n -= __dn;
90 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
91 __storage_type __b1 = *__first.__seg_ & __m;
92 *__first.__seg_ &= ~__m;
93 unsigned __clz_r = __bits_per_word - __result.__ctz_;
94 __storage_type __ddn = std::min<__storage_type>(__dn, __clz_r);
95 __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn));
96 __storage_type __b2 = *__result.__seg_ & __m;
97 *__result.__seg_ &= ~__m;
98 if (__result.__ctz_ > __first.__ctz_) {
99 unsigned __s = __result.__ctz_ - __first.__ctz_;
100 *__result.__seg_ |= __b1 << __s;
101 *__first.__seg_ |= __b2 >> __s;
102 } else {
103 unsigned __s = __first.__ctz_ - __result.__ctz_;
104 *__result.__seg_ |= __b1 >> __s;
105 *__first.__seg_ |= __b2 << __s;
106 }
107 __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word;
108 __result.__ctz_ = static_cast<unsigned>((__ddn + __result.__ctz_) % __bits_per_word);
109 __dn -= __ddn;
110 if (__dn > 0) {
111 __m = ~__storage_type(0) >> (__bits_per_word - __dn);
112 __b2 = *__result.__seg_ & __m;
113 *__result.__seg_ &= ~__m;
114 unsigned __s = __first.__ctz_ + __ddn;
115 *__result.__seg_ |= __b1 >> __s;
116 *__first.__seg_ |= __b2 << __s;
117 __result.__ctz_ = static_cast<unsigned>(__dn);
118 }
119 ++__first.__seg_;
120 // __first.__ctz_ = 0;
121 }
122 // __first.__ctz_ == 0;
123 // do middle words
124 __storage_type __m = ~__storage_type(0) << __result.__ctz_;
125 unsigned __clz_r = __bits_per_word - __result.__ctz_;
126 for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) {
127 __storage_type __b1 = *__first.__seg_;
128 __storage_type __b2 = *__result.__seg_ & __m;
129 *__result.__seg_ &= ~__m;
130 *__result.__seg_ |= __b1 << __result.__ctz_;
131 *__first.__seg_ = __b2 >> __result.__ctz_;
132 ++__result.__seg_;
133 __b2 = *__result.__seg_ & ~__m;
134 *__result.__seg_ &= __m;
135 *__result.__seg_ |= __b1 >> __clz_r;
136 *__first.__seg_ |= __b2 << __clz_r;
137 }
138 // do last word
139 if (__n > 0) {
140 __m = ~__storage_type(0) >> (__bits_per_word - __n);
141 __storage_type __b1 = *__first.__seg_ & __m;
142 *__first.__seg_ &= ~__m;
143 __storage_type __dn = std::min<__storage_type>(__n, __clz_r);
144 __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn));
145 __storage_type __b2 = *__result.__seg_ & __m;
146 *__result.__seg_ &= ~__m;
147 *__result.__seg_ |= __b1 << __result.__ctz_;
148 *__first.__seg_ |= __b2 >> __result.__ctz_;
149 __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
150 __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
151 __n -= __dn;
152 if (__n > 0) {
153 __m = ~__storage_type(0) >> (__bits_per_word - __n);
154 __b2 = *__result.__seg_ & __m;
155 *__result.__seg_ &= ~__m;
156 *__result.__seg_ |= __b1 >> __dn;
157 *__first.__seg_ |= __b2 << __dn;
158 __result.__ctz_ = static_cast<unsigned>(__n);
159 }
160 }
161 }
162 return __result;
163}
164
165// 2+1 iterators: size2 >= size1; used by std::swap_ranges.
166template <class, class _Cl, class _Cr>
167_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cl, false>, __bit_iterator<_Cr, false> >
168__swap_ranges(__bit_iterator<_Cl, false> __first1,
169 __bit_iterator<_Cl, false> __last1,
170 __bit_iterator<_Cr, false> __first2) {
171 if (__first1.__ctz_ == __first2.__ctz_)
172 return std::make_pair(__last1, std::__swap_ranges_aligned(__first1, __last1, __first2));
173 return std::make_pair(__last1, std::__swap_ranges_unaligned(__first1, __last1, __first2));
174}
175
176// 2+2 iterators: used by std::ranges::swap_ranges.
177template <class _AlgPolicy, class _Cl, class _Cr>
178_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cl, false>, __bit_iterator<_Cr, false> >
179__swap_ranges(__bit_iterator<_Cl, false> __first1,
180 __bit_iterator<_Cl, false> __last1,
181 __bit_iterator<_Cr, false> __first2,
182 __bit_iterator<_Cr, false> __last2) {
183 if (__last1 - __first1 < __last2 - __first2)
184 return std::make_pair(__last1, std::__swap_ranges<_AlgPolicy>(__first1, __last1, __first2).second);
185 return std::make_pair(std::__swap_ranges<_AlgPolicy>(__first2, __last2, __first1).second, __last2);
186}
187
26188// 2+2 iterators: the shorter size will be used.
27189template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2, class _Sentinel2>
28190_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator1, _ForwardIterator2>
lib/libcxx/include/__assert+2-2
......@@ -20,8 +20,8 @@
2020#define _LIBCPP_ASSERT(expression, message) \
2121 (__builtin_expect(static_cast<bool>(expression), 1) \
2222 ? (void)0 \
23 : _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING(__LINE__) ": assertion " _LIBCPP_TOSTRING( \
24 expression) " failed: " message "\n"))
23 : _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING( \
24 __LINE__) ": libc++ Hardening assertion " _LIBCPP_TOSTRING(expression) " failed: " message "\n"))
2525
2626// WARNING: __builtin_assume can currently inhibit optimizations. Only add assumptions with a clear
2727// optimization intent. See https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609 for a
lib/libcxx/include/__assertion_handler+3-12
......@@ -13,9 +13,11 @@
1313#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
1414# include <__cxx03/__config>
1515# include <__cxx03/__verbose_abort>
16# include <__cxx03/__verbose_trap>
1617#else
1718# include <__config>
1819# include <__verbose_abort>
20# include <__verbose_trap>
1921#endif
2022
2123#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -28,18 +30,7 @@
2830
2931#else
3032
31# if __has_builtin(__builtin_verbose_trap)
32// AppleClang shipped a slightly different version of __builtin_verbose_trap from the upstream
33// version before upstream Clang actually got the builtin.
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
36# define _LIBCPP_ASSERTION_HANDLER(message) __builtin_verbose_trap(message)
37# else
38# define _LIBCPP_ASSERTION_HANDLER(message) __builtin_verbose_trap("libc++", message)
39# endif
40# else
41# define _LIBCPP_ASSERTION_HANDLER(message) ((void)message, __builtin_trap())
42# endif
33# define _LIBCPP_ASSERTION_HANDLER(message) _LIBCPP_VERBOSE_TRAP(message)
4334
4435#endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
4536
lib/libcxx/include/__atomic/atomic.h+15-6
......@@ -23,6 +23,7 @@
2323#include <__type_traits/is_integral.h>
2424#include <__type_traits/is_nothrow_constructible.h>
2525#include <__type_traits/is_same.h>
26#include <__type_traits/is_trivially_copyable.h>
2627#include <__type_traits/remove_const.h>
2728#include <__type_traits/remove_pointer.h>
2829#include <__type_traits/remove_volatile.h>
......@@ -40,6 +41,8 @@ struct __atomic_base // false
4041{
4142 mutable __cxx_atomic_impl<_Tp> __a_;
4243
44 using value_type = _Tp;
45
4346#if _LIBCPP_STD_VER >= 17
4447 static constexpr bool is_always_lock_free = __libcpp_is_always_lock_free<__cxx_atomic_impl<_Tp> >::__value;
4548#endif
......@@ -145,6 +148,8 @@ template <class _Tp>
145148struct __atomic_base<_Tp, true> : public __atomic_base<_Tp, false> {
146149 using __base _LIBCPP_NODEBUG = __atomic_base<_Tp, false>;
147150
151 using difference_type = typename __base::value_type;
152
148153 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __atomic_base() _NOEXCEPT = default;
149154
150155 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
......@@ -226,11 +231,15 @@ struct __atomic_waitable_traits<__atomic_base<_Tp, _IsIntegral> > {
226231 }
227232};
228233
234template <typename _Tp>
235struct __check_atomic_mandates {
236 using type _LIBCPP_NODEBUG = _Tp;
237 static_assert(is_trivially_copyable<_Tp>::value, "std::atomic<T> requires that 'T' be a trivially copyable type");
238};
239
229240template <class _Tp>
230struct atomic : public __atomic_base<_Tp> {
241struct atomic : public __atomic_base<typename __check_atomic_mandates<_Tp>::type> {
231242 using __base _LIBCPP_NODEBUG = __atomic_base<_Tp>;
232 using value_type = _Tp;
233 using difference_type = value_type;
234243
235244#if _LIBCPP_STD_VER >= 20
236245 _LIBCPP_HIDE_FROM_ABI atomic() = default;
......@@ -258,8 +267,8 @@ struct atomic : public __atomic_base<_Tp> {
258267template <class _Tp>
259268struct atomic<_Tp*> : public __atomic_base<_Tp*> {
260269 using __base _LIBCPP_NODEBUG = __atomic_base<_Tp*>;
261 using value_type = _Tp*;
262 using difference_type = ptrdiff_t;
270
271 using difference_type = ptrdiff_t;
263272
264273 _LIBCPP_HIDE_FROM_ABI atomic() _NOEXCEPT = default;
265274
......@@ -361,7 +370,7 @@ private:
361370 // https://github.com/llvm/llvm-project/issues/47978
362371 // clang bug: __old is not updated on failure for atomic<long double>::compare_exchange_weak
363372 // Note __old = __self.load(memory_order_relaxed) will not work
364 std::__cxx_atomic_load_inplace(std::addressof(__self.__a_), &__old, memory_order_relaxed);
373 std::__cxx_atomic_load_inplace(std::addressof(__self.__a_), std::addressof(__old), memory_order_relaxed);
365374 }
366375# endif
367376 __new = __operation(__old, __operand);
lib/libcxx/include/__atomic/atomic_ref.h+1-1
......@@ -119,7 +119,7 @@ public:
119119 // that the pointer is going to be aligned properly at runtime because that is a (checked) precondition
120120 // of atomic_ref's constructor.
121121 static constexpr bool is_always_lock_free =
122 __atomic_always_lock_free(sizeof(_Tp), &__get_aligner_instance<required_alignment>::__instance);
122 __atomic_always_lock_free(sizeof(_Tp), std::addressof(__get_aligner_instance<required_alignment>::__instance));
123123
124124 _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const noexcept { return __atomic_is_lock_free(sizeof(_Tp), __ptr_); }
125125
lib/libcxx/include/__atomic/memory_order.h+2-2
......@@ -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 _LIBCPP_NODEBUG = underlying_type<__legacy_memory_order>::type;
27using __memory_order_underlying_t _LIBCPP_NODEBUG = __underlying_type_t<__legacy_memory_order>;
2828
2929#if _LIBCPP_STD_VER >= 20
3030
......@@ -37,7 +37,7 @@ enum class memory_order : __memory_order_underlying_t {
3737 seq_cst = __mo_seq_cst
3838};
3939
40static_assert(is_same<underlying_type<memory_order>::type, __memory_order_underlying_t>::value,
40static_assert(is_same<__underlying_type_t<memory_order>, __memory_order_underlying_t>::value,
4141 "unexpected underlying type for std::memory_order");
4242
4343inline constexpr auto memory_order_relaxed = memory_order::relaxed;
lib/libcxx/include/__atomic/support.h-3
......@@ -10,7 +10,6 @@
1010#define _LIBCPP___ATOMIC_SUPPORT_H
1111
1212#include <__config>
13#include <__type_traits/is_trivially_copyable.h>
1413
1514#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1615# pragma GCC system_header
......@@ -113,8 +112,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
113112
114113template <typename _Tp, typename _Base = __cxx_atomic_base_impl<_Tp> >
115114struct __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
118115 _LIBCPP_HIDE_FROM_ABI __cxx_atomic_impl() _NOEXCEPT = default;
119116 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp __value) _NOEXCEPT : _Base(__value) {}
120117};
lib/libcxx/include/__atomic/support/c11.h+1-1
......@@ -35,7 +35,7 @@ struct __cxx_atomic_base_impl {
3535 }
3636#endif // _LIBCPP_CXX03_LANG
3737 _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp __value) _NOEXCEPT : __a_value(__value) {}
38 _LIBCPP_DISABLE_EXTENSION_WARNING _Atomic(_Tp) __a_value;
38 _Atomic(_Tp) __a_value;
3939};
4040
4141#define __cxx_atomic_is_lock_free(__s) __c11_atomic_is_lock_free(__s)
lib/libcxx/include/__bit/bit_ceil.h+2-2
......@@ -11,8 +11,8 @@
1111
1212#include <__assert>
1313#include <__bit/countl.h>
14#include <__concepts/arithmetic.h>
1514#include <__config>
15#include <__type_traits/integer_traits.h>
1616#include <limits>
1717
1818#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -41,7 +41,7 @@ template <class _Tp>
4141
4242# if _LIBCPP_STD_VER >= 20
4343
44template <__libcpp_unsigned_integer _Tp>
44template <__unsigned_integer _Tp>
4545[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_ceil(_Tp __t) noexcept {
4646 return std::__bit_ceil(__t);
4747}
lib/libcxx/include/__bit/bit_floor.h+2-3
......@@ -10,9 +10,8 @@
1010#define _LIBCPP___BIT_BIT_FLOOR_H
1111
1212#include <__bit/bit_log2.h>
13#include <__concepts/arithmetic.h>
1413#include <__config>
15#include <limits>
14#include <__type_traits/integer_traits.h>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1817# pragma GCC system_header
......@@ -22,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2221
2322#if _LIBCPP_STD_VER >= 20
2423
25template <__libcpp_unsigned_integer _Tp>
24template <__unsigned_integer _Tp>
2625[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_floor(_Tp __t) noexcept {
2726 return __t == 0 ? 0 : _Tp{1} << std::__bit_log2(__t);
2827}
lib/libcxx/include/__bit/bit_log2.h+3-7
......@@ -11,7 +11,7 @@
1111
1212#include <__bit/countl.h>
1313#include <__config>
14#include <__type_traits/is_unsigned_integer.h>
14#include <__type_traits/integer_traits.h>
1515#include <limits>
1616
1717#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -20,16 +20,12 @@
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if _LIBCPP_STD_VER >= 14
24
2523template <class _Tp>
26_LIBCPP_HIDE_FROM_ABI constexpr _Tp __bit_log2(_Tp __t) noexcept {
27 static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__bit_log2 requires an unsigned integer type");
24_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __bit_log2(_Tp __t) _NOEXCEPT {
25 static_assert(__is_unsigned_integer_v<_Tp>, "__bit_log2 requires an unsigned integer type");
2826 return numeric_limits<_Tp>::digits - 1 - std::__countl_zero(__t);
2927}
3028
31#endif // _LIBCPP_STD_VER >= 14
32
3329_LIBCPP_END_NAMESPACE_STD
3430
3531#endif // _LIBCPP___BIT_BIT_LOG2_H
lib/libcxx/include/__bit/bit_width.h+2-2
......@@ -10,8 +10,8 @@
1010#define _LIBCPP___BIT_BIT_WIDTH_H
1111
1212#include <__bit/bit_log2.h>
13#include <__concepts/arithmetic.h>
1413#include <__config>
14#include <__type_traits/integer_traits.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1717# pragma GCC system_header
......@@ -21,7 +21,7 @@
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
2323
24template <__libcpp_unsigned_integer _Tp>
24template <__unsigned_integer _Tp>
2525[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int bit_width(_Tp __t) noexcept {
2626 return __t == 0 ? 0 : std::__bit_log2(__t) + 1;
2727}
lib/libcxx/include/__bit/countl.h+4-68
......@@ -6,16 +6,11 @@
66//
77//===----------------------------------------------------------------------===//
88
9// TODO: __builtin_clzg is available since Clang 19 and GCC 14. When support for older versions is dropped, we can
10// refactor this code to exclusively use __builtin_clzg.
11
129#ifndef _LIBCPP___BIT_COUNTL_H
1310#define _LIBCPP___BIT_COUNTL_H
1411
15#include <__bit/rotate.h>
16#include <__concepts/arithmetic.h>
1712#include <__config>
18#include <__type_traits/is_unsigned_integer.h>
13#include <__type_traits/integer_traits.h>
1914#include <limits>
2015
2116#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -27,79 +22,20 @@ _LIBCPP_PUSH_MACROS
2722
2823_LIBCPP_BEGIN_NAMESPACE_STD
2924
30[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned __x) _NOEXCEPT {
31 return __builtin_clz(__x);
32}
33
34[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned long __x) _NOEXCEPT {
35 return __builtin_clzl(__x);
36}
37
38[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned long long __x) _NOEXCEPT {
39 return __builtin_clzll(__x);
40}
41
42#if _LIBCPP_HAS_INT128
43inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(__uint128_t __x) _NOEXCEPT {
44# if __has_builtin(__builtin_clzg)
45 return __builtin_clzg(__x);
46# else
47 // The function is written in this form due to C++ constexpr limitations.
48 // The algorithm:
49 // - Test whether any bit in the high 64-bits is set
50 // - No bits set:
51 // - The high 64-bits contain 64 leading zeros,
52 // - Add the result of the low 64-bits.
53 // - Any bits set:
54 // - The number of leading zeros of the input is the number of leading
55 // zeros in the high 64-bits.
56 return ((__x >> 64) == 0) ? (64 + __builtin_clzll(static_cast<unsigned long long>(__x)))
57 : __builtin_clzll(static_cast<unsigned long long>(__x >> 64));
58# endif
59}
60#endif // _LIBCPP_HAS_INT128
61
6225template <class _Tp>
6326_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int __countl_zero(_Tp __t) _NOEXCEPT {
64 static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countl_zero requires an unsigned integer type");
65#if __has_builtin(__builtin_clzg)
27 static_assert(__is_unsigned_integer_v<_Tp>, "__countl_zero requires an unsigned integer type");
6628 return __builtin_clzg(__t, numeric_limits<_Tp>::digits);
67#else // __has_builtin(__builtin_clzg)
68 if (__t == 0)
69 return numeric_limits<_Tp>::digits;
70
71 if (sizeof(_Tp) <= sizeof(unsigned int))
72 return std::__libcpp_clz(static_cast<unsigned int>(__t)) -
73 (numeric_limits<unsigned int>::digits - numeric_limits<_Tp>::digits);
74 else if (sizeof(_Tp) <= sizeof(unsigned long))
75 return std::__libcpp_clz(static_cast<unsigned long>(__t)) -
76 (numeric_limits<unsigned long>::digits - numeric_limits<_Tp>::digits);
77 else if (sizeof(_Tp) <= sizeof(unsigned long long))
78 return std::__libcpp_clz(static_cast<unsigned long long>(__t)) -
79 (numeric_limits<unsigned long long>::digits - numeric_limits<_Tp>::digits);
80 else {
81 int __ret = 0;
82 int __iter = 0;
83 const unsigned int __ulldigits = numeric_limits<unsigned long long>::digits;
84 while (true) {
85 __t = std::__rotl(__t, __ulldigits);
86 if ((__iter = std::__countl_zero(static_cast<unsigned long long>(__t))) != __ulldigits)
87 break;
88 __ret += __iter;
89 }
90 return __ret + __iter;
91 }
92#endif // __has_builtin(__builtin_clzg)
9329}
9430
9531#if _LIBCPP_STD_VER >= 20
9632
97template <__libcpp_unsigned_integer _Tp>
33template <__unsigned_integer _Tp>
9834[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int countl_zero(_Tp __t) noexcept {
9935 return std::__countl_zero(__t);
10036}
10137
102template <__libcpp_unsigned_integer _Tp>
38template <__unsigned_integer _Tp>
10339[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int countl_one(_Tp __t) noexcept {
10440 return __t != numeric_limits<_Tp>::max() ? std::countl_zero(static_cast<_Tp>(~__t)) : numeric_limits<_Tp>::digits;
10541}
lib/libcxx/include/__bit/countr.h+5-40
......@@ -6,15 +6,11 @@
66//
77//===----------------------------------------------------------------------===//
88
9// TODO: __builtin_ctzg is available since Clang 19 and GCC 14. When support for older versions is dropped, we can
10// refactor this code to exclusively use __builtin_ctzg.
11
129#ifndef _LIBCPP___BIT_COUNTR_H
1310#define _LIBCPP___BIT_COUNTR_H
1411
15#include <__bit/rotate.h>
16#include <__concepts/arithmetic.h>
1712#include <__config>
13#include <__type_traits/integer_traits.h>
1814#include <limits>
1915
2016#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -26,51 +22,20 @@ _LIBCPP_PUSH_MACROS
2622
2723_LIBCPP_BEGIN_NAMESPACE_STD
2824
29[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned __x) _NOEXCEPT {
30 return __builtin_ctz(__x);
31}
32
33[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned long __x) _NOEXCEPT {
34 return __builtin_ctzl(__x);
35}
36
37[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned long long __x) _NOEXCEPT {
38 return __builtin_ctzll(__x);
39}
40
4125template <class _Tp>
42[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int __countr_zero(_Tp __t) _NOEXCEPT {
43#if __has_builtin(__builtin_ctzg)
26[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __countr_zero(_Tp __t) _NOEXCEPT {
27 static_assert(__is_unsigned_integer_v<_Tp>, "__countr_zero only works with unsigned types");
4428 return __builtin_ctzg(__t, numeric_limits<_Tp>::digits);
45#else // __has_builtin(__builtin_ctzg)
46 if (__t == 0)
47 return numeric_limits<_Tp>::digits;
48 if (sizeof(_Tp) <= sizeof(unsigned int))
49 return std::__libcpp_ctz(static_cast<unsigned int>(__t));
50 else if (sizeof(_Tp) <= sizeof(unsigned long))
51 return std::__libcpp_ctz(static_cast<unsigned long>(__t));
52 else if (sizeof(_Tp) <= sizeof(unsigned long long))
53 return std::__libcpp_ctz(static_cast<unsigned long long>(__t));
54 else {
55 int __ret = 0;
56 const unsigned int __ulldigits = numeric_limits<unsigned long long>::digits;
57 while (static_cast<unsigned long long>(__t) == 0uLL) {
58 __ret += __ulldigits;
59 __t >>= __ulldigits;
60 }
61 return __ret + std::__libcpp_ctz(static_cast<unsigned long long>(__t));
62 }
63#endif // __has_builtin(__builtin_ctzg)
6429}
6530
6631#if _LIBCPP_STD_VER >= 20
6732
68template <__libcpp_unsigned_integer _Tp>
33template <__unsigned_integer _Tp>
6934[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int countr_zero(_Tp __t) noexcept {
7035 return std::__countr_zero(__t);
7136}
7237
73template <__libcpp_unsigned_integer _Tp>
38template <__unsigned_integer _Tp>
7439[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int countr_one(_Tp __t) noexcept {
7540 return __t != numeric_limits<_Tp>::max() ? std::countr_zero(static_cast<_Tp>(~__t)) : numeric_limits<_Tp>::digits;
7641}
lib/libcxx/include/__bit/has_single_bit.h+2-2
......@@ -9,8 +9,8 @@
99#ifndef _LIBCPP___BIT_HAS_SINGLE_BIT_H
1010#define _LIBCPP___BIT_HAS_SINGLE_BIT_H
1111
12#include <__concepts/arithmetic.h>
1312#include <__config>
13#include <__type_traits/integer_traits.h>
1414
1515#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1616# pragma GCC system_header
......@@ -23,7 +23,7 @@ _LIBCPP_PUSH_MACROS
2323
2424_LIBCPP_BEGIN_NAMESPACE_STD
2525
26template <__libcpp_unsigned_integer _Tp>
26template <__unsigned_integer _Tp>
2727[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool has_single_bit(_Tp __t) noexcept {
2828 return __t != 0 && (((__t & (__t - 1)) == 0));
2929}
lib/libcxx/include/__bit/popcount.h+8-36
......@@ -6,16 +6,11 @@
66//
77//===----------------------------------------------------------------------===//
88
9// TODO: __builtin_popcountg is available since Clang 19 and GCC 14. When support for older versions is dropped, we can
10// refactor this code to exclusively use __builtin_popcountg.
11
129#ifndef _LIBCPP___BIT_POPCOUNT_H
1310#define _LIBCPP___BIT_POPCOUNT_H
1411
15#include <__bit/rotate.h>
16#include <__concepts/arithmetic.h>
1712#include <__config>
18#include <limits>
13#include <__type_traits/integer_traits.h>
1914
2015#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2116# pragma GCC system_header
......@@ -26,43 +21,20 @@ _LIBCPP_PUSH_MACROS
2621
2722_LIBCPP_BEGIN_NAMESPACE_STD
2823
29inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_popcount(unsigned __x) _NOEXCEPT {
30 return __builtin_popcount(__x);
31}
32
33inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_popcount(unsigned long __x) _NOEXCEPT {
34 return __builtin_popcountl(__x);
35}
36
37inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_popcount(unsigned long long __x) _NOEXCEPT {
38 return __builtin_popcountll(__x);
24template <class _Tp>
25[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __popcount(_Tp __t) _NOEXCEPT {
26 static_assert(__is_unsigned_integer_v<_Tp>, "__popcount only works with unsigned types");
27 return __builtin_popcountg(__t);
3928}
4029
4130#if _LIBCPP_STD_VER >= 20
4231
43template <__libcpp_unsigned_integer _Tp>
32template <__unsigned_integer _Tp>
4433[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int popcount(_Tp __t) noexcept {
45# if __has_builtin(__builtin_popcountg)
46 return __builtin_popcountg(__t);
47# else // __has_builtin(__builtin_popcountg)
48 if (sizeof(_Tp) <= sizeof(unsigned int))
49 return std::__libcpp_popcount(static_cast<unsigned int>(__t));
50 else if (sizeof(_Tp) <= sizeof(unsigned long))
51 return std::__libcpp_popcount(static_cast<unsigned long>(__t));
52 else if (sizeof(_Tp) <= sizeof(unsigned long long))
53 return std::__libcpp_popcount(static_cast<unsigned long long>(__t));
54 else {
55 int __ret = 0;
56 while (__t != 0) {
57 __ret += std::__libcpp_popcount(static_cast<unsigned long long>(__t));
58 __t >>= numeric_limits<unsigned long long>::digits;
59 }
60 return __ret;
61 }
62# endif // __has_builtin(__builtin_popcountg)
34 return std::__popcount(__t);
6335}
6436
65#endif // _LIBCPP_STD_VER >= 20
37#endif
6638
6739_LIBCPP_END_NAMESPACE_STD
6840
lib/libcxx/include/__bit/rotate.h+5-6
......@@ -9,9 +9,8 @@
99#ifndef _LIBCPP___BIT_ROTATE_H
1010#define _LIBCPP___BIT_ROTATE_H
1111
12#include <__concepts/arithmetic.h>
1312#include <__config>
14#include <__type_traits/is_unsigned_integer.h>
13#include <__type_traits/integer_traits.h>
1514#include <limits>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -25,7 +24,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2524// the rotr function becomes the ROR instruction.
2625template <class _Tp>
2726_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __rotl(_Tp __x, int __s) _NOEXCEPT {
28 static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotl requires an unsigned integer type");
27 static_assert(__is_unsigned_integer_v<_Tp>, "__rotl requires an unsigned integer type");
2928 const int __n = numeric_limits<_Tp>::digits;
3029 int __r = __s % __n;
3130
......@@ -40,7 +39,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __rotl(_Tp __x, int __s)
4039
4140template <class _Tp>
4241_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __rotr(_Tp __x, int __s) _NOEXCEPT {
43 static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotr requires an unsigned integer type");
42 static_assert(__is_unsigned_integer_v<_Tp>, "__rotr requires an unsigned integer type");
4443 const int __n = numeric_limits<_Tp>::digits;
4544 int __r = __s % __n;
4645
......@@ -55,12 +54,12 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __rotr(_Tp __x, int __s)
5554
5655#if _LIBCPP_STD_VER >= 20
5756
58template <__libcpp_unsigned_integer _Tp>
57template <__unsigned_integer _Tp>
5958[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotl(_Tp __t, int __cnt) noexcept {
6059 return std::__rotl(__t, __cnt);
6160}
6261
63template <__libcpp_unsigned_integer _Tp>
62template <__unsigned_integer _Tp>
6463[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotr(_Tp __t, int __cnt) noexcept {
6564 return std::__rotr(__t, __cnt);
6665}
lib/libcxx/include/__bit_reference+109-599
......@@ -10,21 +10,35 @@
1010#ifndef _LIBCPP___BIT_REFERENCE
1111#define _LIBCPP___BIT_REFERENCE
1212
13#include <__algorithm/comp.h>
14#include <__algorithm/copy.h>
15#include <__algorithm/copy_backward.h>
1316#include <__algorithm/copy_n.h>
17#include <__algorithm/equal.h>
1418#include <__algorithm/min.h>
19#include <__algorithm/rotate.h>
20#include <__algorithm/swap_ranges.h>
21#include <__assert>
1522#include <__bit/countr.h>
1623#include <__compare/ordering.h>
1724#include <__config>
1825#include <__cstddef/ptrdiff_t.h>
1926#include <__cstddef/size_t.h>
27#include <__functional/identity.h>
2028#include <__fwd/bit_reference.h>
2129#include <__iterator/iterator_traits.h>
2230#include <__memory/construct_at.h>
2331#include <__memory/pointer_traits.h>
2432#include <__type_traits/conditional.h>
33#include <__type_traits/desugars_to.h>
34#include <__type_traits/enable_if.h>
2535#include <__type_traits/is_constant_evaluated.h>
36#include <__type_traits/is_same.h>
37#include <__type_traits/is_unsigned.h>
2638#include <__type_traits/void_t.h>
39#include <__utility/pair.h>
2740#include <__utility/swap.h>
41#include <climits>
2842
2943#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3044# pragma GCC system_header
......@@ -55,6 +69,53 @@ struct __size_difference_type_traits<_Cp, __void_t<typename _Cp::difference_type
5569 using size_type = typename _Cp::size_type;
5670};
5771
72// The `__x_mask` functions are designed to work exclusively with any unsigned `_StorageType`s, including small
73// integral types such as unsigned char/short, `uint8_t`, and `uint16_t`. To prevent undefined behavior or
74// ambiguities due to integral promotions for the small integral types, all intermediate bitwise operations are
75// explicitly cast back to the unsigned `_StorageType`.
76
77// Creates a mask of type `_StorageType` with a specified number of leading zeros (__clz) and sets all remaining
78// bits to one.
79template <class _StorageType>
80_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _StorageType __trailing_mask(unsigned __clz) {
81 static_assert(is_unsigned<_StorageType>::value, "__trailing_mask only works with unsigned types");
82 return static_cast<_StorageType>(~static_cast<_StorageType>(0)) >> __clz;
83}
84
85// Creates a mask of type `_StorageType` with a specified number of trailing zeros (__ctz) and sets all remaining
86// bits to one.
87template <class _StorageType>
88_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _StorageType __leading_mask(unsigned __ctz) {
89 static_assert(is_unsigned<_StorageType>::value, "__leading_mask only works with unsigned types");
90 return static_cast<_StorageType>(~static_cast<_StorageType>(0)) << __ctz;
91}
92
93// Creates a mask of type `_StorageType` with a specified number of leading zeros (__clz), a specified number of
94// trailing zeros (__ctz), and sets all bits in between to one.
95template <class _StorageType>
96_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _StorageType __middle_mask(unsigned __clz, unsigned __ctz) {
97 static_assert(is_unsigned<_StorageType>::value, "__middle_mask only works with unsigned types");
98 return std::__leading_mask<_StorageType>(__ctz) & std::__trailing_mask<_StorageType>(__clz);
99}
100
101// This function is designed to operate correctly even for smaller integral types like `uint8_t`, `uint16_t`,
102// or `unsigned short`.
103// See https://github.com/llvm/llvm-project/pull/122410.
104template <class _StoragePointer>
105_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
106__fill_masked_range(_StoragePointer __word, unsigned __clz, unsigned __ctz, bool __fill_val) {
107 static_assert(is_unsigned<typename pointer_traits<_StoragePointer>::element_type>::value,
108 "__fill_masked_range must be called with unsigned type");
109 using _StorageType = typename pointer_traits<_StoragePointer>::element_type;
110 _LIBCPP_ASSERT_VALID_INPUT_RANGE(
111 __ctz + __clz < sizeof(_StorageType) * CHAR_BIT, "__fill_masked_range called with invalid range");
112 _StorageType __m = std::__middle_mask<_StorageType>(__clz, __ctz);
113 if (__fill_val)
114 *__word |= __m;
115 else
116 *__word &= ~__m;
117}
118
58119template <class _Cp, bool = __has_storage_type<_Cp>::value>
59120class __bit_reference {
60121 using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type;
......@@ -104,7 +165,7 @@ public:
104165
105166 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void flip() _NOEXCEPT { *__seg_ ^= __mask_; }
106167 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, false> operator&() const _NOEXCEPT {
107 return __bit_iterator<_Cp, false>(__seg_, static_cast<unsigned>(std::__libcpp_ctz(__mask_)));
168 return __bit_iterator<_Cp, false>(__seg_, static_cast<unsigned>(std::__countr_zero(__mask_)));
108169 }
109170
110171private:
......@@ -173,7 +234,7 @@ public:
173234 }
174235
175236 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, true> operator&() const _NOEXCEPT {
176 return __bit_iterator<_Cp, true>(__seg_, static_cast<unsigned>(std::__libcpp_ctz(__mask_)));
237 return __bit_iterator<_Cp, true>(__seg_, static_cast<unsigned>(std::__countr_zero(__mask_)));
177238 }
178239
179240private:
......@@ -183,422 +244,6 @@ private:
183244 __mask_(__m) {}
184245};
185246
186// copy
187
188template <class _Cp, bool _IsConst>
189_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_aligned(
190 __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) {
191 using _In = __bit_iterator<_Cp, _IsConst>;
192 using difference_type = typename _In::difference_type;
193 using __storage_type = typename _In::__storage_type;
194
195 const int __bits_per_word = _In::__bits_per_word;
196 difference_type __n = __last - __first;
197 if (__n > 0) {
198 // do first word
199 if (__first.__ctz_ != 0) {
200 unsigned __clz = __bits_per_word - __first.__ctz_;
201 difference_type __dn = std::min(static_cast<difference_type>(__clz), __n);
202 __n -= __dn;
203 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn));
204 __storage_type __b = *__first.__seg_ & __m;
205 *__result.__seg_ &= ~__m;
206 *__result.__seg_ |= __b;
207 __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
208 __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
209 ++__first.__seg_;
210 // __first.__ctz_ = 0;
211 }
212 // __first.__ctz_ == 0;
213 // do middle words
214 __storage_type __nw = __n / __bits_per_word;
215 std::copy_n(std::__to_address(__first.__seg_), __nw, std::__to_address(__result.__seg_));
216 __n -= __nw * __bits_per_word;
217 __result.__seg_ += __nw;
218 // do last word
219 if (__n > 0) {
220 __first.__seg_ += __nw;
221 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
222 __storage_type __b = *__first.__seg_ & __m;
223 *__result.__seg_ &= ~__m;
224 *__result.__seg_ |= __b;
225 __result.__ctz_ = static_cast<unsigned>(__n);
226 }
227 }
228 return __result;
229}
230
231template <class _Cp, bool _IsConst>
232_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_unaligned(
233 __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) {
234 using _In = __bit_iterator<_Cp, _IsConst>;
235 using difference_type = typename _In::difference_type;
236 using __storage_type = typename _In::__storage_type;
237
238 const int __bits_per_word = _In::__bits_per_word;
239 difference_type __n = __last - __first;
240 if (__n > 0) {
241 // do first word
242 if (__first.__ctz_ != 0) {
243 unsigned __clz_f = __bits_per_word - __first.__ctz_;
244 difference_type __dn = std::min(static_cast<difference_type>(__clz_f), __n);
245 __n -= __dn;
246 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
247 __storage_type __b = *__first.__seg_ & __m;
248 unsigned __clz_r = __bits_per_word - __result.__ctz_;
249 __storage_type __ddn = std::min<__storage_type>(__dn, __clz_r);
250 __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn));
251 *__result.__seg_ &= ~__m;
252 if (__result.__ctz_ > __first.__ctz_)
253 *__result.__seg_ |= __b << (__result.__ctz_ - __first.__ctz_);
254 else
255 *__result.__seg_ |= __b >> (__first.__ctz_ - __result.__ctz_);
256 __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word;
257 __result.__ctz_ = static_cast<unsigned>((__ddn + __result.__ctz_) % __bits_per_word);
258 __dn -= __ddn;
259 if (__dn > 0) {
260 __m = ~__storage_type(0) >> (__bits_per_word - __dn);
261 *__result.__seg_ &= ~__m;
262 *__result.__seg_ |= __b >> (__first.__ctz_ + __ddn);
263 __result.__ctz_ = static_cast<unsigned>(__dn);
264 }
265 ++__first.__seg_;
266 // __first.__ctz_ = 0;
267 }
268 // __first.__ctz_ == 0;
269 // do middle words
270 unsigned __clz_r = __bits_per_word - __result.__ctz_;
271 __storage_type __m = ~__storage_type(0) << __result.__ctz_;
272 for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) {
273 __storage_type __b = *__first.__seg_;
274 *__result.__seg_ &= ~__m;
275 *__result.__seg_ |= __b << __result.__ctz_;
276 ++__result.__seg_;
277 *__result.__seg_ &= __m;
278 *__result.__seg_ |= __b >> __clz_r;
279 }
280 // do last word
281 if (__n > 0) {
282 __m = ~__storage_type(0) >> (__bits_per_word - __n);
283 __storage_type __b = *__first.__seg_ & __m;
284 __storage_type __dn = std::min(__n, static_cast<difference_type>(__clz_r));
285 __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn));
286 *__result.__seg_ &= ~__m;
287 *__result.__seg_ |= __b << __result.__ctz_;
288 __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
289 __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
290 __n -= __dn;
291 if (__n > 0) {
292 __m = ~__storage_type(0) >> (__bits_per_word - __n);
293 *__result.__seg_ &= ~__m;
294 *__result.__seg_ |= __b >> __dn;
295 __result.__ctz_ = static_cast<unsigned>(__n);
296 }
297 }
298 }
299 return __result;
300}
301
302template <class _Cp, bool _IsConst>
303inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, false>
304copy(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) {
305 if (__first.__ctz_ == __result.__ctz_)
306 return std::__copy_aligned(__first, __last, __result);
307 return std::__copy_unaligned(__first, __last, __result);
308}
309
310// copy_backward
311
312template <class _Cp, bool _IsConst>
313_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_backward_aligned(
314 __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) {
315 using _In = __bit_iterator<_Cp, _IsConst>;
316 using difference_type = typename _In::difference_type;
317 using __storage_type = typename _In::__storage_type;
318
319 const int __bits_per_word = _In::__bits_per_word;
320 difference_type __n = __last - __first;
321 if (__n > 0) {
322 // do first word
323 if (__last.__ctz_ != 0) {
324 difference_type __dn = std::min(static_cast<difference_type>(__last.__ctz_), __n);
325 __n -= __dn;
326 unsigned __clz = __bits_per_word - __last.__ctz_;
327 __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz);
328 __storage_type __b = *__last.__seg_ & __m;
329 *__result.__seg_ &= ~__m;
330 *__result.__seg_ |= __b;
331 __result.__ctz_ = static_cast<unsigned>(((-__dn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word);
332 // __last.__ctz_ = 0
333 }
334 // __last.__ctz_ == 0 || __n == 0
335 // __result.__ctz_ == 0 || __n == 0
336 // do middle words
337 __storage_type __nw = __n / __bits_per_word;
338 __result.__seg_ -= __nw;
339 __last.__seg_ -= __nw;
340 std::copy_n(std::__to_address(__last.__seg_), __nw, std::__to_address(__result.__seg_));
341 __n -= __nw * __bits_per_word;
342 // do last word
343 if (__n > 0) {
344 __storage_type __m = ~__storage_type(0) << (__bits_per_word - __n);
345 __storage_type __b = *--__last.__seg_ & __m;
346 *--__result.__seg_ &= ~__m;
347 *__result.__seg_ |= __b;
348 __result.__ctz_ = static_cast<unsigned>(-__n & (__bits_per_word - 1));
349 }
350 }
351 return __result;
352}
353
354template <class _Cp, bool _IsConst>
355_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> __copy_backward_unaligned(
356 __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) {
357 using _In = __bit_iterator<_Cp, _IsConst>;
358 using difference_type = typename _In::difference_type;
359 using __storage_type = typename _In::__storage_type;
360
361 const int __bits_per_word = _In::__bits_per_word;
362 difference_type __n = __last - __first;
363 if (__n > 0) {
364 // do first word
365 if (__last.__ctz_ != 0) {
366 difference_type __dn = std::min(static_cast<difference_type>(__last.__ctz_), __n);
367 __n -= __dn;
368 unsigned __clz_l = __bits_per_word - __last.__ctz_;
369 __storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_l);
370 __storage_type __b = *__last.__seg_ & __m;
371 unsigned __clz_r = __bits_per_word - __result.__ctz_;
372 __storage_type __ddn = std::min(__dn, static_cast<difference_type>(__result.__ctz_));
373 if (__ddn > 0) {
374 __m = (~__storage_type(0) << (__result.__ctz_ - __ddn)) & (~__storage_type(0) >> __clz_r);
375 *__result.__seg_ &= ~__m;
376 if (__result.__ctz_ > __last.__ctz_)
377 *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_);
378 else
379 *__result.__seg_ |= __b >> (__last.__ctz_ - __result.__ctz_);
380 __result.__ctz_ = static_cast<unsigned>(((-__ddn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word);
381 __dn -= __ddn;
382 }
383 if (__dn > 0) {
384 // __result.__ctz_ == 0
385 --__result.__seg_;
386 __result.__ctz_ = static_cast<unsigned>(-__dn & (__bits_per_word - 1));
387 __m = ~__storage_type(0) << __result.__ctz_;
388 *__result.__seg_ &= ~__m;
389 __last.__ctz_ -= __dn + __ddn;
390 *__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_);
391 }
392 // __last.__ctz_ = 0
393 }
394 // __last.__ctz_ == 0 || __n == 0
395 // __result.__ctz_ != 0 || __n == 0
396 // do middle words
397 unsigned __clz_r = __bits_per_word - __result.__ctz_;
398 __storage_type __m = ~__storage_type(0) >> __clz_r;
399 for (; __n >= __bits_per_word; __n -= __bits_per_word) {
400 __storage_type __b = *--__last.__seg_;
401 *__result.__seg_ &= ~__m;
402 *__result.__seg_ |= __b >> __clz_r;
403 *--__result.__seg_ &= __m;
404 *__result.__seg_ |= __b << __result.__ctz_;
405 }
406 // do last word
407 if (__n > 0) {
408 __m = ~__storage_type(0) << (__bits_per_word - __n);
409 __storage_type __b = *--__last.__seg_ & __m;
410 __clz_r = __bits_per_word - __result.__ctz_;
411 __storage_type __dn = std::min(__n, static_cast<difference_type>(__result.__ctz_));
412 __m = (~__storage_type(0) << (__result.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_r);
413 *__result.__seg_ &= ~__m;
414 *__result.__seg_ |= __b >> (__bits_per_word - __result.__ctz_);
415 __result.__ctz_ = static_cast<unsigned>(((-__dn & (__bits_per_word - 1)) + __result.__ctz_) % __bits_per_word);
416 __n -= __dn;
417 if (__n > 0) {
418 // __result.__ctz_ == 0
419 --__result.__seg_;
420 __result.__ctz_ = static_cast<unsigned>(-__n & (__bits_per_word - 1));
421 __m = ~__storage_type(0) << __result.__ctz_;
422 *__result.__seg_ &= ~__m;
423 *__result.__seg_ |= __b << (__result.__ctz_ - (__bits_per_word - __n - __dn));
424 }
425 }
426 }
427 return __result;
428}
429
430template <class _Cp, bool _IsConst>
431inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, false> copy_backward(
432 __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) {
433 if (__last.__ctz_ == __result.__ctz_)
434 return std::__copy_backward_aligned(__first, __last, __result);
435 return std::__copy_backward_unaligned(__first, __last, __result);
436}
437
438// move
439
440template <class _Cp, bool _IsConst>
441inline _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false>
442move(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) {
443 return std::copy(__first, __last, __result);
444}
445
446// move_backward
447
448template <class _Cp, bool _IsConst>
449inline _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false> move_backward(
450 __bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result) {
451 return std::copy_backward(__first, __last, __result);
452}
453
454// swap_ranges
455
456template <class _Cl, class _Cr>
457_LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cr, false> __swap_ranges_aligned(
458 __bit_iterator<_Cl, false> __first, __bit_iterator<_Cl, false> __last, __bit_iterator<_Cr, false> __result) {
459 using _I1 = __bit_iterator<_Cl, false>;
460 using difference_type = typename _I1::difference_type;
461 using __storage_type = typename _I1::__storage_type;
462
463 const int __bits_per_word = _I1::__bits_per_word;
464 difference_type __n = __last - __first;
465 if (__n > 0) {
466 // do first word
467 if (__first.__ctz_ != 0) {
468 unsigned __clz = __bits_per_word - __first.__ctz_;
469 difference_type __dn = std::min(static_cast<difference_type>(__clz), __n);
470 __n -= __dn;
471 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn));
472 __storage_type __b1 = *__first.__seg_ & __m;
473 *__first.__seg_ &= ~__m;
474 __storage_type __b2 = *__result.__seg_ & __m;
475 *__result.__seg_ &= ~__m;
476 *__result.__seg_ |= __b1;
477 *__first.__seg_ |= __b2;
478 __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
479 __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
480 ++__first.__seg_;
481 // __first.__ctz_ = 0;
482 }
483 // __first.__ctz_ == 0;
484 // do middle words
485 for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_, ++__result.__seg_)
486 swap(*__first.__seg_, *__result.__seg_);
487 // do last word
488 if (__n > 0) {
489 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
490 __storage_type __b1 = *__first.__seg_ & __m;
491 *__first.__seg_ &= ~__m;
492 __storage_type __b2 = *__result.__seg_ & __m;
493 *__result.__seg_ &= ~__m;
494 *__result.__seg_ |= __b1;
495 *__first.__seg_ |= __b2;
496 __result.__ctz_ = static_cast<unsigned>(__n);
497 }
498 }
499 return __result;
500}
501
502template <class _Cl, class _Cr>
503_LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cr, false> __swap_ranges_unaligned(
504 __bit_iterator<_Cl, false> __first, __bit_iterator<_Cl, false> __last, __bit_iterator<_Cr, false> __result) {
505 using _I1 = __bit_iterator<_Cl, false>;
506 using difference_type = typename _I1::difference_type;
507 using __storage_type = typename _I1::__storage_type;
508
509 const int __bits_per_word = _I1::__bits_per_word;
510 difference_type __n = __last - __first;
511 if (__n > 0) {
512 // do first word
513 if (__first.__ctz_ != 0) {
514 unsigned __clz_f = __bits_per_word - __first.__ctz_;
515 difference_type __dn = std::min(static_cast<difference_type>(__clz_f), __n);
516 __n -= __dn;
517 __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
518 __storage_type __b1 = *__first.__seg_ & __m;
519 *__first.__seg_ &= ~__m;
520 unsigned __clz_r = __bits_per_word - __result.__ctz_;
521 __storage_type __ddn = std::min<__storage_type>(__dn, __clz_r);
522 __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn));
523 __storage_type __b2 = *__result.__seg_ & __m;
524 *__result.__seg_ &= ~__m;
525 if (__result.__ctz_ > __first.__ctz_) {
526 unsigned __s = __result.__ctz_ - __first.__ctz_;
527 *__result.__seg_ |= __b1 << __s;
528 *__first.__seg_ |= __b2 >> __s;
529 } else {
530 unsigned __s = __first.__ctz_ - __result.__ctz_;
531 *__result.__seg_ |= __b1 >> __s;
532 *__first.__seg_ |= __b2 << __s;
533 }
534 __result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word;
535 __result.__ctz_ = static_cast<unsigned>((__ddn + __result.__ctz_) % __bits_per_word);
536 __dn -= __ddn;
537 if (__dn > 0) {
538 __m = ~__storage_type(0) >> (__bits_per_word - __dn);
539 __b2 = *__result.__seg_ & __m;
540 *__result.__seg_ &= ~__m;
541 unsigned __s = __first.__ctz_ + __ddn;
542 *__result.__seg_ |= __b1 >> __s;
543 *__first.__seg_ |= __b2 << __s;
544 __result.__ctz_ = static_cast<unsigned>(__dn);
545 }
546 ++__first.__seg_;
547 // __first.__ctz_ = 0;
548 }
549 // __first.__ctz_ == 0;
550 // do middle words
551 __storage_type __m = ~__storage_type(0) << __result.__ctz_;
552 unsigned __clz_r = __bits_per_word - __result.__ctz_;
553 for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_) {
554 __storage_type __b1 = *__first.__seg_;
555 __storage_type __b2 = *__result.__seg_ & __m;
556 *__result.__seg_ &= ~__m;
557 *__result.__seg_ |= __b1 << __result.__ctz_;
558 *__first.__seg_ = __b2 >> __result.__ctz_;
559 ++__result.__seg_;
560 __b2 = *__result.__seg_ & ~__m;
561 *__result.__seg_ &= __m;
562 *__result.__seg_ |= __b1 >> __clz_r;
563 *__first.__seg_ |= __b2 << __clz_r;
564 }
565 // do last word
566 if (__n > 0) {
567 __m = ~__storage_type(0) >> (__bits_per_word - __n);
568 __storage_type __b1 = *__first.__seg_ & __m;
569 *__first.__seg_ &= ~__m;
570 __storage_type __dn = std::min<__storage_type>(__n, __clz_r);
571 __m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn));
572 __storage_type __b2 = *__result.__seg_ & __m;
573 *__result.__seg_ &= ~__m;
574 *__result.__seg_ |= __b1 << __result.__ctz_;
575 *__first.__seg_ |= __b2 >> __result.__ctz_;
576 __result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
577 __result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
578 __n -= __dn;
579 if (__n > 0) {
580 __m = ~__storage_type(0) >> (__bits_per_word - __n);
581 __b2 = *__result.__seg_ & __m;
582 *__result.__seg_ &= ~__m;
583 *__result.__seg_ |= __b1 >> __dn;
584 *__first.__seg_ |= __b2 << __dn;
585 __result.__ctz_ = static_cast<unsigned>(__n);
586 }
587 }
588 }
589 return __result;
590}
591
592template <class _Cl, class _Cr>
593inline _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cr, false> swap_ranges(
594 __bit_iterator<_Cl, false> __first1, __bit_iterator<_Cl, false> __last1, __bit_iterator<_Cr, false> __first2) {
595 if (__first1.__ctz_ == __first2.__ctz_)
596 return std::__swap_ranges_aligned(__first1, __last1, __first2);
597 return std::__swap_ranges_unaligned(__first1, __last1, __first2);
598}
599
600// rotate
601
602247template <class _Cp>
603248struct __bit_array {
604249 using difference_type _LIBCPP_NODEBUG = typename __size_difference_type_traits<_Cp>::difference_type;
......@@ -630,166 +275,6 @@ struct __bit_array {
630275 }
631276};
632277
633template <class _Cp>
634_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, false>
635rotate(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __middle, __bit_iterator<_Cp, false> __last) {
636 using _I1 = __bit_iterator<_Cp, false>;
637 using difference_type = typename _I1::difference_type;
638
639 difference_type __d1 = __middle - __first;
640 difference_type __d2 = __last - __middle;
641 _I1 __r = __first + __d2;
642 while (__d1 != 0 && __d2 != 0) {
643 if (__d1 <= __d2) {
644 if (__d1 <= __bit_array<_Cp>::capacity()) {
645 __bit_array<_Cp> __b(__d1);
646 std::copy(__first, __middle, __b.begin());
647 std::copy(__b.begin(), __b.end(), std::copy(__middle, __last, __first));
648 break;
649 } else {
650 __bit_iterator<_Cp, false> __mp = std::swap_ranges(__first, __middle, __middle);
651 __first = __middle;
652 __middle = __mp;
653 __d2 -= __d1;
654 }
655 } else {
656 if (__d2 <= __bit_array<_Cp>::capacity()) {
657 __bit_array<_Cp> __b(__d2);
658 std::copy(__middle, __last, __b.begin());
659 std::copy_backward(__b.begin(), __b.end(), std::copy_backward(__first, __middle, __last));
660 break;
661 } else {
662 __bit_iterator<_Cp, false> __mp = __first + __d2;
663 std::swap_ranges(__first, __mp, __middle);
664 __first = __mp;
665 __d1 -= __d2;
666 }
667 }
668 }
669 return __r;
670}
671
672// equal
673
674template <class _Cp, bool _IC1, bool _IC2>
675_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool __equal_unaligned(
676 __bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2) {
677 using _It = __bit_iterator<_Cp, _IC1>;
678 using difference_type = typename _It::difference_type;
679 using __storage_type = typename _It::__storage_type;
680
681 const int __bits_per_word = _It::__bits_per_word;
682 difference_type __n = __last1 - __first1;
683 if (__n > 0) {
684 // do first word
685 if (__first1.__ctz_ != 0) {
686 unsigned __clz_f = __bits_per_word - __first1.__ctz_;
687 difference_type __dn = std::min(static_cast<difference_type>(__clz_f), __n);
688 __n -= __dn;
689 __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
690 __storage_type __b = *__first1.__seg_ & __m;
691 unsigned __clz_r = __bits_per_word - __first2.__ctz_;
692 __storage_type __ddn = std::min<__storage_type>(__dn, __clz_r);
693 __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn));
694 if (__first2.__ctz_ > __first1.__ctz_) {
695 if ((*__first2.__seg_ & __m) != (__b << (__first2.__ctz_ - __first1.__ctz_)))
696 return false;
697 } else {
698 if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ - __first2.__ctz_)))
699 return false;
700 }
701 __first2.__seg_ += (__ddn + __first2.__ctz_) / __bits_per_word;
702 __first2.__ctz_ = static_cast<unsigned>((__ddn + __first2.__ctz_) % __bits_per_word);
703 __dn -= __ddn;
704 if (__dn > 0) {
705 __m = ~__storage_type(0) >> (__bits_per_word - __dn);
706 if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ + __ddn)))
707 return false;
708 __first2.__ctz_ = static_cast<unsigned>(__dn);
709 }
710 ++__first1.__seg_;
711 // __first1.__ctz_ = 0;
712 }
713 // __first1.__ctz_ == 0;
714 // do middle words
715 unsigned __clz_r = __bits_per_word - __first2.__ctz_;
716 __storage_type __m = ~__storage_type(0) << __first2.__ctz_;
717 for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_) {
718 __storage_type __b = *__first1.__seg_;
719 if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_))
720 return false;
721 ++__first2.__seg_;
722 if ((*__first2.__seg_ & ~__m) != (__b >> __clz_r))
723 return false;
724 }
725 // do last word
726 if (__n > 0) {
727 __m = ~__storage_type(0) >> (__bits_per_word - __n);
728 __storage_type __b = *__first1.__seg_ & __m;
729 __storage_type __dn = std::min(__n, static_cast<difference_type>(__clz_r));
730 __m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn));
731 if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_))
732 return false;
733 __first2.__seg_ += (__dn + __first2.__ctz_) / __bits_per_word;
734 __first2.__ctz_ = static_cast<unsigned>((__dn + __first2.__ctz_) % __bits_per_word);
735 __n -= __dn;
736 if (__n > 0) {
737 __m = ~__storage_type(0) >> (__bits_per_word - __n);
738 if ((*__first2.__seg_ & __m) != (__b >> __dn))
739 return false;
740 }
741 }
742 }
743 return true;
744}
745
746template <class _Cp, bool _IC1, bool _IC2>
747_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool __equal_aligned(
748 __bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2) {
749 using _It = __bit_iterator<_Cp, _IC1>;
750 using difference_type = typename _It::difference_type;
751 using __storage_type = typename _It::__storage_type;
752
753 const int __bits_per_word = _It::__bits_per_word;
754 difference_type __n = __last1 - __first1;
755 if (__n > 0) {
756 // do first word
757 if (__first1.__ctz_ != 0) {
758 unsigned __clz = __bits_per_word - __first1.__ctz_;
759 difference_type __dn = std::min(static_cast<difference_type>(__clz), __n);
760 __n -= __dn;
761 __storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz - __dn));
762 if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m))
763 return false;
764 ++__first2.__seg_;
765 ++__first1.__seg_;
766 // __first1.__ctz_ = 0;
767 // __first2.__ctz_ = 0;
768 }
769 // __first1.__ctz_ == 0;
770 // __first2.__ctz_ == 0;
771 // do middle words
772 for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_, ++__first2.__seg_)
773 if (*__first2.__seg_ != *__first1.__seg_)
774 return false;
775 // do last word
776 if (__n > 0) {
777 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
778 if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m))
779 return false;
780 }
781 }
782 return true;
783}
784
785template <class _Cp, bool _IC1, bool _IC2>
786inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
787equal(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2) {
788 if (__first1.__ctz_ == __first2.__ctz_)
789 return std::__equal_aligned(__first1, __last1, __first2);
790 return std::__equal_unaligned(__first1, __last1, __first2);
791}
792
793278template <class _Cp, bool _IsConst, typename _Cp::__storage_type>
794279class __bit_iterator {
795280public:
......@@ -844,6 +329,7 @@ public:
844329 }
845330
846331 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator*() const _NOEXCEPT {
332 _LIBCPP_ASSERT_INTERNAL(__ctz_ < __bits_per_word, "Dereferencing an invalid __bit_iterator.");
847333 return __conditional_t<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >(
848334 __seg_, __storage_type(1) << __ctz_);
849335 }
......@@ -968,7 +454,10 @@ private:
968454 _LIBCPP_HIDE_FROM_ABI
969455 _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit __bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT
970456 : __seg_(__s),
971 __ctz_(__ctz) {}
457 __ctz_(__ctz) {
458 _LIBCPP_ASSERT_INTERNAL(
459 __ctz_ < __bits_per_word, "__bit_iterator initialized with an invalid number of trailing zeros.");
460 }
972461
973462 friend typename _Cp::__self;
974463
......@@ -989,38 +478,59 @@ private:
989478 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false> __copy_unaligned(
990479 __bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result);
991480 template <class _Dp, bool _IC>
992 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false>
993 copy(__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result);
481 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend pair<__bit_iterator<_Dp, _IC>, __bit_iterator<_Dp, false> >
482 __copy_impl::operator()(
483 __bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result) const;
994484 template <class _Dp, bool _IC>
995485 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false> __copy_backward_aligned(
996486 __bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result);
997487 template <class _Dp, bool _IC>
998488 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false> __copy_backward_unaligned(
999489 __bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result);
1000 template <class _Dp, bool _IC>
1001 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false>
1002 copy_backward(__bit_iterator<_Dp, _IC> __first, __bit_iterator<_Dp, _IC> __last, __bit_iterator<_Dp, false> __result);
490 template <class _AlgPolicy>
491 friend struct __copy_backward_impl;
1003492 template <class _Cl, class _Cr>
1004 friend __bit_iterator<_Cr, false>
493 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Cr, false>
1005494 __swap_ranges_aligned(__bit_iterator<_Cl, false>, __bit_iterator<_Cl, false>, __bit_iterator<_Cr, false>);
1006495 template <class _Cl, class _Cr>
1007 friend __bit_iterator<_Cr, false>
496 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Cr, false>
1008497 __swap_ranges_unaligned(__bit_iterator<_Cl, false>, __bit_iterator<_Cl, false>, __bit_iterator<_Cr, false>);
1009 template <class _Cl, class _Cr>
1010 friend __bit_iterator<_Cr, false>
1011 swap_ranges(__bit_iterator<_Cl, false>, __bit_iterator<_Cl, false>, __bit_iterator<_Cr, false>);
1012 template <class _Dp>
1013 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false>
1014 rotate(__bit_iterator<_Dp, false>, __bit_iterator<_Dp, false>, __bit_iterator<_Dp, false>);
1015 template <class _Dp, bool _IC1, bool _IC2>
1016 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool
1017 __equal_aligned(__bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC2>);
1018 template <class _Dp, bool _IC1, bool _IC2>
498 template <class, class _Cl, class _Cr>
499 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend pair<__bit_iterator<_Cl, false>, __bit_iterator<_Cr, false> >
500 __swap_ranges(__bit_iterator<_Cl, false>, __bit_iterator<_Cl, false>, __bit_iterator<_Cr, false>);
501 template <class, class _Dp>
502 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend pair<__bit_iterator<_Dp, false>, __bit_iterator<_Dp, false> >
503 __rotate(__bit_iterator<_Dp, false>, __bit_iterator<_Dp, false>, __bit_iterator<_Dp, false>);
504 template <class _Dp, bool _IsConst1, bool _IsConst2>
1019505 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool
1020 __equal_unaligned(__bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC2>);
1021 template <class _Dp, bool _IC1, bool _IC2>
506 __equal_aligned(__bit_iterator<_Dp, _IsConst1>, __bit_iterator<_Dp, _IsConst1>, __bit_iterator<_Dp, _IsConst2>);
507 template <class _Dp, bool _IsConst1, bool _IsConst2>
1022508 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool
1023 equal(__bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC2>);
509 __equal_unaligned(__bit_iterator<_Dp, _IsConst1>, __bit_iterator<_Dp, _IsConst1>, __bit_iterator<_Dp, _IsConst2>);
510 template <class _Dp,
511 bool _IsConst1,
512 bool _IsConst2,
513 class _BinaryPredicate,
514 __enable_if_t<__desugars_to_v<__equal_tag, _BinaryPredicate, bool, bool>, int> >
515 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool __equal_iter_impl(
516 __bit_iterator<_Dp, _IsConst1>, __bit_iterator<_Dp, _IsConst1>, __bit_iterator<_Dp, _IsConst2>, _BinaryPredicate);
517 template <class _Dp,
518 bool _IsConst1,
519 bool _IsConst2,
520 class _Pred,
521 class _Proj1,
522 class _Proj2,
523 __enable_if_t<__desugars_to_v<__equal_tag, _Pred, bool, bool> && __is_identity<_Proj1>::value &&
524 __is_identity<_Proj2>::value,
525 int> >
526 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 friend bool __equal_impl(
527 __bit_iterator<_Dp, _IsConst1> __first1,
528 __bit_iterator<_Dp, _IsConst1> __last1,
529 __bit_iterator<_Dp, _IsConst2> __first2,
530 __bit_iterator<_Dp, _IsConst2>,
531 _Pred&,
532 _Proj1&,
533 _Proj2&);
1024534 template <bool _ToFind, class _Dp, bool _IC>
1025535 _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, _IC>
1026536 __find_bool(__bit_iterator<_Dp, _IC>, typename __size_difference_type_traits<_Dp>::size_type);
lib/libcxx/include/__charconv/tables.h+8-12
......@@ -19,16 +19,14 @@
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
22#if _LIBCPP_STD_VER >= 17
23
2422namespace __itoa {
2523
26inline constexpr char __base_2_lut[64] = {
24inline _LIBCPP_CONSTEXPR const char __base_2_lut[64] = {
2725 '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '1', '0', '0', '0', '1', '1', '0', '1', '0', '0', '0', '1',
2826 '0', '1', '0', '1', '1', '0', '0', '1', '1', '1', '1', '0', '0', '0', '1', '0', '0', '1', '1', '0', '1', '0',
2927 '1', '0', '1', '1', '1', '1', '0', '0', '1', '1', '0', '1', '1', '1', '1', '0', '1', '1', '1', '1'};
3028
31inline constexpr char __base_8_lut[128] = {
29inline _LIBCPP_CONSTEXPR const char __base_8_lut[128] = {
3230 '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '1', '0', '1', '1', '1', '2',
3331 '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5',
3432 '2', '6', '2', '7', '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '4', '0',
......@@ -36,7 +34,7 @@ inline constexpr char __base_8_lut[128] = {
3634 '5', '4', '5', '5', '5', '6', '5', '7', '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6',
3735 '6', '7', '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7'};
3836
39inline constexpr char __base_16_lut[512] = {
37inline _LIBCPP_CONSTEXPR const char __base_16_lut[512] = {
4038 '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', '0', 'a', '0',
4139 'b', '0', 'c', '0', 'd', '0', 'e', '0', 'f', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6',
4240 '1', '7', '1', '8', '1', '9', '1', 'a', '1', 'b', '1', 'c', '1', 'd', '1', 'e', '1', 'f', '2', '0', '2', '1', '2',
......@@ -61,7 +59,7 @@ inline constexpr char __base_16_lut[512] = {
6159 '1', 'f', '2', 'f', '3', 'f', '4', 'f', '5', 'f', '6', 'f', '7', 'f', '8', 'f', '9', 'f', 'a', 'f', 'b', 'f', 'c',
6260 'f', 'd', 'f', 'e', 'f', 'f'};
6361
64inline constexpr uint32_t __pow10_32[10] = {
62inline _LIBCPP_CONSTEXPR const uint32_t __pow10_32[10] = {
6563 UINT32_C(0),
6664 UINT32_C(10),
6765 UINT32_C(100),
......@@ -73,7 +71,7 @@ inline constexpr uint32_t __pow10_32[10] = {
7371 UINT32_C(100000000),
7472 UINT32_C(1000000000)};
7573
76inline constexpr uint64_t __pow10_64[20] = {
74inline _LIBCPP_CONSTEXPR const uint64_t __pow10_64[20] = {
7775 UINT64_C(0),
7876 UINT64_C(10),
7977 UINT64_C(100),
......@@ -96,8 +94,8 @@ inline constexpr uint64_t __pow10_64[20] = {
9694 UINT64_C(10000000000000000000)};
9795
9896# if _LIBCPP_HAS_INT128
99inline constexpr int __pow10_128_offset = 0;
100inline constexpr __uint128_t __pow10_128[40] = {
97inline _LIBCPP_CONSTEXPR const int __pow10_128_offset = 0;
98inline _LIBCPP_CONSTEXPR const __uint128_t __pow10_128[40] = {
10199 UINT64_C(0),
102100 UINT64_C(10),
103101 UINT64_C(100),
......@@ -140,7 +138,7 @@ inline constexpr __uint128_t __pow10_128[40] = {
140138 (__uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000000000)) * 10};
141139# endif
142140
143inline constexpr char __digits_base_10[200] = {
141inline _LIBCPP_CONSTEXPR const char __digits_base_10[200] = {
144142 // clang-format off
145143 '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9',
146144 '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9',
......@@ -156,8 +154,6 @@ inline constexpr char __digits_base_10[200] = {
156154
157155} // namespace __itoa
158156
159#endif // _LIBCPP_STD_VER >= 17
160
161157_LIBCPP_END_NAMESPACE_STD
162158
163159#endif // _LIBCPP___CHARCONV_TABLES
lib/libcxx/include/__charconv/to_chars_base_10.h+14-18
......@@ -26,55 +26,53 @@ _LIBCPP_PUSH_MACROS
2626
2727_LIBCPP_BEGIN_NAMESPACE_STD
2828
29#if _LIBCPP_STD_VER >= 17
30
3129namespace __itoa {
3230
33_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append1(char* __first, uint32_t __value) noexcept {
31_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append1(char* __first, uint32_t __value) _NOEXCEPT {
3432 *__first = '0' + static_cast<char>(__value);
3533 return __first + 1;
3634}
3735
38_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append2(char* __first, uint32_t __value) noexcept {
36_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append2(char* __first, uint32_t __value) _NOEXCEPT {
3937 return std::copy_n(&__digits_base_10[__value * 2], 2, __first);
4038}
4139
42_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append3(char* __first, uint32_t __value) noexcept {
40_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append3(char* __first, uint32_t __value) _NOEXCEPT {
4341 return __itoa::__append2(__itoa::__append1(__first, __value / 100), __value % 100);
4442}
4543
46_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append4(char* __first, uint32_t __value) noexcept {
44_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append4(char* __first, uint32_t __value) _NOEXCEPT {
4745 return __itoa::__append2(__itoa::__append2(__first, __value / 100), __value % 100);
4846}
4947
50_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append5(char* __first, uint32_t __value) noexcept {
48_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append5(char* __first, uint32_t __value) _NOEXCEPT {
5149 return __itoa::__append4(__itoa::__append1(__first, __value / 10000), __value % 10000);
5250}
5351
54_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append6(char* __first, uint32_t __value) noexcept {
52_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append6(char* __first, uint32_t __value) _NOEXCEPT {
5553 return __itoa::__append4(__itoa::__append2(__first, __value / 10000), __value % 10000);
5654}
5755
58_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append7(char* __first, uint32_t __value) noexcept {
56_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append7(char* __first, uint32_t __value) _NOEXCEPT {
5957 return __itoa::__append6(__itoa::__append1(__first, __value / 1000000), __value % 1000000);
6058}
6159
62_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append8(char* __first, uint32_t __value) noexcept {
60_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append8(char* __first, uint32_t __value) _NOEXCEPT {
6361 return __itoa::__append6(__itoa::__append2(__first, __value / 1000000), __value % 1000000);
6462}
6563
66_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append9(char* __first, uint32_t __value) noexcept {
64_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char* __append9(char* __first, uint32_t __value) _NOEXCEPT {
6765 return __itoa::__append8(__itoa::__append1(__first, __value / 100000000), __value % 100000000);
6866}
6967
7068template <class _Tp>
71_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI char* __append10(char* __first, _Tp __value) noexcept {
69_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI char* __append10(char* __first, _Tp __value) _NOEXCEPT {
7270 return __itoa::__append8(__itoa::__append2(__first, static_cast<uint32_t>(__value / 100000000)),
7371 static_cast<uint32_t>(__value % 100000000));
7472}
7573
7674_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char*
77__base_10_u32(char* __first, uint32_t __value) noexcept {
75__base_10_u32(char* __first, uint32_t __value) _NOEXCEPT {
7876 if (__value < 1000000) {
7977 if (__value < 10000) {
8078 if (__value < 100) {
......@@ -110,7 +108,7 @@ __base_10_u32(char* __first, uint32_t __value) noexcept {
110108}
111109
112110_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char*
113__base_10_u64(char* __buffer, uint64_t __value) noexcept {
111__base_10_u64(char* __buffer, uint64_t __value) _NOEXCEPT {
114112 if (__value <= UINT32_MAX)
115113 return __itoa::__base_10_u32(__buffer, static_cast<uint32_t>(__value));
116114
......@@ -132,13 +130,13 @@ __base_10_u64(char* __buffer, uint64_t __value) noexcept {
132130/// \note The lookup table contains a partial set of exponents limiting the
133131/// range that can be used. However the range is sufficient for
134132/// \ref __base_10_u128.
135_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline __uint128_t __pow_10(int __exp) noexcept {
133_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline __uint128_t __pow_10(int __exp) _NOEXCEPT {
136134 _LIBCPP_ASSERT_INTERNAL(__exp >= __pow10_128_offset, "Index out of bounds");
137135 return __pow10_128[__exp - __pow10_128_offset];
138136}
139137
140138_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI inline char*
141__base_10_u128(char* __buffer, __uint128_t __value) noexcept {
139__base_10_u128(char* __buffer, __uint128_t __value) _NOEXCEPT {
142140 _LIBCPP_ASSERT_INTERNAL(
143141 __value > numeric_limits<uint64_t>::max(), "The optimizations for this algorithm fails when this isn't true.");
144142
......@@ -179,8 +177,6 @@ __base_10_u128(char* __buffer, __uint128_t __value) noexcept {
179177# endif
180178} // namespace __itoa
181179
182#endif // _LIBCPP_STD_VER >= 17
183
184180_LIBCPP_END_NAMESPACE_STD
185181
186182_LIBCPP_POP_MACROS
lib/libcxx/include/__charconv/to_chars_integral.h+51-36
......@@ -39,16 +39,12 @@ _LIBCPP_PUSH_MACROS
3939
4040_LIBCPP_BEGIN_NAMESPACE_STD
4141
42#if _LIBCPP_STD_VER >= 17
43
44to_chars_result to_chars(char*, char*, bool, int = 10) = delete;
45
4642template <typename _Tp>
47inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI to_chars_result
43inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result
4844__to_chars_itoa(char* __first, char* __last, _Tp __value, false_type);
4945
5046template <typename _Tp>
51inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI to_chars_result
47inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result
5248__to_chars_itoa(char* __first, char* __last, _Tp __value, true_type) {
5349 auto __x = std::__to_unsigned_like(__value);
5450 if (__value < 0 && __first != __last) {
......@@ -60,7 +56,7 @@ __to_chars_itoa(char* __first, char* __last, _Tp __value, true_type) {
6056}
6157
6258template <typename _Tp>
63inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI to_chars_result
59inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result
6460__to_chars_itoa(char* __first, char* __last, _Tp __value, false_type) {
6561 using __tx = __itoa::__traits<_Tp>;
6662 auto __diff = __last - __first;
......@@ -73,7 +69,7 @@ __to_chars_itoa(char* __first, char* __last, _Tp __value, false_type) {
7369
7470# if _LIBCPP_HAS_INT128
7571template <>
76inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI to_chars_result
72inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result
7773__to_chars_itoa(char* __first, char* __last, __uint128_t __value, false_type) {
7874 // When the value fits in 64-bits use the 64-bit code path. This reduces
7975 // the number of expensive calculations on 128-bit values.
......@@ -92,20 +88,20 @@ __to_chars_itoa(char* __first, char* __last, __uint128_t __value, false_type) {
9288}
9389# endif
9490
95template <class _Tp>
96inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI to_chars_result
97__to_chars_integral(char* __first, char* __last, _Tp __value, int __base, false_type);
91template <class _Tp, __enable_if_t<!is_signed<_Tp>::value, int> = 0>
92inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result
93__to_chars_integral(char* __first, char* __last, _Tp __value, int __base);
9894
99template <typename _Tp>
100inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI to_chars_result
101__to_chars_integral(char* __first, char* __last, _Tp __value, int __base, true_type) {
95template <class _Tp, __enable_if_t<is_signed<_Tp>::value, int> = 0>
96inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result
97__to_chars_integral(char* __first, char* __last, _Tp __value, int __base) {
10298 auto __x = std::__to_unsigned_like(__value);
10399 if (__value < 0 && __first != __last) {
104100 *__first++ = '-';
105101 __x = std::__complement(__x);
106102 }
107103
108 return std::__to_chars_integral(__first, __last, __x, __base, false_type());
104 return std::__to_chars_integral(__first, __last, __x, __base);
109105}
110106
111107namespace __itoa {
......@@ -116,15 +112,14 @@ struct _LIBCPP_HIDDEN __integral;
116112template <>
117113struct _LIBCPP_HIDDEN __integral<2> {
118114 template <typename _Tp>
119 _LIBCPP_HIDE_FROM_ABI static constexpr int __width(_Tp __value) noexcept {
115 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR int __width(_Tp __value) _NOEXCEPT {
120116 // If value == 0 still need one digit. If the value != this has no
121 // effect since the code scans for the most significant bit set. (Note
122 // that __libcpp_clz doesn't work for 0.)
123 return numeric_limits<_Tp>::digits - std::__libcpp_clz(__value | 1);
117 // effect since the code scans for the most significant bit set.
118 return numeric_limits<_Tp>::digits - std::__countl_zero(__value | 1);
124119 }
125120
126121 template <typename _Tp>
127 _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI static to_chars_result
122 _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI static __to_chars_result
128123 __to_chars(char* __first, char* __last, _Tp __value) {
129124 ptrdiff_t __cap = __last - __first;
130125 int __n = __width(__value);
......@@ -152,15 +147,14 @@ struct _LIBCPP_HIDDEN __integral<2> {
152147template <>
153148struct _LIBCPP_HIDDEN __integral<8> {
154149 template <typename _Tp>
155 _LIBCPP_HIDE_FROM_ABI static constexpr int __width(_Tp __value) noexcept {
150 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR int __width(_Tp __value) _NOEXCEPT {
156151 // If value == 0 still need one digit. If the value != this has no
157 // effect since the code scans for the most significat bit set. (Note
158 // that __libcpp_clz doesn't work for 0.)
159 return ((numeric_limits<_Tp>::digits - std::__libcpp_clz(__value | 1)) + 2) / 3;
152 // effect since the code scans for the most significat bit set.
153 return ((numeric_limits<_Tp>::digits - std::__countl_zero(__value | 1)) + 2) / 3;
160154 }
161155
162156 template <typename _Tp>
163 _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI static to_chars_result
157 _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI static __to_chars_result
164158 __to_chars(char* __first, char* __last, _Tp __value) {
165159 ptrdiff_t __cap = __last - __first;
166160 int __n = __width(__value);
......@@ -188,15 +182,14 @@ struct _LIBCPP_HIDDEN __integral<8> {
188182template <>
189183struct _LIBCPP_HIDDEN __integral<16> {
190184 template <typename _Tp>
191 _LIBCPP_HIDE_FROM_ABI static constexpr int __width(_Tp __value) noexcept {
185 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR int __width(_Tp __value) _NOEXCEPT {
192186 // If value == 0 still need one digit. If the value != this has no
193 // effect since the code scans for the most significat bit set. (Note
194 // that __libcpp_clz doesn't work for 0.)
195 return (numeric_limits<_Tp>::digits - std::__libcpp_clz(__value | 1) + 3) / 4;
187 // effect since the code scans for the most significat bit set.
188 return (numeric_limits<_Tp>::digits - std::__countl_zero(__value | 1) + 3) / 4;
196189 }
197190
198191 template <typename _Tp>
199 _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI static to_chars_result
192 _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI static __to_chars_result
200193 __to_chars(char* __first, char* __last, _Tp __value) {
201194 ptrdiff_t __cap = __last - __first;
202195 int __n = __width(__value);
......@@ -235,13 +228,13 @@ _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI int __to_chars_integral_widt
235228}
236229
237230template <unsigned _Base, typename _Tp, __enable_if_t<(sizeof(_Tp) >= sizeof(unsigned)), int> = 0>
238_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI to_chars_result
231_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result
239232__to_chars_integral(char* __first, char* __last, _Tp __value) {
240233 return __itoa::__integral<_Base>::__to_chars(__first, __last, __value);
241234}
242235
243236template <unsigned _Base, typename _Tp, __enable_if_t<(sizeof(_Tp) < sizeof(unsigned)), int> = 0>
244_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI to_chars_result
237_LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result
245238__to_chars_integral(char* __first, char* __last, _Tp __value) {
246239 return std::__to_chars_integral<_Base>(__first, __last, static_cast<unsigned>(__value));
247240}
......@@ -272,9 +265,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI int __to_chars_integral_widt
272265 __libcpp_unreachable();
273266}
274267
275template <typename _Tp>
276inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI to_chars_result
277__to_chars_integral(char* __first, char* __last, _Tp __value, int __base, false_type) {
268template <class _Tp, __enable_if_t<!is_signed<_Tp>::value, int> >
269inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __to_chars_result
270__to_chars_integral(char* __first, char* __last, _Tp __value, int __base) {
278271 if (__base == 10) [[likely]]
279272 return std::__to_chars_itoa(__first, __last, __value, false_type());
280273
......@@ -302,6 +295,28 @@ __to_chars_integral(char* __first, char* __last, _Tp __value, int __base, false_
302295 return {__last, errc(0)};
303296}
304297
298_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 char __hex_to_upper(char __c) {
299 switch (__c) {
300 case 'a':
301 return 'A';
302 case 'b':
303 return 'B';
304 case 'c':
305 return 'C';
306 case 'd':
307 return 'D';
308 case 'e':
309 return 'E';
310 case 'f':
311 return 'F';
312 }
313 return __c;
314}
315
316#if _LIBCPP_STD_VER >= 17
317
318to_chars_result to_chars(char*, char*, bool, int = 10) = delete;
319
305320template <typename _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0>
306321inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI to_chars_result
307322to_chars(char* __first, char* __last, _Tp __value) {
......@@ -316,7 +331,7 @@ to_chars(char* __first, char* __last, _Tp __value, int __base) {
316331 _LIBCPP_ASSERT_UNCATEGORIZED(2 <= __base && __base <= 36, "base not in [2, 36]");
317332
318333 using _Type = __make_32_64_or_128_bit_t<_Tp>;
319 return std::__to_chars_integral(__first, __last, static_cast<_Type>(__value), __base, is_signed<_Tp>());
334 return std::__to_chars_integral(__first, __last, static_cast<_Type>(__value), __base);
320335}
321336
322337#endif // _LIBCPP_STD_VER >= 17
lib/libcxx/include/__charconv/to_chars_result.h+9
......@@ -34,6 +34,15 @@ struct _LIBCPP_EXPORTED_FROM_ABI to_chars_result {
3434
3535#endif // _LIBCPP_STD_VER >= 17
3636
37struct __to_chars_result {
38 char* __ptr;
39 errc __ec;
40
41#if _LIBCPP_STD_VER >= 17
42 _LIBCPP_HIDE_FROM_ABI constexpr operator to_chars_result() { return {__ptr, __ec}; }
43#endif
44};
45
3746_LIBCPP_END_NAMESPACE_STD
3847
3948#endif // _LIBCPP___CHARCONV_TO_CHARS_RESULT_H
lib/libcxx/include/__charconv/traits.h+11-23
......@@ -15,6 +15,7 @@
1515#include <__charconv/tables.h>
1616#include <__charconv/to_chars_base_10.h>
1717#include <__config>
18#include <__memory/addressof.h>
1819#include <__type_traits/enable_if.h>
1920#include <__type_traits/is_unsigned.h>
2021#include <cstdint>
......@@ -29,27 +30,22 @@ _LIBCPP_PUSH_MACROS
2930
3031_LIBCPP_BEGIN_NAMESPACE_STD
3132
32#if _LIBCPP_STD_VER >= 17
33
3433namespace __itoa {
3534
3635template <typename _Tp, typename = void>
3736struct _LIBCPP_HIDDEN __traits_base;
3837
3938template <typename _Tp>
40struct _LIBCPP_HIDDEN __traits_base<_Tp, __enable_if_t<sizeof(_Tp) <= sizeof(uint32_t)>> {
39struct _LIBCPP_HIDDEN __traits_base<_Tp, __enable_if_t<sizeof(_Tp) <= sizeof(uint32_t)> > {
4140 using type = uint32_t;
4241
4342 /// The width estimation using a log10 algorithm.
4443 ///
4544 /// The algorithm is based on
4645 /// http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
47 /// Instead of using IntegerLogBase2 it uses __libcpp_clz. Since that
48 /// function requires its input to have at least one bit set the value of
49 /// zero is set to one. This means the first element of the lookup table is
50 /// zero.
46 /// Instead of using IntegerLogBase2 it uses __countl_zero.
5147 static _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI int __width(_Tp __v) {
52 auto __t = (32 - std::__libcpp_clz(static_cast<type>(__v | 1))) * 1233 >> 12;
48 auto __t = (32 - std::__countl_zero(static_cast<type>(__v | 1))) * 1233 >> 12;
5349 return __t - (__v < __itoa::__pow10_32[__t]) + 1;
5450 }
5551
......@@ -63,19 +59,16 @@ struct _LIBCPP_HIDDEN __traits_base<_Tp, __enable_if_t<sizeof(_Tp) <= sizeof(uin
6359};
6460
6561template <typename _Tp>
66struct _LIBCPP_HIDDEN __traits_base<_Tp, __enable_if_t<sizeof(_Tp) == sizeof(uint64_t)>> {
62struct _LIBCPP_HIDDEN __traits_base<_Tp, __enable_if_t<sizeof(_Tp) == sizeof(uint64_t)> > {
6763 using type = uint64_t;
6864
6965 /// The width estimation using a log10 algorithm.
7066 ///
7167 /// The algorithm is based on
7268 /// http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
73 /// Instead of using IntegerLogBase2 it uses __libcpp_clz. Since that
74 /// function requires its input to have at least one bit set the value of
75 /// zero is set to one. This means the first element of the lookup table is
76 /// zero.
69 /// Instead of using IntegerLogBase2 it uses __countl_zero.
7770 static _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI int __width(_Tp __v) {
78 auto __t = (64 - std::__libcpp_clz(static_cast<type>(__v | 1))) * 1233 >> 12;
71 auto __t = (64 - std::__countl_zero(static_cast<type>(__v | 1))) * 1233 >> 12;
7972 return __t - (__v < __itoa::__pow10_64[__t]) + 1;
8073 }
8174
......@@ -97,15 +90,12 @@ struct _LIBCPP_HIDDEN __traits_base<_Tp, __enable_if_t<sizeof(_Tp) == sizeof(__u
9790 ///
9891 /// The algorithm is based on
9992 /// http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
100 /// Instead of using IntegerLogBase2 it uses __libcpp_clz. Since that
101 /// function requires its input to have at least one bit set the value of
102 /// zero is set to one. This means the first element of the lookup table is
103 /// zero.
93 /// Instead of using IntegerLogBase2 it uses __countl_zero.
10494 static _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI int __width(_Tp __v) {
10595 _LIBCPP_ASSERT_INTERNAL(
10696 __v > numeric_limits<uint64_t>::max(), "The optimizations for this algorithm fail when this isn't true.");
10797 // There's always a bit set in the upper 64-bits.
108 auto __t = (128 - std::__libcpp_clz(static_cast<uint64_t>(__v >> 64))) * 1233 >> 12;
98 auto __t = (128 - std::__countl_zero(static_cast<uint64_t>(__v >> 64))) * 1233 >> 12;
10999 _LIBCPP_ASSERT_INTERNAL(__t >= __itoa::__pow10_128_offset, "Index out of bounds");
110100 // __t is adjusted since the lookup table misses the lower entries.
111101 return __t - (__v < __itoa::__pow10_128[__t - __itoa::__pow10_128_offset]) + 1;
......@@ -142,7 +132,7 @@ __mul_overflowed(unsigned short __a, _Tp __b, unsigned short& __r) {
142132template <typename _Tp>
143133inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool __mul_overflowed(_Tp __a, _Tp __b, _Tp& __r) {
144134 static_assert(is_unsigned<_Tp>::value, "");
145 return __builtin_mul_overflow(__a, __b, &__r);
135 return __builtin_mul_overflow(__a, __b, std::addressof(__r));
146136}
147137
148138template <typename _Tp, typename _Up>
......@@ -152,7 +142,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool _LIBCPP_CONSTEXPR_SINCE_CXX23 __mul_overflowed
152142
153143template <typename _Tp>
154144struct _LIBCPP_HIDDEN __traits : __traits_base<_Tp> {
155 static constexpr int digits = numeric_limits<_Tp>::digits10 + 1;
145 static _LIBCPP_CONSTEXPR const int digits = numeric_limits<_Tp>::digits10 + 1;
156146 using __traits_base<_Tp>::__pow;
157147 using typename __traits_base<_Tp>::type;
158148
......@@ -191,8 +181,6 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _Tp __complement(_Tp
191181 return _Tp(~__x + 1);
192182}
193183
194#endif // _LIBCPP_STD_VER >= 17
195
196184_LIBCPP_END_NAMESPACE_STD
197185
198186_LIBCPP_POP_MACROS
lib/libcxx/include/__chrono/convert_to_tm.h+24-10
......@@ -15,6 +15,7 @@
1515#include <__chrono/day.h>
1616#include <__chrono/duration.h>
1717#include <__chrono/file_clock.h>
18#include <__chrono/gps_clock.h>
1819#include <__chrono/hh_mm_ss.h>
1920#include <__chrono/local_info.h>
2021#include <__chrono/month.h>
......@@ -23,6 +24,7 @@
2324#include <__chrono/statically_widen.h>
2425#include <__chrono/sys_info.h>
2526#include <__chrono/system_clock.h>
27#include <__chrono/tai_clock.h>
2628#include <__chrono/time_point.h>
2729#include <__chrono/utc_clock.h>
2830#include <__chrono/weekday.h>
......@@ -35,6 +37,7 @@
3537#include <__config>
3638#include <__format/format_error.h>
3739#include <__memory/addressof.h>
40#include <__type_traits/common_type.h>
3841#include <__type_traits/is_convertible.h>
3942#include <__type_traits/is_specialization.h>
4043#include <cstdint>
......@@ -112,6 +115,21 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(chrono::utc_time<_Duration> __tp) {
112115 return __result;
113116}
114117
118template <class _Tm, class _Duration>
119_LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(chrono::tai_time<_Duration> __tp) {
120 using _Rp = common_type_t<_Duration, chrono::seconds>;
121 // The time between the TAI epoch (1958-01-01) and UNIX epoch (1970-01-01).
122 // This avoids leap second conversion when going from TAI to UTC.
123 // (It also avoids issues when the date is before the UTC epoch.)
124 constexpr chrono::seconds __offset{4383 * 24 * 60 * 60};
125 return std::__convert_to_tm<_Tm>(chrono::sys_time<_Rp>{__tp.time_since_epoch() - __offset});
126}
127
128template <class _Tm, class _Duration>
129_LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(chrono::gps_time<_Duration> __tp) {
130 return std::__convert_to_tm<_Tm>(chrono::utc_clock::to_sys(chrono::gps_clock::to_utc(__tp)));
131}
132
115133# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
116134# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
117135
......@@ -125,20 +143,16 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& __value) {
125143# endif
126144
127145 if constexpr (__is_time_point<_ChronoT>) {
128 if constexpr (same_as<typename _ChronoT::clock, chrono::system_clock>)
129 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
136 else if constexpr (same_as<typename _ChronoT::clock, chrono::file_clock>)
146 if constexpr (same_as<typename _ChronoT::clock, chrono::file_clock>)
137147 return std::__convert_to_tm<_Tm>(_ChronoT::clock::to_sys(__value));
138148 else if constexpr (same_as<typename _ChronoT::clock, chrono::local_t>)
139149 return std::__convert_to_tm<_Tm>(chrono::sys_time<typename _ChronoT::duration>{__value.time_since_epoch()});
140 else
150 else {
151 // Note that some clocks have specializations __convert_to_tm for their
152 // time_point. These don't need to be added here. They do not trigger
153 // this assert.
141154 static_assert(sizeof(_ChronoT) == 0, "TODO: Add the missing clock specialization");
155 }
142156 } else if constexpr (chrono::__is_duration_v<_ChronoT>) {
143157 // [time.format]/6
144158 // ... However, if a flag refers to a "time of day" (e.g. %H, %I, %p,
lib/libcxx/include/__chrono/duration.h+5-5
......@@ -32,7 +32,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3232namespace chrono {
3333
3434template <class _Rep, class _Period = ratio<1> >
35class _LIBCPP_TEMPLATE_VIS duration;
35class duration;
3636
3737template <class _Tp>
3838inline const bool __is_duration_v = false;
......@@ -52,7 +52,7 @@ inline const bool __is_duration_v<const volatile duration<_Rep, _Period> > = tru
5252} // namespace chrono
5353
5454template <class _Rep1, class _Period1, class _Rep2, class _Period2>
55struct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>, chrono::duration<_Rep2, _Period2> > {
55struct common_type<chrono::duration<_Rep1, _Period1>, chrono::duration<_Rep2, _Period2> > {
5656 typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, __ratio_gcd<_Period1, _Period2> > type;
5757};
5858
......@@ -107,7 +107,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration duration_cast(const d
107107}
108108
109109template <class _Rep>
110struct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {};
110struct treat_as_floating_point : is_floating_point<_Rep> {};
111111
112112#if _LIBCPP_STD_VER >= 17
113113template <class _Rep>
......@@ -115,7 +115,7 @@ inline constexpr bool treat_as_floating_point_v = treat_as_floating_point<_Rep>:
115115#endif
116116
117117template <class _Rep>
118struct _LIBCPP_TEMPLATE_VIS duration_values {
118struct duration_values {
119119public:
120120 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT { return _Rep(0); }
121121 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR _Rep max() _NOEXCEPT { return numeric_limits<_Rep>::max(); }
......@@ -156,7 +156,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration round(const duration<
156156// duration
157157
158158template <class _Rep, class _Period>
159class _LIBCPP_TEMPLATE_VIS duration {
159class duration {
160160 static_assert(!__is_duration_v<_Rep>, "A duration representation can not be a duration");
161161 static_assert(__is_ratio_v<_Period>, "Second template parameter of duration must be a std::ratio");
162162 static_assert(_Period::num > 0, "duration period must be positive");
lib/libcxx/include/__chrono/formatter.h+54-24
......@@ -21,6 +21,7 @@
2121# include <__chrono/day.h>
2222# include <__chrono/duration.h>
2323# include <__chrono/file_clock.h>
24# include <__chrono/gps_clock.h>
2425# include <__chrono/hh_mm_ss.h>
2526# include <__chrono/local_info.h>
2627# include <__chrono/month.h>
......@@ -31,6 +32,7 @@
3132# include <__chrono/statically_widen.h>
3233# include <__chrono/sys_info.h>
3334# include <__chrono/system_clock.h>
35# include <__chrono/tai_clock.h>
3436# include <__chrono/time_point.h>
3537# include <__chrono/utc_clock.h>
3638# include <__chrono/weekday.h>
......@@ -48,12 +50,14 @@
4850# include <__format/formatter.h>
4951# include <__format/parser_std_format_spec.h>
5052# include <__format/write_escaped.h>
53# include <__iterator/istreambuf_iterator.h>
54# include <__iterator/ostreambuf_iterator.h>
55# include <__locale_dir/time.h>
5156# include <__memory/addressof.h>
5257# include <__type_traits/is_specialization.h>
5358# include <cmath>
5459# include <ctime>
5560# include <limits>
56# include <locale>
5761# include <sstream>
5862# include <string_view>
5963
......@@ -232,9 +236,13 @@ _LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] const
232236 if constexpr (same_as<_Tp, chrono::sys_info>)
233237 return {__value.abbrev, __value.offset};
234238# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
239 else if constexpr (__is_time_point<_Tp> && requires { requires same_as<typename _Tp::clock, chrono::tai_clock>; })
240 return {"TAI", chrono::seconds{0}};
241 else if constexpr (__is_time_point<_Tp> && requires { requires same_as<typename _Tp::clock, chrono::gps_clock>; })
242 return {"GPS", chrono::seconds{0}};
235243 else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
236244 return __formatter::__convert_to_time_zone(__value.get_info());
237# endif
245# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
238246 else
239247# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
240248 return {"UTC", chrono::seconds{0}};
......@@ -312,7 +320,7 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
312320 case _CharT('T'):
313321 __facet.put(
314322 {__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
315 if constexpr (__use_fraction<_Tp>())
323 if constexpr (__formatter::__use_fraction<_Tp>())
316324 __formatter::__format_sub_seconds(__sstr, __value);
317325 break;
318326
......@@ -375,7 +383,7 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
375383 break;
376384
377385 case _CharT('O'):
378 if constexpr (__use_fraction<_Tp>()) {
386 if constexpr (__formatter::__use_fraction<_Tp>()) {
379387 // Handle OS using the normal representation for the non-fractional
380388 // part. There seems to be no locale information regarding how the
381389 // fractional part should be formatted.
......@@ -692,7 +700,7 @@ __format_chrono(const _Tp& __value,
692700} // namespace __formatter
693701
694702template <__fmt_char_type _CharT>
695struct _LIBCPP_TEMPLATE_VIS __formatter_chrono {
703struct __formatter_chrono {
696704public:
697705 template <class _ParseContext>
698706 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator
......@@ -710,7 +718,7 @@ public:
710718};
711719
712720template <class _Duration, __fmt_char_type _CharT>
713struct _LIBCPP_TEMPLATE_VIS formatter<chrono::sys_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
721struct formatter<chrono::sys_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
714722public:
715723 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
716724
......@@ -724,7 +732,29 @@ public:
724732# if _LIBCPP_HAS_EXPERIMENTAL_TZDB
725733
726734template <class _Duration, __fmt_char_type _CharT>
727struct _LIBCPP_TEMPLATE_VIS formatter<chrono::utc_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
735struct formatter<chrono::utc_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
736public:
737 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
738
739 template <class _ParseContext>
740 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
741 return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__clock);
742 }
743};
744
745template <class _Duration, __fmt_char_type _CharT>
746struct formatter<chrono::tai_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
747public:
748 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
749
750 template <class _ParseContext>
751 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
752 return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__clock);
753 }
754};
755
756template <class _Duration, __fmt_char_type _CharT>
757struct formatter<chrono::gps_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
728758public:
729759 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
730760
......@@ -738,7 +768,7 @@ public:
738768# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
739769
740770template <class _Duration, __fmt_char_type _CharT>
741struct _LIBCPP_TEMPLATE_VIS formatter<chrono::file_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
771struct formatter<chrono::file_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
742772public:
743773 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
744774
......@@ -749,7 +779,7 @@ public:
749779};
750780
751781template <class _Duration, __fmt_char_type _CharT>
752struct _LIBCPP_TEMPLATE_VIS formatter<chrono::local_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
782struct formatter<chrono::local_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
753783public:
754784 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
755785
......@@ -783,7 +813,7 @@ public:
783813};
784814
785815template <__fmt_char_type _CharT>
786struct _LIBCPP_TEMPLATE_VIS formatter<chrono::day, _CharT> : public __formatter_chrono<_CharT> {
816struct formatter<chrono::day, _CharT> : public __formatter_chrono<_CharT> {
787817public:
788818 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
789819
......@@ -794,7 +824,7 @@ public:
794824};
795825
796826template <__fmt_char_type _CharT>
797struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month, _CharT> : public __formatter_chrono<_CharT> {
827struct formatter<chrono::month, _CharT> : public __formatter_chrono<_CharT> {
798828public:
799829 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
800830
......@@ -805,7 +835,7 @@ public:
805835};
806836
807837template <__fmt_char_type _CharT>
808struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year, _CharT> : public __formatter_chrono<_CharT> {
838struct formatter<chrono::year, _CharT> : public __formatter_chrono<_CharT> {
809839public:
810840 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
811841
......@@ -816,7 +846,7 @@ public:
816846};
817847
818848template <__fmt_char_type _CharT>
819struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday, _CharT> : public __formatter_chrono<_CharT> {
849struct formatter<chrono::weekday, _CharT> : public __formatter_chrono<_CharT> {
820850public:
821851 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
822852
......@@ -827,7 +857,7 @@ public:
827857};
828858
829859template <__fmt_char_type _CharT>
830struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday_indexed, _CharT> : public __formatter_chrono<_CharT> {
860struct formatter<chrono::weekday_indexed, _CharT> : public __formatter_chrono<_CharT> {
831861public:
832862 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
833863
......@@ -838,7 +868,7 @@ public:
838868};
839869
840870template <__fmt_char_type _CharT>
841struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday_last, _CharT> : public __formatter_chrono<_CharT> {
871struct formatter<chrono::weekday_last, _CharT> : public __formatter_chrono<_CharT> {
842872public:
843873 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
844874
......@@ -849,7 +879,7 @@ public:
849879};
850880
851881template <__fmt_char_type _CharT>
852struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_day, _CharT> : public __formatter_chrono<_CharT> {
882struct formatter<chrono::month_day, _CharT> : public __formatter_chrono<_CharT> {
853883public:
854884 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
855885
......@@ -860,7 +890,7 @@ public:
860890};
861891
862892template <__fmt_char_type _CharT>
863struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_day_last, _CharT> : public __formatter_chrono<_CharT> {
893struct formatter<chrono::month_day_last, _CharT> : public __formatter_chrono<_CharT> {
864894public:
865895 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
866896
......@@ -871,7 +901,7 @@ public:
871901};
872902
873903template <__fmt_char_type _CharT>
874struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_weekday, _CharT> : public __formatter_chrono<_CharT> {
904struct formatter<chrono::month_weekday, _CharT> : public __formatter_chrono<_CharT> {
875905public:
876906 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
877907
......@@ -882,7 +912,7 @@ public:
882912};
883913
884914template <__fmt_char_type _CharT>
885struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_weekday_last, _CharT> : public __formatter_chrono<_CharT> {
915struct formatter<chrono::month_weekday_last, _CharT> : public __formatter_chrono<_CharT> {
886916public:
887917 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
888918
......@@ -893,7 +923,7 @@ public:
893923};
894924
895925template <__fmt_char_type _CharT>
896struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month, _CharT> : public __formatter_chrono<_CharT> {
926struct formatter<chrono::year_month, _CharT> : public __formatter_chrono<_CharT> {
897927public:
898928 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
899929
......@@ -904,7 +934,7 @@ public:
904934};
905935
906936template <__fmt_char_type _CharT>
907struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_day, _CharT> : public __formatter_chrono<_CharT> {
937struct formatter<chrono::year_month_day, _CharT> : public __formatter_chrono<_CharT> {
908938public:
909939 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
910940
......@@ -915,7 +945,7 @@ public:
915945};
916946
917947template <__fmt_char_type _CharT>
918struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_day_last, _CharT> : public __formatter_chrono<_CharT> {
948struct formatter<chrono::year_month_day_last, _CharT> : public __formatter_chrono<_CharT> {
919949public:
920950 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
921951
......@@ -926,7 +956,7 @@ public:
926956};
927957
928958template <__fmt_char_type _CharT>
929struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_weekday, _CharT> : public __formatter_chrono<_CharT> {
959struct formatter<chrono::year_month_weekday, _CharT> : public __formatter_chrono<_CharT> {
930960public:
931961 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
932962
......@@ -937,7 +967,7 @@ public:
937967};
938968
939969template <__fmt_char_type _CharT>
940struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_weekday_last, _CharT> : public __formatter_chrono<_CharT> {
970struct formatter<chrono::year_month_weekday_last, _CharT> : public __formatter_chrono<_CharT> {
941971public:
942972 using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
943973
lib/libcxx/include/__chrono/gps_clock.h created+90
......@@ -0,0 +1,90 @@
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_GPS_CLOCK_H
11#define _LIBCPP___CHRONO_GPS_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 <__assert>
18# include <__chrono/duration.h>
19# include <__chrono/time_point.h>
20# include <__chrono/utc_clock.h>
21# include <__config>
22# include <__type_traits/common_type.h>
23
24# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26# endif
27
28_LIBCPP_PUSH_MACROS
29# include <__undef_macros>
30
31_LIBCPP_BEGIN_NAMESPACE_STD
32
33# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
34
35namespace chrono {
36
37class gps_clock;
38
39template <class _Duration>
40using gps_time = time_point<gps_clock, _Duration>;
41using gps_seconds = gps_time<seconds>;
42
43class gps_clock {
44public:
45 using rep = utc_clock::rep;
46 using period = utc_clock::period;
47 using duration = chrono::duration<rep, period>;
48 using time_point = chrono::time_point<gps_clock>;
49 static constexpr bool is_steady = false; // The utc_clock is not steady.
50
51 // The static difference between UTC and GPS time as specified in the Standard.
52 static constexpr chrono::seconds __offset{315964809};
53
54 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static time_point now() { return from_utc(utc_clock::now()); }
55
56 template <class _Duration>
57 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static utc_time<common_type_t<_Duration, seconds>>
58 to_utc(const gps_time<_Duration>& __time) noexcept {
59 using _Rp = common_type_t<_Duration, seconds>;
60 _Duration __time_since_epoch = __time.time_since_epoch();
61 _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__time_since_epoch >= utc_time<_Rp>::min().time_since_epoch() + __offset,
62 "the GPS to UTC conversion would underflow");
63
64 return utc_time<_Rp>{__time_since_epoch + __offset};
65 }
66
67 template <class _Duration>
68 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static gps_time<common_type_t<_Duration, seconds>>
69 from_utc(const utc_time<_Duration>& __time) noexcept {
70 using _Rp = common_type_t<_Duration, seconds>;
71 _Duration __time_since_epoch = __time.time_since_epoch();
72 _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__time_since_epoch <= utc_time<_Rp>::max().time_since_epoch() - __offset,
73 "the UTC to GPS conversion would overflow");
74
75 return gps_time<_Rp>{__time_since_epoch - __offset};
76 }
77};
78
79} // namespace chrono
80
81# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM &&
82 // _LIBCPP_HAS_LOCALIZATION
83
84_LIBCPP_END_NAMESPACE_STD
85
86_LIBCPP_POP_MACROS
87
88#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
89
90#endif // _LIBCPP___CHRONO_GPS_CLOCK_H
lib/libcxx/include/__chrono/ostream.h+14
......@@ -18,6 +18,7 @@
1818# include <__chrono/day.h>
1919# include <__chrono/duration.h>
2020# include <__chrono/file_clock.h>
21# include <__chrono/gps_clock.h>
2122# include <__chrono/hh_mm_ss.h>
2223# include <__chrono/local_info.h>
2324# include <__chrono/month.h>
......@@ -26,6 +27,7 @@
2627# include <__chrono/statically_widen.h>
2728# include <__chrono/sys_info.h>
2829# include <__chrono/system_clock.h>
30# include <__chrono/tai_clock.h>
2931# include <__chrono/utc_clock.h>
3032# include <__chrono/weekday.h>
3133# include <__chrono/year.h>
......@@ -71,6 +73,18 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const utc_time<_Duration>& __tp
7173 return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T}"), __tp);
7274}
7375
76template <class _CharT, class _Traits, class _Duration>
77_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
78operator<<(basic_ostream<_CharT, _Traits>& __os, const tai_time<_Duration>& __tp) {
79 return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T}"), __tp);
80}
81
82template <class _CharT, class _Traits, class _Duration>
83_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
84operator<<(basic_ostream<_CharT, _Traits>& __os, const gps_time<_Duration>& __tp) {
85 return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T}"), __tp);
86}
87
7488# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
7589# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
7690
lib/libcxx/include/__chrono/parser_std_format_spec.h+1-1
......@@ -139,7 +139,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr void __validate_time_zone(__flags __flags) {
139139}
140140
141141template <class _CharT>
142class _LIBCPP_TEMPLATE_VIS __parser_chrono {
142class __parser_chrono {
143143 using _ConstIterator _LIBCPP_NODEBUG = typename basic_format_parse_context<_CharT>::const_iterator;
144144
145145public:
lib/libcxx/include/__chrono/tai_clock.h created+108
......@@ -0,0 +1,108 @@
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_TAI_CLOCK_H
11#define _LIBCPP___CHRONO_TAI_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 <__assert>
18# include <__chrono/duration.h>
19# include <__chrono/time_point.h>
20# include <__chrono/utc_clock.h>
21# include <__config>
22# include <__type_traits/common_type.h>
23
24# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26# endif
27
28_LIBCPP_PUSH_MACROS
29# include <__undef_macros>
30
31_LIBCPP_BEGIN_NAMESPACE_STD
32
33# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
34
35namespace chrono {
36
37class tai_clock;
38
39template <class _Duration>
40using tai_time = time_point<tai_clock, _Duration>;
41using tai_seconds = tai_time<seconds>;
42
43// [time.clock.tai.overview]/1
44// The clock tai_clock measures seconds since 1958-01-01 00:00:00 and is
45// offset 10s ahead of UTC at this date. That is, 1958-01-01 00:00:00 TAI is
46// equivalent to 1957-12-31 23:59:50 UTC. Leap seconds are not inserted into
47// TAI. Therefore every time a leap second is inserted into UTC, UTC shifts
48// another second with respect to TAI. For example by 2000-01-01 there had
49// been 22 positive and 0 negative leap seconds inserted so 2000-01-01
50// 00:00:00 UTC is equivalent to 2000-01-01 00:00:32 TAI (22s plus the
51// initial 10s offset).
52//
53// Note this does not specify what the UTC offset before 1958-01-01 00:00:00
54// TAI is, nor does it follow the "real" TAI clock between 1958-01-01 and the
55// start of the UTC epoch. So while the member functions are fully specified in
56// the standard, they do not technically follow the "real-world" TAI clock with
57// 100% accuracy.
58//
59// https://koka-lang.github.io/koka/doc/std_time_utc.html contains more
60// information and references.
61class tai_clock {
62public:
63 using rep = utc_clock::rep;
64 using period = utc_clock::period;
65 using duration = chrono::duration<rep, period>;
66 using time_point = chrono::time_point<tai_clock>;
67 static constexpr bool is_steady = false; // The utc_clock is not steady.
68
69 // The static difference between UTC and TAI time.
70 static constexpr chrono::seconds __offset{378691210};
71
72 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static time_point now() { return from_utc(utc_clock::now()); }
73
74 template <class _Duration>
75 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static utc_time<common_type_t<_Duration, seconds>>
76 to_utc(const tai_time<_Duration>& __time) noexcept {
77 using _Rp = common_type_t<_Duration, seconds>;
78 _Duration __time_since_epoch = __time.time_since_epoch();
79 _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__time_since_epoch >= utc_time<_Rp>::min().time_since_epoch() + __offset,
80 "the TAI to UTC conversion would underflow");
81
82 return utc_time<_Rp>{__time_since_epoch - __offset};
83 }
84
85 template <class _Duration>
86 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static tai_time<common_type_t<_Duration, seconds>>
87 from_utc(const utc_time<_Duration>& __time) noexcept {
88 using _Rp = common_type_t<_Duration, seconds>;
89 _Duration __time_since_epoch = __time.time_since_epoch();
90 _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(__time_since_epoch <= utc_time<_Rp>::max().time_since_epoch() - __offset,
91 "the UTC to TAI conversion would overflow");
92
93 return tai_time<_Rp>{__time_since_epoch + __offset};
94 }
95};
96
97} // namespace chrono
98
99# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM &&
100 // _LIBCPP_HAS_LOCALIZATION
101
102_LIBCPP_END_NAMESPACE_STD
103
104_LIBCPP_POP_MACROS
105
106#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
107
108#endif // _LIBCPP___CHRONO_TAI_CLOCK_H
lib/libcxx/include/__chrono/time_point.h+15-3
......@@ -31,7 +31,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3131namespace chrono {
3232
3333template <class _Clock, class _Duration = typename _Clock::duration>
34class _LIBCPP_TEMPLATE_VIS time_point {
34class time_point {
3535 static_assert(__is_duration_v<_Duration>, "Second template parameter of time_point must be a std::chrono::duration");
3636
3737public:
......@@ -58,6 +58,19 @@ public:
5858
5959 // arithmetic
6060
61#if _LIBCPP_STD_VER >= 20
62 _LIBCPP_HIDE_FROM_ABI constexpr time_point& operator++() {
63 ++__d_;
64 return *this;
65 }
66 _LIBCPP_HIDE_FROM_ABI constexpr time_point operator++(int) { return time_point{__d_++}; }
67 _LIBCPP_HIDE_FROM_ABI constexpr time_point& operator--() {
68 --__d_;
69 return *this;
70 }
71 _LIBCPP_HIDE_FROM_ABI constexpr time_point operator--(int) { return time_point{__d_--}; }
72#endif // _LIBCPP_STD_VER >= 20
73
6174 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 time_point& operator+=(const duration& __d) {
6275 __d_ += __d;
6376 return *this;
......@@ -76,8 +89,7 @@ public:
7689} // namespace chrono
7790
7891template <class _Clock, class _Duration1, class _Duration2>
79struct _LIBCPP_TEMPLATE_VIS
80common_type<chrono::time_point<_Clock, _Duration1>, chrono::time_point<_Clock, _Duration2> > {
92struct common_type<chrono::time_point<_Clock, _Duration1>, chrono::time_point<_Clock, _Duration2> > {
8193 typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
8294};
8395
lib/libcxx/include/__compare/common_comparison_category.h+3-3
......@@ -55,7 +55,7 @@ __compute_comp_type(const _ClassifyCompCategory (&__types)[_Size]) {
5555template <class... _Ts, bool _False = false>
5656_LIBCPP_HIDE_FROM_ABI constexpr auto __get_comp_type() {
5757 using _CCC = _ClassifyCompCategory;
58 constexpr _CCC __type_kinds[] = {_StrongOrd, __type_to_enum<_Ts>()...};
58 constexpr _CCC __type_kinds[] = {_StrongOrd, __comp_detail::__type_to_enum<_Ts>()...};
5959 constexpr _CCC __cat = __comp_detail::__compute_comp_type(__type_kinds);
6060 if constexpr (__cat == _None)
6161 return void();
......@@ -72,8 +72,8 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto __get_comp_type() {
7272
7373// [cmp.common], common comparison category type
7474template <class... _Ts>
75struct _LIBCPP_TEMPLATE_VIS common_comparison_category {
76 using type = decltype(__comp_detail::__get_comp_type<_Ts...>());
75struct common_comparison_category {
76 using type _LIBCPP_NODEBUG = decltype(__comp_detail::__get_comp_type<_Ts...>());
7777};
7878
7979template <class... _Ts>
lib/libcxx/include/__compare/compare_three_way.h+1-1
......@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222
2323#if _LIBCPP_STD_VER >= 20
2424
25struct _LIBCPP_TEMPLATE_VIS compare_three_way {
25struct compare_three_way {
2626 template <class _T1, class _T2>
2727 requires three_way_comparable_with<_T1, _T2>
2828 constexpr _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
lib/libcxx/include/__compare/compare_three_way_result.h+3-3
......@@ -29,12 +29,12 @@ struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result<
2929 _Tp,
3030 _Up,
3131 decltype(std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>(), void())> {
32 using type = decltype(std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>());
32 using type _LIBCPP_NODEBUG =
33 decltype(std::declval<__make_const_lvalue_ref<_Tp>>() <=> std::declval<__make_const_lvalue_ref<_Up>>());
3334};
3435
3536template <class _Tp, class _Up = _Tp>
36struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS compare_three_way_result
37 : __compare_three_way_result<_Tp, _Up, void> {};
37struct _LIBCPP_NO_SPECIALIZATIONS compare_three_way_result : __compare_three_way_result<_Tp, _Up, void> {};
3838
3939template <class _Tp, class _Up = _Tp>
4040using compare_three_way_result_t = typename compare_three_way_result<_Tp, _Up>::type;
lib/libcxx/include/__concepts/arithmetic.h-13
......@@ -13,8 +13,6 @@
1313#include <__type_traits/is_floating_point.h>
1414#include <__type_traits/is_integral.h>
1515#include <__type_traits/is_signed.h>
16#include <__type_traits/is_signed_integer.h>
17#include <__type_traits/is_unsigned_integer.h>
1816
1917#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2018# pragma GCC system_header
......@@ -38,17 +36,6 @@ concept unsigned_integral = integral<_Tp> && !signed_integral<_Tp>;
3836template <class _Tp>
3937concept floating_point = is_floating_point_v<_Tp>;
4038
41// Concept helpers for the internal type traits for the fundamental types.
42
43template <class _Tp>
44concept __libcpp_unsigned_integer = __libcpp_is_unsigned_integer<_Tp>::value;
45
46template <class _Tp>
47concept __libcpp_signed_integer = __libcpp_is_signed_integer<_Tp>::value;
48
49template <class _Tp>
50concept __libcpp_integer = __libcpp_unsigned_integer<_Tp> || __libcpp_signed_integer<_Tp>;
51
5239#endif // _LIBCPP_STD_VER >= 20
5340
5441_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__concepts/class_or_enum.h-1
......@@ -13,7 +13,6 @@
1313#include <__type_traits/is_class.h>
1414#include <__type_traits/is_enum.h>
1515#include <__type_traits/is_union.h>
16#include <__type_traits/remove_cvref.h>
1716
1817#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1918# pragma GCC system_header
lib/libcxx/include/__concepts/common_with.h+1-1
......@@ -12,7 +12,7 @@
1212#include <__concepts/common_reference_with.h>
1313#include <__concepts/same_as.h>
1414#include <__config>
15#include <__type_traits/add_lvalue_reference.h>
15#include <__type_traits/add_reference.h>
1616#include <__type_traits/common_reference.h>
1717#include <__type_traits/common_type.h>
1818#include <__utility/declval.h>
lib/libcxx/include/__concepts/swappable.h-1
......@@ -22,7 +22,6 @@
2222#include <__utility/exchange.h>
2323#include <__utility/forward.h>
2424#include <__utility/move.h>
25#include <__utility/swap.h>
2625
2726#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2827# pragma GCC system_header
lib/libcxx/include/__condition_variable/condition_variable.h+87-99
......@@ -39,60 +39,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3939_LIBCPP_DECLARE_STRONG_ENUM(cv_status){no_timeout, timeout};
4040_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(cv_status)
4141
42class _LIBCPP_EXPORTED_FROM_ABI condition_variable {
43 __libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER;
44
45public:
46 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR condition_variable() _NOEXCEPT = default;
47
48# if _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
49 ~condition_variable() = default;
50# else
51 ~condition_variable();
52# endif
53
54 condition_variable(const condition_variable&) = delete;
55 condition_variable& operator=(const condition_variable&) = delete;
56
57 void notify_one() _NOEXCEPT;
58 void notify_all() _NOEXCEPT;
59
60 void wait(unique_lock<mutex>& __lk) _NOEXCEPT;
61 template <class _Predicate>
62 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS void wait(unique_lock<mutex>& __lk, _Predicate __pred);
63
64 template <class _Clock, class _Duration>
65 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS cv_status
66 wait_until(unique_lock<mutex>& __lk, const chrono::time_point<_Clock, _Duration>& __t);
67
68 template <class _Clock, class _Duration, class _Predicate>
69 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool
70 wait_until(unique_lock<mutex>& __lk, const chrono::time_point<_Clock, _Duration>& __t, _Predicate __pred);
71
72 template <class _Rep, class _Period>
73 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS cv_status
74 wait_for(unique_lock<mutex>& __lk, const chrono::duration<_Rep, _Period>& __d);
75
76 template <class _Rep, class _Period, class _Predicate>
77 bool _LIBCPP_HIDE_FROM_ABI
78 wait_for(unique_lock<mutex>& __lk, const chrono::duration<_Rep, _Period>& __d, _Predicate __pred);
79
80 typedef __libcpp_condvar_t* native_handle_type;
81 _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() { return &__cv_; }
82
83private:
84 void
85 __do_timed_wait(unique_lock<mutex>& __lk, chrono::time_point<chrono::system_clock, chrono::nanoseconds>) _NOEXCEPT;
86# if _LIBCPP_HAS_COND_CLOCKWAIT
87 _LIBCPP_HIDE_FROM_ABI void
88 __do_timed_wait(unique_lock<mutex>& __lk, chrono::time_point<chrono::steady_clock, chrono::nanoseconds>) _NOEXCEPT;
89# endif
90 template <class _Clock>
91 _LIBCPP_HIDE_FROM_ABI void
92 __do_timed_wait(unique_lock<mutex>& __lk, chrono::time_point<_Clock, chrono::nanoseconds>) _NOEXCEPT;
93};
94#endif // _LIBCPP_HAS_THREADS
95
9642template <class _Rep, class _Period, __enable_if_t<is_floating_point<_Rep>::value, int> = 0>
9743inline _LIBCPP_HIDE_FROM_ABI chrono::nanoseconds __safe_nanosecond_cast(chrono::duration<_Rep, _Period> __d) {
9844 using namespace chrono;
......@@ -140,64 +86,106 @@ inline _LIBCPP_HIDE_FROM_ABI chrono::nanoseconds __safe_nanosecond_cast(chrono::
14086 return nanoseconds(__result);
14187}
14288
143#if _LIBCPP_HAS_THREADS
144template <class _Predicate>
145void condition_variable::wait(unique_lock<mutex>& __lk, _Predicate __pred) {
146 while (!__pred())
147 wait(__lk);
148}
89class _LIBCPP_EXPORTED_FROM_ABI condition_variable {
90 __libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER;
14991
150template <class _Clock, class _Duration>
151cv_status condition_variable::wait_until(unique_lock<mutex>& __lk, const chrono::time_point<_Clock, _Duration>& __t) {
152 using namespace chrono;
153 using __clock_tp_ns = time_point<_Clock, nanoseconds>;
92public:
93 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR condition_variable() _NOEXCEPT = default;
15494
155 typename _Clock::time_point __now = _Clock::now();
156 if (__t <= __now)
157 return cv_status::timeout;
95# if _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
96 ~condition_variable() = default;
97# else
98 ~condition_variable();
99# endif
158100
159 __clock_tp_ns __t_ns = __clock_tp_ns(std::__safe_nanosecond_cast(__t.time_since_epoch()));
101 condition_variable(const condition_variable&) = delete;
102 condition_variable& operator=(const condition_variable&) = delete;
160103
161 __do_timed_wait(__lk, __t_ns);
162 return _Clock::now() < __t ? cv_status::no_timeout : cv_status::timeout;
163}
104 void notify_one() _NOEXCEPT;
105 void notify_all() _NOEXCEPT;
106
107 void wait(unique_lock<mutex>& __lk) _NOEXCEPT;
164108
165template <class _Clock, class _Duration, class _Predicate>
166bool condition_variable::wait_until(
167 unique_lock<mutex>& __lk, const chrono::time_point<_Clock, _Duration>& __t, _Predicate __pred) {
168 while (!__pred()) {
169 if (wait_until(__lk, __t) == cv_status::timeout)
170 return __pred();
109 template <class _Predicate>
110 _LIBCPP_HIDE_FROM_ABI void wait(unique_lock<mutex>& __lk, _Predicate __pred) {
111 while (!__pred())
112 wait(__lk);
171113 }
172 return true;
173}
174114
175template <class _Rep, class _Period>
176cv_status condition_variable::wait_for(unique_lock<mutex>& __lk, const chrono::duration<_Rep, _Period>& __d) {
177 using namespace chrono;
178 if (__d <= __d.zero())
179 return cv_status::timeout;
180 using __ns_rep = nanoseconds::rep;
181 steady_clock::time_point __c_now = steady_clock::now();
115 template <class _Clock, class _Duration>
116 _LIBCPP_HIDE_FROM_ABI cv_status
117 wait_until(unique_lock<mutex>& __lk, const chrono::time_point<_Clock, _Duration>& __t) {
118 using namespace chrono;
119 using __clock_tp_ns = time_point<_Clock, nanoseconds>;
120
121 typename _Clock::time_point __now = _Clock::now();
122 if (__t <= __now)
123 return cv_status::timeout;
124
125 __clock_tp_ns __t_ns = __clock_tp_ns(std::__safe_nanosecond_cast(__t.time_since_epoch()));
126
127 __do_timed_wait(__lk, __t_ns);
128 return _Clock::now() < __t ? cv_status::no_timeout : cv_status::timeout;
129 }
130
131 template <class _Clock, class _Duration, class _Predicate>
132 _LIBCPP_HIDE_FROM_ABI bool
133 wait_until(unique_lock<mutex>& __lk, const chrono::time_point<_Clock, _Duration>& __t, _Predicate __pred) {
134 while (!__pred()) {
135 if (wait_until(__lk, __t) == cv_status::timeout)
136 return __pred();
137 }
138 return true;
139 }
140
141 template <class _Rep, class _Period>
142 _LIBCPP_HIDE_FROM_ABI cv_status wait_for(unique_lock<mutex>& __lk, const chrono::duration<_Rep, _Period>& __d) {
143 using namespace chrono;
144 if (__d <= __d.zero())
145 return cv_status::timeout;
146 using __ns_rep = nanoseconds::rep;
147 steady_clock::time_point __c_now = steady_clock::now();
182148
183149# if _LIBCPP_HAS_COND_CLOCKWAIT
184 using __clock_tp_ns = time_point<steady_clock, nanoseconds>;
185 __ns_rep __now_count_ns = std::__safe_nanosecond_cast(__c_now.time_since_epoch()).count();
150 using __clock_tp_ns = time_point<steady_clock, nanoseconds>;
151 __ns_rep __now_count_ns = std::__safe_nanosecond_cast(__c_now.time_since_epoch()).count();
186152# else
187 using __clock_tp_ns = time_point<system_clock, nanoseconds>;
188 __ns_rep __now_count_ns = std::__safe_nanosecond_cast(system_clock::now().time_since_epoch()).count();
153 using __clock_tp_ns = time_point<system_clock, nanoseconds>;
154 __ns_rep __now_count_ns = std::__safe_nanosecond_cast(system_clock::now().time_since_epoch()).count();
189155# endif
190156
191 __ns_rep __d_ns_count = std::__safe_nanosecond_cast(__d).count();
157 __ns_rep __d_ns_count = std::__safe_nanosecond_cast(__d).count();
192158
193 if (__now_count_ns > numeric_limits<__ns_rep>::max() - __d_ns_count) {
194 __do_timed_wait(__lk, __clock_tp_ns::max());
195 } else {
196 __do_timed_wait(__lk, __clock_tp_ns(nanoseconds(__now_count_ns + __d_ns_count)));
159 if (__now_count_ns > numeric_limits<__ns_rep>::max() - __d_ns_count) {
160 __do_timed_wait(__lk, __clock_tp_ns::max());
161 } else {
162 __do_timed_wait(__lk, __clock_tp_ns(nanoseconds(__now_count_ns + __d_ns_count)));
163 }
164
165 return steady_clock::now() - __c_now < __d ? cv_status::no_timeout : cv_status::timeout;
197166 }
198167
199 return steady_clock::now() - __c_now < __d ? cv_status::no_timeout : cv_status::timeout;
200}
168 template <class _Rep, class _Period, class _Predicate>
169 bool _LIBCPP_HIDE_FROM_ABI
170 wait_for(unique_lock<mutex>& __lk, const chrono::duration<_Rep, _Period>& __d, _Predicate __pred);
171
172 typedef __libcpp_condvar_t* native_handle_type;
173 _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() { return &__cv_; }
174
175private:
176 void
177 __do_timed_wait(unique_lock<mutex>& __lk, chrono::time_point<chrono::system_clock, chrono::nanoseconds>) _NOEXCEPT;
178# if _LIBCPP_HAS_COND_CLOCKWAIT
179 _LIBCPP_HIDE_FROM_ABI void
180 __do_timed_wait(unique_lock<mutex>& __lk, chrono::time_point<chrono::steady_clock, chrono::nanoseconds>) _NOEXCEPT;
181# endif
182 template <class _Clock>
183 _LIBCPP_HIDE_FROM_ABI void
184 __do_timed_wait(unique_lock<mutex>& __lk, chrono::time_point<_Clock, chrono::nanoseconds>) _NOEXCEPT;
185};
186#endif // _LIBCPP_HAS_THREADS
187
188#if _LIBCPP_HAS_THREADS
201189
202190template <class _Rep, class _Period, class _Predicate>
203191inline bool
......@@ -210,7 +198,7 @@ inline void condition_variable::__do_timed_wait(
210198 unique_lock<mutex>& __lk, chrono::time_point<chrono::steady_clock, chrono::nanoseconds> __tp) _NOEXCEPT {
211199 using namespace chrono;
212200 if (!__lk.owns_lock())
213 __throw_system_error(EPERM, "condition_variable::timed wait: mutex not locked");
201 std::__throw_system_error(EPERM, "condition_variable::timed wait: mutex not locked");
214202 nanoseconds __d = __tp.time_since_epoch();
215203 timespec __ts;
216204 seconds __s = duration_cast<seconds>(__d);
......@@ -225,7 +213,7 @@ inline void condition_variable::__do_timed_wait(
225213 }
226214 int __ec = pthread_cond_clockwait(&__cv_, __lk.mutex()->native_handle(), CLOCK_MONOTONIC, &__ts);
227215 if (__ec != 0 && __ec != ETIMEDOUT)
228 __throw_system_error(__ec, "condition_variable timed_wait failed");
216 std::__throw_system_error(__ec, "condition_variable timed_wait failed");
229217}
230218# endif // _LIBCPP_HAS_COND_CLOCKWAIT
231219
lib/libcxx/include/__config+186-162
......@@ -28,7 +28,7 @@
2828// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM.
2929// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is
3030// defined to XXYYZZ.
31# define _LIBCPP_VERSION 200100
31# define _LIBCPP_VERSION 210100
3232
3333# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
3434# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
......@@ -38,11 +38,47 @@
3838# define _LIBCPP_FREESTANDING
3939# endif
4040
41// NOLINTNEXTLINE(libcpp-cpp-version-check)
42# if __cplusplus < 201103L
43# define _LIBCPP_CXX03_LANG
44# endif
45
46# if __has_feature(experimental_library)
47# ifndef _LIBCPP_ENABLE_EXPERIMENTAL
48# define _LIBCPP_ENABLE_EXPERIMENTAL
49# endif
50# endif
51
52// Incomplete features get their own specific disabling flags. This makes it
53// easier to grep for target specific flags once the feature is complete.
54# if defined(_LIBCPP_ENABLE_EXPERIMENTAL) || defined(_LIBCPP_BUILDING_LIBRARY)
55# define _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 1
56# else
57# define _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 0
58# endif
59
60# define _LIBCPP_HAS_EXPERIMENTAL_PSTL _LIBCPP_HAS_EXPERIMENTAL_LIBRARY
61# define _LIBCPP_HAS_EXPERIMENTAL_TZDB _LIBCPP_HAS_EXPERIMENTAL_LIBRARY
62# define _LIBCPP_HAS_EXPERIMENTAL_SYNCSTREAM _LIBCPP_HAS_EXPERIMENTAL_LIBRARY
63# define _LIBCPP_HAS_EXPERIMENTAL_HARDENING_OBSERVE_SEMANTIC _LIBCPP_HAS_EXPERIMENTAL_LIBRARY
64
4165// HARDENING {
4266
43// TODO: Remove in LLVM 21. We're making this an error to catch folks who might not have migrated.
44# ifdef _LIBCPP_ENABLE_ASSERTIONS
45# error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE instead"
67// TODO(LLVM 23): Remove this. We're making these an error to catch folks who might not have migrated.
68// Since hardening went through several changes (many of which impacted user-facing macros),
69// we're keeping these checks around for a bit longer than usual. Failure to properly configure
70// hardening results in checks being dropped silently, which is a pretty big deal.
71# if defined(_LIBCPP_ENABLE_ASSERTIONS)
72# error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
73# endif
74# if defined(_LIBCPP_ENABLE_HARDENED_MODE)
75# error "_LIBCPP_ENABLE_HARDENED_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
76# endif
77# if defined(_LIBCPP_ENABLE_SAFE_MODE)
78# error "_LIBCPP_ENABLE_SAFE_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
79# endif
80# if defined(_LIBCPP_ENABLE_DEBUG_MODE)
81# error "_LIBCPP_ENABLE_DEBUG_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
4682# endif
4783
4884// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values:
......@@ -147,16 +183,53 @@ _LIBCPP_HARDENING_MODE_EXTENSIVE, \
147183_LIBCPP_HARDENING_MODE_DEBUG
148184# endif
149185
186// Hardening assertion semantics generally mirror the evaluation semantics of C++26 Contracts:
187// - `ignore` evaluates the assertion but doesn't do anything if it fails (note that it differs from the Contracts
188// `ignore` semantic which wouldn't evaluate the assertion at all);
189// - `observe` logs an error (indicating, if possible, that the error is fatal) and continues execution;
190// - `quick-enforce` terminates the program as fast as possible (via trapping);
191// - `enforce` logs an error and then terminates the program.
192//
193// Notes:
194// - Continuing execution after a hardening check fails results in undefined behavior; the `observe` semantic is meant
195// to make adopting hardening easier but should not be used outside of this scenario;
196// - C++26 wording for Library Hardening precludes a conforming Hardened implementation from using the Contracts
197// `ignore` semantic when evaluating hardened preconditions in the Library. Libc++ allows using this semantic for
198// hardened preconditions, however, be aware that using `ignore` does not produce a conforming "Hardened"
199// implementation, unlike the other semantics above.
200// clang-format off
201# define _LIBCPP_ASSERTION_SEMANTIC_IGNORE (1 << 1)
202# define _LIBCPP_ASSERTION_SEMANTIC_OBSERVE (1 << 2)
203# define _LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE (1 << 3)
204# define _LIBCPP_ASSERTION_SEMANTIC_ENFORCE (1 << 4)
205// clang-format on
206
207// Allow users to define an arbitrary assertion semantic; otherwise, use the default mapping from modes to semantics.
208// The default is for production-capable modes to use `quick-enforce` (i.e., trap) and for the `debug` mode to use
209// `enforce` (i.e., log and abort).
210# ifndef _LIBCPP_ASSERTION_SEMANTIC
211
212# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
213# define _LIBCPP_ASSERTION_SEMANTIC _LIBCPP_ASSERTION_SEMANTIC_ENFORCE
214# else
215# define _LIBCPP_ASSERTION_SEMANTIC _LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE
216# endif
217
218# else
219# if !_LIBCPP_HAS_EXPERIMENTAL_LIBRARY
220# error "Assertion semantics are an experimental feature."
221# endif
222# if defined(_LIBCPP_CXX03_LANG)
223# error "Assertion semantics are not available in the C++03 mode."
224# endif
225
226# endif // _LIBCPP_ASSERTION_SEMANTIC
227
150228// } HARDENING
151229
152230# define _LIBCPP_TOSTRING2(x) #x
153231# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
154232
155// NOLINTNEXTLINE(libcpp-cpp-version-check)
156# if __cplusplus < 201103L
157# define _LIBCPP_CXX03_LANG
158# endif
159
160233# ifndef __has_constexpr_builtin
161234# define __has_constexpr_builtin(x) 0
162235# endif
......@@ -190,24 +263,6 @@ _LIBCPP_HARDENING_MODE_DEBUG
190263# define _LIBCPP_ABI_VCRUNTIME
191264# endif
192265
193# if __has_feature(experimental_library)
194# ifndef _LIBCPP_ENABLE_EXPERIMENTAL
195# define _LIBCPP_ENABLE_EXPERIMENTAL
196# endif
197# endif
198
199// Incomplete features get their own specific disabling flags. This makes it
200// easier to grep for target specific flags once the feature is complete.
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
205# endif
206
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
211266# if defined(__MVS__)
212267# include <features.h> // for __NATIVE_ASCII_F
213268# endif
......@@ -319,41 +374,14 @@ typedef __char32_t char32_t;
319374
320375# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
321376
322// Objective-C++ features (opt-in)
323# if __has_feature(objc_arc)
324# define _LIBCPP_HAS_OBJC_ARC 1
325# else
326# define _LIBCPP_HAS_OBJC_ARC 0
327# endif
328
329# if __has_feature(objc_arc_weak)
330# define _LIBCPP_HAS_OBJC_ARC_WEAK 1
331# else
332# define _LIBCPP_HAS_OBJC_ARC_WEAK 0
333# endif
334
335# if __has_extension(blocks)
336# define _LIBCPP_HAS_EXTENSION_BLOCKS 1
337# else
338# define _LIBCPP_HAS_EXTENSION_BLOCKS 0
339# endif
340
341# if _LIBCPP_HAS_EXTENSION_BLOCKS && defined(__APPLE__)
377# if __has_extension(blocks) && defined(__APPLE__)
342378# define _LIBCPP_HAS_BLOCKS_RUNTIME 1
343379# else
344380# define _LIBCPP_HAS_BLOCKS_RUNTIME 0
345381# endif
346382
347# if __has_feature(address_sanitizer)
348# define _LIBCPP_HAS_ASAN 1
349# else
350# define _LIBCPP_HAS_ASAN 0
351# endif
352
353383# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
354384
355# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
356
357385# if defined(_LIBCPP_OBJECT_FORMAT_COFF)
358386
359387# ifdef _DLL
......@@ -363,35 +391,30 @@ typedef __char32_t char32_t;
363391# endif
364392
365393# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
366# define _LIBCPP_DLL_VIS
367394# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
368395# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
369396# define _LIBCPP_OVERRIDABLE_FUNC_VIS
370397# define _LIBCPP_EXPORTED_FROM_ABI
371398# elif defined(_LIBCPP_BUILDING_LIBRARY)
372# define _LIBCPP_DLL_VIS __declspec(dllexport)
373399# if defined(__MINGW32__)
374# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
400# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllexport)
375401# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
376402# else
377403# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
378# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
404# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __declspec(dllexport)
379405# endif
380# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
406# define _LIBCPP_OVERRIDABLE_FUNC_VIS __declspec(dllexport)
381407# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
382408# else
383# define _LIBCPP_DLL_VIS __declspec(dllimport)
384# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
409# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllimport)
385410# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
386411# define _LIBCPP_OVERRIDABLE_FUNC_VIS
387412# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
388413# endif
389414
390415# define _LIBCPP_HIDDEN
391# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
392# define _LIBCPP_TEMPLATE_VIS
393416# define _LIBCPP_TEMPLATE_DATA_VIS
394# define _LIBCPP_TYPE_VISIBILITY_DEFAULT
417# define _LIBCPP_NAMESPACE_VISIBILITY
395418
396419# else
397420
......@@ -412,24 +435,12 @@ typedef __char32_t char32_t;
412435# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default")
413436# endif
414437
415# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
416// The inline should be removed once PR32114 is resolved
417# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
418# else
419# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
420# endif
421
422// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates
423# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__)
424# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
425# else
426# define _LIBCPP_TEMPLATE_VIS
427# endif
428
429438# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
430# define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default")))
439# define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__type_visibility__("default")))
440# elif !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
441# define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__visibility__("default")))
431442# else
432# define _LIBCPP_TYPE_VISIBILITY_DEFAULT
443# define _LIBCPP_NAMESPACE_VISIBILITY
433444# endif
434445
435446# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
......@@ -549,24 +560,17 @@ typedef __char32_t char32_t;
549560# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
550561# endif
551562
552// TODO: Remove this workaround once we drop support for Clang 16
553# if __has_warning("-Wc++23-extensions")
554# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions")
555# else
556# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++2b-extensions")
557# endif
558
559563// Clang modules take a significant compile time hit when pushing and popping diagnostics.
560// Since all the headers are marked as system headers in the modulemap, we can simply disable this
561// pushing and popping when building with clang modules.
562# if !__has_feature(modules)
564// Since all the headers are marked as system headers unless _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER is defined, we can
565// simply disable this pushing and popping when _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER isn't defined.
566# ifdef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
563567# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \
564568 _LIBCPP_DIAGNOSTIC_PUSH \
565569 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions") \
566570 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \
567571 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \
568572 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \
569 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION \
573 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions") \
570574 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \
571575 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \
572576 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \
......@@ -577,15 +581,27 @@ typedef __char32_t char32_t;
577581# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS
578582# endif
579583
580// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
581584// clang-format off
582# define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \
583 namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \
584 inline namespace _LIBCPP_ABI_NAMESPACE {
585# define _LIBCPP_END_NAMESPACE_STD }} _LIBCPP_POP_EXTENSION_DIAGNOSTICS
586585
587#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace std { namespace experimental {
588#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL }}
586// The unversioned namespace is used when we want to be ABI compatible with other standard libraries in some way. There
587// are two main categories where that's the case:
588// - Historically, we have made exception types ABI compatible with libstdc++ to allow throwing them between libstdc++
589// and libc++. This is not used anymore for new exception types, since there is no use-case for it anymore.
590// - Types and functions which are used by the compiler are in the unversioned namespace, since the compiler has to know
591// their mangling without the appropriate declaration in some cases.
592// If it's not clear whether using the unversioned namespace is the correct thing to do, it's not. The versioned
593// namespace (_LIBCPP_BEGIN_NAMESPACE_STD) should almost always be used.
594# define _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD \
595 _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS namespace _LIBCPP_NAMESPACE_VISIBILITY std {
596
597# define _LIBCPP_END_UNVERSIONED_NAMESPACE_STD } _LIBCPP_POP_EXTENSION_DIAGNOSTICS
598
599# define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD inline namespace _LIBCPP_ABI_NAMESPACE {
600# define _LIBCPP_END_NAMESPACE_STD } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD
601
602// TODO: This should really be in the versioned namespace
603#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD namespace experimental {
604#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD
589605
590606#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 {
591607#define _LIBCPP_END_NAMESPACE_LFTS } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
......@@ -663,7 +679,10 @@ typedef __char32_t char32_t;
663679# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
664680 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \
665681 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
666 __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000)
682 __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) || \
683 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && \
684 __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 60000) || \
685 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 130000)
667686# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0
668687# else
669688# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1
......@@ -675,10 +694,6 @@ typedef __char32_t char32_t;
675694# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1
676695# endif
677696
678# if defined(__APPLE__) || defined(__FreeBSD__)
679# define _LIBCPP_HAS_DEFAULTRUNELOCALE
680# endif
681
682697# if defined(__APPLE__) || defined(__FreeBSD__)
683698# define _LIBCPP_WCTYPE_IS_MASK
684699# endif
......@@ -741,8 +756,10 @@ typedef __char32_t char32_t;
741756
742757# if _LIBCPP_STD_VER >= 26
743758# define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED
759# define _LIBCPP_DEPRECATED_IN_CXX26_(m) _LIBCPP_DEPRECATED_(m)
744760# else
745761# define _LIBCPP_DEPRECATED_IN_CXX26
762# define _LIBCPP_DEPRECATED_IN_CXX26_(m)
746763# endif
747764
748765# if _LIBCPP_HAS_CHAR8_T
......@@ -937,23 +954,6 @@ typedef __char32_t char32_t;
937954# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
938955# endif
939956
940// Work around the attribute handling in clang. When both __declspec and
941// __attribute__ are present, the processing goes awry preventing the definition
942// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
943// combining the two does work.
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
949# endif
950
951# if _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
952# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
953# else
954# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
955# endif
956
957957# if _LIBCPP_STD_VER >= 20
958958# define _LIBCPP_CONSTINIT constinit
959959# elif __has_attribute(__require_constant_initialization__)
......@@ -1064,9 +1064,8 @@ typedef __char32_t char32_t;
10641064# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "")
10651065# endif
10661066
1067// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use
1068// compiler intrinsics in the Objective-C++ mode.
1069# ifdef __OBJC__
1067// TODO(LLVM 22): Remove the workaround
1068# if defined(__OBJC__) && (!defined(_LIBCPP_CLANG_VER) || _LIBCPP_CLANG_VER < 2001)
10701069# define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS
10711070# endif
10721071
......@@ -1119,26 +1118,28 @@ typedef __char32_t char32_t;
11191118
11201119// Optional attributes - these are useful for a better QoI, but not required to be available
11211120
1121# define _LIBCPP_NOALIAS __attribute__((__malloc__))
1122# define _LIBCPP_NODEBUG [[__gnu__::__nodebug__]]
1123# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
1124# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
1125# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
1126 __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1127# define _LIBCPP_PACKED __attribute__((__packed__))
1128
11221129# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
11231130# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
11241131# else
11251132# define _LIBCPP_NO_CFI
11261133# endif
11271134
1128# if __has_attribute(__malloc__)
1129# define _LIBCPP_NOALIAS __attribute__((__malloc__))
1130# else
1131# define _LIBCPP_NOALIAS
1132# endif
1133
11341135# if __has_attribute(__using_if_exists__)
11351136# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__))
11361137# else
11371138# define _LIBCPP_USING_IF_EXISTS
11381139# endif
11391140
1140# if __has_attribute(__no_destroy__)
1141# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
1141# if __has_cpp_attribute(_Clang::__no_destroy__)
1142# define _LIBCPP_NO_DESTROY [[_Clang::__no_destroy__]]
11421143# else
11431144# define _LIBCPP_NO_DESTROY
11441145# endif
......@@ -1149,15 +1150,6 @@ typedef __char32_t char32_t;
11491150# define _LIBCPP_DIAGNOSE_WARNING(...)
11501151# endif
11511152
1152// Use a function like macro to imply that it must be followed by a semicolon
1153# if __has_cpp_attribute(fallthrough)
1154# define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1155# elif __has_attribute(__fallthrough__)
1156# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
1157# else
1158# define _LIBCPP_FALLTHROUGH() ((void)0)
1159# endif
1160
11611153# if __has_cpp_attribute(_Clang::__lifetimebound__)
11621154# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]]
11631155# else
......@@ -1170,8 +1162,6 @@ typedef __char32_t char32_t;
11701162# define _LIBCPP_NOESCAPE
11711163# endif
11721164
1173# define _LIBCPP_NODEBUG [[__gnu__::__nodebug__]]
1174
11751165# if __has_cpp_attribute(_Clang::__no_specializations__)
11761166# define _LIBCPP_NO_SPECIALIZATIONS \
11771167 [[_Clang::__no_specializations__("Users are not allowed to specialize this standard library entity")]]
......@@ -1179,43 +1169,70 @@ typedef __char32_t char32_t;
11791169# define _LIBCPP_NO_SPECIALIZATIONS
11801170# endif
11811171
1182# if __has_attribute(__standalone_debug__)
1183# define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1172# if __has_cpp_attribute(_Clang::__standalone_debug__)
1173# define _LIBCPP_STANDALONE_DEBUG [[_Clang::__standalone_debug__]]
11841174# else
11851175# define _LIBCPP_STANDALONE_DEBUG
11861176# endif
11871177
1188# if __has_attribute(__preferred_name__)
1189# define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1178# if __has_cpp_attribute(_Clang::__preferred_name__)
1179# define _LIBCPP_PREFERRED_NAME(x) [[_Clang::__preferred_name__(x)]]
11901180# else
11911181# define _LIBCPP_PREFERRED_NAME(x)
11921182# endif
11931183
1194# if __has_attribute(__no_sanitize__)
1195# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
1184# if __has_cpp_attribute(_Clang::__scoped_lockable__)
1185# define _LIBCPP_SCOPED_LOCKABLE [[_Clang::__scoped_lockable__]]
1186# else
1187# define _LIBCPP_SCOPED_LOCKABLE
1188# endif
1189
1190# if __has_cpp_attribute(_Clang::__capability__)
1191# define _LIBCPP_CAPABILITY(...) [[_Clang::__capability__(__VA_ARGS__)]]
11961192# else
1197# define _LIBCPP_NO_SANITIZE(...)
1193# define _LIBCPP_CAPABILITY(...)
11981194# endif
11991195
1200# if __has_attribute(__init_priority__)
1201# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
1196# if __has_attribute(__acquire_capability__)
1197# define _LIBCPP_ACQUIRE_CAPABILITY(...) __attribute__((__acquire_capability__(__VA_ARGS__)))
12021198# else
1203# define _LIBCPP_INIT_PRIORITY_MAX
1199# define _LIBCPP_ACQUIRE_CAPABILITY(...)
12041200# endif
12051201
1206# if __has_attribute(__format__)
1207// The attribute uses 1-based indices for ordinary and static member functions.
1208// The attribute uses 2-based indices for non-static member functions.
1209# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
1210 __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1202# if __has_cpp_attribute(_Clang::__try_acquire_capability__)
1203# define _LIBCPP_TRY_ACQUIRE_CAPABILITY(...) [[_Clang::__try_acquire_capability__(__VA_ARGS__)]]
12111204# else
1212# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
1205# define _LIBCPP_TRY_ACQUIRE_CAPABILITY(...)
12131206# endif
12141207
1215# if __has_attribute(__packed__)
1216# define _LIBCPP_PACKED __attribute__((__packed__))
1208# if __has_cpp_attribute(_Clang::__acquire_shared_capability__)
1209# define _LIBCPP_ACQUIRE_SHARED_CAPABILITY [[_Clang::__acquire_shared_capability__]]
12171210# else
1218# define _LIBCPP_PACKED
1211# define _LIBCPP_ACQUIRE_SHARED_CAPABILITY
1212# endif
1213
1214# if __has_cpp_attribute(_Clang::__try_acquire_shared_capability__)
1215# define _LIBCPP_TRY_ACQUIRE_SHARED_CAPABILITY(...) [[_Clang::__try_acquire_shared_capability__(__VA_ARGS__)]]
1216# else
1217# define _LIBCPP_TRY_ACQUIRE_SHARED_CAPABILITY(...)
1218# endif
1219
1220# if __has_cpp_attribute(_Clang::__release_capability__)
1221# define _LIBCPP_RELEASE_CAPABILITY [[_Clang::__release_capability__]]
1222# else
1223# define _LIBCPP_RELEASE_CAPABILITY
1224# endif
1225
1226# if __has_cpp_attribute(_Clang::__release_shared_capability__)
1227# define _LIBCPP_RELEASE_SHARED_CAPABILITY [[_Clang::__release_shared_capability__]]
1228# else
1229# define _LIBCPP_RELEASE_SHARED_CAPABILITY
1230# endif
1231
1232# if __has_attribute(__requires_capability__)
1233# define _LIBCPP_REQUIRES_CAPABILITY(...) __attribute__((__requires_capability__(__VA_ARGS__)))
1234# else
1235# define _LIBCPP_REQUIRES_CAPABILITY(...)
12191236# endif
12201237
12211238# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases)
......@@ -1231,6 +1248,13 @@ typedef __char32_t char32_t;
12311248# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
12321249# endif
12331250
1251# if __has_feature(nullability)
1252# define _LIBCPP_DIAGNOSE_NULLPTR _Nonnull
1253# else
1254# define _LIBCPP_DIAGNOSE_NULLPTR
1255# endif
1256
1257// TODO(LLVM 22): Remove this macro once LLVM19 support ends. __cpp_explicit_this_parameter has been set in LLVM20.
12341258// Clang-18 has support for deducing this, but it does not set the FTM.
12351259# if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800)
12361260# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 1
lib/libcxx/include/__configuration/abi.h+30-104
......@@ -38,92 +38,47 @@
3838#endif
3939
4040#if _LIBCPP_ABI_VERSION >= 2
41// Change short string representation so that string data starts at offset 0,
42// improving its alignment in some cases.
43# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
44// Fix deque iterator type in order to support incomplete types.
45# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
46// Fix undefined behavior in how std::list stores its linked nodes.
47# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
48// Fix undefined behavior in how __tree stores its end and parent nodes.
49# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
50// Fix undefined behavior in how __hash_table stores its pointer types.
51# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
52# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
53# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
41// TODO: Move the description of the remaining ABI flags to ABIGuarantees.rst or remove them.
42
5443// Override the default return value of exception::what() for bad_function_call::what()
5544// with a string that is specific to bad_function_call (see http://wg21.link/LWG2233).
5645// This is an ABI break on platforms that sign and authenticate vtable function pointers
5746// because it changes the mangling of the virtual function located in the vtable, which
5847// changes how it gets signed.
5948# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
60// Enable optimized version of __do_get_(un)signed which avoids redundant copies.
61# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
62// Give reverse_iterator<T> one data member of type T, not two.
63// Also, in C++17 and later, don't derive iterator types from std::iterator.
49// According to the Standard, `bitset::operator[] const` returns bool
50# define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
51
52// In LLVM 20, we've changed to take these ABI breaks unconditionally. These flags only exist in case someone is running
53// into the static_asserts we added to catch the ABI break and don't care that it is one.
54// TODO(LLVM 22): Remove these flags
55# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
56# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
57# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
58# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
59
60// These flags are documented in ABIGuarantees.rst
61# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
62# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
63# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
64# define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
65# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
66# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
67# define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION
68# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
69# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
70# define _LIBCPP_ABI_IOS_ALLOW_ARBITRARY_FILL_VALUE
71# define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING
72# define _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE
6473# define _LIBCPP_ABI_NO_ITERATOR_BASES
65// Use the smallest possible integer type to represent the index of the variant.
66// Previously libc++ used "unsigned int" exclusively.
67# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
68// Unstable attempt to provide a more optimized std::function
74# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
6975# define _LIBCPP_ABI_OPTIMIZED_FUNCTION
70// All the regex constants must be distinct and nonzero.
7176# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
72// Re-worked external template instantiations for std::string with a focus on
73// performance and fast-path inlining.
7477# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
75// Enable clang::trivial_abi on std::unique_ptr.
76# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
77// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr
78# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
79// std::random_device holds some state when it uses an implementation that gets
80// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this
81// implementation to another one on a platform that has already shipped
82// std::random_device, one needs to retain the same object layout to remain ABI
83// compatible. This switch removes these workarounds for platforms that don't care
84// about ABI compatibility.
85# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
86// Don't export the legacy __basic_string_common class and its methods from the built library.
87# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
88// Don't export the legacy __vector_base_common class and its methods from the built library.
89# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
90// According to the Standard, `bitset::operator[] const` returns bool
91# define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
92// Fix the implementation of CityHash used for std::hash<fundamental-type>.
93// This is an ABI break because `std::hash` will return a different result,
94// which means that hashing the same object in translation units built against
95// different versions of libc++ can return inconsistent results. This is especially
96// tricky since std::hash is used in the implementation of unordered containers.
97//
98// The incorrect implementation of CityHash has the problem that it drops some
99// bits on the floor.
100# define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION
101// Remove the base 10 implementation of std::to_chars from the dylib.
102// The implementation moved to the header, but we still export the symbols from
103// the dylib for backwards compatibility.
104# define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
105// Define std::array/std::string_view iterators to be __wrap_iters instead of raw
106// pointers, which prevents people from relying on a non-portable implementation
107// detail. This is especially useful because enabling bounded iterators hardening
108// requires code not to make these assumptions.
10978# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY
11079# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW
111// Dont' add an inline namespace for `std::filesystem`
112# define _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE
113// std::basic_ios uses WEOF to indicate that the fill value is
114// uninitialized. However, on platforms where the size of char_type is
115// equal to or greater than the size of int_type and char_type is unsigned,
116// std::char_traits<char_type>::eq_int_type() cannot distinguish between WEOF
117// and WCHAR_MAX. This ABI setting determines whether we should instead track whether the fill
118// value has been initialized using a separate boolean, which changes the ABI.
119# define _LIBCPP_ABI_IOS_ALLOW_ARBITRARY_FILL_VALUE
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
80# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
81
12782#elif _LIBCPP_ABI_VERSION == 1
12883# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
12984// Enable compiling copies of now inline methods into the dylib to support
......@@ -138,7 +93,7 @@
13893# endif
13994// Feature macros for disabling pre ABI v1 features. All of these options
14095// are deprecated.
141# if defined(__FreeBSD__) && __FreeBSD__ < 14
96# if defined(__FreeBSD__)
14297# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
14398# endif
14499#endif
......@@ -153,35 +108,6 @@
153108// The macro below is used for all classes whose ABI have changed as part of fixing these bugs.
154109#define _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS __attribute__((__abi_tag__("llvm18_nua")))
155110
156// Changes the iterator type of select containers (see below) to a bounded iterator that keeps track of whether it's
157// within the bounds of the original container and asserts it on every dereference.
158//
159// ABI impact: changes the iterator type of the relevant containers.
160//
161// Supported containers:
162// - `span`;
163// - `string_view`.
164// #define _LIBCPP_ABI_BOUNDED_ITERATORS
165
166// Changes the iterator type of `basic_string` to a bounded iterator that keeps track of whether it's within the bounds
167// of the original container and asserts it on every dereference and when performing iterator arithmetics.
168//
169// ABI impact: changes the iterator type of `basic_string` and its specializations, such as `string` and `wstring`.
170// #define _LIBCPP_ABI_BOUNDED_ITERATORS_IN_STRING
171
172// Changes the iterator type of `vector` to a bounded iterator that keeps track of whether it's within the bounds of the
173// original container and asserts it on every dereference and when performing iterator arithmetics. Note: this doesn't
174// yet affect `vector<bool>`.
175//
176// ABI impact: changes the iterator type of `vector` (except `vector<bool>`).
177// #define _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
178
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
185111// [[msvc::no_unique_address]] seems to mostly affect empty classes, so the padding scheme for Itanium doesn't work.
186112#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING)
187113# define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING
lib/libcxx/include/__configuration/availability.h+24-41
......@@ -69,7 +69,13 @@
6969
7070// Availability markup is disabled when building the library, or when a non-Clang
7171// compiler is used because only Clang supports the necessary attributes.
72#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCXXABI_BUILDING_LIBRARY) || !defined(_LIBCPP_COMPILER_CLANG_BASED)
72//
73// We also allow users to force-disable availability markup via the `_LIBCPP_DISABLE_AVAILABILITY`
74// macro because that is the only way to work around a Clang bug related to availability
75// attributes: https://github.com/llvm/llvm-project/issues/134151.
76// Once that bug has been fixed, we should remove the macro.
77#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCXXABI_BUILDING_LIBRARY) || \
78 !defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_DISABLE_AVAILABILITY)
7379# undef _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS
7480# define _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS 0
7581#endif
......@@ -78,6 +84,9 @@
7884// in all versions of the library are available.
7985#if !_LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS
8086
87# define _LIBCPP_INTRODUCED_IN_LLVM_21 1
88# define _LIBCPP_INTRODUCED_IN_LLVM_21_ATTRIBUTE /* nothing */
89
8190# define _LIBCPP_INTRODUCED_IN_LLVM_20 1
8291# define _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE /* nothing */
8392
......@@ -107,13 +116,15 @@
107116# define _LIBCPP_INTRODUCED_IN_LLVM_9_ATTRIBUTE_PUSH /* nothing */
108117# define _LIBCPP_INTRODUCED_IN_LLVM_9_ATTRIBUTE_POP /* nothing */
109118
110# define _LIBCPP_INTRODUCED_IN_LLVM_4 1
111# define _LIBCPP_INTRODUCED_IN_LLVM_4_ATTRIBUTE /* nothing */
112
113119#elif defined(__APPLE__)
114120
115121// clang-format off
116122
123// LLVM 21
124// TODO: Fill this in
125# define _LIBCPP_INTRODUCED_IN_LLVM_21 0
126# define _LIBCPP_INTRODUCED_IN_LLVM_21_ATTRIBUTE __attribute__((unavailable))
127
117128// LLVM 20
118129// TODO: Fill this in
119130# define _LIBCPP_INTRODUCED_IN_LLVM_20 0
......@@ -244,14 +255,6 @@
244255 _Pragma("clang attribute pop") \
245256 _Pragma("clang attribute pop")
246257
247// LLVM 4
248# if defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 50000
249# define _LIBCPP_INTRODUCED_IN_LLVM_4 0
250# else
251# define _LIBCPP_INTRODUCED_IN_LLVM_4 1
252# endif
253# define _LIBCPP_INTRODUCED_IN_LLVM_4_ATTRIBUTE __attribute__((availability(watchos, strict, introduced = 5.0)))
254
255258// clang-format on
256259
257260#else
......@@ -263,23 +266,6 @@
263266
264267#endif
265268
266// These macros control the availability of std::bad_optional_access and
267// other exception types. These were put in the shared library to prevent
268// code bloat from every user program defining the vtable for these exception
269// types.
270//
271// Note that when exceptions are disabled, the methods that normally throw
272// these exceptions can be used even on older deployment targets, but those
273// methods will abort instead of throwing.
274#define _LIBCPP_AVAILABILITY_HAS_BAD_OPTIONAL_ACCESS _LIBCPP_INTRODUCED_IN_LLVM_4
275#define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS _LIBCPP_INTRODUCED_IN_LLVM_4_ATTRIBUTE
276
277#define _LIBCPP_AVAILABILITY_HAS_BAD_VARIANT_ACCESS _LIBCPP_INTRODUCED_IN_LLVM_4
278#define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS _LIBCPP_INTRODUCED_IN_LLVM_4_ATTRIBUTE
279
280#define _LIBCPP_AVAILABILITY_HAS_BAD_ANY_CAST _LIBCPP_INTRODUCED_IN_LLVM_4
281#define _LIBCPP_AVAILABILITY_BAD_ANY_CAST _LIBCPP_INTRODUCED_IN_LLVM_4_ATTRIBUTE
282
283269// These macros control the availability of all parts of <filesystem> that
284270// depend on something in the dylib.
285271#define _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY _LIBCPP_INTRODUCED_IN_LLVM_9
......@@ -359,18 +345,15 @@
359345#define _LIBCPP_AVAILABILITY_HAS_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20
360346#define _LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE
361347
362// Define availability attributes that depend on _LIBCPP_HAS_EXCEPTIONS.
363// Those are defined in terms of the availability attributes above, and
364// should not be vendor-specific.
365#if !_LIBCPP_HAS_EXCEPTIONS
366# define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
367# define _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS
368# define _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
369#else
370# define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _LIBCPP_AVAILABILITY_BAD_ANY_CAST
371# define _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
372# define _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS
373#endif
348// This controls whether `std::__hash_memory` is available in the dylib, which
349// is used for some `std::hash` specializations.
350#define _LIBCPP_AVAILABILITY_HAS_HASH_MEMORY _LIBCPP_INTRODUCED_IN_LLVM_21
351// No attribute, since we've had hash in the headers before
352
353// This controls whether we provide a message for `bad_function_call::what()` that specific to `std::bad_function_call`.
354// See https://wg21.link/LWG2233. This requires `std::bad_function_call::what()` to be available in the dylib.
355#define _LIBCPP_AVAILABILITY_HAS_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE _LIBCPP_INTRODUCED_IN_LLVM_21
356// No attribute, since we've had bad_function_call::what() in the headers before
374357
375358// Define availability attributes that depend on both
376359// _LIBCPP_HAS_EXCEPTIONS and _LIBCPP_HAS_RTTI.
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 < 1800
37# warning "Libc++ only supports Clang 18 and later"
36# if _LIBCPP_CLANG_VER < 1900
37# warning "Libc++ only supports Clang 19 and later"
3838# endif
3939# elif defined(_LIBCPP_APPLE_CLANG_VER)
4040# if _LIBCPP_APPLE_CLANG_VER < 1500
lib/libcxx/include/__configuration/platform.h+7
......@@ -42,6 +42,13 @@
4242# endif
4343#endif
4444
45// This is required in order for _NEWLIB_VERSION to be defined in places where we use it.
46// TODO: We shouldn't be including arbitrarily-named headers from libc++ since this can break valid
47// user code. Move code paths that need _NEWLIB_VERSION to another customization mechanism.
48#if __has_include(<picolibc.h>)
49# include <picolibc.h>
50#endif
51
4552#ifndef __BYTE_ORDER__
4653# error \
4754 "Your compiler doesn't seem to define __BYTE_ORDER__, which is required by libc++ to know the endianness of your target platform"
lib/libcxx/include/__coroutine/coroutine_handle.h+4-4
......@@ -28,10 +28,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2828
2929// [coroutine.handle]
3030template <class _Promise = void>
31struct _LIBCPP_TEMPLATE_VIS coroutine_handle;
31struct coroutine_handle;
3232
3333template <>
34struct _LIBCPP_TEMPLATE_VIS coroutine_handle<void> {
34struct coroutine_handle<void> {
3535public:
3636 // [coroutine.handle.con], construct/reset
3737 constexpr coroutine_handle() noexcept = default;
......@@ -93,7 +93,7 @@ operator<=>(coroutine_handle<> __x, coroutine_handle<> __y) noexcept {
9393}
9494
9595template <class _Promise>
96struct _LIBCPP_TEMPLATE_VIS coroutine_handle {
96struct coroutine_handle {
9797public:
9898 // [coroutine.handle.con], construct/reset
9999 constexpr coroutine_handle() noexcept = default;
......@@ -172,6 +172,6 @@ struct hash<coroutine_handle<_Tp>> {
172172
173173_LIBCPP_END_NAMESPACE_STD
174174
175#endif // __LIBCPP_STD_VER >= 20
175#endif // _LIBCPP_STD_VER >= 20
176176
177177#endif // _LIBCPP___COROUTINE_COROUTINE_HANDLE_H
lib/libcxx/include/__coroutine/coroutine_traits.h+1-1
......@@ -43,6 +43,6 @@ struct coroutine_traits : public __coroutine_traits_sfinae<_Ret> {};
4343
4444_LIBCPP_END_NAMESPACE_STD
4545
46#endif // __LIBCPP_STD_VER >= 20
46#endif // _LIBCPP_STD_VER >= 20
4747
4848#endif // _LIBCPP___COROUTINE_COROUTINE_TRAITS_H
lib/libcxx/include/__coroutine/noop_coroutine_handle.h+2-2
......@@ -28,7 +28,7 @@ struct noop_coroutine_promise {};
2828
2929// [coroutine.handle.noop]
3030template <>
31struct _LIBCPP_TEMPLATE_VIS coroutine_handle<noop_coroutine_promise> {
31struct coroutine_handle<noop_coroutine_promise> {
3232public:
3333 // [coroutine.handle.noop.conv], conversion
3434 _LIBCPP_HIDE_FROM_ABI constexpr operator coroutine_handle<>() const noexcept {
......@@ -94,6 +94,6 @@ inline _LIBCPP_HIDE_FROM_ABI noop_coroutine_handle noop_coroutine() noexcept { r
9494
9595_LIBCPP_END_NAMESPACE_STD
9696
97#endif // __LIBCPP_STD_VER >= 20
97#endif // _LIBCPP_STD_VER >= 20
9898
9999#endif // _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H
lib/libcxx/include/__coroutine/trivial_awaitables.h+1-1
......@@ -35,6 +35,6 @@ struct suspend_always {
3535
3636_LIBCPP_END_NAMESPACE_STD
3737
38#endif // __LIBCPP_STD_VER >= 20
38#endif // _LIBCPP_STD_VER >= 20
3939
4040#endif // __LIBCPP___COROUTINE_TRIVIAL_AWAITABLES_H
lib/libcxx/include/__cstddef/byte.h+2-2
......@@ -19,7 +19,7 @@
1919#endif
2020
2121#if _LIBCPP_STD_VER >= 17
22namespace std { // purposefully not versioned
22_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
2323
2424enum class byte : unsigned char {};
2525
......@@ -79,7 +79,7 @@ template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
7979 return static_cast<_Integer>(__b);
8080}
8181
82} // namespace std
82_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
8383#endif // _LIBCPP_STD_VER >= 17
8484
8585#endif // _LIBCPP___CSTDDEF_BYTE_H
lib/libcxx/include/__debug_utils/sanitizers.h+5-5
......@@ -17,7 +17,7 @@
1717# pragma GCC system_header
1818#endif
1919
20#if _LIBCPP_HAS_ASAN
20#if __has_feature(address_sanitizer)
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_ASAN
31#endif // __has_feature(address_sanitizer)
3232
3333_LIBCPP_BEGIN_NAMESPACE_STD
3434
3535// ASan choices
36#if _LIBCPP_HAS_ASAN
36#if __has_feature(address_sanitizer)
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#if !_LIBCPP_HAS_ASAN
60#if !__has_feature(address_sanitizer)
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#if !_LIBCPP_HAS_ASAN
89#if !__has_feature(address_sanitizer)
9090 (void)__first_storage;
9191 (void)__last_storage;
9292 (void)__old_last_contained;
lib/libcxx/include/__exception/exception.h+2-2
......@@ -21,7 +21,7 @@
2121# pragma GCC system_header
2222#endif
2323
24namespace std { // purposefully not using versioning namespace
24_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
2525
2626#if defined(_LIBCPP_ABI_VCRUNTIME) && (!defined(_HAS_EXCEPTIONS) || _HAS_EXCEPTIONS != 0)
2727// The std::exception class was already included above, but we're explicit about this condition here for clarity.
......@@ -89,6 +89,6 @@ public:
8989};
9090#endif // !_LIBCPP_ABI_VCRUNTIME
9191
92} // namespace std
92_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
9393
9494#endif // _LIBCPP___EXCEPTION_EXCEPTION_H
lib/libcxx/include/__exception/exception_ptr.h+49-21
......@@ -15,6 +15,7 @@
1515#include <__memory/addressof.h>
1616#include <__memory/construct_at.h>
1717#include <__type_traits/decay.h>
18#include <__type_traits/is_pointer.h>
1819#include <cstdlib>
1920#include <typeinfo>
2021
......@@ -52,7 +53,7 @@ _LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
5253
5354#endif
5455
55namespace std { // purposefully not using versioning namespace
56_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
5657
5758#ifndef _LIBCPP_ABI_MICROSOFT
5859
......@@ -62,11 +63,13 @@ class _LIBCPP_EXPORTED_FROM_ABI exception_ptr {
6263 static exception_ptr __from_native_exception_pointer(void*) _NOEXCEPT;
6364
6465 template <class _Ep>
65 friend _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep) _NOEXCEPT;
66 friend _LIBCPP_HIDE_FROM_ABI exception_ptr __make_exception_ptr_explicit(_Ep&) _NOEXCEPT;
6667
6768public:
68 // exception_ptr is basically a COW string.
69 // exception_ptr is basically a COW string so it is trivially relocatable.
70 // It is also replaceable because assignment has normal value semantics.
6971 using __trivially_relocatable _LIBCPP_NODEBUG = exception_ptr;
72 using __replaceable _LIBCPP_NODEBUG = exception_ptr;
7073
7174 _LIBCPP_HIDE_FROM_ABI exception_ptr() _NOEXCEPT : __ptr_() {}
7275 _LIBCPP_HIDE_FROM_ABI exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {}
......@@ -89,25 +92,21 @@ public:
8992 friend _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr);
9093};
9194
92template <class _Ep>
93_LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
9495# if _LIBCPP_HAS_EXCEPTIONS
95# if _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION && __cplusplus >= 201103L
96# if _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION
97template <class _Ep>
98_LIBCPP_HIDE_FROM_ABI exception_ptr __make_exception_ptr_explicit(_Ep& __e) _NOEXCEPT {
9699 using _Ep2 = __decay_t<_Ep>;
97
98100 void* __ex = __cxxabiv1::__cxa_allocate_exception(sizeof(_Ep));
99101# ifdef __wasm__
100 // In Wasm, a destructor returns its argument
101 (void)__cxxabiv1::__cxa_init_primary_exception(
102 __ex, const_cast<std::type_info*>(&typeid(_Ep)), [](void* __p) -> void* {
102 auto __cleanup = [](void* __p) -> void* {
103 std::__destroy_at(static_cast<_Ep2*>(__p));
104 return __p;
105 };
103106# else
104 (void)__cxxabiv1::__cxa_init_primary_exception(__ex, const_cast<std::type_info*>(&typeid(_Ep)), [](void* __p) {
105# endif
106 std::__destroy_at(static_cast<_Ep2*>(__p));
107# ifdef __wasm__
108 return __p;
107 auto __cleanup = [](void* __p) { std::__destroy_at(static_cast<_Ep2*>(__p)); };
109108# endif
110 });
109 (void)__cxxabiv1::__cxa_init_primary_exception(__ex, const_cast<std::type_info*>(&typeid(_Ep)), __cleanup);
111110
112111 try {
113112 ::new (__ex) _Ep2(__e);
......@@ -116,18 +115,47 @@ _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
116115 __cxxabiv1::__cxa_free_exception(__ex);
117116 return current_exception();
118117 }
119# else
118}
119# endif
120
121template <class _Ep>
122_LIBCPP_HIDE_FROM_ABI exception_ptr __make_exception_ptr_via_throw(_Ep& __e) _NOEXCEPT {
120123 try {
121124 throw __e;
122125 } catch (...) {
123126 return current_exception();
124127 }
128}
129
130template <class _Ep>
131_LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
132 // Objective-C exceptions are thrown via pointer. When throwing an Objective-C exception,
133 // Clang generates a call to `objc_exception_throw` instead of the usual `__cxa_throw`.
134 // That function creates an exception with a special Objective-C typeinfo instead of
135 // the usual C++ typeinfo, since that is needed to implement the behavior documented
136 // at [1]).
137 //
138 // Because of this special behavior, we can't create an exception via `__cxa_init_primary_exception`
139 // for Objective-C exceptions, otherwise we'd bypass `objc_exception_throw`. See https://llvm.org/PR135089.
140 //
141 // [1]:
142 // https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Exceptions/Articles/Exceptions64Bit.html
143 if _LIBCPP_CONSTEXPR (is_pointer<_Ep>::value) {
144 return std::__make_exception_ptr_via_throw(__e);
145 }
146
147# if _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION && !defined(_LIBCPP_CXX03_LANG)
148 return std::__make_exception_ptr_explicit(__e);
149# else
150 return std::__make_exception_ptr_via_throw(__e);
125151# endif
126# else
127 ((void)__e);
152}
153# else // !_LIBCPP_HAS_EXCEPTIONS
154template <class _Ep>
155_LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep) _NOEXCEPT {
128156 std::abort();
129# endif
130157}
158# endif // _LIBCPP_HAS_EXCEPTIONS
131159
132160#else // _LIBCPP_ABI_MICROSOFT
133161
......@@ -171,6 +199,6 @@ _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
171199}
172200
173201#endif // _LIBCPP_ABI_MICROSOFT
174} // namespace std
202_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
175203
176204#endif // _LIBCPP___EXCEPTION_EXCEPTION_PTR_H
lib/libcxx/include/__exception/nested_exception.h+2-2
......@@ -27,7 +27,7 @@
2727# pragma GCC system_header
2828#endif
2929
30namespace std { // purposefully not using versioning namespace
30_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
3131
3232class _LIBCPP_EXPORTED_FROM_ABI nested_exception {
3333 exception_ptr __ptr_;
......@@ -95,6 +95,6 @@ inline _LIBCPP_HIDE_FROM_ABI void rethrow_if_nested(const _Ep& __e) {
9595template <class _Ep, __enable_if_t<!__can_dynamic_cast<_Ep, nested_exception>::value, int> = 0>
9696inline _LIBCPP_HIDE_FROM_ABI void rethrow_if_nested(const _Ep&) {}
9797
98} // namespace std
98_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
9999
100100#endif // _LIBCPP___EXCEPTION_NESTED_EXCEPTION_H
lib/libcxx/include/__exception/operations.h+2-2
......@@ -15,7 +15,7 @@
1515# pragma GCC system_header
1616#endif
1717
18namespace std { // purposefully not using versioning namespace
18_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
1919#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS) || \
2020 defined(_LIBCPP_BUILDING_LIBRARY)
2121using unexpected_handler = void (*)();
......@@ -37,6 +37,6 @@ class _LIBCPP_EXPORTED_FROM_ABI exception_ptr;
3737
3838_LIBCPP_EXPORTED_FROM_ABI exception_ptr current_exception() _NOEXCEPT;
3939[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr);
40} // namespace std
40_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
4141
4242#endif // _LIBCPP___EXCEPTION_OPERATIONS_H
lib/libcxx/include/__exception/terminate.h+2-2
......@@ -15,8 +15,8 @@
1515# pragma GCC system_header
1616#endif
1717
18namespace std { // purposefully not using versioning namespace
18_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
1919[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void terminate() _NOEXCEPT;
20} // namespace std
20_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
2121
2222#endif // _LIBCPP___EXCEPTION_TERMINATE_H
lib/libcxx/include/__expected/expected.h+40-5
......@@ -25,10 +25,12 @@
2525#include <__type_traits/is_assignable.h>
2626#include <__type_traits/is_constructible.h>
2727#include <__type_traits/is_convertible.h>
28#include <__type_traits/is_core_convertible.h>
2829#include <__type_traits/is_function.h>
2930#include <__type_traits/is_nothrow_assignable.h>
3031#include <__type_traits/is_nothrow_constructible.h>
3132#include <__type_traits/is_reference.h>
33#include <__type_traits/is_replaceable.h>
3234#include <__type_traits/is_same.h>
3335#include <__type_traits/is_swappable.h>
3436#include <__type_traits/is_trivially_constructible.h>
......@@ -470,6 +472,8 @@ public:
470472 __conditional_t<__libcpp_is_trivially_relocatable<_Tp>::value && __libcpp_is_trivially_relocatable<_Err>::value,
471473 expected,
472474 void>;
475 using __replaceable _LIBCPP_NODEBUG =
476 __conditional_t<__is_replaceable_v<_Tp> && __is_replaceable_v<_Err>, expected, void>;
473477
474478 template <class _Up>
475479 using rebind = expected<_Up, error_type>;
......@@ -1139,8 +1143,15 @@ public:
11391143
11401144 // [expected.object.eq], equality operators
11411145 template <class _T2, class _E2>
1146 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const expected<_T2, _E2>& __y)
11421147 requires(!is_void_v<_T2>)
1143 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const expected<_T2, _E2>& __y) {
1148# if _LIBCPP_STD_VER >= 26
1149 && requires {
1150 { *__x == *__y } -> __core_convertible_to<bool>;
1151 { __x.error() == __y.error() } -> __core_convertible_to<bool>;
1152 }
1153# endif
1154 {
11441155 if (__x.__has_val() != __y.__has_val()) {
11451156 return false;
11461157 } else {
......@@ -1153,12 +1164,24 @@ public:
11531164 }
11541165
11551166 template <class _T2>
1156 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const _T2& __v) {
1167 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const _T2& __v)
1168# if _LIBCPP_STD_VER >= 26
1169 requires(!__is_std_expected<_T2>::value) && requires {
1170 { *__x == __v } -> __core_convertible_to<bool>;
1171 }
1172# endif
1173 {
11571174 return __x.__has_val() && static_cast<bool>(__x.__val() == __v);
11581175 }
11591176
11601177 template <class _E2>
1161 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const unexpected<_E2>& __e) {
1178 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const unexpected<_E2>& __e)
1179# if _LIBCPP_STD_VER >= 26
1180 requires requires {
1181 { __x.error() == __e.error() } -> __core_convertible_to<bool>;
1182 }
1183# endif
1184 {
11621185 return !__x.__has_val() && static_cast<bool>(__x.__unex() == __e.error());
11631186 }
11641187};
......@@ -1851,7 +1874,13 @@ public:
18511874 // [expected.void.eq], equality operators
18521875 template <class _T2, class _E2>
18531876 requires is_void_v<_T2>
1854 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const expected<_T2, _E2>& __y) {
1877 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const expected<_T2, _E2>& __y)
1878# if _LIBCPP_STD_VER >= 26
1879 requires requires {
1880 { __x.error() == __y.error() } -> __core_convertible_to<bool>;
1881 }
1882# endif
1883 {
18551884 if (__x.__has_val() != __y.__has_val()) {
18561885 return false;
18571886 } else {
......@@ -1860,7 +1889,13 @@ public:
18601889 }
18611890
18621891 template <class _E2>
1863 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const unexpected<_E2>& __y) {
1892 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const unexpected<_E2>& __y)
1893# if _LIBCPP_STD_VER >= 26
1894 requires requires {
1895 { __x.error() == __y.error() } -> __core_convertible_to<bool>;
1896 }
1897# endif
1898 {
18641899 return !__x.__has_val() && static_cast<bool>(__x.__unex() == __y.error());
18651900 }
18661901};
lib/libcxx/include/__filesystem/directory_entry.h+1-1
......@@ -286,7 +286,7 @@ private:
286286 return;
287287 }
288288 if (__ec && (!__allow_dne || !__is_dne_error(__ec)))
289 __throw_filesystem_error(__msg, __p_, __ec);
289 filesystem::__throw_filesystem_error(__msg, __p_, __ec);
290290 }
291291
292292 _LIBCPP_HIDE_FROM_ABI void __refresh(error_code* __ec = nullptr) {
lib/libcxx/include/__filesystem/operations.h+3-3
......@@ -66,6 +66,9 @@ _LIBCPP_EXPORTED_FROM_ABI bool __remove(const path&, error_code* __ec = nullptr)
6666_LIBCPP_EXPORTED_FROM_ABI void __rename(const path& __from, const path& __to, error_code* __ec = nullptr);
6767_LIBCPP_EXPORTED_FROM_ABI void __resize_file(const path&, uintmax_t __size, error_code* = nullptr);
6868_LIBCPP_EXPORTED_FROM_ABI path __temp_directory_path(error_code* __ec = nullptr);
69_LIBCPP_EXPORTED_FROM_ABI bool __fs_is_empty(const path& __p, error_code* __ec = nullptr);
70_LIBCPP_EXPORTED_FROM_ABI void __permissions(const path&, perms, perm_options, error_code* = nullptr);
71_LIBCPP_EXPORTED_FROM_ABI space_info __space(const path&, error_code* __ec = nullptr);
6972
7073inline _LIBCPP_HIDE_FROM_ABI path absolute(const path& __p) { return __absolute(__p); }
7174inline _LIBCPP_HIDE_FROM_ABI path absolute(const path& __p, error_code& __ec) { return __absolute(__p, &__ec); }
......@@ -182,7 +185,6 @@ inline _LIBCPP_HIDE_FROM_ABI bool is_directory(const path& __p) { return is_dire
182185inline _LIBCPP_HIDE_FROM_ABI bool is_directory(const path& __p, error_code& __ec) noexcept {
183186 return is_directory(__status(__p, &__ec));
184187}
185_LIBCPP_EXPORTED_FROM_ABI bool __fs_is_empty(const path& __p, error_code* __ec = nullptr);
186188inline _LIBCPP_HIDE_FROM_ABI bool is_empty(const path& __p) { return __fs_is_empty(__p); }
187189inline _LIBCPP_HIDE_FROM_ABI bool is_empty(const path& __p, error_code& __ec) { return __fs_is_empty(__p, &__ec); }
188190inline _LIBCPP_HIDE_FROM_ABI bool is_fifo(file_status __s) noexcept { return __s.type() == file_type::fifo; }
......@@ -220,7 +222,6 @@ inline _LIBCPP_HIDE_FROM_ABI void last_write_time(const path& __p, file_time_typ
220222inline _LIBCPP_HIDE_FROM_ABI void last_write_time(const path& __p, file_time_type __t, error_code& __ec) noexcept {
221223 __last_write_time(__p, __t, &__ec);
222224}
223_LIBCPP_EXPORTED_FROM_ABI void __permissions(const path&, perms, perm_options, error_code* = nullptr);
224225inline _LIBCPP_HIDE_FROM_ABI void
225226permissions(const path& __p, perms __prms, perm_options __opts = perm_options::replace) {
226227 __permissions(__p, __prms, __opts);
......@@ -281,7 +282,6 @@ inline _LIBCPP_HIDE_FROM_ABI void resize_file(const path& __p, uintmax_t __ns) {
281282inline _LIBCPP_HIDE_FROM_ABI void resize_file(const path& __p, uintmax_t __ns, error_code& __ec) noexcept {
282283 return __resize_file(__p, __ns, &__ec);
283284}
284_LIBCPP_EXPORTED_FROM_ABI space_info __space(const path&, error_code* __ec = nullptr);
285285inline _LIBCPP_HIDE_FROM_ABI space_info space(const path& __p) { return __space(__p); }
286286inline _LIBCPP_HIDE_FROM_ABI space_info space(const path& __p, error_code& __ec) noexcept {
287287 return __space(__p, &__ec);
lib/libcxx/include/__filesystem/path.h+3-2
......@@ -17,7 +17,9 @@
1717#include <__fwd/functional.h>
1818#include <__iterator/back_insert_iterator.h>
1919#include <__iterator/iterator_traits.h>
20#include <__memory/addressof.h>
2021#include <__type_traits/decay.h>
22#include <__type_traits/enable_if.h>
2123#include <__type_traits/is_pointer.h>
2224#include <__type_traits/remove_const.h>
2325#include <__type_traits/remove_pointer.h>
......@@ -27,7 +29,6 @@
2729
2830#if _LIBCPP_HAS_LOCALIZATION
2931# include <iomanip> // for quoted
30# include <locale>
3132#endif
3233
3334#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -583,7 +584,7 @@ public:
583584
584585 template <class _ECharT, __enable_if_t<__can_convert_char<_ECharT>::value, int> = 0>
585586 _LIBCPP_HIDE_FROM_ABI path& operator+=(_ECharT __x) {
586 _PathCVT<_ECharT>::__append_source(__pn_, basic_string_view<_ECharT>(&__x, 1));
587 _PathCVT<_ECharT>::__append_source(__pn_, basic_string_view<_ECharT>(std::addressof(__x), 1));
587588 return *this;
588589 }
589590
lib/libcxx/include/__filesystem/u8path.h+1-6
......@@ -13,14 +13,9 @@
1313#include <__algorithm/unwrap_iter.h>
1414#include <__config>
1515#include <__filesystem/path.h>
16#include <__locale>
1617#include <string>
1718
18// Only required on Windows for __widen_from_utf8, and included conservatively
19// because it requires support for localization.
20#if defined(_LIBCPP_WIN32API)
21# include <locale>
22#endif
23
2419#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2520# pragma GCC system_header
2621#endif
lib/libcxx/include/__flat_map/flat_map.h+258-185
......@@ -11,16 +11,15 @@
1111#define _LIBCPP___FLAT_MAP_FLAT_MAP_H
1212
1313#include <__algorithm/lexicographical_compare_three_way.h>
14#include <__algorithm/lower_bound.h>
1415#include <__algorithm/min.h>
1516#include <__algorithm/ranges_adjacent_find.h>
1617#include <__algorithm/ranges_equal.h>
1718#include <__algorithm/ranges_inplace_merge.h>
18#include <__algorithm/ranges_lower_bound.h>
19#include <__algorithm/ranges_partition_point.h>
2019#include <__algorithm/ranges_sort.h>
2120#include <__algorithm/ranges_unique.h>
22#include <__algorithm/ranges_upper_bound.h>
2321#include <__algorithm/remove_if.h>
22#include <__algorithm/upper_bound.h>
2423#include <__assert>
2524#include <__compare/synth_three_way.h>
2625#include <__concepts/swappable.h>
......@@ -33,6 +32,7 @@
3332#include <__functional/invoke.h>
3433#include <__functional/is_transparent.h>
3534#include <__functional/operations.h>
35#include <__fwd/memory.h>
3636#include <__fwd/vector.h>
3737#include <__iterator/concepts.h>
3838#include <__iterator/distance.h>
......@@ -114,11 +114,12 @@ public:
114114 class value_compare {
115115 private:
116116 _LIBCPP_NO_UNIQUE_ADDRESS key_compare __comp_;
117 _LIBCPP_HIDE_FROM_ABI value_compare(key_compare __c) : __comp_(__c) {}
117 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 value_compare(key_compare __c) : __comp_(__c) {}
118118 friend flat_map;
119119
120120 public:
121 _LIBCPP_HIDE_FROM_ABI bool operator()(const_reference __x, const_reference __y) const {
121 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool
122 operator()(const_reference __x, const_reference __y) const {
122123 return __comp_(__x.first, __y.first);
123124 }
124125 };
......@@ -137,14 +138,14 @@ private:
137138
138139public:
139140 // [flat.map.cons], construct/copy/destroy
140 _LIBCPP_HIDE_FROM_ABI flat_map() noexcept(
141 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map() noexcept(
141142 is_nothrow_default_constructible_v<_KeyContainer> && is_nothrow_default_constructible_v<_MappedContainer> &&
142143 is_nothrow_default_constructible_v<_Compare>)
143144 : __containers_(), __compare_() {}
144145
145146 _LIBCPP_HIDE_FROM_ABI flat_map(const flat_map&) = default;
146147
147 _LIBCPP_HIDE_FROM_ABI flat_map(flat_map&& __other) noexcept(
148 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(flat_map&& __other) noexcept(
148149 is_nothrow_move_constructible_v<_KeyContainer> && is_nothrow_move_constructible_v<_MappedContainer> &&
149150 is_nothrow_move_constructible_v<_Compare>)
150151# if _LIBCPP_HAS_EXCEPTIONS
......@@ -165,7 +166,7 @@ public:
165166
166167 template <class _Allocator>
167168 requires __allocator_ctor_constraint<_Allocator>
168 _LIBCPP_HIDE_FROM_ABI flat_map(const flat_map& __other, const _Allocator& __alloc)
169 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(const flat_map& __other, const _Allocator& __alloc)
169170 : flat_map(__ctor_uses_allocator_tag{},
170171 __alloc,
171172 __other.__containers_.keys,
......@@ -174,7 +175,7 @@ public:
174175
175176 template <class _Allocator>
176177 requires __allocator_ctor_constraint<_Allocator>
177 _LIBCPP_HIDE_FROM_ABI flat_map(flat_map&& __other, const _Allocator& __alloc)
178 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(flat_map&& __other, const _Allocator& __alloc)
178179# if _LIBCPP_HAS_EXCEPTIONS
179180 try
180181# endif // _LIBCPP_HAS_EXCEPTIONS
......@@ -191,7 +192,7 @@ public:
191192# endif // _LIBCPP_HAS_EXCEPTIONS
192193 }
193194
194 _LIBCPP_HIDE_FROM_ABI flat_map(
195 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(
195196 key_container_type __key_cont, mapped_container_type __mapped_cont, const key_compare& __comp = key_compare())
196197 : __containers_{.keys = std::move(__key_cont), .values = std::move(__mapped_cont)}, __compare_(__comp) {
197198 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
......@@ -201,7 +202,7 @@ public:
201202
202203 template <class _Allocator>
203204 requires __allocator_ctor_constraint<_Allocator>
204 _LIBCPP_HIDE_FROM_ABI
205 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
205206 flat_map(const key_container_type& __key_cont, const mapped_container_type& __mapped_cont, const _Allocator& __alloc)
206207 : flat_map(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont) {
207208 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
......@@ -211,7 +212,7 @@ public:
211212
212213 template <class _Allocator>
213214 requires __allocator_ctor_constraint<_Allocator>
214 _LIBCPP_HIDE_FROM_ABI
215 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
215216 flat_map(const key_container_type& __key_cont,
216217 const mapped_container_type& __mapped_cont,
217218 const key_compare& __comp,
......@@ -222,7 +223,7 @@ public:
222223 __sort_and_unique();
223224 }
224225
225 _LIBCPP_HIDE_FROM_ABI
226 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
226227 flat_map(sorted_unique_t,
227228 key_container_type __key_cont,
228229 mapped_container_type __mapped_cont,
......@@ -236,7 +237,7 @@ public:
236237
237238 template <class _Allocator>
238239 requires __allocator_ctor_constraint<_Allocator>
239 _LIBCPP_HIDE_FROM_ABI
240 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
240241 flat_map(sorted_unique_t,
241242 const key_container_type& __key_cont,
242243 const mapped_container_type& __mapped_cont,
......@@ -250,12 +251,12 @@ public:
250251
251252 template <class _Allocator>
252253 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)
254 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(
255 sorted_unique_t,
256 const key_container_type& __key_cont,
257 const mapped_container_type& __mapped_cont,
258 const key_compare& __comp,
259 const _Allocator& __alloc)
259260 : flat_map(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont, __comp) {
260261 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
261262 "flat_map keys and mapped containers have different size");
......@@ -263,21 +264,22 @@ public:
263264 __is_sorted_and_unique(__containers_.keys), "Either the key container is not sorted or it contains duplicates");
264265 }
265266
266 _LIBCPP_HIDE_FROM_ABI explicit flat_map(const key_compare& __comp) : __containers_(), __compare_(__comp) {}
267 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit flat_map(const key_compare& __comp)
268 : __containers_(), __compare_(__comp) {}
267269
268270 template <class _Allocator>
269271 requires __allocator_ctor_constraint<_Allocator>
270 _LIBCPP_HIDE_FROM_ABI flat_map(const key_compare& __comp, const _Allocator& __alloc)
272 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(const key_compare& __comp, const _Allocator& __alloc)
271273 : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {}
272274
273275 template <class _Allocator>
274276 requires __allocator_ctor_constraint<_Allocator>
275 _LIBCPP_HIDE_FROM_ABI explicit flat_map(const _Allocator& __alloc)
277 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit flat_map(const _Allocator& __alloc)
276278 : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc) {}
277279
278280 template <class _InputIterator>
279281 requires __has_input_iterator_category<_InputIterator>::value
280 _LIBCPP_HIDE_FROM_ABI
282 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
281283 flat_map(_InputIterator __first, _InputIterator __last, const key_compare& __comp = key_compare())
282284 : __containers_(), __compare_(__comp) {
283285 insert(__first, __last);
......@@ -285,7 +287,7 @@ public:
285287
286288 template <class _InputIterator, class _Allocator>
287289 requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>)
288 _LIBCPP_HIDE_FROM_ABI
290 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
289291 flat_map(_InputIterator __first, _InputIterator __last, const key_compare& __comp, const _Allocator& __alloc)
290292 : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {
291293 insert(__first, __last);
......@@ -293,99 +295,105 @@ public:
293295
294296 template <class _InputIterator, class _Allocator>
295297 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)
298 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
299 flat_map(_InputIterator __first, _InputIterator __last, const _Allocator& __alloc)
297300 : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc) {
298301 insert(__first, __last);
299302 }
300303
301304 template <_ContainerCompatibleRange<value_type> _Range>
302 _LIBCPP_HIDE_FROM_ABI flat_map(from_range_t __fr, _Range&& __rg)
305 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(from_range_t __fr, _Range&& __rg)
303306 : flat_map(__fr, std::forward<_Range>(__rg), key_compare()) {}
304307
305308 template <_ContainerCompatibleRange<value_type> _Range, class _Allocator>
306309 requires __allocator_ctor_constraint<_Allocator>
307 _LIBCPP_HIDE_FROM_ABI flat_map(from_range_t, _Range&& __rg, const _Allocator& __alloc)
310 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(from_range_t, _Range&& __rg, const _Allocator& __alloc)
308311 : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc) {
309312 insert_range(std::forward<_Range>(__rg));
310313 }
311314
312315 template <_ContainerCompatibleRange<value_type> _Range>
313 _LIBCPP_HIDE_FROM_ABI flat_map(from_range_t, _Range&& __rg, const key_compare& __comp) : flat_map(__comp) {
316 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(from_range_t, _Range&& __rg, const key_compare& __comp)
317 : flat_map(__comp) {
314318 insert_range(std::forward<_Range>(__rg));
315319 }
316320
317321 template <_ContainerCompatibleRange<value_type> _Range, class _Allocator>
318322 requires __allocator_ctor_constraint<_Allocator>
319 _LIBCPP_HIDE_FROM_ABI flat_map(from_range_t, _Range&& __rg, const key_compare& __comp, const _Allocator& __alloc)
323 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
324 flat_map(from_range_t, _Range&& __rg, const key_compare& __comp, const _Allocator& __alloc)
320325 : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {
321326 insert_range(std::forward<_Range>(__rg));
322327 }
323328
324329 template <class _InputIterator>
325330 requires __has_input_iterator_category<_InputIterator>::value
326 _LIBCPP_HIDE_FROM_ABI
331 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
327332 flat_map(sorted_unique_t, _InputIterator __first, _InputIterator __last, const key_compare& __comp = key_compare())
328333 : __containers_(), __compare_(__comp) {
329334 insert(sorted_unique, __first, __last);
330335 }
331336 template <class _InputIterator, class _Allocator>
332337 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)
338 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(
339 sorted_unique_t,
340 _InputIterator __first,
341 _InputIterator __last,
342 const key_compare& __comp,
343 const _Allocator& __alloc)
339344 : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {
340345 insert(sorted_unique, __first, __last);
341346 }
342347
343348 template <class _InputIterator, class _Allocator>
344349 requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>)
345 _LIBCPP_HIDE_FROM_ABI
350 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
346351 flat_map(sorted_unique_t, _InputIterator __first, _InputIterator __last, const _Allocator& __alloc)
347352 : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc) {
348353 insert(sorted_unique, __first, __last);
349354 }
350355
351 _LIBCPP_HIDE_FROM_ABI flat_map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
356 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
357 flat_map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
352358 : flat_map(__il.begin(), __il.end(), __comp) {}
353359
354360 template <class _Allocator>
355361 requires __allocator_ctor_constraint<_Allocator>
356 _LIBCPP_HIDE_FROM_ABI
362 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
357363 flat_map(initializer_list<value_type> __il, const key_compare& __comp, const _Allocator& __alloc)
358364 : flat_map(__il.begin(), __il.end(), __comp, __alloc) {}
359365
360366 template <class _Allocator>
361367 requires __allocator_ctor_constraint<_Allocator>
362 _LIBCPP_HIDE_FROM_ABI flat_map(initializer_list<value_type> __il, const _Allocator& __alloc)
368 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
369 flat_map(initializer_list<value_type> __il, const _Allocator& __alloc)
363370 : flat_map(__il.begin(), __il.end(), __alloc) {}
364371
365 _LIBCPP_HIDE_FROM_ABI
372 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
366373 flat_map(sorted_unique_t, initializer_list<value_type> __il, const key_compare& __comp = key_compare())
367374 : flat_map(sorted_unique, __il.begin(), __il.end(), __comp) {}
368375
369376 template <class _Allocator>
370377 requires __allocator_ctor_constraint<_Allocator>
371 _LIBCPP_HIDE_FROM_ABI
378 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
372379 flat_map(sorted_unique_t, initializer_list<value_type> __il, const key_compare& __comp, const _Allocator& __alloc)
373380 : flat_map(sorted_unique, __il.begin(), __il.end(), __comp, __alloc) {}
374381
375382 template <class _Allocator>
376383 requires __allocator_ctor_constraint<_Allocator>
377 _LIBCPP_HIDE_FROM_ABI flat_map(sorted_unique_t, initializer_list<value_type> __il, const _Allocator& __alloc)
384 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
385 flat_map(sorted_unique_t, initializer_list<value_type> __il, const _Allocator& __alloc)
378386 : flat_map(sorted_unique, __il.begin(), __il.end(), __alloc) {}
379387
380 _LIBCPP_HIDE_FROM_ABI flat_map& operator=(initializer_list<value_type> __il) {
388 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map& operator=(initializer_list<value_type> __il) {
381389 clear();
382390 insert(__il);
383391 return *this;
384392 }
385393
386 _LIBCPP_HIDE_FROM_ABI flat_map& operator=(const flat_map&) = default;
394 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map& operator=(const flat_map&) = default;
387395
388 _LIBCPP_HIDE_FROM_ABI flat_map& operator=(flat_map&& __other) noexcept(
396 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map& operator=(flat_map&& __other) noexcept(
389397 is_nothrow_move_assignable_v<_KeyContainer> && is_nothrow_move_assignable_v<_MappedContainer> &&
390398 is_nothrow_move_assignable_v<_Compare>) {
391399 // No matter what happens, we always want to clear the other container before returning
......@@ -402,49 +410,65 @@ public:
402410 }
403411
404412 // iterators
405 _LIBCPP_HIDE_FROM_ABI iterator begin() noexcept {
413 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator begin() noexcept {
406414 return iterator(__containers_.keys.begin(), __containers_.values.begin());
407415 }
408416
409 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const noexcept {
417 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator begin() const noexcept {
410418 return const_iterator(__containers_.keys.begin(), __containers_.values.begin());
411419 }
412420
413 _LIBCPP_HIDE_FROM_ABI iterator end() noexcept {
421 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator end() noexcept {
414422 return iterator(__containers_.keys.end(), __containers_.values.end());
415423 }
416424
417 _LIBCPP_HIDE_FROM_ABI const_iterator end() const noexcept {
425 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator end() const noexcept {
418426 return const_iterator(__containers_.keys.end(), __containers_.values.end());
419427 }
420428
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()); }
429 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reverse_iterator rbegin() noexcept {
430 return reverse_iterator(end());
431 }
432 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reverse_iterator rbegin() const noexcept {
433 return const_reverse_iterator(end());
434 }
435 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reverse_iterator rend() noexcept {
436 return reverse_iterator(begin());
437 }
438 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reverse_iterator rend() const noexcept {
439 return const_reverse_iterator(begin());
440 }
425441
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()); }
442 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator cbegin() const noexcept { return begin(); }
443 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator cend() const noexcept { return end(); }
444 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reverse_iterator crbegin() const noexcept {
445 return const_reverse_iterator(end());
446 }
447 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reverse_iterator crend() const noexcept {
448 return const_reverse_iterator(begin());
449 }
430450
431451 // [flat.map.capacity], capacity
432 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool empty() const noexcept { return __containers_.keys.empty(); }
452 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool empty() const noexcept {
453 return __containers_.keys.empty();
454 }
433455
434 _LIBCPP_HIDE_FROM_ABI size_type size() const noexcept { return __containers_.keys.size(); }
456 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type size() const noexcept {
457 return __containers_.keys.size();
458 }
435459
436 _LIBCPP_HIDE_FROM_ABI size_type max_size() const noexcept {
460 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type max_size() const noexcept {
437461 return std::min<size_type>(__containers_.keys.max_size(), __containers_.values.max_size());
438462 }
439463
440464 // [flat.map.access], element access
441 _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](const key_type& __x)
465 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& operator[](const key_type& __x)
442466 requires is_constructible_v<mapped_type>
443467 {
444468 return try_emplace(__x).first->second;
445469 }
446470
447 _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](key_type&& __x)
471 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& operator[](key_type&& __x)
448472 requires is_constructible_v<mapped_type>
449473 {
450474 return try_emplace(std::move(__x)).first->second;
......@@ -453,11 +477,11 @@ public:
453477 template <class _Kp>
454478 requires(__is_compare_transparent && is_constructible_v<key_type, _Kp> && is_constructible_v<mapped_type> &&
455479 !is_convertible_v<_Kp &&, const_iterator> && !is_convertible_v<_Kp &&, iterator>)
456 _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](_Kp&& __x) {
480 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& operator[](_Kp&& __x) {
457481 return try_emplace(std::forward<_Kp>(__x)).first->second;
458482 }
459483
460 _LIBCPP_HIDE_FROM_ABI mapped_type& at(const key_type& __x) {
484 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& at(const key_type& __x) {
461485 auto __it = find(__x);
462486 if (__it == end()) {
463487 std::__throw_out_of_range("flat_map::at(const key_type&): Key does not exist");
......@@ -465,7 +489,7 @@ public:
465489 return __it->second;
466490 }
467491
468 _LIBCPP_HIDE_FROM_ABI const mapped_type& at(const key_type& __x) const {
492 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const mapped_type& at(const key_type& __x) const {
469493 auto __it = find(__x);
470494 if (__it == end()) {
471495 std::__throw_out_of_range("flat_map::at(const key_type&) const: Key does not exist");
......@@ -475,7 +499,7 @@ public:
475499
476500 template <class _Kp>
477501 requires __is_compare_transparent
478 _LIBCPP_HIDE_FROM_ABI mapped_type& at(const _Kp& __x) {
502 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& at(const _Kp& __x) {
479503 auto __it = find(__x);
480504 if (__it == end()) {
481505 std::__throw_out_of_range("flat_map::at(const K&): Key does not exist");
......@@ -485,7 +509,7 @@ public:
485509
486510 template <class _Kp>
487511 requires __is_compare_transparent
488 _LIBCPP_HIDE_FROM_ABI const mapped_type& at(const _Kp& __x) const {
512 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const mapped_type& at(const _Kp& __x) const {
489513 auto __it = find(__x);
490514 if (__it == end()) {
491515 std::__throw_out_of_range("flat_map::at(const K&) const: Key does not exist");
......@@ -496,45 +520,49 @@ public:
496520 // [flat.map.modifiers], modifiers
497521 template <class... _Args>
498522 requires is_constructible_v<pair<key_type, mapped_type>, _Args...>
499 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> emplace(_Args&&... __args) {
523 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> emplace(_Args&&... __args) {
500524 std::pair<key_type, mapped_type> __pair(std::forward<_Args>(__args)...);
501525 return __try_emplace(std::move(__pair.first), std::move(__pair.second));
502526 }
503527
504528 template <class... _Args>
505529 requires is_constructible_v<pair<key_type, mapped_type>, _Args...>
506 _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __hint, _Args&&... __args) {
530 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator emplace_hint(const_iterator __hint, _Args&&... __args) {
507531 std::pair<key_type, mapped_type> __pair(std::forward<_Args>(__args)...);
508532 return __try_emplace_hint(__hint, std::move(__pair.first), std::move(__pair.second)).first;
509533 }
510534
511 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __x) { return emplace(__x); }
535 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> insert(const value_type& __x) {
536 return emplace(__x);
537 }
512538
513 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __x) { return emplace(std::move(__x)); }
539 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> insert(value_type&& __x) {
540 return emplace(std::move(__x));
541 }
514542
515 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, const value_type& __x) {
543 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const_iterator __hint, const value_type& __x) {
516544 return emplace_hint(__hint, __x);
517545 }
518546
519 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, value_type&& __x) {
547 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const_iterator __hint, value_type&& __x) {
520548 return emplace_hint(__hint, std::move(__x));
521549 }
522550
523551 template <class _PairLike>
524552 requires is_constructible_v<pair<key_type, mapped_type>, _PairLike>
525 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(_PairLike&& __x) {
553 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> insert(_PairLike&& __x) {
526554 return emplace(std::forward<_PairLike>(__x));
527555 }
528556
529557 template <class _PairLike>
530558 requires is_constructible_v<pair<key_type, mapped_type>, _PairLike>
531 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, _PairLike&& __x) {
559 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const_iterator __hint, _PairLike&& __x) {
532560 return emplace_hint(__hint, std::forward<_PairLike>(__x));
533561 }
534562
535563 template <class _InputIterator>
536564 requires __has_input_iterator_category<_InputIterator>::value
537 _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last) {
565 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert(_InputIterator __first, _InputIterator __last) {
538566 if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>) {
539567 __reserve(__last - __first);
540568 }
......@@ -543,7 +571,8 @@ public:
543571
544572 template <class _InputIterator>
545573 requires __has_input_iterator_category<_InputIterator>::value
546 _LIBCPP_HIDE_FROM_ABI void insert(sorted_unique_t, _InputIterator __first, _InputIterator __last) {
574 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
575 insert(sorted_unique_t, _InputIterator __first, _InputIterator __last) {
547576 if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>) {
548577 __reserve(__last - __first);
549578 }
......@@ -552,7 +581,7 @@ public:
552581 }
553582
554583 template <_ContainerCompatibleRange<value_type> _Range>
555 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
584 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert_range(_Range&& __range) {
556585 if constexpr (ranges::sized_range<_Range>) {
557586 __reserve(ranges::size(__range));
558587 }
......@@ -560,19 +589,22 @@ public:
560589 __append_sort_merge_unique</*WasSorted = */ false>(ranges::begin(__range), ranges::end(__range));
561590 }
562591
563 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
592 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert(initializer_list<value_type> __il) {
593 insert(__il.begin(), __il.end());
594 }
564595
565 _LIBCPP_HIDE_FROM_ABI void insert(sorted_unique_t, initializer_list<value_type> __il) {
596 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert(sorted_unique_t, initializer_list<value_type> __il) {
566597 insert(sorted_unique, __il.begin(), __il.end());
567598 }
568599
569 _LIBCPP_HIDE_FROM_ABI containers extract() && {
600 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 containers extract() && {
570601 auto __guard = std::__make_scope_guard([&]() noexcept { clear() /* noexcept */; });
571602 auto __ret = std::move(__containers_);
572603 return __ret;
573604 }
574605
575 _LIBCPP_HIDE_FROM_ABI void replace(key_container_type&& __key_cont, mapped_container_type&& __mapped_cont) {
606 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
607 replace(key_container_type&& __key_cont, mapped_container_type&& __mapped_cont) {
576608 _LIBCPP_ASSERT_VALID_INPUT_RANGE(
577609 __key_cont.size() == __mapped_cont.size(), "flat_map keys and mapped containers have different size");
578610
......@@ -586,13 +618,15 @@ public:
586618
587619 template <class... _Args>
588620 requires is_constructible_v<mapped_type, _Args...>
589 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(const key_type& __key, _Args&&... __args) {
621 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
622 try_emplace(const key_type& __key, _Args&&... __args) {
590623 return __try_emplace(__key, std::forward<_Args>(__args)...);
591624 }
592625
593626 template <class... _Args>
594627 requires is_constructible_v<mapped_type, _Args...>
595 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(key_type&& __key, _Args&&... __args) {
628 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
629 try_emplace(key_type&& __key, _Args&&... __args) {
596630 return __try_emplace(std::move(__key), std::forward<_Args>(__args)...);
597631 }
598632
......@@ -600,75 +634,84 @@ public:
600634 requires(__is_compare_transparent && is_constructible_v<key_type, _Kp> &&
601635 is_constructible_v<mapped_type, _Args...> && !is_convertible_v<_Kp &&, const_iterator> &&
602636 !is_convertible_v<_Kp &&, iterator>)
603 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(_Kp&& __key, _Args&&... __args) {
637 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> try_emplace(_Kp&& __key, _Args&&... __args) {
604638 return __try_emplace(std::forward<_Kp>(__key), std::forward<_Args>(__args)...);
605639 }
606640
607641 template <class... _Args>
608642 requires is_constructible_v<mapped_type, _Args...>
609 _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator __hint, const key_type& __key, _Args&&... __args) {
643 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator
644 try_emplace(const_iterator __hint, const key_type& __key, _Args&&... __args) {
610645 return __try_emplace_hint(__hint, __key, std::forward<_Args>(__args)...).first;
611646 }
612647
613648 template <class... _Args>
614649 requires is_constructible_v<mapped_type, _Args...>
615 _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator __hint, key_type&& __key, _Args&&... __args) {
650 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator
651 try_emplace(const_iterator __hint, key_type&& __key, _Args&&... __args) {
616652 return __try_emplace_hint(__hint, std::move(__key), std::forward<_Args>(__args)...).first;
617653 }
618654
619655 template <class _Kp, class... _Args>
620656 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) {
657 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator
658 try_emplace(const_iterator __hint, _Kp&& __key, _Args&&... __args) {
622659 return __try_emplace_hint(__hint, std::forward<_Kp>(__key), std::forward<_Args>(__args)...).first;
623660 }
624661
625662 template <class _Mapped>
626663 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) {
664 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
665 insert_or_assign(const key_type& __key, _Mapped&& __obj) {
628666 return __insert_or_assign(__key, std::forward<_Mapped>(__obj));
629667 }
630668
631669 template <class _Mapped>
632670 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) {
671 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
672 insert_or_assign(key_type&& __key, _Mapped&& __obj) {
634673 return __insert_or_assign(std::move(__key), std::forward<_Mapped>(__obj));
635674 }
636675
637676 template <class _Kp, class _Mapped>
638677 requires __is_compare_transparent && is_constructible_v<key_type, _Kp> && is_assignable_v<mapped_type&, _Mapped> &&
639678 is_constructible_v<mapped_type, _Mapped>
640 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert_or_assign(_Kp&& __key, _Mapped&& __obj) {
679 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
680 insert_or_assign(_Kp&& __key, _Mapped&& __obj) {
641681 return __insert_or_assign(std::forward<_Kp>(__key), std::forward<_Mapped>(__obj));
642682 }
643683
644684 template <class _Mapped>
645685 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) {
686 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator
687 insert_or_assign(const_iterator __hint, const key_type& __key, _Mapped&& __obj) {
647688 return __insert_or_assign(__hint, __key, std::forward<_Mapped>(__obj));
648689 }
649690
650691 template <class _Mapped>
651692 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) {
693 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator
694 insert_or_assign(const_iterator __hint, key_type&& __key, _Mapped&& __obj) {
653695 return __insert_or_assign(__hint, std::move(__key), std::forward<_Mapped>(__obj));
654696 }
655697
656698 template <class _Kp, class _Mapped>
657699 requires __is_compare_transparent && is_constructible_v<key_type, _Kp> && is_assignable_v<mapped_type&, _Mapped> &&
658700 is_constructible_v<mapped_type, _Mapped>
659 _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __hint, _Kp&& __key, _Mapped&& __obj) {
701 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator
702 insert_or_assign(const_iterator __hint, _Kp&& __key, _Mapped&& __obj) {
660703 return __insert_or_assign(__hint, std::forward<_Kp>(__key), std::forward<_Mapped>(__obj));
661704 }
662705
663 _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __position) {
706 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator erase(iterator __position) {
664707 return __erase(__position.__key_iter_, __position.__mapped_iter_);
665708 }
666709
667 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position) {
710 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator erase(const_iterator __position) {
668711 return __erase(__position.__key_iter_, __position.__mapped_iter_);
669712 }
670713
671 _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __x) {
714 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type erase(const key_type& __x) {
672715 auto __iter = find(__x);
673716 if (__iter != end()) {
674717 erase(__iter);
......@@ -680,14 +723,14 @@ public:
680723 template <class _Kp>
681724 requires(__is_compare_transparent && !is_convertible_v<_Kp &&, iterator> &&
682725 !is_convertible_v<_Kp &&, const_iterator>)
683 _LIBCPP_HIDE_FROM_ABI size_type erase(_Kp&& __x) {
726 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type erase(_Kp&& __x) {
684727 auto [__first, __last] = equal_range(__x);
685728 auto __res = __last - __first;
686729 erase(__first, __last);
687730 return __res;
688731 }
689732
690 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last) {
733 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator erase(const_iterator __first, const_iterator __last) {
691734 auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
692735 auto __key_it = __containers_.keys.erase(__first.__key_iter_, __last.__key_iter_);
693736 auto __mapped_it = __containers_.values.erase(__first.__mapped_iter_, __last.__mapped_iter_);
......@@ -695,7 +738,7 @@ public:
695738 return iterator(std::move(__key_it), std::move(__mapped_it));
696739 }
697740
698 _LIBCPP_HIDE_FROM_ABI void swap(flat_map& __y) noexcept {
741 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void swap(flat_map& __y) noexcept {
699742 // warning: The spec has unconditional noexcept, which means that
700743 // if any of the following functions throw an exception,
701744 // std::terminate will be called.
......@@ -705,133 +748,156 @@ public:
705748 ranges::swap(__containers_.values, __y.__containers_.values);
706749 }
707750
708 _LIBCPP_HIDE_FROM_ABI void clear() noexcept {
751 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void clear() noexcept {
709752 __containers_.keys.clear();
710753 __containers_.values.clear();
711754 }
712755
713756 // 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_); }
757 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 key_compare key_comp() const { return __compare_; }
758 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 value_compare value_comp() const {
759 return value_compare(__compare_);
760 }
716761
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; }
762 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const key_container_type& keys() const noexcept {
763 return __containers_.keys;
764 }
765 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const mapped_container_type& values() const noexcept {
766 return __containers_.values;
767 }
719768
720769 // map operations
721 _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __x) { return __find_impl(*this, __x); }
770 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator find(const key_type& __x) {
771 return __find_impl(*this, __x);
772 }
722773
723 _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __x) const { return __find_impl(*this, __x); }
774 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator find(const key_type& __x) const {
775 return __find_impl(*this, __x);
776 }
724777
725778 template <class _Kp>
726779 requires __is_compare_transparent
727 _LIBCPP_HIDE_FROM_ABI iterator find(const _Kp& __x) {
780 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator find(const _Kp& __x) {
728781 return __find_impl(*this, __x);
729782 }
730783
731784 template <class _Kp>
732785 requires __is_compare_transparent
733 _LIBCPP_HIDE_FROM_ABI const_iterator find(const _Kp& __x) const {
786 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator find(const _Kp& __x) const {
734787 return __find_impl(*this, __x);
735788 }
736789
737 _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __x) const { return contains(__x) ? 1 : 0; }
790 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type count(const key_type& __x) const {
791 return contains(__x) ? 1 : 0;
792 }
738793
739794 template <class _Kp>
740795 requires __is_compare_transparent
741 _LIBCPP_HIDE_FROM_ABI size_type count(const _Kp& __x) const {
796 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type count(const _Kp& __x) const {
742797 return contains(__x) ? 1 : 0;
743798 }
744799
745 _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __x) const { return find(__x) != end(); }
800 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool contains(const key_type& __x) const {
801 return find(__x) != end();
802 }
746803
747804 template <class _Kp>
748805 requires __is_compare_transparent
749 _LIBCPP_HIDE_FROM_ABI bool contains(const _Kp& __x) const {
806 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool contains(const _Kp& __x) const {
750807 return find(__x) != end();
751808 }
752809
753 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __x) { return __lower_bound<iterator>(*this, __x); }
810 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator lower_bound(const key_type& __x) {
811 return __lower_bound<iterator>(*this, __x);
812 }
754813
755 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __x) const {
814 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator lower_bound(const key_type& __x) const {
756815 return __lower_bound<const_iterator>(*this, __x);
757816 }
758817
759818 template <class _Kp>
760819 requires __is_compare_transparent
761 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _Kp& __x) {
820 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator lower_bound(const _Kp& __x) {
762821 return __lower_bound<iterator>(*this, __x);
763822 }
764823
765824 template <class _Kp>
766825 requires __is_compare_transparent
767 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _Kp& __x) const {
826 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator lower_bound(const _Kp& __x) const {
768827 return __lower_bound<const_iterator>(*this, __x);
769828 }
770829
771 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __x) { return __upper_bound<iterator>(*this, __x); }
830 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator upper_bound(const key_type& __x) {
831 return __upper_bound<iterator>(*this, __x);
832 }
772833
773 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __x) const {
834 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator upper_bound(const key_type& __x) const {
774835 return __upper_bound<const_iterator>(*this, __x);
775836 }
776837
777838 template <class _Kp>
778839 requires __is_compare_transparent
779 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _Kp& __x) {
840 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator upper_bound(const _Kp& __x) {
780841 return __upper_bound<iterator>(*this, __x);
781842 }
782843
783844 template <class _Kp>
784845 requires __is_compare_transparent
785 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _Kp& __x) const {
846 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator upper_bound(const _Kp& __x) const {
786847 return __upper_bound<const_iterator>(*this, __x);
787848 }
788849
789 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __x) {
850 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, iterator> equal_range(const key_type& __x) {
790851 return __equal_range_impl(*this, __x);
791852 }
792853
793 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __x) const {
854 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<const_iterator, const_iterator>
855 equal_range(const key_type& __x) const {
794856 return __equal_range_impl(*this, __x);
795857 }
796858
797859 template <class _Kp>
798860 requires __is_compare_transparent
799 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _Kp& __x) {
861 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, iterator> equal_range(const _Kp& __x) {
800862 return __equal_range_impl(*this, __x);
801863 }
802864 template <class _Kp>
803865 requires __is_compare_transparent
804 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _Kp& __x) const {
866 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<const_iterator, const_iterator>
867 equal_range(const _Kp& __x) const {
805868 return __equal_range_impl(*this, __x);
806869 }
807870
808 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const flat_map& __x, const flat_map& __y) {
871 friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator==(const flat_map& __x, const flat_map& __y) {
809872 return ranges::equal(__x, __y);
810873 }
811874
812 friend _LIBCPP_HIDE_FROM_ABI auto operator<=>(const flat_map& __x, const flat_map& __y) {
875 friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 auto
876 operator<=>(const flat_map& __x, const flat_map& __y) {
813877 return std::lexicographical_compare_three_way(
814878 __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
815879 }
816880
817 friend _LIBCPP_HIDE_FROM_ABI void swap(flat_map& __x, flat_map& __y) noexcept { __x.swap(__y); }
881 friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void swap(flat_map& __x, flat_map& __y) noexcept {
882 __x.swap(__y);
883 }
818884
819885private:
820886 struct __ctor_uses_allocator_tag {
821 explicit _LIBCPP_HIDE_FROM_ABI __ctor_uses_allocator_tag() = default;
887 explicit _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __ctor_uses_allocator_tag() = default;
822888 };
823889 struct __ctor_uses_allocator_empty_tag {
824 explicit _LIBCPP_HIDE_FROM_ABI __ctor_uses_allocator_empty_tag() = default;
890 explicit _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __ctor_uses_allocator_empty_tag() = default;
825891 };
826892
827893 template <class _Allocator, class _KeyCont, class _MappedCont, class... _CompArg>
828894 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)
895 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(
896 __ctor_uses_allocator_tag,
897 const _Allocator& __alloc,
898 _KeyCont&& __key_cont,
899 _MappedCont&& __mapped_cont,
900 _CompArg&&... __comp)
835901 : __containers_{.keys = std::make_obj_using_allocator<key_container_type>(
836902 __alloc, std::forward<_KeyCont>(__key_cont)),
837903 .values = std::make_obj_using_allocator<mapped_container_type>(
......@@ -840,12 +906,13 @@ private:
840906
841907 template <class _Allocator, class... _CompArg>
842908 requires __allocator_ctor_constraint<_Allocator>
843 _LIBCPP_HIDE_FROM_ABI flat_map(__ctor_uses_allocator_empty_tag, const _Allocator& __alloc, _CompArg&&... __comp)
909 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
910 flat_map(__ctor_uses_allocator_empty_tag, const _Allocator& __alloc, _CompArg&&... __comp)
844911 : __containers_{.keys = std::make_obj_using_allocator<key_container_type>(__alloc),
845912 .values = std::make_obj_using_allocator<mapped_container_type>(__alloc)},
846913 __compare_(std::forward<_CompArg>(__comp)...) {}
847914
848 _LIBCPP_HIDE_FROM_ABI bool __is_sorted_and_unique(auto&& __key_container) const {
915 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool __is_sorted_and_unique(auto&& __key_container) const {
849916 auto __greater_or_equal_to = [this](const auto& __x, const auto& __y) { return !__compare_(__x, __y); };
850917 return ranges::adjacent_find(__key_container, __greater_or_equal_to) == ranges::end(__key_container);
851918 }
......@@ -853,7 +920,7 @@ private:
853920 // This function is only used in constructors. So there is not exception handling in this function.
854921 // If the function exits via an exception, there will be no flat_map object constructed, thus, there
855922 // is no invariant state to preserve
856 _LIBCPP_HIDE_FROM_ABI void __sort_and_unique() {
923 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __sort_and_unique() {
857924 auto __zv = ranges::views::zip(__containers_.keys, __containers_.values);
858925 ranges::sort(__zv, __compare_, [](const auto& __p) -> decltype(auto) { return std::get<0>(__p); });
859926 auto __dup_start = ranges::unique(__zv, __key_equiv(__compare_)).begin();
......@@ -862,8 +929,17 @@ private:
862929 __containers_.values.erase(__containers_.values.begin() + __dist, __containers_.values.end());
863930 }
864931
932 template <class _Self, class _KeyIter>
933 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static auto
934 __corresponding_mapped_it(_Self&& __self, _KeyIter&& __key_iter) {
935 return __self.__containers_.values.begin() +
936 static_cast<ranges::range_difference_t<mapped_container_type>>(
937 ranges::distance(__self.__containers_.keys.begin(), __key_iter));
938 }
939
865940 template <bool _WasSorted, class _InputIterator, class _Sentinel>
866 _LIBCPP_HIDE_FROM_ABI void __append_sort_merge_unique(_InputIterator __first, _Sentinel __last) {
941 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
942 __append_sort_merge_unique(_InputIterator __first, _Sentinel __last) {
867943 auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
868944 size_t __num_of_appended = __flat_map_utils::__append(*this, std::move(__first), std::move(__last));
869945 if (__num_of_appended != 0) {
......@@ -891,7 +967,7 @@ private:
891967 }
892968
893969 template <class _Self, class _Kp>
894 _LIBCPP_HIDE_FROM_ABI static auto __find_impl(_Self&& __self, const _Kp& __key) {
970 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static auto __find_impl(_Self&& __self, const _Kp& __key) {
895971 auto __it = __self.lower_bound(__key);
896972 auto __last = __self.end();
897973 if (__it == __last || __self.__compare_(__key, __it->first)) {
......@@ -901,8 +977,9 @@ private:
901977 }
902978
903979 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_);
980 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static auto __key_equal_range(_Self&& __self, const _Kp& __key) {
981 auto __it =
982 std::lower_bound(__self.__containers_.keys.begin(), __self.__containers_.keys.end(), __key, __self.__compare_);
906983 auto __last = __self.__containers_.keys.end();
907984 if (__it == __last || __self.__compare_(__key, *__it)) {
908985 return std::make_pair(__it, __it);
......@@ -911,44 +988,33 @@ private:
911988 }
912989
913990 template <class _Self, class _Kp>
914 _LIBCPP_HIDE_FROM_ABI static auto __equal_range_impl(_Self&& __self, const _Kp& __key) {
991 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static auto __equal_range_impl(_Self&& __self, const _Kp& __key) {
915992 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)));
993 using __iterator_type = ranges::iterator_t<decltype(__self)>;
994 return std::make_pair(__iterator_type(__key_first, __corresponding_mapped_it(__self, __key_first)),
995 __iterator_type(__key_last, __corresponding_mapped_it(__self, __key_last)));
926996 }
927997
928998 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);
999 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static _Res __lower_bound(_Self&& __self, _Kp& __x) {
1000 auto __key_iter =
1001 std::lower_bound(__self.__containers_.keys.begin(), __self.__containers_.keys.end(), __x, __self.__compare_);
1002 auto __mapped_iter = __corresponding_mapped_it(__self, __key_iter);
1003 return _Res(std::move(__key_iter), std::move(__mapped_iter));
9311004 }
9321005
9331006 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
1007 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static _Res __upper_bound(_Self&& __self, _Kp& __x) {
1008 auto __key_iter =
1009 std::upper_bound(__self.__containers_.keys.begin(), __self.__containers_.keys.end(), __x, __self.__compare_);
1010 auto __mapped_iter = __corresponding_mapped_it(__self, __key_iter);
9461011 return _Res(std::move(__key_iter), std::move(__mapped_iter));
9471012 }
9481013
9491014 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_);
1015 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
1016 __try_emplace(_KeyArg&& __key, _MArgs&&... __mapped_args) {
1017 auto __key_it = std::lower_bound(__containers_.keys.begin(), __containers_.keys.end(), __key, __compare_);
9521018 auto __mapped_it = __containers_.values.begin() + ranges::distance(__containers_.keys.begin(), __key_it);
9531019
9541020 if (__key_it == __containers_.keys.end() || __compare_(__key, *__key_it)) {
......@@ -966,7 +1032,7 @@ private:
9661032 }
9671033
9681034 template <class _Kp>
969 _LIBCPP_HIDE_FROM_ABI bool __is_hint_correct(const_iterator __hint, _Kp&& __key) {
1035 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool __is_hint_correct(const_iterator __hint, _Kp&& __key) {
9701036 if (__hint != cbegin() && !__compare_((__hint - 1)->first, __key)) {
9711037 return false;
9721038 }
......@@ -977,7 +1043,8 @@ private:
9771043 }
9781044
9791045 template <class _Kp, class... _Args>
980 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __try_emplace_hint(const_iterator __hint, _Kp&& __key, _Args&&... __args) {
1046 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
1047 __try_emplace_hint(const_iterator __hint, _Kp&& __key, _Args&&... __args) {
9811048 if (__is_hint_correct(__hint, __key)) {
9821049 if (__hint == cend() || __compare_(__key, __hint->first)) {
9831050 return {__flat_map_utils::__emplace_exact_pos(
......@@ -998,7 +1065,8 @@ private:
9981065 }
9991066
10001067 template <class _Kp, class _Mapped>
1001 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_or_assign(_Kp&& __key, _Mapped&& __mapped) {
1068 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
1069 __insert_or_assign(_Kp&& __key, _Mapped&& __mapped) {
10021070 auto __r = try_emplace(std::forward<_Kp>(__key), std::forward<_Mapped>(__mapped));
10031071 if (!__r.second) {
10041072 __r.first->second = std::forward<_Mapped>(__mapped);
......@@ -1007,7 +1075,8 @@ private:
10071075 }
10081076
10091077 template <class _Kp, class _Mapped>
1010 _LIBCPP_HIDE_FROM_ABI iterator __insert_or_assign(const_iterator __hint, _Kp&& __key, _Mapped&& __mapped) {
1078 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator
1079 __insert_or_assign(const_iterator __hint, _Kp&& __key, _Mapped&& __mapped) {
10111080 auto __r = __try_emplace_hint(__hint, std::forward<_Kp>(__key), std::forward<_Mapped>(__mapped));
10121081 if (!__r.second) {
10131082 __r.first->second = std::forward<_Mapped>(__mapped);
......@@ -1015,18 +1084,19 @@ private:
10151084 return __r.first;
10161085 }
10171086
1018 _LIBCPP_HIDE_FROM_ABI void __reserve(size_t __size) {
1019 if constexpr (requires { __containers_.keys.reserve(__size); }) {
1087 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __reserve(size_t __size) {
1088 if constexpr (__container_traits<_KeyContainer>::__reservable) {
10201089 __containers_.keys.reserve(__size);
10211090 }
10221091
1023 if constexpr (requires { __containers_.values.reserve(__size); }) {
1092 if constexpr (__container_traits<_MappedContainer>::__reservable) {
10241093 __containers_.values.reserve(__size);
10251094 }
10261095 }
10271096
10281097 template <class _KIter, class _MIter>
1029 _LIBCPP_HIDE_FROM_ABI iterator __erase(_KIter __key_iter_to_remove, _MIter __mapped_iter_to_remove) {
1098 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator
1099 __erase(_KIter __key_iter_to_remove, _MIter __mapped_iter_to_remove) {
10301100 auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
10311101 auto __key_iter = __containers_.keys.erase(__key_iter_to_remove);
10321102 auto __mapped_iter = __containers_.values.erase(__mapped_iter_to_remove);
......@@ -1036,7 +1106,8 @@ private:
10361106
10371107 template <class _Key2, class _Tp2, class _Compare2, class _KeyContainer2, class _MappedContainer2, class _Predicate>
10381108 friend typename flat_map<_Key2, _Tp2, _Compare2, _KeyContainer2, _MappedContainer2>::size_type
1039 erase_if(flat_map<_Key2, _Tp2, _Compare2, _KeyContainer2, _MappedContainer2>&, _Predicate);
1109 _LIBCPP_CONSTEXPR_SINCE_CXX26
1110 erase_if(flat_map<_Key2, _Tp2, _Compare2, _KeyContainer2, _MappedContainer2>&, _Predicate);
10401111
10411112 friend __flat_map_utils;
10421113
......@@ -1044,8 +1115,9 @@ private:
10441115 _LIBCPP_NO_UNIQUE_ADDRESS key_compare __compare_;
10451116
10461117 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 {
1118 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __key_equiv(key_compare __c) : __comp_(__c) {}
1119 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool
1120 operator()(const_reference __x, const_reference __y) const {
10491121 return !__comp_(std::get<0>(__x), std::get<0>(__y)) && !__comp_(std::get<0>(__y), std::get<0>(__x));
10501122 }
10511123 key_compare __comp_;
......@@ -1168,8 +1240,9 @@ struct uses_allocator<flat_map<_Key, _Tp, _Compare, _KeyContainer, _MappedContai
11681240 : bool_constant<uses_allocator_v<_KeyContainer, _Allocator> && uses_allocator_v<_MappedContainer, _Allocator>> {};
11691241
11701242template <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) {
1243_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
1244 typename flat_map<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>::size_type
1245 erase_if(flat_map<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>& __flat_map, _Predicate __pred) {
11731246 auto __zv = ranges::views::zip(__flat_map.__containers_.keys, __flat_map.__containers_.values);
11741247 auto __first = __zv.begin();
11751248 auto __last = __zv.end();
lib/libcxx/include/__flat_map/flat_multimap.h+14-13
......@@ -10,18 +10,16 @@
1010#ifndef _LIBCPP___FLAT_MAP_FLAT_MULTIMAP_H
1111#define _LIBCPP___FLAT_MAP_FLAT_MULTIMAP_H
1212
13#include <__algorithm/equal_range.h>
1314#include <__algorithm/lexicographical_compare_three_way.h>
15#include <__algorithm/lower_bound.h>
1416#include <__algorithm/min.h>
1517#include <__algorithm/ranges_equal.h>
16#include <__algorithm/ranges_equal_range.h>
1718#include <__algorithm/ranges_inplace_merge.h>
1819#include <__algorithm/ranges_is_sorted.h>
19#include <__algorithm/ranges_lower_bound.h>
20#include <__algorithm/ranges_partition_point.h>
2120#include <__algorithm/ranges_sort.h>
22#include <__algorithm/ranges_unique.h>
23#include <__algorithm/ranges_upper_bound.h>
2421#include <__algorithm/remove_if.h>
22#include <__algorithm/upper_bound.h>
2523#include <__assert>
2624#include <__compare/synth_three_way.h>
2725#include <__concepts/convertible_to.h>
......@@ -443,7 +441,7 @@ public:
443441 is_move_constructible_v<mapped_type>
444442 _LIBCPP_HIDE_FROM_ABI iterator emplace(_Args&&... __args) {
445443 std::pair<key_type, mapped_type> __pair(std::forward<_Args>(__args)...);
446 auto __key_it = ranges::upper_bound(__containers_.keys, __pair.first, __compare_);
444 auto __key_it = std::upper_bound(__containers_.keys.begin(), __containers_.keys.end(), __pair.first, __compare_);
447445 auto __mapped_it = __corresponding_mapped_it(*this, __key_it);
448446
449447 return __flat_map_utils::__emplace_exact_pos(
......@@ -473,7 +471,7 @@ public:
473471 // |
474472 // hint
475473 // We want to insert "2" after the last existing "2"
476 __key_iter = ranges::upper_bound(__containers_.keys.begin(), __key_iter, __pair.first, __compare_);
474 __key_iter = std::upper_bound(__containers_.keys.begin(), __key_iter, __pair.first, __compare_);
477475 __mapped_iter = __corresponding_mapped_it(*this, __key_iter);
478476 } else {
479477 _LIBCPP_ASSERT_INTERNAL(!__prev_larger && __next_smaller, "this means that the multimap is not sorted");
......@@ -485,7 +483,7 @@ public:
485483 // |
486484 // hint
487485 // We want to insert "2" before the first existing "2"
488 __key_iter = ranges::lower_bound(__key_iter, __containers_.keys.end(), __pair.first, __compare_);
486 __key_iter = std::lower_bound(__key_iter, __containers_.keys.end(), __pair.first, __compare_);
489487 __mapped_iter = __corresponding_mapped_it(*this, __key_iter);
490488 }
491489 return __flat_map_utils::__emplace_exact_pos(
......@@ -804,7 +802,8 @@ private:
804802
805803 template <class _Self, class _Kp>
806804 _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_);
805 auto [__key_first, __key_last] =
806 std::equal_range(__self.__containers_.keys.begin(), __self.__containers_.keys.end(), __key, __self.__compare_);
808807
809808 using __iterator_type = ranges::iterator_t<decltype(__self)>;
810809 return std::make_pair(__iterator_type(__key_first, __corresponding_mapped_it(__self, __key_first)),
......@@ -813,24 +812,26 @@ private:
813812
814813 template <class _Res, class _Self, class _Kp>
815814 _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_);
815 auto __key_iter =
816 std::lower_bound(__self.__containers_.keys.begin(), __self.__containers_.keys.end(), __x, __self.__compare_);
817817 auto __mapped_iter = __corresponding_mapped_it(__self, __key_iter);
818818 return _Res(std::move(__key_iter), std::move(__mapped_iter));
819819 }
820820
821821 template <class _Res, class _Self, class _Kp>
822822 _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_);
823 auto __key_iter =
824 std::upper_bound(__self.__containers_.keys.begin(), __self.__containers_.keys.end(), __x, __self.__compare_);
824825 auto __mapped_iter = __corresponding_mapped_it(__self, __key_iter);
825826 return _Res(std::move(__key_iter), std::move(__mapped_iter));
826827 }
827828
828829 _LIBCPP_HIDE_FROM_ABI void __reserve(size_t __size) {
829 if constexpr (requires { __containers_.keys.reserve(__size); }) {
830 if constexpr (__container_traits<_KeyContainer>::__reservable) {
830831 __containers_.keys.reserve(__size);
831832 }
832833
833 if constexpr (requires { __containers_.values.reserve(__size); }) {
834 if constexpr (__container_traits<_MappedContainer>::__reservable) {
834835 __containers_.values.reserve(__size);
835836 }
836837 }
lib/libcxx/include/__flat_map/key_value_iterator.h+64-22
......@@ -13,9 +13,12 @@
1313#include <__compare/three_way_comparable.h>
1414#include <__concepts/convertible_to.h>
1515#include <__config>
16#include <__cstddef/size_t.h>
1617#include <__iterator/iterator_traits.h>
18#include <__iterator/product_iterator.h>
1719#include <__memory/addressof.h>
1820#include <__type_traits/conditional.h>
21#include <__utility/forward.h>
1922#include <__utility/move.h>
2023#include <__utility/pair.h>
2124
......@@ -46,7 +49,7 @@ private:
4649
4750 struct __arrow_proxy {
4851 __reference __ref_;
49 _LIBCPP_HIDE_FROM_ABI __reference* operator->() { return std::addressof(__ref_); }
52 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __reference* operator->() { return std::addressof(__ref_); }
5053 };
5154
5255 __key_iterator __key_iter_;
......@@ -57,6 +60,8 @@ private:
5760 template <class, class, class, bool>
5861 friend struct __key_value_iterator;
5962
63 friend struct __product_iterator_traits<__key_value_iterator>;
64
6065public:
6166 using iterator_concept = random_access_iterator_tag;
6267 // `__key_value_iterator` only satisfy "Cpp17InputIterator" named requirements, because
......@@ -69,104 +74,141 @@ public:
6974
7075 _LIBCPP_HIDE_FROM_ABI __key_value_iterator() = default;
7176
72 _LIBCPP_HIDE_FROM_ABI __key_value_iterator(__key_value_iterator<_Owner, _KeyContainer, _MappedContainer, !_Const> __i)
77 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
78 __key_value_iterator(__key_value_iterator<_Owner, _KeyContainer, _MappedContainer, !_Const> __i)
7379 requires _Const && convertible_to<typename _KeyContainer::iterator, __key_iterator> &&
7480 convertible_to<typename _MappedContainer::iterator, __mapped_iterator>
7581 : __key_iter_(std::move(__i.__key_iter_)), __mapped_iter_(std::move(__i.__mapped_iter_)) {}
7682
77 _LIBCPP_HIDE_FROM_ABI __key_value_iterator(__key_iterator __key_iter, __mapped_iterator __mapped_iter)
83 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
84 __key_value_iterator(__key_iterator __key_iter, __mapped_iterator __mapped_iter)
7885 : __key_iter_(std::move(__key_iter)), __mapped_iter_(std::move(__mapped_iter)) {}
7986
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}; }
87 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __reference operator*() const {
88 return __reference(*__key_iter_, *__mapped_iter_);
89 }
90 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __arrow_proxy operator->() const { return __arrow_proxy{**this}; }
8291
83 _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator++() {
92 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __key_value_iterator& operator++() {
8493 ++__key_iter_;
8594 ++__mapped_iter_;
8695 return *this;
8796 }
8897
89 _LIBCPP_HIDE_FROM_ABI __key_value_iterator operator++(int) {
98 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __key_value_iterator operator++(int) {
9099 __key_value_iterator __tmp(*this);
91100 ++*this;
92101 return __tmp;
93102 }
94103
95 _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator--() {
104 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __key_value_iterator& operator--() {
96105 --__key_iter_;
97106 --__mapped_iter_;
98107 return *this;
99108 }
100109
101 _LIBCPP_HIDE_FROM_ABI __key_value_iterator operator--(int) {
110 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __key_value_iterator operator--(int) {
102111 __key_value_iterator __tmp(*this);
103112 --*this;
104113 return __tmp;
105114 }
106115
107 _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator+=(difference_type __x) {
116 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __key_value_iterator& operator+=(difference_type __x) {
108117 __key_iter_ += __x;
109118 __mapped_iter_ += __x;
110119 return *this;
111120 }
112121
113 _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator-=(difference_type __x) {
122 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __key_value_iterator& operator-=(difference_type __x) {
114123 __key_iter_ -= __x;
115124 __mapped_iter_ -= __x;
116125 return *this;
117126 }
118127
119 _LIBCPP_HIDE_FROM_ABI __reference operator[](difference_type __n) const { return *(*this + __n); }
128 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __reference operator[](difference_type __n) const {
129 return *(*this + __n);
130 }
120131
121 _LIBCPP_HIDE_FROM_ABI friend constexpr bool
132 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend bool
122133 operator==(const __key_value_iterator& __x, const __key_value_iterator& __y) {
123134 return __x.__key_iter_ == __y.__key_iter_;
124135 }
125136
126 _LIBCPP_HIDE_FROM_ABI friend bool operator<(const __key_value_iterator& __x, const __key_value_iterator& __y) {
137 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend bool
138 operator<(const __key_value_iterator& __x, const __key_value_iterator& __y) {
127139 return __x.__key_iter_ < __y.__key_iter_;
128140 }
129141
130 _LIBCPP_HIDE_FROM_ABI friend bool operator>(const __key_value_iterator& __x, const __key_value_iterator& __y) {
142 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend bool
143 operator>(const __key_value_iterator& __x, const __key_value_iterator& __y) {
131144 return __y < __x;
132145 }
133146
134 _LIBCPP_HIDE_FROM_ABI friend bool operator<=(const __key_value_iterator& __x, const __key_value_iterator& __y) {
147 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend bool
148 operator<=(const __key_value_iterator& __x, const __key_value_iterator& __y) {
135149 return !(__y < __x);
136150 }
137151
138 _LIBCPP_HIDE_FROM_ABI friend bool operator>=(const __key_value_iterator& __x, const __key_value_iterator& __y) {
152 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend bool
153 operator>=(const __key_value_iterator& __x, const __key_value_iterator& __y) {
139154 return !(__x < __y);
140155 }
141156
142 _LIBCPP_HIDE_FROM_ABI friend auto operator<=>(const __key_value_iterator& __x, const __key_value_iterator& __y)
157 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend auto
158 operator<=>(const __key_value_iterator& __x, const __key_value_iterator& __y)
143159 requires three_way_comparable<__key_iterator>
144160 {
145161 return __x.__key_iter_ <=> __y.__key_iter_;
146162 }
147163
148 _LIBCPP_HIDE_FROM_ABI friend __key_value_iterator operator+(const __key_value_iterator& __i, difference_type __n) {
164 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend __key_value_iterator
165 operator+(const __key_value_iterator& __i, difference_type __n) {
149166 auto __tmp = __i;
150167 __tmp += __n;
151168 return __tmp;
152169 }
153170
154 _LIBCPP_HIDE_FROM_ABI friend __key_value_iterator operator+(difference_type __n, const __key_value_iterator& __i) {
171 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend __key_value_iterator
172 operator+(difference_type __n, const __key_value_iterator& __i) {
155173 return __i + __n;
156174 }
157175
158 _LIBCPP_HIDE_FROM_ABI friend __key_value_iterator operator-(const __key_value_iterator& __i, difference_type __n) {
176 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend __key_value_iterator
177 operator-(const __key_value_iterator& __i, difference_type __n) {
159178 auto __tmp = __i;
160179 __tmp -= __n;
161180 return __tmp;
162181 }
163182
164 _LIBCPP_HIDE_FROM_ABI friend difference_type
183 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend difference_type
165184 operator-(const __key_value_iterator& __x, const __key_value_iterator& __y) {
166185 return difference_type(__x.__key_iter_ - __y.__key_iter_);
167186 }
168187};
169188
189template <class _Owner, class _KeyContainer, class _MappedContainer, bool _Const>
190struct __product_iterator_traits<__key_value_iterator<_Owner, _KeyContainer, _MappedContainer, _Const>> {
191 static constexpr size_t __size = 2;
192
193 template <size_t _Nth, class _Iter>
194 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static decltype(auto) __get_iterator_element(_Iter&& __it)
195 requires(_Nth <= 1)
196 {
197 if constexpr (_Nth == 0) {
198 return std::forward<_Iter>(__it).__key_iter_;
199 } else {
200 return std::forward<_Iter>(__it).__mapped_iter_;
201 }
202 }
203
204 template <class _KeyIter, class _MappedIter>
205 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static auto
206 __make_product_iterator(_KeyIter&& __key_iter, _MappedIter&& __mapped_iter) {
207 return __key_value_iterator<_Owner, _KeyContainer, _MappedContainer, _Const>(
208 std::forward<_KeyIter>(__key_iter), std::forward<_MappedIter>(__mapped_iter));
209 }
210};
211
170212_LIBCPP_END_NAMESPACE_STD
171213
172214#endif // _LIBCPP_STD_VER >= 23
lib/libcxx/include/__flat_map/utils.h+22-4
......@@ -11,6 +11,7 @@
1111#define _LIBCPP___FLAT_MAP_UTILS_H
1212
1313#include <__config>
14#include <__iterator/product_iterator.h>
1415#include <__type_traits/container_traits.h>
1516#include <__utility/exception_guard.h>
1617#include <__utility/forward.h>
......@@ -35,7 +36,7 @@ struct __flat_map_utils {
3536 // roll back the changes it made to the map. If it cannot roll back the changes, it will
3637 // clear the map.
3738 template <class _Map, class _IterK, class _IterM, class _KeyArg, class... _MArgs>
38 _LIBCPP_HIDE_FROM_ABI static typename _Map::iterator __emplace_exact_pos(
39 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static typename _Map::iterator __emplace_exact_pos(
3940 _Map& __map, _IterK&& __it_key, _IterM&& __it_mapped, _KeyArg&& __key, _MArgs&&... __mapped_args) {
4041 auto __on_key_failed = std::__make_exception_guard([&]() noexcept {
4142 using _KeyContainer = typename _Map::key_container_type;
......@@ -79,10 +80,8 @@ struct __flat_map_utils {
7980 return typename _Map::iterator(std::move(__key_it), std::move(__mapped_it));
8081 }
8182
82 // TODO: We could optimize this, see
83 // https://github.com/llvm/llvm-project/issues/108624
8483 template <class _Map, class _InputIterator, class _Sentinel>
85 _LIBCPP_HIDE_FROM_ABI static typename _Map::size_type
84 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static typename _Map::size_type
8685 __append(_Map& __map, _InputIterator __first, _Sentinel __last) {
8786 typename _Map::size_type __num_appended = 0;
8887 for (; __first != __last; ++__first) {
......@@ -93,6 +92,25 @@ struct __flat_map_utils {
9392 }
9493 return __num_appended;
9594 }
95
96 template <class _Map, class _InputIterator>
97 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static typename _Map::size_type
98 __append(_Map& __map, _InputIterator __first, _InputIterator __last)
99 requires __is_product_iterator_of_size<_InputIterator, 2>::value
100 {
101 auto __s1 = __map.__containers_.keys.size();
102 __map.__containers_.keys.insert(
103 __map.__containers_.keys.end(),
104 __product_iterator_traits<_InputIterator>::template __get_iterator_element<0>(__first),
105 __product_iterator_traits<_InputIterator>::template __get_iterator_element<0>(__last));
106
107 __map.__containers_.values.insert(
108 __map.__containers_.values.end(),
109 __product_iterator_traits<_InputIterator>::template __get_iterator_element<1>(__first),
110 __product_iterator_traits<_InputIterator>::template __get_iterator_element<1>(__last));
111
112 return __map.__containers_.keys.size() - __s1;
113 }
96114};
97115_LIBCPP_END_NAMESPACE_STD
98116
lib/libcxx/include/__flat_set/flat_multiset.h created+792
......@@ -0,0 +1,792 @@
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_MULTISET_H
11#define _LIBCPP___FLAT_MAP_FLAT_MULTISET_H
12
13#include <__algorithm/equal_range.h>
14#include <__algorithm/lexicographical_compare_three_way.h>
15#include <__algorithm/lower_bound.h>
16#include <__algorithm/min.h>
17#include <__algorithm/ranges_equal.h>
18#include <__algorithm/ranges_inplace_merge.h>
19#include <__algorithm/ranges_is_sorted.h>
20#include <__algorithm/ranges_sort.h>
21#include <__algorithm/ranges_unique.h>
22#include <__algorithm/remove_if.h>
23#include <__algorithm/upper_bound.h>
24#include <__assert>
25#include <__compare/synth_three_way.h>
26#include <__concepts/convertible_to.h>
27#include <__concepts/swappable.h>
28#include <__config>
29#include <__cstddef/byte.h>
30#include <__cstddef/ptrdiff_t.h>
31#include <__flat_map/key_value_iterator.h>
32#include <__flat_map/sorted_equivalent.h>
33#include <__flat_set/ra_iterator.h>
34#include <__flat_set/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/prev.h>
43#include <__iterator/ranges_iterator_traits.h>
44#include <__iterator/reverse_iterator.h>
45#include <__memory/allocator_traits.h>
46#include <__memory/uses_allocator.h>
47#include <__memory/uses_allocator_construction.h>
48#include <__ranges/access.h>
49#include <__ranges/concepts.h>
50#include <__ranges/container_compatible_range.h>
51#include <__ranges/drop_view.h>
52#include <__ranges/from_range.h>
53#include <__ranges/ref_view.h>
54#include <__ranges/size.h>
55#include <__ranges/subrange.h>
56#include <__ranges/zip_view.h>
57#include <__type_traits/conjunction.h>
58#include <__type_traits/container_traits.h>
59#include <__type_traits/invoke.h>
60#include <__type_traits/is_allocator.h>
61#include <__type_traits/is_nothrow_constructible.h>
62#include <__type_traits/is_same.h>
63#include <__type_traits/maybe_const.h>
64#include <__utility/as_const.h>
65#include <__utility/exception_guard.h>
66#include <__utility/move.h>
67#include <__utility/pair.h>
68#include <__utility/scope_guard.h>
69#include <__vector/vector.h>
70#include <initializer_list>
71
72#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
73# pragma GCC system_header
74#endif
75
76_LIBCPP_PUSH_MACROS
77#include <__undef_macros>
78
79#if _LIBCPP_STD_VER >= 23
80
81_LIBCPP_BEGIN_NAMESPACE_STD
82
83template <class _Key, class _Compare = less<_Key>, class _KeyContainer = vector<_Key>>
84class flat_multiset {
85 template <class, class, class>
86 friend class flat_multiset;
87
88 friend __flat_set_utils;
89
90 static_assert(is_same_v<_Key, typename _KeyContainer::value_type>);
91 static_assert(!is_same_v<_KeyContainer, std::vector<bool>>, "vector<bool> is not a sequence container");
92
93public:
94 // types
95 using key_type = _Key;
96 using value_type = _Key;
97 using key_compare = __type_identity_t<_Compare>;
98 using value_compare = _Compare;
99 using reference = value_type&;
100 using const_reference = const value_type&;
101 using size_type = typename _KeyContainer::size_type;
102 using difference_type = typename _KeyContainer::difference_type;
103 using iterator = __ra_iterator<flat_multiset, typename _KeyContainer::const_iterator>;
104 using const_iterator = iterator;
105 using reverse_iterator = std::reverse_iterator<iterator>;
106 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
107 using container_type = _KeyContainer;
108
109public:
110 // [flat.multiset.cons], constructors
111 _LIBCPP_HIDE_FROM_ABI flat_multiset() noexcept(is_nothrow_default_constructible_v<_KeyContainer> &&
112 is_nothrow_default_constructible_v<_Compare>)
113 : __keys_(), __compare_() {}
114
115 _LIBCPP_HIDE_FROM_ABI flat_multiset(const flat_multiset&) = default;
116
117 // The copy/move constructors are not specified in the spec, which means they should be defaulted.
118 // However, the move constructor can potentially leave a moved-from object in an inconsistent
119 // state if an exception is thrown.
120 _LIBCPP_HIDE_FROM_ABI flat_multiset(flat_multiset&& __other) noexcept(
121 is_nothrow_move_constructible_v<_KeyContainer> && is_nothrow_move_constructible_v<_Compare>)
122# if _LIBCPP_HAS_EXCEPTIONS
123 try
124# endif // _LIBCPP_HAS_EXCEPTIONS
125 : __keys_(std::move(__other.__keys_)), __compare_(std::move(__other.__compare_)) {
126 __other.clear();
127# if _LIBCPP_HAS_EXCEPTIONS
128 } catch (...) {
129 __other.clear();
130 // gcc does not like the `throw` keyword in a conditionally noexcept function
131 if constexpr (!(is_nothrow_move_constructible_v<_KeyContainer> && is_nothrow_move_constructible_v<_Compare>)) {
132 throw;
133 }
134# endif // _LIBCPP_HAS_EXCEPTIONS
135 }
136
137 _LIBCPP_HIDE_FROM_ABI explicit flat_multiset(const key_compare& __comp) : __keys_(), __compare_(__comp) {}
138
139 _LIBCPP_HIDE_FROM_ABI explicit flat_multiset(container_type __keys, const key_compare& __comp = key_compare())
140 : __keys_(std::move(__keys)), __compare_(__comp) {
141 ranges::sort(__keys_, __compare_);
142 }
143
144 _LIBCPP_HIDE_FROM_ABI
145 flat_multiset(sorted_equivalent_t, container_type __keys, const key_compare& __comp = key_compare())
146 : __keys_(std::move(__keys)), __compare_(__comp) {
147 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(ranges::is_sorted(__keys_, __compare_), "Key container is not sorted");
148 }
149
150 template <class _InputIterator>
151 requires __has_input_iterator_category<_InputIterator>::value
152 _LIBCPP_HIDE_FROM_ABI
153 flat_multiset(_InputIterator __first, _InputIterator __last, const key_compare& __comp = key_compare())
154 : __keys_(), __compare_(__comp) {
155 insert(__first, __last);
156 }
157
158 template <class _InputIterator>
159 requires __has_input_iterator_category<_InputIterator>::value
160 _LIBCPP_HIDE_FROM_ABI flat_multiset(
161 sorted_equivalent_t, _InputIterator __first, _InputIterator __last, const key_compare& __comp = key_compare())
162 : __keys_(__first, __last), __compare_(__comp) {
163 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(ranges::is_sorted(__keys_, __compare_), "Key container is not sorted");
164 }
165
166 template <_ContainerCompatibleRange<value_type> _Range>
167 _LIBCPP_HIDE_FROM_ABI flat_multiset(from_range_t __fr, _Range&& __rg)
168 : flat_multiset(__fr, std::forward<_Range>(__rg), key_compare()) {}
169
170 template <_ContainerCompatibleRange<value_type> _Range>
171 _LIBCPP_HIDE_FROM_ABI flat_multiset(from_range_t, _Range&& __rg, const key_compare& __comp) : flat_multiset(__comp) {
172 insert_range(std::forward<_Range>(__rg));
173 }
174
175 _LIBCPP_HIDE_FROM_ABI flat_multiset(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
176 : flat_multiset(__il.begin(), __il.end(), __comp) {}
177
178 _LIBCPP_HIDE_FROM_ABI
179 flat_multiset(sorted_equivalent_t, initializer_list<value_type> __il, const key_compare& __comp = key_compare())
180 : flat_multiset(sorted_equivalent, __il.begin(), __il.end(), __comp) {}
181
182 template <class _Allocator>
183 requires uses_allocator<container_type, _Allocator>::value
184 _LIBCPP_HIDE_FROM_ABI explicit flat_multiset(const _Allocator& __alloc)
185 : __keys_(std::make_obj_using_allocator<container_type>(__alloc)), __compare_() {}
186
187 template <class _Allocator>
188 requires uses_allocator<container_type, _Allocator>::value
189 _LIBCPP_HIDE_FROM_ABI flat_multiset(const key_compare& __comp, const _Allocator& __alloc)
190 : __keys_(std::make_obj_using_allocator<container_type>(__alloc)), __compare_(__comp) {}
191
192 template <class _Allocator>
193 requires uses_allocator<container_type, _Allocator>::value
194 _LIBCPP_HIDE_FROM_ABI flat_multiset(const container_type& __keys, const _Allocator& __alloc)
195 : __keys_(std::make_obj_using_allocator<container_type>(__alloc, __keys)), __compare_() {
196 ranges::sort(__keys_, __compare_);
197 }
198
199 template <class _Allocator>
200 requires uses_allocator<container_type, _Allocator>::value
201 _LIBCPP_HIDE_FROM_ABI
202 flat_multiset(const container_type& __keys, const key_compare& __comp, const _Allocator& __alloc)
203 : __keys_(std::make_obj_using_allocator<container_type>(__alloc, __keys)), __compare_(__comp) {
204 ranges::sort(__keys_, __compare_);
205 }
206
207 template <class _Allocator>
208 requires uses_allocator<container_type, _Allocator>::value
209 _LIBCPP_HIDE_FROM_ABI flat_multiset(sorted_equivalent_t, const container_type& __keys, const _Allocator& __alloc)
210 : __keys_(std::make_obj_using_allocator<container_type>(__alloc, __keys)), __compare_() {
211 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(ranges::is_sorted(__keys_, __compare_), "Key container is not sorted");
212 }
213
214 template <class _Allocator>
215 requires uses_allocator<container_type, _Allocator>::value
216 _LIBCPP_HIDE_FROM_ABI
217 flat_multiset(sorted_equivalent_t, const container_type& __keys, const key_compare& __comp, const _Allocator& __alloc)
218 : __keys_(std::make_obj_using_allocator<container_type>(__alloc, __keys)), __compare_(__comp) {
219 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(ranges::is_sorted(__keys_, __compare_), "Key container is not sorted");
220 }
221
222 template <class _Allocator>
223 requires uses_allocator<container_type, _Allocator>::value
224 _LIBCPP_HIDE_FROM_ABI flat_multiset(const flat_multiset& __other, const _Allocator& __alloc)
225 : __keys_(std::make_obj_using_allocator<container_type>(__alloc, __other.__keys_)),
226 __compare_(__other.__compare_) {}
227
228 template <class _Allocator>
229 requires uses_allocator<container_type, _Allocator>::value
230 _LIBCPP_HIDE_FROM_ABI flat_multiset(flat_multiset&& __other, const _Allocator& __alloc)
231# if _LIBCPP_HAS_EXCEPTIONS
232 try
233# endif // _LIBCPP_HAS_EXCEPTIONS
234 : __keys_(std::make_obj_using_allocator<container_type>(__alloc, std::move(__other.__keys_))),
235 __compare_(std::move(__other.__compare_)) {
236 __other.clear();
237# if _LIBCPP_HAS_EXCEPTIONS
238 } catch (...) {
239 __other.clear();
240 throw;
241# endif // _LIBCPP_HAS_EXCEPTIONS
242 }
243
244 template <class _InputIterator, class _Allocator>
245 requires(__has_input_iterator_category<_InputIterator>::value && uses_allocator<container_type, _Allocator>::value)
246 _LIBCPP_HIDE_FROM_ABI flat_multiset(_InputIterator __first, _InputIterator __last, const _Allocator& __alloc)
247 : __keys_(std::make_obj_using_allocator<container_type>(__alloc)), __compare_() {
248 insert(__first, __last);
249 }
250
251 template <class _InputIterator, class _Allocator>
252 requires(__has_input_iterator_category<_InputIterator>::value && uses_allocator<container_type, _Allocator>::value)
253 _LIBCPP_HIDE_FROM_ABI
254 flat_multiset(_InputIterator __first, _InputIterator __last, const key_compare& __comp, const _Allocator& __alloc)
255 : __keys_(std::make_obj_using_allocator<container_type>(__alloc)), __compare_(__comp) {
256 insert(__first, __last);
257 }
258
259 template <class _InputIterator, class _Allocator>
260 requires(__has_input_iterator_category<_InputIterator>::value && uses_allocator<container_type, _Allocator>::value)
261 _LIBCPP_HIDE_FROM_ABI
262 flat_multiset(sorted_equivalent_t, _InputIterator __first, _InputIterator __last, const _Allocator& __alloc)
263 : __keys_(std::make_obj_using_allocator<container_type>(__alloc, __first, __last)), __compare_() {
264 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(ranges::is_sorted(__keys_, __compare_), "Key container is not sorted");
265 }
266
267 template <class _InputIterator, class _Allocator>
268 requires(__has_input_iterator_category<_InputIterator>::value && uses_allocator<container_type, _Allocator>::value)
269 _LIBCPP_HIDE_FROM_ABI
270 flat_multiset(sorted_equivalent_t,
271 _InputIterator __first,
272 _InputIterator __last,
273 const key_compare& __comp,
274 const _Allocator& __alloc)
275 : __keys_(std::make_obj_using_allocator<container_type>(__alloc, __first, __last)), __compare_(__comp) {
276 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(ranges::is_sorted(__keys_, __compare_), "Key container is not sorted");
277 }
278
279 template <_ContainerCompatibleRange<value_type> _Range, class _Allocator>
280 requires uses_allocator<container_type, _Allocator>::value
281 _LIBCPP_HIDE_FROM_ABI flat_multiset(from_range_t, _Range&& __rg, const _Allocator& __alloc)
282 : __keys_(std::make_obj_using_allocator<container_type>(__alloc)), __compare_() {
283 insert_range(std::forward<_Range>(__rg));
284 }
285
286 template <_ContainerCompatibleRange<value_type> _Range, class _Allocator>
287 requires uses_allocator<container_type, _Allocator>::value
288 _LIBCPP_HIDE_FROM_ABI flat_multiset(from_range_t, _Range&& __rg, const key_compare& __comp, const _Allocator& __alloc)
289 : __keys_(std::make_obj_using_allocator<container_type>(__alloc)), __compare_(__comp) {
290 insert_range(std::forward<_Range>(__rg));
291 }
292
293 template <class _Allocator>
294 requires uses_allocator<container_type, _Allocator>::value
295 _LIBCPP_HIDE_FROM_ABI flat_multiset(initializer_list<value_type> __il, const _Allocator& __alloc)
296 : flat_multiset(__il.begin(), __il.end(), __alloc) {}
297
298 template <class _Allocator>
299 requires uses_allocator<container_type, _Allocator>::value
300 _LIBCPP_HIDE_FROM_ABI
301 flat_multiset(initializer_list<value_type> __il, const key_compare& __comp, const _Allocator& __alloc)
302 : flat_multiset(__il.begin(), __il.end(), __comp, __alloc) {}
303
304 template <class _Allocator>
305 requires uses_allocator<container_type, _Allocator>::value
306 _LIBCPP_HIDE_FROM_ABI flat_multiset(sorted_equivalent_t, initializer_list<value_type> __il, const _Allocator& __alloc)
307 : flat_multiset(sorted_equivalent, __il.begin(), __il.end(), __alloc) {}
308
309 template <class _Allocator>
310 requires uses_allocator<container_type, _Allocator>::value
311 _LIBCPP_HIDE_FROM_ABI flat_multiset(
312 sorted_equivalent_t, initializer_list<value_type> __il, const key_compare& __comp, const _Allocator& __alloc)
313 : flat_multiset(sorted_equivalent, __il.begin(), __il.end(), __comp, __alloc) {}
314
315 _LIBCPP_HIDE_FROM_ABI flat_multiset& operator=(initializer_list<value_type> __il) {
316 clear();
317 insert(__il);
318 return *this;
319 }
320
321 // copy/move assignment are not specified in the spec (defaulted)
322 // but move assignment can potentially leave moved from object in an inconsistent
323 // state if an exception is thrown
324 _LIBCPP_HIDE_FROM_ABI flat_multiset& operator=(const flat_multiset&) = default;
325
326 _LIBCPP_HIDE_FROM_ABI flat_multiset& operator=(flat_multiset&& __other) noexcept(
327 is_nothrow_move_assignable_v<_KeyContainer> && is_nothrow_move_assignable_v<_Compare>) {
328 auto __clear_other_guard = std::__make_scope_guard([&]() noexcept { __other.clear() /* noexcept */; });
329 auto __clear_self_guard = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
330 __keys_ = std::move(__other.__keys_);
331 __compare_ = std::move(__other.__compare_);
332 __clear_self_guard.__complete();
333 return *this;
334 }
335
336 // iterators
337 _LIBCPP_HIDE_FROM_ABI iterator begin() noexcept { return iterator(std::as_const(__keys_).begin()); }
338 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const noexcept { return const_iterator(__keys_.begin()); }
339 _LIBCPP_HIDE_FROM_ABI iterator end() noexcept { return iterator(std::as_const(__keys_).end()); }
340 _LIBCPP_HIDE_FROM_ABI const_iterator end() const noexcept { return const_iterator(__keys_.end()); }
341
342 _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() noexcept { return reverse_iterator(end()); }
343 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); }
344 _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() noexcept { return reverse_iterator(begin()); }
345 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); }
346
347 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const noexcept { return begin(); }
348 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const noexcept { return end(); }
349 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); }
350 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); }
351
352 // capacity
353 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool empty() const noexcept { return __keys_.empty(); }
354 _LIBCPP_HIDE_FROM_ABI size_type size() const noexcept { return __keys_.size(); }
355 _LIBCPP_HIDE_FROM_ABI size_type max_size() const noexcept { return __keys_.max_size(); }
356
357 // [flat.multiset.modifiers], modifiers
358 template <class... _Args>
359 requires is_constructible_v<value_type, _Args...>
360 _LIBCPP_HIDE_FROM_ABI iterator emplace(_Args&&... __args) {
361 if constexpr (sizeof...(__args) == 1 && (is_same_v<remove_cvref_t<_Args>, _Key> && ...)) {
362 return __emplace(std::forward<_Args>(__args)...);
363 } else {
364 return __emplace(_Key(std::forward<_Args>(__args)...));
365 }
366 }
367
368 template <class... _Args>
369 requires is_constructible_v<value_type, _Args...>
370 _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __hint, _Args&&... __args) {
371 if constexpr (sizeof...(__args) == 1 && (is_same_v<remove_cvref_t<_Args>, _Key> && ...)) {
372 return __emplace_hint(std::move(__hint), std::forward<_Args>(__args)...);
373 } else {
374 return __emplace_hint(std::move(__hint), _Key(std::forward<_Args>(__args)...));
375 }
376 }
377
378 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return emplace(__x); }
379
380 _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __x) { return emplace(std::move(__x)); }
381
382 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, const value_type& __x) {
383 return emplace_hint(__hint, __x);
384 }
385
386 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, value_type&& __x) {
387 return emplace_hint(__hint, std::move(__x));
388 }
389
390 template <class _InputIterator>
391 requires __has_input_iterator_category<_InputIterator>::value
392 _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last) {
393 if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>) {
394 __reserve(__last - __first);
395 }
396 __append_sort_merge</*WasSorted = */ false>(std::move(__first), std::move(__last));
397 }
398
399 template <class _InputIterator>
400 requires __has_input_iterator_category<_InputIterator>::value
401 _LIBCPP_HIDE_FROM_ABI void insert(sorted_equivalent_t, _InputIterator __first, _InputIterator __last) {
402 if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>) {
403 __reserve(__last - __first);
404 }
405
406 __append_sort_merge</*WasSorted = */ true>(std::move(__first), std::move(__last));
407 }
408
409 template <_ContainerCompatibleRange<value_type> _Range>
410 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
411 if constexpr (ranges::sized_range<_Range>) {
412 __reserve(ranges::size(__range));
413 }
414
415 __append_sort_merge</*WasSorted = */ false>(std::forward<_Range>(__range));
416 }
417
418 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
419
420 _LIBCPP_HIDE_FROM_ABI void insert(sorted_equivalent_t, initializer_list<value_type> __il) {
421 insert(sorted_equivalent, __il.begin(), __il.end());
422 }
423
424 _LIBCPP_HIDE_FROM_ABI container_type extract() && {
425 auto __guard = std::__make_scope_guard([&]() noexcept { clear() /* noexcept */; });
426 auto __ret = std::move(__keys_);
427 return __ret;
428 }
429
430 _LIBCPP_HIDE_FROM_ABI void replace(container_type&& __keys) {
431 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(ranges::is_sorted(__keys, __compare_), "Key container is not sorted");
432 auto __guard = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
433 __keys_ = std::move(__keys);
434 __guard.__complete();
435 }
436
437 _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __position) {
438 auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
439 auto __key_iter = __keys_.erase(__position.__base());
440 __on_failure.__complete();
441 return iterator(__key_iter);
442 }
443
444 // The following overload is the same as the iterator overload
445 // iterator erase(const_iterator __position);
446
447 _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __x) {
448 auto [__first, __last] = equal_range(__x);
449 auto __res = __last - __first;
450 erase(__first, __last);
451 return __res;
452 }
453
454 template <class _Kp>
455 requires(__is_transparent_v<_Compare> && !is_convertible_v<_Kp &&, iterator> &&
456 !is_convertible_v<_Kp &&, const_iterator>)
457 _LIBCPP_HIDE_FROM_ABI size_type erase(_Kp&& __x) {
458 auto [__first, __last] = equal_range(__x);
459 auto __res = __last - __first;
460 erase(__first, __last);
461 return __res;
462 }
463
464 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last) {
465 auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
466 auto __key_it = __keys_.erase(__first.__base(), __last.__base());
467 __on_failure.__complete();
468 return iterator(std::move(__key_it));
469 }
470
471 _LIBCPP_HIDE_FROM_ABI void swap(flat_multiset& __y) noexcept {
472 // warning: The spec has unconditional noexcept, which means that
473 // if any of the following functions throw an exception,
474 // std::terminate will be called
475 // This is discussed in P3567, which hasn't been voted on yet.
476 ranges::swap(__compare_, __y.__compare_);
477 ranges::swap(__keys_, __y.__keys_);
478 }
479
480 _LIBCPP_HIDE_FROM_ABI void clear() noexcept { __keys_.clear(); }
481
482 // observers
483 _LIBCPP_HIDE_FROM_ABI key_compare key_comp() const { return __compare_; }
484 _LIBCPP_HIDE_FROM_ABI value_compare value_comp() const { return __compare_; }
485
486 // map operations
487 _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __x) { return __find_impl(*this, __x); }
488
489 _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __x) const { return __find_impl(*this, __x); }
490
491 template <class _Kp>
492 requires __is_transparent_v<_Compare>
493 _LIBCPP_HIDE_FROM_ABI iterator find(const _Kp& __x) {
494 return __find_impl(*this, __x);
495 }
496
497 template <class _Kp>
498 requires __is_transparent_v<_Compare>
499 _LIBCPP_HIDE_FROM_ABI const_iterator find(const _Kp& __x) const {
500 return __find_impl(*this, __x);
501 }
502
503 _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __x) const {
504 auto [__first, __last] = equal_range(__x);
505 return __last - __first;
506 }
507
508 template <class _Kp>
509 requires __is_transparent_v<_Compare>
510 _LIBCPP_HIDE_FROM_ABI size_type count(const _Kp& __x) const {
511 auto [__first, __last] = equal_range(__x);
512 return __last - __first;
513 }
514
515 _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __x) const { return find(__x) != end(); }
516
517 template <class _Kp>
518 requires __is_transparent_v<_Compare>
519 _LIBCPP_HIDE_FROM_ABI bool contains(const _Kp& __x) const {
520 return find(__x) != end();
521 }
522
523 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __x) {
524 const auto& __keys = __keys_;
525 return iterator(std::lower_bound(__keys.begin(), __keys.end(), __x, __compare_));
526 }
527
528 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __x) const {
529 return const_iterator(std::lower_bound(__keys_.begin(), __keys_.end(), __x, __compare_));
530 }
531
532 template <class _Kp>
533 requires __is_transparent_v<_Compare>
534 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _Kp& __x) {
535 const auto& __keys = __keys_;
536 return iterator(std::lower_bound(__keys.begin(), __keys.end(), __x, __compare_));
537 }
538
539 template <class _Kp>
540 requires __is_transparent_v<_Compare>
541 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _Kp& __x) const {
542 return const_iterator(std::lower_bound(__keys_.begin(), __keys_.end(), __x, __compare_));
543 }
544
545 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __x) {
546 const auto& __keys = __keys_;
547 return iterator(std::upper_bound(__keys.begin(), __keys.end(), __x, __compare_));
548 }
549
550 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __x) const {
551 return const_iterator(std::upper_bound(__keys_.begin(), __keys_.end(), __x, __compare_));
552 }
553
554 template <class _Kp>
555 requires __is_transparent_v<_Compare>
556 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _Kp& __x) {
557 const auto& __keys = __keys_;
558 return iterator(std::upper_bound(__keys.begin(), __keys.end(), __x, __compare_));
559 }
560
561 template <class _Kp>
562 requires __is_transparent_v<_Compare>
563 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _Kp& __x) const {
564 return const_iterator(std::upper_bound(__keys_.begin(), __keys_.end(), __x, __compare_));
565 }
566
567 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __x) {
568 return __equal_range_impl(*this, __x);
569 }
570
571 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __x) const {
572 return __equal_range_impl(*this, __x);
573 }
574
575 template <class _Kp>
576 requires __is_transparent_v<_Compare>
577 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _Kp& __x) {
578 return __equal_range_impl(*this, __x);
579 }
580 template <class _Kp>
581 requires __is_transparent_v<_Compare>
582 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _Kp& __x) const {
583 return __equal_range_impl(*this, __x);
584 }
585
586 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const flat_multiset& __x, const flat_multiset& __y) {
587 return ranges::equal(__x, __y);
588 }
589
590 friend _LIBCPP_HIDE_FROM_ABI auto operator<=>(const flat_multiset& __x, const flat_multiset& __y) {
591 return std::lexicographical_compare_three_way(
592 __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
593 }
594
595 friend _LIBCPP_HIDE_FROM_ABI void swap(flat_multiset& __x, flat_multiset& __y) noexcept { __x.swap(__y); }
596
597private:
598 template <bool _WasSorted, class... _Args>
599 _LIBCPP_HIDE_FROM_ABI void __append_sort_merge(_Args&&... __args) {
600 auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
601 size_type __old_size = size();
602 __flat_set_utils::__append(*this, std::forward<_Args>(__args)...);
603 if constexpr (!_WasSorted) {
604 ranges::sort(__keys_.begin() + __old_size, __keys_.end(), __compare_);
605 } else {
606 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
607 ranges::is_sorted(__keys_ | ranges::views::drop(__old_size)), "Key container is not sorted");
608 }
609 ranges::inplace_merge(__keys_.begin(), __keys_.begin() + __old_size, __keys_.end(), __compare_);
610 __on_failure.__complete();
611 }
612
613 template <class _Kp>
614 _LIBCPP_HIDE_FROM_ABI iterator __emplace(_Kp&& __key) {
615 auto __it = upper_bound(__key);
616 return __flat_set_utils::__emplace_exact_pos(*this, __it, std::forward<_Kp>(__key));
617 }
618
619 template <class _Kp>
620 _LIBCPP_HIDE_FROM_ABI iterator __emplace_hint(const_iterator __hint, _Kp&& __key) {
621 auto __prev_larger = __hint != cbegin() && __compare_(__key, *std::prev(__hint));
622 auto __next_smaller = __hint != cend() && __compare_(*__hint, __key);
623
624 if (!__prev_larger && !__next_smaller) [[likely]] {
625 // hint correct, just use exact hint iterator
626 } else if (__prev_larger && !__next_smaller) {
627 // the hint position is more to the right than the key should have been.
628 // we want to emplace the element to a position as right as possible
629 // e.g. Insert new element "2" in the following range
630 // 1, 1, 2, 2, 2, 3, 4, 6
631 // ^
632 // |
633 // hint
634 // We want to insert "2" after the last existing "2"
635 __hint = std::upper_bound(begin(), __hint, __key, __compare_);
636 } else {
637 _LIBCPP_ASSERT_INTERNAL(!__prev_larger && __next_smaller, "this means that the multiset is not sorted");
638
639 // the hint position is more to the left than the key should have been.
640 // we want to emplace the element to a position as left as possible
641 // 1, 1, 2, 2, 2, 3, 4, 6
642 // ^
643 // |
644 // hint
645 // We want to insert "2" before the first existing "2"
646 __hint = std::lower_bound(__hint, end(), __key, __compare_);
647 }
648 return __flat_set_utils::__emplace_exact_pos(*this, __hint, std::forward<_Kp>(__key));
649 }
650
651 template <class _Self, class _Kp>
652 _LIBCPP_HIDE_FROM_ABI static auto __find_impl(_Self&& __self, const _Kp& __key) {
653 auto __it = __self.lower_bound(__key);
654 auto __last = __self.end();
655 if (__it == __last || __self.__compare_(__key, *__it)) {
656 return __last;
657 }
658 return __it;
659 }
660
661 template <class _Self, class _Kp>
662 _LIBCPP_HIDE_FROM_ABI static auto __equal_range_impl(_Self&& __self, const _Kp& __key) {
663 using __iter = _If<is_const_v<__libcpp_remove_reference_t<_Self>>, const_iterator, iterator>;
664 auto [__key_first, __key_last] =
665 std::equal_range(__self.__keys_.begin(), __self.__keys_.end(), __key, __self.__compare_);
666 return std::make_pair(__iter(__key_first), __iter(__key_last));
667 }
668
669 _LIBCPP_HIDE_FROM_ABI void __reserve(size_t __size) {
670 if constexpr (__container_traits<_KeyContainer>::__reservable) {
671 __keys_.reserve(__size);
672 }
673 }
674
675 template <class _Key2, class _Compare2, class _KeyContainer2, class _Predicate>
676 friend typename flat_multiset<_Key2, _Compare2, _KeyContainer2>::size_type
677 erase_if(flat_multiset<_Key2, _Compare2, _KeyContainer2>&, _Predicate);
678
679 _KeyContainer __keys_;
680 _LIBCPP_NO_UNIQUE_ADDRESS key_compare __compare_;
681
682 struct __key_equiv {
683 _LIBCPP_HIDE_FROM_ABI __key_equiv(key_compare __c) : __comp_(__c) {}
684 _LIBCPP_HIDE_FROM_ABI bool operator()(const_reference __x, const_reference __y) const {
685 return !__comp_(std::get<0>(__x), std::get<0>(__y)) && !__comp_(std::get<0>(__y), std::get<0>(__x));
686 }
687 key_compare __comp_;
688 };
689};
690
691template <class _KeyContainer, class _Compare = less<typename _KeyContainer::value_type>>
692 requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value &&
693 is_invocable_v<const _Compare&,
694 const typename _KeyContainer::value_type&,
695 const typename _KeyContainer::value_type&>)
696flat_multiset(_KeyContainer, _Compare = _Compare())
697 -> flat_multiset<typename _KeyContainer::value_type, _Compare, _KeyContainer>;
698
699template <class _KeyContainer, class _Allocator>
700 requires(uses_allocator_v<_KeyContainer, _Allocator> && !__is_allocator<_KeyContainer>::value)
701flat_multiset(_KeyContainer, _Allocator)
702 -> flat_multiset<typename _KeyContainer::value_type, less<typename _KeyContainer::value_type>, _KeyContainer>;
703
704template <class _KeyContainer, class _Compare, class _Allocator>
705 requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value &&
706 uses_allocator_v<_KeyContainer, _Allocator> &&
707 is_invocable_v<const _Compare&,
708 const typename _KeyContainer::value_type&,
709 const typename _KeyContainer::value_type&>)
710flat_multiset(_KeyContainer, _Compare, _Allocator)
711 -> flat_multiset<typename _KeyContainer::value_type, _Compare, _KeyContainer>;
712
713template <class _KeyContainer, class _Compare = less<typename _KeyContainer::value_type>>
714 requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value &&
715 is_invocable_v<const _Compare&,
716 const typename _KeyContainer::value_type&,
717 const typename _KeyContainer::value_type&>)
718flat_multiset(sorted_equivalent_t, _KeyContainer, _Compare = _Compare())
719 -> flat_multiset<typename _KeyContainer::value_type, _Compare, _KeyContainer>;
720
721template <class _KeyContainer, class _Allocator>
722 requires(uses_allocator_v<_KeyContainer, _Allocator> && !__is_allocator<_KeyContainer>::value)
723flat_multiset(sorted_equivalent_t, _KeyContainer, _Allocator)
724 -> flat_multiset<typename _KeyContainer::value_type, less<typename _KeyContainer::value_type>, _KeyContainer>;
725
726template <class _KeyContainer, class _Compare, class _Allocator>
727 requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value &&
728 uses_allocator_v<_KeyContainer, _Allocator> &&
729 is_invocable_v<const _Compare&,
730 const typename _KeyContainer::value_type&,
731 const typename _KeyContainer::value_type&>)
732flat_multiset(sorted_equivalent_t, _KeyContainer, _Compare, _Allocator)
733 -> flat_multiset<typename _KeyContainer::value_type, _Compare, _KeyContainer>;
734
735template <class _InputIterator, class _Compare = less<__iter_value_type<_InputIterator>>>
736 requires(__has_input_iterator_category<_InputIterator>::value && !__is_allocator<_Compare>::value)
737flat_multiset(_InputIterator, _InputIterator, _Compare = _Compare())
738 -> flat_multiset<__iter_value_type<_InputIterator>, _Compare>;
739
740template <class _InputIterator, class _Compare = less<__iter_value_type<_InputIterator>>>
741 requires(__has_input_iterator_category<_InputIterator>::value && !__is_allocator<_Compare>::value)
742flat_multiset(sorted_equivalent_t, _InputIterator, _InputIterator, _Compare = _Compare())
743 -> flat_multiset<__iter_value_type<_InputIterator>, _Compare>;
744
745template <ranges::input_range _Range,
746 class _Compare = less<ranges::range_value_t<_Range>>,
747 class _Allocator = allocator<ranges::range_value_t<_Range>>,
748 class = __enable_if_t<!__is_allocator<_Compare>::value && __is_allocator<_Allocator>::value>>
749flat_multiset(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator()) -> flat_multiset<
750 ranges::range_value_t<_Range>,
751 _Compare,
752 vector<ranges::range_value_t<_Range>, __allocator_traits_rebind_t<_Allocator, ranges::range_value_t<_Range>>>>;
753
754template <ranges::input_range _Range, class _Allocator, class = __enable_if_t<__is_allocator<_Allocator>::value>>
755flat_multiset(from_range_t, _Range&&, _Allocator) -> flat_multiset<
756 ranges::range_value_t<_Range>,
757 less<ranges::range_value_t<_Range>>,
758 vector<ranges::range_value_t<_Range>, __allocator_traits_rebind_t<_Allocator, ranges::range_value_t<_Range>>>>;
759
760template <class _Key, class _Compare = less<_Key>>
761 requires(!__is_allocator<_Compare>::value)
762flat_multiset(initializer_list<_Key>, _Compare = _Compare()) -> flat_multiset<_Key, _Compare>;
763
764template <class _Key, class _Compare = less<_Key>>
765 requires(!__is_allocator<_Compare>::value)
766flat_multiset(sorted_equivalent_t, initializer_list<_Key>, _Compare = _Compare()) -> flat_multiset<_Key, _Compare>;
767
768template <class _Key, class _Compare, class _KeyContainer, class _Allocator>
769struct uses_allocator<flat_multiset<_Key, _Compare, _KeyContainer>, _Allocator>
770 : bool_constant<uses_allocator_v<_KeyContainer, _Allocator> > {};
771
772template <class _Key, class _Compare, class _KeyContainer, class _Predicate>
773_LIBCPP_HIDE_FROM_ABI typename flat_multiset<_Key, _Compare, _KeyContainer>::size_type
774erase_if(flat_multiset<_Key, _Compare, _KeyContainer>& __flat_multiset, _Predicate __pred) {
775 auto __guard = std::__make_exception_guard([&] { __flat_multiset.clear(); });
776 auto __it =
777 std::remove_if(__flat_multiset.__keys_.begin(), __flat_multiset.__keys_.end(), [&](const auto& __e) -> bool {
778 return static_cast<bool>(__pred(__e));
779 });
780 auto __res = __flat_multiset.__keys_.end() - __it;
781 __flat_multiset.__keys_.erase(__it, __flat_multiset.__keys_.end());
782 __guard.__complete();
783 return __res;
784}
785
786_LIBCPP_END_NAMESPACE_STD
787
788#endif // _LIBCPP_STD_VER >= 23
789
790_LIBCPP_POP_MACROS
791
792#endif // _LIBCPP___FLAT_MAP_FLAT_MULTISET_H
lib/libcxx/include/__flat_set/flat_set.h created+874
......@@ -0,0 +1,874 @@
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_SET_FLAT_SET_H
11#define _LIBCPP___FLAT_SET_FLAT_SET_H
12
13#include <__algorithm/lexicographical_compare_three_way.h>
14#include <__algorithm/lower_bound.h>
15#include <__algorithm/min.h>
16#include <__algorithm/ranges_adjacent_find.h>
17#include <__algorithm/ranges_equal.h>
18#include <__algorithm/ranges_inplace_merge.h>
19#include <__algorithm/ranges_sort.h>
20#include <__algorithm/ranges_unique.h>
21#include <__algorithm/remove_if.h>
22#include <__algorithm/upper_bound.h>
23#include <__assert>
24#include <__compare/synth_three_way.h>
25#include <__concepts/swappable.h>
26#include <__config>
27#include <__cstddef/ptrdiff_t.h>
28#include <__flat_map/sorted_unique.h>
29#include <__flat_set/ra_iterator.h>
30#include <__flat_set/utils.h>
31#include <__functional/invoke.h>
32#include <__functional/is_transparent.h>
33#include <__functional/operations.h>
34#include <__fwd/vector.h>
35#include <__iterator/concepts.h>
36#include <__iterator/distance.h>
37#include <__iterator/iterator_traits.h>
38#include <__iterator/next.h>
39#include <__iterator/prev.h>
40#include <__iterator/ranges_iterator_traits.h>
41#include <__iterator/reverse_iterator.h>
42#include <__memory/allocator_traits.h>
43#include <__memory/uses_allocator.h>
44#include <__memory/uses_allocator_construction.h>
45#include <__ranges/access.h>
46#include <__ranges/concepts.h>
47#include <__ranges/container_compatible_range.h>
48#include <__ranges/drop_view.h>
49#include <__ranges/from_range.h>
50#include <__ranges/ref_view.h>
51#include <__ranges/size.h>
52#include <__ranges/subrange.h>
53#include <__type_traits/conjunction.h>
54#include <__type_traits/container_traits.h>
55#include <__type_traits/invoke.h>
56#include <__type_traits/is_allocator.h>
57#include <__type_traits/is_const.h>
58#include <__type_traits/is_nothrow_constructible.h>
59#include <__type_traits/is_same.h>
60#include <__type_traits/remove_reference.h>
61#include <__utility/as_const.h>
62#include <__utility/exception_guard.h>
63#include <__utility/move.h>
64#include <__utility/pair.h>
65#include <__utility/scope_guard.h>
66#include <__vector/vector.h>
67#include <initializer_list>
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, class _Compare = less<_Key>, class _KeyContainer = vector<_Key>>
81class flat_set {
82 template <class, class, class>
83 friend class flat_set;
84
85 friend __flat_set_utils;
86
87 static_assert(is_same_v<_Key, typename _KeyContainer::value_type>);
88 static_assert(!is_same_v<_KeyContainer, std::vector<bool>>, "vector<bool> is not a sequence container");
89
90 using __key_iterator _LIBCPP_NODEBUG = typename _KeyContainer::const_iterator;
91
92public:
93 // types
94 using key_type = _Key;
95 using value_type = _Key;
96 using key_compare = __type_identity_t<_Compare>;
97 using value_compare = _Compare;
98 using reference = value_type&;
99 using const_reference = const value_type&;
100 using size_type = typename _KeyContainer::size_type;
101 using difference_type = typename _KeyContainer::difference_type;
102 using iterator = __ra_iterator<flat_set, typename _KeyContainer::const_iterator>;
103 using const_iterator = iterator;
104 using reverse_iterator = std::reverse_iterator<iterator>;
105 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
106 using container_type = _KeyContainer;
107
108public:
109 // [flat.set.cons], construct/copy/destroy
110 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
111 flat_set() noexcept(is_nothrow_default_constructible_v<_KeyContainer> && is_nothrow_default_constructible_v<_Compare>)
112 : __keys_(), __compare_() {}
113
114 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_set(const flat_set&) = default;
115
116 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_set(flat_set&& __other) noexcept(
117 is_nothrow_move_constructible_v<_KeyContainer> && is_nothrow_move_constructible_v<_Compare>)
118# if _LIBCPP_HAS_EXCEPTIONS
119 try
120# endif // _LIBCPP_HAS_EXCEPTIONS
121 : __keys_(std::move(__other.__keys_)), __compare_(std::move(__other.__compare_)) {
122 __other.clear();
123# if _LIBCPP_HAS_EXCEPTIONS
124 } catch (...) {
125 __other.clear();
126 // gcc does not like the `throw` keyword in a conditionally noexcept function
127 if constexpr (!(is_nothrow_move_constructible_v<_KeyContainer> && is_nothrow_move_constructible_v<_Compare>)) {
128 throw;
129 }
130# endif // _LIBCPP_HAS_EXCEPTIONS
131 }
132
133 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit flat_set(const key_compare& __comp)
134 : __keys_(), __compare_(__comp) {}
135
136 _LIBCPP_HIDE_FROM_ABI
137 _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit flat_set(container_type __keys, const key_compare& __comp = key_compare())
138 : __keys_(std::move(__keys)), __compare_(__comp) {
139 __sort_and_unique();
140 }
141
142 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
143 flat_set(sorted_unique_t, container_type __keys, const key_compare& __comp = key_compare())
144 : __keys_(std::move(__keys)), __compare_(__comp) {
145 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
146 __is_sorted_and_unique(__keys_), "Either the key container is not sorted or it contains duplicates");
147 }
148
149 template <class _InputIterator>
150 requires __has_input_iterator_category<_InputIterator>::value
151 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
152 flat_set(_InputIterator __first, _InputIterator __last, const key_compare& __comp = key_compare())
153 : __keys_(), __compare_(__comp) {
154 insert(__first, __last);
155 }
156
157 template <class _InputIterator>
158 requires __has_input_iterator_category<_InputIterator>::value
159 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
160 flat_set(sorted_unique_t, _InputIterator __first, _InputIterator __last, const key_compare& __comp = key_compare())
161 : __keys_(__first, __last), __compare_(__comp) {
162 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
163 __is_sorted_and_unique(__keys_), "Either the key container is not sorted or it contains duplicates");
164 }
165
166 template <_ContainerCompatibleRange<value_type> _Range>
167 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_set(from_range_t, _Range&& __rg)
168 : flat_set(from_range, std::forward<_Range>(__rg), key_compare()) {}
169
170 template <_ContainerCompatibleRange<value_type> _Range>
171 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_set(from_range_t, _Range&& __rg, const key_compare& __comp)
172 : flat_set(__comp) {
173 insert_range(std::forward<_Range>(__rg));
174 }
175
176 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
177 flat_set(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
178 : flat_set(__il.begin(), __il.end(), __comp) {}
179
180 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
181 flat_set(sorted_unique_t, initializer_list<value_type> __il, const key_compare& __comp = key_compare())
182 : flat_set(sorted_unique, __il.begin(), __il.end(), __comp) {}
183
184 template <class _Allocator>
185 requires uses_allocator<container_type, _Allocator>::value
186 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit flat_set(const _Allocator& __alloc)
187 : __keys_(std::make_obj_using_allocator<container_type>(__alloc)), __compare_() {}
188
189 template <class _Allocator>
190 requires uses_allocator<container_type, _Allocator>::value
191 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_set(const key_compare& __comp, const _Allocator& __alloc)
192 : __keys_(std::make_obj_using_allocator<container_type>(__alloc)), __compare_(__comp) {}
193
194 template <class _Allocator>
195 requires uses_allocator<container_type, _Allocator>::value
196 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_set(const container_type& __keys, const _Allocator& __alloc)
197 : __keys_(std::make_obj_using_allocator<container_type>(__alloc, __keys)), __compare_() {
198 __sort_and_unique();
199 }
200
201 template <class _Allocator>
202 requires uses_allocator<container_type, _Allocator>::value
203 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
204 flat_set(const container_type& __keys, const key_compare& __comp, const _Allocator& __alloc)
205 : __keys_(std::make_obj_using_allocator<container_type>(__alloc, __keys)), __compare_(__comp) {
206 __sort_and_unique();
207 }
208
209 template <class _Allocator>
210 requires uses_allocator<container_type, _Allocator>::value
211 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
212 flat_set(sorted_unique_t, const container_type& __keys, const _Allocator& __alloc)
213 : __keys_(std::make_obj_using_allocator<container_type>(__alloc, __keys)), __compare_() {
214 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
215 __is_sorted_and_unique(__keys_), "Either the key container is not sorted or it contains duplicates");
216 }
217
218 template <class _Allocator>
219 requires uses_allocator<container_type, _Allocator>::value
220 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
221 flat_set(sorted_unique_t, const container_type& __keys, const key_compare& __comp, const _Allocator& __alloc)
222 : __keys_(std::make_obj_using_allocator<container_type>(__alloc, __keys)), __compare_(__comp) {
223 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
224 __is_sorted_and_unique(__keys_), "Either the key container is not sorted or it contains duplicates");
225 }
226
227 template <class _Allocator>
228 requires uses_allocator<container_type, _Allocator>::value
229 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_set(const flat_set& __other, const _Allocator& __alloc)
230 : __keys_(std::make_obj_using_allocator<container_type>(__alloc, __other.__keys_)),
231 __compare_(__other.__compare_) {}
232
233 template <class _Allocator>
234 requires uses_allocator<container_type, _Allocator>::value
235 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_set(flat_set&& __other, const _Allocator& __alloc)
236# if _LIBCPP_HAS_EXCEPTIONS
237 try
238# endif // _LIBCPP_HAS_EXCEPTIONS
239 : __keys_(std::make_obj_using_allocator<container_type>(__alloc, std::move(__other.__keys_))),
240 __compare_(std::move(__other.__compare_)) {
241 __other.clear();
242# if _LIBCPP_HAS_EXCEPTIONS
243 } catch (...) {
244 __other.clear();
245 throw;
246# endif // _LIBCPP_HAS_EXCEPTIONS
247 }
248
249 template <class _InputIterator, class _Allocator>
250 requires(__has_input_iterator_category<_InputIterator>::value && uses_allocator<container_type, _Allocator>::value)
251 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
252 flat_set(_InputIterator __first, _InputIterator __last, const _Allocator& __alloc)
253 : __keys_(std::make_obj_using_allocator<container_type>(__alloc)), __compare_() {
254 insert(__first, __last);
255 }
256
257 template <class _InputIterator, class _Allocator>
258 requires(__has_input_iterator_category<_InputIterator>::value && uses_allocator<container_type, _Allocator>::value)
259 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
260 flat_set(_InputIterator __first, _InputIterator __last, const key_compare& __comp, const _Allocator& __alloc)
261 : __keys_(std::make_obj_using_allocator<container_type>(__alloc)), __compare_(__comp) {
262 insert(__first, __last);
263 }
264
265 template <class _InputIterator, class _Allocator>
266 requires(__has_input_iterator_category<_InputIterator>::value && uses_allocator<container_type, _Allocator>::value)
267 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
268 flat_set(sorted_unique_t, _InputIterator __first, _InputIterator __last, const _Allocator& __alloc)
269 : __keys_(std::make_obj_using_allocator<container_type>(__alloc, __first, __last)), __compare_() {
270 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
271 __is_sorted_and_unique(__keys_), "Either the key container is not sorted or it contains duplicates");
272 }
273
274 template <class _InputIterator, class _Allocator>
275 requires(__has_input_iterator_category<_InputIterator>::value && uses_allocator<container_type, _Allocator>::value)
276 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_set(
277 sorted_unique_t,
278 _InputIterator __first,
279 _InputIterator __last,
280 const key_compare& __comp,
281 const _Allocator& __alloc)
282 : __keys_(std::make_obj_using_allocator<container_type>(__alloc, __first, __last)), __compare_(__comp) {
283 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
284 __is_sorted_and_unique(__keys_), "Either the key container is not sorted or it contains duplicates");
285 }
286
287 template <_ContainerCompatibleRange<value_type> _Range, class _Allocator>
288 requires uses_allocator<container_type, _Allocator>::value
289 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_set(from_range_t, _Range&& __rg, const _Allocator& __alloc)
290 : __keys_(std::make_obj_using_allocator<container_type>(__alloc)), __compare_() {
291 insert_range(std::forward<_Range>(__rg));
292 }
293
294 template <_ContainerCompatibleRange<value_type> _Range, class _Allocator>
295 requires uses_allocator<container_type, _Allocator>::value
296 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
297 flat_set(from_range_t, _Range&& __rg, const key_compare& __comp, const _Allocator& __alloc)
298 : __keys_(std::make_obj_using_allocator<container_type>(__alloc)), __compare_(__comp) {
299 insert_range(std::forward<_Range>(__rg));
300 }
301
302 template <class _Allocator>
303 requires uses_allocator<container_type, _Allocator>::value
304 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
305 flat_set(initializer_list<value_type> __il, const _Allocator& __alloc)
306 : flat_set(__il.begin(), __il.end(), __alloc) {}
307
308 template <class _Allocator>
309 requires uses_allocator<container_type, _Allocator>::value
310 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
311 flat_set(initializer_list<value_type> __il, const key_compare& __comp, const _Allocator& __alloc)
312 : flat_set(__il.begin(), __il.end(), __comp, __alloc) {}
313
314 template <class _Allocator>
315 requires uses_allocator<container_type, _Allocator>::value
316 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
317 flat_set(sorted_unique_t, initializer_list<value_type> __il, const _Allocator& __alloc)
318 : flat_set(sorted_unique, __il.begin(), __il.end(), __alloc) {}
319
320 template <class _Allocator>
321 requires uses_allocator<container_type, _Allocator>::value
322 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
323 flat_set(sorted_unique_t, initializer_list<value_type> __il, const key_compare& __comp, const _Allocator& __alloc)
324 : flat_set(sorted_unique, __il.begin(), __il.end(), __comp, __alloc) {}
325
326 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_set& operator=(initializer_list<value_type> __il) {
327 clear();
328 insert(__il);
329 return *this;
330 }
331
332 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_set& operator=(const flat_set&) = default;
333
334 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_set& operator=(flat_set&& __other) noexcept(
335 is_nothrow_move_assignable_v<_KeyContainer> && is_nothrow_move_assignable_v<_Compare>) {
336 // No matter what happens, we always want to clear the other container before returning
337 // since we moved from it
338 auto __clear_other_guard = std::__make_scope_guard([&]() noexcept { __other.clear() /* noexcept */; });
339 {
340 // If an exception is thrown, we have no choice but to clear *this to preserve invariants
341 auto __on_exception = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
342 __keys_ = std::move(__other.__keys_);
343 __compare_ = std::move(__other.__compare_);
344 __on_exception.__complete();
345 }
346 return *this;
347 }
348
349 // iterators
350 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator begin() noexcept {
351 return iterator(std::as_const(__keys_).begin());
352 }
353 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator begin() const noexcept {
354 return const_iterator(__keys_.begin());
355 }
356 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator end() noexcept {
357 return iterator(std::as_const(__keys_).end());
358 }
359 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator end() const noexcept {
360 return const_iterator(__keys_.end());
361 }
362
363 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reverse_iterator rbegin() noexcept {
364 return reverse_iterator(end());
365 }
366 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reverse_iterator rbegin() const noexcept {
367 return const_reverse_iterator(end());
368 }
369 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reverse_iterator rend() noexcept {
370 return reverse_iterator(begin());
371 }
372 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reverse_iterator rend() const noexcept {
373 return const_reverse_iterator(begin());
374 }
375
376 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator cbegin() const noexcept { return begin(); }
377 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator cend() const noexcept { return end(); }
378 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reverse_iterator crbegin() const noexcept {
379 return const_reverse_iterator(end());
380 }
381 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reverse_iterator crend() const noexcept {
382 return const_reverse_iterator(begin());
383 }
384
385 // [flat.set.capacity], capacity
386 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool empty() const noexcept {
387 return __keys_.empty();
388 }
389
390 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type size() const noexcept { return __keys_.size(); }
391
392 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type max_size() const noexcept { return __keys_.max_size(); }
393
394 // [flat.set.modifiers], modifiers
395 template <class... _Args>
396 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> emplace(_Args&&... __args) {
397 if constexpr (sizeof...(__args) == 1 && (is_same_v<remove_cvref_t<_Args>, _Key> && ...)) {
398 return __emplace(std::forward<_Args>(__args)...);
399 } else {
400 return __emplace(_Key(std::forward<_Args>(__args)...));
401 }
402 }
403
404 template <class... _Args>
405 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator emplace_hint(const_iterator __hint, _Args&&... __args) {
406 if constexpr (sizeof...(__args) == 1 && (is_same_v<remove_cvref_t<_Args>, _Key> && ...)) {
407 return __emplace_hint(std::move(__hint), std::forward<_Args>(__args)...);
408 } else {
409 return __emplace_hint(std::move(__hint), _Key(std::forward<_Args>(__args)...));
410 }
411 }
412
413 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> insert(const value_type& __x) {
414 return emplace(__x);
415 }
416
417 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> insert(value_type&& __x) {
418 return emplace(std::move(__x));
419 }
420
421 template <class _Kp>
422 requires(__is_transparent_v<_Compare> && is_constructible_v<value_type, _Kp>)
423 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> insert(_Kp&& __x) {
424 return __emplace(std::forward<_Kp>(__x));
425 }
426 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const_iterator __hint, const value_type& __x) {
427 return emplace_hint(__hint, __x);
428 }
429
430 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const_iterator __hint, value_type&& __x) {
431 return emplace_hint(__hint, std::move(__x));
432 }
433
434 template <class _Kp>
435 requires(__is_transparent_v<_Compare> && is_constructible_v<value_type, _Kp>)
436 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const_iterator __hint, _Kp&& __x) {
437 return __emplace_hint(__hint, std::forward<_Kp>(__x));
438 }
439
440 template <class _InputIterator>
441 requires __has_input_iterator_category<_InputIterator>::value
442 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert(_InputIterator __first, _InputIterator __last) {
443 if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>) {
444 __reserve(__last - __first);
445 }
446 __append_sort_merge_unique</*WasSorted = */ false>(std::move(__first), std::move(__last));
447 }
448
449 template <class _InputIterator>
450 requires __has_input_iterator_category<_InputIterator>::value
451 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
452 insert(sorted_unique_t, _InputIterator __first, _InputIterator __last) {
453 if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>) {
454 __reserve(__last - __first);
455 }
456
457 __append_sort_merge_unique</*WasSorted = */ true>(std::move(__first), std::move(__last));
458 }
459
460 template <_ContainerCompatibleRange<value_type> _Range>
461 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert_range(_Range&& __range) {
462 if constexpr (ranges::sized_range<_Range>) {
463 __reserve(ranges::size(__range));
464 }
465
466 __append_sort_merge_unique</*WasSorted = */ false>(std::forward<_Range>(__range));
467 }
468
469 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert(initializer_list<value_type> __il) {
470 insert(__il.begin(), __il.end());
471 }
472
473 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert(sorted_unique_t, initializer_list<value_type> __il) {
474 insert(sorted_unique, __il.begin(), __il.end());
475 }
476
477 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 container_type extract() && {
478 auto __guard = std::__make_scope_guard([&]() noexcept { clear() /* noexcept */; });
479 auto __ret = std::move(__keys_);
480 return __ret;
481 }
482
483 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void replace(container_type&& __keys) {
484 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
485 __is_sorted_and_unique(__keys), "Either the key container is not sorted or it contains duplicates");
486 auto __guard = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
487 __keys_ = std::move(__keys);
488 __guard.__complete();
489 }
490
491 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator erase(iterator __position) {
492 auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
493 auto __key_iter = __keys_.erase(__position.__base());
494 __on_failure.__complete();
495 return iterator(__key_iter);
496 }
497
498 // The following overload is the same as the iterator overload
499 // iterator erase(const_iterator __position);
500
501 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type erase(const key_type& __x) {
502 auto __iter = find(__x);
503 if (__iter != end()) {
504 erase(__iter);
505 return 1;
506 }
507 return 0;
508 }
509
510 template <class _Kp>
511 requires(__is_transparent_v<_Compare> && !is_convertible_v<_Kp &&, iterator> &&
512 !is_convertible_v<_Kp &&, const_iterator>)
513 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type erase(_Kp&& __x) {
514 auto [__first, __last] = equal_range(__x);
515 auto __res = __last - __first;
516 erase(__first, __last);
517 return __res;
518 }
519
520 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator erase(const_iterator __first, const_iterator __last) {
521 auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
522 auto __key_it = __keys_.erase(__first.__base(), __last.__base());
523 __on_failure.__complete();
524 return iterator(std::move(__key_it));
525 }
526
527 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void swap(flat_set& __y) noexcept {
528 // warning: The spec has unconditional noexcept, which means that
529 // if any of the following functions throw an exception,
530 // std::terminate will be called.
531 // This is discussed in P2767, which hasn't been voted on yet.
532 ranges::swap(__compare_, __y.__compare_);
533 ranges::swap(__keys_, __y.__keys_);
534 }
535
536 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void clear() noexcept { __keys_.clear(); }
537
538 // observers
539 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 key_compare key_comp() const { return __compare_; }
540 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 value_compare value_comp() const { return __compare_; }
541
542 // set operations
543 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator find(const key_type& __x) {
544 return __find_impl(*this, __x);
545 }
546
547 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator find(const key_type& __x) const {
548 return __find_impl(*this, __x);
549 }
550
551 template <class _Kp>
552 requires __is_transparent_v<_Compare>
553 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator find(const _Kp& __x) {
554 return __find_impl(*this, __x);
555 }
556
557 template <class _Kp>
558 requires __is_transparent_v<_Compare>
559 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator find(const _Kp& __x) const {
560 return __find_impl(*this, __x);
561 }
562
563 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type count(const key_type& __x) const {
564 return contains(__x) ? 1 : 0;
565 }
566
567 template <class _Kp>
568 requires __is_transparent_v<_Compare>
569 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type count(const _Kp& __x) const {
570 return contains(__x) ? 1 : 0;
571 }
572
573 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool contains(const key_type& __x) const {
574 return find(__x) != end();
575 }
576
577 template <class _Kp>
578 requires __is_transparent_v<_Compare>
579 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool contains(const _Kp& __x) const {
580 return find(__x) != end();
581 }
582
583 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator lower_bound(const key_type& __x) {
584 const auto& __keys = __keys_;
585 return iterator(std::lower_bound(__keys.begin(), __keys.end(), __x, __compare_));
586 }
587
588 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator lower_bound(const key_type& __x) const {
589 return const_iterator(std::lower_bound(__keys_.begin(), __keys_.end(), __x, __compare_));
590 }
591
592 template <class _Kp>
593 requires __is_transparent_v<_Compare>
594 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator lower_bound(const _Kp& __x) {
595 const auto& __keys = __keys_;
596 return iterator(std::lower_bound(__keys.begin(), __keys.end(), __x, __compare_));
597 }
598
599 template <class _Kp>
600 requires __is_transparent_v<_Compare>
601 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator lower_bound(const _Kp& __x) const {
602 return const_iterator(std::lower_bound(__keys_.begin(), __keys_.end(), __x, __compare_));
603 }
604
605 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator upper_bound(const key_type& __x) {
606 const auto& __keys = __keys_;
607 return iterator(std::upper_bound(__keys.begin(), __keys.end(), __x, __compare_));
608 }
609
610 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator upper_bound(const key_type& __x) const {
611 return const_iterator(std::upper_bound(__keys_.begin(), __keys_.end(), __x, __compare_));
612 }
613
614 template <class _Kp>
615 requires __is_transparent_v<_Compare>
616 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator upper_bound(const _Kp& __x) {
617 const auto& __keys = __keys_;
618 return iterator(std::upper_bound(__keys.begin(), __keys.end(), __x, __compare_));
619 }
620
621 template <class _Kp>
622 requires __is_transparent_v<_Compare>
623 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator upper_bound(const _Kp& __x) const {
624 return const_iterator(std::upper_bound(__keys_.begin(), __keys_.end(), __x, __compare_));
625 }
626
627 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, iterator> equal_range(const key_type& __x) {
628 return __equal_range_impl(*this, __x);
629 }
630
631 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<const_iterator, const_iterator>
632 equal_range(const key_type& __x) const {
633 return __equal_range_impl(*this, __x);
634 }
635
636 template <class _Kp>
637 requires __is_transparent_v<_Compare>
638 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, iterator> equal_range(const _Kp& __x) {
639 return __equal_range_impl(*this, __x);
640 }
641 template <class _Kp>
642 requires __is_transparent_v<_Compare>
643 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<const_iterator, const_iterator>
644 equal_range(const _Kp& __x) const {
645 return __equal_range_impl(*this, __x);
646 }
647
648 friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator==(const flat_set& __x, const flat_set& __y) {
649 return ranges::equal(__x, __y);
650 }
651
652 friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 auto
653 operator<=>(const flat_set& __x, const flat_set& __y) {
654 return std::lexicographical_compare_three_way(
655 __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
656 }
657
658 friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void swap(flat_set& __x, flat_set& __y) noexcept {
659 __x.swap(__y);
660 }
661
662private:
663 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool __is_sorted_and_unique(auto&& __key_container) const {
664 auto __greater_or_equal_to = [this](const auto& __x, const auto& __y) { return !__compare_(__x, __y); };
665 return ranges::adjacent_find(__key_container, __greater_or_equal_to) == ranges::end(__key_container);
666 }
667
668 // This function is only used in constructors. So there is not exception handling in this function.
669 // If the function exits via an exception, there will be no flat_set object constructed, thus, there
670 // is no invariant state to preserve
671 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __sort_and_unique() {
672 ranges::sort(__keys_, __compare_);
673 auto __dup_start = ranges::unique(__keys_, __key_equiv(__compare_)).begin();
674 __keys_.erase(__dup_start, __keys_.end());
675 }
676
677 template <bool _WasSorted, class... _Args>
678 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __append_sort_merge_unique(_Args&&... __args) {
679 auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
680 size_type __old_size = size();
681 __flat_set_utils::__append(*this, std::forward<_Args>(__args)...);
682 if (size() != __old_size) {
683 if constexpr (!_WasSorted) {
684 ranges::sort(__keys_.begin() + __old_size, __keys_.end(), __compare_);
685 } else {
686 _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__is_sorted_and_unique(__keys_ | ranges::views::drop(__old_size)),
687 "Either the key container is not sorted or it contains duplicates");
688 }
689 ranges::inplace_merge(__keys_.begin(), __keys_.begin() + __old_size, __keys_.end(), __compare_);
690
691 auto __dup_start = ranges::unique(__keys_, __key_equiv(__compare_)).begin();
692 __keys_.erase(__dup_start, __keys_.end());
693 }
694 __on_failure.__complete();
695 }
696
697 template <class _Self, class _Kp>
698 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static auto __find_impl(_Self&& __self, const _Kp& __key) {
699 auto __it = __self.lower_bound(__key);
700 auto __last = __self.end();
701 if (__it == __last || __self.__compare_(__key, *__it)) {
702 return __last;
703 }
704 return __it;
705 }
706
707 template <class _Self, class _Kp>
708 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static auto __equal_range_impl(_Self&& __self, const _Kp& __key) {
709 using __iter = _If<is_const_v<__libcpp_remove_reference_t<_Self>>, const_iterator, iterator>;
710 auto __it = std::lower_bound(__self.__keys_.begin(), __self.__keys_.end(), __key, __self.__compare_);
711 auto __last = __self.__keys_.end();
712 if (__it == __last || __self.__compare_(__key, *__it)) {
713 return std::make_pair(__iter(__it), __iter(__it));
714 }
715 return std::make_pair(__iter(__it), __iter(std::next(__it)));
716 }
717
718 template <class _Kp>
719 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> __emplace(_Kp&& __key) {
720 auto __it = lower_bound(__key);
721 if (__it == end() || __compare_(__key, *__it)) {
722 return pair<iterator, bool>(__flat_set_utils::__emplace_exact_pos(*this, __it, std::forward<_Kp>(__key)), true);
723 } else {
724 return pair<iterator, bool>(std::move(__it), false);
725 }
726 }
727
728 template <class _Kp>
729 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool __is_hint_correct(const_iterator __hint, _Kp&& __key) {
730 if (__hint != cbegin() && !__compare_(*std::prev(__hint), __key)) {
731 return false;
732 }
733 if (__hint != cend() && __compare_(*__hint, __key)) {
734 return false;
735 }
736 return true;
737 }
738
739 template <class _Kp>
740 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator __emplace_hint(const_iterator __hint, _Kp&& __key) {
741 if (__is_hint_correct(__hint, __key)) {
742 if (__hint == cend() || __compare_(__key, *__hint)) {
743 return __flat_set_utils::__emplace_exact_pos(*this, __hint, std::forward<_Kp>(__key));
744 } else {
745 // we already have an equal key
746 return __hint;
747 }
748 } else {
749 return __emplace(std::forward<_Kp>(__key)).first;
750 }
751 }
752
753 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __reserve(size_t __size) {
754 if constexpr (__container_traits<_KeyContainer>::__reservable) {
755 __keys_.reserve(__size);
756 }
757 }
758
759 template <class _Key2, class _Compare2, class _KeyContainer2, class _Predicate>
760 friend typename flat_set<_Key2, _Compare2, _KeyContainer2>::size_type _LIBCPP_CONSTEXPR_SINCE_CXX26
761 erase_if(flat_set<_Key2, _Compare2, _KeyContainer2>&, _Predicate);
762
763 _KeyContainer __keys_;
764 _LIBCPP_NO_UNIQUE_ADDRESS key_compare __compare_;
765
766 struct __key_equiv {
767 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __key_equiv(key_compare __c) : __comp_(__c) {}
768 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool
769 operator()(const_reference __x, const_reference __y) const {
770 return !__comp_(__x, __y) && !__comp_(__y, __x);
771 }
772 key_compare __comp_;
773 };
774};
775
776template <class _KeyContainer, class _Compare = less<typename _KeyContainer::value_type>>
777 requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value &&
778 is_invocable_v<const _Compare&,
779 const typename _KeyContainer::value_type&,
780 const typename _KeyContainer::value_type&>)
781flat_set(_KeyContainer, _Compare = _Compare()) -> flat_set<typename _KeyContainer::value_type, _Compare, _KeyContainer>;
782
783template <class _KeyContainer, class _Allocator>
784 requires(uses_allocator_v<_KeyContainer, _Allocator> && !__is_allocator<_KeyContainer>::value)
785flat_set(_KeyContainer, _Allocator)
786 -> flat_set<typename _KeyContainer::value_type, less<typename _KeyContainer::value_type>, _KeyContainer>;
787
788template <class _KeyContainer, class _Compare, class _Allocator>
789 requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value &&
790 uses_allocator_v<_KeyContainer, _Allocator> &&
791 is_invocable_v<const _Compare&,
792 const typename _KeyContainer::value_type&,
793 const typename _KeyContainer::value_type&>)
794flat_set(_KeyContainer, _Compare, _Allocator) -> flat_set<typename _KeyContainer::value_type, _Compare, _KeyContainer>;
795
796template <class _KeyContainer, class _Compare = less<typename _KeyContainer::value_type>>
797 requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value &&
798 is_invocable_v<const _Compare&,
799 const typename _KeyContainer::value_type&,
800 const typename _KeyContainer::value_type&>)
801flat_set(sorted_unique_t, _KeyContainer, _Compare = _Compare())
802 -> flat_set<typename _KeyContainer::value_type, _Compare, _KeyContainer>;
803
804template <class _KeyContainer, class _Allocator>
805 requires(uses_allocator_v<_KeyContainer, _Allocator> && !__is_allocator<_KeyContainer>::value)
806flat_set(sorted_unique_t, _KeyContainer, _Allocator)
807 -> flat_set<typename _KeyContainer::value_type, less<typename _KeyContainer::value_type>, _KeyContainer>;
808
809template <class _KeyContainer, class _Compare, class _Allocator>
810 requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value &&
811 uses_allocator_v<_KeyContainer, _Allocator> &&
812 is_invocable_v<const _Compare&,
813 const typename _KeyContainer::value_type&,
814 const typename _KeyContainer::value_type&>)
815flat_set(sorted_unique_t, _KeyContainer, _Compare, _Allocator)
816 -> flat_set<typename _KeyContainer::value_type, _Compare, _KeyContainer>;
817
818template <class _InputIterator, class _Compare = less<__iter_value_type<_InputIterator>>>
819 requires(__has_input_iterator_category<_InputIterator>::value && !__is_allocator<_Compare>::value)
820flat_set(_InputIterator, _InputIterator, _Compare = _Compare())
821 -> flat_set<__iter_value_type<_InputIterator>, _Compare>;
822
823template <class _InputIterator, class _Compare = less<__iter_value_type<_InputIterator>>>
824 requires(__has_input_iterator_category<_InputIterator>::value && !__is_allocator<_Compare>::value)
825flat_set(sorted_unique_t, _InputIterator, _InputIterator, _Compare = _Compare())
826 -> flat_set<__iter_value_type<_InputIterator>, _Compare>;
827
828template <ranges::input_range _Range,
829 class _Compare = less<ranges::range_value_t<_Range>>,
830 class _Allocator = allocator<ranges::range_value_t<_Range>>,
831 class = __enable_if_t<!__is_allocator<_Compare>::value && __is_allocator<_Allocator>::value>>
832flat_set(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator()) -> flat_set<
833 ranges::range_value_t<_Range>,
834 _Compare,
835 vector<ranges::range_value_t<_Range>, __allocator_traits_rebind_t<_Allocator, ranges::range_value_t<_Range>>>>;
836
837template <ranges::input_range _Range, class _Allocator, class = __enable_if_t<__is_allocator<_Allocator>::value>>
838flat_set(from_range_t, _Range&&, _Allocator) -> flat_set<
839 ranges::range_value_t<_Range>,
840 less<ranges::range_value_t<_Range>>,
841 vector<ranges::range_value_t<_Range>, __allocator_traits_rebind_t<_Allocator, ranges::range_value_t<_Range>>>>;
842
843template <class _Key, class _Compare = less<_Key>>
844 requires(!__is_allocator<_Compare>::value)
845flat_set(initializer_list<_Key>, _Compare = _Compare()) -> flat_set<_Key, _Compare>;
846
847template <class _Key, class _Compare = less<_Key>>
848 requires(!__is_allocator<_Compare>::value)
849flat_set(sorted_unique_t, initializer_list<_Key>, _Compare = _Compare()) -> flat_set<_Key, _Compare>;
850
851template <class _Key, class _Compare, class _KeyContainer, class _Allocator>
852struct uses_allocator<flat_set<_Key, _Compare, _KeyContainer>, _Allocator>
853 : bool_constant<uses_allocator_v<_KeyContainer, _Allocator>> {};
854
855template <class _Key, class _Compare, class _KeyContainer, class _Predicate>
856_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 typename flat_set<_Key, _Compare, _KeyContainer>::size_type
857erase_if(flat_set<_Key, _Compare, _KeyContainer>& __flat_set, _Predicate __pred) {
858 auto __guard = std::__make_exception_guard([&] { __flat_set.clear(); });
859 auto __it = std::remove_if(__flat_set.__keys_.begin(), __flat_set.__keys_.end(), [&](const auto& __e) -> bool {
860 return static_cast<bool>(__pred(__e));
861 });
862 auto __res = __flat_set.__keys_.end() - __it;
863 __flat_set.__keys_.erase(__it, __flat_set.__keys_.end());
864 __guard.__complete();
865 return __res;
866}
867
868_LIBCPP_END_NAMESPACE_STD
869
870#endif // _LIBCPP_STD_VER >= 23
871
872_LIBCPP_POP_MACROS
873
874#endif // _LIBCPP___FLAT_SET_FLAT_SET_H
lib/libcxx/include/__flat_set/ra_iterator.h created+157
......@@ -0,0 +1,157 @@
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_SET_RA_ITERATOR_H
11#define _LIBCPP___FLAT_SET_RA_ITERATOR_H
12
13#include "__type_traits/is_same.h"
14#include <__compare/three_way_comparable.h>
15#include <__config>
16#include <__iterator/incrementable_traits.h>
17#include <__iterator/iterator_traits.h>
18#include <__type_traits/is_constructible.h>
19#include <__utility/move.h>
20
21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22# pragma GCC system_header
23#endif
24
25_LIBCPP_PUSH_MACROS
26#include <__undef_macros>
27
28#if _LIBCPP_STD_VER >= 23
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32/**
33 * __ra_iterator is a random access iterator that wraps an underlying iterator.
34 * It also stores the underlying container type in its type so that algorithms
35 * can optimize based on the underlying container type, and to avoid inadvertently
36 * mixing iterators coming from different containers..
37 */
38template <class _Container, class _Iterator>
39struct __ra_iterator {
40private:
41 _Iterator __iter_;
42
43 friend _Container;
44
45 // note: checking the concept random_access_iterator does not work for incomplete types
46 static_assert(_IsSame<typename iterator_traits<_Iterator>::iterator_category, random_access_iterator_tag>::value,
47 "Underlying iterator must be a random access iterator");
48
49public:
50 using iterator_concept = random_access_iterator_tag; // deliberately lower contiguous_iterator
51 using iterator_category = random_access_iterator_tag;
52 using value_type = iter_value_t<_Iterator>;
53 using difference_type = iter_difference_t<_Iterator>;
54
55 _LIBCPP_HIDE_FROM_ABI __ra_iterator()
56 requires is_default_constructible_v<_Iterator>
57 = default;
58
59 _LIBCPP_HIDE_FROM_ABI explicit constexpr __ra_iterator(_Iterator __iter) : __iter_(std::move(__iter)) {}
60
61 _LIBCPP_HIDE_FROM_ABI constexpr _Iterator __base() const noexcept(noexcept(_Iterator(__iter_))) { return __iter_; }
62
63 _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const { return *__iter_; }
64 _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator->() const
65 requires requires { __iter_.operator->(); }
66 {
67 return __iter_.operator->();
68 }
69
70 _LIBCPP_HIDE_FROM_ABI constexpr __ra_iterator& operator++() {
71 ++__iter_;
72 return *this;
73 }
74
75 _LIBCPP_HIDE_FROM_ABI constexpr __ra_iterator operator++(int) {
76 __ra_iterator __tmp(*this);
77 ++*this;
78 return __tmp;
79 }
80
81 _LIBCPP_HIDE_FROM_ABI constexpr __ra_iterator& operator--() {
82 --__iter_;
83 return *this;
84 }
85
86 _LIBCPP_HIDE_FROM_ABI constexpr __ra_iterator operator--(int) {
87 __ra_iterator __tmp(*this);
88 --*this;
89 return __tmp;
90 }
91
92 _LIBCPP_HIDE_FROM_ABI constexpr __ra_iterator& operator+=(difference_type __x) {
93 __iter_ += __x;
94 return *this;
95 }
96
97 _LIBCPP_HIDE_FROM_ABI constexpr __ra_iterator& operator-=(difference_type __x) {
98 __iter_ -= __x;
99 return *this;
100 }
101
102 _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](difference_type __n) const { return *(*this + __n); }
103
104 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __ra_iterator& __x, const __ra_iterator& __y) {
105 return __x.__iter_ == __y.__iter_;
106 }
107
108 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(const __ra_iterator& __x, const __ra_iterator& __y) {
109 return __x.__iter_ < __y.__iter_;
110 }
111
112 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(const __ra_iterator& __x, const __ra_iterator& __y) {
113 return __y < __x;
114 }
115
116 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(const __ra_iterator& __x, const __ra_iterator& __y) {
117 return !(__y < __x);
118 }
119
120 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(const __ra_iterator& __x, const __ra_iterator& __y) {
121 return !(__x < __y);
122 }
123
124 _LIBCPP_HIDE_FROM_ABI friend constexpr auto operator<=>(const __ra_iterator& __x, const __ra_iterator& __y)
125 requires three_way_comparable<_Iterator>
126 {
127 return __x.__iter_ <=> __y.__iter_;
128 }
129
130 _LIBCPP_HIDE_FROM_ABI friend constexpr __ra_iterator operator+(const __ra_iterator& __i, difference_type __n) {
131 auto __tmp = __i;
132 __tmp += __n;
133 return __tmp;
134 }
135
136 _LIBCPP_HIDE_FROM_ABI friend constexpr __ra_iterator operator+(difference_type __n, const __ra_iterator& __i) {
137 return __i + __n;
138 }
139
140 _LIBCPP_HIDE_FROM_ABI friend constexpr __ra_iterator operator-(const __ra_iterator& __i, difference_type __n) {
141 auto __tmp = __i;
142 __tmp -= __n;
143 return __tmp;
144 }
145
146 _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type operator-(const __ra_iterator& __x, const __ra_iterator& __y) {
147 return __x.__iter_ - __y.__iter_;
148 }
149};
150
151_LIBCPP_END_NAMESPACE_STD
152
153#endif // _LIBCPP_STD_VER >= 23
154
155_LIBCPP_POP_MACROS
156
157#endif // _LIBCPP___FLAT_SET_RA_ITERATOR_H
lib/libcxx/include/__flat_set/utils.h created+82
......@@ -0,0 +1,82 @@
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_SET_UTILS_H
11#define _LIBCPP___FLAT_SET_UTILS_H
12
13#include <__config>
14#include <__iterator/iterator_traits.h>
15#include <__ranges/access.h>
16#include <__ranges/concepts.h>
17#include <__type_traits/container_traits.h>
18#include <__type_traits/decay.h>
19#include <__utility/exception_guard.h>
20#include <__utility/forward.h>
21#include <__utility/move.h>
22
23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24# pragma GCC system_header
25#endif
26
27_LIBCPP_PUSH_MACROS
28#include <__undef_macros>
29
30#if _LIBCPP_STD_VER >= 23
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33
34// These utilities are defined in a class instead of a namespace so that this class can be befriended more easily.
35struct __flat_set_utils {
36 // Emplace a key into a flat_{multi}set, at the exact position that
37 // __it point to, assuming that the key is not already present in the set.
38 // When an exception is thrown during the emplacement, the function will clear the set if the container does not
39 // have strong exception safety guarantee on emplacement.
40 template <class _Set, class _Iter, class _KeyArg>
41 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static auto
42 __emplace_exact_pos(_Set& __set, _Iter&& __iter, _KeyArg&& __key) {
43 using _KeyContainer = typename decay_t<_Set>::container_type;
44 auto __on_failure = std::__make_exception_guard([&]() noexcept {
45 if constexpr (!__container_traits<_KeyContainer>::__emplacement_has_strong_exception_safety_guarantee) {
46 __set.clear() /* noexcept */;
47 }
48 });
49 auto __key_it = __set.__keys_.emplace(__iter.__base(), std::forward<_KeyArg>(__key));
50 __on_failure.__complete();
51 return typename decay_t<_Set>::iterator(std::move(__key_it));
52 }
53
54 template <class _Set, class _InputIterator>
55 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static void
56 __append(_Set& __set, _InputIterator __first, _InputIterator __last) {
57 __set.__keys_.insert(__set.__keys_.end(), std::move(__first), std::move(__last));
58 }
59
60 template <class _Set, class _Range>
61 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static void __append(_Set& __set, _Range&& __rng) {
62 if constexpr (requires { __set.__keys_.insert_range(__set.__keys_.end(), std::forward<_Range>(__rng)); }) {
63 // C++23 Sequence Container should have insert_range member function
64 // Note that not all Sequence Containers provide append_range.
65 __set.__keys_.insert_range(__set.__keys_.end(), std::forward<_Range>(__rng));
66 } else if constexpr (ranges::common_range<_Range> &&
67 __has_input_iterator_category<ranges::iterator_t<_Range>>::value) {
68 __set.__keys_.insert(__set.__keys_.end(), ranges::begin(__rng), ranges::end(__rng));
69 } else {
70 for (auto&& __x : __rng) {
71 __set.__keys_.insert(__set.__keys_.end(), std::forward<decltype(__x)>(__x));
72 }
73 }
74 }
75};
76_LIBCPP_END_NAMESPACE_STD
77
78#endif // _LIBCPP_STD_VER >= 23
79
80_LIBCPP_POP_MACROS
81
82#endif // #define _LIBCPP___FLAT_SET_UTILS_H
lib/libcxx/include/__format/buffer.h+14-15
......@@ -15,7 +15,6 @@
1515#include <__algorithm/max.h>
1616#include <__algorithm/min.h>
1717#include <__algorithm/ranges_copy.h>
18#include <__algorithm/ranges_copy_n.h>
1918#include <__algorithm/transform.h>
2019#include <__algorithm/unwrap_iter.h>
2120#include <__concepts/same_as.h>
......@@ -33,7 +32,7 @@
3332#include <__memory/allocator.h>
3433#include <__memory/allocator_traits.h>
3534#include <__memory/construct_at.h>
36#include <__memory/ranges_construct_at.h>
35#include <__memory/destroy.h>
3736#include <__memory/uninitialized_algorithms.h>
3837#include <__type_traits/add_pointer.h>
3938#include <__type_traits/conditional.h>
......@@ -180,7 +179,7 @@ private:
180179/// The latter option allows formatted_size to use the output buffer without
181180/// ever writing anything to the buffer.
182181template <__fmt_char_type _CharT>
183class _LIBCPP_TEMPLATE_VIS __output_buffer {
182class __output_buffer {
184183public:
185184 using value_type _LIBCPP_NODEBUG = _CharT;
186185 using __prepare_write_type _LIBCPP_NODEBUG = void (*)(__output_buffer<_CharT>&, size_t);
......@@ -340,18 +339,18 @@ concept __insertable =
340339
341340/// Extract the container type of a \ref back_insert_iterator.
342341template <class _It>
343struct _LIBCPP_TEMPLATE_VIS __back_insert_iterator_container {
342struct __back_insert_iterator_container {
344343 using type _LIBCPP_NODEBUG = void;
345344};
346345
347346template <__insertable _Container>
348struct _LIBCPP_TEMPLATE_VIS __back_insert_iterator_container<back_insert_iterator<_Container>> {
347struct __back_insert_iterator_container<back_insert_iterator<_Container>> {
349348 using type _LIBCPP_NODEBUG = _Container;
350349};
351350
352351// A dynamically growing buffer.
353352template <__fmt_char_type _CharT>
354class _LIBCPP_TEMPLATE_VIS __allocating_buffer : public __output_buffer<_CharT> {
353class __allocating_buffer : public __output_buffer<_CharT> {
355354public:
356355 __allocating_buffer(const __allocating_buffer&) = delete;
357356 __allocating_buffer& operator=(const __allocating_buffer&) = delete;
......@@ -408,7 +407,7 @@ private:
408407
409408// A buffer that directly writes to the underlying buffer.
410409template <class _OutIt, __fmt_char_type _CharT>
411class _LIBCPP_TEMPLATE_VIS __direct_iterator_buffer : public __output_buffer<_CharT> {
410class __direct_iterator_buffer : public __output_buffer<_CharT> {
412411public:
413412 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit __direct_iterator_buffer(_OutIt __out_it)
414413 : __direct_iterator_buffer{__out_it, nullptr} {}
......@@ -437,7 +436,7 @@ private:
437436
438437// A buffer that writes its output to the end of a container.
439438template <class _OutIt, __fmt_char_type _CharT>
440class _LIBCPP_TEMPLATE_VIS __container_inserter_buffer : public __output_buffer<_CharT> {
439class __container_inserter_buffer : public __output_buffer<_CharT> {
441440public:
442441 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit __container_inserter_buffer(_OutIt __out_it)
443442 : __container_inserter_buffer{__out_it, nullptr} {}
......@@ -478,7 +477,7 @@ private:
478477// Unlike the __container_inserter_buffer this class' performance does benefit
479478// from allocating and then inserting.
480479template <class _OutIt, __fmt_char_type _CharT>
481class _LIBCPP_TEMPLATE_VIS __iterator_buffer : public __allocating_buffer<_CharT> {
480class __iterator_buffer : public __allocating_buffer<_CharT> {
482481public:
483482 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit __iterator_buffer(_OutIt __out_it)
484483 : __allocating_buffer<_CharT>{}, __out_it_{std::move(__out_it)} {}
......@@ -496,7 +495,7 @@ private:
496495
497496// Selects the type of the buffer used for the output iterator.
498497template <class _OutIt, __fmt_char_type _CharT>
499class _LIBCPP_TEMPLATE_VIS __buffer_selector {
498class __buffer_selector {
500499 using _Container _LIBCPP_NODEBUG = __back_insert_iterator_container<_OutIt>::type;
501500
502501public:
......@@ -510,7 +509,7 @@ public:
510509
511510// A buffer that counts and limits the number of insertions.
512511template <class _OutIt, __fmt_char_type _CharT>
513class _LIBCPP_TEMPLATE_VIS __format_to_n_buffer : private __buffer_selector<_OutIt, _CharT>::type {
512class __format_to_n_buffer : private __buffer_selector<_OutIt, _CharT>::type {
514513public:
515514 using _Base _LIBCPP_NODEBUG = __buffer_selector<_OutIt, _CharT>::type;
516515
......@@ -534,7 +533,7 @@ private:
534533// Since formatted_size only needs to know the size, the output itself is
535534// discarded.
536535template <__fmt_char_type _CharT>
537class _LIBCPP_TEMPLATE_VIS __formatted_size_buffer : private __output_buffer<_CharT> {
536class __formatted_size_buffer : private __output_buffer<_CharT> {
538537public:
539538 using _Base _LIBCPP_NODEBUG = __output_buffer<_CharT>;
540539
......@@ -577,7 +576,7 @@ private:
577576// This class uses its own buffer management, since using vector
578577// would lead to a circular include with formatter for vector<bool>.
579578template <__fmt_char_type _CharT>
580class _LIBCPP_TEMPLATE_VIS __retarget_buffer {
579class __retarget_buffer {
581580 using _Alloc _LIBCPP_NODEBUG = allocator<_CharT>;
582581
583582public:
......@@ -621,7 +620,7 @@ public:
621620 }
622621
623622 _LIBCPP_HIDE_FROM_ABI ~__retarget_buffer() {
624 ranges::destroy_n(__ptr_, __size_);
623 std::destroy_n(__ptr_, __size_);
625624 allocator_traits<_Alloc>::deallocate(__alloc_, __ptr_, __capacity_);
626625 }
627626
......@@ -686,7 +685,7 @@ private:
686685 // guard is optimized away so there is no runtime overhead.
687686 std::uninitialized_move_n(__ptr_, __size_, __result.ptr);
688687 __guard.__complete();
689 ranges::destroy_n(__ptr_, __size_);
688 std::destroy_n(__ptr_, __size_);
690689 allocator_traits<_Alloc>::deallocate(__alloc_, __ptr_, __capacity_);
691690
692691 __ptr_ = __result.ptr;
lib/libcxx/include/__format/container_adaptor.h+4-4
......@@ -35,7 +35,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3535// adaptor headers. To use the format functions users already include <format>.
3636
3737template <class _Adaptor, class _CharT>
38struct _LIBCPP_TEMPLATE_VIS __formatter_container_adaptor {
38struct __formatter_container_adaptor {
3939private:
4040 using __maybe_const_container _LIBCPP_NODEBUG = __fmt_maybe_const<typename _Adaptor::container_type, _CharT>;
4141 using __maybe_const_adaptor _LIBCPP_NODEBUG = __maybe_const<is_const_v<__maybe_const_container>, _Adaptor>;
......@@ -55,15 +55,15 @@ public:
5555};
5656
5757template <class _CharT, class _Tp, formattable<_CharT> _Container>
58struct _LIBCPP_TEMPLATE_VIS formatter<queue<_Tp, _Container>, _CharT>
58struct formatter<queue<_Tp, _Container>, _CharT>
5959 : public __formatter_container_adaptor<queue<_Tp, _Container>, _CharT> {};
6060
6161template <class _CharT, class _Tp, class _Container, class _Compare>
62struct _LIBCPP_TEMPLATE_VIS formatter<priority_queue<_Tp, _Container, _Compare>, _CharT>
62struct formatter<priority_queue<_Tp, _Container, _Compare>, _CharT>
6363 : public __formatter_container_adaptor<priority_queue<_Tp, _Container, _Compare>, _CharT> {};
6464
6565template <class _CharT, class _Tp, formattable<_CharT> _Container>
66struct _LIBCPP_TEMPLATE_VIS formatter<stack<_Tp, _Container>, _CharT>
66struct formatter<stack<_Tp, _Container>, _CharT>
6767 : public __formatter_container_adaptor<stack<_Tp, _Container>, _CharT> {};
6868
6969#endif // _LIBCPP_STD_VER >= 23
lib/libcxx/include/__format/escaped_output_table.h+53-29
......@@ -109,7 +109,7 @@ namespace __escaped_output_table {
109109/// - bits [14, 31] The lower bound code point of the range. The upper bound of
110110/// the range is lower bound + size. Note the code expects code units the fit
111111/// into 18 bits, instead of the 21 bits needed for the full Unicode range.
112_LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
112_LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[735] = {
113113 0x00000020 /* 00000000 - 00000020 [ 33] */,
114114 0x001fc021 /* 0000007f - 000000a0 [ 34] */,
115115 0x002b4000 /* 000000ad - 000000ad [ 1] */,
......@@ -136,7 +136,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
136136 0x02170001 /* 0000085c - 0000085d [ 2] */,
137137 0x0217c000 /* 0000085f - 0000085f [ 1] */,
138138 0x021ac004 /* 0000086b - 0000086f [ 5] */,
139 0x0223c008 /* 0000088f - 00000897 [ 9] */,
139 0x0223c007 /* 0000088f - 00000896 [ 8] */,
140140 0x02388000 /* 000008e2 - 000008e2 [ 1] */,
141141 0x02610000 /* 00000984 - 00000984 [ 1] */,
142142 0x02634001 /* 0000098d - 0000098e [ 2] */,
......@@ -331,12 +331,11 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
331331 0x06a68005 /* 00001a9a - 00001a9f [ 6] */,
332332 0x06ab8001 /* 00001aae - 00001aaf [ 2] */,
333333 0x06b3c030 /* 00001acf - 00001aff [ 49] */,
334 0x06d34002 /* 00001b4d - 00001b4f [ 3] */,
335 0x06dfc000 /* 00001b7f - 00001b7f [ 1] */,
334 0x06d34000 /* 00001b4d - 00001b4d [ 1] */,
336335 0x06fd0007 /* 00001bf4 - 00001bfb [ 8] */,
337336 0x070e0002 /* 00001c38 - 00001c3a [ 3] */,
338337 0x07128002 /* 00001c4a - 00001c4c [ 3] */,
339 0x07224006 /* 00001c89 - 00001c8f [ 7] */,
338 0x0722c004 /* 00001c8b - 00001c8f [ 5] */,
340339 0x072ec001 /* 00001cbb - 00001cbc [ 2] */,
341340 0x07320007 /* 00001cc8 - 00001ccf [ 8] */,
342341 0x073ec004 /* 00001cfb - 00001cff [ 5] */,
......@@ -364,7 +363,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
364363 0x0830400e /* 000020c1 - 000020cf [ 15] */,
365364 0x083c400e /* 000020f1 - 000020ff [ 15] */,
366365 0x08630003 /* 0000218c - 0000218f [ 4] */,
367 0x0909c018 /* 00002427 - 0000243f [ 25] */,
366 0x090a8015 /* 0000242a - 0000243f [ 22] */,
368367 0x0912c014 /* 0000244b - 0000245f [ 21] */,
369368 0x0add0001 /* 00002b74 - 00002b75 [ 2] */,
370369 0x0ae58000 /* 00002b96 - 00002b96 [ 1] */,
......@@ -393,16 +392,16 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
393392 0x0c400004 /* 00003100 - 00003104 [ 5] */,
394393 0x0c4c0000 /* 00003130 - 00003130 [ 1] */,
395394 0x0c63c000 /* 0000318f - 0000318f [ 1] */,
396 0x0c79000a /* 000031e4 - 000031ee [ 11] */,
395 0x0c798008 /* 000031e6 - 000031ee [ 9] */,
397396 0x0c87c000 /* 0000321f - 0000321f [ 1] */,
398397 0x29234002 /* 0000a48d - 0000a48f [ 3] */,
399398 0x2931c008 /* 0000a4c7 - 0000a4cf [ 9] */,
400399 0x298b0013 /* 0000a62c - 0000a63f [ 20] */,
401400 0x29be0007 /* 0000a6f8 - 0000a6ff [ 8] */,
402 0x29f2c004 /* 0000a7cb - 0000a7cf [ 5] */,
401 0x29f38001 /* 0000a7ce - 0000a7cf [ 2] */,
403402 0x29f48000 /* 0000a7d2 - 0000a7d2 [ 1] */,
404403 0x29f50000 /* 0000a7d4 - 0000a7d4 [ 1] */,
405 0x29f68017 /* 0000a7da - 0000a7f1 [ 24] */,
404 0x29f74014 /* 0000a7dd - 0000a7f1 [ 21] */,
406405 0x2a0b4002 /* 0000a82d - 0000a82f [ 3] */,
407406 0x2a0e8005 /* 0000a83a - 0000a83f [ 6] */,
408407 0x2a1e0007 /* 0000a878 - 0000a87f [ 8] */,
......@@ -491,7 +490,8 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
491490 0x41688000 /* 000105a2 - 000105a2 [ 1] */,
492491 0x416c8000 /* 000105b2 - 000105b2 [ 1] */,
493492 0x416e8000 /* 000105ba - 000105ba [ 1] */,
494 0x416f4042 /* 000105bd - 000105ff [ 67] */,
493 0x416f4002 /* 000105bd - 000105bf [ 3] */,
494 0x417d000b /* 000105f4 - 000105ff [ 12] */,
495495 0x41cdc008 /* 00010737 - 0001073f [ 9] */,
496496 0x41d58009 /* 00010756 - 0001075f [ 10] */,
497497 0x41da0017 /* 00010768 - 0001077f [ 24] */,
......@@ -534,11 +534,15 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
534534 0x432cc00c /* 00010cb3 - 00010cbf [ 13] */,
535535 0x433cc006 /* 00010cf3 - 00010cf9 [ 7] */,
536536 0x434a0007 /* 00010d28 - 00010d2f [ 8] */,
537 0x434e8125 /* 00010d3a - 00010e5f [ 294] */,
537 0x434e8005 /* 00010d3a - 00010d3f [ 6] */,
538 0x43598002 /* 00010d66 - 00010d68 [ 3] */,
539 0x43618007 /* 00010d86 - 00010d8d [ 8] */,
540 0x436400cf /* 00010d90 - 00010e5f [ 208] */,
538541 0x439fc000 /* 00010e7f - 00010e7f [ 1] */,
539542 0x43aa8000 /* 00010eaa - 00010eaa [ 1] */,
540543 0x43ab8001 /* 00010eae - 00010eaf [ 2] */,
541 0x43ac804a /* 00010eb2 - 00010efc [ 75] */,
544 0x43ac800f /* 00010eb2 - 00010ec1 [ 16] */,
545 0x43b14036 /* 00010ec5 - 00010efb [ 55] */,
542546 0x43ca0007 /* 00010f28 - 00010f2f [ 8] */,
543547 0x43d68015 /* 00010f5a - 00010f6f [ 22] */,
544548 0x43e28025 /* 00010f8a - 00010faf [ 38] */,
......@@ -578,7 +582,18 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
578582 0x44d60004 /* 00011358 - 0001135c [ 5] */,
579583 0x44d90001 /* 00011364 - 00011365 [ 2] */,
580584 0x44db4002 /* 0001136d - 0001136f [ 3] */,
581 0x44dd408a /* 00011375 - 000113ff [ 139] */,
585 0x44dd400a /* 00011375 - 0001137f [ 11] */,
586 0x44e28000 /* 0001138a - 0001138a [ 1] */,
587 0x44e30001 /* 0001138c - 0001138d [ 2] */,
588 0x44e3c000 /* 0001138f - 0001138f [ 1] */,
589 0x44ed8000 /* 000113b6 - 000113b6 [ 1] */,
590 0x44f04000 /* 000113c1 - 000113c1 [ 1] */,
591 0x44f0c001 /* 000113c3 - 000113c4 [ 2] */,
592 0x44f18000 /* 000113c6 - 000113c6 [ 1] */,
593 0x44f2c000 /* 000113cb - 000113cb [ 1] */,
594 0x44f58000 /* 000113d6 - 000113d6 [ 1] */,
595 0x44f64007 /* 000113d9 - 000113e0 [ 8] */,
596 0x44f8c01c /* 000113e3 - 000113ff [ 29] */,
582597 0x45170000 /* 0001145c - 0001145c [ 1] */,
583598 0x4518801d /* 00011462 - 0001147f [ 30] */,
584599 0x45320007 /* 000114c8 - 000114cf [ 8] */,
......@@ -589,7 +604,8 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
589604 0x45968005 /* 0001165a - 0001165f [ 6] */,
590605 0x459b4012 /* 0001166d - 0001167f [ 19] */,
591606 0x45ae8005 /* 000116ba - 000116bf [ 6] */,
592 0x45b28035 /* 000116ca - 000116ff [ 54] */,
607 0x45b28005 /* 000116ca - 000116cf [ 6] */,
608 0x45b9001b /* 000116e4 - 000116ff [ 28] */,
593609 0x45c6c001 /* 0001171b - 0001171c [ 2] */,
594610 0x45cb0003 /* 0001172c - 0001172f [ 4] */,
595611 0x45d1c0b8 /* 00011747 - 000117ff [ 185] */,
......@@ -609,7 +625,9 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
609625 0x46920007 /* 00011a48 - 00011a4f [ 8] */,
610626 0x46a8c00c /* 00011aa3 - 00011aaf [ 13] */,
611627 0x46be4006 /* 00011af9 - 00011aff [ 7] */,
612 0x46c280f5 /* 00011b0a - 00011bff [ 246] */,
628 0x46c280b5 /* 00011b0a - 00011bbf [ 182] */,
629 0x46f8800d /* 00011be2 - 00011bef [ 14] */,
630 0x46fe8005 /* 00011bfa - 00011bff [ 6] */,
613631 0x47024000 /* 00011c09 - 00011c09 [ 1] */,
614632 0x470dc000 /* 00011c37 - 00011c37 [ 1] */,
615633 0x47118009 /* 00011c46 - 00011c4f [ 10] */,
......@@ -633,7 +651,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
633651 0x47be4006 /* 00011ef9 - 00011eff [ 7] */,
634652 0x47c44000 /* 00011f11 - 00011f11 [ 1] */,
635653 0x47cec002 /* 00011f3b - 00011f3d [ 3] */,
636 0x47d68055 /* 00011f5a - 00011faf [ 86] */,
654 0x47d6c054 /* 00011f5b - 00011faf [ 85] */,
637655 0x47ec400e /* 00011fb1 - 00011fbf [ 15] */,
638656 0x47fc800c /* 00011ff2 - 00011ffe [ 13] */,
639657 0x48e68065 /* 0001239a - 000123ff [ 102] */,
......@@ -642,8 +660,10 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
642660 0x49510a4b /* 00012544 - 00012f8f [ 2636] */,
643661 0x4bfcc00c /* 00012ff3 - 00012fff [ 13] */,
644662 0x4d0c000f /* 00013430 - 0001343f [ 16] */,
645 0x4d158fa9 /* 00013456 - 000143ff [ 4010] */,
646 0x5191e1b8 /* 00014647 - 000167ff [ 8633] */,
663 0x4d158009 /* 00013456 - 0001345f [ 10] */,
664 0x50fec004 /* 000143fb - 000143ff [ 5] */,
665 0x5191dab8 /* 00014647 - 000160ff [ 6841] */,
666 0x584e86c5 /* 0001613a - 000167ff [ 1734] */,
647667 0x5a8e4006 /* 00016a39 - 00016a3f [ 7] */,
648668 0x5a97c000 /* 00016a5f - 00016a5f [ 1] */,
649669 0x5a9a8003 /* 00016a6a - 00016a6d [ 4] */,
......@@ -655,7 +675,8 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
655675 0x5ad68000 /* 00016b5a - 00016b5a [ 1] */,
656676 0x5ad88000 /* 00016b62 - 00016b62 [ 1] */,
657677 0x5ade0004 /* 00016b78 - 00016b7c [ 5] */,
658 0x5ae402af /* 00016b90 - 00016e3f [ 688] */,
678 0x5ae401af /* 00016b90 - 00016d3f [ 432] */,
679 0x5b5e80c5 /* 00016d7a - 00016e3f [ 198] */,
659680 0x5ba6c064 /* 00016e9b - 00016eff [ 101] */,
660681 0x5bd2c003 /* 00016f4b - 00016f4e [ 4] */,
661682 0x5be20006 /* 00016f88 - 00016f8e [ 7] */,
......@@ -663,7 +684,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
663684 0x5bf9400a /* 00016fe5 - 00016fef [ 11] */,
664685 0x5bfc800d /* 00016ff2 - 00016fff [ 14] */,
665686 0x61fe0007 /* 000187f8 - 000187ff [ 8] */,
666 0x63358029 /* 00018cd6 - 00018cff [ 42] */,
687 0x63358028 /* 00018cd6 - 00018cfe [ 41] */,
667688 0x634262e6 /* 00018d09 - 0001afef [ 8935] */,
668689 0x6bfd0000 /* 0001aff4 - 0001aff4 [ 1] */,
669690 0x6bff0000 /* 0001affc - 0001affc [ 1] */,
......@@ -678,7 +699,9 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
678699 0x6f1f4002 /* 0001bc7d - 0001bc7f [ 3] */,
679700 0x6f224006 /* 0001bc89 - 0001bc8f [ 7] */,
680701 0x6f268001 /* 0001bc9a - 0001bc9b [ 2] */,
681 0x6f28125f /* 0001bca0 - 0001ceff [ 4704] */,
702 0x6f280f5f /* 0001bca0 - 0001cbff [ 3936] */,
703 0x733e8005 /* 0001ccfa - 0001ccff [ 6] */,
704 0x73ad004b /* 0001ceb4 - 0001ceff [ 76] */,
682705 0x73cb8001 /* 0001cf2e - 0001cf2f [ 2] */,
683706 0x73d1c008 /* 0001cf47 - 0001cf4f [ 9] */,
684707 0x73f1003b /* 0001cfc4 - 0001cfff [ 60] */,
......@@ -730,7 +753,9 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
730753 0x78abc010 /* 0001e2af - 0001e2bf [ 17] */,
731754 0x78be8004 /* 0001e2fa - 0001e2fe [ 5] */,
732755 0x78c001cf /* 0001e300 - 0001e4cf [ 464] */,
733 0x793e82e5 /* 0001e4fa - 0001e7df [ 742] */,
756 0x793e80d5 /* 0001e4fa - 0001e5cf [ 214] */,
757 0x797ec003 /* 0001e5fb - 0001e5fe [ 4] */,
758 0x798001df /* 0001e600 - 0001e7df [ 480] */,
734759 0x79f9c000 /* 0001e7e7 - 0001e7e7 [ 1] */,
735760 0x79fb0000 /* 0001e7ec - 0001e7ec [ 1] */,
736761 0x79fbc000 /* 0001e7ef - 0001e7ef [ 1] */,
......@@ -800,18 +825,17 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = {
800825 0x7e168005 /* 0001f85a - 0001f85f [ 6] */,
801826 0x7e220007 /* 0001f888 - 0001f88f [ 8] */,
802827 0x7e2b8001 /* 0001f8ae - 0001f8af [ 2] */,
803 0x7e2c804d /* 0001f8b2 - 0001f8ff [ 78] */,
828 0x7e2f0003 /* 0001f8bc - 0001f8bf [ 4] */,
829 0x7e30803d /* 0001f8c2 - 0001f8ff [ 62] */,
804830 0x7e95000b /* 0001fa54 - 0001fa5f [ 12] */,
805831 0x7e9b8001 /* 0001fa6e - 0001fa6f [ 2] */,
806832 0x7e9f4002 /* 0001fa7d - 0001fa7f [ 3] */,
807 0x7ea24006 /* 0001fa89 - 0001fa8f [ 7] */,
808 0x7eaf8000 /* 0001fabe - 0001fabe [ 1] */,
809 0x7eb18007 /* 0001fac6 - 0001facd [ 8] */,
810 0x7eb70003 /* 0001fadc - 0001fadf [ 4] */,
811 0x7eba4006 /* 0001fae9 - 0001faef [ 7] */,
833 0x7ea28004 /* 0001fa8a - 0001fa8e [ 5] */,
834 0x7eb1c006 /* 0001fac7 - 0001facd [ 7] */,
835 0x7eb74001 /* 0001fadd - 0001fade [ 2] */,
836 0x7eba8005 /* 0001faea - 0001faef [ 6] */,
812837 0x7ebe4006 /* 0001faf9 - 0001faff [ 7] */,
813838 0x7ee4c000 /* 0001fb93 - 0001fb93 [ 1] */,
814 0x7ef2c024 /* 0001fbcb - 0001fbef [ 37] */,
815839 0x7efe8405 /* 0001fbfa - 0001ffff [ 1030] */,
816840 0xa9b8001f /* 0002a6e0 - 0002a6ff [ 32] */,
817841 0xadce8005 /* 0002b73a - 0002b73f [ 6] */,
lib/libcxx/include/__format/extended_grapheme_cluster_table.h+52-47
......@@ -125,7 +125,7 @@ enum class __property : uint8_t {
125125/// following benchmark.
126126/// libcxx/benchmarks/std_format_spec_string_unicode.bench.cpp
127127// clang-format off
128_LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = {
128_LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1501] = {
129129 0x00000091,
130130 0x00005005,
131131 0x00005811,
......@@ -164,7 +164,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = {
164164 0x00414842,
165165 0x0042c822,
166166 0x00448018,
167 0x0044c072,
167 0x0044b882,
168168 0x00465172,
169169 0x00471008,
170170 0x004719f2,
......@@ -246,14 +246,12 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = {
246246 0x0064101a,
247247 0x0065e002,
248248 0x0065f00a,
249 0x0065f802,
250 0x0066001a,
249 0x0065f812,
250 0x0066080a,
251251 0x00661002,
252252 0x0066181a,
253 0x00663002,
254 0x0066381a,
255 0x0066501a,
256 0x00666012,
253 0x00663022,
254 0x00665032,
257255 0x0066a812,
258256 0x00671012,
259257 0x0067980a,
......@@ -318,10 +316,8 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = {
318316 0x008b047c,
319317 0x008d457b,
320318 0x009ae822,
321 0x00b89022,
322 0x00b8a80a,
323 0x00b99012,
324 0x00b9a00a,
319 0x00b89032,
320 0x00b99022,
325321 0x00ba9012,
326322 0x00bb9012,
327323 0x00bda012,
......@@ -361,29 +357,23 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = {
361357 0x00d581e2,
362358 0x00d80032,
363359 0x00d8200a,
364 0x00d9a062,
365 0x00d9d80a,
366 0x00d9e002,
367 0x00d9e84a,
368 0x00da1002,
369 0x00da181a,
360 0x00d9a092,
361 0x00d9f03a,
362 0x00da1022,
370363 0x00db5882,
371364 0x00dc0012,
372365 0x00dc100a,
373366 0x00dd080a,
374367 0x00dd1032,
375368 0x00dd301a,
376 0x00dd4012,
377 0x00dd500a,
378 0x00dd5822,
369 0x00dd4052,
379370 0x00df3002,
380371 0x00df380a,
381372 0x00df4012,
382373 0x00df502a,
383374 0x00df6802,
384375 0x00df700a,
385 0x00df7822,
386 0x00df901a,
376 0x00df7842,
387377 0x00e1207a,
388378 0x00e16072,
389379 0x00e1a01a,
......@@ -475,7 +465,8 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = {
475465 0x0547f802,
476466 0x05493072,
477467 0x054a38a2,
478 0x054a901a,
468 0x054a900a,
469 0x054a9802,
479470 0x054b01c4,
480471 0x054c0022,
481472 0x054c180a,
......@@ -484,7 +475,8 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = {
484475 0x054db032,
485476 0x054dd01a,
486477 0x054de012,
487 0x054df02a,
478 0x054df01a,
479 0x054e0002,
488480 0x054f2802,
489481 0x05514852,
490482 0x0551781a,
......@@ -1328,8 +1320,9 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = {
13281320 0x0851f802,
13291321 0x08572812,
13301322 0x08692032,
1323 0x086b4842,
13311324 0x08755812,
1332 0x0877e822,
1325 0x0877e032,
13331326 0x087a30a2,
13341327 0x087c1032,
13351328 0x0880000a,
......@@ -1357,7 +1350,8 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = {
13571350 0x088c100a,
13581351 0x088d982a,
13591352 0x088db082,
1360 0x088df81a,
1353 0x088df80a,
1354 0x088e0002,
13611355 0x088e1018,
13621356 0x088e4832,
13631357 0x088e700a,
......@@ -1365,9 +1359,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = {
13651359 0x0891602a,
13661360 0x08917822,
13671361 0x0891901a,
1368 0x0891a002,
1369 0x0891a80a,
1370 0x0891b012,
1362 0x0891a032,
13711363 0x0891f002,
13721364 0x08920802,
13731365 0x0896f802,
......@@ -1381,11 +1373,24 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = {
13811373 0x089a0002,
13821374 0x089a083a,
13831375 0x089a381a,
1384 0x089a582a,
1376 0x089a581a,
1377 0x089a6802,
13851378 0x089ab802,
13861379 0x089b101a,
13871380 0x089b3062,
13881381 0x089b8042,
1382 0x089dc002,
1383 0x089dc81a,
1384 0x089dd852,
1385 0x089e1002,
1386 0x089e2802,
1387 0x089e3822,
1388 0x089e500a,
1389 0x089e601a,
1390 0x089e7022,
1391 0x089e8808,
1392 0x089e9002,
1393 0x089f0812,
13891394 0x08a1a82a,
13901395 0x08a1c072,
13911396 0x08a2001a,
......@@ -1422,10 +1427,10 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = {
14221427 0x08b5600a,
14231428 0x08b56802,
14241429 0x08b5701a,
1425 0x08b58052,
1426 0x08b5b00a,
1427 0x08b5b802,
1428 0x08b8e822,
1430 0x08b58072,
1431 0x08b8e802,
1432 0x08b8f00a,
1433 0x08b8f802,
14291434 0x08b91032,
14301435 0x08b9300a,
14311436 0x08b93842,
......@@ -1436,9 +1441,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = {
14361441 0x08c98002,
14371442 0x08c9884a,
14381443 0x08c9b81a,
1439 0x08c9d812,
1440 0x08c9e80a,
1441 0x08c9f002,
1444 0x08c9d832,
14421445 0x08c9f808,
14431446 0x08ca000a,
14441447 0x08ca0808,
......@@ -1495,28 +1498,29 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = {
14951498 0x08f9a01a,
14961499 0x08f9b042,
14971500 0x08f9f01a,
1498 0x08fa0002,
1499 0x08fa080a,
1500 0x08fa1002,
1501 0x08fa0022,
1502 0x08fad002,
15011503 0x09a180f1,
15021504 0x09a20002,
15031505 0x09a238e2,
1506 0x0b08f0b2,
1507 0x0b09502a,
1508 0x0b096822,
15041509 0x0b578042,
15051510 0x0b598062,
1511 0x0b6b180c,
1512 0x0b6b383c,
15061513 0x0b7a7802,
15071514 0x0b7a8b6a,
15081515 0x0b7c7832,
15091516 0x0b7f2002,
1510 0x0b7f801a,
1517 0x0b7f8012,
15111518 0x0de4e812,
15121519 0x0de50031,
15131520 0x0e7802d2,
15141521 0x0e798162,
1515 0x0e8b2802,
1516 0x0e8b300a,
1517 0x0e8b3822,
1518 0x0e8b680a,
1519 0x0e8b7042,
1522 0x0e8b2842,
1523 0x0e8b6852,
15201524 0x0e8b9871,
15211525 0x0e8bd872,
15221526 0x0e8c2862,
......@@ -1538,6 +1542,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = {
15381542 0x0f157002,
15391543 0x0f176032,
15401544 0x0f276032,
1545 0x0f2f7012,
15411546 0x0f468062,
15421547 0x0f4a2062,
15431548 0x0f8007f3,
lib/libcxx/include/__format/format_arg.h+3-3
......@@ -277,9 +277,9 @@ public:
277277};
278278
279279template <class _Context>
280class _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS basic_format_arg {
280class _LIBCPP_NO_SPECIALIZATIONS basic_format_arg {
281281public:
282 class _LIBCPP_TEMPLATE_VIS handle;
282 class handle;
283283
284284 _LIBCPP_HIDE_FROM_ABI basic_format_arg() noexcept : __type_{__format::__arg_t::__none} {}
285285
......@@ -355,7 +355,7 @@ public:
355355};
356356
357357template <class _Context>
358class _LIBCPP_TEMPLATE_VIS basic_format_arg<_Context>::handle {
358class basic_format_arg<_Context>::handle {
359359public:
360360 _LIBCPP_HIDE_FROM_ABI void format(basic_format_parse_context<char_type>& __parse_ctx, _Context& __ctx) const {
361361 __handle_.__format_(__parse_ctx, __ctx, __handle_.__ptr_);
lib/libcxx/include/__format/format_arg_store.h+24-14
......@@ -14,13 +14,14 @@
1414# pragma GCC system_header
1515#endif
1616
17#include <__concepts/arithmetic.h>
1817#include <__concepts/same_as.h>
1918#include <__config>
19#include <__cstddef/size_t.h>
2020#include <__format/concepts.h>
2121#include <__format/format_arg.h>
2222#include <__type_traits/conditional.h>
2323#include <__type_traits/extent.h>
24#include <__type_traits/integer_traits.h>
2425#include <__type_traits/remove_const.h>
2526#include <cstdint>
2627#include <string>
......@@ -32,6 +33,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3233
3334namespace __format {
3435
36template <class _Arr, class _Elem>
37inline constexpr bool __is_bounded_array_of = false;
38
39template <class _Elem, size_t _Len>
40inline constexpr bool __is_bounded_array_of<_Elem[_Len], _Elem> = true;
41
3542/// \returns The @c __arg_t based on the type of the formatting argument.
3643///
3744/// \pre \c __formattable<_Tp, typename _Context::char_type>
......@@ -58,7 +65,7 @@ consteval __arg_t __determine_arg_t() {
5865# endif
5966
6067// Signed integers
61template <class, __libcpp_signed_integer _Tp>
68template <class, __signed_integer _Tp>
6269consteval __arg_t __determine_arg_t() {
6370 if constexpr (sizeof(_Tp) <= sizeof(int))
6471 return __arg_t::__int;
......@@ -73,7 +80,7 @@ consteval __arg_t __determine_arg_t() {
7380}
7481
7582// Unsigned integers
76template <class, __libcpp_unsigned_integer _Tp>
83template <class, __unsigned_integer _Tp>
7784consteval __arg_t __determine_arg_t() {
7885 if constexpr (sizeof(_Tp) <= sizeof(unsigned))
7986 return __arg_t::__unsigned;
......@@ -110,7 +117,7 @@ consteval __arg_t __determine_arg_t() {
110117
111118// Char array
112119template <class _Context, class _Tp>
113 requires(is_array_v<_Tp> && same_as<_Tp, typename _Context::char_type[extent_v<_Tp>]>)
120 requires __is_bounded_array_of<_Tp, typename _Context::char_type>
114121consteval __arg_t __determine_arg_t() {
115122 return __arg_t::__string_view;
116123}
......@@ -164,17 +171,18 @@ consteval __arg_t __determine_arg_t() {
164171template <class _Context, class _Tp>
165172_LIBCPP_HIDE_FROM_ABI basic_format_arg<_Context> __create_format_arg(_Tp& __value) noexcept {
166173 using _Dp = remove_const_t<_Tp>;
167 constexpr __arg_t __arg = __determine_arg_t<_Context, _Dp>();
174 constexpr __arg_t __arg = __format::__determine_arg_t<_Context, _Dp>();
168175 static_assert(__arg != __arg_t::__none, "the supplied type is not formattable");
169176 static_assert(__formattable_with<_Tp, _Context>);
170177
178 using __context_char_type = _Context::char_type;
171179 // Not all types can be used to directly initialize the
172180 // __basic_format_arg_value. First handle all types needing adjustment, the
173181 // final else requires no adjustment.
174182 if constexpr (__arg == __arg_t::__char_type)
175183
176184# if _LIBCPP_HAS_WIDE_CHARACTERS
177 if constexpr (same_as<typename _Context::char_type, wchar_t> && same_as<_Dp, char>)
185 if constexpr (same_as<__context_char_type, wchar_t> && same_as<_Dp, char>)
178186 return basic_format_arg<_Context>{__arg, static_cast<wchar_t>(static_cast<unsigned char>(__value))};
179187 else
180188# endif
......@@ -189,14 +197,16 @@ _LIBCPP_HIDE_FROM_ABI basic_format_arg<_Context> __create_format_arg(_Tp& __valu
189197 return basic_format_arg<_Context>{__arg, static_cast<unsigned long long>(__value)};
190198 else if constexpr (__arg == __arg_t::__string_view)
191199 // Using std::size on a character array will add the NUL-terminator to the size.
192 if constexpr (is_array_v<_Dp>)
193 return basic_format_arg<_Context>{
194 __arg, basic_string_view<typename _Context::char_type>{__value, extent_v<_Dp> - 1}};
195 else
196 // When the _Traits or _Allocator are different an implicit conversion will
197 // fail.
200 if constexpr (__is_bounded_array_of<_Dp, __context_char_type>) {
201 const __context_char_type* const __pbegin = std::begin(__value);
202 const __context_char_type* const __pzero =
203 char_traits<__context_char_type>::find(__pbegin, extent_v<_Dp>, __context_char_type{});
204 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__pzero != nullptr, "formatting a non-null-terminated array");
198205 return basic_format_arg<_Context>{
199 __arg, basic_string_view<typename _Context::char_type>{__value.data(), __value.size()}};
206 __arg, basic_string_view<__context_char_type>{__pbegin, static_cast<size_t>(__pzero - __pbegin)}};
207 } else
208 // When the _Traits or _Allocator are different an implicit conversion will fail.
209 return basic_format_arg<_Context>{__arg, basic_string_view<__context_char_type>{__value.data(), __value.size()}};
200210 else if constexpr (__arg == __arg_t::__ptr)
201211 return basic_format_arg<_Context>{__arg, static_cast<const void*>(__value)};
202212 else if constexpr (__arg == __arg_t::__handle)
......@@ -247,7 +257,7 @@ struct __unpacked_format_arg_store {
247257} // namespace __format
248258
249259template <class _Context, class... _Args>
250struct _LIBCPP_TEMPLATE_VIS __format_arg_store {
260struct __format_arg_store {
251261 _LIBCPP_HIDE_FROM_ABI __format_arg_store(_Args&... __args) noexcept {
252262 if constexpr (sizeof...(_Args) != 0) {
253263 if constexpr (__format::__use_packed_format_arg_store(sizeof...(_Args)))
lib/libcxx/include/__format/format_args.h+1-1
......@@ -26,7 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2626#if _LIBCPP_STD_VER >= 20
2727
2828template <class _Context>
29class _LIBCPP_TEMPLATE_VIS basic_format_args {
29class basic_format_args {
3030public:
3131 template <class... _Args>
3232 _LIBCPP_HIDE_FROM_ABI basic_format_args(const __format_arg_store<_Context, _Args...>& __store) noexcept
lib/libcxx/include/__format/format_context.h+4-9
......@@ -42,7 +42,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4242
4343template <class _OutIt, class _CharT>
4444 requires output_iterator<_OutIt, const _CharT&>
45class _LIBCPP_TEMPLATE_VIS basic_format_context;
45class basic_format_context;
4646
4747# if _LIBCPP_HAS_LOCALIZATION
4848/**
......@@ -72,13 +72,8 @@ using wformat_context = basic_format_context< back_insert_iterator<__format::__o
7272
7373template <class _OutIt, class _CharT>
7474 requires output_iterator<_OutIt, const _CharT&>
75class
76 // clang-format off
77 _LIBCPP_TEMPLATE_VIS
78 _LIBCPP_PREFERRED_NAME(format_context)
79 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wformat_context))
80 // clang-format on
81 basic_format_context {
75class _LIBCPP_PREFERRED_NAME(format_context)
76 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wformat_context)) basic_format_context {
8277public:
8378 using iterator = _OutIt;
8479 using char_type = _CharT;
......@@ -153,7 +148,7 @@ public:
153148// Here the width of an element in input is determined dynamically.
154149// Note when the top-level element has no width the retargeting is not needed.
155150template <class _CharT>
156class _LIBCPP_TEMPLATE_VIS basic_format_context<typename __format::__retarget_buffer<_CharT>::__iterator, _CharT> {
151class basic_format_context<typename __format::__retarget_buffer<_CharT>::__iterator, _CharT> {
157152public:
158153 using iterator = typename __format::__retarget_buffer<_CharT>::__iterator;
159154 using char_type = _CharT;
lib/libcxx/include/__format/format_functions.h+48-5
......@@ -11,6 +11,8 @@
1111#define _LIBCPP___FORMAT_FORMAT_FUNCTIONS
1212
1313#include <__algorithm/clamp.h>
14#include <__algorithm/ranges_find_first_of.h>
15#include <__chrono/statically_widen.h>
1416#include <__concepts/convertible_to.h>
1517#include <__concepts/same_as.h>
1618#include <__config>
......@@ -36,6 +38,7 @@
3638#include <__iterator/iterator_traits.h> // iter_value_t
3739#include <__variant/monostate.h>
3840#include <array>
41#include <optional>
3942#include <string>
4043#include <string_view>
4144
......@@ -83,7 +86,7 @@ namespace __format {
8386/// When parsing a handle which is not enabled the code is ill-formed.
8487/// This helper uses the parser of the appropriate formatter for the stored type.
8588template <class _CharT>
86class _LIBCPP_TEMPLATE_VIS __compile_time_handle {
89class __compile_time_handle {
8790public:
8891 template <class _ParseContext>
8992 _LIBCPP_HIDE_FROM_ABI constexpr void __parse(_ParseContext& __ctx) const {
......@@ -110,7 +113,7 @@ private:
110113// Dummy format_context only providing the parts used during constant
111114// validation of the basic_format_string.
112115template <class _CharT>
113struct _LIBCPP_TEMPLATE_VIS __compile_time_basic_format_context {
116struct __compile_time_basic_format_context {
114117public:
115118 using char_type = _CharT;
116119
......@@ -339,12 +342,12 @@ _LIBCPP_HIDE_FROM_ABI constexpr typename _Ctx::iterator __vformat_to(_ParseCtx&&
339342
340343# if _LIBCPP_STD_VER >= 26
341344template <class _CharT>
342struct _LIBCPP_TEMPLATE_VIS __runtime_format_string {
345struct __runtime_format_string {
343346private:
344347 basic_string_view<_CharT> __str_;
345348
346349 template <class _Cp, class... _Args>
347 friend struct _LIBCPP_TEMPLATE_VIS basic_format_string;
350 friend struct basic_format_string;
348351
349352public:
350353 _LIBCPP_HIDE_FROM_ABI __runtime_format_string(basic_string_view<_CharT> __s) noexcept : __str_(__s) {}
......@@ -362,7 +365,7 @@ _LIBCPP_HIDE_FROM_ABI inline __runtime_format_string<wchar_t> runtime_format(wst
362365# endif // _LIBCPP_STD_VER >= 26
363366
364367template <class _CharT, class... _Args>
365struct _LIBCPP_TEMPLATE_VIS basic_format_string {
368struct basic_format_string {
366369 template <class _Tp>
367370 requires convertible_to<const _Tp&, basic_string_view<_CharT>>
368371 consteval basic_format_string(const _Tp& __str) : __str_{__str} {
......@@ -447,10 +450,47 @@ format_to(_OutIt __out_it, wformat_string<_Args...> __fmt, _Args&&... __args) {
447450}
448451# endif
449452
453// Try constant folding the format string instead of going through the whole formatting machinery. If there is no
454// constant folding no extra code should be emitted (with optimizations enabled) and the function returns nullopt. When
455// constant folding is successful, the formatting is performed and the resulting string is returned.
456namespace __format {
457template <class _CharT>
458[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<basic_string<_CharT>> __try_constant_folding(
459 basic_string_view<_CharT> __fmt,
460 basic_format_args<basic_format_context<back_insert_iterator<__format::__output_buffer<_CharT>>, _CharT>> __args) {
461 // Fold strings not containing '{' or '}' to just return the string
462 if (bool __is_identity = [&] [[__gnu__::__pure__]] // Make sure the compiler knows this call can be eliminated
463 { return std::ranges::find_first_of(__fmt, array{'{', '}'}) == __fmt.end(); }();
464 __builtin_constant_p(__is_identity) && __is_identity)
465 return basic_string<_CharT>{__fmt};
466
467 // Fold '{}' to the appropriate conversion function
468 if (auto __only_first_arg = __fmt == _LIBCPP_STATICALLY_WIDEN(_CharT, "{}");
469 __builtin_constant_p(__only_first_arg) && __only_first_arg) {
470 if (auto __arg = __args.get(0); __builtin_constant_p(__arg.__type_)) {
471 return std::__visit_format_arg(
472 []<class _Tp>(_Tp&& __argument) -> optional<basic_string<_CharT>> {
473 if constexpr (is_same_v<remove_cvref_t<_Tp>, basic_string_view<_CharT>>) {
474 return basic_string<_CharT>{__argument};
475 } else {
476 return nullopt;
477 }
478 },
479 __arg);
480 }
481 }
482
483 return nullopt;
484}
485} // namespace __format
486
450487// TODO FMT This needs to be a template or std::to_chars(floating-point) availability markup
451488// fires too eagerly, see http://llvm.org/PR61563.
452489template <class = void>
453490[[nodiscard]] _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI string vformat(string_view __fmt, format_args __args) {
491 auto __result = __format::__try_constant_folding(__fmt, __args);
492 if (__result.has_value())
493 return *std::move(__result);
454494 __format::__allocating_buffer<char> __buffer;
455495 std::vformat_to(__buffer.__make_output_iterator(), __fmt, __args);
456496 return string{__buffer.__view()};
......@@ -462,6 +502,9 @@ template <class = void>
462502template <class = void>
463503[[nodiscard]] _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI wstring
464504vformat(wstring_view __fmt, wformat_args __args) {
505 auto __result = __format::__try_constant_folding(__fmt, __args);
506 if (__result.has_value())
507 return *std::move(__result);
465508 __format::__allocating_buffer<wchar_t> __buffer;
466509 std::vformat_to(__buffer.__make_output_iterator(), __fmt, __args);
467510 return wstring{__buffer.__view()};
lib/libcxx/include/__format/format_parse_context.h+1-1
......@@ -24,7 +24,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2424#if _LIBCPP_STD_VER >= 20
2525
2626template <class _CharT>
27class _LIBCPP_TEMPLATE_VIS basic_format_parse_context {
27class basic_format_parse_context {
2828public:
2929 using char_type = _CharT;
3030 using const_iterator = typename basic_string_view<_CharT>::const_iterator;
lib/libcxx/include/__format/format_string.h+1-1
......@@ -29,7 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2929namespace __format {
3030
3131template <contiguous_iterator _Iterator>
32struct _LIBCPP_TEMPLATE_VIS __parse_number_result {
32struct __parse_number_result {
3333 _Iterator __last;
3434 uint32_t __value;
3535};
lib/libcxx/include/__format/format_to_n_result.h+1-1
......@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#if _LIBCPP_STD_VER >= 20
2323
2424template <class _OutIt>
25struct _LIBCPP_TEMPLATE_VIS format_to_n_result {
25struct format_to_n_result {
2626 _OutIt out;
2727 iter_difference_t<_OutIt> size;
2828};
lib/libcxx/include/__format/formatter.h+9-7
......@@ -21,6 +21,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121
2222#if _LIBCPP_STD_VER >= 20
2323
24struct __disabled_formatter {
25 __disabled_formatter() = delete;
26 __disabled_formatter(const __disabled_formatter&) = delete;
27 __disabled_formatter& operator=(const __disabled_formatter&) = delete;
28};
29
2430/// The default formatter template.
2531///
2632/// [format.formatter.spec]/5
......@@ -28,14 +34,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2834/// - is_default_constructible_v<F>,
2935/// - is_copy_constructible_v<F>,
3036/// - is_move_constructible_v<F>,
31/// - is_copy_assignable<F>, and
32/// - is_move_assignable<F>.
37/// - is_copy_assignable_v<F>, and
38/// - is_move_assignable_v<F>.
3339template <class _Tp, class _CharT>
34struct _LIBCPP_TEMPLATE_VIS formatter {
35 formatter() = delete;
36 formatter(const formatter&) = delete;
37 formatter& operator=(const formatter&) = delete;
38};
40struct formatter : __disabled_formatter {};
3941
4042# if _LIBCPP_STD_VER >= 23
4143
lib/libcxx/include/__format/formatter_bool.h+1-1
......@@ -33,7 +33,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3333#if _LIBCPP_STD_VER >= 20
3434
3535template <__fmt_char_type _CharT>
36struct _LIBCPP_TEMPLATE_VIS formatter<bool, _CharT> {
36struct formatter<bool, _CharT> {
3737public:
3838 template <class _ParseContext>
3939 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
lib/libcxx/include/__format/formatter_char.h+4-4
......@@ -31,7 +31,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3131#if _LIBCPP_STD_VER >= 20
3232
3333template <__fmt_char_type _CharT>
34struct _LIBCPP_TEMPLATE_VIS __formatter_char {
34struct __formatter_char {
3535public:
3636 template <class _ParseContext>
3737 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -75,14 +75,14 @@ public:
7575};
7676
7777template <>
78struct _LIBCPP_TEMPLATE_VIS formatter<char, char> : public __formatter_char<char> {};
78struct formatter<char, char> : public __formatter_char<char> {};
7979
8080# if _LIBCPP_HAS_WIDE_CHARACTERS
8181template <>
82struct _LIBCPP_TEMPLATE_VIS formatter<char, wchar_t> : public __formatter_char<wchar_t> {};
82struct formatter<char, wchar_t> : public __formatter_char<wchar_t> {};
8383
8484template <>
85struct _LIBCPP_TEMPLATE_VIS formatter<wchar_t, wchar_t> : public __formatter_char<wchar_t> {};
85struct formatter<wchar_t, wchar_t> : public __formatter_char<wchar_t> {};
8686# endif // _LIBCPP_HAS_WIDE_CHARACTERS
8787
8888# if _LIBCPP_STD_VER >= 23
lib/libcxx/include/__format/formatter_floating_point.h+6-5
......@@ -19,6 +19,7 @@
1919#include <__assert>
2020#include <__charconv/chars_format.h>
2121#include <__charconv/to_chars_floating_point.h>
22#include <__charconv/to_chars_integral.h>
2223#include <__charconv/to_chars_result.h>
2324#include <__concepts/arithmetic.h>
2425#include <__concepts/same_as.h>
......@@ -140,7 +141,7 @@ struct __traits<double> {
140141/// Depending on the maximum size required for a value, the buffer is allocated
141142/// on the stack or the heap.
142143template <floating_point _Fp>
143class _LIBCPP_TEMPLATE_VIS __float_buffer {
144class __float_buffer {
144145 using _Traits _LIBCPP_NODEBUG = __traits<_Fp>;
145146
146147public:
......@@ -750,7 +751,7 @@ __format_floating_point(_Tp __value, _FormatContext& __ctx, __format_spec::__par
750751} // namespace __formatter
751752
752753template <__fmt_char_type _CharT>
753struct _LIBCPP_TEMPLATE_VIS __formatter_floating_point {
754struct __formatter_floating_point {
754755public:
755756 template <class _ParseContext>
756757 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -768,11 +769,11 @@ public:
768769};
769770
770771template <__fmt_char_type _CharT>
771struct _LIBCPP_TEMPLATE_VIS formatter<float, _CharT> : public __formatter_floating_point<_CharT> {};
772struct formatter<float, _CharT> : public __formatter_floating_point<_CharT> {};
772773template <__fmt_char_type _CharT>
773struct _LIBCPP_TEMPLATE_VIS formatter<double, _CharT> : public __formatter_floating_point<_CharT> {};
774struct formatter<double, _CharT> : public __formatter_floating_point<_CharT> {};
774775template <__fmt_char_type _CharT>
775struct _LIBCPP_TEMPLATE_VIS formatter<long double, _CharT> : public __formatter_floating_point<_CharT> {};
776struct formatter<long double, _CharT> : public __formatter_floating_point<_CharT> {};
776777
777778# if _LIBCPP_STD_VER >= 23
778779template <>
lib/libcxx/include/__format/formatter_integer.h+13-13
......@@ -30,7 +30,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3030#if _LIBCPP_STD_VER >= 20
3131
3232template <__fmt_char_type _CharT>
33struct _LIBCPP_TEMPLATE_VIS __formatter_integer {
33struct __formatter_integer {
3434public:
3535 template <class _ParseContext>
3636 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -58,34 +58,34 @@ public:
5858
5959// Signed integral types.
6060template <__fmt_char_type _CharT>
61struct _LIBCPP_TEMPLATE_VIS formatter<signed char, _CharT> : public __formatter_integer<_CharT> {};
61struct formatter<signed char, _CharT> : public __formatter_integer<_CharT> {};
6262template <__fmt_char_type _CharT>
63struct _LIBCPP_TEMPLATE_VIS formatter<short, _CharT> : public __formatter_integer<_CharT> {};
63struct formatter<short, _CharT> : public __formatter_integer<_CharT> {};
6464template <__fmt_char_type _CharT>
65struct _LIBCPP_TEMPLATE_VIS formatter<int, _CharT> : public __formatter_integer<_CharT> {};
65struct formatter<int, _CharT> : public __formatter_integer<_CharT> {};
6666template <__fmt_char_type _CharT>
67struct _LIBCPP_TEMPLATE_VIS formatter<long, _CharT> : public __formatter_integer<_CharT> {};
67struct formatter<long, _CharT> : public __formatter_integer<_CharT> {};
6868template <__fmt_char_type _CharT>
69struct _LIBCPP_TEMPLATE_VIS formatter<long long, _CharT> : public __formatter_integer<_CharT> {};
69struct formatter<long long, _CharT> : public __formatter_integer<_CharT> {};
7070# if _LIBCPP_HAS_INT128
7171template <__fmt_char_type _CharT>
72struct _LIBCPP_TEMPLATE_VIS formatter<__int128_t, _CharT> : public __formatter_integer<_CharT> {};
72struct formatter<__int128_t, _CharT> : public __formatter_integer<_CharT> {};
7373# endif
7474
7575// Unsigned integral types.
7676template <__fmt_char_type _CharT>
77struct _LIBCPP_TEMPLATE_VIS formatter<unsigned char, _CharT> : public __formatter_integer<_CharT> {};
77struct formatter<unsigned char, _CharT> : public __formatter_integer<_CharT> {};
7878template <__fmt_char_type _CharT>
79struct _LIBCPP_TEMPLATE_VIS formatter<unsigned short, _CharT> : public __formatter_integer<_CharT> {};
79struct formatter<unsigned short, _CharT> : public __formatter_integer<_CharT> {};
8080template <__fmt_char_type _CharT>
81struct _LIBCPP_TEMPLATE_VIS formatter<unsigned, _CharT> : public __formatter_integer<_CharT> {};
81struct formatter<unsigned, _CharT> : public __formatter_integer<_CharT> {};
8282template <__fmt_char_type _CharT>
83struct _LIBCPP_TEMPLATE_VIS formatter<unsigned long, _CharT> : public __formatter_integer<_CharT> {};
83struct formatter<unsigned long, _CharT> : public __formatter_integer<_CharT> {};
8484template <__fmt_char_type _CharT>
85struct _LIBCPP_TEMPLATE_VIS formatter<unsigned long long, _CharT> : public __formatter_integer<_CharT> {};
85struct formatter<unsigned long long, _CharT> : public __formatter_integer<_CharT> {};
8686# if _LIBCPP_HAS_INT128
8787template <__fmt_char_type _CharT>
88struct _LIBCPP_TEMPLATE_VIS formatter<__uint128_t, _CharT> : public __formatter_integer<_CharT> {};
88struct formatter<__uint128_t, _CharT> : public __formatter_integer<_CharT> {};
8989# endif
9090
9191# if _LIBCPP_STD_VER >= 23
lib/libcxx/include/__format/formatter_integral.h+4-4
......@@ -338,7 +338,7 @@ _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator __format_integer(
338338 if (__specs.__std_.__type_ != __format_spec::__type::__hexadecimal_upper_case) [[likely]]
339339 return __formatter::__write(__first, __last, __ctx.out(), __specs);
340340
341 return __formatter::__write_transformed(__first, __last, __ctx.out(), __specs, __formatter::__hex_to_upper);
341 return __formatter::__write_transformed(__first, __last, __ctx.out(), __specs, std::__hex_to_upper);
342342}
343343
344344template <unsigned_integral _Tp, class _CharT, class _FormatContext>
......@@ -404,17 +404,17 @@ __format_integer(_Tp __value, _FormatContext& __ctx, __format_spec::__parsed_spe
404404//
405405
406406template <class _CharT>
407struct _LIBCPP_TEMPLATE_VIS __bool_strings;
407struct __bool_strings;
408408
409409template <>
410struct _LIBCPP_TEMPLATE_VIS __bool_strings<char> {
410struct __bool_strings<char> {
411411 static constexpr string_view __true{"true"};
412412 static constexpr string_view __false{"false"};
413413};
414414
415415# if _LIBCPP_HAS_WIDE_CHARACTERS
416416template <>
417struct _LIBCPP_TEMPLATE_VIS __bool_strings<wchar_t> {
417struct __bool_strings<wchar_t> {
418418 static constexpr wstring_view __true{L"true"};
419419 static constexpr wstring_view __false{L"false"};
420420};
lib/libcxx/include/__format/formatter_output.h-18
......@@ -45,24 +45,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4545
4646namespace __formatter {
4747
48_LIBCPP_HIDE_FROM_ABI constexpr char __hex_to_upper(char __c) {
49 switch (__c) {
50 case 'a':
51 return 'A';
52 case 'b':
53 return 'B';
54 case 'c':
55 return 'C';
56 case 'd':
57 return 'D';
58 case 'e':
59 return 'E';
60 case 'f':
61 return 'F';
62 }
63 return __c;
64}
65
6648struct _LIBCPP_EXPORTED_FROM_ABI __padding_size_result {
6749 size_t __before_;
6850 size_t __after_;
lib/libcxx/include/__format/formatter_pointer.h+4-4
......@@ -29,7 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2929#if _LIBCPP_STD_VER >= 20
3030
3131template <__fmt_char_type _CharT>
32struct _LIBCPP_TEMPLATE_VIS __formatter_pointer {
32struct __formatter_pointer {
3333public:
3434 template <class _ParseContext>
3535 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -59,11 +59,11 @@ public:
5959// - template<> struct formatter<void*, charT>;
6060// - template<> struct formatter<const void*, charT>;
6161template <__fmt_char_type _CharT>
62struct _LIBCPP_TEMPLATE_VIS formatter<nullptr_t, _CharT> : public __formatter_pointer<_CharT> {};
62struct formatter<nullptr_t, _CharT> : public __formatter_pointer<_CharT> {};
6363template <__fmt_char_type _CharT>
64struct _LIBCPP_TEMPLATE_VIS formatter<void*, _CharT> : public __formatter_pointer<_CharT> {};
64struct formatter<void*, _CharT> : public __formatter_pointer<_CharT> {};
6565template <__fmt_char_type _CharT>
66struct _LIBCPP_TEMPLATE_VIS formatter<const void*, _CharT> : public __formatter_pointer<_CharT> {};
66struct formatter<const void*, _CharT> : public __formatter_pointer<_CharT> {};
6767
6868# if _LIBCPP_STD_VER >= 23
6969template <>
lib/libcxx/include/__format/formatter_string.h+24-8
......@@ -10,6 +10,7 @@
1010#ifndef _LIBCPP___FORMAT_FORMATTER_STRING_H
1111#define _LIBCPP___FORMAT_FORMATTER_STRING_H
1212
13#include <__assert>
1314#include <__config>
1415#include <__format/concepts.h>
1516#include <__format/format_parse_context.h>
......@@ -17,6 +18,7 @@
1718#include <__format/formatter_output.h>
1819#include <__format/parser_std_format_spec.h>
1920#include <__format/write_escaped.h>
21#include <cstddef>
2022#include <string>
2123#include <string_view>
2224
......@@ -29,7 +31,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2931#if _LIBCPP_STD_VER >= 20
3032
3133template <__fmt_char_type _CharT>
32struct _LIBCPP_TEMPLATE_VIS __formatter_string {
34struct __formatter_string {
3335public:
3436 template <class _ParseContext>
3537 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
......@@ -58,7 +60,7 @@ public:
5860
5961// Formatter const char*.
6062template <__fmt_char_type _CharT>
61struct _LIBCPP_TEMPLATE_VIS formatter<const _CharT*, _CharT> : public __formatter_string<_CharT> {
63struct formatter<const _CharT*, _CharT> : public __formatter_string<_CharT> {
6264 using _Base _LIBCPP_NODEBUG = __formatter_string<_CharT>;
6365
6466 template <class _FormatContext>
......@@ -77,7 +79,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<const _CharT*, _CharT> : public __formatte
7779
7880// Formatter char*.
7981template <__fmt_char_type _CharT>
80struct _LIBCPP_TEMPLATE_VIS formatter<_CharT*, _CharT> : public formatter<const _CharT*, _CharT> {
82struct formatter<_CharT*, _CharT> : public formatter<const _CharT*, _CharT> {
8183 using _Base _LIBCPP_NODEBUG = formatter<const _CharT*, _CharT>;
8284
8385 template <class _FormatContext>
......@@ -88,20 +90,21 @@ struct _LIBCPP_TEMPLATE_VIS formatter<_CharT*, _CharT> : public formatter<const
8890
8991// Formatter char[].
9092template <__fmt_char_type _CharT, size_t _Size>
91struct _LIBCPP_TEMPLATE_VIS formatter<_CharT[_Size], _CharT> : public __formatter_string<_CharT> {
93struct formatter<_CharT[_Size], _CharT> : public __formatter_string<_CharT> {
9294 using _Base _LIBCPP_NODEBUG = __formatter_string<_CharT>;
9395
9496 template <class _FormatContext>
9597 _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator
9698 format(const _CharT (&__str)[_Size], _FormatContext& __ctx) const {
97 return _Base::format(basic_string_view<_CharT>(__str, _Size), __ctx);
99 const _CharT* const __pzero = char_traits<_CharT>::find(__str, _Size, _CharT{});
100 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__pzero != nullptr, "formatting a non-null-terminated array");
101 return _Base::format(basic_string_view<_CharT>(__str, static_cast<size_t>(__pzero - __str)), __ctx);
98102 }
99103};
100104
101105// Formatter std::string.
102106template <__fmt_char_type _CharT, class _Traits, class _Allocator>
103struct _LIBCPP_TEMPLATE_VIS formatter<basic_string<_CharT, _Traits, _Allocator>, _CharT>
104 : public __formatter_string<_CharT> {
107struct formatter<basic_string<_CharT, _Traits, _Allocator>, _CharT> : public __formatter_string<_CharT> {
105108 using _Base _LIBCPP_NODEBUG = __formatter_string<_CharT>;
106109
107110 template <class _FormatContext>
......@@ -114,7 +117,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<basic_string<_CharT, _Traits, _Allocator>,
114117
115118// Formatter std::string_view.
116119template <__fmt_char_type _CharT, class _Traits>
117struct _LIBCPP_TEMPLATE_VIS formatter<basic_string_view<_CharT, _Traits>, _CharT> : public __formatter_string<_CharT> {
120struct formatter<basic_string_view<_CharT, _Traits>, _CharT> : public __formatter_string<_CharT> {
118121 using _Base _LIBCPP_NODEBUG = __formatter_string<_CharT>;
119122
120123 template <class _FormatContext>
......@@ -125,6 +128,19 @@ struct _LIBCPP_TEMPLATE_VIS formatter<basic_string_view<_CharT, _Traits>, _CharT
125128 }
126129};
127130
131# if _LIBCPP_HAS_WIDE_CHARACTERS
132template <>
133struct formatter<char*, wchar_t> : __disabled_formatter {};
134template <>
135struct formatter<const char*, wchar_t> : __disabled_formatter {};
136template <size_t _Size>
137struct formatter<char[_Size], wchar_t> : __disabled_formatter {};
138template <class _Traits, class _Allocator>
139struct formatter<basic_string<char, _Traits, _Allocator>, wchar_t> : __disabled_formatter {};
140template <class _Traits>
141struct formatter<basic_string_view<char, _Traits>, wchar_t> : __disabled_formatter {};
142# endif // _LIBCPP_HAS_WIDE_CHARACTERS
143
128144# if _LIBCPP_STD_VER >= 23
129145template <>
130146inline constexpr bool enable_nonlocking_formatter_optimization<char*> = true;
lib/libcxx/include/__format/formatter_tuple.h+3-5
......@@ -36,7 +36,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3636#if _LIBCPP_STD_VER >= 23
3737
3838template <__fmt_char_type _CharT, class _Tuple, formattable<_CharT>... _Args>
39struct _LIBCPP_TEMPLATE_VIS __formatter_tuple {
39struct __formatter_tuple {
4040 _LIBCPP_HIDE_FROM_ABI constexpr void set_separator(basic_string_view<_CharT> __separator) noexcept {
4141 __separator_ = __separator;
4242 }
......@@ -136,12 +136,10 @@ private:
136136};
137137
138138template <__fmt_char_type _CharT, formattable<_CharT>... _Args>
139struct _LIBCPP_TEMPLATE_VIS formatter<pair<_Args...>, _CharT>
140 : public __formatter_tuple<_CharT, pair<_Args...>, _Args...> {};
139struct formatter<pair<_Args...>, _CharT> : public __formatter_tuple<_CharT, pair<_Args...>, _Args...> {};
141140
142141template <__fmt_char_type _CharT, formattable<_CharT>... _Args>
143struct _LIBCPP_TEMPLATE_VIS formatter<tuple<_Args...>, _CharT>
144 : public __formatter_tuple<_CharT, tuple<_Args...>, _Args...> {};
142struct formatter<tuple<_Args...>, _CharT> : public __formatter_tuple<_CharT, tuple<_Args...>, _Args...> {};
145143
146144#endif // _LIBCPP_STD_VER >= 23
147145
lib/libcxx/include/__format/indic_conjunct_break_table.h+257-55
......@@ -107,10 +107,9 @@ enum class __property : uint8_t {
107107/// following benchmark.
108108/// libcxx/benchmarks/std_format_spec_string_unicode.bench.cpp
109109// clang-format off
110_LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[201] = {
111 0x00180139,
112 0x001a807d,
113 0x00241811,
110_LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[403] = {
111 0x001801bd,
112 0x00241819,
114113 0x002c88b1,
115114 0x002df801,
116115 0x002e0805,
......@@ -125,6 +124,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[201] = {
125124 0x0037500d,
126125 0x00388801,
127126 0x00398069,
127 0x003d3029,
128128 0x003f5821,
129129 0x003fe801,
130130 0x0040b00d,
......@@ -132,87 +132,174 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[201] = {
132132 0x00412809,
133133 0x00414811,
134134 0x0042c809,
135 0x0044c01d,
135 0x0044b821,
136136 0x0046505d,
137 0x00471871,
137 0x0047187d,
138138 0x0048a890,
139 0x0049d001,
139140 0x0049e001,
141 0x004a081d,
140142 0x004a6802,
141 0x004a880d,
143 0x004a8819,
142144 0x004ac01c,
145 0x004b1005,
143146 0x004bc01c,
147 0x004c0801,
144148 0x004ca84c,
145149 0x004d5018,
146150 0x004d9000,
147151 0x004db00c,
148152 0x004de001,
153 0x004df001,
154 0x004e080d,
149155 0x004e6802,
156 0x004eb801,
150157 0x004ee004,
151158 0x004ef800,
159 0x004f1005,
152160 0x004f8004,
153161 0x004ff001,
162 0x00500805,
154163 0x0051e001,
164 0x00520805,
165 0x00523805,
166 0x00525809,
167 0x00528801,
168 0x00538005,
169 0x0053a801,
170 0x00540805,
155171 0x0054a84c,
156172 0x00555018,
157173 0x00559004,
158174 0x0055a810,
159175 0x0055e001,
176 0x00560811,
177 0x00563805,
160178 0x00566802,
179 0x00571005,
161180 0x0057c800,
181 0x0057d015,
182 0x00580801,
162183 0x0058a84c,
163184 0x00595018,
164185 0x00599004,
165186 0x0059a810,
166187 0x0059e001,
188 0x0059f005,
189 0x005a080d,
167190 0x005a6802,
191 0x005aa809,
168192 0x005ae004,
169193 0x005af800,
194 0x005b1005,
170195 0x005b8800,
196 0x005c1001,
197 0x005df001,
198 0x005e0001,
199 0x005e6801,
200 0x005eb801,
201 0x00600001,
202 0x00602001,
171203 0x0060a84c,
172204 0x0061503c,
173205 0x0061e001,
206 0x0061f009,
207 0x00623009,
208 0x00625009,
174209 0x00626802,
175210 0x0062a805,
176211 0x0062c008,
212 0x00631005,
213 0x00640801,
177214 0x0065e001,
215 0x0065f805,
216 0x00661001,
217 0x00663009,
218 0x0066500d,
219 0x0066a805,
220 0x00671005,
221 0x00680005,
178222 0x0068a894,
179223 0x0069d805,
224 0x0069f001,
225 0x006a080d,
180226 0x006a6802,
181 0x0071c009,
182 0x0072400d,
183 0x0075c009,
184 0x0076400d,
227 0x006ab801,
228 0x006b1005,
229 0x006c0801,
230 0x006e5001,
231 0x006e7801,
232 0x006e9009,
233 0x006eb001,
234 0x006ef801,
235 0x00718801,
236 0x0071a019,
237 0x0072381d,
238 0x00758801,
239 0x0075a021,
240 0x00764019,
185241 0x0078c005,
186242 0x0079a801,
187243 0x0079b801,
188244 0x0079c801,
189 0x007b8805,
190 0x007ba001,
191 0x007bd00d,
192 0x007c0001,
193 0x007c1009,
245 0x007b8835,
246 0x007c0011,
194247 0x007c3005,
248 0x007c6829,
249 0x007cc88d,
195250 0x007e3001,
196 0x0081b801,
251 0x0081680d,
252 0x00819015,
197253 0x0081c805,
254 0x0081e805,
255 0x0082c005,
256 0x0082f009,
257 0x0083880d,
258 0x00841001,
259 0x00842805,
198260 0x00846801,
261 0x0084e801,
199262 0x009ae809,
200 0x00b8a001,
201 0x00be9001,
263 0x00b8900d,
264 0x00b99009,
265 0x00ba9005,
266 0x00bb9005,
267 0x00bda005,
268 0x00bdb819,
269 0x00be3001,
270 0x00be4829,
202271 0x00bee801,
272 0x00c05809,
273 0x00c07801,
274 0x00c42805,
203275 0x00c54801,
276 0x00c90009,
277 0x00c93805,
278 0x00c99001,
204279 0x00c9c809,
205280 0x00d0b805,
281 0x00d0d801,
282 0x00d2b001,
283 0x00d2c019,
206284 0x00d30001,
207 0x00d3a81d,
285 0x00d31001,
286 0x00d3281d,
287 0x00d39825,
208288 0x00d3f801,
209 0x00d58035,
210 0x00d5f83d,
211 0x00d9a001,
289 0x00d58079,
290 0x00d8000d,
291 0x00d9a025,
292 0x00da1009,
212293 0x00db5821,
213 0x00dd5801,
294 0x00dc0005,
295 0x00dd100d,
296 0x00dd4015,
214297 0x00df3001,
215 0x00e1b801,
298 0x00df4005,
299 0x00df6801,
300 0x00df7811,
301 0x00e1601d,
302 0x00e1b005,
216303 0x00e68009,
217304 0x00e6a031,
218305 0x00e71019,
......@@ -221,82 +308,193 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[201] = {
221308 0x00e7c005,
222309 0x00ee00fd,
223310 0x01006801,
224 0x01068031,
225 0x01070801,
226 0x0107282d,
311 0x01068081,
227312 0x01677809,
228313 0x016bf801,
229314 0x016f007d,
230315 0x01815015,
231316 0x0184c805,
232 0x05337801,
317 0x0533780d,
233318 0x0533a025,
234319 0x0534f005,
235320 0x05378005,
321 0x05401001,
322 0x05403001,
323 0x05405801,
324 0x05412805,
236325 0x05416001,
326 0x05462005,
237327 0x05470045,
238 0x05495809,
328 0x0547f801,
329 0x0549301d,
330 0x054a3829,
331 0x054a9801,
332 0x054c0009,
239333 0x054d9801,
334 0x054db00d,
335 0x054de005,
336 0x054e0001,
337 0x054f2801,
338 0x05514815,
339 0x05518805,
340 0x0551a805,
341 0x05521801,
342 0x05526001,
343 0x0553e001,
240344 0x05558001,
241345 0x05559009,
242346 0x0555b805,
243347 0x0555f005,
244348 0x05560801,
349 0x05576005,
245350 0x0557b001,
351 0x055f2801,
352 0x055f4001,
246353 0x055f6801,
247354 0x07d8f001,
355 0x07f0003d,
248356 0x07f1003d,
357 0x07fcf005,
249358 0x080fe801,
250359 0x08170001,
251360 0x081bb011,
252 0x08506801,
253 0x08507801,
361 0x08500809,
362 0x08502805,
363 0x0850600d,
254364 0x0851c009,
255365 0x0851f801,
256366 0x08572805,
257367 0x0869200d,
368 0x086b4811,
258369 0x08755805,
259 0x0877e809,
370 0x0877e00d,
260371 0x087a3029,
261372 0x087c100d,
373 0x08800801,
374 0x0881c039,
262375 0x08838001,
263 0x0883f801,
264 0x0885d001,
376 0x08839805,
377 0x0883f809,
378 0x0885980d,
379 0x0885c805,
380 0x08861001,
265381 0x08880009,
266 0x08899805,
382 0x08893811,
383 0x0889681d,
267384 0x088b9801,
268 0x088e5001,
269 0x0891b001,
270 0x08974805,
385 0x088c0005,
386 0x088db021,
387 0x088e0001,
388 0x088e480d,
389 0x088e7801,
390 0x08917809,
391 0x0891a00d,
392 0x0891f001,
393 0x08920801,
394 0x0896f801,
395 0x0897181d,
396 0x08980005,
271397 0x0899d805,
398 0x0899f001,
399 0x089a0001,
400 0x089a6801,
401 0x089ab801,
272402 0x089b3019,
273403 0x089b8011,
404 0x089dc001,
405 0x089dd815,
406 0x089e1001,
407 0x089e2801,
408 0x089e3809,
409 0x089e7009,
410 0x089e9001,
411 0x089f0805,
412 0x08a1c01d,
413 0x08a21009,
274414 0x08a23001,
275415 0x08a2f001,
276 0x08a61801,
277 0x08ae0001,
278 0x08b5b801,
279 0x08b95801,
280 0x08c1d001,
281 0x08c9f001,
416 0x08a58001,
417 0x08a59815,
418 0x08a5d001,
419 0x08a5e801,
420 0x08a5f805,
421 0x08a61005,
422 0x08ad7801,
423 0x08ad900d,
424 0x08ade005,
425 0x08adf805,
426 0x08aee005,
427 0x08b1981d,
428 0x08b1e801,
429 0x08b1f805,
430 0x08b55801,
431 0x08b56801,
432 0x08b5801d,
433 0x08b8e801,
434 0x08b8f801,
435 0x08b9100d,
436 0x08b93811,
437 0x08c17821,
438 0x08c1c805,
439 0x08c98001,
440 0x08c9d80d,
282441 0x08ca1801,
283 0x08d1a001,
442 0x08cea00d,
443 0x08ced005,
444 0x08cf0001,
445 0x08d00825,
446 0x08d19815,
447 0x08d1d80d,
284448 0x08d23801,
285 0x08d4c801,
286 0x08ea1001,
287 0x08ea2005,
449 0x08d28815,
450 0x08d2c809,
451 0x08d45031,
452 0x08d4c005,
453 0x08e18019,
454 0x08e1c015,
455 0x08e1f801,
456 0x08e49055,
457 0x08e55019,
458 0x08e59005,
459 0x08e5a805,
460 0x08e98815,
461 0x08e9d001,
462 0x08e9e005,
463 0x08e9f819,
464 0x08ea3801,
465 0x08ec8005,
466 0x08eca801,
288467 0x08ecb801,
289 0x08fa1001,
468 0x08f79805,
469 0x08f80005,
470 0x08f9b011,
471 0x08fa0009,
472 0x08fad001,
473 0x09a20001,
474 0x09a23839,
475 0x0b08f02d,
476 0x0b096809,
290477 0x0b578011,
291478 0x0b598019,
292 0x0de4f001,
293 0x0e8b2801,
294 0x0e8b3809,
295 0x0e8b7011,
479 0x0b7a7801,
480 0x0b7c780d,
481 0x0b7f2001,
482 0x0b7f8005,
483 0x0de4e805,
484 0x0e7800b5,
485 0x0e798059,
486 0x0e8b2811,
487 0x0e8b6815,
296488 0x0e8bd81d,
297489 0x0e8c2819,
298490 0x0e8d500d,
299491 0x0e921009,
492 0x0ed000d9,
493 0x0ed1d8c5,
494 0x0ed3a801,
495 0x0ed42001,
496 0x0ed4d811,
497 0x0ed50839,
300498 0x0f000019,
301499 0x0f004041,
302500 0x0f00d819,
......@@ -307,8 +505,12 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[201] = {
307505 0x0f157001,
308506 0x0f17600d,
309507 0x0f27600d,
508 0x0f2f7005,
310509 0x0f468019,
311 0x0f4a2019};
510 0x0f4a2019,
511 0x0f9fd811,
512 0x7001017d,
513 0x700803bd};
312514// clang-format on
313515
314516/// Returns the indic conjuct break property of a code point.
lib/libcxx/include/__format/parser_std_format_spec.h+1-1
......@@ -335,7 +335,7 @@ static_assert(is_trivially_copyable_v<__parsed_specifications<wchar_t>>);
335335/// set to zero. That way they can be repurposed if a future revision of the
336336/// Standards adds new fields to std-format-spec.
337337template <class _CharT>
338class _LIBCPP_TEMPLATE_VIS __parser {
338class __parser {
339339public:
340340 // Parses the format specification.
341341 //
lib/libcxx/include/__format/range_default_formatter.h+7-7
......@@ -52,7 +52,7 @@ _LIBCPP_DIAGNOSTIC_POP
5252// There is no definition of this struct, it's purely intended to be used to
5353// generate diagnostics.
5454template <class _Rp>
55struct _LIBCPP_TEMPLATE_VIS __instantiated_the_primary_template_of_format_kind;
55struct __instantiated_the_primary_template_of_format_kind;
5656
5757template <class _Rp>
5858constexpr range_format format_kind = [] {
......@@ -88,12 +88,12 @@ inline constexpr range_format format_kind<_Rp> = [] {
8888}();
8989
9090template <range_format _Kp, ranges::input_range _Rp, class _CharT>
91struct _LIBCPP_TEMPLATE_VIS __range_default_formatter;
91struct __range_default_formatter;
9292
9393// Required specializations
9494
9595template <ranges::input_range _Rp, class _CharT>
96struct _LIBCPP_TEMPLATE_VIS __range_default_formatter<range_format::sequence, _Rp, _CharT> {
96struct __range_default_formatter<range_format::sequence, _Rp, _CharT> {
9797private:
9898 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_;
......@@ -120,7 +120,7 @@ public:
120120};
121121
122122template <ranges::input_range _Rp, class _CharT>
123struct _LIBCPP_TEMPLATE_VIS __range_default_formatter<range_format::map, _Rp, _CharT> {
123struct __range_default_formatter<range_format::map, _Rp, _CharT> {
124124private:
125125 using __maybe_const_map _LIBCPP_NODEBUG = __fmt_maybe_const<_Rp, _CharT>;
126126 using __element_type _LIBCPP_NODEBUG = remove_cvref_t<ranges::range_reference_t<__maybe_const_map>>;
......@@ -148,7 +148,7 @@ public:
148148};
149149
150150template <ranges::input_range _Rp, class _CharT>
151struct _LIBCPP_TEMPLATE_VIS __range_default_formatter<range_format::set, _Rp, _CharT> {
151struct __range_default_formatter<range_format::set, _Rp, _CharT> {
152152private:
153153 using __maybe_const_set _LIBCPP_NODEBUG = __fmt_maybe_const<_Rp, _CharT>;
154154 using __element_type _LIBCPP_NODEBUG = remove_cvref_t<ranges::range_reference_t<__maybe_const_set>>;
......@@ -173,7 +173,7 @@ public:
173173
174174template <range_format _Kp, ranges::input_range _Rp, class _CharT>
175175 requires(_Kp == range_format::string || _Kp == range_format::debug_string)
176struct _LIBCPP_TEMPLATE_VIS __range_default_formatter<_Kp, _Rp, _CharT> {
176struct __range_default_formatter<_Kp, _Rp, _CharT> {
177177private:
178178 // This deviates from the Standard, there the exposition only type is
179179 // formatter<basic_string<charT>, charT> underlying_;
......@@ -205,7 +205,7 @@ public:
205205
206206template <ranges::input_range _Rp, class _CharT>
207207 requires(format_kind<_Rp> != range_format::disabled && formattable<ranges::range_reference_t<_Rp>, _CharT>)
208struct _LIBCPP_TEMPLATE_VIS formatter<_Rp, _CharT> : __range_default_formatter<format_kind<_Rp>, _Rp, _CharT> {};
208struct formatter<_Rp, _CharT> : __range_default_formatter<format_kind<_Rp>, _Rp, _CharT> {};
209209
210210#endif // _LIBCPP_STD_VER >= 23
211211
lib/libcxx/include/__format/range_formatter.h+1-1
......@@ -39,7 +39,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3939
4040template <class _Tp, class _CharT = char>
4141 requires same_as<remove_cvref_t<_Tp>, _Tp> && formattable<_Tp, _CharT>
42struct _LIBCPP_TEMPLATE_VIS range_formatter {
42struct range_formatter {
4343 _LIBCPP_HIDE_FROM_ABI constexpr void set_separator(basic_string_view<_CharT> __separator) noexcept {
4444 __separator_ = __separator;
4545 }
lib/libcxx/include/__format/width_estimation_table.h+11-8
......@@ -119,7 +119,7 @@ namespace __width_estimation_table {
119119/// - bits [0, 13] The size of the range, allowing 16384 elements.
120120/// - bits [14, 31] The lower bound code point of the range. The upper bound of
121121/// the range is lower bound + size.
122_LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[107] = {
122_LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[110] = {
123123 0x0440005f /* 00001100 - 0000115f [ 96] */, //
124124 0x08c68001 /* 0000231a - 0000231b [ 2] */, //
125125 0x08ca4001 /* 00002329 - 0000232a [ 2] */, //
......@@ -128,8 +128,10 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[107] = {
128128 0x08fcc000 /* 000023f3 - 000023f3 [ 1] */, //
129129 0x097f4001 /* 000025fd - 000025fe [ 2] */, //
130130 0x09850001 /* 00002614 - 00002615 [ 2] */, //
131 0x098c0007 /* 00002630 - 00002637 [ 8] */, //
131132 0x0992000b /* 00002648 - 00002653 [ 12] */, //
132133 0x099fc000 /* 0000267f - 0000267f [ 1] */, //
134 0x09a28005 /* 0000268a - 0000268f [ 6] */, //
133135 0x09a4c000 /* 00002693 - 00002693 [ 1] */, //
134136 0x09a84000 /* 000026a1 - 000026a1 [ 1] */, //
135137 0x09aa8001 /* 000026aa - 000026ab [ 2] */, //
......@@ -163,7 +165,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[107] = {
163165 0x0c264066 /* 00003099 - 000030ff [ 103] */, //
164166 0x0c41402a /* 00003105 - 0000312f [ 43] */, //
165167 0x0c4c405d /* 00003131 - 0000318e [ 94] */, //
166 0x0c640053 /* 00003190 - 000031e3 [ 84] */, //
168 0x0c640055 /* 00003190 - 000031e5 [ 86] */, //
167169 0x0c7bc02f /* 000031ef - 0000321e [ 48] */, //
168170 0x0c880027 /* 00003220 - 00003247 [ 40] */, //
169171 0x0c943fff /* 00003250 - 0000724f [16384] */, //
......@@ -182,7 +184,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[107] = {
182184 0x5bfc0001 /* 00016ff0 - 00016ff1 [ 2] */, //
183185 0x5c0017f7 /* 00017000 - 000187f7 [ 6136] */, //
184186 0x620004d5 /* 00018800 - 00018cd5 [ 1238] */, //
185 0x63400008 /* 00018d00 - 00018d08 [ 9] */, //
187 0x633fc009 /* 00018cff - 00018d08 [ 10] */, //
186188 0x6bfc0003 /* 0001aff0 - 0001aff3 [ 4] */, //
187189 0x6bfd4006 /* 0001aff5 - 0001affb [ 7] */, //
188190 0x6bff4001 /* 0001affd - 0001affe [ 2] */, //
......@@ -192,6 +194,8 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[107] = {
192194 0x6c554000 /* 0001b155 - 0001b155 [ 1] */, //
193195 0x6c590003 /* 0001b164 - 0001b167 [ 4] */, //
194196 0x6c5c018b /* 0001b170 - 0001b2fb [ 396] */, //
197 0x74c00056 /* 0001d300 - 0001d356 [ 87] */, //
198 0x74d80016 /* 0001d360 - 0001d376 [ 23] */, //
195199 0x7c010000 /* 0001f004 - 0001f004 [ 1] */, //
196200 0x7c33c000 /* 0001f0cf - 0001f0cf [ 1] */, //
197201 0x7c638000 /* 0001f18e - 0001f18e [ 1] */, //
......@@ -213,11 +217,10 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[107] = {
213217 0x7dfc0000 /* 0001f7f0 - 0001f7f0 [ 1] */, //
214218 0x7e4000ff /* 0001f900 - 0001f9ff [ 256] */, //
215219 0x7e9c000c /* 0001fa70 - 0001fa7c [ 13] */, //
216 0x7ea00008 /* 0001fa80 - 0001fa88 [ 9] */, //
217 0x7ea4002d /* 0001fa90 - 0001fabd [ 46] */, //
218 0x7eafc006 /* 0001fabf - 0001fac5 [ 7] */, //
219 0x7eb3800d /* 0001face - 0001fadb [ 14] */, //
220 0x7eb80008 /* 0001fae0 - 0001fae8 [ 9] */, //
220 0x7ea00009 /* 0001fa80 - 0001fa89 [ 10] */, //
221 0x7ea3c037 /* 0001fa8f - 0001fac6 [ 56] */, //
222 0x7eb3800e /* 0001face - 0001fadc [ 15] */, //
223 0x7eb7c00a /* 0001fadf - 0001fae9 [ 11] */, //
221224 0x7ebc0008 /* 0001faf0 - 0001faf8 [ 9] */, //
222225 0x80003fff /* 00020000 - 00023fff [16384] */, //
223226 0x90003fff /* 00024000 - 00027fff [16384] */, //
lib/libcxx/include/__functional/binary_function.h+3-4
......@@ -21,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION)
2222
2323template <class _Arg1, class _Arg2, class _Result>
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binary_function {
24struct _LIBCPP_DEPRECATED_IN_CXX11 binary_function {
2525 typedef _Arg1 first_argument_type;
2626 typedef _Arg2 second_argument_type;
2727 typedef _Result result_type;
......@@ -39,11 +39,10 @@ struct __binary_function_keep_layout_base {
3939};
4040
4141#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION)
42_LIBCPP_DIAGNOSTIC_PUSH
43_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
42_LIBCPP_SUPPRESS_DEPRECATED_PUSH
4443template <class _Arg1, class _Arg2, class _Result>
4544using __binary_function _LIBCPP_NODEBUG = binary_function<_Arg1, _Arg2, _Result>;
46_LIBCPP_DIAGNOSTIC_POP
45_LIBCPP_SUPPRESS_DEPRECATED_POP
4746#else
4847template <class _Arg1, class _Arg2, class _Result>
4948using __binary_function _LIBCPP_NODEBUG = __binary_function_keep_layout_base<_Arg1, _Arg2, _Result>;
lib/libcxx/include/__functional/binary_negate.h+1-1
......@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
2323
2424template <class _Predicate>
25class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate
25class _LIBCPP_DEPRECATED_IN_CXX17 binary_negate
2626 : public __binary_function<typename _Predicate::first_argument_type,
2727 typename _Predicate::second_argument_type,
2828 bool> {
lib/libcxx/include/__functional/bind.h+3-3
......@@ -130,7 +130,7 @@ struct __mu_return_invokable // false
130130
131131template <class _Ti, class... _Uj>
132132struct __mu_return_invokable<true, _Ti, _Uj...> {
133 using type = __invoke_result_t<_Ti&, _Uj...>;
133 using type _LIBCPP_NODEBUG = __invoke_result_t<_Ti&, _Uj...>;
134134};
135135
136136template <class _Ti, class... _Uj>
......@@ -181,12 +181,12 @@ struct __bind_return;
181181
182182template <class _Fp, class... _BoundArgs, class _TupleUj>
183183struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> {
184 using type = __invoke_result_t< _Fp&, typename __mu_return< _BoundArgs, _TupleUj >::type... >;
184 using type _LIBCPP_NODEBUG = __invoke_result_t<_Fp&, typename __mu_return<_BoundArgs, _TupleUj>::type...>;
185185};
186186
187187template <class _Fp, class... _BoundArgs, class _TupleUj>
188188struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> {
189 using type = __invoke_result_t< _Fp&, typename __mu_return< const _BoundArgs, _TupleUj >::type... >;
189 using type _LIBCPP_NODEBUG = __invoke_result_t<_Fp&, typename __mu_return<const _BoundArgs, _TupleUj>::type...>;
190190};
191191
192192template <class _Fp, class _BoundArgs, size_t... _Indx, class _Args>
lib/libcxx/include/__functional/binder1st.h+1-1
......@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
2323
2424template <class _Operation>
25class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st
25class _LIBCPP_DEPRECATED_IN_CXX11 binder1st
2626 : public __unary_function<typename _Operation::second_argument_type, typename _Operation::result_type> {
2727protected:
2828 _Operation op;
lib/libcxx/include/__functional/binder2nd.h+1-1
......@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
2323
2424template <class _Operation>
25class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
25class _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
2626 : public __unary_function<typename _Operation::first_argument_type, typename _Operation::result_type> {
2727protected:
2828 _Operation op;
lib/libcxx/include/__functional/boyer_moore_searcher.h+7-9
......@@ -17,12 +17,10 @@
1717#include <__config>
1818#include <__functional/hash.h>
1919#include <__functional/operations.h>
20#include <__iterator/distance.h>
2120#include <__iterator/iterator_traits.h>
2221#include <__memory/shared_ptr.h>
2322#include <__type_traits/make_unsigned.h>
2423#include <__utility/pair.h>
25#include <__vector/vector.h>
2624#include <array>
2725#include <limits>
2826#include <unordered_map>
......@@ -88,7 +86,7 @@ public:
8886template <class _RandomAccessIterator1,
8987 class _Hash = hash<typename iterator_traits<_RandomAccessIterator1>::value_type>,
9088 class _BinaryPredicate = equal_to<>>
91class _LIBCPP_TEMPLATE_VIS boyer_moore_searcher {
89class boyer_moore_searcher {
9290private:
9391 using difference_type = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
9492 using value_type = typename std::iterator_traits<_RandomAccessIterator1>::value_type;
......@@ -125,8 +123,8 @@ public:
125123 template <class _RandomAccessIterator2>
126124 _LIBCPP_HIDE_FROM_ABI pair<_RandomAccessIterator2, _RandomAccessIterator2>
127125 operator()(_RandomAccessIterator2 __first, _RandomAccessIterator2 __last) const {
128 static_assert(__is_same_uncvref<typename iterator_traits<_RandomAccessIterator1>::value_type,
129 typename iterator_traits<_RandomAccessIterator2>::value_type>::value,
126 static_assert(is_same_v<__remove_cvref_t<typename iterator_traits<_RandomAccessIterator1>::value_type>,
127 __remove_cvref_t<typename iterator_traits<_RandomAccessIterator2>::value_type>>,
130128 "Corpus and Pattern iterators must point to the same type");
131129 if (__first == __last)
132130 return std::make_pair(__last, __last);
......@@ -196,7 +194,7 @@ private:
196194 if (__count == 0)
197195 return;
198196
199 vector<difference_type> __scratch(__count);
197 auto __scratch = std::make_unique<difference_type[]>(__count);
200198
201199 __compute_bm_prefix(__first, __last, __pred, __scratch);
202200 for (size_t __i = 0; __i <= __count; ++__i)
......@@ -219,7 +217,7 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(boyer_moore_searcher);
219217template <class _RandomAccessIterator1,
220218 class _Hash = hash<typename iterator_traits<_RandomAccessIterator1>::value_type>,
221219 class _BinaryPredicate = equal_to<>>
222class _LIBCPP_TEMPLATE_VIS boyer_moore_horspool_searcher {
220class boyer_moore_horspool_searcher {
223221private:
224222 using difference_type = typename iterator_traits<_RandomAccessIterator1>::difference_type;
225223 using value_type = typename iterator_traits<_RandomAccessIterator1>::value_type;
......@@ -256,8 +254,8 @@ public:
256254 template <class _RandomAccessIterator2>
257255 _LIBCPP_HIDE_FROM_ABI pair<_RandomAccessIterator2, _RandomAccessIterator2>
258256 operator()(_RandomAccessIterator2 __first, _RandomAccessIterator2 __last) const {
259 static_assert(__is_same_uncvref<typename std::iterator_traits<_RandomAccessIterator1>::value_type,
260 typename std::iterator_traits<_RandomAccessIterator2>::value_type>::value,
257 static_assert(is_same_v<__remove_cvref_t<typename std::iterator_traits<_RandomAccessIterator1>::value_type>,
258 __remove_cvref_t<typename std::iterator_traits<_RandomAccessIterator2>::value_type>>,
261259 "Corpus and Pattern iterators must point to the same type");
262260 if (__first == __last)
263261 return std::make_pair(__last, __last);
lib/libcxx/include/__functional/default_searcher.h+1-1
......@@ -27,7 +27,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2727
2828// default searcher
2929template <class _ForwardIterator, class _BinaryPredicate = equal_to<>>
30class _LIBCPP_TEMPLATE_VIS default_searcher {
30class default_searcher {
3131public:
3232 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
3333 default_searcher(_ForwardIterator __f, _ForwardIterator __l, _BinaryPredicate __p = _BinaryPredicate())
lib/libcxx/include/__functional/function.h+78-301
......@@ -17,13 +17,7 @@
1717#include <__functional/binary_function.h>
1818#include <__functional/invoke.h>
1919#include <__functional/unary_function.h>
20#include <__iterator/iterator_traits.h>
2120#include <__memory/addressof.h>
22#include <__memory/allocator.h>
23#include <__memory/allocator_destructor.h>
24#include <__memory/allocator_traits.h>
25#include <__memory/compressed_pair.h>
26#include <__memory/unique_ptr.h>
2721#include <__type_traits/aligned_storage.h>
2822#include <__type_traits/decay.h>
2923#include <__type_traits/is_core_convertible.h>
......@@ -34,9 +28,7 @@
3428#include <__type_traits/strip_signature.h>
3529#include <__utility/forward.h>
3630#include <__utility/move.h>
37#include <__utility/piecewise_construct.h>
3831#include <__utility/swap.h>
39#include <__verbose_abort>
4032#include <tuple>
4133#include <typeinfo>
4234
......@@ -71,7 +63,7 @@ public:
7163 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~bad_function_call() _NOEXCEPT override {}
7264# endif
7365
74# ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
66# if _LIBCPP_AVAILABILITY_HAS_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
7567 const char* what() const _NOEXCEPT override;
7668# endif
7769};
......@@ -86,7 +78,7 @@ _LIBCPP_DIAGNOSTIC_POP
8678}
8779
8880template <class _Fp>
89class _LIBCPP_TEMPLATE_VIS function; // undefined
81class function; // undefined
9082
9183namespace __function {
9284
......@@ -122,7 +114,7 @@ _LIBCPP_HIDE_FROM_ABI bool __not_null(function<_Fp> const& __f) {
122114 return !!__f;
123115}
124116
125# if _LIBCPP_HAS_EXTENSION_BLOCKS
117# if __has_extension(blocks)
126118template <class _Rp, class... _Args>
127119_LIBCPP_HIDE_FROM_ABI bool __not_null(_Rp (^__p)(_Args...)) {
128120 return __p;
......@@ -133,108 +125,10 @@ _LIBCPP_HIDE_FROM_ABI bool __not_null(_Rp (^__p)(_Args...)) {
133125
134126namespace __function {
135127
136// __alloc_func holds a functor and an allocator.
137
138template <class _Fp, class _Ap, class _FB>
139class __alloc_func;
140template <class _Fp, class _FB>
141class __default_alloc_func;
142
143template <class _Fp, class _Ap, class _Rp, class... _ArgTypes>
144class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> {
145 _LIBCPP_COMPRESSED_PAIR(_Fp, __func_, _Ap, __alloc_);
146
147public:
148 using _Target _LIBCPP_NODEBUG = _Fp;
149 using _Alloc _LIBCPP_NODEBUG = _Ap;
150
151 _LIBCPP_HIDE_FROM_ABI const _Target& __target() const { return __func_; }
152
153 // WIN32 APIs may define __allocator, so use __get_allocator instead.
154 _LIBCPP_HIDE_FROM_ABI const _Alloc& __get_allocator() const { return __alloc_; }
155
156 _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(_Target&& __f) : __func_(std::move(__f)), __alloc_() {}
157
158 _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(const _Target& __f, const _Alloc& __a) : __func_(__f), __alloc_(__a) {}
159
160 _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(const _Target& __f, _Alloc&& __a)
161 : __func_(__f), __alloc_(std::move(__a)) {}
162
163 _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(_Target&& __f, _Alloc&& __a)
164 : __func_(std::move(__f)), __alloc_(std::move(__a)) {}
165
166 _LIBCPP_HIDE_FROM_ABI _Rp operator()(_ArgTypes&&... __arg) {
167 return std::__invoke_r<_Rp>(__func_, std::forward<_ArgTypes>(__arg)...);
168 }
169
170 _LIBCPP_HIDE_FROM_ABI __alloc_func* __clone() const {
171 typedef allocator_traits<_Alloc> __alloc_traits;
172 typedef __rebind_alloc<__alloc_traits, __alloc_func> _AA;
173 _AA __a(__alloc_);
174 typedef __allocator_destructor<_AA> _Dp;
175 unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
176 ::new ((void*)__hold.get()) __alloc_func(__func_, _Alloc(__a));
177 return __hold.release();
178 }
179
180 _LIBCPP_HIDE_FROM_ABI void destroy() _NOEXCEPT {
181 __func_.~_Fp();
182 __alloc_.~_Alloc();
183 }
184
185 _LIBCPP_HIDE_FROM_ABI static void __destroy_and_delete(__alloc_func* __f) {
186 typedef allocator_traits<_Alloc> __alloc_traits;
187 typedef __rebind_alloc<__alloc_traits, __alloc_func> _FunAlloc;
188 _FunAlloc __a(__f->__get_allocator());
189 __f->destroy();
190 __a.deallocate(__f, 1);
191 }
192};
193
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
201template <class _Fp, class _Rp, class... _ArgTypes>
202class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> {
203 _Fp __f_;
204
205public:
206 using _Target _LIBCPP_NODEBUG = _Fp;
207
208 _LIBCPP_HIDE_FROM_ABI const _Target& __target() const { return __f_; }
209
210 _LIBCPP_HIDE_FROM_ABI explicit __default_alloc_func(_Target&& __f) : __f_(std::move(__f)) {}
211
212 _LIBCPP_HIDE_FROM_ABI explicit __default_alloc_func(const _Target& __f) : __f_(__f) {}
213
214 _LIBCPP_HIDE_FROM_ABI _Rp operator()(_ArgTypes&&... __arg) {
215 return std::__invoke_r<_Rp>(__f_, std::forward<_ArgTypes>(__arg)...);
216 }
217
218 _LIBCPP_HIDE_FROM_ABI __default_alloc_func* __clone() const {
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_);
222 (void)__hold.release();
223 return __res;
224 }
225
226 _LIBCPP_HIDE_FROM_ABI void destroy() _NOEXCEPT { __f_.~_Target(); }
227
228 _LIBCPP_HIDE_FROM_ABI static void __destroy_and_delete(__default_alloc_func* __f) {
229 __f->destroy();
230 std::__libcpp_deallocate<__default_alloc_func>(__f, __element_count(1));
231 }
232};
233
234128// __base provides an abstract interface for copyable functors.
235129
236130template <class _Fp>
237class _LIBCPP_TEMPLATE_VIS __base;
131class __base;
238132
239133template <class _Rp, class... _ArgTypes>
240134class __base<_Rp(_ArgTypes...)> {
......@@ -257,84 +151,38 @@ public:
257151
258152// __func implements __base for a given functor type.
259153
260template <class _FD, class _Alloc, class _FB>
154template <class _FD, class _FB>
261155class __func;
262156
263template <class _Fp, class _Alloc, class _Rp, class... _ArgTypes>
264class __func<_Fp, _Alloc, _Rp(_ArgTypes...)> : public __base<_Rp(_ArgTypes...)> {
265 __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_;
157template <class _Fp, class _Rp, class... _ArgTypes>
158class __func<_Fp, _Rp(_ArgTypes...)> : public __base<_Rp(_ArgTypes...)> {
159 _Fp __func_;
266160
267161public:
268 _LIBCPP_HIDE_FROM_ABI explicit __func(_Fp&& __f) : __f_(std::move(__f)) {}
162 _LIBCPP_HIDE_FROM_ABI explicit __func(_Fp&& __f) : __func_(std::move(__f)) {}
163 _LIBCPP_HIDE_FROM_ABI explicit __func(const _Fp& __f) : __func_(__f) {}
269164
270 _LIBCPP_HIDE_FROM_ABI explicit __func(const _Fp& __f, const _Alloc& __a) : __f_(__f, __a) {}
165 _LIBCPP_HIDE_FROM_ABI_VIRTUAL __base<_Rp(_ArgTypes...)>* __clone() const override { return new __func(__func_); }
271166
272 _LIBCPP_HIDE_FROM_ABI explicit __func(const _Fp& __f, _Alloc&& __a) : __f_(__f, std::move(__a)) {}
273
274 _LIBCPP_HIDE_FROM_ABI explicit __func(_Fp&& __f, _Alloc&& __a) : __f_(std::move(__f), std::move(__a)) {}
167 _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __clone(__base<_Rp(_ArgTypes...)>* __p) const override {
168 ::new ((void*)__p) __func(__func_);
169 }
275170
276 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual __base<_Rp(_ArgTypes...)>* __clone() const;
277 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
278 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy() _NOEXCEPT;
279 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy_deallocate() _NOEXCEPT;
280 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual _Rp operator()(_ArgTypes&&... __arg);
171 _LIBCPP_HIDE_FROM_ABI_VIRTUAL void destroy() _NOEXCEPT override { __func_.~_Fp(); }
172 _LIBCPP_HIDE_FROM_ABI_VIRTUAL void destroy_deallocate() _NOEXCEPT override { delete this; }
173 _LIBCPP_HIDE_FROM_ABI_VIRTUAL _Rp operator()(_ArgTypes&&... __arg) override {
174 return std::__invoke_r<_Rp>(__func_, std::forward<_ArgTypes>(__arg)...);
175 }
281176# if _LIBCPP_HAS_RTTI
282 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual const void* target(const type_info&) const _NOEXCEPT;
283 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual const std::type_info& target_type() const _NOEXCEPT;
177 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const void* target(const type_info& __ti) const _NOEXCEPT override {
178 if (__ti == typeid(_Fp))
179 return std::addressof(__func_);
180 return nullptr;
181 }
182 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const std::type_info& target_type() const _NOEXCEPT override { return typeid(_Fp); }
284183# endif // _LIBCPP_HAS_RTTI
285184};
286185
287template <class _Fp, class _Alloc, class _Rp, class... _ArgTypes>
288__base<_Rp(_ArgTypes...)>* __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const {
289 typedef allocator_traits<_Alloc> __alloc_traits;
290 typedef __rebind_alloc<__alloc_traits, __func> _Ap;
291 _Ap __a(__f_.__get_allocator());
292 typedef __allocator_destructor<_Ap> _Dp;
293 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
294 ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a));
295 return __hold.release();
296}
297
298template <class _Fp, class _Alloc, class _Rp, class... _ArgTypes>
299void __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const {
300 ::new ((void*)__p) __func(__f_.__target(), __f_.__get_allocator());
301}
302
303template <class _Fp, class _Alloc, class _Rp, class... _ArgTypes>
304void __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT {
305 __f_.destroy();
306}
307
308template <class _Fp, class _Alloc, class _Rp, class... _ArgTypes>
309void __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT {
310 typedef allocator_traits<_Alloc> __alloc_traits;
311 typedef __rebind_alloc<__alloc_traits, __func> _Ap;
312 _Ap __a(__f_.__get_allocator());
313 __f_.destroy();
314 __a.deallocate(this, 1);
315}
316
317template <class _Fp, class _Alloc, class _Rp, class... _ArgTypes>
318_Rp __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&&... __arg) {
319 return __f_(std::forward<_ArgTypes>(__arg)...);
320}
321
322# if _LIBCPP_HAS_RTTI
323
324template <class _Fp, class _Alloc, class _Rp, class... _ArgTypes>
325const void* __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT {
326 if (__ti == typeid(_Fp))
327 return std::addressof(__f_.__target());
328 return nullptr;
329}
330
331template <class _Fp, class _Alloc, class _Rp, class... _ArgTypes>
332const std::type_info& __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT {
333 return typeid(_Fp);
334}
335
336# endif // _LIBCPP_HAS_RTTI
337
338186// __value_func creates a value-type from a __func.
339187
340188template <class _Fp>
......@@ -354,29 +202,19 @@ class __value_func<_Rp(_ArgTypes...)> {
354202public:
355203 _LIBCPP_HIDE_FROM_ABI __value_func() _NOEXCEPT : __f_(nullptr) {}
356204
357 template <class _Fp, class _Alloc>
358 _LIBCPP_HIDE_FROM_ABI __value_func(_Fp&& __f, const _Alloc& __a) : __f_(nullptr) {
359 typedef allocator_traits<_Alloc> __alloc_traits;
360 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
361 typedef __rebind_alloc<__alloc_traits, _Fun> _FunAlloc;
205 template <class _Fp, __enable_if_t<!is_same<__decay_t<_Fp>, __value_func>::value, int> = 0>
206 _LIBCPP_HIDE_FROM_ABI explicit __value_func(_Fp&& __f) : __f_(nullptr) {
207 typedef __function::__func<_Fp, _Rp(_ArgTypes...)> _Fun;
362208
363209 if (__function::__not_null(__f)) {
364 _FunAlloc __af(__a);
365 if (sizeof(_Fun) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value &&
366 is_nothrow_copy_constructible<_FunAlloc>::value) {
367 __f_ = ::new ((void*)&__buf_) _Fun(std::move(__f), _Alloc(__af));
210 if (sizeof(_Fun) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value) {
211 __f_ = ::new (std::addressof(__buf_)) _Fun(std::move(__f));
368212 } else {
369 typedef __allocator_destructor<_FunAlloc> _Dp;
370 unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
371 ::new ((void*)__hold.get()) _Fun(std::move(__f), _Alloc(__a));
372 __f_ = __hold.release();
213 __f_ = new _Fun(std::move(__f));
373214 }
374215 }
375216 }
376217
377 template <class _Fp, __enable_if_t<!is_same<__decay_t<_Fp>, __value_func>::value, int> = 0>
378 _LIBCPP_HIDE_FROM_ABI explicit __value_func(_Fp&& __f) : __value_func(std::forward<_Fp>(__f), allocator<_Fp>()) {}
379
380218 _LIBCPP_HIDE_FROM_ABI __value_func(const __value_func& __f) {
381219 if (__f.__f_ == nullptr)
382220 __f_ = nullptr;
......@@ -432,12 +270,12 @@ public:
432270
433271 _LIBCPP_HIDE_FROM_ABI _Rp operator()(_ArgTypes&&... __args) const {
434272 if (__f_ == nullptr)
435 __throw_bad_function_call();
273 std::__throw_bad_function_call();
436274 return (*__f_)(std::forward<_ArgTypes>(__args)...);
437275 }
438276
439277 _LIBCPP_HIDE_FROM_ABI void swap(__value_func& __f) _NOEXCEPT {
440 if (&__f == this)
278 if (std::addressof(__f) == this)
441279 return;
442280 if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_) {
443281 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
......@@ -539,22 +377,22 @@ private:
539377 template <typename _Fun>
540378 _LIBCPP_HIDE_FROM_ABI static void* __large_clone(const void* __s) {
541379 const _Fun* __f = static_cast<const _Fun*>(__s);
542 return __f->__clone();
380 return new _Fun(*__f);
543381 }
544382
545383 template <typename _Fun>
546384 _LIBCPP_HIDE_FROM_ABI static void __large_destroy(void* __s) {
547 _Fun::__destroy_and_delete(static_cast<_Fun*>(__s));
385 delete static_cast<_Fun*>(__s);
548386 }
549387
550388 template <typename _Fun>
551389 _LIBCPP_HIDE_FROM_ABI static const __policy* __choose_policy(/* is_small = */ false_type) {
552390 static constexpr __policy __policy = {
553 &__large_clone<_Fun>,
554 &__large_destroy<_Fun>,
391 std::addressof(__large_clone<_Fun>),
392 std::addressof(__large_destroy<_Fun>),
555393 false,
556394# if _LIBCPP_HAS_RTTI
557 &typeid(typename _Fun::_Target)
395 &typeid(_Fun)
558396# else
559397 nullptr
560398# endif
......@@ -569,7 +407,7 @@ private:
569407 nullptr,
570408 false,
571409# if _LIBCPP_HAS_RTTI
572 &typeid(typename _Fun::_Target)
410 &typeid(_Fun)
573411# else
574412 nullptr
575413# endif
......@@ -583,42 +421,7 @@ private:
583421template <typename _Tp>
584422using __fast_forward _LIBCPP_NODEBUG = __conditional_t<is_scalar<_Tp>::value, _Tp, _Tp&&>;
585423
586// __policy_invoker calls an instance of __alloc_func held in __policy_storage.
587
588template <class _Fp>
589struct __policy_invoker;
590
591template <class _Rp, class... _ArgTypes>
592struct __policy_invoker<_Rp(_ArgTypes...)> {
593 typedef _Rp (*__Call)(const __policy_storage*, __fast_forward<_ArgTypes>...);
594
595 __Call __call_;
596
597 // Creates an invoker that throws bad_function_call.
598 _LIBCPP_HIDE_FROM_ABI __policy_invoker() : __call_(&__call_empty) {}
599
600 // Creates an invoker that calls the given instance of __func.
601 template <typename _Fun>
602 _LIBCPP_HIDE_FROM_ABI static __policy_invoker __create() {
603 return __policy_invoker(&__call_impl<_Fun>);
604 }
605
606private:
607 _LIBCPP_HIDE_FROM_ABI explicit __policy_invoker(__Call __c) : __call_(__c) {}
608
609 _LIBCPP_HIDE_FROM_ABI static _Rp __call_empty(const __policy_storage*, __fast_forward<_ArgTypes>...) {
610 __throw_bad_function_call();
611 }
612
613 template <typename _Fun>
614 _LIBCPP_HIDE_FROM_ABI static _Rp __call_impl(const __policy_storage* __buf, __fast_forward<_ArgTypes>... __args) {
615 _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value ? &__buf->__small : __buf->__large);
616 return (*__f)(std::forward<_ArgTypes>(__args)...);
617 }
618};
619
620// __policy_func uses a __policy and __policy_invoker to create a type-erased,
621// copyable functor.
424// __policy_func uses a __policy to create a type-erased, copyable functor.
622425
623426template <class _Fp>
624427class __policy_func;
......@@ -628,69 +431,52 @@ class __policy_func<_Rp(_ArgTypes...)> {
628431 // Inline storage for small objects.
629432 __policy_storage __buf_;
630433
631 // Calls the value stored in __buf_. This could technically be part of
632 // policy, but storing it here eliminates a level of indirection inside
633 // operator().
634 typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker;
635 __invoker __invoker_;
434 using _ErasedFunc _LIBCPP_NODEBUG = _Rp(const __policy_storage*, __fast_forward<_ArgTypes>...);
435
436 _ErasedFunc* __func_;
636437
637438 // The policy that describes how to move / copy / destroy __buf_. Never
638439 // null, even if the function is empty.
639440 const __policy* __policy_;
640441
641public:
642 _LIBCPP_HIDE_FROM_ABI __policy_func() : __policy_(__policy::__create_empty()) {}
643
644 template <class _Fp, class _Alloc>
645 _LIBCPP_HIDE_FROM_ABI __policy_func(_Fp&& __f, const _Alloc& __a) : __policy_(__policy::__create_empty()) {
646 typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
647 typedef allocator_traits<_Alloc> __alloc_traits;
648 typedef __rebind_alloc<__alloc_traits, _Fun> _FunAlloc;
442 _LIBCPP_HIDE_FROM_ABI static _Rp __empty_func(const __policy_storage*, __fast_forward<_ArgTypes>...) {
443 std::__throw_bad_function_call();
444 }
649445
650 if (__function::__not_null(__f)) {
651 __invoker_ = __invoker::template __create<_Fun>();
652 __policy_ = __policy::__create<_Fun>();
446 template <class _Fun>
447 _LIBCPP_HIDE_FROM_ABI static _Rp __call_func(const __policy_storage* __buf, __fast_forward<_ArgTypes>... __args) {
448 _Fun* __func = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value ? &__buf->__small : __buf->__large);
653449
654 _FunAlloc __af(__a);
655 if (__use_small_storage<_Fun>()) {
656 ::new ((void*)&__buf_.__small) _Fun(std::move(__f), _Alloc(__af));
657 } else {
658 typedef __allocator_destructor<_FunAlloc> _Dp;
659 unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
660 ::new ((void*)__hold.get()) _Fun(std::move(__f), _Alloc(__af));
661 __buf_.__large = __hold.release();
662 }
663 }
450 return std::__invoke_r<_Rp>(*__func, std::forward<_ArgTypes>(__args)...);
664451 }
665452
453public:
454 _LIBCPP_HIDE_FROM_ABI __policy_func() : __func_(__empty_func), __policy_(__policy::__create_empty()) {}
455
666456 template <class _Fp, __enable_if_t<!is_same<__decay_t<_Fp>, __policy_func>::value, int> = 0>
667457 _LIBCPP_HIDE_FROM_ABI explicit __policy_func(_Fp&& __f) : __policy_(__policy::__create_empty()) {
668 typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun;
669
670458 if (__function::__not_null(__f)) {
671 __invoker_ = __invoker::template __create<_Fun>();
672 __policy_ = __policy::__create<_Fun>();
673 if (__use_small_storage<_Fun>()) {
674 ::new ((void*)&__buf_.__small) _Fun(std::move(__f));
459 __func_ = __call_func<_Fp>;
460 __policy_ = __policy::__create<_Fp>();
461 if (__use_small_storage<_Fp>()) {
462 ::new ((void*)&__buf_.__small) _Fp(std::move(__f));
675463 } else {
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));
678 (void)__hold.release();
464 __buf_.__large = ::new _Fp(std::move(__f));
679465 }
680466 }
681467 }
682468
683469 _LIBCPP_HIDE_FROM_ABI __policy_func(const __policy_func& __f)
684 : __buf_(__f.__buf_), __invoker_(__f.__invoker_), __policy_(__f.__policy_) {
470 : __buf_(__f.__buf_), __func_(__f.__func_), __policy_(__f.__policy_) {
685471 if (__policy_->__clone)
686472 __buf_.__large = __policy_->__clone(__f.__buf_.__large);
687473 }
688474
689475 _LIBCPP_HIDE_FROM_ABI __policy_func(__policy_func&& __f)
690 : __buf_(__f.__buf_), __invoker_(__f.__invoker_), __policy_(__f.__policy_) {
476 : __buf_(__f.__buf_), __func_(__f.__func_), __policy_(__f.__policy_) {
691477 if (__policy_->__destroy) {
692 __f.__policy_ = __policy::__create_empty();
693 __f.__invoker_ = __invoker();
478 __f.__policy_ = __policy::__create_empty();
479 __f.__func_ = {};
694480 }
695481 }
696482
......@@ -700,30 +486,30 @@ public:
700486 }
701487
702488 _LIBCPP_HIDE_FROM_ABI __policy_func& operator=(__policy_func&& __f) {
703 *this = nullptr;
704 __buf_ = __f.__buf_;
705 __invoker_ = __f.__invoker_;
706 __policy_ = __f.__policy_;
707 __f.__policy_ = __policy::__create_empty();
708 __f.__invoker_ = __invoker();
489 *this = nullptr;
490 __buf_ = __f.__buf_;
491 __func_ = __f.__func_;
492 __policy_ = __f.__policy_;
493 __f.__policy_ = __policy::__create_empty();
494 __f.__func_ = {};
709495 return *this;
710496 }
711497
712498 _LIBCPP_HIDE_FROM_ABI __policy_func& operator=(nullptr_t) {
713499 const __policy* __p = __policy_;
714500 __policy_ = __policy::__create_empty();
715 __invoker_ = __invoker();
501 __func_ = {};
716502 if (__p->__destroy)
717503 __p->__destroy(__buf_.__large);
718504 return *this;
719505 }
720506
721507 _LIBCPP_HIDE_FROM_ABI _Rp operator()(_ArgTypes&&... __args) const {
722 return __invoker_.__call_(std::addressof(__buf_), std::forward<_ArgTypes>(__args)...);
508 return __func_(std::addressof(__buf_), std::forward<_ArgTypes>(__args)...);
723509 }
724510
725511 _LIBCPP_HIDE_FROM_ABI void swap(__policy_func& __f) {
726 std::swap(__invoker_, __f.__invoker_);
512 std::swap(__func_, __f.__func_);
727513 std::swap(__policy_, __f.__policy_);
728514 std::swap(__buf_, __f.__buf_);
729515 }
......@@ -750,14 +536,14 @@ public:
750536extern "C" void* _Block_copy(const void*);
751537extern "C" void _Block_release(const void*);
752538
753template <class _Rp1, class... _ArgTypes1, class _Alloc, class _Rp, class... _ArgTypes>
754class __func<_Rp1 (^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> : public __base<_Rp(_ArgTypes...)> {
539template <class _Rp1, class... _ArgTypes1, class _Rp, class... _ArgTypes>
540class __func<_Rp1 (^)(_ArgTypes1...), _Rp(_ArgTypes...)> : public __base<_Rp(_ArgTypes...)> {
755541 typedef _Rp1 (^__block_type)(_ArgTypes1...);
756542 __block_type __f_;
757543
758544public:
759545 _LIBCPP_HIDE_FROM_ABI explicit __func(__block_type const& __f)
760# if _LIBCPP_HAS_OBJC_ARC
546# if __has_feature(objc_arc)
761547 : __f_(__f)
762548# else
763549 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
......@@ -767,15 +553,6 @@ public:
767553
768554 // [TODO] add && to save on a retain
769555
770 _LIBCPP_HIDE_FROM_ABI explicit __func(__block_type __f, const _Alloc& /* unused */)
771# if _LIBCPP_HAS_OBJC_ARC
772 : __f_(__f)
773# else
774 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
775# endif
776 {
777 }
778
779556 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual __base<_Rp(_ArgTypes...)>* __clone() const {
780557 _LIBCPP_ASSERT_INTERNAL(
781558 false,
......@@ -790,7 +567,7 @@ public:
790567 }
791568
792569 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy() _NOEXCEPT {
793# if !_LIBCPP_HAS_OBJC_ARC
570# if !__has_feature(objc_arc)
794571 if (__f_)
795572 _Block_release(__f_);
796573# endif
......@@ -822,12 +599,12 @@ public:
822599# endif // _LIBCPP_HAS_RTTI
823600};
824601
825# endif // _LIBCPP_HAS_EXTENSION_BLOCKS
602# endif // _LIBCPP_HAS_BLOCKS_RUNTIME
826603
827604} // namespace __function
828605
829606template <class _Rp, class... _ArgTypes>
830class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
607class function<_Rp(_ArgTypes...)>
831608 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
832609 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)> {
833610# ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION
......@@ -954,7 +731,7 @@ function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(std::move(__f)) {}
954731# if _LIBCPP_STD_VER <= 14
955732template <class _Rp, class... _ArgTypes>
956733template <class _Fp, class _Alloc, class>
957function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a, _Fp __f) : __f_(std::move(__f), __a) {}
734function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, _Fp __f) : __f_(std::move(__f)) {}
958735# endif
959736
960737template <class _Rp, class... _ArgTypes>
lib/libcxx/include/__functional/hash.h+44-126
......@@ -13,11 +13,14 @@
1313#include <__cstddef/nullptr_t.h>
1414#include <__functional/unary_function.h>
1515#include <__fwd/functional.h>
16#include <__memory/addressof.h>
1617#include <__type_traits/conjunction.h>
1718#include <__type_traits/enable_if.h>
1819#include <__type_traits/invoke.h>
1920#include <__type_traits/is_constructible.h>
2021#include <__type_traits/is_enum.h>
22#include <__type_traits/is_floating_point.h>
23#include <__type_traits/is_integral.h>
2124#include <__type_traits/underlying_type.h>
2225#include <__utility/pair.h>
2326#include <__utility/swap.h>
......@@ -33,7 +36,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3336template <class _Size>
3437inline _LIBCPP_HIDE_FROM_ABI _Size __loadword(const void* __p) {
3538 _Size __r;
36 std::memcpy(&__r, __p, sizeof(__r));
39 std::memcpy(std::addressof(__r), __p, sizeof(__r));
3740 return __r;
3841}
3942
......@@ -63,10 +66,10 @@ struct __murmur2_or_cityhash<_Size, 32> {
6366 switch (__len) {
6467 case 3:
6568 __h ^= static_cast<_Size>(__data[2] << 16);
66 _LIBCPP_FALLTHROUGH();
69 [[__fallthrough__]];
6770 case 2:
6871 __h ^= static_cast<_Size>(__data[1] << 8);
69 _LIBCPP_FALLTHROUGH();
72 [[__fallthrough__]];
7073 case 1:
7174 __h ^= __data[0];
7275 __h *= __m;
......@@ -237,6 +240,14 @@ private:
237240 }
238241};
239242
243#if _LIBCPP_AVAILABILITY_HAS_HASH_MEMORY
244[[__gnu__::__pure__]] _LIBCPP_EXPORTED_FROM_ABI size_t __hash_memory(_LIBCPP_NOESCAPE const void*, size_t) _NOEXCEPT;
245#else
246_LIBCPP_HIDE_FROM_ABI inline size_t __hash_memory(const void* __ptr, size_t __size) _NOEXCEPT {
247 return __murmur2_or_cityhash<size_t>()(__ptr, __size);
248}
249#endif
250
240251template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
241252struct __scalar_hash;
242253
......@@ -276,7 +287,7 @@ struct __scalar_hash<_Tp, 2> : public __unary_function<_Tp, size_t> {
276287 } __s;
277288 } __u;
278289 __u.__t = __v;
279 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
290 return std::__hash_memory(std::addressof(__u), sizeof(__u));
280291 }
281292};
282293
......@@ -292,7 +303,7 @@ struct __scalar_hash<_Tp, 3> : public __unary_function<_Tp, size_t> {
292303 } __s;
293304 } __u;
294305 __u.__t = __v;
295 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
306 return std::__hash_memory(std::addressof(__u), sizeof(__u));
296307 }
297308};
298309
......@@ -309,7 +320,7 @@ struct __scalar_hash<_Tp, 4> : public __unary_function<_Tp, size_t> {
309320 } __s;
310321 } __u;
311322 __u.__t = __v;
312 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
323 return std::__hash_memory(std::addressof(__u), sizeof(__u));
313324 }
314325};
315326
......@@ -325,133 +336,54 @@ _LIBCPP_HIDE_FROM_ABI inline size_t __hash_combine(size_t __lhs, size_t __rhs) _
325336}
326337
327338template <class _Tp>
328struct _LIBCPP_TEMPLATE_VIS hash<_Tp*> : public __unary_function<_Tp*, size_t> {
339struct hash<_Tp*> : public __unary_function<_Tp*, size_t> {
329340 _LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp* __v) const _NOEXCEPT {
330341 union {
331342 _Tp* __t;
332343 size_t __a;
333344 } __u;
334345 __u.__t = __v;
335 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
346 return std::__hash_memory(std::addressof(__u), sizeof(__u));
336347 }
337348};
338349
339template <>
340struct _LIBCPP_TEMPLATE_VIS hash<bool> : public __unary_function<bool, size_t> {
341 _LIBCPP_HIDE_FROM_ABI size_t operator()(bool __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
342};
343
344template <>
345struct _LIBCPP_TEMPLATE_VIS hash<char> : public __unary_function<char, size_t> {
346 _LIBCPP_HIDE_FROM_ABI size_t operator()(char __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
350template <class _Tp, class = void>
351struct __hash_impl {
352 __hash_impl() = delete;
353 __hash_impl(__hash_impl const&) = delete;
354 __hash_impl& operator=(__hash_impl const&) = delete;
347355};
348356
349template <>
350struct _LIBCPP_TEMPLATE_VIS hash<signed char> : public __unary_function<signed char, size_t> {
351 _LIBCPP_HIDE_FROM_ABI size_t operator()(signed char __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
352};
353
354template <>
355struct _LIBCPP_TEMPLATE_VIS hash<unsigned char> : public __unary_function<unsigned char, size_t> {
356 _LIBCPP_HIDE_FROM_ABI size_t operator()(unsigned char __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
357};
358
359#if _LIBCPP_HAS_CHAR8_T
360template <>
361struct _LIBCPP_TEMPLATE_VIS hash<char8_t> : public __unary_function<char8_t, size_t> {
362 _LIBCPP_HIDE_FROM_ABI size_t operator()(char8_t __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
363};
364#endif // _LIBCPP_HAS_CHAR8_T
365
366template <>
367struct _LIBCPP_TEMPLATE_VIS hash<char16_t> : public __unary_function<char16_t, size_t> {
368 _LIBCPP_HIDE_FROM_ABI size_t operator()(char16_t __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
369};
370
371template <>
372struct _LIBCPP_TEMPLATE_VIS hash<char32_t> : public __unary_function<char32_t, size_t> {
373 _LIBCPP_HIDE_FROM_ABI size_t operator()(char32_t __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
374};
375
376#if _LIBCPP_HAS_WIDE_CHARACTERS
377template <>
378struct _LIBCPP_TEMPLATE_VIS hash<wchar_t> : public __unary_function<wchar_t, size_t> {
379 _LIBCPP_HIDE_FROM_ABI size_t operator()(wchar_t __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
380};
381#endif // _LIBCPP_HAS_WIDE_CHARACTERS
382
383template <>
384struct _LIBCPP_TEMPLATE_VIS hash<short> : public __unary_function<short, size_t> {
385 _LIBCPP_HIDE_FROM_ABI size_t operator()(short __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
386};
387
388template <>
389struct _LIBCPP_TEMPLATE_VIS hash<unsigned short> : public __unary_function<unsigned short, size_t> {
390 _LIBCPP_HIDE_FROM_ABI size_t operator()(unsigned short __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
391};
392
393template <>
394struct _LIBCPP_TEMPLATE_VIS hash<int> : public __unary_function<int, size_t> {
395 _LIBCPP_HIDE_FROM_ABI size_t operator()(int __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
396};
397
398template <>
399struct _LIBCPP_TEMPLATE_VIS hash<unsigned int> : public __unary_function<unsigned int, size_t> {
400 _LIBCPP_HIDE_FROM_ABI size_t operator()(unsigned int __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
401};
402
403template <>
404struct _LIBCPP_TEMPLATE_VIS hash<long> : public __unary_function<long, size_t> {
405 _LIBCPP_HIDE_FROM_ABI size_t operator()(long __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
406};
407
408template <>
409struct _LIBCPP_TEMPLATE_VIS hash<unsigned long> : public __unary_function<unsigned long, size_t> {
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);
357template <class _Tp>
358struct __hash_impl<_Tp, __enable_if_t<is_enum<_Tp>::value> > : __unary_function<_Tp, size_t> {
359 _LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp __v) const _NOEXCEPT {
360 using type = __underlying_type_t<_Tp>;
361 return hash<type>()(static_cast<type>(__v));
414362 }
415363};
416364
417template <>
418struct _LIBCPP_TEMPLATE_VIS hash<long long> : public __scalar_hash<long long> {};
419
420template <>
421struct _LIBCPP_TEMPLATE_VIS hash<unsigned long long> : public __scalar_hash<unsigned long long> {};
422
423#if _LIBCPP_HAS_INT128
424
425template <>
426struct _LIBCPP_TEMPLATE_VIS hash<__int128_t> : public __scalar_hash<__int128_t> {};
427
428template <>
429struct _LIBCPP_TEMPLATE_VIS hash<__uint128_t> : public __scalar_hash<__uint128_t> {};
365template <class _Tp>
366struct __hash_impl<_Tp, __enable_if_t<is_integral<_Tp>::value && (sizeof(_Tp) <= sizeof(size_t))> >
367 : __unary_function<_Tp, size_t> {
368 _LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
369};
430370
431#endif
371template <class _Tp>
372struct __hash_impl<_Tp, __enable_if_t<is_integral<_Tp>::value && (sizeof(_Tp) > sizeof(size_t))> >
373 : __scalar_hash<_Tp> {};
432374
433template <>
434struct _LIBCPP_TEMPLATE_VIS hash<float> : public __scalar_hash<float> {
435 _LIBCPP_HIDE_FROM_ABI size_t operator()(float __v) const _NOEXCEPT {
375template <class _Tp>
376struct __hash_impl<_Tp, __enable_if_t<is_floating_point<_Tp>::value> > : __scalar_hash<_Tp> {
377 _LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp __v) const _NOEXCEPT {
436378 // -0.0 and 0.0 should return same hash
437379 if (__v == 0.0f)
438380 return 0;
439 return __scalar_hash<float>::operator()(__v);
440 }
441};
442
443template <>
444struct _LIBCPP_TEMPLATE_VIS hash<double> : public __scalar_hash<double> {
445 _LIBCPP_HIDE_FROM_ABI size_t operator()(double __v) const _NOEXCEPT {
446 // -0.0 and 0.0 should return same hash
447 if (__v == 0.0)
448 return 0;
449 return __scalar_hash<double>::operator()(__v);
381 return __scalar_hash<_Tp>::operator()(__v);
450382 }
451383};
452384
453385template <>
454struct _LIBCPP_TEMPLATE_VIS hash<long double> : public __scalar_hash<long double> {
386struct __hash_impl<long double> : __scalar_hash<long double> {
455387 _LIBCPP_HIDE_FROM_ABI size_t operator()(long double __v) const _NOEXCEPT {
456388 // -0.0 and 0.0 should return same hash
457389 if (__v == 0.0L)
......@@ -492,27 +424,13 @@ struct _LIBCPP_TEMPLATE_VIS hash<long double> : public __scalar_hash<long double
492424 }
493425};
494426
495template <class _Tp, bool = is_enum<_Tp>::value>
496struct _LIBCPP_TEMPLATE_VIS __enum_hash : public __unary_function<_Tp, size_t> {
497 _LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp __v) const _NOEXCEPT {
498 typedef typename underlying_type<_Tp>::type type;
499 return hash<type>()(static_cast<type>(__v));
500 }
501};
502template <class _Tp>
503struct _LIBCPP_TEMPLATE_VIS __enum_hash<_Tp, false> {
504 __enum_hash() = delete;
505 __enum_hash(__enum_hash const&) = delete;
506 __enum_hash& operator=(__enum_hash const&) = delete;
507};
508
509427template <class _Tp>
510struct _LIBCPP_TEMPLATE_VIS hash : public __enum_hash<_Tp> {};
428struct hash : public __hash_impl<_Tp> {};
511429
512430#if _LIBCPP_STD_VER >= 17
513431
514432template <>
515struct _LIBCPP_TEMPLATE_VIS hash<nullptr_t> : public __unary_function<nullptr_t, size_t> {
433struct hash<nullptr_t> : public __unary_function<nullptr_t, size_t> {
516434 _LIBCPP_HIDE_FROM_ABI size_t operator()(nullptr_t) const _NOEXCEPT { return 662607004ull; }
517435};
518436#endif
lib/libcxx/include/__functional/mem_fun_ref.h+8-9
......@@ -23,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2323#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
2424
2525template <class _Sp, class _Tp>
26class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t : public __unary_function<_Tp*, _Sp> {
26class _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t : public __unary_function<_Tp*, _Sp> {
2727 _Sp (_Tp::*__p_)();
2828
2929public:
......@@ -32,7 +32,7 @@ public:
3232};
3333
3434template <class _Sp, class _Tp, class _Ap>
35class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t : public __binary_function<_Tp*, _Ap, _Sp> {
35class _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t : public __binary_function<_Tp*, _Ap, _Sp> {
3636 _Sp (_Tp::*__p_)(_Ap);
3737
3838public:
......@@ -51,7 +51,7 @@ _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_HIDE_FROM_ABI mem_fun1_t<_Sp, _Tp, _A
5151}
5252
5353template <class _Sp, class _Tp>
54class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t : public __unary_function<_Tp, _Sp> {
54class _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t : public __unary_function<_Tp, _Sp> {
5555 _Sp (_Tp::*__p_)();
5656
5757public:
......@@ -60,7 +60,7 @@ public:
6060};
6161
6262template <class _Sp, class _Tp, class _Ap>
63class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t : public __binary_function<_Tp, _Ap, _Sp> {
63class _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t : public __binary_function<_Tp, _Ap, _Sp> {
6464 _Sp (_Tp::*__p_)(_Ap);
6565
6666public:
......@@ -80,7 +80,7 @@ mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) {
8080}
8181
8282template <class _Sp, class _Tp>
83class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t : public __unary_function<const _Tp*, _Sp> {
83class _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t : public __unary_function<const _Tp*, _Sp> {
8484 _Sp (_Tp::*__p_)() const;
8585
8686public:
......@@ -89,8 +89,7 @@ public:
8989};
9090
9191template <class _Sp, class _Tp, class _Ap>
92class _LIBCPP_TEMPLATE_VIS
93_LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t : public __binary_function<const _Tp*, _Ap, _Sp> {
92class _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t : public __binary_function<const _Tp*, _Ap, _Sp> {
9493 _Sp (_Tp::*__p_)(_Ap) const;
9594
9695public:
......@@ -110,7 +109,7 @@ mem_fun(_Sp (_Tp::*__f)(_Ap) const) {
110109}
111110
112111template <class _Sp, class _Tp>
113class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t : public __unary_function<_Tp, _Sp> {
112class _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t : public __unary_function<_Tp, _Sp> {
114113 _Sp (_Tp::*__p_)() const;
115114
116115public:
......@@ -119,7 +118,7 @@ public:
119118};
120119
121120template <class _Sp, class _Tp, class _Ap>
122class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t : public __binary_function<_Tp, _Ap, _Sp> {
121class _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t : public __binary_function<_Tp, _Ap, _Sp> {
123122 _Sp (_Tp::*__p_)(_Ap) const;
124123
125124public:
lib/libcxx/include/__functional/operations.h+39-42
......@@ -13,6 +13,7 @@
1313#include <__config>
1414#include <__functional/binary_function.h>
1515#include <__functional/unary_function.h>
16#include <__fwd/functional.h>
1617#include <__type_traits/desugars_to.h>
1718#include <__type_traits/is_integral.h>
1819#include <__utility/forward.h>
......@@ -30,7 +31,7 @@ template <class _Tp = void>
3031#else
3132template <class _Tp>
3233#endif
33struct _LIBCPP_TEMPLATE_VIS plus : __binary_function<_Tp, _Tp, _Tp> {
34struct plus : __binary_function<_Tp, _Tp, _Tp> {
3435 typedef _Tp __result_type; // used by valarray
3536 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const {
3637 return __x + __y;
......@@ -48,7 +49,7 @@ inline const bool __desugars_to_v<__plus_tag, plus<void>, _Tp, _Up> = true;
4849
4950#if _LIBCPP_STD_VER >= 14
5051template <>
51struct _LIBCPP_TEMPLATE_VIS plus<void> {
52struct plus<void> {
5253 template <class _T1, class _T2>
5354 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
5455 noexcept(noexcept(std::forward<_T1>(__t) + std::forward<_T2>(__u))) //
......@@ -64,7 +65,7 @@ template <class _Tp = void>
6465#else
6566template <class _Tp>
6667#endif
67struct _LIBCPP_TEMPLATE_VIS minus : __binary_function<_Tp, _Tp, _Tp> {
68struct minus : __binary_function<_Tp, _Tp, _Tp> {
6869 typedef _Tp __result_type; // used by valarray
6970 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const {
7071 return __x - __y;
......@@ -74,7 +75,7 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(minus);
7475
7576#if _LIBCPP_STD_VER >= 14
7677template <>
77struct _LIBCPP_TEMPLATE_VIS minus<void> {
78struct minus<void> {
7879 template <class _T1, class _T2>
7980 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
8081 noexcept(noexcept(std::forward<_T1>(__t) - std::forward<_T2>(__u))) //
......@@ -90,7 +91,7 @@ template <class _Tp = void>
9091#else
9192template <class _Tp>
9293#endif
93struct _LIBCPP_TEMPLATE_VIS multiplies : __binary_function<_Tp, _Tp, _Tp> {
94struct multiplies : __binary_function<_Tp, _Tp, _Tp> {
9495 typedef _Tp __result_type; // used by valarray
9596 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const {
9697 return __x * __y;
......@@ -100,7 +101,7 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(multiplies);
100101
101102#if _LIBCPP_STD_VER >= 14
102103template <>
103struct _LIBCPP_TEMPLATE_VIS multiplies<void> {
104struct multiplies<void> {
104105 template <class _T1, class _T2>
105106 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
106107 noexcept(noexcept(std::forward<_T1>(__t) * std::forward<_T2>(__u))) //
......@@ -116,7 +117,7 @@ template <class _Tp = void>
116117#else
117118template <class _Tp>
118119#endif
119struct _LIBCPP_TEMPLATE_VIS divides : __binary_function<_Tp, _Tp, _Tp> {
120struct divides : __binary_function<_Tp, _Tp, _Tp> {
120121 typedef _Tp __result_type; // used by valarray
121122 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const {
122123 return __x / __y;
......@@ -126,7 +127,7 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(divides);
126127
127128#if _LIBCPP_STD_VER >= 14
128129template <>
129struct _LIBCPP_TEMPLATE_VIS divides<void> {
130struct divides<void> {
130131 template <class _T1, class _T2>
131132 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
132133 noexcept(noexcept(std::forward<_T1>(__t) / std::forward<_T2>(__u))) //
......@@ -142,7 +143,7 @@ template <class _Tp = void>
142143#else
143144template <class _Tp>
144145#endif
145struct _LIBCPP_TEMPLATE_VIS modulus : __binary_function<_Tp, _Tp, _Tp> {
146struct modulus : __binary_function<_Tp, _Tp, _Tp> {
146147 typedef _Tp __result_type; // used by valarray
147148 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const {
148149 return __x % __y;
......@@ -152,7 +153,7 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(modulus);
152153
153154#if _LIBCPP_STD_VER >= 14
154155template <>
155struct _LIBCPP_TEMPLATE_VIS modulus<void> {
156struct modulus<void> {
156157 template <class _T1, class _T2>
157158 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
158159 noexcept(noexcept(std::forward<_T1>(__t) % std::forward<_T2>(__u))) //
......@@ -168,7 +169,7 @@ template <class _Tp = void>
168169#else
169170template <class _Tp>
170171#endif
171struct _LIBCPP_TEMPLATE_VIS negate : __unary_function<_Tp, _Tp> {
172struct negate : __unary_function<_Tp, _Tp> {
172173 typedef _Tp __result_type; // used by valarray
173174 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return -__x; }
174175};
......@@ -176,7 +177,7 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(negate);
176177
177178#if _LIBCPP_STD_VER >= 14
178179template <>
179struct _LIBCPP_TEMPLATE_VIS negate<void> {
180struct negate<void> {
180181 template <class _Tp>
181182 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_Tp&& __x) const
182183 noexcept(noexcept(-std::forward<_Tp>(__x))) //
......@@ -194,7 +195,7 @@ template <class _Tp = void>
194195#else
195196template <class _Tp>
196197#endif
197struct _LIBCPP_TEMPLATE_VIS bit_and : __binary_function<_Tp, _Tp, _Tp> {
198struct bit_and : __binary_function<_Tp, _Tp, _Tp> {
198199 typedef _Tp __result_type; // used by valarray
199200 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const {
200201 return __x & __y;
......@@ -204,7 +205,7 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_and);
204205
205206#if _LIBCPP_STD_VER >= 14
206207template <>
207struct _LIBCPP_TEMPLATE_VIS bit_and<void> {
208struct bit_and<void> {
208209 template <class _T1, class _T2>
209210 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
210211 noexcept(noexcept(std::forward<_T1>(__t) &
......@@ -217,13 +218,13 @@ struct _LIBCPP_TEMPLATE_VIS bit_and<void> {
217218
218219#if _LIBCPP_STD_VER >= 14
219220template <class _Tp = void>
220struct _LIBCPP_TEMPLATE_VIS bit_not : __unary_function<_Tp, _Tp> {
221struct bit_not : __unary_function<_Tp, _Tp> {
221222 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return ~__x; }
222223};
223224_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_not);
224225
225226template <>
226struct _LIBCPP_TEMPLATE_VIS bit_not<void> {
227struct bit_not<void> {
227228 template <class _Tp>
228229 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_Tp&& __x) const
229230 noexcept(noexcept(~std::forward<_Tp>(__x))) //
......@@ -239,7 +240,7 @@ template <class _Tp = void>
239240#else
240241template <class _Tp>
241242#endif
242struct _LIBCPP_TEMPLATE_VIS bit_or : __binary_function<_Tp, _Tp, _Tp> {
243struct bit_or : __binary_function<_Tp, _Tp, _Tp> {
243244 typedef _Tp __result_type; // used by valarray
244245 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const {
245246 return __x | __y;
......@@ -249,7 +250,7 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_or);
249250
250251#if _LIBCPP_STD_VER >= 14
251252template <>
252struct _LIBCPP_TEMPLATE_VIS bit_or<void> {
253struct bit_or<void> {
253254 template <class _T1, class _T2>
254255 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
255256 noexcept(noexcept(std::forward<_T1>(__t) | std::forward<_T2>(__u))) //
......@@ -265,7 +266,7 @@ template <class _Tp = void>
265266#else
266267template <class _Tp>
267268#endif
268struct _LIBCPP_TEMPLATE_VIS bit_xor : __binary_function<_Tp, _Tp, _Tp> {
269struct bit_xor : __binary_function<_Tp, _Tp, _Tp> {
269270 typedef _Tp __result_type; // used by valarray
270271 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const {
271272 return __x ^ __y;
......@@ -275,7 +276,7 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_xor);
275276
276277#if _LIBCPP_STD_VER >= 14
277278template <>
278struct _LIBCPP_TEMPLATE_VIS bit_xor<void> {
279struct bit_xor<void> {
279280 template <class _T1, class _T2>
280281 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
281282 noexcept(noexcept(std::forward<_T1>(__t) ^ std::forward<_T2>(__u))) //
......@@ -293,7 +294,7 @@ template <class _Tp = void>
293294#else
294295template <class _Tp>
295296#endif
296struct _LIBCPP_TEMPLATE_VIS equal_to : __binary_function<_Tp, _Tp, bool> {
297struct equal_to : __binary_function<_Tp, _Tp, bool> {
297298 typedef bool __result_type; // used by valarray
298299 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {
299300 return __x == __y;
......@@ -303,7 +304,7 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(equal_to);
303304
304305#if _LIBCPP_STD_VER >= 14
305306template <>
306struct _LIBCPP_TEMPLATE_VIS equal_to<void> {
307struct equal_to<void> {
307308 template <class _T1, class _T2>
308309 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
309310 noexcept(noexcept(std::forward<_T1>(__t) == std::forward<_T2>(__u))) //
......@@ -328,7 +329,7 @@ template <class _Tp = void>
328329#else
329330template <class _Tp>
330331#endif
331struct _LIBCPP_TEMPLATE_VIS not_equal_to : __binary_function<_Tp, _Tp, bool> {
332struct not_equal_to : __binary_function<_Tp, _Tp, bool> {
332333 typedef bool __result_type; // used by valarray
333334 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {
334335 return __x != __y;
......@@ -338,7 +339,7 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(not_equal_to);
338339
339340#if _LIBCPP_STD_VER >= 14
340341template <>
341struct _LIBCPP_TEMPLATE_VIS not_equal_to<void> {
342struct not_equal_to<void> {
342343 template <class _T1, class _T2>
343344 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
344345 noexcept(noexcept(std::forward<_T1>(__t) != std::forward<_T2>(__u))) //
......@@ -349,12 +350,8 @@ struct _LIBCPP_TEMPLATE_VIS not_equal_to<void> {
349350};
350351#endif
351352
352#if _LIBCPP_STD_VER >= 14
353template <class _Tp = void>
354#else
355353template <class _Tp>
356#endif
357struct _LIBCPP_TEMPLATE_VIS less : __binary_function<_Tp, _Tp, bool> {
354struct less : __binary_function<_Tp, _Tp, bool> {
358355 typedef bool __result_type; // used by valarray
359356 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {
360357 return __x < __y;
......@@ -370,7 +367,7 @@ inline const bool __desugars_to_v<__totally_ordered_less_tag, less<_Tp>, _Tp, _T
370367
371368#if _LIBCPP_STD_VER >= 14
372369template <>
373struct _LIBCPP_TEMPLATE_VIS less<void> {
370struct less<void> {
374371 template <class _T1, class _T2>
375372 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
376373 noexcept(noexcept(std::forward<_T1>(__t) < std::forward<_T2>(__u))) //
......@@ -392,7 +389,7 @@ template <class _Tp = void>
392389#else
393390template <class _Tp>
394391#endif
395struct _LIBCPP_TEMPLATE_VIS less_equal : __binary_function<_Tp, _Tp, bool> {
392struct less_equal : __binary_function<_Tp, _Tp, bool> {
396393 typedef bool __result_type; // used by valarray
397394 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {
398395 return __x <= __y;
......@@ -402,7 +399,7 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(less_equal);
402399
403400#if _LIBCPP_STD_VER >= 14
404401template <>
405struct _LIBCPP_TEMPLATE_VIS less_equal<void> {
402struct less_equal<void> {
406403 template <class _T1, class _T2>
407404 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
408405 noexcept(noexcept(std::forward<_T1>(__t) <= std::forward<_T2>(__u))) //
......@@ -418,7 +415,7 @@ template <class _Tp = void>
418415#else
419416template <class _Tp>
420417#endif
421struct _LIBCPP_TEMPLATE_VIS greater_equal : __binary_function<_Tp, _Tp, bool> {
418struct greater_equal : __binary_function<_Tp, _Tp, bool> {
422419 typedef bool __result_type; // used by valarray
423420 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {
424421 return __x >= __y;
......@@ -428,7 +425,7 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(greater_equal);
428425
429426#if _LIBCPP_STD_VER >= 14
430427template <>
431struct _LIBCPP_TEMPLATE_VIS greater_equal<void> {
428struct greater_equal<void> {
432429 template <class _T1, class _T2>
433430 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
434431 noexcept(noexcept(std::forward<_T1>(__t) >=
......@@ -444,7 +441,7 @@ template <class _Tp = void>
444441#else
445442template <class _Tp>
446443#endif
447struct _LIBCPP_TEMPLATE_VIS greater : __binary_function<_Tp, _Tp, bool> {
444struct greater : __binary_function<_Tp, _Tp, bool> {
448445 typedef bool __result_type; // used by valarray
449446 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {
450447 return __x > __y;
......@@ -457,7 +454,7 @@ inline const bool __desugars_to_v<__greater_tag, greater<_Tp>, _Tp, _Tp> = true;
457454
458455#if _LIBCPP_STD_VER >= 14
459456template <>
460struct _LIBCPP_TEMPLATE_VIS greater<void> {
457struct greater<void> {
461458 template <class _T1, class _T2>
462459 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
463460 noexcept(noexcept(std::forward<_T1>(__t) > std::forward<_T2>(__u))) //
......@@ -478,7 +475,7 @@ template <class _Tp = void>
478475#else
479476template <class _Tp>
480477#endif
481struct _LIBCPP_TEMPLATE_VIS logical_and : __binary_function<_Tp, _Tp, bool> {
478struct logical_and : __binary_function<_Tp, _Tp, bool> {
482479 typedef bool __result_type; // used by valarray
483480 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {
484481 return __x && __y;
......@@ -488,7 +485,7 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_and);
488485
489486#if _LIBCPP_STD_VER >= 14
490487template <>
491struct _LIBCPP_TEMPLATE_VIS logical_and<void> {
488struct logical_and<void> {
492489 template <class _T1, class _T2>
493490 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
494491 noexcept(noexcept(std::forward<_T1>(__t) && std::forward<_T2>(__u))) //
......@@ -504,7 +501,7 @@ template <class _Tp = void>
504501#else
505502template <class _Tp>
506503#endif
507struct _LIBCPP_TEMPLATE_VIS logical_not : __unary_function<_Tp, bool> {
504struct logical_not : __unary_function<_Tp, bool> {
508505 typedef bool __result_type; // used by valarray
509506 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x) const { return !__x; }
510507};
......@@ -512,7 +509,7 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_not);
512509
513510#if _LIBCPP_STD_VER >= 14
514511template <>
515struct _LIBCPP_TEMPLATE_VIS logical_not<void> {
512struct logical_not<void> {
516513 template <class _Tp>
517514 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_Tp&& __x) const
518515 noexcept(noexcept(!std::forward<_Tp>(__x))) //
......@@ -528,7 +525,7 @@ template <class _Tp = void>
528525#else
529526template <class _Tp>
530527#endif
531struct _LIBCPP_TEMPLATE_VIS logical_or : __binary_function<_Tp, _Tp, bool> {
528struct logical_or : __binary_function<_Tp, _Tp, bool> {
532529 typedef bool __result_type; // used by valarray
533530 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {
534531 return __x || __y;
......@@ -538,7 +535,7 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_or);
538535
539536#if _LIBCPP_STD_VER >= 14
540537template <>
541struct _LIBCPP_TEMPLATE_VIS logical_or<void> {
538struct logical_or<void> {
542539 template <class _T1, class _T2>
543540 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
544541 noexcept(noexcept(std::forward<_T1>(__t) || std::forward<_T2>(__u))) //
lib/libcxx/include/__functional/pointer_to_binary_function.h+1-2
......@@ -22,8 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
2323
2424template <class _Arg1, class _Arg2, class _Result>
25class _LIBCPP_TEMPLATE_VIS
26_LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function : public __binary_function<_Arg1, _Arg2, _Result> {
25class _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function : public __binary_function<_Arg1, _Arg2, _Result> {
2726 _Result (*__f_)(_Arg1, _Arg2);
2827
2928public:
lib/libcxx/include/__functional/pointer_to_unary_function.h+1-2
......@@ -22,8 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
2323
2424template <class _Arg, class _Result>
25class _LIBCPP_TEMPLATE_VIS
26_LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function : public __unary_function<_Arg, _Result> {
25class _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function : public __unary_function<_Arg, _Result> {
2726 _Result (*__f_)(_Arg);
2827
2928public:
lib/libcxx/include/__functional/reference_wrapper.h+42-6
......@@ -11,13 +11,18 @@
1111#define _LIBCPP___FUNCTIONAL_REFERENCE_WRAPPER_H
1212
1313#include <__compare/synth_three_way.h>
14#include <__concepts/boolean_testable.h>
14#include <__concepts/convertible_to.h>
1515#include <__config>
1616#include <__functional/weak_result_type.h>
1717#include <__memory/addressof.h>
18#include <__type_traits/common_reference.h>
19#include <__type_traits/desugars_to.h>
1820#include <__type_traits/enable_if.h>
1921#include <__type_traits/invoke.h>
2022#include <__type_traits/is_const.h>
23#include <__type_traits/is_core_convertible.h>
24#include <__type_traits/is_same.h>
25#include <__type_traits/is_specialization.h>
2126#include <__type_traits/remove_cvref.h>
2227#include <__type_traits/void_t.h>
2328#include <__utility/declval.h>
......@@ -30,7 +35,7 @@
3035_LIBCPP_BEGIN_NAMESPACE_STD
3136
3237template <class _Tp>
33class _LIBCPP_TEMPLATE_VIS reference_wrapper : public __weak_result_type<_Tp> {
38class reference_wrapper : public __weak_result_type<_Tp> {
3439public:
3540 // types
3641 typedef _Tp type;
......@@ -44,7 +49,7 @@ private:
4449public:
4550 template <class _Up,
4651 class = __void_t<decltype(__fun(std::declval<_Up>()))>,
47 __enable_if_t<!__is_same_uncvref<_Up, reference_wrapper>::value, int> = 0>
52 __enable_if_t<!is_same<__remove_cvref_t<_Up>, reference_wrapper>::value, int> = 0>
4853 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference_wrapper(_Up&& __u)
4954 _NOEXCEPT_(noexcept(__fun(std::declval<_Up>()))) {
5055 type& __f = static_cast<_Up&&>(__u);
......@@ -74,7 +79,7 @@ public:
7479
7580 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(reference_wrapper __x, reference_wrapper __y)
7681 requires requires {
77 { __x.get() == __y.get() } -> __boolean_testable;
82 { __x.get() == __y.get() } -> __core_convertible_to<bool>;
7883 }
7984 {
8085 return __x.get() == __y.get();
......@@ -82,7 +87,7 @@ public:
8287
8388 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(reference_wrapper __x, const _Tp& __y)
8489 requires requires {
85 { __x.get() == __y } -> __boolean_testable;
90 { __x.get() == __y } -> __core_convertible_to<bool>;
8691 }
8792 {
8893 return __x.get() == __y;
......@@ -90,7 +95,7 @@ public:
9095
9196 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(reference_wrapper __x, reference_wrapper<const _Tp> __y)
9297 requires(!is_const_v<_Tp>) && requires {
93 { __x.get() == __y.get() } -> __boolean_testable;
98 { __x.get() == __y.get() } -> __core_convertible_to<bool>;
9499 }
95100 {
96101 return __x.get() == __y.get();
......@@ -149,6 +154,37 @@ void ref(const _Tp&&) = delete;
149154template <class _Tp>
150155void cref(const _Tp&&) = delete;
151156
157// Let desugars-to pass through std::reference_wrapper
158template <class _CanonicalTag, class _Operation, class... _Args>
159inline const bool __desugars_to_v<_CanonicalTag, reference_wrapper<_Operation>, _Args...> =
160 __desugars_to_v<_CanonicalTag, _Operation, _Args...>;
161
162#if _LIBCPP_STD_VER >= 20
163
164template <class _Tp>
165inline constexpr bool __is_ref_wrapper = __is_specialization_v<_Tp, reference_wrapper>;
166
167template <class _Rp, class _Tp, class _RpQual, class _TpQual>
168concept __ref_wrap_common_reference_exists_with = __is_ref_wrapper<_Rp> && requires {
169 typename common_reference_t<typename _Rp::type&, _TpQual>;
170} && convertible_to<_RpQual, common_reference_t<typename _Rp::type&, _TpQual>>;
171
172template <class _Rp, class _Tp, template <class> class _RpQual, template <class> class _TpQual>
173 requires(__ref_wrap_common_reference_exists_with<_Rp, _Tp, _RpQual<_Rp>, _TpQual<_Tp>> &&
174 !__ref_wrap_common_reference_exists_with<_Tp, _Rp, _TpQual<_Tp>, _RpQual<_Rp>>)
175struct basic_common_reference<_Rp, _Tp, _RpQual, _TpQual> {
176 using type _LIBCPP_NODEBUG = common_reference_t<typename _Rp::type&, _TpQual<_Tp>>;
177};
178
179template <class _Tp, class _Rp, template <class> class _TpQual, template <class> class _RpQual>
180 requires(__ref_wrap_common_reference_exists_with<_Rp, _Tp, _RpQual<_Rp>, _TpQual<_Tp>> &&
181 !__ref_wrap_common_reference_exists_with<_Tp, _Rp, _TpQual<_Tp>, _RpQual<_Rp>>)
182struct basic_common_reference<_Tp, _Rp, _TpQual, _RpQual> {
183 using type _LIBCPP_NODEBUG = common_reference_t<typename _Rp::type&, _TpQual<_Tp>>;
184};
185
186#endif // _LIBCPP_STD_VER >= 20
187
152188_LIBCPP_END_NAMESPACE_STD
153189
154190#endif // _LIBCPP___FUNCTIONAL_REFERENCE_WRAPPER_H
lib/libcxx/include/__functional/unary_function.h+3-4
......@@ -20,7 +20,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2020#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION)
2121
2222template <class _Arg, class _Result>
23struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 unary_function {
23struct _LIBCPP_DEPRECATED_IN_CXX11 unary_function {
2424 typedef _Arg argument_type;
2525 typedef _Result result_type;
2626};
......@@ -36,11 +36,10 @@ struct __unary_function_keep_layout_base {
3636};
3737
3838#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION)
39_LIBCPP_DIAGNOSTIC_PUSH
40_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
39_LIBCPP_SUPPRESS_DEPRECATED_PUSH
4140template <class _Arg, class _Result>
4241using __unary_function _LIBCPP_NODEBUG = unary_function<_Arg, _Result>;
43_LIBCPP_DIAGNOSTIC_POP
42_LIBCPP_SUPPRESS_DEPRECATED_POP
4443#else
4544template <class _Arg, class _Result>
4645using __unary_function _LIBCPP_NODEBUG = __unary_function_keep_layout_base<_Arg, _Result>;
lib/libcxx/include/__functional/unary_negate.h+1-2
......@@ -22,8 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
2323
2424template <class _Predicate>
25class _LIBCPP_TEMPLATE_VIS
26_LIBCPP_DEPRECATED_IN_CXX17 unary_negate : public __unary_function<typename _Predicate::argument_type, bool> {
25class _LIBCPP_DEPRECATED_IN_CXX17 unary_negate : public __unary_function<typename _Predicate::argument_type, bool> {
2726 _Predicate __pred_;
2827
2928public:
lib/libcxx/include/__functional/weak_result_type.h+2
......@@ -77,6 +77,7 @@ struct __maybe_derive_from_unary_function // bool is true
7777template <class _Tp>
7878struct __maybe_derive_from_unary_function<_Tp, false> {};
7979
80_LIBCPP_SUPPRESS_DEPRECATED_PUSH
8081template <class _Tp, bool = __derives_from_binary_function<_Tp>::value>
8182struct __maybe_derive_from_binary_function // bool is true
8283 : public __derives_from_binary_function<_Tp>::type {};
......@@ -99,6 +100,7 @@ struct __weak_result_type_imp<_Tp, false>
99100
100101template <class _Tp>
101102struct __weak_result_type : public __weak_result_type_imp<_Tp> {};
103_LIBCPP_SUPPRESS_DEPRECATED_POP
102104
103105// 0 argument case
104106
lib/libcxx/include/__fwd/array.h+1-1
......@@ -20,7 +20,7 @@
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
2222template <class _Tp, size_t _Size>
23struct _LIBCPP_TEMPLATE_VIS array;
23struct array;
2424
2525template <size_t _Ip, class _Tp, size_t _Size>
2626_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp& get(array<_Tp, _Size>&) _NOEXCEPT;
lib/libcxx/include/__fwd/bit_reference.h+16
......@@ -20,9 +20,25 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2020template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0>
2121class __bit_iterator;
2222
23template <class _Cp>
24struct __bit_array;
25
2326template <class, class = void>
2427struct __size_difference_type_traits;
2528
29template <class _StoragePointer>
30_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
31__fill_masked_range(_StoragePointer __word, unsigned __clz, unsigned __ctz, bool __fill_val);
32
33template <class _StorageType>
34_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _StorageType __trailing_mask(unsigned __clz);
35
36template <class _StorageType>
37_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _StorageType __leading_mask(unsigned __ctz);
38
39template <class _StorageType>
40_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _StorageType __middle_mask(unsigned __clz, unsigned __ctz);
41
2642_LIBCPP_END_NAMESPACE_STD
2743
2844#endif // _LIBCPP___FWD_BIT_REFERENCE_H
lib/libcxx/include/__fwd/byte.h+2-2
......@@ -16,11 +16,11 @@
1616#endif
1717
1818#if _LIBCPP_STD_VER >= 17
19namespace std { // purposefully not versioned
19_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
2020
2121enum class byte : unsigned char;
2222
23} // namespace std
23_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
2424#endif // _LIBCPP_STD_VER >= 17
2525
2626#endif // _LIBCPP___FWD_BYTE_H
lib/libcxx/include/__fwd/complex.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22class _LIBCPP_TEMPLATE_VIS complex;
22class complex;
2323
2424#if _LIBCPP_STD_VER >= 26
2525
lib/libcxx/include/__fwd/deque.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp, class _Allocator = allocator<_Tp> >
22class _LIBCPP_TEMPLATE_VIS deque;
22class deque;
2323
2424_LIBCPP_END_NAMESPACE_STD
2525
lib/libcxx/include/__fwd/format.h+3-3
......@@ -22,14 +22,14 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#if _LIBCPP_STD_VER >= 20
2323
2424template <class _Context>
25class _LIBCPP_TEMPLATE_VIS basic_format_arg;
25class basic_format_arg;
2626
2727template <class _OutIt, class _CharT>
2828 requires output_iterator<_OutIt, const _CharT&>
29class _LIBCPP_TEMPLATE_VIS basic_format_context;
29class basic_format_context;
3030
3131template <class _Tp, class _CharT = char>
32struct _LIBCPP_TEMPLATE_VIS formatter;
32struct formatter;
3333
3434#endif // _LIBCPP_STD_VER >= 20
3535
lib/libcxx/include/__fwd/fstream.h+4-4
......@@ -19,13 +19,13 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _CharT, class _Traits = char_traits<_CharT> >
22class _LIBCPP_TEMPLATE_VIS basic_filebuf;
22class basic_filebuf;
2323template <class _CharT, class _Traits = char_traits<_CharT> >
24class _LIBCPP_TEMPLATE_VIS basic_ifstream;
24class basic_ifstream;
2525template <class _CharT, class _Traits = char_traits<_CharT> >
26class _LIBCPP_TEMPLATE_VIS basic_ofstream;
26class basic_ofstream;
2727template <class _CharT, class _Traits = char_traits<_CharT> >
28class _LIBCPP_TEMPLATE_VIS basic_fstream;
28class basic_fstream;
2929
3030using filebuf = basic_filebuf<char>;
3131using ifstream = basic_ifstream<char>;
lib/libcxx/include/__fwd/functional.h+9-2
......@@ -17,11 +17,18 @@
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
1919
20#if _LIBCPP_STD_VER >= 14
21template <class _Tp = void>
22#else
23template <class _Tp>
24#endif
25struct less;
26
2027template <class>
21struct _LIBCPP_TEMPLATE_VIS hash;
28struct hash;
2229
2330template <class>
24class _LIBCPP_TEMPLATE_VIS reference_wrapper;
31class reference_wrapper;
2532
2633_LIBCPP_END_NAMESPACE_STD
2734
lib/libcxx/include/__fwd/ios.h+1-1
......@@ -21,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121class _LIBCPP_EXPORTED_FROM_ABI ios_base;
2222
2323template <class _CharT, class _Traits = char_traits<_CharT> >
24class _LIBCPP_TEMPLATE_VIS basic_ios;
24class basic_ios;
2525
2626using ios = basic_ios<char>;
2727#if _LIBCPP_HAS_WIDE_CHARACTERS
lib/libcxx/include/__fwd/istream.h+2-2
......@@ -19,10 +19,10 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _CharT, class _Traits = char_traits<_CharT> >
22class _LIBCPP_TEMPLATE_VIS basic_istream;
22class basic_istream;
2323
2424template <class _CharT, class _Traits = char_traits<_CharT> >
25class _LIBCPP_TEMPLATE_VIS basic_iostream;
25class basic_iostream;
2626
2727using istream = basic_istream<char>;
2828using iostream = basic_iostream<char>;
lib/libcxx/include/__fwd/map.h created+31
......@@ -0,0 +1,31 @@
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_MAP_H
10#define _LIBCPP___FWD_MAP_H
11
12#include <__config>
13#include <__fwd/functional.h>
14#include <__fwd/memory.h>
15#include <__fwd/pair.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 <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
24class map;
25
26template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
27class multimap;
28
29_LIBCPP_END_NAMESPACE_STD
30
31#endif // _LIBCPP___FWD_MAP_H
lib/libcxx/include/__fwd/memory.h+2-2
......@@ -18,10 +18,10 @@
1818_LIBCPP_BEGIN_NAMESPACE_STD
1919
2020template <class _Tp>
21class _LIBCPP_TEMPLATE_VIS allocator;
21class allocator;
2222
2323template <class _Tp>
24class _LIBCPP_TEMPLATE_VIS shared_ptr;
24class shared_ptr;
2525
2626_LIBCPP_END_NAMESPACE_STD
2727
lib/libcxx/include/__fwd/memory_resource.h+1-1
......@@ -21,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121
2222namespace pmr {
2323template <class _ValueType>
24class _LIBCPP_AVAILABILITY_PMR _LIBCPP_TEMPLATE_VIS polymorphic_allocator;
24class _LIBCPP_AVAILABILITY_PMR polymorphic_allocator;
2525} // namespace pmr
2626
2727_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__fwd/ostream.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _CharT, class _Traits = char_traits<_CharT> >
22class _LIBCPP_TEMPLATE_VIS basic_ostream;
22class basic_ostream;
2323
2424using ostream = basic_ostream<char>;
2525
lib/libcxx/include/__fwd/pair.h+7-1
......@@ -20,7 +20,13 @@
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
2222template <class, class>
23struct _LIBCPP_TEMPLATE_VIS pair;
23struct pair;
24
25template <class _Type>
26inline const bool __is_pair_v = false;
27
28template <class _Type1, class _Type2>
29inline const bool __is_pair_v<pair<_Type1, _Type2> > = true;
2430
2531template <size_t _Ip, class _T1, class _T2>
2632_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Ip, pair<_T1, _T2> >::type&
lib/libcxx/include/__fwd/queue.h+2-2
......@@ -21,10 +21,10 @@
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
2323template <class _Tp, class _Container = deque<_Tp> >
24class _LIBCPP_TEMPLATE_VIS queue;
24class queue;
2525
2626template <class _Tp, class _Container = vector<_Tp>, class _Compare = less<typename _Container::value_type> >
27class _LIBCPP_TEMPLATE_VIS priority_queue;
27class priority_queue;
2828
2929_LIBCPP_END_NAMESPACE_STD
3030
lib/libcxx/include/__fwd/set.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___FWD_SET_H
10#define _LIBCPP___FWD_SET_H
11
12#include <__config>
13#include <__fwd/functional.h>
14#include <__fwd/memory.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 <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
23class set;
24
25template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
26class multiset;
27
28_LIBCPP_END_NAMESPACE_STD
29
30#endif // _LIBCPP___FWD_SET_H
lib/libcxx/include/__fwd/sstream.h+4-4
......@@ -20,14 +20,14 @@
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
2222template <class _CharT, class _Traits = char_traits<_CharT>, class _Allocator = allocator<_CharT> >
23class _LIBCPP_TEMPLATE_VIS basic_stringbuf;
23class basic_stringbuf;
2424
2525template <class _CharT, class _Traits = char_traits<_CharT>, class _Allocator = allocator<_CharT> >
26class _LIBCPP_TEMPLATE_VIS basic_istringstream;
26class basic_istringstream;
2727template <class _CharT, class _Traits = char_traits<_CharT>, class _Allocator = allocator<_CharT> >
28class _LIBCPP_TEMPLATE_VIS basic_ostringstream;
28class basic_ostringstream;
2929template <class _CharT, class _Traits = char_traits<_CharT>, class _Allocator = allocator<_CharT> >
30class _LIBCPP_TEMPLATE_VIS basic_stringstream;
30class basic_stringstream;
3131
3232using stringbuf = basic_stringbuf<char>;
3333using istringstream = basic_istringstream<char>;
lib/libcxx/include/__fwd/stack.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp, class _Container = deque<_Tp> >
22class _LIBCPP_TEMPLATE_VIS stack;
22class stack;
2323
2424_LIBCPP_END_NAMESPACE_STD
2525
lib/libcxx/include/__fwd/streambuf.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _CharT, class _Traits = char_traits<_CharT> >
22class _LIBCPP_TEMPLATE_VIS basic_streambuf;
22class basic_streambuf;
2323
2424using streambuf = basic_streambuf<char>;
2525
lib/libcxx/include/__fwd/string.h+2-2
......@@ -20,7 +20,7 @@
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
2222template <class _CharT>
23struct _LIBCPP_TEMPLATE_VIS char_traits;
23struct char_traits;
2424template <>
2525struct char_traits<char>;
2626
......@@ -40,7 +40,7 @@ struct char_traits<wchar_t>;
4040#endif
4141
4242template <class _CharT, class _Traits = char_traits<_CharT>, class _Allocator = allocator<_CharT> >
43class _LIBCPP_TEMPLATE_VIS basic_string;
43class basic_string;
4444
4545using string = basic_string<char>;
4646
lib/libcxx/include/__fwd/string_view.h+1-1
......@@ -20,7 +20,7 @@
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
2222template <class _CharT, class _Traits = char_traits<_CharT> >
23class _LIBCPP_TEMPLATE_VIS basic_string_view;
23class basic_string_view;
2424
2525typedef basic_string_view<char> string_view;
2626#if _LIBCPP_HAS_CHAR8_T
lib/libcxx/include/__fwd/subrange.h+1-1
......@@ -28,7 +28,7 @@ enum class subrange_kind : bool { unsized, sized };
2828
2929template <input_or_output_iterator _Iter, sentinel_for<_Iter> _Sent, subrange_kind _Kind>
3030 requires(_Kind == subrange_kind::sized || !sized_sentinel_for<_Sent, _Iter>)
31class _LIBCPP_TEMPLATE_VIS subrange;
31class subrange;
3232
3333template <size_t _Index, class _Iter, class _Sent, subrange_kind _Kind>
3434 requires((_Index == 0 && copyable<_Iter>) || _Index == 1)
lib/libcxx/include/__fwd/tuple.h+3-3
......@@ -19,15 +19,15 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <size_t, class>
22struct _LIBCPP_TEMPLATE_VIS tuple_element;
22struct tuple_element;
2323
2424#ifndef _LIBCPP_CXX03_LANG
2525
2626template <class...>
27class _LIBCPP_TEMPLATE_VIS tuple;
27class tuple;
2828
2929template <class>
30struct _LIBCPP_TEMPLATE_VIS tuple_size;
30struct tuple_size;
3131
3232template <size_t _Ip, class... _Tp>
3333_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Ip, tuple<_Tp...> >::type&
lib/libcxx/include/__fwd/variant.h+11-20
......@@ -21,16 +21,16 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121#if _LIBCPP_STD_VER >= 17
2222
2323template <class... _Types>
24class _LIBCPP_TEMPLATE_VIS variant;
24class variant;
2525
2626template <class _Tp>
27struct _LIBCPP_TEMPLATE_VIS variant_size;
27struct variant_size;
2828
2929template <class _Tp>
3030inline constexpr size_t variant_size_v = variant_size<_Tp>::value;
3131
3232template <size_t _Ip, class _Tp>
33struct _LIBCPP_TEMPLATE_VIS variant_alternative;
33struct variant_alternative;
3434
3535template <size_t _Ip, class _Tp>
3636using variant_alternative_t = typename variant_alternative<_Ip, _Tp>::type;
......@@ -38,37 +38,28 @@ using variant_alternative_t = typename variant_alternative<_Ip, _Tp>::type;
3838inline constexpr size_t variant_npos = static_cast<size_t>(-1);
3939
4040template <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...>&);
41_LIBCPP_HIDE_FROM_ABI constexpr variant_alternative_t<_Ip, variant<_Types...>>& get(variant<_Types...>&);
4442
4543template <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...>&&);
44_LIBCPP_HIDE_FROM_ABI constexpr variant_alternative_t<_Ip, variant<_Types...>>&& get(variant<_Types...>&&);
4945
5046template <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...>&);
47_LIBCPP_HIDE_FROM_ABI constexpr const variant_alternative_t<_Ip, variant<_Types...>>& get(const variant<_Types...>&);
5448
5549template <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...>&&);
50_LIBCPP_HIDE_FROM_ABI constexpr const variant_alternative_t<_Ip, variant<_Types...>>&& get(const variant<_Types...>&&);
5951
6052template <class _Tp, class... _Types>
61_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Tp& get(variant<_Types...>&);
53_LIBCPP_HIDE_FROM_ABI constexpr _Tp& get(variant<_Types...>&);
6254
6355template <class _Tp, class... _Types>
64_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Tp&& get(variant<_Types...>&&);
56_LIBCPP_HIDE_FROM_ABI constexpr _Tp&& get(variant<_Types...>&&);
6557
6658template <class _Tp, class... _Types>
67_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const _Tp& get(const variant<_Types...>&);
59_LIBCPP_HIDE_FROM_ABI constexpr const _Tp& get(const variant<_Types...>&);
6860
6961template <class _Tp, class... _Types>
70_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const _Tp&&
71get(const variant<_Types...>&&);
62_LIBCPP_HIDE_FROM_ABI constexpr const _Tp&& get(const variant<_Types...>&&);
7263
7364#endif // _LIBCPP_STD_VER >= 17
7465
lib/libcxx/include/__fwd/vector.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp, class _Alloc = allocator<_Tp> >
22class _LIBCPP_TEMPLATE_VIS vector;
22class vector;
2323
2424template <class _Allocator>
2525class vector<bool, _Allocator>;
lib/libcxx/include/__hash_table+111-72
......@@ -29,6 +29,7 @@
2929#include <__memory/unique_ptr.h>
3030#include <__new/launder.h>
3131#include <__type_traits/can_extract_key.h>
32#include <__type_traits/copy_cvref.h>
3233#include <__type_traits/enable_if.h>
3334#include <__type_traits/invoke.h>
3435#include <__type_traits/is_const.h>
......@@ -108,9 +109,22 @@ struct __hash_node_base {
108109 _LIBCPP_HIDE_FROM_ABI explicit __hash_node_base(__next_pointer __next) _NOEXCEPT : __next_(__next) {}
109110};
110111
112template <class _Tp>
113struct __get_hash_node_value_type {
114 using type _LIBCPP_NODEBUG = _Tp;
115};
116
117template <class _Key, class _Tp>
118struct __get_hash_node_value_type<__hash_value_type<_Key, _Tp> > {
119 using type _LIBCPP_NODEBUG = pair<const _Key, _Tp>;
120};
121
122template <class _Tp>
123using __get_hash_node_value_type_t _LIBCPP_NODEBUG = typename __get_hash_node_value_type<_Tp>::type;
124
111125template <class _Tp, class _VoidPtr>
112126struct __hash_node : public __hash_node_base< __rebind_pointer_t<_VoidPtr, __hash_node<_Tp, _VoidPtr> > > {
113 typedef _Tp __node_value_type;
127 using __node_value_type _LIBCPP_NODEBUG = __get_hash_node_value_type_t<_Tp>;
114128 using _Base _LIBCPP_NODEBUG = __hash_node_base<__rebind_pointer_t<_VoidPtr, __hash_node<_Tp, _VoidPtr> > >;
115129 using __next_pointer _LIBCPP_NODEBUG = typename _Base::__next_pointer;
116130
......@@ -122,18 +136,20 @@ struct __hash_node : public __hash_node_base< __rebind_pointer_t<_VoidPtr, __has
122136
123137private:
124138 union {
125 _Tp __value_;
139 __node_value_type __value_;
126140 };
127141
128142public:
129 _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return __value_; }
143 _LIBCPP_HIDE_FROM_ABI __node_value_type& __get_value() { return __value_; }
130144#else
131145
132146private:
133 _ALIGNAS_TYPE(_Tp) char __buffer_[sizeof(_Tp)];
147 _ALIGNAS_TYPE(__node_value_type) char __buffer_[sizeof(__node_value_type)];
134148
135149public:
136 _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return *std::__launder(reinterpret_cast<_Tp*>(&__buffer_)); }
150 _LIBCPP_HIDE_FROM_ABI __node_value_type& __get_value() {
151 return *std::__launder(reinterpret_cast<__node_value_type*>(&__buffer_));
152 }
137153#endif
138154
139155 _LIBCPP_HIDE_FROM_ABI explicit __hash_node(__next_pointer __next, size_t __hash) : _Base(__next), __hash_(__hash) {}
......@@ -147,24 +163,24 @@ inline _LIBCPP_HIDE_FROM_ABI size_t __constrain_hash(size_t __h, size_t __bc) {
147163}
148164
149165inline _LIBCPP_HIDE_FROM_ABI size_t __next_hash_pow2(size_t __n) {
150 return __n < 2 ? __n : (size_t(1) << (numeric_limits<size_t>::digits - __libcpp_clz(__n - 1)));
166 return __n < 2 ? __n : (size_t(1) << (numeric_limits<size_t>::digits - std::__countl_zero(__n - 1)));
151167}
152168
153169template <class _Tp, class _Hash, class _Equal, class _Alloc>
154170class __hash_table;
155171
156172template <class _NodePtr>
157class _LIBCPP_TEMPLATE_VIS __hash_iterator;
173class __hash_iterator;
158174template <class _ConstNodePtr>
159class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
175class __hash_const_iterator;
160176template <class _NodePtr>
161class _LIBCPP_TEMPLATE_VIS __hash_local_iterator;
177class __hash_local_iterator;
162178template <class _ConstNodePtr>
163class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
179class __hash_const_local_iterator;
164180template <class _HashIterator>
165class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
181class __hash_map_iterator;
166182template <class _HashIterator>
167class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
183class __hash_map_const_iterator;
168184
169185template <class _Tp>
170186struct __hash_key_value_types {
......@@ -191,18 +207,18 @@ struct __hash_key_value_types<__hash_value_type<_Key, _Tp> > {
191207
192208 _LIBCPP_HIDE_FROM_ABI static key_type const& __get_key(__container_value_type const& __v) { return __v.first; }
193209
194 template <class _Up, __enable_if_t<__is_same_uncvref<_Up, __node_value_type>::value, int> = 0>
210 template <class _Up, __enable_if_t<is_same<__remove_cvref_t<_Up>, __node_value_type>::value, int> = 0>
195211 _LIBCPP_HIDE_FROM_ABI static __container_value_type const& __get_value(_Up& __t) {
196212 return __t.__get_value();
197213 }
198214
199 template <class _Up, __enable_if_t<__is_same_uncvref<_Up, __container_value_type>::value, int> = 0>
215 template <class _Up, __enable_if_t<is_same<__remove_cvref_t<_Up>, __container_value_type>::value, int> = 0>
200216 _LIBCPP_HIDE_FROM_ABI static __container_value_type const& __get_value(_Up& __t) {
201217 return __t;
202218 }
203219
204 _LIBCPP_HIDE_FROM_ABI static __container_value_type* __get_ptr(__node_value_type& __n) {
205 return std::addressof(__n.__get_value());
220 _LIBCPP_HIDE_FROM_ABI static __container_value_type* __get_ptr(__container_value_type& __n) {
221 return std::addressof(__n);
206222 }
207223 _LIBCPP_HIDE_FROM_ABI static pair<key_type&&, mapped_type&&> __move(__node_value_type& __v) { return __v.__move(); }
208224};
......@@ -242,7 +258,7 @@ public:
242258
243259 typedef typename __node_base_type::__next_pointer __next_pointer;
244260
245 typedef _Tp __node_value_type;
261 using __node_value_type _LIBCPP_NODEBUG = __get_hash_node_value_type_t<_Tp>;
246262 typedef __rebind_pointer_t<_VoidPtr, __node_value_type> __node_value_type_pointer;
247263 typedef __rebind_pointer_t<_VoidPtr, const __node_value_type> __const_node_value_type_pointer;
248264
......@@ -273,7 +289,7 @@ struct __make_hash_node_types {
273289};
274290
275291template <class _NodePtr>
276class _LIBCPP_TEMPLATE_VIS __hash_iterator {
292class __hash_iterator {
277293 typedef __hash_node_types<_NodePtr> _NodeTypes;
278294 typedef _NodePtr __node_pointer;
279295 typedef typename _NodeTypes::__next_pointer __next_pointer;
......@@ -327,17 +343,17 @@ private:
327343 template <class, class, class, class>
328344 friend class __hash_table;
329345 template <class>
330 friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
346 friend class __hash_const_iterator;
331347 template <class>
332 friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
348 friend class __hash_map_iterator;
333349 template <class, class, class, class, class>
334 friend class _LIBCPP_TEMPLATE_VIS unordered_map;
350 friend class unordered_map;
335351 template <class, class, class, class, class>
336 friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
352 friend class unordered_multimap;
337353};
338354
339355template <class _NodePtr>
340class _LIBCPP_TEMPLATE_VIS __hash_const_iterator {
356class __hash_const_iterator {
341357 static_assert(!is_const<typename pointer_traits<_NodePtr>::element_type>::value, "");
342358 typedef __hash_node_types<_NodePtr> _NodeTypes;
343359 typedef _NodePtr __node_pointer;
......@@ -395,15 +411,15 @@ private:
395411 template <class, class, class, class>
396412 friend class __hash_table;
397413 template <class>
398 friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
414 friend class __hash_map_const_iterator;
399415 template <class, class, class, class, class>
400 friend class _LIBCPP_TEMPLATE_VIS unordered_map;
416 friend class unordered_map;
401417 template <class, class, class, class, class>
402 friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
418 friend class unordered_multimap;
403419};
404420
405421template <class _NodePtr>
406class _LIBCPP_TEMPLATE_VIS __hash_local_iterator {
422class __hash_local_iterator {
407423 typedef __hash_node_types<_NodePtr> _NodeTypes;
408424 typedef _NodePtr __node_pointer;
409425 typedef typename _NodeTypes::__next_pointer __next_pointer;
......@@ -468,13 +484,13 @@ private:
468484 template <class, class, class, class>
469485 friend class __hash_table;
470486 template <class>
471 friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
487 friend class __hash_const_local_iterator;
472488 template <class>
473 friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
489 friend class __hash_map_iterator;
474490};
475491
476492template <class _ConstNodePtr>
477class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator {
493class __hash_const_local_iterator {
478494 typedef __hash_node_types<_ConstNodePtr> _NodeTypes;
479495 typedef _ConstNodePtr __node_pointer;
480496 typedef typename _NodeTypes::__next_pointer __next_pointer;
......@@ -553,7 +569,7 @@ private:
553569 template <class, class, class, class>
554570 friend class __hash_table;
555571 template <class>
556 friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
572 friend class __hash_map_const_iterator;
557573};
558574
559575template <class _Alloc>
......@@ -667,14 +683,14 @@ int __diagnose_unordered_container_requirements(void*);
667683template <class _Tp, class _Hash, class _Equal, class _Alloc>
668684class __hash_table {
669685public:
670 typedef _Tp value_type;
686 using value_type = __get_hash_node_value_type_t<_Tp>;
671687 typedef _Hash hasher;
672688 typedef _Equal key_equal;
673689 typedef _Alloc allocator_type;
674690
675691private:
676692 typedef allocator_traits<allocator_type> __alloc_traits;
677 typedef typename __make_hash_node_types<value_type, typename __alloc_traits::void_pointer>::type _NodeTypes;
693 typedef typename __make_hash_node_types<_Tp, typename __alloc_traits::void_pointer>::type _NodeTypes;
678694
679695public:
680696 typedef typename _NodeTypes::__node_value_type __node_value_type;
......@@ -770,9 +786,10 @@ public:
770786
771787 _LIBCPP_HIDE_FROM_ABI __hash_table& operator=(const __hash_table& __u);
772788 _LIBCPP_HIDE_FROM_ABI __hash_table& operator=(__hash_table&& __u)
773 _NOEXCEPT_(__node_traits::propagate_on_container_move_assignment::value&&
774 is_nothrow_move_assignable<__node_allocator>::value&& is_nothrow_move_assignable<hasher>::value&&
775 is_nothrow_move_assignable<key_equal>::value);
789 _NOEXCEPT_(is_nothrow_move_assignable<hasher>::value&& is_nothrow_move_assignable<key_equal>::value &&
790 ((__node_traits::propagate_on_container_move_assignment::value &&
791 is_nothrow_move_assignable<__node_allocator>::value) ||
792 allocator_traits<__node_allocator>::is_always_equal::value));
776793 template <class _InputIterator>
777794 _LIBCPP_HIDE_FROM_ABI void __assign_unique(_InputIterator __first, _InputIterator __last);
778795 template <class _InputIterator>
......@@ -835,27 +852,36 @@ public:
835852 template <class... _Args>
836853 _LIBCPP_HIDE_FROM_ABI iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args);
837854
838 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(__container_value_type&& __x) {
839 return __emplace_unique_key_args(_NodeTypes::__get_key(__x), std::move(__x));
840 }
855 template <class _ValueT = _Tp, __enable_if_t<__is_hash_value_type<_ValueT>::value, int> = 0>
856 _LIBCPP_HIDE_FROM_ABI void __insert_unique_from_orphaned_node(value_type&& __value) {
857 using __key_type = typename _NodeTypes::key_type;
841858
842 template <class _Pp, __enable_if_t<!__is_same_uncvref<_Pp, __container_value_type>::value, int> = 0>
843 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(_Pp&& __x) {
844 return __emplace_unique(std::forward<_Pp>(__x));
859 __node_holder __h = __construct_node(const_cast<__key_type&&>(__value.first), std::move(__value.second));
860 __node_insert_unique(__h.get());
861 __h.release();
845862 }
846863
847 template <class _Pp>
848 _LIBCPP_HIDE_FROM_ABI iterator __insert_multi(_Pp&& __x) {
849 return __emplace_multi(std::forward<_Pp>(__x));
864 template <class _ValueT = _Tp, __enable_if_t<!__is_hash_value_type<_ValueT>::value, int> = 0>
865 _LIBCPP_HIDE_FROM_ABI void __insert_unique_from_orphaned_node(value_type&& __value) {
866 __node_holder __h = __construct_node(std::move(__value));
867 __node_insert_unique(__h.get());
868 __h.release();
850869 }
851870
852 template <class _Pp>
853 _LIBCPP_HIDE_FROM_ABI iterator __insert_multi(const_iterator __p, _Pp&& __x) {
854 return __emplace_hint_multi(__p, std::forward<_Pp>(__x));
871 template <class _ValueT = _Tp, __enable_if_t<__is_hash_value_type<_ValueT>::value, int> = 0>
872 _LIBCPP_HIDE_FROM_ABI void __insert_multi_from_orphaned_node(value_type&& __value) {
873 using __key_type = typename _NodeTypes::key_type;
874
875 __node_holder __h = __construct_node(const_cast<__key_type&&>(__value.first), std::move(__value.second));
876 __node_insert_multi(__h.get());
877 __h.release();
855878 }
856879
857 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(const __container_value_type& __x) {
858 return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x);
880 template <class _ValueT = _Tp, __enable_if_t<!__is_hash_value_type<_ValueT>::value, int> = 0>
881 _LIBCPP_HIDE_FROM_ABI void __insert_multi_from_orphaned_node(value_type&& __value) {
882 __node_holder __h = __construct_node(std::move(__value));
883 __node_insert_multi(__h.get());
884 __h.release();
859885 }
860886
861887#if _LIBCPP_STD_VER >= 17
......@@ -1019,10 +1045,25 @@ private:
10191045 _LIBCPP_HIDE_FROM_ABI void __deallocate_node(__next_pointer __np) _NOEXCEPT;
10201046 _LIBCPP_HIDE_FROM_ABI __next_pointer __detach() _NOEXCEPT;
10211047
1048 template <class _From, class _ValueT = _Tp, __enable_if_t<__is_hash_value_type<_ValueT>::value, int> = 0>
1049 _LIBCPP_HIDE_FROM_ABI void __assign_value(__get_hash_node_value_type_t<_Tp>& __lhs, _From&& __rhs) {
1050 using __key_type = typename _NodeTypes::key_type;
1051
1052 // This is technically UB, since the object was constructed as `const`.
1053 // Clang doesn't optimize on this currently though.
1054 const_cast<__key_type&>(__lhs.first) = const_cast<__copy_cvref_t<_From, __key_type>&&>(__rhs.first);
1055 __lhs.second = std::forward<_From>(__rhs).second;
1056 }
1057
1058 template <class _From, class _ValueT = _Tp, __enable_if_t<!__is_hash_value_type<_ValueT>::value, int> = 0>
1059 _LIBCPP_HIDE_FROM_ABI void __assign_value(_Tp& __lhs, _From&& __rhs) {
1060 __lhs = std::forward<_From>(__rhs);
1061 }
1062
10221063 template <class, class, class, class, class>
1023 friend class _LIBCPP_TEMPLATE_VIS unordered_map;
1064 friend class unordered_map;
10241065 template <class, class, class, class, class>
1025 friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
1066 friend class unordered_multimap;
10261067};
10271068
10281069template <class _Tp, class _Hash, class _Equal, class _Alloc>
......@@ -1215,8 +1256,8 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(__hash_table& __u,
12151256#endif // _LIBCPP_HAS_EXCEPTIONS
12161257 const_iterator __i = __u.begin();
12171258 while (__cache != nullptr && __u.size() != 0) {
1218 __cache->__upcast()->__get_value() = std::move(__u.remove(__i++)->__get_value());
1219 __next_pointer __next = __cache->__next_;
1259 __assign_value(__cache->__upcast()->__get_value(), std::move(__u.remove(__i++)->__get_value()));
1260 __next_pointer __next = __cache->__next_;
12201261 __node_insert_multi(__cache->__upcast());
12211262 __cache = __next;
12221263 }
......@@ -1229,19 +1270,17 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(__hash_table& __u,
12291270 __deallocate_node(__cache);
12301271 }
12311272 const_iterator __i = __u.begin();
1232 while (__u.size() != 0) {
1233 __node_holder __h = __construct_node(_NodeTypes::__move(__u.remove(__i++)->__get_value()));
1234 __node_insert_multi(__h.get());
1235 __h.release();
1236 }
1273 while (__u.size() != 0)
1274 __insert_multi_from_orphaned_node(std::move(__u.remove(__i++)->__get_value()));
12371275 }
12381276}
12391277
12401278template <class _Tp, class _Hash, class _Equal, class _Alloc>
1241inline __hash_table<_Tp, _Hash, _Equal, _Alloc>&
1242__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u) _NOEXCEPT_(
1243 __node_traits::propagate_on_container_move_assignment::value&& is_nothrow_move_assignable<__node_allocator>::value&&
1244 is_nothrow_move_assignable<hasher>::value&& is_nothrow_move_assignable<key_equal>::value) {
1279inline __hash_table<_Tp, _Hash, _Equal, _Alloc>& __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u)
1280 _NOEXCEPT_(is_nothrow_move_assignable<hasher>::value&& is_nothrow_move_assignable<key_equal>::value &&
1281 ((__node_traits::propagate_on_container_move_assignment::value &&
1282 is_nothrow_move_assignable<__node_allocator>::value) ||
1283 allocator_traits<__node_allocator>::is_always_equal::value)) {
12451284 __move_assign(__u, integral_constant<bool, __node_traits::propagate_on_container_move_assignment::value>());
12461285 return *this;
12471286}
......@@ -1260,8 +1299,8 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __
12601299 try {
12611300#endif // _LIBCPP_HAS_EXCEPTIONS
12621301 for (; __cache != nullptr && __first != __last; ++__first) {
1263 __cache->__upcast()->__get_value() = *__first;
1264 __next_pointer __next = __cache->__next_;
1302 __assign_value(__cache->__upcast()->__get_value(), *__first);
1303 __next_pointer __next = __cache->__next_;
12651304 __node_insert_unique(__cache->__upcast());
12661305 __cache = __next;
12671306 }
......@@ -1274,7 +1313,7 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __
12741313 __deallocate_node(__cache);
12751314 }
12761315 for (; __first != __last; ++__first)
1277 __insert_unique(*__first);
1316 __emplace_unique(*__first);
12781317}
12791318
12801319template <class _Tp, class _Hash, class _Equal, class _Alloc>
......@@ -1292,7 +1331,7 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __f
12921331 try {
12931332#endif // _LIBCPP_HAS_EXCEPTIONS
12941333 for (; __cache != nullptr && __first != __last; ++__first) {
1295 __cache->__upcast()->__get_value() = *__first;
1334 __assign_value(__cache->__upcast()->__get_value(), *__first);
12961335 __next_pointer __next = __cache->__next_;
12971336 __node_insert_multi(__cache->__upcast());
12981337 __cache = __next;
......@@ -1306,7 +1345,7 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __f
13061345 __deallocate_node(__cache);
13071346 }
13081347 for (; __first != __last; ++__first)
1309 __insert_multi(_NodeTypes::__get_value(*__first));
1348 __emplace_multi(_NodeTypes::__get_value(*__first));
13101349}
13111350
13121351template <class _Tp, class _Hash, class _Equal, class _Alloc>
......@@ -1769,9 +1808,9 @@ template <class _Tp, class _Hash, class _Equal, class _Alloc>
17691808template <class _Key>
17701809typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
17711810__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) {
1772 size_t __hash = hash_function()(__k);
17731811 size_type __bc = bucket_count();
1774 if (__bc != 0) {
1812 if (__bc != 0 && size() != 0) {
1813 size_t __hash = hash_function()(__k);
17751814 size_t __chash = std::__constrain_hash(__hash, __bc);
17761815 __next_pointer __nd = __bucket_list_[__chash];
17771816 if (__nd != nullptr) {
......@@ -1790,9 +1829,9 @@ template <class _Tp, class _Hash, class _Equal, class _Alloc>
17901829template <class _Key>
17911830typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
17921831__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const {
1793 size_t __hash = hash_function()(__k);
17941832 size_type __bc = bucket_count();
1795 if (__bc != 0) {
1833 if (__bc != 0 && size() != 0) {
1834 size_t __hash = hash_function()(__k);
17961835 size_t __chash = std::__constrain_hash(__hash, __bc);
17971836 __next_pointer __nd = __bucket_list_[__chash];
17981837 if (__nd != nullptr) {
lib/libcxx/include/__ios/fpos.h+1-1
......@@ -20,7 +20,7 @@
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
2222template <class _StateT>
23class _LIBCPP_TEMPLATE_VIS fpos {
23class fpos {
2424private:
2525 _StateT __st_;
2626 streamoff __off_;
lib/libcxx/include/__iterator/advance.h+7-9
......@@ -65,9 +65,8 @@ template < class _InputIter,
6565_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 void advance(_InputIter& __i, _Distance __orig_n) {
6666 typedef typename iterator_traits<_InputIter>::difference_type _Difference;
6767 _Difference __n = static_cast<_Difference>(std::__convert_to_integral(__orig_n));
68 // Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation.
69 _LIBCPP_ASSERT_PEDANTIC(__n >= 0 || __has_bidirectional_iterator_category<_InputIter>::value,
70 "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
68 _LIBCPP_ASSERT_PEDANTIC(__has_bidirectional_iterator_category<_InputIter>::value || __n >= 0,
69 "std::advance: Can only pass a negative `n` with a bidirectional_iterator.");
7170 std::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
7271}
7372
......@@ -98,9 +97,8 @@ public:
9897 // Preconditions: If `I` does not model `bidirectional_iterator`, `n` is not negative.
9998 template <input_or_output_iterator _Ip>
10099 _LIBCPP_HIDE_FROM_ABI constexpr void operator()(_Ip& __i, iter_difference_t<_Ip> __n) const {
101 // Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation.
102 _LIBCPP_ASSERT_PEDANTIC(
103 __n >= 0 || bidirectional_iterator<_Ip>, "If `n < 0`, then `bidirectional_iterator<I>` must be true.");
100 _LIBCPP_ASSERT_PEDANTIC(bidirectional_iterator<_Ip> || __n >= 0,
101 "ranges::advance: Can only pass a negative `n` with a bidirectional_iterator.");
104102
105103 // If `I` models `random_access_iterator`, equivalent to `i += n`.
106104 if constexpr (random_access_iterator<_Ip>) {
......@@ -149,9 +147,9 @@ public:
149147 template <input_or_output_iterator _Ip, sentinel_for<_Ip> _Sp>
150148 _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Ip>
151149 operator()(_Ip& __i, iter_difference_t<_Ip> __n, _Sp __bound_sentinel) const {
152 // Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation.
153 _LIBCPP_ASSERT_PEDANTIC((__n >= 0) || (bidirectional_iterator<_Ip> && same_as<_Ip, _Sp>),
154 "If `n < 0`, then `bidirectional_iterator<I> && same_as<I, S>` must be true.");
150 _LIBCPP_ASSERT_PEDANTIC(
151 (bidirectional_iterator<_Ip> && same_as<_Ip, _Sp>) || (__n >= 0),
152 "ranges::advance: Can only pass a negative `n` with a bidirectional_iterator coming from a common_range.");
155153 // If `S` and `I` model `sized_sentinel_for<S, I>`:
156154 if constexpr (sized_sentinel_for<_Sp, _Ip>) {
157155 // If |n| >= |bound_sentinel - i|, equivalent to `ranges::advance(i, bound_sentinel)`.
lib/libcxx/include/__iterator/aliasing_iterator.h+6-3
......@@ -12,8 +12,10 @@
1212#include <__config>
1313#include <__cstddef/ptrdiff_t.h>
1414#include <__iterator/iterator_traits.h>
15#include <__memory/addressof.h>
1516#include <__memory/pointer_traits.h>
16#include <__type_traits/is_trivial.h>
17#include <__type_traits/is_trivially_constructible.h>
18#include <__type_traits/is_trivially_copyable.h>
1719
1820#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1921# pragma GCC system_header
......@@ -44,7 +46,8 @@ struct __aliasing_iterator_wrapper {
4446 using reference = value_type&;
4547 using pointer = value_type*;
4648
47 static_assert(is_trivial<value_type>::value);
49 static_assert(is_trivially_default_constructible<value_type>::value);
50 static_assert(is_trivially_copyable<value_type>::value);
4851 static_assert(sizeof(__base_value_type) == sizeof(value_type));
4952
5053 _LIBCPP_HIDE_FROM_ABI __iterator() = default;
......@@ -102,7 +105,7 @@ struct __aliasing_iterator_wrapper {
102105
103106 _LIBCPP_HIDE_FROM_ABI _Alias operator*() const _NOEXCEPT {
104107 _Alias __val;
105 __builtin_memcpy(&__val, std::__to_address(__base_), sizeof(value_type));
108 __builtin_memcpy(std::addressof(__val), std::__to_address(__base_), sizeof(value_type));
106109 return __val;
107110 }
108111
lib/libcxx/include/__iterator/back_insert_iterator.h+1-1
......@@ -28,7 +28,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2828
2929_LIBCPP_SUPPRESS_DEPRECATED_PUSH
3030template <class _Container>
31class _LIBCPP_TEMPLATE_VIS back_insert_iterator
31class back_insert_iterator
3232#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
3333 : public iterator<output_iterator_tag, void, void, void, void>
3434#endif
lib/libcxx/include/__iterator/common_iterator.h+4-3
......@@ -28,6 +28,7 @@
2828#include <__memory/addressof.h>
2929#include <__type_traits/conditional.h>
3030#include <__type_traits/is_pointer.h>
31#include <__type_traits/is_referenceable.h>
3132#include <__utility/declval.h>
3233#include <variant>
3334
......@@ -157,7 +158,7 @@ public:
157158 ++*this;
158159 return __tmp;
159160 } else if constexpr (requires(_Iter& __i) {
160 { *__i++ } -> __can_reference;
161 { *__i++ } -> __referenceable;
161162 } || !__can_use_postfix_proxy<_Iter>) {
162163 return std::__unchecked_get<_Iter>(__hold_)++;
163164 } else {
......@@ -272,13 +273,13 @@ concept __common_iter_has_ptr_op = requires(const common_iterator<_Iter, _Sent>&
272273
273274template <class, class>
274275struct __arrow_type_or_void {
275 using type = void;
276 using type _LIBCPP_NODEBUG = void;
276277};
277278
278279template <class _Iter, class _Sent>
279280 requires __common_iter_has_ptr_op<_Iter, _Sent>
280281struct __arrow_type_or_void<_Iter, _Sent> {
281 using type = decltype(std::declval<const common_iterator<_Iter, _Sent>&>().operator->());
282 using type _LIBCPP_NODEBUG = decltype(std::declval<const common_iterator<_Iter, _Sent>&>().operator->());
282283};
283284
284285template <input_iterator _Iter, class _Sent>
lib/libcxx/include/__iterator/concepts.h+46-5
......@@ -29,15 +29,19 @@
2929#include <__iterator/incrementable_traits.h>
3030#include <__iterator/iter_move.h>
3131#include <__iterator/iterator_traits.h>
32#include <__iterator/readable_traits.h>
3332#include <__memory/pointer_traits.h>
3433#include <__type_traits/add_pointer.h>
3534#include <__type_traits/common_reference.h>
35#include <__type_traits/conditional.h>
36#include <__type_traits/disjunction.h>
37#include <__type_traits/enable_if.h>
3638#include <__type_traits/integral_constant.h>
3739#include <__type_traits/invoke.h>
3840#include <__type_traits/is_pointer.h>
3941#include <__type_traits/is_primary_template.h>
4042#include <__type_traits/is_reference.h>
43#include <__type_traits/is_referenceable.h>
44#include <__type_traits/is_valid_expansion.h>
4145#include <__type_traits/remove_cv.h>
4246#include <__type_traits/remove_cvref.h>
4347#include <__utility/forward.h>
......@@ -80,12 +84,13 @@ concept __specialization_of_projected = requires {
8084
8185template <class _Tp>
8286struct __indirect_value_t_impl {
83 using type = iter_value_t<_Tp>&;
87 using type _LIBCPP_NODEBUG = iter_value_t<_Tp>&;
8488};
8589template <__specialization_of_projected _Tp>
8690struct __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>;
91 using type _LIBCPP_NODEBUG =
92 invoke_result_t<__projected_projection_t<_Tp>&,
93 typename __indirect_value_t_impl<__projected_iterator_t<_Tp>>::type>;
8994};
9095
9196template <indirectly_readable _Tp>
......@@ -131,7 +136,7 @@ concept incrementable = regular<_Ip> && weakly_incrementable<_Ip> && requires(_I
131136// [iterator.concept.iterator]
132137template <class _Ip>
133138concept input_or_output_iterator = requires(_Ip __i) {
134 { *__i } -> __can_reference;
139 { *__i } -> __referenceable;
135140} && weakly_incrementable<_Ip>;
136141
137142// [iterator.concept.sentinel]
......@@ -149,6 +154,42 @@ concept sized_sentinel_for =
149154 { __i - __s } -> same_as<iter_difference_t<_Ip>>;
150155 };
151156
157template <class _Iter>
158struct __iter_traits_cache {
159 using type _LIBCPP_NODEBUG =
160 _If<__is_primary_template<iterator_traits<_Iter> >::value, _Iter, iterator_traits<_Iter> >;
161};
162template <class _Iter>
163using _ITER_TRAITS _LIBCPP_NODEBUG = typename __iter_traits_cache<_Iter>::type;
164
165struct __iter_concept_concept_test {
166 template <class _Iter>
167 using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_concept;
168};
169struct __iter_concept_category_test {
170 template <class _Iter>
171 using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_category;
172};
173struct __iter_concept_random_fallback {
174 template <class _Iter>
175 using _Apply _LIBCPP_NODEBUG =
176 __enable_if_t<__is_primary_template<iterator_traits<_Iter> >::value, random_access_iterator_tag>;
177};
178
179template <class _Iter, class _Tester>
180struct __test_iter_concept : _IsValidExpansion<_Tester::template _Apply, _Iter>, _Tester {};
181
182template <class _Iter>
183struct __iter_concept_cache {
184 using type _LIBCPP_NODEBUG =
185 _Or<__test_iter_concept<_Iter, __iter_concept_concept_test>,
186 __test_iter_concept<_Iter, __iter_concept_category_test>,
187 __test_iter_concept<_Iter, __iter_concept_random_fallback> >;
188};
189
190template <class _Iter>
191using _ITER_CONCEPT _LIBCPP_NODEBUG = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>;
192
152193// [iterator.concept.input]
153194template <class _Ip>
154195concept input_iterator = input_or_output_iterator<_Ip> && indirectly_readable<_Ip> && requires {
lib/libcxx/include/__iterator/front_insert_iterator.h+1-1
......@@ -28,7 +28,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2828
2929_LIBCPP_SUPPRESS_DEPRECATED_PUSH
3030template <class _Container>
31class _LIBCPP_TEMPLATE_VIS front_insert_iterator
31class front_insert_iterator
3232#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
3333 : public iterator<output_iterator_tag, void, void, void, void>
3434#endif
lib/libcxx/include/__iterator/insert_iterator.h+1-1
......@@ -37,7 +37,7 @@ using __insert_iterator_iter_t _LIBCPP_NODEBUG = typename _Container::iterator;
3737
3838_LIBCPP_SUPPRESS_DEPRECATED_PUSH
3939template <class _Container>
40class _LIBCPP_TEMPLATE_VIS insert_iterator
40class insert_iterator
4141#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
4242 : public iterator<output_iterator_tag, void, void, void, void>
4343#endif
lib/libcxx/include/__iterator/istream_iterator.h+4-1
......@@ -27,7 +27,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2727
2828_LIBCPP_SUPPRESS_DEPRECATED_PUSH
2929template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
30class _LIBCPP_TEMPLATE_VIS istream_iterator
30class istream_iterator
3131#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
3232 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
3333#endif
......@@ -58,6 +58,9 @@ public:
5858 __in_stream_ = nullptr;
5959 }
6060
61 // LWG3600 Changed the wording of the copy constructor. In libc++ this constructor
62 // can still be trivial after this change.
63
6164 _LIBCPP_HIDE_FROM_ABI const _Tp& operator*() const { return __value_; }
6265 _LIBCPP_HIDE_FROM_ABI const _Tp* operator->() const { return std::addressof((operator*())); }
6366 _LIBCPP_HIDE_FROM_ABI istream_iterator& operator++() {
lib/libcxx/include/__iterator/istreambuf_iterator.h+1-1
......@@ -27,7 +27,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2727
2828_LIBCPP_SUPPRESS_DEPRECATED_PUSH
2929template <class _CharT, class _Traits>
30class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
30class istreambuf_iterator
3131#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
3232 : public iterator<input_iterator_tag, _CharT, typename _Traits::off_type, _CharT*, _CharT>
3333#endif
lib/libcxx/include/__iterator/iter_move.h+2-1
......@@ -14,6 +14,7 @@
1414#include <__config>
1515#include <__iterator/iterator_traits.h>
1616#include <__type_traits/is_reference.h>
17#include <__type_traits/is_referenceable.h>
1718#include <__type_traits/remove_cvref.h>
1819#include <__utility/declval.h>
1920#include <__utility/forward.h>
......@@ -90,7 +91,7 @@ inline constexpr auto iter_move = __iter_move::__fn{};
9091
9192template <__dereferenceable _Tp>
9293 requires requires(_Tp& __t) {
93 { ranges::iter_move(__t) } -> __can_reference;
94 { ranges::iter_move(__t) } -> __referenceable;
9495 }
9596using iter_rvalue_reference_t = decltype(ranges::iter_move(std::declval<_Tp&>()));
9697
lib/libcxx/include/__iterator/iterator.h+1-1
......@@ -20,7 +20,7 @@
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
2222template <class _Category, class _Tp, class _Distance = ptrdiff_t, class _Pointer = _Tp*, class _Reference = _Tp&>
23struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 iterator {
23struct _LIBCPP_DEPRECATED_IN_CXX17 iterator {
2424 typedef _Tp value_type;
2525 typedef _Distance difference_type;
2626 typedef _Pointer pointer;
lib/libcxx/include/__iterator/iterator_traits.h+71-126
......@@ -22,16 +22,18 @@
2222#include <__fwd/pair.h>
2323#include <__iterator/incrementable_traits.h>
2424#include <__iterator/readable_traits.h>
25#include <__tuple/tuple_element.h>
2526#include <__type_traits/common_reference.h>
2627#include <__type_traits/conditional.h>
28#include <__type_traits/detected_or.h>
2729#include <__type_traits/disjunction.h>
28#include <__type_traits/enable_if.h>
2930#include <__type_traits/integral_constant.h>
3031#include <__type_traits/is_convertible.h>
3132#include <__type_traits/is_object.h>
3233#include <__type_traits/is_primary_template.h>
3334#include <__type_traits/is_reference.h>
34#include <__type_traits/is_valid_expansion.h>
35#include <__type_traits/is_referenceable.h>
36#include <__type_traits/nat.h>
3537#include <__type_traits/remove_const.h>
3638#include <__type_traits/remove_cv.h>
3739#include <__type_traits/remove_cvref.h>
......@@ -46,15 +48,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4648
4749#if _LIBCPP_STD_VER >= 20
4850
49template <class _Tp>
50using __with_reference _LIBCPP_NODEBUG = _Tp&;
51
52template <class _Tp>
53concept __can_reference = requires { typename __with_reference<_Tp>; };
54
5551template <class _Tp>
5652concept __dereferenceable = requires(_Tp& __t) {
57 { *__t } -> __can_reference; // not required to be equality-preserving
53 { *__t } -> __referenceable; // not required to be equality-preserving
5854};
5955
6056// [iterator.traits]
......@@ -64,92 +60,17 @@ using iter_reference_t = decltype(*std::declval<_Tp&>());
6460#endif // _LIBCPP_STD_VER >= 20
6561
6662template <class _Iter>
67struct _LIBCPP_TEMPLATE_VIS iterator_traits;
63struct iterator_traits;
6864
69struct _LIBCPP_TEMPLATE_VIS input_iterator_tag {};
70struct _LIBCPP_TEMPLATE_VIS output_iterator_tag {};
71struct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {};
72struct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
73struct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
65struct input_iterator_tag {};
66struct output_iterator_tag {};
67struct forward_iterator_tag : public input_iterator_tag {};
68struct bidirectional_iterator_tag : public forward_iterator_tag {};
69struct random_access_iterator_tag : public bidirectional_iterator_tag {};
7470#if _LIBCPP_STD_VER >= 20
75struct _LIBCPP_TEMPLATE_VIS contiguous_iterator_tag : public random_access_iterator_tag {};
71struct contiguous_iterator_tag : public random_access_iterator_tag {};
7672#endif
7773
78template <class _Iter>
79struct __iter_traits_cache {
80 using type = _If< __is_primary_template<iterator_traits<_Iter> >::value, _Iter, iterator_traits<_Iter> >;
81};
82template <class _Iter>
83using _ITER_TRAITS _LIBCPP_NODEBUG = typename __iter_traits_cache<_Iter>::type;
84
85struct __iter_concept_concept_test {
86 template <class _Iter>
87 using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_concept;
88};
89struct __iter_concept_category_test {
90 template <class _Iter>
91 using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_category;
92};
93struct __iter_concept_random_fallback {
94 template <class _Iter>
95 using _Apply _LIBCPP_NODEBUG =
96 __enable_if_t<__is_primary_template<iterator_traits<_Iter> >::value, random_access_iterator_tag>;
97};
98
99template <class _Iter, class _Tester>
100struct __test_iter_concept : _IsValidExpansion<_Tester::template _Apply, _Iter>, _Tester {};
101
102template <class _Iter>
103struct __iter_concept_cache {
104 using type = _Or< __test_iter_concept<_Iter, __iter_concept_concept_test>,
105 __test_iter_concept<_Iter, __iter_concept_category_test>,
106 __test_iter_concept<_Iter, __iter_concept_random_fallback> >;
107};
108
109template <class _Iter>
110using _ITER_CONCEPT _LIBCPP_NODEBUG = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>;
111
112template <class _Tp>
113struct __has_iterator_typedefs {
114private:
115 template <class _Up>
116 static false_type __test(...);
117 template <class _Up>
118 static true_type
119 __test(__void_t<typename _Up::iterator_category>* = nullptr,
120 __void_t<typename _Up::difference_type>* = nullptr,
121 __void_t<typename _Up::value_type>* = nullptr,
122 __void_t<typename _Up::reference>* = nullptr,
123 __void_t<typename _Up::pointer>* = nullptr);
124
125public:
126 static const bool value = decltype(__test<_Tp>(nullptr, nullptr, nullptr, nullptr, nullptr))::value;
127};
128
129template <class _Tp>
130struct __has_iterator_category {
131private:
132 template <class _Up>
133 static false_type __test(...);
134 template <class _Up>
135 static true_type __test(typename _Up::iterator_category* = nullptr);
136
137public:
138 static const bool value = decltype(__test<_Tp>(nullptr))::value;
139};
140
141template <class _Tp>
142struct __has_iterator_concept {
143private:
144 template <class _Up>
145 static false_type __test(...);
146 template <class _Up>
147 static true_type __test(typename _Up::iterator_concept* = nullptr);
148
149public:
150 static const bool value = decltype(__test<_Tp>(nullptr))::value;
151};
152
15374#if _LIBCPP_STD_VER >= 20
15475
15576// The `cpp17-*-iterator` exposition-only concepts have very similar names to the `Cpp17*Iterator` named requirements
......@@ -158,9 +79,9 @@ public:
15879namespace __iterator_traits_detail {
15980template <class _Ip>
16081concept __cpp17_iterator = requires(_Ip __i) {
161 { *__i } -> __can_reference;
82 { *__i } -> __referenceable;
16283 { ++__i } -> same_as<_Ip&>;
163 { *__i++ } -> __can_reference;
84 { *__i++ } -> __referenceable;
16485} && copyable<_Ip>;
16586
16687template <class _Ip>
......@@ -219,16 +140,6 @@ concept __specifies_members = requires {
219140 requires __has_member_iterator_category<_Ip>;
220141};
221142
222template <class>
223struct __iterator_traits_member_pointer_or_void {
224 using type = void;
225};
226
227template <__has_member_pointer _Tp>
228struct __iterator_traits_member_pointer_or_void<_Tp> {
229 using type = typename _Tp::pointer;
230};
231
232143template <class _Tp>
233144concept __cpp17_iterator_missing_members = !__specifies_members<_Tp> && __iterator_traits_detail::__cpp17_iterator<_Tp>;
234145
......@@ -239,14 +150,14 @@ concept __cpp17_input_iterator_missing_members =
239150// Otherwise, `pointer` names `void`.
240151template <class>
241152struct __iterator_traits_member_pointer_or_arrow_or_void {
242 using type = void;
153 using type _LIBCPP_NODEBUG = void;
243154};
244155
245156// [iterator.traits]/3.2.1
246157// If the qualified-id `I::pointer` is valid and denotes a type, `pointer` names that type.
247158template <__has_member_pointer _Ip>
248159struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> {
249 using type = typename _Ip::pointer;
160 using type _LIBCPP_NODEBUG = typename _Ip::pointer;
250161};
251162
252163// Otherwise, if `decltype(declval<I&>().operator->())` is well-formed, then `pointer` names that
......@@ -254,48 +165,48 @@ struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> {
254165template <class _Ip>
255166 requires requires(_Ip& __i) { __i.operator->(); } && (!__has_member_pointer<_Ip>)
256167struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> {
257 using type = decltype(std::declval<_Ip&>().operator->());
168 using type _LIBCPP_NODEBUG = decltype(std::declval<_Ip&>().operator->());
258169};
259170
260171// Otherwise, `reference` names `iter-reference-t<I>`.
261172template <class _Ip>
262173struct __iterator_traits_member_reference {
263 using type = iter_reference_t<_Ip>;
174 using type _LIBCPP_NODEBUG = iter_reference_t<_Ip>;
264175};
265176
266177// [iterator.traits]/3.2.2
267178// If the qualified-id `I::reference` is valid and denotes a type, `reference` names that type.
268179template <__has_member_reference _Ip>
269180struct __iterator_traits_member_reference<_Ip> {
270 using type = typename _Ip::reference;
181 using type _LIBCPP_NODEBUG = typename _Ip::reference;
271182};
272183
273184// [iterator.traits]/3.2.3.4
274185// input_iterator_tag
275186template <class _Ip>
276187struct __deduce_iterator_category {
277 using type = input_iterator_tag;
188 using type _LIBCPP_NODEBUG = input_iterator_tag;
278189};
279190
280191// [iterator.traits]/3.2.3.1
281192// `random_access_iterator_tag` if `I` satisfies `cpp17-random-access-iterator`, or otherwise
282193template <__iterator_traits_detail::__cpp17_random_access_iterator _Ip>
283194struct __deduce_iterator_category<_Ip> {
284 using type = random_access_iterator_tag;
195 using type _LIBCPP_NODEBUG = random_access_iterator_tag;
285196};
286197
287198// [iterator.traits]/3.2.3.2
288199// `bidirectional_iterator_tag` if `I` satisfies `cpp17-bidirectional-iterator`, or otherwise
289200template <__iterator_traits_detail::__cpp17_bidirectional_iterator _Ip>
290201struct __deduce_iterator_category<_Ip> {
291 using type = bidirectional_iterator_tag;
202 using type _LIBCPP_NODEBUG = bidirectional_iterator_tag;
292203};
293204
294205// [iterator.traits]/3.2.3.3
295206// `forward_iterator_tag` if `I` satisfies `cpp17-forward-iterator`, or otherwise
296207template <__iterator_traits_detail::__cpp17_forward_iterator _Ip>
297208struct __deduce_iterator_category<_Ip> {
298 using type = forward_iterator_tag;
209 using type _LIBCPP_NODEBUG = forward_iterator_tag;
299210};
300211
301212template <class _Ip>
......@@ -306,13 +217,13 @@ struct __iterator_traits_iterator_category : __deduce_iterator_category<_Ip> {};
306217// that type.
307218template <__has_member_iterator_category _Ip>
308219struct __iterator_traits_iterator_category<_Ip> {
309 using type = typename _Ip::iterator_category;
220 using type _LIBCPP_NODEBUG = typename _Ip::iterator_category;
310221};
311222
312223// otherwise, it names void.
313224template <class>
314225struct __iterator_traits_difference_type {
315 using type = void;
226 using type _LIBCPP_NODEBUG = void;
316227};
317228
318229// If the qualified-id `incrementable_traits<I>::difference_type` is valid and denotes a type, then
......@@ -320,7 +231,7 @@ struct __iterator_traits_difference_type {
320231template <class _Ip>
321232 requires requires { typename incrementable_traits<_Ip>::difference_type; }
322233struct __iterator_traits_difference_type<_Ip> {
323 using type = typename incrementable_traits<_Ip>::difference_type;
234 using type _LIBCPP_NODEBUG = typename incrementable_traits<_Ip>::difference_type;
324235};
325236
326237// [iterator.traits]/3.4
......@@ -328,6 +239,9 @@ struct __iterator_traits_difference_type<_Ip> {
328239template <class>
329240struct __iterator_traits {};
330241
242template <class _Tp>
243using __pointer_member _LIBCPP_NODEBUG = typename _Tp::pointer;
244
331245// [iterator.traits]/3.1
332246// If `I` has valid ([temp.deduct]) member types `difference-type`, `value-type`, `reference`, and
333247// `iterator-category`, then `iterator-traits<I>` has the following publicly accessible members:
......@@ -336,7 +250,7 @@ struct __iterator_traits<_Ip> {
336250 using iterator_category = typename _Ip::iterator_category;
337251 using value_type = typename _Ip::value_type;
338252 using difference_type = typename _Ip::difference_type;
339 using pointer = typename __iterator_traits_member_pointer_or_void<_Ip>::type;
253 using pointer = __detected_or_t<void, __pointer_member, _Ip>;
340254 using reference = typename _Ip::reference;
341255};
342256
......@@ -391,13 +305,30 @@ struct __iterator_traits<_Iter, true>
391305 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
392306 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value > {};
393307
308template <class _Tp>
309struct __has_iterator_typedefs {
310private:
311 template <class _Up>
312 static false_type __test(...);
313 template <class _Up>
314 static true_type
315 __test(__void_t<typename _Up::iterator_category>* = nullptr,
316 __void_t<typename _Up::difference_type>* = nullptr,
317 __void_t<typename _Up::value_type>* = nullptr,
318 __void_t<typename _Up::reference>* = nullptr,
319 __void_t<typename _Up::pointer>* = nullptr);
320
321public:
322 static const bool value = decltype(__test<_Tp>(nullptr, nullptr, nullptr, nullptr, nullptr))::value;
323};
324
394325// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
395326// exists. Else iterator_traits<Iterator> will be an empty class. This is a
396327// conforming extension which allows some programs to compile and behave as
397328// the client expects instead of failing at compile time.
398329
399330template <class _Iter>
400struct _LIBCPP_TEMPLATE_VIS iterator_traits : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> {
331struct iterator_traits : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> {
401332 using __primary_template _LIBCPP_NODEBUG = iterator_traits;
402333};
403334#endif // _LIBCPP_STD_VER >= 20
......@@ -406,7 +337,7 @@ template <class _Tp>
406337#if _LIBCPP_STD_VER >= 20
407338 requires is_object_v<_Tp>
408339#endif
409struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*> {
340struct iterator_traits<_Tp*> {
410341 typedef ptrdiff_t difference_type;
411342 typedef __remove_cv_t<_Tp> value_type;
412343 typedef _Tp* pointer;
......@@ -417,18 +348,19 @@ struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*> {
417348#endif
418349};
419350
420template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
421struct __has_iterator_category_convertible_to : is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up> {
422};
351template <class _Tp>
352using __iterator_category _LIBCPP_NODEBUG = typename _Tp::iterator_category;
423353
424template <class _Tp, class _Up>
425struct __has_iterator_category_convertible_to<_Tp, _Up, false> : false_type {};
354template <class _Tp>
355using __iterator_concept _LIBCPP_NODEBUG = typename _Tp::iterator_concept;
426356
427template <class _Tp, class _Up, bool = __has_iterator_concept<_Tp>::value>
428struct __has_iterator_concept_convertible_to : is_convertible<typename _Tp::iterator_concept, _Up> {};
357template <class _Tp, class _Up>
358using __has_iterator_category_convertible_to _LIBCPP_NODEBUG =
359 is_convertible<__detected_or_t<__nat, __iterator_category, iterator_traits<_Tp> >, _Up>;
429360
430361template <class _Tp, class _Up>
431struct __has_iterator_concept_convertible_to<_Tp, _Up, false> : false_type {};
362using __has_iterator_concept_convertible_to _LIBCPP_NODEBUG =
363 is_convertible<__detected_or_t<__nat, __iterator_concept, _Tp>, _Up>;
432364
433365template <class _Tp>
434366using __has_input_iterator_category _LIBCPP_NODEBUG = __has_iterator_category_convertible_to<_Tp, input_iterator_tag>;
......@@ -490,6 +422,18 @@ using __has_exactly_bidirectional_iterator_category _LIBCPP_NODEBUG =
490422template <class _InputIterator>
491423using __iter_value_type _LIBCPP_NODEBUG = typename iterator_traits<_InputIterator>::value_type;
492424
425#if _LIBCPP_STD_VER >= 23
426template <class _InputIterator>
427using __iter_key_type _LIBCPP_NODEBUG = remove_const_t<tuple_element_t<0, __iter_value_type<_InputIterator>>>;
428
429template <class _InputIterator>
430using __iter_mapped_type _LIBCPP_NODEBUG = tuple_element_t<1, __iter_value_type<_InputIterator>>;
431
432template <class _InputIterator>
433using __iter_to_alloc_type _LIBCPP_NODEBUG =
434 pair<const tuple_element_t<0, __iter_value_type<_InputIterator>>,
435 tuple_element_t<1, __iter_value_type<_InputIterator>>>;
436#else
493437template <class _InputIterator>
494438using __iter_key_type _LIBCPP_NODEBUG =
495439 __remove_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>;
......@@ -501,6 +445,7 @@ template <class _InputIterator>
501445using __iter_to_alloc_type _LIBCPP_NODEBUG =
502446 pair<const typename iterator_traits<_InputIterator>::value_type::first_type,
503447 typename iterator_traits<_InputIterator>::value_type::second_type>;
448#endif // _LIBCPP_STD_VER >= 23
504449
505450template <class _Iter>
506451using __iterator_category_type _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::iterator_category;
lib/libcxx/include/__iterator/move_iterator.h+1-1
......@@ -64,7 +64,7 @@ concept __move_iter_comparable = requires {
6464#endif // _LIBCPP_STD_VER >= 20
6565
6666template <class _Iter>
67class _LIBCPP_TEMPLATE_VIS move_iterator
67class move_iterator
6868#if _LIBCPP_STD_VER >= 20
6969 : public __move_iter_category_base<_Iter>
7070#endif
lib/libcxx/include/__iterator/move_sentinel.h+1-1
......@@ -27,7 +27,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2727#if _LIBCPP_STD_VER >= 20
2828
2929template <semiregular _Sent>
30class _LIBCPP_TEMPLATE_VIS move_sentinel {
30class move_sentinel {
3131public:
3232 _LIBCPP_HIDE_FROM_ABI move_sentinel() = default;
3333
lib/libcxx/include/__iterator/next.h-6
......@@ -10,7 +10,6 @@
1010#ifndef _LIBCPP___ITERATOR_NEXT_H
1111#define _LIBCPP___ITERATOR_NEXT_H
1212
13#include <__assert>
1413#include <__config>
1514#include <__iterator/advance.h>
1615#include <__iterator/concepts.h>
......@@ -27,11 +26,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2726template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
2827[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _InputIter
2928next(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n = 1) {
30 // Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation.
31 // Note that this check duplicates the similar check in `std::advance`.
32 _LIBCPP_ASSERT_PEDANTIC(__n >= 0 || __has_bidirectional_iterator_category<_InputIter>::value,
33 "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
34
3529 std::advance(__x, __n);
3630 return __x;
3731}
lib/libcxx/include/__iterator/ostream_iterator.h+1-1
......@@ -26,7 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2626
2727_LIBCPP_SUPPRESS_DEPRECATED_PUSH
2828template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
29class _LIBCPP_TEMPLATE_VIS ostream_iterator
29class ostream_iterator
3030#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
3131 : public iterator<output_iterator_tag, void, void, void, void>
3232#endif
lib/libcxx/include/__iterator/ostreambuf_iterator.h+1-1
......@@ -27,7 +27,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2727
2828_LIBCPP_SUPPRESS_DEPRECATED_PUSH
2929template <class _CharT, class _Traits>
30class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
30class ostreambuf_iterator
3131#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
3232 : public iterator<output_iterator_tag, void, void, void, void>
3333#endif
lib/libcxx/include/__iterator/prev.h-5
......@@ -10,7 +10,6 @@
1010#ifndef _LIBCPP___ITERATOR_PREV_H
1111#define _LIBCPP___ITERATOR_PREV_H
1212
13#include <__assert>
1413#include <__config>
1514#include <__iterator/advance.h>
1615#include <__iterator/concepts.h>
......@@ -31,10 +30,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3130template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
3231[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _InputIter
3332prev(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n) {
34 // Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation.
35 // Note that this check duplicates the similar check in `std::advance`.
36 _LIBCPP_ASSERT_PEDANTIC(__n <= 0 || __has_bidirectional_iterator_category<_InputIter>::value,
37 "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
3833 std::advance(__x, -__n);
3934 return __x;
4035}
lib/libcxx/include/__iterator/product_iterator.h created+76
......@@ -0,0 +1,76 @@
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___ITERATOR_PRODUCT_ITERATOR_H
10#define _LIBCPP___ITERATOR_PRODUCT_ITERATOR_H
11
12// Product iterators are iterators that contain two or more underlying iterators.
13//
14// For example, std::flat_map stores its data into two separate containers, and its iterator
15// is a proxy over two separate underlying iterators. The concept of product iterators
16// allows algorithms to operate over these underlying iterators separately, opening the
17// door to various optimizations.
18//
19// If __product_iterator_traits can be instantiated, the following functions and associated types must be provided:
20// - static constexpr size_t Traits::__size
21// The number of underlying iterators inside the product iterator.
22//
23// - template <size_t _N>
24// static decltype(auto) Traits::__get_iterator_element(It&& __it)
25// Returns the _Nth iterator element of the given product iterator.
26//
27// - template <class... _Iters>
28// static _Iterator __make_product_iterator(_Iters&&...);
29// Creates a product iterator from the given underlying iterators.
30
31#include <__config>
32#include <__cstddef/size_t.h>
33#include <__type_traits/enable_if.h>
34#include <__type_traits/integral_constant.h>
35#include <__utility/declval.h>
36
37#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
38# pragma GCC system_header
39#endif
40
41_LIBCPP_BEGIN_NAMESPACE_STD
42
43template <class _Iterator>
44struct __product_iterator_traits;
45/* exposition-only:
46{
47 static constexpr size_t __size = ...;
48
49 template <size_t _N, class _Iter>
50 static decltype(auto) __get_iterator_element(_Iter&&);
51
52 template <class... _Iters>
53 static _Iterator __make_product_iterator(_Iters&&...);
54};
55*/
56
57template <class _Tp, size_t = 0>
58struct __is_product_iterator : false_type {};
59
60template <class _Tp>
61struct __is_product_iterator<_Tp, sizeof(__product_iterator_traits<_Tp>) * 0> : true_type {};
62
63template <class _Tp, size_t _Size, class = void>
64struct __is_product_iterator_of_size : false_type {};
65
66template <class _Tp, size_t _Size>
67struct __is_product_iterator_of_size<_Tp, _Size, __enable_if_t<__product_iterator_traits<_Tp>::__size == _Size> >
68 : true_type {};
69
70template <class _Iterator, size_t _Nth>
71using __product_iterator_element_t _LIBCPP_NODEBUG =
72 decltype(__product_iterator_traits<_Iterator>::template __get_iterator_element<_Nth>(std::declval<_Iterator>()));
73
74_LIBCPP_END_NAMESPACE_STD
75
76#endif // _LIBCPP___ITERATOR_PRODUCT_ITERATOR_H
lib/libcxx/include/__iterator/reverse_iterator.h+1-1
......@@ -48,7 +48,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4848
4949_LIBCPP_SUPPRESS_DEPRECATED_PUSH
5050template <class _Iter>
51class _LIBCPP_TEMPLATE_VIS reverse_iterator
51class reverse_iterator
5252#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
5353 : public iterator<typename iterator_traits<_Iter>::iterator_category,
5454 typename iterator_traits<_Iter>::value_type,
lib/libcxx/include/__iterator/segmented_iterator.h+6
......@@ -42,6 +42,7 @@
4242
4343#include <__config>
4444#include <__cstddef/size_t.h>
45#include <__iterator/iterator_traits.h>
4546#include <__type_traits/integral_constant.h>
4647
4748#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -74,6 +75,11 @@ struct __has_specialization<_Tp, sizeof(_Tp) * 0> : true_type {};
7475template <class _Iterator>
7576using __is_segmented_iterator _LIBCPP_NODEBUG = __has_specialization<__segmented_iterator_traits<_Iterator> >;
7677
78template <class _SegmentedIterator>
79struct __has_random_access_local_iterator
80 : __has_random_access_iterator_category<
81 typename __segmented_iterator_traits< _SegmentedIterator >::__local_iterator > {};
82
7783_LIBCPP_END_NAMESPACE_STD
7884
7985#endif // _LIBCPP___SEGMENTED_ITERATOR_H
lib/libcxx/include/__iterator/wrap_iter.h+3-3
......@@ -112,9 +112,9 @@ private:
112112 template <class _CharT, class _Traits>
113113 friend class basic_string_view;
114114 template <class _Tp, class _Alloc>
115 friend class _LIBCPP_TEMPLATE_VIS vector;
115 friend class vector;
116116 template <class _Tp, size_t>
117 friend class _LIBCPP_TEMPLATE_VIS span;
117 friend class span;
118118 template <class _Tp, size_t _Size>
119119 friend struct array;
120120};
......@@ -236,7 +236,7 @@ struct __libcpp_is_contiguous_iterator<__wrap_iter<_It> > : true_type {};
236236#endif
237237
238238template <class _It>
239struct _LIBCPP_TEMPLATE_VIS pointer_traits<__wrap_iter<_It> > {
239struct pointer_traits<__wrap_iter<_It> > {
240240 typedef __wrap_iter<_It> pointer;
241241 typedef typename pointer_traits<_It>::element_type element_type;
242242 typedef typename pointer_traits<_It>::difference_type difference_type;
lib/libcxx/include/__locale+114-122
......@@ -11,36 +11,43 @@
1111#define _LIBCPP___LOCALE
1212
1313#include <__config>
14#include <__locale_dir/locale_base_api.h>
15#include <__memory/shared_count.h>
16#include <__mutex/once_flag.h>
17#include <__type_traits/make_unsigned.h>
18#include <__utility/no_destroy.h>
19#include <__utility/private_constructor_tag.h>
20#include <cctype>
21#include <clocale>
22#include <cstdint>
23#include <cstdlib>
24#include <string>
14
15#if _LIBCPP_HAS_LOCALIZATION
16
17# include <__locale_dir/locale_base_api.h>
18# include <__memory/addressof.h>
19# include <__memory/shared_count.h>
20# include <__mutex/once_flag.h>
21# include <__type_traits/make_unsigned.h>
22# include <__utility/no_destroy.h>
23# include <__utility/private_constructor_tag.h>
24# include <cctype>
25# include <clocale>
26# include <cstdint>
27# include <cstdlib>
28# include <string>
2529
2630// Some platforms require more includes than others. Keep the includes on all plaforms for now.
27#include <cstddef>
28#include <cstring>
31# include <cstddef>
32# include <cstring>
2933
30#if _LIBCPP_HAS_WIDE_CHARACTERS
31# include <cwchar>
32#else
33# include <__std_mbstate_t.h>
34#endif
34# if _LIBCPP_HAS_WIDE_CHARACTERS
35# include <cwchar>
36# else
37# include <__std_mbstate_t.h>
38# endif
3539
36#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
37# pragma GCC system_header
38#endif
40# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
41# pragma GCC system_header
42# endif
3943
4044_LIBCPP_BEGIN_NAMESPACE_STD
4145
4246class _LIBCPP_EXPORTED_FROM_ABI locale;
4347
48template <class _CharT>
49class collate;
50
4451template <class _Facet>
4552_LIBCPP_HIDE_FROM_ABI bool has_facet(const locale&) _NOEXCEPT;
4653
......@@ -49,8 +56,10 @@ _LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale&);
4956
5057class _LIBCPP_EXPORTED_FROM_ABI locale {
5158public:
52 // locale is essentially a shared_ptr that doesn't support weak_ptrs and never got a move constructor.
59 // locale is essentially a shared_ptr that doesn't support weak_ptrs and never got a move constructor,
60 // so it is trivially relocatable. Like shared_ptr, it is also replaceable.
5361 using __trivially_relocatable _LIBCPP_NODEBUG = locale;
62 using __replaceable _LIBCPP_NODEBUG = locale;
5463
5564 // types:
5665 class _LIBCPP_EXPORTED_FROM_ABI facet;
......@@ -80,17 +89,25 @@ public:
8089 const locale& operator=(const locale&) _NOEXCEPT;
8190
8291 template <class _Facet>
83 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS locale combine(const locale&) const;
92 _LIBCPP_HIDE_FROM_ABI locale combine(const locale& __other) const {
93 if (!std::has_facet<_Facet>(__other))
94 __throw_runtime_error("locale::combine: locale missing facet");
95
96 return locale(*this, std::addressof(const_cast<_Facet&>(std::use_facet<_Facet>(__other))));
97 }
8498
8599 // locale operations:
86100 string name() const;
87101 bool operator==(const locale&) const;
88#if _LIBCPP_STD_VER <= 17
102# if _LIBCPP_STD_VER <= 17
89103 _LIBCPP_HIDE_FROM_ABI bool operator!=(const locale& __y) const { return !(*this == __y); }
90#endif
104# endif
91105 template <class _CharT, class _Traits, class _Allocator>
92 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool
93 operator()(const basic_string<_CharT, _Traits, _Allocator>&, const basic_string<_CharT, _Traits, _Allocator>&) const;
106 _LIBCPP_HIDE_FROM_ABI bool operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
107 const basic_string<_CharT, _Traits, _Allocator>& __y) const {
108 return std::use_facet<std::collate<_CharT> >(*this).compare(
109 __x.data(), __x.data() + __x.size(), __y.data(), __y.data() + __y.size()) < 0;
110 }
94111
95112 // global locale objects:
96113 static locale global(const locale&);
......@@ -151,14 +168,6 @@ inline _LIBCPP_HIDE_FROM_ABI locale::locale(const locale& __other, _Facet* __f)
151168 __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
152169}
153170
154template <class _Facet>
155locale locale::combine(const locale& __other) const {
156 if (!std::has_facet<_Facet>(__other))
157 __throw_runtime_error("locale::combine: locale missing facet");
158
159 return locale(*this, &const_cast<_Facet&>(std::use_facet<_Facet>(__other)));
160}
161
162171template <class _Facet>
163172inline _LIBCPP_HIDE_FROM_ABI bool has_facet(const locale& __l) _NOEXCEPT {
164173 return __l.has_facet(_Facet::id);
......@@ -172,7 +181,7 @@ inline _LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale& __l) {
172181// template <class _CharT> class collate;
173182
174183template <class _CharT>
175class _LIBCPP_TEMPLATE_VIS collate : public locale::facet {
184class collate : public locale::facet {
176185public:
177186 typedef _CharT char_type;
178187 typedef basic_string<char_type> string_type;
......@@ -237,14 +246,14 @@ long collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) cons
237246}
238247
239248extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>;
240#if _LIBCPP_HAS_WIDE_CHARACTERS
249# if _LIBCPP_HAS_WIDE_CHARACTERS
241250extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>;
242#endif
251# endif
243252
244253// template <class CharT> class collate_byname;
245254
246255template <class _CharT>
247class _LIBCPP_TEMPLATE_VIS collate_byname;
256class collate_byname;
248257
249258template <>
250259class _LIBCPP_EXPORTED_FROM_ABI collate_byname<char> : public collate<char> {
......@@ -264,7 +273,7 @@ protected:
264273 string_type do_transform(const char_type* __lo, const char_type* __hi) const override;
265274};
266275
267#if _LIBCPP_HAS_WIDE_CHARACTERS
276# if _LIBCPP_HAS_WIDE_CHARACTERS
268277template <>
269278class _LIBCPP_EXPORTED_FROM_ABI collate_byname<wchar_t> : public collate<wchar_t> {
270279 __locale::__locale_t __l_;
......@@ -283,20 +292,13 @@ protected:
283292 const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const override;
284293 string_type do_transform(const char_type* __lo, const char_type* __hi) const override;
285294};
286#endif
287
288template <class _CharT, class _Traits, class _Allocator>
289bool locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
290 const basic_string<_CharT, _Traits, _Allocator>& __y) const {
291 return std::use_facet<std::collate<_CharT> >(*this).compare(
292 __x.data(), __x.data() + __x.size(), __y.data(), __y.data() + __y.size()) < 0;
293}
295# endif
294296
295297// template <class charT> class ctype
296298
297299class _LIBCPP_EXPORTED_FROM_ABI ctype_base {
298300public:
299#if defined(_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE)
301# if defined(_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE)
300302 typedef unsigned long mask;
301303 static const mask space = 1 << 0;
302304 static const mask print = 1 << 1;
......@@ -308,14 +310,14 @@ public:
308310 static const mask punct = 1 << 7;
309311 static const mask xdigit = 1 << 8;
310312 static const mask blank = 1 << 9;
311# if defined(__BIONIC__)
313# if defined(__BIONIC__)
312314 // Historically this was a part of regex_traits rather than ctype_base. The
313315 // historical value of the constant is preserved for ABI compatibility.
314316 static const mask __regex_word = 0x8000;
315# else
317# else
316318 static const mask __regex_word = 1 << 10;
317# endif // defined(__BIONIC__)
318#elif defined(__GLIBC__)
319# endif // defined(__BIONIC__)
320# elif defined(__GLIBC__)
319321 typedef unsigned short mask;
320322 static const mask space = _ISspace;
321323 static const mask print = _ISprint;
......@@ -327,12 +329,12 @@ public:
327329 static const mask punct = _ISpunct;
328330 static const mask xdigit = _ISxdigit;
329331 static const mask blank = _ISblank;
330# if defined(__mips__) || (BYTE_ORDER == BIG_ENDIAN)
332# if defined(__mips__) || (BYTE_ORDER == BIG_ENDIAN)
331333 static const mask __regex_word = static_cast<mask>(_ISbit(15));
332# else
334# else
333335 static const mask __regex_word = 0x80;
334# endif
335#elif defined(_LIBCPP_MSVCRT_LIKE)
336# endif
337# elif defined(_LIBCPP_MSVCRT_LIKE)
336338 typedef unsigned short mask;
337339 static const mask space = _SPACE;
338340 static const mask print = _BLANK | _PUNCT | _ALPHA | _DIGIT;
......@@ -345,16 +347,16 @@ public:
345347 static const mask xdigit = _HEX;
346348 static const mask blank = _BLANK;
347349 static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used
348# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
349# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
350#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
351# ifdef __APPLE__
350# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
351# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
352# elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
353# ifdef __APPLE__
352354 typedef uint32_t mask;
353# elif defined(__FreeBSD__)
355# elif defined(__FreeBSD__)
354356 typedef unsigned long mask;
355# elif defined(__NetBSD__)
357# elif defined(__NetBSD__)
356358 typedef unsigned short mask;
357# endif
359# endif
358360 static const mask space = _CTYPE_S;
359361 static const mask print = _CTYPE_R;
360362 static const mask cntrl = _CTYPE_C;
......@@ -365,16 +367,16 @@ public:
365367 static const mask punct = _CTYPE_P;
366368 static const mask xdigit = _CTYPE_X;
367369
368# if defined(__NetBSD__)
370# if defined(__NetBSD__)
369371 static const mask blank = _CTYPE_BL;
370372 // NetBSD defines classes up to 0x2000
371373 // see sys/ctype_bits.h, _CTYPE_Q
372374 static const mask __regex_word = 0x8000;
373# else
375# else
374376 static const mask blank = _CTYPE_B;
375377 static const mask __regex_word = 0x80;
376# endif
377#elif defined(_AIX)
378# endif
379# elif defined(_AIX)
378380 typedef unsigned int mask;
379381 static const mask space = _ISSPACE;
380382 static const mask print = _ISPRINT;
......@@ -387,7 +389,7 @@ public:
387389 static const mask xdigit = _ISXDIGIT;
388390 static const mask blank = _ISBLANK;
389391 static const mask __regex_word = 0x8000;
390#elif defined(_NEWLIB_VERSION)
392# elif defined(_NEWLIB_VERSION)
391393 // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
392394 typedef char mask;
393395 // In case char is signed, static_cast is needed to avoid warning on
......@@ -404,11 +406,11 @@ public:
404406 static const mask blank = static_cast<mask>(_B);
405407 // mask is already fully saturated, use a different type in regex_type_traits.
406408 static const unsigned short __regex_word = 0x100;
407# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
408# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
409# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
410#elif defined(__MVS__)
411# if defined(__NATIVE_ASCII_F)
409# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
410# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
411# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
412# elif defined(__MVS__)
413# if defined(__NATIVE_ASCII_F)
412414 typedef unsigned int mask;
413415 static const mask space = _ISSPACE_A;
414416 static const mask print = _ISPRINT_A;
......@@ -420,7 +422,7 @@ public:
420422 static const mask punct = _ISPUNCT_A;
421423 static const mask xdigit = _ISXDIGIT_A;
422424 static const mask blank = _ISBLANK_A;
423# else
425# else
424426 typedef unsigned short mask;
425427 static const mask space = __ISSPACE;
426428 static const mask print = __ISPRINT;
......@@ -432,11 +434,11 @@ public:
432434 static const mask punct = __ISPUNCT;
433435 static const mask xdigit = __ISXDIGIT;
434436 static const mask blank = __ISBLANK;
435# endif
437# endif
436438 static const mask __regex_word = 0x8000;
437#else
438# error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?
439#endif
439# else
440# error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?
441# endif
440442 static const mask alnum = alpha | digit;
441443 static const mask graph = alnum | punct;
442444
......@@ -448,9 +450,9 @@ public:
448450};
449451
450452template <class _CharT>
451class _LIBCPP_TEMPLATE_VIS ctype;
453class ctype;
452454
453#if _LIBCPP_HAS_WIDE_CHARACTERS
455# if _LIBCPP_HAS_WIDE_CHARACTERS
454456template <>
455457class _LIBCPP_EXPORTED_FROM_ABI ctype<wchar_t> : public locale::facet, public ctype_base {
456458public:
......@@ -515,7 +517,7 @@ protected:
515517 virtual const char_type*
516518 do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
517519};
518#endif // _LIBCPP_HAS_WIDE_CHARACTERS
520# endif // _LIBCPP_HAS_WIDE_CHARACTERS
519521
520522inline _LIBCPP_HIDE_FROM_ABI bool __libcpp_isascii(int __c) { return (__c & ~0x7F) == 0; }
521523
......@@ -580,25 +582,13 @@ public:
580582
581583 static locale::id id;
582584
583#ifdef _CACHED_RUNES
585# ifdef _CACHED_RUNES
584586 static const size_t table_size = _CACHED_RUNES;
585#else
587# else
586588 static const size_t table_size = 256; // FIXME: Don't hardcode this.
587#endif
589# endif
588590 _LIBCPP_HIDE_FROM_ABI const mask* table() const _NOEXCEPT { return __tab_; }
589591 static const mask* classic_table() _NOEXCEPT;
590#if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
591 static const int* __classic_upper_table() _NOEXCEPT;
592 static const int* __classic_lower_table() _NOEXCEPT;
593#endif
594#if defined(__NetBSD__)
595 static const short* __classic_upper_table() _NOEXCEPT;
596 static const short* __classic_lower_table() _NOEXCEPT;
597#endif
598#if defined(__MVS__)
599 static const unsigned short* __classic_upper_table() _NOEXCEPT;
600 static const unsigned short* __classic_lower_table() _NOEXCEPT;
601#endif
602592
603593protected:
604594 ~ctype() override;
......@@ -615,7 +605,7 @@ protected:
615605// template <class CharT> class ctype_byname;
616606
617607template <class _CharT>
618class _LIBCPP_TEMPLATE_VIS ctype_byname;
608class ctype_byname;
619609
620610template <>
621611class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<char> : public ctype<char> {
......@@ -633,7 +623,7 @@ protected:
633623 const char_type* do_tolower(char_type* __low, const char_type* __high) const override;
634624};
635625
636#if _LIBCPP_HAS_WIDE_CHARACTERS
626# if _LIBCPP_HAS_WIDE_CHARACTERS
637627template <>
638628class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<wchar_t> : public ctype<wchar_t> {
639629 __locale::__locale_t __l_;
......@@ -658,7 +648,7 @@ protected:
658648 const char_type*
659649 do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const override;
660650};
661#endif // _LIBCPP_HAS_WIDE_CHARACTERS
651# endif // _LIBCPP_HAS_WIDE_CHARACTERS
662652
663653template <class _CharT>
664654inline _LIBCPP_HIDE_FROM_ABI bool isspace(_CharT __c, const locale& __loc) {
......@@ -741,7 +731,7 @@ public:
741731// template <class internT, class externT, class stateT> class codecvt;
742732
743733template <class _InternT, class _ExternT, class _StateT>
744class _LIBCPP_TEMPLATE_VIS codecvt;
734class codecvt;
745735
746736// template <> class codecvt<char, char, mbstate_t>
747737
......@@ -824,7 +814,7 @@ protected:
824814
825815// template <> class codecvt<wchar_t, char, mbstate_t>
826816
827#if _LIBCPP_HAS_WIDE_CHARACTERS
817# if _LIBCPP_HAS_WIDE_CHARACTERS
828818template <>
829819class _LIBCPP_EXPORTED_FROM_ABI codecvt<wchar_t, char, mbstate_t> : public locale::facet, public codecvt_base {
830820 __locale::__locale_t __l_;
......@@ -903,7 +893,7 @@ protected:
903893 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
904894 virtual int do_max_length() const _NOEXCEPT;
905895};
906#endif // _LIBCPP_HAS_WIDE_CHARACTERS
896# endif // _LIBCPP_HAS_WIDE_CHARACTERS
907897
908898// template <> class codecvt<char16_t, char, mbstate_t> // deprecated in C++20
909899
......@@ -985,7 +975,7 @@ protected:
985975 virtual int do_max_length() const _NOEXCEPT;
986976};
987977
988#if _LIBCPP_HAS_CHAR8_T
978# if _LIBCPP_HAS_CHAR8_T
989979
990980// template <> class codecvt<char16_t, char8_t, mbstate_t> // C++20
991981
......@@ -1066,7 +1056,7 @@ protected:
10661056 virtual int do_max_length() const _NOEXCEPT;
10671057};
10681058
1069#endif
1059# endif
10701060
10711061// template <> class codecvt<char32_t, char, mbstate_t> // deprecated in C++20
10721062
......@@ -1148,7 +1138,7 @@ protected:
11481138 virtual int do_max_length() const _NOEXCEPT;
11491139};
11501140
1151#if _LIBCPP_HAS_CHAR8_T
1141# if _LIBCPP_HAS_CHAR8_T
11521142
11531143// template <> class codecvt<char32_t, char8_t, mbstate_t> // C++20
11541144
......@@ -1229,12 +1219,12 @@ protected:
12291219 virtual int do_max_length() const _NOEXCEPT;
12301220};
12311221
1232#endif
1222# endif
12331223
12341224// template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
12351225
12361226template <class _InternT, class _ExternT, class _StateT>
1237class _LIBCPP_TEMPLATE_VIS codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> {
1227class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> {
12381228public:
12391229 _LIBCPP_HIDE_FROM_ABI explicit codecvt_byname(const char* __nm, size_t __refs = 0)
12401230 : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
......@@ -1251,17 +1241,17 @@ codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname() {}
12511241_LIBCPP_SUPPRESS_DEPRECATED_POP
12521242
12531243extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>;
1254#if _LIBCPP_HAS_WIDE_CHARACTERS
1244# if _LIBCPP_HAS_WIDE_CHARACTERS
12551245extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>;
1256#endif
1246# endif
12571247extern template class _LIBCPP_DEPRECATED_IN_CXX20
12581248_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>; // deprecated in C++20
12591249extern template class _LIBCPP_DEPRECATED_IN_CXX20
12601250_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>; // deprecated in C++20
1261#if _LIBCPP_HAS_CHAR8_T
1251# if _LIBCPP_HAS_CHAR8_T
12621252extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>; // C++20
12631253extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>; // C++20
1264#endif
1254# endif
12651255
12661256template <size_t _Np>
12671257struct __narrow_to_utf8 {
......@@ -1298,7 +1288,7 @@ struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<16> : public codecvt<char16_t,
12981288 const char16_t* __wn = (const char16_t*)__wb;
12991289 __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn, __buf, __buf + __sz, __bn);
13001290 if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
1301 __throw_runtime_error("locale not supported");
1291 std::__throw_runtime_error("locale not supported");
13021292 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
13031293 *__s = *__p;
13041294 __wb = (const _CharT*)__wn;
......@@ -1326,7 +1316,7 @@ struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<32> : public codecvt<char32_t,
13261316 const char32_t* __wn = (const char32_t*)__wb;
13271317 __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn, __buf, __buf + __sz, __bn);
13281318 if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
1329 __throw_runtime_error("locale not supported");
1319 std::__throw_runtime_error("locale not supported");
13301320 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
13311321 *__s = *__p;
13321322 __wb = (const _CharT*)__wn;
......@@ -1370,7 +1360,7 @@ struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<16> : public codecvt<char16_t
13701360 const char* __nn = __nb;
13711361 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb + __sz : __ne, __nn, __buf, __buf + __sz, __bn);
13721362 if (__r == codecvt_base::error || __nn == __nb)
1373 __throw_runtime_error("locale not supported");
1363 std::__throw_runtime_error("locale not supported");
13741364 for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
13751365 *__s = *__p;
13761366 __nb = __nn;
......@@ -1398,7 +1388,7 @@ struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<32> : public codecvt<char32_t
13981388 const char* __nn = __nb;
13991389 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb + __sz : __ne, __nn, __buf, __buf + __sz, __bn);
14001390 if (__r == codecvt_base::error || __nn == __nb)
1401 __throw_runtime_error("locale not supported");
1391 std::__throw_runtime_error("locale not supported");
14021392 for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
14031393 *__s = *__p;
14041394 __nb = __nn;
......@@ -1410,7 +1400,7 @@ struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<32> : public codecvt<char32_t
14101400// template <class charT> class numpunct
14111401
14121402template <class _CharT>
1413class _LIBCPP_TEMPLATE_VIS numpunct;
1403class numpunct;
14141404
14151405template <>
14161406class _LIBCPP_EXPORTED_FROM_ABI numpunct<char> : public locale::facet {
......@@ -1441,7 +1431,7 @@ protected:
14411431 string __grouping_;
14421432};
14431433
1444#if _LIBCPP_HAS_WIDE_CHARACTERS
1434# if _LIBCPP_HAS_WIDE_CHARACTERS
14451435template <>
14461436class _LIBCPP_EXPORTED_FROM_ABI numpunct<wchar_t> : public locale::facet {
14471437public:
......@@ -1470,12 +1460,12 @@ protected:
14701460 char_type __thousands_sep_;
14711461 string __grouping_;
14721462};
1473#endif // _LIBCPP_HAS_WIDE_CHARACTERS
1463# endif // _LIBCPP_HAS_WIDE_CHARACTERS
14741464
14751465// template <class charT> class numpunct_byname
14761466
14771467template <class _CharT>
1478class _LIBCPP_TEMPLATE_VIS numpunct_byname;
1468class numpunct_byname;
14791469
14801470template <>
14811471class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname<char> : public numpunct<char> {
......@@ -1493,7 +1483,7 @@ private:
14931483 void __init(const char*);
14941484};
14951485
1496#if _LIBCPP_HAS_WIDE_CHARACTERS
1486# if _LIBCPP_HAS_WIDE_CHARACTERS
14971487template <>
14981488class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname<wchar_t> : public numpunct<wchar_t> {
14991489public:
......@@ -1509,8 +1499,10 @@ protected:
15091499private:
15101500 void __init(const char*);
15111501};
1512#endif // _LIBCPP_HAS_WIDE_CHARACTERS
1502# endif // _LIBCPP_HAS_WIDE_CHARACTERS
15131503
15141504_LIBCPP_END_NAMESPACE_STD
15151505
1506#endif // _LIBCPP_HAS_LOCALIZATION
1507
15161508#endif // _LIBCPP___LOCALE
lib/libcxx/include/__locale_dir/check_grouping.h created+31
......@@ -0,0 +1,31 @@
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_CHECK_GROUPING_H
10#define _LIBCPP___LOCALE_DIR_CHECK_GROUPING_H
11
12#include <__config>
13#include <__fwd/string.h>
14#include <ios>
15
16#if _LIBCPP_HAS_LOCALIZATION
17
18# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20# endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24_LIBCPP_EXPORTED_FROM_ABI void
25__check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end, ios_base::iostate& __err);
26
27_LIBCPP_END_NAMESPACE_STD
28
29#endif // _LIBCPP_HAS_LOCALIZATION
30
31#endif // _LIBCPP___LOCALE_DIR_CHECK_GROUPING_H
lib/libcxx/include/__locale_dir/get_c_locale.h created+40
......@@ -0,0 +1,40 @@
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_GET_C_LOCALE_H
10#define _LIBCPP___LOCALE_DIR_GET_C_LOCALE_H
11
12#include <__config>
13#include <__locale_dir/locale_base_api.h>
14
15#if _LIBCPP_HAS_LOCALIZATION
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// FIXME: This should really be part of the locale base API
24
25# if defined(__APPLE__) || defined(__FreeBSD__)
26# define _LIBCPP_GET_C_LOCALE 0
27# elif defined(__NetBSD__)
28# define _LIBCPP_GET_C_LOCALE LC_C_LOCALE
29# else
30# define _LIBCPP_GET_C_LOCALE __cloc()
31// Get the C locale object
32_LIBCPP_EXPORTED_FROM_ABI __locale::__locale_t __cloc();
33# define __cloc_defined
34# endif
35
36_LIBCPP_END_NAMESPACE_STD
37
38#endif // _LIBCPP_HAS_LOCALIZATION
39
40#endif // _LIBCPP___LOCALE_DIR_GET_C_LOCALE_H
lib/libcxx/include/__locale_dir/locale_base_api.h+59-59
......@@ -64,8 +64,6 @@
6464// Character manipulation functions
6565// --------------------------------
6666// namespace __locale {
67// int __islower(int, __locale_t);
68// int __isupper(int, __locale_t);
6967// int __isdigit(int, __locale_t); // required by the headers
7068// int __isxdigit(int, __locale_t); // required by the headers
7169// int __toupper(int, __locale_t);
......@@ -111,59 +109,64 @@
111109// int __sscanf(const char*, __locale_t, const char*, ...); // required by the headers
112110// }
113111
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(__NetBSD__)
119# include <__locale_dir/support/netbsd.h>
120#elif defined(_LIBCPP_MSVCRT_LIKE)
121# include <__locale_dir/support/windows.h>
122#elif defined(__Fuchsia__)
123# include <__locale_dir/support/fuchsia.h>
124#else
112#if _LIBCPP_HAS_LOCALIZATION
113
114# if defined(__APPLE__)
115# include <__locale_dir/support/apple.h>
116# elif defined(__FreeBSD__)
117# include <__locale_dir/support/freebsd.h>
118/* zig patch: https://github.com/llvm/llvm-project/pull/143055 */
119# elif defined(__NetBSD__)
120# include <__locale_dir/support/netbsd.h>
121# elif defined(_LIBCPP_MSVCRT_LIKE)
122# include <__locale_dir/support/windows.h>
123# elif defined(__Fuchsia__)
124# include <__locale_dir/support/fuchsia.h>
125# elif defined(__linux__)
126# include <__locale_dir/support/linux.h>
127# else
125128
126129// TODO: This is a temporary definition to bridge between the old way we defined the locale base API
127130// (by providing global non-reserved names) and the new API. As we move individual platforms
128131// towards the new way of defining the locale base API, this should disappear since each platform
129132// will define those directly.
130# if defined(_AIX) || defined(__MVS__)
131# include <__locale_dir/locale_base_api/ibm.h>
132# elif defined(__ANDROID__)
133# include <__locale_dir/locale_base_api/android.h>
134# elif defined(__OpenBSD__)
135# include <__locale_dir/locale_base_api/openbsd.h>
136# elif defined(__wasi__) || _LIBCPP_HAS_MUSL_LIBC
137# include <__locale_dir/locale_base_api/musl.h>
138# endif
133# if defined(_AIX) || defined(__MVS__)
134# include <__locale_dir/locale_base_api/ibm.h>
135# elif defined(__ANDROID__)
136# include <__locale_dir/locale_base_api/android.h>
137# elif defined(__OpenBSD__)
138# include <__locale_dir/locale_base_api/openbsd.h>
139# elif defined(__wasi__) || _LIBCPP_HAS_MUSL_LIBC
140# include <__locale_dir/locale_base_api/musl.h>
141# endif
139142
140# include <__locale_dir/locale_base_api/bsd_locale_fallbacks.h>
143# include <__locale_dir/locale_base_api/bsd_locale_fallbacks.h>
141144
142# include <__cstddef/size_t.h>
143# include <__utility/forward.h>
144# include <ctype.h>
145# include <string.h>
146# include <time.h>
147# if _LIBCPP_HAS_WIDE_CHARACTERS
148# include <wctype.h>
149# endif
145# include <__cstddef/size_t.h>
146# include <__utility/forward.h>
147# include <ctype.h>
148# include <string.h>
149# include <time.h>
150# if _LIBCPP_HAS_WIDE_CHARACTERS
151# include <wctype.h>
152# endif
150153_LIBCPP_BEGIN_NAMESPACE_STD
151154namespace __locale {
152155//
153156// Locale management
154157//
155# define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK
156# define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK
157# define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK
158# define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK
159# define _LIBCPP_TIME_MASK LC_TIME_MASK
160# define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
161# define _LIBCPP_ALL_MASK LC_ALL_MASK
162# define _LIBCPP_LC_ALL LC_ALL
158# define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK
159# define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK
160# define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK
161# define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK
162# define _LIBCPP_TIME_MASK LC_TIME_MASK
163# define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
164# define _LIBCPP_ALL_MASK LC_ALL_MASK
165# define _LIBCPP_LC_ALL LC_ALL
163166
164167using __locale_t _LIBCPP_NODEBUG = locale_t;
165168
166# if defined(_LIBCPP_BUILDING_LIBRARY)
169# if defined(_LIBCPP_BUILDING_LIBRARY)
167170using __lconv_t _LIBCPP_NODEBUG = lconv;
168171
169172inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __name, __locale_t __loc) {
......@@ -177,7 +180,7 @@ inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, char const* __loc
177180inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { freelocale(__loc); }
178181
179182inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) { return __libcpp_localeconv_l(__loc); }
180# endif // _LIBCPP_BUILDING_LIBRARY
183# endif // _LIBCPP_BUILDING_LIBRARY
181184
182185//
183186// Strtonum functions
......@@ -206,15 +209,10 @@ __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
206209//
207210// Character manipulation functions
208211//
209# if defined(_LIBCPP_BUILDING_LIBRARY)
210inline _LIBCPP_HIDE_FROM_ABI int __islower(int __ch, __locale_t __loc) { return islower_l(__ch, __loc); }
211inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __ch, __locale_t __loc) { return isupper_l(__ch, __loc); }
212# endif
213
214212inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __ch, __locale_t __loc) { return isdigit_l(__ch, __loc); }
215213inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __ch, __locale_t __loc) { return isxdigit_l(__ch, __loc); }
216214
217# if defined(_LIBCPP_BUILDING_LIBRARY)
215# if defined(_LIBCPP_BUILDING_LIBRARY)
218216inline _LIBCPP_HIDE_FROM_ABI int __strcoll(const char* __s1, const char* __s2, __locale_t __loc) {
219217 return strcoll_l(__s1, __s2, __loc);
220218}
......@@ -224,7 +222,7 @@ inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, s
224222inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __ch, __locale_t __loc) { return toupper_l(__ch, __loc); }
225223inline _LIBCPP_HIDE_FROM_ABI int __tolower(int __ch, __locale_t __loc) { return tolower_l(__ch, __loc); }
226224
227# if _LIBCPP_HAS_WIDE_CHARACTERS
225# if _LIBCPP_HAS_WIDE_CHARACTERS
228226inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __s1, const wchar_t* __s2, __locale_t __loc) {
229227 return wcscoll_l(__s1, __s2, __loc);
230228}
......@@ -246,7 +244,7 @@ inline _LIBCPP_HIDE_FROM_ABI int __iswpunct(wint_t __ch, __locale_t __loc) { ret
246244inline _LIBCPP_HIDE_FROM_ABI int __iswxdigit(wint_t __ch, __locale_t __loc) { return iswxdigit_l(__ch, __loc); }
247245inline _LIBCPP_HIDE_FROM_ABI wint_t __towupper(wint_t __ch, __locale_t __loc) { return towupper_l(__ch, __loc); }
248246inline _LIBCPP_HIDE_FROM_ABI wint_t __towlower(wint_t __ch, __locale_t __loc) { return towlower_l(__ch, __loc); }
249# endif
247# endif
250248
251249inline _LIBCPP_HIDE_FROM_ABI size_t
252250__strftime(char* __s, size_t __max, const char* __format, const tm* __tm, __locale_t __loc) {
......@@ -259,7 +257,7 @@ __strftime(char* __s, size_t __max, const char* __format, const tm* __tm, __loca
259257inline _LIBCPP_HIDE_FROM_ABI decltype(__libcpp_mb_cur_max_l(__locale_t())) __mb_len_max(__locale_t __loc) {
260258 return __libcpp_mb_cur_max_l(__loc);
261259}
262# if _LIBCPP_HAS_WIDE_CHARACTERS
260# if _LIBCPP_HAS_WIDE_CHARACTERS
263261inline _LIBCPP_HIDE_FROM_ABI wint_t __btowc(int __ch, __locale_t __loc) { return __libcpp_btowc_l(__ch, __loc); }
264262inline _LIBCPP_HIDE_FROM_ABI int __wctob(wint_t __ch, __locale_t __loc) { return __libcpp_wctob_l(__ch, __loc); }
265263inline _LIBCPP_HIDE_FROM_ABI size_t
......@@ -287,17 +285,17 @@ inline _LIBCPP_HIDE_FROM_ABI size_t
287285__mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) {
288286 return __libcpp_mbsrtowcs_l(__dest, __src, __len, __ps, __loc);
289287}
290# endif // _LIBCPP_HAS_WIDE_CHARACTERS
291# endif // _LIBCPP_BUILDING_LIBRARY
288# endif // _LIBCPP_HAS_WIDE_CHARACTERS
289# endif // _LIBCPP_BUILDING_LIBRARY
292290
293291_LIBCPP_DIAGNOSTIC_PUSH
294292_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat")
295293_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates
296# ifdef _LIBCPP_COMPILER_CLANG_BASED
297# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__)
298# else
299# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */
300# endif
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
301299
302300template <class... _Args>
303301_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf(
......@@ -315,11 +313,13 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __s
315313 return std::__libcpp_sscanf_l(__s, __loc, __format, std::forward<_Args>(__args)...);
316314}
317315_LIBCPP_DIAGNOSTIC_POP
318# undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
316# undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
319317
320318} // namespace __locale
321319_LIBCPP_END_NAMESPACE_STD
322320
323#endif // Compatibility definition of locale base APIs
321# endif // Compatibility definition of locale base APIs
322
323#endif // _LIBCPP_HAS_LOCALIZATION
324324
325325#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H
lib/libcxx/include/__locale_dir/messages.h created+143
......@@ -0,0 +1,143 @@
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_MESSAGES_H
10#define _LIBCPP___LOCALE_DIR_MESSAGES_H
11
12#include <__config>
13#include <__iterator/back_insert_iterator.h>
14#include <__locale>
15#include <string>
16
17#if _LIBCPP_HAS_LOCALIZATION
18
19# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21# endif
22
23# if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
24// Most unix variants have catopen. These are the specific ones that don't.
25# if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__EMSCRIPTEN__)
26# define _LIBCPP_HAS_CATOPEN 1
27# include <nl_types.h>
28# else
29# define _LIBCPP_HAS_CATOPEN 0
30# endif
31# else
32# define _LIBCPP_HAS_CATOPEN 0
33# endif
34
35_LIBCPP_BEGIN_NAMESPACE_STD
36
37class _LIBCPP_EXPORTED_FROM_ABI messages_base {
38public:
39 typedef intptr_t catalog;
40
41 _LIBCPP_HIDE_FROM_ABI messages_base() {}
42};
43
44template <class _CharT>
45class messages : public locale::facet, public messages_base {
46public:
47 typedef _CharT char_type;
48 typedef basic_string<_CharT> string_type;
49
50 _LIBCPP_HIDE_FROM_ABI explicit messages(size_t __refs = 0) : locale::facet(__refs) {}
51
52 _LIBCPP_HIDE_FROM_ABI catalog open(const basic_string<char>& __nm, const locale& __loc) const {
53 return do_open(__nm, __loc);
54 }
55
56 _LIBCPP_HIDE_FROM_ABI string_type get(catalog __c, int __set, int __msgid, const string_type& __dflt) const {
57 return do_get(__c, __set, __msgid, __dflt);
58 }
59
60 _LIBCPP_HIDE_FROM_ABI void close(catalog __c) const { do_close(__c); }
61
62 static locale::id id;
63
64protected:
65 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~messages() override {}
66
67 virtual catalog do_open(const basic_string<char>&, const locale&) const;
68 virtual string_type do_get(catalog, int __set, int __msgid, const string_type& __dflt) const;
69 virtual void do_close(catalog) const;
70};
71
72template <class _CharT>
73locale::id messages<_CharT>::id;
74
75template <class _CharT>
76typename messages<_CharT>::catalog messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const {
77# if _LIBCPP_HAS_CATOPEN
78 return (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE);
79# else // !_LIBCPP_HAS_CATOPEN
80 (void)__nm;
81 return -1;
82# endif // _LIBCPP_HAS_CATOPEN
83}
84
85template <class _CharT>
86typename messages<_CharT>::string_type
87messages<_CharT>::do_get(catalog __c, int __set, int __msgid, const string_type& __dflt) const {
88# if _LIBCPP_HAS_CATOPEN
89 string __ndflt;
90 __narrow_to_utf8<sizeof(char_type) * __CHAR_BIT__>()(
91 std::back_inserter(__ndflt), __dflt.c_str(), __dflt.c_str() + __dflt.size());
92 nl_catd __cat = (nl_catd)__c;
93 static_assert(sizeof(catalog) >= sizeof(nl_catd), "Unexpected nl_catd type");
94 char* __n = catgets(__cat, __set, __msgid, __ndflt.c_str());
95 string_type __w;
96 __widen_from_utf8<sizeof(char_type) * __CHAR_BIT__>()(std::back_inserter(__w), __n, __n + std::strlen(__n));
97 return __w;
98# else // !_LIBCPP_HAS_CATOPEN
99 (void)__c;
100 (void)__set;
101 (void)__msgid;
102 return __dflt;
103# endif // _LIBCPP_HAS_CATOPEN
104}
105
106template <class _CharT>
107void messages<_CharT>::do_close(catalog __c) const {
108# if _LIBCPP_HAS_CATOPEN
109 catclose((nl_catd)__c);
110# else // !_LIBCPP_HAS_CATOPEN
111 (void)__c;
112# endif // _LIBCPP_HAS_CATOPEN
113}
114
115extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<char>;
116# if _LIBCPP_HAS_WIDE_CHARACTERS
117extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<wchar_t>;
118# endif
119
120template <class _CharT>
121class messages_byname : public messages<_CharT> {
122public:
123 typedef messages_base::catalog catalog;
124 typedef basic_string<_CharT> string_type;
125
126 _LIBCPP_HIDE_FROM_ABI explicit messages_byname(const char*, size_t __refs = 0) : messages<_CharT>(__refs) {}
127
128 _LIBCPP_HIDE_FROM_ABI explicit messages_byname(const string&, size_t __refs = 0) : messages<_CharT>(__refs) {}
129
130protected:
131 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~messages_byname() override {}
132};
133
134extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<char>;
135# if _LIBCPP_HAS_WIDE_CHARACTERS
136extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<wchar_t>;
137# endif
138
139_LIBCPP_END_NAMESPACE_STD
140
141#endif // _LIBCPP_HAS_LOCALIZATION
142
143#endif // _LIBCPP___LOCALE_DIR_MESSAGES_H
lib/libcxx/include/__locale_dir/money.h created+873
......@@ -0,0 +1,873 @@
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_MONEY_H
10#define _LIBCPP___LOCALE_DIR_MONEY_H
11
12#include <__algorithm/copy.h>
13#include <__algorithm/equal.h>
14#include <__algorithm/find.h>
15#include <__algorithm/reverse.h>
16#include <__config>
17#include <__locale>
18#include <__locale_dir/check_grouping.h>
19#include <__locale_dir/get_c_locale.h>
20#include <__locale_dir/pad_and_output.h>
21#include <__memory/unique_ptr.h>
22#include <ios>
23#include <string>
24
25#if _LIBCPP_HAS_LOCALIZATION
26
27# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28# pragma GCC system_header
29# endif
30
31_LIBCPP_PUSH_MACROS
32# include <__undef_macros>
33
34_LIBCPP_BEGIN_NAMESPACE_STD
35
36// money_base
37
38class _LIBCPP_EXPORTED_FROM_ABI money_base {
39public:
40 enum part { none, space, symbol, sign, value };
41 struct pattern {
42 char field[4];
43 };
44
45 _LIBCPP_HIDE_FROM_ABI money_base() {}
46};
47
48// moneypunct
49
50template <class _CharT, bool _International = false>
51class moneypunct : public locale::facet, public money_base {
52public:
53 typedef _CharT char_type;
54 typedef basic_string<char_type> string_type;
55
56 _LIBCPP_HIDE_FROM_ABI explicit moneypunct(size_t __refs = 0) : locale::facet(__refs) {}
57
58 _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); }
59 _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); }
60 _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); }
61 _LIBCPP_HIDE_FROM_ABI string_type curr_symbol() const { return do_curr_symbol(); }
62 _LIBCPP_HIDE_FROM_ABI string_type positive_sign() const { return do_positive_sign(); }
63 _LIBCPP_HIDE_FROM_ABI string_type negative_sign() const { return do_negative_sign(); }
64 _LIBCPP_HIDE_FROM_ABI int frac_digits() const { return do_frac_digits(); }
65 _LIBCPP_HIDE_FROM_ABI pattern pos_format() const { return do_pos_format(); }
66 _LIBCPP_HIDE_FROM_ABI pattern neg_format() const { return do_neg_format(); }
67
68 static locale::id id;
69 static const bool intl = _International;
70
71protected:
72 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~moneypunct() override {}
73
74 virtual char_type do_decimal_point() const { return numeric_limits<char_type>::max(); }
75 virtual char_type do_thousands_sep() const { return numeric_limits<char_type>::max(); }
76 virtual string do_grouping() const { return string(); }
77 virtual string_type do_curr_symbol() const { return string_type(); }
78 virtual string_type do_positive_sign() const { return string_type(); }
79 virtual string_type do_negative_sign() const { return string_type(1, '-'); }
80 virtual int do_frac_digits() const { return 0; }
81 virtual pattern do_pos_format() const {
82 pattern __p = {{symbol, sign, none, value}};
83 return __p;
84 }
85 virtual pattern do_neg_format() const {
86 pattern __p = {{symbol, sign, none, value}};
87 return __p;
88 }
89};
90
91template <class _CharT, bool _International>
92locale::id moneypunct<_CharT, _International>::id;
93
94template <class _CharT, bool _International>
95const bool moneypunct<_CharT, _International>::intl;
96
97extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, false>;
98extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, true>;
99# if _LIBCPP_HAS_WIDE_CHARACTERS
100extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, false>;
101extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, true>;
102# endif
103
104// moneypunct_byname
105
106template <class _CharT, bool _International = false>
107class moneypunct_byname : public moneypunct<_CharT, _International> {
108public:
109 typedef money_base::pattern pattern;
110 typedef _CharT char_type;
111 typedef basic_string<char_type> string_type;
112
113 _LIBCPP_HIDE_FROM_ABI explicit moneypunct_byname(const char* __nm, size_t __refs = 0)
114 : moneypunct<_CharT, _International>(__refs) {
115 init(__nm);
116 }
117
118 _LIBCPP_HIDE_FROM_ABI explicit moneypunct_byname(const string& __nm, size_t __refs = 0)
119 : moneypunct<_CharT, _International>(__refs) {
120 init(__nm.c_str());
121 }
122
123protected:
124 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~moneypunct_byname() override {}
125
126 char_type do_decimal_point() const override { return __decimal_point_; }
127 char_type do_thousands_sep() const override { return __thousands_sep_; }
128 string do_grouping() const override { return __grouping_; }
129 string_type do_curr_symbol() const override { return __curr_symbol_; }
130 string_type do_positive_sign() const override { return __positive_sign_; }
131 string_type do_negative_sign() const override { return __negative_sign_; }
132 int do_frac_digits() const override { return __frac_digits_; }
133 pattern do_pos_format() const override { return __pos_format_; }
134 pattern do_neg_format() const override { return __neg_format_; }
135
136private:
137 char_type __decimal_point_;
138 char_type __thousands_sep_;
139 string __grouping_;
140 string_type __curr_symbol_;
141 string_type __positive_sign_;
142 string_type __negative_sign_;
143 int __frac_digits_;
144 pattern __pos_format_;
145 pattern __neg_format_;
146
147 void init(const char*);
148};
149
150template <>
151_LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<char, false>::init(const char*);
152template <>
153_LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<char, true>::init(const char*);
154extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, false>;
155extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, true>;
156
157# if _LIBCPP_HAS_WIDE_CHARACTERS
158template <>
159_LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<wchar_t, false>::init(const char*);
160template <>
161_LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<wchar_t, true>::init(const char*);
162extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, false>;
163extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, true>;
164# endif
165
166// money_get
167
168template <class _CharT>
169class __money_get {
170protected:
171 typedef _CharT char_type;
172 typedef basic_string<char_type> string_type;
173
174 _LIBCPP_HIDE_FROM_ABI __money_get() {}
175
176 static void __gather_info(
177 bool __intl,
178 const locale& __loc,
179 money_base::pattern& __pat,
180 char_type& __dp,
181 char_type& __ts,
182 string& __grp,
183 string_type& __sym,
184 string_type& __psn,
185 string_type& __nsn,
186 int& __fd);
187};
188
189template <class _CharT>
190void __money_get<_CharT>::__gather_info(
191 bool __intl,
192 const locale& __loc,
193 money_base::pattern& __pat,
194 char_type& __dp,
195 char_type& __ts,
196 string& __grp,
197 string_type& __sym,
198 string_type& __psn,
199 string_type& __nsn,
200 int& __fd) {
201 if (__intl) {
202 const moneypunct<char_type, true>& __mp = std::use_facet<moneypunct<char_type, true> >(__loc);
203 __pat = __mp.neg_format();
204 __nsn = __mp.negative_sign();
205 __psn = __mp.positive_sign();
206 __dp = __mp.decimal_point();
207 __ts = __mp.thousands_sep();
208 __grp = __mp.grouping();
209 __sym = __mp.curr_symbol();
210 __fd = __mp.frac_digits();
211 } else {
212 const moneypunct<char_type, false>& __mp = std::use_facet<moneypunct<char_type, false> >(__loc);
213 __pat = __mp.neg_format();
214 __nsn = __mp.negative_sign();
215 __psn = __mp.positive_sign();
216 __dp = __mp.decimal_point();
217 __ts = __mp.thousands_sep();
218 __grp = __mp.grouping();
219 __sym = __mp.curr_symbol();
220 __fd = __mp.frac_digits();
221 }
222}
223
224extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<char>;
225# if _LIBCPP_HAS_WIDE_CHARACTERS
226extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<wchar_t>;
227# endif
228
229template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
230class money_get : public locale::facet, private __money_get<_CharT> {
231public:
232 typedef _CharT char_type;
233 typedef _InputIterator iter_type;
234 typedef basic_string<char_type> string_type;
235
236 _LIBCPP_HIDE_FROM_ABI explicit money_get(size_t __refs = 0) : locale::facet(__refs) {}
237
238 _LIBCPP_HIDE_FROM_ABI iter_type
239 get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, long double& __v) const {
240 return do_get(__b, __e, __intl, __iob, __err, __v);
241 }
242
243 _LIBCPP_HIDE_FROM_ABI iter_type
244 get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, string_type& __v) const {
245 return do_get(__b, __e, __intl, __iob, __err, __v);
246 }
247
248 static locale::id id;
249
250protected:
251 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~money_get() override {}
252
253 virtual iter_type
254 do_get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, long double& __v) const;
255 virtual iter_type
256 do_get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, string_type& __v) const;
257
258private:
259 static bool __do_get(
260 iter_type& __b,
261 iter_type __e,
262 bool __intl,
263 const locale& __loc,
264 ios_base::fmtflags __flags,
265 ios_base::iostate& __err,
266 bool& __neg,
267 const ctype<char_type>& __ct,
268 unique_ptr<char_type, void (*)(void*)>& __wb,
269 char_type*& __wn,
270 char_type* __we);
271};
272
273template <class _CharT, class _InputIterator>
274locale::id money_get<_CharT, _InputIterator>::id;
275
276_LIBCPP_EXPORTED_FROM_ABI void __do_nothing(void*);
277
278template <class _Tp>
279_LIBCPP_HIDE_FROM_ABI void __double_or_nothing(unique_ptr<_Tp, void (*)(void*)>& __b, _Tp*& __n, _Tp*& __e) {
280 bool __owns = __b.get_deleter() != __do_nothing;
281 size_t __cur_cap = static_cast<size_t>(__e - __b.get()) * sizeof(_Tp);
282 size_t __new_cap = __cur_cap < numeric_limits<size_t>::max() / 2 ? 2 * __cur_cap : numeric_limits<size_t>::max();
283 if (__new_cap == 0)
284 __new_cap = sizeof(_Tp);
285 size_t __n_off = static_cast<size_t>(__n - __b.get());
286 _Tp* __t = (_Tp*)std::realloc(__owns ? __b.get() : 0, __new_cap);
287 if (__t == 0)
288 std::__throw_bad_alloc();
289 if (__owns)
290 __b.release();
291 else
292 std::memcpy(__t, __b.get(), __cur_cap);
293 __b = unique_ptr<_Tp, void (*)(void*)>(__t, free);
294 __new_cap /= sizeof(_Tp);
295 __n = __b.get() + __n_off;
296 __e = __b.get() + __new_cap;
297}
298
299// true == success
300template <class _CharT, class _InputIterator>
301bool money_get<_CharT, _InputIterator>::__do_get(
302 iter_type& __b,
303 iter_type __e,
304 bool __intl,
305 const locale& __loc,
306 ios_base::fmtflags __flags,
307 ios_base::iostate& __err,
308 bool& __neg,
309 const ctype<char_type>& __ct,
310 unique_ptr<char_type, void (*)(void*)>& __wb,
311 char_type*& __wn,
312 char_type* __we) {
313 if (__b == __e) {
314 __err |= ios_base::failbit;
315 return false;
316 }
317 const unsigned __bz = 100;
318 unsigned __gbuf[__bz];
319 unique_ptr<unsigned, void (*)(void*)> __gb(__gbuf, __do_nothing);
320 unsigned* __gn = __gb.get();
321 unsigned* __ge = __gn + __bz;
322 money_base::pattern __pat;
323 char_type __dp;
324 char_type __ts;
325 string __grp;
326 string_type __sym;
327 string_type __psn;
328 string_type __nsn;
329 // Capture the spaces read into money_base::{space,none} so they
330 // can be compared to initial spaces in __sym.
331 string_type __spaces;
332 int __fd;
333 __money_get<_CharT>::__gather_info(__intl, __loc, __pat, __dp, __ts, __grp, __sym, __psn, __nsn, __fd);
334 const string_type* __trailing_sign = 0;
335 __wn = __wb.get();
336 for (unsigned __p = 0; __p < 4 && __b != __e; ++__p) {
337 switch (__pat.field[__p]) {
338 case money_base::space:
339 if (__p != 3) {
340 if (__ct.is(ctype_base::space, *__b))
341 __spaces.push_back(*__b++);
342 else {
343 __err |= ios_base::failbit;
344 return false;
345 }
346 }
347 [[__fallthrough__]];
348 case money_base::none:
349 if (__p != 3) {
350 while (__b != __e && __ct.is(ctype_base::space, *__b))
351 __spaces.push_back(*__b++);
352 }
353 break;
354 case money_base::sign:
355 if (__psn.size() > 0 && *__b == __psn[0]) {
356 ++__b;
357 __neg = false;
358 if (__psn.size() > 1)
359 __trailing_sign = std::addressof(__psn);
360 break;
361 }
362 if (__nsn.size() > 0 && *__b == __nsn[0]) {
363 ++__b;
364 __neg = true;
365 if (__nsn.size() > 1)
366 __trailing_sign = std::addressof(__nsn);
367 break;
368 }
369 if (__psn.size() > 0 && __nsn.size() > 0) { // sign is required
370 __err |= ios_base::failbit;
371 return false;
372 }
373 if (__psn.size() == 0 && __nsn.size() == 0)
374 // locale has no way of specifying a sign. Use the initial value of __neg as a default
375 break;
376 __neg = (__nsn.size() == 0);
377 break;
378 case money_base::symbol: {
379 bool __more_needed =
380 __trailing_sign || (__p < 2) || (__p == 2 && __pat.field[3] != static_cast<char>(money_base::none));
381 bool __sb = (__flags & ios_base::showbase) != 0;
382 if (__sb || __more_needed) {
383 typename string_type::const_iterator __sym_space_end = __sym.begin();
384 if (__p > 0 && (__pat.field[__p - 1] == money_base::none || __pat.field[__p - 1] == money_base::space)) {
385 // Match spaces we've already read against spaces at
386 // the beginning of __sym.
387 while (__sym_space_end != __sym.end() && __ct.is(ctype_base::space, *__sym_space_end))
388 ++__sym_space_end;
389 const size_t __num_spaces = __sym_space_end - __sym.begin();
390 if (__num_spaces > __spaces.size() ||
391 !std::equal(__spaces.end() - __num_spaces, __spaces.end(), __sym.begin())) {
392 // No match. Put __sym_space_end back at the
393 // beginning of __sym, which will prevent a
394 // match in the next loop.
395 __sym_space_end = __sym.begin();
396 }
397 }
398 typename string_type::const_iterator __sym_curr_char = __sym_space_end;
399 while (__sym_curr_char != __sym.end() && __b != __e && *__b == *__sym_curr_char) {
400 ++__b;
401 ++__sym_curr_char;
402 }
403 if (__sb && __sym_curr_char != __sym.end()) {
404 __err |= ios_base::failbit;
405 return false;
406 }
407 }
408 } break;
409 case money_base::value: {
410 unsigned __ng = 0;
411 for (; __b != __e; ++__b) {
412 char_type __c = *__b;
413 if (__ct.is(ctype_base::digit, __c)) {
414 if (__wn == __we)
415 std::__double_or_nothing(__wb, __wn, __we);
416 *__wn++ = __c;
417 ++__ng;
418 } else if (__grp.size() > 0 && __ng > 0 && __c == __ts) {
419 if (__gn == __ge)
420 std::__double_or_nothing(__gb, __gn, __ge);
421 *__gn++ = __ng;
422 __ng = 0;
423 } else
424 break;
425 }
426 if (__gb.get() != __gn && __ng > 0) {
427 if (__gn == __ge)
428 std::__double_or_nothing(__gb, __gn, __ge);
429 *__gn++ = __ng;
430 }
431 if (__fd > 0) {
432 if (__b == __e || *__b != __dp) {
433 __err |= ios_base::failbit;
434 return false;
435 }
436 for (++__b; __fd > 0; --__fd, ++__b) {
437 if (__b == __e || !__ct.is(ctype_base::digit, *__b)) {
438 __err |= ios_base::failbit;
439 return false;
440 }
441 if (__wn == __we)
442 std::__double_or_nothing(__wb, __wn, __we);
443 *__wn++ = *__b;
444 }
445 }
446 if (__wn == __wb.get()) {
447 __err |= ios_base::failbit;
448 return false;
449 }
450 } break;
451 }
452 }
453 if (__trailing_sign) {
454 for (unsigned __i = 1; __i < __trailing_sign->size(); ++__i, ++__b) {
455 if (__b == __e || *__b != (*__trailing_sign)[__i]) {
456 __err |= ios_base::failbit;
457 return false;
458 }
459 }
460 }
461 if (__gb.get() != __gn) {
462 ios_base::iostate __et = ios_base::goodbit;
463 __check_grouping(__grp, __gb.get(), __gn, __et);
464 if (__et) {
465 __err |= ios_base::failbit;
466 return false;
467 }
468 }
469 return true;
470}
471
472template <class _CharT, class _InputIterator>
473_InputIterator money_get<_CharT, _InputIterator>::do_get(
474 iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, long double& __v) const {
475 const int __bz = 100;
476 char_type __wbuf[__bz];
477 unique_ptr<char_type, void (*)(void*)> __wb(__wbuf, __do_nothing);
478 char_type* __wn;
479 char_type* __we = __wbuf + __bz;
480 locale __loc = __iob.getloc();
481 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc);
482 bool __neg = false;
483 if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct, __wb, __wn, __we)) {
484 const char __src[] = "0123456789";
485 char_type __atoms[sizeof(__src) - 1];
486 __ct.widen(__src, __src + (sizeof(__src) - 1), __atoms);
487 char __nbuf[__bz];
488 char* __nc = __nbuf;
489 const char* __nc_in = __nc;
490 unique_ptr<char, void (*)(void*)> __h(nullptr, free);
491 if (__wn - __wb.get() > __bz - 2) {
492 __h.reset((char*)malloc(static_cast<size_t>(__wn - __wb.get() + 2)));
493 if (__h.get() == nullptr)
494 std::__throw_bad_alloc();
495 __nc = __h.get();
496 __nc_in = __nc;
497 }
498 if (__neg)
499 *__nc++ = '-';
500 for (const char_type* __w = __wb.get(); __w < __wn; ++__w, ++__nc)
501 *__nc = __src[std::find(__atoms, std::end(__atoms), *__w) - __atoms];
502 *__nc = char();
503 if (sscanf(__nc_in, "%Lf", &__v) != 1)
504 std::__throw_runtime_error("money_get error");
505 }
506 if (__b == __e)
507 __err |= ios_base::eofbit;
508 return __b;
509}
510
511template <class _CharT, class _InputIterator>
512_InputIterator money_get<_CharT, _InputIterator>::do_get(
513 iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, string_type& __v) const {
514 const int __bz = 100;
515 char_type __wbuf[__bz];
516 unique_ptr<char_type, void (*)(void*)> __wb(__wbuf, __do_nothing);
517 char_type* __wn;
518 char_type* __we = __wbuf + __bz;
519 locale __loc = __iob.getloc();
520 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc);
521 bool __neg = false;
522 if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct, __wb, __wn, __we)) {
523 __v.clear();
524 if (__neg)
525 __v.push_back(__ct.widen('-'));
526 char_type __z = __ct.widen('0');
527 char_type* __w;
528 for (__w = __wb.get(); __w < __wn - 1; ++__w)
529 if (*__w != __z)
530 break;
531 __v.append(__w, __wn);
532 }
533 if (__b == __e)
534 __err |= ios_base::eofbit;
535 return __b;
536}
537
538extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<char>;
539# if _LIBCPP_HAS_WIDE_CHARACTERS
540extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<wchar_t>;
541# endif
542
543// money_put
544
545template <class _CharT>
546class __money_put {
547protected:
548 typedef _CharT char_type;
549 typedef basic_string<char_type> string_type;
550
551 _LIBCPP_HIDE_FROM_ABI __money_put() {}
552
553 static void __gather_info(
554 bool __intl,
555 bool __neg,
556 const locale& __loc,
557 money_base::pattern& __pat,
558 char_type& __dp,
559 char_type& __ts,
560 string& __grp,
561 string_type& __sym,
562 string_type& __sn,
563 int& __fd);
564 static void __format(
565 char_type* __mb,
566 char_type*& __mi,
567 char_type*& __me,
568 ios_base::fmtflags __flags,
569 const char_type* __db,
570 const char_type* __de,
571 const ctype<char_type>& __ct,
572 bool __neg,
573 const money_base::pattern& __pat,
574 char_type __dp,
575 char_type __ts,
576 const string& __grp,
577 const string_type& __sym,
578 const string_type& __sn,
579 int __fd);
580};
581
582template <class _CharT>
583void __money_put<_CharT>::__gather_info(
584 bool __intl,
585 bool __neg,
586 const locale& __loc,
587 money_base::pattern& __pat,
588 char_type& __dp,
589 char_type& __ts,
590 string& __grp,
591 string_type& __sym,
592 string_type& __sn,
593 int& __fd) {
594 if (__intl) {
595 const moneypunct<char_type, true>& __mp = std::use_facet<moneypunct<char_type, true> >(__loc);
596 if (__neg) {
597 __pat = __mp.neg_format();
598 __sn = __mp.negative_sign();
599 } else {
600 __pat = __mp.pos_format();
601 __sn = __mp.positive_sign();
602 }
603 __dp = __mp.decimal_point();
604 __ts = __mp.thousands_sep();
605 __grp = __mp.grouping();
606 __sym = __mp.curr_symbol();
607 __fd = __mp.frac_digits();
608 } else {
609 const moneypunct<char_type, false>& __mp = std::use_facet<moneypunct<char_type, false> >(__loc);
610 if (__neg) {
611 __pat = __mp.neg_format();
612 __sn = __mp.negative_sign();
613 } else {
614 __pat = __mp.pos_format();
615 __sn = __mp.positive_sign();
616 }
617 __dp = __mp.decimal_point();
618 __ts = __mp.thousands_sep();
619 __grp = __mp.grouping();
620 __sym = __mp.curr_symbol();
621 __fd = __mp.frac_digits();
622 }
623}
624
625template <class _CharT>
626void __money_put<_CharT>::__format(
627 char_type* __mb,
628 char_type*& __mi,
629 char_type*& __me,
630 ios_base::fmtflags __flags,
631 const char_type* __db,
632 const char_type* __de,
633 const ctype<char_type>& __ct,
634 bool __neg,
635 const money_base::pattern& __pat,
636 char_type __dp,
637 char_type __ts,
638 const string& __grp,
639 const string_type& __sym,
640 const string_type& __sn,
641 int __fd) {
642 __me = __mb;
643 for (char __p : __pat.field) {
644 switch (__p) {
645 case money_base::none:
646 __mi = __me;
647 break;
648 case money_base::space:
649 __mi = __me;
650 *__me++ = __ct.widen(' ');
651 break;
652 case money_base::sign:
653 if (!__sn.empty())
654 *__me++ = __sn[0];
655 break;
656 case money_base::symbol:
657 if (!__sym.empty() && (__flags & ios_base::showbase))
658 __me = std::copy(__sym.begin(), __sym.end(), __me);
659 break;
660 case money_base::value: {
661 // remember start of value so we can reverse it
662 char_type* __t = __me;
663 // find beginning of digits
664 if (__neg)
665 ++__db;
666 // find end of digits
667 const char_type* __d;
668 for (__d = __db; __d < __de; ++__d)
669 if (!__ct.is(ctype_base::digit, *__d))
670 break;
671 // print fractional part
672 if (__fd > 0) {
673 int __f;
674 for (__f = __fd; __d > __db && __f > 0; --__f)
675 *__me++ = *--__d;
676 char_type __z = __f > 0 ? __ct.widen('0') : char_type();
677 for (; __f > 0; --__f)
678 *__me++ = __z;
679 *__me++ = __dp;
680 }
681 // print units part
682 if (__d == __db) {
683 *__me++ = __ct.widen('0');
684 } else {
685 unsigned __ng = 0;
686 unsigned __ig = 0;
687 unsigned __gl = __grp.empty() ? numeric_limits<unsigned>::max() : static_cast<unsigned>(__grp[__ig]);
688 while (__d != __db) {
689 if (__ng == __gl) {
690 *__me++ = __ts;
691 __ng = 0;
692 if (++__ig < __grp.size())
693 __gl = __grp[__ig] == numeric_limits<char>::max()
694 ? numeric_limits<unsigned>::max()
695 : static_cast<unsigned>(__grp[__ig]);
696 }
697 *__me++ = *--__d;
698 ++__ng;
699 }
700 }
701 // reverse it
702 std::reverse(__t, __me);
703 } break;
704 }
705 }
706 // print rest of sign, if any
707 if (__sn.size() > 1)
708 __me = std::copy(__sn.begin() + 1, __sn.end(), __me);
709 // set alignment
710 if ((__flags & ios_base::adjustfield) == ios_base::left)
711 __mi = __me;
712 else if ((__flags & ios_base::adjustfield) != ios_base::internal)
713 __mi = __mb;
714}
715
716extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<char>;
717# if _LIBCPP_HAS_WIDE_CHARACTERS
718extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<wchar_t>;
719# endif
720
721template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
722class money_put : public locale::facet, private __money_put<_CharT> {
723public:
724 typedef _CharT char_type;
725 typedef _OutputIterator iter_type;
726 typedef basic_string<char_type> string_type;
727
728 _LIBCPP_HIDE_FROM_ABI explicit money_put(size_t __refs = 0) : locale::facet(__refs) {}
729
730 _LIBCPP_HIDE_FROM_ABI iter_type
731 put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, long double __units) const {
732 return do_put(__s, __intl, __iob, __fl, __units);
733 }
734
735 _LIBCPP_HIDE_FROM_ABI iter_type
736 put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, const string_type& __digits) const {
737 return do_put(__s, __intl, __iob, __fl, __digits);
738 }
739
740 static locale::id id;
741
742protected:
743 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~money_put() override {}
744
745 virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, long double __units) const;
746 virtual iter_type
747 do_put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, const string_type& __digits) const;
748};
749
750template <class _CharT, class _OutputIterator>
751locale::id money_put<_CharT, _OutputIterator>::id;
752
753template <class _CharT, class _OutputIterator>
754_OutputIterator money_put<_CharT, _OutputIterator>::do_put(
755 iter_type __s, bool __intl, ios_base& __iob, char_type __fl, long double __units) const {
756 // convert to char
757 const size_t __bs = 100;
758 char __buf[__bs];
759 char* __bb = __buf;
760 char_type __digits[__bs];
761 char_type* __db = __digits;
762 int __n = snprintf(__bb, __bs, "%.0Lf", __units);
763 unique_ptr<char, void (*)(void*)> __hn(nullptr, free);
764 unique_ptr<char_type, void (*)(void*)> __hd(0, free);
765 // secure memory for digit storage
766 if (static_cast<size_t>(__n) > __bs - 1) {
767 __n = __locale::__asprintf(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units);
768 if (__n == -1)
769 std::__throw_bad_alloc();
770 __hn.reset(__bb);
771 __hd.reset((char_type*)malloc(static_cast<size_t>(__n) * sizeof(char_type)));
772 if (__hd == nullptr)
773 std::__throw_bad_alloc();
774 __db = __hd.get();
775 }
776 // gather info
777 locale __loc = __iob.getloc();
778 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc);
779 __ct.widen(__bb, __bb + __n, __db);
780 bool __neg = __n > 0 && __bb[0] == '-';
781 money_base::pattern __pat;
782 char_type __dp;
783 char_type __ts;
784 string __grp;
785 string_type __sym;
786 string_type __sn;
787 int __fd;
788 this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
789 // secure memory for formatting
790 char_type __mbuf[__bs];
791 char_type* __mb = __mbuf;
792 unique_ptr<char_type, void (*)(void*)> __hw(0, free);
793 size_t __exn = __n > __fd ? (static_cast<size_t>(__n) - static_cast<size_t>(__fd)) * 2 + __sn.size() + __sym.size() +
794 static_cast<size_t>(__fd) + 1
795 : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2;
796 if (__exn > __bs) {
797 __hw.reset((char_type*)malloc(__exn * sizeof(char_type)));
798 __mb = __hw.get();
799 if (__mb == 0)
800 std::__throw_bad_alloc();
801 }
802 // format
803 char_type* __mi;
804 char_type* __me;
805 this->__format(
806 __mb, __mi, __me, __iob.flags(), __db, __db + __n, __ct, __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
807 return std::__pad_and_output(__s, __mb, __mi, __me, __iob, __fl);
808}
809
810template <class _CharT, class _OutputIterator>
811_OutputIterator money_put<_CharT, _OutputIterator>::do_put(
812 iter_type __s, bool __intl, ios_base& __iob, char_type __fl, const string_type& __digits) const {
813 // gather info
814 locale __loc = __iob.getloc();
815 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc);
816 bool __neg = __digits.size() > 0 && __digits[0] == __ct.widen('-');
817 money_base::pattern __pat;
818 char_type __dp;
819 char_type __ts;
820 string __grp;
821 string_type __sym;
822 string_type __sn;
823 int __fd;
824 this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
825 // secure memory for formatting
826 char_type __mbuf[100];
827 char_type* __mb = __mbuf;
828 unique_ptr<char_type, void (*)(void*)> __h(0, free);
829 size_t __exn =
830 static_cast<int>(__digits.size()) > __fd
831 ? (__digits.size() - static_cast<size_t>(__fd)) * 2 + __sn.size() + __sym.size() + static_cast<size_t>(__fd) +
832 1
833 : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2;
834 if (__exn > 100) {
835 __h.reset((char_type*)malloc(__exn * sizeof(char_type)));
836 __mb = __h.get();
837 if (__mb == 0)
838 std::__throw_bad_alloc();
839 }
840 // format
841 char_type* __mi;
842 char_type* __me;
843 this->__format(
844 __mb,
845 __mi,
846 __me,
847 __iob.flags(),
848 __digits.data(),
849 __digits.data() + __digits.size(),
850 __ct,
851 __neg,
852 __pat,
853 __dp,
854 __ts,
855 __grp,
856 __sym,
857 __sn,
858 __fd);
859 return std::__pad_and_output(__s, __mb, __mi, __me, __iob, __fl);
860}
861
862extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<char>;
863# if _LIBCPP_HAS_WIDE_CHARACTERS
864extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<wchar_t>;
865# endif
866
867_LIBCPP_END_NAMESPACE_STD
868
869_LIBCPP_POP_MACROS
870
871#endif // _LIBCPP_HAS_LOCALIZATION
872
873#endif // _LIBCPP___LOCALE_DIR_MONEY_H
lib/libcxx/include/__locale_dir/num.h created+1072
......@@ -0,0 +1,1072 @@
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_NUM_H
10#define _LIBCPP___LOCALE_DIR_NUM_H
11
12#include <__algorithm/find.h>
13#include <__algorithm/reverse.h>
14#include <__charconv/to_chars_integral.h>
15#include <__charconv/traits.h>
16#include <__config>
17#include <__iterator/istreambuf_iterator.h>
18#include <__iterator/ostreambuf_iterator.h>
19#include <__locale_dir/check_grouping.h>
20#include <__locale_dir/get_c_locale.h>
21#include <__locale_dir/pad_and_output.h>
22#include <__locale_dir/scan_keyword.h>
23#include <__memory/unique_ptr.h>
24#include <__system_error/errc.h>
25#include <cerrno>
26#include <ios>
27#include <streambuf>
28
29#if _LIBCPP_HAS_LOCALIZATION
30
31# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
32# pragma GCC system_header
33# endif
34
35// TODO: Properly qualify calls now that the locale base API defines functions instead of macros
36// NOLINTBEGIN(libcpp-robust-against-adl)
37
38_LIBCPP_PUSH_MACROS
39# include <__undef_macros>
40
41_LIBCPP_BEGIN_NAMESPACE_STD
42
43struct _LIBCPP_EXPORTED_FROM_ABI __num_get_base {
44 static const int __num_get_buf_sz = 40;
45
46 static int __get_base(ios_base&);
47 static const char __src[33]; // "0123456789abcdefABCDEFxX+-pPiInN"
48 // count of leading characters in __src used for parsing integers ("012..X+-")
49 static const size_t __int_chr_cnt = 26;
50 // count of leading characters in __src used for parsing floating-point values ("012..-pP")
51 static const size_t __fp_chr_cnt = 28;
52};
53
54template <class _CharT>
55struct __num_get : protected __num_get_base {
56 static string __stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, _CharT& __thousands_sep);
57
58 static int __stage2_float_loop(
59 _CharT __ct,
60 bool& __in_units,
61 char& __exp,
62 char* __a,
63 char*& __a_end,
64 _CharT __decimal_point,
65 _CharT __thousands_sep,
66 const string& __grouping,
67 unsigned* __g,
68 unsigned*& __g_end,
69 unsigned& __dc,
70 _CharT* __atoms);
71
72 [[__deprecated__("This exists only for ABI compatibility")]] static string
73 __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep);
74 static int __stage2_int_loop(
75 _CharT __ct,
76 int __base,
77 char* __a,
78 char*& __a_end,
79 unsigned& __dc,
80 _CharT __thousands_sep,
81 const string& __grouping,
82 unsigned* __g,
83 unsigned*& __g_end,
84 _CharT* __atoms);
85
86 _LIBCPP_HIDE_FROM_ABI static string __stage2_int_prep(ios_base& __iob, _CharT& __thousands_sep) {
87 locale __loc = __iob.getloc();
88 const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
89 __thousands_sep = __np.thousands_sep();
90 return __np.grouping();
91 }
92
93 _LIBCPP_HIDE_FROM_ABI const _CharT* __do_widen(ios_base& __iob, _CharT* __atoms) const {
94 return __do_widen_p(__iob, __atoms);
95 }
96
97private:
98 template <typename _Tp>
99 _LIBCPP_HIDE_FROM_ABI const _Tp* __do_widen_p(ios_base& __iob, _Tp* __atoms) const {
100 locale __loc = __iob.getloc();
101 use_facet<ctype<_Tp> >(__loc).widen(__src, __src + __int_chr_cnt, __atoms);
102 return __atoms;
103 }
104
105 _LIBCPP_HIDE_FROM_ABI const char* __do_widen_p(ios_base& __iob, char* __atoms) const {
106 (void)__iob;
107 (void)__atoms;
108 return __src;
109 }
110};
111
112template <class _CharT>
113string __num_get<_CharT>::__stage2_float_prep(
114 ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, _CharT& __thousands_sep) {
115 locale __loc = __iob.getloc();
116 std::use_facet<ctype<_CharT> >(__loc).widen(__src, __src + __fp_chr_cnt, __atoms);
117 const numpunct<_CharT>& __np = std::use_facet<numpunct<_CharT> >(__loc);
118 __decimal_point = __np.decimal_point();
119 __thousands_sep = __np.thousands_sep();
120 return __np.grouping();
121}
122
123template <class _CharT>
124int __num_get<_CharT>::__stage2_int_loop(
125 _CharT __ct,
126 int __base,
127 char* __a,
128 char*& __a_end,
129 unsigned& __dc,
130 _CharT __thousands_sep,
131 const string& __grouping,
132 unsigned* __g,
133 unsigned*& __g_end,
134 _CharT* __atoms) {
135 if (__a_end == __a && (__ct == __atoms[24] || __ct == __atoms[25])) {
136 *__a_end++ = __ct == __atoms[24] ? '+' : '-';
137 __dc = 0;
138 return 0;
139 }
140 if (__grouping.size() != 0 && __ct == __thousands_sep) {
141 if (__g_end - __g < __num_get_buf_sz) {
142 *__g_end++ = __dc;
143 __dc = 0;
144 }
145 return 0;
146 }
147 ptrdiff_t __f = std::find(__atoms, __atoms + __int_chr_cnt, __ct) - __atoms;
148 if (__f >= 24)
149 return -1;
150 switch (__base) {
151 case 8:
152 case 10:
153 if (__f >= __base)
154 return -1;
155 break;
156 case 16:
157 if (__f < 22)
158 break;
159 if (__a_end != __a && __a_end - __a <= 2 && __a_end[-1] == '0') {
160 __dc = 0;
161 *__a_end++ = __src[__f];
162 return 0;
163 }
164 return -1;
165 }
166 *__a_end++ = __src[__f];
167 ++__dc;
168 return 0;
169}
170
171template <class _CharT>
172int __num_get<_CharT>::__stage2_float_loop(
173 _CharT __ct,
174 bool& __in_units,
175 char& __exp,
176 char* __a,
177 char*& __a_end,
178 _CharT __decimal_point,
179 _CharT __thousands_sep,
180 const string& __grouping,
181 unsigned* __g,
182 unsigned*& __g_end,
183 unsigned& __dc,
184 _CharT* __atoms) {
185 if (__ct == __decimal_point) {
186 if (!__in_units)
187 return -1;
188 __in_units = false;
189 *__a_end++ = '.';
190 if (__grouping.size() != 0 && __g_end - __g < __num_get_buf_sz)
191 *__g_end++ = __dc;
192 return 0;
193 }
194 if (__ct == __thousands_sep && __grouping.size() != 0) {
195 if (!__in_units)
196 return -1;
197 if (__g_end - __g < __num_get_buf_sz) {
198 *__g_end++ = __dc;
199 __dc = 0;
200 }
201 return 0;
202 }
203 ptrdiff_t __f = std::find(__atoms, __atoms + __num_get_base::__fp_chr_cnt, __ct) - __atoms;
204 if (__f >= static_cast<ptrdiff_t>(__num_get_base::__fp_chr_cnt))
205 return -1;
206 char __x = __src[__f];
207 if (__x == '-' || __x == '+') {
208 if (__a_end == __a || (std::toupper(__a_end[-1]) == std::toupper(__exp))) {
209 *__a_end++ = __x;
210 return 0;
211 }
212 return -1;
213 }
214 if (__x == 'x' || __x == 'X')
215 __exp = 'P';
216 else if (std::toupper(__x) == __exp) {
217 __exp = std::tolower(__exp);
218 if (__in_units) {
219 __in_units = false;
220 if (__grouping.size() != 0 && __g_end - __g < __num_get_buf_sz)
221 *__g_end++ = __dc;
222 }
223 }
224 *__a_end++ = __x;
225 if (__f >= 22)
226 return 0;
227 ++__dc;
228 return 0;
229}
230
231extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<char>;
232# if _LIBCPP_HAS_WIDE_CHARACTERS
233extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<wchar_t>;
234# endif
235
236template <class _Tp>
237_LIBCPP_HIDE_FROM_ABI _Tp __do_strtod(const char* __a, char** __p2);
238
239template <>
240inline _LIBCPP_HIDE_FROM_ABI float __do_strtod<float>(const char* __a, char** __p2) {
241 return __locale::__strtof(__a, __p2, _LIBCPP_GET_C_LOCALE);
242}
243
244template <>
245inline _LIBCPP_HIDE_FROM_ABI double __do_strtod<double>(const char* __a, char** __p2) {
246 return __locale::__strtod(__a, __p2, _LIBCPP_GET_C_LOCALE);
247}
248
249template <>
250inline _LIBCPP_HIDE_FROM_ABI long double __do_strtod<long double>(const char* __a, char** __p2) {
251 return __locale::__strtold(__a, __p2, _LIBCPP_GET_C_LOCALE);
252}
253
254template <class _Tp>
255_LIBCPP_HIDE_FROM_ABI _Tp __num_get_float(const char* __a, const char* __a_end, ios_base::iostate& __err) {
256 if (__a != __a_end) {
257 __libcpp_remove_reference_t<decltype(errno)> __save_errno = errno;
258 errno = 0;
259 char* __p2;
260 _Tp __ld = std::__do_strtod<_Tp>(__a, &__p2);
261 __libcpp_remove_reference_t<decltype(errno)> __current_errno = errno;
262 if (__current_errno == 0)
263 errno = __save_errno;
264 if (__p2 != __a_end) {
265 __err = ios_base::failbit;
266 return 0;
267 } else if (__current_errno == ERANGE)
268 __err = ios_base::failbit;
269 return __ld;
270 }
271 __err = ios_base::failbit;
272 return 0;
273}
274
275template <class _Tp>
276_LIBCPP_HIDE_FROM_ABI _Tp
277__num_get_signed_integral(const char* __a, const char* __a_end, ios_base::iostate& __err, int __base) {
278 if (__a != __a_end) {
279 __libcpp_remove_reference_t<decltype(errno)> __save_errno = errno;
280 errno = 0;
281 char* __p2;
282 long long __ll = __locale::__strtoll(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
283 __libcpp_remove_reference_t<decltype(errno)> __current_errno = errno;
284 if (__current_errno == 0)
285 errno = __save_errno;
286 if (__p2 != __a_end) {
287 __err = ios_base::failbit;
288 return 0;
289 } else if (__current_errno == ERANGE || __ll < numeric_limits<_Tp>::min() || numeric_limits<_Tp>::max() < __ll) {
290 __err = ios_base::failbit;
291 if (__ll > 0)
292 return numeric_limits<_Tp>::max();
293 else
294 return numeric_limits<_Tp>::min();
295 }
296 return static_cast<_Tp>(__ll);
297 }
298 __err = ios_base::failbit;
299 return 0;
300}
301
302template <class _Tp>
303_LIBCPP_HIDE_FROM_ABI _Tp
304__num_get_unsigned_integral(const char* __a, const char* __a_end, ios_base::iostate& __err, int __base) {
305 if (__a != __a_end) {
306 const bool __negate = *__a == '-';
307 if (__negate && ++__a == __a_end) {
308 __err = ios_base::failbit;
309 return 0;
310 }
311 __libcpp_remove_reference_t<decltype(errno)> __save_errno = errno;
312 errno = 0;
313 char* __p2;
314 unsigned long long __ll = __locale::__strtoull(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
315 __libcpp_remove_reference_t<decltype(errno)> __current_errno = errno;
316 if (__current_errno == 0)
317 errno = __save_errno;
318 if (__p2 != __a_end) {
319 __err = ios_base::failbit;
320 return 0;
321 } else if (__current_errno == ERANGE || numeric_limits<_Tp>::max() < __ll) {
322 __err = ios_base::failbit;
323 return numeric_limits<_Tp>::max();
324 }
325 _Tp __res = static_cast<_Tp>(__ll);
326 if (__negate)
327 __res = -__res;
328 return __res;
329 }
330 __err = ios_base::failbit;
331 return 0;
332}
333
334template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
335class num_get : public locale::facet, private __num_get<_CharT> {
336public:
337 typedef _CharT char_type;
338 typedef _InputIterator iter_type;
339
340 _LIBCPP_HIDE_FROM_ABI explicit num_get(size_t __refs = 0) : locale::facet(__refs) {}
341
342 _LIBCPP_HIDE_FROM_ABI iter_type
343 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, bool& __v) const {
344 return do_get(__b, __e, __iob, __err, __v);
345 }
346
347 _LIBCPP_HIDE_FROM_ABI iter_type
348 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long& __v) const {
349 return do_get(__b, __e, __iob, __err, __v);
350 }
351
352 _LIBCPP_HIDE_FROM_ABI iter_type
353 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long long& __v) const {
354 return do_get(__b, __e, __iob, __err, __v);
355 }
356
357 _LIBCPP_HIDE_FROM_ABI iter_type
358 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned short& __v) const {
359 return do_get(__b, __e, __iob, __err, __v);
360 }
361
362 _LIBCPP_HIDE_FROM_ABI iter_type
363 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned int& __v) const {
364 return do_get(__b, __e, __iob, __err, __v);
365 }
366
367 _LIBCPP_HIDE_FROM_ABI iter_type
368 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long& __v) const {
369 return do_get(__b, __e, __iob, __err, __v);
370 }
371
372 _LIBCPP_HIDE_FROM_ABI iter_type
373 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long long& __v) const {
374 return do_get(__b, __e, __iob, __err, __v);
375 }
376
377 _LIBCPP_HIDE_FROM_ABI iter_type
378 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, float& __v) const {
379 return do_get(__b, __e, __iob, __err, __v);
380 }
381
382 _LIBCPP_HIDE_FROM_ABI iter_type
383 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, double& __v) const {
384 return do_get(__b, __e, __iob, __err, __v);
385 }
386
387 _LIBCPP_HIDE_FROM_ABI iter_type
388 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long double& __v) const {
389 return do_get(__b, __e, __iob, __err, __v);
390 }
391
392 _LIBCPP_HIDE_FROM_ABI iter_type
393 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, void*& __v) const {
394 return do_get(__b, __e, __iob, __err, __v);
395 }
396
397 static locale::id id;
398
399protected:
400 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~num_get() override {}
401
402 template <class _Fp>
403 _LIBCPP_HIDE_FROM_ABI iter_type
404 __do_get_floating_point(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Fp& __v) const {
405 // Stage 1, nothing to do
406 // Stage 2
407 char_type __atoms[__num_get_base::__fp_chr_cnt];
408 char_type __decimal_point;
409 char_type __thousands_sep;
410 string __grouping = this->__stage2_float_prep(__iob, __atoms, __decimal_point, __thousands_sep);
411 string __buf;
412 __buf.resize(__buf.capacity());
413 char* __a = &__buf[0];
414 char* __a_end = __a;
415 unsigned __g[__num_get_base::__num_get_buf_sz];
416 unsigned* __g_end = __g;
417 unsigned __dc = 0;
418 bool __in_units = true;
419 char __exp = 'E';
420 bool __is_leading_parsed = false;
421 for (; __b != __e; ++__b) {
422 if (__a_end == __a + __buf.size()) {
423 size_t __tmp = __buf.size();
424 __buf.resize(2 * __buf.size());
425 __buf.resize(__buf.capacity());
426 __a = &__buf[0];
427 __a_end = __a + __tmp;
428 }
429 if (this->__stage2_float_loop(
430 *__b,
431 __in_units,
432 __exp,
433 __a,
434 __a_end,
435 __decimal_point,
436 __thousands_sep,
437 __grouping,
438 __g,
439 __g_end,
440 __dc,
441 __atoms))
442 break;
443
444 // the leading character excluding the sign must be a decimal digit
445 if (!__is_leading_parsed) {
446 if (__a_end - __a >= 1 && __a[0] != '-' && __a[0] != '+') {
447 if (('0' <= __a[0] && __a[0] <= '9') || __a[0] == '.')
448 __is_leading_parsed = true;
449 else
450 break;
451 } else if (__a_end - __a >= 2 && (__a[0] == '-' || __a[0] == '+')) {
452 if (('0' <= __a[1] && __a[1] <= '9') || __a[1] == '.')
453 __is_leading_parsed = true;
454 else
455 break;
456 }
457 }
458 }
459 if (__grouping.size() != 0 && __in_units && __g_end - __g < __num_get_base::__num_get_buf_sz)
460 *__g_end++ = __dc;
461 // Stage 3
462 __v = std::__num_get_float<_Fp>(__a, __a_end, __err);
463 // Digit grouping checked
464 __check_grouping(__grouping, __g, __g_end, __err);
465 // EOF checked
466 if (__b == __e)
467 __err |= ios_base::eofbit;
468 return __b;
469 }
470
471 template <class _Signed>
472 _LIBCPP_HIDE_FROM_ABI iter_type
473 __do_get_signed(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Signed& __v) const {
474 // Stage 1
475 int __base = this->__get_base(__iob);
476 // Stage 2
477 char_type __thousands_sep;
478 const int __atoms_size = __num_get_base::__int_chr_cnt;
479 char_type __atoms1[__atoms_size];
480 const char_type* __atoms = this->__do_widen(__iob, __atoms1);
481 string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
482 string __buf;
483 __buf.resize(__buf.capacity());
484 char* __a = &__buf[0];
485 char* __a_end = __a;
486 unsigned __g[__num_get_base::__num_get_buf_sz];
487 unsigned* __g_end = __g;
488 unsigned __dc = 0;
489 for (; __b != __e; ++__b) {
490 if (__a_end == __a + __buf.size()) {
491 size_t __tmp = __buf.size();
492 __buf.resize(2 * __buf.size());
493 __buf.resize(__buf.capacity());
494 __a = &__buf[0];
495 __a_end = __a + __tmp;
496 }
497 if (this->__stage2_int_loop(
498 *__b,
499 __base,
500 __a,
501 __a_end,
502 __dc,
503 __thousands_sep,
504 __grouping,
505 __g,
506 __g_end,
507 const_cast<char_type*>(__atoms)))
508 break;
509 }
510 if (__grouping.size() != 0 && __g_end - __g < __num_get_base::__num_get_buf_sz)
511 *__g_end++ = __dc;
512 // Stage 3
513 __v = std::__num_get_signed_integral<_Signed>(__a, __a_end, __err, __base);
514 // Digit grouping checked
515 __check_grouping(__grouping, __g, __g_end, __err);
516 // EOF checked
517 if (__b == __e)
518 __err |= ios_base::eofbit;
519 return __b;
520 }
521
522 template <class _Unsigned>
523 _LIBCPP_HIDE_FROM_ABI iter_type
524 __do_get_unsigned(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Unsigned& __v) const {
525 // Stage 1
526 int __base = this->__get_base(__iob);
527 // Stage 2
528 char_type __thousands_sep;
529 const int __atoms_size = __num_get_base::__int_chr_cnt;
530 char_type __atoms1[__atoms_size];
531 const char_type* __atoms = this->__do_widen(__iob, __atoms1);
532 string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
533 string __buf;
534 __buf.resize(__buf.capacity());
535 char* __a = &__buf[0];
536 char* __a_end = __a;
537 unsigned __g[__num_get_base::__num_get_buf_sz];
538 unsigned* __g_end = __g;
539 unsigned __dc = 0;
540 for (; __b != __e; ++__b) {
541 if (__a_end == __a + __buf.size()) {
542 size_t __tmp = __buf.size();
543 __buf.resize(2 * __buf.size());
544 __buf.resize(__buf.capacity());
545 __a = &__buf[0];
546 __a_end = __a + __tmp;
547 }
548 if (this->__stage2_int_loop(
549 *__b,
550 __base,
551 __a,
552 __a_end,
553 __dc,
554 __thousands_sep,
555 __grouping,
556 __g,
557 __g_end,
558 const_cast<char_type*>(__atoms)))
559 break;
560 }
561 if (__grouping.size() != 0 && __g_end - __g < __num_get_base::__num_get_buf_sz)
562 *__g_end++ = __dc;
563 // Stage 3
564 __v = std::__num_get_unsigned_integral<_Unsigned>(__a, __a_end, __err, __base);
565 // Digit grouping checked
566 __check_grouping(__grouping, __g, __g_end, __err);
567 // EOF checked
568 if (__b == __e)
569 __err |= ios_base::eofbit;
570 return __b;
571 }
572
573 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, bool& __v) const;
574
575 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long& __v) const {
576 return this->__do_get_signed(__b, __e, __iob, __err, __v);
577 }
578
579 virtual iter_type
580 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long long& __v) const {
581 return this->__do_get_signed(__b, __e, __iob, __err, __v);
582 }
583
584 virtual iter_type
585 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned short& __v) const {
586 return this->__do_get_unsigned(__b, __e, __iob, __err, __v);
587 }
588
589 virtual iter_type
590 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned int& __v) const {
591 return this->__do_get_unsigned(__b, __e, __iob, __err, __v);
592 }
593
594 virtual iter_type
595 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long& __v) const {
596 return this->__do_get_unsigned(__b, __e, __iob, __err, __v);
597 }
598
599 virtual iter_type
600 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long long& __v) const {
601 return this->__do_get_unsigned(__b, __e, __iob, __err, __v);
602 }
603
604 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, float& __v) const {
605 return this->__do_get_floating_point(__b, __e, __iob, __err, __v);
606 }
607
608 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, double& __v) const {
609 return this->__do_get_floating_point(__b, __e, __iob, __err, __v);
610 }
611
612 virtual iter_type
613 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long double& __v) const {
614 return this->__do_get_floating_point(__b, __e, __iob, __err, __v);
615 }
616
617 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, void*& __v) const;
618};
619
620template <class _CharT, class _InputIterator>
621locale::id num_get<_CharT, _InputIterator>::id;
622
623template <class _CharT, class _InputIterator>
624_InputIterator num_get<_CharT, _InputIterator>::do_get(
625 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, bool& __v) const {
626 if ((__iob.flags() & ios_base::boolalpha) == 0) {
627 long __lv = -1;
628 __b = do_get(__b, __e, __iob, __err, __lv);
629 switch (__lv) {
630 case 0:
631 __v = false;
632 break;
633 case 1:
634 __v = true;
635 break;
636 default:
637 __v = true;
638 __err = ios_base::failbit;
639 break;
640 }
641 return __b;
642 }
643 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__iob.getloc());
644 const numpunct<_CharT>& __np = std::use_facet<numpunct<_CharT> >(__iob.getloc());
645 typedef typename numpunct<_CharT>::string_type string_type;
646 const string_type __names[2] = {__np.truename(), __np.falsename()};
647 const string_type* __i = std::__scan_keyword(__b, __e, __names, __names + 2, __ct, __err);
648 __v = __i == __names;
649 return __b;
650}
651
652template <class _CharT, class _InputIterator>
653_InputIterator num_get<_CharT, _InputIterator>::do_get(
654 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, void*& __v) const {
655 // Stage 1
656 int __base = 16;
657 // Stage 2
658 char_type __atoms[__num_get_base::__int_chr_cnt];
659 char_type __thousands_sep = char_type();
660 string __grouping;
661 std::use_facet<ctype<_CharT> >(__iob.getloc())
662 .widen(__num_get_base::__src, __num_get_base::__src + __num_get_base::__int_chr_cnt, __atoms);
663 string __buf;
664 __buf.resize(__buf.capacity());
665 char* __a = &__buf[0];
666 char* __a_end = __a;
667 unsigned __g[__num_get_base::__num_get_buf_sz];
668 unsigned* __g_end = __g;
669 unsigned __dc = 0;
670 for (; __b != __e; ++__b) {
671 if (__a_end == __a + __buf.size()) {
672 size_t __tmp = __buf.size();
673 __buf.resize(2 * __buf.size());
674 __buf.resize(__buf.capacity());
675 __a = &__buf[0];
676 __a_end = __a + __tmp;
677 }
678 if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms))
679 break;
680 }
681 // Stage 3
682 __buf.resize(__a_end - __a);
683 if (__locale::__sscanf(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1)
684 __err = ios_base::failbit;
685 // EOF checked
686 if (__b == __e)
687 __err |= ios_base::eofbit;
688 return __b;
689}
690
691extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<char>;
692# if _LIBCPP_HAS_WIDE_CHARACTERS
693extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<wchar_t>;
694# endif
695
696struct _LIBCPP_EXPORTED_FROM_ABI __num_put_base {
697protected:
698 static void __format_int(char* __fmt, const char* __len, bool __signd, ios_base::fmtflags __flags);
699 static bool __format_float(char* __fmt, const char* __len, ios_base::fmtflags __flags);
700 static char* __identify_padding(char* __nb, char* __ne, const ios_base& __iob);
701};
702
703template <class _CharT>
704struct __num_put : protected __num_put_base {
705 static void __widen_and_group_int(
706 char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc);
707 static void __widen_and_group_float(
708 char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc);
709};
710
711template <class _CharT>
712void __num_put<_CharT>::__widen_and_group_int(
713 char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc) {
714 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__loc);
715 const numpunct<_CharT>& __npt = std::use_facet<numpunct<_CharT> >(__loc);
716 string __grouping = __npt.grouping();
717 if (__grouping.empty()) {
718 __ct.widen(__nb, __ne, __ob);
719 __oe = __ob + (__ne - __nb);
720 } else {
721 __oe = __ob;
722 char* __nf = __nb;
723 if (*__nf == '-' || *__nf == '+')
724 *__oe++ = __ct.widen(*__nf++);
725 if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || __nf[1] == 'X')) {
726 *__oe++ = __ct.widen(*__nf++);
727 *__oe++ = __ct.widen(*__nf++);
728 }
729 std::reverse(__nf, __ne);
730 _CharT __thousands_sep = __npt.thousands_sep();
731 unsigned __dc = 0;
732 unsigned __dg = 0;
733 for (char* __p = __nf; __p < __ne; ++__p) {
734 if (static_cast<unsigned>(__grouping[__dg]) > 0 && __dc == static_cast<unsigned>(__grouping[__dg])) {
735 *__oe++ = __thousands_sep;
736 __dc = 0;
737 if (__dg < __grouping.size() - 1)
738 ++__dg;
739 }
740 *__oe++ = __ct.widen(*__p);
741 ++__dc;
742 }
743 std::reverse(__ob + (__nf - __nb), __oe);
744 }
745 if (__np == __ne)
746 __op = __oe;
747 else
748 __op = __ob + (__np - __nb);
749}
750
751template <class _CharT>
752void __num_put<_CharT>::__widen_and_group_float(
753 char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc) {
754 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__loc);
755 const numpunct<_CharT>& __npt = std::use_facet<numpunct<_CharT> >(__loc);
756 string __grouping = __npt.grouping();
757 __oe = __ob;
758 char* __nf = __nb;
759 if (*__nf == '-' || *__nf == '+')
760 *__oe++ = __ct.widen(*__nf++);
761 char* __ns;
762 if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || __nf[1] == 'X')) {
763 *__oe++ = __ct.widen(*__nf++);
764 *__oe++ = __ct.widen(*__nf++);
765 for (__ns = __nf; __ns < __ne; ++__ns)
766 if (!__locale::__isxdigit(*__ns, _LIBCPP_GET_C_LOCALE))
767 break;
768 } else {
769 for (__ns = __nf; __ns < __ne; ++__ns)
770 if (!__locale::__isdigit(*__ns, _LIBCPP_GET_C_LOCALE))
771 break;
772 }
773 if (__grouping.empty()) {
774 __ct.widen(__nf, __ns, __oe);
775 __oe += __ns - __nf;
776 } else {
777 std::reverse(__nf, __ns);
778 _CharT __thousands_sep = __npt.thousands_sep();
779 unsigned __dc = 0;
780 unsigned __dg = 0;
781 for (char* __p = __nf; __p < __ns; ++__p) {
782 if (__grouping[__dg] > 0 && __dc == static_cast<unsigned>(__grouping[__dg])) {
783 *__oe++ = __thousands_sep;
784 __dc = 0;
785 if (__dg < __grouping.size() - 1)
786 ++__dg;
787 }
788 *__oe++ = __ct.widen(*__p);
789 ++__dc;
790 }
791 std::reverse(__ob + (__nf - __nb), __oe);
792 }
793 for (__nf = __ns; __nf < __ne; ++__nf) {
794 if (*__nf == '.') {
795 *__oe++ = __npt.decimal_point();
796 ++__nf;
797 break;
798 } else
799 *__oe++ = __ct.widen(*__nf);
800 }
801 __ct.widen(__nf, __ne, __oe);
802 __oe += __ne - __nf;
803 if (__np == __ne)
804 __op = __oe;
805 else
806 __op = __ob + (__np - __nb);
807}
808
809extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<char>;
810# if _LIBCPP_HAS_WIDE_CHARACTERS
811extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<wchar_t>;
812# endif
813
814template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
815class num_put : public locale::facet, private __num_put<_CharT> {
816public:
817 typedef _CharT char_type;
818 typedef _OutputIterator iter_type;
819
820 _LIBCPP_HIDE_FROM_ABI explicit num_put(size_t __refs = 0) : locale::facet(__refs) {}
821
822 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, bool __v) const {
823 return do_put(__s, __iob, __fl, __v);
824 }
825
826 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, long __v) const {
827 return do_put(__s, __iob, __fl, __v);
828 }
829
830 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, long long __v) const {
831 return do_put(__s, __iob, __fl, __v);
832 }
833
834 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long __v) const {
835 return do_put(__s, __iob, __fl, __v);
836 }
837
838 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long long __v) const {
839 return do_put(__s, __iob, __fl, __v);
840 }
841
842 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, double __v) const {
843 return do_put(__s, __iob, __fl, __v);
844 }
845
846 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, long double __v) const {
847 return do_put(__s, __iob, __fl, __v);
848 }
849
850 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, const void* __v) const {
851 return do_put(__s, __iob, __fl, __v);
852 }
853
854 static locale::id id;
855
856protected:
857 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~num_put() override {}
858
859 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, bool __v) const;
860 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, long __v) const;
861 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, long long __v) const;
862 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long) const;
863 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long long) const;
864 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, double __v) const;
865 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, long double __v) const;
866 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, const void* __v) const;
867
868 template <class _Integral>
869 _LIBCPP_HIDE_FROM_ABI inline _OutputIterator
870 __do_put_integral(iter_type __s, ios_base& __iob, char_type __fl, _Integral __v) const;
871
872 template <class _Float>
873 _LIBCPP_HIDE_FROM_ABI inline _OutputIterator
874 __do_put_floating_point(iter_type __s, ios_base& __iob, char_type __fl, _Float __v, char const* __len) const;
875};
876
877template <class _CharT, class _OutputIterator>
878locale::id num_put<_CharT, _OutputIterator>::id;
879
880template <class _CharT, class _OutputIterator>
881_OutputIterator
882num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, bool __v) const {
883 if ((__iob.flags() & ios_base::boolalpha) == 0)
884 return do_put(__s, __iob, __fl, (unsigned long)__v);
885 const numpunct<char_type>& __np = std::use_facet<numpunct<char_type> >(__iob.getloc());
886 typedef typename numpunct<char_type>::string_type string_type;
887 string_type __nm = __v ? __np.truename() : __np.falsename();
888 for (typename string_type::iterator __i = __nm.begin(); __i != __nm.end(); ++__i, ++__s)
889 *__s = *__i;
890 return __s;
891}
892
893template <class _CharT, class _OutputIterator>
894template <class _Integral>
895_LIBCPP_HIDE_FROM_ABI inline _OutputIterator num_put<_CharT, _OutputIterator>::__do_put_integral(
896 iter_type __s, ios_base& __iob, char_type __fl, _Integral __v) const {
897 // Stage 1 - Get number in narrow char
898
899 // Worst case is octal, with showbase enabled. Note that octal is always
900 // printed as an unsigned value.
901 using _Unsigned = typename make_unsigned<_Integral>::type;
902 _LIBCPP_CONSTEXPR const unsigned __buffer_size =
903 (numeric_limits<_Unsigned>::digits / 3) // 1 char per 3 bits
904 + ((numeric_limits<_Unsigned>::digits % 3) != 0) // round up
905 + 2; // base prefix + terminating null character
906
907 char __char_buffer[__buffer_size];
908 char* __buffer_ptr = __char_buffer;
909
910 auto __flags = __iob.flags();
911
912 auto __basefield = (__flags & ios_base::basefield);
913
914 // Extract base
915 int __base = 10;
916 if (__basefield == ios_base::oct)
917 __base = 8;
918 else if (__basefield == ios_base::hex)
919 __base = 16;
920
921 // Print '-' and make the argument unsigned
922 auto __uval = std::__to_unsigned_like(__v);
923 if (__basefield != ios_base::oct && __basefield != ios_base::hex && __v < 0) {
924 *__buffer_ptr++ = '-';
925 __uval = std::__complement(__uval);
926 }
927
928 // Maybe add '+' prefix
929 if (std::is_signed<_Integral>::value && (__flags & ios_base::showpos) && __basefield != ios_base::oct &&
930 __basefield != ios_base::hex && __v >= 0)
931 *__buffer_ptr++ = '+';
932
933 // Add base prefix
934 if (__v != 0 && __flags & ios_base::showbase) {
935 if (__basefield == ios_base::oct) {
936 *__buffer_ptr++ = '0';
937 } else if (__basefield == ios_base::hex) {
938 *__buffer_ptr++ = '0';
939 *__buffer_ptr++ = (__flags & ios_base::uppercase ? 'X' : 'x');
940 }
941 }
942
943 auto __res = std::__to_chars_integral(__buffer_ptr, __char_buffer + __buffer_size, __uval, __base);
944 _LIBCPP_ASSERT_INTERNAL(__res.__ec == std::errc(0), "to_chars: invalid maximum buffer size computed?");
945
946 // Make letters uppercase
947 if (__flags & ios_base::hex && __flags & ios_base::uppercase) {
948 for (; __buffer_ptr != __res.__ptr; ++__buffer_ptr)
949 *__buffer_ptr = std::__hex_to_upper(*__buffer_ptr);
950 }
951
952 char* __np = this->__identify_padding(__char_buffer, __res.__ptr, __iob);
953 // Stage 2 - Widen __nar while adding thousands separators
954 char_type __o[2 * (__buffer_size - 1) - 1];
955 char_type* __op; // pad here
956 char_type* __oe; // end of output
957 this->__widen_and_group_int(__char_buffer, __np, __res.__ptr, __o, __op, __oe, __iob.getloc());
958 // [__o, __oe) contains thousands_sep'd wide number
959 // Stage 3 & 4
960 return std::__pad_and_output(__s, __o, __op, __oe, __iob, __fl);
961}
962
963template <class _CharT, class _OutputIterator>
964_OutputIterator
965num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, long __v) const {
966 return this->__do_put_integral(__s, __iob, __fl, __v);
967}
968
969template <class _CharT, class _OutputIterator>
970_OutputIterator
971num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, long long __v) const {
972 return this->__do_put_integral(__s, __iob, __fl, __v);
973}
974
975template <class _CharT, class _OutputIterator>
976_OutputIterator
977num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long __v) const {
978 return this->__do_put_integral(__s, __iob, __fl, __v);
979}
980
981template <class _CharT, class _OutputIterator>
982_OutputIterator
983num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long long __v) const {
984 return this->__do_put_integral(__s, __iob, __fl, __v);
985}
986
987template <class _CharT, class _OutputIterator>
988template <class _Float>
989_LIBCPP_HIDE_FROM_ABI inline _OutputIterator num_put<_CharT, _OutputIterator>::__do_put_floating_point(
990 iter_type __s, ios_base& __iob, char_type __fl, _Float __v, char const* __len) const {
991 // Stage 1 - Get number in narrow char
992 char __fmt[8] = {'%', 0};
993 bool __specify_precision = this->__format_float(__fmt + 1, __len, __iob.flags());
994 const unsigned __nbuf = 30;
995 char __nar[__nbuf];
996 char* __nb = __nar;
997 int __nc;
998 _LIBCPP_DIAGNOSTIC_PUSH
999 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
1000 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
1001 if (__specify_precision)
1002 __nc = __locale::__snprintf(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
1003 else
1004 __nc = __locale::__snprintf(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
1005 unique_ptr<char, void (*)(void*)> __nbh(nullptr, free);
1006 if (__nc > static_cast<int>(__nbuf - 1)) {
1007 if (__specify_precision)
1008 __nc = __locale::__asprintf(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
1009 else
1010 __nc = __locale::__asprintf(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
1011 if (__nc == -1)
1012 std::__throw_bad_alloc();
1013 __nbh.reset(__nb);
1014 }
1015 _LIBCPP_DIAGNOSTIC_POP
1016 char* __ne = __nb + __nc;
1017 char* __np = this->__identify_padding(__nb, __ne, __iob);
1018 // Stage 2 - Widen __nar while adding thousands separators
1019 char_type __o[2 * (__nbuf - 1) - 1];
1020 char_type* __ob = __o;
1021 unique_ptr<char_type, void (*)(void*)> __obh(0, free);
1022 if (__nb != __nar) {
1023 __ob = (char_type*)malloc(2 * static_cast<size_t>(__nc) * sizeof(char_type));
1024 if (__ob == 0)
1025 std::__throw_bad_alloc();
1026 __obh.reset(__ob);
1027 }
1028 char_type* __op; // pad here
1029 char_type* __oe; // end of output
1030 this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc());
1031 // [__o, __oe) contains thousands_sep'd wide number
1032 // Stage 3 & 4
1033 __s = std::__pad_and_output(__s, __ob, __op, __oe, __iob, __fl);
1034 return __s;
1035}
1036
1037template <class _CharT, class _OutputIterator>
1038_OutputIterator
1039num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, double __v) const {
1040 return this->__do_put_floating_point(__s, __iob, __fl, __v, "");
1041}
1042
1043template <class _CharT, class _OutputIterator>
1044_OutputIterator
1045num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, long double __v) const {
1046 return this->__do_put_floating_point(__s, __iob, __fl, __v, "L");
1047}
1048
1049template <class _CharT, class _OutputIterator>
1050_OutputIterator
1051num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, const void* __v) const {
1052 auto __flags = __iob.flags();
1053 __iob.flags((__flags & ~ios_base::basefield & ~ios_base::uppercase) | ios_base::hex | ios_base::showbase);
1054 auto __res = __do_put_integral(__s, __iob, __fl, reinterpret_cast<uintptr_t>(__v));
1055 __iob.flags(__flags);
1056 return __res;
1057}
1058
1059extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<char>;
1060# if _LIBCPP_HAS_WIDE_CHARACTERS
1061extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<wchar_t>;
1062# endif
1063
1064_LIBCPP_END_NAMESPACE_STD
1065
1066_LIBCPP_POP_MACROS
1067
1068// NOLINTEND(libcpp-robust-against-adl)
1069
1070#endif // _LIBCPP_HAS_LOCALIZATION
1071
1072#endif // _LIBCPP___LOCALE_DIR_NUM_H
lib/libcxx/include/__locale_dir/scan_keyword.h created+143
......@@ -0,0 +1,143 @@
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_SCAN_KEYWORD_H
10#define _LIBCPP___LOCALE_DIR_SCAN_KEYWORD_H
11
12#include <__config>
13#include <__memory/unique_ptr.h>
14#include <ios>
15
16#if _LIBCPP_HAS_LOCALIZATION
17
18# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20# endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24// __scan_keyword
25// Scans [__b, __e) until a match is found in the basic_strings range
26// [__kb, __ke) or until it can be shown that there is no match in [__kb, __ke).
27// __b will be incremented (visibly), consuming CharT until a match is found
28// or proved to not exist. A keyword may be "", in which will match anything.
29// If one keyword is a prefix of another, and the next CharT in the input
30// might match another keyword, the algorithm will attempt to find the longest
31// matching keyword. If the longer matching keyword ends up not matching, then
32// no keyword match is found. If no keyword match is found, __ke is returned
33// and failbit is set in __err.
34// Else an iterator pointing to the matching keyword is found. If more than
35// one keyword matches, an iterator to the first matching keyword is returned.
36// If on exit __b == __e, eofbit is set in __err. If __case_sensitive is false,
37// __ct is used to force to lower case before comparing characters.
38// Examples:
39// Keywords: "a", "abb"
40// If the input is "a", the first keyword matches and eofbit is set.
41// If the input is "abc", no match is found and "ab" are consumed.
42template <class _InputIterator, class _ForwardIterator, class _Ctype>
43_LIBCPP_HIDE_FROM_ABI _ForwardIterator __scan_keyword(
44 _InputIterator& __b,
45 _InputIterator __e,
46 _ForwardIterator __kb,
47 _ForwardIterator __ke,
48 const _Ctype& __ct,
49 ios_base::iostate& __err,
50 bool __case_sensitive = true) {
51 typedef typename iterator_traits<_InputIterator>::value_type _CharT;
52 size_t __nkw = static_cast<size_t>(std::distance(__kb, __ke));
53 const unsigned char __doesnt_match = '\0';
54 const unsigned char __might_match = '\1';
55 const unsigned char __does_match = '\2';
56 unsigned char __statbuf[100];
57 unsigned char* __status = __statbuf;
58 unique_ptr<unsigned char, void (*)(void*)> __stat_hold(nullptr, free);
59 if (__nkw > sizeof(__statbuf)) {
60 __status = (unsigned char*)malloc(__nkw);
61 if (__status == nullptr)
62 std::__throw_bad_alloc();
63 __stat_hold.reset(__status);
64 }
65 size_t __n_might_match = __nkw; // At this point, any keyword might match
66 size_t __n_does_match = 0; // but none of them definitely do
67 // Initialize all statuses to __might_match, except for "" keywords are __does_match
68 unsigned char* __st = __status;
69 for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void)++__st) {
70 if (!__ky->empty())
71 *__st = __might_match;
72 else {
73 *__st = __does_match;
74 --__n_might_match;
75 ++__n_does_match;
76 }
77 }
78 // While there might be a match, test keywords against the next CharT
79 for (size_t __indx = 0; __b != __e && __n_might_match > 0; ++__indx) {
80 // Peek at the next CharT but don't consume it
81 _CharT __c = *__b;
82 if (!__case_sensitive)
83 __c = __ct.toupper(__c);
84 bool __consume = false;
85 // For each keyword which might match, see if the __indx character is __c
86 // If a match if found, consume __c
87 // If a match is found, and that is the last character in the keyword,
88 // then that keyword matches.
89 // If the keyword doesn't match this character, then change the keyword
90 // to doesn't match
91 __st = __status;
92 for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void)++__st) {
93 if (*__st == __might_match) {
94 _CharT __kc = (*__ky)[__indx];
95 if (!__case_sensitive)
96 __kc = __ct.toupper(__kc);
97 if (__c == __kc) {
98 __consume = true;
99 if (__ky->size() == __indx + 1) {
100 *__st = __does_match;
101 --__n_might_match;
102 ++__n_does_match;
103 }
104 } else {
105 *__st = __doesnt_match;
106 --__n_might_match;
107 }
108 }
109 }
110 // consume if we matched a character
111 if (__consume) {
112 ++__b;
113 // If we consumed a character and there might be a matched keyword that
114 // was marked matched on a previous iteration, then such keywords
115 // which are now marked as not matching.
116 if (__n_might_match + __n_does_match > 1) {
117 __st = __status;
118 for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void)++__st) {
119 if (*__st == __does_match && __ky->size() != __indx + 1) {
120 *__st = __doesnt_match;
121 --__n_does_match;
122 }
123 }
124 }
125 }
126 }
127 // We've exited the loop because we hit eof and/or we have no more "might matches".
128 if (__b == __e)
129 __err |= ios_base::eofbit;
130 // Return the first matching result
131 for (__st = __status; __kb != __ke; ++__kb, (void)++__st)
132 if (*__st == __does_match)
133 break;
134 if (__kb == __ke)
135 __err |= ios_base::failbit;
136 return __kb;
137}
138
139_LIBCPP_END_NAMESPACE_STD
140
141#endif // _LIBCPP_HAS_LOCALIZATION
142
143#endif // _LIBCPP___LOCALE_DIR_SCAN_KEYWORD_H
lib/libcxx/include/__locale_dir/support/apple.h-2
......@@ -15,8 +15,6 @@
1515# pragma GCC system_header
1616#endif
1717
18#include <xlocale.h>
19
2018#include <__locale_dir/support/bsd_like.h>
2119
2220#endif // _LIBCPP___LOCALE_DIR_SUPPORT_APPLE_H
lib/libcxx/include/__locale_dir/support/bsd_like.h+7-8
......@@ -24,6 +24,11 @@
2424# include <wctype.h>
2525#endif
2626
27/* zig patch: https://github.com/llvm/llvm-project/pull/143055 */
28#if __has_include(<xlocale.h>)
29# include <xlocale.h>
30#endif
31
2732#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2833# pragma GCC system_header
2934#endif
......@@ -43,9 +48,9 @@ namespace __locale {
4348#define _LIBCPP_ALL_MASK LC_ALL_MASK
4449#define _LIBCPP_LC_ALL LC_ALL
4550
46using __locale_t = ::locale_t;
51using __locale_t _LIBCPP_NODEBUG = ::locale_t;
4752#if defined(_LIBCPP_BUILDING_LIBRARY)
48using __lconv_t = std::lconv;
53using __lconv_t _LIBCPP_NODEBUG = std::lconv;
4954
5055inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __locale, __locale_t __base) {
5156 return ::newlocale(__category_mask, __locale, __base);
......@@ -87,12 +92,6 @@ __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
8792//
8893// Character manipulation functions
8994//
90#if defined(_LIBCPP_BUILDING_LIBRARY)
91inline _LIBCPP_HIDE_FROM_ABI int __islower(int __c, __locale_t __loc) { return ::islower_l(__c, __loc); }
92
93inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __c, __locale_t __loc) { return ::isupper_l(__c, __loc); }
94#endif
95
9695inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t __loc) { return ::isdigit_l(__c, __loc); }
9796
9897inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t __loc) { return ::isxdigit_l(__c, __loc); }
lib/libcxx/include/__locale_dir/support/freebsd.h-2
......@@ -15,8 +15,6 @@
1515# pragma GCC system_header
1616#endif
1717
18#include <xlocale.h>
19
2018#include <__locale_dir/support/bsd_like.h>
2119
2220#endif // _LIBCPP___LOCALE_DIR_SUPPORT_FREEBSD_H
lib/libcxx/include/__locale_dir/support/fuchsia.h+2-2
......@@ -49,10 +49,10 @@ struct __locale_guard {
4949#define _LIBCPP_ALL_MASK LC_ALL_MASK
5050#define _LIBCPP_LC_ALL LC_ALL
5151
52using __locale_t = locale_t;
52using __locale_t _LIBCPP_NODEBUG = locale_t;
5353
5454#if defined(_LIBCPP_BUILDING_LIBRARY)
55using __lconv_t = std::lconv;
55using __lconv_t _LIBCPP_NODEBUG = std::lconv;
5656
5757inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __name, __locale_t __loc) {
5858 return ::newlocale(__category_mask, __name, __loc);
lib/libcxx/include/__locale_dir/support/linux.h created+281
......@@ -0,0 +1,281 @@
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_LINUX_H
10#define _LIBCPP___LOCALE_DIR_SUPPORT_LINUX_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 <cstdio>
18#include <cstdlib>
19#include <ctype.h>
20#include <stdarg.h>
21#include <string.h>
22#include <time.h>
23#if _LIBCPP_HAS_WIDE_CHARACTERS
24# include <cwchar>
25# include <wctype.h>
26#endif
27
28#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29# pragma GCC system_header
30#endif
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33namespace __locale {
34
35struct __locale_guard {
36 _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {}
37
38 _LIBCPP_HIDE_FROM_ABI ~__locale_guard() {
39 if (__old_loc_)
40 ::uselocale(__old_loc_);
41 }
42
43 locale_t __old_loc_;
44
45 __locale_guard(__locale_guard const&) = delete;
46 __locale_guard& operator=(__locale_guard const&) = delete;
47};
48
49//
50// Locale management
51//
52#define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK
53#define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK
54#define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK
55#define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK
56#define _LIBCPP_TIME_MASK LC_TIME_MASK
57#define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
58#define _LIBCPP_ALL_MASK LC_ALL_MASK
59#define _LIBCPP_LC_ALL LC_ALL
60
61using __locale_t _LIBCPP_NODEBUG = ::locale_t;
62
63#if defined(_LIBCPP_BUILDING_LIBRARY)
64using __lconv_t _LIBCPP_NODEBUG = std::lconv;
65
66inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __locale, __locale_t __base) {
67 return ::newlocale(__category_mask, __locale, __base);
68}
69
70inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { ::freelocale(__loc); }
71
72inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, char const* __locale) {
73 return ::setlocale(__category, __locale);
74}
75
76inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) {
77 __locale_guard __current(__loc);
78 return std::localeconv();
79}
80#endif // _LIBCPP_BUILDING_LIBRARY
81
82//
83// Strtonum functions
84//
85inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) {
86 return ::strtof_l(__nptr, __endptr, __loc);
87}
88
89inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) {
90 return ::strtod_l(__nptr, __endptr, __loc);
91}
92
93inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) {
94 return ::strtold_l(__nptr, __endptr, __loc);
95}
96
97inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
98#if !_LIBCPP_HAS_MUSL_LIBC
99 return ::strtoll_l(__nptr, __endptr, __base, __loc);
100#else
101 (void)__loc;
102 return ::strtoll(__nptr, __endptr, __base);
103#endif
104}
105
106inline _LIBCPP_HIDE_FROM_ABI unsigned long long
107__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
108#if !_LIBCPP_HAS_MUSL_LIBC
109 return ::strtoull_l(__nptr, __endptr, __base, __loc);
110#else
111 (void)__loc;
112 return ::strtoull(__nptr, __endptr, __base);
113#endif
114}
115
116//
117// Character manipulation functions
118//
119inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t __loc) { return isdigit_l(__c, __loc); }
120
121inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t __loc) { return isxdigit_l(__c, __loc); }
122
123#if defined(_LIBCPP_BUILDING_LIBRARY)
124inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __c, __locale_t __loc) { return toupper_l(__c, __loc); }
125
126inline _LIBCPP_HIDE_FROM_ABI int __tolower(int __c, __locale_t __loc) { return tolower_l(__c, __loc); }
127
128inline _LIBCPP_HIDE_FROM_ABI int __strcoll(const char* __s1, const char* __s2, __locale_t __loc) {
129 return strcoll_l(__s1, __s2, __loc);
130}
131
132inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, size_t __n, __locale_t __loc) {
133 return strxfrm_l(__dest, __src, __n, __loc);
134}
135
136# if _LIBCPP_HAS_WIDE_CHARACTERS
137inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __c, wctype_t __type, __locale_t __loc) {
138 return iswctype_l(__c, __type, __loc);
139}
140
141inline _LIBCPP_HIDE_FROM_ABI int __iswspace(wint_t __c, __locale_t __loc) { return iswspace_l(__c, __loc); }
142
143inline _LIBCPP_HIDE_FROM_ABI int __iswprint(wint_t __c, __locale_t __loc) { return iswprint_l(__c, __loc); }
144
145inline _LIBCPP_HIDE_FROM_ABI int __iswcntrl(wint_t __c, __locale_t __loc) { return iswcntrl_l(__c, __loc); }
146
147inline _LIBCPP_HIDE_FROM_ABI int __iswupper(wint_t __c, __locale_t __loc) { return iswupper_l(__c, __loc); }
148
149inline _LIBCPP_HIDE_FROM_ABI int __iswlower(wint_t __c, __locale_t __loc) { return iswlower_l(__c, __loc); }
150
151inline _LIBCPP_HIDE_FROM_ABI int __iswalpha(wint_t __c, __locale_t __loc) { return iswalpha_l(__c, __loc); }
152
153inline _LIBCPP_HIDE_FROM_ABI int __iswblank(wint_t __c, __locale_t __loc) { return iswblank_l(__c, __loc); }
154
155inline _LIBCPP_HIDE_FROM_ABI int __iswdigit(wint_t __c, __locale_t __loc) { return iswdigit_l(__c, __loc); }
156
157inline _LIBCPP_HIDE_FROM_ABI int __iswpunct(wint_t __c, __locale_t __loc) { return iswpunct_l(__c, __loc); }
158
159inline _LIBCPP_HIDE_FROM_ABI int __iswxdigit(wint_t __c, __locale_t __loc) { return iswxdigit_l(__c, __loc); }
160
161inline _LIBCPP_HIDE_FROM_ABI wint_t __towupper(wint_t __c, __locale_t __loc) { return towupper_l(__c, __loc); }
162
163inline _LIBCPP_HIDE_FROM_ABI wint_t __towlower(wint_t __c, __locale_t __loc) { return towlower_l(__c, __loc); }
164
165inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __ws1, const wchar_t* __ws2, __locale_t __loc) {
166 return wcscoll_l(__ws1, __ws2, __loc);
167}
168
169inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) {
170 return wcsxfrm_l(__dest, __src, __n, __loc);
171}
172# endif // _LIBCPP_HAS_WIDE_CHARACTERS
173
174inline _LIBCPP_HIDE_FROM_ABI size_t
175__strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t __loc) {
176 return strftime_l(__s, __max, __format, __tm, __loc);
177}
178
179//
180// Other functions
181//
182inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __mb_len_max(__locale_t __loc) {
183 __locale_guard __current(__loc);
184 return MB_CUR_MAX;
185}
186
187# if _LIBCPP_HAS_WIDE_CHARACTERS
188inline _LIBCPP_HIDE_FROM_ABI wint_t __btowc(int __c, __locale_t __loc) {
189 __locale_guard __current(__loc);
190 return std::btowc(__c);
191}
192
193inline _LIBCPP_HIDE_FROM_ABI int __wctob(wint_t __c, __locale_t __loc) {
194 __locale_guard __current(__loc);
195 return std::wctob(__c);
196}
197
198inline _LIBCPP_HIDE_FROM_ABI size_t
199__wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t __loc) {
200 __locale_guard __current(__loc);
201 return ::wcsnrtombs(__dest, __src, __nwc, __len, __ps); // non-standard
202}
203
204inline _LIBCPP_HIDE_FROM_ABI size_t __wcrtomb(char* __s, wchar_t __wc, mbstate_t* __ps, __locale_t __loc) {
205 __locale_guard __current(__loc);
206 return std::wcrtomb(__s, __wc, __ps);
207}
208
209inline _LIBCPP_HIDE_FROM_ABI size_t
210__mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t __loc) {
211 __locale_guard __current(__loc);
212 return ::mbsnrtowcs(__dest, __src, __nms, __len, __ps); // non-standard
213}
214
215inline _LIBCPP_HIDE_FROM_ABI size_t
216__mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
217 __locale_guard __current(__loc);
218 return std::mbrtowc(__pwc, __s, __n, __ps);
219}
220
221inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) {
222 __locale_guard __current(__loc);
223 return std::mbtowc(__pwc, __pmb, __max);
224}
225
226inline _LIBCPP_HIDE_FROM_ABI size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
227 __locale_guard __current(__loc);
228 return std::mbrlen(__s, __n, __ps);
229}
230
231inline _LIBCPP_HIDE_FROM_ABI size_t
232__mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) {
233 __locale_guard __current(__loc);
234 return std::mbsrtowcs(__dest, __src, __len, __ps);
235}
236# endif // _LIBCPP_HAS_WIDE_CHARACTERS
237#endif // _LIBCPP_BUILDING_LIBRARY
238
239#ifndef _LIBCPP_COMPILER_GCC // GCC complains that this can't be always_inline due to C-style varargs
240_LIBCPP_HIDE_FROM_ABI
241#endif
242inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf(
243 char* __s, size_t __n, __locale_t __loc, const char* __format, ...) {
244 va_list __va;
245 va_start(__va, __format);
246 __locale_guard __current(__loc);
247 int __res = std::vsnprintf(__s, __n, __format, __va);
248 va_end(__va);
249 return __res;
250}
251
252#ifndef _LIBCPP_COMPILER_GCC // GCC complains that this can't be always_inline due to C-style varargs
253_LIBCPP_HIDE_FROM_ABI
254#endif
255inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf(
256 char** __s, __locale_t __loc, const char* __format, ...) {
257 va_list __va;
258 va_start(__va, __format);
259 __locale_guard __current(__loc);
260 int __res = ::vasprintf(__s, __format, __va); // non-standard
261 va_end(__va);
262 return __res;
263}
264
265#ifndef _LIBCPP_COMPILER_GCC // GCC complains that this can't be always_inline due to C-style varargs
266_LIBCPP_HIDE_FROM_ABI
267#endif
268inline _LIBCPP_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf(
269 const char* __s, __locale_t __loc, const char* __format, ...) {
270 va_list __va;
271 va_start(__va, __format);
272 __locale_guard __current(__loc);
273 int __res = std::vsscanf(__s, __format, __va);
274 va_end(__va);
275 return __res;
276}
277
278} // namespace __locale
279_LIBCPP_END_NAMESPACE_STD
280
281#endif // _LIBCPP___LOCALE_DIR_SUPPORT_LINUX_H
lib/libcxx/include/__locale_dir/support/netbsd.h+2
......@@ -6,6 +6,8 @@
66//
77//===----------------------------------------------------------------------===//
88
9/* zig patch: https://github.com/llvm/llvm-project/pull/143055 */
10
911#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_NETBSD_H
1012#define _LIBCPP___LOCALE_DIR_SUPPORT_NETBSD_H
1113
lib/libcxx/include/__locale_dir/support/no_locale/characters.h-6
......@@ -29,12 +29,6 @@ namespace __locale {
2929//
3030// Character manipulation functions
3131//
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
3832inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t) { return std::isdigit(__c); }
3933
4034inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t) { return std::isxdigit(__c); }
lib/libcxx/include/__locale_dir/support/windows.h+2-8
......@@ -29,7 +29,7 @@
2929_LIBCPP_BEGIN_NAMESPACE_STD
3030namespace __locale {
3131
32using __lconv_t = std::lconv;
32using __lconv_t _LIBCPP_NODEBUG = std::lconv;
3333
3434class __lconv_storage {
3535public:
......@@ -197,12 +197,6 @@ __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
197197//
198198// Character manipulation functions
199199//
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
206200inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t __loc) { return _isdigit_l(__c, __loc); }
207201
208202inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t __loc) { return _isxdigit_l(__c, __loc); }
......@@ -317,7 +311,7 @@ struct __locale_guard {
317311 if (std::strcmp(__l.__get_locale(), __lc) != 0) {
318312 __locale_all = _strdup(__lc);
319313 if (__locale_all == nullptr)
320 __throw_bad_alloc();
314 std::__throw_bad_alloc();
321315 __locale::__setlocale(LC_ALL, __l.__get_locale());
322316 }
323317 }
lib/libcxx/include/__locale_dir/time.h created+766
......@@ -0,0 +1,766 @@
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_TIME_H
10#define _LIBCPP___LOCALE_DIR_TIME_H
11
12#include <__algorithm/copy.h>
13#include <__config>
14#include <__locale_dir/get_c_locale.h>
15#include <__locale_dir/scan_keyword.h>
16#include <ios>
17
18#if _LIBCPP_HAS_LOCALIZATION
19
20# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21# pragma GCC system_header
22# endif
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26template <class _CharT, class _InputIterator>
27_LIBCPP_HIDE_FROM_ABI int __get_up_to_n_digits(
28 _InputIterator& __b, _InputIterator __e, ios_base::iostate& __err, const ctype<_CharT>& __ct, int __n) {
29 // Precondition: __n >= 1
30 if (__b == __e) {
31 __err |= ios_base::eofbit | ios_base::failbit;
32 return 0;
33 }
34 // get first digit
35 _CharT __c = *__b;
36 if (!__ct.is(ctype_base::digit, __c)) {
37 __err |= ios_base::failbit;
38 return 0;
39 }
40 int __r = __ct.narrow(__c, 0) - '0';
41 for (++__b, (void)--__n; __b != __e && __n > 0; ++__b, (void)--__n) {
42 // get next digit
43 __c = *__b;
44 if (!__ct.is(ctype_base::digit, __c))
45 return __r;
46 __r = __r * 10 + __ct.narrow(__c, 0) - '0';
47 }
48 if (__b == __e)
49 __err |= ios_base::eofbit;
50 return __r;
51}
52
53class _LIBCPP_EXPORTED_FROM_ABI time_base {
54public:
55 enum dateorder { no_order, dmy, mdy, ymd, ydm };
56};
57
58template <class _CharT>
59class __time_get_c_storage {
60protected:
61 typedef basic_string<_CharT> string_type;
62
63 virtual const string_type* __weeks() const;
64 virtual const string_type* __months() const;
65 virtual const string_type* __am_pm() const;
66 virtual const string_type& __c() const;
67 virtual const string_type& __r() const;
68 virtual const string_type& __x() const;
69 virtual const string_type& __X() const;
70
71 _LIBCPP_HIDE_FROM_ABI ~__time_get_c_storage() {}
72};
73
74template <>
75_LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__weeks() const;
76template <>
77_LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__months() const;
78template <>
79_LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__am_pm() const;
80template <>
81_LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__c() const;
82template <>
83_LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__r() const;
84template <>
85_LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__x() const;
86template <>
87_LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__X() const;
88
89# if _LIBCPP_HAS_WIDE_CHARACTERS
90template <>
91_LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__weeks() const;
92template <>
93_LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__months() const;
94template <>
95_LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__am_pm() const;
96template <>
97_LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__c() const;
98template <>
99_LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__r() const;
100template <>
101_LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__x() const;
102template <>
103_LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__X() const;
104# endif
105
106template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
107class time_get : public locale::facet, public time_base, private __time_get_c_storage<_CharT> {
108public:
109 typedef _CharT char_type;
110 typedef _InputIterator iter_type;
111 typedef time_base::dateorder dateorder;
112 typedef basic_string<char_type> string_type;
113
114 _LIBCPP_HIDE_FROM_ABI explicit time_get(size_t __refs = 0) : locale::facet(__refs) {}
115
116 _LIBCPP_HIDE_FROM_ABI dateorder date_order() const { return this->do_date_order(); }
117
118 _LIBCPP_HIDE_FROM_ABI iter_type
119 get_time(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
120 return do_get_time(__b, __e, __iob, __err, __tm);
121 }
122
123 _LIBCPP_HIDE_FROM_ABI iter_type
124 get_date(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
125 return do_get_date(__b, __e, __iob, __err, __tm);
126 }
127
128 _LIBCPP_HIDE_FROM_ABI iter_type
129 get_weekday(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
130 return do_get_weekday(__b, __e, __iob, __err, __tm);
131 }
132
133 _LIBCPP_HIDE_FROM_ABI iter_type
134 get_monthname(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
135 return do_get_monthname(__b, __e, __iob, __err, __tm);
136 }
137
138 _LIBCPP_HIDE_FROM_ABI iter_type
139 get_year(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
140 return do_get_year(__b, __e, __iob, __err, __tm);
141 }
142
143 _LIBCPP_HIDE_FROM_ABI iter_type
144 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, char __fmt, char __mod = 0)
145 const {
146 return do_get(__b, __e, __iob, __err, __tm, __fmt, __mod);
147 }
148
149 iter_type
150 get(iter_type __b,
151 iter_type __e,
152 ios_base& __iob,
153 ios_base::iostate& __err,
154 tm* __tm,
155 const char_type* __fmtb,
156 const char_type* __fmte) const;
157
158 static locale::id id;
159
160protected:
161 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_get() override {}
162
163 virtual dateorder do_date_order() const;
164 virtual iter_type
165 do_get_time(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;
166 virtual iter_type
167 do_get_date(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;
168 virtual iter_type
169 do_get_weekday(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;
170 virtual iter_type
171 do_get_monthname(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;
172 virtual iter_type
173 do_get_year(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;
174 virtual iter_type do_get(
175 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, char __fmt, char __mod) const;
176
177private:
178 void __get_white_space(iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
179 void __get_percent(iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
180
181 void __get_weekdayname(
182 int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
183 void __get_monthname(
184 int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
185 void __get_day(int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
186 void
187 __get_month(int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
188 void
189 __get_year(int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
190 void
191 __get_year4(int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
192 void
193 __get_hour(int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
194 void
195 __get_12_hour(int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
196 void
197 __get_am_pm(int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
198 void
199 __get_minute(int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
200 void
201 __get_second(int& __s, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
202 void
203 __get_weekday(int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
204 void __get_day_year_num(
205 int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
206};
207
208template <class _CharT, class _InputIterator>
209locale::id time_get<_CharT, _InputIterator>::id;
210
211// time_get primitives
212
213template <class _CharT, class _InputIterator>
214void time_get<_CharT, _InputIterator>::__get_weekdayname(
215 int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
216 // Note: ignoring case comes from the POSIX strptime spec
217 const string_type* __wk = this->__weeks();
218 ptrdiff_t __i = std::__scan_keyword(__b, __e, __wk, __wk + 14, __ct, __err, false) - __wk;
219 if (__i < 14)
220 __w = __i % 7;
221}
222
223template <class _CharT, class _InputIterator>
224void time_get<_CharT, _InputIterator>::__get_monthname(
225 int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
226 // Note: ignoring case comes from the POSIX strptime spec
227 const string_type* __month = this->__months();
228 ptrdiff_t __i = std::__scan_keyword(__b, __e, __month, __month + 24, __ct, __err, false) - __month;
229 if (__i < 24)
230 __m = __i % 12;
231}
232
233template <class _CharT, class _InputIterator>
234void time_get<_CharT, _InputIterator>::__get_day(
235 int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
236 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
237 if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 31)
238 __d = __t;
239 else
240 __err |= ios_base::failbit;
241}
242
243template <class _CharT, class _InputIterator>
244void time_get<_CharT, _InputIterator>::__get_month(
245 int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
246 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2) - 1;
247 if (!(__err & ios_base::failbit) && 0 <= __t && __t <= 11)
248 __m = __t;
249 else
250 __err |= ios_base::failbit;
251}
252
253template <class _CharT, class _InputIterator>
254void time_get<_CharT, _InputIterator>::__get_year(
255 int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
256 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 4);
257 if (!(__err & ios_base::failbit)) {
258 if (__t < 69)
259 __t += 2000;
260 else if (69 <= __t && __t <= 99)
261 __t += 1900;
262 __y = __t - 1900;
263 }
264}
265
266template <class _CharT, class _InputIterator>
267void time_get<_CharT, _InputIterator>::__get_year4(
268 int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
269 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 4);
270 if (!(__err & ios_base::failbit))
271 __y = __t - 1900;
272}
273
274template <class _CharT, class _InputIterator>
275void time_get<_CharT, _InputIterator>::__get_hour(
276 int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
277 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
278 if (!(__err & ios_base::failbit) && __t <= 23)
279 __h = __t;
280 else
281 __err |= ios_base::failbit;
282}
283
284template <class _CharT, class _InputIterator>
285void time_get<_CharT, _InputIterator>::__get_12_hour(
286 int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
287 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
288 if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 12)
289 __h = __t;
290 else
291 __err |= ios_base::failbit;
292}
293
294template <class _CharT, class _InputIterator>
295void time_get<_CharT, _InputIterator>::__get_minute(
296 int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
297 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
298 if (!(__err & ios_base::failbit) && __t <= 59)
299 __m = __t;
300 else
301 __err |= ios_base::failbit;
302}
303
304template <class _CharT, class _InputIterator>
305void time_get<_CharT, _InputIterator>::__get_second(
306 int& __s, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
307 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
308 if (!(__err & ios_base::failbit) && __t <= 60)
309 __s = __t;
310 else
311 __err |= ios_base::failbit;
312}
313
314template <class _CharT, class _InputIterator>
315void time_get<_CharT, _InputIterator>::__get_weekday(
316 int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
317 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 1);
318 if (!(__err & ios_base::failbit) && __t <= 6)
319 __w = __t;
320 else
321 __err |= ios_base::failbit;
322}
323
324template <class _CharT, class _InputIterator>
325void time_get<_CharT, _InputIterator>::__get_day_year_num(
326 int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
327 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 3);
328 if (!(__err & ios_base::failbit) && __t <= 365)
329 __d = __t;
330 else
331 __err |= ios_base::failbit;
332}
333
334template <class _CharT, class _InputIterator>
335void time_get<_CharT, _InputIterator>::__get_white_space(
336 iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
337 for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b)
338 ;
339 if (__b == __e)
340 __err |= ios_base::eofbit;
341}
342
343template <class _CharT, class _InputIterator>
344void time_get<_CharT, _InputIterator>::__get_am_pm(
345 int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
346 const string_type* __ap = this->__am_pm();
347 if (__ap[0].size() + __ap[1].size() == 0) {
348 __err |= ios_base::failbit;
349 return;
350 }
351 ptrdiff_t __i = std::__scan_keyword(__b, __e, __ap, __ap + 2, __ct, __err, false) - __ap;
352 if (__i == 0 && __h == 12)
353 __h = 0;
354 else if (__i == 1 && __h < 12)
355 __h += 12;
356}
357
358template <class _CharT, class _InputIterator>
359void time_get<_CharT, _InputIterator>::__get_percent(
360 iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
361 if (__b == __e) {
362 __err |= ios_base::eofbit | ios_base::failbit;
363 return;
364 }
365 if (__ct.narrow(*__b, 0) != '%')
366 __err |= ios_base::failbit;
367 else if (++__b == __e)
368 __err |= ios_base::eofbit;
369}
370
371// time_get end primitives
372
373template <class _CharT, class _InputIterator>
374_InputIterator time_get<_CharT, _InputIterator>::get(
375 iter_type __b,
376 iter_type __e,
377 ios_base& __iob,
378 ios_base::iostate& __err,
379 tm* __tm,
380 const char_type* __fmtb,
381 const char_type* __fmte) const {
382 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
383 __err = ios_base::goodbit;
384 while (__fmtb != __fmte && __err == ios_base::goodbit) {
385 if (__b == __e) {
386 __err = ios_base::failbit;
387 break;
388 }
389 if (__ct.narrow(*__fmtb, 0) == '%') {
390 if (++__fmtb == __fmte) {
391 __err = ios_base::failbit;
392 break;
393 }
394 char __cmd = __ct.narrow(*__fmtb, 0);
395 char __opt = '\0';
396 if (__cmd == 'E' || __cmd == '0') {
397 if (++__fmtb == __fmte) {
398 __err = ios_base::failbit;
399 break;
400 }
401 __opt = __cmd;
402 __cmd = __ct.narrow(*__fmtb, 0);
403 }
404 __b = do_get(__b, __e, __iob, __err, __tm, __cmd, __opt);
405 ++__fmtb;
406 } else if (__ct.is(ctype_base::space, *__fmtb)) {
407 for (++__fmtb; __fmtb != __fmte && __ct.is(ctype_base::space, *__fmtb); ++__fmtb)
408 ;
409 for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b)
410 ;
411 } else if (__ct.toupper(*__b) == __ct.toupper(*__fmtb)) {
412 ++__b;
413 ++__fmtb;
414 } else
415 __err = ios_base::failbit;
416 }
417 if (__b == __e)
418 __err |= ios_base::eofbit;
419 return __b;
420}
421
422template <class _CharT, class _InputIterator>
423typename time_get<_CharT, _InputIterator>::dateorder time_get<_CharT, _InputIterator>::do_date_order() const {
424 return mdy;
425}
426
427template <class _CharT, class _InputIterator>
428_InputIterator time_get<_CharT, _InputIterator>::do_get_time(
429 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
430 const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
431 return get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt) / sizeof(__fmt[0]));
432}
433
434template <class _CharT, class _InputIterator>
435_InputIterator time_get<_CharT, _InputIterator>::do_get_date(
436 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
437 const string_type& __fmt = this->__x();
438 return get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size());
439}
440
441template <class _CharT, class _InputIterator>
442_InputIterator time_get<_CharT, _InputIterator>::do_get_weekday(
443 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
444 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
445 __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);
446 return __b;
447}
448
449template <class _CharT, class _InputIterator>
450_InputIterator time_get<_CharT, _InputIterator>::do_get_monthname(
451 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
452 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
453 __get_monthname(__tm->tm_mon, __b, __e, __err, __ct);
454 return __b;
455}
456
457template <class _CharT, class _InputIterator>
458_InputIterator time_get<_CharT, _InputIterator>::do_get_year(
459 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
460 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
461 __get_year(__tm->tm_year, __b, __e, __err, __ct);
462 return __b;
463}
464
465template <class _CharT, class _InputIterator>
466_InputIterator time_get<_CharT, _InputIterator>::do_get(
467 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, char __fmt, char) const {
468 __err = ios_base::goodbit;
469 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
470 switch (__fmt) {
471 case 'a':
472 case 'A':
473 __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);
474 break;
475 case 'b':
476 case 'B':
477 case 'h':
478 __get_monthname(__tm->tm_mon, __b, __e, __err, __ct);
479 break;
480 case 'c': {
481 const string_type& __fm = this->__c();
482 __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());
483 } break;
484 case 'd':
485 case 'e':
486 __get_day(__tm->tm_mday, __b, __e, __err, __ct);
487 break;
488 case 'D': {
489 const char_type __fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};
490 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));
491 } break;
492 case 'F': {
493 const char_type __fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'};
494 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));
495 } break;
496 case 'H':
497 __get_hour(__tm->tm_hour, __b, __e, __err, __ct);
498 break;
499 case 'I':
500 __get_12_hour(__tm->tm_hour, __b, __e, __err, __ct);
501 break;
502 case 'j':
503 __get_day_year_num(__tm->tm_yday, __b, __e, __err, __ct);
504 break;
505 case 'm':
506 __get_month(__tm->tm_mon, __b, __e, __err, __ct);
507 break;
508 case 'M':
509 __get_minute(__tm->tm_min, __b, __e, __err, __ct);
510 break;
511 case 'n':
512 case 't':
513 __get_white_space(__b, __e, __err, __ct);
514 break;
515 case 'p':
516 __get_am_pm(__tm->tm_hour, __b, __e, __err, __ct);
517 break;
518 case 'r': {
519 const char_type __fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};
520 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));
521 } break;
522 case 'R': {
523 const char_type __fm[] = {'%', 'H', ':', '%', 'M'};
524 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));
525 } break;
526 case 'S':
527 __get_second(__tm->tm_sec, __b, __e, __err, __ct);
528 break;
529 case 'T': {
530 const char_type __fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
531 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));
532 } break;
533 case 'w':
534 __get_weekday(__tm->tm_wday, __b, __e, __err, __ct);
535 break;
536 case 'x':
537 return do_get_date(__b, __e, __iob, __err, __tm);
538 case 'X': {
539 const string_type& __fm = this->__X();
540 __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());
541 } break;
542 case 'y':
543 __get_year(__tm->tm_year, __b, __e, __err, __ct);
544 break;
545 case 'Y':
546 __get_year4(__tm->tm_year, __b, __e, __err, __ct);
547 break;
548 case '%':
549 __get_percent(__b, __e, __err, __ct);
550 break;
551 default:
552 __err |= ios_base::failbit;
553 }
554 return __b;
555}
556
557extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<char>;
558# if _LIBCPP_HAS_WIDE_CHARACTERS
559extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<wchar_t>;
560# endif
561
562class _LIBCPP_EXPORTED_FROM_ABI __time_get {
563protected:
564 __locale::__locale_t __loc_;
565
566 __time_get(const char* __nm);
567 __time_get(const string& __nm);
568 ~__time_get();
569};
570
571template <class _CharT>
572class __time_get_storage : public __time_get {
573protected:
574 typedef basic_string<_CharT> string_type;
575
576 string_type __weeks_[14];
577 string_type __months_[24];
578 string_type __am_pm_[2];
579 string_type __c_;
580 string_type __r_;
581 string_type __x_;
582 string_type __X_;
583
584 explicit __time_get_storage(const char* __nm);
585 explicit __time_get_storage(const string& __nm);
586
587 _LIBCPP_HIDE_FROM_ABI ~__time_get_storage() {}
588
589 time_base::dateorder __do_date_order() const;
590
591private:
592 void init(const ctype<_CharT>&);
593 string_type __analyze(char __fmt, const ctype<_CharT>&);
594};
595
596# define _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(_CharT) \
597 template <> \
598 _LIBCPP_EXPORTED_FROM_ABI time_base::dateorder __time_get_storage<_CharT>::__do_date_order() const; \
599 template <> \
600 _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const char*); \
601 template <> \
602 _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const string&); \
603 template <> \
604 _LIBCPP_EXPORTED_FROM_ABI void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \
605 template <> \
606 _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::string_type __time_get_storage<_CharT>::__analyze( \
607 char, const ctype<_CharT>&); \
608 extern template _LIBCPP_EXPORTED_FROM_ABI time_base::dateorder __time_get_storage<_CharT>::__do_date_order() \
609 const; \
610 extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const char*); \
611 extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const string&); \
612 extern template _LIBCPP_EXPORTED_FROM_ABI void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \
613 extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::string_type \
614 __time_get_storage<_CharT>::__analyze(char, const ctype<_CharT>&);
615
616_LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(char)
617# if _LIBCPP_HAS_WIDE_CHARACTERS
618_LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(wchar_t)
619# endif
620# undef _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION
621
622template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
623class time_get_byname : public time_get<_CharT, _InputIterator>, private __time_get_storage<_CharT> {
624public:
625 typedef time_base::dateorder dateorder;
626 typedef _InputIterator iter_type;
627 typedef _CharT char_type;
628 typedef basic_string<char_type> string_type;
629
630 _LIBCPP_HIDE_FROM_ABI explicit time_get_byname(const char* __nm, size_t __refs = 0)
631 : time_get<_CharT, _InputIterator>(__refs), __time_get_storage<_CharT>(__nm) {}
632 _LIBCPP_HIDE_FROM_ABI explicit time_get_byname(const string& __nm, size_t __refs = 0)
633 : time_get<_CharT, _InputIterator>(__refs), __time_get_storage<_CharT>(__nm) {}
634
635protected:
636 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_get_byname() override {}
637
638 _LIBCPP_HIDE_FROM_ABI_VIRTUAL dateorder do_date_order() const override { return this->__do_date_order(); }
639
640private:
641 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __weeks() const override { return this->__weeks_; }
642 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __months() const override { return this->__months_; }
643 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __am_pm() const override { return this->__am_pm_; }
644 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __c() const override { return this->__c_; }
645 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __r() const override { return this->__r_; }
646 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __x() const override { return this->__x_; }
647 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __X() const override { return this->__X_; }
648};
649
650extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<char>;
651# if _LIBCPP_HAS_WIDE_CHARACTERS
652extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<wchar_t>;
653# endif
654
655class _LIBCPP_EXPORTED_FROM_ABI __time_put {
656 __locale::__locale_t __loc_;
657
658protected:
659 _LIBCPP_HIDE_FROM_ABI __time_put() : __loc_(_LIBCPP_GET_C_LOCALE) {}
660 __time_put(const char* __nm);
661 __time_put(const string& __nm);
662 ~__time_put();
663 void __do_put(char* __nb, char*& __ne, const tm* __tm, char __fmt, char __mod) const;
664# if _LIBCPP_HAS_WIDE_CHARACTERS
665 void __do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm, char __fmt, char __mod) const;
666# endif
667};
668
669template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
670class time_put : public locale::facet, private __time_put {
671public:
672 typedef _CharT char_type;
673 typedef _OutputIterator iter_type;
674
675 _LIBCPP_HIDE_FROM_ABI explicit time_put(size_t __refs = 0) : locale::facet(__refs) {}
676
677 iter_type
678 put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, const char_type* __pb, const char_type* __pe)
679 const;
680
681 _LIBCPP_HIDE_FROM_ABI iter_type
682 put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, char __fmt, char __mod = 0) const {
683 return do_put(__s, __iob, __fl, __tm, __fmt, __mod);
684 }
685
686 static locale::id id;
687
688protected:
689 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_put() override {}
690 virtual iter_type do_put(iter_type __s, ios_base&, char_type, const tm* __tm, char __fmt, char __mod) const;
691
692 _LIBCPP_HIDE_FROM_ABI explicit time_put(const char* __nm, size_t __refs) : locale::facet(__refs), __time_put(__nm) {}
693 _LIBCPP_HIDE_FROM_ABI explicit time_put(const string& __nm, size_t __refs)
694 : locale::facet(__refs), __time_put(__nm) {}
695};
696
697template <class _CharT, class _OutputIterator>
698locale::id time_put<_CharT, _OutputIterator>::id;
699
700template <class _CharT, class _OutputIterator>
701_OutputIterator time_put<_CharT, _OutputIterator>::put(
702 iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, const char_type* __pb, const char_type* __pe)
703 const {
704 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
705 for (; __pb != __pe; ++__pb) {
706 if (__ct.narrow(*__pb, 0) == '%') {
707 if (++__pb == __pe) {
708 *__s++ = __pb[-1];
709 break;
710 }
711 char __mod = 0;
712 char __fmt = __ct.narrow(*__pb, 0);
713 if (__fmt == 'E' || __fmt == 'O') {
714 if (++__pb == __pe) {
715 *__s++ = __pb[-2];
716 *__s++ = __pb[-1];
717 break;
718 }
719 __mod = __fmt;
720 __fmt = __ct.narrow(*__pb, 0);
721 }
722 __s = do_put(__s, __iob, __fl, __tm, __fmt, __mod);
723 } else
724 *__s++ = *__pb;
725 }
726 return __s;
727}
728
729template <class _CharT, class _OutputIterator>
730_OutputIterator time_put<_CharT, _OutputIterator>::do_put(
731 iter_type __s, ios_base&, char_type, const tm* __tm, char __fmt, char __mod) const {
732 char_type __nar[100];
733 char_type* __nb = __nar;
734 char_type* __ne = __nb + 100;
735 __do_put(__nb, __ne, __tm, __fmt, __mod);
736 return std::copy(__nb, __ne, __s);
737}
738
739extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<char>;
740# if _LIBCPP_HAS_WIDE_CHARACTERS
741extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<wchar_t>;
742# endif
743
744template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
745class time_put_byname : public time_put<_CharT, _OutputIterator> {
746public:
747 _LIBCPP_HIDE_FROM_ABI explicit time_put_byname(const char* __nm, size_t __refs = 0)
748 : time_put<_CharT, _OutputIterator>(__nm, __refs) {}
749
750 _LIBCPP_HIDE_FROM_ABI explicit time_put_byname(const string& __nm, size_t __refs = 0)
751 : time_put<_CharT, _OutputIterator>(__nm, __refs) {}
752
753protected:
754 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_put_byname() override {}
755};
756
757extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<char>;
758# if _LIBCPP_HAS_WIDE_CHARACTERS
759extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<wchar_t>;
760# endif
761
762_LIBCPP_END_NAMESPACE_STD
763
764#endif // _LIBCPP_HAS_LOCALIZATION
765
766#endif // _LIBCPP___LOCALE_DIR_TIME_H
lib/libcxx/include/__locale_dir/wbuffer_convert.h created+430
......@@ -0,0 +1,430 @@
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_WBUFFER_CONVERT_H
10#define _LIBCPP___LOCALE_DIR_WBUFFER_CONVERT_H
11
12#include <__algorithm/reverse.h>
13#include <__config>
14#include <__string/char_traits.h>
15#include <ios>
16#include <streambuf>
17
18#if _LIBCPP_HAS_LOCALIZATION
19
20# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21# pragma GCC system_header
22# endif
23
24# if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT)
25
26_LIBCPP_PUSH_MACROS
27# include <__undef_macros>
28
29_LIBCPP_BEGIN_NAMESPACE_STD
30
31template <class _Codecvt, class _Elem = wchar_t, class _Tr = char_traits<_Elem> >
32class _LIBCPP_DEPRECATED_IN_CXX17 wbuffer_convert : public basic_streambuf<_Elem, _Tr> {
33public:
34 // types:
35 typedef _Elem char_type;
36 typedef _Tr traits_type;
37 typedef typename traits_type::int_type int_type;
38 typedef typename traits_type::pos_type pos_type;
39 typedef typename traits_type::off_type off_type;
40 typedef typename _Codecvt::state_type state_type;
41
42private:
43 char* __extbuf_;
44 const char* __extbufnext_;
45 const char* __extbufend_;
46 char __extbuf_min_[8];
47 size_t __ebs_;
48 char_type* __intbuf_;
49 size_t __ibs_;
50 streambuf* __bufptr_;
51 _Codecvt* __cv_;
52 state_type __st_;
53 ios_base::openmode __cm_;
54 bool __owns_eb_;
55 bool __owns_ib_;
56 bool __always_noconv_;
57
58public:
59# ifndef _LIBCPP_CXX03_LANG
60 _LIBCPP_HIDE_FROM_ABI wbuffer_convert() : wbuffer_convert(nullptr) {}
61 explicit _LIBCPP_HIDE_FROM_ABI
62 wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt = new _Codecvt, state_type __state = state_type());
63# else
64 _LIBCPP_EXPLICIT_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
65 wbuffer_convert(streambuf* __bytebuf = nullptr, _Codecvt* __pcvt = new _Codecvt, state_type __state = state_type());
66# endif
67
68 _LIBCPP_HIDE_FROM_ABI ~wbuffer_convert();
69
70 _LIBCPP_HIDE_FROM_ABI streambuf* rdbuf() const { return __bufptr_; }
71 _LIBCPP_HIDE_FROM_ABI streambuf* rdbuf(streambuf* __bytebuf) {
72 streambuf* __r = __bufptr_;
73 __bufptr_ = __bytebuf;
74 return __r;
75 }
76
77 wbuffer_convert(const wbuffer_convert&) = delete;
78 wbuffer_convert& operator=(const wbuffer_convert&) = delete;
79
80 _LIBCPP_HIDE_FROM_ABI state_type state() const { return __st_; }
81
82protected:
83 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int_type underflow();
84 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int_type pbackfail(int_type __c = traits_type::eof());
85 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int_type overflow(int_type __c = traits_type::eof());
86 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* __s, streamsize __n);
87 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual pos_type
88 seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __wch = ios_base::in | ios_base::out);
89 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual pos_type
90 seekpos(pos_type __sp, ios_base::openmode __wch = ios_base::in | ios_base::out);
91 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int sync();
92
93private:
94 _LIBCPP_HIDE_FROM_ABI_VIRTUAL bool __read_mode();
95 _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __write_mode();
96 _LIBCPP_HIDE_FROM_ABI_VIRTUAL wbuffer_convert* __close();
97};
98
99_LIBCPP_SUPPRESS_DEPRECATED_PUSH
100template <class _Codecvt, class _Elem, class _Tr>
101wbuffer_convert<_Codecvt, _Elem, _Tr>::wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt, state_type __state)
102 : __extbuf_(nullptr),
103 __extbufnext_(nullptr),
104 __extbufend_(nullptr),
105 __ebs_(0),
106 __intbuf_(0),
107 __ibs_(0),
108 __bufptr_(__bytebuf),
109 __cv_(__pcvt),
110 __st_(__state),
111 __cm_(0),
112 __owns_eb_(false),
113 __owns_ib_(false),
114 __always_noconv_(__cv_ ? __cv_->always_noconv() : false) {
115 setbuf(0, 4096);
116}
117
118template <class _Codecvt, class _Elem, class _Tr>
119wbuffer_convert<_Codecvt, _Elem, _Tr>::~wbuffer_convert() {
120 __close();
121 delete __cv_;
122 if (__owns_eb_)
123 delete[] __extbuf_;
124 if (__owns_ib_)
125 delete[] __intbuf_;
126}
127
128template <class _Codecvt, class _Elem, class _Tr>
129typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type wbuffer_convert<_Codecvt, _Elem, _Tr>::underflow() {
130 _LIBCPP_SUPPRESS_DEPRECATED_POP
131 if (__cv_ == 0 || __bufptr_ == nullptr)
132 return traits_type::eof();
133 bool __initial = __read_mode();
134 char_type __1buf;
135 if (this->gptr() == 0)
136 this->setg(std::addressof(__1buf), std::addressof(__1buf) + 1, std::addressof(__1buf) + 1);
137 const size_t __unget_sz = __initial ? 0 : std::min<size_t>((this->egptr() - this->eback()) / 2, 4);
138 int_type __c = traits_type::eof();
139 if (this->gptr() == this->egptr()) {
140 std::memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type));
141 if (__always_noconv_) {
142 streamsize __nmemb = static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz);
143 __nmemb = __bufptr_->sgetn((char*)this->eback() + __unget_sz, __nmemb);
144 if (__nmemb != 0) {
145 this->setg(this->eback(), this->eback() + __unget_sz, this->eback() + __unget_sz + __nmemb);
146 __c = *this->gptr();
147 }
148 } else {
149 if (__extbufend_ != __extbufnext_) {
150 _LIBCPP_ASSERT_NON_NULL(__extbufnext_ != nullptr, "underflow moving from nullptr");
151 _LIBCPP_ASSERT_NON_NULL(__extbuf_ != nullptr, "underflow moving into nullptr");
152 std::memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_);
153 }
154 __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_);
155 __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_);
156 streamsize __nmemb = std::min(static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz),
157 static_cast<streamsize>(__extbufend_ - __extbufnext_));
158 codecvt_base::result __r;
159 // FIXME: Do we ever need to restore the state here?
160 // state_type __svs = __st_;
161 streamsize __nr = __bufptr_->sgetn(const_cast<char*>(__extbufnext_), __nmemb);
162 if (__nr != 0) {
163 __extbufend_ = __extbufnext_ + __nr;
164 char_type* __inext;
165 __r = __cv_->in(
166 __st_, __extbuf_, __extbufend_, __extbufnext_, this->eback() + __unget_sz, this->egptr(), __inext);
167 if (__r == codecvt_base::noconv) {
168 this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)const_cast<char*>(__extbufend_));
169 __c = *this->gptr();
170 } else if (__inext != this->eback() + __unget_sz) {
171 this->setg(this->eback(), this->eback() + __unget_sz, __inext);
172 __c = *this->gptr();
173 }
174 }
175 }
176 } else
177 __c = *this->gptr();
178 if (this->eback() == std::addressof(__1buf))
179 this->setg(0, 0, 0);
180 return __c;
181}
182
183_LIBCPP_SUPPRESS_DEPRECATED_PUSH
184template <class _Codecvt, class _Elem, class _Tr>
185typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type
186wbuffer_convert<_Codecvt, _Elem, _Tr>::pbackfail(int_type __c) {
187 _LIBCPP_SUPPRESS_DEPRECATED_POP
188 if (__cv_ != 0 && __bufptr_ && this->eback() < this->gptr()) {
189 if (traits_type::eq_int_type(__c, traits_type::eof())) {
190 this->gbump(-1);
191 return traits_type::not_eof(__c);
192 }
193 if (traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) {
194 this->gbump(-1);
195 *this->gptr() = traits_type::to_char_type(__c);
196 return __c;
197 }
198 }
199 return traits_type::eof();
200}
201
202_LIBCPP_SUPPRESS_DEPRECATED_PUSH
203template <class _Codecvt, class _Elem, class _Tr>
204typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type wbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c) {
205 _LIBCPP_SUPPRESS_DEPRECATED_POP
206 if (__cv_ == 0 || !__bufptr_)
207 return traits_type::eof();
208 __write_mode();
209 char_type __1buf;
210 char_type* __pb_save = this->pbase();
211 char_type* __epb_save = this->epptr();
212 if (!traits_type::eq_int_type(__c, traits_type::eof())) {
213 if (this->pptr() == 0)
214 this->setp(std::addressof(__1buf), std::addressof(__1buf) + 1);
215 *this->pptr() = traits_type::to_char_type(__c);
216 this->pbump(1);
217 }
218 if (this->pptr() != this->pbase()) {
219 if (__always_noconv_) {
220 streamsize __nmemb = static_cast<streamsize>(this->pptr() - this->pbase());
221 if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb)
222 return traits_type::eof();
223 } else {
224 char* __extbe = __extbuf_;
225 codecvt_base::result __r;
226 do {
227 const char_type* __e;
228 __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, __extbuf_, __extbuf_ + __ebs_, __extbe);
229 if (__e == this->pbase())
230 return traits_type::eof();
231 if (__r == codecvt_base::noconv) {
232 streamsize __nmemb = static_cast<size_t>(this->pptr() - this->pbase());
233 if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb)
234 return traits_type::eof();
235 } else if (__r == codecvt_base::ok || __r == codecvt_base::partial) {
236 streamsize __nmemb = static_cast<size_t>(__extbe - __extbuf_);
237 if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb)
238 return traits_type::eof();
239 if (__r == codecvt_base::partial) {
240 this->setp(const_cast<char_type*>(__e), this->pptr());
241 this->__pbump(this->epptr() - this->pbase());
242 }
243 } else
244 return traits_type::eof();
245 } while (__r == codecvt_base::partial);
246 }
247 this->setp(__pb_save, __epb_save);
248 }
249 return traits_type::not_eof(__c);
250}
251
252_LIBCPP_SUPPRESS_DEPRECATED_PUSH
253template <class _Codecvt, class _Elem, class _Tr>
254basic_streambuf<_Elem, _Tr>* wbuffer_convert<_Codecvt, _Elem, _Tr>::setbuf(char_type* __s, streamsize __n) {
255 _LIBCPP_SUPPRESS_DEPRECATED_POP
256 this->setg(0, 0, 0);
257 this->setp(0, 0);
258 if (__owns_eb_)
259 delete[] __extbuf_;
260 if (__owns_ib_)
261 delete[] __intbuf_;
262 __ebs_ = __n;
263 if (__ebs_ > sizeof(__extbuf_min_)) {
264 if (__always_noconv_ && __s) {
265 __extbuf_ = (char*)__s;
266 __owns_eb_ = false;
267 } else {
268 __extbuf_ = new char[__ebs_];
269 __owns_eb_ = true;
270 }
271 } else {
272 __extbuf_ = __extbuf_min_;
273 __ebs_ = sizeof(__extbuf_min_);
274 __owns_eb_ = false;
275 }
276 if (!__always_noconv_) {
277 __ibs_ = max<streamsize>(__n, sizeof(__extbuf_min_));
278 if (__s && __ibs_ >= sizeof(__extbuf_min_)) {
279 __intbuf_ = __s;
280 __owns_ib_ = false;
281 } else {
282 __intbuf_ = new char_type[__ibs_];
283 __owns_ib_ = true;
284 }
285 } else {
286 __ibs_ = 0;
287 __intbuf_ = 0;
288 __owns_ib_ = false;
289 }
290 return this;
291}
292
293_LIBCPP_SUPPRESS_DEPRECATED_PUSH
294template <class _Codecvt, class _Elem, class _Tr>
295typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type
296wbuffer_convert<_Codecvt, _Elem, _Tr>::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __om) {
297 int __width = __cv_->encoding();
298 if (__cv_ == 0 || !__bufptr_ || (__width <= 0 && __off != 0) || sync())
299 return pos_type(off_type(-1));
300 // __width > 0 || __off == 0, now check __way
301 if (__way != ios_base::beg && __way != ios_base::cur && __way != ios_base::end)
302 return pos_type(off_type(-1));
303 pos_type __r = __bufptr_->pubseekoff(__width * __off, __way, __om);
304 __r.state(__st_);
305 return __r;
306}
307
308template <class _Codecvt, class _Elem, class _Tr>
309typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type
310wbuffer_convert<_Codecvt, _Elem, _Tr>::seekpos(pos_type __sp, ios_base::openmode __wch) {
311 if (__cv_ == 0 || !__bufptr_ || sync())
312 return pos_type(off_type(-1));
313 if (__bufptr_->pubseekpos(__sp, __wch) == pos_type(off_type(-1)))
314 return pos_type(off_type(-1));
315 return __sp;
316}
317
318template <class _Codecvt, class _Elem, class _Tr>
319int wbuffer_convert<_Codecvt, _Elem, _Tr>::sync() {
320 _LIBCPP_SUPPRESS_DEPRECATED_POP
321 if (__cv_ == 0 || !__bufptr_)
322 return 0;
323 if (__cm_ & ios_base::out) {
324 if (this->pptr() != this->pbase())
325 if (overflow() == traits_type::eof())
326 return -1;
327 codecvt_base::result __r;
328 do {
329 char* __extbe;
330 __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe);
331 streamsize __nmemb = static_cast<streamsize>(__extbe - __extbuf_);
332 if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb)
333 return -1;
334 } while (__r == codecvt_base::partial);
335 if (__r == codecvt_base::error)
336 return -1;
337 if (__bufptr_->pubsync())
338 return -1;
339 } else if (__cm_ & ios_base::in) {
340 off_type __c;
341 if (__always_noconv_)
342 __c = this->egptr() - this->gptr();
343 else {
344 int __width = __cv_->encoding();
345 __c = __extbufend_ - __extbufnext_;
346 if (__width > 0)
347 __c += __width * (this->egptr() - this->gptr());
348 else {
349 if (this->gptr() != this->egptr()) {
350 std::reverse(this->gptr(), this->egptr());
351 codecvt_base::result __r;
352 const char_type* __e = this->gptr();
353 char* __extbe;
354 do {
355 __r = __cv_->out(__st_, __e, this->egptr(), __e, __extbuf_, __extbuf_ + __ebs_, __extbe);
356 switch (__r) {
357 case codecvt_base::noconv:
358 __c += this->egptr() - this->gptr();
359 break;
360 case codecvt_base::ok:
361 case codecvt_base::partial:
362 __c += __extbe - __extbuf_;
363 break;
364 default:
365 return -1;
366 }
367 } while (__r == codecvt_base::partial);
368 }
369 }
370 }
371 if (__bufptr_->pubseekoff(-__c, ios_base::cur, __cm_) == pos_type(off_type(-1)))
372 return -1;
373 this->setg(0, 0, 0);
374 __cm_ = 0;
375 }
376 return 0;
377}
378
379_LIBCPP_SUPPRESS_DEPRECATED_PUSH
380template <class _Codecvt, class _Elem, class _Tr>
381bool wbuffer_convert<_Codecvt, _Elem, _Tr>::__read_mode() {
382 if (!(__cm_ & ios_base::in)) {
383 this->setp(0, 0);
384 if (__always_noconv_)
385 this->setg((char_type*)__extbuf_, (char_type*)__extbuf_ + __ebs_, (char_type*)__extbuf_ + __ebs_);
386 else
387 this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_);
388 __cm_ = ios_base::in;
389 return true;
390 }
391 return false;
392}
393
394template <class _Codecvt, class _Elem, class _Tr>
395void wbuffer_convert<_Codecvt, _Elem, _Tr>::__write_mode() {
396 if (!(__cm_ & ios_base::out)) {
397 this->setg(0, 0, 0);
398 if (__ebs_ > sizeof(__extbuf_min_)) {
399 if (__always_noconv_)
400 this->setp((char_type*)__extbuf_, (char_type*)__extbuf_ + (__ebs_ - 1));
401 else
402 this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1));
403 } else
404 this->setp(0, 0);
405 __cm_ = ios_base::out;
406 }
407}
408
409template <class _Codecvt, class _Elem, class _Tr>
410wbuffer_convert<_Codecvt, _Elem, _Tr>* wbuffer_convert<_Codecvt, _Elem, _Tr>::__close() {
411 wbuffer_convert* __rt = nullptr;
412 if (__cv_ != nullptr && __bufptr_ != nullptr) {
413 __rt = this;
414 if ((__cm_ & ios_base::out) && sync())
415 __rt = nullptr;
416 }
417 return __rt;
418}
419
420_LIBCPP_SUPPRESS_DEPRECATED_POP
421
422_LIBCPP_END_NAMESPACE_STD
423
424_LIBCPP_POP_MACROS
425
426# endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT)
427
428#endif // _LIBCPP_HAS_LOCALIZATION
429
430#endif // _LIBCPP___LOCALE_DIR_WBUFFER_CONVERT_H
lib/libcxx/include/__locale_dir/wstring_convert.h created+254
......@@ -0,0 +1,254 @@
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_WSTRING_CONVERT_H
10#define _LIBCPP___LOCALE_DIR_WSTRING_CONVERT_H
11
12#include <__config>
13#include <__locale>
14#include <__memory/allocator.h>
15#include <string>
16
17#if _LIBCPP_HAS_LOCALIZATION
18
19# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21# endif
22
23# if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT)
24
25_LIBCPP_PUSH_MACROS
26# include <__undef_macros>
27
28_LIBCPP_BEGIN_NAMESPACE_STD
29
30template <class _Codecvt,
31 class _Elem = wchar_t,
32 class _WideAlloc = allocator<_Elem>,
33 class _ByteAlloc = allocator<char> >
34class _LIBCPP_DEPRECATED_IN_CXX17 wstring_convert {
35public:
36 typedef basic_string<char, char_traits<char>, _ByteAlloc> byte_string;
37 typedef basic_string<_Elem, char_traits<_Elem>, _WideAlloc> wide_string;
38 typedef typename _Codecvt::state_type state_type;
39 typedef typename wide_string::traits_type::int_type int_type;
40
41private:
42 byte_string __byte_err_string_;
43 wide_string __wide_err_string_;
44 _Codecvt* __cvtptr_;
45 state_type __cvtstate_;
46 size_t __cvtcount_;
47
48public:
49# ifndef _LIBCPP_CXX03_LANG
50 _LIBCPP_HIDE_FROM_ABI wstring_convert() : wstring_convert(new _Codecvt) {}
51 _LIBCPP_HIDE_FROM_ABI explicit wstring_convert(_Codecvt* __pcvt);
52# else
53 _LIBCPP_HIDE_FROM_ABI _LIBCPP_EXPLICIT_SINCE_CXX14 wstring_convert(_Codecvt* __pcvt = new _Codecvt);
54# endif
55
56 _LIBCPP_HIDE_FROM_ABI wstring_convert(_Codecvt* __pcvt, state_type __state);
57 _LIBCPP_EXPLICIT_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
58 wstring_convert(const byte_string& __byte_err, const wide_string& __wide_err = wide_string());
59# ifndef _LIBCPP_CXX03_LANG
60 _LIBCPP_HIDE_FROM_ABI wstring_convert(wstring_convert&& __wc);
61# endif
62 _LIBCPP_HIDE_FROM_ABI ~wstring_convert();
63
64 wstring_convert(const wstring_convert& __wc) = delete;
65 wstring_convert& operator=(const wstring_convert& __wc) = delete;
66
67 _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(char __byte) { return from_bytes(&__byte, &__byte + 1); }
68 _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const char* __ptr) {
69 return from_bytes(__ptr, __ptr + char_traits<char>::length(__ptr));
70 }
71 _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const byte_string& __str) {
72 return from_bytes(__str.data(), __str.data() + __str.size());
73 }
74 _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const char* __first, const char* __last);
75
76 _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(_Elem __wchar) {
77 return to_bytes(std::addressof(__wchar), std::addressof(__wchar) + 1);
78 }
79 _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const _Elem* __wptr) {
80 return to_bytes(__wptr, __wptr + char_traits<_Elem>::length(__wptr));
81 }
82 _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const wide_string& __wstr) {
83 return to_bytes(__wstr.data(), __wstr.data() + __wstr.size());
84 }
85 _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const _Elem* __first, const _Elem* __last);
86
87 _LIBCPP_HIDE_FROM_ABI size_t converted() const _NOEXCEPT { return __cvtcount_; }
88 _LIBCPP_HIDE_FROM_ABI state_type state() const { return __cvtstate_; }
89};
90
91_LIBCPP_SUPPRESS_DEPRECATED_PUSH
92template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
93inline wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert(_Codecvt* __pcvt)
94 : __cvtptr_(__pcvt), __cvtstate_(), __cvtcount_(0) {}
95_LIBCPP_SUPPRESS_DEPRECATED_POP
96
97template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
98inline wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert(_Codecvt* __pcvt, state_type __state)
99 : __cvtptr_(__pcvt), __cvtstate_(__state), __cvtcount_(0) {}
100
101template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
102wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert(
103 const byte_string& __byte_err, const wide_string& __wide_err)
104 : __byte_err_string_(__byte_err), __wide_err_string_(__wide_err), __cvtstate_(), __cvtcount_(0) {
105 __cvtptr_ = new _Codecvt;
106}
107
108# ifndef _LIBCPP_CXX03_LANG
109
110template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
111inline wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert(wstring_convert&& __wc)
112 : __byte_err_string_(std::move(__wc.__byte_err_string_)),
113 __wide_err_string_(std::move(__wc.__wide_err_string_)),
114 __cvtptr_(__wc.__cvtptr_),
115 __cvtstate_(__wc.__cvtstate_),
116 __cvtcount_(__wc.__cvtcount_) {
117 __wc.__cvtptr_ = nullptr;
118}
119
120# endif // _LIBCPP_CXX03_LANG
121
122_LIBCPP_SUPPRESS_DEPRECATED_PUSH
123template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
124wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::~wstring_convert() {
125 delete __cvtptr_;
126}
127
128template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
129typename wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wide_string
130wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::from_bytes(const char* __frm, const char* __frm_end) {
131 _LIBCPP_SUPPRESS_DEPRECATED_POP
132 __cvtcount_ = 0;
133 if (__cvtptr_ != nullptr) {
134 wide_string __ws(2 * (__frm_end - __frm), _Elem());
135 if (__frm != __frm_end)
136 __ws.resize(__ws.capacity());
137 codecvt_base::result __r = codecvt_base::ok;
138 state_type __st = __cvtstate_;
139 if (__frm != __frm_end) {
140 _Elem* __to = std::addressof(__ws[0]);
141 _Elem* __to_end = __to + __ws.size();
142 const char* __frm_nxt;
143 do {
144 _Elem* __to_nxt;
145 __r = __cvtptr_->in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
146 __cvtcount_ += __frm_nxt - __frm;
147 if (__frm_nxt == __frm) {
148 __r = codecvt_base::error;
149 } else if (__r == codecvt_base::noconv) {
150 __ws.resize(__to - std::addressof(__ws[0]));
151 // This only gets executed if _Elem is char
152 __ws.append((const _Elem*)__frm, (const _Elem*)__frm_end);
153 __frm = __frm_nxt;
154 __r = codecvt_base::ok;
155 } else if (__r == codecvt_base::ok) {
156 __ws.resize(__to_nxt - std::addressof(__ws[0]));
157 __frm = __frm_nxt;
158 } else if (__r == codecvt_base::partial) {
159 ptrdiff_t __s = __to_nxt - std::addressof(__ws[0]);
160 __ws.resize(2 * __s);
161 __to = std::addressof(__ws[0]) + __s;
162 __to_end = std::addressof(__ws[0]) + __ws.size();
163 __frm = __frm_nxt;
164 }
165 } while (__r == codecvt_base::partial && __frm_nxt < __frm_end);
166 }
167 if (__r == codecvt_base::ok)
168 return __ws;
169 }
170
171 if (__wide_err_string_.empty())
172 std::__throw_range_error("wstring_convert: from_bytes error");
173
174 return __wide_err_string_;
175}
176
177template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
178typename wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::byte_string
179wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::to_bytes(const _Elem* __frm, const _Elem* __frm_end) {
180 __cvtcount_ = 0;
181 if (__cvtptr_ != nullptr) {
182 byte_string __bs(2 * (__frm_end - __frm), char());
183 if (__frm != __frm_end)
184 __bs.resize(__bs.capacity());
185 codecvt_base::result __r = codecvt_base::ok;
186 state_type __st = __cvtstate_;
187 if (__frm != __frm_end) {
188 char* __to = std::addressof(__bs[0]);
189 char* __to_end = __to + __bs.size();
190 const _Elem* __frm_nxt;
191 do {
192 char* __to_nxt;
193 __r = __cvtptr_->out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
194 __cvtcount_ += __frm_nxt - __frm;
195 if (__frm_nxt == __frm) {
196 __r = codecvt_base::error;
197 } else if (__r == codecvt_base::noconv) {
198 __bs.resize(__to - std::addressof(__bs[0]));
199 // This only gets executed if _Elem is char
200 __bs.append((const char*)__frm, (const char*)__frm_end);
201 __frm = __frm_nxt;
202 __r = codecvt_base::ok;
203 } else if (__r == codecvt_base::ok) {
204 __bs.resize(__to_nxt - std::addressof(__bs[0]));
205 __frm = __frm_nxt;
206 } else if (__r == codecvt_base::partial) {
207 ptrdiff_t __s = __to_nxt - std::addressof(__bs[0]);
208 __bs.resize(2 * __s);
209 __to = std::addressof(__bs[0]) + __s;
210 __to_end = std::addressof(__bs[0]) + __bs.size();
211 __frm = __frm_nxt;
212 }
213 } while (__r == codecvt_base::partial && __frm_nxt < __frm_end);
214 }
215 if (__r == codecvt_base::ok) {
216 size_t __s = __bs.size();
217 __bs.resize(__bs.capacity());
218 char* __to = std::addressof(__bs[0]) + __s;
219 char* __to_end = __to + __bs.size();
220 do {
221 char* __to_nxt;
222 __r = __cvtptr_->unshift(__st, __to, __to_end, __to_nxt);
223 if (__r == codecvt_base::noconv) {
224 __bs.resize(__to - std::addressof(__bs[0]));
225 __r = codecvt_base::ok;
226 } else if (__r == codecvt_base::ok) {
227 __bs.resize(__to_nxt - std::addressof(__bs[0]));
228 } else if (__r == codecvt_base::partial) {
229 ptrdiff_t __sp = __to_nxt - std::addressof(__bs[0]);
230 __bs.resize(2 * __sp);
231 __to = std::addressof(__bs[0]) + __sp;
232 __to_end = std::addressof(__bs[0]) + __bs.size();
233 }
234 } while (__r == codecvt_base::partial);
235 if (__r == codecvt_base::ok)
236 return __bs;
237 }
238 }
239
240 if (__byte_err_string_.empty())
241 std::__throw_range_error("wstring_convert: to_bytes error");
242
243 return __byte_err_string_;
244}
245
246_LIBCPP_END_NAMESPACE_STD
247
248_LIBCPP_POP_MACROS
249
250# endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT)
251
252#endif // _LIBCPP_HAS_LOCALIZATION
253
254#endif // _LIBCPP___LOCALE_DIR_WSTRING_CONVERT_H
lib/libcxx/include/__log_hardening_failure created+42
......@@ -0,0 +1,42 @@
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___LOG_HARDENING_FAILURE
11#define _LIBCPP___LOG_HARDENING_FAILURE
12
13#include <__config>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19// Hardening logging is not available in the C++03 mode; moreover, it is currently only available in the experimental
20// library.
21#if _LIBCPP_HAS_EXPERIMENTAL_HARDENING_OBSERVE_SEMANTIC && !defined(_LIBCPP_CXX03_LANG)
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25// This function should never be called directly from the code -- it should only be called through the
26// `_LIBCPP_LOG_HARDENING_FAILURE` macro.
27[[__gnu__::__cold__]] _LIBCPP_EXPORTED_FROM_ABI void __log_hardening_failure(const char* __message) noexcept;
28
29// _LIBCPP_LOG_HARDENING_FAILURE(message)
30//
31// This macro is used to log an error without terminating the program (as is the case for hardening failures if the
32// `observe` assertion semantic is used).
33
34# if !defined(_LIBCPP_LOG_HARDENING_FAILURE)
35# define _LIBCPP_LOG_HARDENING_FAILURE(__message) ::std::__log_hardening_failure(__message)
36# endif // !defined(_LIBCPP_LOG_HARDENING_FAILURE)
37
38_LIBCPP_END_NAMESPACE_STD
39
40#endif // _LIBCPP_HAS_EXPERIMENTAL_HARDENING_OBSERVE_SEMANTIC && !defined(_LIBCPP_CXX03_LANG)
41
42#endif // _LIBCPP___LOG_HARDENING_FAILURE
lib/libcxx/include/__math/abs.h+24
......@@ -39,6 +39,30 @@ template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
3939 return __builtin_fabs((double)__x);
4040}
4141
42// abs
43
44[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline float abs(float __x) _NOEXCEPT { return __builtin_fabsf(__x); }
45[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline double abs(double __x) _NOEXCEPT { return __builtin_fabs(__x); }
46
47[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline long double abs(long double __x) _NOEXCEPT {
48 return __builtin_fabsl(__x);
49}
50
51template <class = int>
52[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline int abs(int __x) _NOEXCEPT {
53 return __builtin_abs(__x);
54}
55
56template <class = int>
57[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline long abs(long __x) _NOEXCEPT {
58 return __builtin_labs(__x);
59}
60
61template <class = int>
62[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline long long abs(long long __x) _NOEXCEPT {
63 return __builtin_llabs(__x);
64}
65
4266} // namespace __math
4367
4468_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__math/copysign.h+1-1
......@@ -33,7 +33,7 @@ namespace __math {
3333}
3434
3535template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
36[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type copysign(_A1 __x, _A2 __y) _NOEXCEPT {
36[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> copysign(_A1 __x, _A2 __y) _NOEXCEPT {
3737 return ::__builtin_copysign(__x, __y);
3838}
3939
lib/libcxx/include/__math/exponential_functions.h+2-2
......@@ -158,8 +158,8 @@ inline _LIBCPP_HIDE_FROM_ABI long double pow(long double __x, long double __y) _
158158}
159159
160160template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
161inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type pow(_A1 __x, _A2 __y) _NOEXCEPT {
162 using __result_type = typename __promote<_A1, _A2>::type;
161inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> pow(_A1 __x, _A2 __y) _NOEXCEPT {
162 using __result_type = __promote_t<_A1, _A2>;
163163 static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
164164 return __math::pow((__result_type)__x, (__result_type)__y);
165165}
lib/libcxx/include/__math/fdim.h+2-2
......@@ -35,8 +35,8 @@ inline _LIBCPP_HIDE_FROM_ABI long double fdim(long double __x, long double __y)
3535}
3636
3737template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
38inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fdim(_A1 __x, _A2 __y) _NOEXCEPT {
39 using __result_type = typename __promote<_A1, _A2>::type;
38inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> fdim(_A1 __x, _A2 __y) _NOEXCEPT {
39 using __result_type = __promote_t<_A1, _A2>;
4040 static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
4141 return __math::fdim((__result_type)__x, (__result_type)__y);
4242}
lib/libcxx/include/__math/fma.h+2-2
......@@ -40,8 +40,8 @@ template <class _A1,
4040 class _A2,
4141 class _A3,
4242 __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value && is_arithmetic<_A3>::value, int> = 0>
43inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2, _A3>::type fma(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT {
44 using __result_type = typename __promote<_A1, _A2, _A3>::type;
43inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2, _A3> fma(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT {
44 using __result_type = __promote_t<_A1, _A2, _A3>;
4545 static_assert(
4646 !(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value && _IsSame<_A3, __result_type>::value),
4747 "");
lib/libcxx/include/__math/hypot.h+4-4
......@@ -43,8 +43,8 @@ inline _LIBCPP_HIDE_FROM_ABI long double hypot(long double __x, long double __y)
4343}
4444
4545template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
46inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type hypot(_A1 __x, _A2 __y) _NOEXCEPT {
47 using __result_type = typename __promote<_A1, _A2>::type;
46inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> hypot(_A1 __x, _A2 __y) _NOEXCEPT {
47 using __result_type = __promote_t<_A1, _A2>;
4848 static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
4949 return __math::hypot((__result_type)__x, (__result_type)__y);
5050}
......@@ -91,8 +91,8 @@ template <class _A1,
9191 class _A2,
9292 class _A3,
9393 std::enable_if_t< is_arithmetic_v<_A1> && is_arithmetic_v<_A2> && is_arithmetic_v<_A3>, int> = 0 >
94_LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2, _A3>::type hypot(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT {
95 using __result_type = typename __promote<_A1, _A2, _A3>::type;
94_LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2, _A3> hypot(_A1 __x, _A2 __y, _A3 __z) _NOEXCEPT {
95 using __result_type = __promote_t<_A1, _A2, _A3>;
9696 static_assert(!(
9797 std::is_same_v<_A1, __result_type> && std::is_same_v<_A2, __result_type> && std::is_same_v<_A3, __result_type>));
9898 return __math::__hypot(
lib/libcxx/include/__math/inverse_trigonometric_functions.h+2-2
......@@ -86,8 +86,8 @@ inline _LIBCPP_HIDE_FROM_ABI long double atan2(long double __y, long double __x)
8686}
8787
8888template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
89inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type atan2(_A1 __y, _A2 __x) _NOEXCEPT {
90 using __result_type = typename __promote<_A1, _A2>::type;
89inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> atan2(_A1 __y, _A2 __x) _NOEXCEPT {
90 using __result_type = __promote_t<_A1, _A2>;
9191 static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
9292 return __math::atan2((__result_type)__y, (__result_type)__x);
9393}
lib/libcxx/include/__math/min_max.h+4-4
......@@ -39,8 +39,8 @@ template <class = int>
3939}
4040
4141template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
42[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmax(_A1 __x, _A2 __y) _NOEXCEPT {
43 using __result_type = typename __promote<_A1, _A2>::type;
42[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> fmax(_A1 __x, _A2 __y) _NOEXCEPT {
43 using __result_type = __promote_t<_A1, _A2>;
4444 static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
4545 return __math::fmax((__result_type)__x, (__result_type)__y);
4646}
......@@ -61,8 +61,8 @@ template <class = int>
6161}
6262
6363template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
64[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmin(_A1 __x, _A2 __y) _NOEXCEPT {
65 using __result_type = typename __promote<_A1, _A2>::type;
64[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> fmin(_A1 __x, _A2 __y) _NOEXCEPT {
65 using __result_type = __promote_t<_A1, _A2>;
6666 static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
6767 return __math::fmin((__result_type)__x, (__result_type)__y);
6868}
lib/libcxx/include/__math/modulo.h+2-2
......@@ -37,8 +37,8 @@ inline _LIBCPP_HIDE_FROM_ABI long double fmod(long double __x, long double __y)
3737}
3838
3939template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
40inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmod(_A1 __x, _A2 __y) _NOEXCEPT {
41 using __result_type = typename __promote<_A1, _A2>::type;
40inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> fmod(_A1 __x, _A2 __y) _NOEXCEPT {
41 using __result_type = __promote_t<_A1, _A2>;
4242 static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
4343 return __math::fmod((__result_type)__x, (__result_type)__y);
4444}
lib/libcxx/include/__math/remainder.h+4-4
......@@ -37,8 +37,8 @@ inline _LIBCPP_HIDE_FROM_ABI long double remainder(long double __x, long double
3737}
3838
3939template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
40inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type remainder(_A1 __x, _A2 __y) _NOEXCEPT {
41 using __result_type = typename __promote<_A1, _A2>::type;
40inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> remainder(_A1 __x, _A2 __y) _NOEXCEPT {
41 using __result_type = __promote_t<_A1, _A2>;
4242 static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
4343 return __math::remainder((__result_type)__x, (__result_type)__y);
4444}
......@@ -59,8 +59,8 @@ inline _LIBCPP_HIDE_FROM_ABI long double remquo(long double __x, long double __y
5959}
6060
6161template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
62inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type remquo(_A1 __x, _A2 __y, int* __z) _NOEXCEPT {
63 using __result_type = typename __promote<_A1, _A2>::type;
62inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> remquo(_A1 __x, _A2 __y, int* __z) _NOEXCEPT {
63 using __result_type = __promote_t<_A1, _A2>;
6464 static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
6565 return __math::remquo((__result_type)__x, (__result_type)__y, __z);
6666}
lib/libcxx/include/__math/rounding_functions.h+2-2
......@@ -158,8 +158,8 @@ inline _LIBCPP_HIDE_FROM_ABI long double nextafter(long double __x, long double
158158}
159159
160160template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
161inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type nextafter(_A1 __x, _A2 __y) _NOEXCEPT {
162 using __result_type = typename __promote<_A1, _A2>::type;
161inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> nextafter(_A1 __x, _A2 __y) _NOEXCEPT {
162 using __result_type = __promote_t<_A1, _A2>;
163163 static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
164164 return __math::nextafter((__result_type)__x, (__result_type)__y);
165165}
lib/libcxx/include/__math/traits.h+7-13
......@@ -13,7 +13,6 @@
1313#include <__type_traits/enable_if.h>
1414#include <__type_traits/is_arithmetic.h>
1515#include <__type_traits/is_integral.h>
16#include <__type_traits/is_signed.h>
1716#include <__type_traits/promote.h>
1817
1918#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -51,16 +50,11 @@ template <class = void>
5150 return __builtin_signbit(__x);
5251}
5352
54template <class _A1, __enable_if_t<is_integral<_A1>::value && is_signed<_A1>::value, int> = 0>
53template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
5554[[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
5655 return __x < 0;
5756}
5857
59template <class _A1, __enable_if_t<is_integral<_A1>::value && !is_signed<_A1>::value, int> = 0>
60[[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(_A1) _NOEXCEPT {
61 return false;
62}
63
6458// isfinite
6559
6660template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
......@@ -151,7 +145,7 @@ template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
151145
152146template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
153147[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) _NOEXCEPT {
154 using type = typename __promote<_A1, _A2>::type;
148 using type = __promote_t<_A1, _A2>;
155149 return __builtin_isgreater((type)__x, (type)__y);
156150}
157151
......@@ -159,7 +153,7 @@ template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_ar
159153
160154template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
161155[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT {
162 using type = typename __promote<_A1, _A2>::type;
156 using type = __promote_t<_A1, _A2>;
163157 return __builtin_isgreaterequal((type)__x, (type)__y);
164158}
165159
......@@ -167,7 +161,7 @@ template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_ar
167161
168162template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
169163[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NOEXCEPT {
170 using type = typename __promote<_A1, _A2>::type;
164 using type = __promote_t<_A1, _A2>;
171165 return __builtin_isless((type)__x, (type)__y);
172166}
173167
......@@ -175,7 +169,7 @@ template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_ar
175169
176170template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
177171[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y) _NOEXCEPT {
178 using type = typename __promote<_A1, _A2>::type;
172 using type = __promote_t<_A1, _A2>;
179173 return __builtin_islessequal((type)__x, (type)__y);
180174}
181175
......@@ -183,7 +177,7 @@ template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_ar
183177
184178template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
185179[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 __y) _NOEXCEPT {
186 using type = typename __promote<_A1, _A2>::type;
180 using type = __promote_t<_A1, _A2>;
187181 return __builtin_islessgreater((type)__x, (type)__y);
188182}
189183
......@@ -191,7 +185,7 @@ template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_ar
191185
192186template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
193187[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isunordered(_A1 __x, _A2 __y) _NOEXCEPT {
194 using type = typename __promote<_A1, _A2>::type;
188 using type = __promote_t<_A1, _A2>;
195189 return __builtin_isunordered((type)__x, (type)__y);
196190}
197191
lib/libcxx/include/__mbstate_t.h+4-4
......@@ -43,12 +43,12 @@
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 _LIBCPP_HAS_WIDE_CHARACTERS && __has_include_next(<wchar.h>)
47# include_next <wchar.h> // fall back to the C standard provider of mbstate_t
46#elif __has_include_next(<wchar.h>)
47# include_next <wchar.h> // use the C standard provider of mbstate_t if present
4848#elif __has_include_next(<uchar.h>)
49# include_next <uchar.h> // <uchar.h> is also required to make mbstate_t visible
49# include_next <uchar.h> // Try <uchar.h> in absence of <wchar.h> for mbstate_t
5050#else
51# error "We don't know how to get the definition of mbstate_t without <wchar.h> on your platform."
51# error "We don't know how to get the definition of mbstate_t on your platform."
5252#endif
5353
5454#endif // _LIBCPP___MBSTATE_T_H
lib/libcxx/include/__mdspan/aligned_accessor.h created+87
......@@ -0,0 +1,87 @@
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// Kokkos v. 4.0
9// Copyright (2022) National Technology & Engineering
10// Solutions of Sandia, LLC (NTESS).
11//
12// Under the terms of Contract DE-NA0003525 with NTESS,
13// the U.S. Government retains certain rights in this software.
14//
15//===---------------------------------------------------------------------===//
16
17#ifndef _LIBCPP___MDSPAN_ALIGNED_ACCESSOR_H
18#define _LIBCPP___MDSPAN_ALIGNED_ACCESSOR_H
19
20#include <__config>
21#include <__cstddef/size_t.h>
22#include <__mdspan/default_accessor.h>
23#include <__memory/assume_aligned.h>
24#include <__type_traits/is_abstract.h>
25#include <__type_traits/is_array.h>
26#include <__type_traits/is_convertible.h>
27#include <__type_traits/remove_const.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
38#if _LIBCPP_STD_VER >= 26
39
40template <class _ElementType, size_t _ByteAlignment>
41struct aligned_accessor {
42 static_assert(_ByteAlignment != 0 && (_ByteAlignment & (_ByteAlignment - 1)) == 0,
43 "aligned_accessor: byte alignment must be a power of two");
44 static_assert(_ByteAlignment >= alignof(_ElementType), "aligned_accessor: insufficient byte alignment");
45 static_assert(!is_array_v<_ElementType>, "aligned_accessor: template argument may not be an array type");
46 static_assert(!is_abstract_v<_ElementType>, "aligned_accessor: template argument may not be an abstract class");
47
48 using offset_policy = default_accessor<_ElementType>;
49 using element_type = _ElementType;
50 using reference = _ElementType&;
51 using data_handle_type = _ElementType*;
52
53 static constexpr size_t byte_alignment = _ByteAlignment;
54
55 _LIBCPP_HIDE_FROM_ABI constexpr aligned_accessor() noexcept = default;
56
57 template <class _OtherElementType, size_t _OtherByteAlignment>
58 requires(is_convertible_v<_OtherElementType (*)[], element_type (*)[]> && _OtherByteAlignment >= byte_alignment)
59 _LIBCPP_HIDE_FROM_ABI constexpr aligned_accessor(aligned_accessor<_OtherElementType, _OtherByteAlignment>) noexcept {}
60
61 template <class _OtherElementType>
62 requires(is_convertible_v<_OtherElementType (*)[], element_type (*)[]>)
63 _LIBCPP_HIDE_FROM_ABI explicit constexpr aligned_accessor(default_accessor<_OtherElementType>) noexcept {}
64
65 template <class _OtherElementType>
66 requires(is_convertible_v<element_type (*)[], _OtherElementType (*)[]>)
67 _LIBCPP_HIDE_FROM_ABI constexpr operator default_accessor<_OtherElementType>() const noexcept {
68 return {};
69 }
70
71 _LIBCPP_HIDE_FROM_ABI constexpr reference access(data_handle_type __p, size_t __i) const noexcept {
72 return std::assume_aligned<byte_alignment>(__p)[__i];
73 }
74
75 _LIBCPP_HIDE_FROM_ABI constexpr typename offset_policy::data_handle_type
76 offset(data_handle_type __p, size_t __i) const noexcept {
77 return std::assume_aligned<byte_alignment>(__p) + __i;
78 }
79};
80
81#endif // _LIBCPP_STD_VER >= 26
82
83_LIBCPP_END_NAMESPACE_STD
84
85_LIBCPP_POP_MACROS
86
87#endif // _LIBCPP___MDSPAN_ALIGNED_ACCESSOR_H
lib/libcxx/include/__mdspan/extents.h+5-5
......@@ -21,11 +21,10 @@
2121#include <__config>
2222
2323#include <__concepts/arithmetic.h>
24#include <__cstddef/byte.h>
2524#include <__type_traits/common_type.h>
25#include <__type_traits/integer_traits.h>
2626#include <__type_traits/is_convertible.h>
2727#include <__type_traits/is_nothrow_constructible.h>
28#include <__type_traits/is_same.h>
2928#include <__type_traits/make_unsigned.h>
3029#include <__utility/integer_sequence.h>
3130#include <__utility/unreachable.h>
......@@ -283,7 +282,8 @@ public:
283282 using size_type = make_unsigned_t<index_type>;
284283 using rank_type = size_t;
285284
286 static_assert(__libcpp_integer<index_type>, "extents::index_type must be a signed or unsigned integer type");
285 static_assert(__signed_or_unsigned_integer<index_type>,
286 "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
......@@ -440,13 +440,13 @@ struct __make_dextents;
440440
441441template <class _IndexType, size_t _Rank, size_t... _ExtentsPack>
442442struct __make_dextents< _IndexType, _Rank, extents<_IndexType, _ExtentsPack...>> {
443 using type =
443 using type _LIBCPP_NODEBUG =
444444 typename __make_dextents< _IndexType, _Rank - 1, extents<_IndexType, dynamic_extent, _ExtentsPack...>>::type;
445445};
446446
447447template <class _IndexType, size_t... _ExtentsPack>
448448struct __make_dextents< _IndexType, 0, extents<_IndexType, _ExtentsPack...>> {
449 using type = extents<_IndexType, _ExtentsPack...>;
449 using type _LIBCPP_NODEBUG = extents<_IndexType, _ExtentsPack...>;
450450};
451451
452452} // namespace __mdspan_detail
lib/libcxx/include/__mdspan/layout_left.h+2-1
......@@ -21,6 +21,7 @@
2121#include <__config>
2222#include <__fwd/mdspan.h>
2323#include <__mdspan/extents.h>
24#include <__memory/addressof.h>
2425#include <__type_traits/common_type.h>
2526#include <__type_traits/is_constructible.h>
2627#include <__type_traits/is_convertible.h>
......@@ -58,7 +59,7 @@ private:
5859
5960 index_type __prod = __ext.extent(0);
6061 for (rank_type __r = 1; __r < extents_type::rank(); __r++) {
61 bool __overflowed = __builtin_mul_overflow(__prod, __ext.extent(__r), &__prod);
62 bool __overflowed = __builtin_mul_overflow(__prod, __ext.extent(__r), std::addressof(__prod));
6263 if (__overflowed)
6364 return false;
6465 }
lib/libcxx/include/__mdspan/layout_right.h+2-1
......@@ -22,6 +22,7 @@
2222#include <__cstddef/size_t.h>
2323#include <__fwd/mdspan.h>
2424#include <__mdspan/extents.h>
25#include <__memory/addressof.h>
2526#include <__type_traits/common_type.h>
2627#include <__type_traits/is_constructible.h>
2728#include <__type_traits/is_convertible.h>
......@@ -58,7 +59,7 @@ private:
5859
5960 index_type __prod = __ext.extent(0);
6061 for (rank_type __r = 1; __r < extents_type::rank(); __r++) {
61 bool __overflowed = __builtin_mul_overflow(__prod, __ext.extent(__r), &__prod);
62 bool __overflowed = __builtin_mul_overflow(__prod, __ext.extent(__r), std::addressof(__prod));
6263 if (__overflowed)
6364 return false;
6465 }
lib/libcxx/include/__mdspan/layout_stride.h+6-4
......@@ -22,6 +22,7 @@
2222#include <__config>
2323#include <__fwd/mdspan.h>
2424#include <__mdspan/extents.h>
25#include <__memory/addressof.h>
2526#include <__type_traits/common_type.h>
2627#include <__type_traits/is_constructible.h>
2728#include <__type_traits/is_convertible.h>
......@@ -86,7 +87,7 @@ private:
8687
8788 index_type __prod = __ext.extent(0);
8889 for (rank_type __r = 1; __r < __rank_; __r++) {
89 bool __overflowed = __builtin_mul_overflow(__prod, __ext.extent(__r), &__prod);
90 bool __overflowed = __builtin_mul_overflow(__prod, __ext.extent(__r), std::addressof(__prod));
9091 if (__overflowed)
9192 return false;
9293 }
......@@ -109,11 +110,12 @@ private:
109110 }
110111 if (__ext.extent(__r) == static_cast<index_type>(0))
111112 return true;
112 index_type __prod = (__ext.extent(__r) - 1);
113 bool __overflowed_mul = __builtin_mul_overflow(__prod, static_cast<index_type>(__strides[__r]), &__prod);
113 index_type __prod = (__ext.extent(__r) - 1);
114 bool __overflowed_mul =
115 __builtin_mul_overflow(__prod, static_cast<index_type>(__strides[__r]), std::addressof(__prod));
114116 if (__overflowed_mul)
115117 return false;
116 bool __overflowed_add = __builtin_add_overflow(__size, __prod, &__size);
118 bool __overflowed_add = __builtin_add_overflow(__size, __prod, std::addressof(__size));
117119 if (__overflowed_add)
118120 return false;
119121 }
lib/libcxx/include/__mdspan/mdspan.h+7-5
......@@ -20,8 +20,10 @@
2020#include <__assert>
2121#include <__config>
2222#include <__fwd/mdspan.h>
23#include <__mdspan/aligned_accessor.h>
2324#include <__mdspan/default_accessor.h>
2425#include <__mdspan/extents.h>
26#include <__memory/addressof.h>
2527#include <__type_traits/extent.h>
2628#include <__type_traits/is_abstract.h>
2729#include <__type_traits/is_array.h>
......@@ -215,7 +217,7 @@ public:
215217 _LIBCPP_ASSERT_UNCATEGORIZED(
216218 false == ([&]<size_t... _Idxs>(index_sequence<_Idxs...>) {
217219 size_type __prod = 1;
218 return (__builtin_mul_overflow(__prod, extent(_Idxs), &__prod) || ... || false);
220 return (__builtin_mul_overflow(__prod, extent(_Idxs), std::addressof(__prod)) || ... || false);
219221 }(make_index_sequence<rank()>())),
220222 "mdspan: size() is not representable as size_type");
221223 return [&]<size_t... _Idxs>(index_sequence<_Idxs...>) {
......@@ -266,13 +268,13 @@ private:
266268# if _LIBCPP_STD_VER >= 26
267269template <class _ElementType, class... _OtherIndexTypes>
268270 requires((is_convertible_v<_OtherIndexTypes, size_t> && ...) && (sizeof...(_OtherIndexTypes) > 0))
269explicit mdspan(_ElementType*,
270 _OtherIndexTypes...) -> mdspan<_ElementType, extents<size_t, __maybe_static_ext<_OtherIndexTypes>...>>;
271explicit mdspan(_ElementType*, _OtherIndexTypes...)
272 -> mdspan<_ElementType, extents<size_t, __maybe_static_ext<_OtherIndexTypes>...>>;
271273# else
272274template <class _ElementType, class... _OtherIndexTypes>
273275 requires((is_convertible_v<_OtherIndexTypes, size_t> && ...) && (sizeof...(_OtherIndexTypes) > 0))
274explicit mdspan(_ElementType*,
275 _OtherIndexTypes...) -> mdspan<_ElementType, dextents<size_t, sizeof...(_OtherIndexTypes)>>;
276explicit mdspan(_ElementType*, _OtherIndexTypes...)
277 -> mdspan<_ElementType, dextents<size_t, sizeof...(_OtherIndexTypes)>>;
276278# endif
277279
278280template <class _Pointer>
lib/libcxx/include/__memory/addressof.h+2-2
......@@ -23,7 +23,7 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_NO_CFI _LIBCPP_HIDE_FROM_ABI _Tp* a
2323 return __builtin_addressof(__x);
2424}
2525
26#if _LIBCPP_HAS_OBJC_ARC
26#if __has_feature(objc_arc)
2727// Objective-C++ Automatic Reference Counting uses qualified pointers
2828// that require special addressof() signatures.
2929template <class _Tp>
......@@ -31,7 +31,7 @@ inline _LIBCPP_HIDE_FROM_ABI __strong _Tp* addressof(__strong _Tp& __x) _NOEXCEP
3131 return &__x;
3232}
3333
34# if _LIBCPP_HAS_OBJC_ARC_WEAK
34# if __has_feature(objc_arc_weak)
3535template <class _Tp>
3636inline _LIBCPP_HIDE_FROM_ABI __weak _Tp* addressof(__weak _Tp& __x) _NOEXCEPT {
3737 return &__x;
lib/libcxx/include/__memory/allocation_guard.h+11-9
......@@ -49,24 +49,26 @@ struct __allocation_guard {
4949 using _Size _LIBCPP_NODEBUG = typename allocator_traits<_Alloc>::size_type;
5050
5151 template <class _AllocT> // we perform the allocator conversion inside the constructor
52 _LIBCPP_HIDE_FROM_ABI explicit __allocation_guard(_AllocT __alloc, _Size __n)
52 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit __allocation_guard(_AllocT __alloc, _Size __n)
5353 : __alloc_(std::move(__alloc)),
5454 __n_(__n),
5555 __ptr_(allocator_traits<_Alloc>::allocate(__alloc_, __n_)) // initialization order is important
5656 {}
5757
58 _LIBCPP_HIDE_FROM_ABI ~__allocation_guard() _NOEXCEPT { __destroy(); }
58 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI ~__allocation_guard() _NOEXCEPT { __destroy(); }
5959
60 _LIBCPP_HIDE_FROM_ABI __allocation_guard(const __allocation_guard&) = delete;
61 _LIBCPP_HIDE_FROM_ABI __allocation_guard(__allocation_guard&& __other) _NOEXCEPT
60 __allocation_guard(const __allocation_guard&) = delete;
61 __allocation_guard& operator=(const __allocation_guard& __other) = delete;
62
63 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __allocation_guard(__allocation_guard&& __other) _NOEXCEPT
6264 : __alloc_(std::move(__other.__alloc_)),
6365 __n_(__other.__n_),
6466 __ptr_(__other.__ptr_) {
6567 __other.__ptr_ = nullptr;
6668 }
6769
68 _LIBCPP_HIDE_FROM_ABI __allocation_guard& operator=(const __allocation_guard& __other) = delete;
69 _LIBCPP_HIDE_FROM_ABI __allocation_guard& operator=(__allocation_guard&& __other) _NOEXCEPT {
70 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __allocation_guard&
71 operator=(__allocation_guard&& __other) _NOEXCEPT {
7072 if (std::addressof(__other) != this) {
7173 __destroy();
7274
......@@ -79,17 +81,17 @@ struct __allocation_guard {
7981 return *this;
8082 }
8183
82 _LIBCPP_HIDE_FROM_ABI _Pointer
84 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI _Pointer
8385 __release_ptr() _NOEXCEPT { // not called __release() because it's a keyword in objective-c++
8486 _Pointer __tmp = __ptr_;
8587 __ptr_ = nullptr;
8688 return __tmp;
8789 }
8890
89 _LIBCPP_HIDE_FROM_ABI _Pointer __get() const _NOEXCEPT { return __ptr_; }
91 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI _Pointer __get() const _NOEXCEPT { return __ptr_; }
9092
9193private:
92 _LIBCPP_HIDE_FROM_ABI void __destroy() _NOEXCEPT {
94 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __destroy() _NOEXCEPT {
9395 if (__ptr_ != nullptr) {
9496 allocator_traits<_Alloc>::deallocate(__alloc_, __ptr_, __n_);
9597 }
lib/libcxx/include/__memory/allocator.h+3-3
......@@ -38,7 +38,7 @@ class allocator;
3838// These specializations shouldn't be marked _LIBCPP_DEPRECATED_IN_CXX17.
3939// Specializing allocator<void> is deprecated, but not using it.
4040template <>
41class _LIBCPP_TEMPLATE_VIS allocator<void> {
41class allocator<void> {
4242public:
4343 _LIBCPP_DEPRECATED_IN_CXX17 typedef void* pointer;
4444 _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* const_pointer;
......@@ -77,7 +77,7 @@ struct __non_trivial_if<true, _Unique> {
7777// allocator<void> trivial in C++20.
7878
7979template <class _Tp>
80class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if<!is_void<_Tp>::value, allocator<_Tp> > {
80class allocator : private __non_trivial_if<!is_void<_Tp>::value, allocator<_Tp> > {
8181 static_assert(!is_const<_Tp>::value, "std::allocator does not support const types");
8282 static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types");
8383
......@@ -98,7 +98,7 @@ public:
9898 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* allocate(size_t __n) {
9999 static_assert(sizeof(_Tp) >= 0, "cannot allocate memory for an incomplete type");
100100 if (__n > allocator_traits<allocator>::max_size(*this))
101 __throw_bad_array_new_length();
101 std::__throw_bad_array_new_length();
102102 if (__libcpp_is_constant_evaluated()) {
103103 return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
104104 } else {
lib/libcxx/include/__memory/allocator_arg_t.h+1-1
......@@ -23,7 +23,7 @@
2323
2424_LIBCPP_BEGIN_NAMESPACE_STD
2525
26struct _LIBCPP_TEMPLATE_VIS allocator_arg_t {
26struct allocator_arg_t {
2727 explicit allocator_arg_t() = default;
2828};
2929
lib/libcxx/include/__memory/allocator_traits.h+87-120
......@@ -36,12 +36,7 @@ _LIBCPP_PUSH_MACROS
3636
3737_LIBCPP_BEGIN_NAMESPACE_STD
3838
39#define _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(NAME, PROPERTY) \
40 template <class _Tp, class = void> \
41 struct NAME : false_type {}; \
42 template <class _Tp> \
43 struct NAME<_Tp, __void_t<typename _Tp::PROPERTY > > : true_type {}
44
39_LIBCPP_SUPPRESS_DEPRECATED_PUSH
4540// __pointer
4641template <class _Tp>
4742using __pointer_member _LIBCPP_NODEBUG = typename _Tp::pointer;
......@@ -49,50 +44,45 @@ using __pointer_member _LIBCPP_NODEBUG = typename _Tp::pointer;
4944template <class _Tp, class _Alloc>
5045using __pointer _LIBCPP_NODEBUG = __detected_or_t<_Tp*, __pointer_member, __libcpp_remove_reference_t<_Alloc> >;
5146
52// __const_pointer
53_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_const_pointer, const_pointer);
54template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
55struct __const_pointer {
56 using type _LIBCPP_NODEBUG = typename _Alloc::const_pointer;
57};
58template <class _Tp, class _Ptr, class _Alloc>
59struct __const_pointer<_Tp, _Ptr, _Alloc, false> {
47// This trait returns _Alias<_Alloc> if that's well-formed, and _Ptr rebound to _Tp otherwise
48template <class _Alloc, template <class> class _Alias, class _Ptr, class _Tp, class = void>
49struct __rebind_or_alias_pointer {
6050#ifdef _LIBCPP_CXX03_LANG
61 using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const _Tp>::other;
51 using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<_Tp>::other;
6252#else
63 using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const _Tp>;
53 using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<_Tp>;
6454#endif
6555};
6656
67// __void_pointer
68_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_void_pointer, void_pointer);
69template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
70struct __void_pointer {
71 using type _LIBCPP_NODEBUG = typename _Alloc::void_pointer;
57template <class _Ptr, class _Alloc, class _Tp, template <class> class _Alias>
58struct __rebind_or_alias_pointer<_Alloc, _Alias, _Ptr, _Tp, __void_t<_Alias<_Alloc> > > {
59 using type _LIBCPP_NODEBUG = _Alias<_Alloc>;
7260};
61
62// __const_pointer
63template <class _Alloc>
64using __const_pointer_member _LIBCPP_NODEBUG = typename _Alloc::const_pointer;
65
66template <class _Tp, class _Ptr, class _Alloc>
67using __const_pointer_t _LIBCPP_NODEBUG =
68 typename __rebind_or_alias_pointer<_Alloc, __const_pointer_member, _Ptr, const _Tp>::type;
69_LIBCPP_SUPPRESS_DEPRECATED_POP
70
71// __void_pointer
72template <class _Alloc>
73using __void_pointer_member _LIBCPP_NODEBUG = typename _Alloc::void_pointer;
74
7375template <class _Ptr, class _Alloc>
74struct __void_pointer<_Ptr, _Alloc, false> {
75#ifdef _LIBCPP_CXX03_LANG
76 using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void>::other;
77#else
78 using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<void>;
79#endif
80};
76using __void_pointer_t _LIBCPP_NODEBUG =
77 typename __rebind_or_alias_pointer<_Alloc, __void_pointer_member, _Ptr, void>::type;
8178
8279// __const_void_pointer
83_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_const_void_pointer, const_void_pointer);
84template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
85struct __const_void_pointer {
86 using type _LIBCPP_NODEBUG = typename _Alloc::const_void_pointer;
87};
80template <class _Alloc>
81using __const_void_pointer_member _LIBCPP_NODEBUG = typename _Alloc::const_void_pointer;
82
8883template <class _Ptr, class _Alloc>
89struct __const_void_pointer<_Ptr, _Alloc, false> {
90#ifdef _LIBCPP_CXX03_LANG
91 using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const void>::other;
92#else
93 using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<const void>;
94#endif
95};
84using __const_void_pointer_t _LIBCPP_NODEBUG =
85 typename __rebind_or_alias_pointer<_Alloc, __const_void_pointer_member, _Ptr, const void>::type;
9686
9787// __size_type
9888template <class _Tp>
......@@ -102,13 +92,13 @@ template <class _Alloc, class _DiffType>
10292using __size_type _LIBCPP_NODEBUG = __detected_or_t<__make_unsigned_t<_DiffType>, __size_type_member, _Alloc>;
10393
10494// __alloc_traits_difference_type
105_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_alloc_traits_difference_type, difference_type);
106template <class _Alloc, class _Ptr, bool = __has_alloc_traits_difference_type<_Alloc>::value>
95template <class _Alloc, class _Ptr, class = void>
10796struct __alloc_traits_difference_type {
10897 using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::difference_type;
10998};
99
110100template <class _Alloc, class _Ptr>
111struct __alloc_traits_difference_type<_Alloc, _Ptr, true> {
101struct __alloc_traits_difference_type<_Alloc, _Ptr, __void_t<typename _Alloc::difference_type> > {
112102 using type _LIBCPP_NODEBUG = typename _Alloc::difference_type;
113103};
114104
......@@ -138,6 +128,7 @@ template <class _Alloc>
138128using __propagate_on_container_swap _LIBCPP_NODEBUG =
139129 __detected_or_t<false_type, __propagate_on_container_swap_member, _Alloc>;
140130
131_LIBCPP_SUPPRESS_DEPRECATED_PUSH
141132// __is_always_equal
142133template <class _Tp>
143134using __is_always_equal_member _LIBCPP_NODEBUG = typename _Tp::is_always_equal;
......@@ -147,15 +138,14 @@ using __is_always_equal _LIBCPP_NODEBUG =
147138 __detected_or_t<typename is_empty<_Alloc>::type, __is_always_equal_member, _Alloc>;
148139
149140// __allocator_traits_rebind
150_LIBCPP_SUPPRESS_DEPRECATED_PUSH
151141template <class _Tp, class _Up, class = void>
152struct __has_rebind_other : false_type {};
142inline const bool __has_rebind_other_v = false;
153143template <class _Tp, class _Up>
154struct __has_rebind_other<_Tp, _Up, __void_t<typename _Tp::template rebind<_Up>::other> > : true_type {};
144inline const bool __has_rebind_other_v<_Tp, _Up, __void_t<typename _Tp::template rebind<_Up>::other> > = true;
155145
156template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
146template <class _Tp, class _Up, bool = __has_rebind_other_v<_Tp, _Up> >
157147struct __allocator_traits_rebind {
158 static_assert(__has_rebind_other<_Tp, _Up>::value, "This allocator has to implement rebind");
148 static_assert(__has_rebind_other_v<_Tp, _Up>, "This allocator has to implement rebind");
159149 using type _LIBCPP_NODEBUG = typename _Tp::template rebind<_Up>::other;
160150};
161151template <template <class, class...> class _Alloc, class _Tp, class... _Args, class _Up>
......@@ -173,53 +163,52 @@ using __allocator_traits_rebind_t _LIBCPP_NODEBUG = typename __allocator_traits_
173163
174164_LIBCPP_SUPPRESS_DEPRECATED_PUSH
175165
176// __has_allocate_hint
166// __has_allocate_hint_v
177167template <class _Alloc, class _SizeType, class _ConstVoidPtr, class = void>
178struct __has_allocate_hint : false_type {};
168inline const bool __has_allocate_hint_v = false;
179169
180170template <class _Alloc, class _SizeType, class _ConstVoidPtr>
181struct __has_allocate_hint<
171inline const bool __has_allocate_hint_v<
182172 _Alloc,
183173 _SizeType,
184174 _ConstVoidPtr,
185 decltype((void)std::declval<_Alloc>().allocate(std::declval<_SizeType>(), std::declval<_ConstVoidPtr>()))>
186 : true_type {};
175 decltype((void)std::declval<_Alloc>().allocate(std::declval<_SizeType>(), std::declval<_ConstVoidPtr>()))> = true;
187176
188// __has_construct
177// __has_construct_v
189178template <class, class _Alloc, class... _Args>
190struct __has_construct_impl : false_type {};
179inline const bool __has_construct_impl = false;
191180
192181template <class _Alloc, class... _Args>
193struct __has_construct_impl<decltype((void)std::declval<_Alloc>().construct(std::declval<_Args>()...)),
194 _Alloc,
195 _Args...> : true_type {};
182inline const bool
183 __has_construct_impl<decltype((void)std::declval<_Alloc>().construct(std::declval<_Args>()...)), _Alloc, _Args...> =
184 true;
196185
197186template <class _Alloc, class... _Args>
198struct __has_construct : __has_construct_impl<void, _Alloc, _Args...> {};
187inline const bool __has_construct_v = __has_construct_impl<void, _Alloc, _Args...>;
199188
200// __has_destroy
189// __has_destroy_v
201190template <class _Alloc, class _Pointer, class = void>
202struct __has_destroy : false_type {};
191inline const bool __has_destroy_v = false;
203192
204193template <class _Alloc, class _Pointer>
205struct __has_destroy<_Alloc, _Pointer, decltype((void)std::declval<_Alloc>().destroy(std::declval<_Pointer>()))>
206 : true_type {};
194inline const bool
195 __has_destroy_v<_Alloc, _Pointer, decltype((void)std::declval<_Alloc>().destroy(std::declval<_Pointer>()))> = true;
207196
208// __has_max_size
197// __has_max_size_v
209198template <class _Alloc, class = void>
210struct __has_max_size : false_type {};
199inline const bool __has_max_size_v = false;
211200
212201template <class _Alloc>
213struct __has_max_size<_Alloc, decltype((void)std::declval<_Alloc&>().max_size())> : true_type {};
202inline const bool __has_max_size_v<_Alloc, decltype((void)std::declval<_Alloc&>().max_size())> = true;
214203
215// __has_select_on_container_copy_construction
204// __has_select_on_container_copy_construction_v
216205template <class _Alloc, class = void>
217struct __has_select_on_container_copy_construction : false_type {};
206inline const bool __has_select_on_container_copy_construction_v = false;
218207
219208template <class _Alloc>
220struct __has_select_on_container_copy_construction<
209inline const bool __has_select_on_container_copy_construction_v<
221210 _Alloc,
222 decltype((void)std::declval<_Alloc>().select_on_container_copy_construction())> : true_type {};
211 decltype((void)std::declval<_Alloc>().select_on_container_copy_construction())> = true;
223212
224213_LIBCPP_SUPPRESS_DEPRECATED_POP
225214
......@@ -235,13 +224,13 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(allocation_result);
235224#endif // _LIBCPP_STD_VER
236225
237226template <class _Alloc>
238struct _LIBCPP_TEMPLATE_VIS allocator_traits {
227struct allocator_traits {
239228 using allocator_type = _Alloc;
240229 using value_type = typename allocator_type::value_type;
241230 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;
231 using const_pointer = __const_pointer_t<value_type, pointer, allocator_type>;
232 using void_pointer = __void_pointer_t<pointer, allocator_type>;
233 using const_void_pointer = __const_void_pointer_t<pointer, allocator_type>;
245234 using difference_type = typename __alloc_traits_difference_type<allocator_type, pointer>::type;
246235 using size_type = __size_type<allocator_type, difference_type>;
247236 using propagate_on_container_copy_assignment = __propagate_on_container_copy_assignment<allocator_type>;
......@@ -270,16 +259,14 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits {
270259 return __a.allocate(__n);
271260 }
272261
273 template <class _Ap = _Alloc, __enable_if_t<__has_allocate_hint<_Ap, size_type, const_void_pointer>::value, int> = 0>
262 template <class _Ap = _Alloc, __enable_if_t<__has_allocate_hint_v<_Ap, size_type, const_void_pointer>, int> = 0>
274263 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer
275264 allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) {
276265 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
277266 return __a.allocate(__n, __hint);
278267 _LIBCPP_SUPPRESS_DEPRECATED_POP
279268 }
280 template <class _Ap = _Alloc,
281 class = void,
282 __enable_if_t<!__has_allocate_hint<_Ap, size_type, const_void_pointer>::value, int> = 0>
269 template <class _Ap = _Alloc, __enable_if_t<!__has_allocate_hint_v<_Ap, size_type, const_void_pointer>, int> = 0>
283270 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer
284271 allocate(allocator_type& __a, size_type __n, const_void_pointer) {
285272 return __a.allocate(__n);
......@@ -302,52 +289,47 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits {
302289 __a.deallocate(__p, __n);
303290 }
304291
305 template <class _Tp, class... _Args, __enable_if_t<__has_construct<allocator_type, _Tp*, _Args...>::value, int> = 0>
292 template <class _Tp, class... _Args, __enable_if_t<__has_construct_v<allocator_type, _Tp*, _Args...>, int> = 0>
306293 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void
307294 construct(allocator_type& __a, _Tp* __p, _Args&&... __args) {
308295 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
309296 __a.construct(__p, std::forward<_Args>(__args)...);
310297 _LIBCPP_SUPPRESS_DEPRECATED_POP
311298 }
312 template <class _Tp,
313 class... _Args,
314 class = void,
315 __enable_if_t<!__has_construct<allocator_type, _Tp*, _Args...>::value, int> = 0>
299 template <class _Tp, class... _Args, __enable_if_t<!__has_construct_v<allocator_type, _Tp*, _Args...>, int> = 0>
316300 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void
317301 construct(allocator_type&, _Tp* __p, _Args&&... __args) {
318302 std::__construct_at(__p, std::forward<_Args>(__args)...);
319303 }
320304
321 template <class _Tp, __enable_if_t<__has_destroy<allocator_type, _Tp*>::value, int> = 0>
305 template <class _Tp, __enable_if_t<__has_destroy_v<allocator_type, _Tp*>, int> = 0>
322306 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void destroy(allocator_type& __a, _Tp* __p) {
323307 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
324308 __a.destroy(__p);
325309 _LIBCPP_SUPPRESS_DEPRECATED_POP
326310 }
327 template <class _Tp, class = void, __enable_if_t<!__has_destroy<allocator_type, _Tp*>::value, int> = 0>
311 template <class _Tp, __enable_if_t<!__has_destroy_v<allocator_type, _Tp*>, int> = 0>
328312 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void destroy(allocator_type&, _Tp* __p) {
329313 std::__destroy_at(__p);
330314 }
331315
332 template <class _Ap = _Alloc, __enable_if_t<__has_max_size<const _Ap>::value, int> = 0>
316 template <class _Ap = _Alloc, __enable_if_t<__has_max_size_v<const _Ap>, int> = 0>
333317 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type max_size(const allocator_type& __a) _NOEXCEPT {
334318 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
335319 return __a.max_size();
336320 _LIBCPP_SUPPRESS_DEPRECATED_POP
337321 }
338 template <class _Ap = _Alloc, class = void, __enable_if_t<!__has_max_size<const _Ap>::value, int> = 0>
322 template <class _Ap = _Alloc, __enable_if_t<!__has_max_size_v<const _Ap>, int> = 0>
339323 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type max_size(const allocator_type&) _NOEXCEPT {
340324 return numeric_limits<size_type>::max() / sizeof(value_type);
341325 }
342326
343 template <class _Ap = _Alloc, __enable_if_t<__has_select_on_container_copy_construction<const _Ap>::value, int> = 0>
327 template <class _Ap = _Alloc, __enable_if_t<__has_select_on_container_copy_construction_v<const _Ap>, int> = 0>
344328 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static allocator_type
345329 select_on_container_copy_construction(const allocator_type& __a) {
346330 return __a.select_on_container_copy_construction();
347331 }
348 template <class _Ap = _Alloc,
349 class = void,
350 __enable_if_t<!__has_select_on_container_copy_construction<const _Ap>::value, int> = 0>
332 template <class _Ap = _Alloc, __enable_if_t<!__has_select_on_container_copy_construction_v<const _Ap>, int> = 0>
351333 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static allocator_type
352334 select_on_container_copy_construction(const allocator_type& __a) {
353335 return __a;
......@@ -370,42 +352,27 @@ struct __check_valid_allocator : true_type {
370352 "original allocator");
371353};
372354
373// __is_default_allocator
355// __is_default_allocator_v
374356template <class _Tp>
375struct __is_default_allocator : false_type {};
376
377template <class>
378class allocator;
357inline const bool __is_std_allocator_v = false;
379358
380359template <class _Tp>
381struct __is_default_allocator<allocator<_Tp> > : true_type {};
382
383// __is_cpp17_move_insertable
384template <class _Alloc, class = void>
385struct __is_cpp17_move_insertable : is_move_constructible<typename _Alloc::value_type> {};
360inline const bool __is_std_allocator_v<allocator<_Tp> > = true;
386361
362// __is_cpp17_move_insertable_v
387363template <class _Alloc>
388struct __is_cpp17_move_insertable<
389 _Alloc,
390 __enable_if_t< !__is_default_allocator<_Alloc>::value &&
391 __has_construct<_Alloc, typename _Alloc::value_type*, typename _Alloc::value_type&&>::value > >
392 : true_type {};
393
394// __is_cpp17_copy_insertable
395template <class _Alloc, class = void>
396struct __is_cpp17_copy_insertable
397 : integral_constant<bool,
398 is_copy_constructible<typename _Alloc::value_type>::value &&
399 __is_cpp17_move_insertable<_Alloc>::value > {};
364inline const bool __is_cpp17_move_insertable_v =
365 is_move_constructible<typename _Alloc::value_type>::value ||
366 (!__is_std_allocator_v<_Alloc> &&
367 __has_construct_v<_Alloc, typename _Alloc::value_type*, typename _Alloc::value_type&&>);
400368
369// __is_cpp17_copy_insertable_v
401370template <class _Alloc>
402struct __is_cpp17_copy_insertable<
403 _Alloc,
404 __enable_if_t< !__is_default_allocator<_Alloc>::value &&
405 __has_construct<_Alloc, typename _Alloc::value_type*, const typename _Alloc::value_type&>::value > >
406 : __is_cpp17_move_insertable<_Alloc> {};
407
408#undef _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX
371inline const bool __is_cpp17_copy_insertable_v =
372 __is_cpp17_move_insertable_v<_Alloc> &&
373 (is_copy_constructible<typename _Alloc::value_type>::value ||
374 (!__is_std_allocator_v<_Alloc> &&
375 __has_construct_v<_Alloc, typename _Alloc::value_type*, const typename _Alloc::value_type&>));
409376
410377_LIBCPP_END_NAMESPACE_STD
411378
lib/libcxx/include/__memory/auto_ptr.h+2-2
......@@ -26,7 +26,7 @@ struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref {
2626};
2727
2828template <class _Tp>
29class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr {
29class _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr {
3030private:
3131 _Tp* __ptr_;
3232
......@@ -80,7 +80,7 @@ public:
8080};
8181
8282template <>
83class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void> {
83class _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void> {
8484public:
8585 typedef void element_type;
8686};
lib/libcxx/include/__memory/compressed_pair.h+50-19
......@@ -15,7 +15,6 @@
1515#include <__type_traits/datasizeof.h>
1616#include <__type_traits/is_empty.h>
1717#include <__type_traits/is_final.h>
18#include <__type_traits/is_reference.h>
1918
2019#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2120# pragma GCC system_header
......@@ -63,9 +62,17 @@ inline const size_t __compressed_pair_alignment = _LIBCPP_ALIGNOF(_Tp);
6362template <class _Tp>
6463inline const size_t __compressed_pair_alignment<_Tp&> = _LIBCPP_ALIGNOF(void*);
6564
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>)>
65template <class _ToPad>
66inline const bool __is_reference_or_unpadded_object =
67 (is_empty<_ToPad>::value && !__libcpp_is_final<_ToPad>::value) || sizeof(_ToPad) == __datasizeof_v<_ToPad>;
68
69template <class _Tp>
70inline const bool __is_reference_or_unpadded_object<_Tp&> = true;
71
72template <class _Tp>
73inline const bool __is_reference_or_unpadded_object<_Tp&&> = true;
74
75template <class _ToPad, bool _Empty = __is_reference_or_unpadded_object<_ToPad> >
6976class __compressed_pair_padding {
7077 char __padding_[sizeof(_ToPad) - __datasizeof_v<_ToPad>] = {};
7178};
......@@ -73,21 +80,45 @@ class __compressed_pair_padding {
7380template <class _ToPad>
7481class __compressed_pair_padding<_ToPad, true> {};
7582
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__, _)
83// TODO: Fix the ABI for GCC as well once https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121637 is fixed
84# ifdef _LIBCPP_COMPILER_GCC
85# define _LIBCPP_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2) \
86 _LIBCPP_NO_UNIQUE_ADDRESS __attribute__((__aligned__(::std::__compressed_pair_alignment<T2>))) T1 Initializer1; \
87 _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T1> _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \
88 _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \
89 _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T2> _LIBCPP_CONCAT3(__padding2_, __LINE__, _)
90
91# define _LIBCPP_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3, Initializer3) \
92 _LIBCPP_NO_UNIQUE_ADDRESS \
93 __attribute__((__aligned__(::std::__compressed_pair_alignment<T2>), \
94 __aligned__(::std::__compressed_pair_alignment<T3>))) T1 Initializer1; \
95 _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T1> _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \
96 _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \
97 _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T2> _LIBCPP_CONCAT3(__padding2_, __LINE__, _); \
98 _LIBCPP_NO_UNIQUE_ADDRESS T3 Initializer3; \
99 _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T3> _LIBCPP_CONCAT3(__padding3_, __LINE__, _)
100# else
101# define _LIBCPP_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2) \
102 struct { \
103 _LIBCPP_NO_UNIQUE_ADDRESS \
104 __attribute__((__aligned__(::std::__compressed_pair_alignment<T2>))) T1 Initializer1; \
105 _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T1> _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \
106 _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \
107 _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T2> _LIBCPP_CONCAT3(__padding2_, __LINE__, _); \
108 }
109
110# define _LIBCPP_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3, Initializer3) \
111 struct { \
112 _LIBCPP_NO_UNIQUE_ADDRESS \
113 __attribute__((__aligned__(::std::__compressed_pair_alignment<T2>), \
114 __aligned__(::std::__compressed_pair_alignment<T3>))) T1 Initializer1; \
115 _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T1> _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \
116 _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \
117 _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T2> _LIBCPP_CONCAT3(__padding2_, __LINE__, _); \
118 _LIBCPP_NO_UNIQUE_ADDRESS T3 Initializer3; \
119 _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T3> _LIBCPP_CONCAT3(__padding3_, __LINE__, _); \
120 }
121# endif
91122
92123#else
93124# define _LIBCPP_COMPRESSED_PAIR(T1, Name1, T2, Name2) \
lib/libcxx/include/__memory/construct_at.h+4-38
......@@ -12,14 +12,12 @@
1212
1313#include <__assert>
1414#include <__config>
15#include <__iterator/access.h>
1615#include <__memory/addressof.h>
1716#include <__new/placement_new_delete.h>
1817#include <__type_traits/enable_if.h>
1918#include <__type_traits/is_array.h>
2019#include <__utility/declval.h>
2120#include <__utility/forward.h>
22#include <__utility/move.h>
2321
2422#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2523# pragma GCC system_header
......@@ -57,9 +55,6 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* __construct_at(_Tp* __l
5755// The internal functions are available regardless of the language version (with the exception of the `__destroy_at`
5856// taking an array).
5957
60template <class _ForwardIterator>
61_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator __destroy(_ForwardIterator, _ForwardIterator);
62
6358template <class _Tp, __enable_if_t<!is_array<_Tp>::value, int> = 0>
6459_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __destroy_at(_Tp* __loc) {
6560 _LIBCPP_ASSERT_NON_NULL(__loc != nullptr, "null pointer given to destroy_at");
......@@ -68,30 +63,13 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __destroy_at(_Tp* __loc
6863
6964#if _LIBCPP_STD_VER >= 20
7065template <class _Tp, __enable_if_t<is_array<_Tp>::value, int> = 0>
71_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __destroy_at(_Tp* __loc) {
66_LIBCPP_HIDE_FROM_ABI constexpr void __destroy_at(_Tp* __loc) {
7267 _LIBCPP_ASSERT_NON_NULL(__loc != nullptr, "null pointer given to destroy_at");
73 std::__destroy(std::begin(*__loc), std::end(*__loc));
68 for (auto&& __val : *__loc)
69 std::__destroy_at(std::addressof(__val));
7470}
7571#endif
7672
77template <class _ForwardIterator>
78_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
79__destroy(_ForwardIterator __first, _ForwardIterator __last) {
80 for (; __first != __last; ++__first)
81 std::__destroy_at(std::addressof(*__first));
82 return __first;
83}
84
85template <class _BidirectionalIterator>
86_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _BidirectionalIterator
87__reverse_destroy(_BidirectionalIterator __first, _BidirectionalIterator __last) {
88 while (__last != __first) {
89 --__last;
90 std::__destroy_at(std::addressof(*__last));
91 }
92 return __last;
93}
94
9573#if _LIBCPP_STD_VER >= 17
9674
9775template <class _Tp, enable_if_t<!is_array_v<_Tp>, int> = 0>
......@@ -101,23 +79,11 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void destroy_at(_Tp* __loc)
10179
10280# if _LIBCPP_STD_VER >= 20
10381template <class _Tp, enable_if_t<is_array_v<_Tp>, int> = 0>
104_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void destroy_at(_Tp* __loc) {
82_LIBCPP_HIDE_FROM_ABI constexpr void destroy_at(_Tp* __loc) {
10583 std::__destroy_at(__loc);
10684}
10785# endif
10886
109template <class _ForwardIterator>
110_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void destroy(_ForwardIterator __first, _ForwardIterator __last) {
111 (void)std::__destroy(std::move(__first), std::move(__last));
112}
113
114template <class _ForwardIterator, class _Size>
115_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
116 for (; __n > 0; (void)++__first, --__n)
117 std::__destroy_at(std::addressof(*__first));
118 return __first;
119}
120
12187#endif // _LIBCPP_STD_VER >= 17
12288
12389_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__memory/destroy.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___MEMORY_DESTROY_H
10#define _LIBCPP___MEMORY_DESTROY_H
11
12#include <__config>
13#include <__memory/addressof.h>
14#include <__memory/allocator_traits.h>
15#include <__memory/construct_at.h>
16#include <__utility/move.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_PUSH_MACROS
23#include <__undef_macros>
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27template <class _ForwardIterator>
28_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
29__destroy(_ForwardIterator __first, _ForwardIterator __last) {
30 for (; __first != __last; ++__first)
31 std::__destroy_at(std::addressof(*__first));
32 return __first;
33}
34
35template <class _BidirectionalIterator>
36_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _BidirectionalIterator
37__reverse_destroy(_BidirectionalIterator __first, _BidirectionalIterator __last) {
38 while (__last != __first) {
39 --__last;
40 std::__destroy_at(std::addressof(*__last));
41 }
42 return __last;
43}
44
45// Destroy all elements in [__first, __last) from left to right using allocator destruction.
46template <class _Alloc, class _Iter, class _Sent>
47_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
48__allocator_destroy(_Alloc& __alloc, _Iter __first, _Sent __last) {
49 for (; __first != __last; ++__first)
50 allocator_traits<_Alloc>::destroy(__alloc, std::addressof(*__first));
51}
52
53#if _LIBCPP_STD_VER >= 17
54template <class _ForwardIterator>
55_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void destroy(_ForwardIterator __first, _ForwardIterator __last) {
56 (void)std::__destroy(std::move(__first), std::move(__last));
57}
58
59template <class _ForwardIterator, class _Size>
60_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
61 for (; __n > 0; (void)++__first, --__n)
62 std::__destroy_at(std::addressof(*__first));
63 return __first;
64}
65#endif
66
67_LIBCPP_END_NAMESPACE_STD
68
69_LIBCPP_POP_MACROS
70
71#endif // _LIBCPP___MEMORY_DESTROY_H
lib/libcxx/include/__memory/inout_ptr.h+1-1
......@@ -35,7 +35,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3535#if _LIBCPP_STD_VER >= 23
3636
3737template <class _Smart, class _Pointer, class... _Args>
38class _LIBCPP_TEMPLATE_VIS inout_ptr_t {
38class inout_ptr_t {
3939 static_assert(!__is_specialization_v<_Smart, shared_ptr>, "std::shared_ptr<> is not supported with std::inout_ptr.");
4040
4141public:
lib/libcxx/include/__memory/is_sufficiently_aligned.h created+34
......@@ -0,0 +1,34 @@
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_IS_SUFFICIENTLY_ALIGNED_H
11#define _LIBCPP___MEMORY_IS_SUFFICIENTLY_ALIGNED_H
12
13#include <__config>
14#include <__cstddef/size_t.h>
15#include <cstdint>
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#if _LIBCPP_STD_VER >= 26
24
25template <size_t _Alignment, class _Tp>
26_LIBCPP_HIDE_FROM_ABI bool is_sufficiently_aligned(_Tp* __ptr) {
27 return reinterpret_cast<uintptr_t>(__ptr) % _Alignment == 0;
28}
29
30#endif // _LIBCPP_STD_VER >= 26
31
32_LIBCPP_END_NAMESPACE_STD
33
34#endif // _LIBCPP___MEMORY_IS_SUFFICIENTLY_ALIGNED_H
lib/libcxx/include/__memory/out_ptr.h+1-1
......@@ -34,7 +34,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3434#if _LIBCPP_STD_VER >= 23
3535
3636template <class _Smart, class _Pointer, class... _Args>
37class _LIBCPP_TEMPLATE_VIS out_ptr_t {
37class out_ptr_t {
3838 static_assert(!__is_specialization_v<_Smart, shared_ptr> || sizeof...(_Args) > 0,
3939 "Using std::shared_ptr<> without a deleter in std::out_ptr is not supported.");
4040
lib/libcxx/include/__memory/pointer_traits.h+52-90
......@@ -16,11 +16,13 @@
1616#include <__type_traits/conditional.h>
1717#include <__type_traits/conjunction.h>
1818#include <__type_traits/decay.h>
19#include <__type_traits/detected_or.h>
1920#include <__type_traits/enable_if.h>
2021#include <__type_traits/integral_constant.h>
2122#include <__type_traits/is_class.h>
2223#include <__type_traits/is_function.h>
2324#include <__type_traits/is_void.h>
25#include <__type_traits/nat.h>
2426#include <__type_traits/void_t.h>
2527#include <__utility/declval.h>
2628#include <__utility/forward.h>
......@@ -34,67 +36,37 @@ _LIBCPP_PUSH_MACROS
3436
3537_LIBCPP_BEGIN_NAMESPACE_STD
3638
37// clang-format off
38#define _LIBCPP_CLASS_TRAITS_HAS_XXX(NAME, PROPERTY) \
39 template <class _Tp, class = void> \
40 struct NAME : false_type {}; \
41 template <class _Tp> \
42 struct NAME<_Tp, __void_t<typename _Tp::PROPERTY> > : true_type {}
43// clang-format on
44
45_LIBCPP_CLASS_TRAITS_HAS_XXX(__has_pointer, pointer);
46_LIBCPP_CLASS_TRAITS_HAS_XXX(__has_element_type, element_type);
47
48template <class _Ptr, bool = __has_element_type<_Ptr>::value>
49struct __pointer_traits_element_type {};
50
5139template <class _Ptr>
52struct __pointer_traits_element_type<_Ptr, true> {
53 using type _LIBCPP_NODEBUG = typename _Ptr::element_type;
54};
40struct __pointer_traits_element_type_impl {};
5541
5642template <template <class, class...> class _Sp, class _Tp, class... _Args>
57struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true> {
58 using type _LIBCPP_NODEBUG = typename _Sp<_Tp, _Args...>::element_type;
59};
60
61template <template <class, class...> class _Sp, class _Tp, class... _Args>
62struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false> {
43struct __pointer_traits_element_type_impl<_Sp<_Tp, _Args...> > {
6344 using type _LIBCPP_NODEBUG = _Tp;
6445};
6546
66template <class _Tp, class = void>
67struct __has_difference_type : false_type {};
68
69template <class _Tp>
70struct __has_difference_type<_Tp, __void_t<typename _Tp::difference_type> > : true_type {};
71
72template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
73struct __pointer_traits_difference_type {
74 using type _LIBCPP_NODEBUG = ptrdiff_t;
75};
47template <class _Ptr, class = void>
48struct __pointer_traits_element_type : __pointer_traits_element_type_impl<_Ptr> {};
7649
7750template <class _Ptr>
78struct __pointer_traits_difference_type<_Ptr, true> {
79 using type _LIBCPP_NODEBUG = typename _Ptr::difference_type;
51struct __pointer_traits_element_type<_Ptr, __void_t<typename _Ptr::element_type> > {
52 using type _LIBCPP_NODEBUG = typename _Ptr::element_type;
8053};
8154
8255template <class _Tp, class _Up>
83struct __has_rebind {
84private:
85 template <class _Xp>
86 static false_type __test(...);
87 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
88 template <class _Xp>
89 static true_type __test(typename _Xp::template rebind<_Up>* = 0);
90 _LIBCPP_SUPPRESS_DEPRECATED_POP
56struct __pointer_traits_rebind_impl {
57 static_assert(false, "Cannot rebind pointer; did you forget to add a rebind member to your pointer?");
58};
9159
92public:
93 static const bool value = decltype(__test<_Tp>(0))::value;
60template <template <class, class...> class _Sp, class _Tp, class... _Args, class _Up>
61struct __pointer_traits_rebind_impl<_Sp<_Tp, _Args...>, _Up> {
62 using type _LIBCPP_NODEBUG = _Sp<_Up, _Args...>;
9463};
9564
96template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
97struct __pointer_traits_rebind {
65template <class _Tp, class _Up, class = void>
66struct __pointer_traits_rebind : __pointer_traits_rebind_impl<_Tp, _Up> {};
67
68template <class _Tp, class _Up>
69struct __pointer_traits_rebind<_Tp, _Up, __void_t<typename _Tp::template rebind<_Up> > > {
9870#ifndef _LIBCPP_CXX03_LANG
9971 using type _LIBCPP_NODEBUG = typename _Tp::template rebind<_Up>;
10072#else
......@@ -102,19 +74,8 @@ struct __pointer_traits_rebind {
10274#endif
10375};
10476
105template <template <class, class...> class _Sp, class _Tp, class... _Args, class _Up>
106struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true> {
107#ifndef _LIBCPP_CXX03_LANG
108 using type _LIBCPP_NODEBUG = typename _Sp<_Tp, _Args...>::template rebind<_Up>;
109#else
110 using type _LIBCPP_NODEBUG = typename _Sp<_Tp, _Args...>::template rebind<_Up>::other;
111#endif
112};
113
114template <template <class, class...> class _Sp, class _Tp, class... _Args, class _Up>
115struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false> {
116 typedef _Sp<_Up, _Args...> type;
117};
77template <class _Tp>
78using __difference_type_member _LIBCPP_NODEBUG = typename _Tp::difference_type;
11879
11980template <class _Ptr, class = void>
12081struct __pointer_traits_impl {};
......@@ -123,7 +84,7 @@ template <class _Ptr>
12384struct __pointer_traits_impl<_Ptr, __void_t<typename __pointer_traits_element_type<_Ptr>::type> > {
12485 typedef _Ptr pointer;
12586 typedef typename __pointer_traits_element_type<pointer>::type element_type;
126 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
87 using difference_type = __detected_or_t<ptrdiff_t, __difference_type_member, pointer>;
12788
12889#ifndef _LIBCPP_CXX03_LANG
12990 template <class _Up>
......@@ -135,9 +96,6 @@ struct __pointer_traits_impl<_Ptr, __void_t<typename __pointer_traits_element_ty
13596 };
13697#endif // _LIBCPP_CXX03_LANG
13798
138private:
139 struct __nat {};
140
14199public:
142100 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer
143101 pointer_to(__conditional_t<is_void<element_type>::value, __nat, element_type>& __r) {
......@@ -146,10 +104,10 @@ public:
146104};
147105
148106template <class _Ptr>
149struct _LIBCPP_TEMPLATE_VIS pointer_traits : __pointer_traits_impl<_Ptr> {};
107struct pointer_traits : __pointer_traits_impl<_Ptr> {};
150108
151109template <class _Tp>
152struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*> {
110struct pointer_traits<_Tp*> {
153111 typedef _Tp* pointer;
154112 typedef _Tp element_type;
155113 typedef ptrdiff_t difference_type;
......@@ -164,9 +122,6 @@ struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*> {
164122 };
165123#endif
166124
167private:
168 struct __nat {};
169
170125public:
171126 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer
172127 pointer_to(__conditional_t<is_void<element_type>::value, __nat, element_type>& __r) _NOEXCEPT {
......@@ -245,8 +200,8 @@ inline _LIBCPP_HIDE_FROM_ABI constexpr auto to_address(_Tp* __p) noexcept {
245200}
246201
247202template <class _Pointer>
248inline _LIBCPP_HIDE_FROM_ABI constexpr auto
249to_address(const _Pointer& __p) noexcept -> decltype(std::__to_address(__p)) {
203inline _LIBCPP_HIDE_FROM_ABI constexpr auto to_address(const _Pointer& __p) noexcept
204 -> decltype(std::__to_address(__p)) {
250205 return std::__to_address(__p);
251206}
252207#endif
......@@ -257,40 +212,35 @@ template <class _Tp>
257212struct __pointer_of {};
258213
259214template <class _Tp>
260 requires(__has_pointer<_Tp>::value)
215concept __has_pointer_member = requires { typename _Tp::pointer; };
216
217template <class _Tp>
218concept __has_element_type_member = requires { typename _Tp::element_type; };
219
220template <class _Tp>
221 requires __has_pointer_member<_Tp>
261222struct __pointer_of<_Tp> {
262 using type = typename _Tp::pointer;
223 using type _LIBCPP_NODEBUG = typename _Tp::pointer;
263224};
264225
265226template <class _Tp>
266 requires(!__has_pointer<_Tp>::value && __has_element_type<_Tp>::value)
227 requires(!__has_pointer_member<_Tp> && __has_element_type_member<_Tp>)
267228struct __pointer_of<_Tp> {
268 using type = typename _Tp::element_type*;
229 using type _LIBCPP_NODEBUG = typename _Tp::element_type*;
269230};
270231
271232template <class _Tp>
272 requires(!__has_pointer<_Tp>::value && !__has_element_type<_Tp>::value &&
273 __has_element_type<pointer_traits<_Tp>>::value)
233 requires(!__has_pointer_member<_Tp> && !__has_element_type_member<_Tp> &&
234 __has_element_type_member<pointer_traits<_Tp>>)
274235struct __pointer_of<_Tp> {
275 using type = typename pointer_traits<_Tp>::element_type*;
236 using type _LIBCPP_NODEBUG = typename pointer_traits<_Tp>::element_type*;
276237};
277238
278239template <typename _Tp>
279240using __pointer_of_t _LIBCPP_NODEBUG = typename __pointer_of<_Tp>::type;
280241
281template <class _Tp, class _Up>
282struct __pointer_of_or {
283 using type _LIBCPP_NODEBUG = _Up;
284};
285
286template <class _Tp, class _Up>
287 requires requires { typename __pointer_of_t<_Tp>; }
288struct __pointer_of_or<_Tp, _Up> {
289 using type _LIBCPP_NODEBUG = __pointer_of_t<_Tp>;
290};
291
292242template <typename _Tp, typename _Up>
293using __pointer_of_or_t _LIBCPP_NODEBUG = typename __pointer_of_or<_Tp, _Up>::type;
243using __pointer_of_or_t _LIBCPP_NODEBUG = __detected_or_t<_Up, __pointer_of_t, _Tp>;
294244
295245template <class _Smart>
296246concept __resettable_smart_pointer = requires(_Smart __s) { __s.reset(); };
......@@ -302,6 +252,18 @@ concept __resettable_smart_pointer_with_args = requires(_Smart __s, _Pointer __p
302252
303253#endif
304254
255// This function ensures safe conversions between fancy pointers at compile-time, where we avoid casts from/to
256// `__void_pointer` by obtaining the underlying raw pointer from the fancy pointer using `std::to_address`,
257// then dereferencing it to retrieve the pointed-to object, and finally constructing the target fancy pointer
258// to that object using the `std::pointer_traits<>::pinter_to` function.
259template <class _PtrTo, class _PtrFrom>
260_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _PtrTo __static_fancy_pointer_cast(const _PtrFrom& __p) {
261 using __ptr_traits = pointer_traits<_PtrTo>;
262 using __element_type = typename __ptr_traits::element_type;
263 return __p ? __ptr_traits::pointer_to(*static_cast<__element_type*>(std::addressof(*__p)))
264 : static_cast<_PtrTo>(nullptr);
265}
266
305267_LIBCPP_END_NAMESPACE_STD
306268
307269_LIBCPP_POP_MACROS
lib/libcxx/include/__memory/ranges_construct_at.h-35
......@@ -61,41 +61,6 @@ inline namespace __cpo {
6161inline constexpr auto destroy_at = __destroy_at{};
6262} // namespace __cpo
6363
64// destroy
65
66struct __destroy {
67 template <__nothrow_input_iterator _InputIterator, __nothrow_sentinel_for<_InputIterator> _Sentinel>
68 requires destructible<iter_value_t<_InputIterator>>
69 _LIBCPP_HIDE_FROM_ABI constexpr _InputIterator operator()(_InputIterator __first, _Sentinel __last) const noexcept {
70 return std::__destroy(std::move(__first), std::move(__last));
71 }
72
73 template <__nothrow_input_range _InputRange>
74 requires destructible<range_value_t<_InputRange>>
75 _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_InputRange> operator()(_InputRange&& __range) const noexcept {
76 return (*this)(ranges::begin(__range), ranges::end(__range));
77 }
78};
79
80inline namespace __cpo {
81inline constexpr auto destroy = __destroy{};
82} // namespace __cpo
83
84// destroy_n
85
86struct __destroy_n {
87 template <__nothrow_input_iterator _InputIterator>
88 requires destructible<iter_value_t<_InputIterator>>
89 _LIBCPP_HIDE_FROM_ABI constexpr _InputIterator
90 operator()(_InputIterator __first, iter_difference_t<_InputIterator> __n) const noexcept {
91 return std::destroy_n(std::move(__first), __n);
92 }
93};
94
95inline namespace __cpo {
96inline constexpr auto destroy_n = __destroy_n{};
97} // namespace __cpo
98
9964} // namespace ranges
10065
10166#endif // _LIBCPP_STD_VER >= 20
lib/libcxx/include/__memory/ranges_destroy.h created+79
......@@ -0,0 +1,79 @@
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_RANGES_DESTROY_H
11#define _LIBCPP___MEMORY_RANGES_DESTROY_H
12
13#include <__concepts/destructible.h>
14#include <__config>
15#include <__iterator/incrementable_traits.h>
16#include <__iterator/iterator_traits.h>
17#include <__memory/concepts.h>
18#include <__memory/destroy.h>
19#include <__ranges/access.h>
20#include <__ranges/concepts.h>
21#include <__ranges/dangling.h>
22#include <__utility/move.h>
23
24#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25# pragma GCC system_header
26#endif
27
28_LIBCPP_PUSH_MACROS
29#include <__undef_macros>
30
31_LIBCPP_BEGIN_NAMESPACE_STD
32
33#if _LIBCPP_STD_VER >= 20
34namespace ranges {
35
36// destroy
37
38struct __destroy {
39 template <__nothrow_input_iterator _InputIterator, __nothrow_sentinel_for<_InputIterator> _Sentinel>
40 requires destructible<iter_value_t<_InputIterator>>
41 _LIBCPP_HIDE_FROM_ABI constexpr _InputIterator operator()(_InputIterator __first, _Sentinel __last) const noexcept {
42 return std::__destroy(std::move(__first), std::move(__last));
43 }
44
45 template <__nothrow_input_range _InputRange>
46 requires destructible<range_value_t<_InputRange>>
47 _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_InputRange> operator()(_InputRange&& __range) const noexcept {
48 return (*this)(ranges::begin(__range), ranges::end(__range));
49 }
50};
51
52inline namespace __cpo {
53inline constexpr auto destroy = __destroy{};
54} // namespace __cpo
55
56// destroy_n
57
58struct __destroy_n {
59 template <__nothrow_input_iterator _InputIterator>
60 requires destructible<iter_value_t<_InputIterator>>
61 _LIBCPP_HIDE_FROM_ABI constexpr _InputIterator
62 operator()(_InputIterator __first, iter_difference_t<_InputIterator> __n) const noexcept {
63 return std::destroy_n(std::move(__first), __n);
64 }
65};
66
67inline namespace __cpo {
68inline constexpr auto destroy_n = __destroy_n{};
69} // namespace __cpo
70
71} // namespace ranges
72
73#endif // _LIBCPP_STD_VER >= 20
74
75_LIBCPP_END_NAMESPACE_STD
76
77_LIBCPP_POP_MACROS
78
79#endif // _LIBCPP___MEMORY_RANGES_DESTROY_H
lib/libcxx/include/__memory/raw_storage_iterator.h+1-1
......@@ -30,7 +30,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3030
3131_LIBCPP_SUPPRESS_DEPRECATED_PUSH
3232template <class _OutputIterator, class _Tp>
33class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 raw_storage_iterator
33class _LIBCPP_DEPRECATED_IN_CXX17 raw_storage_iterator
3434# if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
3535 : public iterator<output_iterator_tag, void, void, void, void>
3636# endif
lib/libcxx/include/__memory/shared_count.h+3-2
......@@ -10,6 +10,7 @@
1010#define _LIBCPP___MEMORY_SHARED_COUNT_H
1111
1212#include <__config>
13#include <__memory/addressof.h>
1314#include <typeinfo>
1415
1516#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -52,7 +53,7 @@ inline _LIBCPP_HIDE_FROM_ABI _ValueType __libcpp_acquire_load(_ValueType const*
5253template <class _Tp>
5354inline _LIBCPP_HIDE_FROM_ABI _Tp __libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT {
5455#if _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT && _LIBCPP_HAS_THREADS
55 return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED);
56 return __atomic_add_fetch(std::addressof(__t), 1, __ATOMIC_RELAXED);
5657#else
5758 return __t += 1;
5859#endif
......@@ -61,7 +62,7 @@ inline _LIBCPP_HIDE_FROM_ABI _Tp __libcpp_atomic_refcount_increment(_Tp& __t) _N
6162template <class _Tp>
6263inline _LIBCPP_HIDE_FROM_ABI _Tp __libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT {
6364#if _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT && _LIBCPP_HAS_THREADS
64 return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL);
65 return __atomic_add_fetch(std::addressof(__t), -1, __ATOMIC_ACQ_REL);
6566#else
6667 return __t -= 1;
6768#endif
lib/libcxx/include/__memory/shared_ptr.h+23-19
......@@ -29,11 +29,12 @@
2929#include <__memory/auto_ptr.h>
3030#include <__memory/compressed_pair.h>
3131#include <__memory/construct_at.h>
32#include <__memory/destroy.h>
3233#include <__memory/pointer_traits.h>
3334#include <__memory/shared_count.h>
3435#include <__memory/uninitialized_algorithms.h>
3536#include <__memory/unique_ptr.h>
36#include <__type_traits/add_lvalue_reference.h>
37#include <__type_traits/add_reference.h>
3738#include <__type_traits/conditional.h>
3839#include <__type_traits/conjunction.h>
3940#include <__type_traits/disjunction.h>
......@@ -89,7 +90,7 @@ public:
8990}
9091
9192template <class _Tp>
92class _LIBCPP_TEMPLATE_VIS weak_ptr;
93class weak_ptr;
9394
9495template <class _Tp, class _Dp, class _Alloc>
9596class __shared_ptr_pointer : public __shared_weak_count {
......@@ -217,7 +218,7 @@ private:
217218
218219struct __shared_ptr_dummy_rebind_allocator_type;
219220template <>
220class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type> {
221class allocator<__shared_ptr_dummy_rebind_allocator_type> {
221222public:
222223 template <class _Other>
223224 struct rebind {
......@@ -226,7 +227,7 @@ public:
226227};
227228
228229template <class _Tp>
229class _LIBCPP_TEMPLATE_VIS enable_shared_from_this;
230class enable_shared_from_this;
230231
231232// http://eel.is/c++draft/util.sharedptr#util.smartptr.shared.general-6
232233// A pointer type Y* is said to be compatible with a pointer type T*
......@@ -303,7 +304,7 @@ using __shared_ptr_nullptr_deleter_ctor_reqs _LIBCPP_NODEBUG =
303304#endif
304305
305306template <class _Tp>
306class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr {
307class _LIBCPP_SHARED_PTR_TRIVIAL_ABI shared_ptr {
307308 struct __nullptr_sfinae_tag {};
308309
309310public:
......@@ -315,8 +316,10 @@ public:
315316#endif
316317
317318 // A shared_ptr contains only two raw pointers which point to the heap and move constructing already doesn't require
318 // any bookkeeping, so it's always trivially relocatable.
319 // any bookkeeping, so it's always trivially relocatable. It is also replaceable because assignment just rebinds the
320 // shared_ptr to manage a different object.
319321 using __trivially_relocatable _LIBCPP_NODEBUG = shared_ptr;
322 using __replaceable _LIBCPP_NODEBUG = shared_ptr;
320323
321324private:
322325 element_type* __ptr_;
......@@ -496,7 +499,7 @@ public:
496499 _LIBCPP_HIDE_FROM_ABI explicit shared_ptr(const weak_ptr<_Yp>& __r)
497500 : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_) {
498501 if (__cntrl_ == nullptr)
499 __throw_bad_weak_ptr();
502 std::__throw_bad_weak_ptr();
500503 }
501504
502505#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
......@@ -710,9 +713,9 @@ private:
710713 struct __shared_ptr_default_delete<_Yp[], _Un> : default_delete<_Yp[]> {};
711714
712715 template <class _Up>
713 friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
716 friend class shared_ptr;
714717 template <class _Up>
715 friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
718 friend class weak_ptr;
716719};
717720
718721#if _LIBCPP_STD_VER >= 17
......@@ -1201,7 +1204,7 @@ inline _LIBCPP_HIDE_FROM_ABI _Dp* get_deleter(const shared_ptr<_Tp>& __p) _NOEXC
12011204#endif // _LIBCPP_HAS_RTTI
12021205
12031206template <class _Tp>
1204class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS weak_ptr {
1207class _LIBCPP_SHARED_PTR_TRIVIAL_ABI weak_ptr {
12051208public:
12061209#if _LIBCPP_STD_VER >= 17
12071210 typedef remove_extent_t<_Tp> element_type;
......@@ -1210,8 +1213,9 @@ public:
12101213#endif
12111214
12121215 // A weak_ptr contains only two raw pointers which point to the heap and move constructing already doesn't require
1213 // any bookkeeping, so it's always trivially relocatable.
1216 // any bookkeeping, so it's always trivially relocatable. It's also replaceable for the same reason.
12141217 using __trivially_relocatable _LIBCPP_NODEBUG = weak_ptr;
1218 using __replaceable _LIBCPP_NODEBUG = weak_ptr;
12151219
12161220private:
12171221 element_type* __ptr_;
......@@ -1262,9 +1266,9 @@ public:
12621266 }
12631267
12641268 template <class _Up>
1265 friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
1269 friend class weak_ptr;
12661270 template <class _Up>
1267 friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
1271 friend class shared_ptr;
12681272};
12691273
12701274#if _LIBCPP_STD_VER >= 17
......@@ -1382,7 +1386,7 @@ struct owner_less;
13821386#endif
13831387
13841388template <class _Tp>
1385struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> > : __binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> {
1389struct owner_less<shared_ptr<_Tp> > : __binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool> {
13861390 _LIBCPP_HIDE_FROM_ABI bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT {
13871391 return __x.owner_before(__y);
13881392 }
......@@ -1395,7 +1399,7 @@ struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> > : __binary_function<sha
13951399};
13961400
13971401template <class _Tp>
1398struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> > : __binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> {
1402struct owner_less<weak_ptr<_Tp> > : __binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool> {
13991403 _LIBCPP_HIDE_FROM_ABI bool operator()(weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT {
14001404 return __x.owner_before(__y);
14011405 }
......@@ -1409,7 +1413,7 @@ struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> > : __binary_function<weak_
14091413
14101414#if _LIBCPP_STD_VER >= 17
14111415template <>
1412struct _LIBCPP_TEMPLATE_VIS owner_less<void> {
1416struct owner_less<void> {
14131417 template <class _Tp, class _Up>
14141418 _LIBCPP_HIDE_FROM_ABI bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT {
14151419 return __x.owner_before(__y);
......@@ -1431,7 +1435,7 @@ struct _LIBCPP_TEMPLATE_VIS owner_less<void> {
14311435#endif
14321436
14331437template <class _Tp>
1434class _LIBCPP_TEMPLATE_VIS enable_shared_from_this {
1438class enable_shared_from_this {
14351439 mutable weak_ptr<_Tp> __weak_this_;
14361440
14371441protected:
......@@ -1455,10 +1459,10 @@ public:
14551459};
14561460
14571461template <class _Tp>
1458struct _LIBCPP_TEMPLATE_VIS hash;
1462struct hash;
14591463
14601464template <class _Tp>
1461struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> > {
1465struct hash<shared_ptr<_Tp> > {
14621466#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
14631467 _LIBCPP_DEPRECATED_IN_CXX17 typedef shared_ptr<_Tp> argument_type;
14641468 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
lib/libcxx/include/__memory/uninitialized_algorithms.h+13-20
......@@ -16,11 +16,13 @@
1616#include <__algorithm/unwrap_range.h>
1717#include <__config>
1818#include <__cstddef/size_t.h>
19#include <__fwd/memory.h>
1920#include <__iterator/iterator_traits.h>
2021#include <__iterator/reverse_iterator.h>
2122#include <__memory/addressof.h>
2223#include <__memory/allocator_traits.h>
2324#include <__memory/construct_at.h>
25#include <__memory/destroy.h>
2426#include <__memory/pointer_traits.h>
2527#include <__type_traits/enable_if.h>
2628#include <__type_traits/extent.h>
......@@ -31,7 +33,6 @@
3133#include <__type_traits/is_trivially_constructible.h>
3234#include <__type_traits/is_trivially_relocatable.h>
3335#include <__type_traits/is_unbounded_array.h>
34#include <__type_traits/negation.h>
3536#include <__type_traits/remove_const.h>
3637#include <__type_traits/remove_extent.h>
3738#include <__utility/exception_guard.h>
......@@ -511,14 +512,6 @@ __uninitialized_allocator_value_construct_n_multidimensional(_Alloc& __alloc, _B
511512
512513#endif // _LIBCPP_STD_VER >= 17
513514
514// Destroy all elements in [__first, __last) from left to right using allocator destruction.
515template <class _Alloc, class _Iter, class _Sent>
516_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
517__allocator_destroy(_Alloc& __alloc, _Iter __first, _Sent __last) {
518 for (; __first != __last; ++__first)
519 allocator_traits<_Alloc>::destroy(__alloc, std::__to_address(__first));
520}
521
522515template <class _Alloc, class _Iter>
523516class _AllocatorDestroyRangeReverse {
524517public:
......@@ -556,17 +549,17 @@ __uninitialized_allocator_copy_impl(_Alloc& __alloc, _Iter1 __first1, _Sent1 __l
556549}
557550
558551template <class _Alloc, class _Type>
559struct __allocator_has_trivial_copy_construct : _Not<__has_construct<_Alloc, _Type*, const _Type&> > {};
552inline const bool __allocator_has_trivial_copy_construct_v = !__has_construct_v<_Alloc, _Type*, const _Type&>;
560553
561554template <class _Type>
562struct __allocator_has_trivial_copy_construct<allocator<_Type>, _Type> : true_type {};
555inline const bool __allocator_has_trivial_copy_construct_v<allocator<_Type>, _Type> = true;
563556
564557template <class _Alloc,
565558 class _In,
566559 class _Out,
567560 __enable_if_t<is_trivially_copy_constructible<_In>::value && is_trivially_copy_assignable<_In>::value &&
568561 is_same<__remove_const_t<_In>, __remove_const_t<_Out> >::value &&
569 __allocator_has_trivial_copy_construct<_Alloc, _In>::value,
562 __allocator_has_trivial_copy_construct_v<_Alloc, _In>,
570563 int> = 0>
571564_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Out*
572565__uninitialized_allocator_copy_impl(_Alloc&, _In* __first1, _In* __last1, _Out* __first2) {
......@@ -592,16 +585,16 @@ __uninitialized_allocator_copy(_Alloc& __alloc, _Iter1 __first1, _Sent1 __last1,
592585}
593586
594587template <class _Alloc, class _Type>
595struct __allocator_has_trivial_move_construct : _Not<__has_construct<_Alloc, _Type*, _Type&&> > {};
588inline const bool __allocator_has_trivial_move_construct_v = !__has_construct_v<_Alloc, _Type*, _Type&&>;
596589
597590template <class _Type>
598struct __allocator_has_trivial_move_construct<allocator<_Type>, _Type> : true_type {};
591inline const bool __allocator_has_trivial_move_construct_v<allocator<_Type>, _Type> = true;
599592
600593template <class _Alloc, class _Tp>
601struct __allocator_has_trivial_destroy : _Not<__has_destroy<_Alloc, _Tp*> > {};
594inline const bool __allocator_has_trivial_destroy_v = !__has_destroy_v<_Alloc, _Tp*>;
602595
603596template <class _Tp, class _Up>
604struct __allocator_has_trivial_destroy<allocator<_Tp>, _Up> : true_type {};
597inline const bool __allocator_has_trivial_destroy_v<allocator<_Tp>, _Up> = true;
605598
606599// __uninitialized_allocator_relocate relocates the objects in [__first, __last) into __result.
607600// Relocation means that the objects in [__first, __last) are placed into __result as-if by move-construct and destroy,
......@@ -620,11 +613,11 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __uninitialized_allocat
620613 _Alloc& __alloc, _ContiguousIterator __first, _ContiguousIterator __last, _ContiguousIterator __result) {
621614 static_assert(__libcpp_is_contiguous_iterator<_ContiguousIterator>::value, "");
622615 using _ValueType = typename iterator_traits<_ContiguousIterator>::value_type;
623 static_assert(__is_cpp17_move_insertable<_Alloc>::value,
624 "The specified type does not meet the requirements of Cpp17MoveInsertable");
616 static_assert(
617 __is_cpp17_move_insertable_v<_Alloc>, "The specified type does not meet the requirements of Cpp17MoveInsertable");
625618 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) {
619 !__allocator_has_trivial_move_construct_v<_Alloc, _ValueType> ||
620 !__allocator_has_trivial_destroy_v<_Alloc, _ValueType>) {
628621 auto __destruct_first = __result;
629622 auto __guard = std::__make_exception_guard(
630623 _AllocatorDestroyRangeReverse<_Alloc, _ContiguousIterator>(__alloc, __destruct_first, __result));
lib/libcxx/include/__memory/unique_ptr.h+28-36
......@@ -24,7 +24,7 @@
2424#include <__memory/auto_ptr.h>
2525#include <__memory/compressed_pair.h>
2626#include <__memory/pointer_traits.h>
27#include <__type_traits/add_lvalue_reference.h>
27#include <__type_traits/add_reference.h>
2828#include <__type_traits/common_type.h>
2929#include <__type_traits/conditional.h>
3030#include <__type_traits/dependent_type.h>
......@@ -39,6 +39,7 @@
3939#include <__type_traits/is_function.h>
4040#include <__type_traits/is_pointer.h>
4141#include <__type_traits/is_reference.h>
42#include <__type_traits/is_replaceable.h>
4243#include <__type_traits/is_same.h>
4344#include <__type_traits/is_swappable.h>
4445#include <__type_traits/is_trivially_relocatable.h>
......@@ -62,13 +63,11 @@ _LIBCPP_PUSH_MACROS
6263_LIBCPP_BEGIN_NAMESPACE_STD
6364
6465template <class _Tp>
65struct _LIBCPP_TEMPLATE_VIS default_delete {
66struct default_delete {
6667 static_assert(!is_function<_Tp>::value, "default_delete cannot be instantiated for function types");
67#ifndef _LIBCPP_CXX03_LANG
68 _LIBCPP_HIDE_FROM_ABI constexpr default_delete() _NOEXCEPT = default;
69#else
70 _LIBCPP_HIDE_FROM_ABI default_delete() {}
71#endif
68
69 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
70
7271 template <class _Up, __enable_if_t<is_convertible<_Up*, _Tp*>::value, int> = 0>
7372 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 default_delete(const default_delete<_Up>&) _NOEXCEPT {}
7473
......@@ -80,35 +79,24 @@ struct _LIBCPP_TEMPLATE_VIS default_delete {
8079};
8180
8281template <class _Tp>
83struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> {
84private:
85 template <class _Up>
86 struct _EnableIfConvertible : enable_if<is_convertible<_Up (*)[], _Tp (*)[]>::value> {};
82struct default_delete<_Tp[]> {
83 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
8784
88public:
89#ifndef _LIBCPP_CXX03_LANG
90 _LIBCPP_HIDE_FROM_ABI constexpr default_delete() _NOEXCEPT = default;
91#else
92 _LIBCPP_HIDE_FROM_ABI default_delete() {}
93#endif
94
95 template <class _Up>
96 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23
97 default_delete(const default_delete<_Up[]>&, typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {}
85 template <class _Up, __enable_if_t<is_convertible<_Up (*)[], _Tp (*)[]>::value, int> = 0>
86 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 default_delete(const default_delete<_Up[]>&) _NOEXCEPT {}
9887
99 template <class _Up>
100 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename _EnableIfConvertible<_Up>::type
101 operator()(_Up* __ptr) const _NOEXCEPT {
88 template <class _Up, __enable_if_t<is_convertible<_Up (*)[], _Tp (*)[]>::value, int> = 0>
89 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator()(_Up* __ptr) const _NOEXCEPT {
10290 static_assert(sizeof(_Up) >= 0, "cannot delete an incomplete type");
10391 delete[] __ptr;
10492 }
10593};
10694
10795template <class _Deleter>
108struct __is_default_deleter : false_type {};
96inline const bool __is_default_deleter_v = false;
10997
11098template <class _Tp>
111struct __is_default_deleter<default_delete<_Tp> > : true_type {};
99inline const bool __is_default_deleter_v<default_delete<_Tp> > = true;
112100
113101template <class _Deleter>
114102struct __unique_ptr_deleter_sfinae {
......@@ -139,7 +127,7 @@ struct __unique_ptr_deleter_sfinae<_Deleter&> {
139127#endif
140128
141129template <class _Tp, class _Dp = default_delete<_Tp> >
142class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr {
130class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI unique_ptr {
143131public:
144132 typedef _Tp element_type;
145133 typedef _Dp deleter_type;
......@@ -157,6 +145,8 @@ public:
157145 __libcpp_is_trivially_relocatable<pointer>::value && __libcpp_is_trivially_relocatable<deleter_type>::value,
158146 unique_ptr,
159147 void>;
148 using __replaceable _LIBCPP_NODEBUG =
149 __conditional_t<__is_replaceable_v<pointer> && __is_replaceable_v<deleter_type>, unique_ptr, void>;
160150
161151private:
162152 _LIBCPP_COMPRESSED_PAIR(pointer, __ptr_, deleter_type, __deleter_);
......@@ -313,7 +303,7 @@ public:
313303// We provide some helper classes that allow bounds checking when accessing a unique_ptr<T[]>.
314304// There are a few cases where bounds checking can be implemented:
315305//
316// 1. When an array cookie (see [1]) exists at the beginning of the array allocation, we are
306// 1. When an array cookie exists at the beginning of the array allocation, we are
317307// able to reuse that cookie to extract the size of the array and perform bounds checking.
318308// An array cookie is a size inserted at the beginning of the allocation by the compiler.
319309// That size is inserted implicitly when doing `new T[n]` in some cases (as of writing this
......@@ -355,7 +345,7 @@ struct __unique_ptr_array_bounds_stateless {
355345
356346 template <class _Deleter,
357347 class _Tp,
358 __enable_if_t<__is_default_deleter<_Deleter>::value && __has_array_cookie<_Tp>::value, int> = 0>
348 __enable_if_t<__is_default_deleter_v<_Deleter> && __has_array_cookie<_Tp>::value, int> = 0>
359349 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __in_bounds(_Tp* __ptr, size_t __index) const {
360350 // In constant expressions, we can't check the array cookie so we just pretend that the index
361351 // is in-bounds. The compiler catches invalid accesses anyway.
......@@ -367,7 +357,7 @@ struct __unique_ptr_array_bounds_stateless {
367357
368358 template <class _Deleter,
369359 class _Tp,
370 __enable_if_t<!__is_default_deleter<_Deleter>::value || !__has_array_cookie<_Tp>::value, int> = 0>
360 __enable_if_t<!__is_default_deleter_v<_Deleter> || !__has_array_cookie<_Tp>::value, int> = 0>
371361 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __in_bounds(_Tp*, size_t) const {
372362 return true; // If we don't have an array cookie, we assume the access is in-bounds
373363 }
......@@ -385,7 +375,7 @@ struct __unique_ptr_array_bounds_stored {
385375 // Use the array cookie if there's one
386376 template <class _Deleter,
387377 class _Tp,
388 __enable_if_t<__is_default_deleter<_Deleter>::value && __has_array_cookie<_Tp>::value, int> = 0>
378 __enable_if_t<__is_default_deleter_v<_Deleter> && __has_array_cookie<_Tp>::value, int> = 0>
389379 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __in_bounds(_Tp* __ptr, size_t __index) const {
390380 if (__libcpp_is_constant_evaluated())
391381 return true;
......@@ -396,7 +386,7 @@ struct __unique_ptr_array_bounds_stored {
396386 // Otherwise, fall back on the stored size (if any)
397387 template <class _Deleter,
398388 class _Tp,
399 __enable_if_t<!__is_default_deleter<_Deleter>::value || !__has_array_cookie<_Tp>::value, int> = 0>
389 __enable_if_t<!__is_default_deleter_v<_Deleter> || !__has_array_cookie<_Tp>::value, int> = 0>
400390 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __in_bounds(_Tp*, size_t __index) const {
401391 return __index < __size_;
402392 }
......@@ -406,7 +396,7 @@ private:
406396};
407397
408398template <class _Tp, class _Dp>
409class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> {
399class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI unique_ptr<_Tp[], _Dp> {
410400public:
411401 typedef _Tp element_type;
412402 typedef _Dp deleter_type;
......@@ -423,6 +413,8 @@ public:
423413 __libcpp_is_trivially_relocatable<pointer>::value && __libcpp_is_trivially_relocatable<deleter_type>::value,
424414 unique_ptr,
425415 void>;
416 using __replaceable _LIBCPP_NODEBUG =
417 __conditional_t<__is_replaceable_v<pointer> && __is_replaceable_v<deleter_type>, unique_ptr, void>;
426418
427419private:
428420 template <class _Up, class _OtherDeleter>
......@@ -796,13 +788,13 @@ void make_unique_for_overwrite(_Args&&...) = delete;
796788#endif // _LIBCPP_STD_VER >= 20
797789
798790template <class _Tp>
799struct _LIBCPP_TEMPLATE_VIS hash;
791struct hash;
800792
801793template <class _Tp, class _Dp>
802794#ifdef _LIBCPP_CXX03_LANG
803struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> >
795struct hash<unique_ptr<_Tp, _Dp> >
804796#else
805struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper< unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer> >
797struct hash<__enable_hash_helper< unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer> >
806798#endif
807799{
808800#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
lib/libcxx/include/__memory/uses_allocator.h+1-1
......@@ -40,7 +40,7 @@ template <class _Tp, class _Alloc>
4040struct __uses_allocator<_Tp, _Alloc, false> : public false_type {};
4141
4242template <class _Tp, class _Alloc>
43struct _LIBCPP_TEMPLATE_VIS uses_allocator : public __uses_allocator<_Tp, _Alloc> {};
43struct uses_allocator : public __uses_allocator<_Tp, _Alloc> {};
4444
4545#if _LIBCPP_STD_VER >= 17
4646template <class _Tp, class _Alloc>
lib/libcxx/include/__memory/uses_allocator_construction.h+1-8
......@@ -14,7 +14,6 @@
1414#include <__memory/uses_allocator.h>
1515#include <__tuple/tuple_like_no_subrange.h>
1616#include <__type_traits/enable_if.h>
17#include <__type_traits/is_same.h>
1817#include <__type_traits/remove_cv.h>
1918#include <__utility/declval.h>
2019#include <__utility/pair.h>
......@@ -31,14 +30,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3130
3231#if _LIBCPP_STD_VER >= 17
3332
34template <class _Type>
35inline constexpr bool __is_std_pair = false;
36
37template <class _Type1, class _Type2>
38inline constexpr bool __is_std_pair<pair<_Type1, _Type2>> = true;
39
4033template <class _Tp>
41inline constexpr bool __is_cv_std_pair = __is_std_pair<remove_cv_t<_Tp>>;
34inline constexpr bool __is_cv_std_pair = __is_pair_v<remove_cv_t<_Tp>>;
4235
4336template <class _Tp, class = void>
4437struct __uses_allocator_construction_args;
lib/libcxx/include/__memory_resource/polymorphic_allocator.h+2-2
......@@ -41,7 +41,7 @@ template <class _ValueType
4141 = byte
4242# endif
4343 >
44class _LIBCPP_AVAILABILITY_PMR _LIBCPP_TEMPLATE_VIS polymorphic_allocator {
44class _LIBCPP_AVAILABILITY_PMR polymorphic_allocator {
4545
4646public:
4747 using value_type = _ValueType;
......@@ -64,7 +64,7 @@ public:
6464
6565 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _ValueType* allocate(size_t __n) {
6666 if (__n > __max_size()) {
67 __throw_bad_array_new_length();
67 std::__throw_bad_array_new_length();
6868 }
6969 return static_cast<_ValueType*>(__res_->allocate(__n * sizeof(_ValueType), alignof(_ValueType)));
7070 }
lib/libcxx/include/__mutex/lock_guard.h+4-6
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Mutex>
22class _LIBCPP_TEMPLATE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(scoped_lockable) lock_guard {
22class _LIBCPP_SCOPED_LOCKABLE lock_guard {
2323public:
2424 typedef _Mutex mutex_type;
2525
......@@ -27,16 +27,14 @@ private:
2727 mutex_type& __m_;
2828
2929public:
30 [[__nodiscard__]]
31 _LIBCPP_HIDE_FROM_ABI explicit lock_guard(mutex_type& __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability(__m))
30 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI explicit lock_guard(mutex_type& __m) _LIBCPP_ACQUIRE_CAPABILITY(__m)
3231 : __m_(__m) {
3332 __m_.lock();
3433 }
3534
36 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI lock_guard(mutex_type& __m, adopt_lock_t)
37 _LIBCPP_THREAD_SAFETY_ANNOTATION(requires_capability(__m))
35 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI lock_guard(mutex_type& __m, adopt_lock_t) _LIBCPP_REQUIRES_CAPABILITY(__m)
3836 : __m_(__m) {}
39 _LIBCPP_HIDE_FROM_ABI ~lock_guard() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) { __m_.unlock(); }
37 _LIBCPP_RELEASE_CAPABILITY _LIBCPP_HIDE_FROM_ABI ~lock_guard() { __m_.unlock(); }
4038
4139 lock_guard(lock_guard const&) = delete;
4240 lock_guard& operator=(lock_guard const&) = delete;
lib/libcxx/include/__mutex/mutex.h+4-4
......@@ -21,7 +21,7 @@
2121
2222_LIBCPP_BEGIN_NAMESPACE_STD
2323
24class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_THREAD_SAFETY_ANNOTATION(capability("mutex")) mutex {
24class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_CAPABILITY("mutex") mutex {
2525 __libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER;
2626
2727public:
......@@ -36,9 +36,9 @@ public:
3636 ~mutex() _NOEXCEPT;
3737# endif
3838
39 void lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability());
40 bool try_lock() _NOEXCEPT _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_capability(true));
41 void unlock() _NOEXCEPT _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability());
39 _LIBCPP_ACQUIRE_CAPABILITY() void lock();
40 _LIBCPP_TRY_ACQUIRE_CAPABILITY(true) bool try_lock() _NOEXCEPT;
41 _LIBCPP_RELEASE_CAPABILITY void unlock() _NOEXCEPT;
4242
4343 typedef __libcpp_mutex_t* native_handle_type;
4444 _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() { return &__m_; }
lib/libcxx/include/__mutex/once_flag.h+6-5
......@@ -11,6 +11,7 @@
1111
1212#include <__config>
1313#include <__functional/invoke.h>
14#include <__memory/addressof.h>
1415#include <__memory/shared_count.h> // __libcpp_acquire_load
1516#include <__tuple/tuple_indices.h>
1617#include <__tuple/tuple_size.h>
......@@ -30,7 +31,7 @@ _LIBCPP_PUSH_MACROS
3031
3132_LIBCPP_BEGIN_NAMESPACE_STD
3233
33struct _LIBCPP_TEMPLATE_VIS once_flag;
34struct once_flag;
3435
3536#ifndef _LIBCPP_CXX03_LANG
3637
......@@ -47,7 +48,7 @@ _LIBCPP_HIDE_FROM_ABI void call_once(once_flag&, const _Callable&);
4748
4849#endif // _LIBCPP_CXX03_LANG
4950
50struct _LIBCPP_TEMPLATE_VIS once_flag {
51struct once_flag {
5152 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR once_flag() _NOEXCEPT : __state_(_Unset) {}
5253 once_flag(const once_flag&) = delete;
5354 once_flag& operator=(const once_flag&) = delete;
......@@ -128,7 +129,7 @@ inline _LIBCPP_HIDE_FROM_ABI void call_once(once_flag& __flag, _Callable&& __fun
128129 typedef tuple<_Callable&&, _Args&&...> _Gp;
129130 _Gp __f(std::forward<_Callable>(__func), std::forward<_Args>(__args)...);
130131 __call_once_param<_Gp> __p(__f);
131 std::__call_once(__flag.__state_, &__p, &__call_once_proxy<_Gp>);
132 std::__call_once(__flag.__state_, std::addressof(__p), std::addressof(__call_once_proxy<_Gp>));
132133 }
133134}
134135
......@@ -138,7 +139,7 @@ template <class _Callable>
138139inline _LIBCPP_HIDE_FROM_ABI void call_once(once_flag& __flag, _Callable& __func) {
139140 if (__libcpp_acquire_load(&__flag.__state_) != once_flag::_Complete) {
140141 __call_once_param<_Callable> __p(__func);
141 std::__call_once(__flag.__state_, &__p, &__call_once_proxy<_Callable>);
142 std::__call_once(__flag.__state_, std::addressof(__p), std::addressof(__call_once_proxy<_Callable>));
142143 }
143144}
144145
......@@ -146,7 +147,7 @@ template <class _Callable>
146147inline _LIBCPP_HIDE_FROM_ABI void call_once(once_flag& __flag, const _Callable& __func) {
147148 if (__libcpp_acquire_load(&__flag.__state_) != once_flag::_Complete) {
148149 __call_once_param<const _Callable> __p(__func);
149 std::__call_once(__flag.__state_, &__p, &__call_once_proxy<const _Callable>);
150 std::__call_once(__flag.__state_, std::addressof(__p), std::addressof(__call_once_proxy<const _Callable>));
150151 }
151152}
152153
lib/libcxx/include/__mutex/unique_lock.h+10-10
......@@ -25,7 +25,7 @@
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
2727template <class _Mutex>
28class _LIBCPP_TEMPLATE_VIS unique_lock {
28class unique_lock {
2929public:
3030 typedef _Mutex mutex_type;
3131
......@@ -116,9 +116,9 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(unique_lock);
116116template <class _Mutex>
117117_LIBCPP_HIDE_FROM_ABI void unique_lock<_Mutex>::lock() {
118118 if (__m_ == nullptr)
119 __throw_system_error(EPERM, "unique_lock::lock: references null mutex");
119 std::__throw_system_error(EPERM, "unique_lock::lock: references null mutex");
120120 if (__owns_)
121 __throw_system_error(EDEADLK, "unique_lock::lock: already locked");
121 std::__throw_system_error(EDEADLK, "unique_lock::lock: already locked");
122122 __m_->lock();
123123 __owns_ = true;
124124}
......@@ -126,9 +126,9 @@ _LIBCPP_HIDE_FROM_ABI void unique_lock<_Mutex>::lock() {
126126template <class _Mutex>
127127_LIBCPP_HIDE_FROM_ABI bool unique_lock<_Mutex>::try_lock() {
128128 if (__m_ == nullptr)
129 __throw_system_error(EPERM, "unique_lock::try_lock: references null mutex");
129 std::__throw_system_error(EPERM, "unique_lock::try_lock: references null mutex");
130130 if (__owns_)
131 __throw_system_error(EDEADLK, "unique_lock::try_lock: already locked");
131 std::__throw_system_error(EDEADLK, "unique_lock::try_lock: already locked");
132132 __owns_ = __m_->try_lock();
133133 return __owns_;
134134}
......@@ -137,9 +137,9 @@ template <class _Mutex>
137137template <class _Rep, class _Period>
138138_LIBCPP_HIDE_FROM_ABI bool unique_lock<_Mutex>::try_lock_for(const chrono::duration<_Rep, _Period>& __d) {
139139 if (__m_ == nullptr)
140 __throw_system_error(EPERM, "unique_lock::try_lock_for: references null mutex");
140 std::__throw_system_error(EPERM, "unique_lock::try_lock_for: references null mutex");
141141 if (__owns_)
142 __throw_system_error(EDEADLK, "unique_lock::try_lock_for: already locked");
142 std::__throw_system_error(EDEADLK, "unique_lock::try_lock_for: already locked");
143143 __owns_ = __m_->try_lock_for(__d);
144144 return __owns_;
145145}
......@@ -148,9 +148,9 @@ template <class _Mutex>
148148template <class _Clock, class _Duration>
149149_LIBCPP_HIDE_FROM_ABI bool unique_lock<_Mutex>::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) {
150150 if (__m_ == nullptr)
151 __throw_system_error(EPERM, "unique_lock::try_lock_until: references null mutex");
151 std::__throw_system_error(EPERM, "unique_lock::try_lock_until: references null mutex");
152152 if (__owns_)
153 __throw_system_error(EDEADLK, "unique_lock::try_lock_until: already locked");
153 std::__throw_system_error(EDEADLK, "unique_lock::try_lock_until: already locked");
154154 __owns_ = __m_->try_lock_until(__t);
155155 return __owns_;
156156}
......@@ -158,7 +158,7 @@ _LIBCPP_HIDE_FROM_ABI bool unique_lock<_Mutex>::try_lock_until(const chrono::tim
158158template <class _Mutex>
159159_LIBCPP_HIDE_FROM_ABI void unique_lock<_Mutex>::unlock() {
160160 if (!__owns_)
161 __throw_system_error(EPERM, "unique_lock::unlock: not locked");
161 std::__throw_system_error(EPERM, "unique_lock::unlock: not locked");
162162 __m_->unlock();
163163 __owns_ = false;
164164}
lib/libcxx/include/__new/align_val_t.h+2-3
......@@ -16,8 +16,7 @@
1616# pragma GCC system_header
1717#endif
1818
19// purposefully not using versioning namespace
20namespace std {
19_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
2120#if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION && !defined(_LIBCPP_ABI_VCRUNTIME)
2221# ifndef _LIBCPP_CXX03_LANG
2322enum class align_val_t : size_t {};
......@@ -25,6 +24,6 @@ enum class align_val_t : size_t {};
2524enum align_val_t { __zero = 0, __max = (size_t)-1 };
2625# endif
2726#endif
28} // namespace std
27_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
2928
3029#endif // _LIBCPP___NEW_ALIGN_VAL_T_H
lib/libcxx/include/__new/allocate.h+20-51
......@@ -31,37 +31,16 @@ _LIBCPP_CONSTEXPR inline _LIBCPP_HIDE_FROM_ABI bool __is_overaligned_for_new(siz
3131#endif
3232}
3333
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
5234template <class _Tp>
5335inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _Tp*
54__libcpp_allocate(__element_count __n, size_t __align = _LIBCPP_ALIGNOF(_Tp)) {
36__libcpp_allocate(__element_count __n, [[__maybe_unused__]] size_t __align = _LIBCPP_ALIGNOF(_Tp)) {
5537 size_t __size = static_cast<size_t>(__n) * sizeof(_Tp);
5638#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 }
39 if (__is_overaligned_for_new(__align))
40 return static_cast<_Tp*>(__builtin_operator_new(__size, static_cast<align_val_t>(__align)));
6141#endif
6242
63 (void)__align;
64 return static_cast<_Tp*>(std::__libcpp_operator_new(__size));
43 return static_cast<_Tp*>(__builtin_operator_new(__size));
6544}
6645
6746#if _LIBCPP_HAS_SIZED_DEALLOCATION
......@@ -71,39 +50,29 @@ __libcpp_allocate(__element_count __n, size_t __align = _LIBCPP_ALIGNOF(_Tp)) {
7150#endif
7251
7352template <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 }
53inline _LIBCPP_HIDE_FROM_ABI void
54__libcpp_deallocate(__type_identity_t<_Tp>* __ptr,
55 __element_count __n,
56 [[__maybe_unused__]] size_t __align = _LIBCPP_ALIGNOF(_Tp)) _NOEXCEPT {
57 [[__maybe_unused__]] size_t __size = static_cast<size_t>(__n) * sizeof(_Tp);
58#if _LIBCPP_HAS_ALIGNED_ALLOCATION
59 if (__is_overaligned_for_new(__align))
60 return __builtin_operator_delete(
61 __ptr _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(, __size), static_cast<align_val_t>(__align));
8862#endif
63 return __builtin_operator_delete(__ptr _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(, __size));
8964}
9065
9166#undef _LIBCPP_ONLY_IF_SIZED_DEALLOCATION
9267
9368template <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 }
69inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate_unsized(
70 __type_identity_t<_Tp>* __ptr, [[__maybe_unused__]] size_t __align = _LIBCPP_ALIGNOF(_Tp)) _NOEXCEPT {
71#if _LIBCPP_HAS_ALIGNED_ALLOCATION
72 if (__is_overaligned_for_new(__align))
73 return __builtin_operator_delete(__ptr, static_cast<align_val_t>(__align));
10674#endif
75 return __builtin_operator_delete(__ptr);
10776}
10877_LIBCPP_END_NAMESPACE_STD
10978
lib/libcxx/include/__new/destroying_delete_t.h+2-3
......@@ -16,15 +16,14 @@
1616#endif
1717
1818#if _LIBCPP_STD_VER >= 20
19// purposefully not using versioning namespace
20namespace std {
19_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
2120// Enable the declaration even if the compiler doesn't support the language
2221// feature.
2322struct destroying_delete_t {
2423 explicit destroying_delete_t() = default;
2524};
2625inline constexpr destroying_delete_t destroying_delete{};
27} // namespace std
26_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
2827#endif
2928
3029#endif // _LIBCPP___NEW_DESTROYING_DELETE_T_H
lib/libcxx/include/__new/exceptions.h+2-3
......@@ -17,8 +17,7 @@
1717# pragma GCC system_header
1818#endif
1919
20// purposefully not using versioning namespace
21namespace std {
20_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
2221#if !defined(_LIBCPP_ABI_VCRUNTIME)
2322
2423class _LIBCPP_EXPORTED_FROM_ABI bad_alloc : public exception {
......@@ -69,6 +68,6 @@ public:
6968 _LIBCPP_VERBOSE_ABORT("bad_array_new_length was thrown in -fno-exceptions mode");
7069#endif
7170}
72} // namespace std
71_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
7372
7473#endif // _LIBCPP___NEW_EXCEPTIONS_H
lib/libcxx/include/__new/new_handler.h+2-3
......@@ -18,12 +18,11 @@
1818#if defined(_LIBCPP_ABI_VCRUNTIME)
1919# include <new.h>
2020#else
21// purposefully not using versioning namespace
22namespace std {
21_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
2322typedef void (*new_handler)();
2423_LIBCPP_EXPORTED_FROM_ABI new_handler set_new_handler(new_handler) _NOEXCEPT;
2524_LIBCPP_EXPORTED_FROM_ABI new_handler get_new_handler() _NOEXCEPT;
26} // namespace std
25_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
2726#endif // _LIBCPP_ABI_VCRUNTIME
2827
2928#endif // _LIBCPP___NEW_NEW_HANDLER_H
lib/libcxx/include/__new/nothrow_t.h+2-3
......@@ -18,13 +18,12 @@
1818#if defined(_LIBCPP_ABI_VCRUNTIME)
1919# include <new.h>
2020#else
21// purposefully not using versioning namespace
22namespace std {
21_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
2322struct _LIBCPP_EXPORTED_FROM_ABI nothrow_t {
2423 explicit nothrow_t() = default;
2524};
2625extern _LIBCPP_EXPORTED_FROM_ABI const nothrow_t nothrow;
27} // namespace std
26_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
2827#endif // _LIBCPP_ABI_VCRUNTIME
2928
3029#endif // _LIBCPP___NEW_NOTHROW_T_H
lib/libcxx/include/__node_handle+7-6
......@@ -62,6 +62,7 @@ public:
6262#include <__config>
6363#include <__memory/allocator_traits.h>
6464#include <__memory/pointer_traits.h>
65#include <__type_traits/is_specialization.h>
6566#include <optional>
6667
6768#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -80,7 +81,7 @@ template <class _NodeType, class _Alloc>
8081struct __generic_container_node_destructor;
8182
8283template <class _NodeType, class _Alloc, template <class, class> class _MapOrSetSpecifics>
83class _LIBCPP_TEMPLATE_VIS __basic_node_handle
84class __basic_node_handle
8485 : public _MapOrSetSpecifics< _NodeType, __basic_node_handle<_NodeType, _Alloc, _MapOrSetSpecifics>> {
8586 template <class _Tp, class _Compare, class _Allocator>
8687 friend class __tree;
......@@ -175,15 +176,15 @@ struct __set_node_handle_specifics {
175176
176177template <class _NodeType, class _Derived>
177178struct __map_node_handle_specifics {
178 typedef typename _NodeType::__node_value_type::key_type key_type;
179 typedef typename _NodeType::__node_value_type::mapped_type mapped_type;
179 using key_type = __remove_const_t<typename _NodeType::__node_value_type::first_type>;
180 using mapped_type = typename _NodeType::__node_value_type::second_type;
180181
181182 _LIBCPP_HIDE_FROM_ABI key_type& key() const {
182 return static_cast<_Derived const*>(this)->__ptr_->__get_value().__ref().first;
183 return const_cast<key_type&>(static_cast<_Derived const*>(this)->__ptr_->__get_value().first);
183184 }
184185
185186 _LIBCPP_HIDE_FROM_ABI mapped_type& mapped() const {
186 return static_cast<_Derived const*>(this)->__ptr_->__get_value().__ref().second;
187 return static_cast<_Derived const*>(this)->__ptr_->__get_value().second;
187188 }
188189};
189190
......@@ -194,7 +195,7 @@ template <class _NodeType, class _Alloc>
194195using __map_node_handle _LIBCPP_NODEBUG = __basic_node_handle< _NodeType, _Alloc, __map_node_handle_specifics>;
195196
196197template <class _Iterator, class _NodeType>
197struct _LIBCPP_TEMPLATE_VIS __insert_return_type {
198struct __insert_return_type {
198199 _Iterator position;
199200 bool inserted;
200201 _NodeType node;
lib/libcxx/include/__numeric/gcd_lcm.h+3-2
......@@ -10,15 +10,16 @@
1010#ifndef _LIBCPP___NUMERIC_GCD_LCM_H
1111#define _LIBCPP___NUMERIC_GCD_LCM_H
1212
13#include <__algorithm/min.h>
1413#include <__assert>
1514#include <__bit/countr.h>
1615#include <__config>
16#include <__memory/addressof.h>
1717#include <__type_traits/common_type.h>
1818#include <__type_traits/is_integral.h>
1919#include <__type_traits/is_same.h>
2020#include <__type_traits/is_signed.h>
2121#include <__type_traits/make_unsigned.h>
22#include <__type_traits/remove_cv.h>
2223#include <limits>
2324
2425#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -115,7 +116,7 @@ constexpr _LIBCPP_HIDE_FROM_ABI common_type_t<_Tp, _Up> lcm(_Tp __m, _Up __n) {
115116 _Rp __val1 = __ct_abs<_Rp, _Tp>()(__m) / std::gcd(__m, __n);
116117 _Rp __val2 = __ct_abs<_Rp, _Up>()(__n);
117118 _Rp __res;
118 [[maybe_unused]] bool __overflow = __builtin_mul_overflow(__val1, __val2, &__res);
119 [[maybe_unused]] bool __overflow = __builtin_mul_overflow(__val1, __val2, std::addressof(__res));
119120 _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(!__overflow, "Overflow in lcm");
120121 return __res;
121122}
lib/libcxx/include/__numeric/ranges_iota.h created+65
......@@ -0,0 +1,65 @@
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___NUMERIC_RANGES_IOTA_H
11#define _LIBCPP___NUMERIC_RANGES_IOTA_H
12
13#include <__algorithm/out_value_result.h>
14#include <__config>
15#include <__iterator/concepts.h>
16#include <__ranges/access.h>
17#include <__ranges/concepts.h>
18#include <__ranges/dangling.h>
19#include <__utility/as_const.h>
20#include <__utility/move.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_LIBCPP_BEGIN_NAMESPACE_STD
30
31#if _LIBCPP_STD_VER >= 23
32namespace ranges {
33template <typename _Out, typename _Tp>
34using iota_result = ranges::out_value_result<_Out, _Tp>;
35
36struct __iota_fn {
37public:
38 template <input_or_output_iterator _Out, sentinel_for<_Out> _Sent, weakly_incrementable _Tp>
39 requires indirectly_writable<_Out, const _Tp&>
40 _LIBCPP_HIDE_FROM_ABI static constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp __value) {
41 while (__first != __last) {
42 *__first = std::as_const(__value);
43 ++__first;
44 ++__value;
45 }
46 return {std::move(__first), std::move(__value)};
47 }
48
49 template <weakly_incrementable _Tp, ranges::output_range<const _Tp&> _Range>
50 _LIBCPP_HIDE_FROM_ABI static constexpr iota_result<ranges::borrowed_iterator_t<_Range>, _Tp>
51 operator()(_Range&& __r, _Tp __value) {
52 return operator()(ranges::begin(__r), ranges::end(__r), std::move(__value));
53 }
54};
55
56inline constexpr auto iota = __iota_fn{};
57} // namespace ranges
58
59#endif // _LIBCPP_STD_VER >= 23
60
61_LIBCPP_END_NAMESPACE_STD
62
63_LIBCPP_POP_MACROS
64
65#endif // _LIBCPP___NUMERIC_RANGES_IOTA_H
lib/libcxx/include/__numeric/saturation_arithmetic.h+19-18
......@@ -11,8 +11,9 @@
1111#define _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
1212
1313#include <__assert>
14#include <__concepts/arithmetic.h>
1514#include <__config>
15#include <__memory/addressof.h>
16#include <__type_traits/integer_traits.h>
1617#include <__utility/cmp.h>
1718#include <limits>
1819
......@@ -27,12 +28,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2728
2829#if _LIBCPP_STD_VER >= 20
2930
30template <__libcpp_integer _Tp>
31template <__signed_or_unsigned_integer _Tp>
3132_LIBCPP_HIDE_FROM_ABI constexpr _Tp __add_sat(_Tp __x, _Tp __y) noexcept {
32 if (_Tp __sum; !__builtin_add_overflow(__x, __y, &__sum))
33 if (_Tp __sum; !__builtin_add_overflow(__x, __y, std::addressof(__sum)))
3334 return __sum;
3435 // Handle overflow
35 if constexpr (__libcpp_unsigned_integer<_Tp>) {
36 if constexpr (__unsigned_integer<_Tp>) {
3637 return std::numeric_limits<_Tp>::max();
3738 } else {
3839 // Signed addition overflow
......@@ -45,12 +46,12 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp __add_sat(_Tp __x, _Tp __y) noexcept {
4546 }
4647}
4748
48template <__libcpp_integer _Tp>
49template <__signed_or_unsigned_integer _Tp>
4950_LIBCPP_HIDE_FROM_ABI constexpr _Tp __sub_sat(_Tp __x, _Tp __y) noexcept {
50 if (_Tp __sub; !__builtin_sub_overflow(__x, __y, &__sub))
51 if (_Tp __sub; !__builtin_sub_overflow(__x, __y, std::addressof(__sub)))
5152 return __sub;
5253 // Handle overflow
53 if constexpr (__libcpp_unsigned_integer<_Tp>) {
54 if constexpr (__unsigned_integer<_Tp>) {
5455 // Overflows if (x < y)
5556 return std::numeric_limits<_Tp>::min();
5657 } else {
......@@ -64,12 +65,12 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp __sub_sat(_Tp __x, _Tp __y) noexcept {
6465 }
6566}
6667
67template <__libcpp_integer _Tp>
68template <__signed_or_unsigned_integer _Tp>
6869_LIBCPP_HIDE_FROM_ABI constexpr _Tp __mul_sat(_Tp __x, _Tp __y) noexcept {
69 if (_Tp __mul; !__builtin_mul_overflow(__x, __y, &__mul))
70 if (_Tp __mul; !__builtin_mul_overflow(__x, __y, std::addressof(__mul)))
7071 return __mul;
7172 // Handle overflow
72 if constexpr (__libcpp_unsigned_integer<_Tp>) {
73 if constexpr (__unsigned_integer<_Tp>) {
7374 return std::numeric_limits<_Tp>::max();
7475 } else {
7576 // Signed multiplication overflow
......@@ -80,10 +81,10 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp __mul_sat(_Tp __x, _Tp __y) noexcept {
8081 }
8182}
8283
83template <__libcpp_integer _Tp>
84template <__signed_or_unsigned_integer _Tp>
8485_LIBCPP_HIDE_FROM_ABI constexpr _Tp __div_sat(_Tp __x, _Tp __y) noexcept {
8586 _LIBCPP_ASSERT_UNCATEGORIZED(__y != 0, "Division by 0 is undefined");
86 if constexpr (__libcpp_unsigned_integer<_Tp>) {
87 if constexpr (__unsigned_integer<_Tp>) {
8788 return __x / __y;
8889 } else {
8990 // Handle signed division overflow
......@@ -93,7 +94,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp __div_sat(_Tp __x, _Tp __y) noexcept {
9394 }
9495}
9596
96template <__libcpp_integer _Rp, __libcpp_integer _Tp>
97template <__signed_or_unsigned_integer _Rp, __signed_or_unsigned_integer _Tp>
9798_LIBCPP_HIDE_FROM_ABI constexpr _Rp __saturate_cast(_Tp __x) noexcept {
9899 // Saturation is impossible edge case when ((min _Rp) < (min _Tp) && (max _Rp) > (max _Tp)) and it is expected to be
99100 // optimized out by the compiler.
......@@ -111,27 +112,27 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Rp __saturate_cast(_Tp __x) noexcept {
111112
112113#if _LIBCPP_STD_VER >= 26
113114
114template <__libcpp_integer _Tp>
115template <__signed_or_unsigned_integer _Tp>
115116_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
116117 return std::__add_sat(__x, __y);
117118}
118119
119template <__libcpp_integer _Tp>
120template <__signed_or_unsigned_integer _Tp>
120121_LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept {
121122 return std::__sub_sat(__x, __y);
122123}
123124
124template <__libcpp_integer _Tp>
125template <__signed_or_unsigned_integer _Tp>
125126_LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept {
126127 return std::__mul_sat(__x, __y);
127128}
128129
129template <__libcpp_integer _Tp>
130template <__signed_or_unsigned_integer _Tp>
130131_LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept {
131132 return std::__div_sat(__x, __y);
132133}
133134
134template <__libcpp_integer _Rp, __libcpp_integer _Tp>
135template <__signed_or_unsigned_integer _Rp, __signed_or_unsigned_integer _Tp>
135136_LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept {
136137 return std::__saturate_cast<_Rp>(__x);
137138}
lib/libcxx/include/__ostream/basic_ostream.h+12-9
......@@ -15,6 +15,10 @@
1515
1616# include <__exception/operations.h>
1717# include <__fwd/memory.h>
18# include <__iterator/ostreambuf_iterator.h>
19# include <__locale_dir/num.h>
20# include <__locale_dir/pad_and_output.h>
21# include <__memory/addressof.h>
1822# include <__memory/unique_ptr.h>
1923# include <__new/exceptions.h>
2024# include <__ostream/put_character_sequence.h>
......@@ -26,7 +30,6 @@
2630# include <__utility/declval.h>
2731# include <bitset>
2832# include <ios>
29# include <locale>
3033# include <streambuf>
3134# include <string_view>
3235
......@@ -40,7 +43,7 @@ _LIBCPP_PUSH_MACROS
4043_LIBCPP_BEGIN_NAMESPACE_STD
4144
4245template <class _CharT, class _Traits>
43class _LIBCPP_TEMPLATE_VIS basic_ostream : virtual public basic_ios<_CharT, _Traits> {
46class basic_ostream : virtual public basic_ios<_CharT, _Traits> {
4447public:
4548 // types (inherited from basic_ios (27.5.4)):
4649 typedef _CharT char_type;
......@@ -70,7 +73,7 @@ protected:
7073
7174public:
7275 // 27.7.2.4 Prefix/suffix:
73 class _LIBCPP_TEMPLATE_VIS sentry;
76 class sentry;
7477
7578 // 27.7.2.6 Formatted output:
7679 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&)) {
......@@ -180,7 +183,7 @@ protected:
180183};
181184
182185template <class _CharT, class _Traits>
183class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry {
186class basic_ostream<_CharT, _Traits>::sentry {
184187 bool __ok_;
185188 basic_ostream<_CharT, _Traits>& __os_;
186189
......@@ -339,7 +342,7 @@ basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(const
339342
340343template <class _CharT, class _Traits>
341344_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) {
342 return std::__put_character_sequence(__os, &__c, 1);
345 return std::__put_character_sequence(__os, std::addressof(__c), 1);
343346}
344347
345348template <class _CharT, class _Traits>
......@@ -353,9 +356,9 @@ _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_
353356 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
354357 if (std::__pad_and_output(
355358 _Ip(__os),
356 &__c,
357 (__os.flags() & ios_base::adjustfield) == ios_base::left ? &__c + 1 : &__c,
358 &__c + 1,
359 std::addressof(__c),
360 std::addressof(__c) + (((__os.flags() & ios_base::adjustfield) == ios_base::left) ? 1 : 0),
361 std::addressof(__c) + 1,
359362 __os,
360363 __os.fill())
361364 .failed())
......@@ -407,7 +410,7 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn) {
407410 if (__len > __bs) {
408411 __wb = (_CharT*)malloc(__len * sizeof(_CharT));
409412 if (__wb == 0)
410 __throw_bad_alloc();
413 std::__throw_bad_alloc();
411414 __h.reset(__wb);
412415 }
413416 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
lib/libcxx/include/__ostream/print.h+3-13
......@@ -18,8 +18,8 @@
1818# include <__ostream/basic_ostream.h>
1919# include <format>
2020# include <ios>
21# include <locale>
2221# include <print>
22# include <streambuf>
2323
2424# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2525# pragma GCC system_header
......@@ -49,21 +49,11 @@ __vprint_nonunicode(ostream& __os, string_view __fmt, format_args __args, bool _
4949 if (__write_nl)
5050 __o += '\n';
5151
52 const char* __str = __o.data();
53 size_t __len = __o.size();
54
5552# if _LIBCPP_HAS_EXCEPTIONS
5653 try {
5754# endif // _LIBCPP_HAS_EXCEPTIONS
58 typedef ostreambuf_iterator<char> _Ip;
59 if (std::__pad_and_output(
60 _Ip(__os),
61 __str,
62 (__os.flags() & ios_base::adjustfield) == ios_base::left ? __str + __len : __str,
63 __str + __len,
64 __os,
65 __os.fill())
66 .failed())
55 if (auto __rdbuf = __os.rdbuf();
56 !__rdbuf || __rdbuf->sputn(__o.data(), __o.size()) != static_cast<streamsize>(__o.size()))
6757 __os.setstate(ios_base::badbit | ios_base::failbit);
6858
6959# if _LIBCPP_HAS_EXCEPTIONS
lib/libcxx/include/__pstl/backends/libdispatch.h+1
......@@ -22,6 +22,7 @@
2222#include <__iterator/move_iterator.h>
2323#include <__memory/allocator.h>
2424#include <__memory/construct_at.h>
25#include <__memory/destroy.h>
2526#include <__memory/unique_ptr.h>
2627#include <__new/exceptions.h>
2728#include <__numeric/reduce.h>
lib/libcxx/include/__random/bernoulli_distribution.h+2-2
......@@ -23,12 +23,12 @@ _LIBCPP_PUSH_MACROS
2323
2424_LIBCPP_BEGIN_NAMESPACE_STD
2525
26class _LIBCPP_TEMPLATE_VIS bernoulli_distribution {
26class bernoulli_distribution {
2727public:
2828 // types
2929 typedef bool result_type;
3030
31 class _LIBCPP_TEMPLATE_VIS param_type {
31 class param_type {
3232 double __p_;
3333
3434 public:
lib/libcxx/include/__random/binomial_distribution.h+2-2
......@@ -25,14 +25,14 @@ _LIBCPP_PUSH_MACROS
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
2727template <class _IntType = int>
28class _LIBCPP_TEMPLATE_VIS binomial_distribution {
28class binomial_distribution {
2929 static_assert(__libcpp_random_is_valid_inttype<_IntType>::value, "IntType must be a supported integer type");
3030
3131public:
3232 // types
3333 typedef _IntType result_type;
3434
35 class _LIBCPP_TEMPLATE_VIS param_type {
35 class param_type {
3636 result_type __t_;
3737 double __p_;
3838 double __pr_;
lib/libcxx/include/__random/cauchy_distribution.h+2-2
......@@ -26,7 +26,7 @@ _LIBCPP_PUSH_MACROS
2626_LIBCPP_BEGIN_NAMESPACE_STD
2727
2828template <class _RealType = double>
29class _LIBCPP_TEMPLATE_VIS cauchy_distribution {
29class cauchy_distribution {
3030 static_assert(__libcpp_random_is_valid_realtype<_RealType>::value,
3131 "RealType must be a supported floating-point type");
3232
......@@ -34,7 +34,7 @@ public:
3434 // types
3535 typedef _RealType result_type;
3636
37 class _LIBCPP_TEMPLATE_VIS param_type {
37 class param_type {
3838 result_type __a_;
3939 result_type __b_;
4040
lib/libcxx/include/__random/chi_squared_distribution.h+2-2
......@@ -25,7 +25,7 @@ _LIBCPP_PUSH_MACROS
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
2727template <class _RealType = double>
28class _LIBCPP_TEMPLATE_VIS chi_squared_distribution {
28class chi_squared_distribution {
2929 static_assert(__libcpp_random_is_valid_realtype<_RealType>::value,
3030 "RealType must be a supported floating-point type");
3131
......@@ -33,7 +33,7 @@ public:
3333 // types
3434 typedef _RealType result_type;
3535
36 class _LIBCPP_TEMPLATE_VIS param_type {
36 class param_type {
3737 result_type __n_;
3838
3939 public:
lib/libcxx/include/__random/clamp_to_integral.h+1-1
......@@ -43,7 +43,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _IntT __max_representable_int_for_float(
4343template <class _IntT, class _RealT>
4444_LIBCPP_HIDE_FROM_ABI _IntT __clamp_to_integral(_RealT __r) _NOEXCEPT {
4545 using _Lim = numeric_limits<_IntT>;
46 const _IntT __max_val = __max_representable_int_for_float<_IntT, _RealT>();
46 const _IntT __max_val = std::__max_representable_int_for_float<_IntT, _RealT>();
4747 if (__r >= ::nextafter(static_cast<_RealT>(__max_val), INFINITY)) {
4848 return _Lim::max();
4949 } else if (__r <= _Lim::lowest()) {
lib/libcxx/include/__random/discard_block_engine.h+1-1
......@@ -28,7 +28,7 @@ _LIBCPP_PUSH_MACROS
2828_LIBCPP_BEGIN_NAMESPACE_STD
2929
3030template <class _Engine, size_t __p, size_t __r>
31class _LIBCPP_TEMPLATE_VIS discard_block_engine {
31class discard_block_engine {
3232 _Engine __e_;
3333 int __n_;
3434
lib/libcxx/include/__random/discrete_distribution.h+2-2
......@@ -28,14 +28,14 @@ _LIBCPP_PUSH_MACROS
2828_LIBCPP_BEGIN_NAMESPACE_STD
2929
3030template <class _IntType = int>
31class _LIBCPP_TEMPLATE_VIS discrete_distribution {
31class discrete_distribution {
3232 static_assert(__libcpp_random_is_valid_inttype<_IntType>::value, "IntType must be a supported integer type");
3333
3434public:
3535 // types
3636 typedef _IntType result_type;
3737
38 class _LIBCPP_TEMPLATE_VIS param_type {
38 class param_type {
3939 vector<double> __p_;
4040
4141 public:
lib/libcxx/include/__random/exponential_distribution.h+2-2
......@@ -27,7 +27,7 @@ _LIBCPP_PUSH_MACROS
2727_LIBCPP_BEGIN_NAMESPACE_STD
2828
2929template <class _RealType = double>
30class _LIBCPP_TEMPLATE_VIS exponential_distribution {
30class exponential_distribution {
3131 static_assert(__libcpp_random_is_valid_realtype<_RealType>::value,
3232 "RealType must be a supported floating-point type");
3333
......@@ -35,7 +35,7 @@ public:
3535 // types
3636 typedef _RealType result_type;
3737
38 class _LIBCPP_TEMPLATE_VIS param_type {
38 class param_type {
3939 result_type __lambda_;
4040
4141 public:
lib/libcxx/include/__random/extreme_value_distribution.h+2-2
......@@ -26,7 +26,7 @@ _LIBCPP_PUSH_MACROS
2626_LIBCPP_BEGIN_NAMESPACE_STD
2727
2828template <class _RealType = double>
29class _LIBCPP_TEMPLATE_VIS extreme_value_distribution {
29class extreme_value_distribution {
3030 static_assert(__libcpp_random_is_valid_realtype<_RealType>::value,
3131 "RealType must be a supported floating-point type");
3232
......@@ -34,7 +34,7 @@ public:
3434 // types
3535 typedef _RealType result_type;
3636
37 class _LIBCPP_TEMPLATE_VIS param_type {
37 class param_type {
3838 result_type __a_;
3939 result_type __b_;
4040
lib/libcxx/include/__random/fisher_f_distribution.h+2-2
......@@ -25,7 +25,7 @@ _LIBCPP_PUSH_MACROS
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
2727template <class _RealType = double>
28class _LIBCPP_TEMPLATE_VIS fisher_f_distribution {
28class fisher_f_distribution {
2929 static_assert(__libcpp_random_is_valid_realtype<_RealType>::value,
3030 "RealType must be a supported floating-point type");
3131
......@@ -33,7 +33,7 @@ public:
3333 // types
3434 typedef _RealType result_type;
3535
36 class _LIBCPP_TEMPLATE_VIS param_type {
36 class param_type {
3737 result_type __m_;
3838 result_type __n_;
3939
lib/libcxx/include/__random/gamma_distribution.h+2-2
......@@ -27,7 +27,7 @@ _LIBCPP_PUSH_MACROS
2727_LIBCPP_BEGIN_NAMESPACE_STD
2828
2929template <class _RealType = double>
30class _LIBCPP_TEMPLATE_VIS gamma_distribution {
30class gamma_distribution {
3131 static_assert(__libcpp_random_is_valid_realtype<_RealType>::value,
3232 "RealType must be a supported floating-point type");
3333
......@@ -35,7 +35,7 @@ public:
3535 // types
3636 typedef _RealType result_type;
3737
38 class _LIBCPP_TEMPLATE_VIS param_type {
38 class param_type {
3939 result_type __alpha_;
4040 result_type __beta_;
4141
lib/libcxx/include/__random/geometric_distribution.h+2-2
......@@ -25,14 +25,14 @@ _LIBCPP_PUSH_MACROS
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
2727template <class _IntType = int>
28class _LIBCPP_TEMPLATE_VIS geometric_distribution {
28class geometric_distribution {
2929 static_assert(__libcpp_random_is_valid_inttype<_IntType>::value, "IntType must be a supported integer type");
3030
3131public:
3232 // types
3333 typedef _IntType result_type;
3434
35 class _LIBCPP_TEMPLATE_VIS param_type {
35 class param_type {
3636 double __p_;
3737
3838 public:
lib/libcxx/include/__random/independent_bits_engine.h+1-1
......@@ -31,7 +31,7 @@ _LIBCPP_PUSH_MACROS
3131_LIBCPP_BEGIN_NAMESPACE_STD
3232
3333template <class _Engine, size_t __w, class _UIntType>
34class _LIBCPP_TEMPLATE_VIS independent_bits_engine {
34class independent_bits_engine {
3535 template <class _UInt, _UInt _R0, size_t _Wp, size_t _Mp>
3636 class __get_n {
3737 static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UInt>::digits;
lib/libcxx/include/__random/linear_congruential_engine.h+2-2
......@@ -220,7 +220,7 @@ struct __lce_ta<__a, __c, __m, (unsigned short)(-1), __mode> {
220220};
221221
222222template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
223class _LIBCPP_TEMPLATE_VIS linear_congruential_engine;
223class linear_congruential_engine;
224224
225225template <class _CharT, class _Traits, class _Up, _Up _Ap, _Up _Cp, _Up _Np>
226226_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
......@@ -231,7 +231,7 @@ _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
231231operator>>(basic_istream<_CharT, _Traits>& __is, linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x);
232232
233233template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
234class _LIBCPP_TEMPLATE_VIS linear_congruential_engine {
234class linear_congruential_engine {
235235public:
236236 // types
237237 typedef _UIntType result_type;
lib/libcxx/include/__random/lognormal_distribution.h+2-2
......@@ -26,7 +26,7 @@ _LIBCPP_PUSH_MACROS
2626_LIBCPP_BEGIN_NAMESPACE_STD
2727
2828template <class _RealType = double>
29class _LIBCPP_TEMPLATE_VIS lognormal_distribution {
29class lognormal_distribution {
3030 static_assert(__libcpp_random_is_valid_realtype<_RealType>::value,
3131 "RealType must be a supported floating-point type");
3232
......@@ -34,7 +34,7 @@ public:
3434 // types
3535 typedef _RealType result_type;
3636
37 class _LIBCPP_TEMPLATE_VIS param_type {
37 class param_type {
3838 result_type __m_;
3939 result_type __s_;
4040
lib/libcxx/include/__random/mersenne_twister_engine.h+2-2
......@@ -42,7 +42,7 @@ template <class _UIntType,
4242 _UIntType __c,
4343 size_t __l,
4444 _UIntType __f>
45class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine;
45class mersenne_twister_engine;
4646
4747template <class _UInt,
4848 size_t _Wp,
......@@ -134,7 +134,7 @@ template <class _UIntType,
134134 _UIntType __c,
135135 size_t __l,
136136 _UIntType __f>
137class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine {
137class mersenne_twister_engine {
138138public:
139139 // types
140140 typedef _UIntType result_type;
lib/libcxx/include/__random/negative_binomial_distribution.h+2-2
......@@ -28,14 +28,14 @@ _LIBCPP_PUSH_MACROS
2828_LIBCPP_BEGIN_NAMESPACE_STD
2929
3030template <class _IntType = int>
31class _LIBCPP_TEMPLATE_VIS negative_binomial_distribution {
31class negative_binomial_distribution {
3232 static_assert(__libcpp_random_is_valid_inttype<_IntType>::value, "IntType must be a supported integer type");
3333
3434public:
3535 // types
3636 typedef _IntType result_type;
3737
38 class _LIBCPP_TEMPLATE_VIS param_type {
38 class param_type {
3939 result_type __k_;
4040 double __p_;
4141
lib/libcxx/include/__random/normal_distribution.h+2-2
......@@ -26,7 +26,7 @@ _LIBCPP_PUSH_MACROS
2626_LIBCPP_BEGIN_NAMESPACE_STD
2727
2828template <class _RealType = double>
29class _LIBCPP_TEMPLATE_VIS normal_distribution {
29class normal_distribution {
3030 static_assert(__libcpp_random_is_valid_realtype<_RealType>::value,
3131 "RealType must be a supported floating-point type");
3232
......@@ -34,7 +34,7 @@ public:
3434 // types
3535 typedef _RealType result_type;
3636
37 class _LIBCPP_TEMPLATE_VIS param_type {
37 class param_type {
3838 result_type __mean_;
3939 result_type __stddev_;
4040
lib/libcxx/include/__random/piecewise_constant_distribution.h+2-2
......@@ -29,7 +29,7 @@ _LIBCPP_PUSH_MACROS
2929_LIBCPP_BEGIN_NAMESPACE_STD
3030
3131template <class _RealType = double>
32class _LIBCPP_TEMPLATE_VIS piecewise_constant_distribution {
32class piecewise_constant_distribution {
3333 static_assert(__libcpp_random_is_valid_realtype<_RealType>::value,
3434 "RealType must be a supported floating-point type");
3535
......@@ -37,7 +37,7 @@ public:
3737 // types
3838 typedef _RealType result_type;
3939
40 class _LIBCPP_TEMPLATE_VIS param_type {
40 class param_type {
4141 vector<result_type> __b_;
4242 vector<result_type> __densities_;
4343 vector<result_type> __areas_;
lib/libcxx/include/__random/piecewise_linear_distribution.h+2-2
......@@ -30,7 +30,7 @@ _LIBCPP_PUSH_MACROS
3030_LIBCPP_BEGIN_NAMESPACE_STD
3131
3232template <class _RealType = double>
33class _LIBCPP_TEMPLATE_VIS piecewise_linear_distribution {
33class piecewise_linear_distribution {
3434 static_assert(__libcpp_random_is_valid_realtype<_RealType>::value,
3535 "RealType must be a supported floating-point type");
3636
......@@ -38,7 +38,7 @@ public:
3838 // types
3939 typedef _RealType result_type;
4040
41 class _LIBCPP_TEMPLATE_VIS param_type {
41 class param_type {
4242 vector<result_type> __b_;
4343 vector<result_type> __densities_;
4444 vector<result_type> __areas_;
lib/libcxx/include/__random/poisson_distribution.h+2-2
......@@ -29,14 +29,14 @@ _LIBCPP_PUSH_MACROS
2929_LIBCPP_BEGIN_NAMESPACE_STD
3030
3131template <class _IntType = int>
32class _LIBCPP_TEMPLATE_VIS poisson_distribution {
32class poisson_distribution {
3333 static_assert(__libcpp_random_is_valid_inttype<_IntType>::value, "IntType must be a supported integer type");
3434
3535public:
3636 // types
3737 typedef _IntType result_type;
3838
39 class _LIBCPP_TEMPLATE_VIS param_type {
39 class param_type {
4040 double __mean_;
4141 double __s_;
4242 double __d_;
lib/libcxx/include/__random/seed_seq.h+1-1
......@@ -30,7 +30,7 @@ _LIBCPP_PUSH_MACROS
3030
3131_LIBCPP_BEGIN_NAMESPACE_STD
3232
33class _LIBCPP_TEMPLATE_VIS seed_seq {
33class seed_seq {
3434public:
3535 // types
3636 typedef uint32_t result_type;
lib/libcxx/include/__random/shuffle_order_engine.h+1-1
......@@ -52,7 +52,7 @@ public:
5252};
5353
5454template <class _Engine, size_t __k>
55class _LIBCPP_TEMPLATE_VIS shuffle_order_engine {
55class shuffle_order_engine {
5656 static_assert(0 < __k, "shuffle_order_engine invalid parameters");
5757
5858public:
lib/libcxx/include/__random/student_t_distribution.h+2-2
......@@ -27,7 +27,7 @@ _LIBCPP_PUSH_MACROS
2727_LIBCPP_BEGIN_NAMESPACE_STD
2828
2929template <class _RealType = double>
30class _LIBCPP_TEMPLATE_VIS student_t_distribution {
30class student_t_distribution {
3131 static_assert(__libcpp_random_is_valid_realtype<_RealType>::value,
3232 "RealType must be a supported floating-point type");
3333
......@@ -35,7 +35,7 @@ public:
3535 // types
3636 typedef _RealType result_type;
3737
38 class _LIBCPP_TEMPLATE_VIS param_type {
38 class param_type {
3939 result_type __n_;
4040
4141 public:
lib/libcxx/include/__random/subtract_with_carry_engine.h+2-2
......@@ -30,7 +30,7 @@ _LIBCPP_PUSH_MACROS
3030_LIBCPP_BEGIN_NAMESPACE_STD
3131
3232template <class _UIntType, size_t __w, size_t __s, size_t __r>
33class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine;
33class subtract_with_carry_engine;
3434
3535template <class _UInt, size_t _Wp, size_t _Sp, size_t _Rp>
3636_LIBCPP_HIDE_FROM_ABI bool operator==(const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x,
......@@ -49,7 +49,7 @@ _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
4949operator>>(basic_istream<_CharT, _Traits>& __is, subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x);
5050
5151template <class _UIntType, size_t __w, size_t __s, size_t __r>
52class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine {
52class subtract_with_carry_engine {
5353public:
5454 // types
5555 typedef _UIntType result_type;
lib/libcxx/include/__random/uniform_real_distribution.h+2-2
......@@ -25,7 +25,7 @@ _LIBCPP_PUSH_MACROS
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
2727template <class _RealType = double>
28class _LIBCPP_TEMPLATE_VIS uniform_real_distribution {
28class uniform_real_distribution {
2929 static_assert(__libcpp_random_is_valid_realtype<_RealType>::value,
3030 "RealType must be a supported floating-point type");
3131
......@@ -33,7 +33,7 @@ public:
3333 // types
3434 typedef _RealType result_type;
3535
36 class _LIBCPP_TEMPLATE_VIS param_type {
36 class param_type {
3737 result_type __a_;
3838 result_type __b_;
3939
lib/libcxx/include/__random/weibull_distribution.h+2-2
......@@ -26,7 +26,7 @@ _LIBCPP_PUSH_MACROS
2626_LIBCPP_BEGIN_NAMESPACE_STD
2727
2828template <class _RealType = double>
29class _LIBCPP_TEMPLATE_VIS weibull_distribution {
29class weibull_distribution {
3030 static_assert(__libcpp_random_is_valid_realtype<_RealType>::value,
3131 "RealType must be a supported floating-point type");
3232
......@@ -34,7 +34,7 @@ public:
3434 // types
3535 typedef _RealType result_type;
3636
37 class _LIBCPP_TEMPLATE_VIS param_type {
37 class param_type {
3838 result_type __a_;
3939 result_type __b_;
4040
lib/libcxx/include/__ranges/concepts.h+40
......@@ -10,7 +10,9 @@
1010#ifndef _LIBCPP___RANGES_CONCEPTS_H
1111#define _LIBCPP___RANGES_CONCEPTS_H
1212
13#include <__concepts/common_reference_with.h>
1314#include <__concepts/constructible.h>
15#include <__concepts/convertible_to.h>
1416#include <__concepts/movable.h>
1517#include <__concepts/same_as.h>
1618#include <__config>
......@@ -25,6 +27,8 @@
2527#include <__ranges/enable_view.h>
2628#include <__ranges/size.h>
2729#include <__type_traits/add_pointer.h>
30#include <__type_traits/common_reference.h>
31#include <__type_traits/common_type.h>
2832#include <__type_traits/is_reference.h>
2933#include <__type_traits/remove_cvref.h>
3034#include <__type_traits/remove_reference.h>
......@@ -133,6 +137,42 @@ concept viewable_range =
133137 (is_lvalue_reference_v<_Tp> ||
134138 (movable<remove_reference_t<_Tp>> && !__is_std_initializer_list<remove_cvref_t<_Tp>>))));
135139
140# if _LIBCPP_STD_VER >= 23
141
142template <class... _Rs>
143using __concat_reference_t _LIBCPP_NODEBUG = common_reference_t<range_reference_t<_Rs>...>;
144
145template <class... _Rs>
146using __concat_value_t _LIBCPP_NODEBUG = common_type_t<range_value_t<_Rs>...>;
147
148template <class... _Rs>
149using __concat_rvalue_reference_t _LIBCPP_NODEBUG = common_reference_t<range_rvalue_reference_t<_Rs>...>;
150
151template <class _Ref, class _RRef, class _It>
152concept __concat_indirectly_readable_impl = requires(const _It __it) {
153 { *__it } -> convertible_to<_Ref>;
154 { ranges::iter_move(__it) } -> convertible_to<_RRef>;
155};
156
157template <class... _Rs>
158concept __concat_indirectly_readable =
159 common_reference_with<__concat_reference_t<_Rs...>&&, __concat_value_t<_Rs...>&> &&
160 common_reference_with<__concat_reference_t<_Rs...>&&, __concat_rvalue_reference_t<_Rs...>&&> &&
161 common_reference_with<__concat_rvalue_reference_t<_Rs...>&&, const __concat_value_t<_Rs...>&> &&
162 (__concat_indirectly_readable_impl<__concat_reference_t<_Rs...>,
163 __concat_rvalue_reference_t<_Rs...>,
164 iterator_t<_Rs>> &&
165 ...);
166
167template <class... _Rs>
168concept __concatable = requires {
169 typename __concat_reference_t<_Rs...>;
170 typename __concat_value_t<_Rs...>;
171 typename __concat_rvalue_reference_t<_Rs...>;
172} && __concat_indirectly_readable<_Rs...>;
173
174# endif // _LIBCPP_STD_VER >= 23
175
136176} // namespace ranges
137177
138178#endif // _LIBCPP_STD_VER >= 20
lib/libcxx/include/__ranges/drop_view.h+4-4
......@@ -185,22 +185,22 @@ struct __passthrough_type;
185185
186186template <class _Tp, size_t _Extent>
187187struct __passthrough_type<span<_Tp, _Extent>> {
188 using type = span<_Tp>;
188 using type _LIBCPP_NODEBUG = span<_Tp>;
189189};
190190
191191template <class _CharT, class _Traits>
192192struct __passthrough_type<basic_string_view<_CharT, _Traits>> {
193 using type = basic_string_view<_CharT, _Traits>;
193 using type _LIBCPP_NODEBUG = basic_string_view<_CharT, _Traits>;
194194};
195195
196196template <class _Np, class _Bound>
197197struct __passthrough_type<iota_view<_Np, _Bound>> {
198 using type = iota_view<_Np, _Bound>;
198 using type _LIBCPP_NODEBUG = iota_view<_Np, _Bound>;
199199};
200200
201201template <class _Iter, class _Sent, subrange_kind _Kind>
202202struct __passthrough_type<subrange<_Iter, _Sent, _Kind>> {
203 using type = subrange<_Iter, _Sent, _Kind>;
203 using type _LIBCPP_NODEBUG = subrange<_Iter, _Sent, _Kind>;
204204};
205205
206206template <class _Tp>
lib/libcxx/include/__ranges/elements_view.h+1-1
......@@ -197,7 +197,7 @@ class elements_view<_View, _Np>::__iterator
197197 }
198198
199199public:
200 using iterator_concept = decltype(__get_iterator_concept());
200 using iterator_concept = decltype(__iterator::__get_iterator_concept());
201201 using value_type = remove_cvref_t<tuple_element_t<_Np, range_value_t<_Base>>>;
202202 using difference_type = range_difference_t<_Base>;
203203
lib/libcxx/include/__ranges/enable_view.h+3-4
......@@ -14,7 +14,6 @@
1414#include <__concepts/same_as.h>
1515#include <__config>
1616#include <__type_traits/is_class.h>
17#include <__type_traits/is_convertible.h>
1817#include <__type_traits/remove_cv.h>
1918
2019#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -34,12 +33,12 @@ template <class _Derived>
3433class view_interface;
3534
3635template <class _Op, class _Yp>
37 requires is_convertible_v<_Op*, view_interface<_Yp>*>
38void __is_derived_from_view_interface(const _Op*, const view_interface<_Yp>*);
36 requires(!same_as<_Op, view_interface<_Yp>>)
37void __is_derived_from_view_interface(view_interface<_Yp>*);
3938
4039template <class _Tp>
4140inline constexpr bool enable_view = derived_from<_Tp, view_base> || requires {
42 ranges::__is_derived_from_view_interface((_Tp*)nullptr, (_Tp*)nullptr);
41 ranges::__is_derived_from_view_interface<remove_cv_t<_Tp>>((remove_cv_t<_Tp>*)nullptr);
4342};
4443
4544} // namespace ranges
lib/libcxx/include/__ranges/join_with_view.h created+460
......@@ -0,0 +1,460 @@
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___RANGES_JOIN_WITH_VIEW_H
11#define _LIBCPP___RANGES_JOIN_WITH_VIEW_H
12
13#include <__concepts/common_reference_with.h>
14#include <__concepts/common_with.h>
15#include <__concepts/constructible.h>
16#include <__concepts/convertible_to.h>
17#include <__concepts/derived_from.h>
18#include <__concepts/equality_comparable.h>
19#include <__config>
20#include <__functional/bind_back.h>
21#include <__iterator/concepts.h>
22#include <__iterator/incrementable_traits.h>
23#include <__iterator/iter_move.h>
24#include <__iterator/iter_swap.h>
25#include <__iterator/iterator_traits.h>
26#include <__memory/addressof.h>
27#include <__ranges/access.h>
28#include <__ranges/all.h>
29#include <__ranges/concepts.h>
30#include <__ranges/non_propagating_cache.h>
31#include <__ranges/range_adaptor.h>
32#include <__ranges/single_view.h>
33#include <__ranges/view_interface.h>
34#include <__type_traits/conditional.h>
35#include <__type_traits/decay.h>
36#include <__type_traits/is_reference.h>
37#include <__type_traits/maybe_const.h>
38#include <__utility/as_const.h>
39#include <__utility/as_lvalue.h>
40#include <__utility/empty.h>
41#include <__utility/forward.h>
42#include <__utility/move.h>
43#include <variant>
44
45#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
46# pragma GCC system_header
47#endif
48
49_LIBCPP_PUSH_MACROS
50#include <__undef_macros>
51
52_LIBCPP_BEGIN_NAMESPACE_STD
53
54#if _LIBCPP_STD_VER >= 23
55
56namespace ranges {
57template <class _Range>
58concept __bidirectional_common = bidirectional_range<_Range> && common_range<_Range>;
59
60template <input_range _View, forward_range _Pattern>
61 requires view<_View> && input_range<range_reference_t<_View>> && view<_Pattern> &&
62 __concatable<range_reference_t<_View>, _Pattern>
63class join_with_view : public view_interface<join_with_view<_View, _Pattern>> {
64 using _InnerRng _LIBCPP_NODEBUG = range_reference_t<_View>;
65
66 _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
67
68 static constexpr bool _UseOuterItCache = !forward_range<_View>;
69 using _OuterItCache _LIBCPP_NODEBUG =
70 _If<_UseOuterItCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
71 _LIBCPP_NO_UNIQUE_ADDRESS _OuterItCache __outer_it_;
72
73 static constexpr bool _UseInnerCache = !is_reference_v<_InnerRng>;
74 using _InnerCache _LIBCPP_NODEBUG =
75 _If<_UseInnerCache, __non_propagating_cache<remove_cvref_t<_InnerRng>>, __empty_cache>;
76 _LIBCPP_NO_UNIQUE_ADDRESS _InnerCache __inner_;
77
78 _LIBCPP_NO_UNIQUE_ADDRESS _Pattern __pattern_ = _Pattern();
79
80 template <bool _Const>
81 struct __iterator;
82
83 template <bool _Const>
84 struct __sentinel;
85
86public:
87 _LIBCPP_HIDE_FROM_ABI join_with_view()
88 requires default_initializable<_View> && default_initializable<_Pattern>
89 = default;
90
91 _LIBCPP_HIDE_FROM_ABI constexpr explicit join_with_view(_View __base, _Pattern __pattern)
92 : __base_(std::move(__base)), __pattern_(std::move(__pattern)) {}
93
94 template <input_range _Range>
95 requires constructible_from<_View, views::all_t<_Range>> &&
96 constructible_from<_Pattern, single_view<range_value_t<_InnerRng>>>
97 _LIBCPP_HIDE_FROM_ABI constexpr explicit join_with_view(_Range&& __r, range_value_t<_InnerRng> __e)
98 : __base_(views::all(std::forward<_Range>(__r))), __pattern_(views::single(std::move(__e))) {}
99
100 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
101 requires copy_constructible<_View>
102 {
103 return __base_;
104 }
105
106 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); }
107
108 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() {
109 if constexpr (forward_range<_View>) {
110 constexpr bool __use_const = __simple_view<_View> && is_reference_v<_InnerRng> && __simple_view<_Pattern>;
111 return __iterator<__use_const>{*this, ranges::begin(__base_)};
112 } else {
113 __outer_it_.__emplace(ranges::begin(__base_));
114 return __iterator<false>{*this};
115 }
116 }
117
118 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
119 requires forward_range<const _View> && forward_range<const _Pattern> &&
120 is_reference_v<range_reference_t<const _View>> && input_range<range_reference_t<const _View>> &&
121 __concatable<range_reference_t<const _View>, const _Pattern>
122 {
123 return __iterator<true>{*this, ranges::begin(__base_)};
124 }
125
126 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() {
127 constexpr bool __use_const = __simple_view<_View> && __simple_view<_Pattern>;
128 if constexpr (forward_range<_View> && is_reference_v<_InnerRng> && forward_range<_InnerRng> &&
129 common_range<_View> && common_range<_InnerRng>)
130 return __iterator<__use_const>{*this, ranges::end(__base_)};
131 else
132 return __sentinel<__use_const>{*this};
133 }
134
135 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
136 requires forward_range<const _View> && forward_range<const _Pattern> &&
137 is_reference_v<range_reference_t<const _View>> && input_range<range_reference_t<const _View>> &&
138 __concatable<range_reference_t<const _View>, const _Pattern>
139 {
140 using _InnerConstRng = range_reference_t<const _View>;
141 if constexpr (forward_range<_InnerConstRng> && common_range<const _View> && common_range<_InnerConstRng>)
142 return __iterator<true>{*this, ranges::end(__base_)};
143 else
144 return __sentinel<true>{*this};
145 }
146};
147
148template <class _Range, class _Pattern>
149join_with_view(_Range&&, _Pattern&&) -> join_with_view<views::all_t<_Range>, views::all_t<_Pattern>>;
150
151template <input_range _Range>
152join_with_view(_Range&&, range_value_t<range_reference_t<_Range>>)
153 -> join_with_view<views::all_t<_Range>, single_view<range_value_t<range_reference_t<_Range>>>>;
154
155template <class _Base, class _PatternBase, class _InnerBase = range_reference_t<_Base>>
156struct __join_with_view_iterator_category {};
157
158template <class _Base, class _PatternBase, class _InnerBase>
159 requires is_reference_v<_InnerBase> && forward_range<_Base> && forward_range<_InnerBase>
160struct __join_with_view_iterator_category<_Base, _PatternBase, _InnerBase> {
161private:
162 static consteval auto __get_iterator_category() noexcept {
163 using _OuterC = iterator_traits<iterator_t<_Base>>::iterator_category;
164 using _InnerC = iterator_traits<iterator_t<_InnerBase>>::iterator_category;
165 using _PatternC = iterator_traits<iterator_t<_PatternBase>>::iterator_category;
166
167 if constexpr (!is_reference_v<common_reference_t<iter_reference_t<iterator_t<_InnerBase>>,
168 iter_reference_t<iterator_t<_PatternBase>>>>)
169 return input_iterator_tag{};
170 else if constexpr (derived_from<_OuterC, bidirectional_iterator_tag> &&
171 derived_from<_InnerC, bidirectional_iterator_tag> &&
172 derived_from<_PatternC, bidirectional_iterator_tag> && common_range<_InnerBase> &&
173 common_range<_PatternBase>)
174 return bidirectional_iterator_tag{};
175 else if constexpr (derived_from<_OuterC, forward_iterator_tag> && derived_from<_InnerC, forward_iterator_tag> &&
176 derived_from<_PatternC, forward_iterator_tag>)
177 return forward_iterator_tag{};
178 else
179 return input_iterator_tag{};
180 }
181
182public:
183 using iterator_category = decltype(__get_iterator_category());
184};
185
186template <input_range _View, forward_range _Pattern>
187 requires view<_View> && input_range<range_reference_t<_View>> && view<_Pattern> &&
188 __concatable<range_reference_t<_View>, _Pattern>
189template <bool _Const>
190struct join_with_view<_View, _Pattern>::__iterator
191 : public __join_with_view_iterator_category<__maybe_const<_Const, _View>, __maybe_const<_Const, _Pattern>> {
192private:
193 friend join_with_view;
194
195 using _Parent _LIBCPP_NODEBUG = __maybe_const<_Const, join_with_view>;
196 using _Base _LIBCPP_NODEBUG = __maybe_const<_Const, _View>;
197 using _InnerBase _LIBCPP_NODEBUG = range_reference_t<_Base>;
198 using _PatternBase _LIBCPP_NODEBUG = __maybe_const<_Const, _Pattern>;
199
200 using _OuterIter _LIBCPP_NODEBUG = iterator_t<_Base>;
201 using _InnerIter _LIBCPP_NODEBUG = iterator_t<_InnerBase>;
202 using _PatternIter _LIBCPP_NODEBUG = iterator_t<_PatternBase>;
203
204 static_assert(!_Const || forward_range<_Base>, "Const can only be true when Base models forward_range.");
205
206 static constexpr bool __ref_is_glvalue = is_reference_v<_InnerBase>;
207
208 _Parent* __parent_ = nullptr;
209
210 static constexpr bool _OuterIterPresent = forward_range<_Base>;
211 using _OuterIterType _LIBCPP_NODEBUG = _If<_OuterIterPresent, _OuterIter, std::__empty>;
212 _LIBCPP_NO_UNIQUE_ADDRESS _OuterIterType __outer_it_ = _OuterIterType();
213
214 variant<_PatternIter, _InnerIter> __inner_it_;
215
216 _LIBCPP_HIDE_FROM_ABI constexpr __iterator(_Parent& __parent, _OuterIter __outer)
217 requires forward_range<_Base>
218 : __parent_(std::addressof(__parent)), __outer_it_(std::move(__outer)) {
219 if (__get_outer() != ranges::end(__parent_->__base_)) {
220 __inner_it_.template emplace<1>(ranges::begin(__update_inner()));
221 __satisfy();
222 }
223 }
224
225 _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(_Parent& __parent)
226 requires(!forward_range<_Base>)
227 : __parent_(std::addressof(__parent)) {
228 if (__get_outer() != ranges::end(__parent_->__base_)) {
229 __inner_it_.template emplace<1>(ranges::begin(__update_inner()));
230 __satisfy();
231 }
232 }
233
234 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _OuterIter& __get_outer() {
235 if constexpr (forward_range<_Base>)
236 return __outer_it_;
237 else
238 return *__parent_->__outer_it_;
239 }
240
241 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _OuterIter& __get_outer() const {
242 if constexpr (forward_range<_Base>)
243 return __outer_it_;
244 else
245 return *__parent_->__outer_it_;
246 }
247
248 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto& __update_inner() {
249 if constexpr (__ref_is_glvalue)
250 return std::__as_lvalue(*__get_outer());
251 else
252 return __parent_->__inner_.__emplace_from([this]() -> decltype(auto) { return *__get_outer(); });
253 }
254
255 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto& __get_inner() {
256 if constexpr (__ref_is_glvalue)
257 return std::__as_lvalue(*__get_outer());
258 else
259 return *__parent_->__inner_;
260 }
261
262 _LIBCPP_HIDE_FROM_ABI constexpr void __satisfy() {
263 while (true) {
264 if (__inner_it_.index() == 0) {
265 if (std::get<0>(__inner_it_) != ranges::end(__parent_->__pattern_))
266 break;
267
268 __inner_it_.template emplace<1>(ranges::begin(__update_inner()));
269 } else {
270 if (std::get<1>(__inner_it_) != ranges::end(__get_inner()))
271 break;
272
273 if (++__get_outer() == ranges::end(__parent_->__base_)) {
274 if constexpr (__ref_is_glvalue)
275 __inner_it_.template emplace<0>();
276
277 break;
278 }
279
280 __inner_it_.template emplace<0>(ranges::begin(__parent_->__pattern_));
281 }
282 }
283 }
284
285 [[nodiscard]] static consteval auto __get_iterator_concept() noexcept {
286 if constexpr (__ref_is_glvalue && bidirectional_range<_Base> && __bidirectional_common<_InnerBase> &&
287 __bidirectional_common<_PatternBase>)
288 return bidirectional_iterator_tag{};
289 else if constexpr (__ref_is_glvalue && forward_range<_Base> && forward_range<_InnerBase>)
290 return forward_iterator_tag{};
291 else
292 return input_iterator_tag{};
293 }
294
295public:
296 using iterator_concept = decltype(__get_iterator_concept());
297 using value_type = common_type_t<iter_value_t<_InnerIter>, iter_value_t<_PatternIter>>;
298 using difference_type =
299 common_type_t<iter_difference_t<_OuterIter>, iter_difference_t<_InnerIter>, iter_difference_t<_PatternIter>>;
300
301 _LIBCPP_HIDE_FROM_ABI __iterator() = default;
302
303 _LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator<!_Const> __i)
304 requires _Const && convertible_to<iterator_t<_View>, _OuterIter> &&
305 convertible_to<iterator_t<_InnerRng>, _InnerIter> && convertible_to<iterator_t<_Pattern>, _PatternIter>
306 : __parent_(__i.__parent_), __outer_it_(std::move(__i.__outer_it_)) {
307 if (__i.__inner_it_.index() == 0) {
308 __inner_it_.template emplace<0>(std::get<0>(std::move(__i.__inner_it_)));
309 } else {
310 __inner_it_.template emplace<1>(std::get<1>(std::move(__i.__inner_it_)));
311 }
312 }
313
314 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const {
315 using __reference = common_reference_t<iter_reference_t<_InnerIter>, iter_reference_t<_PatternIter>>;
316 return std::visit([](auto& __it) -> __reference { return *__it; }, __inner_it_);
317 }
318
319 _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator++() {
320 std::visit([](auto& __it) { ++__it; }, __inner_it_);
321 __satisfy();
322 return *this;
323 }
324
325 _LIBCPP_HIDE_FROM_ABI constexpr void operator++(int) { ++*this; }
326
327 _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator++(int)
328 requires __ref_is_glvalue && forward_iterator<_OuterIter> && forward_iterator<_InnerIter>
329 {
330 __iterator __tmp = *this;
331 ++*this;
332 return __tmp;
333 }
334
335 _LIBCPP_HIDE_FROM_ABI constexpr __iterator& operator--()
336 requires __ref_is_glvalue
337 && bidirectional_range<_Base> && __bidirectional_common<_InnerBase> && __bidirectional_common<_PatternBase>
338 {
339 if (__outer_it_ == ranges::end(__parent_->__base_)) {
340 auto&& __inner = *--__outer_it_;
341 __inner_it_.template emplace<1>(ranges::end(__inner));
342 }
343
344 while (true) {
345 if (__inner_it_.index() == 0) {
346 auto& __it = std::get<0>(__inner_it_);
347 if (__it == ranges::begin(__parent_->__pattern_)) {
348 auto&& __inner = *--__outer_it_;
349 __inner_it_.template emplace<1>(ranges::end(__inner));
350 } else
351 break;
352 } else {
353 auto& __it = std::get<1>(__inner_it_);
354 auto&& __inner = *__outer_it_;
355 if (__it == ranges::begin(__inner))
356 __inner_it_.template emplace<0>(ranges::end(__parent_->__pattern_));
357 else
358 break;
359 }
360 }
361
362 std::visit([](auto& __it) { --__it; }, __inner_it_);
363 return *this;
364 }
365
366 _LIBCPP_HIDE_FROM_ABI constexpr __iterator operator--(int)
367 requires __ref_is_glvalue
368 && bidirectional_range<_Base> && __bidirectional_common<_InnerBase> && __bidirectional_common<_PatternBase>
369 {
370 __iterator __tmp = *this;
371 --*this;
372 return __tmp;
373 }
374
375 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __iterator& __x, const __iterator& __y)
376 requires __ref_is_glvalue && forward_range<_Base> && equality_comparable<_InnerIter>
377 {
378 return __x.__outer_it_ == __y.__outer_it_ && __x.__inner_it_ == __y.__inner_it_;
379 }
380
381 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr decltype(auto) iter_move(const __iterator& __x) {
382 using __rvalue_reference =
383 common_reference_t<iter_rvalue_reference_t<_InnerIter>, iter_rvalue_reference_t<_PatternIter>>;
384 return std::visit<__rvalue_reference>(ranges::iter_move, __x.__inner_it_);
385 }
386
387 _LIBCPP_HIDE_FROM_ABI friend constexpr void iter_swap(const __iterator& __x, const __iterator& __y)
388 requires indirectly_swappable<_InnerIter, _PatternIter>
389 {
390 std::visit(ranges::iter_swap, __x.__inner_it_, __y.__inner_it_);
391 }
392};
393
394template <input_range _View, forward_range _Pattern>
395 requires view<_View> && input_range<range_reference_t<_View>> && view<_Pattern> &&
396 __concatable<range_reference_t<_View>, _Pattern>
397template <bool _Const>
398struct join_with_view<_View, _Pattern>::__sentinel {
399private:
400 friend join_with_view;
401
402 using _Parent _LIBCPP_NODEBUG = __maybe_const<_Const, join_with_view>;
403 using _Base _LIBCPP_NODEBUG = __maybe_const<_Const, _View>;
404
405 _LIBCPP_NO_UNIQUE_ADDRESS sentinel_t<_Base> __end_ = sentinel_t<_Base>();
406
407 _LIBCPP_HIDE_FROM_ABI constexpr explicit __sentinel(_Parent& __parent) : __end_(ranges::end(__parent.__base_)) {}
408
409 template <bool _OtherConst>
410 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto& __get_outer_of(const __iterator<_OtherConst>& __x) {
411 return __x.__get_outer();
412 }
413
414public:
415 _LIBCPP_HIDE_FROM_ABI __sentinel() = default;
416
417 _LIBCPP_HIDE_FROM_ABI constexpr __sentinel(__sentinel<!_Const> __s)
418 requires _Const && convertible_to<sentinel_t<_View>, sentinel_t<_Base>>
419 : __end_(std::move(__s.__end_)) {}
420
421 template <bool _OtherConst>
422 requires sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
423 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr bool
424 operator==(const __iterator<_OtherConst>& __x, const __sentinel& __y) {
425 return __get_outer_of(__x) == __y.__end_;
426 }
427};
428
429namespace views {
430namespace __join_with_view {
431struct __fn {
432 template <class _Range, class _Pattern>
433 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Range&& __range, _Pattern&& __pattern) const
434 noexcept(noexcept(/**/ join_with_view(std::forward<_Range>(__range), std::forward<_Pattern>(__pattern))))
435 -> decltype(/*--*/ join_with_view(std::forward<_Range>(__range), std::forward<_Pattern>(__pattern))) {
436 return /*-------------*/ join_with_view(std::forward<_Range>(__range), std::forward<_Pattern>(__pattern));
437 }
438
439 template <class _Pattern>
440 requires constructible_from<decay_t<_Pattern>, _Pattern>
441 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Pattern&& __pattern) const
442 noexcept(is_nothrow_constructible_v<decay_t<_Pattern>, _Pattern>) {
443 return __pipeable(std::__bind_back(*this, std::forward<_Pattern>(__pattern)));
444 }
445};
446} // namespace __join_with_view
447
448inline namespace __cpo {
449inline constexpr auto join_with = __join_with_view::__fn{};
450} // namespace __cpo
451} // namespace views
452} // namespace ranges
453
454#endif // _LIBCPP_STD_VER >= 23
455
456_LIBCPP_END_NAMESPACE_STD
457
458_LIBCPP_POP_MACROS
459
460#endif // _LIBCPP___RANGES_JOIN_WITH_VIEW_H
lib/libcxx/include/__ranges/non_propagating_cache.h+1-1
......@@ -36,7 +36,7 @@ namespace ranges {
3636// may refer to internal details of the source view.
3737template <class _Tp>
3838 requires is_object_v<_Tp>
39class _LIBCPP_TEMPLATE_VIS __non_propagating_cache {
39class __non_propagating_cache {
4040 struct __from_tag {};
4141 struct __forward_tag {};
4242
lib/libcxx/include/__ranges/repeat_view.h+2-2
......@@ -52,12 +52,12 @@ concept __integer_like_with_usable_difference_type =
5252
5353template <class _Tp>
5454struct __repeat_view_iterator_difference {
55 using type = _IotaDiffT<_Tp>;
55 using type _LIBCPP_NODEBUG = _IotaDiffT<_Tp>;
5656};
5757
5858template <__signed_integer_like _Tp>
5959struct __repeat_view_iterator_difference<_Tp> {
60 using type = _Tp;
60 using type _LIBCPP_NODEBUG = _Tp;
6161};
6262
6363template <class _Tp>
lib/libcxx/include/__ranges/reverse_view.h+2-2
......@@ -144,13 +144,13 @@ inline constexpr bool __is_unsized_reverse_subrange<subrange<reverse_iterator<_I
144144
145145template <class _Tp>
146146struct __unwrapped_reverse_subrange {
147 using type =
147 using type _LIBCPP_NODEBUG =
148148 void; // avoid SFINAE-ing out the overload below -- let the concept requirements do it for better diagnostics
149149};
150150
151151template <class _Iter, subrange_kind _Kind>
152152struct __unwrapped_reverse_subrange<subrange<reverse_iterator<_Iter>, reverse_iterator<_Iter>, _Kind>> {
153 using type = subrange<_Iter, _Iter, _Kind>;
153 using type _LIBCPP_NODEBUG = subrange<_Iter, _Iter, _Kind>;
154154};
155155
156156struct __fn : __range_adaptor_closure<__fn> {
lib/libcxx/include/__ranges/subrange.h+5-5
......@@ -72,7 +72,7 @@ template <input_or_output_iterator _Iter,
7272 sentinel_for<_Iter> _Sent = _Iter,
7373 subrange_kind _Kind = sized_sentinel_for<_Sent, _Iter> ? subrange_kind::sized : subrange_kind::unsized>
7474 requires(_Kind == subrange_kind::sized || !sized_sentinel_for<_Sent, _Iter>)
75class _LIBCPP_TEMPLATE_VIS subrange : public view_interface<subrange<_Iter, _Sent, _Kind>> {
75class subrange : public view_interface<subrange<_Iter, _Sent, _Kind>> {
7676public:
7777 // Note: this is an internal implementation detail that is public only for internal usage.
7878 static constexpr bool _StoreSize = (_Kind == subrange_kind::sized && !sized_sentinel_for<_Sent, _Iter>);
......@@ -247,22 +247,22 @@ struct tuple_size<ranges::subrange<_Ip, _Sp, _Kp>> : integral_constant<size_t, 2
247247
248248template <class _Ip, class _Sp, ranges::subrange_kind _Kp>
249249struct tuple_element<0, ranges::subrange<_Ip, _Sp, _Kp>> {
250 using type = _Ip;
250 using type _LIBCPP_NODEBUG = _Ip;
251251};
252252
253253template <class _Ip, class _Sp, ranges::subrange_kind _Kp>
254254struct tuple_element<1, ranges::subrange<_Ip, _Sp, _Kp>> {
255 using type = _Sp;
255 using type _LIBCPP_NODEBUG = _Sp;
256256};
257257
258258template <class _Ip, class _Sp, ranges::subrange_kind _Kp>
259259struct tuple_element<0, const ranges::subrange<_Ip, _Sp, _Kp>> {
260 using type = _Ip;
260 using type _LIBCPP_NODEBUG = _Ip;
261261};
262262
263263template <class _Ip, class _Sp, ranges::subrange_kind _Kp>
264264struct tuple_element<1, const ranges::subrange<_Ip, _Sp, _Kp>> {
265 using type = _Sp;
265 using type _LIBCPP_NODEBUG = _Sp;
266266};
267267
268268#endif // _LIBCPP_STD_VER >= 20
lib/libcxx/include/__ranges/take_view.h+3-3
......@@ -229,18 +229,18 @@ struct __passthrough_type;
229229
230230template <class _Tp, size_t _Extent>
231231struct __passthrough_type<span<_Tp, _Extent>> {
232 using type = span<_Tp>;
232 using type _LIBCPP_NODEBUG = span<_Tp>;
233233};
234234
235235template <class _CharT, class _Traits>
236236struct __passthrough_type<basic_string_view<_CharT, _Traits>> {
237 using type = basic_string_view<_CharT, _Traits>;
237 using type _LIBCPP_NODEBUG = basic_string_view<_CharT, _Traits>;
238238};
239239
240240template <class _Iter, class _Sent, subrange_kind _Kind>
241241 requires requires { typename subrange<_Iter>; }
242242struct __passthrough_type<subrange<_Iter, _Sent, _Kind>> {
243 using type = subrange<_Iter>;
243 using type _LIBCPP_NODEBUG = subrange<_Iter>;
244244};
245245
246246template <class _Tp>
lib/libcxx/include/__ranges/to.h+4-2
......@@ -26,7 +26,9 @@
2626#include <__ranges/size.h>
2727#include <__ranges/transform_view.h>
2828#include <__type_traits/add_pointer.h>
29#include <__type_traits/is_class.h>
2930#include <__type_traits/is_const.h>
31#include <__type_traits/is_union.h>
3032#include <__type_traits/is_volatile.h>
3133#include <__type_traits/type_identity.h>
3234#include <__utility/declval.h>
......@@ -81,7 +83,7 @@ template <class _Container, input_range _Range, class... _Args>
8183 static_assert(!is_const_v<_Container>, "The target container cannot be const-qualified, please remove the const");
8284 static_assert(
8385 !is_volatile_v<_Container>, "The target container cannot be volatile-qualified, please remove the volatile");
84
86 static_assert(is_class_v<_Container> || is_union_v<_Container>, "The target must be a class type or union type");
8587 // First see if the non-recursive case applies -- the conversion target is either:
8688 // - a range with a convertible value type;
8789 // - a non-range type which might support being created from the input argument(s) (e.g. an `optional`).
......@@ -208,7 +210,7 @@ template <class _Container, class... _Args>
208210 static_assert(!is_const_v<_Container>, "The target container cannot be const-qualified, please remove the const");
209211 static_assert(
210212 !is_volatile_v<_Container>, "The target container cannot be volatile-qualified, please remove the volatile");
211
213 static_assert(is_class_v<_Container> || is_union_v<_Container>, "The target must be a class type or union type");
212214 auto __to_func = []<input_range _Range, class... _Tail>(_Range&& __range, _Tail&&... __tail) static
213215 requires requires { //
214216 /**/ ranges::to<_Container>(std::forward<_Range>(__range), std::forward<_Tail>(__tail)...);
lib/libcxx/include/__ranges/transform_view.h+6-5
......@@ -38,6 +38,7 @@
3838#include <__type_traits/is_nothrow_constructible.h>
3939#include <__type_traits/is_object.h>
4040#include <__type_traits/is_reference.h>
41#include <__type_traits/is_referenceable.h>
4142#include <__type_traits/maybe_const.h>
4243#include <__type_traits/remove_cvref.h>
4344#include <__utility/forward.h>
......@@ -63,7 +64,7 @@ concept __regular_invocable_with_range_ref = regular_invocable<_Fn, range_refere
6364template <class _View, class _Fn>
6465concept __transform_view_constraints =
6566 view<_View> && is_object_v<_Fn> && regular_invocable<_Fn&, range_reference_t<_View>> &&
66 __can_reference<invoke_result_t<_Fn&, range_reference_t<_View>>>;
67 __is_referenceable_v<invoke_result_t<_Fn&, range_reference_t<_View>>>;
6768
6869# if _LIBCPP_STD_VER >= 23
6970template <input_range _View, move_constructible _Fn>
......@@ -136,22 +137,22 @@ transform_view(_Range&&, _Fn) -> transform_view<views::all_t<_Range>, _Fn>;
136137
137138template <class _View>
138139struct __transform_view_iterator_concept {
139 using type = input_iterator_tag;
140 using type _LIBCPP_NODEBUG = input_iterator_tag;
140141};
141142
142143template <random_access_range _View>
143144struct __transform_view_iterator_concept<_View> {
144 using type = random_access_iterator_tag;
145 using type _LIBCPP_NODEBUG = random_access_iterator_tag;
145146};
146147
147148template <bidirectional_range _View>
148149struct __transform_view_iterator_concept<_View> {
149 using type = bidirectional_iterator_tag;
150 using type _LIBCPP_NODEBUG = bidirectional_iterator_tag;
150151};
151152
152153template <forward_range _View>
153154struct __transform_view_iterator_concept<_View> {
154 using type = forward_iterator_tag;
155 using type _LIBCPP_NODEBUG = forward_iterator_tag;
155156};
156157
157158template <class, class>
lib/libcxx/include/__ranges/zip_view.h+23-1
......@@ -23,6 +23,7 @@
2323#include <__iterator/iter_move.h>
2424#include <__iterator/iter_swap.h>
2525#include <__iterator/iterator_traits.h>
26#include <__iterator/product_iterator.h>
2627#include <__ranges/access.h>
2728#include <__ranges/all.h>
2829#include <__ranges/concepts.h>
......@@ -251,8 +252,12 @@ class zip_view<_Views...>::__iterator : public __zip_view_iterator_category_base
251252
252253 friend class zip_view<_Views...>;
253254
255 static constexpr bool __is_zip_view_iterator = true;
256
257 friend struct __product_iterator_traits<__iterator>;
258
254259public:
255 using iterator_concept = decltype(__get_zip_view_iterator_tag<_Const, _Views...>());
260 using iterator_concept = decltype(ranges::__get_zip_view_iterator_tag<_Const, _Views...>());
256261 using value_type = tuple<range_value_t<__maybe_const<_Const, _Views>>...>;
257262 using difference_type = common_type_t<range_difference_t<__maybe_const<_Const, _Views>>...>;
258263
......@@ -468,6 +473,23 @@ inline constexpr auto zip = __zip::__fn{};
468473} // namespace views
469474} // namespace ranges
470475
476template <class _Iterator>
477 requires _Iterator::__is_zip_view_iterator
478struct __product_iterator_traits<_Iterator> {
479 static constexpr size_t __size = tuple_size<decltype(std::declval<_Iterator>().__current_)>::value;
480
481 template <size_t _Nth, class _Iter>
482 requires(_Nth < __size)
483 _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_iterator_element(_Iter&& __it) {
484 return std::get<_Nth>(std::forward<_Iter>(__it).__current_);
485 }
486
487 template <class... _Iters>
488 _LIBCPP_HIDE_FROM_ABI static constexpr _Iterator __make_product_iterator(_Iters&&... __iters) {
489 return _Iterator(std::tuple(std::forward<_Iters>(__iters)...));
490 }
491};
492
471493#endif // _LIBCPP_STD_VER >= 23
472494
473495_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__split_buffer+8-3
......@@ -28,6 +28,7 @@
2828#include <__type_traits/integral_constant.h>
2929#include <__type_traits/is_nothrow_assignable.h>
3030#include <__type_traits/is_nothrow_constructible.h>
31#include <__type_traits/is_replaceable.h>
3132#include <__type_traits/is_swappable.h>
3233#include <__type_traits/is_trivially_destructible.h>
3334#include <__type_traits/is_trivially_relocatable.h>
......@@ -72,6 +73,10 @@ public:
7273 __libcpp_is_trivially_relocatable<pointer>::value && __libcpp_is_trivially_relocatable<allocator_type>::value,
7374 __split_buffer,
7475 void>;
76 using __replaceable _LIBCPP_NODEBUG =
77 __conditional_t<__is_replaceable_v<pointer> && __container_allocator_is_replaceable<__alloc_traits>::value,
78 __split_buffer,
79 void>;
7580
7681 pointer __first_;
7782 pointer __begin_;
......@@ -233,7 +238,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __split_buffer<_Tp, _Allocator>::__invariants
233238// Postcondition: size() == size() + __n
234239template <class _Tp, class _Allocator>
235240_LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n) {
236 _ConstructTransaction __tx(&this->__end_, __n);
241 _ConstructTransaction __tx(std::addressof(this->__end_), __n);
237242 for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) {
238243 __alloc_traits::construct(__alloc_, std::__to_address(__tx.__pos_));
239244 }
......@@ -248,7 +253,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::__construct_
248253template <class _Tp, class _Allocator>
249254_LIBCPP_CONSTEXPR_SINCE_CXX20 void
250255__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) {
251 _ConstructTransaction __tx(&this->__end_, __n);
256 _ConstructTransaction __tx(std::addressof(this->__end_), __n);
252257 for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) {
253258 __alloc_traits::construct(__alloc_, std::__to_address(__tx.__pos_), __x);
254259 }
......@@ -283,7 +288,7 @@ template <class _Tp, class _Allocator>
283288template <class _ForwardIterator>
284289_LIBCPP_CONSTEXPR_SINCE_CXX20 void
285290__split_buffer<_Tp, _Allocator>::__construct_at_end_with_size(_ForwardIterator __first, size_type __n) {
286 _ConstructTransaction __tx(&this->__end_, __n);
291 _ConstructTransaction __tx(std::addressof(this->__end_), __n);
287292 for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_, (void)++__first) {
288293 __alloc_traits::construct(__alloc_, std::__to_address(__tx.__pos_), *__first);
289294 }
lib/libcxx/include/__stop_token/atomic_unique_lock.h+1-1
......@@ -28,7 +28,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2828// and LockedBit is the value of State when the lock bit is set, e.g 1 << 2
2929template <class _State, _State _LockedBit>
3030class _LIBCPP_AVAILABILITY_SYNC __atomic_unique_lock {
31 static_assert(std::__libcpp_popcount(static_cast<unsigned long long>(_LockedBit)) == 1,
31 static_assert(std::__popcount(static_cast<unsigned long long>(_LockedBit)) == 1,
3232 "LockedBit must be an integer where only one bit is set");
3333
3434 std::atomic<_State>& __state_;
lib/libcxx/include/__stop_token/intrusive_shared_ptr.h+2-1
......@@ -14,6 +14,7 @@
1414#include <__atomic/memory_order.h>
1515#include <__config>
1616#include <__cstddef/nullptr_t.h>
17#include <__memory/addressof.h>
1718#include <__type_traits/is_reference.h>
1819#include <__utility/move.h>
1920#include <__utility/swap.h>
......@@ -113,7 +114,7 @@ private:
113114
114115 _LIBCPP_HIDE_FROM_ABI static void __decrement_ref_count(_Tp& __obj) {
115116 if (__get_atomic_ref_count(__obj).fetch_sub(1, std::memory_order_acq_rel) == 1) {
116 delete &__obj;
117 delete std::addressof(__obj);
117118 }
118119 }
119120
lib/libcxx/include/__string/char_traits.h+7-14
......@@ -78,7 +78,7 @@ exposition-only to document what members a char_traits specialization should pro
7878// char_traits<char>
7979
8080template <>
81struct _LIBCPP_TEMPLATE_VIS char_traits<char> {
81struct char_traits<char> {
8282 using char_type = char;
8383 using int_type = int;
8484 using off_type = streamoff;
......@@ -132,8 +132,6 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char> {
132132
133133 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const char_type*
134134 find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT {
135 if (__n == 0)
136 return nullptr;
137135 return std::__constexpr_memchr(__s, __a, __n);
138136 }
139137
......@@ -236,7 +234,7 @@ struct __char_traits_base {
236234
237235#if _LIBCPP_HAS_WIDE_CHARACTERS
238236template <>
239struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t> : __char_traits_base<wchar_t, wint_t, static_cast<wint_t>(WEOF)> {
237struct char_traits<wchar_t> : __char_traits_base<wchar_t, wint_t, static_cast<wint_t>(WEOF)> {
240238 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 int
241239 compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
242240 if (__n == 0)
......@@ -250,8 +248,6 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t> : __char_traits_base<wchar_t, w
250248
251249 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const char_type*
252250 find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT {
253 if (__n == 0)
254 return nullptr;
255251 return std::__constexpr_wmemchr(__s, __a, __n);
256252 }
257253};
......@@ -260,8 +256,7 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t> : __char_traits_base<wchar_t, w
260256#if _LIBCPP_HAS_CHAR8_T
261257
262258template <>
263struct _LIBCPP_TEMPLATE_VIS char_traits<char8_t>
264 : __char_traits_base<char8_t, unsigned int, static_cast<unsigned int>(EOF)> {
259struct char_traits<char8_t> : __char_traits_base<char8_t, unsigned int, static_cast<unsigned int>(EOF)> {
265260 static _LIBCPP_HIDE_FROM_ABI constexpr int
266261 compare(const char_type* __s1, const char_type* __s2, size_t __n) noexcept {
267262 return std::__constexpr_memcmp(__s1, __s2, __element_count(__n));
......@@ -280,8 +275,7 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char8_t>
280275#endif // _LIBCPP_HAS_CHAR8_T
281276
282277template <>
283struct _LIBCPP_TEMPLATE_VIS char_traits<char16_t>
284 : __char_traits_base<char16_t, uint_least16_t, static_cast<uint_least16_t>(0xFFFF)> {
278struct char_traits<char16_t> : __char_traits_base<char16_t, uint_least16_t, static_cast<uint_least16_t>(0xFFFF)> {
285279 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX17 int
286280 compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
287281 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX17 size_t length(const char_type* __s) _NOEXCEPT;
......@@ -315,8 +309,7 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX17 size_t char_traits<char16_t>::length(const
315309}
316310
317311template <>
318struct _LIBCPP_TEMPLATE_VIS char_traits<char32_t>
319 : __char_traits_base<char32_t, uint_least32_t, static_cast<uint_least32_t>(0xFFFFFFFF)> {
312struct char_traits<char32_t> : __char_traits_base<char32_t, uint_least32_t, static_cast<uint_least32_t>(0xFFFFFFFF)> {
320313 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX17 int
321314 compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
322315 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX17 size_t length(const char_type* __s) _NOEXCEPT;
......@@ -355,7 +348,7 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX17 size_t char_traits<char32_t>::length(const
355348template <class _CharT, class _SizeT, class _Traits, _SizeT __npos>
356349inline _SizeT _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
357350__str_find(const _CharT* __p, _SizeT __sz, _CharT __c, _SizeT __pos) _NOEXCEPT {
358 if (__pos >= __sz)
351 if (__pos > __sz)
359352 return __npos;
360353 const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c);
361354 if (__r == nullptr)
......@@ -534,7 +527,7 @@ __str_find_last_not_of(const _CharT* __p, _SizeT __sz, _CharT __c, _SizeT __pos)
534527template <class _Ptr>
535528inline _LIBCPP_HIDE_FROM_ABI size_t __do_string_hash(_Ptr __p, _Ptr __e) {
536529 typedef typename iterator_traits<_Ptr>::value_type value_type;
537 return __murmur2_or_cityhash<size_t>()(__p, (__e - __p) * sizeof(value_type));
530 return std::__hash_memory(__p, (__e - __p) * sizeof(value_type));
538531}
539532
540533_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__string/constexpr_c_functions.h+13-10
......@@ -146,7 +146,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __constexpr_memchr(_Tp*
146146 return nullptr;
147147 } else {
148148 char __value_buffer = 0;
149 __builtin_memcpy(&__value_buffer, &__value, sizeof(char));
149 __builtin_memcpy(&__value_buffer, std::addressof(__value), sizeof(char));
150150 return static_cast<_Tp*>(__builtin_memchr(__str, __value_buffer, __count));
151151 }
152152}
......@@ -204,23 +204,26 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& __assign_trivially_copy
204204 return __dest;
205205}
206206
207template <class _Tp, class _Up, __enable_if_t<__is_always_bitcastable<_Up, _Tp>::value, int> = 0>
207template <class _Tp, class _Up>
208208_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp*
209209__constexpr_memmove(_Tp* __dest, _Up* __src, __element_count __n) {
210 static_assert(__is_always_bitcastable<_Up, _Tp>::value);
210211 size_t __count = static_cast<size_t>(__n);
211212 if (__libcpp_is_constant_evaluated()) {
212213#ifdef _LIBCPP_COMPILER_CLANG_BASED
213 if (is_same<__remove_cv_t<_Tp>, __remove_cv_t<_Up> >::value) {
214 if _LIBCPP_CONSTEXPR (is_same<__remove_cv_t<_Tp>, __remove_cv_t<_Up> >::value) {
214215 ::__builtin_memmove(__dest, __src, __count * sizeof(_Tp));
215216 return __dest;
216 }
217 } else
217218#endif
218 if (std::__is_pointer_in_range(__src, __src + __count, __dest)) {
219 for (; __count > 0; --__count)
220 std::__assign_trivially_copyable(__dest[__count - 1], __src[__count - 1]);
221 } else {
222 for (size_t __i = 0; __i != __count; ++__i)
223 std::__assign_trivially_copyable(__dest[__i], __src[__i]);
219 {
220 if (std::__is_pointer_in_range(__src, __src + __count, __dest)) {
221 for (; __count > 0; --__count)
222 std::__assign_trivially_copyable(__dest[__count - 1], __src[__count - 1]);
223 } else {
224 for (size_t __i = 0; __i != __count; ++__i)
225 std::__assign_trivially_copyable(__dest[__i], __src[__i]);
226 }
224227 }
225228 } else if (__count > 0) {
226229 ::__builtin_memmove(__dest, __src, (__count - 1) * sizeof(_Tp) + __datasizeof_v<_Tp>);
lib/libcxx/include/__string/extern_template_lists.h+63-102
......@@ -17,116 +17,77 @@
1717
1818// clang-format off
1919
20// We maintain 2 ABI lists:
20// We maintain multiple ABI lists:
21// - _LIBCPP_STRING_COMMON_EXTERN_TEMPLATE_LIST
2122// - _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST
2223// - _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST
23// As the name implies, the ABI lists define the V1 (Stable) and unstable ABI.
24// As the name implies, the ABI lists define a common subset, the V1 (Stable) and unstable ABI.
2425//
25// For unstable, we may explicitly remove function that are external in V1,
26// and add (new) external functions to better control inlining and compiler
27// optimization opportunities.
26// For unstable, we may explicitly remove function that are external in V1.
2827//
2928// For stable, the ABI list should rarely change, except for adding new
3029// functions supporting new c++ version / API changes. Typically entries
3130// must never be removed from the stable list.
32#define _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_Func, _CharType) \
33 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*, size_type)) \
34 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type const*, size_type, size_type) const) \
35 _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::__init(value_type const*, size_type, size_type)) \
36 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::basic_string(basic_string const&)) \
37 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*)) \
38 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::basic_string(basic_string const&, allocator<_CharType> const&)) \
39 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::find_last_not_of(value_type const*, size_type, size_type) const) \
40 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::~basic_string()) \
41 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::find_first_not_of(value_type const*, size_type, size_type) const) \
42 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::insert(size_type, size_type, value_type)) \
43 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::operator=(value_type)) \
44 _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::__init(value_type const*, size_type)) \
45 _Func(_LIBCPP_EXPORTED_FROM_ABI const _CharType& basic_string<_CharType>::at(size_type) const) \
46 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*, size_type)) \
47 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::find_first_of(value_type const*, size_type, size_type) const) \
48 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, size_type, value_type)) \
49 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::assign(value_type const*, size_type)) \
50 _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::reserve(size_type)) \
51 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::append(value_type const*, size_type)) \
52 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::assign(basic_string const&, size_type, size_type)) \
53 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::copy(value_type*, size_type, size_type) const) \
54 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::basic_string(basic_string const&, size_type, size_type, allocator<_CharType> const&)) \
55 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type, size_type) const) \
56 _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::__init(size_type, value_type)) \
57 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*)) \
58 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::find_last_of(value_type const*, size_type, size_type) const) \
59 _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::__grow_by(size_type, size_type, size_type, size_type, size_type, size_type)) \
60 _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::__grow_by_and_replace(size_type, size_type, size_type, size_type, size_type, size_type, value_type const*)) \
61 _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::push_back(value_type)) \
62 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::append(size_type, value_type)) \
63 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type, size_type) const) \
64 _Func(_LIBCPP_EXPORTED_FROM_ABI const basic_string<_CharType>::size_type basic_string<_CharType>::npos) \
65 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::assign(size_type, value_type)) \
66 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::erase(size_type, size_type)) \
67 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::append(basic_string const&, size_type, size_type)) \
68 _Func(_LIBCPP_EXPORTED_FROM_ABI int basic_string<_CharType>::compare(value_type const*) const) \
69 _Func(_LIBCPP_EXPORTED_FROM_ABI int basic_string<_CharType>::compare(size_type, size_type, value_type const*) const) \
70 _Func(_LIBCPP_EXPORTED_FROM_ABI _CharType& basic_string<_CharType>::at(size_type)) \
71 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::assign(value_type const*)) \
72 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type const*, size_type, size_type) const) \
73 _Func(_LIBCPP_EXPORTED_FROM_ABI int basic_string<_CharType>::compare(size_type, size_type, basic_string const&, size_type, size_type) const) \
74 _Func(_LIBCPP_EXPORTED_FROM_ABI int basic_string<_CharType>::compare(size_type, size_type, value_type const*, size_type) const) \
75 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::operator=(basic_string const&)) \
76 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::append(value_type const*)) \
77 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, basic_string const&, size_type, size_type)) \
78 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::iterator basic_string<_CharType>::insert(basic_string::const_iterator, value_type)) \
79 _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::resize(size_type, value_type)) \
80 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::insert(size_type, basic_string const&, size_type, size_type))
31#define _LIBCPP_STRING_COMMON_EXTERN_TEMPLATE_LIST(Func, CharT) \
32 Func(void basic_string<CharT>::__init(const value_type*, size_type)) \
33 Func(void basic_string<CharT>::__init(size_type, value_type)) \
34 Func(basic_string<CharT>::basic_string(const basic_string&, size_type, size_type, const allocator<CharT>&)) \
35 Func(basic_string<CharT>::~basic_string()) \
36 Func(basic_string<CharT>& basic_string<CharT>::operator=(value_type)) \
37 Func(basic_string<CharT>& basic_string<CharT>::assign(size_type, value_type)) \
38 Func(basic_string<CharT>& basic_string<CharT>::assign(const basic_string&, size_type, size_type)) \
39 Func(basic_string<CharT>& basic_string<CharT>::append(size_type, value_type)) \
40 Func(basic_string<CharT>& basic_string<CharT>::append(const value_type*)) \
41 Func(basic_string<CharT>& basic_string<CharT>::append(const value_type*, size_type)) \
42 Func(basic_string<CharT>& basic_string<CharT>::append(const basic_string&, size_type, size_type)) \
43 Func(void basic_string<CharT>::push_back(value_type)) \
44 Func(basic_string<CharT>& basic_string<CharT>::insert(size_type, const value_type*)) \
45 Func(basic_string<CharT>& basic_string<CharT>::insert(size_type, size_type, value_type)) \
46 Func(basic_string<CharT>& basic_string<CharT>::insert(size_type, const value_type*, size_type)) \
47 Func(basic_string<CharT>& basic_string<CharT>::insert(size_type, const basic_string&, size_type, size_type)) \
48 Func(basic_string<CharT>::iterator basic_string<CharT>::insert(basic_string::const_iterator, value_type)) \
49 Func(basic_string<CharT>& basic_string<CharT>::replace(size_type, size_type, const value_type*)) \
50 Func(basic_string<CharT>& basic_string<CharT>::replace(size_type, size_type, size_type, value_type)) \
51 Func(basic_string<CharT>& basic_string<CharT>::replace(size_type, size_type, const value_type*, size_type)) \
52 Func(basic_string<CharT>& basic_string<CharT>::replace(size_type, size_type, const basic_string&, size_type, size_type)) \
53 Func(void basic_string<CharT>::__grow_by_and_replace(size_type, size_type, size_type, size_type, size_type, size_type, const value_type*)) \
54 Func(void basic_string<CharT>::resize(size_type, value_type)) \
55 Func(void basic_string<CharT>::reserve(size_type)) \
56 Func(basic_string<CharT>::size_type basic_string<CharT>::copy(value_type*, size_type, size_type) const) \
57 Func(basic_string<CharT>::size_type basic_string<CharT>::find(value_type, size_type) const) \
58 Func(basic_string<CharT>::size_type basic_string<CharT>::find(const value_type*, size_type, size_type) const) \
59 Func(basic_string<CharT>::size_type basic_string<CharT>::rfind(value_type, size_type) const) \
60 Func(basic_string<CharT>::size_type basic_string<CharT>::rfind(const value_type*, size_type, size_type) const) \
61 Func(basic_string<CharT>::size_type basic_string<CharT>::find_first_of(const value_type*, size_type, size_type) const) \
62 Func(basic_string<CharT>::size_type basic_string<CharT>::find_last_of(const value_type*, size_type, size_type) const) \
63 Func(basic_string<CharT>::size_type basic_string<CharT>::find_first_not_of(const value_type*, size_type, size_type) const) \
64 Func(basic_string<CharT>::size_type basic_string<CharT>::find_last_not_of(const value_type*, size_type, size_type) const) \
65 Func(CharT& basic_string<CharT>::at(size_type)) \
66 Func(const CharT& basic_string<CharT>::at(size_type) const) \
67 Func(int basic_string<CharT>::compare(const value_type*) const) \
68 Func(int basic_string<CharT>::compare(size_type, size_type, const value_type*) const) \
69 Func(int basic_string<CharT>::compare(size_type, size_type, const value_type*, size_type) const) \
70 Func(int basic_string<CharT>::compare(size_type, size_type, const basic_string&, size_type, size_type) const) \
71 Func(const basic_string<CharT>::size_type basic_string<CharT>::npos) \
8172
82#define _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_Func, _CharType) \
83 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*, size_type)) \
84 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type const*, size_type, size_type) const) \
85 _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::__init(value_type const*, size_type, size_type)) \
86 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*)) \
87 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::find_last_not_of(value_type const*, size_type, size_type) const) \
88 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::~basic_string()) \
89 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::find_first_not_of(value_type const*, size_type, size_type) const) \
90 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::insert(size_type, size_type, value_type)) \
91 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::operator=(value_type)) \
92 _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::__init(value_type const*, size_type)) \
93 _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::__init_copy_ctor_external(value_type const*, size_type)) \
94 _Func(_LIBCPP_EXPORTED_FROM_ABI const _CharType& basic_string<_CharType>::at(size_type) const) \
95 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*, size_type)) \
96 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::find_first_of(value_type const*, size_type, size_type) const) \
97 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, size_type, value_type)) \
98 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::__assign_external(value_type const*, size_type)) \
99 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::__assign_external(value_type const*)) \
100 _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::reserve(size_type)) \
101 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::append(value_type const*, size_type)) \
102 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::assign(basic_string const&, size_type, size_type)) \
103 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::copy(value_type*, size_type, size_type) const) \
104 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::basic_string(basic_string const&, size_type, size_type, allocator<_CharType> const&)) \
105 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type, size_type) const) \
106 _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::__init(size_type, value_type)) \
107 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::insert(size_type, value_type const*)) \
108 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::find_last_of(value_type const*, size_type, size_type) const) \
109 _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::__grow_by_and_replace(size_type, size_type, size_type, size_type, size_type, size_type, value_type const*)) \
110 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::__assign_no_alias<false>(value_type const*, size_type)) \
111 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::__assign_no_alias<true>(value_type const*, size_type)) \
112 _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::push_back(value_type)) \
113 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::append(size_type, value_type)) \
114 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type, size_type) const) \
115 _Func(_LIBCPP_EXPORTED_FROM_ABI const basic_string<_CharType>::size_type basic_string<_CharType>::npos) \
116 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::assign(size_type, value_type)) \
117 _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::__erase_external_with_move(size_type, size_type)) \
118 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::append(basic_string const&, size_type, size_type)) \
119 _Func(_LIBCPP_EXPORTED_FROM_ABI int basic_string<_CharType>::compare(value_type const*) const) \
120 _Func(_LIBCPP_EXPORTED_FROM_ABI int basic_string<_CharType>::compare(size_type, size_type, value_type const*) const) \
121 _Func(_LIBCPP_EXPORTED_FROM_ABI _CharType& basic_string<_CharType>::at(size_type)) \
122 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::find(value_type const*, size_type, size_type) const) \
123 _Func(_LIBCPP_EXPORTED_FROM_ABI int basic_string<_CharType>::compare(size_type, size_type, basic_string const&, size_type, size_type) const) \
124 _Func(_LIBCPP_EXPORTED_FROM_ABI int basic_string<_CharType>::compare(size_type, size_type, value_type const*, size_type) const) \
125 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::append(value_type const*)) \
126 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, basic_string const&, size_type, size_type)) \
127 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::iterator basic_string<_CharType>::insert(basic_string::const_iterator, value_type)) \
128 _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::resize(size_type, value_type)) \
129 _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::insert(size_type, basic_string const&, size_type, size_type))
73#define _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(Func, CharT) \
74 _LIBCPP_STRING_COMMON_EXTERN_TEMPLATE_LIST(Func, CharT) \
75 Func(basic_string<CharT>::basic_string(const basic_string&)) \
76 Func(basic_string<CharT>::basic_string(const basic_string&, const allocator<CharT>&)) \
77 Func(basic_string<CharT>& basic_string<CharT>::assign(const value_type*)) \
78 Func(basic_string<CharT>& basic_string<CharT>::assign(const value_type*, size_type)) \
79 Func(basic_string<CharT>& basic_string<CharT>::operator=(basic_string const&)) \
80 Func(void basic_string<CharT>::__grow_by(size_type, size_type, size_type, size_type, size_type, size_type)) \
81 Func(basic_string<CharT>& basic_string<CharT>::erase(size_type, size_type)) \
82
83#define _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(Func, CharT) \
84 _LIBCPP_STRING_COMMON_EXTERN_TEMPLATE_LIST(Func, CharT) \
85 Func(void basic_string<CharT>::__init_copy_ctor_external(const value_type*, size_type)) \
86 Func(basic_string<CharT>& basic_string<CharT>::__assign_external(const value_type*, size_type)) \
87 Func(basic_string<CharT>& basic_string<CharT>::__assign_external(const value_type*)) \
88 Func(basic_string<CharT>& basic_string<CharT>::__assign_no_alias<false>(const value_type*, size_type)) \
89 Func(basic_string<CharT>& basic_string<CharT>::__assign_no_alias<true>(const value_type*, size_type)) \
90 Func(void basic_string<CharT>::__erase_external_with_move(size_type, size_type))
13091
13192// clang-format on
13293
lib/libcxx/include/__system_error/error_category.h+2-2
......@@ -67,8 +67,8 @@ public:
6767 string message(int __ev) const override;
6868};
6969
70__attribute__((__const__)) _LIBCPP_EXPORTED_FROM_ABI const error_category& generic_category() _NOEXCEPT;
71__attribute__((__const__)) _LIBCPP_EXPORTED_FROM_ABI const error_category& system_category() _NOEXCEPT;
70[[__gnu__::__const__]] _LIBCPP_EXPORTED_FROM_ABI const error_category& generic_category() _NOEXCEPT;
71[[__gnu__::__const__]] _LIBCPP_EXPORTED_FROM_ABI const error_category& system_category() _NOEXCEPT;
7272
7373_LIBCPP_END_NAMESPACE_STD
7474
lib/libcxx/include/__system_error/error_code.h+2-2
......@@ -26,7 +26,7 @@
2626_LIBCPP_BEGIN_NAMESPACE_STD
2727
2828template <class _Tp>
29struct _LIBCPP_TEMPLATE_VIS is_error_code_enum : public false_type {};
29struct is_error_code_enum : public false_type {};
3030
3131#if _LIBCPP_STD_VER >= 17
3232template <class _Tp>
......@@ -131,7 +131,7 @@ inline _LIBCPP_HIDE_FROM_ABI strong_ordering operator<=>(const error_code& __x,
131131#endif // _LIBCPP_STD_VER <= 17
132132
133133template <>
134struct _LIBCPP_TEMPLATE_VIS hash<error_code> : public __unary_function<error_code, size_t> {
134struct hash<error_code> : public __unary_function<error_code, size_t> {
135135 _LIBCPP_HIDE_FROM_ABI size_t operator()(const error_code& __ec) const _NOEXCEPT {
136136 return static_cast<size_t>(__ec.value());
137137 }
lib/libcxx/include/__system_error/error_condition.h+4-4
......@@ -25,7 +25,7 @@
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
2727template <class _Tp>
28struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum : public false_type {};
28struct is_error_condition_enum : public false_type {};
2929
3030#if _LIBCPP_STD_VER >= 17
3131template <class _Tp>
......@@ -33,11 +33,11 @@ inline constexpr bool is_error_condition_enum_v = is_error_condition_enum<_Tp>::
3333#endif
3434
3535template <>
36struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc> : true_type {};
36struct is_error_condition_enum<errc> : true_type {};
3737
3838#ifdef _LIBCPP_CXX03_LANG
3939template <>
40struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc::__lx> : true_type {};
40struct is_error_condition_enum<errc::__lx> : true_type {};
4141#endif
4242
4343namespace __adl_only {
......@@ -118,7 +118,7 @@ operator<=>(const error_condition& __x, const error_condition& __y) noexcept {
118118#endif // _LIBCPP_STD_VER <= 17
119119
120120template <>
121struct _LIBCPP_TEMPLATE_VIS hash<error_condition> : public __unary_function<error_condition, size_t> {
121struct hash<error_condition> : public __unary_function<error_condition, size_t> {
122122 _LIBCPP_HIDE_FROM_ABI size_t operator()(const error_condition& __ec) const _NOEXCEPT {
123123 return static_cast<size_t>(__ec.value());
124124 }
lib/libcxx/include/__thread/formatter.h+1-1
......@@ -34,7 +34,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3434# if _LIBCPP_HAS_THREADS
3535
3636template <__fmt_char_type _CharT>
37struct _LIBCPP_TEMPLATE_VIS formatter<__thread_id, _CharT> {
37struct formatter<__thread_id, _CharT> {
3838public:
3939 template <class _ParseContext>
4040 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
lib/libcxx/include/__thread/id.h+2-2
......@@ -34,7 +34,7 @@ _LIBCPP_HIDE_FROM_ABI __thread_id get_id() _NOEXCEPT;
3434template <>
3535struct hash<__thread_id>;
3636
37class _LIBCPP_TEMPLATE_VIS __thread_id {
37class __thread_id {
3838 // FIXME: pthread_t is a pointer on Darwin but a long on Linux.
3939 // NULL is the no-thread value on Darwin. Someone needs to check
4040 // on other platforms. We assume 0 works everywhere for now.
......@@ -72,7 +72,7 @@ private:
7272
7373 friend __thread_id this_thread::get_id() _NOEXCEPT;
7474 friend class _LIBCPP_EXPORTED_FROM_ABI thread;
75 friend struct _LIBCPP_TEMPLATE_VIS hash<__thread_id>;
75 friend struct hash<__thread_id>;
7676};
7777
7878inline _LIBCPP_HIDE_FROM_ABI bool operator==(__thread_id __x, __thread_id __y) _NOEXCEPT {
lib/libcxx/include/__thread/support/windows.h+2-4
......@@ -28,12 +28,10 @@ using __libcpp_timespec_t = ::timespec;
2828typedef void* __libcpp_mutex_t;
2929#define _LIBCPP_MUTEX_INITIALIZER 0
3030
31#if defined(_M_IX86) || defined(__i386__) || defined(_M_ARM) || defined(__arm__)
32typedef void* __libcpp_recursive_mutex_t[6];
33#elif defined(_M_AMD64) || defined(__x86_64__) || defined(_M_ARM64) || defined(__aarch64__)
31#if defined(_WIN64)
3432typedef void* __libcpp_recursive_mutex_t[5];
3533#else
36# error Unsupported architecture
34typedef void* __libcpp_recursive_mutex_t[6];
3735#endif
3836
3937_LIBCPP_EXPORTED_FROM_ABI int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t* __m);
lib/libcxx/include/__thread/thread.h+65-69
......@@ -16,6 +16,8 @@
1616#include <__exception/terminate.h>
1717#include <__functional/hash.h>
1818#include <__functional/unary_function.h>
19#include <__locale>
20#include <__memory/addressof.h>
1921#include <__memory/unique_ptr.h>
2022#include <__mutex/mutex.h>
2123#include <__system_error/throw_system_error.h>
......@@ -29,7 +31,6 @@
2931#include <tuple>
3032
3133#if _LIBCPP_HAS_LOCALIZATION
32# include <locale>
3334# include <sstream>
3435#endif
3536
......@@ -100,7 +101,7 @@ template <class _Tp>
100101__thread_specific_ptr<_Tp>::__thread_specific_ptr() {
101102 int __ec = __libcpp_tls_create(&__key_, &__thread_specific_ptr::__at_thread_exit);
102103 if (__ec)
103 __throw_system_error(__ec, "__thread_specific_ptr construction failed");
104 std::__throw_system_error(__ec, "__thread_specific_ptr construction failed");
104105}
105106
106107template <class _Tp>
......@@ -118,7 +119,7 @@ void __thread_specific_ptr<_Tp>::set_pointer(pointer __p) {
118119}
119120
120121template <>
121struct _LIBCPP_TEMPLATE_VIS hash<__thread_id> : public __unary_function<__thread_id, size_t> {
122struct hash<__thread_id> : public __unary_function<__thread_id, size_t> {
122123 _LIBCPP_HIDE_FROM_ABI size_t operator()(__thread_id __v) const _NOEXCEPT {
123124 return hash<__libcpp_thread_id>()(__v.__id_);
124125 }
......@@ -151,47 +152,6 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, __thread_id __id) {
151152}
152153# endif // _LIBCPP_HAS_LOCALIZATION
153154
154class _LIBCPP_EXPORTED_FROM_ABI thread {
155 __libcpp_thread_t __t_;
156
157 thread(const thread&);
158 thread& operator=(const thread&);
159
160public:
161 typedef __thread_id id;
162 typedef __libcpp_thread_t native_handle_type;
163
164 _LIBCPP_HIDE_FROM_ABI thread() _NOEXCEPT : __t_(_LIBCPP_NULL_THREAD) {}
165# ifndef _LIBCPP_CXX03_LANG
166 template <class _Fp, class... _Args, __enable_if_t<!is_same<__remove_cvref_t<_Fp>, thread>::value, int> = 0>
167 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS explicit thread(_Fp&& __f, _Args&&... __args);
168# else // _LIBCPP_CXX03_LANG
169 template <class _Fp>
170 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS explicit thread(_Fp __f);
171# endif
172 ~thread();
173
174 _LIBCPP_HIDE_FROM_ABI thread(thread&& __t) _NOEXCEPT : __t_(__t.__t_) { __t.__t_ = _LIBCPP_NULL_THREAD; }
175
176 _LIBCPP_HIDE_FROM_ABI thread& operator=(thread&& __t) _NOEXCEPT {
177 if (!__libcpp_thread_isnull(&__t_))
178 terminate();
179 __t_ = __t.__t_;
180 __t.__t_ = _LIBCPP_NULL_THREAD;
181 return *this;
182 }
183
184 _LIBCPP_HIDE_FROM_ABI void swap(thread& __t) _NOEXCEPT { std::swap(__t_, __t.__t_); }
185
186 _LIBCPP_HIDE_FROM_ABI bool joinable() const _NOEXCEPT { return !__libcpp_thread_isnull(&__t_); }
187 void join();
188 void detach();
189 _LIBCPP_HIDE_FROM_ABI id get_id() const _NOEXCEPT { return __libcpp_thread_get_id(&__t_); }
190 _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() _NOEXCEPT { return __t_; }
191
192 static unsigned hardware_concurrency() _NOEXCEPT;
193};
194
195155# ifndef _LIBCPP_CXX03_LANG
196156
197157template <class _TSp, class _Fp, class... _Args, size_t... _Indices>
......@@ -209,19 +169,6 @@ _LIBCPP_HIDE_FROM_ABI void* __thread_proxy(void* __vp) {
209169 return nullptr;
210170}
211171
212template <class _Fp, class... _Args, __enable_if_t<!is_same<__remove_cvref_t<_Fp>, thread>::value, int> >
213thread::thread(_Fp&& __f, _Args&&... __args) {
214 typedef unique_ptr<__thread_struct> _TSPtr;
215 _TSPtr __tsp(new __thread_struct);
216 typedef tuple<_TSPtr, __decay_t<_Fp>, __decay_t<_Args>...> _Gp;
217 unique_ptr<_Gp> __p(new _Gp(std::move(__tsp), std::forward<_Fp>(__f), std::forward<_Args>(__args)...));
218 int __ec = std::__libcpp_thread_create(&__t_, &__thread_proxy<_Gp>, __p.get());
219 if (__ec == 0)
220 __p.release();
221 else
222 __throw_system_error(__ec, "thread constructor failed");
223}
224
225172# else // _LIBCPP_CXX03_LANG
226173
227174template <class _Fp>
......@@ -242,20 +189,69 @@ _LIBCPP_HIDE_FROM_ABI void* __thread_proxy_cxx03(void* __vp) {
242189 return nullptr;
243190}
244191
245template <class _Fp>
246thread::thread(_Fp __f) {
247 typedef __thread_invoke_pair<_Fp> _InvokePair;
248 typedef unique_ptr<_InvokePair> _PairPtr;
249 _PairPtr __pp(new _InvokePair(__f));
250 int __ec = std::__libcpp_thread_create(&__t_, &__thread_proxy_cxx03<_InvokePair>, __pp.get());
251 if (__ec == 0)
252 __pp.release();
253 else
254 __throw_system_error(__ec, "thread constructor failed");
255}
256
257192# endif // _LIBCPP_CXX03_LANG
258193
194class _LIBCPP_EXPORTED_FROM_ABI thread {
195 __libcpp_thread_t __t_;
196
197 thread(const thread&);
198 thread& operator=(const thread&);
199
200public:
201 typedef __thread_id id;
202 typedef __libcpp_thread_t native_handle_type;
203
204 _LIBCPP_HIDE_FROM_ABI thread() _NOEXCEPT : __t_(_LIBCPP_NULL_THREAD) {}
205
206# ifndef _LIBCPP_CXX03_LANG
207 template <class _Fp, class... _Args, __enable_if_t<!is_same<__remove_cvref_t<_Fp>, thread>::value, int> = 0>
208 _LIBCPP_HIDE_FROM_ABI explicit thread(_Fp&& __f, _Args&&... __args) {
209 typedef unique_ptr<__thread_struct> _TSPtr;
210 _TSPtr __tsp(new __thread_struct);
211 typedef tuple<_TSPtr, __decay_t<_Fp>, __decay_t<_Args>...> _Gp;
212 unique_ptr<_Gp> __p(new _Gp(std::move(__tsp), std::forward<_Fp>(__f), std::forward<_Args>(__args)...));
213 int __ec = std::__libcpp_thread_create(&__t_, std::addressof(__thread_proxy<_Gp>), __p.get());
214 if (__ec == 0)
215 __p.release();
216 else
217 __throw_system_error(__ec, "thread constructor failed");
218 }
219# else // _LIBCPP_CXX03_LANG
220 template <class _Fp>
221 _LIBCPP_HIDE_FROM_ABI explicit thread(_Fp __f) {
222 typedef __thread_invoke_pair<_Fp> _InvokePair;
223 typedef unique_ptr<_InvokePair> _PairPtr;
224 _PairPtr __pp(new _InvokePair(__f));
225 int __ec = std::__libcpp_thread_create(&__t_, &__thread_proxy_cxx03<_InvokePair>, __pp.get());
226 if (__ec == 0)
227 __pp.release();
228 else
229 __throw_system_error(__ec, "thread constructor failed");
230 }
231# endif
232 ~thread();
233
234 _LIBCPP_HIDE_FROM_ABI thread(thread&& __t) _NOEXCEPT : __t_(__t.__t_) { __t.__t_ = _LIBCPP_NULL_THREAD; }
235
236 _LIBCPP_HIDE_FROM_ABI thread& operator=(thread&& __t) _NOEXCEPT {
237 if (!__libcpp_thread_isnull(&__t_))
238 terminate();
239 __t_ = __t.__t_;
240 __t.__t_ = _LIBCPP_NULL_THREAD;
241 return *this;
242 }
243
244 _LIBCPP_HIDE_FROM_ABI void swap(thread& __t) _NOEXCEPT { std::swap(__t_, __t.__t_); }
245
246 _LIBCPP_HIDE_FROM_ABI bool joinable() const _NOEXCEPT { return !__libcpp_thread_isnull(&__t_); }
247 void join();
248 void detach();
249 _LIBCPP_HIDE_FROM_ABI id get_id() const _NOEXCEPT { return __libcpp_thread_get_id(&__t_); }
250 _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() _NOEXCEPT { return __t_; }
251
252 static unsigned hardware_concurrency() _NOEXCEPT;
253};
254
259255inline _LIBCPP_HIDE_FROM_ABI void swap(thread& __x, thread& __y) _NOEXCEPT { __x.swap(__y); }
260256
261257#endif // _LIBCPP_HAS_THREADS
lib/libcxx/include/__tree+269-361
......@@ -13,6 +13,9 @@
1313#include <__algorithm/min.h>
1414#include <__assert>
1515#include <__config>
16#include <__fwd/map.h>
17#include <__fwd/pair.h>
18#include <__fwd/set.h>
1619#include <__iterator/distance.h>
1720#include <__iterator/iterator_traits.h>
1821#include <__iterator/next.h>
......@@ -23,6 +26,7 @@
2326#include <__memory/swap_allocator.h>
2427#include <__memory/unique_ptr.h>
2528#include <__type_traits/can_extract_key.h>
29#include <__type_traits/copy_cvref.h>
2630#include <__type_traits/enable_if.h>
2731#include <__type_traits/invoke.h>
2832#include <__type_traits/is_const.h>
......@@ -31,6 +35,7 @@
3135#include <__type_traits/is_nothrow_constructible.h>
3236#include <__type_traits/is_same.h>
3337#include <__type_traits/is_swappable.h>
38#include <__type_traits/remove_const.h>
3439#include <__type_traits/remove_const_ref.h>
3540#include <__type_traits/remove_cvref.h>
3641#include <__utility/forward.h>
......@@ -48,21 +53,12 @@ _LIBCPP_PUSH_MACROS
4853
4954_LIBCPP_BEGIN_NAMESPACE_STD
5055
51template <class, class, class, class>
52class _LIBCPP_TEMPLATE_VIS map;
53template <class, class, class, class>
54class _LIBCPP_TEMPLATE_VIS multimap;
55template <class, class, class>
56class _LIBCPP_TEMPLATE_VIS set;
57template <class, class, class>
58class _LIBCPP_TEMPLATE_VIS multiset;
59
6056template <class _Tp, class _Compare, class _Allocator>
6157class __tree;
6258template <class _Tp, class _NodePtr, class _DiffType>
63class _LIBCPP_TEMPLATE_VIS __tree_iterator;
59class __tree_iterator;
6460template <class _Tp, class _ConstNodePtr, class _DiffType>
65class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
61class __tree_const_iterator;
6662
6763template <class _Pointer>
6864class __tree_end_node;
......@@ -77,9 +73,9 @@ struct __value_type;
7773template <class _Allocator>
7874class __map_node_destructor;
7975template <class _TreeIterator>
80class _LIBCPP_TEMPLATE_VIS __map_iterator;
76class __map_iterator;
8177template <class _TreeIterator>
82class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
78class __map_const_iterator;
8379
8480/*
8581
......@@ -142,7 +138,7 @@ unsigned __tree_sub_invariant(_NodePtr __x) {
142138}
143139
144140// Determines if the red black tree rooted at __root is a proper red black tree.
145// __root == nullptr is a proper tree. Returns true is __root is a proper
141// __root == nullptr is a proper tree. Returns true if __root is a proper
146142// red black tree, else returns false.
147143template <class _NodePtr>
148144_LIBCPP_HIDE_FROM_ABI bool __tree_invariant(_NodePtr __root) {
......@@ -510,119 +506,42 @@ template <class _One>
510506struct __is_tree_value_type<_One> : __is_tree_value_type_imp<__remove_cvref_t<_One> > {};
511507
512508template <class _Tp>
513struct __tree_key_value_types {
514 typedef _Tp key_type;
515 typedef _Tp __node_value_type;
516 typedef _Tp __container_value_type;
517 static const bool __is_map = false;
518
519 _LIBCPP_HIDE_FROM_ABI static key_type const& __get_key(_Tp const& __v) { return __v; }
520 _LIBCPP_HIDE_FROM_ABI static __container_value_type const& __get_value(__node_value_type const& __v) { return __v; }
521 _LIBCPP_HIDE_FROM_ABI static __container_value_type* __get_ptr(__node_value_type& __n) { return std::addressof(__n); }
522 _LIBCPP_HIDE_FROM_ABI static __container_value_type&& __move(__node_value_type& __v) { return std::move(__v); }
509struct __get_tree_key_type {
510 using type _LIBCPP_NODEBUG = _Tp;
523511};
524512
525template <class _Key, class _Tp>
526struct __tree_key_value_types<__value_type<_Key, _Tp> > {
527 typedef _Key key_type;
528 typedef _Tp mapped_type;
529 typedef __value_type<_Key, _Tp> __node_value_type;
530 typedef pair<const _Key, _Tp> __container_value_type;
531 typedef __container_value_type __map_value_type;
532 static const bool __is_map = true;
533
534 _LIBCPP_HIDE_FROM_ABI static key_type const& __get_key(__node_value_type const& __t) {
535 return __t.__get_value().first;
536 }
537
538 template <class _Up, __enable_if_t<__is_same_uncvref<_Up, __container_value_type>::value, int> = 0>
539 _LIBCPP_HIDE_FROM_ABI static key_type const& __get_key(_Up& __t) {
540 return __t.first;
541 }
542
543 _LIBCPP_HIDE_FROM_ABI static __container_value_type const& __get_value(__node_value_type const& __t) {
544 return __t.__get_value();
545 }
546
547 template <class _Up, __enable_if_t<__is_same_uncvref<_Up, __container_value_type>::value, int> = 0>
548 _LIBCPP_HIDE_FROM_ABI static __container_value_type const& __get_value(_Up& __t) {
549 return __t;
550 }
551
552 _LIBCPP_HIDE_FROM_ABI static __container_value_type* __get_ptr(__node_value_type& __n) {
553 return std::addressof(__n.__get_value());
554 }
555
556 _LIBCPP_HIDE_FROM_ABI static pair<key_type&&, mapped_type&&> __move(__node_value_type& __v) { return __v.__move(); }
513template <class _Key, class _ValueT>
514struct __get_tree_key_type<__value_type<_Key, _ValueT> > {
515 using type _LIBCPP_NODEBUG = _Key;
557516};
558517
559template <class _VoidPtr>
560struct __tree_node_base_types {
561 typedef _VoidPtr __void_pointer;
562
563 typedef __tree_node_base<__void_pointer> __node_base_type;
564 typedef __rebind_pointer_t<_VoidPtr, __node_base_type> __node_base_pointer;
565
566 typedef __tree_end_node<__node_base_pointer> __end_node_type;
567 typedef __rebind_pointer_t<_VoidPtr, __end_node_type> __end_node_pointer;
568 typedef __end_node_pointer __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.");
580#endif
518template <class _Tp>
519using __get_tree_key_type_t _LIBCPP_NODEBUG = typename __get_tree_key_type<_Tp>::type;
581520
582private:
583 static_assert(is_same<typename pointer_traits<_VoidPtr>::element_type, void>::value,
584 "_VoidPtr does not point to unqualified void type");
521template <class _Tp>
522struct __get_node_value_type {
523 using type _LIBCPP_NODEBUG = _Tp;
585524};
586525
587template <class _Tp, class _AllocPtr, class _KVTypes = __tree_key_value_types<_Tp>, bool = _KVTypes::__is_map>
588struct __tree_map_pointer_types {};
589
590template <class _Tp, class _AllocPtr, class _KVTypes>
591struct __tree_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> {
592 typedef typename _KVTypes::__map_value_type _Mv;
593 typedef __rebind_pointer_t<_AllocPtr, _Mv> __map_value_type_pointer;
594 typedef __rebind_pointer_t<_AllocPtr, const _Mv> __const_map_value_type_pointer;
526template <class _Key, class _ValueT>
527struct __get_node_value_type<__value_type<_Key, _ValueT> > {
528 using type _LIBCPP_NODEBUG = pair<const _Key, _ValueT>;
595529};
596530
531template <class _Tp>
532using __get_node_value_type_t _LIBCPP_NODEBUG = typename __get_node_value_type<_Tp>::type;
533
597534template <class _NodePtr, class _NodeT = typename pointer_traits<_NodePtr>::element_type>
598535struct __tree_node_types;
599536
600537template <class _NodePtr, class _Tp, class _VoidPtr>
601struct __tree_node_types<_NodePtr, __tree_node<_Tp, _VoidPtr> >
602 : public __tree_node_base_types<_VoidPtr>, __tree_key_value_types<_Tp>, __tree_map_pointer_types<_Tp, _VoidPtr> {
603 typedef __tree_node_base_types<_VoidPtr> __base;
604 typedef __tree_key_value_types<_Tp> __key_base;
605 typedef __tree_map_pointer_types<_Tp, _VoidPtr> __map_pointer_base;
606
607public:
608 typedef typename pointer_traits<_NodePtr>::element_type __node_type;
609 typedef _NodePtr __node_pointer;
610
611 typedef _Tp __node_value_type;
612 typedef __rebind_pointer_t<_VoidPtr, __node_value_type> __node_value_type_pointer;
613 typedef __rebind_pointer_t<_VoidPtr, const __node_value_type> __const_node_value_type_pointer;
614 typedef typename __base::__end_node_pointer __iter_pointer;
538struct __tree_node_types<_NodePtr, __tree_node<_Tp, _VoidPtr> > {
539 using __node_base_pointer _LIBCPP_NODEBUG = __rebind_pointer_t<_VoidPtr, __tree_node_base<_VoidPtr> >;
540 using __end_node_pointer _LIBCPP_NODEBUG = __rebind_pointer_t<_VoidPtr, __tree_end_node<__node_base_pointer> >;
615541
616542private:
617 static_assert(!is_const<__node_type>::value, "_NodePtr should never be a pointer to const");
618 static_assert(is_same<__rebind_pointer_t<_VoidPtr, __node_type>, _NodePtr>::value,
619 "_VoidPtr does not rebind to _NodePtr.");
620};
621
622template <class _ValueTp, class _VoidPtr>
623struct __make_tree_node_types {
624 typedef __rebind_pointer_t<_VoidPtr, __tree_node<_ValueTp, _VoidPtr> > _NodePtr;
625 typedef __tree_node_types<_NodePtr> type;
543 static_assert(is_same<typename pointer_traits<_VoidPtr>::element_type, void>::value,
544 "_VoidPtr does not point to unqualified void type");
626545};
627546
628547// node
......@@ -637,20 +556,19 @@ public:
637556};
638557
639558template <class _VoidPtr>
640class _LIBCPP_STANDALONE_DEBUG __tree_node_base : public __tree_node_base_types<_VoidPtr>::__end_node_type {
641 typedef __tree_node_base_types<_VoidPtr> _NodeBaseTypes;
642
559class _LIBCPP_STANDALONE_DEBUG
560__tree_node_base : public __tree_end_node<__rebind_pointer_t<_VoidPtr, __tree_node_base<_VoidPtr> > > {
643561public:
644 typedef typename _NodeBaseTypes::__node_base_pointer pointer;
645 typedef typename _NodeBaseTypes::__parent_pointer __parent_pointer;
562 using pointer = __rebind_pointer_t<_VoidPtr, __tree_node_base>;
563 using __end_node_pointer _LIBCPP_NODEBUG = __rebind_pointer_t<_VoidPtr, __tree_end_node<pointer> >;
646564
647565 pointer __right_;
648 __parent_pointer __parent_;
566 __end_node_pointer __parent_;
649567 bool __is_black_;
650568
651569 _LIBCPP_HIDE_FROM_ABI pointer __parent_unsafe() const { return static_cast<pointer>(__parent_); }
652570
653 _LIBCPP_HIDE_FROM_ABI void __set_parent(pointer __p) { __parent_ = static_cast<__parent_pointer>(__p); }
571 _LIBCPP_HIDE_FROM_ABI void __set_parent(pointer __p) { __parent_ = static_cast<__end_node_pointer>(__p); }
654572
655573 ~__tree_node_base() = delete;
656574 __tree_node_base(__tree_node_base const&) = delete;
......@@ -660,11 +578,11 @@ public:
660578template <class _Tp, class _VoidPtr>
661579class _LIBCPP_STANDALONE_DEBUG __tree_node : public __tree_node_base<_VoidPtr> {
662580public:
663 typedef _Tp __node_value_type;
581 using __node_value_type _LIBCPP_NODEBUG = __get_node_value_type_t<_Tp>;
664582
665583 __node_value_type __value_;
666584
667 _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return __value_; }
585 _LIBCPP_HIDE_FROM_ABI __node_value_type& __get_value() { return __value_; }
668586
669587 ~__tree_node() = delete;
670588 __tree_node(__tree_node const&) = delete;
......@@ -680,7 +598,6 @@ public:
680598 typedef typename __alloc_traits::pointer pointer;
681599
682600private:
683 typedef __tree_node_types<pointer> _NodeTypes;
684601 allocator_type& __na_;
685602
686603public:
......@@ -695,7 +612,7 @@ public:
695612
696613 _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT {
697614 if (__value_constructed)
698 __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_));
615 __alloc_traits::destroy(__na_, std::addressof(__p->__value_));
699616 if (__p)
700617 __alloc_traits::deallocate(__na_, __p, 1);
701618 }
......@@ -714,22 +631,20 @@ struct __generic_container_node_destructor<__tree_node<_Tp, _VoidPtr>, _Alloc> :
714631#endif
715632
716633template <class _Tp, class _NodePtr, class _DiffType>
717class _LIBCPP_TEMPLATE_VIS __tree_iterator {
634class __tree_iterator {
718635 typedef __tree_node_types<_NodePtr> _NodeTypes;
719636 typedef _NodePtr __node_pointer;
720637 typedef typename _NodeTypes::__node_base_pointer __node_base_pointer;
721638 typedef typename _NodeTypes::__end_node_pointer __end_node_pointer;
722 typedef typename _NodeTypes::__iter_pointer __iter_pointer;
723 typedef pointer_traits<__node_pointer> __pointer_traits;
724639
725 __iter_pointer __ptr_;
640 __end_node_pointer __ptr_;
726641
727642public:
728 typedef bidirectional_iterator_tag iterator_category;
729 typedef _Tp value_type;
730 typedef _DiffType difference_type;
731 typedef value_type& reference;
732 typedef typename _NodeTypes::__node_value_type_pointer pointer;
643 using iterator_category = bidirectional_iterator_tag;
644 using value_type = __get_node_value_type_t<_Tp>;
645 using difference_type = _DiffType;
646 using reference = value_type&;
647 using pointer = __rebind_pointer_t<_NodePtr, value_type>;
733648
734649 _LIBCPP_HIDE_FROM_ABI __tree_iterator() _NOEXCEPT
735650#if _LIBCPP_STD_VER >= 14
......@@ -742,8 +657,7 @@ public:
742657 _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__get_np()->__value_); }
743658
744659 _LIBCPP_HIDE_FROM_ABI __tree_iterator& operator++() {
745 __ptr_ = static_cast<__iter_pointer>(
746 std::__tree_next_iter<__end_node_pointer>(static_cast<__node_base_pointer>(__ptr_)));
660 __ptr_ = std::__tree_next_iter<__end_node_pointer>(static_cast<__node_base_pointer>(__ptr_));
747661 return *this;
748662 }
749663 _LIBCPP_HIDE_FROM_ABI __tree_iterator operator++(int) {
......@@ -753,8 +667,7 @@ public:
753667 }
754668
755669 _LIBCPP_HIDE_FROM_ABI __tree_iterator& operator--() {
756 __ptr_ = static_cast<__iter_pointer>(
757 std::__tree_prev_iter<__node_base_pointer>(static_cast<__end_node_pointer>(__ptr_)));
670 __ptr_ = static_cast<__end_node_pointer>(std::__tree_prev_iter<__node_base_pointer>(__ptr_));
758671 return *this;
759672 }
760673 _LIBCPP_HIDE_FROM_ABI __tree_iterator operator--(int) {
......@@ -777,36 +690,35 @@ private:
777690 template <class, class, class>
778691 friend class __tree;
779692 template <class, class, class>
780 friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
693 friend class __tree_const_iterator;
781694 template <class>
782 friend class _LIBCPP_TEMPLATE_VIS __map_iterator;
695 friend class __map_iterator;
783696 template <class, class, class, class>
784 friend class _LIBCPP_TEMPLATE_VIS map;
697 friend class map;
785698 template <class, class, class, class>
786 friend class _LIBCPP_TEMPLATE_VIS multimap;
699 friend class multimap;
787700 template <class, class, class>
788 friend class _LIBCPP_TEMPLATE_VIS set;
701 friend class set;
789702 template <class, class, class>
790 friend class _LIBCPP_TEMPLATE_VIS multiset;
703 friend class multiset;
791704};
792705
793706template <class _Tp, class _NodePtr, class _DiffType>
794class _LIBCPP_TEMPLATE_VIS __tree_const_iterator {
707class __tree_const_iterator {
795708 typedef __tree_node_types<_NodePtr> _NodeTypes;
796 typedef typename _NodeTypes::__node_pointer __node_pointer;
709 // NOLINTNEXTLINE(libcpp-nodebug-on-aliases) lldb relies on this alias for pretty printing
710 using __node_pointer = _NodePtr;
797711 typedef typename _NodeTypes::__node_base_pointer __node_base_pointer;
798712 typedef typename _NodeTypes::__end_node_pointer __end_node_pointer;
799 typedef typename _NodeTypes::__iter_pointer __iter_pointer;
800 typedef pointer_traits<__node_pointer> __pointer_traits;
801713
802 __iter_pointer __ptr_;
714 __end_node_pointer __ptr_;
803715
804716public:
805 typedef bidirectional_iterator_tag iterator_category;
806 typedef _Tp value_type;
807 typedef _DiffType difference_type;
808 typedef const value_type& reference;
809 typedef typename _NodeTypes::__const_node_value_type_pointer pointer;
717 using iterator_category = bidirectional_iterator_tag;
718 using value_type = __get_node_value_type_t<_Tp>;
719 using difference_type = _DiffType;
720 using reference = const value_type&;
721 using pointer = __rebind_pointer_t<_NodePtr, const value_type>;
810722
811723 _LIBCPP_HIDE_FROM_ABI __tree_const_iterator() _NOEXCEPT
812724#if _LIBCPP_STD_VER >= 14
......@@ -816,7 +728,7 @@ public:
816728 }
817729
818730private:
819 typedef __tree_iterator<value_type, __node_pointer, difference_type> __non_const_iterator;
731 typedef __tree_iterator<_Tp, __node_pointer, difference_type> __non_const_iterator;
820732
821733public:
822734 _LIBCPP_HIDE_FROM_ABI __tree_const_iterator(__non_const_iterator __p) _NOEXCEPT : __ptr_(__p.__ptr_) {}
......@@ -825,8 +737,7 @@ public:
825737 _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__get_np()->__value_); }
826738
827739 _LIBCPP_HIDE_FROM_ABI __tree_const_iterator& operator++() {
828 __ptr_ = static_cast<__iter_pointer>(
829 std::__tree_next_iter<__end_node_pointer>(static_cast<__node_base_pointer>(__ptr_)));
740 __ptr_ = std::__tree_next_iter<__end_node_pointer>(static_cast<__node_base_pointer>(__ptr_));
830741 return *this;
831742 }
832743
......@@ -837,8 +748,7 @@ public:
837748 }
838749
839750 _LIBCPP_HIDE_FROM_ABI __tree_const_iterator& operator--() {
840 __ptr_ = static_cast<__iter_pointer>(
841 std::__tree_prev_iter<__node_base_pointer>(static_cast<__end_node_pointer>(__ptr_)));
751 __ptr_ = static_cast<__end_node_pointer>(std::__tree_prev_iter<__node_base_pointer>(__ptr_));
842752 return *this;
843753 }
844754
......@@ -863,15 +773,15 @@ private:
863773 template <class, class, class>
864774 friend class __tree;
865775 template <class, class, class, class>
866 friend class _LIBCPP_TEMPLATE_VIS map;
776 friend class map;
867777 template <class, class, class, class>
868 friend class _LIBCPP_TEMPLATE_VIS multimap;
778 friend class multimap;
869779 template <class, class, class>
870 friend class _LIBCPP_TEMPLATE_VIS set;
780 friend class set;
871781 template <class, class, class>
872 friend class _LIBCPP_TEMPLATE_VIS multiset;
782 friend class multiset;
873783 template <class>
874 friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
784 friend class __map_const_iterator;
875785};
876786
877787template <class _Tp, class _Compare>
......@@ -884,42 +794,50 @@ int __diagnose_non_const_comparator();
884794template <class _Tp, class _Compare, class _Allocator>
885795class __tree {
886796public:
887 typedef _Tp value_type;
797 using value_type = __get_node_value_type_t<_Tp>;
888798 typedef _Compare value_compare;
889799 typedef _Allocator allocator_type;
890800
891801private:
892802 typedef allocator_traits<allocator_type> __alloc_traits;
893 typedef typename __make_tree_node_types<value_type, typename __alloc_traits::void_pointer>::type _NodeTypes;
894 typedef typename _NodeTypes::key_type key_type;
803 using key_type = __get_tree_key_type_t<_Tp>;
895804
896805public:
897 typedef typename _NodeTypes::__node_value_type __node_value_type;
898 typedef typename _NodeTypes::__container_value_type __container_value_type;
899
900806 typedef typename __alloc_traits::pointer pointer;
901807 typedef typename __alloc_traits::const_pointer const_pointer;
902808 typedef typename __alloc_traits::size_type size_type;
903809 typedef typename __alloc_traits::difference_type difference_type;
904810
905811public:
906 typedef typename _NodeTypes::__void_pointer __void_pointer;
812 using __void_pointer _LIBCPP_NODEBUG = typename __alloc_traits::void_pointer;
907813
908 typedef typename _NodeTypes::__node_type __node;
909 typedef typename _NodeTypes::__node_pointer __node_pointer;
814 using __node _LIBCPP_NODEBUG = __tree_node<_Tp, __void_pointer>;
815 // NOLINTNEXTLINE(libcpp-nodebug-on-aliases) lldb relies on this alias for pretty printing
816 using __node_pointer = __rebind_pointer_t<__void_pointer, __node>;
910817
911 typedef typename _NodeTypes::__node_base_type __node_base;
912 typedef typename _NodeTypes::__node_base_pointer __node_base_pointer;
818 using __node_base _LIBCPP_NODEBUG = __tree_node_base<__void_pointer>;
819 using __node_base_pointer _LIBCPP_NODEBUG = __rebind_pointer_t<__void_pointer, __node_base>;
913820
914 typedef typename _NodeTypes::__end_node_type __end_node_t;
915 typedef typename _NodeTypes::__end_node_pointer __end_node_ptr;
821 using __end_node_t _LIBCPP_NODEBUG = __tree_end_node<__node_base_pointer>;
822 using __end_node_pointer _LIBCPP_NODEBUG = __rebind_pointer_t<__void_pointer, __end_node_t>;
916823
917 typedef typename _NodeTypes::__parent_pointer __parent_pointer;
918 typedef typename _NodeTypes::__iter_pointer __iter_pointer;
824 using __parent_pointer _LIBCPP_NODEBUG = __end_node_pointer; // TODO: Remove this once the uses in <map> are removed
919825
920826 typedef __rebind_alloc<__alloc_traits, __node> __node_allocator;
921827 typedef allocator_traits<__node_allocator> __node_traits;
922828
829// TODO(LLVM 22): Remove this check
830#ifndef _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
831 static_assert(sizeof(__node_base_pointer) == sizeof(__end_node_pointer) && _LIBCPP_ALIGNOF(__node_base_pointer) ==
832 _LIBCPP_ALIGNOF(__end_node_pointer),
833 "It looks like you are using std::__tree (an implementation detail for (multi)map/set) with a fancy "
834 "pointer type that thas a different representation depending on whether it points to a __tree base "
835 "pointer or a __tree node pointer (both of which are implementation details of the standard library). "
836 "This means that your ABI is being broken between LLVM 19 and LLVM 20. If you don't care about your "
837 "ABI being broken, define the _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB macro to silence this "
838 "diagnostic.");
839#endif
840
923841private:
924842 // check for sane allocator pointer rebinding semantics. Rebinding the
925843 // allocator for a new pointer type should be exactly the same as rebinding
......@@ -932,24 +850,23 @@ private:
932850 "Allocator does not rebind pointers in a sane manner.");
933851
934852private:
935 __iter_pointer __begin_node_;
853 __end_node_pointer __begin_node_;
936854 _LIBCPP_COMPRESSED_PAIR(__end_node_t, __end_node_, __node_allocator, __node_alloc_);
937855 _LIBCPP_COMPRESSED_PAIR(size_type, __size_, value_compare, __value_comp_);
938856
939857public:
940 _LIBCPP_HIDE_FROM_ABI __iter_pointer __end_node() _NOEXCEPT {
941 return static_cast<__iter_pointer>(pointer_traits<__end_node_ptr>::pointer_to(__end_node_));
858 _LIBCPP_HIDE_FROM_ABI __end_node_pointer __end_node() _NOEXCEPT {
859 return pointer_traits<__end_node_pointer>::pointer_to(__end_node_);
942860 }
943 _LIBCPP_HIDE_FROM_ABI __iter_pointer __end_node() const _NOEXCEPT {
944 return static_cast<__iter_pointer>(
945 pointer_traits<__end_node_ptr>::pointer_to(const_cast<__end_node_t&>(__end_node_)));
861 _LIBCPP_HIDE_FROM_ABI __end_node_pointer __end_node() const _NOEXCEPT {
862 return pointer_traits<__end_node_pointer>::pointer_to(const_cast<__end_node_t&>(__end_node_));
946863 }
947864 _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __node_alloc_; }
948865
949866private:
950867 _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __node_alloc_; }
951 _LIBCPP_HIDE_FROM_ABI __iter_pointer& __begin_node() _NOEXCEPT { return __begin_node_; }
952 _LIBCPP_HIDE_FROM_ABI const __iter_pointer& __begin_node() const _NOEXCEPT { return __begin_node_; }
868 _LIBCPP_HIDE_FROM_ABI __end_node_pointer& __begin_node() _NOEXCEPT { return __begin_node_; }
869 _LIBCPP_HIDE_FROM_ABI const __end_node_pointer& __begin_node() const _NOEXCEPT { return __begin_node_; }
953870
954871public:
955872 _LIBCPP_HIDE_FROM_ABI allocator_type __alloc() const _NOEXCEPT { return allocator_type(__node_alloc()); }
......@@ -971,8 +888,8 @@ public:
971888 return std::addressof(__end_node()->__left_);
972889 }
973890
974 typedef __tree_iterator<value_type, __node_pointer, difference_type> iterator;
975 typedef __tree_const_iterator<value_type, __node_pointer, difference_type> const_iterator;
891 typedef __tree_iterator<_Tp, __node_pointer, difference_type> iterator;
892 typedef __tree_const_iterator<_Tp, __node_pointer, difference_type> const_iterator;
976893
977894 _LIBCPP_HIDE_FROM_ABI explicit __tree(const value_compare& __comp) _NOEXCEPT_(
978895 is_nothrow_default_constructible<__node_allocator>::value&& is_nothrow_copy_constructible<value_compare>::value);
......@@ -987,9 +904,12 @@ public:
987904 _LIBCPP_HIDE_FROM_ABI __tree(__tree&& __t) _NOEXCEPT_(
988905 is_nothrow_move_constructible<__node_allocator>::value&& is_nothrow_move_constructible<value_compare>::value);
989906 _LIBCPP_HIDE_FROM_ABI __tree(__tree&& __t, const allocator_type& __a);
990 _LIBCPP_HIDE_FROM_ABI __tree& operator=(__tree&& __t) _NOEXCEPT_(
991 __node_traits::propagate_on_container_move_assignment::value&& is_nothrow_move_assignable<value_compare>::value&&
992 is_nothrow_move_assignable<__node_allocator>::value);
907 _LIBCPP_HIDE_FROM_ABI __tree& operator=(__tree&& __t)
908 _NOEXCEPT_(is_nothrow_move_assignable<value_compare>::value &&
909 ((__node_traits::propagate_on_container_move_assignment::value &&
910 is_nothrow_move_assignable<__node_allocator>::value) ||
911 allocator_traits<__node_allocator>::is_always_equal::value));
912
993913 _LIBCPP_HIDE_FROM_ABI ~__tree();
994914
995915 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return iterator(__begin_node()); }
......@@ -1035,7 +955,7 @@ public:
1035955
1036956 template <class _First,
1037957 class _Second,
1038 __enable_if_t<__can_extract_map_key<_First, key_type, __container_value_type>::value, int> = 0>
958 __enable_if_t<__can_extract_map_key<_First, key_type, value_type>::value, int> = 0>
1039959 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __emplace_unique(_First&& __f, _Second&& __s) {
1040960 return __emplace_unique_key_args(__f, std::forward<_First>(__f), std::forward<_Second>(__s));
1041961 }
......@@ -1067,7 +987,7 @@ public:
1067987
1068988 template <class _First,
1069989 class _Second,
1070 __enable_if_t<__can_extract_map_key<_First, key_type, __container_value_type>::value, int> = 0>
990 __enable_if_t<__can_extract_map_key<_First, key_type, value_type>::value, int> = 0>
1071991 _LIBCPP_HIDE_FROM_ABI iterator __emplace_hint_unique(const_iterator __p, _First&& __f, _Second&& __s) {
1072992 return __emplace_hint_unique_key_args(__p, __f, std::forward<_First>(__f), std::forward<_Second>(__s)).first;
1073993 }
......@@ -1095,52 +1015,28 @@ public:
10951015 return __emplace_hint_unique_key_args(__p, __x.first, std::forward<_Pp>(__x)).first;
10961016 }
10971017
1098 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(const __container_value_type& __v) {
1099 return __emplace_unique_key_args(_NodeTypes::__get_key(__v), __v);
1100 }
1101
1102 _LIBCPP_HIDE_FROM_ABI iterator __insert_unique(const_iterator __p, const __container_value_type& __v) {
1103 return __emplace_hint_unique_key_args(__p, _NodeTypes::__get_key(__v), __v).first;
1104 }
1105
1106 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(__container_value_type&& __v) {
1107 return __emplace_unique_key_args(_NodeTypes::__get_key(__v), std::move(__v));
1108 }
1109
1110 _LIBCPP_HIDE_FROM_ABI iterator __insert_unique(const_iterator __p, __container_value_type&& __v) {
1111 return __emplace_hint_unique_key_args(__p, _NodeTypes::__get_key(__v), std::move(__v)).first;
1112 }
1113
1114 template <class _Vp, __enable_if_t<!is_same<__remove_const_ref_t<_Vp>, __container_value_type>::value, int> = 0>
1115 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(_Vp&& __v) {
1116 return __emplace_unique(std::forward<_Vp>(__v));
1117 }
1118
1119 template <class _Vp, __enable_if_t<!is_same<__remove_const_ref_t<_Vp>, __container_value_type>::value, int> = 0>
1120 _LIBCPP_HIDE_FROM_ABI iterator __insert_unique(const_iterator __p, _Vp&& __v) {
1121 return __emplace_hint_unique(__p, std::forward<_Vp>(__v));
1122 }
1123
1124 _LIBCPP_HIDE_FROM_ABI iterator __insert_multi(__container_value_type&& __v) {
1125 return __emplace_multi(std::move(__v));
1018 template <class _ValueT = _Tp, __enable_if_t<__is_tree_value_type<_ValueT>::value, int> = 0>
1019 _LIBCPP_HIDE_FROM_ABI void
1020 __insert_unique_from_orphaned_node(const_iterator __p, __get_node_value_type_t<_Tp>&& __value) {
1021 __emplace_hint_unique(__p, const_cast<key_type&&>(__value.first), std::move(__value.second));
11261022 }
11271023
1128 _LIBCPP_HIDE_FROM_ABI iterator __insert_multi(const_iterator __p, __container_value_type&& __v) {
1129 return __emplace_hint_multi(__p, std::move(__v));
1024 template <class _ValueT = _Tp, __enable_if_t<!__is_tree_value_type<_ValueT>::value, int> = 0>
1025 _LIBCPP_HIDE_FROM_ABI void __insert_unique_from_orphaned_node(const_iterator __p, _Tp&& __value) {
1026 __emplace_hint_unique(__p, std::move(__value));
11301027 }
11311028
1132 template <class _Vp>
1133 _LIBCPP_HIDE_FROM_ABI iterator __insert_multi(_Vp&& __v) {
1134 return __emplace_multi(std::forward<_Vp>(__v));
1029 template <class _ValueT = _Tp, __enable_if_t<__is_tree_value_type<_ValueT>::value, int> = 0>
1030 _LIBCPP_HIDE_FROM_ABI void __insert_multi_from_orphaned_node(const_iterator __p, value_type&& __value) {
1031 __emplace_hint_multi(__p, const_cast<key_type&&>(__value.first), std::move(__value.second));
11351032 }
11361033
1137 template <class _Vp>
1138 _LIBCPP_HIDE_FROM_ABI iterator __insert_multi(const_iterator __p, _Vp&& __v) {
1139 return __emplace_hint_multi(__p, std::forward<_Vp>(__v));
1034 template <class _ValueT = _Tp, __enable_if_t<!__is_tree_value_type<_ValueT>::value, int> = 0>
1035 _LIBCPP_HIDE_FROM_ABI void __insert_multi_from_orphaned_node(const_iterator __p, _Tp&& __value) {
1036 __emplace_hint_multi(__p, std::move(__value));
11401037 }
11411038
1142 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool>
1143 __node_assign_unique(const __container_value_type& __v, __node_pointer __dest);
1039 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __node_assign_unique(const value_type& __v, __node_pointer __dest);
11441040
11451041 _LIBCPP_HIDE_FROM_ABI iterator __node_insert_multi(__node_pointer __nd);
11461042 _LIBCPP_HIDE_FROM_ABI iterator __node_insert_multi(const_iterator __p, __node_pointer __nd);
......@@ -1176,7 +1072,7 @@ public:
11761072 _LIBCPP_HIDE_FROM_ABI size_type __erase_multi(const _Key& __k);
11771073
11781074 _LIBCPP_HIDE_FROM_ABI void
1179 __insert_node_at(__parent_pointer __parent, __node_base_pointer& __child, __node_base_pointer __new_node) _NOEXCEPT;
1075 __insert_node_at(__end_node_pointer __parent, __node_base_pointer& __child, __node_base_pointer __new_node) _NOEXCEPT;
11801076
11811077 template <class _Key>
11821078 _LIBCPP_HIDE_FROM_ABI iterator find(const _Key& __v);
......@@ -1193,27 +1089,27 @@ public:
11931089 return __lower_bound(__v, __root(), __end_node());
11941090 }
11951091 template <class _Key>
1196 _LIBCPP_HIDE_FROM_ABI iterator __lower_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result);
1092 _LIBCPP_HIDE_FROM_ABI iterator __lower_bound(const _Key& __v, __node_pointer __root, __end_node_pointer __result);
11971093 template <class _Key>
11981094 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _Key& __v) const {
11991095 return __lower_bound(__v, __root(), __end_node());
12001096 }
12011097 template <class _Key>
12021098 _LIBCPP_HIDE_FROM_ABI const_iterator
1203 __lower_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result) const;
1099 __lower_bound(const _Key& __v, __node_pointer __root, __end_node_pointer __result) const;
12041100 template <class _Key>
12051101 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _Key& __v) {
12061102 return __upper_bound(__v, __root(), __end_node());
12071103 }
12081104 template <class _Key>
1209 _LIBCPP_HIDE_FROM_ABI iterator __upper_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result);
1105 _LIBCPP_HIDE_FROM_ABI iterator __upper_bound(const _Key& __v, __node_pointer __root, __end_node_pointer __result);
12101106 template <class _Key>
12111107 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _Key& __v) const {
12121108 return __upper_bound(__v, __root(), __end_node());
12131109 }
12141110 template <class _Key>
12151111 _LIBCPP_HIDE_FROM_ABI const_iterator
1216 __upper_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result) const;
1112 __upper_bound(const _Key& __v, __node_pointer __root, __end_node_pointer __result) const;
12171113 template <class _Key>
12181114 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> __equal_range_unique(const _Key& __k);
12191115 template <class _Key>
......@@ -1229,28 +1125,17 @@ public:
12291125
12301126 _LIBCPP_HIDE_FROM_ABI __node_holder remove(const_iterator __p) _NOEXCEPT;
12311127
1232private:
1233 _LIBCPP_HIDE_FROM_ABI __node_base_pointer& __find_leaf_low(__parent_pointer& __parent, const key_type& __v);
1234 _LIBCPP_HIDE_FROM_ABI __node_base_pointer& __find_leaf_high(__parent_pointer& __parent, const key_type& __v);
1235 _LIBCPP_HIDE_FROM_ABI __node_base_pointer&
1236 __find_leaf(const_iterator __hint, __parent_pointer& __parent, const key_type& __v);
12371128 // FIXME: Make this function const qualified. Unfortunately doing so
12381129 // breaks existing code which uses non-const callable comparators.
12391130 template <class _Key>
1240 _LIBCPP_HIDE_FROM_ABI __node_base_pointer& __find_equal(__parent_pointer& __parent, const _Key& __v);
1131 _LIBCPP_HIDE_FROM_ABI __node_base_pointer& __find_equal(__end_node_pointer& __parent, const _Key& __v);
12411132 template <class _Key>
1242 _LIBCPP_HIDE_FROM_ABI __node_base_pointer& __find_equal(__parent_pointer& __parent, const _Key& __v) const {
1133 _LIBCPP_HIDE_FROM_ABI __node_base_pointer& __find_equal(__end_node_pointer& __parent, const _Key& __v) const {
12431134 return const_cast<__tree*>(this)->__find_equal(__parent, __v);
12441135 }
12451136 template <class _Key>
12461137 _LIBCPP_HIDE_FROM_ABI __node_base_pointer&
1247 __find_equal(const_iterator __hint, __parent_pointer& __parent, __node_base_pointer& __dummy, const _Key& __v);
1248
1249 template <class... _Args>
1250 _LIBCPP_HIDE_FROM_ABI __node_holder __construct_node(_Args&&... __args);
1251
1252 // TODO: Make this _LIBCPP_HIDE_FROM_ABI
1253 _LIBCPP_HIDDEN void destroy(__node_pointer __nd) _NOEXCEPT;
1138 __find_equal(const_iterator __hint, __end_node_pointer& __parent, __node_base_pointer& __dummy, const _Key& __v);
12541139
12551140 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __tree& __t) {
12561141 __copy_assign_alloc(__t, integral_constant<bool, __node_traits::propagate_on_container_copy_assignment::value>());
......@@ -1263,6 +1148,20 @@ private:
12631148 }
12641149 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __tree&, false_type) {}
12651150
1151private:
1152 _LIBCPP_HIDE_FROM_ABI __node_base_pointer& __find_leaf_low(__end_node_pointer& __parent, const value_type& __v);
1153
1154 _LIBCPP_HIDE_FROM_ABI __node_base_pointer& __find_leaf_high(__end_node_pointer& __parent, const value_type& __v);
1155
1156 _LIBCPP_HIDE_FROM_ABI __node_base_pointer&
1157 __find_leaf(const_iterator __hint, __end_node_pointer& __parent, const value_type& __v);
1158
1159 template <class... _Args>
1160 _LIBCPP_HIDE_FROM_ABI __node_holder __construct_node(_Args&&... __args);
1161
1162 // TODO: Make this _LIBCPP_HIDE_FROM_ABI
1163 _LIBCPP_HIDDEN void destroy(__node_pointer __nd) _NOEXCEPT;
1164
12661165 _LIBCPP_HIDE_FROM_ABI void __move_assign(__tree& __t, false_type);
12671166 _LIBCPP_HIDE_FROM_ABI void __move_assign(__tree& __t, true_type) _NOEXCEPT_(
12681167 is_nothrow_move_assignable<value_compare>::value&& is_nothrow_move_assignable<__node_allocator>::value);
......@@ -1279,6 +1178,21 @@ private:
12791178 }
12801179 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__tree&, false_type) _NOEXCEPT {}
12811180
1181 template <class _From, class _ValueT = _Tp, __enable_if_t<__is_tree_value_type<_ValueT>::value, int> = 0>
1182 _LIBCPP_HIDE_FROM_ABI static void __assign_value(__get_node_value_type_t<value_type>& __lhs, _From&& __rhs) {
1183 using __key_type = __remove_const_t<typename value_type::first_type>;
1184
1185 // This is technically UB, since the object was constructed as `const`.
1186 // Clang doesn't optimize on this currently though.
1187 const_cast<__key_type&>(__lhs.first) = const_cast<__copy_cvref_t<_From, __key_type>&&>(__rhs.first);
1188 __lhs.second = std::forward<_From>(__rhs).second;
1189 }
1190
1191 template <class _To, class _From, class _ValueT = _Tp, __enable_if_t<!__is_tree_value_type<_ValueT>::value, int> = 0>
1192 _LIBCPP_HIDE_FROM_ABI static void __assign_value(_To& __lhs, _From&& __rhs) {
1193 __lhs = std::forward<_From>(__rhs);
1194 }
1195
12821196 struct _DetachedTreeCache {
12831197 _LIBCPP_HIDE_FROM_ABI explicit _DetachedTreeCache(__tree* __t) _NOEXCEPT
12841198 : __t_(__t),
......@@ -1315,11 +1229,6 @@ private:
13151229 __node_pointer __cache_root_;
13161230 __node_pointer __cache_elem_;
13171231 };
1318
1319 template <class, class, class, class>
1320 friend class _LIBCPP_TEMPLATE_VIS map;
1321 template <class, class, class, class>
1322 friend class _LIBCPP_TEMPLATE_VIS multimap;
13231232};
13241233
13251234template <class _Tp, class _Compare, class _Allocator>
......@@ -1331,13 +1240,13 @@ __tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp) _NOEXCEPT
13311240
13321241template <class _Tp, class _Compare, class _Allocator>
13331242__tree<_Tp, _Compare, _Allocator>::__tree(const allocator_type& __a)
1334 : __begin_node_(__iter_pointer()), __node_alloc_(__node_allocator(__a)), __size_(0) {
1243 : __begin_node_(), __node_alloc_(__node_allocator(__a)), __size_(0) {
13351244 __begin_node() = __end_node();
13361245}
13371246
13381247template <class _Tp, class _Compare, class _Allocator>
13391248__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp, const allocator_type& __a)
1340 : __begin_node_(__iter_pointer()), __node_alloc_(__node_allocator(__a)), __size_(0), __value_comp_(__comp) {
1249 : __begin_node_(), __node_alloc_(__node_allocator(__a)), __size_(0), __value_comp_(__comp) {
13411250 __begin_node() = __end_node();
13421251}
13431252
......@@ -1397,8 +1306,8 @@ template <class _ForwardIterator>
13971306void __tree<_Tp, _Compare, _Allocator>::__assign_unique(_ForwardIterator __first, _ForwardIterator __last) {
13981307 typedef iterator_traits<_ForwardIterator> _ITraits;
13991308 typedef typename _ITraits::value_type _ItValueType;
1400 static_assert(is_same<_ItValueType, __container_value_type>::value,
1401 "__assign_unique may only be called with the containers value type");
1309 static_assert(
1310 is_same<_ItValueType, value_type>::value, "__assign_unique may only be called with the containers value type");
14021311 static_assert(
14031312 __has_forward_iterator_category<_ForwardIterator>::value, "__assign_unique requires a forward iterator");
14041313 if (size() != 0) {
......@@ -1409,7 +1318,7 @@ void __tree<_Tp, _Compare, _Allocator>::__assign_unique(_ForwardIterator __first
14091318 }
14101319 }
14111320 for (; __first != __last; ++__first)
1412 __insert_unique(*__first);
1321 __emplace_unique(*__first);
14131322}
14141323
14151324template <class _Tp, class _Compare, class _Allocator>
......@@ -1418,24 +1327,23 @@ void __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _
14181327 typedef iterator_traits<_InputIterator> _ITraits;
14191328 typedef typename _ITraits::value_type _ItValueType;
14201329 static_assert(
1421 (is_same<_ItValueType, __container_value_type>::value || is_same<_ItValueType, __node_value_type>::value),
1422 "__assign_multi may only be called with the containers value type"
1423 " or the nodes value type");
1330 is_same<_ItValueType, value_type>::value, "__assign_multi may only be called with the containers value_type");
14241331 if (size() != 0) {
14251332 _DetachedTreeCache __cache(this);
14261333 for (; __cache.__get() && __first != __last; ++__first) {
1427 __cache.__get()->__value_ = *__first;
1334 __assign_value(__cache.__get()->__value_, *__first);
14281335 __node_insert_multi(__cache.__get());
14291336 __cache.__advance();
14301337 }
14311338 }
1339 const_iterator __e = end();
14321340 for (; __first != __last; ++__first)
1433 __insert_multi(_NodeTypes::__get_value(*__first));
1341 __emplace_hint_multi(__e, *__first);
14341342}
14351343
14361344template <class _Tp, class _Compare, class _Allocator>
14371345__tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t)
1438 : __begin_node_(__iter_pointer()),
1346 : __begin_node_(),
14391347 __node_alloc_(__node_traits::select_on_container_copy_construction(__t.__node_alloc())),
14401348 __size_(0),
14411349 __value_comp_(__t.value_comp()) {
......@@ -1453,7 +1361,7 @@ __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) _NOEXCEPT_(
14531361 if (size() == 0)
14541362 __begin_node() = __end_node();
14551363 else {
1456 __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node());
1364 __end_node()->__left_->__parent_ = static_cast<__end_node_pointer>(__end_node());
14571365 __t.__begin_node() = __t.__end_node();
14581366 __t.__end_node()->__left_ = nullptr;
14591367 __t.size() = 0;
......@@ -1469,7 +1377,7 @@ __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __
14691377 else {
14701378 __begin_node() = __t.__begin_node();
14711379 __end_node()->__left_ = __t.__end_node()->__left_;
1472 __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node());
1380 __end_node()->__left_->__parent_ = static_cast<__end_node_pointer>(__end_node());
14731381 size() = __t.size();
14741382 __t.__begin_node() = __t.__end_node();
14751383 __t.__end_node()->__left_ = nullptr;
......@@ -1492,7 +1400,7 @@ void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, true_type)
14921400 if (size() == 0)
14931401 __begin_node() = __end_node();
14941402 else {
1495 __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node());
1403 __end_node()->__left_->__parent_ = static_cast<__end_node_pointer>(__end_node());
14961404 __t.__begin_node() = __t.__end_node();
14971405 __t.__end_node()->__left_ = nullptr;
14981406 __t.size() = 0;
......@@ -1509,22 +1417,23 @@ void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, false_type) {
15091417 if (size() != 0) {
15101418 _DetachedTreeCache __cache(this);
15111419 while (__cache.__get() != nullptr && __t.size() != 0) {
1512 __cache.__get()->__value_ = std::move(__t.remove(__t.begin())->__value_);
1420 __assign_value(__cache.__get()->__value_, std::move(__t.remove(__t.begin())->__value_));
15131421 __node_insert_multi(__cache.__get());
15141422 __cache.__advance();
15151423 }
15161424 }
1517 while (__t.size() != 0)
1518 __insert_multi(__e, _NodeTypes::__move(__t.remove(__t.begin())->__value_));
1425 while (__t.size() != 0) {
1426 __insert_multi_from_orphaned_node(__e, std::move(__t.remove(__t.begin())->__value_));
1427 }
15191428 }
15201429}
15211430
15221431template <class _Tp, class _Compare, class _Allocator>
1523__tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(__tree&& __t) _NOEXCEPT_(
1524 __node_traits::propagate_on_container_move_assignment::value&& is_nothrow_move_assignable<value_compare>::value&&
1525 is_nothrow_move_assignable<__node_allocator>::value)
1526
1527{
1432__tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(__tree&& __t)
1433 _NOEXCEPT_(is_nothrow_move_assignable<value_compare>::value &&
1434 ((__node_traits::propagate_on_container_move_assignment::value &&
1435 is_nothrow_move_assignable<__node_allocator>::value) ||
1436 allocator_traits<__node_allocator>::is_always_equal::value)) {
15281437 __move_assign(__t, integral_constant<bool, __node_traits::propagate_on_container_move_assignment::value>());
15291438 return *this;
15301439}
......@@ -1541,7 +1450,7 @@ void __tree<_Tp, _Compare, _Allocator>::destroy(__node_pointer __nd) _NOEXCEPT {
15411450 destroy(static_cast<__node_pointer>(__nd->__left_));
15421451 destroy(static_cast<__node_pointer>(__nd->__right_));
15431452 __node_allocator& __na = __node_alloc();
1544 __node_traits::destroy(__na, _NodeTypes::__get_ptr(__nd->__value_));
1453 __node_traits::destroy(__na, std::addressof(__nd->__value_));
15451454 __node_traits::deallocate(__na, __nd, 1);
15461455 }
15471456}
......@@ -1564,11 +1473,11 @@ void __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t)
15641473 if (size() == 0)
15651474 __begin_node() = __end_node();
15661475 else
1567 __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node());
1476 __end_node()->__left_->__parent_ = __end_node();
15681477 if (__t.size() == 0)
15691478 __t.__begin_node() = __t.__end_node();
15701479 else
1571 __t.__end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__t.__end_node());
1480 __t.__end_node()->__left_->__parent_ = __t.__end_node();
15721481}
15731482
15741483template <class _Tp, class _Compare, class _Allocator>
......@@ -1584,7 +1493,7 @@ void __tree<_Tp, _Compare, _Allocator>::clear() _NOEXCEPT {
15841493// Return reference to null leaf
15851494template <class _Tp, class _Compare, class _Allocator>
15861495typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer&
1587__tree<_Tp, _Compare, _Allocator>::__find_leaf_low(__parent_pointer& __parent, const key_type& __v) {
1496__tree<_Tp, _Compare, _Allocator>::__find_leaf_low(__end_node_pointer& __parent, const value_type& __v) {
15881497 __node_pointer __nd = __root();
15891498 if (__nd != nullptr) {
15901499 while (true) {
......@@ -1592,20 +1501,20 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf_low(__parent_pointer& __parent, c
15921501 if (__nd->__right_ != nullptr)
15931502 __nd = static_cast<__node_pointer>(__nd->__right_);
15941503 else {
1595 __parent = static_cast<__parent_pointer>(__nd);
1504 __parent = static_cast<__end_node_pointer>(__nd);
15961505 return __nd->__right_;
15971506 }
15981507 } else {
15991508 if (__nd->__left_ != nullptr)
16001509 __nd = static_cast<__node_pointer>(__nd->__left_);
16011510 else {
1602 __parent = static_cast<__parent_pointer>(__nd);
1511 __parent = static_cast<__end_node_pointer>(__nd);
16031512 return __parent->__left_;
16041513 }
16051514 }
16061515 }
16071516 }
1608 __parent = static_cast<__parent_pointer>(__end_node());
1517 __parent = __end_node();
16091518 return __parent->__left_;
16101519}
16111520
......@@ -1614,7 +1523,7 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf_low(__parent_pointer& __parent, c
16141523// Return reference to null leaf
16151524template <class _Tp, class _Compare, class _Allocator>
16161525typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer&
1617__tree<_Tp, _Compare, _Allocator>::__find_leaf_high(__parent_pointer& __parent, const key_type& __v) {
1526__tree<_Tp, _Compare, _Allocator>::__find_leaf_high(__end_node_pointer& __parent, const value_type& __v) {
16181527 __node_pointer __nd = __root();
16191528 if (__nd != nullptr) {
16201529 while (true) {
......@@ -1622,20 +1531,20 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf_high(__parent_pointer& __parent,
16221531 if (__nd->__left_ != nullptr)
16231532 __nd = static_cast<__node_pointer>(__nd->__left_);
16241533 else {
1625 __parent = static_cast<__parent_pointer>(__nd);
1534 __parent = static_cast<__end_node_pointer>(__nd);
16261535 return __parent->__left_;
16271536 }
16281537 } else {
16291538 if (__nd->__right_ != nullptr)
16301539 __nd = static_cast<__node_pointer>(__nd->__right_);
16311540 else {
1632 __parent = static_cast<__parent_pointer>(__nd);
1541 __parent = static_cast<__end_node_pointer>(__nd);
16331542 return __nd->__right_;
16341543 }
16351544 }
16361545 }
16371546 }
1638 __parent = static_cast<__parent_pointer>(__end_node());
1547 __parent = __end_node();
16391548 return __parent->__left_;
16401549}
16411550
......@@ -1646,8 +1555,8 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf_high(__parent_pointer& __parent,
16461555// Set __parent to parent of null leaf
16471556// Return reference to null leaf
16481557template <class _Tp, class _Compare, class _Allocator>
1649typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer&
1650__tree<_Tp, _Compare, _Allocator>::__find_leaf(const_iterator __hint, __parent_pointer& __parent, const key_type& __v) {
1558typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Compare, _Allocator>::__find_leaf(
1559 const_iterator __hint, __end_node_pointer& __parent, const value_type& __v) {
16511560 if (__hint == end() || !value_comp()(*__hint, __v)) // check before
16521561 {
16531562 // __v <= *__hint
......@@ -1655,10 +1564,10 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf(const_iterator __hint, __parent_p
16551564 if (__prior == begin() || !value_comp()(__v, *--__prior)) {
16561565 // *prev(__hint) <= __v <= *__hint
16571566 if (__hint.__ptr_->__left_ == nullptr) {
1658 __parent = static_cast<__parent_pointer>(__hint.__ptr_);
1567 __parent = static_cast<__end_node_pointer>(__hint.__ptr_);
16591568 return __parent->__left_;
16601569 } else {
1661 __parent = static_cast<__parent_pointer>(__prior.__ptr_);
1570 __parent = static_cast<__end_node_pointer>(__prior.__ptr_);
16621571 return static_cast<__node_base_pointer>(__prior.__ptr_)->__right_;
16631572 }
16641573 }
......@@ -1676,7 +1585,7 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf(const_iterator __hint, __parent_p
16761585template <class _Tp, class _Compare, class _Allocator>
16771586template <class _Key>
16781587typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer&
1679__tree<_Tp, _Compare, _Allocator>::__find_equal(__parent_pointer& __parent, const _Key& __v) {
1588__tree<_Tp, _Compare, _Allocator>::__find_equal(__end_node_pointer& __parent, const _Key& __v) {
16801589 __node_pointer __nd = __root();
16811590 __node_base_pointer* __nd_ptr = __root_ptr();
16821591 if (__nd != nullptr) {
......@@ -1686,7 +1595,7 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(__parent_pointer& __parent, cons
16861595 __nd_ptr = std::addressof(__nd->__left_);
16871596 __nd = static_cast<__node_pointer>(__nd->__left_);
16881597 } else {
1689 __parent = static_cast<__parent_pointer>(__nd);
1598 __parent = static_cast<__end_node_pointer>(__nd);
16901599 return __parent->__left_;
16911600 }
16921601 } else if (value_comp()(__nd->__value_, __v)) {
......@@ -1694,16 +1603,16 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(__parent_pointer& __parent, cons
16941603 __nd_ptr = std::addressof(__nd->__right_);
16951604 __nd = static_cast<__node_pointer>(__nd->__right_);
16961605 } else {
1697 __parent = static_cast<__parent_pointer>(__nd);
1606 __parent = static_cast<__end_node_pointer>(__nd);
16981607 return __nd->__right_;
16991608 }
17001609 } else {
1701 __parent = static_cast<__parent_pointer>(__nd);
1610 __parent = static_cast<__end_node_pointer>(__nd);
17021611 return *__nd_ptr;
17031612 }
17041613 }
17051614 }
1706 __parent = static_cast<__parent_pointer>(__end_node());
1615 __parent = __end_node();
17071616 return __parent->__left_;
17081617}
17091618
......@@ -1717,7 +1626,7 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(__parent_pointer& __parent, cons
17171626template <class _Tp, class _Compare, class _Allocator>
17181627template <class _Key>
17191628typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Compare, _Allocator>::__find_equal(
1720 const_iterator __hint, __parent_pointer& __parent, __node_base_pointer& __dummy, const _Key& __v) {
1629 const_iterator __hint, __end_node_pointer& __parent, __node_base_pointer& __dummy, const _Key& __v) {
17211630 if (__hint == end() || value_comp()(__v, *__hint)) // check before
17221631 {
17231632 // __v < *__hint
......@@ -1725,10 +1634,10 @@ typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Co
17251634 if (__prior == begin() || value_comp()(*--__prior, __v)) {
17261635 // *prev(__hint) < __v < *__hint
17271636 if (__hint.__ptr_->__left_ == nullptr) {
1728 __parent = static_cast<__parent_pointer>(__hint.__ptr_);
1637 __parent = __hint.__ptr_;
17291638 return __parent->__left_;
17301639 } else {
1731 __parent = static_cast<__parent_pointer>(__prior.__ptr_);
1640 __parent = __prior.__ptr_;
17321641 return static_cast<__node_base_pointer>(__prior.__ptr_)->__right_;
17331642 }
17341643 }
......@@ -1741,10 +1650,10 @@ typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Co
17411650 if (__next == end() || value_comp()(__v, *__next)) {
17421651 // *__hint < __v < *std::next(__hint)
17431652 if (__hint.__get_np()->__right_ == nullptr) {
1744 __parent = static_cast<__parent_pointer>(__hint.__ptr_);
1653 __parent = __hint.__ptr_;
17451654 return static_cast<__node_base_pointer>(__hint.__ptr_)->__right_;
17461655 } else {
1747 __parent = static_cast<__parent_pointer>(__next.__ptr_);
1656 __parent = __next.__ptr_;
17481657 return __parent->__left_;
17491658 }
17501659 }
......@@ -1752,21 +1661,21 @@ typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& __tree<_Tp, _Co
17521661 return __find_equal(__parent, __v);
17531662 }
17541663 // else __v == *__hint
1755 __parent = static_cast<__parent_pointer>(__hint.__ptr_);
1664 __parent = __hint.__ptr_;
17561665 __dummy = static_cast<__node_base_pointer>(__hint.__ptr_);
17571666 return __dummy;
17581667}
17591668
17601669template <class _Tp, class _Compare, class _Allocator>
17611670void __tree<_Tp, _Compare, _Allocator>::__insert_node_at(
1762 __parent_pointer __parent, __node_base_pointer& __child, __node_base_pointer __new_node) _NOEXCEPT {
1671 __end_node_pointer __parent, __node_base_pointer& __child, __node_base_pointer __new_node) _NOEXCEPT {
17631672 __new_node->__left_ = nullptr;
17641673 __new_node->__right_ = nullptr;
17651674 __new_node->__parent_ = __parent;
17661675 // __new_node->__is_black_ is initialized in __tree_balance_after_insert
17671676 __child = __new_node;
17681677 if (__begin_node()->__left_ != nullptr)
1769 __begin_node() = static_cast<__iter_pointer>(__begin_node()->__left_);
1678 __begin_node() = static_cast<__end_node_pointer>(__begin_node()->__left_);
17701679 std::__tree_balance_after_insert(__end_node()->__left_, __child);
17711680 ++size();
17721681}
......@@ -1775,7 +1684,7 @@ template <class _Tp, class _Compare, class _Allocator>
17751684template <class _Key, class... _Args>
17761685pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
17771686__tree<_Tp, _Compare, _Allocator>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args) {
1778 __parent_pointer __parent;
1687 __end_node_pointer __parent;
17791688 __node_base_pointer& __child = __find_equal(__parent, __k);
17801689 __node_pointer __r = static_cast<__node_pointer>(__child);
17811690 bool __inserted = false;
......@@ -1793,7 +1702,7 @@ template <class _Key, class... _Args>
17931702pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
17941703__tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_key_args(
17951704 const_iterator __p, _Key const& __k, _Args&&... __args) {
1796 __parent_pointer __parent;
1705 __end_node_pointer __parent;
17971706 __node_base_pointer __dummy;
17981707 __node_base_pointer& __child = __find_equal(__p, __parent, __dummy, __k);
17991708 __node_pointer __r = static_cast<__node_pointer>(__child);
......@@ -1811,10 +1720,9 @@ template <class _Tp, class _Compare, class _Allocator>
18111720template <class... _Args>
18121721typename __tree<_Tp, _Compare, _Allocator>::__node_holder
18131722__tree<_Tp, _Compare, _Allocator>::__construct_node(_Args&&... __args) {
1814 static_assert(!__is_tree_value_type<_Args...>::value, "Cannot construct from __value_type");
18151723 __node_allocator& __na = __node_alloc();
18161724 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1817 __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), std::forward<_Args>(__args)...);
1725 __node_traits::construct(__na, std::addressof(__h->__value_), std::forward<_Args>(__args)...);
18181726 __h.get_deleter().__value_constructed = true;
18191727 return __h;
18201728}
......@@ -1824,7 +1732,7 @@ template <class... _Args>
18241732pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
18251733__tree<_Tp, _Compare, _Allocator>::__emplace_unique_impl(_Args&&... __args) {
18261734 __node_holder __h = __construct_node(std::forward<_Args>(__args)...);
1827 __parent_pointer __parent;
1735 __end_node_pointer __parent;
18281736 __node_base_pointer& __child = __find_equal(__parent, __h->__value_);
18291737 __node_pointer __r = static_cast<__node_pointer>(__child);
18301738 bool __inserted = false;
......@@ -1841,7 +1749,7 @@ template <class... _Args>
18411749typename __tree<_Tp, _Compare, _Allocator>::iterator
18421750__tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_impl(const_iterator __p, _Args&&... __args) {
18431751 __node_holder __h = __construct_node(std::forward<_Args>(__args)...);
1844 __parent_pointer __parent;
1752 __end_node_pointer __parent;
18451753 __node_base_pointer __dummy;
18461754 __node_base_pointer& __child = __find_equal(__p, __parent, __dummy, __h->__value_);
18471755 __node_pointer __r = static_cast<__node_pointer>(__child);
......@@ -1857,8 +1765,8 @@ template <class... _Args>
18571765typename __tree<_Tp, _Compare, _Allocator>::iterator
18581766__tree<_Tp, _Compare, _Allocator>::__emplace_multi(_Args&&... __args) {
18591767 __node_holder __h = __construct_node(std::forward<_Args>(__args)...);
1860 __parent_pointer __parent;
1861 __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__h->__value_));
1768 __end_node_pointer __parent;
1769 __node_base_pointer& __child = __find_leaf_high(__parent, __h->__value_);
18621770 __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
18631771 return iterator(static_cast<__node_pointer>(__h.release()));
18641772}
......@@ -1868,21 +1776,21 @@ template <class... _Args>
18681776typename __tree<_Tp, _Compare, _Allocator>::iterator
18691777__tree<_Tp, _Compare, _Allocator>::__emplace_hint_multi(const_iterator __p, _Args&&... __args) {
18701778 __node_holder __h = __construct_node(std::forward<_Args>(__args)...);
1871 __parent_pointer __parent;
1872 __node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__h->__value_));
1779 __end_node_pointer __parent;
1780 __node_base_pointer& __child = __find_leaf(__p, __parent, __h->__value_);
18731781 __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
18741782 return iterator(static_cast<__node_pointer>(__h.release()));
18751783}
18761784
18771785template <class _Tp, class _Compare, class _Allocator>
18781786pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool>
1879__tree<_Tp, _Compare, _Allocator>::__node_assign_unique(const __container_value_type& __v, __node_pointer __nd) {
1880 __parent_pointer __parent;
1881 __node_base_pointer& __child = __find_equal(__parent, _NodeTypes::__get_key(__v));
1787__tree<_Tp, _Compare, _Allocator>::__node_assign_unique(const value_type& __v, __node_pointer __nd) {
1788 __end_node_pointer __parent;
1789 __node_base_pointer& __child = __find_equal(__parent, __v);
18821790 __node_pointer __r = static_cast<__node_pointer>(__child);
18831791 bool __inserted = false;
18841792 if (__child == nullptr) {
1885 __nd->__value_ = __v;
1793 __assign_value(__nd->__value_, __v);
18861794 __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd));
18871795 __r = __nd;
18881796 __inserted = true;
......@@ -1893,8 +1801,8 @@ __tree<_Tp, _Compare, _Allocator>::__node_assign_unique(const __container_value_
18931801template <class _Tp, class _Compare, class _Allocator>
18941802typename __tree<_Tp, _Compare, _Allocator>::iterator
18951803__tree<_Tp, _Compare, _Allocator>::__node_insert_multi(__node_pointer __nd) {
1896 __parent_pointer __parent;
1897 __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__nd->__value_));
1804 __end_node_pointer __parent;
1805 __node_base_pointer& __child = __find_leaf_high(__parent, __nd->__value_);
18981806 __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd));
18991807 return iterator(__nd);
19001808}
......@@ -1902,8 +1810,8 @@ __tree<_Tp, _Compare, _Allocator>::__node_insert_multi(__node_pointer __nd) {
19021810template <class _Tp, class _Compare, class _Allocator>
19031811typename __tree<_Tp, _Compare, _Allocator>::iterator
19041812__tree<_Tp, _Compare, _Allocator>::__node_insert_multi(const_iterator __p, __node_pointer __nd) {
1905 __parent_pointer __parent;
1906 __node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__nd->__value_));
1813 __end_node_pointer __parent;
1814 __node_base_pointer& __child = __find_leaf(__p, __parent, __nd->__value_);
19071815 __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd));
19081816 return iterator(__nd);
19091817}
......@@ -1929,7 +1837,7 @@ __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_unique(_NodeHandle&& __n
19291837 return _InsertReturnType{end(), false, _NodeHandle()};
19301838
19311839 __node_pointer __ptr = __nh.__ptr_;
1932 __parent_pointer __parent;
1840 __end_node_pointer __parent;
19331841 __node_base_pointer& __child = __find_equal(__parent, __ptr->__value_);
19341842 if (__child != nullptr)
19351843 return _InsertReturnType{iterator(static_cast<__node_pointer>(__child)), false, std::move(__nh)};
......@@ -1947,7 +1855,7 @@ __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_unique(const_iterator __
19471855 return end();
19481856
19491857 __node_pointer __ptr = __nh.__ptr_;
1950 __parent_pointer __parent;
1858 __end_node_pointer __parent;
19511859 __node_base_pointer __dummy;
19521860 __node_base_pointer& __child = __find_equal(__hint, __parent, __dummy, __ptr->__value_);
19531861 __node_pointer __r = static_cast<__node_pointer>(__child);
......@@ -1983,8 +1891,8 @@ _LIBCPP_HIDE_FROM_ABI void __tree<_Tp, _Compare, _Allocator>::__node_handle_merg
19831891
19841892 for (typename _Tree::iterator __i = __source.begin(); __i != __source.end();) {
19851893 __node_pointer __src_ptr = __i.__get_np();
1986 __parent_pointer __parent;
1987 __node_base_pointer& __child = __find_equal(__parent, _NodeTypes::__get_key(__src_ptr->__value_));
1894 __end_node_pointer __parent;
1895 __node_base_pointer& __child = __find_equal(__parent, __src_ptr->__value_);
19881896 ++__i;
19891897 if (__child != nullptr)
19901898 continue;
......@@ -2000,8 +1908,8 @@ __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_multi(_NodeHandle&& __nh
20001908 if (__nh.empty())
20011909 return end();
20021910 __node_pointer __ptr = __nh.__ptr_;
2003 __parent_pointer __parent;
2004 __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__ptr->__value_));
1911 __end_node_pointer __parent;
1912 __node_base_pointer& __child = __find_leaf_high(__parent, __ptr->__value_);
20051913 __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr));
20061914 __nh.__release_ptr();
20071915 return iterator(__ptr);
......@@ -2015,8 +1923,8 @@ __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_multi(const_iterator __h
20151923 return end();
20161924
20171925 __node_pointer __ptr = __nh.__ptr_;
2018 __parent_pointer __parent;
2019 __node_base_pointer& __child = __find_leaf(__hint, __parent, _NodeTypes::__get_key(__ptr->__value_));
1926 __end_node_pointer __parent;
1927 __node_base_pointer& __child = __find_leaf(__hint, __parent, __ptr->__value_);
20201928 __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr));
20211929 __nh.__release_ptr();
20221930 return iterator(__ptr);
......@@ -2029,8 +1937,8 @@ _LIBCPP_HIDE_FROM_ABI void __tree<_Tp, _Compare, _Allocator>::__node_handle_merg
20291937
20301938 for (typename _Tree::iterator __i = __source.begin(); __i != __source.end();) {
20311939 __node_pointer __src_ptr = __i.__get_np();
2032 __parent_pointer __parent;
2033 __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__src_ptr->__value_));
1940 __end_node_pointer __parent;
1941 __node_base_pointer& __child = __find_leaf_high(__parent, __src_ptr->__value_);
20341942 ++__i;
20351943 __source.__remove_node_pointer(__src_ptr);
20361944 __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__src_ptr));
......@@ -2044,7 +1952,7 @@ typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allo
20441952 __node_pointer __np = __p.__get_np();
20451953 iterator __r = __remove_node_pointer(__np);
20461954 __node_allocator& __na = __node_alloc();
2047 __node_traits::destroy(__na, _NodeTypes::__get_ptr(const_cast<__node_value_type&>(*__p)));
1955 __node_traits::destroy(__na, std::addressof(const_cast<value_type&>(*__p)));
20481956 __node_traits::deallocate(__na, __np, 1);
20491957 return __r;
20501958}
......@@ -2118,17 +2026,17 @@ template <class _Tp, class _Compare, class _Allocator>
21182026template <class _Key>
21192027typename __tree<_Tp, _Compare, _Allocator>::size_type
21202028__tree<_Tp, _Compare, _Allocator>::__count_multi(const _Key& __k) const {
2121 __iter_pointer __result = __end_node();
2122 __node_pointer __rt = __root();
2029 __end_node_pointer __result = __end_node();
2030 __node_pointer __rt = __root();
21232031 while (__rt != nullptr) {
21242032 if (value_comp()(__k, __rt->__value_)) {
2125 __result = static_cast<__iter_pointer>(__rt);
2033 __result = static_cast<__end_node_pointer>(__rt);
21262034 __rt = static_cast<__node_pointer>(__rt->__left_);
21272035 } else if (value_comp()(__rt->__value_, __k))
21282036 __rt = static_cast<__node_pointer>(__rt->__right_);
21292037 else
21302038 return std::distance(
2131 __lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__iter_pointer>(__rt)),
2039 __lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__end_node_pointer>(__rt)),
21322040 __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result));
21332041 }
21342042 return 0;
......@@ -2137,10 +2045,10 @@ __tree<_Tp, _Compare, _Allocator>::__count_multi(const _Key& __k) const {
21372045template <class _Tp, class _Compare, class _Allocator>
21382046template <class _Key>
21392047typename __tree<_Tp, _Compare, _Allocator>::iterator
2140__tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result) {
2048__tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v, __node_pointer __root, __end_node_pointer __result) {
21412049 while (__root != nullptr) {
21422050 if (!value_comp()(__root->__value_, __v)) {
2143 __result = static_cast<__iter_pointer>(__root);
2051 __result = static_cast<__end_node_pointer>(__root);
21442052 __root = static_cast<__node_pointer>(__root->__left_);
21452053 } else
21462054 __root = static_cast<__node_pointer>(__root->__right_);
......@@ -2151,10 +2059,10 @@ __tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v, __node_pointer
21512059template <class _Tp, class _Compare, class _Allocator>
21522060template <class _Key>
21532061typename __tree<_Tp, _Compare, _Allocator>::const_iterator __tree<_Tp, _Compare, _Allocator>::__lower_bound(
2154 const _Key& __v, __node_pointer __root, __iter_pointer __result) const {
2062 const _Key& __v, __node_pointer __root, __end_node_pointer __result) const {
21552063 while (__root != nullptr) {
21562064 if (!value_comp()(__root->__value_, __v)) {
2157 __result = static_cast<__iter_pointer>(__root);
2065 __result = static_cast<__end_node_pointer>(__root);
21582066 __root = static_cast<__node_pointer>(__root->__left_);
21592067 } else
21602068 __root = static_cast<__node_pointer>(__root->__right_);
......@@ -2165,10 +2073,10 @@ typename __tree<_Tp, _Compare, _Allocator>::const_iterator __tree<_Tp, _Compare,
21652073template <class _Tp, class _Compare, class _Allocator>
21662074template <class _Key>
21672075typename __tree<_Tp, _Compare, _Allocator>::iterator
2168__tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v, __node_pointer __root, __iter_pointer __result) {
2076__tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v, __node_pointer __root, __end_node_pointer __result) {
21692077 while (__root != nullptr) {
21702078 if (value_comp()(__v, __root->__value_)) {
2171 __result = static_cast<__iter_pointer>(__root);
2079 __result = static_cast<__end_node_pointer>(__root);
21722080 __root = static_cast<__node_pointer>(__root->__left_);
21732081 } else
21742082 __root = static_cast<__node_pointer>(__root->__right_);
......@@ -2179,10 +2087,10 @@ __tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v, __node_pointer
21792087template <class _Tp, class _Compare, class _Allocator>
21802088template <class _Key>
21812089typename __tree<_Tp, _Compare, _Allocator>::const_iterator __tree<_Tp, _Compare, _Allocator>::__upper_bound(
2182 const _Key& __v, __node_pointer __root, __iter_pointer __result) const {
2090 const _Key& __v, __node_pointer __root, __end_node_pointer __result) const {
21832091 while (__root != nullptr) {
21842092 if (value_comp()(__v, __root->__value_)) {
2185 __result = static_cast<__iter_pointer>(__root);
2093 __result = static_cast<__end_node_pointer>(__root);
21862094 __root = static_cast<__node_pointer>(__root->__left_);
21872095 } else
21882096 __root = static_cast<__node_pointer>(__root->__right_);
......@@ -2195,17 +2103,17 @@ template <class _Key>
21952103pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, typename __tree<_Tp, _Compare, _Allocator>::iterator>
21962104__tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) {
21972105 typedef pair<iterator, iterator> _Pp;
2198 __iter_pointer __result = __end_node();
2199 __node_pointer __rt = __root();
2106 __end_node_pointer __result = __end_node();
2107 __node_pointer __rt = __root();
22002108 while (__rt != nullptr) {
22012109 if (value_comp()(__k, __rt->__value_)) {
2202 __result = static_cast<__iter_pointer>(__rt);
2110 __result = static_cast<__end_node_pointer>(__rt);
22032111 __rt = static_cast<__node_pointer>(__rt->__left_);
22042112 } else if (value_comp()(__rt->__value_, __k))
22052113 __rt = static_cast<__node_pointer>(__rt->__right_);
22062114 else
22072115 return _Pp(iterator(__rt),
2208 iterator(__rt->__right_ != nullptr ? static_cast<__iter_pointer>(std::__tree_min(__rt->__right_))
2116 iterator(__rt->__right_ != nullptr ? static_cast<__end_node_pointer>(std::__tree_min(__rt->__right_))
22092117 : __result));
22102118 }
22112119 return _Pp(iterator(__result), iterator(__result));
......@@ -2217,11 +2125,11 @@ pair<typename __tree<_Tp, _Compare, _Allocator>::const_iterator,
22172125 typename __tree<_Tp, _Compare, _Allocator>::const_iterator>
22182126__tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) const {
22192127 typedef pair<const_iterator, const_iterator> _Pp;
2220 __iter_pointer __result = __end_node();
2221 __node_pointer __rt = __root();
2128 __end_node_pointer __result = __end_node();
2129 __node_pointer __rt = __root();
22222130 while (__rt != nullptr) {
22232131 if (value_comp()(__k, __rt->__value_)) {
2224 __result = static_cast<__iter_pointer>(__rt);
2132 __result = static_cast<__end_node_pointer>(__rt);
22252133 __rt = static_cast<__node_pointer>(__rt->__left_);
22262134 } else if (value_comp()(__rt->__value_, __k))
22272135 __rt = static_cast<__node_pointer>(__rt->__right_);
......@@ -2229,7 +2137,7 @@ __tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) const {
22292137 return _Pp(
22302138 const_iterator(__rt),
22312139 const_iterator(
2232 __rt->__right_ != nullptr ? static_cast<__iter_pointer>(std::__tree_min(__rt->__right_)) : __result));
2140 __rt->__right_ != nullptr ? static_cast<__end_node_pointer>(std::__tree_min(__rt->__right_)) : __result));
22332141 }
22342142 return _Pp(const_iterator(__result), const_iterator(__result));
22352143}
......@@ -2239,16 +2147,16 @@ template <class _Key>
22392147pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, typename __tree<_Tp, _Compare, _Allocator>::iterator>
22402148__tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) {
22412149 typedef pair<iterator, iterator> _Pp;
2242 __iter_pointer __result = __end_node();
2150 __end_node_pointer __result = __end_node();
22432151 __node_pointer __rt = __root();
22442152 while (__rt != nullptr) {
22452153 if (value_comp()(__k, __rt->__value_)) {
2246 __result = static_cast<__iter_pointer>(__rt);
2154 __result = static_cast<__end_node_pointer>(__rt);
22472155 __rt = static_cast<__node_pointer>(__rt->__left_);
22482156 } else if (value_comp()(__rt->__value_, __k))
22492157 __rt = static_cast<__node_pointer>(__rt->__right_);
22502158 else
2251 return _Pp(__lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__iter_pointer>(__rt)),
2159 return _Pp(__lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__end_node_pointer>(__rt)),
22522160 __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result));
22532161 }
22542162 return _Pp(iterator(__result), iterator(__result));
......@@ -2260,16 +2168,16 @@ pair<typename __tree<_Tp, _Compare, _Allocator>::const_iterator,
22602168 typename __tree<_Tp, _Compare, _Allocator>::const_iterator>
22612169__tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) const {
22622170 typedef pair<const_iterator, const_iterator> _Pp;
2263 __iter_pointer __result = __end_node();
2171 __end_node_pointer __result = __end_node();
22642172 __node_pointer __rt = __root();
22652173 while (__rt != nullptr) {
22662174 if (value_comp()(__k, __rt->__value_)) {
2267 __result = static_cast<__iter_pointer>(__rt);
2175 __result = static_cast<__end_node_pointer>(__rt);
22682176 __rt = static_cast<__node_pointer>(__rt->__left_);
22692177 } else if (value_comp()(__rt->__value_, __k))
22702178 __rt = static_cast<__node_pointer>(__rt->__right_);
22712179 else
2272 return _Pp(__lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__iter_pointer>(__rt)),
2180 return _Pp(__lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__end_node_pointer>(__rt)),
22732181 __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result));
22742182 }
22752183 return _Pp(const_iterator(__result), const_iterator(__result));
......@@ -2281,9 +2189,9 @@ __tree<_Tp, _Compare, _Allocator>::remove(const_iterator __p) _NOEXCEPT {
22812189 __node_pointer __np = __p.__get_np();
22822190 if (__begin_node() == __p.__ptr_) {
22832191 if (__np->__right_ != nullptr)
2284 __begin_node() = static_cast<__iter_pointer>(__np->__right_);
2192 __begin_node() = static_cast<__end_node_pointer>(__np->__right_);
22852193 else
2286 __begin_node() = static_cast<__iter_pointer>(__np->__parent_);
2194 __begin_node() = static_cast<__end_node_pointer>(__np->__parent_);
22872195 }
22882196 --size();
22892197 std::__tree_remove(__end_node()->__left_, static_cast<__node_base_pointer>(__np));
lib/libcxx/include/__tuple/make_tuple_types.h+1-1
......@@ -60,7 +60,7 @@ struct __make_tuple_types {
6060 static_assert(_Sp <= _Ep, "__make_tuple_types input error");
6161 using _RawTp _LIBCPP_NODEBUG = __remove_cvref_t<_Tp>;
6262 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>;
63 using type _LIBCPP_NODEBUG = typename _Maker::template __apply_quals<_Tp>;
6464};
6565
6666template <class... _Types, size_t _Ep>
lib/libcxx/include/__tuple/sfinae_helpers.h+1-1
......@@ -58,7 +58,7 @@ struct __tuple_constructible<_Tp, _Up, true, true>
5858 typename __make_tuple_types<_Up>::type > {};
5959
6060template <size_t _Ip, class... _Tp>
61struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, tuple<_Tp...> > {
61struct tuple_element<_Ip, tuple<_Tp...> > {
6262 using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, __tuple_types<_Tp...> >::type;
6363};
6464
lib/libcxx/include/__tuple/tuple_element.h+5-5
......@@ -21,27 +21,27 @@
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
2323template <size_t _Ip, class _Tp>
24struct _LIBCPP_TEMPLATE_VIS tuple_element;
24struct tuple_element;
2525
2626template <size_t _Ip, class _Tp>
27struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp> {
27struct tuple_element<_Ip, const _Tp> {
2828 using type _LIBCPP_NODEBUG = const typename tuple_element<_Ip, _Tp>::type;
2929};
3030
3131template <size_t _Ip, class _Tp>
32struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp> {
32struct tuple_element<_Ip, volatile _Tp> {
3333 using type _LIBCPP_NODEBUG = volatile typename tuple_element<_Ip, _Tp>::type;
3434};
3535
3636template <size_t _Ip, class _Tp>
37struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp> {
37struct tuple_element<_Ip, const volatile _Tp> {
3838 using type _LIBCPP_NODEBUG = const volatile typename tuple_element<_Ip, _Tp>::type;
3939};
4040
4141#ifndef _LIBCPP_CXX03_LANG
4242
4343template <size_t _Ip, class... _Types>
44struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...> > {
44struct tuple_element<_Ip, __tuple_types<_Types...> > {
4545 static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range");
4646 using type _LIBCPP_NODEBUG = __type_pack_element<_Ip, _Types...>;
4747};
lib/libcxx/include/__tuple/tuple_size.h+11-14
......@@ -25,45 +25,42 @@
2525_LIBCPP_BEGIN_NAMESPACE_STD
2626
2727template <class _Tp>
28struct _LIBCPP_TEMPLATE_VIS tuple_size;
28struct tuple_size;
2929
3030#if !defined(_LIBCPP_CXX03_LANG)
3131template <class _Tp, class...>
3232using __enable_if_tuple_size_imp _LIBCPP_NODEBUG = _Tp;
3333
3434template <class _Tp>
35struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp< const _Tp,
36 __enable_if_t<!is_volatile<_Tp>::value>,
37 integral_constant<size_t, sizeof(tuple_size<_Tp>)>>>
35struct tuple_size<
36 __enable_if_tuple_size_imp<const _Tp, __enable_if_t<!is_volatile<_Tp>::value>, decltype(tuple_size<_Tp>::value)>>
3837 : public integral_constant<size_t, tuple_size<_Tp>::value> {};
3938
4039template <class _Tp>
41struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp< volatile _Tp,
42 __enable_if_t<!is_const<_Tp>::value>,
43 integral_constant<size_t, sizeof(tuple_size<_Tp>)>>>
40struct tuple_size<
41 __enable_if_tuple_size_imp<volatile _Tp, __enable_if_t<!is_const<_Tp>::value>, decltype(tuple_size<_Tp>::value)>>
4442 : public integral_constant<size_t, tuple_size<_Tp>::value> {};
4543
4644template <class _Tp>
47struct _LIBCPP_TEMPLATE_VIS
48tuple_size<__enable_if_tuple_size_imp<const volatile _Tp, integral_constant<size_t, sizeof(tuple_size<_Tp>)>>>
45struct tuple_size<__enable_if_tuple_size_imp<const volatile _Tp, decltype(tuple_size<_Tp>::value)>>
4946 : public integral_constant<size_t, tuple_size<_Tp>::value> {};
5047
5148#else
5249template <class _Tp>
53struct _LIBCPP_TEMPLATE_VIS tuple_size<const _Tp> : public tuple_size<_Tp> {};
50struct tuple_size<const _Tp> : public tuple_size<_Tp> {};
5451template <class _Tp>
55struct _LIBCPP_TEMPLATE_VIS tuple_size<volatile _Tp> : public tuple_size<_Tp> {};
52struct tuple_size<volatile _Tp> : public tuple_size<_Tp> {};
5653template <class _Tp>
57struct _LIBCPP_TEMPLATE_VIS tuple_size<const volatile _Tp> : public tuple_size<_Tp> {};
54struct tuple_size<const volatile _Tp> : public tuple_size<_Tp> {};
5855#endif
5956
6057#ifndef _LIBCPP_CXX03_LANG
6158
6259template <class... _Tp>
63struct _LIBCPP_TEMPLATE_VIS tuple_size<tuple<_Tp...> > : public integral_constant<size_t, sizeof...(_Tp)> {};
60struct tuple_size<tuple<_Tp...> > : public integral_constant<size_t, sizeof...(_Tp)> {};
6461
6562template <class... _Tp>
66struct _LIBCPP_TEMPLATE_VIS tuple_size<__tuple_types<_Tp...> > : public integral_constant<size_t, sizeof...(_Tp)> {};
63struct tuple_size<__tuple_types<_Tp...> > : public integral_constant<size_t, sizeof...(_Tp)> {};
6764
6865# if _LIBCPP_STD_VER >= 17
6966template <class _Tp>
lib/libcxx/include/__type_traits/add_cv_quals.h+3-3
......@@ -18,7 +18,7 @@
1818_LIBCPP_BEGIN_NAMESPACE_STD
1919
2020template <class _Tp>
21struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS add_const {
21struct _LIBCPP_NO_SPECIALIZATIONS add_const {
2222 using type _LIBCPP_NODEBUG = const _Tp;
2323};
2424
......@@ -28,7 +28,7 @@ using add_const_t = typename add_const<_Tp>::type;
2828#endif
2929
3030template <class _Tp>
31struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS add_cv {
31struct _LIBCPP_NO_SPECIALIZATIONS add_cv {
3232 using type _LIBCPP_NODEBUG = const volatile _Tp;
3333};
3434
......@@ -38,7 +38,7 @@ using add_cv_t = typename add_cv<_Tp>::type;
3838#endif
3939
4040template <class _Tp>
41struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS add_volatile {
41struct _LIBCPP_NO_SPECIALIZATIONS add_volatile {
4242 using type _LIBCPP_NODEBUG = volatile _Tp;
4343};
4444
lib/libcxx/include/__type_traits/add_lvalue_reference.h deleted-54
......@@ -1,54 +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_LVALUE_REFERENCE_H
10#define _LIBCPP___TYPE_TRAITS_ADD_LVALUE_REFERENCE_H
11
12#include <__config>
13#include <__type_traits/is_referenceable.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 __has_builtin(__add_lvalue_reference)
22
23template <class _Tp>
24using __add_lvalue_reference_t _LIBCPP_NODEBUG = __add_lvalue_reference(_Tp);
25
26#else
27
28template <class _Tp, bool = __libcpp_is_referenceable<_Tp>::value>
29struct __add_lvalue_reference_impl {
30 using type _LIBCPP_NODEBUG = _Tp;
31};
32template <class _Tp >
33struct __add_lvalue_reference_impl<_Tp, true> {
34 using type _LIBCPP_NODEBUG = _Tp&;
35};
36
37template <class _Tp>
38using __add_lvalue_reference_t = typename __add_lvalue_reference_impl<_Tp>::type;
39
40#endif // __has_builtin(__add_lvalue_reference)
41
42template <class _Tp>
43struct _LIBCPP_NO_SPECIALIZATIONS add_lvalue_reference {
44 using type _LIBCPP_NODEBUG = __add_lvalue_reference_t<_Tp>;
45};
46
47#if _LIBCPP_STD_VER >= 14
48template <class _Tp>
49using add_lvalue_reference_t = __add_lvalue_reference_t<_Tp>;
50#endif
51
52_LIBCPP_END_NAMESPACE_STD
53
54#endif // _LIBCPP___TYPE_TRAITS_ADD_LVALUE_REFERENCE_H
lib/libcxx/include/__type_traits/add_pointer.h+14-4
......@@ -20,13 +20,23 @@
2020
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
23#if !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS) && __has_builtin(__add_pointer)
23#if !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS)
2424
25template <class _Tp>
26struct _LIBCPP_NO_SPECIALIZATIONS add_pointer {
27 using type _LIBCPP_NODEBUG = __add_pointer(_Tp);
28};
29
30# ifdef _LIBCPP_COMPILER_GCC
31template <class _Tp>
32using __add_pointer_t _LIBCPP_NODEBUG = typename add_pointer<_Tp>::type;
33# else
2534template <class _Tp>
2635using __add_pointer_t _LIBCPP_NODEBUG = __add_pointer(_Tp);
36# endif
2737
2838#else
29template <class _Tp, bool = __libcpp_is_referenceable<_Tp>::value || is_void<_Tp>::value>
39template <class _Tp, bool = __is_referenceable_v<_Tp> || is_void<_Tp>::value>
3040struct __add_pointer_impl {
3141 using type _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tp>*;
3242};
......@@ -38,13 +48,13 @@ struct __add_pointer_impl<_Tp, false> {
3848template <class _Tp>
3949using __add_pointer_t = typename __add_pointer_impl<_Tp>::type;
4050
41#endif // !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS) && __has_builtin(__add_pointer)
42
4351template <class _Tp>
4452struct _LIBCPP_NO_SPECIALIZATIONS add_pointer {
4553 using type _LIBCPP_NODEBUG = __add_pointer_t<_Tp>;
4654};
4755
56#endif // !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS)
57
4858#if _LIBCPP_STD_VER >= 14
4959template <class _Tp>
5060using add_pointer_t = __add_pointer_t<_Tp>;
lib/libcxx/include/__type_traits/add_reference.h created+58
......@@ -0,0 +1,58 @@
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_REFERENCE_H
10#define _LIBCPP___TYPE_TRAITS_ADD_REFERENCE_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_NO_SPECIALIZATIONS add_lvalue_reference {
22 using type _LIBCPP_NODEBUG = __add_lvalue_reference(_Tp);
23};
24
25#ifdef _LIBCPP_COMPILER_GCC
26template <class _Tp>
27using __add_lvalue_reference_t _LIBCPP_NODEBUG = typename add_lvalue_reference<_Tp>::type;
28#else
29template <class _Tp>
30using __add_lvalue_reference_t _LIBCPP_NODEBUG = __add_lvalue_reference(_Tp);
31#endif
32
33#if _LIBCPP_STD_VER >= 14
34template <class _Tp>
35using add_lvalue_reference_t = __add_lvalue_reference_t<_Tp>;
36#endif
37
38template <class _Tp>
39struct _LIBCPP_NO_SPECIALIZATIONS add_rvalue_reference {
40 using type _LIBCPP_NODEBUG = __add_rvalue_reference(_Tp);
41};
42
43#ifdef _LIBCPP_COMPILER_GCC
44template <class _Tp>
45using __add_rvalue_reference_t _LIBCPP_NODEBUG = typename add_rvalue_reference<_Tp>::type;
46#else
47template <class _Tp>
48using __add_rvalue_reference_t _LIBCPP_NODEBUG = __add_rvalue_reference(_Tp);
49#endif
50
51#if _LIBCPP_STD_VER >= 14
52template <class _Tp>
53using add_rvalue_reference_t = __add_rvalue_reference_t<_Tp>;
54#endif
55
56_LIBCPP_END_NAMESPACE_STD
57
58#endif // _LIBCPP___TYPE_TRAITS_ADD_REFERENCE_H
lib/libcxx/include/__type_traits/add_rvalue_reference.h deleted-54
......@@ -1,54 +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_RVALUE_REFERENCE_H
10#define _LIBCPP___TYPE_TRAITS_ADD_RVALUE_REFERENCE_H
11
12#include <__config>
13#include <__type_traits/is_referenceable.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 __has_builtin(__add_rvalue_reference)
22
23template <class _Tp>
24using __add_rvalue_reference_t _LIBCPP_NODEBUG = __add_rvalue_reference(_Tp);
25
26#else
27
28template <class _Tp, bool = __libcpp_is_referenceable<_Tp>::value>
29struct __add_rvalue_reference_impl {
30 using type _LIBCPP_NODEBUG = _Tp;
31};
32template <class _Tp >
33struct __add_rvalue_reference_impl<_Tp, true> {
34 using type _LIBCPP_NODEBUG = _Tp&&;
35};
36
37template <class _Tp>
38using __add_rvalue_reference_t = typename __add_rvalue_reference_impl<_Tp>::type;
39
40#endif // __has_builtin(__add_rvalue_reference)
41
42template <class _Tp>
43struct _LIBCPP_NO_SPECIALIZATIONS add_rvalue_reference {
44 using type = __add_rvalue_reference_t<_Tp>;
45};
46
47#if _LIBCPP_STD_VER >= 14
48template <class _Tp>
49using add_rvalue_reference_t = __add_rvalue_reference_t<_Tp>;
50#endif
51
52_LIBCPP_END_NAMESPACE_STD
53
54#endif // _LIBCPP___TYPE_TRAITS_ADD_RVALUE_REFERENCE_H
lib/libcxx/include/__type_traits/aligned_storage.h+1-1
......@@ -68,7 +68,7 @@ struct __find_max_align<__type_list<_Head, _Tail...>, _Len>
6868 __select_align<_Len, _Head::value, __find_max_align<__type_list<_Tail...>, _Len>::value>::value> {};
6969
7070template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
71struct _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS aligned_storage {
71struct _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_NO_SPECIALIZATIONS aligned_storage {
7272 union _ALIGNAS(_Align) type {
7373 unsigned char __data[(_Len + _Align - 1) / _Align * _Align];
7474 };
lib/libcxx/include/__type_traits/alignment_of.h+1-2
......@@ -20,8 +20,7 @@
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
2222template <class _Tp>
23struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS alignment_of
24 : public integral_constant<size_t, _LIBCPP_ALIGNOF(_Tp)> {};
23struct _LIBCPP_NO_SPECIALIZATIONS alignment_of : public integral_constant<size_t, _LIBCPP_ALIGNOF(_Tp)> {};
2524
2625#if _LIBCPP_STD_VER >= 17
2726template <class _Tp>
lib/libcxx/include/__type_traits/common_reference.h+22-12
......@@ -10,6 +10,7 @@
1010#define _LIBCPP___TYPE_TRAITS_COMMON_REFERENCE_H
1111
1212#include <__config>
13#include <__type_traits/add_pointer.h>
1314#include <__type_traits/common_type.h>
1415#include <__type_traits/copy_cv.h>
1516#include <__type_traits/copy_cvref.h>
......@@ -109,11 +110,18 @@ struct __common_ref {};
109110// Note C: For the common_reference trait applied to a parameter pack [...]
110111
111112template <class...>
112struct common_reference;
113struct _LIBCPP_NO_SPECIALIZATIONS common_reference;
113114
114115template <class... _Types>
115116using common_reference_t = typename common_reference<_Types...>::type;
116117
118template <class, class, template <class> class, template <class> class>
119struct basic_common_reference {};
120
121_LIBCPP_DIAGNOSTIC_PUSH
122# if __has_warning("-Winvalid-specialization")
123_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
124# endif
117125// bullet 1 - sizeof...(T) == 0
118126template <>
119127struct common_reference<> {};
......@@ -121,7 +129,7 @@ struct common_reference<> {};
121129// bullet 2 - sizeof...(T) == 1
122130template <class _Tp>
123131struct common_reference<_Tp> {
124 using type = _Tp;
132 using type _LIBCPP_NODEBUG = _Tp;
125133};
126134
127135// bullet 3 - sizeof...(T) == 2
......@@ -132,22 +140,23 @@ struct __common_reference_sub_bullet2 : __common_reference_sub_bullet3<_Tp, _Up>
132140template <class _Tp, class _Up>
133141struct __common_reference_sub_bullet1 : __common_reference_sub_bullet2<_Tp, _Up> {};
134142
135// sub-bullet 1 - If T1 and T2 are reference types and COMMON-REF(T1, T2) is well-formed, then
136// the member typedef `type` denotes that type.
143// sub-bullet 1 - Let R be COMMON-REF(T1, T2). If T1 and T2 are reference types, R is well-formed, and
144// is_convertible_v<add_pointer_t<T1>, add_pointer_t<R>> && is_convertible_v<add_pointer_t<T2>, add_pointer_t<R>> is
145// true, then the member typedef type denotes R.
146
137147template <class _Tp, class _Up>
138148struct common_reference<_Tp, _Up> : __common_reference_sub_bullet1<_Tp, _Up> {};
139149
140150template <class _Tp, class _Up>
141 requires is_reference_v<_Tp> && is_reference_v<_Up> && requires { typename __common_ref_t<_Tp, _Up>; }
151 requires is_reference_v<_Tp> && is_reference_v<_Up> && requires { typename __common_ref_t<_Tp, _Up>; } &&
152 is_convertible_v<add_pointer_t<_Tp>, add_pointer_t<__common_ref_t<_Tp, _Up>>> &&
153 is_convertible_v<add_pointer_t<_Up>, add_pointer_t<__common_ref_t<_Tp, _Up>>>
142154struct __common_reference_sub_bullet1<_Tp, _Up> {
143 using type = __common_ref_t<_Tp, _Up>;
155 using type _LIBCPP_NODEBUG = __common_ref_t<_Tp, _Up>;
144156};
145157
146158// sub-bullet 2 - Otherwise, if basic_common_reference<remove_cvref_t<T1>, remove_cvref_t<T2>, XREF(T1), XREF(T2)>::type
147159// is well-formed, then the member typedef `type` denotes that type.
148template <class, class, template <class> class, template <class> class>
149struct basic_common_reference {};
150
151160template <class _Tp, class _Up>
152161using __basic_common_reference_t _LIBCPP_NODEBUG =
153162 typename basic_common_reference<remove_cvref_t<_Tp>,
......@@ -158,7 +167,7 @@ using __basic_common_reference_t _LIBCPP_NODEBUG =
158167template <class _Tp, class _Up>
159168 requires requires { typename __basic_common_reference_t<_Tp, _Up>; }
160169struct __common_reference_sub_bullet2<_Tp, _Up> {
161 using type = __basic_common_reference_t<_Tp, _Up>;
170 using type _LIBCPP_NODEBUG = __basic_common_reference_t<_Tp, _Up>;
162171};
163172
164173// sub-bullet 3 - Otherwise, if COND-RES(T1, T2) is well-formed,
......@@ -166,7 +175,7 @@ struct __common_reference_sub_bullet2<_Tp, _Up> {
166175template <class _Tp, class _Up>
167176 requires requires { typename __cond_res<_Tp, _Up>; }
168177struct __common_reference_sub_bullet3<_Tp, _Up> {
169 using type = __cond_res<_Tp, _Up>;
178 using type _LIBCPP_NODEBUG = __cond_res<_Tp, _Up>;
170179};
171180
172181// sub-bullet 4 & 5 - Otherwise, if common_type_t<T1, T2> is well-formed,
......@@ -180,10 +189,11 @@ struct __common_reference_sub_bullet3 : common_type<_Tp, _Up> {};
180189template <class _Tp, class _Up, class _Vp, class... _Rest>
181190 requires requires { typename common_reference_t<_Tp, _Up>; }
182191struct common_reference<_Tp, _Up, _Vp, _Rest...> : common_reference<common_reference_t<_Tp, _Up>, _Vp, _Rest...> {};
192_LIBCPP_DIAGNOSTIC_POP
183193
184194// bullet 5 - Otherwise, there shall be no member `type`.
185195template <class...>
186struct common_reference {};
196struct _LIBCPP_NO_SPECIALIZATIONS common_reference {};
187197
188198#endif // _LIBCPP_STD_VER >= 20
189199
lib/libcxx/include/__type_traits/common_type.h+6-7
......@@ -48,7 +48,7 @@ struct __common_type3 {};
4848// sub-bullet 4 - "if COND_RES(CREF(D1), CREF(D2)) denotes a type..."
4949template <class _Tp, class _Up>
5050struct __common_type3<_Tp, _Up, void_t<__cond_type<const _Tp&, const _Up&>>> {
51 using type = remove_cvref_t<__cond_type<const _Tp&, const _Up&>>;
51 using type _LIBCPP_NODEBUG = remove_cvref_t<__cond_type<const _Tp&, const _Up&>>;
5252};
5353
5454template <class _Tp, class _Up, class = void>
......@@ -70,7 +70,7 @@ struct __common_type_impl {};
7070template <class... _Tp>
7171struct __common_types;
7272template <class... _Tp>
73struct _LIBCPP_TEMPLATE_VIS common_type;
73struct common_type;
7474
7575template <class _Tp, class _Up>
7676struct __common_type_impl< __common_types<_Tp, _Up>, __void_t<typename common_type<_Tp, _Up>::type> > {
......@@ -84,18 +84,18 @@ struct __common_type_impl<__common_types<_Tp, _Up, _Vp, _Rest...>, __void_t<type
8484// bullet 1 - sizeof...(Tp) == 0
8585
8686template <>
87struct _LIBCPP_TEMPLATE_VIS common_type<> {};
87struct common_type<> {};
8888
8989// bullet 2 - sizeof...(Tp) == 1
9090
9191template <class _Tp>
92struct _LIBCPP_TEMPLATE_VIS common_type<_Tp> : public common_type<_Tp, _Tp> {};
92struct common_type<_Tp> : public common_type<_Tp, _Tp> {};
9393
9494// bullet 3 - sizeof...(Tp) == 2
9595
9696// sub-bullet 1 - "If is_same_v<T1, D1> is false or ..."
9797template <class _Tp, class _Up>
98struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up>
98struct common_type<_Tp, _Up>
9999 : __conditional_t<_IsSame<_Tp, __decay_t<_Tp> >::value && _IsSame<_Up, __decay_t<_Up> >::value,
100100 __common_type2_imp<_Tp, _Up>,
101101 common_type<__decay_t<_Tp>, __decay_t<_Up> > > {};
......@@ -103,8 +103,7 @@ struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up>
103103// bullet 4 - sizeof...(Tp) > 2
104104
105105template <class _Tp, class _Up, class _Vp, class... _Rest>
106struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up, _Vp, _Rest...>
107 : __common_type_impl<__common_types<_Tp, _Up, _Vp, _Rest...> > {};
106struct common_type<_Tp, _Up, _Vp, _Rest...> : __common_type_impl<__common_types<_Tp, _Up, _Vp, _Rest...> > {};
108107
109108#endif
110109
lib/libcxx/include/__type_traits/conditional.h+2-2
......@@ -36,7 +36,7 @@ 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 _LIBCPP_NO_SPECIALIZATIONS conditional {
39struct _LIBCPP_NO_SPECIALIZATIONS conditional {
4040 using type _LIBCPP_NODEBUG = _If;
4141};
4242
......@@ -45,7 +45,7 @@ _LIBCPP_DIAGNOSTIC_PUSH
4545_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
4646#endif
4747template <class _If, class _Then>
48struct _LIBCPP_TEMPLATE_VIS conditional<false, _If, _Then> {
48struct conditional<false, _If, _Then> {
4949 using type _LIBCPP_NODEBUG = _Then;
5050};
5151_LIBCPP_DIAGNOSTIC_POP
lib/libcxx/include/__type_traits/container_traits.h+3
......@@ -36,6 +36,9 @@ struct __container_traits {
3636 // `insert(...)` or `emplace(...)` has strong exception guarantee, that is, if the function
3737 // exits via an exception, the original container is unaffected
3838 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = false;
39
40 // A trait that tells whether a container supports `reserve(n)` member function.
41 static _LIBCPP_CONSTEXPR const bool __reservable = false;
3942};
4043
4144_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/copy_cvref.h+1-2
......@@ -10,8 +10,7 @@
1010#define _LIBCPP___TYPE_TRAITS_COPY_CVREF_H
1111
1212#include <__config>
13#include <__type_traits/add_lvalue_reference.h>
14#include <__type_traits/add_rvalue_reference.h>
13#include <__type_traits/add_reference.h>
1514#include <__type_traits/copy_cv.h>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__type_traits/decay.h+6-38
......@@ -10,14 +10,6 @@
1010#define _LIBCPP___TYPE_TRAITS_DECAY_H
1111
1212#include <__config>
13#include <__type_traits/add_pointer.h>
14#include <__type_traits/conditional.h>
15#include <__type_traits/is_array.h>
16#include <__type_traits/is_function.h>
17#include <__type_traits/is_referenceable.h>
18#include <__type_traits/remove_cv.h>
19#include <__type_traits/remove_extent.h>
20#include <__type_traits/remove_reference.h>
2113
2214#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2315# pragma GCC system_header
......@@ -25,42 +17,18 @@
2517
2618_LIBCPP_BEGIN_NAMESPACE_STD
2719
28#if __has_builtin(__decay)
29template <class _Tp>
30using __decay_t _LIBCPP_NODEBUG = __decay(_Tp);
31
3220template <class _Tp>
3321struct _LIBCPP_NO_SPECIALIZATIONS decay {
34 using type _LIBCPP_NODEBUG = __decay_t<_Tp>;
35};
36
37#else
38template <class _Up, bool>
39struct __decay {
40 using type _LIBCPP_NODEBUG = __remove_cv_t<_Up>;
41};
42
43template <class _Up>
44struct __decay<_Up, true> {
45public:
46 using type _LIBCPP_NODEBUG =
47 __conditional_t<is_array<_Up>::value,
48 __add_pointer_t<__remove_extent_t<_Up> >,
49 __conditional_t<is_function<_Up>::value, typename add_pointer<_Up>::type, __remove_cv_t<_Up> > >;
22 using type _LIBCPP_NODEBUG = __decay(_Tp);
5023};
5124
25#ifdef _LIBCPP_COMPILER_GCC
5226template <class _Tp>
53struct _LIBCPP_TEMPLATE_VIS decay {
54private:
55 using _Up _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tp>;
56
57public:
58 using type _LIBCPP_NODEBUG = typename __decay<_Up, __libcpp_is_referenceable<_Up>::value>::type;
59};
60
27using __decay_t _LIBCPP_NODEBUG = typename decay<_Tp>::type;
28#else
6129template <class _Tp>
62using __decay_t = typename decay<_Tp>::type;
63#endif // __has_builtin(__decay)
30using __decay_t _LIBCPP_NODEBUG = __decay(_Tp);
31#endif
6432
6533#if _LIBCPP_STD_VER >= 14
6634template <class _Tp>
lib/libcxx/include/__type_traits/dependent_type.h+1-1
......@@ -18,7 +18,7 @@
1818_LIBCPP_BEGIN_NAMESPACE_STD
1919
2020template <class _Tp, bool>
21struct _LIBCPP_TEMPLATE_VIS __dependent_type : public _Tp {};
21struct __dependent_type : public _Tp {};
2222
2323_LIBCPP_END_NAMESPACE_STD
2424
lib/libcxx/include/__type_traits/desugars_to.h+12
......@@ -52,6 +52,18 @@ struct __totally_ordered_less_tag {};
5252template <class _CanonicalTag, class _Operation, class... _Args>
5353inline const bool __desugars_to_v = false;
5454
55// For the purpose of determining whether something desugars to something else,
56// we disregard const and ref qualifiers on the operation itself.
57template <class _CanonicalTag, class _Operation, class... _Args>
58inline const bool __desugars_to_v<_CanonicalTag, _Operation const, _Args...> =
59 __desugars_to_v<_CanonicalTag, _Operation, _Args...>;
60template <class _CanonicalTag, class _Operation, class... _Args>
61inline const bool __desugars_to_v<_CanonicalTag, _Operation&, _Args...> =
62 __desugars_to_v<_CanonicalTag, _Operation, _Args...>;
63template <class _CanonicalTag, class _Operation, class... _Args>
64inline const bool __desugars_to_v<_CanonicalTag, _Operation&&, _Args...> =
65 __desugars_to_v<_CanonicalTag, _Operation, _Args...>;
66
5567_LIBCPP_END_NAMESPACE_STD
5668
5769#endif // _LIBCPP___TYPE_TRAITS_DESUGARS_TO_H
lib/libcxx/include/__type_traits/enable_if.h+2-2
......@@ -18,14 +18,14 @@
1818_LIBCPP_BEGIN_NAMESPACE_STD
1919
2020template <bool, class _Tp = void>
21struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS enable_if{};
21struct _LIBCPP_NO_SPECIALIZATIONS enable_if{};
2222
2323_LIBCPP_DIAGNOSTIC_PUSH
2424#if __has_warning("-Winvalid-specialization")
2525_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
2626#endif
2727template <class _Tp>
28struct _LIBCPP_TEMPLATE_VIS enable_if<true, _Tp> {
28struct enable_if<true, _Tp> {
2929 typedef _Tp type;
3030};
3131_LIBCPP_DIAGNOSTIC_POP
lib/libcxx/include/__type_traits/extent.h+6-6
......@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#if __has_builtin(__array_extent)
2323
2424template <class _Tp, size_t _Dim = 0>
25struct _LIBCPP_NO_SPECIALIZATIONS _LIBCPP_TEMPLATE_VIS extent : integral_constant<size_t, __array_extent(_Tp, _Dim)> {};
25struct _LIBCPP_NO_SPECIALIZATIONS extent : integral_constant<size_t, __array_extent(_Tp, _Dim)> {};
2626
2727# if _LIBCPP_STD_VER >= 17
2828template <class _Tp, unsigned _Ip = 0>
......@@ -32,15 +32,15 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr size_t extent_v = __array_extent(_Tp
3232#else // __has_builtin(__array_extent)
3333
3434template <class _Tp, unsigned _Ip = 0>
35struct _LIBCPP_TEMPLATE_VIS extent : public integral_constant<size_t, 0> {};
35struct extent : public integral_constant<size_t, 0> {};
3636template <class _Tp>
37struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], 0> : public integral_constant<size_t, 0> {};
37struct extent<_Tp[], 0> : public integral_constant<size_t, 0> {};
3838template <class _Tp, unsigned _Ip>
39struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], _Ip> : public integral_constant<size_t, extent<_Tp, _Ip - 1>::value> {};
39struct extent<_Tp[], _Ip> : public integral_constant<size_t, extent<_Tp, _Ip - 1>::value> {};
4040template <class _Tp, size_t _Np>
41struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], 0> : public integral_constant<size_t, _Np> {};
41struct extent<_Tp[_Np], 0> : public integral_constant<size_t, _Np> {};
4242template <class _Tp, size_t _Np, unsigned _Ip>
43struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], _Ip> : public integral_constant<size_t, extent<_Tp, _Ip - 1>::value> {};
43struct extent<_Tp[_Np], _Ip> : public integral_constant<size_t, extent<_Tp, _Ip - 1>::value> {};
4444
4545# if _LIBCPP_STD_VER >= 17
4646template <class _Tp, unsigned _Ip = 0>
lib/libcxx/include/__type_traits/has_unique_object_representation.h+2-8
......@@ -11,7 +11,6 @@
1111
1212#include <__config>
1313#include <__type_traits/integral_constant.h>
14#include <__type_traits/remove_all_extents.h>
1514
1615#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1716# pragma GCC system_header
......@@ -22,13 +21,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2221#if _LIBCPP_STD_VER >= 17
2322
2423template <class _Tp>
25struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS has_unique_object_representations
26 // TODO: We work around a Clang and GCC bug in __has_unique_object_representations by using remove_all_extents
27 // even though it should not be necessary. This was reported to the compilers:
28 // - Clang: https://github.com/llvm/llvm-project/issues/95311
29 // - GCC: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115476
30 // remove_all_extents_t can be removed once all the compilers we support have fixed this bug.
31 : public integral_constant<bool, __has_unique_object_representations(remove_all_extents_t<_Tp>)> {};
24struct _LIBCPP_NO_SPECIALIZATIONS has_unique_object_representations
25 : integral_constant<bool, __has_unique_object_representations(_Tp)> {};
3226
3327template <class _Tp>
3428_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool has_unique_object_representations_v =
lib/libcxx/include/__type_traits/has_virtual_destructor.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS has_virtual_destructor
22struct _LIBCPP_NO_SPECIALIZATIONS has_virtual_destructor
2323 : public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
2424
2525#if _LIBCPP_STD_VER >= 17
lib/libcxx/include/__type_traits/integer_traits.h created+73
......@@ -0,0 +1,73 @@
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_INTEGER_TRAITS_H
10#define _LIBCPP___TYPE_TRAITS_INTEGER_TRAITS_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
20// This trait is to determine whether a type is a /signed integer type/
21// See [basic.fundamental]/p1
22template <class _Tp>
23inline const bool __is_signed_integer_v = false;
24template <>
25inline const bool __is_signed_integer_v<signed char> = true;
26template <>
27inline const bool __is_signed_integer_v<signed short> = true;
28template <>
29inline const bool __is_signed_integer_v<signed int> = true;
30template <>
31inline const bool __is_signed_integer_v<signed long> = true;
32template <>
33inline const bool __is_signed_integer_v<signed long long> = true;
34#if _LIBCPP_HAS_INT128
35template <>
36inline const bool __is_signed_integer_v<__int128_t> = true;
37#endif
38
39// This trait is to determine whether a type is an /unsigned integer type/
40// See [basic.fundamental]/p2
41template <class _Tp>
42inline const bool __is_unsigned_integer_v = false;
43template <>
44inline const bool __is_unsigned_integer_v<unsigned char> = true;
45template <>
46inline const bool __is_unsigned_integer_v<unsigned short> = true;
47template <>
48inline const bool __is_unsigned_integer_v<unsigned int> = true;
49template <>
50inline const bool __is_unsigned_integer_v<unsigned long> = true;
51template <>
52inline const bool __is_unsigned_integer_v<unsigned long long> = true;
53#if _LIBCPP_HAS_INT128
54template <>
55inline const bool __is_unsigned_integer_v<__uint128_t> = true;
56#endif
57
58#if _LIBCPP_STD_VER >= 20
59template <class _Tp>
60concept __signed_integer = __is_signed_integer_v<_Tp>;
61
62template <class _Tp>
63concept __unsigned_integer = __is_unsigned_integer_v<_Tp>;
64
65// This isn't called __integer, because an integer type according to [basic.fundamental]/p11 is the same as an integral
66// type. An integral type is _not_ the same set of types as signed and unsigned integer types combined.
67template <class _Tp>
68concept __signed_or_unsigned_integer = __signed_integer<_Tp> || __unsigned_integer<_Tp>;
69#endif
70
71_LIBCPP_END_NAMESPACE_STD
72
73#endif // _LIBCPP___TYPE_TRAITS_INTEGER_TRAITS_H
lib/libcxx/include/__type_traits/integral_constant.h+1-1
......@@ -18,7 +18,7 @@
1818_LIBCPP_BEGIN_NAMESPACE_STD
1919
2020template <class _Tp, _Tp __v>
21struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS integral_constant {
21struct _LIBCPP_NO_SPECIALIZATIONS integral_constant {
2222 static inline _LIBCPP_CONSTEXPR const _Tp value = __v;
2323 typedef _Tp value_type;
2424 typedef integral_constant type;
lib/libcxx/include/__type_traits/invoke.h+110-37
......@@ -22,6 +22,7 @@
2222#include <__type_traits/is_same.h>
2323#include <__type_traits/is_void.h>
2424#include <__type_traits/nat.h>
25#include <__type_traits/void_t.h>
2526#include <__utility/declval.h>
2627#include <__utility/forward.h>
2728
......@@ -41,19 +42,22 @@
4142// return std::invoke_r(std::forward<Args>(args)...);
4243// }
4344//
44// template <class Ret, class Func, class... Args>
45// inline const bool __is_invocable_r_v = is_invocable_r_v<Ret, Func, Args...>;
46//
4745// template <class Func, class... Args>
4846// struct __is_invocable : is_invocable<Func, Args...> {};
4947//
5048// template <class Func, class... Args>
5149// inline const bool __is_invocable_v = is_invocable_v<Func, Args...>;
5250//
51// template <class Ret, class Func, class... Args>
52// inline const bool __is_invocable_r_v = is_invocable_r_v<Ret, Func, Args...>;
53//
5354// template <class Func, class... Args>
5455// inline const bool __is_nothrow_invocable_v = is_nothrow_invocable_v<Func, Args...>;
5556//
5657// template <class Func, class... Args>
58// inline const bool __is_nothrow_invocable_r_v = is_nothrow_invocable_r_v<Func, Args...>;
59//
60// template <class Func, class... Args>
5761// struct __invoke_result : invoke_result {};
5862//
5963// template <class Func, class... Args>
......@@ -61,6 +65,72 @@
6165
6266_LIBCPP_BEGIN_NAMESPACE_STD
6367
68#if __has_builtin(__builtin_invoke)
69
70template <class, class... _Args>
71struct __invoke_result_impl {};
72
73template <class... _Args>
74struct __invoke_result_impl<__void_t<decltype(__builtin_invoke(std::declval<_Args>()...))>, _Args...> {
75 using type _LIBCPP_NODEBUG = decltype(__builtin_invoke(std::declval<_Args>()...));
76};
77
78template <class... _Args>
79using __invoke_result _LIBCPP_NODEBUG = __invoke_result_impl<void, _Args...>;
80
81template <class... _Args>
82using __invoke_result_t _LIBCPP_NODEBUG = typename __invoke_result<_Args...>::type;
83
84template <class... _Args>
85_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __invoke_result_t<_Args...> __invoke(_Args&&... __args)
86 _NOEXCEPT_(noexcept(__builtin_invoke(std::forward<_Args>(__args)...))) {
87 return __builtin_invoke(std::forward<_Args>(__args)...);
88}
89
90template <class _Void, class... _Args>
91inline const bool __is_invocable_impl = false;
92
93template <class... _Args>
94inline const bool __is_invocable_impl<__void_t<__invoke_result_t<_Args...> >, _Args...> = true;
95
96template <class... _Args>
97inline const bool __is_invocable_v = __is_invocable_impl<void, _Args...>;
98
99template <class... _Args>
100struct __is_invocable : integral_constant<bool, __is_invocable_v<_Args...> > {};
101
102template <class _Ret, bool, class... _Args>
103inline const bool __is_invocable_r_impl = false;
104
105template <class _Ret, class... _Args>
106inline const bool __is_invocable_r_impl<_Ret, true, _Args...> =
107 __is_core_convertible<__invoke_result_t<_Args...>, _Ret>::value || is_void<_Ret>::value;
108
109template <class _Ret, class... _Args>
110inline const bool __is_invocable_r_v = __is_invocable_r_impl<_Ret, __is_invocable_v<_Args...>, _Args...>;
111
112template <bool __is_invocable, class... _Args>
113inline const bool __is_nothrow_invocable_impl = false;
114
115template <class... _Args>
116inline const bool __is_nothrow_invocable_impl<true, _Args...> = noexcept(__builtin_invoke(std::declval<_Args>()...));
117
118template <class... _Args>
119inline const bool __is_nothrow_invocable_v = __is_nothrow_invocable_impl<__is_invocable_v<_Args...>, _Args...>;
120
121template <bool __is_invocable, class _Ret, class... _Args>
122inline const bool __is_nothrow_invocable_r_impl = false;
123
124template <class _Ret, class... _Args>
125inline const bool __is_nothrow_invocable_r_impl<true, _Ret, _Args...> =
126 __is_nothrow_core_convertible_v<__invoke_result_t<_Args...>, _Ret> || is_void<_Ret>::value;
127
128template <class _Ret, class... _Args>
129inline const bool __is_nothrow_invocable_r_v =
130 __is_nothrow_invocable_r_impl<__is_nothrow_invocable_v<_Args...>, _Ret, _Args...>;
131
132#else // __has_builtin(__builtin_invoke)
133
64134template <class _DecayedFp>
65135struct __member_pointer_class_type {};
66136
......@@ -211,21 +281,21 @@ struct __nothrow_invokable_r_imp<true, false, _Ret, _Fp, _Args...> {
211281 template <class _Tp>
212282 static void __test_noexcept(_Tp) _NOEXCEPT;
213283
214#ifdef _LIBCPP_CXX03_LANG
284# ifdef _LIBCPP_CXX03_LANG
215285 static const bool value = false;
216#else
286# else
217287 static const bool value =
218288 noexcept(_ThisT::__test_noexcept<_Ret>(std::__invoke(std::declval<_Fp>(), std::declval<_Args>()...)));
219#endif
289# endif
220290};
221291
222292template <class _Ret, class _Fp, class... _Args>
223293struct __nothrow_invokable_r_imp<true, true, _Ret, _Fp, _Args...> {
224#ifdef _LIBCPP_CXX03_LANG
294# ifdef _LIBCPP_CXX03_LANG
225295 static const bool value = false;
226#else
296# else
227297 static const bool value = noexcept(std::__invoke(std::declval<_Fp>(), std::declval<_Args>()...));
228#endif
298# endif
229299};
230300
231301template <class _Ret, class _Fp, class... _Args>
......@@ -236,22 +306,6 @@ template <class _Fp, class... _Args>
236306using __nothrow_invokable _LIBCPP_NODEBUG =
237307 __nothrow_invokable_r_imp<__is_invocable<_Fp, _Args...>::value, true, void, _Fp, _Args...>;
238308
239template <class _Ret, bool = is_void<_Ret>::value>
240struct __invoke_void_return_wrapper {
241 template <class... _Args>
242 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static _Ret __call(_Args&&... __args) {
243 return std::__invoke(std::forward<_Args>(__args)...);
244 }
245};
246
247template <class _Ret>
248struct __invoke_void_return_wrapper<_Ret, true> {
249 template <class... _Args>
250 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void __call(_Args&&... __args) {
251 std::__invoke(std::forward<_Args>(__args)...);
252 }
253};
254
255309template <class _Func, class... _Args>
256310inline const bool __is_invocable_v = __is_invocable<_Func, _Args...>::value;
257311
......@@ -261,6 +315,9 @@ inline const bool __is_invocable_r_v = __invokable_r<_Ret, _Func, _Args...>::val
261315template <class _Func, class... _Args>
262316inline const bool __is_nothrow_invocable_v = __nothrow_invokable<_Func, _Args...>::value;
263317
318template <class _Ret, class _Func, class... _Args>
319inline const bool __is_nothrow_invocable_r_v = __nothrow_invokable_r<_Ret, _Func, _Args...>::value;
320
264321template <class _Func, class... _Args>
265322struct __invoke_result
266323 : enable_if<__is_invocable_v<_Func, _Args...>, typename __invokable_r<void, _Func, _Args...>::_Result> {};
......@@ -268,6 +325,24 @@ struct __invoke_result
268325template <class _Func, class... _Args>
269326using __invoke_result_t _LIBCPP_NODEBUG = typename __invoke_result<_Func, _Args...>::type;
270327
328#endif // __has_builtin(__builtin_invoke_r)
329
330template <class _Ret, bool = is_void<_Ret>::value>
331struct __invoke_void_return_wrapper {
332 template <class... _Args>
333 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static _Ret __call(_Args&&... __args) {
334 return std::__invoke(std::forward<_Args>(__args)...);
335 }
336};
337
338template <class _Ret>
339struct __invoke_void_return_wrapper<_Ret, true> {
340 template <class... _Args>
341 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void __call(_Args&&... __args) {
342 std::__invoke(std::forward<_Args>(__args)...);
343 }
344};
345
271346template <class _Ret, class... _Args>
272347_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Ret __invoke_r(_Args&&... __args) {
273348 return __invoke_void_return_wrapper<_Ret>::__call(std::forward<_Args>(__args)...);
......@@ -278,11 +353,10 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Ret __invoke_r(_Args&&... _
278353// is_invocable
279354
280355template <class _Fn, class... _Args>
281struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_invocable : bool_constant<__is_invocable_v<_Fn, _Args...>> {};
356struct _LIBCPP_NO_SPECIALIZATIONS is_invocable : bool_constant<__is_invocable_v<_Fn, _Args...> > {};
282357
283358template <class _Ret, class _Fn, class... _Args>
284struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_invocable_r
285 : bool_constant<__is_invocable_r_v<_Ret, _Fn, _Args...>> {};
359struct _LIBCPP_NO_SPECIALIZATIONS is_invocable_r : bool_constant<__is_invocable_r_v<_Ret, _Fn, _Args...>> {};
286360
287361template <class _Fn, class... _Args>
288362_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_invocable_v = __is_invocable_v<_Fn, _Args...>;
......@@ -293,27 +367,26 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_invocable_r_v = __is_invocab
293367// is_nothrow_invocable
294368
295369template <class _Fn, class... _Args>
296struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_invocable
297 : bool_constant<__nothrow_invokable<_Fn, _Args...>::value> {};
370struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_invocable : bool_constant<__is_nothrow_invocable_v<_Fn, _Args...> > {};
298371
299372template <class _Ret, class _Fn, class... _Args>
300struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_invocable_r
301 : bool_constant<__nothrow_invokable_r<_Ret, _Fn, _Args...>::value> {};
373struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_invocable_r
374 : bool_constant<__is_nothrow_invocable_r_v<_Ret, _Fn, _Args...>> {};
302375
303376template <class _Fn, class... _Args>
304_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<_Fn, _Args...>::value;
377_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_invocable_v = __is_nothrow_invocable_v<_Fn, _Args...>;
305378
306379template <class _Ret, class _Fn, class... _Args>
307380_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_invocable_r_v =
308 is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
381 __is_nothrow_invocable_r_v<_Ret, _Fn, _Args...>;
309382
310383template <class _Fn, class... _Args>
311struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS invoke_result : __invoke_result<_Fn, _Args...> {};
384struct _LIBCPP_NO_SPECIALIZATIONS invoke_result : __invoke_result<_Fn, _Args...> {};
312385
313386template <class _Fn, class... _Args>
314using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
387using invoke_result_t = __invoke_result_t<_Fn, _Args...>;
315388
316#endif // _LIBCPP_STD_VER >= 17
389#endif
317390
318391_LIBCPP_END_NAMESPACE_STD
319392
lib/libcxx/include/__type_traits/is_abstract.h+1-2
......@@ -19,8 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_abstract
23 : public integral_constant<bool, __is_abstract(_Tp)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_abstract : integral_constant<bool, __is_abstract(_Tp)> {};
2423
2524#if _LIBCPP_STD_VER >= 17
2625template <class _Tp>
lib/libcxx/include/__type_traits/is_aggregate.h+1-2
......@@ -21,8 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121#if _LIBCPP_STD_VER >= 17
2222
2323template <class _Tp>
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_aggregate
25 : public integral_constant<bool, __is_aggregate(_Tp)> {};
24struct _LIBCPP_NO_SPECIALIZATIONS is_aggregate : integral_constant<bool, __is_aggregate(_Tp)> {};
2625
2726template <class _Tp>
2827_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_aggregate_v = __is_aggregate(_Tp);
lib/libcxx/include/__type_traits/is_arithmetic.h+2-2
......@@ -21,8 +21,8 @@
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
2323template <class _Tp>
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_arithmetic
25 : public integral_constant<bool, is_integral<_Tp>::value || is_floating_point<_Tp>::value> {};
24struct _LIBCPP_NO_SPECIALIZATIONS is_arithmetic
25 : integral_constant<bool, is_integral<_Tp>::value || is_floating_point<_Tp>::value> {};
2626
2727#if _LIBCPP_STD_VER >= 17
2828template <class _Tp>
lib/libcxx/include/__type_traits/is_array.h+3-23
......@@ -10,7 +10,6 @@
1010#define _LIBCPP___TYPE_TRAITS_IS_ARRAY_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1413#include <__type_traits/integral_constant.h>
1514
1615#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -19,32 +18,13 @@
1918
2019_LIBCPP_BEGIN_NAMESPACE_STD
2120
22#if __has_builtin(__is_array) && \
23 (!defined(_LIBCPP_COMPILER_CLANG_BASED) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1900))
24
2521template <class _Tp>
26struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_array : _BoolConstant<__is_array(_Tp)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_array : _BoolConstant<__is_array(_Tp)> {};
2723
28# if _LIBCPP_STD_VER >= 17
24#if _LIBCPP_STD_VER >= 17
2925template <class _Tp>
3026_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_array_v = __is_array(_Tp);
31# endif
32
33#else
34
35template <class _Tp>
36struct _LIBCPP_TEMPLATE_VIS is_array : public false_type {};
37template <class _Tp>
38struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[]> : public true_type {};
39template <class _Tp, size_t _Np>
40struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[_Np]> : public true_type {};
41
42# if _LIBCPP_STD_VER >= 17
43template <class _Tp>
44inline constexpr bool is_array_v = is_array<_Tp>::value;
45# endif
46
47#endif // __has_builtin(__is_array)
27#endif
4828
4929_LIBCPP_END_NAMESPACE_STD
5030
lib/libcxx/include/__type_traits/is_assignable.h+6-8
......@@ -10,8 +10,7 @@
1010#define _LIBCPP___TYPE_TRAITS_IS_ASSIGNABLE_H
1111
1212#include <__config>
13#include <__type_traits/add_lvalue_reference.h>
14#include <__type_traits/add_rvalue_reference.h>
13#include <__type_traits/add_reference.h>
1514#include <__type_traits/integral_constant.h>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -21,7 +20,7 @@
2120_LIBCPP_BEGIN_NAMESPACE_STD
2221
2322template <class _Tp, class _Up>
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_assignable : _BoolConstant<__is_assignable(_Tp, _Up)> {};
23struct _LIBCPP_NO_SPECIALIZATIONS is_assignable : _BoolConstant<__is_assignable(_Tp, _Up)> {};
2524
2625#if _LIBCPP_STD_VER >= 17
2726template <class _Tp, class _Arg>
......@@ -29,9 +28,8 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_assignable_v = __is_assignab
2928#endif
3029
3130template <class _Tp>
32struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_copy_assignable
33 : public integral_constant<bool,
34 __is_assignable(__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<const _Tp>)> {};
31struct _LIBCPP_NO_SPECIALIZATIONS is_copy_assignable
32 : integral_constant<bool, __is_assignable(__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<const _Tp>)> {};
3533
3634#if _LIBCPP_STD_VER >= 17
3735template <class _Tp>
......@@ -39,8 +37,8 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_copy_assignable_v = is_copy_
3937#endif
4038
4139template <class _Tp>
42struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_move_assignable
43 : public integral_constant<bool, __is_assignable(__add_lvalue_reference_t<_Tp>, __add_rvalue_reference_t<_Tp>)> {};
40struct _LIBCPP_NO_SPECIALIZATIONS is_move_assignable
41 : integral_constant<bool, __is_assignable(__add_lvalue_reference_t<_Tp>, __add_rvalue_reference_t<_Tp>)> {};
4442
4543#if _LIBCPP_STD_VER >= 17
4644template <class _Tp>
lib/libcxx/include/__type_traits/is_base_of.h+2-4
......@@ -19,8 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Bp, class _Dp>
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_base_of
23 : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_base_of : integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
2423
2524#if _LIBCPP_STD_VER >= 17
2625template <class _Bp, class _Dp>
......@@ -31,8 +30,7 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_base_of_v = __is_base_of(_Bp
3130# if __has_builtin(__builtin_is_virtual_base_of)
3231
3332template <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)> {};
33struct _LIBCPP_NO_SPECIALIZATIONS is_virtual_base_of : bool_constant<__builtin_is_virtual_base_of(_Base, _Derived)> {};
3634
3735template <class _Base, class _Derived>
3836_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_virtual_base_of_v = __builtin_is_virtual_base_of(_Base, _Derived);
lib/libcxx/include/__type_traits/is_bounded_array.h+5-16
......@@ -10,7 +10,6 @@
1010#define _LIBCPP___TYPE_TRAITS_IS_BOUNDED_ARRAY_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1413#include <__type_traits/integral_constant.h>
1514
1615#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -19,26 +18,16 @@
1918
2019_LIBCPP_BEGIN_NAMESPACE_STD
2120
22template <class>
23inline const bool __is_bounded_array_v = false;
24template <class _Tp, size_t _Np>
25inline const bool __is_bounded_array_v<_Tp[_Np]> = true;
21template <class _Tp>
22inline const bool __is_bounded_array_v = __is_bounded_array(_Tp);
2623
2724#if _LIBCPP_STD_VER >= 20
2825
29template <class>
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
36template <class _Tp, size_t _Np>
37struct _LIBCPP_TEMPLATE_VIS is_bounded_array<_Tp[_Np]> : true_type {};
38_LIBCPP_DIAGNOSTIC_POP
26template <class _Tp>
27struct _LIBCPP_NO_SPECIALIZATIONS is_bounded_array : bool_constant<__is_bounded_array(_Tp)> {};
3928
4029template <class _Tp>
41_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_bounded_array_v = is_bounded_array<_Tp>::value;
30_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_bounded_array_v = __is_bounded_array(_Tp);
4231
4332#endif
4433
lib/libcxx/include/__type_traits/is_char_like_type.h+4-2
......@@ -12,7 +12,8 @@
1212#include <__config>
1313#include <__type_traits/conjunction.h>
1414#include <__type_traits/is_standard_layout.h>
15#include <__type_traits/is_trivial.h>
15#include <__type_traits/is_trivially_constructible.h>
16#include <__type_traits/is_trivially_copyable.h>
1617
1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1819# pragma GCC system_header
......@@ -21,7 +22,8 @@
2122_LIBCPP_BEGIN_NAMESPACE_STD
2223
2324template <class _CharT>
24using _IsCharLikeType _LIBCPP_NODEBUG = _And<is_standard_layout<_CharT>, is_trivial<_CharT> >;
25using _IsCharLikeType _LIBCPP_NODEBUG =
26 _And<is_standard_layout<_CharT>, is_trivially_default_constructible<_CharT>, is_trivially_copyable<_CharT> >;
2527
2628_LIBCPP_END_NAMESPACE_STD
2729
lib/libcxx/include/__type_traits/is_class.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_class : public integral_constant<bool, __is_class(_Tp)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_class : integral_constant<bool, __is_class(_Tp)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
lib/libcxx/include/__type_traits/is_compound.h+2-2
......@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#if __has_builtin(__is_compound)
2323
2424template <class _Tp>
25struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_compound : _BoolConstant<__is_compound(_Tp)> {};
25struct _LIBCPP_NO_SPECIALIZATIONS is_compound : _BoolConstant<__is_compound(_Tp)> {};
2626
2727# if _LIBCPP_STD_VER >= 17
2828template <class _Tp>
......@@ -32,7 +32,7 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_compound_v = __is_compound(_
3232#else // __has_builtin(__is_compound)
3333
3434template <class _Tp>
35struct _LIBCPP_TEMPLATE_VIS is_compound : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
35struct is_compound : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
3636
3737# if _LIBCPP_STD_VER >= 17
3838template <class _Tp>
lib/libcxx/include/__type_traits/is_const.h+3-19
......@@ -18,29 +18,13 @@
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
21#if __has_builtin(__is_const)
22
2321template <class _Tp>
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_const : _BoolConstant<__is_const(_Tp)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_const : _BoolConstant<__is_const(_Tp)> {};
2523
26# if _LIBCPP_STD_VER >= 17
24#if _LIBCPP_STD_VER >= 17
2725template <class _Tp>
2826_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_const_v = __is_const(_Tp);
29# endif
30
31#else
32
33template <class _Tp>
34struct _LIBCPP_TEMPLATE_VIS is_const : public false_type {};
35template <class _Tp>
36struct _LIBCPP_TEMPLATE_VIS is_const<_Tp const> : public true_type {};
37
38# if _LIBCPP_STD_VER >= 17
39template <class _Tp>
40inline constexpr bool is_const_v = is_const<_Tp>::value;
41# endif
42
43#endif // __has_builtin(__is_const)
27#endif
4428
4529_LIBCPP_END_NAMESPACE_STD
4630
lib/libcxx/include/__type_traits/is_constructible.h+7-10
......@@ -10,8 +10,7 @@
1010#define _LIBCPP___TYPE_IS_CONSTRUCTIBLE_H
1111
1212#include <__config>
13#include <__type_traits/add_lvalue_reference.h>
14#include <__type_traits/add_rvalue_reference.h>
13#include <__type_traits/add_reference.h>
1514#include <__type_traits/integral_constant.h>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -21,8 +20,7 @@
2120_LIBCPP_BEGIN_NAMESPACE_STD
2221
2322template <class _Tp, class... _Args>
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_constructible
25 : public integral_constant<bool, __is_constructible(_Tp, _Args...)> {};
23struct _LIBCPP_NO_SPECIALIZATIONS is_constructible : integral_constant<bool, __is_constructible(_Tp, _Args...)> {};
2624
2725#if _LIBCPP_STD_VER >= 17
2826template <class _Tp, class... _Args>
......@@ -30,8 +28,8 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_constructible_v = __is_const
3028#endif
3129
3230template <class _Tp>
33struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_copy_constructible
34 : public integral_constant<bool, __is_constructible(_Tp, __add_lvalue_reference_t<const _Tp>)> {};
31struct _LIBCPP_NO_SPECIALIZATIONS is_copy_constructible
32 : integral_constant<bool, __is_constructible(_Tp, __add_lvalue_reference_t<const _Tp>)> {};
3533
3634#if _LIBCPP_STD_VER >= 17
3735template <class _Tp>
......@@ -39,8 +37,8 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_copy_constructible_v = is_co
3937#endif
4038
4139template <class _Tp>
42struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_move_constructible
43 : public integral_constant<bool, __is_constructible(_Tp, __add_rvalue_reference_t<_Tp>)> {};
40struct _LIBCPP_NO_SPECIALIZATIONS is_move_constructible
41 : integral_constant<bool, __is_constructible(_Tp, __add_rvalue_reference_t<_Tp>)> {};
4442
4543#if _LIBCPP_STD_VER >= 17
4644template <class _Tp>
......@@ -48,8 +46,7 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_move_constructible_v = is_mo
4846#endif
4947
5048template <class _Tp>
51struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_default_constructible
52 : public integral_constant<bool, __is_constructible(_Tp)> {};
49struct _LIBCPP_NO_SPECIALIZATIONS is_default_constructible : integral_constant<bool, __is_constructible(_Tp)> {};
5350
5451#if _LIBCPP_STD_VER >= 17
5552template <class _Tp>
lib/libcxx/include/__type_traits/is_convertible.h+11-2
......@@ -19,14 +19,23 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _T1, class _T2>
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_convertible
23 : public integral_constant<bool, __is_convertible(_T1, _T2)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_convertible : integral_constant<bool, __is_convertible(_T1, _T2)> {};
2423
2524#if _LIBCPP_STD_VER >= 17
2625template <class _From, class _To>
2726_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_convertible_v = __is_convertible(_From, _To);
2827#endif
2928
29#if _LIBCPP_STD_VER >= 20
30
31template <class _Tp, class _Up>
32struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_convertible : bool_constant<__is_nothrow_convertible(_Tp, _Up)> {};
33
34template <class _Tp, class _Up>
35_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_convertible_v = __is_nothrow_convertible(_Tp, _Up);
36
37#endif // _LIBCPP_STD_VER >= 20
38
3039_LIBCPP_END_NAMESPACE_STD
3140
3241#endif // _LIBCPP___TYPE_TRAITS_IS_CONVERTIBLE_H
lib/libcxx/include/__type_traits/is_core_convertible.h+22-3
......@@ -24,11 +24,30 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2424// and __is_core_convertible<immovable-type,immovable-type> is true in C++17 and later.
2525
2626template <class _Tp, class _Up, class = void>
27struct __is_core_convertible : public false_type {};
27inline const bool __is_core_convertible_v = false;
2828
2929template <class _Tp, class _Up>
30struct __is_core_convertible<_Tp, _Up, decltype(static_cast<void (*)(_Up)>(0)(static_cast<_Tp (*)()>(0)()))>
31 : public true_type {};
30inline const bool
31 __is_core_convertible_v<_Tp, _Up, decltype(static_cast<void (*)(_Up)>(0)(static_cast<_Tp (*)()>(0)()))> = true;
32
33template <class _Tp, class _Up>
34using __is_core_convertible _LIBCPP_NODEBUG = integral_constant<bool, __is_core_convertible_v<_Tp, _Up> >;
35
36#if _LIBCPP_STD_VER >= 20
37
38template <class _Tp, class _Up>
39concept __core_convertible_to = __is_core_convertible_v<_Tp, _Up>;
40
41#endif // _LIBCPP_STD_VER >= 20
42
43template <class _Tp, class _Up, bool = __is_core_convertible_v<_Tp, _Up> >
44inline const bool __is_nothrow_core_convertible_v = false;
45
46#ifndef _LIBCPP_CXX03_LANG
47template <class _Tp, class _Up>
48inline const bool __is_nothrow_core_convertible_v<_Tp, _Up, true> =
49 noexcept(static_cast<void (*)(_Up) noexcept>(0)(static_cast<_Tp (*)() noexcept>(0)()));
50#endif
3251
3352_LIBCPP_END_NAMESPACE_STD
3453
lib/libcxx/include/__type_traits/is_destructible.h+8-8
......@@ -25,7 +25,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2525#if __has_builtin(__is_destructible)
2626
2727template <class _Tp>
28struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_destructible : _BoolConstant<__is_destructible(_Tp)> {};
28struct _LIBCPP_NO_SPECIALIZATIONS is_destructible : _BoolConstant<__is_destructible(_Tp)> {};
2929
3030# if _LIBCPP_STD_VER >= 17
3131template <class _Tp>
......@@ -62,28 +62,28 @@ struct __destructible_imp;
6262
6363template <class _Tp>
6464struct __destructible_imp<_Tp, false>
65 : public integral_constant<bool, __is_destructor_wellformed<__remove_all_extents_t<_Tp> >::value> {};
65 : integral_constant<bool, __is_destructor_wellformed<__remove_all_extents_t<_Tp> >::value> {};
6666
6767template <class _Tp>
68struct __destructible_imp<_Tp, true> : public true_type {};
68struct __destructible_imp<_Tp, true> : true_type {};
6969
7070template <class _Tp, bool>
7171struct __destructible_false;
7272
7373template <class _Tp>
74struct __destructible_false<_Tp, false> : public __destructible_imp<_Tp, is_reference<_Tp>::value> {};
74struct __destructible_false<_Tp, false> : __destructible_imp<_Tp, is_reference<_Tp>::value> {};
7575
7676template <class _Tp>
77struct __destructible_false<_Tp, true> : public false_type {};
77struct __destructible_false<_Tp, true> : false_type {};
7878
7979template <class _Tp>
80struct is_destructible : public __destructible_false<_Tp, is_function<_Tp>::value> {};
80struct is_destructible : __destructible_false<_Tp, is_function<_Tp>::value> {};
8181
8282template <class _Tp>
83struct is_destructible<_Tp[]> : public false_type {};
83struct is_destructible<_Tp[]> : false_type {};
8484
8585template <>
86struct is_destructible<void> : public false_type {};
86struct is_destructible<void> : false_type {};
8787
8888# if _LIBCPP_STD_VER >= 17
8989template <class _Tp>
lib/libcxx/include/__type_traits/is_empty.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_empty : public integral_constant<bool, __is_empty(_Tp)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_empty : integral_constant<bool, __is_empty(_Tp)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
lib/libcxx/include/__type_traits/is_enum.h+2-2
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_enum : public integral_constant<bool, __is_enum(_Tp)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_enum : integral_constant<bool, __is_enum(_Tp)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
......@@ -29,7 +29,7 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_enum_v = __is_enum(_Tp);
2929#if _LIBCPP_STD_VER >= 23
3030
3131template <class _Tp>
32struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_scoped_enum : bool_constant<__is_scoped_enum(_Tp)> {};
32struct _LIBCPP_NO_SPECIALIZATIONS is_scoped_enum : bool_constant<__is_scoped_enum(_Tp)> {};
3333
3434template <class _Tp>
3535_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_scoped_enum_v = __is_scoped_enum(_Tp);
lib/libcxx/include/__type_traits/is_final.h+2-2
......@@ -19,11 +19,11 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS __libcpp_is_final : public integral_constant<bool, __is_final(_Tp)> {};
22struct __libcpp_is_final : integral_constant<bool, __is_final(_Tp)> {};
2323
2424#if _LIBCPP_STD_VER >= 14
2525template <class _Tp>
26struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_final : public integral_constant<bool, __is_final(_Tp)> {};
26struct _LIBCPP_NO_SPECIALIZATIONS is_final : integral_constant<bool, __is_final(_Tp)> {};
2727#endif
2828
2929#if _LIBCPP_STD_VER >= 17
lib/libcxx/include/__type_traits/is_floating_point.h+5-6
......@@ -20,15 +20,14 @@
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
2222// clang-format off
23template <class _Tp> struct __libcpp_is_floating_point : public false_type {};
24template <> struct __libcpp_is_floating_point<float> : public true_type {};
25template <> struct __libcpp_is_floating_point<double> : public true_type {};
26template <> struct __libcpp_is_floating_point<long double> : public true_type {};
23template <class _Tp> struct __libcpp_is_floating_point : false_type {};
24template <> struct __libcpp_is_floating_point<float> : true_type {};
25template <> struct __libcpp_is_floating_point<double> : true_type {};
26template <> struct __libcpp_is_floating_point<long double> : true_type {};
2727// clang-format on
2828
2929template <class _Tp>
30struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_floating_point
31 : public __libcpp_is_floating_point<__remove_cv_t<_Tp> > {};
30struct _LIBCPP_NO_SPECIALIZATIONS is_floating_point : __libcpp_is_floating_point<__remove_cv_t<_Tp> > {};
3231
3332#if _LIBCPP_STD_VER >= 17
3433template <class _Tp>
lib/libcxx/include/__type_traits/is_function.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_function : integral_constant<bool, __is_function(_Tp)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_function : integral_constant<bool, __is_function(_Tp)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
lib/libcxx/include/__type_traits/is_fundamental.h+3-3
......@@ -23,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2323#if __has_builtin(__is_fundamental)
2424
2525template <class _Tp>
26struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_fundamental : _BoolConstant<__is_fundamental(_Tp)> {};
26struct _LIBCPP_NO_SPECIALIZATIONS is_fundamental : _BoolConstant<__is_fundamental(_Tp)> {};
2727
2828# if _LIBCPP_STD_VER >= 17
2929template <class _Tp>
......@@ -33,8 +33,8 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_fundamental_v = __is_fundame
3333#else // __has_builtin(__is_fundamental)
3434
3535template <class _Tp>
36struct _LIBCPP_TEMPLATE_VIS is_fundamental
37 : public integral_constant<bool, is_void<_Tp>::value || __is_null_pointer_v<_Tp> || is_arithmetic<_Tp>::value> {};
36struct is_fundamental
37 : integral_constant<bool, is_void<_Tp>::value || __is_null_pointer_v<_Tp> || is_arithmetic<_Tp>::value> {};
3838
3939# if _LIBCPP_STD_VER >= 17
4040template <class _Tp>
lib/libcxx/include/__type_traits/is_implicit_lifetime.h+1-2
......@@ -22,8 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222# if __has_builtin(__builtin_is_implicit_lifetime)
2323
2424template <class _Tp>
25struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_implicit_lifetime
26 : public bool_constant<__builtin_is_implicit_lifetime(_Tp)> {};
25struct _LIBCPP_NO_SPECIALIZATIONS is_implicit_lifetime : bool_constant<__builtin_is_implicit_lifetime(_Tp)> {};
2726
2827template <class _Tp>
2928_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_implicit_lifetime_v = __builtin_is_implicit_lifetime(_Tp);
lib/libcxx/include/__type_traits/is_integral.h+13-13
......@@ -19,6 +19,18 @@
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
22#if __has_builtin(__is_integral)
23
24template <class _Tp>
25struct _LIBCPP_NO_SPECIALIZATIONS is_integral : _BoolConstant<__is_integral(_Tp)> {};
26
27# if _LIBCPP_STD_VER >= 17
28template <class _Tp>
29_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_integral_v = __is_integral(_Tp);
30# endif
31
32#else
33
2234// clang-format off
2335template <class _Tp> struct __libcpp_is_integral { enum { value = 0 }; };
2436template <> struct __libcpp_is_integral<bool> { enum { value = 1 }; };
......@@ -47,20 +59,8 @@ template <> struct __libcpp_is_integral<__uint128_t> { enum { va
4759#endif
4860// clang-format on
4961
50#if __has_builtin(__is_integral)
51
52template <class _Tp>
53struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_integral : _BoolConstant<__is_integral(_Tp)> {};
54
55# if _LIBCPP_STD_VER >= 17
56template <class _Tp>
57_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_integral_v = __is_integral(_Tp);
58# endif
59
60#else
61
6262template <class _Tp>
63struct _LIBCPP_TEMPLATE_VIS is_integral : public _BoolConstant<__libcpp_is_integral<__remove_cv_t<_Tp> >::value> {};
63struct is_integral : public _BoolConstant<__libcpp_is_integral<__remove_cv_t<_Tp> >::value> {};
6464
6565# if _LIBCPP_STD_VER >= 17
6666template <class _Tp>
lib/libcxx/include/__type_traits/is_literal_type.h+2-2
......@@ -20,8 +20,8 @@ _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 _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_NO_SPECIALIZATIONS is_literal_type
24 : public integral_constant<bool, __is_literal_type(_Tp)> {};
23struct _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_NO_SPECIALIZATIONS is_literal_type
24 : integral_constant<bool, __is_literal_type(_Tp)> {};
2525
2626# if _LIBCPP_STD_VER >= 17
2727template <class _Tp>
lib/libcxx/include/__type_traits/is_member_pointer.h+3-5
......@@ -19,15 +19,13 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_member_pointer : _BoolConstant<__is_member_pointer(_Tp)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_member_pointer : _BoolConstant<__is_member_pointer(_Tp)> {};
2323
2424template <class _Tp>
25struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_member_object_pointer
26 : _BoolConstant<__is_member_object_pointer(_Tp)> {};
25struct _LIBCPP_NO_SPECIALIZATIONS is_member_object_pointer : _BoolConstant<__is_member_object_pointer(_Tp)> {};
2726
2827template <class _Tp>
29struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_member_function_pointer
30 : _BoolConstant<__is_member_function_pointer(_Tp)> {};
28struct _LIBCPP_NO_SPECIALIZATIONS is_member_function_pointer : _BoolConstant<__is_member_function_pointer(_Tp)> {};
3129
3230#if _LIBCPP_STD_VER >= 17
3331template <class _Tp>
lib/libcxx/include/__type_traits/is_nothrow_assignable.h+8-12
......@@ -10,8 +10,7 @@
1010#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_ASSIGNABLE_H
1111
1212#include <__config>
13#include <__type_traits/add_lvalue_reference.h>
14#include <__type_traits/add_rvalue_reference.h>
13#include <__type_traits/add_reference.h>
1514#include <__type_traits/integral_constant.h>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -21,8 +20,8 @@
2120_LIBCPP_BEGIN_NAMESPACE_STD
2221
2322template <class _Tp, class _Arg>
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_assignable
25 : public integral_constant<bool, __is_nothrow_assignable(_Tp, _Arg)> {};
23struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_assignable : integral_constant<bool, __is_nothrow_assignable(_Tp, _Arg)> {
24};
2625
2726#if _LIBCPP_STD_VER >= 17
2827template <class _Tp, class _Arg>
......@@ -30,10 +29,9 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_assignable_v = __is_
3029#endif
3130
3231template <class _Tp>
33struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_copy_assignable
34 : public integral_constant<
35 bool,
36 __is_nothrow_assignable(__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<const _Tp>)> {};
32struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_copy_assignable
33 : integral_constant<bool,
34 __is_nothrow_assignable(__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<const _Tp>)> {};
3735
3836#if _LIBCPP_STD_VER >= 17
3937template <class _Tp>
......@@ -41,10 +39,8 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_copy_assignable_v =
4139#endif
4240
4341template <class _Tp>
44struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_move_assignable
45 : public integral_constant<bool,
46 __is_nothrow_assignable(__add_lvalue_reference_t<_Tp>, __add_rvalue_reference_t<_Tp>)> {
47};
42struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_move_assignable
43 : integral_constant<bool, __is_nothrow_assignable(__add_lvalue_reference_t<_Tp>, __add_rvalue_reference_t<_Tp>)> {};
4844
4945#if _LIBCPP_STD_VER >= 17
5046template <class _Tp>
lib/libcxx/include/__type_traits/is_nothrow_constructible.h+9-10
......@@ -10,8 +10,7 @@
1010#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONSTRUCTIBLE_H
1111
1212#include <__config>
13#include <__type_traits/add_lvalue_reference.h>
14#include <__type_traits/add_rvalue_reference.h>
13#include <__type_traits/add_reference.h>
1514#include <__type_traits/integral_constant.h>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -21,8 +20,8 @@
2120_LIBCPP_BEGIN_NAMESPACE_STD
2221
2322template < class _Tp, class... _Args>
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_constructible
25 : public integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {};
23struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_constructible
24 : integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {};
2625
2726#if _LIBCPP_STD_VER >= 17
2827template <class _Tp, class... _Args>
......@@ -31,8 +30,8 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_constructible_v =
3130#endif
3231
3332template <class _Tp>
34struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_copy_constructible
35 : public integral_constant< bool, __is_nothrow_constructible(_Tp, __add_lvalue_reference_t<const _Tp>)> {};
33struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_copy_constructible
34 : integral_constant<bool, __is_nothrow_constructible(_Tp, __add_lvalue_reference_t<const _Tp>)> {};
3635
3736#if _LIBCPP_STD_VER >= 17
3837template <class _Tp>
......@@ -41,8 +40,8 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_copy_constructible_v
4140#endif
4241
4342template <class _Tp>
44struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_move_constructible
45 : public integral_constant<bool, __is_nothrow_constructible(_Tp, __add_rvalue_reference_t<_Tp>)> {};
43struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_move_constructible
44 : integral_constant<bool, __is_nothrow_constructible(_Tp, __add_rvalue_reference_t<_Tp>)> {};
4645
4746#if _LIBCPP_STD_VER >= 17
4847template <class _Tp>
......@@ -51,8 +50,8 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_move_constructible_v
5150#endif
5251
5352template <class _Tp>
54struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_default_constructible
55 : public integral_constant<bool, __is_nothrow_constructible(_Tp)> {};
53struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_default_constructible
54 : integral_constant<bool, __is_nothrow_constructible(_Tp)> {};
5655
5756#if _LIBCPP_STD_VER >= 17
5857template <class _Tp>
lib/libcxx/include/__type_traits/is_nothrow_convertible.h deleted-62
......@@ -1,62 +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_IS_NOTHROW_CONVERTIBLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONVERTIBLE_H
11
12#include <__config>
13#include <__type_traits/conjunction.h>
14#include <__type_traits/disjunction.h>
15#include <__type_traits/integral_constant.h>
16#include <__type_traits/is_convertible.h>
17#include <__type_traits/is_void.h>
18#include <__type_traits/lazy.h>
19#include <__utility/declval.h>
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 _LIBCPP_STD_VER >= 20
28
29# if __has_builtin(__is_nothrow_convertible)
30
31template <class _Tp, class _Up>
32struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_convertible : bool_constant<__is_nothrow_convertible(_Tp, _Up)> {};
33
34template <class _Tp, class _Up>
35_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_convertible_v = __is_nothrow_convertible(_Tp, _Up);
36
37# else // __has_builtin(__is_nothrow_convertible)
38
39template <typename _Tp>
40void __test_noexcept(_Tp) noexcept;
41
42template <typename _Fm, typename _To>
43bool_constant<noexcept(std::__test_noexcept<_To>(std::declval<_Fm>()))> __is_nothrow_convertible_test();
44
45template <typename _Fm, typename _To>
46struct __is_nothrow_convertible_helper : decltype(__is_nothrow_convertible_test<_Fm, _To>()) {};
47
48template <typename _Fm, typename _To>
49struct is_nothrow_convertible
50 : _Or<_And<is_void<_To>, is_void<_Fm>>,
51 _Lazy<_And, is_convertible<_Fm, _To>, __is_nothrow_convertible_helper<_Fm, _To> > >::type {};
52
53template <typename _Fm, typename _To>
54inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<_Fm, _To>::value;
55
56# endif // __has_builtin(__is_nothrow_convertible)
57
58#endif // _LIBCPP_STD_VER >= 20
59
60_LIBCPP_END_NAMESPACE_STD
61
62#endif // _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONVERTIBLE_H
lib/libcxx/include/__type_traits/is_nothrow_destructible.h+7-10
......@@ -24,8 +24,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2424#if __has_builtin(__is_nothrow_destructible)
2525
2626template <class _Tp>
27struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_destructible
28 : integral_constant<bool, __is_nothrow_destructible(_Tp)> {};
27struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_destructible : integral_constant<bool, __is_nothrow_destructible(_Tp)> {};
2928
3029#else
3130
......@@ -33,24 +32,22 @@ template <bool, class _Tp>
3332struct __libcpp_is_nothrow_destructible;
3433
3534template <class _Tp>
36struct __libcpp_is_nothrow_destructible<false, _Tp> : public false_type {};
35struct __libcpp_is_nothrow_destructible<false, _Tp> : false_type {};
3736
3837template <class _Tp>
39struct __libcpp_is_nothrow_destructible<true, _Tp>
40 : public integral_constant<bool, noexcept(std::declval<_Tp>().~_Tp()) > {};
38struct __libcpp_is_nothrow_destructible<true, _Tp> : integral_constant<bool, noexcept(std::declval<_Tp>().~_Tp()) > {};
4139
4240template <class _Tp>
43struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
44 : public __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp> {};
41struct is_nothrow_destructible : __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp> {};
4542
4643template <class _Tp, size_t _Ns>
47struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[_Ns]> : public is_nothrow_destructible<_Tp> {};
44struct is_nothrow_destructible<_Tp[_Ns]> : is_nothrow_destructible<_Tp> {};
4845
4946template <class _Tp>
50struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&> : public true_type {};
47struct is_nothrow_destructible<_Tp&> : true_type {};
5148
5249template <class _Tp>
53struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&&> : public true_type {};
50struct is_nothrow_destructible<_Tp&&> : true_type {};
5451
5552#endif // __has_builtin(__is_nothrow_destructible)
5653
lib/libcxx/include/__type_traits/is_null_pointer.h+1-2
......@@ -24,8 +24,7 @@ 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 _LIBCPP_NO_SPECIALIZATIONS is_null_pointer
28 : integral_constant<bool, __is_null_pointer_v<_Tp>> {};
27struct _LIBCPP_NO_SPECIALIZATIONS is_null_pointer : integral_constant<bool, __is_null_pointer_v<_Tp>> {};
2928
3029# if _LIBCPP_STD_VER >= 17
3130template <class _Tp>
lib/libcxx/include/__type_traits/is_object.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_object : _BoolConstant<__is_object(_Tp)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_object : _BoolConstant<__is_object(_Tp)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
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 _LIBCPP_NO_SPECIALIZATIONS is_pod : public integral_constant<bool, __is_pod(_Tp)> {};
22struct _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_NO_SPECIALIZATIONS is_pod : integral_constant<bool, __is_pod(_Tp)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
26_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_pod_v = __is_pod(_Tp);
26_LIBCPP_DEPRECATED_IN_CXX20 _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+1-35
......@@ -11,7 +11,6 @@
1111
1212#include <__config>
1313#include <__type_traits/integral_constant.h>
14#include <__type_traits/remove_cv.h>
1514
1615#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1716# pragma GCC system_header
......@@ -19,47 +18,14 @@
1918
2019_LIBCPP_BEGIN_NAMESPACE_STD
2120
22#if __has_builtin(__is_pointer)
23
2421template <class _Tp>
25struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_pointer : _BoolConstant<__is_pointer(_Tp)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_pointer : _BoolConstant<__is_pointer(_Tp)> {};
2623
2724# if _LIBCPP_STD_VER >= 17
2825template <class _Tp>
2926_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_pointer_v = __is_pointer(_Tp);
3027# endif
3128
32#else // __has_builtin(__is_pointer)
33
34template <class _Tp>
35struct __libcpp_is_pointer : public false_type {};
36template <class _Tp>
37struct __libcpp_is_pointer<_Tp*> : public true_type {};
38
39template <class _Tp>
40struct __libcpp_remove_objc_qualifiers {
41 typedef _Tp type;
42};
43# if _LIBCPP_HAS_OBJC_ARC
44// clang-format off
45template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __strong> { typedef _Tp type; };
46template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __weak> { typedef _Tp type; };
47template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __autoreleasing> { typedef _Tp type; };
48template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __unsafe_unretained> { typedef _Tp type; };
49// clang-format on
50# endif
51
52template <class _Tp>
53struct _LIBCPP_TEMPLATE_VIS is_pointer
54 : public __libcpp_is_pointer<typename __libcpp_remove_objc_qualifiers<__remove_cv_t<_Tp> >::type> {};
55
56# if _LIBCPP_STD_VER >= 17
57template <class _Tp>
58inline constexpr bool is_pointer_v = is_pointer<_Tp>::value;
59# endif
60
61#endif // __has_builtin(__is_pointer)
62
6329_LIBCPP_END_NAMESPACE_STD
6430
6531#endif // _LIBCPP___TYPE_TRAITS_IS_POINTER_H
lib/libcxx/include/__type_traits/is_polymorphic.h+1-2
......@@ -19,8 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_polymorphic
23 : public integral_constant<bool, __is_polymorphic(_Tp)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_polymorphic : integral_constant<bool, __is_polymorphic(_Tp)> {};
2423
2524#if _LIBCPP_STD_VER >= 17
2625template <class _Tp>
lib/libcxx/include/__type_traits/is_reference.h+7-9
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_reference : _BoolConstant<__is_reference(_Tp)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_reference : _BoolConstant<__is_reference(_Tp)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
......@@ -29,12 +29,10 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_reference_v = __is_reference
2929#if __has_builtin(__is_lvalue_reference) && __has_builtin(__is_rvalue_reference)
3030
3131template <class _Tp>
32struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_lvalue_reference : _BoolConstant<__is_lvalue_reference(_Tp)> {
33};
32struct _LIBCPP_NO_SPECIALIZATIONS is_lvalue_reference : _BoolConstant<__is_lvalue_reference(_Tp)> {};
3433
3534template <class _Tp>
36struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_rvalue_reference : _BoolConstant<__is_rvalue_reference(_Tp)> {
37};
35struct _LIBCPP_NO_SPECIALIZATIONS is_rvalue_reference : _BoolConstant<__is_rvalue_reference(_Tp)> {};
3836
3937# if _LIBCPP_STD_VER >= 17
4038template <class _Tp>
......@@ -46,14 +44,14 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_rvalue_reference_v = __is_rv
4644#else // __has_builtin(__is_lvalue_reference)
4745
4846template <class _Tp>
49struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference : public false_type {};
47struct is_lvalue_reference : false_type {};
5048template <class _Tp>
51struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference<_Tp&> : public true_type {};
49struct is_lvalue_reference<_Tp&> : true_type {};
5250
5351template <class _Tp>
54struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference : public false_type {};
52struct is_rvalue_reference : false_type {};
5553template <class _Tp>
56struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference<_Tp&&> : public true_type {};
54struct is_rvalue_reference<_Tp&&> : true_type {};
5755
5856# if _LIBCPP_STD_VER >= 17
5957template <class _Tp>
lib/libcxx/include/__type_traits/is_reference_wrapper.h+3-3
......@@ -21,11 +21,11 @@
2121_LIBCPP_BEGIN_NAMESPACE_STD
2222
2323template <class _Tp>
24struct __is_reference_wrapper_impl : public false_type {};
24struct __is_reference_wrapper_impl : false_type {};
2525template <class _Tp>
26struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {};
26struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : true_type {};
2727template <class _Tp>
28struct __is_reference_wrapper : public __is_reference_wrapper_impl<__remove_cv_t<_Tp> > {};
28struct __is_reference_wrapper : __is_reference_wrapper_impl<__remove_cv_t<_Tp> > {};
2929
3030_LIBCPP_END_NAMESPACE_STD
3131
lib/libcxx/include/__type_traits/is_referenceable.h+8-15
......@@ -10,8 +10,7 @@
1010#define _LIBCPP___TYPE_TRAITS_IS_REFERENCEABLE_H
1111
1212#include <__config>
13#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_same.h>
13#include <__type_traits/void_t.h>
1514
1615#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1716# pragma GCC system_header
......@@ -19,22 +18,16 @@
1918
2019_LIBCPP_BEGIN_NAMESPACE_STD
2120
22#if __has_builtin(__is_referenceable)
21template <class _Tp, class = void>
22inline const bool __is_referenceable_v = false;
23
2324template <class _Tp>
24struct __libcpp_is_referenceable : integral_constant<bool, __is_referenceable(_Tp)> {};
25#else
26struct __libcpp_is_referenceable_impl {
27 template <class _Tp>
28 static _Tp& __test(int);
29 template <class _Tp>
30 static false_type __test(...);
31};
25inline const bool __is_referenceable_v<_Tp, __void_t<_Tp&> > = true;
3226
27#if _LIBCPP_STD_VER >= 20
3328template <class _Tp>
34struct __libcpp_is_referenceable
35 : integral_constant<bool, _IsNotSame<decltype(__libcpp_is_referenceable_impl::__test<_Tp>(0)), false_type>::value> {
36};
37#endif // __has_builtin(__is_referenceable)
29concept __referenceable = __is_referenceable_v<_Tp>;
30#endif
3831
3932_LIBCPP_END_NAMESPACE_STD
4033
lib/libcxx/include/__type_traits/is_replaceable.h created+61
......@@ -0,0 +1,61 @@
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_REPLACEABLE_H
10#define _LIBCPP___TYPE_TRAITS_IS_REPLACEABLE_H
11
12#include <__config>
13#include <__type_traits/enable_if.h>
14#include <__type_traits/integral_constant.h>
15#include <__type_traits/is_same.h>
16#include <__type_traits/is_trivially_copyable.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24// A type is replaceable if, with `x` and `y` being different objects, `x = std::move(y)` is equivalent to:
25//
26// std::destroy_at(&x)
27// std::construct_at(&x, std::move(y))
28//
29// This allows turning a move-assignment into a sequence of destroy + move-construct, which
30// is often more efficient. This is especially relevant when the move-construct is in fact
31// part of a trivial relocation from somewhere else, in which case there is a huge win.
32//
33// Note that this requires language support in order to be really effective, but we
34// currently emulate the base template with something very conservative.
35template <class _Tp, class = void>
36struct __is_replaceable : is_trivially_copyable<_Tp> {};
37
38template <class _Tp>
39struct __is_replaceable<_Tp, __enable_if_t<is_same<_Tp, typename _Tp::__replaceable>::value> > : true_type {};
40
41template <class _Tp>
42inline const bool __is_replaceable_v = __is_replaceable<_Tp>::value;
43
44// Determines whether an allocator member of a container is replaceable.
45//
46// First, we require the allocator type to be considered replaceable. If not, then something fishy might be
47// happening. Assuming the allocator type is replaceable, we conclude replaceability of the allocator as a
48// member of the container if the allocator always compares equal (in which case propagation doesn't matter),
49// or if the allocator always propagates on assignment, which is required in order for move construction and
50// assignment to be equivalent.
51template <class _AllocatorTraits>
52struct __container_allocator_is_replaceable
53 : integral_constant<bool,
54 __is_replaceable_v<typename _AllocatorTraits::allocator_type> &&
55 (_AllocatorTraits::is_always_equal::value ||
56 (_AllocatorTraits::propagate_on_container_move_assignment::value &&
57 _AllocatorTraits::propagate_on_container_copy_assignment::value))> {};
58
59_LIBCPP_END_NAMESPACE_STD
60
61#endif // _LIBCPP___TYPE_TRAITS_IS_REPLACEABLE_H
lib/libcxx/include/__type_traits/is_same.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp, class _Up>
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_same : _BoolConstant<__is_same(_Tp, _Up)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_same : _BoolConstant<__is_same(_Tp, _Up)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp, class _Up>
lib/libcxx/include/__type_traits/is_scalar.h+5-5
......@@ -26,7 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2626#if __has_builtin(__is_scalar)
2727
2828template <class _Tp>
29struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_scalar : _BoolConstant<__is_scalar(_Tp)> {};
29struct _LIBCPP_NO_SPECIALIZATIONS is_scalar : _BoolConstant<__is_scalar(_Tp)> {};
3030
3131# if _LIBCPP_STD_VER >= 17
3232template <class _Tp>
......@@ -37,15 +37,15 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_scalar_v = __is_scalar(_Tp);
3737
3838template <class _Tp>
3939struct __is_block : false_type {};
40# if _LIBCPP_HAS_EXTENSION_BLOCKS
40# if __has_extension(blocks)
4141template <class _Rp, class... _Args>
4242struct __is_block<_Rp (^)(_Args...)> : true_type {};
4343# endif
4444
4545// clang-format off
4646template <class _Tp>
47struct _LIBCPP_TEMPLATE_VIS is_scalar
48 : public integral_constant<
47struct is_scalar
48 : integral_constant<
4949 bool, is_arithmetic<_Tp>::value ||
5050 is_member_pointer<_Tp>::value ||
5151 is_pointer<_Tp>::value ||
......@@ -55,7 +55,7 @@ struct _LIBCPP_TEMPLATE_VIS is_scalar
5555// clang-format on
5656
5757template <>
58struct _LIBCPP_TEMPLATE_VIS is_scalar<nullptr_t> : public true_type {};
58struct is_scalar<nullptr_t> : true_type {};
5959
6060# if _LIBCPP_STD_VER >= 17
6161template <class _Tp>
lib/libcxx/include/__type_traits/is_signed.h+5-12
......@@ -12,7 +12,6 @@
1212#include <__config>
1313#include <__type_traits/integral_constant.h>
1414#include <__type_traits/is_arithmetic.h>
15#include <__type_traits/is_integral.h>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1817# pragma GCC system_header
......@@ -23,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2322#if __has_builtin(__is_signed)
2423
2524template <class _Tp>
26struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_signed : _BoolConstant<__is_signed(_Tp)> {};
25struct _LIBCPP_NO_SPECIALIZATIONS is_signed : _BoolConstant<__is_signed(_Tp)> {};
2726
2827# if _LIBCPP_STD_VER >= 17
2928template <class _Tp>
......@@ -32,24 +31,18 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_signed_v = __is_signed(_Tp);
3231
3332#else // __has_builtin(__is_signed)
3433
35template <class _Tp, bool = is_integral<_Tp>::value>
36struct __libcpp_is_signed_impl : public _BoolConstant<(_Tp(-1) < _Tp(0))> {};
37
38template <class _Tp>
39struct __libcpp_is_signed_impl<_Tp, false> : public true_type {}; // floating point
40
4134template <class _Tp, bool = is_arithmetic<_Tp>::value>
42struct __libcpp_is_signed : public __libcpp_is_signed_impl<_Tp> {};
35inline constexpr bool __is_signed_v = false;
4336
4437template <class _Tp>
45struct __libcpp_is_signed<_Tp, false> : public false_type {};
38inline constexpr bool __is_signed_v<_Tp, true> = _Tp(-1) < _Tp(0);
4639
4740template <class _Tp>
48struct _LIBCPP_TEMPLATE_VIS is_signed : public __libcpp_is_signed<_Tp> {};
41struct is_signed : integral_constant<bool, __is_signed_v<_Tp>> {};
4942
5043# if _LIBCPP_STD_VER >= 17
5144template <class _Tp>
52inline constexpr bool is_signed_v = is_signed<_Tp>::value;
45inline constexpr bool is_signed_v = __is_signed_v<_Tp>;
5346# endif
5447
5548#endif // __has_builtin(__is_signed)
lib/libcxx/include/__type_traits/is_signed_integer.h deleted-35
......@@ -1,35 +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_IS_SIGNED_INTEGER_H
10#define _LIBCPP___TYPE_TRAITS_IS_SIGNED_INTEGER_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// clang-format off
22template <class _Tp> struct __libcpp_is_signed_integer : public false_type {};
23template <> struct __libcpp_is_signed_integer<signed char> : public true_type {};
24template <> struct __libcpp_is_signed_integer<signed short> : public true_type {};
25template <> struct __libcpp_is_signed_integer<signed int> : public true_type {};
26template <> struct __libcpp_is_signed_integer<signed long> : public true_type {};
27template <> struct __libcpp_is_signed_integer<signed long long> : public true_type {};
28#if _LIBCPP_HAS_INT128
29template <> struct __libcpp_is_signed_integer<__int128_t> : public true_type {};
30#endif
31// clang-format on
32
33_LIBCPP_END_NAMESPACE_STD
34
35#endif // _LIBCPP___TYPE_TRAITS_IS_SIGNED_INTEGER_H
lib/libcxx/include/__type_traits/is_standard_layout.h+1-2
......@@ -19,8 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_standard_layout
23 : public integral_constant<bool, __is_standard_layout(_Tp)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_standard_layout : integral_constant<bool, __is_standard_layout(_Tp)> {};
2423
2524#if _LIBCPP_STD_VER >= 17
2625template <class _Tp>
lib/libcxx/include/__type_traits/is_swappable.h+5-8
......@@ -11,7 +11,7 @@
1111
1212#include <__config>
1313#include <__cstddef/size_t.h>
14#include <__type_traits/add_lvalue_reference.h>
14#include <__type_traits/add_reference.h>
1515#include <__type_traits/enable_if.h>
1616#include <__type_traits/integral_constant.h>
1717#include <__type_traits/is_assignable.h>
......@@ -77,30 +77,27 @@ template <class _Tp, class _Up>
7777_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_swappable_with_v = __is_swappable_with_v<_Tp, _Up>;
7878
7979template <class _Tp, class _Up>
80struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_swappable_with
81 : bool_constant<is_swappable_with_v<_Tp, _Up>> {};
80struct _LIBCPP_NO_SPECIALIZATIONS is_swappable_with : bool_constant<is_swappable_with_v<_Tp, _Up>> {};
8281
8382template <class _Tp>
8483_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_swappable_v =
8584 is_swappable_with_v<__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<_Tp>>;
8685
8786template <class _Tp>
88struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_swappable : bool_constant<is_swappable_v<_Tp>> {};
87struct _LIBCPP_NO_SPECIALIZATIONS is_swappable : bool_constant<is_swappable_v<_Tp>> {};
8988
9089template <class _Tp, class _Up>
9190_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_swappable_with_v = __is_nothrow_swappable_with_v<_Tp, _Up>;
9291
9392template <class _Tp, class _Up>
94struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_swappable_with
95 : bool_constant<is_nothrow_swappable_with_v<_Tp, _Up>> {};
93struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_swappable_with : bool_constant<is_nothrow_swappable_with_v<_Tp, _Up>> {};
9694
9795template <class _Tp>
9896_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_swappable_v =
9997 is_nothrow_swappable_with_v<__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<_Tp>>;
10098
10199template <class _Tp>
102struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_nothrow_swappable
103 : bool_constant<is_nothrow_swappable_v<_Tp>> {};
100struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_swappable : bool_constant<is_nothrow_swappable_v<_Tp>> {};
104101
105102#endif // _LIBCPP_STD_VER >= 17
106103
lib/libcxx/include/__type_traits/is_trivial.h+5-2
......@@ -19,11 +19,14 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivial : public integral_constant<bool, __is_trivial(_Tp)> {
23};
22struct _LIBCPP_DEPRECATED_IN_CXX26_(
23 "Consider using is_trivially_copyable<T>::value && is_trivially_default_constructible<T>::value instead.")
24 _LIBCPP_NO_SPECIALIZATIONS is_trivial : integral_constant<bool, __is_trivial(_Tp)> {};
2425
2526#if _LIBCPP_STD_VER >= 17
2627template <class _Tp>
28_LIBCPP_DEPRECATED_IN_CXX26_(
29 "Consider using is_trivially_copyable_v<T> && is_trivially_default_constructible_v<T> instead.")
2730_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_trivial_v = __is_trivial(_Tp);
2831#endif
2932
lib/libcxx/include/__type_traits/is_trivially_assignable.h+6-8
......@@ -10,8 +10,7 @@
1010#define _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_ASSIGNABLE_H
1111
1212#include <__config>
13#include <__type_traits/add_lvalue_reference.h>
14#include <__type_traits/add_rvalue_reference.h>
13#include <__type_traits/add_reference.h>
1514#include <__type_traits/integral_constant.h>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -30,8 +29,8 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_trivially_assignable_v = __i
3029#endif
3130
3231template <class _Tp>
33struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivially_copy_assignable
34 : public integral_constant<
32struct _LIBCPP_NO_SPECIALIZATIONS is_trivially_copy_assignable
33 : integral_constant<
3534 bool,
3635 __is_trivially_assignable(__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<const _Tp>)> {};
3736
......@@ -42,10 +41,9 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_trivially_copy_assignable_v
4241#endif
4342
4443template <class _Tp>
45struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivially_move_assignable
46 : public integral_constant<
47 bool,
48 __is_trivially_assignable(__add_lvalue_reference_t<_Tp>, __add_rvalue_reference_t<_Tp>)> {};
44struct _LIBCPP_NO_SPECIALIZATIONS is_trivially_move_assignable
45 : integral_constant<bool, __is_trivially_assignable(__add_lvalue_reference_t<_Tp>, __add_rvalue_reference_t<_Tp>)> {
46};
4947
5048#if _LIBCPP_STD_VER >= 17
5149template <class _Tp>
lib/libcxx/include/__type_traits/is_trivially_constructible.h+8-9
......@@ -10,8 +10,7 @@
1010#define _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_CONSTRUCTIBLE_H
1111
1212#include <__config>
13#include <__type_traits/add_lvalue_reference.h>
14#include <__type_traits/add_rvalue_reference.h>
13#include <__type_traits/add_reference.h>
1514#include <__type_traits/integral_constant.h>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -21,7 +20,7 @@
2120_LIBCPP_BEGIN_NAMESPACE_STD
2221
2322template <class _Tp, class... _Args>
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivially_constructible
23struct _LIBCPP_NO_SPECIALIZATIONS is_trivially_constructible
2524 : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)> {};
2625
2726#if _LIBCPP_STD_VER >= 17
......@@ -31,8 +30,8 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_trivially_constructible_v =
3130#endif
3231
3332template <class _Tp>
34struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivially_copy_constructible
35 : public integral_constant<bool, __is_trivially_constructible(_Tp, __add_lvalue_reference_t<const _Tp>)> {};
33struct _LIBCPP_NO_SPECIALIZATIONS is_trivially_copy_constructible
34 : integral_constant<bool, __is_trivially_constructible(_Tp, __add_lvalue_reference_t<const _Tp>)> {};
3635
3736#if _LIBCPP_STD_VER >= 17
3837template <class _Tp>
......@@ -41,8 +40,8 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_trivially_copy_constructible
4140#endif
4241
4342template <class _Tp>
44struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivially_move_constructible
45 : public integral_constant<bool, __is_trivially_constructible(_Tp, __add_rvalue_reference_t<_Tp>)> {};
43struct _LIBCPP_NO_SPECIALIZATIONS is_trivially_move_constructible
44 : integral_constant<bool, __is_trivially_constructible(_Tp, __add_rvalue_reference_t<_Tp>)> {};
4645
4746#if _LIBCPP_STD_VER >= 17
4847template <class _Tp>
......@@ -51,8 +50,8 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_trivially_move_constructible
5150#endif
5251
5352template <class _Tp>
54struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivially_default_constructible
55 : public integral_constant<bool, __is_trivially_constructible(_Tp)> {};
53struct _LIBCPP_NO_SPECIALIZATIONS is_trivially_default_constructible
54 : integral_constant<bool, __is_trivially_constructible(_Tp)> {};
5655
5756#if _LIBCPP_STD_VER >= 17
5857template <class _Tp>
lib/libcxx/include/__type_traits/is_trivially_copyable.h+1-2
......@@ -20,8 +20,7 @@
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
2222template <class _Tp>
23struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivially_copyable
24 : public integral_constant<bool, __is_trivially_copyable(_Tp)> {};
23struct _LIBCPP_NO_SPECIALIZATIONS is_trivially_copyable : integral_constant<bool, __is_trivially_copyable(_Tp)> {};
2524
2625#if _LIBCPP_STD_VER >= 17
2726template <class _Tp>
lib/libcxx/include/__type_traits/is_trivially_destructible.h+4-4
......@@ -22,14 +22,14 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222#if __has_builtin(__is_trivially_destructible)
2323
2424template <class _Tp>
25struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_trivially_destructible
26 : public integral_constant<bool, __is_trivially_destructible(_Tp)> {};
25struct _LIBCPP_NO_SPECIALIZATIONS is_trivially_destructible
26 : integral_constant<bool, __is_trivially_destructible(_Tp)> {};
2727
2828#elif __has_builtin(__has_trivial_destructor)
2929
3030template <class _Tp>
31struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
32 : public integral_constant<bool, is_destructible<_Tp>::value&& __has_trivial_destructor(_Tp)> {};
31struct is_trivially_destructible
32 : integral_constant<bool, is_destructible<_Tp>::value&& __has_trivial_destructor(_Tp)> {};
3333
3434#else
3535
lib/libcxx/include/__type_traits/is_unbounded_array.h+2-10
......@@ -25,19 +25,11 @@ inline const bool __is_unbounded_array_v<_Tp[]> = true;
2525
2626#if _LIBCPP_STD_VER >= 20
2727
28template <class>
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
3528template <class _Tp>
36struct _LIBCPP_TEMPLATE_VIS is_unbounded_array<_Tp[]> : true_type {};
37_LIBCPP_DIAGNOSTIC_POP
29struct _LIBCPP_NO_SPECIALIZATIONS is_unbounded_array : bool_constant<__is_unbounded_array_v<_Tp>> {};
3830
3931template <class _Tp>
40_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_unbounded_array_v = is_unbounded_array<_Tp>::value;
32_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_unbounded_array_v = __is_unbounded_array_v<_Tp>;
4133
4234#endif
4335
lib/libcxx/include/__type_traits/is_union.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_union : public integral_constant<bool, __is_union(_Tp)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_union : integral_constant<bool, __is_union(_Tp)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
lib/libcxx/include/__type_traits/is_unsigned.h+5-12
......@@ -11,7 +11,6 @@
1111
1212#include <__config>
1313#include <__type_traits/integral_constant.h>
14#include <__type_traits/is_arithmetic.h>
1514#include <__type_traits/is_integral.h>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -23,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2322#if __has_builtin(__is_unsigned)
2423
2524template <class _Tp>
26struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_unsigned : _BoolConstant<__is_unsigned(_Tp)> {};
25struct _LIBCPP_NO_SPECIALIZATIONS is_unsigned : _BoolConstant<__is_unsigned(_Tp)> {};
2726
2827# if _LIBCPP_STD_VER >= 17
2928template <class _Tp>
......@@ -33,23 +32,17 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_unsigned_v = __is_unsigned(_
3332#else // __has_builtin(__is_unsigned)
3433
3534template <class _Tp, bool = is_integral<_Tp>::value>
36struct __libcpp_is_unsigned_impl : public _BoolConstant<(_Tp(0) < _Tp(-1))> {};
35inline constexpr bool __is_unsigned_v = false;
3736
3837template <class _Tp>
39struct __libcpp_is_unsigned_impl<_Tp, false> : public false_type {}; // floating point
40
41template <class _Tp, bool = is_arithmetic<_Tp>::value>
42struct __libcpp_is_unsigned : public __libcpp_is_unsigned_impl<_Tp> {};
43
44template <class _Tp>
45struct __libcpp_is_unsigned<_Tp, false> : public false_type {};
38inline constexpr bool __is_unsigned_v<_Tp, true> = _Tp(0) < _Tp(-1);
4639
4740template <class _Tp>
48struct _LIBCPP_TEMPLATE_VIS is_unsigned : public __libcpp_is_unsigned<_Tp> {};
41struct is_unsigned : integral_constant<bool, __is_unsigned_v<_Tp>> {};
4942
5043# if _LIBCPP_STD_VER >= 17
5144template <class _Tp>
52inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;
45inline constexpr bool is_unsigned_v = __is_unsigned_v<_Tp>;
5346# endif
5447
5548#endif // __has_builtin(__is_unsigned)
lib/libcxx/include/__type_traits/is_unsigned_integer.h deleted-35
......@@ -1,35 +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_IS_UNSIGNED_INTEGER_H
10#define _LIBCPP___TYPE_TRAITS_IS_UNSIGNED_INTEGER_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// clang-format off
22template <class _Tp> struct __libcpp_is_unsigned_integer : public false_type {};
23template <> struct __libcpp_is_unsigned_integer<unsigned char> : public true_type {};
24template <> struct __libcpp_is_unsigned_integer<unsigned short> : public true_type {};
25template <> struct __libcpp_is_unsigned_integer<unsigned int> : public true_type {};
26template <> struct __libcpp_is_unsigned_integer<unsigned long> : public true_type {};
27template <> struct __libcpp_is_unsigned_integer<unsigned long long> : public true_type {};
28#if _LIBCPP_HAS_INT128
29template <> struct __libcpp_is_unsigned_integer<__uint128_t> : public true_type {};
30#endif
31// clang-format on
32
33_LIBCPP_END_NAMESPACE_STD
34
35#endif // _LIBCPP___TYPE_TRAITS_IS_UNSIGNED_INTEGER_H
lib/libcxx/include/__type_traits/is_void.h+1-1
......@@ -19,7 +19,7 @@
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
2121template <class _Tp>
22struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_void : _BoolConstant<__is_same(__remove_cv(_Tp), void)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_void : _BoolConstant<__is_same(__remove_cv(_Tp), void)> {};
2323
2424#if _LIBCPP_STD_VER >= 17
2525template <class _Tp>
lib/libcxx/include/__type_traits/is_volatile.h+3-19
......@@ -18,29 +18,13 @@
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
21#if __has_builtin(__is_volatile)
22
2321template <class _Tp>
24struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS is_volatile : _BoolConstant<__is_volatile(_Tp)> {};
22struct _LIBCPP_NO_SPECIALIZATIONS is_volatile : _BoolConstant<__is_volatile(_Tp)> {};
2523
26# if _LIBCPP_STD_VER >= 17
24#if _LIBCPP_STD_VER >= 17
2725template <class _Tp>
2826_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_volatile_v = __is_volatile(_Tp);
29# endif
30
31#else
32
33template <class _Tp>
34struct _LIBCPP_TEMPLATE_VIS is_volatile : public false_type {};
35template <class _Tp>
36struct _LIBCPP_TEMPLATE_VIS is_volatile<_Tp volatile> : public true_type {};
37
38# if _LIBCPP_STD_VER >= 17
39template <class _Tp>
40inline constexpr bool is_volatile_v = is_volatile<_Tp>::value;
41# endif
42
43#endif // __has_builtin(__is_volatile)
27#endif
4428
4529_LIBCPP_END_NAMESPACE_STD
4630
lib/libcxx/include/__type_traits/promote.h+16-20
......@@ -10,7 +10,7 @@
1010#define _LIBCPP___TYPE_TRAITS_PROMOTE_H
1111
1212#include <__config>
13#include <__type_traits/integral_constant.h>
13#include <__type_traits/enable_if.h>
1414#include <__type_traits/is_arithmetic.h>
1515
1616#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -19,28 +19,24 @@
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
22template <class... _Args>
23class __promote {
24 static_assert((is_arithmetic<_Args>::value && ...));
25
26 static float __test(float);
27 static double __test(char);
28 static double __test(int);
29 static double __test(unsigned);
30 static double __test(long);
31 static double __test(unsigned long);
32 static double __test(long long);
33 static double __test(unsigned long long);
22float __promote_impl(float);
23double __promote_impl(char);
24double __promote_impl(int);
25double __promote_impl(unsigned);
26double __promote_impl(long);
27double __promote_impl(unsigned long);
28double __promote_impl(long long);
29double __promote_impl(unsigned long long);
3430#if _LIBCPP_HAS_INT128
35 static double __test(__int128_t);
36 static double __test(__uint128_t);
31double __promote_impl(__int128_t);
32double __promote_impl(__uint128_t);
3733#endif
38 static double __test(double);
39 static long double __test(long double);
34double __promote_impl(double);
35long double __promote_impl(long double);
4036
41public:
42 using type = decltype((__test(_Args()) + ...));
43};
37template <class... _Args>
38using __promote_t _LIBCPP_NODEBUG =
39 decltype((__enable_if_t<(is_arithmetic<_Args>::value && ...)>)0, (std::__promote_impl(_Args()) + ...));
4440
4541_LIBCPP_END_NAMESPACE_STD
4642
lib/libcxx/include/__type_traits/rank.h+6-6
......@@ -19,25 +19,25 @@
1919
2020_LIBCPP_BEGIN_NAMESPACE_STD
2121
22// TODO: Enable using the builtin __array_rank when https://llvm.org/PR57133 is resolved
23#if __has_builtin(__array_rank) && 0
22#if __has_builtin(__array_rank) && !defined(_LIBCPP_COMPILER_CLANG_BASED) || \
23 (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 2001)
2424
2525template <class _Tp>
26struct rank : integral_constant<size_t, __array_rank(_Tp)> {};
26struct _LIBCPP_NO_SPECIALIZATIONS rank : integral_constant<size_t, __array_rank(_Tp)> {};
2727
2828#else
2929
3030template <class _Tp>
31struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS rank : public integral_constant<size_t, 0> {};
31struct _LIBCPP_NO_SPECIALIZATIONS rank : public integral_constant<size_t, 0> {};
3232
3333_LIBCPP_DIAGNOSTIC_PUSH
3434# if __has_warning("-Winvalid-specialization")
3535_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
3636# endif
3737template <class _Tp>
38struct _LIBCPP_TEMPLATE_VIS rank<_Tp[]> : public integral_constant<size_t, rank<_Tp>::value + 1> {};
38struct rank<_Tp[]> : public integral_constant<size_t, rank<_Tp>::value + 1> {};
3939template <class _Tp, size_t _Np>
40struct _LIBCPP_TEMPLATE_VIS rank<_Tp[_Np]> : public integral_constant<size_t, rank<_Tp>::value + 1> {};
40struct rank<_Tp[_Np]> : public integral_constant<size_t, rank<_Tp>::value + 1> {};
4141_LIBCPP_DIAGNOSTIC_POP
4242
4343#endif // __has_builtin(__array_rank)
lib/libcxx/include/__type_traits/reference_constructs_from_temporary.h created+44
......@@ -0,0 +1,44 @@
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_REFERENCE_CONSTRUCTS_FROM_TEMPORARY_H
10#define _LIBCPP___TYPE_TRAITS_REFERENCE_CONSTRUCTS_FROM_TEMPORARY_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 && __has_builtin(__reference_constructs_from_temporary)
22
23template <class _Tp, class _Up>
24struct _LIBCPP_NO_SPECIALIZATIONS reference_constructs_from_temporary
25 : public bool_constant<__reference_constructs_from_temporary(_Tp, _Up)> {};
26
27template <class _Tp, class _Up>
28_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool reference_constructs_from_temporary_v =
29 __reference_constructs_from_temporary(_Tp, _Up);
30
31#endif
32
33#if __has_builtin(__reference_constructs_from_temporary)
34template <class _Tp, class _Up>
35inline const bool __reference_constructs_from_temporary_v = __reference_constructs_from_temporary(_Tp, _Up);
36#else
37// TODO(LLVM 22): Remove this as all supported compilers should have __reference_constructs_from_temporary implemented.
38template <class _Tp, class _Up>
39inline const bool __reference_constructs_from_temporary_v = __reference_binds_to_temporary(_Tp, _Up);
40#endif
41
42_LIBCPP_END_NAMESPACE_STD
43
44#endif // _LIBCPP___TYPE_TRAITS_REFERENCE_CONSTRUCTS_FROM_TEMPORARY_H
lib/libcxx/include/__type_traits/reference_converts_from_temporary.h created+35
......@@ -0,0 +1,35 @@
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_REFERENCE_CONVERTS_FROM_TEMPORARY_H
10#define _LIBCPP___TYPE_TRAITS_REFERENCE_CONVERTS_FROM_TEMPORARY_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 && __has_builtin(__reference_converts_from_temporary)
22
23template <class _Tp, class _Up>
24struct _LIBCPP_NO_SPECIALIZATIONS reference_converts_from_temporary
25 : public bool_constant<__reference_converts_from_temporary(_Tp, _Up)> {};
26
27template <class _Tp, class _Up>
28_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool reference_converts_from_temporary_v =
29 __reference_converts_from_temporary(_Tp, _Up);
30
31#endif
32
33_LIBCPP_END_NAMESPACE_STD
34
35#endif // _LIBCPP___TYPE_TRAITS_REFERENCE_CONVERTS_FROM_TEMPORARY_H
lib/libcxx/include/__type_traits/remove_all_extents.h+4-18
......@@ -10,7 +10,6 @@
1010#define _LIBCPP___TYPE_TRAITS_REMOVE_ALL_EXTENTS_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1413
1514#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1615# pragma GCC system_header
......@@ -18,31 +17,18 @@
1817
1918_LIBCPP_BEGIN_NAMESPACE_STD
2019
21#if __has_builtin(__remove_all_extents)
2220template <class _Tp>
2321struct _LIBCPP_NO_SPECIALIZATIONS remove_all_extents {
2422 using type _LIBCPP_NODEBUG = __remove_all_extents(_Tp);
2523};
2624
25#ifdef _LIBCPP_COMPILER_GCC
2726template <class _Tp>
28using __remove_all_extents_t _LIBCPP_NODEBUG = __remove_all_extents(_Tp);
27using __remove_all_extents_t _LIBCPP_NODEBUG = typename remove_all_extents<_Tp>::type;
2928#else
3029template <class _Tp>
31struct _LIBCPP_TEMPLATE_VIS remove_all_extents {
32 typedef _Tp type;
33};
34template <class _Tp>
35struct _LIBCPP_TEMPLATE_VIS remove_all_extents<_Tp[]> {
36 typedef typename remove_all_extents<_Tp>::type type;
37};
38template <class _Tp, size_t _Np>
39struct _LIBCPP_TEMPLATE_VIS remove_all_extents<_Tp[_Np]> {
40 typedef typename remove_all_extents<_Tp>::type type;
41};
42
43template <class _Tp>
44using __remove_all_extents_t = typename remove_all_extents<_Tp>::type;
45#endif // __has_builtin(__remove_all_extents)
30using __remove_all_extents_t _LIBCPP_NODEBUG = __remove_all_extents(_Tp);
31#endif
4632
4733#if _LIBCPP_STD_VER >= 14
4834template <class _Tp>
lib/libcxx/include/__type_traits/remove_const.h+2-2
......@@ -27,11 +27,11 @@ template <class _Tp>
2727using __remove_const_t _LIBCPP_NODEBUG = __remove_const(_Tp);
2828#else
2929template <class _Tp>
30struct _LIBCPP_TEMPLATE_VIS remove_const {
30struct remove_const {
3131 typedef _Tp type;
3232};
3333template <class _Tp>
34struct _LIBCPP_TEMPLATE_VIS remove_const<const _Tp> {
34struct remove_const<const _Tp> {
3535 typedef _Tp type;
3636};
3737
lib/libcxx/include/__type_traits/remove_cvref.h-4
......@@ -10,7 +10,6 @@
1010#define _LIBCPP___TYPE_TRAITS_REMOVE_CVREF_H
1111
1212#include <__config>
13#include <__type_traits/is_same.h>
1413
1514#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1615# pragma GCC system_header
......@@ -31,9 +30,6 @@ template <class _Tp>
3130using __remove_cvref_t _LIBCPP_NODEBUG = __remove_cvref(_Tp);
3231#endif // __has_builtin(__remove_cvref)
3332
34template <class _Tp, class _Up>
35using __is_same_uncvref _LIBCPP_NODEBUG = _IsSame<__remove_cvref_t<_Tp>, __remove_cvref_t<_Up> >;
36
3733#if _LIBCPP_STD_VER >= 20
3834template <class _Tp>
3935struct _LIBCPP_NO_SPECIALIZATIONS remove_cvref {
lib/libcxx/include/__type_traits/remove_extent.h+4-18
......@@ -10,7 +10,6 @@
1010#define _LIBCPP___TYPE_TRAITS_REMOVE_EXTENT_H
1111
1212#include <__config>
13#include <__cstddef/size_t.h>
1413
1514#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1615# pragma GCC system_header
......@@ -18,31 +17,18 @@
1817
1918_LIBCPP_BEGIN_NAMESPACE_STD
2019
21#if __has_builtin(__remove_extent)
2220template <class _Tp>
2321struct _LIBCPP_NO_SPECIALIZATIONS remove_extent {
2422 using type _LIBCPP_NODEBUG = __remove_extent(_Tp);
2523};
2624
25#ifdef _LIBCPP_COMPILER_GCC
2726template <class _Tp>
28using __remove_extent_t _LIBCPP_NODEBUG = __remove_extent(_Tp);
27using __remove_extent_t _LIBCPP_NODEBUG = typename remove_extent<_Tp>::type;
2928#else
3029template <class _Tp>
31struct _LIBCPP_TEMPLATE_VIS remove_extent {
32 typedef _Tp type;
33};
34template <class _Tp>
35struct _LIBCPP_TEMPLATE_VIS remove_extent<_Tp[]> {
36 typedef _Tp type;
37};
38template <class _Tp, size_t _Np>
39struct _LIBCPP_TEMPLATE_VIS remove_extent<_Tp[_Np]> {
40 typedef _Tp type;
41};
42
43template <class _Tp>
44using __remove_extent_t = typename remove_extent<_Tp>::type;
45#endif // __has_builtin(__remove_extent)
30using __remove_extent_t _LIBCPP_NODEBUG = __remove_extent(_Tp);
31#endif
4632
4733#if _LIBCPP_STD_VER >= 14
4834template <class _Tp>
lib/libcxx/include/__type_traits/remove_pointer.h+5-5
......@@ -32,11 +32,11 @@ using __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 {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;};
35template <class _Tp> struct remove_pointer {using type _LIBCPP_NODEBUG = _Tp;};
36template <class _Tp> struct remove_pointer<_Tp*> {using type _LIBCPP_NODEBUG = _Tp;};
37template <class _Tp> struct remove_pointer<_Tp* const> {using type _LIBCPP_NODEBUG = _Tp;};
38template <class _Tp> struct remove_pointer<_Tp* volatile> {using type _LIBCPP_NODEBUG = _Tp;};
39template <class _Tp> struct remove_pointer<_Tp* const volatile> {using type _LIBCPP_NODEBUG = _Tp;};
4040// clang-format on
4141
4242template <class _Tp>
lib/libcxx/include/__type_traits/remove_volatile.h+2-2
......@@ -27,11 +27,11 @@ template <class _Tp>
2727using __remove_volatile_t _LIBCPP_NODEBUG = __remove_volatile(_Tp);
2828#else
2929template <class _Tp>
30struct _LIBCPP_TEMPLATE_VIS remove_volatile {
30struct remove_volatile {
3131 typedef _Tp type;
3232};
3333template <class _Tp>
34struct _LIBCPP_TEMPLATE_VIS remove_volatile<volatile _Tp> {
34struct remove_volatile<volatile _Tp> {
3535 typedef _Tp type;
3636};
3737
lib/libcxx/include/__type_traits/result_of.h+1-1
......@@ -29,7 +29,7 @@ _LIBCPP_DIAGNOSTIC_PUSH
2929_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
3030#endif
3131template <class _Fp, class... _Args>
32struct _LIBCPP_TEMPLATE_VIS result_of<_Fp(_Args...)> : __invoke_result<_Fp, _Args...> {};
32struct result_of<_Fp(_Args...)> : __invoke_result<_Fp, _Args...> {};
3333_LIBCPP_DIAGNOSTIC_POP
3434
3535# if _LIBCPP_STD_VER >= 14
lib/libcxx/include/__type_traits/strip_signature.h+18-18
......@@ -26,52 +26,52 @@ struct __strip_signature;
2626
2727template <class _Rp, class... _Args>
2828struct __strip_signature<_Rp (*)(_Args...)> {
29 using type = _Rp(_Args...);
29 using type _LIBCPP_NODEBUG = _Rp(_Args...);
3030};
3131
3232template <class _Rp, class... _Args>
3333struct __strip_signature<_Rp (*)(_Args...) noexcept> {
34 using type = _Rp(_Args...);
34 using type _LIBCPP_NODEBUG = _Rp(_Args...);
3535};
3636
3737# endif // defined(__cpp_static_call_operator) && __cpp_static_call_operator >= 202207L
3838
3939// clang-format off
4040template<class _Rp, class _Gp, class ..._Ap>
41struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); };
41struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
4242template<class _Rp, class _Gp, class ..._Ap>
43struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); };
43struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
4444template<class _Rp, class _Gp, class ..._Ap>
45struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); };
45struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
4646template<class _Rp, class _Gp, class ..._Ap>
47struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); };
47struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
4848
4949template<class _Rp, class _Gp, class ..._Ap>
50struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); };
50struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
5151template<class _Rp, class _Gp, class ..._Ap>
52struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); };
52struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
5353template<class _Rp, class _Gp, class ..._Ap>
54struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); };
54struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
5555template<class _Rp, class _Gp, class ..._Ap>
56struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); };
56struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
5757
5858template<class _Rp, class _Gp, class ..._Ap>
59struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); };
59struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
6060template<class _Rp, class _Gp, class ..._Ap>
61struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); };
61struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
6262template<class _Rp, class _Gp, class ..._Ap>
63struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); };
63struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
6464template<class _Rp, class _Gp, class ..._Ap>
65struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); };
65struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
6666
6767template<class _Rp, class _Gp, class ..._Ap>
68struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); };
68struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
6969template<class _Rp, class _Gp, class ..._Ap>
70struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); };
70struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
7171template<class _Rp, class _Gp, class ..._Ap>
72struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); };
72struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
7373template<class _Rp, class _Gp, class ..._Ap>
74struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); };
74struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type _LIBCPP_NODEBUG = _Rp(_Ap...); };
7575// clang-format on
7676
7777_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__type_traits/underlying_type.h+11-2
......@@ -18,7 +18,7 @@
1818
1919_LIBCPP_BEGIN_NAMESPACE_STD
2020
21template <class _Tp, bool = is_enum<_Tp>::value>
21template <class _Tp, bool>
2222struct __underlying_type_impl;
2323
2424template <class _Tp>
......@@ -32,9 +32,18 @@ struct __underlying_type_impl<_Tp, true> {
3232template <class _Tp>
3333struct _LIBCPP_NO_SPECIALIZATIONS underlying_type : __underlying_type_impl<_Tp, is_enum<_Tp>::value> {};
3434
35// GCC doesn't SFINAE away when using __underlying_type directly
36#if !defined(_LIBCPP_COMPILER_GCC)
37template <class _Tp>
38using __underlying_type_t _LIBCPP_NODEBUG = __underlying_type(_Tp);
39#else
40template <class _Tp>
41using __underlying_type_t _LIBCPP_NODEBUG = typename underlying_type<_Tp>::type;
42#endif
43
3544#if _LIBCPP_STD_VER >= 14
3645template <class _Tp>
37using underlying_type_t = typename underlying_type<_Tp>::type;
46using underlying_type_t = __underlying_type_t<_Tp>;
3847#endif
3948
4049_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__utility/cmp.h+8-8
......@@ -9,8 +9,8 @@
99#ifndef _LIBCPP___UTILITY_CMP_H
1010#define _LIBCPP___UTILITY_CMP_H
1111
12#include <__concepts/arithmetic.h>
1312#include <__config>
13#include <__type_traits/integer_traits.h>
1414#include <__type_traits/is_signed.h>
1515#include <__type_traits/make_unsigned.h>
1616#include <limits>
......@@ -26,7 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2626
2727#if _LIBCPP_STD_VER >= 20
2828
29template <__libcpp_integer _Tp, __libcpp_integer _Up>
29template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up>
3030_LIBCPP_HIDE_FROM_ABI constexpr bool cmp_equal(_Tp __t, _Up __u) noexcept {
3131 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
3232 return __t == __u;
......@@ -36,12 +36,12 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_equal(_Tp __t, _Up __u) noexcept {
3636 return __u < 0 ? false : __t == make_unsigned_t<_Up>(__u);
3737}
3838
39template <__libcpp_integer _Tp, __libcpp_integer _Up>
39template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up>
4040_LIBCPP_HIDE_FROM_ABI constexpr bool cmp_not_equal(_Tp __t, _Up __u) noexcept {
4141 return !std::cmp_equal(__t, __u);
4242}
4343
44template <__libcpp_integer _Tp, __libcpp_integer _Up>
44template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up>
4545_LIBCPP_HIDE_FROM_ABI constexpr bool cmp_less(_Tp __t, _Up __u) noexcept {
4646 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
4747 return __t < __u;
......@@ -51,22 +51,22 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_less(_Tp __t, _Up __u) noexcept {
5151 return __u < 0 ? false : __t < make_unsigned_t<_Up>(__u);
5252}
5353
54template <__libcpp_integer _Tp, __libcpp_integer _Up>
54template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up>
5555_LIBCPP_HIDE_FROM_ABI constexpr bool cmp_greater(_Tp __t, _Up __u) noexcept {
5656 return std::cmp_less(__u, __t);
5757}
5858
59template <__libcpp_integer _Tp, __libcpp_integer _Up>
59template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up>
6060_LIBCPP_HIDE_FROM_ABI constexpr bool cmp_less_equal(_Tp __t, _Up __u) noexcept {
6161 return !std::cmp_greater(__t, __u);
6262}
6363
64template <__libcpp_integer _Tp, __libcpp_integer _Up>
64template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up>
6565_LIBCPP_HIDE_FROM_ABI constexpr bool cmp_greater_equal(_Tp __t, _Up __u) noexcept {
6666 return !std::cmp_less(__t, __u);
6767}
6868
69template <__libcpp_integer _Tp, __libcpp_integer _Up>
69template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up>
7070_LIBCPP_HIDE_FROM_ABI constexpr bool in_range(_Up __u) noexcept {
7171 return std::cmp_less_equal(__u, numeric_limits<_Tp>::max()) &&
7272 std::cmp_greater_equal(__u, numeric_limits<_Tp>::min());
lib/libcxx/include/__utility/convert_to_integral.h+1-1
......@@ -50,7 +50,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __uint128_t __convert_to_integral
5050
5151template <class _Tp, bool = is_enum<_Tp>::value>
5252struct __sfinae_underlying_type {
53 typedef typename underlying_type<_Tp>::type type;
53 using type = __underlying_type_t<_Tp>;
5454 typedef decltype(((type)1) + 0) __promoted_type;
5555};
5656
lib/libcxx/include/__utility/exception_guard.h+3-4
......@@ -6,13 +6,12 @@
66//
77//===----------------------------------------------------------------------===//
88
9#ifndef _LIBCPP___UTILITY_TRANSACTION_H
10#define _LIBCPP___UTILITY_TRANSACTION_H
9#ifndef _LIBCPP___UTILITY_EXCEPTION_GUARD_H
10#define _LIBCPP___UTILITY_EXCEPTION_GUARD_H
1111
1212#include <__assert>
1313#include <__config>
1414#include <__type_traits/is_nothrow_constructible.h>
15#include <__utility/exchange.h>
1615#include <__utility/move.h>
1716
1817#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -141,4 +140,4 @@ _LIBCPP_END_NAMESPACE_STD
141140
142141_LIBCPP_POP_MACROS
143142
144#endif // _LIBCPP___UTILITY_TRANSACTION_H
143#endif // _LIBCPP___UTILITY_EXCEPTION_GUARD_H
lib/libcxx/include/__utility/in_place.h+2-2
......@@ -28,14 +28,14 @@ struct _LIBCPP_EXPORTED_FROM_ABI in_place_t {
2828inline constexpr in_place_t in_place{};
2929
3030template <class _Tp>
31struct _LIBCPP_TEMPLATE_VIS in_place_type_t {
31struct in_place_type_t {
3232 _LIBCPP_HIDE_FROM_ABI explicit in_place_type_t() = default;
3333};
3434template <class _Tp>
3535inline constexpr in_place_type_t<_Tp> in_place_type{};
3636
3737template <size_t _Idx>
38struct _LIBCPP_TEMPLATE_VIS in_place_index_t {
38struct in_place_index_t {
3939 _LIBCPP_HIDE_FROM_ABI explicit in_place_index_t() = default;
4040};
4141template <size_t _Idx>
lib/libcxx/include/__utility/integer_sequence.h+1-1
......@@ -46,7 +46,7 @@ using __make_indices_imp _LIBCPP_NODEBUG =
4646#if _LIBCPP_STD_VER >= 14
4747
4848template <class _Tp, _Tp... _Ip>
49struct _LIBCPP_TEMPLATE_VIS integer_sequence {
49struct integer_sequence {
5050 typedef _Tp value_type;
5151 static_assert(is_integral<_Tp>::value, "std::integer_sequence can only be instantiated with an integral type");
5252 static _LIBCPP_HIDE_FROM_ABI constexpr size_t size() noexcept { return sizeof...(_Ip); }
lib/libcxx/include/__utility/no_destroy.h-1
......@@ -11,7 +11,6 @@
1111
1212#include <__config>
1313#include <__new/placement_new_delete.h>
14#include <__type_traits/is_constant_evaluated.h>
1514#include <__utility/forward.h>
1615
1716#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__utility/pair.h+97-83
......@@ -11,6 +11,7 @@
1111
1212#include <__compare/common_comparison_category.h>
1313#include <__compare/synth_three_way.h>
14#include <__concepts/boolean_testable.h>
1415#include <__concepts/different_from.h>
1516#include <__config>
1617#include <__cstddef/size_t.h>
......@@ -23,7 +24,6 @@
2324#include <__type_traits/common_reference.h>
2425#include <__type_traits/common_type.h>
2526#include <__type_traits/conditional.h>
26#include <__type_traits/decay.h>
2727#include <__type_traits/enable_if.h>
2828#include <__type_traits/integral_constant.h>
2929#include <__type_traits/is_assignable.h>
......@@ -32,11 +32,11 @@
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_replaceable.h>
3536#include <__type_traits/is_same.h>
3637#include <__type_traits/is_swappable.h>
3738#include <__type_traits/is_trivially_relocatable.h>
3839#include <__type_traits/nat.h>
39#include <__type_traits/remove_cvref.h>
4040#include <__type_traits/unwrap_ref.h>
4141#include <__utility/declval.h>
4242#include <__utility/forward.h>
......@@ -52,6 +52,33 @@ _LIBCPP_PUSH_MACROS
5252
5353_LIBCPP_BEGIN_NAMESPACE_STD
5454
55#ifndef _LIBCPP_CXX03_LANG
56
57template <class _T1, class _T2>
58struct __check_pair_construction {
59 template <int&...>
60 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit_default() {
61 return __is_implicitly_default_constructible<_T1>::value && __is_implicitly_default_constructible<_T2>::value;
62 }
63
64 template <int&...>
65 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_default() {
66 return is_default_constructible<_T1>::value && is_default_constructible<_T2>::value;
67 }
68
69 template <class _U1, class _U2>
70 static _LIBCPP_HIDE_FROM_ABI constexpr bool __is_pair_constructible() {
71 return is_constructible<_T1, _U1>::value && is_constructible<_T2, _U2>::value;
72 }
73
74 template <class _U1, class _U2>
75 static _LIBCPP_HIDE_FROM_ABI constexpr bool __is_implicit() {
76 return is_convertible<_U1, _T1>::value && is_convertible<_U2, _T2>::value;
77 }
78};
79
80#endif
81
5582template <class, class>
5683struct __non_trivially_copyable_base {
5784 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __non_trivially_copyable_base() _NOEXCEPT {}
......@@ -60,7 +87,7 @@ struct __non_trivially_copyable_base {
6087};
6188
6289template <class _T1, class _T2>
63struct _LIBCPP_TEMPLATE_VIS pair
90struct pair
6491#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
6592 : private __non_trivially_copyable_base<_T1, _T2>
6693#endif
......@@ -75,6 +102,7 @@ struct _LIBCPP_TEMPLATE_VIS pair
75102 __conditional_t<__libcpp_is_trivially_relocatable<_T1>::value && __libcpp_is_trivially_relocatable<_T2>::value,
76103 pair,
77104 void>;
105 using __replaceable _LIBCPP_NODEBUG = __conditional_t<__is_replaceable_v<_T1> && __is_replaceable_v<_T2>, pair, void>;
78106
79107 _LIBCPP_HIDE_FROM_ABI pair(pair const&) = default;
80108 _LIBCPP_HIDE_FROM_ABI pair(pair&&) = default;
......@@ -107,40 +135,16 @@ struct _LIBCPP_TEMPLATE_VIS pair
107135 return *this;
108136 }
109137#else
110 struct _CheckArgs {
111 template <int&...>
112 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit_default() {
113 return __is_implicitly_default_constructible<_T1>::value && __is_implicitly_default_constructible<_T2>::value;
114 }
115
116 template <int&...>
117 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_default() {
118 return is_default_constructible<_T1>::value && is_default_constructible<_T2>::value;
119 }
120
121 template <class _U1, class _U2>
122 static _LIBCPP_HIDE_FROM_ABI constexpr bool __is_pair_constructible() {
123 return is_constructible<first_type, _U1>::value && is_constructible<second_type, _U2>::value;
124 }
125
126 template <class _U1, class _U2>
127 static _LIBCPP_HIDE_FROM_ABI constexpr bool __is_implicit() {
128 return is_convertible<_U1, first_type>::value && is_convertible<_U2, second_type>::value;
129 }
130 };
131
132 template <bool _MaybeEnable>
133 using _CheckArgsDep _LIBCPP_NODEBUG = __conditional_t<_MaybeEnable, _CheckArgs, void>;
134
135 template <bool _Dummy = true, __enable_if_t<_CheckArgsDep<_Dummy>::__enable_default(), int> = 0>
136 explicit(!_CheckArgsDep<_Dummy>::__enable_implicit_default()) _LIBCPP_HIDE_FROM_ABI constexpr pair() noexcept(
138 template <class _CheckArgsDep = __check_pair_construction<_T1, _T2>,
139 __enable_if_t<_CheckArgsDep::__enable_default(), int> = 0>
140 explicit(!_CheckArgsDep::__enable_implicit_default()) _LIBCPP_HIDE_FROM_ABI constexpr pair() noexcept(
137141 is_nothrow_default_constructible<first_type>::value && is_nothrow_default_constructible<second_type>::value)
138142 : first(), second() {}
139143
140 template <bool _Dummy = true,
141 __enable_if_t<_CheckArgsDep<_Dummy>::template __is_pair_constructible<_T1 const&, _T2 const&>(), int> = 0>
144 template <class _CheckArgsDep = __check_pair_construction<_T1, _T2>,
145 __enable_if_t<_CheckArgsDep::template __is_pair_constructible<_T1 const&, _T2 const&>(), int> = 0>
142146 _LIBCPP_HIDE_FROM_ABI
143 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgsDep<_Dummy>::template __is_implicit<_T1 const&, _T2 const&>())
147 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgsDep::template __is_implicit<_T1 const&, _T2 const&>())
144148 pair(_T1 const& __t1, _T2 const& __t2) noexcept(is_nothrow_copy_constructible<first_type>::value &&
145149 is_nothrow_copy_constructible<second_type>::value)
146150 : first(__t1), second(__t2) {}
......@@ -153,62 +157,64 @@ struct _LIBCPP_TEMPLATE_VIS pair
153157 class _U1,
154158 class _U2,
155159# endif
156 __enable_if_t<_CheckArgs::template __is_pair_constructible<_U1, _U2>(), int> = 0 >
157 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgs::template __is_implicit<_U1, _U2>())
160 __enable_if_t<__check_pair_construction<_T1, _T2>::template __is_pair_constructible<_U1, _U2>(), int> = 0 >
161 _LIBCPP_HIDE_FROM_ABI
162 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!__check_pair_construction<_T1, _T2>::template __is_implicit<_U1, _U2>())
158163 pair(_U1&& __u1, _U2&& __u2) noexcept(is_nothrow_constructible<first_type, _U1>::value &&
159164 is_nothrow_constructible<second_type, _U2>::value)
160165 : first(std::forward<_U1>(__u1)), second(std::forward<_U2>(__u2)) {
161166 }
162167
163168# if _LIBCPP_STD_VER >= 23
164 template <class _U1, class _U2, __enable_if_t<_CheckArgs::template __is_pair_constructible<_U1&, _U2&>(), int> = 0>
165 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_CheckArgs::template __is_implicit<_U1&, _U2&>())
169 template <class _U1,
170 class _U2,
171 __enable_if_t<__check_pair_construction<_T1, _T2>::template __is_pair_constructible<_U1&, _U2&>(), int> = 0>
172 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!__check_pair_construction<_T1, _T2>::template __is_implicit<_U1&, _U2&>())
166173 pair(pair<_U1, _U2>& __p) noexcept((is_nothrow_constructible<first_type, _U1&>::value &&
167174 is_nothrow_constructible<second_type, _U2&>::value))
168175 : first(__p.first), second(__p.second) {}
169176# endif
170177
171 template <class _U1,
172 class _U2,
173 __enable_if_t<_CheckArgs::template __is_pair_constructible<_U1 const&, _U2 const&>(), int> = 0>
174 _LIBCPP_HIDE_FROM_ABI
175 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgs::template __is_implicit<_U1 const&, _U2 const&>())
178 template <
179 class _U1,
180 class _U2,
181 __enable_if_t<__check_pair_construction<_T1, _T2>::template __is_pair_constructible<_U1 const&, _U2 const&>(),
182 int> = 0>
183 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(
184 !__check_pair_construction<_T1, _T2>::template __is_implicit<_U1 const&, _U2 const&>())
176185 pair(pair<_U1, _U2> const& __p) noexcept(is_nothrow_constructible<first_type, _U1 const&>::value &&
177186 is_nothrow_constructible<second_type, _U2 const&>::value)
178187 : first(__p.first), second(__p.second) {}
179188
180 template <class _U1, class _U2, __enable_if_t<_CheckArgs::template __is_pair_constructible<_U1, _U2>(), int> = 0>
181 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!_CheckArgs::template __is_implicit<_U1, _U2>())
189 template <class _U1,
190 class _U2,
191 __enable_if_t<__check_pair_construction<_T1, _T2>::template __is_pair_constructible<_U1, _U2>(), int> = 0>
192 _LIBCPP_HIDE_FROM_ABI
193 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(!__check_pair_construction<_T1, _T2>::template __is_implicit<_U1, _U2>())
182194 pair(pair<_U1, _U2>&& __p) noexcept(is_nothrow_constructible<first_type, _U1&&>::value &&
183195 is_nothrow_constructible<second_type, _U2&&>::value)
184196 : first(std::forward<_U1>(__p.first)), second(std::forward<_U2>(__p.second)) {}
185197
186198# if _LIBCPP_STD_VER >= 23
187 template <class _U1,
188 class _U2,
189 __enable_if_t<_CheckArgs::template __is_pair_constructible<const _U1&&, const _U2&&>(), int> = 0>
190 _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_CheckArgs::template __is_implicit<const _U1&&, const _U2&&>())
199 template <
200 class _U1,
201 class _U2,
202 __enable_if_t<__check_pair_construction<_T1, _T2>::template __is_pair_constructible<const _U1&&, const _U2&&>(),
203 int> = 0>
204 _LIBCPP_HIDE_FROM_ABI constexpr explicit(
205 !__check_pair_construction<_T1, _T2>::template __is_implicit<const _U1&&, const _U2&&>())
191206 pair(const pair<_U1, _U2>&& __p) noexcept(is_nothrow_constructible<first_type, const _U1&&>::value &&
192207 is_nothrow_constructible<second_type, const _U2&&>::value)
193208 : first(std::move(__p.first)), second(std::move(__p.second)) {}
194209# endif
195210
196211# if _LIBCPP_STD_VER >= 23
197 // TODO: Remove this workaround in LLVM 20. The bug got fixed in Clang 18.
198 // This is a workaround for http://llvm.org/PR60710. We should be able to remove it once Clang is fixed.
199 template <class _PairLike>
200 _LIBCPP_HIDE_FROM_ABI static constexpr bool __pair_like_explicit_wknd() {
201 if constexpr (__pair_like_no_subrange<_PairLike>) {
202 return !is_convertible_v<decltype(std::get<0>(std::declval<_PairLike&&>())), first_type> ||
203 !is_convertible_v<decltype(std::get<1>(std::declval<_PairLike&&>())), second_type>;
204 }
205 return false;
206 }
207
208212 template <__pair_like_no_subrange _PairLike>
209213 requires(is_constructible_v<first_type, decltype(std::get<0>(std::declval<_PairLike &&>()))> &&
210214 is_constructible_v<second_type, decltype(std::get<1>(std::declval<_PairLike &&>()))>)
211 _LIBCPP_HIDE_FROM_ABI constexpr explicit(__pair_like_explicit_wknd<_PairLike>()) pair(_PairLike&& __p)
215 _LIBCPP_HIDE_FROM_ABI constexpr explicit(
216 !is_convertible_v<decltype(std::get<0>(std::declval<_PairLike&&>())), first_type> ||
217 !is_convertible_v<decltype(std::get<1>(std::declval<_PairLike&&>())), second_type>) pair(_PairLike&& __p)
212218 : first(std::get<0>(std::forward<_PairLike>(__p))), second(std::get<1>(std::forward<_PairLike>(__p))) {}
213219# endif
214220
......@@ -450,7 +456,14 @@ pair(_T1, _T2) -> pair<_T1, _T2>;
450456
451457template <class _T1, class _T2, class _U1, class _U2>
452458inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
453operator==(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {
459operator==(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y)
460#if _LIBCPP_STD_VER >= 26
461 requires requires {
462 { __x.first == __y.first } -> __boolean_testable;
463 { __x.second == __y.second } -> __boolean_testable;
464 }
465#endif
466{
454467 return __x.first == __y.first && __x.second == __y.second;
455468}
456469
......@@ -506,13 +519,14 @@ template <class _T1, class _T2, class _U1, class _U2, template <class> class _TQ
506519 typename pair<common_reference_t<_TQual<_T1>, _UQual<_U1>>, common_reference_t<_TQual<_T2>, _UQual<_U2>>>;
507520 }
508521struct basic_common_reference<pair<_T1, _T2>, pair<_U1, _U2>, _TQual, _UQual> {
509 using type = pair<common_reference_t<_TQual<_T1>, _UQual<_U1>>, common_reference_t<_TQual<_T2>, _UQual<_U2>>>;
522 using type _LIBCPP_NODEBUG =
523 pair<common_reference_t<_TQual<_T1>, _UQual<_U1>>, common_reference_t<_TQual<_T2>, _UQual<_U2>>>;
510524};
511525
512526template <class _T1, class _T2, class _U1, class _U2>
513527 requires requires { typename pair<common_type_t<_T1, _U1>, common_type_t<_T2, _U2>>; }
514528struct common_type<pair<_T1, _T2>, pair<_U1, _U2>> {
515 using type = pair<common_type_t<_T1, _U1>, common_type_t<_T2, _U2>>;
529 using type _LIBCPP_NODEBUG = pair<common_type_t<_T1, _U1>, common_type_t<_T2, _U2>>;
516530};
517531#endif // _LIBCPP_STD_VER >= 23
518532
......@@ -538,20 +552,20 @@ make_pair(_T1&& __t1, _T2&& __t2) {
538552}
539553
540554template <class _T1, class _T2>
541struct _LIBCPP_TEMPLATE_VIS tuple_size<pair<_T1, _T2> > : public integral_constant<size_t, 2> {};
555struct tuple_size<pair<_T1, _T2> > : public integral_constant<size_t, 2> {};
542556
543557template <size_t _Ip, class _T1, class _T2>
544struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> > {
558struct tuple_element<_Ip, pair<_T1, _T2> > {
545559 static_assert(_Ip < 2, "Index out of bounds in std::tuple_element<std::pair<T1, T2>>");
546560};
547561
548562template <class _T1, class _T2>
549struct _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> > {
563struct tuple_element<0, pair<_T1, _T2> > {
550564 using type _LIBCPP_NODEBUG = _T1;
551565};
552566
553567template <class _T1, class _T2>
554struct _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> > {
568struct tuple_element<1, pair<_T1, _T2> > {
555569 using type _LIBCPP_NODEBUG = _T2;
556570};
557571
......@@ -631,42 +645,42 @@ get(const pair<_T1, _T2>&& __p) _NOEXCEPT {
631645#if _LIBCPP_STD_VER >= 14
632646template <class _T1, class _T2>
633647inline _LIBCPP_HIDE_FROM_ABI constexpr _T1& get(pair<_T1, _T2>& __p) _NOEXCEPT {
634 return __get_pair<0>::get(__p);
648 return __p.first;
635649}
636650
637651template <class _T1, class _T2>
638652inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const& get(pair<_T1, _T2> const& __p) _NOEXCEPT {
639 return __get_pair<0>::get(__p);
653 return __p.first;
640654}
641655
642656template <class _T1, class _T2>
643657inline _LIBCPP_HIDE_FROM_ABI constexpr _T1&& get(pair<_T1, _T2>&& __p) _NOEXCEPT {
644 return __get_pair<0>::get(std::move(__p));
658 return std::forward<_T1&&>(__p.first);
645659}
646660
647661template <class _T1, class _T2>
648662inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const&& get(pair<_T1, _T2> const&& __p) _NOEXCEPT {
649 return __get_pair<0>::get(std::move(__p));
663 return std::forward<_T1 const&&>(__p.first);
650664}
651665
652template <class _T1, class _T2>
653inline _LIBCPP_HIDE_FROM_ABI constexpr _T1& get(pair<_T2, _T1>& __p) _NOEXCEPT {
654 return __get_pair<1>::get(__p);
666template <class _T2, class _T1>
667inline _LIBCPP_HIDE_FROM_ABI constexpr _T2& get(pair<_T1, _T2>& __p) _NOEXCEPT {
668 return __p.second;
655669}
656670
657template <class _T1, class _T2>
658inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const& get(pair<_T2, _T1> const& __p) _NOEXCEPT {
659 return __get_pair<1>::get(__p);
671template <class _T2, class _T1>
672inline _LIBCPP_HIDE_FROM_ABI constexpr _T2 const& get(pair<_T1, _T2> const& __p) _NOEXCEPT {
673 return __p.second;
660674}
661675
662template <class _T1, class _T2>
663inline _LIBCPP_HIDE_FROM_ABI constexpr _T1&& get(pair<_T2, _T1>&& __p) _NOEXCEPT {
664 return __get_pair<1>::get(std::move(__p));
676template <class _T2, class _T1>
677inline _LIBCPP_HIDE_FROM_ABI constexpr _T2&& get(pair<_T1, _T2>&& __p) _NOEXCEPT {
678 return std::forward<_T2&&>(__p.second);
665679}
666680
667template <class _T1, class _T2>
668inline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const&& get(pair<_T2, _T1> const&& __p) _NOEXCEPT {
669 return __get_pair<1>::get(std::move(__p));
681template <class _T2, class _T1>
682inline _LIBCPP_HIDE_FROM_ABI constexpr _T2 const&& get(pair<_T1, _T2> const&& __p) _NOEXCEPT {
683 return std::forward<_T2 const&&>(__p.second);
670684}
671685
672686#endif // _LIBCPP_STD_VER >= 14
lib/libcxx/include/__utility/piecewise_construct.h+1-1
......@@ -17,7 +17,7 @@
1717
1818_LIBCPP_BEGIN_NAMESPACE_STD
1919
20struct _LIBCPP_TEMPLATE_VIS piecewise_construct_t {
20struct piecewise_construct_t {
2121 explicit piecewise_construct_t() = default;
2222};
2323
lib/libcxx/include/__utility/scope_guard.h-1
......@@ -10,7 +10,6 @@
1010#ifndef _LIBCPP___UTILITY_SCOPE_GUARD_H
1111#define _LIBCPP___UTILITY_SCOPE_GUARD_H
1212
13#include <__assert>
1413#include <__config>
1514#include <__utility/move.h>
1615
lib/libcxx/include/__utility/swap.h-1
......@@ -17,7 +17,6 @@
1717#include <__type_traits/is_nothrow_assignable.h>
1818#include <__type_traits/is_nothrow_constructible.h>
1919#include <__type_traits/is_swappable.h>
20#include <__utility/declval.h>
2120#include <__utility/move.h>
2221
2322#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
lib/libcxx/include/__utility/to_underlying.h+2-2
......@@ -21,8 +21,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121
2222#ifndef _LIBCPP_CXX03_LANG
2323template <class _Tp>
24_LIBCPP_HIDE_FROM_ABI constexpr typename underlying_type<_Tp>::type __to_underlying(_Tp __val) noexcept {
25 return static_cast<typename underlying_type<_Tp>::type>(__val);
24[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr __underlying_type_t<_Tp> __to_underlying(_Tp __val) noexcept {
25 return static_cast<__underlying_type_t<_Tp>>(__val);
2626}
2727#endif // !_LIBCPP_CXX03_LANG
2828
lib/libcxx/include/__variant/monostate.h+7-5
......@@ -23,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2323
2424#if _LIBCPP_STD_VER >= 17
2525
26struct _LIBCPP_TEMPLATE_VIS monostate {};
26struct monostate {};
2727
2828_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(monostate, monostate) noexcept { return true; }
2929
......@@ -48,11 +48,13 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator>=(monostate, monostate) noe
4848# endif // _LIBCPP_STD_VER >= 20
4949
5050template <>
51struct _LIBCPP_TEMPLATE_VIS hash<monostate> {
52 using argument_type = monostate;
53 using result_type = size_t;
51struct hash<monostate> {
52# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
53 using argument_type _LIBCPP_DEPRECATED_IN_CXX17 = monostate;
54 using result_type _LIBCPP_DEPRECATED_IN_CXX17 = size_t;
55# endif
5456
55 inline _LIBCPP_HIDE_FROM_ABI result_type operator()(const argument_type&) const _NOEXCEPT {
57 inline _LIBCPP_HIDE_FROM_ABI size_t operator()(const monostate&) const noexcept {
5658 return 66740831; // return a fundamentally attractive random value.
5759 }
5860};
lib/libcxx/include/__vector/container_traits.h+3-1
......@@ -31,7 +31,9 @@ struct __container_traits<vector<_Tp, _Allocator> > {
3131 // there are no effects. Otherwise, if an exception is thrown by the move constructor of a non-Cpp17CopyInsertable T,
3232 // the effects are unspecified.
3333 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
34 _Or<is_nothrow_move_constructible<_Tp>, __is_cpp17_copy_insertable<_Allocator> >::value;
34 is_nothrow_move_constructible<_Tp>::value || __is_cpp17_copy_insertable_v<_Allocator>;
35
36 static _LIBCPP_CONSTEXPR const bool __reservable = true;
3537};
3638
3739_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/__vector/vector.h+66-60
......@@ -55,9 +55,11 @@
5555#include <__type_traits/is_nothrow_assignable.h>
5656#include <__type_traits/is_nothrow_constructible.h>
5757#include <__type_traits/is_pointer.h>
58#include <__type_traits/is_replaceable.h>
5859#include <__type_traits/is_same.h>
5960#include <__type_traits/is_trivially_relocatable.h>
6061#include <__type_traits/type_identity.h>
62#include <__utility/declval.h>
6163#include <__utility/exception_guard.h>
6264#include <__utility/forward.h>
6365#include <__utility/is_pointer_in_range.h>
......@@ -83,36 +85,33 @@ _LIBCPP_PUSH_MACROS
8385_LIBCPP_BEGIN_NAMESPACE_STD
8486
8587template <class _Tp, class _Allocator /* = allocator<_Tp> */>
86class _LIBCPP_TEMPLATE_VIS vector {
87private:
88 typedef allocator<_Tp> __default_allocator_type;
89
88class vector {
9089public:
9190 //
9291 // Types
9392 //
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;
93 using __self _LIBCPP_NODEBUG = vector;
94 using value_type = _Tp;
95 using allocator_type = _Allocator;
96 using __alloc_traits _LIBCPP_NODEBUG = allocator_traits<allocator_type>;
97 using reference = value_type&;
98 using const_reference = const value_type&;
99 using size_type = typename __alloc_traits::size_type;
100 using difference_type = typename __alloc_traits::difference_type;
101 using pointer = typename __alloc_traits::pointer;
102 using const_pointer = typename __alloc_traits::const_pointer;
104103#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
105104 // Users might provide custom allocators, and prior to C++20 we have no existing way to detect whether the allocator's
106105 // pointer type is contiguous (though it has to be by the Standard). Using the wrapper type ensures the iterator is
107106 // considered contiguous.
108 typedef __bounded_iter<__wrap_iter<pointer> > iterator;
109 typedef __bounded_iter<__wrap_iter<const_pointer> > const_iterator;
107 using iterator = __bounded_iter<__wrap_iter<pointer> >;
108 using const_iterator = __bounded_iter<__wrap_iter<const_pointer> >;
110109#else
111 typedef __wrap_iter<pointer> iterator;
112 typedef __wrap_iter<const_pointer> const_iterator;
110 using iterator = __wrap_iter<pointer>;
111 using const_iterator = __wrap_iter<const_pointer>;
113112#endif
114 typedef std::reverse_iterator<iterator> reverse_iterator;
115 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
113 using reverse_iterator = std::reverse_iterator<iterator>;
114 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
116115
117116 // A vector containers the following members which may be trivially relocatable:
118117 // - pointer: may be trivially relocatable, so it's checked
......@@ -122,6 +121,10 @@ public:
122121 __libcpp_is_trivially_relocatable<pointer>::value && __libcpp_is_trivially_relocatable<allocator_type>::value,
123122 vector,
124123 void>;
124 using __replaceable _LIBCPP_NODEBUG =
125 __conditional_t<__is_replaceable_v<pointer> && __container_allocator_is_replaceable<__alloc_traits>::value,
126 vector,
127 void>;
125128
126129 static_assert(__check_valid_allocator<allocator_type>::value, "");
127130 static_assert(is_same<typename allocator_type::value_type, value_type>::value,
......@@ -463,6 +466,15 @@ public:
463466 emplace_back(_Args&&... __args);
464467#endif
465468
469 template <class... _Args>
470 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __emplace_back_assume_capacity(_Args&&... __args) {
471 _LIBCPP_ASSERT_INTERNAL(
472 size() < capacity(), "We assume that we have enough space to insert an element at the end of the vector");
473 _ConstructTransaction __tx(*this, 1);
474 __alloc_traits::construct(this->__alloc_, std::__to_address(__tx.__pos_), std::forward<_Args>(__args)...);
475 ++__tx.__pos_;
476 }
477
466478#if _LIBCPP_STD_VER >= 23
467479 template <_ContainerCompatibleRange<_Tp> _Range>
468480 _LIBCPP_HIDE_FROM_ABI constexpr void append_range(_Range&& __range) {
......@@ -558,7 +570,7 @@ private:
558570 // Postcondition: size() == 0
559571 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
560572 if (__n > max_size())
561 __throw_length_error();
573 this->__throw_length_error();
562574 auto __allocation = std::__allocate_at_least(this->__alloc_, __n);
563575 __begin_ = __allocation.ptr;
564576 __end_ = __allocation.ptr;
......@@ -605,6 +617,30 @@ private:
605617 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
606618 __assign_with_size(_Iterator __first, _Sentinel __last, difference_type __n);
607619
620 template <class _Iterator,
621 __enable_if_t<!is_same<decltype(*std::declval<_Iterator&>())&&, value_type&&>::value, int> = 0>
622 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
623 __insert_assign_n_unchecked(_Iterator __first, difference_type __n, pointer __position) {
624 for (pointer __end_position = __position + __n; __position != __end_position; ++__position, (void)++__first) {
625 __temp_value<value_type, _Allocator> __tmp(this->__alloc_, *__first);
626 *__position = std::move(__tmp.get());
627 }
628 }
629
630 template <class _Iterator,
631 __enable_if_t<is_same<decltype(*std::declval<_Iterator&>())&&, value_type&&>::value, int> = 0>
632 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
633 __insert_assign_n_unchecked(_Iterator __first, difference_type __n, pointer __position) {
634#if _LIBCPP_STD_VER >= 23
635 if constexpr (!forward_iterator<_Iterator>) { // Handles input-only sized ranges for insert_range
636 ranges::copy_n(std::move(__first), __n, __position);
637 } else
638#endif
639 {
640 std::copy_n(__first, __n, __position);
641 }
642 }
643
608644 template <class _InputIterator, class _Sentinel>
609645 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
610646 __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last);
......@@ -685,47 +721,32 @@ private:
685721 }
686722
687723 _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
690724 __annotate_contiguous_container(data() + capacity(), data() + __current_size);
691#endif
692725 }
693726
694727 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_delete() const _NOEXCEPT {
695#if _LIBCPP_HAS_ASAN
696728 __annotate_contiguous_container(data() + size(), data() + capacity());
697#endif
698729 }
699730
700731 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_increase(size_type __n) const _NOEXCEPT {
701 (void)__n;
702#if _LIBCPP_HAS_ASAN
703732 __annotate_contiguous_container(data() + size(), data() + size() + __n);
704#endif
705733 }
706734
707735 _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
710736 __annotate_contiguous_container(data() + __old_size, data() + size());
711#endif
712737 }
713738
714739 struct _ConstructTransaction {
715740 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit _ConstructTransaction(vector& __v, size_type __n)
716741 : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
717#if _LIBCPP_HAS_ASAN
718742 __v_.__annotate_increase(__n);
719#endif
720743 }
721744
722745 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~_ConstructTransaction() {
723746 __v_.__end_ = __pos_;
724#if _LIBCPP_HAS_ASAN
725747 if (__pos_ != __new_end_) {
726748 __v_.__annotate_shrink(__new_end_ - __v_.__begin_);
727749 }
728#endif
729750 }
730751
731752 vector& __v_;
......@@ -736,13 +757,6 @@ private:
736757 _ConstructTransaction& operator=(_ConstructTransaction const&) = delete;
737758 };
738759
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
746760 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __base_destruct_at_end(pointer __new_last) _NOEXCEPT {
747761 pointer __soon_to_be_end = this->__end_;
748762 while (__new_last != __soon_to_be_end)
......@@ -1130,7 +1144,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 inline
11301144 vector<_Tp, _Allocator>::emplace_back(_Args&&... __args) {
11311145 pointer __end = this->__end_;
11321146 if (__end < this->__cap_) {
1133 __construct_one_at_end(std::forward<_Args>(__args)...);
1147 __emplace_back_assume_capacity(std::forward<_Args>(__args)...);
11341148 ++__end;
11351149 } else {
11361150 __end = __emplace_back_slow_path(std::forward<_Args>(__args)...);
......@@ -1184,7 +1198,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
11841198 pointer __p = this->__begin_ + (__position - begin());
11851199 if (this->__end_ < this->__cap_) {
11861200 if (__p == this->__end_) {
1187 __construct_one_at_end(__x);
1201 __emplace_back_assume_capacity(__x);
11881202 } else {
11891203 __move_range(__p, this->__end_, __p + 1);
11901204 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
......@@ -1206,7 +1220,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) {
12061220 pointer __p = this->__begin_ + (__position - begin());
12071221 if (this->__end_ < this->__cap_) {
12081222 if (__p == this->__end_) {
1209 __construct_one_at_end(std::move(__x));
1223 __emplace_back_assume_capacity(std::move(__x));
12101224 } else {
12111225 __move_range(__p, this->__end_, __p + 1);
12121226 *__p = std::move(__x);
......@@ -1226,7 +1240,7 @@ vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) {
12261240 pointer __p = this->__begin_ + (__position - begin());
12271241 if (this->__end_ < this->__cap_) {
12281242 if (__p == this->__end_) {
1229 __construct_one_at_end(std::forward<_Args>(__args)...);
1243 __emplace_back_assume_capacity(std::forward<_Args>(__args)...);
12301244 } else {
12311245 __temp_value<value_type, _Allocator> __tmp(this->__alloc_, std::forward<_Args>(__args)...);
12321246 __move_range(__p, this->__end_, __p + 1);
......@@ -1245,8 +1259,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
12451259vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) {
12461260 pointer __p = this->__begin_ + (__position - begin());
12471261 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_)) {
1262 if (__n <= static_cast<size_type>(this->__cap_ - this->__end_)) {
12501263 size_type __old_n = __n;
12511264 pointer __old_last = this->__end_;
12521265 if (__n > static_cast<size_type>(this->__end_ - __p)) {
......@@ -1257,7 +1270,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_
12571270 if (__n > 0) {
12581271 __move_range(__p, __old_last, __p + __old_n);
12591272 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1260 if (__p <= __xr && __xr < this->__end_)
1273 if (std::__is_pointer_in_range(std::__to_address(__p), std::__to_address(__end_), std::addressof(__x)))
12611274 __xr += __old_n;
12621275 std::fill_n(__p, __n, *__xr);
12631276 }
......@@ -1278,7 +1291,7 @@ vector<_Tp, _Allocator>::__insert_with_sentinel(const_iterator __position, _Inpu
12781291 pointer __p = this->__begin_ + __off;
12791292 pointer __old_last = this->__end_;
12801293 for (; this->__end_ != this->__cap_ && __first != __last; ++__first)
1281 __construct_one_at_end(*__first);
1294 __emplace_back_assume_capacity(*__first);
12821295
12831296 if (__first == __last)
12841297 (void)std::rotate(__p, __old_last, this->__end_);
......@@ -1325,19 +1338,12 @@ vector<_Tp, _Allocator>::__insert_with_size(
13251338 __construct_at_end(__m, __last, __n - __dx);
13261339 if (__dx > 0) {
13271340 __move_range(__p, __old_last, __p + __n);
1328 std::copy(__first, __m, __p);
1341 __insert_assign_n_unchecked(__first, __dx, __p);
13291342 }
13301343 }
13311344 } else {
13321345 __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 }
1346 __insert_assign_n_unchecked(std::move(__first), __n, __p);
13411347 }
13421348 } else {
13431349 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, this->__alloc_);
lib/libcxx/include/__vector/vector_bool.h+42-51
......@@ -10,14 +10,16 @@
1010#define _LIBCPP___VECTOR_VECTOR_BOOL_H
1111
1212#include <__algorithm/copy.h>
13#include <__algorithm/copy_backward.h>
1314#include <__algorithm/fill_n.h>
1415#include <__algorithm/iterator_operations.h>
1516#include <__algorithm/max.h>
17#include <__algorithm/rotate.h>
1618#include <__assert>
1719#include <__bit_reference>
1820#include <__config>
1921#include <__functional/unary_function.h>
20#include <__fwd/bit_reference.h>
22#include <__fwd/bit_reference.h> // TODO: This is a workaround for https://github.com/llvm/llvm-project/issues/131814
2123#include <__fwd/functional.h>
2224#include <__fwd/vector.h>
2325#include <__iterator/distance.h>
......@@ -73,38 +75,38 @@ struct __has_storage_type<vector<bool, _Allocator> > {
7375};
7476
7577template <class _Allocator>
76class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> {
78class vector<bool, _Allocator> {
7779public:
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;
80 using __self _LIBCPP_NODEBUG = vector;
81 using value_type = bool;
82 using allocator_type = _Allocator;
83 using __alloc_traits _LIBCPP_NODEBUG = allocator_traits<allocator_type>;
84 using size_type = typename __alloc_traits::size_type;
85 using difference_type = typename __alloc_traits::difference_type;
86 using __storage_type _LIBCPP_NODEBUG = size_type;
87 using pointer = __bit_iterator<vector, false>;
88 using const_pointer = __bit_iterator<vector, true>;
89 using iterator = pointer;
90 using const_iterator = const_pointer;
91 using reverse_iterator = std::reverse_iterator<iterator>;
92 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
9193
9294private:
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;
95 using __storage_allocator _LIBCPP_NODEBUG = __rebind_alloc<__alloc_traits, __storage_type>;
96 using __storage_traits _LIBCPP_NODEBUG = allocator_traits<__storage_allocator>;
97 using __storage_pointer _LIBCPP_NODEBUG = typename __storage_traits::pointer;
98 using __const_storage_pointer _LIBCPP_NODEBUG = typename __storage_traits::const_pointer;
9799
98100 __storage_pointer __begin_;
99101 size_type __size_;
100102 _LIBCPP_COMPRESSED_PAIR(size_type, __cap_, __storage_allocator, __alloc_);
101103
102104public:
103 typedef __bit_reference<vector> reference;
105 using reference = __bit_reference<vector>;
104106#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
105107 using const_reference = bool;
106108#else
107 typedef __bit_const_reference<vector> const_reference;
109 using const_reference = __bit_const_reference<vector>;
108110#endif
109111
110112private:
......@@ -445,7 +447,7 @@ private:
445447 // Postcondition: size() == 0
446448 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vallocate(size_type __n) {
447449 if (__n > max_size())
448 __throw_length_error();
450 this->__throw_length_error();
449451 auto __allocation = std::__allocate_at_least(__alloc_, __external_cap_to_internal(__n));
450452 __begin_ = __allocation.ptr;
451453 __size_ = 0;
......@@ -510,14 +512,14 @@ private:
510512
511513 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(vector&, false_type) _NOEXCEPT {}
512514
513 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t __hash_code() const _NOEXCEPT;
515 _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;
514516
515517 friend class __bit_reference<vector>;
516518 friend class __bit_const_reference<vector>;
517519 friend class __bit_iterator<vector, false>;
518520 friend class __bit_iterator<vector, true>;
519521 friend struct __bit_array<vector>;
520 friend struct _LIBCPP_TEMPLATE_VIS hash<vector>;
522 friend struct hash<vector>;
521523};
522524
523525template <class _Allocator>
......@@ -533,10 +535,8 @@ template <class _Allocator>
533535_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::size_type
534536vector<bool, _Allocator>::max_size() const _NOEXCEPT {
535537 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);
538 size_type __nmax = numeric_limits<difference_type>::max();
539 return __nmax / __bits_per_word <= __amax ? __nmax : __internal_cap_to_external(__amax);
540540}
541541
542542// Precondition: __new_size > capacity()
......@@ -549,40 +549,33 @@ vector<bool, _Allocator>::__recommend(size_type __new_size) const {
549549 const size_type __cap = capacity();
550550 if (__cap >= __ms / 2)
551551 return __ms;
552 return std::max(2 * __cap, __align_it(__new_size));
552 return std::max<size_type>(2 * __cap, __align_it(__new_size));
553553}
554554
555555// Default constructs __n objects starting at __end_
556// Precondition: __n > 0
557556// Precondition: size() + __n <= capacity()
558557// Postcondition: size() == size() + __n
559558template <class _Allocator>
560559inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
561560vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) {
562 size_type __old_size = this->__size_;
561 _LIBCPP_ASSERT_INTERNAL(
562 capacity() >= size() + __n, "vector<bool>::__construct_at_end called with insufficient capacity");
563 std::fill_n(end(), __n, __x);
563564 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);
565 if (end().__ctz_ != 0) // Ensure uninitialized leading bits in the last word are set to zero
566 std::fill_n(end(), __bits_per_word - end().__ctz_, 0);
571567}
572568
573569template <class _Allocator>
574570template <class _InputIterator, class _Sentinel>
575571_LIBCPP_CONSTEXPR_SINCE_CXX20 void
576572vector<bool, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
577 size_type __old_size = this->__size_;
573 _LIBCPP_ASSERT_INTERNAL(
574 capacity() >= size() + __n, "vector<bool>::__construct_at_end called with insufficient capacity");
575 std::__copy(std::move(__first), std::move(__last), end());
578576 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));
577 if (end().__ctz_ != 0) // Ensure uninitialized leading bits in the last word are set to zero
578 std::fill_n(end(), __bits_per_word - end().__ctz_, 0);
586579}
587580
588581template <class _Allocator>
......@@ -1100,7 +1093,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 bool vector<bool, _Allocator>::__invariants() cons
11001093}
11011094
11021095template <class _Allocator>
1103_LIBCPP_CONSTEXPR_SINCE_CXX20 size_t vector<bool, _Allocator>::__hash_code() const _NOEXCEPT {
1096size_t vector<bool, _Allocator>::__hash_code() const _NOEXCEPT {
11041097 size_t __h = 0;
11051098 // do middle whole words
11061099 size_type __n = __size_;
......@@ -1116,10 +1109,8 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t vector<bool, _Allocator>::__hash_code() con
11161109}
11171110
11181111template <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 {
1112struct hash<vector<bool, _Allocator> > : public __unary_function<vector<bool, _Allocator>, size_t> {
1113 _LIBCPP_HIDE_FROM_ABI size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT {
11231114 return __vec.__hash_code();
11241115 }
11251116};
lib/libcxx/include/__vector/vector_bool_formatter.h+1-1
......@@ -26,7 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2626template <class _Tp, class _CharT>
2727// Since is-vector-bool-reference is only used once it's inlined here.
2828 requires same_as<typename _Tp::__container, vector<bool, typename _Tp::__container::allocator_type>>
29struct _LIBCPP_TEMPLATE_VIS formatter<_Tp, _CharT> {
29struct formatter<_Tp, _CharT> {
3030private:
3131 formatter<bool, _CharT> __underlying_;
3232
lib/libcxx/include/__verbose_abort+1-7
......@@ -18,16 +18,10 @@
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
2721// This function should never be called directly from the code -- it should only be called through
2822// the _LIBCPP_VERBOSE_ABORT macro.
2923[[__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;
24 __printf__, 1, 2) void __libcpp_verbose_abort(const char* __format, ...) _NOEXCEPT;
3125
3226// _LIBCPP_VERBOSE_ABORT(format, args...)
3327//
lib/libcxx/include/__verbose_trap created+36
......@@ -0,0 +1,36 @@
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___VERBOSE_TRAP
11#define _LIBCPP___VERBOSE_TRAP
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#if __has_builtin(__builtin_verbose_trap)
22// AppleClang shipped a slightly different version of __builtin_verbose_trap from the upstream
23// version before upstream Clang actually got the builtin.
24// TODO: Remove once AppleClang supports the two-arguments version of the builtin.
25# if defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1700
26# define _LIBCPP_VERBOSE_TRAP(message) __builtin_verbose_trap(message)
27# else
28# define _LIBCPP_VERBOSE_TRAP(message) __builtin_verbose_trap("libc++", message)
29# endif
30#else
31# define _LIBCPP_VERBOSE_TRAP(message) ((void)message, __builtin_trap())
32#endif
33
34_LIBCPP_END_NAMESPACE_STD
35
36#endif // _LIBCPP___VERBOSE_TRAP
lib/libcxx/include/algorithm+153-144
......@@ -45,6 +45,9 @@ namespace ranges {
4545 template <class I, class T>
4646 struct in_value_result; // since C++23
4747
48 template <class O, class T>
49 struct out_value_result; // since C++23
50
4851 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
4952 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less> // since C++20
5053 constexpr I min_element(I first, S last, Comp comp = {}, Proj proj = {});
......@@ -422,11 +425,12 @@ namespace ranges {
422425 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
423426 class Proj = identity>
424427 requires sortable<I, Comp, Proj>
425 I ranges::stable_sort(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
428 constexpr I // constexpr since C++26
429 ranges::stable_sort(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
426430
427431 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
428432 requires sortable<iterator_t<R>, Comp, Proj>
429 borrowed_iterator_t<R>
433 constexpr borrowed_iterator_t<R> // constexpr since C++26
430434 ranges::stable_sort(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
431435
432436 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
......@@ -627,12 +631,14 @@ namespace ranges {
627631 template<bidirectional_iterator I, sentinel_for<I> S, class Proj = identity,
628632 indirect_unary_predicate<projected<I, Proj>> Pred>
629633 requires permutable<I>
630 subrange<I> stable_partition(I first, S last, Pred pred, Proj proj = {}); // since C++20
634 constexpr subrange<I> // constexpr since C++26
635 stable_partition(I first, S last, Pred pred, Proj proj = {}); // since C++20
631636
632637 template<bidirectional_range R, class Proj = identity,
633638 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
634639 requires permutable<iterator_t<R>>
635 borrowed_subrange_t<R> stable_partition(R&& r, Pred pred, Proj proj = {}); // since C++20
640 constexpr borrowed_subrange_t<R> // constexpr since C++26
641 stable_partition(R&& r, Pred pred, Proj proj = {}); // since C++20
636642
637643 template<input_iterator I1, sentinel_for<I1> S1, forward_iterator I2, sentinel_for<I2> S2,
638644 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
......@@ -1028,13 +1034,14 @@ namespace ranges {
10281034 template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
10291035 class Proj = identity>
10301036 requires sortable<I, Comp, Proj>
1031 I inplace_merge(I first, I middle, S last, Comp comp = {}, Proj proj = {}); // since C++20
1037 constexpr I // constexpr since C++26
1038 inplace_merge(I first, I middle, S last, Comp comp = {}, Proj proj = {}); // since C++20
10321039
10331040 template<bidirectional_range R, class Comp = ranges::less, class Proj = identity>
10341041 requires sortable<iterator_t<R>, Comp, Proj>
1035 borrowed_iterator_t<R>
1042 constexpr borrowed_iterator_t<R> // constexpr since C++26
10361043 inplace_merge(R&& r, iterator_t<R> middle, Comp comp = {},
1037 Proj proj = {}); // since C++20
1044 Proj proj = {}); // since C++20
10381045
10391046 template<permutable I, sentinel_for<I> S, class Proj = identity,
10401047 indirect_equivalence_relation<projected<I, Proj>> C = ranges::equal_to>
......@@ -1165,84 +1172,84 @@ namespace ranges {
11651172}
11661173
11671174template <class InputIterator, class Predicate>
1168 constexpr bool // constexpr in C++20
1175 constexpr bool // constexpr since C++20
11691176 all_of(InputIterator first, InputIterator last, Predicate pred);
11701177
11711178template <class InputIterator, class Predicate>
1172 constexpr bool // constexpr in C++20
1179 constexpr bool // constexpr since C++20
11731180 any_of(InputIterator first, InputIterator last, Predicate pred);
11741181
11751182template <class InputIterator, class Predicate>
1176 constexpr bool // constexpr in C++20
1183 constexpr bool // constexpr since C++20
11771184 none_of(InputIterator first, InputIterator last, Predicate pred);
11781185
11791186template <class InputIterator, class Function>
1180 constexpr Function // constexpr in C++20
1187 constexpr Function // constexpr since C++20
11811188 for_each(InputIterator first, InputIterator last, Function f);
11821189
11831190template<class InputIterator, class Size, class Function>
1184 constexpr InputIterator // constexpr in C++20
1191 constexpr InputIterator // constexpr since C++20
11851192 for_each_n(InputIterator first, Size n, Function f); // C++17
11861193
11871194template <class InputIterator, class T>
1188 constexpr InputIterator // constexpr in C++20
1195 constexpr InputIterator // constexpr since C++20
11891196 find(InputIterator first, InputIterator last, const T& value);
11901197
11911198template <class InputIterator, class Predicate>
1192 constexpr InputIterator // constexpr in C++20
1199 constexpr InputIterator // constexpr since C++20
11931200 find_if(InputIterator first, InputIterator last, Predicate pred);
11941201
11951202template<class InputIterator, class Predicate>
1196 constexpr InputIterator // constexpr in C++20
1203 constexpr InputIterator // constexpr since C++20
11971204 find_if_not(InputIterator first, InputIterator last, Predicate pred);
11981205
11991206template <class ForwardIterator1, class ForwardIterator2>
1200 constexpr ForwardIterator1 // constexpr in C++20
1207 constexpr ForwardIterator1 // constexpr since C++20
12011208 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
12021209 ForwardIterator2 first2, ForwardIterator2 last2);
12031210
12041211template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
1205 constexpr ForwardIterator1 // constexpr in C++20
1212 constexpr ForwardIterator1 // constexpr since C++20
12061213 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
12071214 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
12081215
12091216template <class ForwardIterator1, class ForwardIterator2>
1210 constexpr ForwardIterator1 // constexpr in C++20
1217 constexpr ForwardIterator1 // constexpr since C++20
12111218 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
12121219 ForwardIterator2 first2, ForwardIterator2 last2);
12131220
12141221template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
1215 constexpr ForwardIterator1 // constexpr in C++20
1222 constexpr ForwardIterator1 // constexpr since C++20
12161223 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
12171224 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
12181225
12191226template <class ForwardIterator>
1220 constexpr ForwardIterator // constexpr in C++20
1227 constexpr ForwardIterator // constexpr since C++20
12211228 adjacent_find(ForwardIterator first, ForwardIterator last);
12221229
12231230template <class ForwardIterator, class BinaryPredicate>
1224 constexpr ForwardIterator // constexpr in C++20
1231 constexpr ForwardIterator // constexpr since C++20
12251232 adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
12261233
12271234template <class InputIterator, class T>
1228 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
1235 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr since C++20
12291236 count(InputIterator first, InputIterator last, const T& value);
12301237
12311238template <class InputIterator, class Predicate>
1232 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
1239 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr since C++20
12331240 count_if(InputIterator first, InputIterator last, Predicate pred);
12341241
12351242template <class InputIterator1, class InputIterator2>
1236 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
1243 constexpr pair<InputIterator1, InputIterator2> // constexpr since C++20
12371244 mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
12381245
12391246template <class InputIterator1, class InputIterator2>
12401247 constexpr pair<InputIterator1, InputIterator2>
12411248 mismatch(InputIterator1 first1, InputIterator1 last1,
1242 InputIterator2 first2, InputIterator2 last2); // since C++14, constexpr in C++20
1249 InputIterator2 first2, InputIterator2 last2); // since C++14, constexpr since C++20
12431250
12441251template <class InputIterator1, class InputIterator2, class BinaryPredicate>
1245 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
1252 constexpr pair<InputIterator1, InputIterator2> // constexpr since C++20
12461253 mismatch(InputIterator1 first1, InputIterator1 last1,
12471254 InputIterator2 first2, BinaryPredicate pred);
12481255
......@@ -1250,19 +1257,19 @@ template <class InputIterator1, class InputIterator2, class BinaryPredicate>
12501257 constexpr pair<InputIterator1, InputIterator2>
12511258 mismatch(InputIterator1 first1, InputIterator1 last1,
12521259 InputIterator2 first2, InputIterator2 last2,
1253 BinaryPredicate pred); // since C++14, constexpr in C++20
1260 BinaryPredicate pred); // since C++14, constexpr since C++20
12541261
12551262template <class InputIterator1, class InputIterator2>
1256 constexpr bool // constexpr in C++20
1263 constexpr bool // constexpr since C++20
12571264 equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
12581265
12591266template <class InputIterator1, class InputIterator2>
12601267 constexpr bool
12611268 equal(InputIterator1 first1, InputIterator1 last1,
1262 InputIterator2 first2, InputIterator2 last2); // since C++14, constexpr in C++20
1269 InputIterator2 first2, InputIterator2 last2); // since C++14, constexpr since C++20
12631270
12641271template <class InputIterator1, class InputIterator2, class BinaryPredicate>
1265 constexpr bool // constexpr in C++20
1272 constexpr bool // constexpr since C++20
12661273 equal(InputIterator1 first1, InputIterator1 last1,
12671274 InputIterator2 first2, BinaryPredicate pred);
12681275
......@@ -1270,20 +1277,20 @@ template <class InputIterator1, class InputIterator2, class BinaryPredicate>
12701277 constexpr bool
12711278 equal(InputIterator1 first1, InputIterator1 last1,
12721279 InputIterator2 first2, InputIterator2 last2,
1273 BinaryPredicate pred); // since C++14, constexpr in C++20
1280 BinaryPredicate pred); // since C++14, constexpr since C++20
12741281
12751282template<class ForwardIterator1, class ForwardIterator2>
1276 constexpr bool // constexpr in C++20
1283 constexpr bool // constexpr since C++20
12771284 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
12781285 ForwardIterator2 first2);
12791286
12801287template<class ForwardIterator1, class ForwardIterator2>
12811288 constexpr bool
12821289 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
1283 ForwardIterator2 first2, ForwardIterator2 last2); // since C++14, constexpr in C++20
1290 ForwardIterator2 first2, ForwardIterator2 last2); // since C++14, constexpr since C++20
12841291
12851292template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
1286 constexpr bool // constexpr in C++20
1293 constexpr bool // constexpr since C++20
12871294 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
12881295 ForwardIterator2 first2, BinaryPredicate pred);
12891296
......@@ -1291,42 +1298,42 @@ template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
12911298 constexpr bool
12921299 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
12931300 ForwardIterator2 first2, ForwardIterator2 last2,
1294 BinaryPredicate pred); // since C++14, constexpr in C++20
1301 BinaryPredicate pred); // since C++14, constexpr since C++20
12951302
12961303template <class ForwardIterator1, class ForwardIterator2>
1297 constexpr ForwardIterator1 // constexpr in C++20
1304 constexpr ForwardIterator1 // constexpr since C++20
12981305 search(ForwardIterator1 first1, ForwardIterator1 last1,
12991306 ForwardIterator2 first2, ForwardIterator2 last2);
13001307
13011308template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
1302 constexpr ForwardIterator1 // constexpr in C++20
1309 constexpr ForwardIterator1 // constexpr since C++20
13031310 search(ForwardIterator1 first1, ForwardIterator1 last1,
13041311 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
13051312
13061313template <class ForwardIterator, class Size, class T>
1307 constexpr ForwardIterator // constexpr in C++20
1314 constexpr ForwardIterator // constexpr since C++20
13081315 search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value);
13091316
13101317template <class ForwardIterator, class Size, class T, class BinaryPredicate>
1311 constexpr ForwardIterator // constexpr in C++20
1318 constexpr ForwardIterator // constexpr since C++20
13121319 search_n(ForwardIterator first, ForwardIterator last,
13131320 Size count, const T& value, BinaryPredicate pred);
13141321
13151322template <class InputIterator, class OutputIterator>
1316 constexpr OutputIterator // constexpr in C++20
1323 constexpr OutputIterator // constexpr since C++20
13171324 copy(InputIterator first, InputIterator last, OutputIterator result);
13181325
13191326template<class InputIterator, class OutputIterator, class Predicate>
1320 constexpr OutputIterator // constexpr in C++20
1327 constexpr OutputIterator // constexpr since C++20
13211328 copy_if(InputIterator first, InputIterator last,
13221329 OutputIterator result, Predicate pred);
13231330
13241331template<class InputIterator, class Size, class OutputIterator>
1325 constexpr OutputIterator // constexpr in C++20
1332 constexpr OutputIterator // constexpr since C++20
13261333 copy_n(InputIterator first, Size n, OutputIterator result);
13271334
13281335template <class BidirectionalIterator1, class BidirectionalIterator2>
1329 constexpr BidirectionalIterator2 // constexpr in C++20
1336 constexpr BidirectionalIterator2 // constexpr since C++20
13301337 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
13311338 BidirectionalIterator2 result);
13321339
......@@ -1341,7 +1348,7 @@ template<class BidirectionalIterator1, class BidirectionalIterator2>
13411348 BidirectionalIterator2 result);
13421349
13431350template <class ForwardIterator1, class ForwardIterator2>
1344 constexpr ForwardIterator2 // constexpr in C++20
1351 constexpr ForwardIterator2 // constexpr since C++20
13451352 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);
13461353
13471354namespace ranges {
......@@ -1360,97 +1367,97 @@ template<input_range R1, input_range R2>
13601367}
13611368
13621369template <class ForwardIterator1, class ForwardIterator2>
1363 constexpr void // constexpr in C++20
1370 constexpr void // constexpr since C++20
13641371 iter_swap(ForwardIterator1 a, ForwardIterator2 b);
13651372
13661373template <class InputIterator, class OutputIterator, class UnaryOperation>
1367 constexpr OutputIterator // constexpr in C++20
1374 constexpr OutputIterator // constexpr since C++20
13681375 transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op);
13691376
13701377template <class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperation>
1371 constexpr OutputIterator // constexpr in C++20
1378 constexpr OutputIterator // constexpr since C++20
13721379 transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
13731380 OutputIterator result, BinaryOperation binary_op);
13741381
13751382template <class ForwardIterator, class T>
1376 constexpr void // constexpr in C++20
1383 constexpr void // constexpr since C++20
13771384 replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value);
13781385
13791386template <class ForwardIterator, class Predicate, class T>
1380 constexpr void // constexpr in C++20
1387 constexpr void // constexpr since C++20
13811388 replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value);
13821389
13831390template <class InputIterator, class OutputIterator, class T>
1384 constexpr OutputIterator // constexpr in C++20
1391 constexpr OutputIterator // constexpr since C++20
13851392 replace_copy(InputIterator first, InputIterator last, OutputIterator result,
13861393 const T& old_value, const T& new_value);
13871394
13881395template <class InputIterator, class OutputIterator, class Predicate, class T>
1389 constexpr OutputIterator // constexpr in C++20
1396 constexpr OutputIterator // constexpr since C++20
13901397 replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value);
13911398
13921399template <class ForwardIterator, class T>
1393 constexpr void // constexpr in C++20
1400 constexpr void // constexpr since C++20
13941401 fill(ForwardIterator first, ForwardIterator last, const T& value);
13951402
13961403template <class OutputIterator, class Size, class T>
1397 constexpr OutputIterator // constexpr in C++20
1404 constexpr OutputIterator // constexpr since C++20
13981405 fill_n(OutputIterator first, Size n, const T& value);
13991406
14001407template <class ForwardIterator, class Generator>
1401 constexpr void // constexpr in C++20
1408 constexpr void // constexpr since C++20
14021409 generate(ForwardIterator first, ForwardIterator last, Generator gen);
14031410
14041411template <class OutputIterator, class Size, class Generator>
1405 constexpr OutputIterator // constexpr in C++20
1412 constexpr OutputIterator // constexpr since C++20
14061413 generate_n(OutputIterator first, Size n, Generator gen);
14071414
14081415template <class ForwardIterator, class T>
1409 constexpr ForwardIterator // constexpr in C++20
1416 constexpr ForwardIterator // constexpr since C++20
14101417 remove(ForwardIterator first, ForwardIterator last, const T& value);
14111418
14121419template <class ForwardIterator, class Predicate>
1413 constexpr ForwardIterator // constexpr in C++20
1420 constexpr ForwardIterator // constexpr since C++20
14141421 remove_if(ForwardIterator first, ForwardIterator last, Predicate pred);
14151422
14161423template <class InputIterator, class OutputIterator, class T>
1417 constexpr OutputIterator // constexpr in C++20
1424 constexpr OutputIterator // constexpr since C++20
14181425 remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value);
14191426
14201427template <class InputIterator, class OutputIterator, class Predicate>
1421 constexpr OutputIterator // constexpr in C++20
1428 constexpr OutputIterator // constexpr since C++20
14221429 remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);
14231430
14241431template <class ForwardIterator>
1425 constexpr ForwardIterator // constexpr in C++20
1432 constexpr ForwardIterator // constexpr since C++20
14261433 unique(ForwardIterator first, ForwardIterator last);
14271434
14281435template <class ForwardIterator, class BinaryPredicate>
1429 constexpr ForwardIterator // constexpr in C++20
1436 constexpr ForwardIterator // constexpr since C++20
14301437 unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
14311438
14321439template <class InputIterator, class OutputIterator>
1433 constexpr OutputIterator // constexpr in C++20
1440 constexpr OutputIterator // constexpr since C++20
14341441 unique_copy(InputIterator first, InputIterator last, OutputIterator result);
14351442
14361443template <class InputIterator, class OutputIterator, class BinaryPredicate>
1437 constexpr OutputIterator // constexpr in C++20
1444 constexpr OutputIterator // constexpr since C++20
14381445 unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred);
14391446
14401447template <class BidirectionalIterator>
1441 constexpr void // constexpr in C++20
1448 constexpr void // constexpr since C++20
14421449 reverse(BidirectionalIterator first, BidirectionalIterator last);
14431450
14441451template <class BidirectionalIterator, class OutputIterator>
1445 constexpr OutputIterator // constexpr in C++20
1452 constexpr OutputIterator // constexpr since C++20
14461453 reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result);
14471454
14481455template <class ForwardIterator>
1449 constexpr ForwardIterator // constexpr in C++20
1456 constexpr ForwardIterator // constexpr since C++20
14501457 rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
14511458
14521459template <class ForwardIterator, class OutputIterator>
1453 constexpr OutputIterator // constexpr in C++20
1460 constexpr OutputIterator // constexpr since C++20
14541461 rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result);
14551462
14561463template <class RandomAccessIterator>
......@@ -1483,254 +1490,254 @@ template<class ForwardIterator>
14831490 typename iterator_traits<ForwardIterator>::difference_type n); // C++20
14841491
14851492template <class InputIterator, class Predicate>
1486 constexpr bool // constexpr in C++20
1493 constexpr bool // constexpr since C++20
14871494 is_partitioned(InputIterator first, InputIterator last, Predicate pred);
14881495
14891496template <class ForwardIterator, class Predicate>
1490 constexpr ForwardIterator // constexpr in C++20
1497 constexpr ForwardIterator // constexpr since C++20
14911498 partition(ForwardIterator first, ForwardIterator last, Predicate pred);
14921499
14931500template <class InputIterator, class OutputIterator1,
14941501 class OutputIterator2, class Predicate>
1495 constexpr pair<OutputIterator1, OutputIterator2> // constexpr in C++20
1502 constexpr pair<OutputIterator1, OutputIterator2> // constexpr since C++20
14961503 partition_copy(InputIterator first, InputIterator last,
14971504 OutputIterator1 out_true, OutputIterator2 out_false,
14981505 Predicate pred);
14991506
15001507template <class ForwardIterator, class Predicate>
1501 ForwardIterator
1508 constexpr ForwardIterator // constexpr since C++26
15021509 stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred);
15031510
15041511template<class ForwardIterator, class Predicate>
1505 constexpr ForwardIterator // constexpr in C++20
1512 constexpr ForwardIterator // constexpr since C++20
15061513 partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
15071514
15081515template <class ForwardIterator>
1509 constexpr bool // constexpr in C++20
1516 constexpr bool // constexpr since C++20
15101517 is_sorted(ForwardIterator first, ForwardIterator last);
15111518
15121519template <class ForwardIterator, class Compare>
1513 constexpr bool // constexpr in C++20
1520 constexpr bool // constexpr since C++20
15141521 is_sorted(ForwardIterator first, ForwardIterator last, Compare comp);
15151522
15161523template<class ForwardIterator>
1517 constexpr ForwardIterator // constexpr in C++20
1524 constexpr ForwardIterator // constexpr since C++20
15181525 is_sorted_until(ForwardIterator first, ForwardIterator last);
15191526
15201527template <class ForwardIterator, class Compare>
1521 constexpr ForwardIterator // constexpr in C++20
1528 constexpr ForwardIterator // constexpr since C++20
15221529 is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp);
15231530
15241531template <class RandomAccessIterator>
1525 constexpr void // constexpr in C++20
1532 constexpr void // constexpr since C++20
15261533 sort(RandomAccessIterator first, RandomAccessIterator last);
15271534
15281535template <class RandomAccessIterator, class Compare>
1529 constexpr void // constexpr in C++20
1536 constexpr void // constexpr since C++20
15301537 sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
15311538
15321539template <class RandomAccessIterator>
1533 constexpr void // constexpr in C++26
1540 constexpr void // constexpr since C++26
15341541 stable_sort(RandomAccessIterator first, RandomAccessIterator last);
15351542
15361543template <class RandomAccessIterator, class Compare>
1537 constexpr void // constexpr in C++26
1544 constexpr void // constexpr since C++26
15381545 stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
15391546
15401547template <class RandomAccessIterator>
1541 constexpr void // constexpr in C++20
1548 constexpr void // constexpr since C++20
15421549 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last);
15431550
15441551template <class RandomAccessIterator, class Compare>
1545 constexpr void // constexpr in C++20
1552 constexpr void // constexpr since C++20
15461553 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp);
15471554
15481555template <class InputIterator, class RandomAccessIterator>
1549 constexpr RandomAccessIterator // constexpr in C++20
1556 constexpr RandomAccessIterator // constexpr since C++20
15501557 partial_sort_copy(InputIterator first, InputIterator last,
15511558 RandomAccessIterator result_first, RandomAccessIterator result_last);
15521559
15531560template <class InputIterator, class RandomAccessIterator, class Compare>
1554 constexpr RandomAccessIterator // constexpr in C++20
1561 constexpr RandomAccessIterator // constexpr since C++20
15551562 partial_sort_copy(InputIterator first, InputIterator last,
15561563 RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp);
15571564
15581565template <class RandomAccessIterator>
1559 constexpr void // constexpr in C++20
1566 constexpr void // constexpr since C++20
15601567 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last);
15611568
15621569template <class RandomAccessIterator, class Compare>
1563 constexpr void // constexpr in C++20
1570 constexpr void // constexpr since C++20
15641571 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp);
15651572
15661573template <class ForwardIterator, class T>
1567 constexpr ForwardIterator // constexpr in C++20
1574 constexpr ForwardIterator // constexpr since C++20
15681575 lower_bound(ForwardIterator first, ForwardIterator last, const T& value);
15691576
15701577template <class ForwardIterator, class T, class Compare>
1571 constexpr ForwardIterator // constexpr in C++20
1578 constexpr ForwardIterator // constexpr since C++20
15721579 lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
15731580
15741581template <class ForwardIterator, class T>
1575 constexpr ForwardIterator // constexpr in C++20
1582 constexpr ForwardIterator // constexpr since C++20
15761583 upper_bound(ForwardIterator first, ForwardIterator last, const T& value);
15771584
15781585template <class ForwardIterator, class T, class Compare>
1579 constexpr ForwardIterator // constexpr in C++20
1586 constexpr ForwardIterator // constexpr since C++20
15801587 upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
15811588
15821589template <class ForwardIterator, class T>
1583 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
1590 constexpr pair<ForwardIterator, ForwardIterator> // constexpr since C++20
15841591 equal_range(ForwardIterator first, ForwardIterator last, const T& value);
15851592
15861593template <class ForwardIterator, class T, class Compare>
1587 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
1594 constexpr pair<ForwardIterator, ForwardIterator> // constexpr since C++20
15881595 equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
15891596
15901597template <class ForwardIterator, class T>
1591 constexpr bool // constexpr in C++20
1598 constexpr bool // constexpr since C++20
15921599 binary_search(ForwardIterator first, ForwardIterator last, const T& value);
15931600
15941601template <class ForwardIterator, class T, class Compare>
1595 constexpr bool // constexpr in C++20
1602 constexpr bool // constexpr since C++20
15961603 binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
15971604
15981605template <class InputIterator1, class InputIterator2, class OutputIterator>
1599 constexpr OutputIterator // constexpr in C++20
1606 constexpr OutputIterator // constexpr since C++20
16001607 merge(InputIterator1 first1, InputIterator1 last1,
16011608 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
16021609
16031610template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
1604 constexpr OutputIterator // constexpr in C++20
1611 constexpr OutputIterator // constexpr since C++20
16051612 merge(InputIterator1 first1, InputIterator1 last1,
16061613 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
16071614
16081615template <class BidirectionalIterator>
1609 void
1616 constexpr void // constexpr since C++26
16101617 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last);
16111618
16121619template <class BidirectionalIterator, class Compare>
1613 void
1620 constexpr void // constexpr since C++26
16141621 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp);
16151622
16161623template <class InputIterator1, class InputIterator2>
1617 constexpr bool // constexpr in C++20
1624 constexpr bool // constexpr since C++20
16181625 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
16191626
16201627template <class InputIterator1, class InputIterator2, class Compare>
1621 constexpr bool // constexpr in C++20
1628 constexpr bool // constexpr since C++20
16221629 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp);
16231630
16241631template <class InputIterator1, class InputIterator2, class OutputIterator>
1625 constexpr OutputIterator // constexpr in C++20
1632 constexpr OutputIterator // constexpr since C++20
16261633 set_union(InputIterator1 first1, InputIterator1 last1,
16271634 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
16281635
16291636template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
1630 constexpr OutputIterator // constexpr in C++20
1637 constexpr OutputIterator // constexpr since C++20
16311638 set_union(InputIterator1 first1, InputIterator1 last1,
16321639 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
16331640
16341641template <class InputIterator1, class InputIterator2, class OutputIterator>
1635 constexpr OutputIterator // constexpr in C++20
1642 constexpr OutputIterator // constexpr since C++20
16361643 set_intersection(InputIterator1 first1, InputIterator1 last1,
16371644 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
16381645
16391646template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
1640 constexpr OutputIterator // constexpr in C++20
1647 constexpr OutputIterator // constexpr since C++20
16411648 set_intersection(InputIterator1 first1, InputIterator1 last1,
16421649 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
16431650
16441651template <class InputIterator1, class InputIterator2, class OutputIterator>
1645 constexpr OutputIterator // constexpr in C++20
1652 constexpr OutputIterator // constexpr since C++20
16461653 set_difference(InputIterator1 first1, InputIterator1 last1,
16471654 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
16481655
16491656template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
1650 constexpr OutputIterator // constexpr in C++20
1657 constexpr OutputIterator // constexpr since C++20
16511658 set_difference(InputIterator1 first1, InputIterator1 last1,
16521659 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
16531660
16541661template <class InputIterator1, class InputIterator2, class OutputIterator>
1655 constexpr OutputIterator // constexpr in C++20
1662 constexpr OutputIterator // constexpr since C++20
16561663 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
16571664 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
16581665
16591666template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
1660 constexpr OutputIterator // constexpr in C++20
1667 constexpr OutputIterator // constexpr since C++20
16611668 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
16621669 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
16631670
16641671template <class RandomAccessIterator>
1665 constexpr void // constexpr in C++20
1672 constexpr void // constexpr since C++20
16661673 push_heap(RandomAccessIterator first, RandomAccessIterator last);
16671674
16681675template <class RandomAccessIterator, class Compare>
1669 constexpr void // constexpr in C++20
1676 constexpr void // constexpr since C++20
16701677 push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
16711678
16721679template <class RandomAccessIterator>
1673 constexpr void // constexpr in C++20
1680 constexpr void // constexpr since C++20
16741681 pop_heap(RandomAccessIterator first, RandomAccessIterator last);
16751682
16761683template <class RandomAccessIterator, class Compare>
1677 constexpr void // constexpr in C++20
1684 constexpr void // constexpr since C++20
16781685 pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
16791686
16801687template <class RandomAccessIterator>
1681 constexpr void // constexpr in C++20
1688 constexpr void // constexpr since C++20
16821689 make_heap(RandomAccessIterator first, RandomAccessIterator last);
16831690
16841691template <class RandomAccessIterator, class Compare>
1685 constexpr void // constexpr in C++20
1692 constexpr void // constexpr since C++20
16861693 make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
16871694
16881695template <class RandomAccessIterator>
1689 constexpr void // constexpr in C++20
1696 constexpr void // constexpr since C++20
16901697 sort_heap(RandomAccessIterator first, RandomAccessIterator last);
16911698
16921699template <class RandomAccessIterator, class Compare>
1693 constexpr void // constexpr in C++20
1700 constexpr void // constexpr since C++20
16941701 sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
16951702
16961703template <class RandomAccessIterator>
1697 constexpr bool // constexpr in C++20
1704 constexpr bool // constexpr since C++20
16981705 is_heap(RandomAccessIterator first, RandomAccessiterator last);
16991706
17001707template <class RandomAccessIterator, class Compare>
1701 constexpr bool // constexpr in C++20
1708 constexpr bool // constexpr since C++20
17021709 is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
17031710
17041711template <class RandomAccessIterator>
1705 constexpr RandomAccessIterator // constexpr in C++20
1712 constexpr RandomAccessIterator // constexpr since C++20
17061713 is_heap_until(RandomAccessIterator first, RandomAccessiterator last);
17071714
17081715template <class RandomAccessIterator, class Compare>
1709 constexpr RandomAccessIterator // constexpr in C++20
1716 constexpr RandomAccessIterator // constexpr since C++20
17101717 is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
17111718
17121719template <class ForwardIterator>
1713 constexpr ForwardIterator // constexpr in C++14
1720 constexpr ForwardIterator // constexpr since C++14
17141721 min_element(ForwardIterator first, ForwardIterator last);
17151722
17161723template <class ForwardIterator, class Compare>
1717 constexpr ForwardIterator // constexpr in C++14
1724 constexpr ForwardIterator // constexpr since C++14
17181725 min_element(ForwardIterator first, ForwardIterator last, Compare comp);
17191726
17201727template <class T>
1721 constexpr const T& // constexpr in C++14
1728 constexpr const T& // constexpr since C++14
17221729 min(const T& a, const T& b);
17231730
17241731template <class T, class Compare>
1725 constexpr const T& // constexpr in C++14
1732 constexpr const T& // constexpr since C++14
17261733 min(const T& a, const T& b, Compare comp);
17271734
17281735template<class T>
1729 constexpr T // constexpr in C++14
1736 constexpr T // constexpr since C++14
17301737 min(initializer_list<T> t);
17311738
17321739template<class T, class Compare>
1733 constexpr T // constexpr in C++14
1740 constexpr T // constexpr since C++14
17341741 min(initializer_list<T> t, Compare comp);
17351742
17361743template<class T>
......@@ -1740,59 +1747,59 @@ template<class T, class Compare>
17401747 constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp); // C++17
17411748
17421749template <class ForwardIterator>
1743 constexpr ForwardIterator // constexpr in C++14
1750 constexpr ForwardIterator // constexpr since C++14
17441751 max_element(ForwardIterator first, ForwardIterator last);
17451752
17461753template <class ForwardIterator, class Compare>
1747 constexpr ForwardIterator // constexpr in C++14
1754 constexpr ForwardIterator // constexpr since C++14
17481755 max_element(ForwardIterator first, ForwardIterator last, Compare comp);
17491756
17501757template <class T>
1751 constexpr const T& // constexpr in C++14
1758 constexpr const T& // constexpr since C++14
17521759 max(const T& a, const T& b);
17531760
17541761template <class T, class Compare>
1755 constexpr const T& // constexpr in C++14
1762 constexpr const T& // constexpr since C++14
17561763 max(const T& a, const T& b, Compare comp);
17571764
17581765template<class T>
1759 constexpr T // constexpr in C++14
1766 constexpr T // constexpr since C++14
17601767 max(initializer_list<T> t);
17611768
17621769template<class T, class Compare>
1763 constexpr T // constexpr in C++14
1770 constexpr T // constexpr since C++14
17641771 max(initializer_list<T> t, Compare comp);
17651772
17661773template<class ForwardIterator>
1767 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14
1774 constexpr pair<ForwardIterator, ForwardIterator> // constexpr since C++14
17681775 minmax_element(ForwardIterator first, ForwardIterator last);
17691776
17701777template<class ForwardIterator, class Compare>
1771 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14
1778 constexpr pair<ForwardIterator, ForwardIterator> // constexpr since C++14
17721779 minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
17731780
17741781template<class T>
1775 constexpr pair<const T&, const T&> // constexpr in C++14
1782 constexpr pair<const T&, const T&> // constexpr since C++14
17761783 minmax(const T& a, const T& b);
17771784
17781785template<class T, class Compare>
1779 constexpr pair<const T&, const T&> // constexpr in C++14
1786 constexpr pair<const T&, const T&> // constexpr since C++14
17801787 minmax(const T& a, const T& b, Compare comp);
17811788
17821789template<class T>
1783 constexpr pair<T, T> // constexpr in C++14
1790 constexpr pair<T, T> // constexpr since C++14
17841791 minmax(initializer_list<T> t);
17851792
17861793template<class T, class Compare>
1787 constexpr pair<T, T> // constexpr in C++14
1794 constexpr pair<T, T> // constexpr since C++14
17881795 minmax(initializer_list<T> t, Compare comp);
17891796
17901797template <class InputIterator1, class InputIterator2>
1791 constexpr bool // constexpr in C++20
1798 constexpr bool // constexpr since C++20
17921799 lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
17931800
17941801template <class InputIterator1, class InputIterator2, class Compare>
1795 constexpr bool // constexpr in C++20
1802 constexpr bool // constexpr since C++20
17961803 lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
17971804 InputIterator2 first2, InputIterator2 last2, Compare comp);
17981805
......@@ -1809,19 +1816,19 @@ template<class InputIterator1, class InputIterator2>
18091816 InputIterator2 first2, InputIterator2 last2); // since C++20
18101817
18111818template <class BidirectionalIterator>
1812 constexpr bool // constexpr in C++20
1819 constexpr bool // constexpr since C++20
18131820 next_permutation(BidirectionalIterator first, BidirectionalIterator last);
18141821
18151822template <class BidirectionalIterator, class Compare>
1816 constexpr bool // constexpr in C++20
1823 constexpr bool // constexpr since C++20
18171824 next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
18181825
18191826template <class BidirectionalIterator>
1820 constexpr bool // constexpr in C++20
1827 constexpr bool // constexpr since C++20
18211828 prev_permutation(BidirectionalIterator first, BidirectionalIterator last);
18221829
18231830template <class BidirectionalIterator, class Compare>
1824 constexpr bool // constexpr in C++20
1831 constexpr bool // constexpr since C++20
18251832 prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
18261833} // std
18271834
......@@ -1932,6 +1939,7 @@ template <class BidirectionalIterator, class Compare>
19321939# include <__algorithm/in_out_result.h>
19331940# include <__algorithm/lexicographical_compare_three_way.h>
19341941# include <__algorithm/min_max_result.h>
1942# include <__algorithm/out_value_result.h>
19351943# include <__algorithm/ranges_adjacent_find.h>
19361944# include <__algorithm/ranges_all_of.h>
19371945# include <__algorithm/ranges_any_of.h>
......@@ -2053,6 +2061,7 @@ template <class BidirectionalIterator, class Compare>
20532061# include <cstring>
20542062# include <iterator>
20552063# include <memory>
2064# include <optional>
20562065# include <stdexcept>
20572066# include <type_traits>
20582067# include <utility>
lib/libcxx/include/any+16-16
......@@ -81,7 +81,7 @@ namespace std {
8181*/
8282
8383#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
84# include <__cxx03/any>
84# include <__cxx03/__config>
8585#else
8686# include <__config>
8787# include <__memory/allocator.h>
......@@ -119,18 +119,18 @@ namespace std {
119119_LIBCPP_PUSH_MACROS
120120# include <__undef_macros>
121121
122namespace std {
123class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_BAD_ANY_CAST bad_any_cast : public bad_cast {
122_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
123class _LIBCPP_EXPORTED_FROM_ABI bad_any_cast : public bad_cast {
124124public:
125125 const char* what() const _NOEXCEPT override;
126126};
127} // namespace std
127_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
128128
129129_LIBCPP_BEGIN_NAMESPACE_STD
130130
131131# if _LIBCPP_STD_VER >= 17
132132
133[[noreturn]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST void __throw_bad_any_cast() {
133[[noreturn]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_any_cast() {
134134# if _LIBCPP_HAS_EXCEPTIONS
135135 throw bad_any_cast();
136136# else
......@@ -139,7 +139,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
139139}
140140
141141// Forward declarations
142class _LIBCPP_TEMPLATE_VIS any;
142class any;
143143
144144template <class _ValueType>
145145_LIBCPP_HIDE_FROM_ABI add_pointer_t<add_const_t<_ValueType>> any_cast(any const*) _NOEXCEPT;
......@@ -166,7 +166,7 @@ template <class _Tp>
166166struct _LargeHandler;
167167
168168template <class _Tp>
169struct _LIBCPP_TEMPLATE_VIS __unique_typeinfo {
169struct __unique_typeinfo {
170170 static constexpr int __id = 0;
171171};
172172
......@@ -189,7 +189,7 @@ using _Handler _LIBCPP_NODEBUG = conditional_t< _IsSmallObject<_Tp>::value, _Sma
189189
190190} // namespace __any_imp
191191
192class _LIBCPP_TEMPLATE_VIS any {
192class any {
193193public:
194194 // construct/destruct
195195 _LIBCPP_HIDE_FROM_ABI constexpr any() _NOEXCEPT : __h_(nullptr) {}
......@@ -316,7 +316,7 @@ private:
316316
317317namespace __any_imp {
318318template <class _Tp>
319struct _LIBCPP_TEMPLATE_VIS _SmallHandler {
319struct _SmallHandler {
320320 _LIBCPP_HIDE_FROM_ABI static void*
321321 __handle(_Action __act, any const* __this, any* __other, type_info const* __info, const void* __fallback_info) {
322322 switch (__act) {
......@@ -383,7 +383,7 @@ private:
383383};
384384
385385template <class _Tp>
386struct _LIBCPP_TEMPLATE_VIS _LargeHandler {
386struct _LargeHandler {
387387 _LIBCPP_HIDE_FROM_ABI static void*
388388 __handle(_Action __act, any const* __this, any* __other, type_info const* __info, void const* __fallback_info) {
389389 switch (__act) {
......@@ -519,38 +519,38 @@ inline _LIBCPP_HIDE_FROM_ABI any make_any(initializer_list<_Up> __il, _Args&&...
519519}
520520
521521template <class _ValueType>
522inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType any_cast(any const& __v) {
522inline _LIBCPP_HIDE_FROM_ABI _ValueType any_cast(any const& __v) {
523523 using _RawValueType = __remove_cvref_t<_ValueType>;
524524 static_assert(is_constructible<_ValueType, _RawValueType const&>::value,
525525 "ValueType is required to be a const lvalue reference "
526526 "or a CopyConstructible type");
527527 auto __tmp = std::any_cast<add_const_t<_RawValueType>>(&__v);
528528 if (__tmp == nullptr)
529 __throw_bad_any_cast();
529 std::__throw_bad_any_cast();
530530 return static_cast<_ValueType>(*__tmp);
531531}
532532
533533template <class _ValueType>
534inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType any_cast(any& __v) {
534inline _LIBCPP_HIDE_FROM_ABI _ValueType any_cast(any& __v) {
535535 using _RawValueType = __remove_cvref_t<_ValueType>;
536536 static_assert(is_constructible<_ValueType, _RawValueType&>::value,
537537 "ValueType is required to be an lvalue reference "
538538 "or a CopyConstructible type");
539539 auto __tmp = std::any_cast<_RawValueType>(&__v);
540540 if (__tmp == nullptr)
541 __throw_bad_any_cast();
541 std::__throw_bad_any_cast();
542542 return static_cast<_ValueType>(*__tmp);
543543}
544544
545545template <class _ValueType>
546inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType any_cast(any&& __v) {
546inline _LIBCPP_HIDE_FROM_ABI _ValueType any_cast(any&& __v) {
547547 using _RawValueType = __remove_cvref_t<_ValueType>;
548548 static_assert(is_constructible<_ValueType, _RawValueType>::value,
549549 "ValueType is required to be an rvalue reference "
550550 "or a CopyConstructible type");
551551 auto __tmp = std::any_cast<_RawValueType>(&__v);
552552 if (__tmp == nullptr)
553 __throw_bad_any_cast();
553 std::__throw_bad_any_cast();
554554 return static_cast<_ValueType>(std::move(*__tmp));
555555}
556556
lib/libcxx/include/array+12-9
......@@ -134,6 +134,7 @@ template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexce
134134# include <__type_traits/is_const.h>
135135# include <__type_traits/is_constructible.h>
136136# include <__type_traits/is_nothrow_constructible.h>
137# include <__type_traits/is_replaceable.h>
137138# include <__type_traits/is_same.h>
138139# include <__type_traits/is_swappable.h>
139140# include <__type_traits/is_trivially_relocatable.h>
......@@ -172,9 +173,10 @@ _LIBCPP_PUSH_MACROS
172173_LIBCPP_BEGIN_NAMESPACE_STD
173174
174175template <class _Tp, size_t _Size>
175struct _LIBCPP_TEMPLATE_VIS array {
176struct array {
176177 using __trivially_relocatable _LIBCPP_NODEBUG =
177178 __conditional_t<__libcpp_is_trivially_relocatable<_Tp>::value, array, void>;
179 using __replaceable _LIBCPP_NODEBUG = __conditional_t<__is_replaceable_v<_Tp>, array, void>;
178180
179181 // types:
180182 using __self _LIBCPP_NODEBUG = array;
......@@ -276,13 +278,13 @@ struct _LIBCPP_TEMPLATE_VIS array {
276278
277279 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference at(size_type __n) {
278280 if (__n >= _Size)
279 __throw_out_of_range("array::at");
281 std::__throw_out_of_range("array::at");
280282 return __elems_[__n];
281283 }
282284
283285 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference at(size_type __n) const {
284286 if (__n >= _Size)
285 __throw_out_of_range("array::at");
287 std::__throw_out_of_range("array::at");
286288 return __elems_[__n];
287289 }
288290
......@@ -298,7 +300,7 @@ struct _LIBCPP_TEMPLATE_VIS array {
298300};
299301
300302template <class _Tp>
301struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> {
303struct array<_Tp, 0> {
302304 // types:
303305 using __self _LIBCPP_NODEBUG = array;
304306 using value_type = _Tp;
......@@ -407,12 +409,12 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> {
407409 }
408410
409411 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference at(size_type) {
410 __throw_out_of_range("array<T, 0>::at");
412 std::__throw_out_of_range("array<T, 0>::at");
411413 __libcpp_unreachable();
412414 }
413415
414416 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference at(size_type) const {
415 __throw_out_of_range("array<T, 0>::at");
417 std::__throw_out_of_range("array<T, 0>::at");
416418 __libcpp_unreachable();
417419 }
418420
......@@ -492,12 +494,12 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(array<_Tp,
492494}
493495
494496template <class _Tp, size_t _Size>
495struct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> > : public integral_constant<size_t, _Size> {};
497struct tuple_size<array<_Tp, _Size> > : public integral_constant<size_t, _Size> {};
496498
497499template <size_t _Ip, class _Tp, size_t _Size>
498struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > {
500struct tuple_element<_Ip, array<_Tp, _Size> > {
499501 static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
500 using type = _Tp;
502 using type _LIBCPP_NODEBUG = _Tp;
501503};
502504
503505template <size_t _Ip, class _Tp, size_t _Size>
......@@ -566,6 +568,7 @@ _LIBCPP_POP_MACROS
566568# include <cstdlib>
567569# include <iterator>
568570# include <new>
571# include <optional>
569572# include <type_traits>
570573# include <utility>
571574# endif
lib/libcxx/include/barrier+1-1
......@@ -46,7 +46,7 @@ namespace std
4646*/
4747
4848#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
49# include <__cxx03/barrier>
49# include <__cxx03/__config>
5050#else
5151# include <__config>
5252
lib/libcxx/include/bit+1-1
......@@ -62,7 +62,7 @@ namespace std {
6262*/
6363
6464#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
65# include <__cxx03/bit>
65# include <__cxx03/__config>
6666#else
6767# include <__config>
6868
lib/libcxx/include/bitset+183-199
......@@ -129,18 +129,29 @@ template <size_t N> struct hash<std::bitset<N>>;
129129#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
130130# include <__cxx03/bitset>
131131#else
132# include <__algorithm/copy.h>
133# include <__algorithm/copy_backward.h>
132134# include <__algorithm/count.h>
135# include <__algorithm/equal.h>
133136# include <__algorithm/fill.h>
134137# include <__algorithm/fill_n.h>
135138# include <__algorithm/find.h>
139# include <__algorithm/min.h>
136140# include <__assert>
141# include <__bit/countr.h>
142# include <__bit/invert_if.h>
137143# include <__bit_reference>
138144# include <__config>
139145# include <__cstddef/ptrdiff_t.h>
140146# include <__cstddef/size_t.h>
141147# include <__functional/hash.h>
148# include <__functional/identity.h>
142149# include <__functional/unary_function.h>
150# include <__tuple/tuple_indices.h>
151# include <__type_traits/enable_if.h>
152# include <__type_traits/integral_constant.h>
143153# include <__type_traits/is_char_like_type.h>
154# include <__utility/integer_sequence.h>
144155# include <climits>
145156# include <stdexcept>
146157# include <string_view>
......@@ -214,28 +225,98 @@ protected:
214225 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset& __v) _NOEXCEPT;
215226
216227 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT;
228
217229 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const {
218 return to_ulong(integral_constant < bool, _Size< sizeof(unsigned long) * CHAR_BIT>());
230 if _LIBCPP_CONSTEXPR (_Size > sizeof(unsigned long) * CHAR_BIT) {
231 if (auto __e = __make_iter(_Size); std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true) != __e)
232 std::__throw_overflow_error("__bitset<_N_words, _Size>::to_ulong overflow error");
233 }
234
235 static_assert(sizeof(__storage_type) >= sizeof(unsigned long),
236 "libc++ only supports platforms where sizeof(size_t) >= sizeof(unsigned long), such as 32-bit and "
237 "64-bit platforms. If you're interested in supporting a platform where that is not the case, please "
238 "contact the libc++ developers.");
239 return static_cast<unsigned long>(__first_[0]);
219240 }
241
220242 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const {
221 return to_ullong(integral_constant < bool, _Size< sizeof(unsigned long long) * CHAR_BIT>());
243 // Check for overflow if _Size does not fit in unsigned long long
244 if _LIBCPP_CONSTEXPR (_Size > sizeof(unsigned long long) * CHAR_BIT) {
245 if (auto __e = __make_iter(_Size);
246 std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true) != __e)
247 std::__throw_overflow_error("__bitset<_N_words, _Size>::to_ullong overflow error");
248 }
249
250 // At this point, the effective bitset size (excluding leading zeros) fits in unsigned long long
251
252 if _LIBCPP_CONSTEXPR (sizeof(__storage_type) >= sizeof(unsigned long long)) {
253 // If __storage_type is at least as large as unsigned long long, the result spans only one word
254 return static_cast<unsigned long long>(__first_[0]);
255 } else {
256 // Otherwise, the result spans multiple words which are concatenated
257 const size_t __ull_words = (sizeof(unsigned long long) - 1) / sizeof(__storage_type) + 1;
258 const size_t __n_words = _N_words < __ull_words ? _N_words : __ull_words;
259 unsigned long long __r = static_cast<unsigned long long>(__first_[0]);
260 for (size_t __i = 1; __i < __n_words; ++__i)
261 __r |= static_cast<unsigned long long>(__first_[__i]) << (__bits_per_word * __i);
262 return __r;
263 }
222264 }
223265
224 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
225 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
266 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT { return !__scan_bits(__bit_not()); }
267 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT {
268 return __scan_bits(std::__identity());
269 }
226270 _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;
227271
272 template <bool _Sparse, class _CharT, class _Traits, class _Allocator>
273 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>
274 __to_string(_CharT __zero, _CharT __one) const {
275 basic_string<_CharT, _Traits, _Allocator> __r(_Size, _Sparse ? __zero : __one);
276 for (size_t __i = 0, __bits = 0; __i < _N_words; ++__i, __bits += __bits_per_word) {
277 __storage_type __word = std::__invert_if<!_Sparse>(__first_[__i]);
278 if (__i == _N_words - 1 && _Size - __bits < __bits_per_word)
279 __word &= (__storage_type(1) << (_Size - __bits)) - 1;
280 for (; __word; __word &= (__word - 1))
281 __r[_Size - 1 - (__bits + std::__countr_zero(__word))] = _Sparse ? __one : __zero;
282 }
283
284 return __r;
285 }
286
228287private:
288 struct __bit_not {
289 template <class _Tp>
290 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp operator()(const _Tp& __x) const _NOEXCEPT {
291 return ~__x;
292 }
293 };
294
295 template <typename _Proj>
296 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool __scan_bits(_Proj __proj) const _NOEXCEPT {
297 size_t __n = _Size;
298 __const_storage_pointer __p = __first_;
299 // do middle whole words
300 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
301 if (__proj(*__p))
302 return true;
303 // do last partial word
304 if (__n > 0) {
305 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
306 if (__proj(*__p) & __m)
307 return true;
308 }
309 return false;
310 }
311
229312# ifdef _LIBCPP_CXX03_LANG
230313 void __init(unsigned long long __v, false_type) _NOEXCEPT;
231314 _LIBCPP_HIDE_FROM_ABI void __init(unsigned long long __v, true_type) _NOEXCEPT;
315# else
316 template <size_t... _Indices>
317 _LIBCPP_HIDE_FROM_ABI constexpr __bitset(unsigned long long __v, std::__tuple_indices<_Indices...>) _NOEXCEPT
318 : __first_{static_cast<__storage_type>(__v >> (_Indices * __bits_per_word))...} {}
232319# endif // _LIBCPP_CXX03_LANG
233 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(false_type) const;
234 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(true_type) const;
235 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(false_type) const;
236 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type) const;
237 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type, false_type) const;
238 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type, true_type) const;
239320};
240321
241322template <size_t _N_words, size_t _Size>
......@@ -253,26 +334,16 @@ inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset() _NOEXCEPT
253334
254335template <size_t _N_words, size_t _Size>
255336void __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT {
256 __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
257 size_t __sz = _Size;
258 for (size_t __i = 0; __i < sizeof(__t) / sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word)
259 if (__sz < __bits_per_word)
260 __t[__i] = static_cast<__storage_type>(__v) & (1ULL << __sz) - 1;
261 else
262 __t[__i] = static_cast<__storage_type>(__v);
263
264 std::copy(__t, __t + sizeof(__t) / sizeof(__t[0]), __first_);
265 std::fill(
266 __first_ + sizeof(__t) / sizeof(__t[0]), __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));
337 const size_t __n_words = std::min((sizeof(unsigned long long) - 1) / sizeof(__storage_type) + 1, _N_words);
338 for (size_t __i = 0; __i < __n_words; ++__i, __v >>= __bits_per_word)
339 __first_[__i] = static_cast<__storage_type>(__v);
340 std::fill(__first_ + __n_words, __first_ + _N_words, __storage_type(0));
267341}
268342
269343template <size_t _N_words, size_t _Size>
270344inline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT {
271345 __first_[0] = __v;
272 if (_Size < __bits_per_word)
273 __first_[0] &= (1ULL << _Size) - 1;
274
275 std::fill(__first_ + 1, __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));
346 std::fill(__first_ + 1, __first_ + _N_words, __storage_type(0));
276347}
277348
278349# endif // _LIBCPP_CXX03_LANG
......@@ -280,21 +351,15 @@ inline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::__init(unsigned lon
280351template <size_t _N_words, size_t _Size>
281352inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
282353# ifndef _LIBCPP_CXX03_LANG
283# if __SIZEOF_SIZE_T__ == 8
284 : __first_{__v}
285# elif __SIZEOF_SIZE_T__ == 4
286 : __first_{static_cast<__storage_type>(__v),
287 _Size >= 2 * __bits_per_word
288 ? static_cast<__storage_type>(__v >> __bits_per_word)
289 : static_cast<__storage_type>((__v >> __bits_per_word) &
290 (__storage_type(1) << (_Size - __bits_per_word)) - 1)}
291# else
292# error This constructor has not been ported to this platform
293# endif
354 : __bitset(__v,
355 std::__make_indices_imp< (_N_words < (sizeof(unsigned long long) - 1) / sizeof(__storage_type) + 1)
356 ? _N_words
357 : (sizeof(unsigned long long) - 1) / sizeof(__storage_type) + 1,
358 0>{})
294359# endif
295360{
296361# ifdef _LIBCPP_CXX03_LANG
297 __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
362 __init(__v, _BoolConstant<sizeof(unsigned long long) <= sizeof(__storage_type)>());
298363# endif
299364}
300365
......@@ -327,98 +392,10 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Siz
327392 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
328393 *__p = ~*__p;
329394 // do last partial word
330 if (__n > 0) {
331 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
332 __storage_type __b = *__p & __m;
333 *__p &= ~__m;
334 *__p |= ~__b & __m;
335 }
336}
337
338template <size_t _N_words, size_t _Size>
339_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
340__bitset<_N_words, _Size>::to_ulong(false_type) const {
341 __const_iterator __e = __make_iter(_Size);
342 __const_iterator __i = std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
343 if (__i != __e)
344 __throw_overflow_error("bitset to_ulong overflow error");
345
346 return __first_[0];
347}
348
349template <size_t _N_words, size_t _Size>
350inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
351__bitset<_N_words, _Size>::to_ulong(true_type) const {
352 return __first_[0];
353}
354
355template <size_t _N_words, size_t _Size>
356_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
357__bitset<_N_words, _Size>::to_ullong(false_type) const {
358 __const_iterator __e = __make_iter(_Size);
359 __const_iterator __i = std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
360 if (__i != __e)
361 __throw_overflow_error("bitset to_ullong overflow error");
362
363 return to_ullong(true_type());
364}
365
366template <size_t _N_words, size_t _Size>
367inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
368__bitset<_N_words, _Size>::to_ullong(true_type) const {
369 return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
370}
371
372template <size_t _N_words, size_t _Size>
373inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
374__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const {
375 return __first_[0];
376}
377
378template <size_t _N_words, size_t _Size>
379_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
380__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const {
381 unsigned long long __r = __first_[0];
382 _LIBCPP_DIAGNOSTIC_PUSH
383 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshift-count-overflow")
384 for (size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
385 __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
386 _LIBCPP_DIAGNOSTIC_POP
387 return __r;
388}
389
390template <size_t _N_words, size_t _Size>
391_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::all() const _NOEXCEPT {
392 // do middle whole words
393 size_t __n = _Size;
394 __const_storage_pointer __p = __first_;
395 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
396 if (~*__p)
397 return false;
398 // do last partial word
399 if (__n > 0) {
400 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
401 if (~*__p & __m)
402 return false;
403 }
404 return true;
405}
406
407template <size_t _N_words, size_t _Size>
408_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::any() const _NOEXCEPT {
409 // do middle whole words
410 size_t __n = _Size;
411 __const_storage_pointer __p = __first_;
412 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
413 if (*__p)
414 return true;
415 // do last partial word
416 if (__n > 0) {
417 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
418 if (*__p & __m)
419 return true;
420 }
421 return false;
395 // Ensure trailing padding bits are zeroed as part of the ABI for consistent hashing behavior. std::hash<bitset>
396 // assumes trailing bits are zeroed; otherwise, identical bitsets could hash differently.
397 if (__n > 0)
398 *__p ^= (__storage_type(1) << __n) - 1;
422399}
423400
424401template <size_t _N_words, size_t _Size>
......@@ -463,10 +440,14 @@ protected:
463440 return __const_reference(&__first_, __storage_type(1) << __pos);
464441 }
465442 _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);
443 // Allow the == case to accommodate the past-the-end iterator.
444 _LIBCPP_ASSERT_INTERNAL(__pos <= __bits_per_word, "Out of bounds access in the single-word bitset implementation.");
445 return __pos != __bits_per_word ? __iterator(&__first_, __pos) : __iterator(&__first_ + 1, 0);
467446 }
468447 _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);
448 // Allow the == case to accommodate the past-the-end iterator.
449 _LIBCPP_ASSERT_INTERNAL(__pos <= __bits_per_word, "Out of bounds access in the single-word bitset implementation.");
450 return __pos != __bits_per_word ? __const_iterator(&__first_, __pos) : __const_iterator(&__first_ + 1, 0);
470451 }
471452
472453 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT;
......@@ -475,8 +456,39 @@ protected:
475456
476457 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT;
477458
478 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const;
479 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const;
459 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const {
460 if _LIBCPP_CONSTEXPR (_Size > sizeof(unsigned long) * CHAR_BIT) {
461 if (auto __e = __make_iter(_Size); std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true) != __e)
462 __throw_overflow_error("__bitset<1, _Size>::to_ulong overflow error");
463 }
464 return static_cast<unsigned long>(__first_);
465 }
466
467 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const {
468 // If _Size exceeds the size of unsigned long long, check for overflow
469 if _LIBCPP_CONSTEXPR (_Size > sizeof(unsigned long long) * CHAR_BIT) {
470 if (auto __e = __make_iter(_Size);
471 std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true) != __e)
472 __throw_overflow_error("__bitset<1, _Size>::to_ullong overflow error");
473 }
474
475 // If _Size fits or no overflow, directly cast to unsigned long long
476 return static_cast<unsigned long long>(__first_);
477 }
478
479 template <bool _Sparse, class _CharT, class _Traits, class _Allocator>
480 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>
481 __to_string(_CharT __zero, _CharT __one) const {
482 basic_string<_CharT, _Traits, _Allocator> __r(_Size, _Sparse ? __zero : __one);
483 __storage_type __word = std::__invert_if<!_Sparse>(__first_);
484 if (_Size < __bits_per_word)
485 __word &= (__storage_type(1) << _Size) - 1;
486 for (; __word; __word &= (__word - 1)) {
487 size_t __pos = std::__countr_zero(__word);
488 __r[_Size - 1 - __pos] = _Sparse ? __one : __zero;
489 }
490 return __r;
491 }
480492
481493 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
482494 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
......@@ -489,8 +501,10 @@ inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0)
489501
490502template <size_t _Size>
491503inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
492 : __first_(_Size == __bits_per_word ? static_cast<__storage_type>(__v)
493 : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)) {}
504 // TODO: We must refer to __bits_per_word in order to work around an issue with the GDB pretty-printers.
505 // Without it, the pretty-printers complain about a missing __bits_per_word member. This needs to
506 // be investigated further.
507 : __first_(_Size == __bits_per_word ? static_cast<__storage_type>(__v) : static_cast<__storage_type>(__v)) {}
494508
495509template <size_t _Size>
496510inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
......@@ -512,19 +526,7 @@ __bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {
512526
513527template <size_t _Size>
514528inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<1, _Size>::flip() _NOEXCEPT {
515 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
516 __first_ = ~__first_;
517 __first_ &= __m;
518}
519
520template <size_t _Size>
521inline _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long __bitset<1, _Size>::to_ulong() const {
522 return __first_;
523}
524
525template <size_t _Size>
526inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long __bitset<1, _Size>::to_ullong() const {
527 return __first_;
529 __first_ ^= ~__storage_type(0) >> (__bits_per_word - _Size);
528530}
529531
530532template <size_t _Size>
......@@ -591,6 +593,12 @@ protected:
591593 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const { return 0; }
592594 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const { return 0; }
593595
596 template <bool _Sparse, class _CharT, class _Traits, class _Allocator>
597 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>
598 __to_string(_CharT, _CharT) const {
599 return basic_string<_CharT, _Traits, _Allocator>();
600 }
601
594602 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT { return true; }
595603 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT { return false; }
596604
......@@ -602,37 +610,32 @@ inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset() _NOEXCEPT {}
602610inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT {}
603611
604612template <size_t _Size>
605class _LIBCPP_TEMPLATE_VIS bitset;
613class bitset;
606614template <size_t _Size>
607615struct hash<bitset<_Size> >;
608616
609617template <size_t _Size>
610class _LIBCPP_TEMPLATE_VIS bitset
611 : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> {
618class bitset : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> {
612619public:
613620 static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
614621 typedef __bitset<__n_words, _Size> __base;
615
616public:
617622 typedef typename __base::reference reference;
618623 typedef typename __base::__const_reference __const_reference;
619624
620625 // 23.3.5.1 constructors:
621626 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
622 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset(unsigned long long __v) _NOEXCEPT : __base(__v) {}
627 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset(unsigned long long __v) _NOEXCEPT
628 : __base(sizeof(unsigned long long) * CHAR_BIT <= _Size ? __v : __v & ((1ULL << _Size) - 1)) {}
623629 template <class _CharT, __enable_if_t<_IsCharLikeType<_CharT>::value, int> = 0>
624630 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset(
625631 const _CharT* __str,
626# if _LIBCPP_STD_VER >= 26
627 typename basic_string_view<_CharT>::size_type __n = basic_string_view<_CharT>::npos,
628# else
629 typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
630# endif
632 size_t __n = basic_string<_CharT>::npos,
631633 _CharT __zero = _CharT('0'),
632634 _CharT __one = _CharT('1')) {
633
634 size_t __rlen = std::min(__n, char_traits<_CharT>::length(__str));
635 __init_from_string_view(basic_string_view<_CharT>(__str, __rlen), __zero, __one);
635 if (__n == basic_string<_CharT>::npos)
636 __init_from_string_view(basic_string_view<_CharT>(__str), __zero, __one);
637 else
638 __init_from_string_view(basic_string_view<_CharT>(__str, __n), __zero, __one);
636639 }
637640# if _LIBCPP_STD_VER >= 26
638641 template <class _CharT, class _Traits>
......@@ -643,7 +646,7 @@ public:
643646 _CharT __zero = _CharT('0'),
644647 _CharT __one = _CharT('1')) {
645648 if (__pos > __str.size())
646 __throw_out_of_range("bitset string pos out of range");
649 std::__throw_out_of_range("bitset string pos out of range");
647650
648651 size_t __rlen = std::min(__n, __str.size() - __pos);
649652 __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one);
......@@ -694,8 +697,10 @@ public:
694697 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p < _Size, "bitset::operator[] index out of bounds");
695698 return __base::__make_ref(__p);
696699 }
697 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const;
698 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const;
700 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const { return __base::to_ulong(); }
701 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const {
702 return __base::to_ullong();
703 }
699704 template <class _CharT, class _Traits, class _Allocator>
700705 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>
701706 to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;
......@@ -714,8 +719,8 @@ public:
714719 _LIBCPP_HIDE_FROM_ABI bool operator!=(const bitset& __rhs) const _NOEXCEPT;
715720# endif
716721 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool test(size_t __pos) const;
717 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
718 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
722 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT { return __base::all(); }
723 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT { return __base::any(); }
719724 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool none() const _NOEXCEPT { return !any(); }
720725 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator<<(size_t __pos) const _NOEXCEPT;
721726 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator>>(size_t __pos) const _NOEXCEPT;
......@@ -734,7 +739,6 @@ private:
734739 _CharT __c = __str[__mp - 1 - __i];
735740 (*this)[__i] = _Traits::eq(__c, __one);
736741 }
737 std::fill(__base::__make_iter(__i), __base::__make_iter(_Size), false);
738742 }
739743
740744 _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return __base::__hash_code(); }
......@@ -788,7 +792,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset
788792template <size_t _Size>
789793_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set(size_t __pos, bool __val) {
790794 if (__pos >= _Size)
791 __throw_out_of_range("bitset set argument out of range");
795 std::__throw_out_of_range("bitset set argument out of range");
792796
793797 (*this)[__pos] = __val;
794798 return *this;
......@@ -803,7 +807,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset
803807template <size_t _Size>
804808_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset(size_t __pos) {
805809 if (__pos >= _Size)
806 __throw_out_of_range("bitset reset argument out of range");
810 std::__throw_out_of_range("bitset reset argument out of range");
807811
808812 (*this)[__pos] = false;
809813 return *this;
......@@ -825,33 +829,22 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset
825829template <size_t _Size>
826830_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip(size_t __pos) {
827831 if (__pos >= _Size)
828 __throw_out_of_range("bitset flip argument out of range");
832 std::__throw_out_of_range("bitset flip argument out of range");
829833
830834 reference __r = __base::__make_ref(__pos);
831835 __r = ~__r;
832836 return *this;
833837}
834838
835template <size_t _Size>
836inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long bitset<_Size>::to_ulong() const {
837 return __base::to_ulong();
838}
839
840template <size_t _Size>
841inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long bitset<_Size>::to_ullong() const {
842 return __base::to_ullong();
843}
844
845839template <size_t _Size>
846840template <class _CharT, class _Traits, class _Allocator>
847841_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>
848842bitset<_Size>::to_string(_CharT __zero, _CharT __one) const {
849 basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
850 for (size_t __i = 0; __i != _Size; ++__i) {
851 if ((*this)[__i])
852 __r[_Size - 1 - __i] = __one;
853 }
854 return __r;
843 bool __sparse = size_t(std::count(__base::__make_iter(0), __base::__make_iter(_Size), true)) < _Size / 2;
844 if (__sparse)
845 return __base::template __to_string<true, _CharT, _Traits, _Allocator>(__zero, __one);
846 else
847 return __base::template __to_string<false, _CharT, _Traits, _Allocator>(__zero, __one);
855848}
856849
857850template <size_t _Size>
......@@ -897,21 +890,11 @@ inline _LIBCPP_HIDE_FROM_ABI bool bitset<_Size>::operator!=(const bitset& __rhs)
897890template <size_t _Size>
898891_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::test(size_t __pos) const {
899892 if (__pos >= _Size)
900 __throw_out_of_range("bitset test argument out of range");
893 std::__throw_out_of_range("bitset test argument out of range");
901894
902895 return (*this)[__pos];
903896}
904897
905template <size_t _Size>
906inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::all() const _NOEXCEPT {
907 return __base::all();
908}
909
910template <size_t _Size>
911inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::any() const _NOEXCEPT {
912 return __base::any();
913}
914
915898template <size_t _Size>
916899inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
917900bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT {
......@@ -953,7 +936,7 @@ operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
953936}
954937
955938template <size_t _Size>
956struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> > : public __unary_function<bitset<_Size>, size_t> {
939struct hash<bitset<_Size> > : public __unary_function<bitset<_Size>, size_t> {
957940 _LIBCPP_HIDE_FROM_ABI size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT { return __bs.__hash_code(); }
958941};
959942
......@@ -972,6 +955,7 @@ _LIBCPP_POP_MACROS
972955# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
973956# include <concepts>
974957# include <cstdlib>
958# include <optional>
975959# include <type_traits>
976960# endif
977961#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
lib/libcxx/include/charconv+1-1
......@@ -76,7 +76,7 @@ namespace std {
7676*/
7777
7878#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
79# include <__cxx03/charconv>
79# include <__cxx03/__config>
8080#else
8181# include <__config>
8282
lib/libcxx/include/chrono+88-22
......@@ -132,6 +132,11 @@ public:
132132
133133 // arithmetic
134134
135 constexpr time_point& operator++(); // C++20
136 constexpr time_point operator++(int); // C++20
137 constexpr time_point& operator--(); // C++20
138 constexpr time_point operator--(int); // C++20
139
135140 time_point& operator+=(const duration& d); // constexpr in C++17
136141 time_point& operator-=(const duration& d); // constexpr in C++17
137142
......@@ -335,6 +340,61 @@ struct leap_second_info { // C++20
335340template<class Duration> // C++20
336341 leap_second_info get_leap_second_info(const utc_time<Duration>& ut);
337342
343
344// [time.clock.tai], class tai_clock
345class tai_clock { // C++20
346public:
347 using rep = a signed arithmetic type;
348 using period = ratio<unspecified, unspecified>;
349 using duration = chrono::duration<rep, period>;
350 using time_point = chrono::time_point<tai_clock>;
351 static constexpr bool is_steady = unspecified;
352
353 static time_point now();
354
355 template<class Duration>
356 static utc_time<common_type_t<Duration, seconds>>
357 to_utc(const tai_time<Duration>& t);
358 template<class Duration>
359 static tai_time<common_type_t<Duration, seconds>>
360 from_utc(const utc_time<Duration>& t);
361};
362
363template<class Duration>
364using tai_time = time_point<tai_clock, Duration>; // C++20
365using tai_seconds = tai_time<seconds>; // C++20
366
367template<class charT, class traits, class Duration> // C++20
368 basic_ostream<charT, traits>&
369 operator<<(basic_ostream<charT, traits>& os, const tai_time<Duration>& t);
370
371// [time.clock.gps], class gps_clock
372class gps_clock { // C++20
373public:
374 using rep = a signed arithmetic type;
375 using period = ratio<unspecified, unspecified>;
376 using duration = chrono::duration<rep, period>;
377 using time_point = chrono::time_point<gps_clock>;
378 static constexpr bool is_steady = unspecified;
379
380 static time_point now();
381
382 template<class Duration>
383 static utc_time<common_type_t<Duration, seconds>>
384 to_utc(const gps_time<Duration>& t);
385 template<class Duration>
386 static gps_time<common_type_t<Duration, seconds>>
387 from_utc(const utc_time<Duration>& t);
388};
389
390template<class Duration>
391using gps_time = time_point<gps_clock, Duration>; // C++20
392using gps_seconds = gps_time<seconds>; // C++20
393
394template<class charT, class traits, class Duration> // C++20
395 basic_ostream<charT, traits>&
396 operator<<(basic_ostream<charT, traits>& os, const gps_time<Duration>& t);
397
338398class file_clock // C++20
339399{
340400public:
......@@ -374,7 +434,7 @@ public:
374434
375435typedef steady_clock high_resolution_clock;
376436
377// 25.7.8, local time // C++20
437// [time.clock.local] local time // C++20
378438struct local_t {};
379439template<class Duration>
380440 using local_time = time_point<local_t, Duration>;
......@@ -385,10 +445,10 @@ template<class charT, class traits, class Duration> // C++20
385445 basic_ostream<charT, traits>&
386446 operator<<(basic_ostream<charT, traits>& os, const local_time<Duration>& tp);
387447
388// 25.8.2, class last_spec // C++20
448// [time.cal.last] class last_spec // C++20
389449struct last_spec;
390450
391// 25.8.3, class day // C++20
451// [time.cal.day] class day // C++20
392452
393453class day;
394454constexpr bool operator==(const day& x, const day& y) noexcept;
......@@ -401,7 +461,7 @@ template<class charT, class traits>
401461 basic_ostream<charT, traits>&
402462 operator<<(basic_ostream<charT, traits>& os, const day& d);
403463
404// 25.8.4, class month // C++20
464// [time.cal.month] class month // C++20
405465class month;
406466constexpr bool operator==(const month& x, const month& y) noexcept;
407467constexpr strong_ordering operator<=>(const month& x, const month& y) noexcept;
......@@ -414,7 +474,7 @@ template<class charT, class traits>
414474 basic_ostream<charT, traits>&
415475 operator<<(basic_ostream<charT, traits>& os, const month& m);
416476
417// 25.8.5, class year // C++20
477// [time.cal.year] class year // C++20
418478class year;
419479constexpr bool operator==(const year& x, const year& y) noexcept;
420480constexpr strong_ordering operator<=>(const year& x, const year& y) noexcept;
......@@ -427,7 +487,7 @@ template<class charT, class traits>
427487 basic_ostream<charT, traits>&
428488 operator<<(basic_ostream<charT, traits>& os, const year& y);
429489
430// 25.8.6, class weekday // C++20
490// [time.cal.wd] class weekday // C++20
431491class weekday;
432492
433493constexpr bool operator==(const weekday& x, const weekday& y) noexcept;
......@@ -439,7 +499,7 @@ template<class charT, class traits>
439499 basic_ostream<charT, traits>&
440500 operator<<(basic_ostream<charT, traits>& os, const weekday& wd);
441501
442// 25.8.7, class weekday_indexed // C++20
502// [time.cal.wdidx] class weekday_indexed // C++20
443503
444504class weekday_indexed;
445505constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept;
......@@ -448,7 +508,7 @@ template<class charT, class traits>
448508 basic_ostream<charT, traits>&
449509 operator<<(basic_ostream<charT, traits>& os, const weekday_indexed& wdi);
450510
451// 25.8.8, class weekday_last // C++20
511// [time.cal.wdlast] class weekday_last // C++20
452512class weekday_last;
453513
454514constexpr bool operator==(const weekday_last& x, const weekday_last& y) noexcept;
......@@ -457,7 +517,7 @@ template<class charT, class traits>
457517 basic_ostream<charT, traits>&
458518 operator<<(basic_ostream<charT, traits>& os, const weekday_last& wdl);
459519
460// 25.8.9, class month_day // C++20
520// [time.cal.md] class month_day // C++20
461521class month_day;
462522
463523constexpr bool operator==(const month_day& x, const month_day& y) noexcept;
......@@ -467,7 +527,7 @@ template<class charT, class traits>
467527 basic_ostream<charT, traits>&
468528 operator<<(basic_ostream<charT, traits>& os, const month_day& md);
469529
470// 25.8.10, class month_day_last // C++20
530// [time.cal.mdlast] class month_day_last // C++20
471531class month_day_last;
472532
473533constexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept;
......@@ -477,7 +537,7 @@ template<class charT, class traits>
477537 basic_ostream<charT, traits>&
478538 operator<<(basic_ostream<charT, traits>& os, const month_day_last& mdl);
479539
480// 25.8.11, class month_weekday // C++20
540// [time.cal.mwd] class month_weekday // C++20
481541class month_weekday;
482542
483543constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept;
......@@ -486,7 +546,7 @@ template<class charT, class traits>
486546 basic_ostream<charT, traits>&
487547 operator<<(basic_ostream<charT, traits>& os, const month_weekday& mwd);
488548
489// 25.8.12, class month_weekday_last // C++20
549// [time.cal.mwdlast] class month_weekday_last // C++20
490550class month_weekday_last;
491551
492552constexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept;
......@@ -496,7 +556,7 @@ template<class charT, class traits>
496556 operator<<(basic_ostream<charT, traits>& os, const month_weekday_last& mwdl);
497557
498558
499// 25.8.13, class year_month // C++20
559// [time.cal.ym] class year_month // C++20
500560class year_month;
501561
502562constexpr bool operator==(const year_month& x, const year_month& y) noexcept;
......@@ -514,7 +574,7 @@ template<class charT, class traits>
514574 basic_ostream<charT, traits>&
515575 operator<<(basic_ostream<charT, traits>& os, const year_month& ym);
516576
517// 25.8.14, class year_month_day class // C++20
577// [time.cal.ymd] class year_month_day class // C++20
518578year_month_day;
519579
520580constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept;
......@@ -531,7 +591,7 @@ template<class charT, class traits>
531591 basic_ostream<charT, traits>&
532592 operator<<(basic_ostream<charT, traits>& os, const year_month_day& ymd);
533593
534// 25.8.15, class year_month_day_last // C++20
594// [time.cal.ymdlast] class year_month_day_last // C++20
535595class year_month_day_last;
536596
537597constexpr bool operator==(const year_month_day_last& x, const year_month_day_last& y) noexcept;
......@@ -554,7 +614,7 @@ template<class charT, class traits>
554614 basic_ostream<charT, traits>&
555615 operator<<(basic_ostream<charT, traits>& os, const year_month_day_last& ymdl);
556616
557// 25.8.16, class year_month_weekday // C++20
617// [time.cal.ymwd] class year_month_weekday // C++20
558618class year_month_weekday;
559619
560620constexpr bool operator==(const year_month_weekday& x,
......@@ -577,7 +637,7 @@ template<class charT, class traits>
577637 basic_ostream<charT, traits>&
578638 operator<<(basic_ostream<charT, traits>& os, const year_month_weekday& ymwd);
579639
580// 25.8.17, class year_month_weekday_last // C++20
640// [time.cal.ymwdlast] class year_month_weekday_last // C++20
581641class year_month_weekday_last;
582642
583643constexpr bool operator==(const year_month_weekday_last& x,
......@@ -599,7 +659,7 @@ template<class charT, class traits>
599659 basic_ostream<charT, traits>&
600660 operator<<(basic_ostream<charT, traits>& os, const year_month_weekday_last& ymwdl);
601661
602// 25.8.18, civil calendar conventional syntax operators // C++20
662// [time.cal.operators] civil calendar conventional syntax operators // C++20
603663constexpr year_month
604664 operator/(const year& y, const month& m) noexcept;
605665constexpr year_month
......@@ -790,7 +850,7 @@ template<class charT, class traits>
790850 basic_ostream<charT, traits>&
791851 operator<<(basic_ostream<charT, traits>& os, const local_info& li);
792852
793// 25.10.5, class time_zone // C++20
853// [time.zone.timezone] class time_zone // C++20
794854enum class choose {earliest, latest};
795855class time_zone {
796856 time_zone(time_zone&&) = default;
......@@ -894,16 +954,20 @@ strong_ordering operator<=>(const time_zone_link& x, const time_zone_link& y);
894954} // chrono
895955
896956namespace std {
957 template<class Rep, class Period, class charT>
958 struct formatter<chrono::duration<Rep, Period>, charT>; // C++20
897959 template<class Duration, class charT>
898960 struct formatter<chrono::sys_time<Duration>, charT>; // C++20
899961 template<class Duration, class charT>
900962 struct formatter<chrono::utc_time<Duration>, charT>; // C++20
901963 template<class Duration, class charT>
902 struct formatter<chrono::filetime<Duration>, charT>; // C++20
964 struct formatter<chrono::tai_time<Duration>, charT>; // C++20
965 template<class Duration, class charT>
966 struct formatter<chrono::gps_time<Duration>, charT>; // C++20
967 template<class Duration, class charT>
968 struct formatter<chrono::file_time<Duration>, charT>; // C++20
903969 template<class Duration, class charT>
904970 struct formatter<chrono::local_time<Duration>, charT>; // C++20
905 template<class Rep, class Period, class charT>
906 struct formatter<chrono::duration<Rep, Period>, charT>; // C++20
907971 template<class charT> struct formatter<chrono::day, charT>; // C++20
908972 template<class charT> struct formatter<chrono::month, charT>; // C++20
909973 template<class charT> struct formatter<chrono::year, charT>; // C++20
......@@ -1013,7 +1077,9 @@ constexpr chrono::year operator ""y(unsigned lo
10131077# endif
10141078
10151079# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
1080# include <__chrono/gps_clock.h>
10161081# include <__chrono/leap_second.h>
1082# include <__chrono/tai_clock.h>
10171083# include <__chrono/time_zone.h>
10181084# include <__chrono/time_zone_link.h>
10191085# include <__chrono/tzdb.h>
lib/libcxx/include/cmath+3-5
......@@ -599,11 +599,9 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr long double lerp(long double __a, long do
599599}
600600
601601template <class _A1, class _A2, class _A3>
602inline _LIBCPP_HIDE_FROM_ABI constexpr
603 typename enable_if_t< is_arithmetic<_A1>::value && is_arithmetic<_A2>::value && is_arithmetic<_A3>::value,
604 __promote<_A1, _A2, _A3> >::type
605 lerp(_A1 __a, _A2 __b, _A3 __t) noexcept {
606 typedef typename __promote<_A1, _A2, _A3>::type __result_type;
602 requires(is_arithmetic_v<_A1> && is_arithmetic_v<_A2> && is_arithmetic_v<_A3>)
603_LIBCPP_HIDE_FROM_ABI inline constexpr __promote_t<_A1, _A2, _A3> lerp(_A1 __a, _A2 __b, _A3 __t) noexcept {
604 using __result_type = __promote_t<_A1, _A2, _A3>;
607605 static_assert(!(
608606 _IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value && _IsSame<_A3, __result_type>::value));
609607 return std::__lerp((__result_type)__a, (__result_type)__b, (__result_type)__t);
lib/libcxx/include/codecvt+22-17
......@@ -58,14 +58,17 @@ class codecvt_utf8_utf16
5858# include <__cxx03/codecvt>
5959#else
6060# include <__config>
61# include <__locale>
62# include <version>
6361
64# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
65# pragma GCC system_header
66# endif
62# if _LIBCPP_HAS_LOCALIZATION
63
64# include <__locale>
65# include <version>
6766
68# if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT)
67# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
68# pragma GCC system_header
69# endif
70
71# if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT)
6972
7073_LIBCPP_BEGIN_NAMESPACE_STD
7174
......@@ -76,7 +79,7 @@ enum _LIBCPP_DEPRECATED_IN_CXX17 codecvt_mode { consume_header = 4, generate_hea
7679template <class _Elem>
7780class __codecvt_utf8;
7881
79# if _LIBCPP_HAS_WIDE_CHARACTERS
82# if _LIBCPP_HAS_WIDE_CHARACTERS
8083template <>
8184class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8<wchar_t> : public codecvt<wchar_t, char, mbstate_t> {
8285 unsigned long __maxcode_;
......@@ -115,7 +118,7 @@ protected:
115118 int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
116119 int do_max_length() const _NOEXCEPT override;
117120};
118# endif // _LIBCPP_HAS_WIDE_CHARACTERS
121# endif // _LIBCPP_HAS_WIDE_CHARACTERS
119122
120123_LIBCPP_SUPPRESS_DEPRECATED_PUSH
121124template <>
......@@ -193,7 +196,7 @@ protected:
193196
194197_LIBCPP_SUPPRESS_DEPRECATED_PUSH
195198template <class _Elem, unsigned long _Maxcode = 0x10ffff, codecvt_mode _Mode = (codecvt_mode)0>
196class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 codecvt_utf8 : public __codecvt_utf8<_Elem> {
199class _LIBCPP_DEPRECATED_IN_CXX17 codecvt_utf8 : public __codecvt_utf8<_Elem> {
197200public:
198201 _LIBCPP_HIDE_FROM_ABI explicit codecvt_utf8(size_t __refs = 0) : __codecvt_utf8<_Elem>(__refs, _Maxcode, _Mode) {}
199202
......@@ -206,7 +209,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
206209template <class _Elem, bool _LittleEndian>
207210class __codecvt_utf16;
208211
209# if _LIBCPP_HAS_WIDE_CHARACTERS
212# if _LIBCPP_HAS_WIDE_CHARACTERS
210213template <>
211214class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf16<wchar_t, false> : public codecvt<wchar_t, char, mbstate_t> {
212215 unsigned long __maxcode_;
......@@ -284,7 +287,7 @@ protected:
284287 int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
285288 int do_max_length() const _NOEXCEPT override;
286289};
287# endif // _LIBCPP_HAS_WIDE_CHARACTERS
290# endif // _LIBCPP_HAS_WIDE_CHARACTERS
288291
289292_LIBCPP_SUPPRESS_DEPRECATED_PUSH
290293template <>
......@@ -436,8 +439,7 @@ protected:
436439
437440_LIBCPP_SUPPRESS_DEPRECATED_PUSH
438441template <class _Elem, unsigned long _Maxcode = 0x10ffff, codecvt_mode _Mode = (codecvt_mode)0>
439class _LIBCPP_TEMPLATE_VIS
440_LIBCPP_DEPRECATED_IN_CXX17 codecvt_utf16 : public __codecvt_utf16<_Elem, _Mode & little_endian> {
442class _LIBCPP_DEPRECATED_IN_CXX17 codecvt_utf16 : public __codecvt_utf16<_Elem, _Mode & little_endian> {
441443public:
442444 _LIBCPP_HIDE_FROM_ABI explicit codecvt_utf16(size_t __refs = 0)
443445 : __codecvt_utf16<_Elem, _Mode & little_endian>(__refs, _Maxcode, _Mode) {}
......@@ -451,7 +453,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
451453template <class _Elem>
452454class __codecvt_utf8_utf16;
453455
454# if _LIBCPP_HAS_WIDE_CHARACTERS
456# if _LIBCPP_HAS_WIDE_CHARACTERS
455457template <>
456458class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8_utf16<wchar_t> : public codecvt<wchar_t, char, mbstate_t> {
457459 unsigned long __maxcode_;
......@@ -490,7 +492,7 @@ protected:
490492 int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
491493 int do_max_length() const _NOEXCEPT override;
492494};
493# endif // _LIBCPP_HAS_WIDE_CHARACTERS
495# endif // _LIBCPP_HAS_WIDE_CHARACTERS
494496
495497_LIBCPP_SUPPRESS_DEPRECATED_PUSH
496498template <>
......@@ -568,7 +570,7 @@ protected:
568570
569571_LIBCPP_SUPPRESS_DEPRECATED_PUSH
570572template <class _Elem, unsigned long _Maxcode = 0x10ffff, codecvt_mode _Mode = (codecvt_mode)0>
571class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 codecvt_utf8_utf16 : public __codecvt_utf8_utf16<_Elem> {
573class _LIBCPP_DEPRECATED_IN_CXX17 codecvt_utf8_utf16 : public __codecvt_utf8_utf16<_Elem> {
572574public:
573575 _LIBCPP_HIDE_FROM_ABI explicit codecvt_utf8_utf16(size_t __refs = 0)
574576 : __codecvt_utf8_utf16<_Elem>(__refs, _Maxcode, _Mode) {}
......@@ -579,7 +581,9 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
579581
580582_LIBCPP_END_NAMESPACE_STD
581583
582# endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT)
584# endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT)
585
586# endif // _LIBCPP_HAS_LOCALIZATION
583587
584588# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
585589# include <atomic>
......@@ -592,6 +596,7 @@ _LIBCPP_END_NAMESPACE_STD
592596# include <limits>
593597# include <mutex>
594598# include <new>
599# include <optional>
595600# include <stdexcept>
596601# include <type_traits>
597602# include <typeinfo>
lib/libcxx/include/compare+1-1
......@@ -141,7 +141,7 @@ namespace std {
141141*/
142142
143143#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
144# include <__cxx03/compare>
144# include <__cxx03/__config>
145145#else
146146# include <__config>
147147
lib/libcxx/include/complex+15-15
......@@ -260,6 +260,7 @@ template<class T> complex<T> tanh (const complex<T>&);
260260# include <__cxx03/complex>
261261#else
262262# include <__config>
263# include <__cstddef/size_t.h>
263264# include <__fwd/complex.h>
264265# include <__fwd/tuple.h>
265266# include <__tuple/tuple_element.h>
......@@ -283,7 +284,7 @@ _LIBCPP_PUSH_MACROS
283284_LIBCPP_BEGIN_NAMESPACE_STD
284285
285286template <class _Tp>
286class _LIBCPP_TEMPLATE_VIS complex;
287class complex;
287288
288289template <class _Tp, __enable_if_t<is_floating_point<_Tp>::value, int> = 0>
289290_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 complex<_Tp>
......@@ -302,7 +303,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 complex<_Tp>
302303operator/(const complex<_Tp>& __x, const complex<_Tp>& __y);
303304
304305template <class _Tp>
305class _LIBCPP_TEMPLATE_VIS complex {
306class complex {
306307public:
307308 typedef _Tp value_type;
308309
......@@ -393,9 +394,9 @@ public:
393394};
394395
395396template <>
396class _LIBCPP_TEMPLATE_VIS complex<double>;
397class complex<double>;
397398template <>
398class _LIBCPP_TEMPLATE_VIS complex<long double>;
399class complex<long double>;
399400
400401struct __from_builtin_tag {};
401402
......@@ -415,7 +416,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __complex_t<_Tp> __make_complex(_Tp __re
415416}
416417
417418template <>
418class _LIBCPP_TEMPLATE_VIS complex<float> {
419class complex<float> {
419420 float __re_;
420421 float __im_;
421422
......@@ -512,7 +513,7 @@ public:
512513};
513514
514515template <>
515class _LIBCPP_TEMPLATE_VIS complex<double> {
516class complex<double> {
516517 double __re_;
517518 double __im_;
518519
......@@ -612,7 +613,7 @@ public:
612613};
613614
614615template <>
615class _LIBCPP_TEMPLATE_VIS complex<long double> {
616class complex<long double> {
616617 long double __re_;
617618 long double __im_;
618619
......@@ -1101,21 +1102,20 @@ inline _LIBCPP_HIDE_FROM_ABI complex<_Tp> pow(const complex<_Tp>& __x, const com
11011102}
11021103
11031104template <class _Tp, class _Up, __enable_if_t<is_floating_point<_Tp>::value && is_floating_point<_Up>::value, int> = 0>
1104inline _LIBCPP_HIDE_FROM_ABI complex<typename __promote<_Tp, _Up>::type>
1105pow(const complex<_Tp>& __x, const complex<_Up>& __y) {
1106 typedef complex<typename __promote<_Tp, _Up>::type> result_type;
1105inline _LIBCPP_HIDE_FROM_ABI complex<__promote_t<_Tp, _Up> > pow(const complex<_Tp>& __x, const complex<_Up>& __y) {
1106 typedef complex<__promote_t<_Tp, _Up> > result_type;
11071107 return std::pow(result_type(__x), result_type(__y));
11081108}
11091109
11101110template <class _Tp, class _Up, __enable_if_t<is_floating_point<_Tp>::value && is_arithmetic<_Up>::value, int> = 0>
1111inline _LIBCPP_HIDE_FROM_ABI complex<typename __promote<_Tp, _Up>::type> pow(const complex<_Tp>& __x, const _Up& __y) {
1112 typedef complex<typename __promote<_Tp, _Up>::type> result_type;
1111inline _LIBCPP_HIDE_FROM_ABI complex<__promote_t<_Tp, _Up> > pow(const complex<_Tp>& __x, const _Up& __y) {
1112 typedef complex<__promote_t<_Tp, _Up> > result_type;
11131113 return std::pow(result_type(__x), result_type(__y));
11141114}
11151115
11161116template <class _Tp, class _Up, __enable_if_t<is_arithmetic<_Tp>::value && is_floating_point<_Up>::value, int> = 0>
1117inline _LIBCPP_HIDE_FROM_ABI complex<typename __promote<_Tp, _Up>::type> pow(const _Tp& __x, const complex<_Up>& __y) {
1118 typedef complex<typename __promote<_Tp, _Up>::type> result_type;
1117inline _LIBCPP_HIDE_FROM_ABI complex<__promote_t<_Tp, _Up> > pow(const _Tp& __x, const complex<_Up>& __y) {
1118 typedef complex<__promote_t<_Tp, _Up> > result_type;
11191119 return std::pow(result_type(__x), result_type(__y));
11201120}
11211121
......@@ -1394,7 +1394,7 @@ struct tuple_size<complex<_Tp>> : integral_constant<size_t, 2> {};
13941394template <size_t _Ip, class _Tp>
13951395struct tuple_element<_Ip, complex<_Tp>> {
13961396 static_assert(_Ip < 2, "Index value is out of range.");
1397 using type = _Tp;
1397 using type _LIBCPP_NODEBUG = _Tp;
13981398};
13991399
14001400template <size_t _Ip, class _Xp>
lib/libcxx/include/concepts+1-1
......@@ -130,7 +130,7 @@ namespace std {
130130*/
131131
132132#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
133# include <__cxx03/concepts>
133# include <__cxx03/__config>
134134#else
135135# include <__config>
136136
lib/libcxx/include/condition_variable+31-36
......@@ -147,6 +147,21 @@ _LIBCPP_PUSH_MACROS
147147
148148_LIBCPP_BEGIN_NAMESPACE_STD
149149
150template <class _Lock>
151struct __unlock_guard {
152 _Lock& __lock_;
153
154 _LIBCPP_HIDE_FROM_ABI __unlock_guard(_Lock& __lock) : __lock_(__lock) { __lock_.unlock(); }
155
156 _LIBCPP_HIDE_FROM_ABI ~__unlock_guard() _NOEXCEPT // turns exception to std::terminate
157 {
158 __lock_.lock();
159 }
160
161 __unlock_guard(const __unlock_guard&) = delete;
162 __unlock_guard& operator=(const __unlock_guard&) = delete;
163};
164
150165class _LIBCPP_EXPORTED_FROM_ABI condition_variable_any {
151166 condition_variable __cv_;
152167 shared_ptr<mutex> __mut_;
......@@ -158,13 +173,25 @@ public:
158173 _LIBCPP_HIDE_FROM_ABI void notify_all() _NOEXCEPT;
159174
160175 template <class _Lock>
161 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS void wait(_Lock& __lock);
176 _LIBCPP_HIDE_FROM_ABI void wait(_Lock& __lock) {
177 shared_ptr<mutex> __mut = __mut_;
178 unique_lock<mutex> __lk(*__mut);
179 __unlock_guard<_Lock> __unlock(__lock);
180 lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock_t());
181 __cv_.wait(__lk);
182 } // __mut_.unlock(), __lock.lock()
183
162184 template <class _Lock, class _Predicate>
163185 _LIBCPP_HIDE_FROM_ABI void wait(_Lock& __lock, _Predicate __pred);
164186
165187 template <class _Lock, class _Clock, class _Duration>
166 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS cv_status
167 wait_until(_Lock& __lock, const chrono::time_point<_Clock, _Duration>& __t);
188 _LIBCPP_HIDE_FROM_ABI cv_status wait_until(_Lock& __lock, const chrono::time_point<_Clock, _Duration>& __t) {
189 shared_ptr<mutex> __mut = __mut_;
190 unique_lock<mutex> __lk(*__mut);
191 __unlock_guard<_Lock> __unlock(__lock);
192 lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock_t());
193 return __cv_.wait_until(__lk, __t);
194 } // __mut_.unlock(), __lock.lock()
168195
169196 template <class _Lock, class _Clock, class _Duration, class _Predicate>
170197 bool _LIBCPP_HIDE_FROM_ABI
......@@ -204,45 +231,12 @@ inline void condition_variable_any::notify_all() _NOEXCEPT {
204231 __cv_.notify_all();
205232}
206233
207template <class _Lock>
208struct __unlock_guard {
209 _Lock& __lock_;
210
211 _LIBCPP_HIDE_FROM_ABI __unlock_guard(_Lock& __lock) : __lock_(__lock) { __lock_.unlock(); }
212
213 _LIBCPP_HIDE_FROM_ABI ~__unlock_guard() _NOEXCEPT // turns exception to std::terminate
214 {
215 __lock_.lock();
216 }
217
218 __unlock_guard(const __unlock_guard&) = delete;
219 __unlock_guard& operator=(const __unlock_guard&) = delete;
220};
221
222template <class _Lock>
223void condition_variable_any::wait(_Lock& __lock) {
224 shared_ptr<mutex> __mut = __mut_;
225 unique_lock<mutex> __lk(*__mut);
226 __unlock_guard<_Lock> __unlock(__lock);
227 lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock_t());
228 __cv_.wait(__lk);
229} // __mut_.unlock(), __lock.lock()
230
231234template <class _Lock, class _Predicate>
232235inline void condition_variable_any::wait(_Lock& __lock, _Predicate __pred) {
233236 while (!__pred())
234237 wait(__lock);
235238}
236239
237template <class _Lock, class _Clock, class _Duration>
238cv_status condition_variable_any::wait_until(_Lock& __lock, const chrono::time_point<_Clock, _Duration>& __t) {
239 shared_ptr<mutex> __mut = __mut_;
240 unique_lock<mutex> __lk(*__mut);
241 __unlock_guard<_Lock> __unlock(__lock);
242 lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock_t());
243 return __cv_.wait_until(__lk, __t);
244} // __mut_.unlock(), __lock.lock()
245
246240template <class _Lock, class _Clock, class _Duration, class _Predicate>
247241inline bool
248242condition_variable_any::wait_until(_Lock& __lock, const chrono::time_point<_Clock, _Duration>& __t, _Predicate __pred) {
......@@ -363,6 +357,7 @@ _LIBCPP_POP_MACROS
363357# include <initializer_list>
364358# include <iosfwd>
365359# include <new>
360# include <optional>
366361# include <stdexcept>
367362# include <system_error>
368363# include <type_traits>
lib/libcxx/include/coroutine+1-1
......@@ -39,7 +39,7 @@ struct suspend_always;
3939 */
4040
4141#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
42# include <__cxx03/coroutine>
42# include <__cxx03/__config>
4343#else
4444# include <__config>
4545
lib/libcxx/include/cwchar+2-1
......@@ -107,6 +107,7 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
107107#else
108108# include <__config>
109109# include <__cstddef/size_t.h>
110# include <__memory/addressof.h>
110111# include <__type_traits/copy_cv.h>
111112# include <__type_traits/is_constant_evaluated.h>
112113# include <__type_traits/is_equality_comparable.h>
......@@ -237,7 +238,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __constexpr_wmemchr(_Tp
237238# if __has_builtin(__builtin_wmemchr)
238239 if (!__libcpp_is_constant_evaluated()) {
239240 wchar_t __value_buffer = 0;
240 __builtin_memcpy(&__value_buffer, &__value, sizeof(wchar_t));
241 __builtin_memcpy(&__value_buffer, std::addressof(__value), sizeof(wchar_t));
241242 return reinterpret_cast<_Tp*>(
242243 __builtin_wmemchr(reinterpret_cast<__copy_cv_t<_Tp, wchar_t>*>(__str), __value_buffer, __count));
243244 }
lib/libcxx/include/deque+35-26
......@@ -59,9 +59,9 @@ public:
5959
6060 deque& operator=(const deque& c);
6161 deque& operator=(deque&& c)
62 noexcept(
63 allocator_type::propagate_on_container_move_assignment::value &&
64 is_nothrow_move_assignable<allocator_type>::value);
62 noexcept((allocator_traits<allocator_type>::propagate_on_container_move_assignment::value &&
63 is_nothrow_move_assignable<allocator_type>::value) ||
64 allocator_traits<allocator_type>::is_always_equal::value);
6565 deque& operator=(initializer_list<value_type> il);
6666
6767 template <class InputIterator>
......@@ -230,6 +230,7 @@ template <class T, class Allocator, class Predicate>
230230# include <__type_traits/is_convertible.h>
231231# include <__type_traits/is_nothrow_assignable.h>
232232# include <__type_traits/is_nothrow_constructible.h>
233# include <__type_traits/is_replaceable.h>
233234# include <__type_traits/is_same.h>
234235# include <__type_traits/is_swappable.h>
235236# include <__type_traits/is_trivially_relocatable.h>
......@@ -283,7 +284,7 @@ template <class _ValueType,
283284 __deque_block_size<_ValueType, _DiffType>::value
284285# endif
285286 >
286class _LIBCPP_TEMPLATE_VIS __deque_iterator {
287class __deque_iterator {
287288 typedef _MapPointer __map_iterator;
288289
289290public:
......@@ -444,9 +445,9 @@ private:
444445 __ptr_(__p) {}
445446
446447 template <class _Tp, class _Ap>
447 friend class _LIBCPP_TEMPLATE_VIS deque;
448 friend class deque;
448449 template <class _Vp, class _Pp, class _Rp, class _MP, class _Dp, _Dp>
449 friend class _LIBCPP_TEMPLATE_VIS __deque_iterator;
450 friend class __deque_iterator;
450451
451452 template <class>
452453 friend struct __segmented_iterator_traits;
......@@ -486,7 +487,7 @@ const _DiffType __deque_iterator<_ValueType, _Pointer, _Reference, _MapPointer,
486487 __deque_block_size<_ValueType, _DiffType>::value;
487488
488489template <class _Tp, class _Allocator /*= allocator<_Tp>*/>
489class _LIBCPP_TEMPLATE_VIS deque {
490class deque {
490491public:
491492 // types:
492493
......@@ -530,6 +531,10 @@ public:
530531 __libcpp_is_trivially_relocatable<__map>::value && __libcpp_is_trivially_relocatable<allocator_type>::value,
531532 deque,
532533 void>;
534 using __replaceable _LIBCPP_NODEBUG =
535 __conditional_t<__is_replaceable_v<__map> && __container_allocator_is_replaceable<__alloc_traits>::value,
536 deque,
537 void>;
533538
534539 static_assert(is_nothrow_default_constructible<allocator_type>::value ==
535540 is_nothrow_default_constructible<__pointer_allocator>::value,
......@@ -674,9 +679,10 @@ public:
674679
675680 _LIBCPP_HIDE_FROM_ABI deque(deque&& __c) noexcept(is_nothrow_move_constructible<allocator_type>::value);
676681 _LIBCPP_HIDE_FROM_ABI deque(deque&& __c, const __type_identity_t<allocator_type>& __a);
677 _LIBCPP_HIDE_FROM_ABI deque&
678 operator=(deque&& __c) noexcept(__alloc_traits::propagate_on_container_move_assignment::value &&
679 is_nothrow_move_assignable<allocator_type>::value);
682 _LIBCPP_HIDE_FROM_ABI deque& operator=(deque&& __c) noexcept(
683 (__alloc_traits::propagate_on_container_move_assignment::value &&
684 is_nothrow_move_assignable<allocator_type>::value) ||
685 __alloc_traits::is_always_equal::value);
680686
681687 _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<value_type> __il) { assign(__il.begin(), __il.end()); }
682688# endif // _LIBCPP_CXX03_LANG
......@@ -924,7 +930,7 @@ private:
924930 (void)__end;
925931 (void)__annotation_type;
926932 (void)__place;
927# if _LIBCPP_HAS_ASAN
933# if __has_feature(address_sanitizer)
928934 // __beg - index of the first item to annotate
929935 // __end - index behind the last item to annotate (so last item + 1)
930936 // __annotation_type - __asan_unposion or __asan_poison
......@@ -1017,23 +1023,23 @@ private:
10171023 std::__annotate_double_ended_contiguous_container<_Allocator>(
10181024 __mem_beg, __mem_end, __old_beg, __old_end, __new_beg, __new_end);
10191025 }
1020# endif // _LIBCPP_HAS_ASAN
1026# endif // __has_feature(address_sanitizer)
10211027 }
10221028
10231029 _LIBCPP_HIDE_FROM_ABI void __annotate_new(size_type __current_size) const _NOEXCEPT {
10241030 (void)__current_size;
1025# if _LIBCPP_HAS_ASAN
1031# if __has_feature(address_sanitizer)
10261032 if (__current_size == 0)
10271033 __annotate_from_to(0, __map_.size() * __block_size, __asan_poison, __asan_back_moved);
10281034 else {
10291035 __annotate_from_to(0, __start_, __asan_poison, __asan_front_moved);
10301036 __annotate_from_to(__start_ + __current_size, __map_.size() * __block_size, __asan_poison, __asan_back_moved);
10311037 }
1032# endif // _LIBCPP_HAS_ASAN
1038# endif // __has_feature(address_sanitizer)
10331039 }
10341040
10351041 _LIBCPP_HIDE_FROM_ABI void __annotate_delete() const _NOEXCEPT {
1036# if _LIBCPP_HAS_ASAN
1042# if __has_feature(address_sanitizer)
10371043 if (empty()) {
10381044 for (size_t __i = 0; __i < __map_.size(); ++__i) {
10391045 __annotate_whole_block(__i, __asan_unposion);
......@@ -1042,19 +1048,19 @@ private:
10421048 __annotate_from_to(0, __start_, __asan_unposion, __asan_front_moved);
10431049 __annotate_from_to(__start_ + size(), __map_.size() * __block_size, __asan_unposion, __asan_back_moved);
10441050 }
1045# endif // _LIBCPP_HAS_ASAN
1051# endif // __has_feature(address_sanitizer)
10461052 }
10471053
10481054 _LIBCPP_HIDE_FROM_ABI void __annotate_increase_front(size_type __n) const _NOEXCEPT {
10491055 (void)__n;
1050# if _LIBCPP_HAS_ASAN
1056# if __has_feature(address_sanitizer)
10511057 __annotate_from_to(__start_ - __n, __start_, __asan_unposion, __asan_front_moved);
10521058# endif
10531059 }
10541060
10551061 _LIBCPP_HIDE_FROM_ABI void __annotate_increase_back(size_type __n) const _NOEXCEPT {
10561062 (void)__n;
1057# if _LIBCPP_HAS_ASAN
1063# if __has_feature(address_sanitizer)
10581064 __annotate_from_to(__start_ + size(), __start_ + size() + __n, __asan_unposion, __asan_back_moved);
10591065# endif
10601066 }
......@@ -1062,7 +1068,7 @@ private:
10621068 _LIBCPP_HIDE_FROM_ABI void __annotate_shrink_front(size_type __old_size, size_type __old_start) const _NOEXCEPT {
10631069 (void)__old_size;
10641070 (void)__old_start;
1065# if _LIBCPP_HAS_ASAN
1071# if __has_feature(address_sanitizer)
10661072 __annotate_from_to(__old_start, __old_start + (__old_size - size()), __asan_poison, __asan_front_moved);
10671073# endif
10681074 }
......@@ -1070,7 +1076,7 @@ private:
10701076 _LIBCPP_HIDE_FROM_ABI void __annotate_shrink_back(size_type __old_size, size_type __old_start) const _NOEXCEPT {
10711077 (void)__old_size;
10721078 (void)__old_start;
1073# if _LIBCPP_HAS_ASAN
1079# if __has_feature(address_sanitizer)
10741080 __annotate_from_to(__old_start + size(), __old_start + __old_size, __asan_poison, __asan_back_moved);
10751081# endif
10761082 }
......@@ -1083,7 +1089,7 @@ private:
10831089 __annotate_whole_block(size_t __block_index, __asan_annotation_type __annotation_type) const _NOEXCEPT {
10841090 (void)__block_index;
10851091 (void)__annotation_type;
1086# if _LIBCPP_HAS_ASAN
1092# if __has_feature(address_sanitizer)
10871093 __map_const_iterator __block_it = __map_.begin() + __block_index;
10881094 const void* __block_start = std::__to_address(*__block_it);
10891095 const void* __block_end = std::__to_address(*__block_it + __block_size);
......@@ -1096,7 +1102,7 @@ private:
10961102 }
10971103# endif
10981104 }
1099# if _LIBCPP_HAS_ASAN
1105# if __has_feature(address_sanitizer)
11001106
11011107public:
11021108 _LIBCPP_HIDE_FROM_ABI bool __verify_asan_annotations() const _NOEXCEPT {
......@@ -1158,7 +1164,7 @@ public:
11581164 }
11591165
11601166private:
1161# endif // _LIBCPP_HAS_ASAN
1167# endif // __has_feature(address_sanitizer)
11621168 _LIBCPP_HIDE_FROM_ABI bool __maybe_remove_front_spare(bool __keep_one = true) {
11631169 if (__front_spare_blocks() >= 2 || (!__keep_one && __front_spare_blocks())) {
11641170 __annotate_whole_block(0, __asan_unposion);
......@@ -1379,8 +1385,9 @@ inline deque<_Tp, _Allocator>::deque(deque&& __c, const __type_identity_t<alloca
13791385
13801386template <class _Tp, class _Allocator>
13811387inline deque<_Tp, _Allocator>& deque<_Tp, _Allocator>::operator=(deque&& __c) noexcept(
1382 __alloc_traits::propagate_on_container_move_assignment::value &&
1383 is_nothrow_move_assignable<allocator_type>::value) {
1388 (__alloc_traits::propagate_on_container_move_assignment::value &&
1389 is_nothrow_move_assignable<allocator_type>::value) ||
1390 __alloc_traits::is_always_equal::value) {
13841391 __move_assign(__c, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());
13851392 return *this;
13861393}
......@@ -2623,7 +2630,9 @@ struct __container_traits<deque<_Tp, _Allocator> > {
26232630 // either end, there are no effects. Otherwise, if an exception is thrown by the move constructor of a
26242631 // non-Cpp17CopyInsertable T, the effects are unspecified.
26252632 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
2626 _Or<is_nothrow_move_constructible<_Tp>, __is_cpp17_copy_insertable<_Allocator> >::value;
2633 is_nothrow_move_constructible<_Tp>::value || __is_cpp17_copy_insertable_v<_Allocator>;
2634
2635 static _LIBCPP_CONSTEXPR const bool __reservable = false;
26272636};
26282637
26292638_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/execution+1-1
......@@ -33,7 +33,7 @@ namespace std {
3333*/
3434
3535#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
36# include <__cxx03/execution>
36# include <__cxx03/__config>
3737#else
3838# include <__config>
3939# include <__type_traits/is_execution_policy.h>
lib/libcxx/include/expected+1-1
......@@ -39,7 +39,7 @@ namespace std {
3939*/
4040
4141#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
42# include <__cxx03/expected>
42# include <__cxx03/__config>
4343#else
4444# include <__config>
4545
lib/libcxx/include/experimental/__simd/declaration.h+1-1
......@@ -49,7 +49,7 @@ using native = __vec_ext<_LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES / sizeof(_Tp)>;
4949// TODO: make this platform dependent
5050template <class _Tp, size_t _Np, class... _Abis>
5151struct deduce {
52 using type = fixed_size<_Np>;
52 using type _LIBCPP_NODEBUG = fixed_size<_Np>;
5353};
5454
5555// TODO: make this platform dependent
lib/libcxx/include/experimental/__simd/utility.h+1-1
......@@ -58,7 +58,7 @@ _LIBCPP_HIDE_FROM_ABI auto __choose_mask_type() {
5858
5959template <class _Tp>
6060_LIBCPP_HIDE_FROM_ABI auto constexpr __set_all_bits(bool __v) {
61 return __v ? (numeric_limits<decltype(__choose_mask_type<_Tp>())>::max()) : 0;
61 return __v ? (numeric_limits<decltype(experimental::__choose_mask_type<_Tp>())>::max()) : 0;
6262}
6363
6464template <class _From, class _To, class = void>
lib/libcxx/include/experimental/iterator+7-1
......@@ -53,7 +53,7 @@ namespace std {
5353*/
5454
5555#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
56# include <__cxx03/experimental/iterator>
56# include <__cxx03/__config>
5757#else
5858# include <__config>
5959# include <__memory/addressof.h>
......@@ -127,8 +127,14 @@ _LIBCPP_POP_MACROS
127127# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
128128# include <cstddef>
129129# include <iosfwd>
130# include <optional>
130131# include <type_traits>
131132# endif
133
134# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 23
135# include <locale>
136# endif
137
132138#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
133139
134140#endif // _LIBCPP_EXPERIMENTAL_ITERATOR
lib/libcxx/include/experimental/memory+2-2
......@@ -50,15 +50,15 @@ public:
5050*/
5151
5252#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
53# include <__cxx03/experimental/memory>
53# include <__cxx03/__config>
5454#else
5555# include <__config>
5656# include <__cstddef/nullptr_t.h>
5757# include <__cstddef/size_t.h>
5858# include <__functional/hash.h>
5959# include <__functional/operations.h>
60# include <__type_traits/add_lvalue_reference.h>
6160# include <__type_traits/add_pointer.h>
61# include <__type_traits/add_reference.h>
6262# include <__type_traits/common_type.h>
6363# include <__type_traits/enable_if.h>
6464# include <__type_traits/is_convertible.h>
lib/libcxx/include/experimental/propagate_const+1-1
......@@ -108,7 +108,7 @@
108108*/
109109
110110#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
111# include <__cxx03/experimental/propagate_const>
111# include <__cxx03/__config>
112112#else
113113# include <__config>
114114# include <__cstddef/nullptr_t.h>
lib/libcxx/include/experimental/simd+1-1
......@@ -76,7 +76,7 @@ inline namespace parallelism_v2 {
7676#endif
7777
7878#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
79# include <__cxx03/experimental/simd>
79# include <__cxx03/__config>
8080#else
8181# include <__config>
8282# include <experimental/__simd/aligned_tag.h>
lib/libcxx/include/experimental/type_traits+5-5
......@@ -69,7 +69,7 @@ inline namespace fundamentals_v1 {
6969 */
7070
7171#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
72# include <__cxx03/experimental/type_traits>
72# include <__cxx03/__config>
7373#else
7474# include <__config>
7575
......@@ -87,16 +87,16 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS
8787// 3.3.2, Other type transformations
8888/*
8989template <class>
90class _LIBCPP_TEMPLATE_VIS raw_invocation_type;
90class raw_invocation_type;
9191
9292template <class _Fn, class ..._Args>
93class _LIBCPP_TEMPLATE_VIS raw_invocation_type<_Fn(_Args...)>;
93class raw_invocation_type<_Fn(_Args...)>;
9494
9595template <class>
96class _LIBCPP_TEMPLATE_VIS invokation_type;
96class invokation_type;
9797
9898template <class _Fn, class ..._Args>
99class _LIBCPP_TEMPLATE_VIS invokation_type<_Fn(_Args...)>;
99class invokation_type<_Fn(_Args...)>;
100100
101101template <class _Tp>
102102using invokation_type_t = typename invokation_type<_Tp>::type;
lib/libcxx/include/experimental/utility+1-1
......@@ -42,7 +42,7 @@ inline namespace fundamentals_v1 {
4242
4343_LIBCPP_BEGIN_NAMESPACE_LFTS
4444
45struct _LIBCPP_TEMPLATE_VIS erased_type {};
45struct erased_type {};
4646
4747_LIBCPP_END_NAMESPACE_LFTS
4848
lib/libcxx/include/ext/__hash+12-12
......@@ -20,64 +20,64 @@
2020namespace __gnu_cxx {
2121
2222template <typename _Tp>
23struct _LIBCPP_TEMPLATE_VIS hash {};
23struct hash {};
2424
2525template <>
26struct _LIBCPP_TEMPLATE_VIS hash<const char*> : public std::__unary_function<const char*, size_t> {
26struct hash<const char*> : public std::__unary_function<const char*, size_t> {
2727 _LIBCPP_HIDE_FROM_ABI size_t operator()(const char* __c) const _NOEXCEPT {
2828 return std::__do_string_hash(__c, __c + strlen(__c));
2929 }
3030};
3131
3232template <>
33struct _LIBCPP_TEMPLATE_VIS hash<char*> : public std::__unary_function<char*, size_t> {
33struct hash<char*> : public std::__unary_function<char*, size_t> {
3434 _LIBCPP_HIDE_FROM_ABI size_t operator()(char* __c) const _NOEXCEPT {
3535 return std::__do_string_hash<const char*>(__c, __c + strlen(__c));
3636 }
3737};
3838
3939template <>
40struct _LIBCPP_TEMPLATE_VIS hash<char> : public std::__unary_function<char, size_t> {
40struct hash<char> : public std::__unary_function<char, size_t> {
4141 _LIBCPP_HIDE_FROM_ABI size_t operator()(char __c) const _NOEXCEPT { return __c; }
4242};
4343
4444template <>
45struct _LIBCPP_TEMPLATE_VIS hash<signed char> : public std::__unary_function<signed char, size_t> {
45struct hash<signed char> : public std::__unary_function<signed char, size_t> {
4646 _LIBCPP_HIDE_FROM_ABI size_t operator()(signed char __c) const _NOEXCEPT { return __c; }
4747};
4848
4949template <>
50struct _LIBCPP_TEMPLATE_VIS hash<unsigned char> : public std::__unary_function<unsigned char, size_t> {
50struct hash<unsigned char> : public std::__unary_function<unsigned char, size_t> {
5151 _LIBCPP_HIDE_FROM_ABI size_t operator()(unsigned char __c) const _NOEXCEPT { return __c; }
5252};
5353
5454template <>
55struct _LIBCPP_TEMPLATE_VIS hash<short> : public std::__unary_function<short, size_t> {
55struct hash<short> : public std::__unary_function<short, size_t> {
5656 _LIBCPP_HIDE_FROM_ABI size_t operator()(short __c) const _NOEXCEPT { return __c; }
5757};
5858
5959template <>
60struct _LIBCPP_TEMPLATE_VIS hash<unsigned short> : public std::__unary_function<unsigned short, size_t> {
60struct hash<unsigned short> : public std::__unary_function<unsigned short, size_t> {
6161 _LIBCPP_HIDE_FROM_ABI size_t operator()(unsigned short __c) const _NOEXCEPT { return __c; }
6262};
6363
6464template <>
65struct _LIBCPP_TEMPLATE_VIS hash<int> : public std::__unary_function<int, size_t> {
65struct hash<int> : public std::__unary_function<int, size_t> {
6666 _LIBCPP_HIDE_FROM_ABI size_t operator()(int __c) const _NOEXCEPT { return __c; }
6767};
6868
6969template <>
70struct _LIBCPP_TEMPLATE_VIS hash<unsigned int> : public std::__unary_function<unsigned int, size_t> {
70struct hash<unsigned int> : public std::__unary_function<unsigned int, size_t> {
7171 _LIBCPP_HIDE_FROM_ABI size_t operator()(unsigned int __c) const _NOEXCEPT { return __c; }
7272};
7373
7474template <>
75struct _LIBCPP_TEMPLATE_VIS hash<long> : public std::__unary_function<long, size_t> {
75struct hash<long> : public std::__unary_function<long, size_t> {
7676 _LIBCPP_HIDE_FROM_ABI size_t operator()(long __c) const _NOEXCEPT { return __c; }
7777};
7878
7979template <>
80struct _LIBCPP_TEMPLATE_VIS hash<unsigned long> : public std::__unary_function<unsigned long, size_t> {
80struct hash<unsigned long> : public std::__unary_function<unsigned long, size_t> {
8181 _LIBCPP_HIDE_FROM_ABI size_t operator()(unsigned long __c) const _NOEXCEPT { return __c; }
8282};
8383} // namespace __gnu_cxx
lib/libcxx/include/ext/hash_map+17-17
......@@ -338,7 +338,7 @@ public:
338338};
339339
340340template <class _HashIterator>
341class _LIBCPP_TEMPLATE_VIS __hash_map_iterator {
341class __hash_map_iterator {
342342 _HashIterator __i_;
343343
344344 typedef const typename _HashIterator::value_type::first_type key_type;
......@@ -376,19 +376,19 @@ public:
376376 }
377377
378378 template <class, class, class, class, class>
379 friend class _LIBCPP_TEMPLATE_VIS hash_map;
379 friend class hash_map;
380380 template <class, class, class, class, class>
381 friend class _LIBCPP_TEMPLATE_VIS hash_multimap;
381 friend class hash_multimap;
382382 template <class>
383 friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
383 friend class __hash_const_iterator;
384384 template <class>
385 friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
385 friend class __hash_const_local_iterator;
386386 template <class>
387 friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
387 friend class __hash_map_const_iterator;
388388};
389389
390390template <class _HashIterator>
391class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator {
391class __hash_map_const_iterator {
392392 _HashIterator __i_;
393393
394394 typedef const typename _HashIterator::value_type::first_type key_type;
......@@ -430,13 +430,13 @@ public:
430430 }
431431
432432 template <class, class, class, class, class>
433 friend class _LIBCPP_TEMPLATE_VIS hash_map;
433 friend class hash_map;
434434 template <class, class, class, class, class>
435 friend class _LIBCPP_TEMPLATE_VIS hash_multimap;
435 friend class hash_multimap;
436436 template <class>
437 friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
437 friend class __hash_const_iterator;
438438 template <class>
439 friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
439 friend class __hash_const_local_iterator;
440440};
441441
442442template <class _Key,
......@@ -444,7 +444,7 @@ template <class _Key,
444444 class _Hash = hash<_Key>,
445445 class _Pred = std::equal_to<_Key>,
446446 class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
447class _LIBCPP_TEMPLATE_VIS hash_map {
447class hash_map {
448448public:
449449 // types
450450 typedef _Key key_type;
......@@ -520,7 +520,7 @@ public:
520520 _LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
521521
522522 _LIBCPP_HIDE_FROM_ABI std::pair<iterator, bool> insert(const value_type& __x) {
523 return __table_.__insert_unique(__x);
523 return __table_.__emplace_unique(__x);
524524 }
525525 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x).first; }
526526 template <class _InputIterator>
......@@ -625,7 +625,7 @@ template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
625625template <class _InputIterator>
626626inline void hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
627627 for (; __first != __last; ++__first)
628 __table_.__insert_unique(*__first);
628 __table_.__emplace_unique(*__first);
629629}
630630
631631template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -670,7 +670,7 @@ template <class _Key,
670670 class _Hash = hash<_Key>,
671671 class _Pred = std::equal_to<_Key>,
672672 class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
673class _LIBCPP_TEMPLATE_VIS hash_multimap {
673class hash_multimap {
674674public:
675675 // types
676676 typedef _Key key_type;
......@@ -744,7 +744,7 @@ public:
744744 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return __table_.begin(); }
745745 _LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
746746
747 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__insert_multi(__x); }
747 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__emplace_multi(__x); }
748748 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x); }
749749 template <class _InputIterator>
750750 _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last);
......@@ -831,7 +831,7 @@ template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
831831template <class _InputIterator>
832832inline void hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
833833 for (; __first != __last; ++__first)
834 __table_.__insert_multi(*__first);
834 __table_.__emplace_multi(*__first);
835835}
836836
837837template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
lib/libcxx/include/ext/hash_set+6-6
......@@ -219,7 +219,7 @@ template <class _Value,
219219 class _Hash = hash<_Value>,
220220 class _Pred = std::equal_to<_Value>,
221221 class _Alloc = std::allocator<_Value> >
222class _LIBCPP_TEMPLATE_VIS hash_set {
222class hash_set {
223223public:
224224 // types
225225 typedef _Value key_type;
......@@ -279,7 +279,7 @@ public:
279279 _LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
280280
281281 _LIBCPP_HIDE_FROM_ABI std::pair<iterator, bool> insert(const value_type& __x) {
282 return __table_.__insert_unique(__x);
282 return __table_.__emplace_unique(__x);
283283 }
284284 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x).first; }
285285 template <class _InputIterator>
......@@ -365,7 +365,7 @@ template <class _Value, class _Hash, class _Pred, class _Alloc>
365365template <class _InputIterator>
366366inline void hash_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
367367 for (; __first != __last; ++__first)
368 __table_.__insert_unique(*__first);
368 __table_.__emplace_unique(*__first);
369369}
370370
371371template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -398,7 +398,7 @@ template <class _Value,
398398 class _Hash = hash<_Value>,
399399 class _Pred = std::equal_to<_Value>,
400400 class _Alloc = std::allocator<_Value> >
401class _LIBCPP_TEMPLATE_VIS hash_multiset {
401class hash_multiset {
402402public:
403403 // types
404404 typedef _Value key_type;
......@@ -458,7 +458,7 @@ public:
458458 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return __table_.begin(); }
459459 _LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
460460
461 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__insert_multi(__x); }
461 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__emplace_multi(__x); }
462462 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x); }
463463 template <class _InputIterator>
464464 _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last);
......@@ -543,7 +543,7 @@ template <class _Value, class _Hash, class _Pred, class _Alloc>
543543template <class _InputIterator>
544544inline void hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
545545 for (; __first != __last; ++__first)
546 __table_.__insert_multi(*__first);
546 __table_.__emplace_multi(*__first);
547547}
548548
549549template <class _Value, class _Hash, class _Pred, class _Alloc>
lib/libcxx/include/filesystem+1-1
......@@ -534,7 +534,7 @@ inline constexpr bool std::ranges::enable_view<std::filesystem::recursive_direct
534534*/
535535
536536#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
537# include <__cxx03/filesystem>
537# include <__cxx03/__config>
538538#else
539539# include <__config>
540540
lib/libcxx/include/flat_map+9
......@@ -72,6 +72,15 @@ namespace std {
7272# include <version>
7373
7474// standard required includes
75
76// [iterator.range]
77# include <__iterator/access.h>
78# include <__iterator/data.h>
79# include <__iterator/empty.h>
80# include <__iterator/reverse_access.h>
81# include <__iterator/size.h>
82
83// [flat.map.syn]
7584# include <compare>
7685# include <initializer_list>
7786
lib/libcxx/include/flat_set created+85
......@@ -0,0 +1,85 @@
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_SET
11#define _LIBCPP_FLAT_SET
12
13/*
14 Header <flat_set> synopsis
15
16#include <compare> // see [compare.syn]
17#include <initializer_list> // see [initializer.list.syn]
18
19namespace std {
20 // [flat.set], class template flat_set
21 template<class Key, class Compare = less<Key>, class KeyContainer = vector<Key>>
22 class flat_set;
23
24 struct sorted_unique_t { explicit sorted_unique_t() = default; };
25 inline constexpr sorted_unique_t sorted_unique{};
26
27 template<class Key, class Compare, class KeyContainer, class Allocator>
28 struct uses_allocator<flat_set<Key, Compare, KeyContainer>, Allocator>;
29
30 // [flat.set.erasure], erasure for flat_set
31 template<class Key, class Compare, class KeyContainer, class Predicate>
32 typename flat_set<Key, Compare, KeyContainer>::size_type
33 erase_if(flat_set<Key, Compare, KeyContainer>& c, Predicate pred);
34
35 // [flat.multiset], class template flat_multiset
36 template<class Key, class Compare = less<Key>, class KeyContainer = vector<Key>>
37 class flat_multiset;
38
39 struct sorted_equivalent_t { explicit sorted_equivalent_t() = default; };
40 inline constexpr sorted_equivalent_t sorted_equivalent{};
41
42 template<class Key, class Compare, class KeyContainer, class Allocator>
43 struct uses_allocator<flat_multiset<Key, Compare, KeyContainer>, Allocator>;
44
45 // [flat.multiset.erasure], erasure for flat_multiset
46 template<class Key, class Compare, class KeyContainer, class Predicate>
47 typename flat_multiset<Key, Compare, KeyContainer>::size_type
48 erase_if(flat_multiset<Key, Compare, KeyContainer>& c, Predicate pred);
49}
50*/
51
52#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
53# include <__cxx03/__config>
54#else
55# include <__config>
56
57# if _LIBCPP_STD_VER >= 23
58# include <__flat_map/sorted_equivalent.h>
59# include <__flat_map/sorted_unique.h>
60# include <__flat_set/flat_multiset.h>
61# include <__flat_set/flat_set.h>
62# endif
63
64// for feature-test macros
65# include <version>
66
67// standard required includes
68
69// [iterator.range]
70# include <__iterator/access.h>
71# include <__iterator/data.h>
72# include <__iterator/empty.h>
73# include <__iterator/reverse_access.h>
74# include <__iterator/size.h>
75
76// [flat.set.syn]
77# include <compare>
78# include <initializer_list>
79
80# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
81# pragma GCC system_header
82# endif
83#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
84
85#endif // _LIBCPP_FLAT_SET
lib/libcxx/include/format+1-1
......@@ -192,7 +192,7 @@ namespace std {
192192*/
193193
194194#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
195# include <__cxx03/format>
195# include <__cxx03/__config>
196196#else
197197# include <__config>
198198
lib/libcxx/include/forward_list+325-284
......@@ -58,9 +58,9 @@ public:
5858
5959 forward_list& operator=(const forward_list& x);
6060 forward_list& operator=(forward_list&& x)
61 noexcept(
62 allocator_type::propagate_on_container_move_assignment::value &&
63 is_nothrow_move_assignable<allocator_type>::value);
61 noexcept((__node_traits::propagate_on_container_move_assignment::value &&
62 is_nothrow_move_assignable<allocator_type>::value) ||
63 allocator_traits<allocator_type>::is_always_equal::value);
6464 forward_list& operator=(initializer_list<value_type> il);
6565
6666 template <class InputIterator>
......@@ -233,6 +233,7 @@ template <class T, class Allocator, class Predicate>
233233# include <__type_traits/is_pointer.h>
234234# include <__type_traits/is_same.h>
235235# include <__type_traits/is_swappable.h>
236# include <__type_traits/remove_cv.h>
236237# include <__type_traits/type_identity.h>
237238# include <__utility/forward.h>
238239# include <__utility/move.h>
......@@ -282,7 +283,6 @@ struct __forward_node_traits {
282283 typedef _NodePtr __node_pointer;
283284 typedef __forward_begin_node<_NodePtr> __begin_node;
284285 typedef __rebind_pointer_t<_NodePtr, __begin_node> __begin_node_pointer;
285 typedef __rebind_pointer_t<_NodePtr, void> __void_pointer;
286286
287287// TODO(LLVM 22): Remove this check
288288# ifndef _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
......@@ -294,11 +294,6 @@ struct __forward_node_traits {
294294 "is being broken between LLVM 19 and LLVM 20. If you don't care about your ABI being broken, define "
295295 "the _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB macro to silence this diagnostic.");
296296# endif
297
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));
301 }
302297};
303298
304299template <class _NodePtr>
......@@ -308,12 +303,8 @@ struct __forward_begin_node {
308303
309304 pointer __next_;
310305
311 _LIBCPP_HIDE_FROM_ABI __forward_begin_node() : __next_(nullptr) {}
312 _LIBCPP_HIDE_FROM_ABI explicit __forward_begin_node(pointer __n) : __next_(__n) {}
313
314 _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __next_as_begin() const {
315 return static_cast<__begin_node_pointer>(__next_);
316 }
306 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __forward_begin_node() : __next_(nullptr) {}
307 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit __forward_begin_node(pointer __n) : __next_(__n) {}
317308};
318309
319310template <class _Tp, class _VoidPtr>
......@@ -336,7 +327,7 @@ private:
336327 };
337328
338329public:
339 _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return __value_; }
330 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return __value_; }
340331# else
341332
342333private:
......@@ -346,43 +337,38 @@ public:
346337 _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return *std::__launder(reinterpret_cast<_Tp*>(&__buffer_)); }
347338# endif
348339
349 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_node(_NodePtr __next) : _Base(__next) {}
350 _LIBCPP_HIDE_FROM_ABI ~__forward_list_node() {}
340 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_node(_NodePtr __next) : _Base(__next) {}
341 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI ~__forward_list_node() {}
351342};
352343
353344template <class _Tp, class _Alloc = allocator<_Tp> >
354class _LIBCPP_TEMPLATE_VIS forward_list;
345class forward_list;
355346template <class _NodeConstPtr>
356class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator;
347class __forward_list_const_iterator;
357348
358349template <class _NodePtr>
359class _LIBCPP_TEMPLATE_VIS __forward_list_iterator {
350class __forward_list_iterator {
360351 typedef __forward_node_traits<_NodePtr> __traits;
352 typedef typename __traits::__node_type __node_type;
353 typedef typename __traits::__begin_node __begin_node_type;
361354 typedef typename __traits::__node_pointer __node_pointer;
362355 typedef typename __traits::__begin_node_pointer __begin_node_pointer;
363 typedef typename __traits::__void_pointer __void_pointer;
364356
365357 __begin_node_pointer __ptr_;
366358
367 _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __get_begin() const {
368 return static_cast<__begin_node_pointer>(static_cast<__void_pointer>(__ptr_));
369 }
370 _LIBCPP_HIDE_FROM_ABI __node_pointer __get_unsafe_node_pointer() const {
371 return static_cast<__node_pointer>(static_cast<__void_pointer>(__ptr_));
372 }
373
374 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_iterator(nullptr_t) _NOEXCEPT : __ptr_(nullptr) {}
359 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_iterator(nullptr_t) _NOEXCEPT
360 : __ptr_(nullptr) {}
375361
376 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_iterator(__begin_node_pointer __p) _NOEXCEPT
377 : __ptr_(__traits::__as_iter_node(__p)) {}
362 _LIBCPP_CONSTEXPR_SINCE_CXX26
363 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_iterator(__begin_node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
378364
379 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT
380 : __ptr_(__traits::__as_iter_node(__p)) {}
365 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT
366 : __ptr_(std::__static_fancy_pointer_cast<__begin_node_pointer>(__p)) {}
381367
382368 template <class, class>
383 friend class _LIBCPP_TEMPLATE_VIS forward_list;
369 friend class forward_list;
384370 template <class>
385 friend class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator;
371 friend class __forward_list_const_iterator;
386372
387373public:
388374 typedef forward_iterator_tag iterator_category;
......@@ -391,58 +377,57 @@ public:
391377 typedef typename pointer_traits<__node_pointer>::difference_type difference_type;
392378 typedef __rebind_pointer_t<__node_pointer, value_type> pointer;
393379
394 _LIBCPP_HIDE_FROM_ABI __forward_list_iterator() _NOEXCEPT : __ptr_(nullptr) {}
380 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __forward_list_iterator() _NOEXCEPT : __ptr_(nullptr) {}
395381
396 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __get_unsafe_node_pointer()->__get_value(); }
397 _LIBCPP_HIDE_FROM_ABI pointer operator->() const {
398 return pointer_traits<pointer>::pointer_to(__get_unsafe_node_pointer()->__get_value());
382 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI reference operator*() const {
383 return std::__static_fancy_pointer_cast<__node_pointer>(__ptr_)->__get_value();
384 }
385 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI pointer operator->() const {
386 return pointer_traits<pointer>::pointer_to(std::__static_fancy_pointer_cast<__node_pointer>(__ptr_)->__get_value());
399387 }
400388
401 _LIBCPP_HIDE_FROM_ABI __forward_list_iterator& operator++() {
402 __ptr_ = __traits::__as_iter_node(__ptr_->__next_);
389 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __forward_list_iterator& operator++() {
390 __ptr_ = std::__static_fancy_pointer_cast<__begin_node_pointer>(__ptr_->__next_);
403391 return *this;
404392 }
405 _LIBCPP_HIDE_FROM_ABI __forward_list_iterator operator++(int) {
393 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __forward_list_iterator operator++(int) {
406394 __forward_list_iterator __t(*this);
407395 ++(*this);
408396 return __t;
409397 }
410398
411 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __forward_list_iterator& __x, const __forward_list_iterator& __y) {
399 friend _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI bool
400 operator==(const __forward_list_iterator& __x, const __forward_list_iterator& __y) {
412401 return __x.__ptr_ == __y.__ptr_;
413402 }
414 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __forward_list_iterator& __x, const __forward_list_iterator& __y) {
403 friend _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI bool
404 operator!=(const __forward_list_iterator& __x, const __forward_list_iterator& __y) {
415405 return !(__x == __y);
416406 }
417407};
418408
419409template <class _NodeConstPtr>
420class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator {
410class __forward_list_const_iterator {
421411 static_assert(!is_const<typename pointer_traits<_NodeConstPtr>::element_type>::value, "");
422412 typedef _NodeConstPtr _NodePtr;
423413
424414 typedef __forward_node_traits<_NodePtr> __traits;
425415 typedef typename __traits::__node_type __node_type;
416 typedef typename __traits::__begin_node __begin_node_type;
426417 typedef typename __traits::__node_pointer __node_pointer;
427418 typedef typename __traits::__begin_node_pointer __begin_node_pointer;
428 typedef typename __traits::__void_pointer __void_pointer;
429419
430420 __begin_node_pointer __ptr_;
431421
432 _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __get_begin() const {
433 return static_cast<__begin_node_pointer>(static_cast<__void_pointer>(__ptr_));
434 }
435 _LIBCPP_HIDE_FROM_ABI __node_pointer __get_unsafe_node_pointer() const {
436 return static_cast<__node_pointer>(static_cast<__void_pointer>(__ptr_));
437 }
438
439 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_const_iterator(nullptr_t) _NOEXCEPT : __ptr_(nullptr) {}
422 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_const_iterator(nullptr_t) _NOEXCEPT
423 : __ptr_(nullptr) {}
440424
441 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_const_iterator(__begin_node_pointer __p) _NOEXCEPT
442 : __ptr_(__traits::__as_iter_node(__p)) {}
425 _LIBCPP_CONSTEXPR_SINCE_CXX26
426 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_const_iterator(__begin_node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
443427
428 _LIBCPP_CONSTEXPR_SINCE_CXX26
444429 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_const_iterator(__node_pointer __p) _NOEXCEPT
445 : __ptr_(__traits::__as_iter_node(__p)) {}
430 : __ptr_(std::__static_fancy_pointer_cast<__begin_node_pointer>(__p)) {}
446431
447432 template <class, class>
448433 friend class forward_list;
......@@ -454,30 +439,32 @@ public:
454439 typedef typename pointer_traits<__node_pointer>::difference_type difference_type;
455440 typedef __rebind_pointer_t<__node_pointer, const value_type> pointer;
456441
457 _LIBCPP_HIDE_FROM_ABI __forward_list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {}
458 _LIBCPP_HIDE_FROM_ABI __forward_list_const_iterator(__forward_list_iterator<__node_pointer> __p) _NOEXCEPT
459 : __ptr_(__p.__ptr_) {}
442 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __forward_list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {}
443 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
444 __forward_list_const_iterator(__forward_list_iterator<__node_pointer> __p) _NOEXCEPT : __ptr_(__p.__ptr_) {}
460445
461 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __get_unsafe_node_pointer()->__get_value(); }
462 _LIBCPP_HIDE_FROM_ABI pointer operator->() const {
463 return pointer_traits<pointer>::pointer_to(__get_unsafe_node_pointer()->__get_value());
446 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI reference operator*() const {
447 return std::__static_fancy_pointer_cast<__node_pointer>(__ptr_)->__get_value();
448 }
449 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI pointer operator->() const {
450 return pointer_traits<pointer>::pointer_to(std::__static_fancy_pointer_cast<__node_pointer>(__ptr_)->__get_value());
464451 }
465452
466 _LIBCPP_HIDE_FROM_ABI __forward_list_const_iterator& operator++() {
467 __ptr_ = __traits::__as_iter_node(__ptr_->__next_);
453 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __forward_list_const_iterator& operator++() {
454 __ptr_ = std::__static_fancy_pointer_cast<__begin_node_pointer>(__ptr_->__next_);
468455 return *this;
469456 }
470 _LIBCPP_HIDE_FROM_ABI __forward_list_const_iterator operator++(int) {
457 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __forward_list_const_iterator operator++(int) {
471458 __forward_list_const_iterator __t(*this);
472459 ++(*this);
473460 return __t;
474461 }
475462
476 friend _LIBCPP_HIDE_FROM_ABI bool
463 friend _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI bool
477464 operator==(const __forward_list_const_iterator& __x, const __forward_list_const_iterator& __y) {
478465 return __x.__ptr_ == __y.__ptr_;
479466 }
480 friend _LIBCPP_HIDE_FROM_ABI bool
467 friend _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI bool
481468 operator!=(const __forward_list_const_iterator& __x, const __forward_list_const_iterator& __y) {
482469 return !(__x == __y);
483470 }
......@@ -501,48 +488,53 @@ protected:
501488
502489 _LIBCPP_COMPRESSED_PAIR(__begin_node, __before_begin_, __node_allocator, __alloc_);
503490
504 _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __before_begin() _NOEXCEPT {
491 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __before_begin() _NOEXCEPT {
505492 return pointer_traits<__begin_node_pointer>::pointer_to(__before_begin_);
506493 }
507 _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __before_begin() const _NOEXCEPT {
508 return pointer_traits<__begin_node_pointer>::pointer_to(const_cast<__begin_node&>(__before_begin_));
494
495 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __before_begin() const _NOEXCEPT {
496 return pointer_traits<__begin_node_pointer>::pointer_to(
497 *const_cast<__begin_node*>(std::addressof(__before_begin_)));
509498 }
510499
511500 typedef __forward_list_iterator<__node_pointer> iterator;
512501 typedef __forward_list_const_iterator<__node_pointer> const_iterator;
513502
514 _LIBCPP_HIDE_FROM_ABI __forward_list_base() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
503 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __forward_list_base()
504 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
515505 : __before_begin_(__begin_node()) {}
516 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_base(const allocator_type& __a)
506 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_base(const allocator_type& __a)
517507 : __before_begin_(__begin_node()), __alloc_(__node_allocator(__a)) {}
518 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_base(const __node_allocator& __a)
508 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_base(const __node_allocator& __a)
519509 : __before_begin_(__begin_node()), __alloc_(__a) {}
520510
521511public:
522512# ifndef _LIBCPP_CXX03_LANG
523 _LIBCPP_HIDE_FROM_ABI
513 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
524514 __forward_list_base(__forward_list_base&& __x) noexcept(is_nothrow_move_constructible<__node_allocator>::value);
525 _LIBCPP_HIDE_FROM_ABI __forward_list_base(__forward_list_base&& __x, const allocator_type& __a);
515 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
516 __forward_list_base(__forward_list_base&& __x, const allocator_type& __a);
526517# endif // _LIBCPP_CXX03_LANG
527518
528519 __forward_list_base(const __forward_list_base&) = delete;
529520 __forward_list_base& operator=(const __forward_list_base&) = delete;
530521
531 _LIBCPP_HIDE_FROM_ABI ~__forward_list_base();
522 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI ~__forward_list_base();
532523
533524protected:
534 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __forward_list_base& __x) {
525 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __forward_list_base& __x) {
535526 __copy_assign_alloc(__x, integral_constant<bool, __node_traits::propagate_on_container_copy_assignment::value>());
536527 }
537528
538 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__forward_list_base& __x)
529 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__forward_list_base& __x)
539530 _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value ||
540531 is_nothrow_move_assignable<__node_allocator>::value) {
541532 __move_assign_alloc(__x, integral_constant<bool, __node_traits::propagate_on_container_move_assignment::value>());
542533 }
543534
544535 template <class... _Args>
545 _LIBCPP_HIDE_FROM_ABI __node_pointer __create_node(__node_pointer __next, _Args&&... __args) {
536 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __node_pointer
537 __create_node(__node_pointer __next, _Args&&... __args) {
546538 __allocation_guard<__node_allocator> __guard(__alloc_, 1);
547539 // Begin the lifetime of the node itself. Note that this doesn't begin the lifetime of the value
548540 // held inside the node, since we need to use the allocator's construct() method for that.
......@@ -557,7 +549,7 @@ protected:
557549 return __guard.__release_ptr();
558550 }
559551
560 _LIBCPP_HIDE_FROM_ABI void __delete_node(__node_pointer __node) {
552 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __delete_node(__node_pointer __node) {
561553 // For the same reason as above, we use the allocator's destroy() method for the value_type,
562554 // but not for the node itself.
563555 __node_traits::destroy(__alloc_, std::addressof(__node->__get_value()));
......@@ -566,7 +558,7 @@ protected:
566558 }
567559
568560public:
569 _LIBCPP_HIDE_FROM_ABI void swap(__forward_list_base& __x)
561 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void swap(__forward_list_base& __x)
570562# if _LIBCPP_STD_VER >= 14
571563 _NOEXCEPT;
572564# else
......@@ -574,18 +566,21 @@ public:
574566# endif
575567
576568protected:
577 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT;
569 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT;
578570
579571private:
580 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __forward_list_base&, false_type) {}
581 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __forward_list_base& __x, true_type) {
572 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __forward_list_base&, false_type) {
573 }
574 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void
575 __copy_assign_alloc(const __forward_list_base& __x, true_type) {
582576 if (__alloc_ != __x.__alloc_)
583577 clear();
584578 __alloc_ = __x.__alloc_;
585579 }
586580
587 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__forward_list_base&, false_type) _NOEXCEPT {}
588 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__forward_list_base& __x, true_type)
581 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void
582 __move_assign_alloc(__forward_list_base&, false_type) _NOEXCEPT {}
583 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__forward_list_base& __x, true_type)
589584 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) {
590585 __alloc_ = std::move(__x.__alloc_);
591586 }
......@@ -594,14 +589,15 @@ private:
594589# ifndef _LIBCPP_CXX03_LANG
595590
596591template <class _Tp, class _Alloc>
597inline __forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x) noexcept(
598 is_nothrow_move_constructible<__node_allocator>::value)
592_LIBCPP_CONSTEXPR_SINCE_CXX26 inline __forward_list_base<_Tp, _Alloc>::__forward_list_base(
593 __forward_list_base&& __x) noexcept(is_nothrow_move_constructible<__node_allocator>::value)
599594 : __before_begin_(std::move(__x.__before_begin_)), __alloc_(std::move(__x.__alloc_)) {
600595 __x.__before_begin()->__next_ = nullptr;
601596}
602597
603598template <class _Tp, class _Alloc>
604inline __forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x, const allocator_type& __a)
599_LIBCPP_CONSTEXPR_SINCE_CXX26 inline __forward_list_base<_Tp, _Alloc>::__forward_list_base(
600 __forward_list_base&& __x, const allocator_type& __a)
605601 : __before_begin_(__begin_node()), __alloc_(__node_allocator(__a)) {
606602 if (__alloc_ == __x.__alloc_) {
607603 __before_begin()->__next_ = __x.__before_begin()->__next_;
......@@ -612,12 +608,12 @@ inline __forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base
612608# endif // _LIBCPP_CXX03_LANG
613609
614610template <class _Tp, class _Alloc>
615__forward_list_base<_Tp, _Alloc>::~__forward_list_base() {
611_LIBCPP_CONSTEXPR_SINCE_CXX26 __forward_list_base<_Tp, _Alloc>::~__forward_list_base() {
616612 clear();
617613}
618614
619615template <class _Tp, class _Alloc>
620inline void __forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x)
616_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void __forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x)
621617# if _LIBCPP_STD_VER >= 14
622618 _NOEXCEPT
623619# else
......@@ -630,7 +626,7 @@ inline void __forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x)
630626}
631627
632628template <class _Tp, class _Alloc>
633void __forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT {
629_LIBCPP_CONSTEXPR_SINCE_CXX26 void __forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT {
634630 for (__node_pointer __p = __before_begin()->__next_; __p != nullptr;) {
635631 __node_pointer __next = __p->__next_;
636632 __delete_node(__p);
......@@ -640,7 +636,7 @@ void __forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT {
640636}
641637
642638template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
643class _LIBCPP_TEMPLATE_VIS forward_list : private __forward_list_base<_Tp, _Alloc> {
639class forward_list : private __forward_list_base<_Tp, _Alloc> {
644640 typedef __forward_list_base<_Tp, _Alloc> __base;
645641 typedef typename __base::__node_allocator __node_allocator;
646642 typedef typename __base::__node_type __node_type;
......@@ -675,104 +671,123 @@ public:
675671 typedef void __remove_return_type;
676672# endif
677673
678 _LIBCPP_HIDE_FROM_ABI forward_list() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) {
679 } // = default;
680 _LIBCPP_HIDE_FROM_ABI explicit forward_list(const allocator_type& __a);
681 _LIBCPP_HIDE_FROM_ABI explicit forward_list(size_type __n);
674 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI forward_list()
675 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) {} // = default;
676 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit forward_list(const allocator_type& __a);
677 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit forward_list(size_type __n);
682678# if _LIBCPP_STD_VER >= 14
683 _LIBCPP_HIDE_FROM_ABI explicit forward_list(size_type __n, const allocator_type& __a);
679 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit forward_list(size_type __n, const allocator_type& __a);
684680# endif
685 _LIBCPP_HIDE_FROM_ABI forward_list(size_type __n, const value_type& __v);
681 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI forward_list(size_type __n, const value_type& __v);
686682
687683 template <__enable_if_t<__is_allocator<_Alloc>::value, int> = 0>
688 _LIBCPP_HIDE_FROM_ABI forward_list(size_type __n, const value_type& __v, const allocator_type& __a) : __base(__a) {
684 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
685 forward_list(size_type __n, const value_type& __v, const allocator_type& __a)
686 : __base(__a) {
689687 insert_after(cbefore_begin(), __n, __v);
690688 }
691689
692690 template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
693 _LIBCPP_HIDE_FROM_ABI forward_list(_InputIterator __f, _InputIterator __l);
691 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI forward_list(_InputIterator __f, _InputIterator __l);
694692
695693 template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
696 _LIBCPP_HIDE_FROM_ABI forward_list(_InputIterator __f, _InputIterator __l, const allocator_type& __a);
694 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
695 forward_list(_InputIterator __f, _InputIterator __l, const allocator_type& __a);
697696
698697# if _LIBCPP_STD_VER >= 23
699698 template <_ContainerCompatibleRange<_Tp> _Range>
700 _LIBCPP_HIDE_FROM_ABI forward_list(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
699 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
700 forward_list(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
701701 : __base(__a) {
702702 prepend_range(std::forward<_Range>(__range));
703703 }
704704# endif
705705
706 _LIBCPP_HIDE_FROM_ABI forward_list(const forward_list& __x);
707 _LIBCPP_HIDE_FROM_ABI forward_list(const forward_list& __x, const __type_identity_t<allocator_type>& __a);
706 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI forward_list(const forward_list& __x);
707 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
708 forward_list(const forward_list& __x, const __type_identity_t<allocator_type>& __a);
708709
709 _LIBCPP_HIDE_FROM_ABI forward_list& operator=(const forward_list& __x);
710 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI forward_list& operator=(const forward_list& __x);
710711
711712# ifndef _LIBCPP_CXX03_LANG
712 _LIBCPP_HIDE_FROM_ABI forward_list(forward_list&& __x) noexcept(is_nothrow_move_constructible<__base>::value)
713 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
714 forward_list(forward_list&& __x) noexcept(is_nothrow_move_constructible<__base>::value)
713715 : __base(std::move(__x)) {}
714 _LIBCPP_HIDE_FROM_ABI forward_list(forward_list&& __x, const __type_identity_t<allocator_type>& __a);
716 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
717 forward_list(forward_list&& __x, const __type_identity_t<allocator_type>& __a);
715718
716 _LIBCPP_HIDE_FROM_ABI forward_list(initializer_list<value_type> __il);
717 _LIBCPP_HIDE_FROM_ABI forward_list(initializer_list<value_type> __il, const allocator_type& __a);
719 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI forward_list(initializer_list<value_type> __il);
720 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
721 forward_list(initializer_list<value_type> __il, const allocator_type& __a);
718722
719 _LIBCPP_HIDE_FROM_ABI forward_list& operator=(forward_list&& __x) noexcept(
720 __node_traits::propagate_on_container_move_assignment::value &&
721 is_nothrow_move_assignable<allocator_type>::value);
723 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI forward_list& operator=(forward_list&& __x) noexcept(
724 (__node_traits::propagate_on_container_move_assignment::value &&
725 is_nothrow_move_assignable<allocator_type>::value) ||
726 allocator_traits<allocator_type>::is_always_equal::value);
722727
723 _LIBCPP_HIDE_FROM_ABI forward_list& operator=(initializer_list<value_type> __il);
728 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI forward_list& operator=(initializer_list<value_type> __il);
724729
725 _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<value_type> __il);
730 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<value_type> __il);
726731# endif // _LIBCPP_CXX03_LANG
727732
728733 // ~forward_list() = default;
729734
730735 template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
731 void _LIBCPP_HIDE_FROM_ABI assign(_InputIterator __f, _InputIterator __l);
736 _LIBCPP_CONSTEXPR_SINCE_CXX26 void _LIBCPP_HIDE_FROM_ABI assign(_InputIterator __f, _InputIterator __l);
732737
733738# if _LIBCPP_STD_VER >= 23
734739 template <_ContainerCompatibleRange<_Tp> _Range>
735 _LIBCPP_HIDE_FROM_ABI void assign_range(_Range&& __range) {
740 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void assign_range(_Range&& __range) {
736741 __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
737742 }
738743# endif
739744
740 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const value_type& __v);
745 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const value_type& __v);
741746
742 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT { return allocator_type(this->__alloc_); }
747 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT {
748 return allocator_type(this->__alloc_);
749 }
743750
744 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return iterator(__base::__before_begin()->__next_); }
745 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT {
751 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT {
752 return iterator(__base::__before_begin()->__next_);
753 }
754 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT {
746755 return const_iterator(__base::__before_begin()->__next_);
747756 }
748 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return iterator(nullptr); }
749 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return const_iterator(nullptr); }
757 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return iterator(nullptr); }
758 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT {
759 return const_iterator(nullptr);
760 }
750761
751 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT {
762 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT {
752763 return const_iterator(__base::__before_begin()->__next_);
753764 }
754 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return const_iterator(nullptr); }
765 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT {
766 return const_iterator(nullptr);
767 }
755768
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 {
769 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator before_begin() _NOEXCEPT {
770 return iterator(__base::__before_begin());
771 }
772 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_iterator before_begin() const _NOEXCEPT {
758773 return const_iterator(__base::__before_begin());
759774 }
760 _LIBCPP_HIDE_FROM_ABI const_iterator cbefore_begin() const _NOEXCEPT {
775 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_iterator cbefore_begin() const _NOEXCEPT {
761776 return const_iterator(__base::__before_begin());
762777 }
763778
764 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT {
779 [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT {
765780 return __base::__before_begin()->__next_ == nullptr;
766781 }
767 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
782 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
768783 return std::min<size_type>(__node_traits::max_size(this->__alloc_), numeric_limits<difference_type>::max());
769784 }
770785
771 _LIBCPP_HIDE_FROM_ABI reference front() {
786 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI reference front() {
772787 _LIBCPP_ASSERT_NON_NULL(!empty(), "forward_list::front called on an empty list");
773788 return __base::__before_begin()->__next_->__get_value();
774789 }
775 _LIBCPP_HIDE_FROM_ABI const_reference front() const {
790 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_reference front() const {
776791 _LIBCPP_ASSERT_NON_NULL(!empty(), "forward_list::front called on an empty list");
777792 return __base::__before_begin()->__next_->__get_value();
778793 }
......@@ -780,52 +795,59 @@ public:
780795# ifndef _LIBCPP_CXX03_LANG
781796# if _LIBCPP_STD_VER >= 17
782797 template <class... _Args>
783 _LIBCPP_HIDE_FROM_ABI reference emplace_front(_Args&&... __args);
798 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI reference emplace_front(_Args&&... __args);
784799# else
785800 template <class... _Args>
786 _LIBCPP_HIDE_FROM_ABI void emplace_front(_Args&&... __args);
801 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void emplace_front(_Args&&... __args);
787802# endif
788 _LIBCPP_HIDE_FROM_ABI void push_front(value_type&& __v);
803 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void push_front(value_type&& __v);
789804# endif // _LIBCPP_CXX03_LANG
790 _LIBCPP_HIDE_FROM_ABI void push_front(const value_type& __v);
805 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void push_front(const value_type& __v);
791806
792807# if _LIBCPP_STD_VER >= 23
793808 template <_ContainerCompatibleRange<_Tp> _Range>
794 _LIBCPP_HIDE_FROM_ABI void prepend_range(_Range&& __range) {
809 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void prepend_range(_Range&& __range) {
795810 insert_range_after(cbefore_begin(), std::forward<_Range>(__range));
796811 }
797812# endif
798813
799 _LIBCPP_HIDE_FROM_ABI void pop_front();
814 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void pop_front();
800815
801816# ifndef _LIBCPP_CXX03_LANG
802817 template <class... _Args>
803 _LIBCPP_HIDE_FROM_ABI iterator emplace_after(const_iterator __p, _Args&&... __args);
818 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator emplace_after(const_iterator __p, _Args&&... __args);
804819
805 _LIBCPP_HIDE_FROM_ABI iterator insert_after(const_iterator __p, value_type&& __v);
806 _LIBCPP_HIDE_FROM_ABI iterator insert_after(const_iterator __p, initializer_list<value_type> __il) {
820 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator insert_after(const_iterator __p, value_type&& __v);
821 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator
822 insert_after(const_iterator __p, initializer_list<value_type> __il) {
807823 return insert_after(__p, __il.begin(), __il.end());
808824 }
809825# endif // _LIBCPP_CXX03_LANG
810 _LIBCPP_HIDE_FROM_ABI iterator insert_after(const_iterator __p, const value_type& __v);
811 _LIBCPP_HIDE_FROM_ABI iterator insert_after(const_iterator __p, size_type __n, const value_type& __v);
826 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator insert_after(const_iterator __p, const value_type& __v);
827 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator
828 insert_after(const_iterator __p, size_type __n, const value_type& __v) {
829 return __insert_after(__p, __n, __v);
830 }
812831 template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
813 _LIBCPP_HIDE_FROM_ABI iterator insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l);
832 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator
833 insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l);
814834
815835# if _LIBCPP_STD_VER >= 23
816836 template <_ContainerCompatibleRange<_Tp> _Range>
817 _LIBCPP_HIDE_FROM_ABI iterator insert_range_after(const_iterator __position, _Range&& __range) {
837 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator
838 insert_range_after(const_iterator __position, _Range&& __range) {
818839 return __insert_after_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
819840 }
820841# endif
821842
822843 template <class _InputIterator, class _Sentinel>
823 _LIBCPP_HIDE_FROM_ABI iterator __insert_after_with_sentinel(const_iterator __p, _InputIterator __f, _Sentinel __l);
844 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator
845 __insert_after_with_sentinel(const_iterator __p, _InputIterator __f, _Sentinel __l);
824846
825 _LIBCPP_HIDE_FROM_ABI iterator erase_after(const_iterator __p);
826 _LIBCPP_HIDE_FROM_ABI iterator erase_after(const_iterator __f, const_iterator __l);
847 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator erase_after(const_iterator __p);
848 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator erase_after(const_iterator __f, const_iterator __l);
827849
828 _LIBCPP_HIDE_FROM_ABI void swap(forward_list& __x)
850 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void swap(forward_list& __x)
829851# if _LIBCPP_STD_VER >= 14
830852 _NOEXCEPT
831853# else
......@@ -835,55 +857,63 @@ public:
835857 __base::swap(__x);
836858 }
837859
838 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n);
839 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n, const value_type& __v);
840 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __base::clear(); }
860 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n);
861 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n, const value_type& __v);
862 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __base::clear(); }
841863
842 _LIBCPP_HIDE_FROM_ABI void splice_after(const_iterator __p, forward_list&& __x);
843 _LIBCPP_HIDE_FROM_ABI void splice_after(const_iterator __p, forward_list&& __x, const_iterator __i);
844 _LIBCPP_HIDE_FROM_ABI void
864 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void splice_after(const_iterator __p, forward_list&& __x);
865 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void
866 splice_after(const_iterator __p, forward_list&& __x, const_iterator __i);
867 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void
845868 splice_after(const_iterator __p, forward_list&& __x, const_iterator __f, const_iterator __l);
846 _LIBCPP_HIDE_FROM_ABI void splice_after(const_iterator __p, forward_list& __x);
847 _LIBCPP_HIDE_FROM_ABI void splice_after(const_iterator __p, forward_list& __x, const_iterator __i);
848 _LIBCPP_HIDE_FROM_ABI void
869 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void splice_after(const_iterator __p, forward_list& __x);
870 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void
871 splice_after(const_iterator __p, forward_list& __x, const_iterator __i);
872 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void
849873 splice_after(const_iterator __p, forward_list& __x, const_iterator __f, const_iterator __l);
850 _LIBCPP_HIDE_FROM_ABI __remove_return_type remove(const value_type& __v);
874 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __remove_return_type remove(const value_type& __v);
851875 template <class _Predicate>
852 _LIBCPP_HIDE_FROM_ABI __remove_return_type remove_if(_Predicate __pred);
853 _LIBCPP_HIDE_FROM_ABI __remove_return_type unique() { return unique(__equal_to()); }
876 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __remove_return_type remove_if(_Predicate __pred);
877 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __remove_return_type unique() { return unique(__equal_to()); }
854878 template <class _BinaryPredicate>
855 _LIBCPP_HIDE_FROM_ABI __remove_return_type unique(_BinaryPredicate __binary_pred);
879 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __remove_return_type unique(_BinaryPredicate __binary_pred);
856880# ifndef _LIBCPP_CXX03_LANG
857 _LIBCPP_HIDE_FROM_ABI void merge(forward_list&& __x) { merge(__x, __less<>()); }
881 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void merge(forward_list&& __x) { merge(__x, __less<>()); }
858882 template <class _Compare>
859 _LIBCPP_HIDE_FROM_ABI void merge(forward_list&& __x, _Compare __comp) {
883 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void merge(forward_list&& __x, _Compare __comp) {
860884 merge(__x, std::move(__comp));
861885 }
862886# endif // _LIBCPP_CXX03_LANG
863 _LIBCPP_HIDE_FROM_ABI void merge(forward_list& __x) { merge(__x, __less<>()); }
887 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void merge(forward_list& __x) { merge(__x, __less<>()); }
864888 template <class _Compare>
865 _LIBCPP_HIDE_FROM_ABI void merge(forward_list& __x, _Compare __comp);
866 _LIBCPP_HIDE_FROM_ABI void sort() { sort(__less<>()); }
889 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void merge(forward_list& __x, _Compare __comp);
890 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void sort() { sort(__less<>()); }
867891 template <class _Compare>
868 _LIBCPP_HIDE_FROM_ABI void sort(_Compare __comp);
869 _LIBCPP_HIDE_FROM_ABI void reverse() _NOEXCEPT;
892 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void sort(_Compare __comp);
893 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void reverse() _NOEXCEPT;
870894
871895private:
872896# ifndef _LIBCPP_CXX03_LANG
873 _LIBCPP_HIDE_FROM_ABI void __move_assign(forward_list& __x, true_type)
897 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __move_assign(forward_list& __x, true_type)
874898 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
875 _LIBCPP_HIDE_FROM_ABI void __move_assign(forward_list& __x, false_type);
899 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __move_assign(forward_list& __x, false_type);
876900# endif // _LIBCPP_CXX03_LANG
877901
878902 template <class _Iter, class _Sent>
879 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iter __f, _Sent __l);
903 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iter __f, _Sent __l);
904
905 template <class... _Args>
906 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator
907 __insert_after(const_iterator __p, size_type __n, _Args&&... __args);
880908
881909 template <class _Compare>
882 static _LIBCPP_HIDE_FROM_ABI __node_pointer __merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp);
910 _LIBCPP_CONSTEXPR_SINCE_CXX26 static _LIBCPP_HIDE_FROM_ABI __node_pointer
911 __merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp);
883912
884913 // TODO: Make this _LIBCPP_HIDE_FROM_ABI
885914 template <class _Compare>
886 static _LIBCPP_HIDDEN __node_pointer __sort(__node_pointer __f, difference_type __sz, _Compare& __comp);
915 _LIBCPP_CONSTEXPR_SINCE_CXX26 static _LIBCPP_HIDDEN __node_pointer
916 __sort(__node_pointer __f, difference_type __sz, _Compare& __comp);
887917};
888918
889919# if _LIBCPP_STD_VER >= 17
......@@ -908,12 +938,13 @@ forward_list(from_range_t, _Range&&, _Alloc = _Alloc()) -> forward_list<ranges::
908938# endif
909939
910940template <class _Tp, class _Alloc>
911inline forward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a) : __base(__a) {}
941_LIBCPP_CONSTEXPR_SINCE_CXX26 inline forward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a) : __base(__a) {}
912942
913943template <class _Tp, class _Alloc>
914forward_list<_Tp, _Alloc>::forward_list(size_type __n) {
944_LIBCPP_CONSTEXPR_SINCE_CXX26 forward_list<_Tp, _Alloc>::forward_list(size_type __n) {
915945 if (__n > 0) {
916 for (__begin_node_pointer __p = __base::__before_begin(); __n > 0; --__n, __p = __p->__next_as_begin()) {
946 for (__begin_node_pointer __p = __base::__before_begin(); __n > 0;
947 --__n, __p = std::__static_fancy_pointer_cast<__begin_node_pointer>(__p->__next_)) {
917948 __p->__next_ = this->__create_node(/* next = */ nullptr);
918949 }
919950 }
......@@ -921,9 +952,11 @@ forward_list<_Tp, _Alloc>::forward_list(size_type __n) {
921952
922953# if _LIBCPP_STD_VER >= 14
923954template <class _Tp, class _Alloc>
924forward_list<_Tp, _Alloc>::forward_list(size_type __n, const allocator_type& __base_alloc) : __base(__base_alloc) {
955_LIBCPP_CONSTEXPR_SINCE_CXX26 forward_list<_Tp, _Alloc>::forward_list(size_type __n, const allocator_type& __base_alloc)
956 : __base(__base_alloc) {
925957 if (__n > 0) {
926 for (__begin_node_pointer __p = __base::__before_begin(); __n > 0; --__n, __p = __p->__next_as_begin()) {
958 for (__begin_node_pointer __p = __base::__before_begin(); __n > 0;
959 --__n, __p = std::__static_fancy_pointer_cast<__begin_node_pointer>(__p->__next_)) {
927960 __p->__next_ = this->__create_node(/* next = */ nullptr);
928961 }
929962 }
......@@ -931,37 +964,39 @@ forward_list<_Tp, _Alloc>::forward_list(size_type __n, const allocator_type& __b
931964# endif
932965
933966template <class _Tp, class _Alloc>
934forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v) {
967_LIBCPP_CONSTEXPR_SINCE_CXX26 forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v) {
935968 insert_after(cbefore_begin(), __n, __v);
936969}
937970
938971template <class _Tp, class _Alloc>
939972template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> >
940forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l) {
973_LIBCPP_CONSTEXPR_SINCE_CXX26 forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l) {
941974 insert_after(cbefore_begin(), __f, __l);
942975}
943976
944977template <class _Tp, class _Alloc>
945978template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> >
979_LIBCPP_CONSTEXPR_SINCE_CXX26
946980forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
947981 : __base(__a) {
948982 insert_after(cbefore_begin(), __f, __l);
949983}
950984
951985template <class _Tp, class _Alloc>
952forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x)
986_LIBCPP_CONSTEXPR_SINCE_CXX26 forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x)
953987 : __base(__node_traits::select_on_container_copy_construction(__x.__alloc_)) {
954988 insert_after(cbefore_begin(), __x.begin(), __x.end());
955989}
956990
957991template <class _Tp, class _Alloc>
992_LIBCPP_CONSTEXPR_SINCE_CXX26
958993forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x, const __type_identity_t<allocator_type>& __a)
959994 : __base(__a) {
960995 insert_after(cbefore_begin(), __x.begin(), __x.end());
961996}
962997
963998template <class _Tp, class _Alloc>
964forward_list<_Tp, _Alloc>& forward_list<_Tp, _Alloc>::operator=(const forward_list& __x) {
999_LIBCPP_CONSTEXPR_SINCE_CXX26 forward_list<_Tp, _Alloc>& forward_list<_Tp, _Alloc>::operator=(const forward_list& __x) {
9651000 if (this != std::addressof(__x)) {
9661001 __base::__copy_assign_alloc(__x);
9671002 assign(__x.begin(), __x.end());
......@@ -971,6 +1006,7 @@ forward_list<_Tp, _Alloc>& forward_list<_Tp, _Alloc>::operator=(const forward_li
9711006
9721007# ifndef _LIBCPP_CXX03_LANG
9731008template <class _Tp, class _Alloc>
1009_LIBCPP_CONSTEXPR_SINCE_CXX26
9741010forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x, const __type_identity_t<allocator_type>& __a)
9751011 : __base(std::move(__x), __a) {
9761012 if (this->__alloc_ != __x.__alloc_) {
......@@ -980,17 +1016,19 @@ forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x, const __type_identit
9801016}
9811017
9821018template <class _Tp, class _Alloc>
983forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il) {
1019_LIBCPP_CONSTEXPR_SINCE_CXX26 forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il) {
9841020 insert_after(cbefore_begin(), __il.begin(), __il.end());
9851021}
9861022
9871023template <class _Tp, class _Alloc>
988forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il, const allocator_type& __a) : __base(__a) {
1024_LIBCPP_CONSTEXPR_SINCE_CXX26
1025forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il, const allocator_type& __a)
1026 : __base(__a) {
9891027 insert_after(cbefore_begin(), __il.begin(), __il.end());
9901028}
9911029
9921030template <class _Tp, class _Alloc>
993void forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type)
1031_LIBCPP_CONSTEXPR_SINCE_CXX26 void forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type)
9941032 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
9951033 clear();
9961034 __base::__move_assign_alloc(__x);
......@@ -999,7 +1037,7 @@ void forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type)
9991037}
10001038
10011039template <class _Tp, class _Alloc>
1002void forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type) {
1040_LIBCPP_CONSTEXPR_SINCE_CXX26 void forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type) {
10031041 if (this->__alloc_ == __x.__alloc_)
10041042 __move_assign(__x, true_type());
10051043 else {
......@@ -1009,14 +1047,18 @@ void forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type) {
10091047}
10101048
10111049template <class _Tp, class _Alloc>
1012inline forward_list<_Tp, _Alloc>& forward_list<_Tp, _Alloc>::operator=(forward_list&& __x) _NOEXCEPT_(
1013 __node_traits::propagate_on_container_move_assignment::value&& is_nothrow_move_assignable<allocator_type>::value) {
1050_LIBCPP_CONSTEXPR_SINCE_CXX26 inline forward_list<_Tp, _Alloc>&
1051forward_list<_Tp, _Alloc>::operator=(forward_list&& __x) noexcept(
1052 (__node_traits::propagate_on_container_move_assignment::value &&
1053 is_nothrow_move_assignable<allocator_type>::value) ||
1054 allocator_traits<allocator_type>::is_always_equal::value) {
10141055 __move_assign(__x, integral_constant<bool, __node_traits::propagate_on_container_move_assignment::value>());
10151056 return *this;
10161057}
10171058
10181059template <class _Tp, class _Alloc>
1019inline forward_list<_Tp, _Alloc>& forward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il) {
1060_LIBCPP_CONSTEXPR_SINCE_CXX26 inline forward_list<_Tp, _Alloc>&
1061forward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il) {
10201062 assign(__il.begin(), __il.end());
10211063 return *this;
10221064}
......@@ -1025,13 +1067,14 @@ inline forward_list<_Tp, _Alloc>& forward_list<_Tp, _Alloc>::operator=(initializ
10251067
10261068template <class _Tp, class _Alloc>
10271069template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> >
1028void forward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l) {
1070_LIBCPP_CONSTEXPR_SINCE_CXX26 void forward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l) {
10291071 __assign_with_sentinel(__f, __l);
10301072}
10311073
10321074template <class _Tp, class _Alloc>
10331075template <class _Iter, class _Sent>
1034_LIBCPP_HIDE_FROM_ABI void forward_list<_Tp, _Alloc>::__assign_with_sentinel(_Iter __f, _Sent __l) {
1076_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void
1077forward_list<_Tp, _Alloc>::__assign_with_sentinel(_Iter __f, _Sent __l) {
10351078 iterator __i = before_begin();
10361079 iterator __j = std::next(__i);
10371080 iterator __e = end();
......@@ -1044,7 +1087,7 @@ _LIBCPP_HIDE_FROM_ABI void forward_list<_Tp, _Alloc>::__assign_with_sentinel(_It
10441087}
10451088
10461089template <class _Tp, class _Alloc>
1047void forward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v) {
1090_LIBCPP_CONSTEXPR_SINCE_CXX26 void forward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v) {
10481091 iterator __i = before_begin();
10491092 iterator __j = std::next(__i);
10501093 iterator __e = end();
......@@ -1059,18 +1102,19 @@ void forward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v) {
10591102# ifndef _LIBCPP_CXX03_LANG
10601103
10611104template <class _Tp, class _Alloc>
1062inline void forward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il) {
1105_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void forward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il) {
10631106 assign(__il.begin(), __il.end());
10641107}
10651108
10661109template <class _Tp, class _Alloc>
10671110template <class... _Args>
1111_LIBCPP_CONSTEXPR_SINCE_CXX26
10681112# if _LIBCPP_STD_VER >= 17
1069typename forward_list<_Tp, _Alloc>::reference
1113 typename forward_list<_Tp, _Alloc>::reference
10701114# else
1071void
1115 void
10721116# endif
1073forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args) {
1117 forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args) {
10741118 __base::__before_begin()->__next_ =
10751119 this->__create_node(/* next = */ __base::__before_begin()->__next_, std::forward<_Args>(__args)...);
10761120# if _LIBCPP_STD_VER >= 17
......@@ -1079,7 +1123,7 @@ forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args) {
10791123}
10801124
10811125template <class _Tp, class _Alloc>
1082void forward_list<_Tp, _Alloc>::push_front(value_type&& __v) {
1126_LIBCPP_CONSTEXPR_SINCE_CXX26 void forward_list<_Tp, _Alloc>::push_front(value_type&& __v) {
10831127 __base::__before_begin()->__next_ =
10841128 this->__create_node(/* next = */ __base::__before_begin()->__next_, std::move(__v));
10851129}
......@@ -1087,12 +1131,12 @@ void forward_list<_Tp, _Alloc>::push_front(value_type&& __v) {
10871131# endif // _LIBCPP_CXX03_LANG
10881132
10891133template <class _Tp, class _Alloc>
1090void forward_list<_Tp, _Alloc>::push_front(const value_type& __v) {
1134_LIBCPP_CONSTEXPR_SINCE_CXX26 void forward_list<_Tp, _Alloc>::push_front(const value_type& __v) {
10911135 __base::__before_begin()->__next_ = this->__create_node(/* next = */ __base::__before_begin()->__next_, __v);
10921136}
10931137
10941138template <class _Tp, class _Alloc>
1095void forward_list<_Tp, _Alloc>::pop_front() {
1139_LIBCPP_CONSTEXPR_SINCE_CXX26 void forward_list<_Tp, _Alloc>::pop_front() {
10961140 _LIBCPP_ASSERT_NON_NULL(!empty(), "forward_list::pop_front called on an empty list");
10971141 __node_pointer __p = __base::__before_begin()->__next_;
10981142 __base::__before_begin()->__next_ = __p->__next_;
......@@ -1103,17 +1147,17 @@ void forward_list<_Tp, _Alloc>::pop_front() {
11031147
11041148template <class _Tp, class _Alloc>
11051149template <class... _Args>
1106typename forward_list<_Tp, _Alloc>::iterator
1150_LIBCPP_CONSTEXPR_SINCE_CXX26 typename forward_list<_Tp, _Alloc>::iterator
11071151forward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args) {
1108 __begin_node_pointer const __r = __p.__get_begin();
1152 __begin_node_pointer const __r = __p.__ptr_;
11091153 __r->__next_ = this->__create_node(/* next = */ __r->__next_, std::forward<_Args>(__args)...);
11101154 return iterator(__r->__next_);
11111155}
11121156
11131157template <class _Tp, class _Alloc>
1114typename forward_list<_Tp, _Alloc>::iterator
1158_LIBCPP_CONSTEXPR_SINCE_CXX26 typename forward_list<_Tp, _Alloc>::iterator
11151159forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v) {
1116 __begin_node_pointer const __r = __p.__get_begin();
1160 __begin_node_pointer const __r = __p.__ptr_;
11171161 __r->__next_ = this->__create_node(/* next = */ __r->__next_, std::move(__v));
11181162 return iterator(__r->__next_);
11191163}
......@@ -1121,25 +1165,26 @@ forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v) {
11211165# endif // _LIBCPP_CXX03_LANG
11221166
11231167template <class _Tp, class _Alloc>
1124typename forward_list<_Tp, _Alloc>::iterator
1168_LIBCPP_CONSTEXPR_SINCE_CXX26 typename forward_list<_Tp, _Alloc>::iterator
11251169forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v) {
1126 __begin_node_pointer const __r = __p.__get_begin();
1170 __begin_node_pointer const __r = __p.__ptr_;
11271171 __r->__next_ = this->__create_node(/* next = */ __r->__next_, __v);
11281172 return iterator(__r->__next_);
11291173}
11301174
11311175template <class _Tp, class _Alloc>
1132typename forward_list<_Tp, _Alloc>::iterator
1133forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n, const value_type& __v) {
1134 __begin_node_pointer __r = __p.__get_begin();
1176template <class... _Args>
1177_LIBCPP_CONSTEXPR_SINCE_CXX26 typename forward_list<_Tp, _Alloc>::iterator
1178forward_list<_Tp, _Alloc>::__insert_after(const_iterator __p, size_type __n, _Args&&... __args) {
1179 __begin_node_pointer __r = __p.__ptr_;
11351180 if (__n > 0) {
1136 __node_pointer __first = this->__create_node(/* next = */ nullptr, __v);
1181 __node_pointer __first = this->__create_node(/* next = */ nullptr, std::forward<_Args>(__args)...);
11371182 __node_pointer __last = __first;
11381183# if _LIBCPP_HAS_EXCEPTIONS
11391184 try {
11401185# endif // _LIBCPP_HAS_EXCEPTIONS
11411186 for (--__n; __n != 0; --__n, __last = __last->__next_) {
1142 __last->__next_ = this->__create_node(/* next = */ nullptr, __v);
1187 __last->__next_ = this->__create_node(/* next = */ nullptr, std::forward<_Args>(__args)...);
11431188 }
11441189# if _LIBCPP_HAS_EXCEPTIONS
11451190 } catch (...) {
......@@ -1153,23 +1198,23 @@ forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n, const
11531198# endif // _LIBCPP_HAS_EXCEPTIONS
11541199 __last->__next_ = __r->__next_;
11551200 __r->__next_ = __first;
1156 __r = static_cast<__begin_node_pointer>(__last);
1201 __r = std::__static_fancy_pointer_cast<__begin_node_pointer>(__last);
11571202 }
11581203 return iterator(__r);
11591204}
11601205
11611206template <class _Tp, class _Alloc>
11621207template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> >
1163typename forward_list<_Tp, _Alloc>::iterator
1208_LIBCPP_CONSTEXPR_SINCE_CXX26 typename forward_list<_Tp, _Alloc>::iterator
11641209forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l) {
11651210 return __insert_after_with_sentinel(__p, std::move(__f), std::move(__l));
11661211}
11671212
11681213template <class _Tp, class _Alloc>
11691214template <class _InputIterator, class _Sentinel>
1170_LIBCPP_HIDE_FROM_ABI typename forward_list<_Tp, _Alloc>::iterator
1215_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI typename forward_list<_Tp, _Alloc>::iterator
11711216forward_list<_Tp, _Alloc>::__insert_after_with_sentinel(const_iterator __p, _InputIterator __f, _Sentinel __l) {
1172 __begin_node_pointer __r = __p.__get_begin();
1217 __begin_node_pointer __r = __p.__ptr_;
11731218
11741219 if (__f != __l) {
11751220 __node_pointer __first = this->__create_node(/* next = */ nullptr, *__f);
......@@ -1194,15 +1239,16 @@ forward_list<_Tp, _Alloc>::__insert_after_with_sentinel(const_iterator __p, _Inp
11941239
11951240 __last->__next_ = __r->__next_;
11961241 __r->__next_ = __first;
1197 __r = static_cast<__begin_node_pointer>(__last);
1242 __r = std::__static_fancy_pointer_cast<__begin_node_pointer>(__last);
11981243 }
11991244
12001245 return iterator(__r);
12011246}
12021247
12031248template <class _Tp, class _Alloc>
1204typename forward_list<_Tp, _Alloc>::iterator forward_list<_Tp, _Alloc>::erase_after(const_iterator __f) {
1205 __begin_node_pointer __p = __f.__get_begin();
1249_LIBCPP_CONSTEXPR_SINCE_CXX26 typename forward_list<_Tp, _Alloc>::iterator
1250forward_list<_Tp, _Alloc>::erase_after(const_iterator __f) {
1251 __begin_node_pointer __p = __f.__ptr_;
12061252 __node_pointer __n = __p->__next_;
12071253 __p->__next_ = __n->__next_;
12081254 this->__delete_node(__n);
......@@ -1210,11 +1256,11 @@ typename forward_list<_Tp, _Alloc>::iterator forward_list<_Tp, _Alloc>::erase_af
12101256}
12111257
12121258template <class _Tp, class _Alloc>
1213typename forward_list<_Tp, _Alloc>::iterator
1259_LIBCPP_CONSTEXPR_SINCE_CXX26 typename forward_list<_Tp, _Alloc>::iterator
12141260forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l) {
1215 __node_pointer __e = __l.__get_unsafe_node_pointer();
1261 __node_pointer __e = std::__static_fancy_pointer_cast<__node_pointer>(__l.__ptr_);
12161262 if (__f != __l) {
1217 __begin_node_pointer __bp = __f.__get_begin();
1263 __begin_node_pointer __bp = __f.__ptr_;
12181264
12191265 __node_pointer __n = __bp->__next_;
12201266 if (__n != __e) {
......@@ -1230,7 +1276,7 @@ forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l) {
12301276}
12311277
12321278template <class _Tp, class _Alloc>
1233void forward_list<_Tp, _Alloc>::resize(size_type __n) {
1279_LIBCPP_CONSTEXPR_SINCE_CXX26 void forward_list<_Tp, _Alloc>::resize(size_type __n) {
12341280 size_type __sz = 0;
12351281 iterator __p = before_begin();
12361282 iterator __i = begin();
......@@ -1239,18 +1285,12 @@ void forward_list<_Tp, _Alloc>::resize(size_type __n) {
12391285 ;
12401286 if (__i != __e)
12411287 erase_after(__p, __e);
1242 else {
1243 __n -= __sz;
1244 if (__n > 0) {
1245 for (__begin_node_pointer __ptr = __p.__get_begin(); __n > 0; --__n, __ptr = __ptr->__next_as_begin()) {
1246 __ptr->__next_ = this->__create_node(/* next = */ nullptr);
1247 }
1248 }
1249 }
1288 else
1289 __insert_after(__p, __n - __sz);
12501290}
12511291
12521292template <class _Tp, class _Alloc>
1253void forward_list<_Tp, _Alloc>::resize(size_type __n, const value_type& __v) {
1293_LIBCPP_CONSTEXPR_SINCE_CXX26 void forward_list<_Tp, _Alloc>::resize(size_type __n, const value_type& __v) {
12541294 size_type __sz = 0;
12551295 iterator __p = before_begin();
12561296 iterator __i = begin();
......@@ -1259,79 +1299,76 @@ void forward_list<_Tp, _Alloc>::resize(size_type __n, const value_type& __v) {
12591299 ;
12601300 if (__i != __e)
12611301 erase_after(__p, __e);
1262 else {
1263 __n -= __sz;
1264 if (__n > 0) {
1265 for (__begin_node_pointer __ptr = __p.__get_begin(); __n > 0; --__n, __ptr = __ptr->__next_as_begin()) {
1266 __ptr->__next_ = this->__create_node(/* next = */ nullptr, __v);
1267 }
1268 }
1269 }
1302 else
1303 __insert_after(__p, __n - __sz, __v);
12701304}
12711305
12721306template <class _Tp, class _Alloc>
1273void forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, forward_list& __x) {
1307_LIBCPP_CONSTEXPR_SINCE_CXX26 void forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, forward_list& __x) {
12741308 if (!__x.empty()) {
1275 if (__p.__get_begin()->__next_ != nullptr) {
1309 if (__p.__ptr_->__next_ != nullptr) {
12761310 const_iterator __lm1 = __x.before_begin();
1277 while (__lm1.__get_begin()->__next_ != nullptr)
1311 while (__lm1.__ptr_->__next_ != nullptr)
12781312 ++__lm1;
1279 __lm1.__get_begin()->__next_ = __p.__get_begin()->__next_;
1313 __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
12801314 }
1281 __p.__get_begin()->__next_ = __x.__before_begin()->__next_;
1315 __p.__ptr_->__next_ = __x.__before_begin()->__next_;
12821316 __x.__before_begin()->__next_ = nullptr;
12831317 }
12841318}
12851319
12861320template <class _Tp, class _Alloc>
1287void forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, forward_list& /*__other*/, const_iterator __i) {
1321_LIBCPP_CONSTEXPR_SINCE_CXX26 void
1322forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, forward_list& /*__other*/, const_iterator __i) {
12881323 const_iterator __lm1 = std::next(__i);
12891324 if (__p != __i && __p != __lm1) {
1290 __i.__get_begin()->__next_ = __lm1.__get_begin()->__next_;
1291 __lm1.__get_begin()->__next_ = __p.__get_begin()->__next_;
1292 __p.__get_begin()->__next_ = __lm1.__get_unsafe_node_pointer();
1325 __i.__ptr_->__next_ = __lm1.__ptr_->__next_;
1326 __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
1327 __p.__ptr_->__next_ = std::__static_fancy_pointer_cast<__node_pointer>(__lm1.__ptr_);
12931328 }
12941329}
12951330
12961331template <class _Tp, class _Alloc>
1297void forward_list<_Tp, _Alloc>::splice_after(
1332_LIBCPP_CONSTEXPR_SINCE_CXX26 void forward_list<_Tp, _Alloc>::splice_after(
12981333 const_iterator __p, forward_list& /*__other*/, const_iterator __f, const_iterator __l) {
12991334 if (__f != __l && __p != __f) {
13001335 const_iterator __lm1 = __f;
1301 while (__lm1.__get_begin()->__next_ != __l.__get_begin())
1336 while (__lm1.__ptr_->__next_ != __l.__ptr_)
13021337 ++__lm1;
13031338 if (__f != __lm1) {
1304 __lm1.__get_begin()->__next_ = __p.__get_begin()->__next_;
1305 __p.__get_begin()->__next_ = __f.__get_begin()->__next_;
1306 __f.__get_begin()->__next_ = __l.__get_unsafe_node_pointer();
1339 __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
1340 __p.__ptr_->__next_ = __f.__ptr_->__next_;
1341 __f.__ptr_->__next_ = std::__static_fancy_pointer_cast<__node_pointer>(__l.__ptr_);
13071342 }
13081343 }
13091344}
13101345
13111346template <class _Tp, class _Alloc>
1312inline _LIBCPP_HIDE_FROM_ABI void forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, forward_list&& __x) {
1347_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI void
1348forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, forward_list&& __x) {
13131349 splice_after(__p, __x);
13141350}
13151351
13161352template <class _Tp, class _Alloc>
1317inline _LIBCPP_HIDE_FROM_ABI void
1353_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI void
13181354forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, forward_list&& __x, const_iterator __i) {
13191355 splice_after(__p, __x, __i);
13201356}
13211357
13221358template <class _Tp, class _Alloc>
1323inline _LIBCPP_HIDE_FROM_ABI void forward_list<_Tp, _Alloc>::splice_after(
1359_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI void forward_list<_Tp, _Alloc>::splice_after(
13241360 const_iterator __p, forward_list&& __x, const_iterator __f, const_iterator __l) {
13251361 splice_after(__p, __x, __f, __l);
13261362}
13271363
13281364template <class _Tp, class _Alloc>
1329typename forward_list<_Tp, _Alloc>::__remove_return_type forward_list<_Tp, _Alloc>::remove(const value_type& __v) {
1365_LIBCPP_CONSTEXPR_SINCE_CXX26 typename forward_list<_Tp, _Alloc>::__remove_return_type
1366forward_list<_Tp, _Alloc>::remove(const value_type& __v) {
13301367 forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
13311368 typename forward_list<_Tp, _Alloc>::size_type __count_removed = 0;
13321369 const iterator __e = end();
1333 for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;) {
1334 if (__i.__get_begin()->__next_->__get_value() == __v) {
1370 for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;) {
1371 if (__i.__ptr_->__next_->__get_value() == __v) {
13351372 ++__count_removed;
13361373 iterator __j = std::next(__i, 2);
13371374 for (; __j != __e && *__j == __v; ++__j)
......@@ -1349,12 +1386,13 @@ typename forward_list<_Tp, _Alloc>::__remove_return_type forward_list<_Tp, _Allo
13491386
13501387template <class _Tp, class _Alloc>
13511388template <class _Predicate>
1352typename forward_list<_Tp, _Alloc>::__remove_return_type forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred) {
1389_LIBCPP_CONSTEXPR_SINCE_CXX26 typename forward_list<_Tp, _Alloc>::__remove_return_type
1390forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred) {
13531391 forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
13541392 typename forward_list<_Tp, _Alloc>::size_type __count_removed = 0;
13551393 const iterator __e = end();
1356 for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;) {
1357 if (__pred(__i.__get_begin()->__next_->__get_value())) {
1394 for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;) {
1395 if (__pred(__i.__ptr_->__next_->__get_value())) {
13581396 ++__count_removed;
13591397 iterator __j = std::next(__i, 2);
13601398 for (; __j != __e && __pred(*__j); ++__j)
......@@ -1372,7 +1410,7 @@ typename forward_list<_Tp, _Alloc>::__remove_return_type forward_list<_Tp, _Allo
13721410
13731411template <class _Tp, class _Alloc>
13741412template <class _BinaryPredicate>
1375typename forward_list<_Tp, _Alloc>::__remove_return_type
1413_LIBCPP_CONSTEXPR_SINCE_CXX26 typename forward_list<_Tp, _Alloc>::__remove_return_type
13761414forward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred) {
13771415 forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
13781416 typename forward_list<_Tp, _Alloc>::size_type __count_removed = 0;
......@@ -1380,7 +1418,7 @@ forward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred) {
13801418 iterator __j = std::next(__i);
13811419 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
13821420 ++__count_removed;
1383 if (__i.__get_begin()->__next_ != __j.__get_unsafe_node_pointer())
1421 if (__i.__ptr_->__next_ != std::__static_fancy_pointer_cast<__node_pointer>(__j.__ptr_))
13841422 __deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j);
13851423 __i = __j;
13861424 }
......@@ -1390,7 +1428,7 @@ forward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred) {
13901428
13911429template <class _Tp, class _Alloc>
13921430template <class _Compare>
1393void forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp) {
1431_LIBCPP_CONSTEXPR_SINCE_CXX26 void forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp) {
13941432 if (this != std::addressof(__x)) {
13951433 __base::__before_begin()->__next_ =
13961434 __merge(__base::__before_begin()->__next_, __x.__before_begin()->__next_, __comp);
......@@ -1400,7 +1438,7 @@ void forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp) {
14001438
14011439template <class _Tp, class _Alloc>
14021440template <class _Compare>
1403typename forward_list<_Tp, _Alloc>::__node_pointer
1441_LIBCPP_CONSTEXPR_SINCE_CXX26 typename forward_list<_Tp, _Alloc>::__node_pointer
14041442forward_list<_Tp, _Alloc>::__merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp) {
14051443 if (__f1 == nullptr)
14061444 return __f2;
......@@ -1437,13 +1475,13 @@ forward_list<_Tp, _Alloc>::__merge(__node_pointer __f1, __node_pointer __f2, _Co
14371475
14381476template <class _Tp, class _Alloc>
14391477template <class _Compare>
1440inline void forward_list<_Tp, _Alloc>::sort(_Compare __comp) {
1478_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void forward_list<_Tp, _Alloc>::sort(_Compare __comp) {
14411479 __base::__before_begin()->__next_ = __sort(__base::__before_begin()->__next_, std::distance(begin(), end()), __comp);
14421480}
14431481
14441482template <class _Tp, class _Alloc>
14451483template <class _Compare>
1446typename forward_list<_Tp, _Alloc>::__node_pointer
1484_LIBCPP_CONSTEXPR_SINCE_CXX26 typename forward_list<_Tp, _Alloc>::__node_pointer
14471485forward_list<_Tp, _Alloc>::__sort(__node_pointer __f1, difference_type __sz, _Compare& __comp) {
14481486 switch (__sz) {
14491487 case 0:
......@@ -1460,14 +1498,14 @@ forward_list<_Tp, _Alloc>::__sort(__node_pointer __f1, difference_type __sz, _Co
14601498 }
14611499 difference_type __sz1 = __sz / 2;
14621500 difference_type __sz2 = __sz - __sz1;
1463 __node_pointer __t = std::next(iterator(__f1), __sz1 - 1).__get_unsafe_node_pointer();
1501 __node_pointer __t = std::__static_fancy_pointer_cast<__node_pointer>(std::next(iterator(__f1), __sz1 - 1).__ptr_);
14641502 __node_pointer __f2 = __t->__next_;
14651503 __t->__next_ = nullptr;
14661504 return __merge(__sort(__f1, __sz1, __comp), __sort(__f2, __sz2, __comp), __comp);
14671505}
14681506
14691507template <class _Tp, class _Alloc>
1470void forward_list<_Tp, _Alloc>::reverse() _NOEXCEPT {
1508_LIBCPP_CONSTEXPR_SINCE_CXX26 void forward_list<_Tp, _Alloc>::reverse() _NOEXCEPT {
14711509 __node_pointer __p = __base::__before_begin()->__next_;
14721510 if (__p != nullptr) {
14731511 __node_pointer __f = __p->__next_;
......@@ -1483,7 +1521,8 @@ void forward_list<_Tp, _Alloc>::reverse() _NOEXCEPT {
14831521}
14841522
14851523template <class _Tp, class _Alloc>
1486_LIBCPP_HIDE_FROM_ABI bool operator==(const forward_list<_Tp, _Alloc>& __x, const forward_list<_Tp, _Alloc>& __y) {
1524_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI bool
1525operator==(const forward_list<_Tp, _Alloc>& __x, const forward_list<_Tp, _Alloc>& __y) {
14871526 typedef forward_list<_Tp, _Alloc> _Cp;
14881527 typedef typename _Cp::const_iterator _Ip;
14891528 _Ip __ix = __x.begin();
......@@ -1499,31 +1538,31 @@ _LIBCPP_HIDE_FROM_ABI bool operator==(const forward_list<_Tp, _Alloc>& __x, cons
14991538# if _LIBCPP_STD_VER <= 17
15001539
15011540template <class _Tp, class _Alloc>
1502inline _LIBCPP_HIDE_FROM_ABI bool
1541_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI bool
15031542operator!=(const forward_list<_Tp, _Alloc>& __x, const forward_list<_Tp, _Alloc>& __y) {
15041543 return !(__x == __y);
15051544}
15061545
15071546template <class _Tp, class _Alloc>
1508inline _LIBCPP_HIDE_FROM_ABI bool
1547_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI bool
15091548operator<(const forward_list<_Tp, _Alloc>& __x, const forward_list<_Tp, _Alloc>& __y) {
15101549 return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
15111550}
15121551
15131552template <class _Tp, class _Alloc>
1514inline _LIBCPP_HIDE_FROM_ABI bool
1553_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI bool
15151554operator>(const forward_list<_Tp, _Alloc>& __x, const forward_list<_Tp, _Alloc>& __y) {
15161555 return __y < __x;
15171556}
15181557
15191558template <class _Tp, class _Alloc>
1520inline _LIBCPP_HIDE_FROM_ABI bool
1559_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI bool
15211560operator>=(const forward_list<_Tp, _Alloc>& __x, const forward_list<_Tp, _Alloc>& __y) {
15221561 return !(__x < __y);
15231562}
15241563
15251564template <class _Tp, class _Alloc>
1526inline _LIBCPP_HIDE_FROM_ABI bool
1565_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI bool
15271566operator<=(const forward_list<_Tp, _Alloc>& __x, const forward_list<_Tp, _Alloc>& __y) {
15281567 return !(__y < __x);
15291568}
......@@ -1531,7 +1570,7 @@ operator<=(const forward_list<_Tp, _Alloc>& __x, const forward_list<_Tp, _Alloc>
15311570# else // #if _LIBCPP_STD_VER <= 17
15321571
15331572template <class _Tp, class _Allocator>
1534_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Tp>
1573_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Tp>
15351574operator<=>(const forward_list<_Tp, _Allocator>& __x, const forward_list<_Tp, _Allocator>& __y) {
15361575 return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
15371576}
......@@ -1539,22 +1578,22 @@ operator<=>(const forward_list<_Tp, _Allocator>& __x, const forward_list<_Tp, _A
15391578# endif // #if _LIBCPP_STD_VER <= 17
15401579
15411580template <class _Tp, class _Alloc>
1542inline _LIBCPP_HIDE_FROM_ABI void swap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y)
1543 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
1581_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI void
1582swap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
15441583 __x.swap(__y);
15451584}
15461585
15471586# if _LIBCPP_STD_VER >= 20
15481587template <class _Tp, class _Allocator, class _Predicate>
1549inline _LIBCPP_HIDE_FROM_ABI typename forward_list<_Tp, _Allocator>::size_type
1588_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI typename forward_list<_Tp, _Allocator>::size_type
15501589erase_if(forward_list<_Tp, _Allocator>& __c, _Predicate __pred) {
15511590 return __c.remove_if(__pred);
15521591}
15531592
15541593template <class _Tp, class _Allocator, class _Up>
1555inline _LIBCPP_HIDE_FROM_ABI typename forward_list<_Tp, _Allocator>::size_type
1594_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI typename forward_list<_Tp, _Allocator>::size_type
15561595erase(forward_list<_Tp, _Allocator>& __c, const _Up& __v) {
1557 return std::erase_if(__c, [&](auto& __elem) { return __elem == __v; });
1596 return std::erase_if(__c, [&](const auto& __elem) -> bool { return __elem == __v; });
15581597}
15591598# endif
15601599
......@@ -1567,6 +1606,8 @@ struct __container_traits<forward_list<_Tp, _Allocator> > {
15671606 // - If an exception is thrown by an insert() or emplace() function while inserting a single element, that
15681607 // function has no effects.
15691608 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
1609
1610 static _LIBCPP_CONSTEXPR const bool __reservable = false;
15701611};
15711612
15721613_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/fstream+93-73
......@@ -189,35 +189,36 @@ typedef basic_fstream<wchar_t> wfstream;
189189#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
190190# include <__cxx03/fstream>
191191#else
192# include <__algorithm/max.h>
193# include <__assert>
194192# 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
215
216_LIBCPP_PUSH_MACROS
217# include <__undef_macros>
218193
219194# if _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
220195
196# include <__algorithm/max.h>
197# include <__assert>
198# include <__filesystem/path.h>
199# include <__fwd/fstream.h>
200# include <__locale>
201# include <__memory/addressof.h>
202# include <__memory/unique_ptr.h>
203# include <__ostream/basic_ostream.h>
204# include <__type_traits/enable_if.h>
205# include <__type_traits/is_same.h>
206# include <__utility/move.h>
207# include <__utility/swap.h>
208# include <__utility/unreachable.h>
209# include <cstdio>
210# include <istream>
211# include <streambuf>
212# include <typeinfo>
213# include <version>
214
215# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
216# pragma GCC system_header
217# endif
218
219_LIBCPP_PUSH_MACROS
220# include <__undef_macros>
221
221222_LIBCPP_BEGIN_NAMESPACE_STD
222223
223224# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_WIN32API)
......@@ -225,7 +226,7 @@ _LIBCPP_EXPORTED_FROM_ABI void* __filebuf_windows_native_handle(FILE* __file) no
225226# endif
226227
227228template <class _CharT, class _Traits>
228class _LIBCPP_TEMPLATE_VIS basic_filebuf : public basic_streambuf<_CharT, _Traits> {
229class basic_filebuf : public basic_streambuf<_CharT, _Traits> {
229230public:
230231 typedef _CharT char_type;
231232 typedef _Traits traits_type;
......@@ -420,7 +421,7 @@ basic_filebuf<_CharT, _Traits>::basic_filebuf()
420421 __owns_ib_(false),
421422 __always_noconv_(false) {
422423 if (std::has_facet<codecvt<char_type, char, state_type> >(this->getloc())) {
423 __cv_ = &std::use_facet<codecvt<char_type, char, state_type> >(this->getloc());
424 __cv_ = std::addressof(std::use_facet<codecvt<char_type, char, state_type> >(this->getloc()));
424425 __always_noconv_ = __cv_->always_noconv();
425426 }
426427 setbuf(nullptr, 4096);
......@@ -695,7 +696,7 @@ basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::open(const char*
695696 if (!__mdstr)
696697 return nullptr;
697698
698 return __do_open(fopen(__s, __mdstr), __mode);
699 return __do_open(std::fopen(__s, __mdstr), __mode);
699700}
700701
701702template <class _CharT, class _Traits>
......@@ -753,14 +754,14 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
753754 bool __initial = __read_mode();
754755 char_type __1buf;
755756 if (this->gptr() == nullptr)
756 this->setg(&__1buf, &__1buf + 1, &__1buf + 1);
757 this->setg(std::addressof(__1buf), std::addressof(__1buf) + 1, std::addressof(__1buf) + 1);
757758 const size_t __unget_sz = __initial ? 0 : std::min<size_t>((this->egptr() - this->eback()) / 2, 4);
758759 int_type __c = traits_type::eof();
759760 if (this->gptr() == this->egptr()) {
760761 std::memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type));
761762 if (__always_noconv_) {
762763 size_t __nmemb = static_cast<size_t>(this->egptr() - this->eback() - __unget_sz);
763 __nmemb = ::fread(this->eback() + __unget_sz, 1, __nmemb, __file_);
764 __nmemb = std::fread(this->eback() + __unget_sz, 1, __nmemb, __file_);
764765 if (__nmemb != 0) {
765766 this->setg(this->eback(), this->eback() + __unget_sz, this->eback() + __unget_sz + __nmemb);
766767 __c = traits_type::to_int_type(*this->gptr());
......@@ -777,10 +778,10 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
777778 std::min(static_cast<size_t>(__ibs_ - __unget_sz), static_cast<size_t>(__extbufend_ - __extbufnext_));
778779 codecvt_base::result __r;
779780 __st_last_ = __st_;
780 size_t __nr = fread((void*)const_cast<char*>(__extbufnext_), 1, __nmemb, __file_);
781 size_t __nr = std::fread((void*)const_cast<char*>(__extbufnext_), 1, __nmemb, __file_);
781782 if (__nr != 0) {
782783 if (!__cv_)
783 __throw_bad_cast();
784 std::__throw_bad_cast();
784785
785786 __extbufend_ = __extbufnext_ + __nr;
786787 char_type* __inext;
......@@ -797,7 +798,7 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
797798 }
798799 } else
799800 __c = traits_type::to_int_type(*this->gptr());
800 if (this->eback() == &__1buf)
801 if (this->eback() == std::addressof(__1buf))
801802 this->setg(nullptr, nullptr, nullptr);
802803 return __c;
803804}
......@@ -828,44 +829,63 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
828829 char_type* __epb_save = this->epptr();
829830 if (!traits_type::eq_int_type(__c, traits_type::eof())) {
830831 if (this->pptr() == nullptr)
831 this->setp(&__1buf, &__1buf + 1);
832 this->setp(std::addressof(__1buf), std::addressof(__1buf) + 1);
832833 *this->pptr() = traits_type::to_char_type(__c);
833834 this->pbump(1);
834835 }
835 if (this->pptr() != this->pbase()) {
836 if (__always_noconv_) {
837 size_t __nmemb = static_cast<size_t>(this->pptr() - this->pbase());
838 if (std::fwrite(this->pbase(), sizeof(char_type), __nmemb, __file_) != __nmemb)
836
837 // There is nothing to write, early return
838 if (this->pptr() == this->pbase()) {
839 return traits_type::not_eof(__c);
840 }
841
842 if (__always_noconv_) {
843 size_t __n = static_cast<size_t>(this->pptr() - this->pbase());
844 if (std::fwrite(this->pbase(), sizeof(char_type), __n, __file_) != __n)
845 return traits_type::eof();
846 } else {
847 if (!__cv_)
848 std::__throw_bad_cast();
849
850 // See [filebuf.virtuals]
851 char_type* __b = this->pbase();
852 char_type* __p = this->pptr();
853 const char_type* __end;
854 char* __extbuf_end = __extbuf_;
855 do {
856 codecvt_base::result __r = __cv_->out(__st_, __b, __p, __end, __extbuf_, __extbuf_ + __ebs_, __extbuf_end);
857 if (__end == __b)
839858 return traits_type::eof();
840 } else {
841 char* __extbe = __extbuf_;
842 codecvt_base::result __r;
843 do {
844 if (!__cv_)
845 __throw_bad_cast();
846859
847 const char_type* __e;
848 __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, __extbuf_, __extbuf_ + __ebs_, __extbe);
849 if (__e == this->pbase())
860 // No conversion needed: output characters directly to the file, done.
861 if (__r == codecvt_base::noconv) {
862 size_t __n = static_cast<size_t>(__p - __b);
863 if (std::fwrite(__b, 1, __n, __file_) != __n)
850864 return traits_type::eof();
851 if (__r == codecvt_base::noconv) {
852 size_t __nmemb = static_cast<size_t>(this->pptr() - this->pbase());
853 if (std::fwrite(this->pbase(), 1, __nmemb, __file_) != __nmemb)
854 return traits_type::eof();
855 } else if (__r == codecvt_base::ok || __r == codecvt_base::partial) {
856 size_t __nmemb = static_cast<size_t>(__extbe - __extbuf_);
857 if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb)
858 return traits_type::eof();
859 if (__r == codecvt_base::partial) {
860 this->setp(const_cast<char_type*>(__e), this->pptr());
861 this->__pbump(this->epptr() - this->pbase());
862 }
863 } else
865 break;
866
867 // Conversion successful: output the converted characters to the file, done.
868 } else if (__r == codecvt_base::ok) {
869 size_t __n = static_cast<size_t>(__extbuf_end - __extbuf_);
870 if (std::fwrite(__extbuf_, 1, __n, __file_) != __n)
864871 return traits_type::eof();
865 } while (__r == codecvt_base::partial);
866 }
867 this->setp(__pb_save, __epb_save);
872 break;
873
874 // Conversion partially successful: output converted characters to the file and repeat with the
875 // remaining characters.
876 } else if (__r == codecvt_base::partial) {
877 size_t __n = static_cast<size_t>(__extbuf_end - __extbuf_);
878 if (std::fwrite(__extbuf_, 1, __n, __file_) != __n)
879 return traits_type::eof();
880 __b = const_cast<char_type*>(__end);
881 continue;
882
883 } else {
884 return traits_type::eof();
885 }
886 } while (true);
868887 }
888 this->setp(__pb_save, __epb_save);
869889 return traits_type::not_eof(__c);
870890}
871891
......@@ -913,7 +933,7 @@ template <class _CharT, class _Traits>
913933typename basic_filebuf<_CharT, _Traits>::pos_type
914934basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode) {
915935 if (!__cv_)
916 __throw_bad_cast();
936 std::__throw_bad_cast();
917937
918938 int __width = __cv_->encoding();
919939 if (__file_ == nullptr || (__width <= 0 && __off != 0) || sync())
......@@ -978,7 +998,7 @@ int basic_filebuf<_CharT, _Traits>::sync() {
978998 if (__file_ == nullptr)
979999 return 0;
9801000 if (!__cv_)
981 __throw_bad_cast();
1001 std::__throw_bad_cast();
9821002
9831003 if (__cm_ & ios_base::out) {
9841004 if (this->pptr() != this->pbase())
......@@ -989,12 +1009,12 @@ int basic_filebuf<_CharT, _Traits>::sync() {
9891009 char* __extbe;
9901010 __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe);
9911011 size_t __nmemb = static_cast<size_t>(__extbe - __extbuf_);
992 if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb)
1012 if (std::fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb)
9931013 return -1;
9941014 } while (__r == codecvt_base::partial);
9951015 if (__r == codecvt_base::error)
9961016 return -1;
997 if (fflush(__file_))
1017 if (std::fflush(__file_))
9981018 return -1;
9991019 } else if (__cm_ & ios_base::in) {
10001020 off_type __c;
......@@ -1029,7 +1049,7 @@ int basic_filebuf<_CharT, _Traits>::sync() {
10291049template <class _CharT, class _Traits>
10301050void basic_filebuf<_CharT, _Traits>::imbue(const locale& __loc) {
10311051 sync();
1032 __cv_ = &std::use_facet<codecvt<char_type, char, state_type> >(__loc);
1052 __cv_ = std::addressof(std::use_facet<codecvt<char_type, char, state_type> >(__loc));
10331053 bool __old_anc = __always_noconv_;
10341054 __always_noconv_ = __cv_->always_noconv();
10351055 if (__old_anc != __always_noconv_) {
......@@ -1095,7 +1115,7 @@ void basic_filebuf<_CharT, _Traits>::__write_mode() {
10951115// basic_ifstream
10961116
10971117template <class _CharT, class _Traits>
1098class _LIBCPP_TEMPLATE_VIS basic_ifstream : public basic_istream<_CharT, _Traits> {
1118class basic_ifstream : public basic_istream<_CharT, _Traits> {
10991119public:
11001120 typedef _CharT char_type;
11011121 typedef _Traits traits_type;
......@@ -1251,7 +1271,7 @@ inline void basic_ifstream<_CharT, _Traits>::close() {
12511271// basic_ofstream
12521272
12531273template <class _CharT, class _Traits>
1254class _LIBCPP_TEMPLATE_VIS basic_ofstream : public basic_ostream<_CharT, _Traits> {
1274class basic_ofstream : public basic_ostream<_CharT, _Traits> {
12551275public:
12561276 typedef _CharT char_type;
12571277 typedef _Traits traits_type;
......@@ -1410,7 +1430,7 @@ inline void basic_ofstream<_CharT, _Traits>::close() {
14101430// basic_fstream
14111431
14121432template <class _CharT, class _Traits>
1413class _LIBCPP_TEMPLATE_VIS basic_fstream : public basic_iostream<_CharT, _Traits> {
1433class basic_fstream : public basic_iostream<_CharT, _Traits> {
14141434public:
14151435 typedef _CharT char_type;
14161436 typedef _Traits traits_type;
......@@ -1570,10 +1590,10 @@ extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_filebuf<char>;
15701590
15711591_LIBCPP_END_NAMESPACE_STD
15721592
1573# endif // _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
1574
15751593_LIBCPP_POP_MACROS
15761594
1595# endif // _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
1596
15771597# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
15781598# include <atomic>
15791599# include <concepts>
lib/libcxx/include/functional+5
......@@ -565,6 +565,7 @@ POLICY: For non-variadic implementations, the number of arguments is limited
565565# include <__functional/bind_front.h>
566566# include <__functional/identity.h>
567567# include <__functional/ranges_operations.h>
568# include <__type_traits/common_reference.h>
568569# include <__type_traits/unwrap_ref.h>
569570# endif
570571
......@@ -599,6 +600,10 @@ POLICY: For non-variadic implementations, the number of arguments is limited
599600# include <utility>
600601# include <vector>
601602# endif
603
604# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER == 23
605# include <__vector/vector.h>
606# endif
602607#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
603608
604609#endif // _LIBCPP_FUNCTIONAL
lib/libcxx/include/future+80-85
......@@ -322,8 +322,6 @@ template <class R, class... ArgTypes>
322322class packaged_task<R(ArgTypes...)>
323323{
324324public:
325 typedef R result_type; // extension
326
327325 // construction and destruction
328326 packaged_task() noexcept;
329327 template <class F>
......@@ -393,7 +391,7 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
393391# include <__system_error/error_code.h>
394392# include <__system_error/error_condition.h>
395393# include <__thread/thread.h>
396# include <__type_traits/add_lvalue_reference.h>
394# include <__type_traits/add_reference.h>
397395# include <__type_traits/aligned_storage.h>
398396# include <__type_traits/conditional.h>
399397# include <__type_traits/decay.h>
......@@ -427,11 +425,11 @@ _LIBCPP_DECLARE_STRONG_ENUM(future_errc){
427425_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_errc)
428426
429427template <>
430struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<future_errc> : public true_type {};
428struct is_error_code_enum<future_errc> : public true_type {};
431429
432430# ifdef _LIBCPP_CXX03_LANG
433431template <>
434struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<future_errc::__lx> : public true_type {};
432struct is_error_code_enum<future_errc::__lx> : public true_type {};
435433# endif
436434
437435// enum class launch
......@@ -440,7 +438,7 @@ _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(launch)
440438
441439# ifndef _LIBCPP_CXX03_LANG
442440
443typedef underlying_type<launch>::type __launch_underlying_type;
441using __launch_underlying_type _LIBCPP_NODEBUG = __underlying_type_t<launch>;
444442
445443inline _LIBCPP_HIDE_FROM_ABI constexpr launch operator&(launch __x, launch __y) {
446444 return static_cast<launch>(static_cast<__launch_underlying_type>(__x) & static_cast<__launch_underlying_type>(__y));
......@@ -541,7 +539,7 @@ public:
541539 lock_guard<mutex> __lk(__mut_);
542540 bool __has_future_attached = (__state_ & __future_attached) != 0;
543541 if (__has_future_attached)
544 __throw_future_error(future_errc::future_already_retrieved);
542 std::__throw_future_error(future_errc::future_already_retrieved);
545543 this->__add_shared();
546544 __state_ |= __future_attached;
547545 }
......@@ -563,24 +561,20 @@ public:
563561 template <class _Rep, class _Period>
564562 future_status _LIBCPP_HIDE_FROM_ABI wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const;
565563 template <class _Clock, class _Duration>
566 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS future_status
567 wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const;
564 _LIBCPP_HIDE_FROM_ABI future_status wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const {
565 unique_lock<mutex> __lk(__mut_);
566 if (__state_ & deferred)
567 return future_status::deferred;
568 while (!(__state_ & ready) && _Clock::now() < __abs_time)
569 __cv_.wait_until(__lk, __abs_time);
570 if (__state_ & ready)
571 return future_status::ready;
572 return future_status::timeout;
573 }
568574
569575 virtual void __execute();
570576};
571577
572template <class _Clock, class _Duration>
573future_status __assoc_sub_state::wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const {
574 unique_lock<mutex> __lk(__mut_);
575 if (__state_ & deferred)
576 return future_status::deferred;
577 while (!(__state_ & ready) && _Clock::now() < __abs_time)
578 __cv_.wait_until(__lk, __abs_time);
579 if (__state_ & ready)
580 return future_status::ready;
581 return future_status::timeout;
582}
583
584578template <class _Rep, class _Period>
585579inline future_status __assoc_sub_state::wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const {
586580 return wait_until(chrono::steady_clock::now() + __rel_time);
......@@ -612,7 +606,7 @@ public:
612606template <class _Rp>
613607void __assoc_state<_Rp>::__on_zero_shared() _NOEXCEPT {
614608 if (this->__state_ & base::__constructed)
615 reinterpret_cast<_Rp*>(&__value_)->~_Rp();
609 reinterpret_cast<_Rp*>(std::addressof(__value_))->~_Rp();
616610 delete this;
617611}
618612
......@@ -621,8 +615,8 @@ template <class _Arg>
621615void __assoc_state<_Rp>::set_value(_Arg&& __arg) {
622616 unique_lock<mutex> __lk(this->__mut_);
623617 if (this->__has_value())
624 __throw_future_error(future_errc::promise_already_satisfied);
625 ::new ((void*)&__value_) _Rp(std::forward<_Arg>(__arg));
618 std::__throw_future_error(future_errc::promise_already_satisfied);
619 ::new ((void*)std::addressof(__value_)) _Rp(std::forward<_Arg>(__arg));
626620 this->__state_ |= base::__constructed | base::ready;
627621 __cv_.notify_all();
628622}
......@@ -632,8 +626,8 @@ template <class _Arg>
632626void __assoc_state<_Rp>::set_value_at_thread_exit(_Arg&& __arg) {
633627 unique_lock<mutex> __lk(this->__mut_);
634628 if (this->__has_value())
635 __throw_future_error(future_errc::promise_already_satisfied);
636 ::new ((void*)&__value_) _Rp(std::forward<_Arg>(__arg));
629 std::__throw_future_error(future_errc::promise_already_satisfied);
630 ::new ((void*)std::addressof(__value_)) _Rp(std::forward<_Arg>(__arg));
637631 this->__state_ |= base::__constructed;
638632 __thread_local_data()->__make_ready_at_thread_exit(this);
639633}
......@@ -644,7 +638,7 @@ _Rp __assoc_state<_Rp>::move() {
644638 this->__sub_wait(__lk);
645639 if (this->__exception_ != nullptr)
646640 std::rethrow_exception(this->__exception_);
647 return std::move(*reinterpret_cast<_Rp*>(&__value_));
641 return std::move(*reinterpret_cast<_Rp*>(std::addressof(__value_)));
648642}
649643
650644template <class _Rp>
......@@ -653,7 +647,7 @@ _Rp& __assoc_state<_Rp>::copy() {
653647 this->__sub_wait(__lk);
654648 if (this->__exception_ != nullptr)
655649 std::rethrow_exception(this->__exception_);
656 return *reinterpret_cast<_Rp*>(&__value_);
650 return *reinterpret_cast<_Rp*>(std::addressof(__value_));
657651}
658652
659653template <class _Rp>
......@@ -682,7 +676,7 @@ template <class _Rp>
682676void __assoc_state<_Rp&>::set_value(_Rp& __arg) {
683677 unique_lock<mutex> __lk(this->__mut_);
684678 if (this->__has_value())
685 __throw_future_error(future_errc::promise_already_satisfied);
679 std::__throw_future_error(future_errc::promise_already_satisfied);
686680 __value_ = std::addressof(__arg);
687681 this->__state_ |= base::__constructed | base::ready;
688682 __cv_.notify_all();
......@@ -692,7 +686,7 @@ template <class _Rp>
692686void __assoc_state<_Rp&>::set_value_at_thread_exit(_Rp& __arg) {
693687 unique_lock<mutex> __lk(this->__mut_);
694688 if (this->__has_value())
695 __throw_future_error(future_errc::promise_already_satisfied);
689 std::__throw_future_error(future_errc::promise_already_satisfied);
696690 __value_ = std::addressof(__arg);
697691 this->__state_ |= base::__constructed;
698692 __thread_local_data()->__make_ready_at_thread_exit(this);
......@@ -907,14 +901,14 @@ void __async_assoc_state<void, _Fp>::__on_zero_shared() _NOEXCEPT {
907901}
908902
909903template <class _Rp>
910class _LIBCPP_TEMPLATE_VIS promise;
904class promise;
911905template <class _Rp>
912class _LIBCPP_TEMPLATE_VIS shared_future;
906class shared_future;
913907
914908// future
915909
916910template <class _Rp>
917class _LIBCPP_TEMPLATE_VIS future;
911class future;
918912
919913template <class _Rp, class _Fp>
920914_LIBCPP_HIDE_FROM_ABI future<_Rp> __make_deferred_assoc_state(_Fp&& __f);
......@@ -923,7 +917,7 @@ template <class _Rp, class _Fp>
923917_LIBCPP_HIDE_FROM_ABI future<_Rp> __make_async_assoc_state(_Fp&& __f);
924918
925919template <class _Rp>
926class _LIBCPP_TEMPLATE_VIS future {
920class future {
927921 __assoc_state<_Rp>* __state_;
928922
929923 explicit _LIBCPP_HIDE_FROM_ABI future(__assoc_state<_Rp>* __state);
......@@ -994,7 +988,7 @@ _Rp future<_Rp>::get() {
994988}
995989
996990template <class _Rp>
997class _LIBCPP_TEMPLATE_VIS future<_Rp&> {
991class future<_Rp&> {
998992 __assoc_state<_Rp&>* __state_;
999993
1000994 explicit _LIBCPP_HIDE_FROM_ABI future(__assoc_state<_Rp&>* __state);
......@@ -1119,7 +1113,7 @@ template <class _Callable>
11191113class packaged_task;
11201114
11211115template <class _Rp>
1122class _LIBCPP_TEMPLATE_VIS promise {
1116class promise {
11231117 __assoc_state<_Rp>* __state_;
11241118
11251119 _LIBCPP_HIDE_FROM_ABI explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {}
......@@ -1185,21 +1179,21 @@ promise<_Rp>::~promise() {
11851179template <class _Rp>
11861180future<_Rp> promise<_Rp>::get_future() {
11871181 if (__state_ == nullptr)
1188 __throw_future_error(future_errc::no_state);
1182 std::__throw_future_error(future_errc::no_state);
11891183 return future<_Rp>(__state_);
11901184}
11911185
11921186template <class _Rp>
11931187void promise<_Rp>::set_value(const _Rp& __r) {
11941188 if (__state_ == nullptr)
1195 __throw_future_error(future_errc::no_state);
1189 std::__throw_future_error(future_errc::no_state);
11961190 __state_->set_value(__r);
11971191}
11981192
11991193template <class _Rp>
12001194void promise<_Rp>::set_value(_Rp&& __r) {
12011195 if (__state_ == nullptr)
1202 __throw_future_error(future_errc::no_state);
1196 std::__throw_future_error(future_errc::no_state);
12031197 __state_->set_value(std::move(__r));
12041198}
12051199
......@@ -1207,21 +1201,21 @@ template <class _Rp>
12071201void promise<_Rp>::set_exception(exception_ptr __p) {
12081202 _LIBCPP_ASSERT_NON_NULL(__p != nullptr, "promise::set_exception: received nullptr");
12091203 if (__state_ == nullptr)
1210 __throw_future_error(future_errc::no_state);
1204 std::__throw_future_error(future_errc::no_state);
12111205 __state_->set_exception(__p);
12121206}
12131207
12141208template <class _Rp>
12151209void promise<_Rp>::set_value_at_thread_exit(const _Rp& __r) {
12161210 if (__state_ == nullptr)
1217 __throw_future_error(future_errc::no_state);
1211 std::__throw_future_error(future_errc::no_state);
12181212 __state_->set_value_at_thread_exit(__r);
12191213}
12201214
12211215template <class _Rp>
12221216void promise<_Rp>::set_value_at_thread_exit(_Rp&& __r) {
12231217 if (__state_ == nullptr)
1224 __throw_future_error(future_errc::no_state);
1218 std::__throw_future_error(future_errc::no_state);
12251219 __state_->set_value_at_thread_exit(std::move(__r));
12261220}
12271221
......@@ -1229,14 +1223,14 @@ template <class _Rp>
12291223void promise<_Rp>::set_exception_at_thread_exit(exception_ptr __p) {
12301224 _LIBCPP_ASSERT_NON_NULL(__p != nullptr, "promise::set_exception_at_thread_exit: received nullptr");
12311225 if (__state_ == nullptr)
1232 __throw_future_error(future_errc::no_state);
1226 std::__throw_future_error(future_errc::no_state);
12331227 __state_->set_exception_at_thread_exit(__p);
12341228}
12351229
12361230// promise<R&>
12371231
12381232template <class _Rp>
1239class _LIBCPP_TEMPLATE_VIS promise<_Rp&> {
1233class promise<_Rp&> {
12401234 __assoc_state<_Rp&>* __state_;
12411235
12421236 _LIBCPP_HIDE_FROM_ABI explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {}
......@@ -1300,14 +1294,14 @@ promise<_Rp&>::~promise() {
13001294template <class _Rp>
13011295future<_Rp&> promise<_Rp&>::get_future() {
13021296 if (__state_ == nullptr)
1303 __throw_future_error(future_errc::no_state);
1297 std::__throw_future_error(future_errc::no_state);
13041298 return future<_Rp&>(__state_);
13051299}
13061300
13071301template <class _Rp>
13081302void promise<_Rp&>::set_value(_Rp& __r) {
13091303 if (__state_ == nullptr)
1310 __throw_future_error(future_errc::no_state);
1304 std::__throw_future_error(future_errc::no_state);
13111305 __state_->set_value(__r);
13121306}
13131307
......@@ -1315,14 +1309,14 @@ template <class _Rp>
13151309void promise<_Rp&>::set_exception(exception_ptr __p) {
13161310 _LIBCPP_ASSERT_NON_NULL(__p != nullptr, "promise::set_exception: received nullptr");
13171311 if (__state_ == nullptr)
1318 __throw_future_error(future_errc::no_state);
1312 std::__throw_future_error(future_errc::no_state);
13191313 __state_->set_exception(__p);
13201314}
13211315
13221316template <class _Rp>
13231317void promise<_Rp&>::set_value_at_thread_exit(_Rp& __r) {
13241318 if (__state_ == nullptr)
1325 __throw_future_error(future_errc::no_state);
1319 std::__throw_future_error(future_errc::no_state);
13261320 __state_->set_value_at_thread_exit(__r);
13271321}
13281322
......@@ -1330,7 +1324,7 @@ template <class _Rp>
13301324void promise<_Rp&>::set_exception_at_thread_exit(exception_ptr __p) {
13311325 _LIBCPP_ASSERT_NON_NULL(__p != nullptr, "promise::set_exception_at_thread_exit: received nullptr");
13321326 if (__state_ == nullptr)
1333 __throw_future_error(future_errc::no_state);
1327 std::__throw_future_error(future_errc::no_state);
13341328 __state_->set_exception_at_thread_exit(__p);
13351329}
13361330
......@@ -1347,8 +1341,17 @@ class _LIBCPP_EXPORTED_FROM_ABI promise<void> {
13471341
13481342public:
13491343 promise();
1350 template <class _Allocator>
1351 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS promise(allocator_arg_t, const _Allocator& __a);
1344 template <class _Alloc>
1345 _LIBCPP_HIDE_FROM_ABI promise(allocator_arg_t, const _Alloc& __a0) {
1346 typedef __assoc_sub_state_alloc<_Alloc> _State;
1347 typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2;
1348 typedef __allocator_destructor<_A2> _D2;
1349 _A2 __a(__a0);
1350 unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1));
1351 ::new ((void*)std::addressof(*__hold.get())) _State(__a0);
1352 __state_ = std::addressof(*__hold.release());
1353 }
1354
13521355 _LIBCPP_HIDE_FROM_ABI promise(promise&& __rhs) _NOEXCEPT : __state_(__rhs.__state_) { __rhs.__state_ = nullptr; }
13531356 promise(const promise& __rhs) = delete;
13541357 ~promise();
......@@ -1374,24 +1377,13 @@ public:
13741377 void set_exception_at_thread_exit(exception_ptr __p);
13751378};
13761379
1377template <class _Alloc>
1378promise<void>::promise(allocator_arg_t, const _Alloc& __a0) {
1379 typedef __assoc_sub_state_alloc<_Alloc> _State;
1380 typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2;
1381 typedef __allocator_destructor<_A2> _D2;
1382 _A2 __a(__a0);
1383 unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1));
1384 ::new ((void*)std::addressof(*__hold.get())) _State(__a0);
1385 __state_ = std::addressof(*__hold.release());
1386}
1387
13881380template <class _Rp>
13891381inline _LIBCPP_HIDE_FROM_ABI void swap(promise<_Rp>& __x, promise<_Rp>& __y) _NOEXCEPT {
13901382 __x.swap(__y);
13911383}
13921384
13931385template <class _Rp, class _Alloc>
1394struct _LIBCPP_TEMPLATE_VIS uses_allocator<promise<_Rp>, _Alloc> : public true_type {};
1386struct uses_allocator<promise<_Rp>, _Alloc> : public true_type {};
13951387
13961388// packaged_task
13971389
......@@ -1610,10 +1602,7 @@ inline _Rp __packaged_task_function<_Rp(_ArgTypes...)>::operator()(_ArgTypes...
16101602}
16111603
16121604template <class _Rp, class... _ArgTypes>
1613class _LIBCPP_TEMPLATE_VIS packaged_task<_Rp(_ArgTypes...)> {
1614public:
1615 using result_type _LIBCPP_DEPRECATED = _Rp; // extension
1616
1605class packaged_task<_Rp(_ArgTypes...)> {
16171606private:
16181607 __packaged_task_function<_Rp(_ArgTypes...)> __f_;
16191608 promise<_Rp> __p_;
......@@ -1665,9 +1654,9 @@ public:
16651654template <class _Rp, class... _ArgTypes>
16661655void packaged_task<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __args) {
16671656 if (__p_.__state_ == nullptr)
1668 __throw_future_error(future_errc::no_state);
1657 std::__throw_future_error(future_errc::no_state);
16691658 if (__p_.__state_->__has_value())
1670 __throw_future_error(future_errc::promise_already_satisfied);
1659 std::__throw_future_error(future_errc::promise_already_satisfied);
16711660# if _LIBCPP_HAS_EXCEPTIONS
16721661 try {
16731662# endif // _LIBCPP_HAS_EXCEPTIONS
......@@ -1682,9 +1671,9 @@ void packaged_task<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __args) {
16821671template <class _Rp, class... _ArgTypes>
16831672void packaged_task<_Rp(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args) {
16841673 if (__p_.__state_ == nullptr)
1685 __throw_future_error(future_errc::no_state);
1674 std::__throw_future_error(future_errc::no_state);
16861675 if (__p_.__state_->__has_value())
1687 __throw_future_error(future_errc::promise_already_satisfied);
1676 std::__throw_future_error(future_errc::promise_already_satisfied);
16881677# if _LIBCPP_HAS_EXCEPTIONS
16891678 try {
16901679# endif // _LIBCPP_HAS_EXCEPTIONS
......@@ -1699,15 +1688,12 @@ void packaged_task<_Rp(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __
16991688template <class _Rp, class... _ArgTypes>
17001689void packaged_task<_Rp(_ArgTypes...)>::reset() {
17011690 if (!valid())
1702 __throw_future_error(future_errc::no_state);
1691 std::__throw_future_error(future_errc::no_state);
17031692 __p_ = promise<_Rp>();
17041693}
17051694
17061695template <class... _ArgTypes>
1707class _LIBCPP_TEMPLATE_VIS packaged_task<void(_ArgTypes...)> {
1708public:
1709 using result_type _LIBCPP_DEPRECATED = void; // extension
1710
1696class packaged_task<void(_ArgTypes...)> {
17111697private:
17121698 __packaged_task_function<void(_ArgTypes...)> __f_;
17131699 promise<void> __p_;
......@@ -1767,9 +1753,9 @@ packaged_task(_Fp) -> packaged_task<_Stripped>;
17671753template <class... _ArgTypes>
17681754void packaged_task<void(_ArgTypes...)>::operator()(_ArgTypes... __args) {
17691755 if (__p_.__state_ == nullptr)
1770 __throw_future_error(future_errc::no_state);
1756 std::__throw_future_error(future_errc::no_state);
17711757 if (__p_.__state_->__has_value())
1772 __throw_future_error(future_errc::promise_already_satisfied);
1758 std::__throw_future_error(future_errc::promise_already_satisfied);
17731759# if _LIBCPP_HAS_EXCEPTIONS
17741760 try {
17751761# endif // _LIBCPP_HAS_EXCEPTIONS
......@@ -1785,9 +1771,9 @@ void packaged_task<void(_ArgTypes...)>::operator()(_ArgTypes... __args) {
17851771template <class... _ArgTypes>
17861772void packaged_task<void(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args) {
17871773 if (__p_.__state_ == nullptr)
1788 __throw_future_error(future_errc::no_state);
1774 std::__throw_future_error(future_errc::no_state);
17891775 if (__p_.__state_->__has_value())
1790 __throw_future_error(future_errc::promise_already_satisfied);
1776 std::__throw_future_error(future_errc::promise_already_satisfied);
17911777# if _LIBCPP_HAS_EXCEPTIONS
17921778 try {
17931779# endif // _LIBCPP_HAS_EXCEPTIONS
......@@ -1803,7 +1789,7 @@ void packaged_task<void(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... _
18031789template <class... _ArgTypes>
18041790void packaged_task<void(_ArgTypes...)>::reset() {
18051791 if (!valid())
1806 __throw_future_error(future_errc::no_state);
1792 std::__throw_future_error(future_errc::no_state);
18071793 __p_ = promise<void>();
18081794}
18091795
......@@ -1815,7 +1801,7 @@ swap(packaged_task<_Rp(_ArgTypes...)>& __x, packaged_task<_Rp(_ArgTypes...)>& __
18151801
18161802# if _LIBCPP_STD_VER <= 14
18171803template <class _Callable, class _Alloc>
1818struct _LIBCPP_TEMPLATE_VIS uses_allocator<packaged_task<_Callable>, _Alloc> : public true_type {};
1804struct uses_allocator<packaged_task<_Callable>, _Alloc> : public true_type {};
18191805# endif
18201806
18211807template <class _Rp, class _Fp>
......@@ -1829,7 +1815,16 @@ template <class _Rp, class _Fp>
18291815_LIBCPP_HIDE_FROM_ABI future<_Rp> __make_async_assoc_state(_Fp&& __f) {
18301816 unique_ptr<__async_assoc_state<_Rp, _Fp>, __release_shared_count> __h(
18311817 new __async_assoc_state<_Rp, _Fp>(std::forward<_Fp>(__f)));
1832 std::thread(&__async_assoc_state<_Rp, _Fp>::__execute, __h.get()).detach();
1818# if _LIBCPP_HAS_EXCEPTIONS
1819 try {
1820# endif
1821 std::thread(&__async_assoc_state<_Rp, _Fp>::__execute, __h.get()).detach();
1822# if _LIBCPP_HAS_EXCEPTIONS
1823 } catch (...) {
1824 __h->__make_ready();
1825 throw;
1826 }
1827# endif
18331828 return future<_Rp>(__h.get());
18341829}
18351830
......@@ -1899,7 +1894,7 @@ async(_Fp&& __f, _Args&&... __args) {
18991894// shared_future
19001895
19011896template <class _Rp>
1902class _LIBCPP_TEMPLATE_VIS shared_future {
1897class shared_future {
19031898 __assoc_state<_Rp>* __state_;
19041899
19051900public:
......@@ -1955,7 +1950,7 @@ shared_future<_Rp>& shared_future<_Rp>::operator=(const shared_future& __rhs) _N
19551950}
19561951
19571952template <class _Rp>
1958class _LIBCPP_TEMPLATE_VIS shared_future<_Rp&> {
1953class shared_future<_Rp&> {
19591954 __assoc_state<_Rp&>* __state_;
19601955
19611956public:
lib/libcxx/include/initializer_list+2-2
......@@ -43,7 +43,7 @@ template<class E> const E* end(initializer_list<E> il) noexcept; // constexpr in
4343*/
4444
4545#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
46# include <__cxx03/initializer_list>
46# include <__cxx03/__config>
4747#else
4848# include <__config>
4949# include <__cstddef/size_t.h>
......@@ -59,7 +59,7 @@ namespace std // purposefully not versioned
5959# ifndef _LIBCPP_CXX03_LANG
6060
6161template <class _Ep>
62class _LIBCPP_TEMPLATE_VIS initializer_list {
62class _LIBCPP_NO_SPECIALIZATIONS initializer_list {
6363 const _Ep* __begin_;
6464 size_t __size_;
6565
lib/libcxx/include/iomanip+8-1
......@@ -49,10 +49,12 @@ template <class charT, class traits, class Allocator>
4949
5050# if _LIBCPP_HAS_LOCALIZATION
5151
52# include <__iterator/istreambuf_iterator.h>
53# include <__locale_dir/money.h>
54# include <__locale_dir/time.h>
5255# include <__ostream/put_character_sequence.h>
5356# include <ios>
5457# include <iosfwd>
55# include <locale>
5658# include <version>
5759
5860# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -564,6 +566,11 @@ _LIBCPP_END_NAMESPACE_STD
564566# include <unordered_map>
565567# include <vector>
566568# endif
569
570# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 23
571# include <locale>
572# endif
573
567574#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
568575
569576#endif // _LIBCPP_IOMANIP
lib/libcxx/include/ios+9-8
......@@ -216,6 +216,11 @@ storage-class-specifier const error_category& iostream_category() noexcept;
216216#else
217217# include <__config>
218218
219// standard-mandated includes
220
221// [ios.syn]
222# include <iosfwd>
223
219224# if _LIBCPP_HAS_LOCALIZATION
220225
221226# include <__fwd/ios.h>
......@@ -230,11 +235,6 @@ storage-class-specifier const error_category& iostream_category() noexcept;
230235# include <__verbose_abort>
231236# include <version>
232237
233// standard-mandated includes
234
235// [ios.syn]
236# include <iosfwd>
237
238238# if _LIBCPP_HAS_ATOMIC_HEADER
239239# include <__atomic/atomic.h> // for __xindex_
240240# endif
......@@ -418,11 +418,11 @@ _LIBCPP_DECLARE_STRONG_ENUM(io_errc){stream = 1};
418418_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc)
419419
420420template <>
421struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc> : public true_type {};
421struct is_error_code_enum<io_errc> : public true_type {};
422422
423423# ifdef _LIBCPP_CXX03_LANG
424424template <>
425struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc::__lx> : public true_type {};
425struct is_error_code_enum<io_errc::__lx> : public true_type {};
426426# endif
427427
428428_LIBCPP_EXPORTED_FROM_ABI const error_category& iostream_category() _NOEXCEPT;
......@@ -559,7 +559,7 @@ private:
559559};
560560
561561template <class _CharT, class _Traits>
562class _LIBCPP_TEMPLATE_VIS basic_ios : public ios_base {
562class basic_ios : public ios_base {
563563public:
564564 // types:
565565 typedef _CharT char_type;
......@@ -887,6 +887,7 @@ _LIBCPP_POP_MACROS
887887# include <limits>
888888# include <mutex>
889889# include <new>
890# include <optional>
890891# include <stdexcept>
891892# include <system_error>
892893# include <type_traits>
lib/libcxx/include/iosfwd+3-3
......@@ -127,12 +127,12 @@ using wosyncstream = basic_osyncstream<wchar_t>; // C++20
127127_LIBCPP_BEGIN_NAMESPACE_STD
128128
129129template <class _CharT, class _Traits = char_traits<_CharT> >
130class _LIBCPP_TEMPLATE_VIS istreambuf_iterator;
130class istreambuf_iterator;
131131template <class _CharT, class _Traits = char_traits<_CharT> >
132class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator;
132class ostreambuf_iterator;
133133
134134template <class _State>
135class _LIBCPP_TEMPLATE_VIS fpos;
135class fpos;
136136typedef fpos<mbstate_t> streampos;
137137# if _LIBCPP_HAS_WIDE_CHARACTERS
138138typedef fpos<mbstate_t> wstreampos;
lib/libcxx/include/istream+65-33
......@@ -167,6 +167,7 @@ template <class Stream, class T>
167167
168168# include <__fwd/istream.h>
169169# include <__iterator/istreambuf_iterator.h>
170# include <__locale_dir/num.h>
170171# include <__ostream/basic_ostream.h>
171172# include <__type_traits/conjunction.h>
172173# include <__type_traits/enable_if.h>
......@@ -176,7 +177,7 @@ template <class Stream, class T>
176177# include <__utility/forward.h>
177178# include <bitset>
178179# include <ios>
179# include <locale>
180# include <streambuf>
180181# include <version>
181182
182183# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
......@@ -189,7 +190,7 @@ _LIBCPP_PUSH_MACROS
189190_LIBCPP_BEGIN_NAMESPACE_STD
190191
191192template <class _CharT, class _Traits>
192class _LIBCPP_TEMPLATE_VIS basic_istream : virtual public basic_ios<_CharT, _Traits> {
193class basic_istream : virtual public basic_ios<_CharT, _Traits> {
193194 streamsize __gc_;
194195
195196 _LIBCPP_HIDE_FROM_ABI void __inc_gcount() {
......@@ -228,7 +229,7 @@ public:
228229 basic_istream& operator=(const basic_istream& __rhs) = delete;
229230
230231 // 27.7.1.1.3 Prefix/suffix:
231 class _LIBCPP_TEMPLATE_VIS sentry;
232 class sentry;
232233
233234 // 27.7.1.2 Formatted input:
234235 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&)) {
......@@ -305,7 +306,7 @@ public:
305306};
306307
307308template <class _CharT, class _Traits>
308class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry {
309class basic_istream<_CharT, _Traits>::sentry {
309310 bool __ok_;
310311
311312public:
......@@ -1167,9 +1168,7 @@ _LIBCPP_HIDE_FROM_ABI _Stream&& operator>>(_Stream&& __is, _Tp&& __x) {
11671168}
11681169
11691170template <class _CharT, class _Traits>
1170class _LIBCPP_TEMPLATE_VIS basic_iostream
1171 : public basic_istream<_CharT, _Traits>,
1172 public basic_ostream<_CharT, _Traits> {
1171class basic_iostream : public basic_istream<_CharT, _Traits>, public basic_ostream<_CharT, _Traits> {
11731172public:
11741173 // types:
11751174 typedef _CharT char_type;
......@@ -1265,41 +1264,70 @@ _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
12651264getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) {
12661265 ios_base::iostate __state = ios_base::goodbit;
12671266 typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
1268 if (__sen) {
1267 if (!__sen)
1268 return __is;
12691269# if _LIBCPP_HAS_EXCEPTIONS
1270 try {
1270 try {
12711271# endif
1272 __str.clear();
1273 streamsize __extr = 0;
1274 while (true) {
1275 typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
1276 if (_Traits::eq_int_type(__i, _Traits::eof())) {
1277 __state |= ios_base::eofbit;
1278 break;
1272 __str.clear();
1273
1274 auto& __buffer = *__is.rdbuf();
1275
1276 auto __next = __buffer.sgetc();
1277 for (; !_Traits::eq_int_type(__next, _Traits::eof()); __next = __buffer.sgetc()) {
1278 const auto* __first = __buffer.gptr();
1279 const auto* __last = __buffer.egptr();
1280 _CharT __1buf;
1281
1282 if (__first == __last) {
1283 __1buf = __next;
1284 __first = std::addressof(__1buf);
1285 __last = std::addressof(__1buf) + 1;
1286 }
1287
1288 auto __bump_stream = [&](ptrdiff_t __diff) {
1289 if (__first == std::addressof(__1buf)) {
1290 _LIBCPP_ASSERT_INTERNAL(__diff == 0 || __diff == 1, "trying to bump stream further than buffer size");
1291 if (__diff != 0)
1292 __buffer.sbumpc();
1293 } else {
1294 __buffer.__gbump_ptrdiff(__diff);
12791295 }
1280 ++__extr;
1281 _CharT __ch = _Traits::to_char_type(__i);
1282 if (_Traits::eq(__ch, __dlm))
1283 break;
1284 __str.push_back(__ch);
1285 if (__str.size() == __str.max_size()) {
1286 __state |= ios_base::failbit;
1296 };
1297
1298 const auto* const __match = _Traits::find(__first, __last - __first, __dlm);
1299 if (__match)
1300 __last = __match;
1301
1302 if (auto __cap = __str.max_size() - __str.size(); __cap > static_cast<size_t>(__last - __first)) {
1303 __str.append(__first, __last);
1304 __bump_stream(__last - __first);
1305
1306 if (__match) {
1307 __bump_stream(1); // Remove the matched character
12871308 break;
12881309 }
1289 }
1290 if (__extr == 0)
1310 } else {
1311 __str.append(__first, __cap);
1312 __bump_stream(__cap);
12911313 __state |= ios_base::failbit;
1292# if _LIBCPP_HAS_EXCEPTIONS
1293 } catch (...) {
1294 __state |= ios_base::badbit;
1295 __is.__setstate_nothrow(__state);
1296 if (__is.exceptions() & ios_base::badbit) {
1297 throw;
1314 break;
12981315 }
12991316 }
1300# endif
1301 __is.setstate(__state);
1317
1318 if (_Traits::eq_int_type(__next, _Traits::eof()))
1319 __state |= ios_base::eofbit | (__str.empty() ? ios_base::failbit : ios_base::goodbit);
1320
1321# if _LIBCPP_HAS_EXCEPTIONS
1322 } catch (...) {
1323 __state |= ios_base::badbit;
1324 __is.__setstate_nothrow(__state);
1325 if (__is.exceptions() & ios_base::badbit) {
1326 throw;
1327 }
13021328 }
1329# endif
1330 __is.setstate(__state);
13031331 return __is;
13041332}
13051333
......@@ -1384,6 +1412,10 @@ _LIBCPP_POP_MACROS
13841412# include <type_traits>
13851413# endif
13861414
1415# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 23
1416# include <locale>
1417# endif
1418
13871419#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
13881420
13891421#endif // _LIBCPP_ISTREAM
lib/libcxx/include/iterator+1-1
......@@ -530,7 +530,7 @@ public:
530530 istream_iterator(); // constexpr since C++11
531531 constexpr istream_iterator(default_sentinel_t); // since C++20
532532 istream_iterator(istream_type& s);
533 istream_iterator(const istream_iterator& x);
533 constexpr istream_iterator(const istream_iterator& x) noexcept(see below);
534534 ~istream_iterator();
535535
536536 const T& operator*() const;
lib/libcxx/include/latch+1-1
......@@ -41,7 +41,7 @@ namespace std
4141*/
4242
4343#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
44# include <__cxx03/latch>
44# include <__cxx03/__config>
4545#else
4646# include <__config>
4747
lib/libcxx/include/limits+7-20
......@@ -108,7 +108,6 @@ template<> class numeric_limits<cv long double>;
108108# include <__config>
109109# include <__type_traits/is_arithmetic.h>
110110# include <__type_traits/is_signed.h>
111# include <__type_traits/remove_cv.h>
112111
113112# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
114113# pragma GCC system_header
......@@ -178,16 +177,6 @@ protected:
178177 static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero;
179178};
180179
181template <class _Tp, int __digits, bool _IsSigned>
182struct __libcpp_compute_min {
183 static _LIBCPP_CONSTEXPR const _Tp value = _Tp(_Tp(1) << __digits);
184};
185
186template <class _Tp, int __digits>
187struct __libcpp_compute_min<_Tp, __digits, false> {
188 static _LIBCPP_CONSTEXPR const _Tp value = _Tp(0);
189};
190
191180template <class _Tp>
192181class __libcpp_numeric_limits<_Tp, true> {
193182protected:
......@@ -199,7 +188,7 @@ protected:
199188 static _LIBCPP_CONSTEXPR const int digits = static_cast<int>(sizeof(type) * __CHAR_BIT__ - is_signed);
200189 static _LIBCPP_CONSTEXPR const int digits10 = digits * 3 / 10;
201190 static _LIBCPP_CONSTEXPR const int max_digits10 = 0;
202 static _LIBCPP_CONSTEXPR const type __min = __libcpp_compute_min<type, digits, is_signed>::value;
191 static _LIBCPP_CONSTEXPR const type __min = is_signed ? _Tp(_Tp(1) << digits) : 0;
203192 static _LIBCPP_CONSTEXPR const type __max = is_signed ? type(type(~0) ^ __min) : type(~0);
204193 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __min; }
205194 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __max; }
......@@ -250,10 +239,8 @@ protected:
250239 static _LIBCPP_CONSTEXPR const int digits = 1;
251240 static _LIBCPP_CONSTEXPR const int digits10 = 0;
252241 static _LIBCPP_CONSTEXPR const int max_digits10 = 0;
253 static _LIBCPP_CONSTEXPR const type __min = false;
254 static _LIBCPP_CONSTEXPR const type __max = true;
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; }
242 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return false; }
243 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return true; }
257244 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return min(); }
258245
259246 static _LIBCPP_CONSTEXPR const bool is_integer = true;
......@@ -462,7 +449,7 @@ protected:
462449};
463450
464451template <class _Tp>
465class _LIBCPP_TEMPLATE_VIS numeric_limits : private __libcpp_numeric_limits<_Tp> {
452class numeric_limits : private __libcpp_numeric_limits<_Tp> {
466453 typedef __libcpp_numeric_limits<_Tp> __base;
467454 typedef typename __base::type type;
468455
......@@ -521,13 +508,13 @@ public:
521508};
522509
523510template <class _Tp>
524class _LIBCPP_TEMPLATE_VIS numeric_limits<const _Tp> : public numeric_limits<_Tp> {};
511class numeric_limits<const _Tp> : public numeric_limits<_Tp> {};
525512
526513template <class _Tp>
527class _LIBCPP_TEMPLATE_VIS numeric_limits<volatile _Tp> : public numeric_limits<_Tp> {};
514class numeric_limits<volatile _Tp> : public numeric_limits<_Tp> {};
528515
529516template <class _Tp>
530class _LIBCPP_TEMPLATE_VIS numeric_limits<const volatile _Tp> : public numeric_limits<_Tp> {};
517class numeric_limits<const volatile _Tp> : public numeric_limits<_Tp> {};
531518
532519_LIBCPP_END_NAMESPACE_STD
533520
lib/libcxx/include/list+343-247
......@@ -60,9 +60,9 @@ public:
6060
6161 list& operator=(const list& x);
6262 list& operator=(list&& x)
63 noexcept(
64 allocator_type::propagate_on_container_move_assignment::value &&
65 is_nothrow_move_assignable<allocator_type>::value);
63 noexcept((__node_alloc_traits::propagate_on_container_move_assignment::value &&
64 is_nothrow_move_assignable<__node_allocator>::value) ||
65 allocator_traits<allocator_type>::is_always_equal::value);
6666 list& operator=(initializer_list<value_type>);
6767 template <class Iter>
6868 void assign(Iter first, Iter last);
......@@ -286,12 +286,6 @@ struct __list_node_pointer_traits {
286286 "LLVM 19 and LLVM 20. If you don't care about your ABI being broken, define the "
287287 "_LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB macro to silence this diagnostic.");
288288# endif
289
290 static _LIBCPP_HIDE_FROM_ABI __base_pointer __unsafe_link_pointer_cast(__base_pointer __p) { return __p; }
291
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));
294 }
295289};
296290
297291template <class _Tp, class _VoidPtr>
......@@ -303,14 +297,20 @@ struct __list_node_base {
303297 __base_pointer __prev_;
304298 __base_pointer __next_;
305299
306 _LIBCPP_HIDE_FROM_ABI __list_node_base() : __prev_(__self()), __next_(__self()) {}
300 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __list_node_base() : __prev_(__self()), __next_(__self()) {}
307301
302 _LIBCPP_CONSTEXPR_SINCE_CXX26
308303 _LIBCPP_HIDE_FROM_ABI explicit __list_node_base(__base_pointer __prev, __base_pointer __next)
309304 : __prev_(__prev), __next_(__next) {}
310305
311 _LIBCPP_HIDE_FROM_ABI __base_pointer __self() { return pointer_traits<__base_pointer>::pointer_to(*this); }
306 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __base_pointer __self() {
307 return pointer_traits<__base_pointer>::pointer_to(*this);
308 }
312309
313 _LIBCPP_HIDE_FROM_ABI __node_pointer __as_node() { return static_cast<__node_pointer>(__self()); }
310 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __node_pointer __as_node() {
311 return pointer_traits<__node_pointer>::pointer_to(
312 *static_cast<typename pointer_traits<__node_pointer>::element_type*>(this));
313 }
314314};
315315
316316template <class _Tp, class _VoidPtr>
......@@ -325,7 +325,7 @@ private:
325325 };
326326
327327public:
328 _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return __value_; }
328 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return __value_; }
329329# else
330330
331331private:
......@@ -338,27 +338,32 @@ public:
338338 typedef __list_node_base<_Tp, _VoidPtr> __base;
339339 typedef typename __base::__base_pointer __base_pointer;
340340
341 _LIBCPP_HIDE_FROM_ABI explicit __list_node(__base_pointer __prev, __base_pointer __next) : __base(__prev, __next) {}
342 _LIBCPP_HIDE_FROM_ABI ~__list_node() {}
341 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit __list_node(__base_pointer __prev, __base_pointer __next)
342 : __base(__prev, __next) {}
343 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI ~__list_node() {}
343344
344 _LIBCPP_HIDE_FROM_ABI __base_pointer __as_link() { return __base::__self(); }
345 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __base_pointer __as_link() {
346 return pointer_traits<__base_pointer>::pointer_to(
347 *static_cast<typename pointer_traits<__base_pointer>::element_type*>(std::addressof(*this)));
348 }
345349};
346350
347351template <class _Tp, class _Alloc = allocator<_Tp> >
348class _LIBCPP_TEMPLATE_VIS list;
352class list;
349353template <class _Tp, class _Alloc>
350354class __list_imp;
351355template <class _Tp, class _VoidPtr>
352class _LIBCPP_TEMPLATE_VIS __list_const_iterator;
356class __list_const_iterator;
353357
354358template <class _Tp, class _VoidPtr>
355class _LIBCPP_TEMPLATE_VIS __list_iterator {
359class __list_iterator {
356360 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
357361 typedef typename _NodeTraits::__base_pointer __base_pointer;
358362
359363 __base_pointer __ptr_;
360364
361 _LIBCPP_HIDE_FROM_ABI explicit __list_iterator(__base_pointer __p) _NOEXCEPT : __ptr_(__p) {}
365 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit __list_iterator(__base_pointer __p) _NOEXCEPT
366 : __ptr_(__p) {}
362367
363368 template <class, class>
364369 friend class list;
......@@ -374,49 +379,54 @@ public:
374379 typedef __rebind_pointer_t<_VoidPtr, value_type> pointer;
375380 typedef typename pointer_traits<pointer>::difference_type difference_type;
376381
377 _LIBCPP_HIDE_FROM_ABI __list_iterator() _NOEXCEPT : __ptr_(nullptr) {}
382 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __list_iterator() _NOEXCEPT : __ptr_(nullptr) {}
378383
379 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __ptr_->__as_node()->__get_value(); }
380 _LIBCPP_HIDE_FROM_ABI pointer operator->() const {
384 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI reference operator*() const {
385 return __ptr_->__as_node()->__get_value();
386 }
387 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI pointer operator->() const {
381388 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__get_value());
382389 }
383390
384 _LIBCPP_HIDE_FROM_ABI __list_iterator& operator++() {
391 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __list_iterator& operator++() {
385392 __ptr_ = __ptr_->__next_;
386393 return *this;
387394 }
388 _LIBCPP_HIDE_FROM_ABI __list_iterator operator++(int) {
395 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __list_iterator operator++(int) {
389396 __list_iterator __t(*this);
390397 ++(*this);
391398 return __t;
392399 }
393400
394 _LIBCPP_HIDE_FROM_ABI __list_iterator& operator--() {
401 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __list_iterator& operator--() {
395402 __ptr_ = __ptr_->__prev_;
396403 return *this;
397404 }
398 _LIBCPP_HIDE_FROM_ABI __list_iterator operator--(int) {
405 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __list_iterator operator--(int) {
399406 __list_iterator __t(*this);
400407 --(*this);
401408 return __t;
402409 }
403410
404 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __list_iterator& __x, const __list_iterator& __y) {
411 friend _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI bool
412 operator==(const __list_iterator& __x, const __list_iterator& __y) {
405413 return __x.__ptr_ == __y.__ptr_;
406414 }
407 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __list_iterator& __x, const __list_iterator& __y) {
415 friend _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI bool
416 operator!=(const __list_iterator& __x, const __list_iterator& __y) {
408417 return !(__x == __y);
409418 }
410419};
411420
412421template <class _Tp, class _VoidPtr>
413class _LIBCPP_TEMPLATE_VIS __list_const_iterator {
422class __list_const_iterator {
414423 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
415424 typedef typename _NodeTraits::__base_pointer __base_pointer;
416425
417426 __base_pointer __ptr_;
418427
419 _LIBCPP_HIDE_FROM_ABI explicit __list_const_iterator(__base_pointer __p) _NOEXCEPT : __ptr_(__p) {}
428 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit __list_const_iterator(__base_pointer __p) _NOEXCEPT
429 : __ptr_(__p) {}
420430
421431 template <class, class>
422432 friend class list;
......@@ -430,39 +440,43 @@ public:
430440 typedef __rebind_pointer_t<_VoidPtr, const value_type> pointer;
431441 typedef typename pointer_traits<pointer>::difference_type difference_type;
432442
433 _LIBCPP_HIDE_FROM_ABI __list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {}
434 _LIBCPP_HIDE_FROM_ABI __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
435 : __ptr_(__p.__ptr_) {}
443 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {}
444 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
445 __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT : __ptr_(__p.__ptr_) {}
436446
437 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __ptr_->__as_node()->__get_value(); }
438 _LIBCPP_HIDE_FROM_ABI pointer operator->() const {
447 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI reference operator*() const {
448 return __ptr_->__as_node()->__get_value();
449 }
450 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI pointer operator->() const {
439451 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__get_value());
440452 }
441453
442 _LIBCPP_HIDE_FROM_ABI __list_const_iterator& operator++() {
454 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __list_const_iterator& operator++() {
443455 __ptr_ = __ptr_->__next_;
444456 return *this;
445457 }
446 _LIBCPP_HIDE_FROM_ABI __list_const_iterator operator++(int) {
458 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __list_const_iterator operator++(int) {
447459 __list_const_iterator __t(*this);
448460 ++(*this);
449461 return __t;
450462 }
451463
452 _LIBCPP_HIDE_FROM_ABI __list_const_iterator& operator--() {
464 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __list_const_iterator& operator--() {
453465 __ptr_ = __ptr_->__prev_;
454466 return *this;
455467 }
456 _LIBCPP_HIDE_FROM_ABI __list_const_iterator operator--(int) {
468 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __list_const_iterator operator--(int) {
457469 __list_const_iterator __t(*this);
458470 --(*this);
459471 return __t;
460472 }
461473
462 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y) {
474 friend _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI bool
475 operator==(const __list_const_iterator& __x, const __list_const_iterator& __y) {
463476 return __x.__ptr_ == __y.__ptr_;
464477 }
465 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y) {
478 friend _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI bool
479 operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y) {
466480 return !(__x == __y);
467481 }
468482};
......@@ -503,43 +517,49 @@ protected:
503517 __node_base __end_;
504518 _LIBCPP_COMPRESSED_PAIR(size_type, __size_, __node_allocator, __node_alloc_);
505519
506 _LIBCPP_HIDE_FROM_ABI __base_pointer __end_as_link() const _NOEXCEPT {
507 return __node_pointer_traits::__unsafe_link_pointer_cast(const_cast<__node_base&>(__end_).__self());
520 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __base_pointer __end_as_link() const _NOEXCEPT {
521 return pointer_traits<__base_pointer>::pointer_to(const_cast<__node_base&>(__end_));
508522 }
509523
510 _LIBCPP_HIDE_FROM_ABI size_type __node_alloc_max_size() const _NOEXCEPT {
524 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI size_type __node_alloc_max_size() const _NOEXCEPT {
511525 return __node_alloc_traits::max_size(__node_alloc_);
512526 }
513 _LIBCPP_HIDE_FROM_ABI static void __unlink_nodes(__base_pointer __f, __base_pointer __l) _NOEXCEPT;
527 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI static void
528 __unlink_nodes(__base_pointer __f, __base_pointer __l) _NOEXCEPT;
514529
515 _LIBCPP_HIDE_FROM_ABI __list_imp() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
516 _LIBCPP_HIDE_FROM_ABI __list_imp(const allocator_type& __a);
517 _LIBCPP_HIDE_FROM_ABI __list_imp(const __node_allocator& __a);
530 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __list_imp()
531 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
532 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __list_imp(const allocator_type& __a);
533 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __list_imp(const __node_allocator& __a);
518534# ifndef _LIBCPP_CXX03_LANG
519 _LIBCPP_HIDE_FROM_ABI __list_imp(__node_allocator&& __a) _NOEXCEPT;
535 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __list_imp(__node_allocator&& __a) _NOEXCEPT;
520536# endif
521 _LIBCPP_HIDE_FROM_ABI ~__list_imp();
522 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT;
523 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __size_ == 0; }
537 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI ~__list_imp();
538 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT;
539 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __size_ == 0; }
524540
525 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return iterator(__end_.__next_); }
526 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return const_iterator(__end_.__next_); }
527 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return iterator(__end_as_link()); }
528 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return const_iterator(__end_as_link()); }
541 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return iterator(__end_.__next_); }
542 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT {
543 return const_iterator(__end_.__next_);
544 }
545 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return iterator(__end_as_link()); }
546 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT {
547 return const_iterator(__end_as_link());
548 }
529549
530 _LIBCPP_HIDE_FROM_ABI void swap(__list_imp& __c)
550 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void swap(__list_imp& __c)
531551# if _LIBCPP_STD_VER >= 14
532552 _NOEXCEPT;
533553# else
534554 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>);
535555# endif
536556
537 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __list_imp& __c) {
557 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __list_imp& __c) {
538558 __copy_assign_alloc(
539559 __c, integral_constant<bool, __node_alloc_traits::propagate_on_container_copy_assignment::value>());
540560 }
541561
542 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__list_imp& __c)
562 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__list_imp& __c)
543563 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_move_assignment::value ||
544564 is_nothrow_move_assignable<__node_allocator>::value) {
545565 __move_assign_alloc(
......@@ -547,7 +567,8 @@ protected:
547567 }
548568
549569 template <class... _Args>
550 _LIBCPP_HIDE_FROM_ABI __node_pointer __create_node(__base_pointer __prev, __base_pointer __next, _Args&&... __args) {
570 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __node_pointer
571 __create_node(__base_pointer __prev, __base_pointer __next, _Args&&... __args) {
551572 __allocation_guard<__node_allocator> __guard(__node_alloc_, 1);
552573 // Begin the lifetime of the node itself. Note that this doesn't begin the lifetime of the value
553574 // held inside the node, since we need to use the allocator's construct() method for that.
......@@ -563,7 +584,7 @@ protected:
563584 return __guard.__release_ptr();
564585 }
565586
566 _LIBCPP_HIDE_FROM_ABI void __delete_node(__node_pointer __node) {
587 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __delete_node(__node_pointer __node) {
567588 // For the same reason as above, we use the allocator's destroy() method for the value_type,
568589 // but not for the node itself.
569590 __node_alloc_traits::destroy(__node_alloc_, std::addressof(__node->__get_value()));
......@@ -572,54 +593,57 @@ protected:
572593 }
573594
574595private:
575 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __list_imp& __c, true_type) {
596 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __list_imp& __c, true_type) {
576597 if (__node_alloc_ != __c.__node_alloc_)
577598 clear();
578599 __node_alloc_ = __c.__node_alloc_;
579600 }
580601
581 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __list_imp&, false_type) {}
602 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __list_imp&, false_type) {}
582603
583 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__list_imp& __c, true_type)
604 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__list_imp& __c, true_type)
584605 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) {
585606 __node_alloc_ = std::move(__c.__node_alloc_);
586607 }
587608
588 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__list_imp&, false_type) _NOEXCEPT {}
609 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__list_imp&, false_type) _NOEXCEPT {}
589610};
590611
591612// Unlink nodes [__f, __l]
592613template <class _Tp, class _Alloc>
593inline void __list_imp<_Tp, _Alloc>::__unlink_nodes(__base_pointer __f, __base_pointer __l) _NOEXCEPT {
614_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void
615__list_imp<_Tp, _Alloc>::__unlink_nodes(__base_pointer __f, __base_pointer __l) _NOEXCEPT {
594616 __f->__prev_->__next_ = __l->__next_;
595617 __l->__next_->__prev_ = __f->__prev_;
596618}
597619
598620template <class _Tp, class _Alloc>
599inline __list_imp<_Tp, _Alloc>::__list_imp() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
621_LIBCPP_CONSTEXPR_SINCE_CXX26 inline __list_imp<_Tp, _Alloc>::__list_imp()
622 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
600623 : __size_(0) {}
601624
602625template <class _Tp, class _Alloc>
603inline __list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
626_LIBCPP_CONSTEXPR_SINCE_CXX26 inline __list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
604627 : __size_(0), __node_alloc_(__node_allocator(__a)) {}
605628
606629template <class _Tp, class _Alloc>
607inline __list_imp<_Tp, _Alloc>::__list_imp(const __node_allocator& __a) : __size_(0), __node_alloc_(__a) {}
630_LIBCPP_CONSTEXPR_SINCE_CXX26 inline __list_imp<_Tp, _Alloc>::__list_imp(const __node_allocator& __a)
631 : __size_(0), __node_alloc_(__a) {}
608632
609633# ifndef _LIBCPP_CXX03_LANG
610634template <class _Tp, class _Alloc>
611inline __list_imp<_Tp, _Alloc>::__list_imp(__node_allocator&& __a) _NOEXCEPT
635_LIBCPP_CONSTEXPR_SINCE_CXX26 inline __list_imp<_Tp, _Alloc>::__list_imp(__node_allocator&& __a) _NOEXCEPT
612636 : __size_(0),
613637 __node_alloc_(std::move(__a)) {}
614638# endif
615639
616640template <class _Tp, class _Alloc>
617__list_imp<_Tp, _Alloc>::~__list_imp() {
641_LIBCPP_CONSTEXPR_SINCE_CXX26 __list_imp<_Tp, _Alloc>::~__list_imp() {
618642 clear();
619643}
620644
621645template <class _Tp, class _Alloc>
622void __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT {
646_LIBCPP_CONSTEXPR_SINCE_CXX26 void __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT {
623647 if (!empty()) {
624648 __base_pointer __f = __end_.__next_;
625649 __base_pointer __l = __end_as_link();
......@@ -634,7 +658,7 @@ void __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT {
634658}
635659
636660template <class _Tp, class _Alloc>
637void __list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
661_LIBCPP_CONSTEXPR_SINCE_CXX26 void __list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
638662# if _LIBCPP_STD_VER >= 14
639663 _NOEXCEPT
640664# else
......@@ -660,7 +684,7 @@ void __list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
660684}
661685
662686template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
663class _LIBCPP_TEMPLATE_VIS list : private __list_imp<_Tp, _Alloc> {
687class list : private __list_imp<_Tp, _Alloc> {
664688 typedef __list_imp<_Tp, _Alloc> __base;
665689 typedef typename __base::__node_type __node_type;
666690 typedef typename __base::__node_allocator __node_allocator;
......@@ -692,169 +716,204 @@ public:
692716 typedef void __remove_return_type;
693717# endif
694718
695 _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) {}
697 _LIBCPP_HIDE_FROM_ABI explicit list(size_type __n);
719 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI list()
720 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) {}
721 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit list(const allocator_type& __a) : __base(__a) {}
722 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit list(size_type __n);
698723# if _LIBCPP_STD_VER >= 14
699 _LIBCPP_HIDE_FROM_ABI explicit list(size_type __n, const allocator_type& __a);
724 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit list(size_type __n, const allocator_type& __a);
700725# endif
701 _LIBCPP_HIDE_FROM_ABI list(size_type __n, const value_type& __x);
726 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI list(size_type __n, const value_type& __x);
702727 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) {
728 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
729 list(size_type __n, const value_type& __x, const allocator_type& __a)
730 : __base(__a) {
704731 for (; __n > 0; --__n)
705732 push_back(__x);
706733 }
707734
708735 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> = 0>
709 _LIBCPP_HIDE_FROM_ABI list(_InpIter __f, _InpIter __l);
736 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI list(_InpIter __f, _InpIter __l);
710737
711738 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> = 0>
712 _LIBCPP_HIDE_FROM_ABI list(_InpIter __f, _InpIter __l, const allocator_type& __a);
739 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI list(_InpIter __f, _InpIter __l, const allocator_type& __a);
713740
714741# if _LIBCPP_STD_VER >= 23
715742 template <_ContainerCompatibleRange<_Tp> _Range>
716 _LIBCPP_HIDE_FROM_ABI list(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
743 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
744 list(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
717745 : __base(__a) {
718746 prepend_range(std::forward<_Range>(__range));
719747 }
720748# endif
721749
722 _LIBCPP_HIDE_FROM_ABI list(const list& __c);
723 _LIBCPP_HIDE_FROM_ABI list(const list& __c, const __type_identity_t<allocator_type>& __a);
724 _LIBCPP_HIDE_FROM_ABI list& operator=(const list& __c);
750 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI list(const list& __c);
751 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
752 list(const list& __c, const __type_identity_t<allocator_type>& __a);
753 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI list& operator=(const list& __c);
725754# ifndef _LIBCPP_CXX03_LANG
726 _LIBCPP_HIDE_FROM_ABI list(initializer_list<value_type> __il);
727 _LIBCPP_HIDE_FROM_ABI list(initializer_list<value_type> __il, const allocator_type& __a);
728
729 _LIBCPP_HIDE_FROM_ABI list(list&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
730 _LIBCPP_HIDE_FROM_ABI list(list&& __c, const __type_identity_t<allocator_type>& __a);
731 _LIBCPP_HIDE_FROM_ABI list& operator=(list&& __c)
732 _NOEXCEPT_(__node_alloc_traits::propagate_on_container_move_assignment::value&&
733 is_nothrow_move_assignable<__node_allocator>::value);
734
735 _LIBCPP_HIDE_FROM_ABI list& operator=(initializer_list<value_type> __il) {
755 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI list(initializer_list<value_type> __il);
756 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
757 list(initializer_list<value_type> __il, const allocator_type& __a);
758
759 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI list(list&& __c)
760 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
761 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI list(list&& __c, const __type_identity_t<allocator_type>& __a);
762 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI list& operator=(list&& __c) noexcept(
763 (__node_alloc_traits::propagate_on_container_move_assignment::value &&
764 is_nothrow_move_assignable<__node_allocator>::value) ||
765 allocator_traits<allocator_type>::is_always_equal::value);
766
767 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI list& operator=(initializer_list<value_type> __il) {
736768 assign(__il.begin(), __il.end());
737769 return *this;
738770 }
739771
740 _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<value_type> __il) { assign(__il.begin(), __il.end()); }
772 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<value_type> __il) {
773 assign(__il.begin(), __il.end());
774 }
741775# endif // _LIBCPP_CXX03_LANG
742776
743777 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> = 0>
744 _LIBCPP_HIDE_FROM_ABI void assign(_InpIter __f, _InpIter __l);
778 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void assign(_InpIter __f, _InpIter __l);
745779
746780# if _LIBCPP_STD_VER >= 23
747781 template <_ContainerCompatibleRange<_Tp> _Range>
748 _LIBCPP_HIDE_FROM_ABI void assign_range(_Range&& __range) {
782 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void assign_range(_Range&& __range) {
749783 __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
750784 }
751785# endif
752786
753 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const value_type& __x);
787 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const value_type& __x);
754788
755 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT;
789 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT;
756790
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(); }
759 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
791 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return this->__size_; }
792 [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT {
793 return __base::empty();
794 }
795 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
760796 return std::min<size_type>(this->__node_alloc_max_size(), numeric_limits<difference_type >::max());
761797 }
762798
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(); }
799 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __base::begin(); }
800 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __base::begin(); }
801 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __base::end(); }
802 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return __base::end(); }
803 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT {
804 return __base::begin();
805 }
806 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return __base::end(); }
769807
770 _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { return reverse_iterator(end()); }
771 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
772 _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT { return reverse_iterator(begin()); }
773 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
774 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
775 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
808 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT {
809 return reverse_iterator(end());
810 }
811 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT {
812 return const_reverse_iterator(end());
813 }
814 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT {
815 return reverse_iterator(begin());
816 }
817 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT {
818 return const_reverse_iterator(begin());
819 }
820 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT {
821 return const_reverse_iterator(end());
822 }
823 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT {
824 return const_reverse_iterator(begin());
825 }
776826
777 _LIBCPP_HIDE_FROM_ABI reference front() {
827 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI reference front() {
778828 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::front called on empty list");
779829 return __base::__end_.__next_->__as_node()->__get_value();
780830 }
781 _LIBCPP_HIDE_FROM_ABI const_reference front() const {
831 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_reference front() const {
782832 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::front called on empty list");
783833 return __base::__end_.__next_->__as_node()->__get_value();
784834 }
785 _LIBCPP_HIDE_FROM_ABI reference back() {
835 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI reference back() {
786836 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::back called on empty list");
787837 return __base::__end_.__prev_->__as_node()->__get_value();
788838 }
789 _LIBCPP_HIDE_FROM_ABI const_reference back() const {
839 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_reference back() const {
790840 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::back called on empty list");
791841 return __base::__end_.__prev_->__as_node()->__get_value();
792842 }
793843
794844# ifndef _LIBCPP_CXX03_LANG
795 _LIBCPP_HIDE_FROM_ABI void push_front(value_type&& __x);
796 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x);
845 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void push_front(value_type&& __x);
846 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x);
797847
798848# if _LIBCPP_STD_VER >= 23
799849 template <_ContainerCompatibleRange<_Tp> _Range>
800 _LIBCPP_HIDE_FROM_ABI void prepend_range(_Range&& __range) {
850 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void prepend_range(_Range&& __range) {
801851 insert_range(begin(), std::forward<_Range>(__range));
802852 }
803853
804854 template <_ContainerCompatibleRange<_Tp> _Range>
805 _LIBCPP_HIDE_FROM_ABI void append_range(_Range&& __range) {
855 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void append_range(_Range&& __range) {
806856 insert_range(end(), std::forward<_Range>(__range));
807857 }
808858# endif
809859
810860 template <class... _Args>
861 _LIBCPP_CONSTEXPR_SINCE_CXX26
811862# if _LIBCPP_STD_VER >= 17
812 _LIBCPP_HIDE_FROM_ABI reference emplace_front(_Args&&... __args);
863 _LIBCPP_HIDE_FROM_ABI reference
864 emplace_front(_Args&&... __args);
813865# else
814 _LIBCPP_HIDE_FROM_ABI void emplace_front(_Args&&... __args);
866 _LIBCPP_HIDE_FROM_ABI void
867 emplace_front(_Args&&... __args);
815868# endif
816869 template <class... _Args>
870 _LIBCPP_CONSTEXPR_SINCE_CXX26
817871# if _LIBCPP_STD_VER >= 17
818 _LIBCPP_HIDE_FROM_ABI reference emplace_back(_Args&&... __args);
872 _LIBCPP_HIDE_FROM_ABI reference
873 emplace_back(_Args&&... __args);
819874# else
820 _LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args);
875 _LIBCPP_HIDE_FROM_ABI void
876 emplace_back(_Args&&... __args);
821877# endif
822878 template <class... _Args>
823 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __p, _Args&&... __args);
879 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __p, _Args&&... __args);
824880
825 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __x);
881 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __x);
826882
827 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, initializer_list<value_type> __il) {
883 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator
884 insert(const_iterator __p, initializer_list<value_type> __il) {
828885 return insert(__p, __il.begin(), __il.end());
829886 }
830887# endif // _LIBCPP_CXX03_LANG
831888
832 _LIBCPP_HIDE_FROM_ABI void push_front(const value_type& __x);
833 _LIBCPP_HIDE_FROM_ABI void push_back(const value_type& __x);
889 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void push_front(const value_type& __x);
890 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void push_back(const value_type& __x);
834891
835892# ifndef _LIBCPP_CXX03_LANG
836893 template <class _Arg>
837 _LIBCPP_HIDE_FROM_ABI void __emplace_back(_Arg&& __arg) {
894 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __emplace_back(_Arg&& __arg) {
838895 emplace_back(std::forward<_Arg>(__arg));
839896 }
840897# else
841898 _LIBCPP_HIDE_FROM_ABI void __emplace_back(value_type const& __arg) { push_back(__arg); }
842899# endif
843900
844 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __x);
845 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, size_type __n, const value_type& __x);
901 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __x);
902 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator
903 insert(const_iterator __p, size_type __n, const value_type& __x);
846904
847905 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> = 0>
848 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, _InpIter __f, _InpIter __l);
906 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, _InpIter __f, _InpIter __l);
849907
850908# if _LIBCPP_STD_VER >= 23
851909 template <_ContainerCompatibleRange<_Tp> _Range>
852 _LIBCPP_HIDE_FROM_ABI iterator insert_range(const_iterator __position, _Range&& __range) {
910 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator
911 insert_range(const_iterator __position, _Range&& __range) {
853912 return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
854913 }
855914# endif
856915
857 _LIBCPP_HIDE_FROM_ABI void swap(list& __c)
916 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void swap(list& __c)
858917# if _LIBCPP_STD_VER >= 14
859918 _NOEXCEPT
860919# else
......@@ -863,72 +922,80 @@ public:
863922 {
864923 __base::swap(__c);
865924 }
866 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __base::clear(); }
925 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __base::clear(); }
867926
868 _LIBCPP_HIDE_FROM_ABI void pop_front();
869 _LIBCPP_HIDE_FROM_ABI void pop_back();
927 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void pop_front();
928 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void pop_back();
870929
871 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p);
872 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l);
930 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p);
931 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l);
873932
874 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n);
875 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n, const value_type& __x);
933 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n);
934 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n, const value_type& __x);
876935
877 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list& __c);
936 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list& __c);
878937# ifndef _LIBCPP_CXX03_LANG
879 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list&& __c) { splice(__p, __c); }
880 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list&& __c, const_iterator __i) { splice(__p, __c, __i); }
881 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l) {
938 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list&& __c) { splice(__p, __c); }
939 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list&& __c, const_iterator __i) {
940 splice(__p, __c, __i);
941 }
942 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void
943 splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l) {
882944 splice(__p, __c, __f, __l);
883945 }
884946# endif
885 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list& __c, const_iterator __i);
886 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
947 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list& __c, const_iterator __i);
948 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void
949 splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
887950
888 _LIBCPP_HIDE_FROM_ABI __remove_return_type remove(const value_type& __x);
951 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __remove_return_type remove(const value_type& __x);
889952 template <class _Pred>
890 _LIBCPP_HIDE_FROM_ABI __remove_return_type remove_if(_Pred __pred);
891 _LIBCPP_HIDE_FROM_ABI __remove_return_type unique() { return unique(__equal_to()); }
953 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __remove_return_type remove_if(_Pred __pred);
954 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __remove_return_type unique() { return unique(__equal_to()); }
892955 template <class _BinaryPred>
893 _LIBCPP_HIDE_FROM_ABI __remove_return_type unique(_BinaryPred __binary_pred);
894 _LIBCPP_HIDE_FROM_ABI void merge(list& __c);
956 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __remove_return_type unique(_BinaryPred __binary_pred);
957 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void merge(list& __c);
895958# ifndef _LIBCPP_CXX03_LANG
896 _LIBCPP_HIDE_FROM_ABI void merge(list&& __c) { merge(__c); }
959 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void merge(list&& __c) { merge(__c); }
897960
898961 template <class _Comp>
899 _LIBCPP_HIDE_FROM_ABI void merge(list&& __c, _Comp __comp) {
962 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void merge(list&& __c, _Comp __comp) {
900963 merge(__c, __comp);
901964 }
902965# endif
903966 template <class _Comp>
904 _LIBCPP_HIDE_FROM_ABI void merge(list& __c, _Comp __comp);
967 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void merge(list& __c, _Comp __comp);
905968
906 _LIBCPP_HIDE_FROM_ABI void sort();
969 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void sort();
907970 template <class _Comp>
908 _LIBCPP_HIDE_FROM_ABI void sort(_Comp __comp);
971 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void sort(_Comp __comp);
909972
910 _LIBCPP_HIDE_FROM_ABI void reverse() _NOEXCEPT;
973 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void reverse() _NOEXCEPT;
911974
912 _LIBCPP_HIDE_FROM_ABI bool __invariants() const;
975 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI bool __invariants() const;
913976
914977private:
915978 template <class _Iterator, class _Sentinel>
916 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iterator __f, _Sentinel __l);
979 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iterator __f, _Sentinel __l);
917980
918981 template <class _Iterator, class _Sentinel>
919 _LIBCPP_HIDE_FROM_ABI iterator __insert_with_sentinel(const_iterator __p, _Iterator __f, _Sentinel __l);
920
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);
924 _LIBCPP_HIDE_FROM_ABI iterator __iterator(size_type __n);
982 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator
983 __insert_with_sentinel(const_iterator __p, _Iterator __f, _Sentinel __l);
984
985 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI static void
986 __link_nodes(__base_pointer __p, __base_pointer __f, __base_pointer __l);
987 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void
988 __link_nodes_at_front(__base_pointer __f, __base_pointer __l);
989 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __link_nodes_at_back(__base_pointer __f, __base_pointer __l);
990 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI iterator __iterator(size_type __n);
925991 // TODO: Make this _LIBCPP_HIDE_FROM_ABI
926992 template <class _Comp>
927 _LIBCPP_HIDDEN static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
993 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDDEN static iterator
994 __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
928995
929 _LIBCPP_HIDE_FROM_ABI void __move_assign(list& __c, true_type)
996 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __move_assign(list& __c, true_type)
930997 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
931 _LIBCPP_HIDE_FROM_ABI void __move_assign(list& __c, false_type);
998 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void __move_assign(list& __c, false_type);
932999};
9331000
9341001# if _LIBCPP_STD_VER >= 17
......@@ -954,7 +1021,8 @@ list(from_range_t, _Range&&, _Alloc = _Alloc()) -> list<ranges::range_value_t<_R
9541021
9551022// Link in nodes [__f, __l] just prior to __p
9561023template <class _Tp, class _Alloc>
957inline void list<_Tp, _Alloc>::__link_nodes(__base_pointer __p, __base_pointer __f, __base_pointer __l) {
1024_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void
1025list<_Tp, _Alloc>::__link_nodes(__base_pointer __p, __base_pointer __f, __base_pointer __l) {
9581026 __p->__prev_->__next_ = __f;
9591027 __f->__prev_ = __p->__prev_;
9601028 __p->__prev_ = __l;
......@@ -963,7 +1031,8 @@ inline void list<_Tp, _Alloc>::__link_nodes(__base_pointer __p, __base_pointer _
9631031
9641032// Link in nodes [__f, __l] at the front of the list
9651033template <class _Tp, class _Alloc>
966inline void list<_Tp, _Alloc>::__link_nodes_at_front(__base_pointer __f, __base_pointer __l) {
1034_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void
1035list<_Tp, _Alloc>::__link_nodes_at_front(__base_pointer __f, __base_pointer __l) {
9671036 __f->__prev_ = __base::__end_as_link();
9681037 __l->__next_ = __base::__end_.__next_;
9691038 __l->__next_->__prev_ = __l;
......@@ -972,7 +1041,8 @@ inline void list<_Tp, _Alloc>::__link_nodes_at_front(__base_pointer __f, __base_
9721041
9731042// Link in nodes [__f, __l] at the back of the list
9741043template <class _Tp, class _Alloc>
975inline void list<_Tp, _Alloc>::__link_nodes_at_back(__base_pointer __f, __base_pointer __l) {
1044_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void
1045list<_Tp, _Alloc>::__link_nodes_at_back(__base_pointer __f, __base_pointer __l) {
9761046 __l->__next_ = __base::__end_as_link();
9771047 __f->__prev_ = __base::__end_.__prev_;
9781048 __f->__prev_->__next_ = __f;
......@@ -980,12 +1050,12 @@ inline void list<_Tp, _Alloc>::__link_nodes_at_back(__base_pointer __f, __base_p
9801050}
9811051
9821052template <class _Tp, class _Alloc>
983inline typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::__iterator(size_type __n) {
1053_LIBCPP_CONSTEXPR_SINCE_CXX26 inline typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::__iterator(size_type __n) {
9841054 return __n <= this->__size_ / 2 ? std::next(begin(), __n) : std::prev(end(), this->__size_ - __n);
9851055}
9861056
9871057template <class _Tp, class _Alloc>
988list<_Tp, _Alloc>::list(size_type __n) {
1058_LIBCPP_CONSTEXPR_SINCE_CXX26 list<_Tp, _Alloc>::list(size_type __n) {
9891059 for (; __n > 0; --__n)
9901060# ifndef _LIBCPP_CXX03_LANG
9911061 emplace_back();
......@@ -996,41 +1066,43 @@ list<_Tp, _Alloc>::list(size_type __n) {
9961066
9971067# if _LIBCPP_STD_VER >= 14
9981068template <class _Tp, class _Alloc>
999list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : __base(__a) {
1069_LIBCPP_CONSTEXPR_SINCE_CXX26 list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : __base(__a) {
10001070 for (; __n > 0; --__n)
10011071 emplace_back();
10021072}
10031073# endif
10041074
10051075template <class _Tp, class _Alloc>
1006list<_Tp, _Alloc>::list(size_type __n, const value_type& __x) {
1076_LIBCPP_CONSTEXPR_SINCE_CXX26 list<_Tp, _Alloc>::list(size_type __n, const value_type& __x) {
10071077 for (; __n > 0; --__n)
10081078 push_back(__x);
10091079}
10101080
10111081template <class _Tp, class _Alloc>
10121082template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> >
1013list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l) {
1083_LIBCPP_CONSTEXPR_SINCE_CXX26 list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l) {
10141084 for (; __f != __l; ++__f)
10151085 __emplace_back(*__f);
10161086}
10171087
10181088template <class _Tp, class _Alloc>
10191089template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> >
1020list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a) : __base(__a) {
1090_LIBCPP_CONSTEXPR_SINCE_CXX26 list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a)
1091 : __base(__a) {
10211092 for (; __f != __l; ++__f)
10221093 __emplace_back(*__f);
10231094}
10241095
10251096template <class _Tp, class _Alloc>
1026list<_Tp, _Alloc>::list(const list& __c)
1097_LIBCPP_CONSTEXPR_SINCE_CXX26 list<_Tp, _Alloc>::list(const list& __c)
10271098 : __base(__node_alloc_traits::select_on_container_copy_construction(__c.__node_alloc_)) {
10281099 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
10291100 push_back(*__i);
10301101}
10311102
10321103template <class _Tp, class _Alloc>
1033list<_Tp, _Alloc>::list(const list& __c, const __type_identity_t<allocator_type>& __a) : __base(__a) {
1104_LIBCPP_CONSTEXPR_SINCE_CXX26 list<_Tp, _Alloc>::list(const list& __c, const __type_identity_t<allocator_type>& __a)
1105 : __base(__a) {
10341106 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
10351107 push_back(*__i);
10361108}
......@@ -1038,25 +1110,28 @@ list<_Tp, _Alloc>::list(const list& __c, const __type_identity_t<allocator_type>
10381110# ifndef _LIBCPP_CXX03_LANG
10391111
10401112template <class _Tp, class _Alloc>
1041list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a) : __base(__a) {
1113_LIBCPP_CONSTEXPR_SINCE_CXX26 list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
1114 : __base(__a) {
10421115 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(), __e = __il.end(); __i != __e; ++__i)
10431116 push_back(*__i);
10441117}
10451118
10461119template <class _Tp, class _Alloc>
1047list<_Tp, _Alloc>::list(initializer_list<value_type> __il) {
1120_LIBCPP_CONSTEXPR_SINCE_CXX26 list<_Tp, _Alloc>::list(initializer_list<value_type> __il) {
10481121 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(), __e = __il.end(); __i != __e; ++__i)
10491122 push_back(*__i);
10501123}
10511124
10521125template <class _Tp, class _Alloc>
1053inline list<_Tp, _Alloc>::list(list&& __c) noexcept(is_nothrow_move_constructible<__node_allocator>::value)
1126_LIBCPP_CONSTEXPR_SINCE_CXX26 inline list<_Tp, _Alloc>::list(list&& __c) noexcept(
1127 is_nothrow_move_constructible<__node_allocator>::value)
10541128 : __base(std::move(__c.__node_alloc_)) {
10551129 splice(end(), __c);
10561130}
10571131
10581132template <class _Tp, class _Alloc>
1059inline list<_Tp, _Alloc>::list(list&& __c, const __type_identity_t<allocator_type>& __a) : __base(__a) {
1133_LIBCPP_CONSTEXPR_SINCE_CXX26 inline list<_Tp, _Alloc>::list(list&& __c, const __type_identity_t<allocator_type>& __a)
1134 : __base(__a) {
10601135 if (__a == __c.get_allocator())
10611136 splice(end(), __c);
10621137 else {
......@@ -1066,15 +1141,16 @@ inline list<_Tp, _Alloc>::list(list&& __c, const __type_identity_t<allocator_typ
10661141}
10671142
10681143template <class _Tp, class _Alloc>
1069inline list<_Tp, _Alloc>& list<_Tp, _Alloc>::operator=(list&& __c) noexcept(
1070 __node_alloc_traits::propagate_on_container_move_assignment::value &&
1071 is_nothrow_move_assignable<__node_allocator>::value) {
1144_LIBCPP_CONSTEXPR_SINCE_CXX26 inline list<_Tp, _Alloc>& list<_Tp, _Alloc>::operator=(list&& __c) noexcept(
1145 (__node_alloc_traits::propagate_on_container_move_assignment::value &&
1146 is_nothrow_move_assignable<__node_allocator>::value) ||
1147 allocator_traits<allocator_type>::is_always_equal::value) {
10721148 __move_assign(__c, integral_constant<bool, __node_alloc_traits::propagate_on_container_move_assignment::value>());
10731149 return *this;
10741150}
10751151
10761152template <class _Tp, class _Alloc>
1077void list<_Tp, _Alloc>::__move_assign(list& __c, false_type) {
1153_LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::__move_assign(list& __c, false_type) {
10781154 if (this->__node_alloc_ != __c.__node_alloc_) {
10791155 typedef move_iterator<iterator> _Ip;
10801156 assign(_Ip(__c.begin()), _Ip(__c.end()));
......@@ -1083,8 +1159,8 @@ void list<_Tp, _Alloc>::__move_assign(list& __c, false_type) {
10831159}
10841160
10851161template <class _Tp, class _Alloc>
1086void list<_Tp, _Alloc>::__move_assign(list& __c,
1087 true_type) noexcept(is_nothrow_move_assignable<__node_allocator>::value) {
1162_LIBCPP_CONSTEXPR_SINCE_CXX26 void
1163list<_Tp, _Alloc>::__move_assign(list& __c, true_type) noexcept(is_nothrow_move_assignable<__node_allocator>::value) {
10881164 clear();
10891165 __base::__move_assign_alloc(__c);
10901166 splice(end(), __c);
......@@ -1093,7 +1169,7 @@ void list<_Tp, _Alloc>::__move_assign(list& __c,
10931169# endif // _LIBCPP_CXX03_LANG
10941170
10951171template <class _Tp, class _Alloc>
1096inline list<_Tp, _Alloc>& list<_Tp, _Alloc>::operator=(const list& __c) {
1172_LIBCPP_CONSTEXPR_SINCE_CXX26 inline list<_Tp, _Alloc>& list<_Tp, _Alloc>::operator=(const list& __c) {
10971173 if (this != std::addressof(__c)) {
10981174 __base::__copy_assign_alloc(__c);
10991175 assign(__c.begin(), __c.end());
......@@ -1103,13 +1179,14 @@ inline list<_Tp, _Alloc>& list<_Tp, _Alloc>::operator=(const list& __c) {
11031179
11041180template <class _Tp, class _Alloc>
11051181template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> >
1106void list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l) {
1182_LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l) {
11071183 __assign_with_sentinel(__f, __l);
11081184}
11091185
11101186template <class _Tp, class _Alloc>
11111187template <class _Iterator, class _Sentinel>
1112_LIBCPP_HIDE_FROM_ABI void list<_Tp, _Alloc>::__assign_with_sentinel(_Iterator __f, _Sentinel __l) {
1188_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void
1189list<_Tp, _Alloc>::__assign_with_sentinel(_Iterator __f, _Sentinel __l) {
11131190 iterator __i = begin();
11141191 iterator __e = end();
11151192 for (; __f != __l && __i != __e; ++__f, (void)++__i)
......@@ -1121,7 +1198,7 @@ _LIBCPP_HIDE_FROM_ABI void list<_Tp, _Alloc>::__assign_with_sentinel(_Iterator _
11211198}
11221199
11231200template <class _Tp, class _Alloc>
1124void list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x) {
1201_LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x) {
11251202 iterator __i = begin();
11261203 iterator __e = end();
11271204 for (; __n > 0 && __i != __e; --__n, (void)++__i)
......@@ -1133,12 +1210,13 @@ void list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x) {
11331210}
11341211
11351212template <class _Tp, class _Alloc>
1136inline _Alloc list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT {
1213_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _Alloc list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT {
11371214 return allocator_type(this->__node_alloc_);
11381215}
11391216
11401217template <class _Tp, class _Alloc>
1141typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x) {
1218_LIBCPP_CONSTEXPR_SINCE_CXX26 typename list<_Tp, _Alloc>::iterator
1219list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x) {
11421220 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, __x);
11431221 __link_nodes(__p.__ptr_, __node->__as_link(), __node->__as_link());
11441222 ++this->__size_;
......@@ -1146,7 +1224,7 @@ typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::insert(const_iterator __
11461224}
11471225
11481226template <class _Tp, class _Alloc>
1149typename list<_Tp, _Alloc>::iterator
1227_LIBCPP_CONSTEXPR_SINCE_CXX26 typename list<_Tp, _Alloc>::iterator
11501228list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x) {
11511229 iterator __r(__p.__ptr_);
11521230 if (__n > 0) {
......@@ -1182,13 +1260,14 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _
11821260
11831261template <class _Tp, class _Alloc>
11841262template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> >
1185typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l) {
1263_LIBCPP_CONSTEXPR_SINCE_CXX26 typename list<_Tp, _Alloc>::iterator
1264list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l) {
11861265 return __insert_with_sentinel(__p, __f, __l);
11871266}
11881267
11891268template <class _Tp, class _Alloc>
11901269template <class _Iterator, class _Sentinel>
1191_LIBCPP_HIDE_FROM_ABI typename list<_Tp, _Alloc>::iterator
1270_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI typename list<_Tp, _Alloc>::iterator
11921271list<_Tp, _Alloc>::__insert_with_sentinel(const_iterator __p, _Iterator __f, _Sentinel __l) {
11931272 iterator __r(__p.__ptr_);
11941273 if (__f != __l) {
......@@ -1223,7 +1302,7 @@ list<_Tp, _Alloc>::__insert_with_sentinel(const_iterator __p, _Iterator __f, _Se
12231302}
12241303
12251304template <class _Tp, class _Alloc>
1226void list<_Tp, _Alloc>::push_front(const value_type& __x) {
1305_LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::push_front(const value_type& __x) {
12271306 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, __x);
12281307 __base_pointer __nl = __node->__as_link();
12291308 __link_nodes_at_front(__nl, __nl);
......@@ -1231,7 +1310,7 @@ void list<_Tp, _Alloc>::push_front(const value_type& __x) {
12311310}
12321311
12331312template <class _Tp, class _Alloc>
1234void list<_Tp, _Alloc>::push_back(const value_type& __x) {
1313_LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::push_back(const value_type& __x) {
12351314 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, __x);
12361315 __base_pointer __nl = __node->__as_link();
12371316 __link_nodes_at_back(__nl, __nl);
......@@ -1241,7 +1320,7 @@ void list<_Tp, _Alloc>::push_back(const value_type& __x) {
12411320# ifndef _LIBCPP_CXX03_LANG
12421321
12431322template <class _Tp, class _Alloc>
1244void list<_Tp, _Alloc>::push_front(value_type&& __x) {
1323_LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::push_front(value_type&& __x) {
12451324 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::move(__x));
12461325 __base_pointer __nl = __node->__as_link();
12471326 __link_nodes_at_front(__nl, __nl);
......@@ -1249,7 +1328,7 @@ void list<_Tp, _Alloc>::push_front(value_type&& __x) {
12491328}
12501329
12511330template <class _Tp, class _Alloc>
1252void list<_Tp, _Alloc>::push_back(value_type&& __x) {
1331_LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::push_back(value_type&& __x) {
12531332 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::move(__x));
12541333 __base_pointer __nl = __node->__as_link();
12551334 __link_nodes_at_back(__nl, __nl);
......@@ -1258,12 +1337,13 @@ void list<_Tp, _Alloc>::push_back(value_type&& __x) {
12581337
12591338template <class _Tp, class _Alloc>
12601339template <class... _Args>
1340_LIBCPP_CONSTEXPR_SINCE_CXX26
12611341# if _LIBCPP_STD_VER >= 17
1262typename list<_Tp, _Alloc>::reference
1342 typename list<_Tp, _Alloc>::reference
12631343# else
1264void
1344 void
12651345# endif
1266list<_Tp, _Alloc>::emplace_front(_Args&&... __args) {
1346 list<_Tp, _Alloc>::emplace_front(_Args&&... __args) {
12671347 __node_pointer __node =
12681348 this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::forward<_Args>(__args)...);
12691349 __base_pointer __nl = __node->__as_link();
......@@ -1276,12 +1356,13 @@ list<_Tp, _Alloc>::emplace_front(_Args&&... __args) {
12761356
12771357template <class _Tp, class _Alloc>
12781358template <class... _Args>
1359_LIBCPP_CONSTEXPR_SINCE_CXX26
12791360# if _LIBCPP_STD_VER >= 17
1280typename list<_Tp, _Alloc>::reference
1361 typename list<_Tp, _Alloc>::reference
12811362# else
1282void
1363 void
12831364# endif
1284list<_Tp, _Alloc>::emplace_back(_Args&&... __args) {
1365 list<_Tp, _Alloc>::emplace_back(_Args&&... __args) {
12851366 __node_pointer __node =
12861367 this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::forward<_Args>(__args)...);
12871368 __base_pointer __nl = __node->__as_link();
......@@ -1294,7 +1375,8 @@ list<_Tp, _Alloc>::emplace_back(_Args&&... __args) {
12941375
12951376template <class _Tp, class _Alloc>
12961377template <class... _Args>
1297typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) {
1378_LIBCPP_CONSTEXPR_SINCE_CXX26 typename list<_Tp, _Alloc>::iterator
1379list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) {
12981380 __node_pointer __node =
12991381 this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::forward<_Args>(__args)...);
13001382 __base_pointer __nl = __node->__as_link();
......@@ -1304,7 +1386,8 @@ typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::emplace(const_iterator _
13041386}
13051387
13061388template <class _Tp, class _Alloc>
1307typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) {
1389_LIBCPP_CONSTEXPR_SINCE_CXX26 typename list<_Tp, _Alloc>::iterator
1390list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) {
13081391 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::move(__x));
13091392 __base_pointer __nl = __node->__as_link();
13101393 __link_nodes(__p.__ptr_, __nl, __nl);
......@@ -1315,7 +1398,7 @@ typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::insert(const_iterator __
13151398# endif // _LIBCPP_CXX03_LANG
13161399
13171400template <class _Tp, class _Alloc>
1318void list<_Tp, _Alloc>::pop_front() {
1401_LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::pop_front() {
13191402 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::pop_front() called with empty list");
13201403 __base_pointer __n = __base::__end_.__next_;
13211404 __base::__unlink_nodes(__n, __n);
......@@ -1324,7 +1407,7 @@ void list<_Tp, _Alloc>::pop_front() {
13241407}
13251408
13261409template <class _Tp, class _Alloc>
1327void list<_Tp, _Alloc>::pop_back() {
1410_LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::pop_back() {
13281411 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::pop_back() called on an empty list");
13291412 __base_pointer __n = __base::__end_.__prev_;
13301413 __base::__unlink_nodes(__n, __n);
......@@ -1333,7 +1416,7 @@ void list<_Tp, _Alloc>::pop_back() {
13331416}
13341417
13351418template <class _Tp, class _Alloc>
1336typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::erase(const_iterator __p) {
1419_LIBCPP_CONSTEXPR_SINCE_CXX26 typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::erase(const_iterator __p) {
13371420 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p != end(), "list::erase(iterator) called with a non-dereferenceable iterator");
13381421 __base_pointer __n = __p.__ptr_;
13391422 __base_pointer __r = __n->__next_;
......@@ -1344,7 +1427,8 @@ typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::erase(const_iterator __p
13441427}
13451428
13461429template <class _Tp, class _Alloc>
1347typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) {
1430_LIBCPP_CONSTEXPR_SINCE_CXX26 typename list<_Tp, _Alloc>::iterator
1431list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) {
13481432 if (__f != __l) {
13491433 __base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
13501434 while (__f != __l) {
......@@ -1358,7 +1442,7 @@ typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::erase(const_iterator __f
13581442}
13591443
13601444template <class _Tp, class _Alloc>
1361void list<_Tp, _Alloc>::resize(size_type __n) {
1445_LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::resize(size_type __n) {
13621446 if (__n < this->__size_)
13631447 erase(__iterator(__n), end());
13641448 else if (__n > this->__size_) {
......@@ -1393,7 +1477,7 @@ void list<_Tp, _Alloc>::resize(size_type __n) {
13931477}
13941478
13951479template <class _Tp, class _Alloc>
1396void list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) {
1480_LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) {
13971481 if (__n < this->__size_)
13981482 erase(__iterator(__n), end());
13991483 else if (__n > this->__size_) {
......@@ -1429,7 +1513,7 @@ void list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) {
14291513}
14301514
14311515template <class _Tp, class _Alloc>
1432void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) {
1516_LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) {
14331517 _LIBCPP_ASSERT_VALID_INPUT_RANGE(
14341518 this != std::addressof(__c), "list::splice(iterator, list) called with this == &list");
14351519 if (!__c.empty()) {
......@@ -1443,7 +1527,7 @@ void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) {
14431527}
14441528
14451529template <class _Tp, class _Alloc>
1446void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) {
1530_LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) {
14471531 if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_) {
14481532 __base_pointer __f = __i.__ptr_;
14491533 __base::__unlink_nodes(__f, __f);
......@@ -1454,7 +1538,8 @@ void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i
14541538}
14551539
14561540template <class _Tp, class _Alloc>
1457void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l) {
1541_LIBCPP_CONSTEXPR_SINCE_CXX26 void
1542list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l) {
14581543 if (__f != __l) {
14591544 __base_pointer __first = __f.__ptr_;
14601545 --__l;
......@@ -1470,7 +1555,8 @@ void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f
14701555}
14711556
14721557template <class _Tp, class _Alloc>
1473typename list<_Tp, _Alloc>::__remove_return_type list<_Tp, _Alloc>::remove(const value_type& __x) {
1558_LIBCPP_CONSTEXPR_SINCE_CXX26 typename list<_Tp, _Alloc>::__remove_return_type
1559list<_Tp, _Alloc>::remove(const value_type& __x) {
14741560 list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
14751561 for (const_iterator __i = begin(), __e = end(); __i != __e;) {
14761562 if (*__i == __x) {
......@@ -1490,7 +1576,8 @@ typename list<_Tp, _Alloc>::__remove_return_type list<_Tp, _Alloc>::remove(const
14901576
14911577template <class _Tp, class _Alloc>
14921578template <class _Pred>
1493typename list<_Tp, _Alloc>::__remove_return_type list<_Tp, _Alloc>::remove_if(_Pred __pred) {
1579_LIBCPP_CONSTEXPR_SINCE_CXX26 typename list<_Tp, _Alloc>::__remove_return_type
1580list<_Tp, _Alloc>::remove_if(_Pred __pred) {
14941581 list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
14951582 for (iterator __i = begin(), __e = end(); __i != __e;) {
14961583 if (__pred(*__i)) {
......@@ -1510,7 +1597,8 @@ typename list<_Tp, _Alloc>::__remove_return_type list<_Tp, _Alloc>::remove_if(_P
15101597
15111598template <class _Tp, class _Alloc>
15121599template <class _BinaryPred>
1513typename list<_Tp, _Alloc>::__remove_return_type list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred) {
1600_LIBCPP_CONSTEXPR_SINCE_CXX26 typename list<_Tp, _Alloc>::__remove_return_type
1601list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred) {
15141602 list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
15151603 for (iterator __i = begin(), __e = end(); __i != __e;) {
15161604 iterator __j = std::next(__i);
......@@ -1526,13 +1614,13 @@ typename list<_Tp, _Alloc>::__remove_return_type list<_Tp, _Alloc>::unique(_Bina
15261614}
15271615
15281616template <class _Tp, class _Alloc>
1529inline void list<_Tp, _Alloc>::merge(list& __c) {
1617_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void list<_Tp, _Alloc>::merge(list& __c) {
15301618 merge(__c, __less<>());
15311619}
15321620
15331621template <class _Tp, class _Alloc>
15341622template <class _Comp>
1535void list<_Tp, _Alloc>::merge(list& __c, _Comp __comp) {
1623_LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::merge(list& __c, _Comp __comp) {
15361624 if (this != std::addressof(__c)) {
15371625 iterator __f1 = begin();
15381626 iterator __e1 = end();
......@@ -1561,19 +1649,19 @@ void list<_Tp, _Alloc>::merge(list& __c, _Comp __comp) {
15611649}
15621650
15631651template <class _Tp, class _Alloc>
1564inline void list<_Tp, _Alloc>::sort() {
1652_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void list<_Tp, _Alloc>::sort() {
15651653 sort(__less<>());
15661654}
15671655
15681656template <class _Tp, class _Alloc>
15691657template <class _Comp>
1570inline void list<_Tp, _Alloc>::sort(_Comp __comp) {
1658_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void list<_Tp, _Alloc>::sort(_Comp __comp) {
15711659 __sort(begin(), end(), this->__size_, __comp);
15721660}
15731661
15741662template <class _Tp, class _Alloc>
15751663template <class _Comp>
1576typename list<_Tp, _Alloc>::iterator
1664_LIBCPP_CONSTEXPR_SINCE_CXX26 typename list<_Tp, _Alloc>::iterator
15771665list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp) {
15781666 switch (__n) {
15791667 case 0:
......@@ -1627,7 +1715,7 @@ list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __
16271715}
16281716
16291717template <class _Tp, class _Alloc>
1630void list<_Tp, _Alloc>::reverse() _NOEXCEPT {
1718_LIBCPP_CONSTEXPR_SINCE_CXX26 void list<_Tp, _Alloc>::reverse() _NOEXCEPT {
16311719 if (this->__size_ > 1) {
16321720 iterator __e = end();
16331721 for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;) {
......@@ -1639,46 +1727,52 @@ void list<_Tp, _Alloc>::reverse() _NOEXCEPT {
16391727}
16401728
16411729template <class _Tp, class _Alloc>
1642bool list<_Tp, _Alloc>::__invariants() const {
1730_LIBCPP_CONSTEXPR_SINCE_CXX26 bool list<_Tp, _Alloc>::__invariants() const {
16431731 return size() == std::distance(begin(), end());
16441732}
16451733
16461734template <class _Tp, class _Alloc>
1647inline _LIBCPP_HIDE_FROM_ABI bool operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
1735_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI bool
1736operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
16481737 return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
16491738}
16501739
16511740# if _LIBCPP_STD_VER <= 17
16521741
16531742template <class _Tp, class _Alloc>
1654inline _LIBCPP_HIDE_FROM_ABI bool operator<(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
1743_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI bool
1744operator<(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
16551745 return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
16561746}
16571747
16581748template <class _Tp, class _Alloc>
1659inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
1749_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI bool
1750operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
16601751 return !(__x == __y);
16611752}
16621753
16631754template <class _Tp, class _Alloc>
1664inline _LIBCPP_HIDE_FROM_ABI bool operator>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
1755_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI bool
1756operator>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
16651757 return __y < __x;
16661758}
16671759
16681760template <class _Tp, class _Alloc>
1669inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
1761_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI bool
1762operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
16701763 return !(__x < __y);
16711764}
16721765
16731766template <class _Tp, class _Alloc>
1674inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
1767_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI bool
1768operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
16751769 return !(__y < __x);
16761770}
16771771
16781772# else // _LIBCPP_STD_VER <= 17
16791773
16801774template <class _Tp, class _Allocator>
1681_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Tp>
1775_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Tp>
16821776operator<=>(const list<_Tp, _Allocator>& __x, const list<_Tp, _Allocator>& __y) {
16831777 return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
16841778}
......@@ -1686,22 +1780,22 @@ operator<=>(const list<_Tp, _Allocator>& __x, const list<_Tp, _Allocator>& __y)
16861780# endif // _LIBCPP_STD_VER <= 17
16871781
16881782template <class _Tp, class _Alloc>
1689inline _LIBCPP_HIDE_FROM_ABI void swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
1783_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI void swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
16901784 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
16911785 __x.swap(__y);
16921786}
16931787
16941788# if _LIBCPP_STD_VER >= 20
16951789template <class _Tp, class _Allocator, class _Predicate>
1696inline _LIBCPP_HIDE_FROM_ABI typename list<_Tp, _Allocator>::size_type
1790_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI typename list<_Tp, _Allocator>::size_type
16971791erase_if(list<_Tp, _Allocator>& __c, _Predicate __pred) {
16981792 return __c.remove_if(__pred);
16991793}
17001794
17011795template <class _Tp, class _Allocator, class _Up>
1702inline _LIBCPP_HIDE_FROM_ABI typename list<_Tp, _Allocator>::size_type
1796_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI typename list<_Tp, _Allocator>::size_type
17031797erase(list<_Tp, _Allocator>& __c, const _Up& __v) {
1704 return std::erase_if(__c, [&](auto& __elem) { return __elem == __v; });
1798 return std::erase_if(__c, [&](const auto& __elem) -> bool { return __elem == __v; });
17051799}
17061800
17071801template <>
......@@ -1722,6 +1816,8 @@ struct __container_traits<list<_Tp, _Allocator> > {
17221816 // - If an exception is thrown by an insert() or emplace() function while inserting a single element, that
17231817 // function has no effects.
17241818 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
1819
1820 static _LIBCPP_CONSTEXPR const bool __reservable = false;
17251821};
17261822
17271823_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/locale+7-3487
......@@ -194,3501 +194,20 @@ template <class charT> class messages_byname;
194194
195195# if _LIBCPP_HAS_LOCALIZATION
196196
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>
208197# 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>
198# include <__locale_dir/messages.h>
199# include <__locale_dir/money.h>
200# include <__locale_dir/num.h>
201# include <__locale_dir/time.h>
202# include <__locale_dir/wbuffer_convert.h>
203# include <__locale_dir/wstring_convert.h>
217204# include <ios>
218# include <limits>
219# include <streambuf>
220205# include <version>
221206
222// TODO: Properly qualify calls now that the locale base API defines functions instead of macros
223// NOLINTBEGIN(libcpp-robust-against-adl)
224
225# if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
226// Most unix variants have catopen. These are the specific ones that don't.
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
235# endif
236
237207# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
238208# pragma GCC system_header
239209# endif
240210
241_LIBCPP_PUSH_MACROS
242# include <__undef_macros>
243
244_LIBCPP_BEGIN_NAMESPACE_STD
245
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()
252// Get the C locale object
253_LIBCPP_EXPORTED_FROM_ABI __locale::__locale_t __cloc();
254# define __cloc_defined
255# endif
256
257// __scan_keyword
258// Scans [__b, __e) until a match is found in the basic_strings range
259// [__kb, __ke) or until it can be shown that there is no match in [__kb, __ke).
260// __b will be incremented (visibly), consuming CharT until a match is found
261// or proved to not exist. A keyword may be "", in which will match anything.
262// If one keyword is a prefix of another, and the next CharT in the input
263// might match another keyword, the algorithm will attempt to find the longest
264// matching keyword. If the longer matching keyword ends up not matching, then
265// no keyword match is found. If no keyword match is found, __ke is returned
266// and failbit is set in __err.
267// Else an iterator pointing to the matching keyword is found. If more than
268// one keyword matches, an iterator to the first matching keyword is returned.
269// If on exit __b == __e, eofbit is set in __err. If __case_sensitive is false,
270// __ct is used to force to lower case before comparing characters.
271// Examples:
272// Keywords: "a", "abb"
273// If the input is "a", the first keyword matches and eofbit is set.
274// If the input is "abc", no match is found and "ab" are consumed.
275template <class _InputIterator, class _ForwardIterator, class _Ctype>
276_LIBCPP_HIDE_FROM_ABI _ForwardIterator __scan_keyword(
277 _InputIterator& __b,
278 _InputIterator __e,
279 _ForwardIterator __kb,
280 _ForwardIterator __ke,
281 const _Ctype& __ct,
282 ios_base::iostate& __err,
283 bool __case_sensitive = true) {
284 typedef typename iterator_traits<_InputIterator>::value_type _CharT;
285 size_t __nkw = static_cast<size_t>(std::distance(__kb, __ke));
286 const unsigned char __doesnt_match = '\0';
287 const unsigned char __might_match = '\1';
288 const unsigned char __does_match = '\2';
289 unsigned char __statbuf[100];
290 unsigned char* __status = __statbuf;
291 unique_ptr<unsigned char, void (*)(void*)> __stat_hold(nullptr, free);
292 if (__nkw > sizeof(__statbuf)) {
293 __status = (unsigned char*)malloc(__nkw);
294 if (__status == nullptr)
295 __throw_bad_alloc();
296 __stat_hold.reset(__status);
297 }
298 size_t __n_might_match = __nkw; // At this point, any keyword might match
299 size_t __n_does_match = 0; // but none of them definitely do
300 // Initialize all statuses to __might_match, except for "" keywords are __does_match
301 unsigned char* __st = __status;
302 for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void)++__st) {
303 if (!__ky->empty())
304 *__st = __might_match;
305 else {
306 *__st = __does_match;
307 --__n_might_match;
308 ++__n_does_match;
309 }
310 }
311 // While there might be a match, test keywords against the next CharT
312 for (size_t __indx = 0; __b != __e && __n_might_match > 0; ++__indx) {
313 // Peek at the next CharT but don't consume it
314 _CharT __c = *__b;
315 if (!__case_sensitive)
316 __c = __ct.toupper(__c);
317 bool __consume = false;
318 // For each keyword which might match, see if the __indx character is __c
319 // If a match if found, consume __c
320 // If a match is found, and that is the last character in the keyword,
321 // then that keyword matches.
322 // If the keyword doesn't match this character, then change the keyword
323 // to doesn't match
324 __st = __status;
325 for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void)++__st) {
326 if (*__st == __might_match) {
327 _CharT __kc = (*__ky)[__indx];
328 if (!__case_sensitive)
329 __kc = __ct.toupper(__kc);
330 if (__c == __kc) {
331 __consume = true;
332 if (__ky->size() == __indx + 1) {
333 *__st = __does_match;
334 --__n_might_match;
335 ++__n_does_match;
336 }
337 } else {
338 *__st = __doesnt_match;
339 --__n_might_match;
340 }
341 }
342 }
343 // consume if we matched a character
344 if (__consume) {
345 ++__b;
346 // If we consumed a character and there might be a matched keyword that
347 // was marked matched on a previous iteration, then such keywords
348 // which are now marked as not matching.
349 if (__n_might_match + __n_does_match > 1) {
350 __st = __status;
351 for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void)++__st) {
352 if (*__st == __does_match && __ky->size() != __indx + 1) {
353 *__st = __doesnt_match;
354 --__n_does_match;
355 }
356 }
357 }
358 }
359 }
360 // We've exited the loop because we hit eof and/or we have no more "might matches".
361 if (__b == __e)
362 __err |= ios_base::eofbit;
363 // Return the first matching result
364 for (__st = __status; __kb != __ke; ++__kb, (void)++__st)
365 if (*__st == __does_match)
366 break;
367 if (__kb == __ke)
368 __err |= ios_base::failbit;
369 return __kb;
370}
371
372struct _LIBCPP_EXPORTED_FROM_ABI __num_get_base {
373 static const int __num_get_buf_sz = 40;
374
375 static int __get_base(ios_base&);
376 static const char __src[33]; // "0123456789abcdefABCDEFxX+-pPiInN"
377 // count of leading characters in __src used for parsing integers ("012..X+-")
378 static const size_t __int_chr_cnt = 26;
379 // count of leading characters in __src used for parsing floating-point values ("012..-pP")
380 static const size_t __fp_chr_cnt = 28;
381};
382
383_LIBCPP_EXPORTED_FROM_ABI void
384__check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end, ios_base::iostate& __err);
385
386template <class _CharT>
387struct __num_get : protected __num_get_base {
388 static string __stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, _CharT& __thousands_sep);
389
390 static int __stage2_float_loop(
391 _CharT __ct,
392 bool& __in_units,
393 char& __exp,
394 char* __a,
395 char*& __a_end,
396 _CharT __decimal_point,
397 _CharT __thousands_sep,
398 const string& __grouping,
399 unsigned* __g,
400 unsigned*& __g_end,
401 unsigned& __dc,
402 _CharT* __atoms);
403# ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
404 static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep);
405 static int __stage2_int_loop(
406 _CharT __ct,
407 int __base,
408 char* __a,
409 char*& __a_end,
410 unsigned& __dc,
411 _CharT __thousands_sep,
412 const string& __grouping,
413 unsigned* __g,
414 unsigned*& __g_end,
415 _CharT* __atoms);
416
417# else
418 static string __stage2_int_prep(ios_base& __iob, _CharT& __thousands_sep) {
419 locale __loc = __iob.getloc();
420 const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
421 __thousands_sep = __np.thousands_sep();
422 return __np.grouping();
423 }
424
425 const _CharT* __do_widen(ios_base& __iob, _CharT* __atoms) const { return __do_widen_p(__iob, __atoms); }
426
427 static int __stage2_int_loop(
428 _CharT __ct,
429 int __base,
430 char* __a,
431 char*& __a_end,
432 unsigned& __dc,
433 _CharT __thousands_sep,
434 const string& __grouping,
435 unsigned* __g,
436 unsigned*& __g_end,
437 const _CharT* __atoms);
438
439private:
440 template <typename _Tp>
441 const _Tp* __do_widen_p(ios_base& __iob, _Tp* __atoms) const {
442 locale __loc = __iob.getloc();
443 use_facet<ctype<_Tp> >(__loc).widen(__src, __src + __int_chr_cnt, __atoms);
444 return __atoms;
445 }
446
447 const char* __do_widen_p(ios_base& __iob, char* __atoms) const {
448 (void)__iob;
449 (void)__atoms;
450 return __src;
451 }
452# endif
453};
454
455# ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
456template <class _CharT>
457string __num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep) {
458 locale __loc = __iob.getloc();
459 std::use_facet<ctype<_CharT> >(__loc).widen(__src, __src + __int_chr_cnt, __atoms);
460 const numpunct<_CharT>& __np = std::use_facet<numpunct<_CharT> >(__loc);
461 __thousands_sep = __np.thousands_sep();
462 return __np.grouping();
463}
464# endif
465
466template <class _CharT>
467string __num_get<_CharT>::__stage2_float_prep(
468 ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, _CharT& __thousands_sep) {
469 locale __loc = __iob.getloc();
470 std::use_facet<ctype<_CharT> >(__loc).widen(__src, __src + __fp_chr_cnt, __atoms);
471 const numpunct<_CharT>& __np = std::use_facet<numpunct<_CharT> >(__loc);
472 __decimal_point = __np.decimal_point();
473 __thousands_sep = __np.thousands_sep();
474 return __np.grouping();
475}
476
477template <class _CharT>
478int
479# ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
480__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
481 unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
482 unsigned* __g, unsigned*& __g_end, _CharT* __atoms)
483# else
484__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
485 unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
486 unsigned* __g, unsigned*& __g_end, const _CharT* __atoms)
487
488# endif
489{
490 if (__a_end == __a && (__ct == __atoms[24] || __ct == __atoms[25])) {
491 *__a_end++ = __ct == __atoms[24] ? '+' : '-';
492 __dc = 0;
493 return 0;
494 }
495 if (__grouping.size() != 0 && __ct == __thousands_sep) {
496 if (__g_end - __g < __num_get_buf_sz) {
497 *__g_end++ = __dc;
498 __dc = 0;
499 }
500 return 0;
501 }
502 ptrdiff_t __f = std::find(__atoms, __atoms + __int_chr_cnt, __ct) - __atoms;
503 if (__f >= 24)
504 return -1;
505 switch (__base) {
506 case 8:
507 case 10:
508 if (__f >= __base)
509 return -1;
510 break;
511 case 16:
512 if (__f < 22)
513 break;
514 if (__a_end != __a && __a_end - __a <= 2 && __a_end[-1] == '0') {
515 __dc = 0;
516 *__a_end++ = __src[__f];
517 return 0;
518 }
519 return -1;
520 }
521 *__a_end++ = __src[__f];
522 ++__dc;
523 return 0;
524}
525
526template <class _CharT>
527int __num_get<_CharT>::__stage2_float_loop(
528 _CharT __ct,
529 bool& __in_units,
530 char& __exp,
531 char* __a,
532 char*& __a_end,
533 _CharT __decimal_point,
534 _CharT __thousands_sep,
535 const string& __grouping,
536 unsigned* __g,
537 unsigned*& __g_end,
538 unsigned& __dc,
539 _CharT* __atoms) {
540 if (__ct == __decimal_point) {
541 if (!__in_units)
542 return -1;
543 __in_units = false;
544 *__a_end++ = '.';
545 if (__grouping.size() != 0 && __g_end - __g < __num_get_buf_sz)
546 *__g_end++ = __dc;
547 return 0;
548 }
549 if (__ct == __thousands_sep && __grouping.size() != 0) {
550 if (!__in_units)
551 return -1;
552 if (__g_end - __g < __num_get_buf_sz) {
553 *__g_end++ = __dc;
554 __dc = 0;
555 }
556 return 0;
557 }
558 ptrdiff_t __f = std::find(__atoms, __atoms + __num_get_base::__fp_chr_cnt, __ct) - __atoms;
559 if (__f >= static_cast<ptrdiff_t>(__num_get_base::__fp_chr_cnt))
560 return -1;
561 char __x = __src[__f];
562 if (__x == '-' || __x == '+') {
563 if (__a_end == __a || (std::toupper(__a_end[-1]) == std::toupper(__exp))) {
564 *__a_end++ = __x;
565 return 0;
566 }
567 return -1;
568 }
569 if (__x == 'x' || __x == 'X')
570 __exp = 'P';
571 else if (std::toupper(__x) == __exp) {
572 __exp = std::tolower(__exp);
573 if (__in_units) {
574 __in_units = false;
575 if (__grouping.size() != 0 && __g_end - __g < __num_get_buf_sz)
576 *__g_end++ = __dc;
577 }
578 }
579 *__a_end++ = __x;
580 if (__f >= 22)
581 return 0;
582 ++__dc;
583 return 0;
584}
585
586extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<char>;
587# if _LIBCPP_HAS_WIDE_CHARACTERS
588extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<wchar_t>;
589# endif
590
591template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
592class _LIBCPP_TEMPLATE_VIS num_get : public locale::facet, private __num_get<_CharT> {
593public:
594 typedef _CharT char_type;
595 typedef _InputIterator iter_type;
596
597 _LIBCPP_HIDE_FROM_ABI explicit num_get(size_t __refs = 0) : locale::facet(__refs) {}
598
599 _LIBCPP_HIDE_FROM_ABI iter_type
600 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, bool& __v) const {
601 return do_get(__b, __e, __iob, __err, __v);
602 }
603
604 _LIBCPP_HIDE_FROM_ABI iter_type
605 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long& __v) const {
606 return do_get(__b, __e, __iob, __err, __v);
607 }
608
609 _LIBCPP_HIDE_FROM_ABI iter_type
610 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long long& __v) const {
611 return do_get(__b, __e, __iob, __err, __v);
612 }
613
614 _LIBCPP_HIDE_FROM_ABI iter_type
615 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned short& __v) const {
616 return do_get(__b, __e, __iob, __err, __v);
617 }
618
619 _LIBCPP_HIDE_FROM_ABI iter_type
620 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned int& __v) const {
621 return do_get(__b, __e, __iob, __err, __v);
622 }
623
624 _LIBCPP_HIDE_FROM_ABI iter_type
625 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long& __v) const {
626 return do_get(__b, __e, __iob, __err, __v);
627 }
628
629 _LIBCPP_HIDE_FROM_ABI iter_type
630 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long long& __v) const {
631 return do_get(__b, __e, __iob, __err, __v);
632 }
633
634 _LIBCPP_HIDE_FROM_ABI iter_type
635 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, float& __v) const {
636 return do_get(__b, __e, __iob, __err, __v);
637 }
638
639 _LIBCPP_HIDE_FROM_ABI iter_type
640 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, double& __v) const {
641 return do_get(__b, __e, __iob, __err, __v);
642 }
643
644 _LIBCPP_HIDE_FROM_ABI iter_type
645 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long double& __v) const {
646 return do_get(__b, __e, __iob, __err, __v);
647 }
648
649 _LIBCPP_HIDE_FROM_ABI iter_type
650 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, void*& __v) const {
651 return do_get(__b, __e, __iob, __err, __v);
652 }
653
654 static locale::id id;
655
656protected:
657 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~num_get() override {}
658
659 template <class _Fp>
660 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS iter_type
661 __do_get_floating_point(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Fp& __v) const;
662
663 template <class _Signed>
664 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS iter_type
665 __do_get_signed(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Signed& __v) const;
666
667 template <class _Unsigned>
668 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS iter_type
669 __do_get_unsigned(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Unsigned& __v) const;
670
671 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, bool& __v) const;
672
673 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long& __v) const {
674 return this->__do_get_signed(__b, __e, __iob, __err, __v);
675 }
676
677 virtual iter_type
678 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long long& __v) const {
679 return this->__do_get_signed(__b, __e, __iob, __err, __v);
680 }
681
682 virtual iter_type
683 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned short& __v) const {
684 return this->__do_get_unsigned(__b, __e, __iob, __err, __v);
685 }
686
687 virtual iter_type
688 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned int& __v) const {
689 return this->__do_get_unsigned(__b, __e, __iob, __err, __v);
690 }
691
692 virtual iter_type
693 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long& __v) const {
694 return this->__do_get_unsigned(__b, __e, __iob, __err, __v);
695 }
696
697 virtual iter_type
698 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long long& __v) const {
699 return this->__do_get_unsigned(__b, __e, __iob, __err, __v);
700 }
701
702 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, float& __v) const {
703 return this->__do_get_floating_point(__b, __e, __iob, __err, __v);
704 }
705
706 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, double& __v) const {
707 return this->__do_get_floating_point(__b, __e, __iob, __err, __v);
708 }
709
710 virtual iter_type
711 do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long double& __v) const {
712 return this->__do_get_floating_point(__b, __e, __iob, __err, __v);
713 }
714
715 virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, void*& __v) const;
716};
717
718template <class _CharT, class _InputIterator>
719locale::id num_get<_CharT, _InputIterator>::id;
720
721template <class _Tp>
722_LIBCPP_HIDE_FROM_ABI _Tp
723__num_get_signed_integral(const char* __a, const char* __a_end, ios_base::iostate& __err, int __base) {
724 if (__a != __a_end) {
725 __libcpp_remove_reference_t<decltype(errno)> __save_errno = errno;
726 errno = 0;
727 char* __p2;
728 long long __ll = __locale::__strtoll(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
729 __libcpp_remove_reference_t<decltype(errno)> __current_errno = errno;
730 if (__current_errno == 0)
731 errno = __save_errno;
732 if (__p2 != __a_end) {
733 __err = ios_base::failbit;
734 return 0;
735 } else if (__current_errno == ERANGE || __ll < numeric_limits<_Tp>::min() || numeric_limits<_Tp>::max() < __ll) {
736 __err = ios_base::failbit;
737 if (__ll > 0)
738 return numeric_limits<_Tp>::max();
739 else
740 return numeric_limits<_Tp>::min();
741 }
742 return static_cast<_Tp>(__ll);
743 }
744 __err = ios_base::failbit;
745 return 0;
746}
747
748template <class _Tp>
749_LIBCPP_HIDE_FROM_ABI _Tp
750__num_get_unsigned_integral(const char* __a, const char* __a_end, ios_base::iostate& __err, int __base) {
751 if (__a != __a_end) {
752 const bool __negate = *__a == '-';
753 if (__negate && ++__a == __a_end) {
754 __err = ios_base::failbit;
755 return 0;
756 }
757 __libcpp_remove_reference_t<decltype(errno)> __save_errno = errno;
758 errno = 0;
759 char* __p2;
760 unsigned long long __ll = __locale::__strtoull(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
761 __libcpp_remove_reference_t<decltype(errno)> __current_errno = errno;
762 if (__current_errno == 0)
763 errno = __save_errno;
764 if (__p2 != __a_end) {
765 __err = ios_base::failbit;
766 return 0;
767 } else if (__current_errno == ERANGE || numeric_limits<_Tp>::max() < __ll) {
768 __err = ios_base::failbit;
769 return numeric_limits<_Tp>::max();
770 }
771 _Tp __res = static_cast<_Tp>(__ll);
772 if (__negate)
773 __res = -__res;
774 return __res;
775 }
776 __err = ios_base::failbit;
777 return 0;
778}
779
780template <class _Tp>
781_LIBCPP_HIDE_FROM_ABI _Tp __do_strtod(const char* __a, char** __p2);
782
783template <>
784inline _LIBCPP_HIDE_FROM_ABI float __do_strtod<float>(const char* __a, char** __p2) {
785 return __locale::__strtof(__a, __p2, _LIBCPP_GET_C_LOCALE);
786}
787
788template <>
789inline _LIBCPP_HIDE_FROM_ABI double __do_strtod<double>(const char* __a, char** __p2) {
790 return __locale::__strtod(__a, __p2, _LIBCPP_GET_C_LOCALE);
791}
792
793template <>
794inline _LIBCPP_HIDE_FROM_ABI long double __do_strtod<long double>(const char* __a, char** __p2) {
795 return __locale::__strtold(__a, __p2, _LIBCPP_GET_C_LOCALE);
796}
797
798template <class _Tp>
799_LIBCPP_HIDE_FROM_ABI _Tp __num_get_float(const char* __a, const char* __a_end, ios_base::iostate& __err) {
800 if (__a != __a_end) {
801 __libcpp_remove_reference_t<decltype(errno)> __save_errno = errno;
802 errno = 0;
803 char* __p2;
804 _Tp __ld = std::__do_strtod<_Tp>(__a, &__p2);
805 __libcpp_remove_reference_t<decltype(errno)> __current_errno = errno;
806 if (__current_errno == 0)
807 errno = __save_errno;
808 if (__p2 != __a_end) {
809 __err = ios_base::failbit;
810 return 0;
811 } else if (__current_errno == ERANGE)
812 __err = ios_base::failbit;
813 return __ld;
814 }
815 __err = ios_base::failbit;
816 return 0;
817}
818
819template <class _CharT, class _InputIterator>
820_InputIterator num_get<_CharT, _InputIterator>::do_get(
821 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, bool& __v) const {
822 if ((__iob.flags() & ios_base::boolalpha) == 0) {
823 long __lv = -1;
824 __b = do_get(__b, __e, __iob, __err, __lv);
825 switch (__lv) {
826 case 0:
827 __v = false;
828 break;
829 case 1:
830 __v = true;
831 break;
832 default:
833 __v = true;
834 __err = ios_base::failbit;
835 break;
836 }
837 return __b;
838 }
839 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__iob.getloc());
840 const numpunct<_CharT>& __np = std::use_facet<numpunct<_CharT> >(__iob.getloc());
841 typedef typename numpunct<_CharT>::string_type string_type;
842 const string_type __names[2] = {__np.truename(), __np.falsename()};
843 const string_type* __i = std::__scan_keyword(__b, __e, __names, __names + 2, __ct, __err);
844 __v = __i == __names;
845 return __b;
846}
847
848// signed
849
850template <class _CharT, class _InputIterator>
851template <class _Signed>
852_InputIterator num_get<_CharT, _InputIterator>::__do_get_signed(
853 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Signed& __v) const {
854 // Stage 1
855 int __base = this->__get_base(__iob);
856 // Stage 2
857 char_type __thousands_sep;
858 const int __atoms_size = __num_get_base::__int_chr_cnt;
859# ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
860 char_type __atoms1[__atoms_size];
861 const char_type* __atoms = this->__do_widen(__iob, __atoms1);
862 string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
863# else
864 char_type __atoms[__atoms_size];
865 string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
866# endif
867 string __buf;
868 __buf.resize(__buf.capacity());
869 char* __a = &__buf[0];
870 char* __a_end = __a;
871 unsigned __g[__num_get_base::__num_get_buf_sz];
872 unsigned* __g_end = __g;
873 unsigned __dc = 0;
874 for (; __b != __e; ++__b) {
875 if (__a_end == __a + __buf.size()) {
876 size_t __tmp = __buf.size();
877 __buf.resize(2 * __buf.size());
878 __buf.resize(__buf.capacity());
879 __a = &__buf[0];
880 __a_end = __a + __tmp;
881 }
882 if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms))
883 break;
884 }
885 if (__grouping.size() != 0 && __g_end - __g < __num_get_base::__num_get_buf_sz)
886 *__g_end++ = __dc;
887 // Stage 3
888 __v = std::__num_get_signed_integral<_Signed>(__a, __a_end, __err, __base);
889 // Digit grouping checked
890 __check_grouping(__grouping, __g, __g_end, __err);
891 // EOF checked
892 if (__b == __e)
893 __err |= ios_base::eofbit;
894 return __b;
895}
896
897// unsigned
898
899template <class _CharT, class _InputIterator>
900template <class _Unsigned>
901_InputIterator num_get<_CharT, _InputIterator>::__do_get_unsigned(
902 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Unsigned& __v) const {
903 // Stage 1
904 int __base = this->__get_base(__iob);
905 // Stage 2
906 char_type __thousands_sep;
907 const int __atoms_size = __num_get_base::__int_chr_cnt;
908# ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
909 char_type __atoms1[__atoms_size];
910 const char_type* __atoms = this->__do_widen(__iob, __atoms1);
911 string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
912# else
913 char_type __atoms[__atoms_size];
914 string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
915# endif
916 string __buf;
917 __buf.resize(__buf.capacity());
918 char* __a = &__buf[0];
919 char* __a_end = __a;
920 unsigned __g[__num_get_base::__num_get_buf_sz];
921 unsigned* __g_end = __g;
922 unsigned __dc = 0;
923 for (; __b != __e; ++__b) {
924 if (__a_end == __a + __buf.size()) {
925 size_t __tmp = __buf.size();
926 __buf.resize(2 * __buf.size());
927 __buf.resize(__buf.capacity());
928 __a = &__buf[0];
929 __a_end = __a + __tmp;
930 }
931 if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms))
932 break;
933 }
934 if (__grouping.size() != 0 && __g_end - __g < __num_get_base::__num_get_buf_sz)
935 *__g_end++ = __dc;
936 // Stage 3
937 __v = std::__num_get_unsigned_integral<_Unsigned>(__a, __a_end, __err, __base);
938 // Digit grouping checked
939 __check_grouping(__grouping, __g, __g_end, __err);
940 // EOF checked
941 if (__b == __e)
942 __err |= ios_base::eofbit;
943 return __b;
944}
945
946// floating point
947
948template <class _CharT, class _InputIterator>
949template <class _Fp>
950_InputIterator num_get<_CharT, _InputIterator>::__do_get_floating_point(
951 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Fp& __v) const {
952 // Stage 1, nothing to do
953 // Stage 2
954 char_type __atoms[__num_get_base::__fp_chr_cnt];
955 char_type __decimal_point;
956 char_type __thousands_sep;
957 string __grouping = this->__stage2_float_prep(__iob, __atoms, __decimal_point, __thousands_sep);
958 string __buf;
959 __buf.resize(__buf.capacity());
960 char* __a = &__buf[0];
961 char* __a_end = __a;
962 unsigned __g[__num_get_base::__num_get_buf_sz];
963 unsigned* __g_end = __g;
964 unsigned __dc = 0;
965 bool __in_units = true;
966 char __exp = 'E';
967 bool __is_leading_parsed = false;
968 for (; __b != __e; ++__b) {
969 if (__a_end == __a + __buf.size()) {
970 size_t __tmp = __buf.size();
971 __buf.resize(2 * __buf.size());
972 __buf.resize(__buf.capacity());
973 __a = &__buf[0];
974 __a_end = __a + __tmp;
975 }
976 if (this->__stage2_float_loop(
977 *__b,
978 __in_units,
979 __exp,
980 __a,
981 __a_end,
982 __decimal_point,
983 __thousands_sep,
984 __grouping,
985 __g,
986 __g_end,
987 __dc,
988 __atoms))
989 break;
990
991 // the leading character excluding the sign must be a decimal digit
992 if (!__is_leading_parsed) {
993 if (__a_end - __a >= 1 && __a[0] != '-' && __a[0] != '+') {
994 if (('0' <= __a[0] && __a[0] <= '9') || __a[0] == '.')
995 __is_leading_parsed = true;
996 else
997 break;
998 } else if (__a_end - __a >= 2 && (__a[0] == '-' || __a[0] == '+')) {
999 if (('0' <= __a[1] && __a[1] <= '9') || __a[1] == '.')
1000 __is_leading_parsed = true;
1001 else
1002 break;
1003 }
1004 }
1005 }
1006 if (__grouping.size() != 0 && __in_units && __g_end - __g < __num_get_base::__num_get_buf_sz)
1007 *__g_end++ = __dc;
1008 // Stage 3
1009 __v = std::__num_get_float<_Fp>(__a, __a_end, __err);
1010 // Digit grouping checked
1011 __check_grouping(__grouping, __g, __g_end, __err);
1012 // EOF checked
1013 if (__b == __e)
1014 __err |= ios_base::eofbit;
1015 return __b;
1016}
1017
1018template <class _CharT, class _InputIterator>
1019_InputIterator num_get<_CharT, _InputIterator>::do_get(
1020 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, void*& __v) const {
1021 // Stage 1
1022 int __base = 16;
1023 // Stage 2
1024 char_type __atoms[__num_get_base::__int_chr_cnt];
1025 char_type __thousands_sep = char_type();
1026 string __grouping;
1027 std::use_facet<ctype<_CharT> >(__iob.getloc())
1028 .widen(__num_get_base::__src, __num_get_base::__src + __num_get_base::__int_chr_cnt, __atoms);
1029 string __buf;
1030 __buf.resize(__buf.capacity());
1031 char* __a = &__buf[0];
1032 char* __a_end = __a;
1033 unsigned __g[__num_get_base::__num_get_buf_sz];
1034 unsigned* __g_end = __g;
1035 unsigned __dc = 0;
1036 for (; __b != __e; ++__b) {
1037 if (__a_end == __a + __buf.size()) {
1038 size_t __tmp = __buf.size();
1039 __buf.resize(2 * __buf.size());
1040 __buf.resize(__buf.capacity());
1041 __a = &__buf[0];
1042 __a_end = __a + __tmp;
1043 }
1044 if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms))
1045 break;
1046 }
1047 // Stage 3
1048 __buf.resize(__a_end - __a);
1049 if (__locale::__sscanf(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1)
1050 __err = ios_base::failbit;
1051 // EOF checked
1052 if (__b == __e)
1053 __err |= ios_base::eofbit;
1054 return __b;
1055}
1056
1057extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<char>;
1058# if _LIBCPP_HAS_WIDE_CHARACTERS
1059extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<wchar_t>;
1060# endif
1061
1062struct _LIBCPP_EXPORTED_FROM_ABI __num_put_base {
1063protected:
1064 static void __format_int(char* __fmt, const char* __len, bool __signd, ios_base::fmtflags __flags);
1065 static bool __format_float(char* __fmt, const char* __len, ios_base::fmtflags __flags);
1066 static char* __identify_padding(char* __nb, char* __ne, const ios_base& __iob);
1067};
1068
1069template <class _CharT>
1070struct __num_put : protected __num_put_base {
1071 static void __widen_and_group_int(
1072 char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc);
1073 static void __widen_and_group_float(
1074 char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc);
1075};
1076
1077template <class _CharT>
1078void __num_put<_CharT>::__widen_and_group_int(
1079 char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc) {
1080 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__loc);
1081 const numpunct<_CharT>& __npt = std::use_facet<numpunct<_CharT> >(__loc);
1082 string __grouping = __npt.grouping();
1083 if (__grouping.empty()) {
1084 __ct.widen(__nb, __ne, __ob);
1085 __oe = __ob + (__ne - __nb);
1086 } else {
1087 __oe = __ob;
1088 char* __nf = __nb;
1089 if (*__nf == '-' || *__nf == '+')
1090 *__oe++ = __ct.widen(*__nf++);
1091 if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || __nf[1] == 'X')) {
1092 *__oe++ = __ct.widen(*__nf++);
1093 *__oe++ = __ct.widen(*__nf++);
1094 }
1095 std::reverse(__nf, __ne);
1096 _CharT __thousands_sep = __npt.thousands_sep();
1097 unsigned __dc = 0;
1098 unsigned __dg = 0;
1099 for (char* __p = __nf; __p < __ne; ++__p) {
1100 if (static_cast<unsigned>(__grouping[__dg]) > 0 && __dc == static_cast<unsigned>(__grouping[__dg])) {
1101 *__oe++ = __thousands_sep;
1102 __dc = 0;
1103 if (__dg < __grouping.size() - 1)
1104 ++__dg;
1105 }
1106 *__oe++ = __ct.widen(*__p);
1107 ++__dc;
1108 }
1109 std::reverse(__ob + (__nf - __nb), __oe);
1110 }
1111 if (__np == __ne)
1112 __op = __oe;
1113 else
1114 __op = __ob + (__np - __nb);
1115}
1116
1117template <class _CharT>
1118void __num_put<_CharT>::__widen_and_group_float(
1119 char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc) {
1120 const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__loc);
1121 const numpunct<_CharT>& __npt = std::use_facet<numpunct<_CharT> >(__loc);
1122 string __grouping = __npt.grouping();
1123 __oe = __ob;
1124 char* __nf = __nb;
1125 if (*__nf == '-' || *__nf == '+')
1126 *__oe++ = __ct.widen(*__nf++);
1127 char* __ns;
1128 if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || __nf[1] == 'X')) {
1129 *__oe++ = __ct.widen(*__nf++);
1130 *__oe++ = __ct.widen(*__nf++);
1131 for (__ns = __nf; __ns < __ne; ++__ns)
1132 if (!__locale::__isxdigit(*__ns, _LIBCPP_GET_C_LOCALE))
1133 break;
1134 } else {
1135 for (__ns = __nf; __ns < __ne; ++__ns)
1136 if (!__locale::__isdigit(*__ns, _LIBCPP_GET_C_LOCALE))
1137 break;
1138 }
1139 if (__grouping.empty()) {
1140 __ct.widen(__nf, __ns, __oe);
1141 __oe += __ns - __nf;
1142 } else {
1143 std::reverse(__nf, __ns);
1144 _CharT __thousands_sep = __npt.thousands_sep();
1145 unsigned __dc = 0;
1146 unsigned __dg = 0;
1147 for (char* __p = __nf; __p < __ns; ++__p) {
1148 if (__grouping[__dg] > 0 && __dc == static_cast<unsigned>(__grouping[__dg])) {
1149 *__oe++ = __thousands_sep;
1150 __dc = 0;
1151 if (__dg < __grouping.size() - 1)
1152 ++__dg;
1153 }
1154 *__oe++ = __ct.widen(*__p);
1155 ++__dc;
1156 }
1157 std::reverse(__ob + (__nf - __nb), __oe);
1158 }
1159 for (__nf = __ns; __nf < __ne; ++__nf) {
1160 if (*__nf == '.') {
1161 *__oe++ = __npt.decimal_point();
1162 ++__nf;
1163 break;
1164 } else
1165 *__oe++ = __ct.widen(*__nf);
1166 }
1167 __ct.widen(__nf, __ne, __oe);
1168 __oe += __ne - __nf;
1169 if (__np == __ne)
1170 __op = __oe;
1171 else
1172 __op = __ob + (__np - __nb);
1173}
1174
1175extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<char>;
1176# if _LIBCPP_HAS_WIDE_CHARACTERS
1177extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<wchar_t>;
1178# endif
1179
1180template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
1181class _LIBCPP_TEMPLATE_VIS num_put : public locale::facet, private __num_put<_CharT> {
1182public:
1183 typedef _CharT char_type;
1184 typedef _OutputIterator iter_type;
1185
1186 _LIBCPP_HIDE_FROM_ABI explicit num_put(size_t __refs = 0) : locale::facet(__refs) {}
1187
1188 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, bool __v) const {
1189 return do_put(__s, __iob, __fl, __v);
1190 }
1191
1192 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, long __v) const {
1193 return do_put(__s, __iob, __fl, __v);
1194 }
1195
1196 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, long long __v) const {
1197 return do_put(__s, __iob, __fl, __v);
1198 }
1199
1200 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long __v) const {
1201 return do_put(__s, __iob, __fl, __v);
1202 }
1203
1204 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long long __v) const {
1205 return do_put(__s, __iob, __fl, __v);
1206 }
1207
1208 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, double __v) const {
1209 return do_put(__s, __iob, __fl, __v);
1210 }
1211
1212 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, long double __v) const {
1213 return do_put(__s, __iob, __fl, __v);
1214 }
1215
1216 _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, const void* __v) const {
1217 return do_put(__s, __iob, __fl, __v);
1218 }
1219
1220 static locale::id id;
1221
1222protected:
1223 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~num_put() override {}
1224
1225 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, bool __v) const;
1226 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, long __v) const;
1227 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, long long __v) const;
1228 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long) const;
1229 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long long) const;
1230 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, double __v) const;
1231 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, long double __v) const;
1232 virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, const void* __v) const;
1233
1234 template <class _Integral>
1235 _LIBCPP_HIDE_FROM_ABI inline _OutputIterator
1236 __do_put_integral(iter_type __s, ios_base& __iob, char_type __fl, _Integral __v, char const* __len) const;
1237
1238 template <class _Float>
1239 _LIBCPP_HIDE_FROM_ABI inline _OutputIterator
1240 __do_put_floating_point(iter_type __s, ios_base& __iob, char_type __fl, _Float __v, char const* __len) const;
1241};
1242
1243template <class _CharT, class _OutputIterator>
1244locale::id num_put<_CharT, _OutputIterator>::id;
1245
1246template <class _CharT, class _OutputIterator>
1247_OutputIterator
1248num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, bool __v) const {
1249 if ((__iob.flags() & ios_base::boolalpha) == 0)
1250 return do_put(__s, __iob, __fl, (unsigned long)__v);
1251 const numpunct<char_type>& __np = std::use_facet<numpunct<char_type> >(__iob.getloc());
1252 typedef typename numpunct<char_type>::string_type string_type;
1253 string_type __nm = __v ? __np.truename() : __np.falsename();
1254 for (typename string_type::iterator __i = __nm.begin(); __i != __nm.end(); ++__i, ++__s)
1255 *__s = *__i;
1256 return __s;
1257}
1258
1259template <class _CharT, class _OutputIterator>
1260template <class _Integral>
1261_LIBCPP_HIDE_FROM_ABI inline _OutputIterator num_put<_CharT, _OutputIterator>::__do_put_integral(
1262 iter_type __s, ios_base& __iob, char_type __fl, _Integral __v, char const* __len) const {
1263 // Stage 1 - Get number in narrow char
1264 char __fmt[8] = {'%', 0};
1265 this->__format_int(__fmt + 1, __len, is_signed<_Integral>::value, __iob.flags());
1266 // Worst case is octal, with showbase enabled. Note that octal is always
1267 // printed as an unsigned value.
1268 using _Unsigned = typename make_unsigned<_Integral>::type;
1269 _LIBCPP_CONSTEXPR const unsigned __nbuf =
1270 (numeric_limits<_Unsigned>::digits / 3) // 1 char per 3 bits
1271 + ((numeric_limits<_Unsigned>::digits % 3) != 0) // round up
1272 + 2; // base prefix + terminating null character
1273 char __nar[__nbuf];
1274 _LIBCPP_DIAGNOSTIC_PUSH
1275 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
1276 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
1277 int __nc = __locale::__snprintf(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
1278 _LIBCPP_DIAGNOSTIC_POP
1279 char* __ne = __nar + __nc;
1280 char* __np = this->__identify_padding(__nar, __ne, __iob);
1281 // Stage 2 - Widen __nar while adding thousands separators
1282 char_type __o[2 * (__nbuf - 1) - 1];
1283 char_type* __op; // pad here
1284 char_type* __oe; // end of output
1285 this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
1286 // [__o, __oe) contains thousands_sep'd wide number
1287 // Stage 3 & 4
1288 return std::__pad_and_output(__s, __o, __op, __oe, __iob, __fl);
1289}
1290
1291template <class _CharT, class _OutputIterator>
1292_OutputIterator
1293num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, long __v) const {
1294 return this->__do_put_integral(__s, __iob, __fl, __v, "l");
1295}
1296
1297template <class _CharT, class _OutputIterator>
1298_OutputIterator
1299num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, long long __v) const {
1300 return this->__do_put_integral(__s, __iob, __fl, __v, "ll");
1301}
1302
1303template <class _CharT, class _OutputIterator>
1304_OutputIterator
1305num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long __v) const {
1306 return this->__do_put_integral(__s, __iob, __fl, __v, "l");
1307}
1308
1309template <class _CharT, class _OutputIterator>
1310_OutputIterator
1311num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long long __v) const {
1312 return this->__do_put_integral(__s, __iob, __fl, __v, "ll");
1313}
1314
1315template <class _CharT, class _OutputIterator>
1316template <class _Float>
1317_LIBCPP_HIDE_FROM_ABI inline _OutputIterator num_put<_CharT, _OutputIterator>::__do_put_floating_point(
1318 iter_type __s, ios_base& __iob, char_type __fl, _Float __v, char const* __len) const {
1319 // Stage 1 - Get number in narrow char
1320 char __fmt[8] = {'%', 0};
1321 bool __specify_precision = this->__format_float(__fmt + 1, __len, __iob.flags());
1322 const unsigned __nbuf = 30;
1323 char __nar[__nbuf];
1324 char* __nb = __nar;
1325 int __nc;
1326 _LIBCPP_DIAGNOSTIC_PUSH
1327 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
1328 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
1329 if (__specify_precision)
1330 __nc = __locale::__snprintf(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
1331 else
1332 __nc = __locale::__snprintf(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
1333 unique_ptr<char, void (*)(void*)> __nbh(nullptr, free);
1334 if (__nc > static_cast<int>(__nbuf - 1)) {
1335 if (__specify_precision)
1336 __nc = __locale::__asprintf(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
1337 else
1338 __nc = __locale::__asprintf(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
1339 if (__nc == -1)
1340 __throw_bad_alloc();
1341 __nbh.reset(__nb);
1342 }
1343 _LIBCPP_DIAGNOSTIC_POP
1344 char* __ne = __nb + __nc;
1345 char* __np = this->__identify_padding(__nb, __ne, __iob);
1346 // Stage 2 - Widen __nar while adding thousands separators
1347 char_type __o[2 * (__nbuf - 1) - 1];
1348 char_type* __ob = __o;
1349 unique_ptr<char_type, void (*)(void*)> __obh(0, free);
1350 if (__nb != __nar) {
1351 __ob = (char_type*)malloc(2 * static_cast<size_t>(__nc) * sizeof(char_type));
1352 if (__ob == 0)
1353 __throw_bad_alloc();
1354 __obh.reset(__ob);
1355 }
1356 char_type* __op; // pad here
1357 char_type* __oe; // end of output
1358 this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc());
1359 // [__o, __oe) contains thousands_sep'd wide number
1360 // Stage 3 & 4
1361 __s = std::__pad_and_output(__s, __ob, __op, __oe, __iob, __fl);
1362 return __s;
1363}
1364
1365template <class _CharT, class _OutputIterator>
1366_OutputIterator
1367num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, double __v) const {
1368 return this->__do_put_floating_point(__s, __iob, __fl, __v, "");
1369}
1370
1371template <class _CharT, class _OutputIterator>
1372_OutputIterator
1373num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, long double __v) const {
1374 return this->__do_put_floating_point(__s, __iob, __fl, __v, "L");
1375}
1376
1377template <class _CharT, class _OutputIterator>
1378_OutputIterator
1379num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, const void* __v) const {
1380 // Stage 1 - Get pointer in narrow char
1381 const unsigned __nbuf = 20;
1382 char __nar[__nbuf];
1383 int __nc = __locale::__snprintf(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, "%p", __v);
1384 char* __ne = __nar + __nc;
1385 char* __np = this->__identify_padding(__nar, __ne, __iob);
1386 // Stage 2 - Widen __nar
1387 char_type __o[2 * (__nbuf - 1) - 1];
1388 char_type* __op; // pad here
1389 char_type* __oe; // end of output
1390 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
1391 __ct.widen(__nar, __ne, __o);
1392 __oe = __o + (__ne - __nar);
1393 if (__np == __ne)
1394 __op = __oe;
1395 else
1396 __op = __o + (__np - __nar);
1397 // [__o, __oe) contains wide number
1398 // Stage 3 & 4
1399 return std::__pad_and_output(__s, __o, __op, __oe, __iob, __fl);
1400}
1401
1402extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<char>;
1403# if _LIBCPP_HAS_WIDE_CHARACTERS
1404extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<wchar_t>;
1405# endif
1406
1407template <class _CharT, class _InputIterator>
1408_LIBCPP_HIDE_FROM_ABI int __get_up_to_n_digits(
1409 _InputIterator& __b, _InputIterator __e, ios_base::iostate& __err, const ctype<_CharT>& __ct, int __n) {
1410 // Precondition: __n >= 1
1411 if (__b == __e) {
1412 __err |= ios_base::eofbit | ios_base::failbit;
1413 return 0;
1414 }
1415 // get first digit
1416 _CharT __c = *__b;
1417 if (!__ct.is(ctype_base::digit, __c)) {
1418 __err |= ios_base::failbit;
1419 return 0;
1420 }
1421 int __r = __ct.narrow(__c, 0) - '0';
1422 for (++__b, (void)--__n; __b != __e && __n > 0; ++__b, (void)--__n) {
1423 // get next digit
1424 __c = *__b;
1425 if (!__ct.is(ctype_base::digit, __c))
1426 return __r;
1427 __r = __r * 10 + __ct.narrow(__c, 0) - '0';
1428 }
1429 if (__b == __e)
1430 __err |= ios_base::eofbit;
1431 return __r;
1432}
1433
1434class _LIBCPP_EXPORTED_FROM_ABI time_base {
1435public:
1436 enum dateorder { no_order, dmy, mdy, ymd, ydm };
1437};
1438
1439template <class _CharT>
1440class _LIBCPP_TEMPLATE_VIS __time_get_c_storage {
1441protected:
1442 typedef basic_string<_CharT> string_type;
1443
1444 virtual const string_type* __weeks() const;
1445 virtual const string_type* __months() const;
1446 virtual const string_type* __am_pm() const;
1447 virtual const string_type& __c() const;
1448 virtual const string_type& __r() const;
1449 virtual const string_type& __x() const;
1450 virtual const string_type& __X() const;
1451
1452 _LIBCPP_HIDE_FROM_ABI ~__time_get_c_storage() {}
1453};
1454
1455template <>
1456_LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__weeks() const;
1457template <>
1458_LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__months() const;
1459template <>
1460_LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__am_pm() const;
1461template <>
1462_LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__c() const;
1463template <>
1464_LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__r() const;
1465template <>
1466_LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__x() const;
1467template <>
1468_LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__X() const;
1469
1470# if _LIBCPP_HAS_WIDE_CHARACTERS
1471template <>
1472_LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__weeks() const;
1473template <>
1474_LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__months() const;
1475template <>
1476_LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__am_pm() const;
1477template <>
1478_LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__c() const;
1479template <>
1480_LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__r() const;
1481template <>
1482_LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__x() const;
1483template <>
1484_LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__X() const;
1485# endif
1486
1487template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
1488class _LIBCPP_TEMPLATE_VIS time_get : public locale::facet, public time_base, private __time_get_c_storage<_CharT> {
1489public:
1490 typedef _CharT char_type;
1491 typedef _InputIterator iter_type;
1492 typedef time_base::dateorder dateorder;
1493 typedef basic_string<char_type> string_type;
1494
1495 _LIBCPP_HIDE_FROM_ABI explicit time_get(size_t __refs = 0) : locale::facet(__refs) {}
1496
1497 _LIBCPP_HIDE_FROM_ABI dateorder date_order() const { return this->do_date_order(); }
1498
1499 _LIBCPP_HIDE_FROM_ABI iter_type
1500 get_time(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1501 return do_get_time(__b, __e, __iob, __err, __tm);
1502 }
1503
1504 _LIBCPP_HIDE_FROM_ABI iter_type
1505 get_date(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1506 return do_get_date(__b, __e, __iob, __err, __tm);
1507 }
1508
1509 _LIBCPP_HIDE_FROM_ABI iter_type
1510 get_weekday(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1511 return do_get_weekday(__b, __e, __iob, __err, __tm);
1512 }
1513
1514 _LIBCPP_HIDE_FROM_ABI iter_type
1515 get_monthname(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1516 return do_get_monthname(__b, __e, __iob, __err, __tm);
1517 }
1518
1519 _LIBCPP_HIDE_FROM_ABI iter_type
1520 get_year(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1521 return do_get_year(__b, __e, __iob, __err, __tm);
1522 }
1523
1524 _LIBCPP_HIDE_FROM_ABI iter_type
1525 get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, char __fmt, char __mod = 0)
1526 const {
1527 return do_get(__b, __e, __iob, __err, __tm, __fmt, __mod);
1528 }
1529
1530 iter_type
1531 get(iter_type __b,
1532 iter_type __e,
1533 ios_base& __iob,
1534 ios_base::iostate& __err,
1535 tm* __tm,
1536 const char_type* __fmtb,
1537 const char_type* __fmte) const;
1538
1539 static locale::id id;
1540
1541protected:
1542 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_get() override {}
1543
1544 virtual dateorder do_date_order() const;
1545 virtual iter_type
1546 do_get_time(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;
1547 virtual iter_type
1548 do_get_date(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;
1549 virtual iter_type
1550 do_get_weekday(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;
1551 virtual iter_type
1552 do_get_monthname(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;
1553 virtual iter_type
1554 do_get_year(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const;
1555 virtual iter_type do_get(
1556 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, char __fmt, char __mod) const;
1557
1558private:
1559 void __get_white_space(iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1560 void __get_percent(iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1561
1562 void __get_weekdayname(
1563 int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1564 void __get_monthname(
1565 int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1566 void __get_day(int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1567 void
1568 __get_month(int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1569 void
1570 __get_year(int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1571 void
1572 __get_year4(int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1573 void
1574 __get_hour(int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1575 void
1576 __get_12_hour(int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1577 void
1578 __get_am_pm(int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1579 void
1580 __get_minute(int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1581 void
1582 __get_second(int& __s, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1583 void
1584 __get_weekday(int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1585 void __get_day_year_num(
1586 int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const;
1587};
1588
1589template <class _CharT, class _InputIterator>
1590locale::id time_get<_CharT, _InputIterator>::id;
1591
1592// time_get primitives
1593
1594template <class _CharT, class _InputIterator>
1595void time_get<_CharT, _InputIterator>::__get_weekdayname(
1596 int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1597 // Note: ignoring case comes from the POSIX strptime spec
1598 const string_type* __wk = this->__weeks();
1599 ptrdiff_t __i = std::__scan_keyword(__b, __e, __wk, __wk + 14, __ct, __err, false) - __wk;
1600 if (__i < 14)
1601 __w = __i % 7;
1602}
1603
1604template <class _CharT, class _InputIterator>
1605void time_get<_CharT, _InputIterator>::__get_monthname(
1606 int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1607 // Note: ignoring case comes from the POSIX strptime spec
1608 const string_type* __month = this->__months();
1609 ptrdiff_t __i = std::__scan_keyword(__b, __e, __month, __month + 24, __ct, __err, false) - __month;
1610 if (__i < 24)
1611 __m = __i % 12;
1612}
1613
1614template <class _CharT, class _InputIterator>
1615void time_get<_CharT, _InputIterator>::__get_day(
1616 int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1617 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
1618 if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 31)
1619 __d = __t;
1620 else
1621 __err |= ios_base::failbit;
1622}
1623
1624template <class _CharT, class _InputIterator>
1625void time_get<_CharT, _InputIterator>::__get_month(
1626 int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1627 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2) - 1;
1628 if (!(__err & ios_base::failbit) && 0 <= __t && __t <= 11)
1629 __m = __t;
1630 else
1631 __err |= ios_base::failbit;
1632}
1633
1634template <class _CharT, class _InputIterator>
1635void time_get<_CharT, _InputIterator>::__get_year(
1636 int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1637 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 4);
1638 if (!(__err & ios_base::failbit)) {
1639 if (__t < 69)
1640 __t += 2000;
1641 else if (69 <= __t && __t <= 99)
1642 __t += 1900;
1643 __y = __t - 1900;
1644 }
1645}
1646
1647template <class _CharT, class _InputIterator>
1648void time_get<_CharT, _InputIterator>::__get_year4(
1649 int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1650 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 4);
1651 if (!(__err & ios_base::failbit))
1652 __y = __t - 1900;
1653}
1654
1655template <class _CharT, class _InputIterator>
1656void time_get<_CharT, _InputIterator>::__get_hour(
1657 int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1658 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
1659 if (!(__err & ios_base::failbit) && __t <= 23)
1660 __h = __t;
1661 else
1662 __err |= ios_base::failbit;
1663}
1664
1665template <class _CharT, class _InputIterator>
1666void time_get<_CharT, _InputIterator>::__get_12_hour(
1667 int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1668 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
1669 if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 12)
1670 __h = __t;
1671 else
1672 __err |= ios_base::failbit;
1673}
1674
1675template <class _CharT, class _InputIterator>
1676void time_get<_CharT, _InputIterator>::__get_minute(
1677 int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1678 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
1679 if (!(__err & ios_base::failbit) && __t <= 59)
1680 __m = __t;
1681 else
1682 __err |= ios_base::failbit;
1683}
1684
1685template <class _CharT, class _InputIterator>
1686void time_get<_CharT, _InputIterator>::__get_second(
1687 int& __s, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1688 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2);
1689 if (!(__err & ios_base::failbit) && __t <= 60)
1690 __s = __t;
1691 else
1692 __err |= ios_base::failbit;
1693}
1694
1695template <class _CharT, class _InputIterator>
1696void time_get<_CharT, _InputIterator>::__get_weekday(
1697 int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1698 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 1);
1699 if (!(__err & ios_base::failbit) && __t <= 6)
1700 __w = __t;
1701 else
1702 __err |= ios_base::failbit;
1703}
1704
1705template <class _CharT, class _InputIterator>
1706void time_get<_CharT, _InputIterator>::__get_day_year_num(
1707 int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1708 int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 3);
1709 if (!(__err & ios_base::failbit) && __t <= 365)
1710 __d = __t;
1711 else
1712 __err |= ios_base::failbit;
1713}
1714
1715template <class _CharT, class _InputIterator>
1716void time_get<_CharT, _InputIterator>::__get_white_space(
1717 iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1718 for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b)
1719 ;
1720 if (__b == __e)
1721 __err |= ios_base::eofbit;
1722}
1723
1724template <class _CharT, class _InputIterator>
1725void time_get<_CharT, _InputIterator>::__get_am_pm(
1726 int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1727 const string_type* __ap = this->__am_pm();
1728 if (__ap[0].size() + __ap[1].size() == 0) {
1729 __err |= ios_base::failbit;
1730 return;
1731 }
1732 ptrdiff_t __i = std::__scan_keyword(__b, __e, __ap, __ap + 2, __ct, __err, false) - __ap;
1733 if (__i == 0 && __h == 12)
1734 __h = 0;
1735 else if (__i == 1 && __h < 12)
1736 __h += 12;
1737}
1738
1739template <class _CharT, class _InputIterator>
1740void time_get<_CharT, _InputIterator>::__get_percent(
1741 iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const {
1742 if (__b == __e) {
1743 __err |= ios_base::eofbit | ios_base::failbit;
1744 return;
1745 }
1746 if (__ct.narrow(*__b, 0) != '%')
1747 __err |= ios_base::failbit;
1748 else if (++__b == __e)
1749 __err |= ios_base::eofbit;
1750}
1751
1752// time_get end primitives
1753
1754template <class _CharT, class _InputIterator>
1755_InputIterator time_get<_CharT, _InputIterator>::get(
1756 iter_type __b,
1757 iter_type __e,
1758 ios_base& __iob,
1759 ios_base::iostate& __err,
1760 tm* __tm,
1761 const char_type* __fmtb,
1762 const char_type* __fmte) const {
1763 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
1764 __err = ios_base::goodbit;
1765 while (__fmtb != __fmte && __err == ios_base::goodbit) {
1766 if (__b == __e) {
1767 __err = ios_base::failbit;
1768 break;
1769 }
1770 if (__ct.narrow(*__fmtb, 0) == '%') {
1771 if (++__fmtb == __fmte) {
1772 __err = ios_base::failbit;
1773 break;
1774 }
1775 char __cmd = __ct.narrow(*__fmtb, 0);
1776 char __opt = '\0';
1777 if (__cmd == 'E' || __cmd == '0') {
1778 if (++__fmtb == __fmte) {
1779 __err = ios_base::failbit;
1780 break;
1781 }
1782 __opt = __cmd;
1783 __cmd = __ct.narrow(*__fmtb, 0);
1784 }
1785 __b = do_get(__b, __e, __iob, __err, __tm, __cmd, __opt);
1786 ++__fmtb;
1787 } else if (__ct.is(ctype_base::space, *__fmtb)) {
1788 for (++__fmtb; __fmtb != __fmte && __ct.is(ctype_base::space, *__fmtb); ++__fmtb)
1789 ;
1790 for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b)
1791 ;
1792 } else if (__ct.toupper(*__b) == __ct.toupper(*__fmtb)) {
1793 ++__b;
1794 ++__fmtb;
1795 } else
1796 __err = ios_base::failbit;
1797 }
1798 if (__b == __e)
1799 __err |= ios_base::eofbit;
1800 return __b;
1801}
1802
1803template <class _CharT, class _InputIterator>
1804typename time_get<_CharT, _InputIterator>::dateorder time_get<_CharT, _InputIterator>::do_date_order() const {
1805 return mdy;
1806}
1807
1808template <class _CharT, class _InputIterator>
1809_InputIterator time_get<_CharT, _InputIterator>::do_get_time(
1810 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1811 const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
1812 return get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt) / sizeof(__fmt[0]));
1813}
1814
1815template <class _CharT, class _InputIterator>
1816_InputIterator time_get<_CharT, _InputIterator>::do_get_date(
1817 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1818 const string_type& __fmt = this->__x();
1819 return get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size());
1820}
1821
1822template <class _CharT, class _InputIterator>
1823_InputIterator time_get<_CharT, _InputIterator>::do_get_weekday(
1824 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1825 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
1826 __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);
1827 return __b;
1828}
1829
1830template <class _CharT, class _InputIterator>
1831_InputIterator time_get<_CharT, _InputIterator>::do_get_monthname(
1832 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1833 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
1834 __get_monthname(__tm->tm_mon, __b, __e, __err, __ct);
1835 return __b;
1836}
1837
1838template <class _CharT, class _InputIterator>
1839_InputIterator time_get<_CharT, _InputIterator>::do_get_year(
1840 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const {
1841 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
1842 __get_year(__tm->tm_year, __b, __e, __err, __ct);
1843 return __b;
1844}
1845
1846template <class _CharT, class _InputIterator>
1847_InputIterator time_get<_CharT, _InputIterator>::do_get(
1848 iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, char __fmt, char) const {
1849 __err = ios_base::goodbit;
1850 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
1851 switch (__fmt) {
1852 case 'a':
1853 case 'A':
1854 __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);
1855 break;
1856 case 'b':
1857 case 'B':
1858 case 'h':
1859 __get_monthname(__tm->tm_mon, __b, __e, __err, __ct);
1860 break;
1861 case 'c': {
1862 const string_type& __fm = this->__c();
1863 __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());
1864 } break;
1865 case 'd':
1866 case 'e':
1867 __get_day(__tm->tm_mday, __b, __e, __err, __ct);
1868 break;
1869 case 'D': {
1870 const char_type __fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};
1871 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));
1872 } break;
1873 case 'F': {
1874 const char_type __fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'};
1875 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));
1876 } break;
1877 case 'H':
1878 __get_hour(__tm->tm_hour, __b, __e, __err, __ct);
1879 break;
1880 case 'I':
1881 __get_12_hour(__tm->tm_hour, __b, __e, __err, __ct);
1882 break;
1883 case 'j':
1884 __get_day_year_num(__tm->tm_yday, __b, __e, __err, __ct);
1885 break;
1886 case 'm':
1887 __get_month(__tm->tm_mon, __b, __e, __err, __ct);
1888 break;
1889 case 'M':
1890 __get_minute(__tm->tm_min, __b, __e, __err, __ct);
1891 break;
1892 case 'n':
1893 case 't':
1894 __get_white_space(__b, __e, __err, __ct);
1895 break;
1896 case 'p':
1897 __get_am_pm(__tm->tm_hour, __b, __e, __err, __ct);
1898 break;
1899 case 'r': {
1900 const char_type __fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};
1901 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));
1902 } break;
1903 case 'R': {
1904 const char_type __fm[] = {'%', 'H', ':', '%', 'M'};
1905 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));
1906 } break;
1907 case 'S':
1908 __get_second(__tm->tm_sec, __b, __e, __err, __ct);
1909 break;
1910 case 'T': {
1911 const char_type __fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
1912 __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0]));
1913 } break;
1914 case 'w':
1915 __get_weekday(__tm->tm_wday, __b, __e, __err, __ct);
1916 break;
1917 case 'x':
1918 return do_get_date(__b, __e, __iob, __err, __tm);
1919 case 'X': {
1920 const string_type& __fm = this->__X();
1921 __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());
1922 } break;
1923 case 'y':
1924 __get_year(__tm->tm_year, __b, __e, __err, __ct);
1925 break;
1926 case 'Y':
1927 __get_year4(__tm->tm_year, __b, __e, __err, __ct);
1928 break;
1929 case '%':
1930 __get_percent(__b, __e, __err, __ct);
1931 break;
1932 default:
1933 __err |= ios_base::failbit;
1934 }
1935 return __b;
1936}
1937
1938extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<char>;
1939# if _LIBCPP_HAS_WIDE_CHARACTERS
1940extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<wchar_t>;
1941# endif
1942
1943class _LIBCPP_EXPORTED_FROM_ABI __time_get {
1944protected:
1945 __locale::__locale_t __loc_;
1946
1947 __time_get(const char* __nm);
1948 __time_get(const string& __nm);
1949 ~__time_get();
1950};
1951
1952template <class _CharT>
1953class _LIBCPP_TEMPLATE_VIS __time_get_storage : public __time_get {
1954protected:
1955 typedef basic_string<_CharT> string_type;
1956
1957 string_type __weeks_[14];
1958 string_type __months_[24];
1959 string_type __am_pm_[2];
1960 string_type __c_;
1961 string_type __r_;
1962 string_type __x_;
1963 string_type __X_;
1964
1965 explicit __time_get_storage(const char* __nm);
1966 explicit __time_get_storage(const string& __nm);
1967
1968 _LIBCPP_HIDE_FROM_ABI ~__time_get_storage() {}
1969
1970 time_base::dateorder __do_date_order() const;
1971
1972private:
1973 void init(const ctype<_CharT>&);
1974 string_type __analyze(char __fmt, const ctype<_CharT>&);
1975};
1976
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 /**/
1997
1998_LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(char)
1999# if _LIBCPP_HAS_WIDE_CHARACTERS
2000_LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(wchar_t)
2001# endif
2002# undef _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION
2003
2004template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
2005class _LIBCPP_TEMPLATE_VIS time_get_byname
2006 : public time_get<_CharT, _InputIterator>,
2007 private __time_get_storage<_CharT> {
2008public:
2009 typedef time_base::dateorder dateorder;
2010 typedef _InputIterator iter_type;
2011 typedef _CharT char_type;
2012 typedef basic_string<char_type> string_type;
2013
2014 _LIBCPP_HIDE_FROM_ABI explicit time_get_byname(const char* __nm, size_t __refs = 0)
2015 : time_get<_CharT, _InputIterator>(__refs), __time_get_storage<_CharT>(__nm) {}
2016 _LIBCPP_HIDE_FROM_ABI explicit time_get_byname(const string& __nm, size_t __refs = 0)
2017 : time_get<_CharT, _InputIterator>(__refs), __time_get_storage<_CharT>(__nm) {}
2018
2019protected:
2020 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_get_byname() override {}
2021
2022 _LIBCPP_HIDE_FROM_ABI_VIRTUAL dateorder do_date_order() const override { return this->__do_date_order(); }
2023
2024private:
2025 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __weeks() const override { return this->__weeks_; }
2026 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __months() const override { return this->__months_; }
2027 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __am_pm() const override { return this->__am_pm_; }
2028 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __c() const override { return this->__c_; }
2029 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __r() const override { return this->__r_; }
2030 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __x() const override { return this->__x_; }
2031 _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __X() const override { return this->__X_; }
2032};
2033
2034extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<char>;
2035# if _LIBCPP_HAS_WIDE_CHARACTERS
2036extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<wchar_t>;
2037# endif
2038
2039class _LIBCPP_EXPORTED_FROM_ABI __time_put {
2040 __locale::__locale_t __loc_;
2041
2042protected:
2043 _LIBCPP_HIDE_FROM_ABI __time_put() : __loc_(_LIBCPP_GET_C_LOCALE) {}
2044 __time_put(const char* __nm);
2045 __time_put(const string& __nm);
2046 ~__time_put();
2047 void __do_put(char* __nb, char*& __ne, const tm* __tm, char __fmt, char __mod) const;
2048# if _LIBCPP_HAS_WIDE_CHARACTERS
2049 void __do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm, char __fmt, char __mod) const;
2050# endif
2051};
2052
2053template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
2054class _LIBCPP_TEMPLATE_VIS time_put : public locale::facet, private __time_put {
2055public:
2056 typedef _CharT char_type;
2057 typedef _OutputIterator iter_type;
2058
2059 _LIBCPP_HIDE_FROM_ABI explicit time_put(size_t __refs = 0) : locale::facet(__refs) {}
2060
2061 iter_type
2062 put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, const char_type* __pb, const char_type* __pe)
2063 const;
2064
2065 _LIBCPP_HIDE_FROM_ABI iter_type
2066 put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, char __fmt, char __mod = 0) const {
2067 return do_put(__s, __iob, __fl, __tm, __fmt, __mod);
2068 }
2069
2070 static locale::id id;
2071
2072protected:
2073 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_put() override {}
2074 virtual iter_type do_put(iter_type __s, ios_base&, char_type, const tm* __tm, char __fmt, char __mod) const;
2075
2076 _LIBCPP_HIDE_FROM_ABI explicit time_put(const char* __nm, size_t __refs) : locale::facet(__refs), __time_put(__nm) {}
2077 _LIBCPP_HIDE_FROM_ABI explicit time_put(const string& __nm, size_t __refs)
2078 : locale::facet(__refs), __time_put(__nm) {}
2079};
2080
2081template <class _CharT, class _OutputIterator>
2082locale::id time_put<_CharT, _OutputIterator>::id;
2083
2084template <class _CharT, class _OutputIterator>
2085_OutputIterator time_put<_CharT, _OutputIterator>::put(
2086 iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, const char_type* __pb, const char_type* __pe)
2087 const {
2088 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc());
2089 for (; __pb != __pe; ++__pb) {
2090 if (__ct.narrow(*__pb, 0) == '%') {
2091 if (++__pb == __pe) {
2092 *__s++ = __pb[-1];
2093 break;
2094 }
2095 char __mod = 0;
2096 char __fmt = __ct.narrow(*__pb, 0);
2097 if (__fmt == 'E' || __fmt == 'O') {
2098 if (++__pb == __pe) {
2099 *__s++ = __pb[-2];
2100 *__s++ = __pb[-1];
2101 break;
2102 }
2103 __mod = __fmt;
2104 __fmt = __ct.narrow(*__pb, 0);
2105 }
2106 __s = do_put(__s, __iob, __fl, __tm, __fmt, __mod);
2107 } else
2108 *__s++ = *__pb;
2109 }
2110 return __s;
2111}
2112
2113template <class _CharT, class _OutputIterator>
2114_OutputIterator time_put<_CharT, _OutputIterator>::do_put(
2115 iter_type __s, ios_base&, char_type, const tm* __tm, char __fmt, char __mod) const {
2116 char_type __nar[100];
2117 char_type* __nb = __nar;
2118 char_type* __ne = __nb + 100;
2119 __do_put(__nb, __ne, __tm, __fmt, __mod);
2120 return std::copy(__nb, __ne, __s);
2121}
2122
2123extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<char>;
2124# if _LIBCPP_HAS_WIDE_CHARACTERS
2125extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<wchar_t>;
2126# endif
2127
2128template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
2129class _LIBCPP_TEMPLATE_VIS time_put_byname : public time_put<_CharT, _OutputIterator> {
2130public:
2131 _LIBCPP_HIDE_FROM_ABI explicit time_put_byname(const char* __nm, size_t __refs = 0)
2132 : time_put<_CharT, _OutputIterator>(__nm, __refs) {}
2133
2134 _LIBCPP_HIDE_FROM_ABI explicit time_put_byname(const string& __nm, size_t __refs = 0)
2135 : time_put<_CharT, _OutputIterator>(__nm, __refs) {}
2136
2137protected:
2138 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_put_byname() override {}
2139};
2140
2141extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<char>;
2142# if _LIBCPP_HAS_WIDE_CHARACTERS
2143extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<wchar_t>;
2144# endif
2145
2146// money_base
2147
2148class _LIBCPP_EXPORTED_FROM_ABI money_base {
2149public:
2150 enum part { none, space, symbol, sign, value };
2151 struct pattern {
2152 char field[4];
2153 };
2154
2155 _LIBCPP_HIDE_FROM_ABI money_base() {}
2156};
2157
2158// moneypunct
2159
2160template <class _CharT, bool _International = false>
2161class _LIBCPP_TEMPLATE_VIS moneypunct : public locale::facet, public money_base {
2162public:
2163 typedef _CharT char_type;
2164 typedef basic_string<char_type> string_type;
2165
2166 _LIBCPP_HIDE_FROM_ABI explicit moneypunct(size_t __refs = 0) : locale::facet(__refs) {}
2167
2168 _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); }
2169 _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); }
2170 _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); }
2171 _LIBCPP_HIDE_FROM_ABI string_type curr_symbol() const { return do_curr_symbol(); }
2172 _LIBCPP_HIDE_FROM_ABI string_type positive_sign() const { return do_positive_sign(); }
2173 _LIBCPP_HIDE_FROM_ABI string_type negative_sign() const { return do_negative_sign(); }
2174 _LIBCPP_HIDE_FROM_ABI int frac_digits() const { return do_frac_digits(); }
2175 _LIBCPP_HIDE_FROM_ABI pattern pos_format() const { return do_pos_format(); }
2176 _LIBCPP_HIDE_FROM_ABI pattern neg_format() const { return do_neg_format(); }
2177
2178 static locale::id id;
2179 static const bool intl = _International;
2180
2181protected:
2182 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~moneypunct() override {}
2183
2184 virtual char_type do_decimal_point() const { return numeric_limits<char_type>::max(); }
2185 virtual char_type do_thousands_sep() const { return numeric_limits<char_type>::max(); }
2186 virtual string do_grouping() const { return string(); }
2187 virtual string_type do_curr_symbol() const { return string_type(); }
2188 virtual string_type do_positive_sign() const { return string_type(); }
2189 virtual string_type do_negative_sign() const { return string_type(1, '-'); }
2190 virtual int do_frac_digits() const { return 0; }
2191 virtual pattern do_pos_format() const {
2192 pattern __p = {{symbol, sign, none, value}};
2193 return __p;
2194 }
2195 virtual pattern do_neg_format() const {
2196 pattern __p = {{symbol, sign, none, value}};
2197 return __p;
2198 }
2199};
2200
2201template <class _CharT, bool _International>
2202locale::id moneypunct<_CharT, _International>::id;
2203
2204template <class _CharT, bool _International>
2205const bool moneypunct<_CharT, _International>::intl;
2206
2207extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, false>;
2208extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, true>;
2209# if _LIBCPP_HAS_WIDE_CHARACTERS
2210extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, false>;
2211extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, true>;
2212# endif
2213
2214// moneypunct_byname
2215
2216template <class _CharT, bool _International = false>
2217class _LIBCPP_TEMPLATE_VIS moneypunct_byname : public moneypunct<_CharT, _International> {
2218public:
2219 typedef money_base::pattern pattern;
2220 typedef _CharT char_type;
2221 typedef basic_string<char_type> string_type;
2222
2223 _LIBCPP_HIDE_FROM_ABI explicit moneypunct_byname(const char* __nm, size_t __refs = 0)
2224 : moneypunct<_CharT, _International>(__refs) {
2225 init(__nm);
2226 }
2227
2228 _LIBCPP_HIDE_FROM_ABI explicit moneypunct_byname(const string& __nm, size_t __refs = 0)
2229 : moneypunct<_CharT, _International>(__refs) {
2230 init(__nm.c_str());
2231 }
2232
2233protected:
2234 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~moneypunct_byname() override {}
2235
2236 char_type do_decimal_point() const override { return __decimal_point_; }
2237 char_type do_thousands_sep() const override { return __thousands_sep_; }
2238 string do_grouping() const override { return __grouping_; }
2239 string_type do_curr_symbol() const override { return __curr_symbol_; }
2240 string_type do_positive_sign() const override { return __positive_sign_; }
2241 string_type do_negative_sign() const override { return __negative_sign_; }
2242 int do_frac_digits() const override { return __frac_digits_; }
2243 pattern do_pos_format() const override { return __pos_format_; }
2244 pattern do_neg_format() const override { return __neg_format_; }
2245
2246private:
2247 char_type __decimal_point_;
2248 char_type __thousands_sep_;
2249 string __grouping_;
2250 string_type __curr_symbol_;
2251 string_type __positive_sign_;
2252 string_type __negative_sign_;
2253 int __frac_digits_;
2254 pattern __pos_format_;
2255 pattern __neg_format_;
2256
2257 void init(const char*);
2258};
2259
2260template <>
2261_LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<char, false>::init(const char*);
2262template <>
2263_LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<char, true>::init(const char*);
2264extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, false>;
2265extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, true>;
2266
2267# if _LIBCPP_HAS_WIDE_CHARACTERS
2268template <>
2269_LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<wchar_t, false>::init(const char*);
2270template <>
2271_LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<wchar_t, true>::init(const char*);
2272extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, false>;
2273extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, true>;
2274# endif
2275
2276// money_get
2277
2278template <class _CharT>
2279class __money_get {
2280protected:
2281 typedef _CharT char_type;
2282 typedef basic_string<char_type> string_type;
2283
2284 _LIBCPP_HIDE_FROM_ABI __money_get() {}
2285
2286 static void __gather_info(
2287 bool __intl,
2288 const locale& __loc,
2289 money_base::pattern& __pat,
2290 char_type& __dp,
2291 char_type& __ts,
2292 string& __grp,
2293 string_type& __sym,
2294 string_type& __psn,
2295 string_type& __nsn,
2296 int& __fd);
2297};
2298
2299template <class _CharT>
2300void __money_get<_CharT>::__gather_info(
2301 bool __intl,
2302 const locale& __loc,
2303 money_base::pattern& __pat,
2304 char_type& __dp,
2305 char_type& __ts,
2306 string& __grp,
2307 string_type& __sym,
2308 string_type& __psn,
2309 string_type& __nsn,
2310 int& __fd) {
2311 if (__intl) {
2312 const moneypunct<char_type, true>& __mp = std::use_facet<moneypunct<char_type, true> >(__loc);
2313 __pat = __mp.neg_format();
2314 __nsn = __mp.negative_sign();
2315 __psn = __mp.positive_sign();
2316 __dp = __mp.decimal_point();
2317 __ts = __mp.thousands_sep();
2318 __grp = __mp.grouping();
2319 __sym = __mp.curr_symbol();
2320 __fd = __mp.frac_digits();
2321 } else {
2322 const moneypunct<char_type, false>& __mp = std::use_facet<moneypunct<char_type, false> >(__loc);
2323 __pat = __mp.neg_format();
2324 __nsn = __mp.negative_sign();
2325 __psn = __mp.positive_sign();
2326 __dp = __mp.decimal_point();
2327 __ts = __mp.thousands_sep();
2328 __grp = __mp.grouping();
2329 __sym = __mp.curr_symbol();
2330 __fd = __mp.frac_digits();
2331 }
2332}
2333
2334extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<char>;
2335# if _LIBCPP_HAS_WIDE_CHARACTERS
2336extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<wchar_t>;
2337# endif
2338
2339template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
2340class _LIBCPP_TEMPLATE_VIS money_get : public locale::facet, private __money_get<_CharT> {
2341public:
2342 typedef _CharT char_type;
2343 typedef _InputIterator iter_type;
2344 typedef basic_string<char_type> string_type;
2345
2346 _LIBCPP_HIDE_FROM_ABI explicit money_get(size_t __refs = 0) : locale::facet(__refs) {}
2347
2348 _LIBCPP_HIDE_FROM_ABI iter_type
2349 get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, long double& __v) const {
2350 return do_get(__b, __e, __intl, __iob, __err, __v);
2351 }
2352
2353 _LIBCPP_HIDE_FROM_ABI iter_type
2354 get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, string_type& __v) const {
2355 return do_get(__b, __e, __intl, __iob, __err, __v);
2356 }
2357
2358 static locale::id id;
2359
2360protected:
2361 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~money_get() override {}
2362
2363 virtual iter_type
2364 do_get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, long double& __v) const;
2365 virtual iter_type
2366 do_get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, string_type& __v) const;
2367
2368private:
2369 static bool __do_get(
2370 iter_type& __b,
2371 iter_type __e,
2372 bool __intl,
2373 const locale& __loc,
2374 ios_base::fmtflags __flags,
2375 ios_base::iostate& __err,
2376 bool& __neg,
2377 const ctype<char_type>& __ct,
2378 unique_ptr<char_type, void (*)(void*)>& __wb,
2379 char_type*& __wn,
2380 char_type* __we);
2381};
2382
2383template <class _CharT, class _InputIterator>
2384locale::id money_get<_CharT, _InputIterator>::id;
2385
2386_LIBCPP_EXPORTED_FROM_ABI void __do_nothing(void*);
2387
2388template <class _Tp>
2389_LIBCPP_HIDE_FROM_ABI void __double_or_nothing(unique_ptr<_Tp, void (*)(void*)>& __b, _Tp*& __n, _Tp*& __e) {
2390 bool __owns = __b.get_deleter() != __do_nothing;
2391 size_t __cur_cap = static_cast<size_t>(__e - __b.get()) * sizeof(_Tp);
2392 size_t __new_cap = __cur_cap < numeric_limits<size_t>::max() / 2 ? 2 * __cur_cap : numeric_limits<size_t>::max();
2393 if (__new_cap == 0)
2394 __new_cap = sizeof(_Tp);
2395 size_t __n_off = static_cast<size_t>(__n - __b.get());
2396 _Tp* __t = (_Tp*)std::realloc(__owns ? __b.get() : 0, __new_cap);
2397 if (__t == 0)
2398 __throw_bad_alloc();
2399 if (__owns)
2400 __b.release();
2401 __b = unique_ptr<_Tp, void (*)(void*)>(__t, free);
2402 __new_cap /= sizeof(_Tp);
2403 __n = __b.get() + __n_off;
2404 __e = __b.get() + __new_cap;
2405}
2406
2407// true == success
2408template <class _CharT, class _InputIterator>
2409bool money_get<_CharT, _InputIterator>::__do_get(
2410 iter_type& __b,
2411 iter_type __e,
2412 bool __intl,
2413 const locale& __loc,
2414 ios_base::fmtflags __flags,
2415 ios_base::iostate& __err,
2416 bool& __neg,
2417 const ctype<char_type>& __ct,
2418 unique_ptr<char_type, void (*)(void*)>& __wb,
2419 char_type*& __wn,
2420 char_type* __we) {
2421 if (__b == __e) {
2422 __err |= ios_base::failbit;
2423 return false;
2424 }
2425 const unsigned __bz = 100;
2426 unsigned __gbuf[__bz];
2427 unique_ptr<unsigned, void (*)(void*)> __gb(__gbuf, __do_nothing);
2428 unsigned* __gn = __gb.get();
2429 unsigned* __ge = __gn + __bz;
2430 money_base::pattern __pat;
2431 char_type __dp;
2432 char_type __ts;
2433 string __grp;
2434 string_type __sym;
2435 string_type __psn;
2436 string_type __nsn;
2437 // Capture the spaces read into money_base::{space,none} so they
2438 // can be compared to initial spaces in __sym.
2439 string_type __spaces;
2440 int __fd;
2441 __money_get<_CharT>::__gather_info(__intl, __loc, __pat, __dp, __ts, __grp, __sym, __psn, __nsn, __fd);
2442 const string_type* __trailing_sign = 0;
2443 __wn = __wb.get();
2444 for (unsigned __p = 0; __p < 4 && __b != __e; ++__p) {
2445 switch (__pat.field[__p]) {
2446 case money_base::space:
2447 if (__p != 3) {
2448 if (__ct.is(ctype_base::space, *__b))
2449 __spaces.push_back(*__b++);
2450 else {
2451 __err |= ios_base::failbit;
2452 return false;
2453 }
2454 }
2455 _LIBCPP_FALLTHROUGH();
2456 case money_base::none:
2457 if (__p != 3) {
2458 while (__b != __e && __ct.is(ctype_base::space, *__b))
2459 __spaces.push_back(*__b++);
2460 }
2461 break;
2462 case money_base::sign:
2463 if (__psn.size() > 0 && *__b == __psn[0]) {
2464 ++__b;
2465 __neg = false;
2466 if (__psn.size() > 1)
2467 __trailing_sign = &__psn;
2468 break;
2469 }
2470 if (__nsn.size() > 0 && *__b == __nsn[0]) {
2471 ++__b;
2472 __neg = true;
2473 if (__nsn.size() > 1)
2474 __trailing_sign = &__nsn;
2475 break;
2476 }
2477 if (__psn.size() > 0 && __nsn.size() > 0) { // sign is required
2478 __err |= ios_base::failbit;
2479 return false;
2480 }
2481 if (__psn.size() == 0 && __nsn.size() == 0)
2482 // locale has no way of specifying a sign. Use the initial value of __neg as a default
2483 break;
2484 __neg = (__nsn.size() == 0);
2485 break;
2486 case money_base::symbol: {
2487 bool __more_needed =
2488 __trailing_sign || (__p < 2) || (__p == 2 && __pat.field[3] != static_cast<char>(money_base::none));
2489 bool __sb = (__flags & ios_base::showbase) != 0;
2490 if (__sb || __more_needed) {
2491 typename string_type::const_iterator __sym_space_end = __sym.begin();
2492 if (__p > 0 && (__pat.field[__p - 1] == money_base::none || __pat.field[__p - 1] == money_base::space)) {
2493 // Match spaces we've already read against spaces at
2494 // the beginning of __sym.
2495 while (__sym_space_end != __sym.end() && __ct.is(ctype_base::space, *__sym_space_end))
2496 ++__sym_space_end;
2497 const size_t __num_spaces = __sym_space_end - __sym.begin();
2498 if (__num_spaces > __spaces.size() ||
2499 !std::equal(__spaces.end() - __num_spaces, __spaces.end(), __sym.begin())) {
2500 // No match. Put __sym_space_end back at the
2501 // beginning of __sym, which will prevent a
2502 // match in the next loop.
2503 __sym_space_end = __sym.begin();
2504 }
2505 }
2506 typename string_type::const_iterator __sym_curr_char = __sym_space_end;
2507 while (__sym_curr_char != __sym.end() && __b != __e && *__b == *__sym_curr_char) {
2508 ++__b;
2509 ++__sym_curr_char;
2510 }
2511 if (__sb && __sym_curr_char != __sym.end()) {
2512 __err |= ios_base::failbit;
2513 return false;
2514 }
2515 }
2516 } break;
2517 case money_base::value: {
2518 unsigned __ng = 0;
2519 for (; __b != __e; ++__b) {
2520 char_type __c = *__b;
2521 if (__ct.is(ctype_base::digit, __c)) {
2522 if (__wn == __we)
2523 std::__double_or_nothing(__wb, __wn, __we);
2524 *__wn++ = __c;
2525 ++__ng;
2526 } else if (__grp.size() > 0 && __ng > 0 && __c == __ts) {
2527 if (__gn == __ge)
2528 std::__double_or_nothing(__gb, __gn, __ge);
2529 *__gn++ = __ng;
2530 __ng = 0;
2531 } else
2532 break;
2533 }
2534 if (__gb.get() != __gn && __ng > 0) {
2535 if (__gn == __ge)
2536 std::__double_or_nothing(__gb, __gn, __ge);
2537 *__gn++ = __ng;
2538 }
2539 if (__fd > 0) {
2540 if (__b == __e || *__b != __dp) {
2541 __err |= ios_base::failbit;
2542 return false;
2543 }
2544 for (++__b; __fd > 0; --__fd, ++__b) {
2545 if (__b == __e || !__ct.is(ctype_base::digit, *__b)) {
2546 __err |= ios_base::failbit;
2547 return false;
2548 }
2549 if (__wn == __we)
2550 std::__double_or_nothing(__wb, __wn, __we);
2551 *__wn++ = *__b;
2552 }
2553 }
2554 if (__wn == __wb.get()) {
2555 __err |= ios_base::failbit;
2556 return false;
2557 }
2558 } break;
2559 }
2560 }
2561 if (__trailing_sign) {
2562 for (unsigned __i = 1; __i < __trailing_sign->size(); ++__i, ++__b) {
2563 if (__b == __e || *__b != (*__trailing_sign)[__i]) {
2564 __err |= ios_base::failbit;
2565 return false;
2566 }
2567 }
2568 }
2569 if (__gb.get() != __gn) {
2570 ios_base::iostate __et = ios_base::goodbit;
2571 __check_grouping(__grp, __gb.get(), __gn, __et);
2572 if (__et) {
2573 __err |= ios_base::failbit;
2574 return false;
2575 }
2576 }
2577 return true;
2578}
2579
2580template <class _CharT, class _InputIterator>
2581_InputIterator money_get<_CharT, _InputIterator>::do_get(
2582 iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, long double& __v) const {
2583 const int __bz = 100;
2584 char_type __wbuf[__bz];
2585 unique_ptr<char_type, void (*)(void*)> __wb(__wbuf, __do_nothing);
2586 char_type* __wn;
2587 char_type* __we = __wbuf + __bz;
2588 locale __loc = __iob.getloc();
2589 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc);
2590 bool __neg = false;
2591 if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct, __wb, __wn, __we)) {
2592 const char __src[] = "0123456789";
2593 char_type __atoms[sizeof(__src) - 1];
2594 __ct.widen(__src, __src + (sizeof(__src) - 1), __atoms);
2595 char __nbuf[__bz];
2596 char* __nc = __nbuf;
2597 unique_ptr<char, void (*)(void*)> __h(nullptr, free);
2598 if (__wn - __wb.get() > __bz - 2) {
2599 __h.reset((char*)malloc(static_cast<size_t>(__wn - __wb.get() + 2)));
2600 if (__h.get() == nullptr)
2601 __throw_bad_alloc();
2602 __nc = __h.get();
2603 }
2604 if (__neg)
2605 *__nc++ = '-';
2606 for (const char_type* __w = __wb.get(); __w < __wn; ++__w, ++__nc)
2607 *__nc = __src[std::find(__atoms, std::end(__atoms), *__w) - __atoms];
2608 *__nc = char();
2609 if (sscanf(__nbuf, "%Lf", &__v) != 1)
2610 __throw_runtime_error("money_get error");
2611 }
2612 if (__b == __e)
2613 __err |= ios_base::eofbit;
2614 return __b;
2615}
2616
2617template <class _CharT, class _InputIterator>
2618_InputIterator money_get<_CharT, _InputIterator>::do_get(
2619 iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, string_type& __v) const {
2620 const int __bz = 100;
2621 char_type __wbuf[__bz];
2622 unique_ptr<char_type, void (*)(void*)> __wb(__wbuf, __do_nothing);
2623 char_type* __wn;
2624 char_type* __we = __wbuf + __bz;
2625 locale __loc = __iob.getloc();
2626 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc);
2627 bool __neg = false;
2628 if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct, __wb, __wn, __we)) {
2629 __v.clear();
2630 if (__neg)
2631 __v.push_back(__ct.widen('-'));
2632 char_type __z = __ct.widen('0');
2633 char_type* __w;
2634 for (__w = __wb.get(); __w < __wn - 1; ++__w)
2635 if (*__w != __z)
2636 break;
2637 __v.append(__w, __wn);
2638 }
2639 if (__b == __e)
2640 __err |= ios_base::eofbit;
2641 return __b;
2642}
2643
2644extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<char>;
2645# if _LIBCPP_HAS_WIDE_CHARACTERS
2646extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<wchar_t>;
2647# endif
2648
2649// money_put
2650
2651template <class _CharT>
2652class __money_put {
2653protected:
2654 typedef _CharT char_type;
2655 typedef basic_string<char_type> string_type;
2656
2657 _LIBCPP_HIDE_FROM_ABI __money_put() {}
2658
2659 static void __gather_info(
2660 bool __intl,
2661 bool __neg,
2662 const locale& __loc,
2663 money_base::pattern& __pat,
2664 char_type& __dp,
2665 char_type& __ts,
2666 string& __grp,
2667 string_type& __sym,
2668 string_type& __sn,
2669 int& __fd);
2670 static void __format(
2671 char_type* __mb,
2672 char_type*& __mi,
2673 char_type*& __me,
2674 ios_base::fmtflags __flags,
2675 const char_type* __db,
2676 const char_type* __de,
2677 const ctype<char_type>& __ct,
2678 bool __neg,
2679 const money_base::pattern& __pat,
2680 char_type __dp,
2681 char_type __ts,
2682 const string& __grp,
2683 const string_type& __sym,
2684 const string_type& __sn,
2685 int __fd);
2686};
2687
2688template <class _CharT>
2689void __money_put<_CharT>::__gather_info(
2690 bool __intl,
2691 bool __neg,
2692 const locale& __loc,
2693 money_base::pattern& __pat,
2694 char_type& __dp,
2695 char_type& __ts,
2696 string& __grp,
2697 string_type& __sym,
2698 string_type& __sn,
2699 int& __fd) {
2700 if (__intl) {
2701 const moneypunct<char_type, true>& __mp = std::use_facet<moneypunct<char_type, true> >(__loc);
2702 if (__neg) {
2703 __pat = __mp.neg_format();
2704 __sn = __mp.negative_sign();
2705 } else {
2706 __pat = __mp.pos_format();
2707 __sn = __mp.positive_sign();
2708 }
2709 __dp = __mp.decimal_point();
2710 __ts = __mp.thousands_sep();
2711 __grp = __mp.grouping();
2712 __sym = __mp.curr_symbol();
2713 __fd = __mp.frac_digits();
2714 } else {
2715 const moneypunct<char_type, false>& __mp = std::use_facet<moneypunct<char_type, false> >(__loc);
2716 if (__neg) {
2717 __pat = __mp.neg_format();
2718 __sn = __mp.negative_sign();
2719 } else {
2720 __pat = __mp.pos_format();
2721 __sn = __mp.positive_sign();
2722 }
2723 __dp = __mp.decimal_point();
2724 __ts = __mp.thousands_sep();
2725 __grp = __mp.grouping();
2726 __sym = __mp.curr_symbol();
2727 __fd = __mp.frac_digits();
2728 }
2729}
2730
2731template <class _CharT>
2732void __money_put<_CharT>::__format(
2733 char_type* __mb,
2734 char_type*& __mi,
2735 char_type*& __me,
2736 ios_base::fmtflags __flags,
2737 const char_type* __db,
2738 const char_type* __de,
2739 const ctype<char_type>& __ct,
2740 bool __neg,
2741 const money_base::pattern& __pat,
2742 char_type __dp,
2743 char_type __ts,
2744 const string& __grp,
2745 const string_type& __sym,
2746 const string_type& __sn,
2747 int __fd) {
2748 __me = __mb;
2749 for (char __p : __pat.field) {
2750 switch (__p) {
2751 case money_base::none:
2752 __mi = __me;
2753 break;
2754 case money_base::space:
2755 __mi = __me;
2756 *__me++ = __ct.widen(' ');
2757 break;
2758 case money_base::sign:
2759 if (!__sn.empty())
2760 *__me++ = __sn[0];
2761 break;
2762 case money_base::symbol:
2763 if (!__sym.empty() && (__flags & ios_base::showbase))
2764 __me = std::copy(__sym.begin(), __sym.end(), __me);
2765 break;
2766 case money_base::value: {
2767 // remember start of value so we can reverse it
2768 char_type* __t = __me;
2769 // find beginning of digits
2770 if (__neg)
2771 ++__db;
2772 // find end of digits
2773 const char_type* __d;
2774 for (__d = __db; __d < __de; ++__d)
2775 if (!__ct.is(ctype_base::digit, *__d))
2776 break;
2777 // print fractional part
2778 if (__fd > 0) {
2779 int __f;
2780 for (__f = __fd; __d > __db && __f > 0; --__f)
2781 *__me++ = *--__d;
2782 char_type __z = __f > 0 ? __ct.widen('0') : char_type();
2783 for (; __f > 0; --__f)
2784 *__me++ = __z;
2785 *__me++ = __dp;
2786 }
2787 // print units part
2788 if (__d == __db) {
2789 *__me++ = __ct.widen('0');
2790 } else {
2791 unsigned __ng = 0;
2792 unsigned __ig = 0;
2793 unsigned __gl = __grp.empty() ? numeric_limits<unsigned>::max() : static_cast<unsigned>(__grp[__ig]);
2794 while (__d != __db) {
2795 if (__ng == __gl) {
2796 *__me++ = __ts;
2797 __ng = 0;
2798 if (++__ig < __grp.size())
2799 __gl = __grp[__ig] == numeric_limits<char>::max()
2800 ? numeric_limits<unsigned>::max()
2801 : static_cast<unsigned>(__grp[__ig]);
2802 }
2803 *__me++ = *--__d;
2804 ++__ng;
2805 }
2806 }
2807 // reverse it
2808 std::reverse(__t, __me);
2809 } break;
2810 }
2811 }
2812 // print rest of sign, if any
2813 if (__sn.size() > 1)
2814 __me = std::copy(__sn.begin() + 1, __sn.end(), __me);
2815 // set alignment
2816 if ((__flags & ios_base::adjustfield) == ios_base::left)
2817 __mi = __me;
2818 else if ((__flags & ios_base::adjustfield) != ios_base::internal)
2819 __mi = __mb;
2820}
2821
2822extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<char>;
2823# if _LIBCPP_HAS_WIDE_CHARACTERS
2824extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<wchar_t>;
2825# endif
2826
2827template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
2828class _LIBCPP_TEMPLATE_VIS money_put : public locale::facet, private __money_put<_CharT> {
2829public:
2830 typedef _CharT char_type;
2831 typedef _OutputIterator iter_type;
2832 typedef basic_string<char_type> string_type;
2833
2834 _LIBCPP_HIDE_FROM_ABI explicit money_put(size_t __refs = 0) : locale::facet(__refs) {}
2835
2836 _LIBCPP_HIDE_FROM_ABI iter_type
2837 put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, long double __units) const {
2838 return do_put(__s, __intl, __iob, __fl, __units);
2839 }
2840
2841 _LIBCPP_HIDE_FROM_ABI iter_type
2842 put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, const string_type& __digits) const {
2843 return do_put(__s, __intl, __iob, __fl, __digits);
2844 }
2845
2846 static locale::id id;
2847
2848protected:
2849 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~money_put() override {}
2850
2851 virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, long double __units) const;
2852 virtual iter_type
2853 do_put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, const string_type& __digits) const;
2854};
2855
2856template <class _CharT, class _OutputIterator>
2857locale::id money_put<_CharT, _OutputIterator>::id;
2858
2859template <class _CharT, class _OutputIterator>
2860_OutputIterator money_put<_CharT, _OutputIterator>::do_put(
2861 iter_type __s, bool __intl, ios_base& __iob, char_type __fl, long double __units) const {
2862 // convert to char
2863 const size_t __bs = 100;
2864 char __buf[__bs];
2865 char* __bb = __buf;
2866 char_type __digits[__bs];
2867 char_type* __db = __digits;
2868 int __n = snprintf(__bb, __bs, "%.0Lf", __units);
2869 unique_ptr<char, void (*)(void*)> __hn(nullptr, free);
2870 unique_ptr<char_type, void (*)(void*)> __hd(0, free);
2871 // secure memory for digit storage
2872 if (static_cast<size_t>(__n) > __bs - 1) {
2873 __n = __locale::__asprintf(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units);
2874 if (__n == -1)
2875 __throw_bad_alloc();
2876 __hn.reset(__bb);
2877 __hd.reset((char_type*)malloc(static_cast<size_t>(__n) * sizeof(char_type)));
2878 if (__hd == nullptr)
2879 __throw_bad_alloc();
2880 __db = __hd.get();
2881 }
2882 // gather info
2883 locale __loc = __iob.getloc();
2884 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc);
2885 __ct.widen(__bb, __bb + __n, __db);
2886 bool __neg = __n > 0 && __bb[0] == '-';
2887 money_base::pattern __pat;
2888 char_type __dp;
2889 char_type __ts;
2890 string __grp;
2891 string_type __sym;
2892 string_type __sn;
2893 int __fd;
2894 this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
2895 // secure memory for formatting
2896 char_type __mbuf[__bs];
2897 char_type* __mb = __mbuf;
2898 unique_ptr<char_type, void (*)(void*)> __hw(0, free);
2899 size_t __exn = __n > __fd ? (static_cast<size_t>(__n) - static_cast<size_t>(__fd)) * 2 + __sn.size() + __sym.size() +
2900 static_cast<size_t>(__fd) + 1
2901 : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2;
2902 if (__exn > __bs) {
2903 __hw.reset((char_type*)malloc(__exn * sizeof(char_type)));
2904 __mb = __hw.get();
2905 if (__mb == 0)
2906 __throw_bad_alloc();
2907 }
2908 // format
2909 char_type* __mi;
2910 char_type* __me;
2911 this->__format(
2912 __mb, __mi, __me, __iob.flags(), __db, __db + __n, __ct, __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
2913 return std::__pad_and_output(__s, __mb, __mi, __me, __iob, __fl);
2914}
2915
2916template <class _CharT, class _OutputIterator>
2917_OutputIterator money_put<_CharT, _OutputIterator>::do_put(
2918 iter_type __s, bool __intl, ios_base& __iob, char_type __fl, const string_type& __digits) const {
2919 // gather info
2920 locale __loc = __iob.getloc();
2921 const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc);
2922 bool __neg = __digits.size() > 0 && __digits[0] == __ct.widen('-');
2923 money_base::pattern __pat;
2924 char_type __dp;
2925 char_type __ts;
2926 string __grp;
2927 string_type __sym;
2928 string_type __sn;
2929 int __fd;
2930 this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
2931 // secure memory for formatting
2932 char_type __mbuf[100];
2933 char_type* __mb = __mbuf;
2934 unique_ptr<char_type, void (*)(void*)> __h(0, free);
2935 size_t __exn =
2936 static_cast<int>(__digits.size()) > __fd
2937 ? (__digits.size() - static_cast<size_t>(__fd)) * 2 + __sn.size() + __sym.size() + static_cast<size_t>(__fd) +
2938 1
2939 : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2;
2940 if (__exn > 100) {
2941 __h.reset((char_type*)malloc(__exn * sizeof(char_type)));
2942 __mb = __h.get();
2943 if (__mb == 0)
2944 __throw_bad_alloc();
2945 }
2946 // format
2947 char_type* __mi;
2948 char_type* __me;
2949 this->__format(
2950 __mb,
2951 __mi,
2952 __me,
2953 __iob.flags(),
2954 __digits.data(),
2955 __digits.data() + __digits.size(),
2956 __ct,
2957 __neg,
2958 __pat,
2959 __dp,
2960 __ts,
2961 __grp,
2962 __sym,
2963 __sn,
2964 __fd);
2965 return std::__pad_and_output(__s, __mb, __mi, __me, __iob, __fl);
2966}
2967
2968extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<char>;
2969# if _LIBCPP_HAS_WIDE_CHARACTERS
2970extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<wchar_t>;
2971# endif
2972
2973// messages
2974
2975class _LIBCPP_EXPORTED_FROM_ABI messages_base {
2976public:
2977 typedef intptr_t catalog;
2978
2979 _LIBCPP_HIDE_FROM_ABI messages_base() {}
2980};
2981
2982template <class _CharT>
2983class _LIBCPP_TEMPLATE_VIS messages : public locale::facet, public messages_base {
2984public:
2985 typedef _CharT char_type;
2986 typedef basic_string<_CharT> string_type;
2987
2988 _LIBCPP_HIDE_FROM_ABI explicit messages(size_t __refs = 0) : locale::facet(__refs) {}
2989
2990 _LIBCPP_HIDE_FROM_ABI catalog open(const basic_string<char>& __nm, const locale& __loc) const {
2991 return do_open(__nm, __loc);
2992 }
2993
2994 _LIBCPP_HIDE_FROM_ABI string_type get(catalog __c, int __set, int __msgid, const string_type& __dflt) const {
2995 return do_get(__c, __set, __msgid, __dflt);
2996 }
2997
2998 _LIBCPP_HIDE_FROM_ABI void close(catalog __c) const { do_close(__c); }
2999
3000 static locale::id id;
3001
3002protected:
3003 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~messages() override {}
3004
3005 virtual catalog do_open(const basic_string<char>&, const locale&) const;
3006 virtual string_type do_get(catalog, int __set, int __msgid, const string_type& __dflt) const;
3007 virtual void do_close(catalog) const;
3008};
3009
3010template <class _CharT>
3011locale::id messages<_CharT>::id;
3012
3013template <class _CharT>
3014typename messages<_CharT>::catalog messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const {
3015# if _LIBCPP_HAS_CATOPEN
3016 return (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE);
3017# else // !_LIBCPP_HAS_CATOPEN
3018 (void)__nm;
3019 return -1;
3020# endif // _LIBCPP_HAS_CATOPEN
3021}
3022
3023template <class _CharT>
3024typename messages<_CharT>::string_type
3025messages<_CharT>::do_get(catalog __c, int __set, int __msgid, const string_type& __dflt) const {
3026# if _LIBCPP_HAS_CATOPEN
3027 string __ndflt;
3028 __narrow_to_utf8<sizeof(char_type) * __CHAR_BIT__>()(
3029 std::back_inserter(__ndflt), __dflt.c_str(), __dflt.c_str() + __dflt.size());
3030 nl_catd __cat = (nl_catd)__c;
3031 static_assert(sizeof(catalog) >= sizeof(nl_catd), "Unexpected nl_catd type");
3032 char* __n = catgets(__cat, __set, __msgid, __ndflt.c_str());
3033 string_type __w;
3034 __widen_from_utf8<sizeof(char_type) * __CHAR_BIT__>()(std::back_inserter(__w), __n, __n + std::strlen(__n));
3035 return __w;
3036# else // !_LIBCPP_HAS_CATOPEN
3037 (void)__c;
3038 (void)__set;
3039 (void)__msgid;
3040 return __dflt;
3041# endif // _LIBCPP_HAS_CATOPEN
3042}
3043
3044template <class _CharT>
3045void messages<_CharT>::do_close(catalog __c) const {
3046# if _LIBCPP_HAS_CATOPEN
3047 catclose((nl_catd)__c);
3048# else // !_LIBCPP_HAS_CATOPEN
3049 (void)__c;
3050# endif // _LIBCPP_HAS_CATOPEN
3051}
3052
3053extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<char>;
3054# if _LIBCPP_HAS_WIDE_CHARACTERS
3055extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<wchar_t>;
3056# endif
3057
3058template <class _CharT>
3059class _LIBCPP_TEMPLATE_VIS messages_byname : public messages<_CharT> {
3060public:
3061 typedef messages_base::catalog catalog;
3062 typedef basic_string<_CharT> string_type;
3063
3064 _LIBCPP_HIDE_FROM_ABI explicit messages_byname(const char*, size_t __refs = 0) : messages<_CharT>(__refs) {}
3065
3066 _LIBCPP_HIDE_FROM_ABI explicit messages_byname(const string&, size_t __refs = 0) : messages<_CharT>(__refs) {}
3067
3068protected:
3069 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~messages_byname() override {}
3070};
3071
3072extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<char>;
3073# if _LIBCPP_HAS_WIDE_CHARACTERS
3074extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<wchar_t>;
3075# endif
3076
3077# if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT)
3078
3079template <class _Codecvt,
3080 class _Elem = wchar_t,
3081 class _WideAlloc = allocator<_Elem>,
3082 class _ByteAlloc = allocator<char> >
3083class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 wstring_convert {
3084public:
3085 typedef basic_string<char, char_traits<char>, _ByteAlloc> byte_string;
3086 typedef basic_string<_Elem, char_traits<_Elem>, _WideAlloc> wide_string;
3087 typedef typename _Codecvt::state_type state_type;
3088 typedef typename wide_string::traits_type::int_type int_type;
3089
3090private:
3091 byte_string __byte_err_string_;
3092 wide_string __wide_err_string_;
3093 _Codecvt* __cvtptr_;
3094 state_type __cvtstate_;
3095 size_t __cvtcount_;
3096
3097public:
3098# ifndef _LIBCPP_CXX03_LANG
3099 _LIBCPP_HIDE_FROM_ABI wstring_convert() : wstring_convert(new _Codecvt) {}
3100 _LIBCPP_HIDE_FROM_ABI explicit wstring_convert(_Codecvt* __pcvt);
3101# else
3102 _LIBCPP_HIDE_FROM_ABI _LIBCPP_EXPLICIT_SINCE_CXX14 wstring_convert(_Codecvt* __pcvt = new _Codecvt);
3103# endif
3104
3105 _LIBCPP_HIDE_FROM_ABI wstring_convert(_Codecvt* __pcvt, state_type __state);
3106 _LIBCPP_EXPLICIT_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
3107 wstring_convert(const byte_string& __byte_err, const wide_string& __wide_err = wide_string());
3108# ifndef _LIBCPP_CXX03_LANG
3109 _LIBCPP_HIDE_FROM_ABI wstring_convert(wstring_convert&& __wc);
3110# endif
3111 _LIBCPP_HIDE_FROM_ABI ~wstring_convert();
3112
3113 wstring_convert(const wstring_convert& __wc) = delete;
3114 wstring_convert& operator=(const wstring_convert& __wc) = delete;
3115
3116 _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(char __byte) { return from_bytes(&__byte, &__byte + 1); }
3117 _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const char* __ptr) {
3118 return from_bytes(__ptr, __ptr + char_traits<char>::length(__ptr));
3119 }
3120 _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const byte_string& __str) {
3121 return from_bytes(__str.data(), __str.data() + __str.size());
3122 }
3123 _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const char* __first, const char* __last);
3124
3125 _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(_Elem __wchar) { return to_bytes(&__wchar, &__wchar + 1); }
3126 _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const _Elem* __wptr) {
3127 return to_bytes(__wptr, __wptr + char_traits<_Elem>::length(__wptr));
3128 }
3129 _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const wide_string& __wstr) {
3130 return to_bytes(__wstr.data(), __wstr.data() + __wstr.size());
3131 }
3132 _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const _Elem* __first, const _Elem* __last);
3133
3134 _LIBCPP_HIDE_FROM_ABI size_t converted() const _NOEXCEPT { return __cvtcount_; }
3135 _LIBCPP_HIDE_FROM_ABI state_type state() const { return __cvtstate_; }
3136};
3137
3138_LIBCPP_SUPPRESS_DEPRECATED_PUSH
3139template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3140inline wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert(_Codecvt* __pcvt)
3141 : __cvtptr_(__pcvt), __cvtstate_(), __cvtcount_(0) {}
3142_LIBCPP_SUPPRESS_DEPRECATED_POP
3143
3144template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3145inline wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert(_Codecvt* __pcvt, state_type __state)
3146 : __cvtptr_(__pcvt), __cvtstate_(__state), __cvtcount_(0) {}
3147
3148template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3149wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert(
3150 const byte_string& __byte_err, const wide_string& __wide_err)
3151 : __byte_err_string_(__byte_err), __wide_err_string_(__wide_err), __cvtstate_(), __cvtcount_(0) {
3152 __cvtptr_ = new _Codecvt;
3153}
3154
3155# ifndef _LIBCPP_CXX03_LANG
3156
3157template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3158inline wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert(wstring_convert&& __wc)
3159 : __byte_err_string_(std::move(__wc.__byte_err_string_)),
3160 __wide_err_string_(std::move(__wc.__wide_err_string_)),
3161 __cvtptr_(__wc.__cvtptr_),
3162 __cvtstate_(__wc.__cvtstate_),
3163 __cvtcount_(__wc.__cvtcount_) {
3164 __wc.__cvtptr_ = nullptr;
3165}
3166
3167# endif // _LIBCPP_CXX03_LANG
3168
3169_LIBCPP_SUPPRESS_DEPRECATED_PUSH
3170template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3171wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::~wstring_convert() {
3172 delete __cvtptr_;
3173}
3174
3175template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3176typename wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wide_string
3177wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::from_bytes(const char* __frm, const char* __frm_end) {
3178 _LIBCPP_SUPPRESS_DEPRECATED_POP
3179 __cvtcount_ = 0;
3180 if (__cvtptr_ != nullptr) {
3181 wide_string __ws(2 * (__frm_end - __frm), _Elem());
3182 if (__frm != __frm_end)
3183 __ws.resize(__ws.capacity());
3184 codecvt_base::result __r = codecvt_base::ok;
3185 state_type __st = __cvtstate_;
3186 if (__frm != __frm_end) {
3187 _Elem* __to = &__ws[0];
3188 _Elem* __to_end = __to + __ws.size();
3189 const char* __frm_nxt;
3190 do {
3191 _Elem* __to_nxt;
3192 __r = __cvtptr_->in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
3193 __cvtcount_ += __frm_nxt - __frm;
3194 if (__frm_nxt == __frm) {
3195 __r = codecvt_base::error;
3196 } else if (__r == codecvt_base::noconv) {
3197 __ws.resize(__to - &__ws[0]);
3198 // This only gets executed if _Elem is char
3199 __ws.append((const _Elem*)__frm, (const _Elem*)__frm_end);
3200 __frm = __frm_nxt;
3201 __r = codecvt_base::ok;
3202 } else if (__r == codecvt_base::ok) {
3203 __ws.resize(__to_nxt - &__ws[0]);
3204 __frm = __frm_nxt;
3205 } else if (__r == codecvt_base::partial) {
3206 ptrdiff_t __s = __to_nxt - &__ws[0];
3207 __ws.resize(2 * __s);
3208 __to = &__ws[0] + __s;
3209 __to_end = &__ws[0] + __ws.size();
3210 __frm = __frm_nxt;
3211 }
3212 } while (__r == codecvt_base::partial && __frm_nxt < __frm_end);
3213 }
3214 if (__r == codecvt_base::ok)
3215 return __ws;
3216 }
3217
3218 if (__wide_err_string_.empty())
3219 __throw_range_error("wstring_convert: from_bytes error");
3220
3221 return __wide_err_string_;
3222}
3223
3224template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc>
3225typename wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::byte_string
3226wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::to_bytes(const _Elem* __frm, const _Elem* __frm_end) {
3227 __cvtcount_ = 0;
3228 if (__cvtptr_ != nullptr) {
3229 byte_string __bs(2 * (__frm_end - __frm), char());
3230 if (__frm != __frm_end)
3231 __bs.resize(__bs.capacity());
3232 codecvt_base::result __r = codecvt_base::ok;
3233 state_type __st = __cvtstate_;
3234 if (__frm != __frm_end) {
3235 char* __to = &__bs[0];
3236 char* __to_end = __to + __bs.size();
3237 const _Elem* __frm_nxt;
3238 do {
3239 char* __to_nxt;
3240 __r = __cvtptr_->out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
3241 __cvtcount_ += __frm_nxt - __frm;
3242 if (__frm_nxt == __frm) {
3243 __r = codecvt_base::error;
3244 } else if (__r == codecvt_base::noconv) {
3245 __bs.resize(__to - &__bs[0]);
3246 // This only gets executed if _Elem is char
3247 __bs.append((const char*)__frm, (const char*)__frm_end);
3248 __frm = __frm_nxt;
3249 __r = codecvt_base::ok;
3250 } else if (__r == codecvt_base::ok) {
3251 __bs.resize(__to_nxt - &__bs[0]);
3252 __frm = __frm_nxt;
3253 } else if (__r == codecvt_base::partial) {
3254 ptrdiff_t __s = __to_nxt - &__bs[0];
3255 __bs.resize(2 * __s);
3256 __to = &__bs[0] + __s;
3257 __to_end = &__bs[0] + __bs.size();
3258 __frm = __frm_nxt;
3259 }
3260 } while (__r == codecvt_base::partial && __frm_nxt < __frm_end);
3261 }
3262 if (__r == codecvt_base::ok) {
3263 size_t __s = __bs.size();
3264 __bs.resize(__bs.capacity());
3265 char* __to = &__bs[0] + __s;
3266 char* __to_end = __to + __bs.size();
3267 do {
3268 char* __to_nxt;
3269 __r = __cvtptr_->unshift(__st, __to, __to_end, __to_nxt);
3270 if (__r == codecvt_base::noconv) {
3271 __bs.resize(__to - &__bs[0]);
3272 __r = codecvt_base::ok;
3273 } else if (__r == codecvt_base::ok) {
3274 __bs.resize(__to_nxt - &__bs[0]);
3275 } else if (__r == codecvt_base::partial) {
3276 ptrdiff_t __sp = __to_nxt - &__bs[0];
3277 __bs.resize(2 * __sp);
3278 __to = &__bs[0] + __sp;
3279 __to_end = &__bs[0] + __bs.size();
3280 }
3281 } while (__r == codecvt_base::partial);
3282 if (__r == codecvt_base::ok)
3283 return __bs;
3284 }
3285 }
3286
3287 if (__byte_err_string_.empty())
3288 __throw_range_error("wstring_convert: to_bytes error");
3289
3290 return __byte_err_string_;
3291}
3292
3293template <class _Codecvt, class _Elem = wchar_t, class _Tr = char_traits<_Elem> >
3294class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 wbuffer_convert : public basic_streambuf<_Elem, _Tr> {
3295public:
3296 // types:
3297 typedef _Elem char_type;
3298 typedef _Tr traits_type;
3299 typedef typename traits_type::int_type int_type;
3300 typedef typename traits_type::pos_type pos_type;
3301 typedef typename traits_type::off_type off_type;
3302 typedef typename _Codecvt::state_type state_type;
3303
3304private:
3305 char* __extbuf_;
3306 const char* __extbufnext_;
3307 const char* __extbufend_;
3308 char __extbuf_min_[8];
3309 size_t __ebs_;
3310 char_type* __intbuf_;
3311 size_t __ibs_;
3312 streambuf* __bufptr_;
3313 _Codecvt* __cv_;
3314 state_type __st_;
3315 ios_base::openmode __cm_;
3316 bool __owns_eb_;
3317 bool __owns_ib_;
3318 bool __always_noconv_;
3319
3320public:
3321# ifndef _LIBCPP_CXX03_LANG
3322 _LIBCPP_HIDE_FROM_ABI wbuffer_convert() : wbuffer_convert(nullptr) {}
3323 explicit _LIBCPP_HIDE_FROM_ABI
3324 wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt = new _Codecvt, state_type __state = state_type());
3325# else
3326 _LIBCPP_EXPLICIT_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
3327 wbuffer_convert(streambuf* __bytebuf = nullptr, _Codecvt* __pcvt = new _Codecvt, state_type __state = state_type());
3328# endif
3329
3330 _LIBCPP_HIDE_FROM_ABI ~wbuffer_convert();
3331
3332 _LIBCPP_HIDE_FROM_ABI streambuf* rdbuf() const { return __bufptr_; }
3333 _LIBCPP_HIDE_FROM_ABI streambuf* rdbuf(streambuf* __bytebuf) {
3334 streambuf* __r = __bufptr_;
3335 __bufptr_ = __bytebuf;
3336 return __r;
3337 }
3338
3339 wbuffer_convert(const wbuffer_convert&) = delete;
3340 wbuffer_convert& operator=(const wbuffer_convert&) = delete;
3341
3342 _LIBCPP_HIDE_FROM_ABI state_type state() const { return __st_; }
3343
3344protected:
3345 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int_type underflow();
3346 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int_type pbackfail(int_type __c = traits_type::eof());
3347 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int_type overflow(int_type __c = traits_type::eof());
3348 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* __s, streamsize __n);
3349 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual pos_type
3350 seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __wch = ios_base::in | ios_base::out);
3351 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual pos_type
3352 seekpos(pos_type __sp, ios_base::openmode __wch = ios_base::in | ios_base::out);
3353 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int sync();
3354
3355private:
3356 _LIBCPP_HIDE_FROM_ABI_VIRTUAL bool __read_mode();
3357 _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __write_mode();
3358 _LIBCPP_HIDE_FROM_ABI_VIRTUAL wbuffer_convert* __close();
3359};
3360
3361_LIBCPP_SUPPRESS_DEPRECATED_PUSH
3362template <class _Codecvt, class _Elem, class _Tr>
3363wbuffer_convert<_Codecvt, _Elem, _Tr>::wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt, state_type __state)
3364 : __extbuf_(nullptr),
3365 __extbufnext_(nullptr),
3366 __extbufend_(nullptr),
3367 __ebs_(0),
3368 __intbuf_(0),
3369 __ibs_(0),
3370 __bufptr_(__bytebuf),
3371 __cv_(__pcvt),
3372 __st_(__state),
3373 __cm_(0),
3374 __owns_eb_(false),
3375 __owns_ib_(false),
3376 __always_noconv_(__cv_ ? __cv_->always_noconv() : false) {
3377 setbuf(0, 4096);
3378}
3379
3380template <class _Codecvt, class _Elem, class _Tr>
3381wbuffer_convert<_Codecvt, _Elem, _Tr>::~wbuffer_convert() {
3382 __close();
3383 delete __cv_;
3384 if (__owns_eb_)
3385 delete[] __extbuf_;
3386 if (__owns_ib_)
3387 delete[] __intbuf_;
3388}
3389
3390template <class _Codecvt, class _Elem, class _Tr>
3391typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type wbuffer_convert<_Codecvt, _Elem, _Tr>::underflow() {
3392 _LIBCPP_SUPPRESS_DEPRECATED_POP
3393 if (__cv_ == 0 || __bufptr_ == nullptr)
3394 return traits_type::eof();
3395 bool __initial = __read_mode();
3396 char_type __1buf;
3397 if (this->gptr() == 0)
3398 this->setg(&__1buf, &__1buf + 1, &__1buf + 1);
3399 const size_t __unget_sz = __initial ? 0 : std::min<size_t>((this->egptr() - this->eback()) / 2, 4);
3400 int_type __c = traits_type::eof();
3401 if (this->gptr() == this->egptr()) {
3402 std::memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type));
3403 if (__always_noconv_) {
3404 streamsize __nmemb = static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz);
3405 __nmemb = __bufptr_->sgetn((char*)this->eback() + __unget_sz, __nmemb);
3406 if (__nmemb != 0) {
3407 this->setg(this->eback(), this->eback() + __unget_sz, this->eback() + __unget_sz + __nmemb);
3408 __c = *this->gptr();
3409 }
3410 } else {
3411 if (__extbufend_ != __extbufnext_) {
3412 _LIBCPP_ASSERT_NON_NULL(__extbufnext_ != nullptr, "underflow moving from nullptr");
3413 _LIBCPP_ASSERT_NON_NULL(__extbuf_ != nullptr, "underflow moving into nullptr");
3414 std::memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_);
3415 }
3416 __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_);
3417 __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_);
3418 streamsize __nmemb = std::min(static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz),
3419 static_cast<streamsize>(__extbufend_ - __extbufnext_));
3420 codecvt_base::result __r;
3421 // FIXME: Do we ever need to restore the state here?
3422 // state_type __svs = __st_;
3423 streamsize __nr = __bufptr_->sgetn(const_cast<char*>(__extbufnext_), __nmemb);
3424 if (__nr != 0) {
3425 __extbufend_ = __extbufnext_ + __nr;
3426 char_type* __inext;
3427 __r = __cv_->in(
3428 __st_, __extbuf_, __extbufend_, __extbufnext_, this->eback() + __unget_sz, this->egptr(), __inext);
3429 if (__r == codecvt_base::noconv) {
3430 this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)const_cast<char*>(__extbufend_));
3431 __c = *this->gptr();
3432 } else if (__inext != this->eback() + __unget_sz) {
3433 this->setg(this->eback(), this->eback() + __unget_sz, __inext);
3434 __c = *this->gptr();
3435 }
3436 }
3437 }
3438 } else
3439 __c = *this->gptr();
3440 if (this->eback() == &__1buf)
3441 this->setg(0, 0, 0);
3442 return __c;
3443}
3444
3445_LIBCPP_SUPPRESS_DEPRECATED_PUSH
3446template <class _Codecvt, class _Elem, class _Tr>
3447typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type
3448wbuffer_convert<_Codecvt, _Elem, _Tr>::pbackfail(int_type __c) {
3449 _LIBCPP_SUPPRESS_DEPRECATED_POP
3450 if (__cv_ != 0 && __bufptr_ && this->eback() < this->gptr()) {
3451 if (traits_type::eq_int_type(__c, traits_type::eof())) {
3452 this->gbump(-1);
3453 return traits_type::not_eof(__c);
3454 }
3455 if (traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) {
3456 this->gbump(-1);
3457 *this->gptr() = traits_type::to_char_type(__c);
3458 return __c;
3459 }
3460 }
3461 return traits_type::eof();
3462}
3463
3464_LIBCPP_SUPPRESS_DEPRECATED_PUSH
3465template <class _Codecvt, class _Elem, class _Tr>
3466typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type wbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c) {
3467 _LIBCPP_SUPPRESS_DEPRECATED_POP
3468 if (__cv_ == 0 || !__bufptr_)
3469 return traits_type::eof();
3470 __write_mode();
3471 char_type __1buf;
3472 char_type* __pb_save = this->pbase();
3473 char_type* __epb_save = this->epptr();
3474 if (!traits_type::eq_int_type(__c, traits_type::eof())) {
3475 if (this->pptr() == 0)
3476 this->setp(&__1buf, &__1buf + 1);
3477 *this->pptr() = traits_type::to_char_type(__c);
3478 this->pbump(1);
3479 }
3480 if (this->pptr() != this->pbase()) {
3481 if (__always_noconv_) {
3482 streamsize __nmemb = static_cast<streamsize>(this->pptr() - this->pbase());
3483 if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb)
3484 return traits_type::eof();
3485 } else {
3486 char* __extbe = __extbuf_;
3487 codecvt_base::result __r;
3488 do {
3489 const char_type* __e;
3490 __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, __extbuf_, __extbuf_ + __ebs_, __extbe);
3491 if (__e == this->pbase())
3492 return traits_type::eof();
3493 if (__r == codecvt_base::noconv) {
3494 streamsize __nmemb = static_cast<size_t>(this->pptr() - this->pbase());
3495 if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb)
3496 return traits_type::eof();
3497 } else if (__r == codecvt_base::ok || __r == codecvt_base::partial) {
3498 streamsize __nmemb = static_cast<size_t>(__extbe - __extbuf_);
3499 if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb)
3500 return traits_type::eof();
3501 if (__r == codecvt_base::partial) {
3502 this->setp(const_cast<char_type*>(__e), this->pptr());
3503 this->__pbump(this->epptr() - this->pbase());
3504 }
3505 } else
3506 return traits_type::eof();
3507 } while (__r == codecvt_base::partial);
3508 }
3509 this->setp(__pb_save, __epb_save);
3510 }
3511 return traits_type::not_eof(__c);
3512}
3513
3514_LIBCPP_SUPPRESS_DEPRECATED_PUSH
3515template <class _Codecvt, class _Elem, class _Tr>
3516basic_streambuf<_Elem, _Tr>* wbuffer_convert<_Codecvt, _Elem, _Tr>::setbuf(char_type* __s, streamsize __n) {
3517 _LIBCPP_SUPPRESS_DEPRECATED_POP
3518 this->setg(0, 0, 0);
3519 this->setp(0, 0);
3520 if (__owns_eb_)
3521 delete[] __extbuf_;
3522 if (__owns_ib_)
3523 delete[] __intbuf_;
3524 __ebs_ = __n;
3525 if (__ebs_ > sizeof(__extbuf_min_)) {
3526 if (__always_noconv_ && __s) {
3527 __extbuf_ = (char*)__s;
3528 __owns_eb_ = false;
3529 } else {
3530 __extbuf_ = new char[__ebs_];
3531 __owns_eb_ = true;
3532 }
3533 } else {
3534 __extbuf_ = __extbuf_min_;
3535 __ebs_ = sizeof(__extbuf_min_);
3536 __owns_eb_ = false;
3537 }
3538 if (!__always_noconv_) {
3539 __ibs_ = max<streamsize>(__n, sizeof(__extbuf_min_));
3540 if (__s && __ibs_ >= sizeof(__extbuf_min_)) {
3541 __intbuf_ = __s;
3542 __owns_ib_ = false;
3543 } else {
3544 __intbuf_ = new char_type[__ibs_];
3545 __owns_ib_ = true;
3546 }
3547 } else {
3548 __ibs_ = 0;
3549 __intbuf_ = 0;
3550 __owns_ib_ = false;
3551 }
3552 return this;
3553}
3554
3555_LIBCPP_SUPPRESS_DEPRECATED_PUSH
3556template <class _Codecvt, class _Elem, class _Tr>
3557typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type
3558wbuffer_convert<_Codecvt, _Elem, _Tr>::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __om) {
3559 int __width = __cv_->encoding();
3560 if (__cv_ == 0 || !__bufptr_ || (__width <= 0 && __off != 0) || sync())
3561 return pos_type(off_type(-1));
3562 // __width > 0 || __off == 0, now check __way
3563 if (__way != ios_base::beg && __way != ios_base::cur && __way != ios_base::end)
3564 return pos_type(off_type(-1));
3565 pos_type __r = __bufptr_->pubseekoff(__width * __off, __way, __om);
3566 __r.state(__st_);
3567 return __r;
3568}
3569
3570template <class _Codecvt, class _Elem, class _Tr>
3571typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type
3572wbuffer_convert<_Codecvt, _Elem, _Tr>::seekpos(pos_type __sp, ios_base::openmode __wch) {
3573 if (__cv_ == 0 || !__bufptr_ || sync())
3574 return pos_type(off_type(-1));
3575 if (__bufptr_->pubseekpos(__sp, __wch) == pos_type(off_type(-1)))
3576 return pos_type(off_type(-1));
3577 return __sp;
3578}
3579
3580template <class _Codecvt, class _Elem, class _Tr>
3581int wbuffer_convert<_Codecvt, _Elem, _Tr>::sync() {
3582 _LIBCPP_SUPPRESS_DEPRECATED_POP
3583 if (__cv_ == 0 || !__bufptr_)
3584 return 0;
3585 if (__cm_ & ios_base::out) {
3586 if (this->pptr() != this->pbase())
3587 if (overflow() == traits_type::eof())
3588 return -1;
3589 codecvt_base::result __r;
3590 do {
3591 char* __extbe;
3592 __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe);
3593 streamsize __nmemb = static_cast<streamsize>(__extbe - __extbuf_);
3594 if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb)
3595 return -1;
3596 } while (__r == codecvt_base::partial);
3597 if (__r == codecvt_base::error)
3598 return -1;
3599 if (__bufptr_->pubsync())
3600 return -1;
3601 } else if (__cm_ & ios_base::in) {
3602 off_type __c;
3603 if (__always_noconv_)
3604 __c = this->egptr() - this->gptr();
3605 else {
3606 int __width = __cv_->encoding();
3607 __c = __extbufend_ - __extbufnext_;
3608 if (__width > 0)
3609 __c += __width * (this->egptr() - this->gptr());
3610 else {
3611 if (this->gptr() != this->egptr()) {
3612 std::reverse(this->gptr(), this->egptr());
3613 codecvt_base::result __r;
3614 const char_type* __e = this->gptr();
3615 char* __extbe;
3616 do {
3617 __r = __cv_->out(__st_, __e, this->egptr(), __e, __extbuf_, __extbuf_ + __ebs_, __extbe);
3618 switch (__r) {
3619 case codecvt_base::noconv:
3620 __c += this->egptr() - this->gptr();
3621 break;
3622 case codecvt_base::ok:
3623 case codecvt_base::partial:
3624 __c += __extbe - __extbuf_;
3625 break;
3626 default:
3627 return -1;
3628 }
3629 } while (__r == codecvt_base::partial);
3630 }
3631 }
3632 }
3633 if (__bufptr_->pubseekoff(-__c, ios_base::cur, __cm_) == pos_type(off_type(-1)))
3634 return -1;
3635 this->setg(0, 0, 0);
3636 __cm_ = 0;
3637 }
3638 return 0;
3639}
3640
3641_LIBCPP_SUPPRESS_DEPRECATED_PUSH
3642template <class _Codecvt, class _Elem, class _Tr>
3643bool wbuffer_convert<_Codecvt, _Elem, _Tr>::__read_mode() {
3644 if (!(__cm_ & ios_base::in)) {
3645 this->setp(0, 0);
3646 if (__always_noconv_)
3647 this->setg((char_type*)__extbuf_, (char_type*)__extbuf_ + __ebs_, (char_type*)__extbuf_ + __ebs_);
3648 else
3649 this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_);
3650 __cm_ = ios_base::in;
3651 return true;
3652 }
3653 return false;
3654}
3655
3656template <class _Codecvt, class _Elem, class _Tr>
3657void wbuffer_convert<_Codecvt, _Elem, _Tr>::__write_mode() {
3658 if (!(__cm_ & ios_base::out)) {
3659 this->setg(0, 0, 0);
3660 if (__ebs_ > sizeof(__extbuf_min_)) {
3661 if (__always_noconv_)
3662 this->setp((char_type*)__extbuf_, (char_type*)__extbuf_ + (__ebs_ - 1));
3663 else
3664 this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1));
3665 } else
3666 this->setp(0, 0);
3667 __cm_ = ios_base::out;
3668 }
3669}
3670
3671template <class _Codecvt, class _Elem, class _Tr>
3672wbuffer_convert<_Codecvt, _Elem, _Tr>* wbuffer_convert<_Codecvt, _Elem, _Tr>::__close() {
3673 wbuffer_convert* __rt = nullptr;
3674 if (__cv_ != nullptr && __bufptr_ != nullptr) {
3675 __rt = this;
3676 if ((__cm_ & ios_base::out) && sync())
3677 __rt = nullptr;
3678 }
3679 return __rt;
3680}
3681
3682_LIBCPP_SUPPRESS_DEPRECATED_POP
3683
3684# endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT)
3685
3686_LIBCPP_END_NAMESPACE_STD
3687
3688_LIBCPP_POP_MACROS
3689
3690// NOLINTEND(libcpp-robust-against-adl)
3691
3692211# endif // _LIBCPP_HAS_LOCALIZATION
3693212
3694213# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
......@@ -3697,6 +216,7 @@ _LIBCPP_POP_MACROS
3697216# include <cstdarg>
3698217# include <iterator>
3699218# include <mutex>
219# include <optional>
3700220# include <stdexcept>
3701221# include <type_traits>
3702222# include <typeinfo>
lib/libcxx/include/map+94-232
......@@ -582,6 +582,7 @@ erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
582582# include <__functional/binary_function.h>
583583# include <__functional/is_transparent.h>
584584# include <__functional/operations.h>
585# include <__fwd/map.h>
585586# include <__iterator/erase_if_container.h>
586587# include <__iterator/iterator_traits.h>
587588# include <__iterator/ranges_iterator_traits.h>
......@@ -592,7 +593,6 @@ erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
592593# include <__memory/pointer_traits.h>
593594# include <__memory/unique_ptr.h>
594595# include <__memory_resource/polymorphic_allocator.h>
595# include <__new/launder.h>
596596# include <__node_handle>
597597# include <__ranges/concepts.h>
598598# include <__ranges/container_compatible_range.h>
......@@ -644,13 +644,13 @@ public:
644644 : _Compare(__c) {}
645645 _LIBCPP_HIDE_FROM_ABI const _Compare& key_comp() const _NOEXCEPT { return *this; }
646646 _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _CP& __y) const {
647 return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);
647 return static_cast<const _Compare&>(*this)(__x.first, __y.first);
648648 }
649649 _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _Key& __y) const {
650 return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);
650 return static_cast<const _Compare&>(*this)(__x.first, __y);
651651 }
652652 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _CP& __y) const {
653 return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);
653 return static_cast<const _Compare&>(*this)(__x, __y.first);
654654 }
655655 _LIBCPP_HIDE_FROM_ABI void swap(__map_value_compare& __y) _NOEXCEPT_(__is_nothrow_swappable_v<_Compare>) {
656656 using std::swap;
......@@ -660,12 +660,12 @@ public:
660660# if _LIBCPP_STD_VER >= 14
661661 template <typename _K2>
662662 _LIBCPP_HIDE_FROM_ABI bool operator()(const _K2& __x, const _CP& __y) const {
663 return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);
663 return static_cast<const _Compare&>(*this)(__x, __y.first);
664664 }
665665
666666 template <typename _K2>
667667 _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _K2& __y) const {
668 return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);
668 return static_cast<const _Compare&>(*this)(__x.first, __y);
669669 }
670670# endif
671671};
......@@ -681,15 +681,9 @@ public:
681681 : __comp_(__c) {}
682682 _LIBCPP_HIDE_FROM_ABI const _Compare& key_comp() const _NOEXCEPT { return __comp_; }
683683
684 _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _CP& __y) const {
685 return __comp_(__x.__get_value().first, __y.__get_value().first);
686 }
687 _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _Key& __y) const {
688 return __comp_(__x.__get_value().first, __y);
689 }
690 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _CP& __y) const {
691 return __comp_(__x, __y.__get_value().first);
692 }
684 _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _CP& __y) const { return __comp_(__x.first, __y.first); }
685 _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _Key& __y) const { return __comp_(__x.first, __y); }
686 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _CP& __y) const { return __comp_(__x, __y.first); }
693687 void swap(__map_value_compare& __y) _NOEXCEPT_(__is_nothrow_swappable_v<_Compare>) {
694688 using std::swap;
695689 swap(__comp_, __y.__comp_);
......@@ -698,12 +692,12 @@ public:
698692# if _LIBCPP_STD_VER >= 14
699693 template <typename _K2>
700694 _LIBCPP_HIDE_FROM_ABI bool operator()(const _K2& __x, const _CP& __y) const {
701 return __comp_(__x, __y.__get_value().first);
695 return __comp_(__x, __y.first);
702696 }
703697
704698 template <typename _K2>
705699 _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _K2& __y) const {
706 return __comp_(__x.__get_value().first, __y);
700 return __comp_(__x.first, __y);
707701 }
708702# endif
709703};
......@@ -748,135 +742,34 @@ public:
748742
749743 _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT {
750744 if (__second_constructed)
751 __alloc_traits::destroy(__na_, std::addressof(__p->__value_.__get_value().second));
745 __alloc_traits::destroy(__na_, std::addressof(__p->__value_.second));
752746 if (__first_constructed)
753 __alloc_traits::destroy(__na_, std::addressof(__p->__value_.__get_value().first));
747 __alloc_traits::destroy(__na_, std::addressof(__p->__value_.first));
754748 if (__p)
755749 __alloc_traits::deallocate(__na_, __p, 1);
756750 }
757751};
758752
759template <class _Key, class _Tp, class _Compare, class _Allocator>
760class map;
761template <class _Key, class _Tp, class _Compare, class _Allocator>
762class multimap;
763template <class _TreeIterator>
764class __map_const_iterator;
765
766# ifndef _LIBCPP_CXX03_LANG
767
768753template <class _Key, class _Tp>
769struct _LIBCPP_STANDALONE_DEBUG __value_type {
770 typedef _Key key_type;
771 typedef _Tp mapped_type;
772 typedef pair<const key_type, mapped_type> value_type;
773 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
774 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
775
776private:
777 value_type __cc_;
778
779public:
780 _LIBCPP_HIDE_FROM_ABI value_type& __get_value() {
781# if _LIBCPP_STD_VER >= 17
782 return *std::launder(std::addressof(__cc_));
783# else
784 return __cc_;
785# endif
786 }
787
788 _LIBCPP_HIDE_FROM_ABI const value_type& __get_value() const {
789# if _LIBCPP_STD_VER >= 17
790 return *std::launder(std::addressof(__cc_));
791# else
792 return __cc_;
793# endif
794 }
795
796 _LIBCPP_HIDE_FROM_ABI __nc_ref_pair_type __ref() {
797 value_type& __v = __get_value();
798 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
799 }
800
801 _LIBCPP_HIDE_FROM_ABI __nc_rref_pair_type __move() {
802 value_type& __v = __get_value();
803 return __nc_rref_pair_type(std::move(const_cast<key_type&>(__v.first)), std::move(__v.second));
804 }
805
806 _LIBCPP_HIDE_FROM_ABI __value_type& operator=(const __value_type& __v) {
807 __ref() = __v.__get_value();
808 return *this;
809 }
810
811 _LIBCPP_HIDE_FROM_ABI __value_type& operator=(__value_type&& __v) {
812 __ref() = __v.__move();
813 return *this;
814 }
815
816 template <class _ValueTp, __enable_if_t<__is_same_uncvref<_ValueTp, value_type>::value, int> = 0>
817 _LIBCPP_HIDE_FROM_ABI __value_type& operator=(_ValueTp&& __v) {
818 __ref() = std::forward<_ValueTp>(__v);
819 return *this;
820 }
821
822 __value_type() = delete;
823 ~__value_type() = delete;
824 __value_type(const __value_type&) = delete;
825 __value_type(__value_type&&) = delete;
826};
827
828# else
829
830template <class _Key, class _Tp>
831struct __value_type {
832 typedef _Key key_type;
833 typedef _Tp mapped_type;
834 typedef pair<const key_type, mapped_type> value_type;
835
836private:
837 value_type __cc_;
838
839public:
840 _LIBCPP_HIDE_FROM_ABI value_type& __get_value() { return __cc_; }
841 _LIBCPP_HIDE_FROM_ABI const value_type& __get_value() const { return __cc_; }
842
843 __value_type() = delete;
844 __value_type(__value_type const&) = delete;
845 __value_type& operator=(__value_type const&) = delete;
846 ~__value_type() = delete;
847};
848
849# endif // _LIBCPP_CXX03_LANG
850
851template <class _Tp>
852struct __extract_key_value_types;
853
854template <class _Key, class _Tp>
855struct __extract_key_value_types<__value_type<_Key, _Tp> > {
856 typedef _Key const __key_type;
857 typedef _Tp __mapped_type;
858};
754struct __value_type;
859755
860756template <class _TreeIterator>
861class _LIBCPP_TEMPLATE_VIS __map_iterator {
862 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
863 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
864
757class __map_iterator {
865758 _TreeIterator __i_;
866759
867760public:
868 typedef bidirectional_iterator_tag iterator_category;
869 typedef typename _NodeTypes::__map_value_type value_type;
870 typedef typename _TreeIterator::difference_type difference_type;
871 typedef value_type& reference;
872 typedef typename _NodeTypes::__map_value_type_pointer pointer;
761 using iterator_category = bidirectional_iterator_tag;
762 using value_type = typename _TreeIterator::value_type;
763 using difference_type = typename _TreeIterator::difference_type;
764 using reference = value_type&;
765 using pointer = typename _TreeIterator::pointer;
873766
874767 _LIBCPP_HIDE_FROM_ABI __map_iterator() _NOEXCEPT {}
875768
876769 _LIBCPP_HIDE_FROM_ABI __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
877770
878 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __i_->__get_value(); }
879 _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
771 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return *__i_; }
772 _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(*__i_); }
880773
881774 _LIBCPP_HIDE_FROM_ABI __map_iterator& operator++() {
882775 ++__i_;
......@@ -906,26 +799,23 @@ public:
906799 }
907800
908801 template <class, class, class, class>
909 friend class _LIBCPP_TEMPLATE_VIS map;
802 friend class map;
910803 template <class, class, class, class>
911 friend class _LIBCPP_TEMPLATE_VIS multimap;
804 friend class multimap;
912805 template <class>
913 friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
806 friend class __map_const_iterator;
914807};
915808
916809template <class _TreeIterator>
917class _LIBCPP_TEMPLATE_VIS __map_const_iterator {
918 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
919 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
920
810class __map_const_iterator {
921811 _TreeIterator __i_;
922812
923813public:
924 typedef bidirectional_iterator_tag iterator_category;
925 typedef typename _NodeTypes::__map_value_type value_type;
926 typedef typename _TreeIterator::difference_type difference_type;
927 typedef const value_type& reference;
928 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
814 using iterator_category = bidirectional_iterator_tag;
815 using value_type = typename _TreeIterator::value_type;
816 using difference_type = typename _TreeIterator::difference_type;
817 using reference = const value_type&;
818 using pointer = typename _TreeIterator::pointer;
929819
930820 _LIBCPP_HIDE_FROM_ABI __map_const_iterator() _NOEXCEPT {}
931821
......@@ -933,8 +823,8 @@ public:
933823 _LIBCPP_HIDE_FROM_ABI
934824 __map_const_iterator(__map_iterator< typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT : __i_(__i.__i_) {}
935825
936 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __i_->__get_value(); }
937 _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
826 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return *__i_; }
827 _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(*__i_); }
938828
939829 _LIBCPP_HIDE_FROM_ABI __map_const_iterator& operator++() {
940830 ++__i_;
......@@ -964,15 +854,15 @@ public:
964854 }
965855
966856 template <class, class, class, class>
967 friend class _LIBCPP_TEMPLATE_VIS map;
857 friend class map;
968858 template <class, class, class, class>
969 friend class _LIBCPP_TEMPLATE_VIS multimap;
859 friend class multimap;
970860 template <class, class, class>
971 friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
861 friend class __tree_const_iterator;
972862};
973863
974template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
975class _LIBCPP_TEMPLATE_VIS map {
864template <class _Key, class _Tp, class _Compare, class _Allocator>
865class map {
976866public:
977867 // types:
978868 typedef _Key key_type;
......@@ -986,7 +876,7 @@ public:
986876 static_assert(is_same<typename allocator_type::value_type, value_type>::value,
987877 "Allocator::value_type must be same type as value_type");
988878
989 class _LIBCPP_TEMPLATE_VIS value_compare : public __binary_function<value_type, value_type, bool> {
879 class value_compare : public __binary_function<value_type, value_type, bool> {
990880 friend class map;
991881
992882 protected:
......@@ -1002,9 +892,8 @@ public:
1002892
1003893private:
1004894 typedef std::__value_type<key_type, mapped_type> __value_type;
1005 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
1006 typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
1007 typedef __tree<__value_type, __vc, __allocator_type> __base;
895 typedef __map_value_compare<key_type, value_type, key_compare> __vc;
896 typedef __tree<__value_type, __vc, allocator_type> __base;
1008897 typedef typename __base::__node_traits __node_traits;
1009898 typedef allocator_traits<allocator_type> __alloc_traits;
1010899
......@@ -1028,9 +917,9 @@ public:
1028917# endif
1029918
1030919 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1031 friend class _LIBCPP_TEMPLATE_VIS map;
920 friend class map;
1032921 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1033 friend class _LIBCPP_TEMPLATE_VIS multimap;
922 friend class multimap;
1034923
1035924 _LIBCPP_HIDE_FROM_ABI map() _NOEXCEPT_(
1036925 is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_default_constructible<key_compare>::value&&
......@@ -1083,31 +972,15 @@ public:
1083972
1084973 _LIBCPP_HIDE_FROM_ABI map(const map& __m) : __tree_(__m.__tree_) { insert(__m.begin(), __m.end()); }
1085974
1086 _LIBCPP_HIDE_FROM_ABI map& operator=(const map& __m) {
1087# ifndef _LIBCPP_CXX03_LANG
1088 __tree_ = __m.__tree_;
1089# else
1090 if (this != std::addressof(__m)) {
1091 __tree_.clear();
1092 __tree_.value_comp() = __m.__tree_.value_comp();
1093 __tree_.__copy_assign_alloc(__m.__tree_);
1094 insert(__m.begin(), __m.end());
1095 }
1096# endif
1097 return *this;
1098 }
975 _LIBCPP_HIDE_FROM_ABI map& operator=(const map& __m) = default;
1099976
1100977# ifndef _LIBCPP_CXX03_LANG
1101978
1102 _LIBCPP_HIDE_FROM_ABI map(map&& __m) noexcept(is_nothrow_move_constructible<__base>::value)
1103 : __tree_(std::move(__m.__tree_)) {}
979 _LIBCPP_HIDE_FROM_ABI map(map&& __m) noexcept(is_nothrow_move_constructible<__base>::value) = default;
1104980
1105981 _LIBCPP_HIDE_FROM_ABI map(map&& __m, const allocator_type& __a);
1106982
1107 _LIBCPP_HIDE_FROM_ABI map& operator=(map&& __m) noexcept(is_nothrow_move_assignable<__base>::value) {
1108 __tree_ = std::move(__m.__tree_);
1109 return *this;
1110 }
983 _LIBCPP_HIDE_FROM_ABI map& operator=(map&& __m) noexcept(is_nothrow_move_assignable<__base>::value) = default;
1111984
1112985 _LIBCPP_HIDE_FROM_ABI map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1113986 : __tree_(__vc(__comp)) {
......@@ -1138,7 +1011,7 @@ public:
11381011 insert(__m.begin(), __m.end());
11391012 }
11401013
1141 _LIBCPP_HIDE_FROM_ABI ~map() { static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); }
1014 _LIBCPP_HIDE_FROM_ABI ~map() { static_assert(sizeof(std::__diagnose_non_const_comparator<_Key, _Compare>()), ""); }
11421015
11431016 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __tree_.begin(); }
11441017 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __tree_.begin(); }
......@@ -1184,29 +1057,29 @@ public:
11841057
11851058 template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
11861059 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(_Pp&& __p) {
1187 return __tree_.__insert_unique(std::forward<_Pp>(__p));
1060 return __tree_.__emplace_unique(std::forward<_Pp>(__p));
11881061 }
11891062
11901063 template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
11911064 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __pos, _Pp&& __p) {
1192 return __tree_.__insert_unique(__pos.__i_, std::forward<_Pp>(__p));
1065 return __tree_.__emplace_hint_unique(__pos.__i_, std::forward<_Pp>(__p));
11931066 }
11941067
11951068# endif // _LIBCPP_CXX03_LANG
11961069
1197 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __v) { return __tree_.__insert_unique(__v); }
1070 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __v) { return __tree_.__emplace_unique(__v); }
11981071
11991072 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
1200 return __tree_.__insert_unique(__p.__i_, __v);
1073 return __tree_.__emplace_hint_unique(__p.__i_, __v);
12011074 }
12021075
12031076# ifndef _LIBCPP_CXX03_LANG
12041077 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __v) {
1205 return __tree_.__insert_unique(std::move(__v));
1078 return __tree_.__emplace_unique(std::move(__v));
12061079 }
12071080
12081081 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
1209 return __tree_.__insert_unique(__p.__i_, std::move(__v));
1082 return __tree_.__emplace_hint_unique(__p.__i_, std::move(__v));
12101083 }
12111084
12121085 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
......@@ -1297,7 +1170,7 @@ public:
12971170 auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, __k, std::forward<_Vp>(__v));
12981171
12991172 if (!__inserted)
1300 __r->__get_value().second = std::forward<_Vp>(__v);
1173 __r->second = std::forward<_Vp>(__v);
13011174
13021175 return __r;
13031176 }
......@@ -1308,7 +1181,7 @@ public:
13081181 __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, std::move(__k), std::forward<_Vp>(__v));
13091182
13101183 if (!__inserted)
1311 __r->__get_value().second = std::forward<_Vp>(__v);
1184 __r->second = std::forward<_Vp>(__v);
13121185
13131186 return __r;
13141187 }
......@@ -1513,8 +1386,9 @@ map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
15131386 : __tree_(std::move(__m.__tree_), typename __base::allocator_type(__a)) {
15141387 if (__a != __m.get_allocator()) {
15151388 const_iterator __e = cend();
1516 while (!__m.empty())
1517 __tree_.__insert_unique(__e.__i_, __m.__tree_.remove(__m.begin().__i_)->__value_.__move());
1389 while (!__m.empty()) {
1390 __tree_.__insert_unique_from_orphaned_node(__e.__i_, std::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
1391 }
15181392 }
15191393}
15201394
......@@ -1522,8 +1396,7 @@ template <class _Key, class _Tp, class _Compare, class _Allocator>
15221396_Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) {
15231397 return __tree_
15241398 .__emplace_unique_key_args(__k, std::piecewise_construct, std::forward_as_tuple(__k), std::forward_as_tuple())
1525 .first->__get_value()
1526 .second;
1399 .first->second;
15271400}
15281401
15291402template <class _Key, class _Tp, class _Compare, class _Allocator>
......@@ -1533,8 +1406,7 @@ _Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k) {
15331406 return __tree_
15341407 .__emplace_unique_key_args(
15351408 __k, std::piecewise_construct, std::forward_as_tuple(std::move(__k)), std::forward_as_tuple())
1536 .first->__get_value()
1537 .second;
1409 .first->second;
15381410 // NOLINTEND(bugprone-use-after-move)
15391411}
15401412
......@@ -1545,9 +1417,9 @@ typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
15451417map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k) {
15461418 __node_allocator& __na = __tree_.__node_alloc();
15471419 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1548 __node_traits::construct(__na, std::addressof(__h->__value_.__get_value().first), __k);
1420 __node_traits::construct(__na, std::addressof(__h->__value_.first), __k);
15491421 __h.get_deleter().__first_constructed = true;
1550 __node_traits::construct(__na, std::addressof(__h->__value_.__get_value().second));
1422 __node_traits::construct(__na, std::addressof(__h->__value_.second));
15511423 __h.get_deleter().__second_constructed = true;
15521424 return __h;
15531425}
......@@ -1562,7 +1434,7 @@ _Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) {
15621434 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
15631435 __r = __h.release();
15641436 }
1565 return __r->__value_.__get_value().second;
1437 return __r->__value_.second;
15661438}
15671439
15681440# endif // _LIBCPP_CXX03_LANG
......@@ -1572,8 +1444,8 @@ _Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) {
15721444 __parent_pointer __parent;
15731445 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
15741446 if (__child == nullptr)
1575 __throw_out_of_range("map::at: key not found");
1576 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
1447 std::__throw_out_of_range("map::at: key not found");
1448 return static_cast<__node_pointer>(__child)->__value_.second;
15771449}
15781450
15791451template <class _Key, class _Tp, class _Compare, class _Allocator>
......@@ -1581,8 +1453,8 @@ const _Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const {
15811453 __parent_pointer __parent;
15821454 __node_base_pointer __child = __tree_.__find_equal(__parent, __k);
15831455 if (__child == nullptr)
1584 __throw_out_of_range("map::at: key not found");
1585 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
1456 std::__throw_out_of_range("map::at: key not found");
1457 return static_cast<__node_pointer>(__child)->__value_.second;
15861458}
15871459
15881460template <class _Key, class _Tp, class _Compare, class _Allocator>
......@@ -1654,10 +1526,12 @@ struct __container_traits<map<_Key, _Tp, _Compare, _Allocator> > {
16541526 // For associative containers, if an exception is thrown by any operation from within
16551527 // an insert or emplace function inserting a single element, the insertion has no effect.
16561528 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
1529
1530 static _LIBCPP_CONSTEXPR const bool __reservable = false;
16571531};
16581532
1659template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
1660class _LIBCPP_TEMPLATE_VIS multimap {
1533template <class _Key, class _Tp, class _Compare, class _Allocator>
1534class multimap {
16611535public:
16621536 // types:
16631537 typedef _Key key_type;
......@@ -1672,7 +1546,7 @@ public:
16721546 static_assert(is_same<typename allocator_type::value_type, value_type>::value,
16731547 "Allocator::value_type must be same type as value_type");
16741548
1675 class _LIBCPP_TEMPLATE_VIS value_compare : public __binary_function<value_type, value_type, bool> {
1549 class value_compare : public __binary_function<value_type, value_type, bool> {
16761550 friend class multimap;
16771551
16781552 protected:
......@@ -1688,9 +1562,8 @@ public:
16881562
16891563private:
16901564 typedef std::__value_type<key_type, mapped_type> __value_type;
1691 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
1692 typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
1693 typedef __tree<__value_type, __vc, __allocator_type> __base;
1565 typedef __map_value_compare<key_type, value_type, key_compare> __vc;
1566 typedef __tree<__value_type, __vc, allocator_type> __base;
16941567 typedef typename __base::__node_traits __node_traits;
16951568 typedef allocator_traits<allocator_type> __alloc_traits;
16961569
......@@ -1711,9 +1584,9 @@ public:
17111584# endif
17121585
17131586 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1714 friend class _LIBCPP_TEMPLATE_VIS map;
1587 friend class map;
17151588 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1716 friend class _LIBCPP_TEMPLATE_VIS multimap;
1589 friend class multimap;
17171590
17181591 _LIBCPP_HIDE_FROM_ABI multimap() _NOEXCEPT_(
17191592 is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_default_constructible<key_compare>::value&&
......@@ -1770,31 +1643,16 @@ public:
17701643 insert(__m.begin(), __m.end());
17711644 }
17721645
1773 _LIBCPP_HIDE_FROM_ABI multimap& operator=(const multimap& __m) {
1774# ifndef _LIBCPP_CXX03_LANG
1775 __tree_ = __m.__tree_;
1776# else
1777 if (this != std::addressof(__m)) {
1778 __tree_.clear();
1779 __tree_.value_comp() = __m.__tree_.value_comp();
1780 __tree_.__copy_assign_alloc(__m.__tree_);
1781 insert(__m.begin(), __m.end());
1782 }
1783# endif
1784 return *this;
1785 }
1646 _LIBCPP_HIDE_FROM_ABI multimap& operator=(const multimap& __m) = default;
17861647
17871648# ifndef _LIBCPP_CXX03_LANG
17881649
1789 _LIBCPP_HIDE_FROM_ABI multimap(multimap&& __m) noexcept(is_nothrow_move_constructible<__base>::value)
1790 : __tree_(std::move(__m.__tree_)) {}
1650 _LIBCPP_HIDE_FROM_ABI multimap(multimap&& __m) noexcept(is_nothrow_move_constructible<__base>::value) = default;
17911651
17921652 _LIBCPP_HIDE_FROM_ABI multimap(multimap&& __m, const allocator_type& __a);
17931653
1794 _LIBCPP_HIDE_FROM_ABI multimap& operator=(multimap&& __m) noexcept(is_nothrow_move_assignable<__base>::value) {
1795 __tree_ = std::move(__m.__tree_);
1796 return *this;
1797 }
1654 _LIBCPP_HIDE_FROM_ABI multimap&
1655 operator=(multimap&& __m) noexcept(is_nothrow_move_assignable<__base>::value) = default;
17981656
17991657 _LIBCPP_HIDE_FROM_ABI multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
18001658 : __tree_(__vc(__comp)) {
......@@ -1826,7 +1684,9 @@ public:
18261684 insert(__m.begin(), __m.end());
18271685 }
18281686
1829 _LIBCPP_HIDE_FROM_ABI ~multimap() { static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); }
1687 _LIBCPP_HIDE_FROM_ABI ~multimap() {
1688 static_assert(sizeof(std::__diagnose_non_const_comparator<_Key, _Compare>()), "");
1689 }
18301690
18311691 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __tree_.begin(); }
18321692 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __tree_.begin(); }
......@@ -1865,34 +1725,34 @@ public:
18651725
18661726 template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
18671727 _LIBCPP_HIDE_FROM_ABI iterator insert(_Pp&& __p) {
1868 return __tree_.__insert_multi(std::forward<_Pp>(__p));
1728 return __tree_.__emplace_multi(std::forward<_Pp>(__p));
18691729 }
18701730
18711731 template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
18721732 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __pos, _Pp&& __p) {
1873 return __tree_.__insert_multi(__pos.__i_, std::forward<_Pp>(__p));
1733 return __tree_.__emplace_hint_multi(__pos.__i_, std::forward<_Pp>(__p));
18741734 }
18751735
1876 _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __v) { return __tree_.__insert_multi(std::move(__v)); }
1736 _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __v) { return __tree_.__emplace_multi(std::move(__v)); }
18771737
18781738 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
1879 return __tree_.__insert_multi(__p.__i_, std::move(__v));
1739 return __tree_.__emplace_hint_multi(__p.__i_, std::move(__v));
18801740 }
18811741
18821742 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
18831743
18841744# endif // _LIBCPP_CXX03_LANG
18851745
1886 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __v) { return __tree_.__insert_multi(__v); }
1746 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __v) { return __tree_.__emplace_multi(__v); }
18871747
18881748 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
1889 return __tree_.__insert_multi(__p.__i_, __v);
1749 return __tree_.__emplace_hint_multi(__p.__i_, __v);
18901750 }
18911751
18921752 template <class _InputIterator>
18931753 _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __f, _InputIterator __l) {
18941754 for (const_iterator __e = cend(); __f != __l; ++__f)
1895 __tree_.__insert_multi(__e.__i_, *__f);
1755 __tree_.__emplace_hint_multi(__e.__i_, *__f);
18961756 }
18971757
18981758# if _LIBCPP_STD_VER >= 23
......@@ -1900,7 +1760,7 @@ public:
19001760 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
19011761 const_iterator __end = cend();
19021762 for (auto&& __element : __range) {
1903 __tree_.__insert_multi(__end.__i_, std::forward<decltype(__element)>(__element));
1763 __tree_.__emplace_hint_multi(__end.__i_, std::forward<decltype(__element)>(__element));
19041764 }
19051765 }
19061766# endif
......@@ -2101,7 +1961,7 @@ multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const alloca
21011961 if (__a != __m.get_allocator()) {
21021962 const_iterator __e = cend();
21031963 while (!__m.empty())
2104 __tree_.__insert_multi(__e.__i_, std::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move()));
1964 __tree_.__insert_multi_from_orphaned_node(__e.__i_, std::move(__m.__tree_.remove(__m.begin().__i_)->__value_));
21051965 }
21061966}
21071967# endif
......@@ -2176,6 +2036,8 @@ struct __container_traits<multimap<_Key, _Tp, _Compare, _Allocator> > {
21762036 // For associative containers, if an exception is thrown by any operation from within
21772037 // an insert or emplace function inserting a single element, the insertion has no effect.
21782038 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
2039
2040 static _LIBCPP_CONSTEXPR const bool __reservable = false;
21792041};
21802042
21812043_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/math.h+1-10
......@@ -378,9 +378,7 @@ extern "C++" {
378378# include <__math/traits.h>
379379# include <__math/trigonometric_functions.h>
380380# include <__type_traits/enable_if.h>
381# include <__type_traits/is_floating_point.h>
382381# include <__type_traits/is_integral.h>
383# include <stdlib.h>
384382
385383// fpclassify relies on implementation-defined constants, so we can't move it to a detail header
386384_LIBCPP_BEGIN_NAMESPACE_STD
......@@ -431,19 +429,12 @@ using std::__math::isnormal;
431429using std::__math::isunordered;
432430# endif // _LIBCPP_MSVCRT
433431
434// abs
435//
436// handled in stdlib.h
437
438// div
439//
440// handled in stdlib.h
441
442432// We have to provide double overloads for <math.h> to work on platforms that don't provide the full set of math
443433// functions. To make the overload set work with multiple functions that take the same arguments, we make our overloads
444434// templates. Functions are preferred over function templates during overload resolution, which means that our overload
445435// will only be selected when the C library doesn't provide one.
446436
437using std::__math::abs;
447438using std::__math::acos;
448439using std::__math::acosh;
449440using std::__math::asin;
lib/libcxx/include/mdspan+44-3
......@@ -33,10 +33,14 @@ namespace std {
3333 template<class ElementType>
3434 class default_accessor;
3535
36 // [mdspan.accessor.aligned], class template aligned_accessor
37 template<class ElementType, size_t ByteAlignment>
38 class aligned_accessor; // since C++26
39
3640 // [mdspan.mdspan], class template mdspan
3741 template<class ElementType, class Extents, class LayoutPolicy = layout_right,
3842 class AccessorPolicy = default_accessor<ElementType>>
39 class mdspan; // not implemented yet
43 class mdspan;
4044}
4145
4246// extents synopsis
......@@ -269,6 +273,38 @@ namespace std {
269273 };
270274}
271275
276// aligned_accessor synopsis
277
278namespace std {
279 template<class ElementType, size_t ByteAlignment>
280 struct aligned_accessor {
281 using offset_policy = default_accessor<ElementType>;
282 using element_type = ElementType;
283 using reference = ElementType&;
284 using data_handle_type = ElementType*;
285
286 static constexpr size_t byte_alignment = ByteAlignment;
287
288 constexpr aligned_accessor() noexcept = default;
289
290 template<class OtherElementType, size_t OtherByteAlignment>
291 constexpr aligned_accessor(
292 aligned_accessor<OtherElementType, OtherByteAlignment>) noexcept;
293
294 template<class OtherElementType>
295 explicit constexpr aligned_accessor(
296 default_accessor<OtherElementType>) noexcept;
297
298 template<class OtherElementType>
299 constexpr operator default_accessor<OtherElementType>() const noexcept;
300
301 constexpr reference access(data_handle_type p, size_t i) const noexcept;
302
303 constexpr typename offset_policy::data_handle_type
304 offset(data_handle_type p, size_t i) const noexcept;
305 };
306}
307
272308// mdspan synopsis
273309
274310namespace std {
......@@ -409,12 +445,17 @@ namespace std {
409445#define _LIBCPP_MDSPAN
410446
411447#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
412# include <__cxx03/mdspan>
448# include <__cxx03/__config>
413449#else
414450# include <__config>
415451
416452# if _LIBCPP_STD_VER >= 23
417# include <__fwd/mdspan.h>
453# include <__fwd/mdspan.h> // TODO(boomanaiden154): This is currently a
454 // non-standard extension to include
455 // std::dynamic_extent tracked by LWG issue 4275.
456 // This comment should be deleted or the include
457 // deleted upon resolution.
458# include <__fwd/span.h>
418459# include <__mdspan/default_accessor.h>
419460# include <__mdspan/extents.h>
420461# include <__mdspan/layout_left.h>
lib/libcxx/include/memory+6
......@@ -912,6 +912,9 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
912912template<size_t N, class T>
913913[[nodiscard]] constexpr T* assume_aligned(T* ptr); // since C++20
914914
915template<size_t Alignment, class T>
916 bool is_sufficiently_aligned(T* ptr); // since C++26
917
915918// [out.ptr.t], class template out_ptr_t
916919template<class Smart, class Pointer, class... Args>
917920 class out_ptr_t; // since c++23
......@@ -945,6 +948,7 @@ template<class Pointer = void, class Smart, class... Args>
945948# include <__memory/allocator_traits.h>
946949# include <__memory/auto_ptr.h>
947950# include <__memory/inout_ptr.h>
951# include <__memory/is_sufficiently_aligned.h>
948952# include <__memory/out_ptr.h>
949953# include <__memory/pointer_traits.h>
950954# include <__memory/raw_storage_iterator.h>
......@@ -958,12 +962,14 @@ template<class Pointer = void, class Smart, class... Args>
958962
959963# if _LIBCPP_STD_VER >= 17
960964# include <__memory/construct_at.h>
965# include <__memory/destroy.h>
961966# endif
962967
963968# if _LIBCPP_STD_VER >= 20
964969# include <__memory/assume_aligned.h>
965970# include <__memory/concepts.h>
966971# include <__memory/ranges_construct_at.h>
972# include <__memory/ranges_destroy.h>
967973# include <__memory/ranges_uninitialized_algorithms.h>
968974# include <__memory/uses_allocator_construction.h>
969975# endif
lib/libcxx/include/memory_resource+1-1
......@@ -50,7 +50,7 @@ namespace std::pmr {
5050 */
5151
5252#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
53# include <__cxx03/memory_resource>
53# include <__cxx03/__config>
5454#else
5555# include <__config>
5656
lib/libcxx/include/mutex+45-49
......@@ -256,26 +256,24 @@ public:
256256 _LIBCPP_HIDE_FROM_ABI bool try_lock_for(const chrono::duration<_Rep, _Period>& __d) {
257257 return try_lock_until(chrono::steady_clock::now() + __d);
258258 }
259
259260 template <class _Clock, class _Duration>
260 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool
261 try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
261 _LIBCPP_HIDE_FROM_ABI bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) {
262 using namespace chrono;
263 unique_lock<mutex> __lk(__m_);
264 bool __no_timeout = _Clock::now() < __t;
265 while (__no_timeout && __locked_)
266 __no_timeout = __cv_.wait_until(__lk, __t) == cv_status::no_timeout;
267 if (!__locked_) {
268 __locked_ = true;
269 return true;
270 }
271 return false;
272 }
273
262274 void unlock() _NOEXCEPT;
263275};
264276
265template <class _Clock, class _Duration>
266bool timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) {
267 using namespace chrono;
268 unique_lock<mutex> __lk(__m_);
269 bool __no_timeout = _Clock::now() < __t;
270 while (__no_timeout && __locked_)
271 __no_timeout = __cv_.wait_until(__lk, __t) == cv_status::no_timeout;
272 if (!__locked_) {
273 __locked_ = true;
274 return true;
275 }
276 return false;
277}
278
279277class _LIBCPP_EXPORTED_FROM_ABI recursive_timed_mutex {
280278 mutex __m_;
281279 condition_variable __cv_;
......@@ -295,34 +293,32 @@ public:
295293 _LIBCPP_HIDE_FROM_ABI bool try_lock_for(const chrono::duration<_Rep, _Period>& __d) {
296294 return try_lock_until(chrono::steady_clock::now() + __d);
297295 }
296
298297 template <class _Clock, class _Duration>
299 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool
300 try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
298 _LIBCPP_HIDE_FROM_ABI bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) {
299 using namespace chrono;
300 __thread_id __id = this_thread::get_id();
301 unique_lock<mutex> __lk(__m_);
302 if (__id == __id_) {
303 if (__count_ == numeric_limits<size_t>::max())
304 return false;
305 ++__count_;
306 return true;
307 }
308 bool __no_timeout = _Clock::now() < __t;
309 while (__no_timeout && __count_ != 0)
310 __no_timeout = __cv_.wait_until(__lk, __t) == cv_status::no_timeout;
311 if (__count_ == 0) {
312 __count_ = 1;
313 __id_ = __id;
314 return true;
315 }
316 return false;
317 }
318
301319 void unlock() _NOEXCEPT;
302320};
303321
304template <class _Clock, class _Duration>
305bool recursive_timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) {
306 using namespace chrono;
307 __thread_id __id = this_thread::get_id();
308 unique_lock<mutex> __lk(__m_);
309 if (__id == __id_) {
310 if (__count_ == numeric_limits<size_t>::max())
311 return false;
312 ++__count_;
313 return true;
314 }
315 bool __no_timeout = _Clock::now() < __t;
316 while (__no_timeout && __count_ != 0)
317 __no_timeout = __cv_.wait_until(__lk, __t) == cv_status::no_timeout;
318 if (__count_ == 0) {
319 __count_ = 1;
320 __id_ = __id;
321 return true;
322 }
323 return false;
324}
325
326322template <class _L0, class _L1>
327323_LIBCPP_HIDE_FROM_ABI int try_lock(_L0& __l0, _L1& __l1) {
328324 unique_lock<_L0> __u0(__l0, try_to_lock_t());
......@@ -423,10 +419,10 @@ inline _LIBCPP_HIDE_FROM_ABI void lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&...
423419
424420# if _LIBCPP_STD_VER >= 17
425421template <class... _Mutexes>
426class _LIBCPP_TEMPLATE_VIS scoped_lock;
422class scoped_lock;
427423
428424template <>
429class _LIBCPP_TEMPLATE_VIS scoped_lock<> {
425class scoped_lock<> {
430426public:
431427 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit scoped_lock() {}
432428 ~scoped_lock() = default;
......@@ -438,7 +434,7 @@ public:
438434};
439435
440436template <class _Mutex>
441class _LIBCPP_TEMPLATE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(scoped_lockable) scoped_lock<_Mutex> {
437class _LIBCPP_SCOPED_LOCKABLE scoped_lock<_Mutex> {
442438public:
443439 typedef _Mutex mutex_type;
444440
......@@ -446,16 +442,15 @@ private:
446442 mutex_type& __m_;
447443
448444public:
449 [[nodiscard]]
450 _LIBCPP_HIDE_FROM_ABI explicit scoped_lock(mutex_type& __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability(__m))
445 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit scoped_lock(mutex_type& __m) _LIBCPP_ACQUIRE_CAPABILITY(__m)
451446 : __m_(__m) {
452447 __m_.lock();
453448 }
454449
455 ~scoped_lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) { __m_.unlock(); }
450 _LIBCPP_RELEASE_CAPABILITY _LIBCPP_HIDE_FROM_ABI ~scoped_lock() { __m_.unlock(); }
456451
457 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit scoped_lock(adopt_lock_t, mutex_type& __m)
458 _LIBCPP_THREAD_SAFETY_ANNOTATION(requires_capability(__m))
452 [[nodiscard]]
453 _LIBCPP_HIDE_FROM_ABI explicit scoped_lock(adopt_lock_t, mutex_type& __m) _LIBCPP_REQUIRES_CAPABILITY(__m)
459454 : __m_(__m) {}
460455
461456 scoped_lock(scoped_lock const&) = delete;
......@@ -463,7 +458,7 @@ public:
463458};
464459
465460template <class... _MArgs>
466class _LIBCPP_TEMPLATE_VIS scoped_lock {
461class scoped_lock {
467462 static_assert(sizeof...(_MArgs) > 1, "At least 2 lock types required");
468463 typedef tuple<_MArgs&...> _MutexTuple;
469464
......@@ -508,6 +503,7 @@ _LIBCPP_POP_MACROS
508503# include <initializer_list>
509504# include <iosfwd>
510505# include <new>
506# include <optional>
511507# include <stdexcept>
512508# include <system_error>
513509# include <type_traits>
lib/libcxx/include/numbers+1-1
......@@ -59,7 +59,7 @@ namespace std::numbers {
5959*/
6060
6161#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
62# include <__cxx03/numbers>
62# include <__cxx03/__config>
6363#else
6464# include <__concepts/arithmetic.h>
6565# include <__config>
lib/libcxx/include/numeric+1
......@@ -172,6 +172,7 @@ constexpr T saturate_cast(U x) noexcept; // freestanding, Sin
172172# include <__numeric/gcd_lcm.h>
173173# include <__numeric/inclusive_scan.h>
174174# include <__numeric/pstl.h>
175# include <__numeric/ranges_iota.h>
175176# include <__numeric/reduce.h>
176177# include <__numeric/transform_exclusive_scan.h>
177178# include <__numeric/transform_inclusive_scan.h>
lib/libcxx/include/optional+154-144
......@@ -178,7 +178,7 @@ namespace std {
178178*/
179179
180180#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
181# include <__cxx03/optional>
181# include <__cxx03/__config>
182182#else
183183# include <__assert>
184184# include <__compare/compare_three_way_result.h>
......@@ -205,11 +205,13 @@ namespace std {
205205# include <__type_traits/is_assignable.h>
206206# include <__type_traits/is_constructible.h>
207207# include <__type_traits/is_convertible.h>
208# include <__type_traits/is_core_convertible.h>
208209# include <__type_traits/is_destructible.h>
209210# include <__type_traits/is_nothrow_assignable.h>
210211# include <__type_traits/is_nothrow_constructible.h>
211212# include <__type_traits/is_object.h>
212213# include <__type_traits/is_reference.h>
214# include <__type_traits/is_replaceable.h>
213215# include <__type_traits/is_same.h>
214216# include <__type_traits/is_scalar.h>
215217# include <__type_traits/is_swappable.h>
......@@ -246,7 +248,7 @@ _LIBCPP_PUSH_MACROS
246248namespace std // purposefully not using versioning namespace
247249{
248250
249class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS bad_optional_access : public exception {
251class _LIBCPP_EXPORTED_FROM_ABI bad_optional_access : public exception {
250252public:
251253 _LIBCPP_HIDE_FROM_ABI bad_optional_access() _NOEXCEPT = default;
252254 _LIBCPP_HIDE_FROM_ABI bad_optional_access(const bad_optional_access&) _NOEXCEPT = default;
......@@ -262,8 +264,7 @@ public:
262264
263265_LIBCPP_BEGIN_NAMESPACE_STD
264266
265[[noreturn]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS void
266__throw_bad_optional_access() {
267[[noreturn]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_optional_access() {
267268# if _LIBCPP_HAS_EXCEPTIONS
268269 throw bad_optional_access();
269270# else
......@@ -590,6 +591,7 @@ public:
590591
591592 using __trivially_relocatable _LIBCPP_NODEBUG =
592593 conditional_t<__libcpp_is_trivially_relocatable<_Tp>::value, optional, void>;
594 using __replaceable _LIBCPP_NODEBUG = conditional_t<__is_replaceable_v<_Tp>, optional, void>;
593595
594596private:
595597 // Disable the reference extension using this static assert.
......@@ -672,44 +674,41 @@ public:
672674 _LIBCPP_HIDE_FROM_ABI constexpr optional(optional&&) = default;
673675 _LIBCPP_HIDE_FROM_ABI constexpr optional(nullopt_t) noexcept {}
674676
675 template <
676 class _InPlaceT,
677 class... _Args,
678 class = enable_if_t< _And< _IsSame<_InPlaceT, in_place_t>, is_constructible<value_type, _Args...> >::value > >
677 template <class _InPlaceT,
678 class... _Args,
679 enable_if_t<_And<_IsSame<_InPlaceT, in_place_t>, is_constructible<value_type, _Args...>>::value, int> = 0>
679680 _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_InPlaceT, _Args&&... __args)
680681 : __base(in_place, std::forward<_Args>(__args)...) {}
681682
682683 template <class _Up,
683684 class... _Args,
684 class = enable_if_t< is_constructible_v<value_type, initializer_list<_Up>&, _Args...>> >
685 enable_if_t<is_constructible_v<value_type, initializer_list<_Up>&, _Args...>, int> = 0>
685686 _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(in_place_t, initializer_list<_Up> __il, _Args&&... __args)
686687 : __base(in_place, __il, std::forward<_Args>(__args)...) {}
687688
688 template <class _Up = value_type,
689 enable_if_t< _CheckOptionalArgsCtor<_Up>::template __enable_implicit<_Up>(), int> = 0>
689 template <class _Up = value_type,
690 enable_if_t<_CheckOptionalArgsCtor<_Up>::template __enable_implicit<_Up>(), int> = 0>
690691 _LIBCPP_HIDE_FROM_ABI constexpr optional(_Up&& __v) : __base(in_place, std::forward<_Up>(__v)) {}
691692
692 template <class _Up, enable_if_t< _CheckOptionalArgsCtor<_Up>::template __enable_explicit<_Up>(), int> = 0>
693 template <class _Up, enable_if_t<_CheckOptionalArgsCtor<_Up>::template __enable_explicit<_Up>(), int> = 0>
693694 _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_Up&& __v) : __base(in_place, std::forward<_Up>(__v)) {}
694695
695696 // LWG2756: conditionally explicit conversion from const optional<_Up>&
696 template <class _Up,
697 enable_if_t< _CheckOptionalLikeCtor<_Up, _Up const&>::template __enable_implicit<_Up>(), int> = 0>
697 template <class _Up, enable_if_t<_CheckOptionalLikeCtor<_Up, _Up const&>::template __enable_implicit<_Up>(), int> = 0>
698698 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional(const optional<_Up>& __v) {
699699 this->__construct_from(__v);
700700 }
701 template <class _Up,
702 enable_if_t< _CheckOptionalLikeCtor<_Up, _Up const&>::template __enable_explicit<_Up>(), int> = 0>
701 template <class _Up, enable_if_t<_CheckOptionalLikeCtor<_Up, _Up const&>::template __enable_explicit<_Up>(), int> = 0>
703702 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit optional(const optional<_Up>& __v) {
704703 this->__construct_from(__v);
705704 }
706705
707706 // LWG2756: conditionally explicit conversion from optional<_Up>&&
708 template <class _Up, enable_if_t< _CheckOptionalLikeCtor<_Up, _Up&&>::template __enable_implicit<_Up>(), int> = 0>
707 template <class _Up, enable_if_t<_CheckOptionalLikeCtor<_Up, _Up&&>::template __enable_implicit<_Up>(), int> = 0>
709708 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional(optional<_Up>&& __v) {
710709 this->__construct_from(std::move(__v));
711710 }
712 template <class _Up, enable_if_t< _CheckOptionalLikeCtor<_Up, _Up&&>::template __enable_explicit<_Up>(), int> = 0>
711 template <class _Up, enable_if_t<_CheckOptionalLikeCtor<_Up, _Up&&>::template __enable_explicit<_Up>(), int> = 0>
713712 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit optional(optional<_Up>&& __v) {
714713 this->__construct_from(std::move(__v));
715714 }
......@@ -718,7 +717,7 @@ public:
718717 template <class _Tag,
719718 class _Fp,
720719 class... _Args,
721 __enable_if_t<_IsSame<_Tag, __optional_construct_from_invoke_tag>::value, int> = 0>
720 enable_if_t<_IsSame<_Tag, __optional_construct_from_invoke_tag>::value, int> = 0>
722721 _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_Tag, _Fp&& __f, _Args&&... __args)
723722 : __base(__optional_construct_from_invoke_tag{}, std::forward<_Fp>(__f), std::forward<_Args>(__args)...) {}
724723# endif
......@@ -732,12 +731,12 @@ public:
732731 _LIBCPP_HIDE_FROM_ABI constexpr optional& operator=(optional&&) = default;
733732
734733 // LWG2756
735 template <
736 class _Up = value_type,
737 class = enable_if_t< _And< _IsNotSame<__remove_cvref_t<_Up>, optional>,
738 _Or< _IsNotSame<__remove_cvref_t<_Up>, value_type>, _Not<is_scalar<value_type>> >,
739 is_constructible<value_type, _Up>,
740 is_assignable<value_type&, _Up> >::value> >
734 template <class _Up = value_type,
735 enable_if_t<_And<_IsNotSame<__remove_cvref_t<_Up>, optional>,
736 _Or<_IsNotSame<__remove_cvref_t<_Up>, value_type>, _Not<is_scalar<value_type>>>,
737 is_constructible<value_type, _Up>,
738 is_assignable<value_type&, _Up>>::value,
739 int> = 0>
741740 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(_Up&& __v) {
742741 if (this->has_value())
743742 this->__get() = std::forward<_Up>(__v);
......@@ -747,21 +746,20 @@ public:
747746 }
748747
749748 // LWG2756
750 template <class _Up,
751 enable_if_t< _CheckOptionalLikeAssign<_Up, _Up const&>::template __enable_assign<_Up>(), int> = 0>
749 template <class _Up, enable_if_t<_CheckOptionalLikeAssign<_Up, _Up const&>::template __enable_assign<_Up>(), int> = 0>
752750 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(const optional<_Up>& __v) {
753751 this->__assign_from(__v);
754752 return *this;
755753 }
756754
757755 // LWG2756
758 template <class _Up, enable_if_t< _CheckOptionalLikeCtor<_Up, _Up&&>::template __enable_assign<_Up>(), int> = 0>
756 template <class _Up, enable_if_t<_CheckOptionalLikeCtor<_Up, _Up&&>::template __enable_assign<_Up>(), int> = 0>
759757 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(optional<_Up>&& __v) {
760758 this->__assign_from(std::move(__v));
761759 return *this;
762760 }
763761
764 template <class... _Args, class = enable_if_t< is_constructible_v<value_type, _Args...> > >
762 template <class... _Args, enable_if_t<is_constructible_v<value_type, _Args...>, int> = 0>
765763 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& emplace(_Args&&... __args) {
766764 reset();
767765 this->__construct(std::forward<_Args>(__args)...);
......@@ -770,7 +768,7 @@ public:
770768
771769 template <class _Up,
772770 class... _Args,
773 class = enable_if_t< is_constructible_v<value_type, initializer_list<_Up>&, _Args...> > >
771 enable_if_t<is_constructible_v<value_type, initializer_list<_Up>&, _Args...>, int> = 0>
774772 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) {
775773 reset();
776774 this->__construct(__il, std::forward<_Args>(__args)...);
......@@ -829,27 +827,27 @@ public:
829827 using __base::__get;
830828 using __base::has_value;
831829
832 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr value_type const& value() const& {
830 _LIBCPP_HIDE_FROM_ABI constexpr value_type const& value() const& {
833831 if (!this->has_value())
834 __throw_bad_optional_access();
832 std::__throw_bad_optional_access();
835833 return this->__get();
836834 }
837835
838 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr value_type& value() & {
836 _LIBCPP_HIDE_FROM_ABI constexpr value_type& value() & {
839837 if (!this->has_value())
840 __throw_bad_optional_access();
838 std::__throw_bad_optional_access();
841839 return this->__get();
842840 }
843841
844 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr value_type&& value() && {
842 _LIBCPP_HIDE_FROM_ABI constexpr value_type&& value() && {
845843 if (!this->has_value())
846 __throw_bad_optional_access();
844 std::__throw_bad_optional_access();
847845 return std::move(this->__get());
848846 }
849847
850 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr value_type const&& value() const&& {
848 _LIBCPP_HIDE_FROM_ABI constexpr value_type const&& value() const&& {
851849 if (!this->has_value())
852 __throw_bad_optional_access();
850 std::__throw_bad_optional_access();
853851 return std::move(this->__get());
854852 }
855853
......@@ -869,7 +867,7 @@ public:
869867
870868# if _LIBCPP_STD_VER >= 23
871869 template <class _Func>
872 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto and_then(_Func&& __f) & {
870 _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) & {
873871 using _Up = invoke_result_t<_Func, value_type&>;
874872 static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
875873 "Result of f(value()) must be a specialization of std::optional");
......@@ -879,7 +877,7 @@ public:
879877 }
880878
881879 template <class _Func>
882 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto and_then(_Func&& __f) const& {
880 _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) const& {
883881 using _Up = invoke_result_t<_Func, const value_type&>;
884882 static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
885883 "Result of f(value()) must be a specialization of std::optional");
......@@ -889,7 +887,7 @@ public:
889887 }
890888
891889 template <class _Func>
892 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto and_then(_Func&& __f) && {
890 _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) && {
893891 using _Up = invoke_result_t<_Func, value_type&&>;
894892 static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
895893 "Result of f(std::move(value())) must be a specialization of std::optional");
......@@ -909,7 +907,7 @@ public:
909907 }
910908
911909 template <class _Func>
912 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto transform(_Func&& __f) & {
910 _LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) & {
913911 using _Up = remove_cv_t<invoke_result_t<_Func, value_type&>>;
914912 static_assert(!is_array_v<_Up>, "Result of f(value()) should not be an Array");
915913 static_assert(!is_same_v<_Up, in_place_t>, "Result of f(value()) should not be std::in_place_t");
......@@ -921,7 +919,7 @@ public:
921919 }
922920
923921 template <class _Func>
924 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto transform(_Func&& __f) const& {
922 _LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) const& {
925923 using _Up = remove_cv_t<invoke_result_t<_Func, const value_type&>>;
926924 static_assert(!is_array_v<_Up>, "Result of f(value()) should not be an Array");
927925 static_assert(!is_same_v<_Up, in_place_t>, "Result of f(value()) should not be std::in_place_t");
......@@ -933,7 +931,7 @@ public:
933931 }
934932
935933 template <class _Func>
936 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto transform(_Func&& __f) && {
934 _LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) && {
937935 using _Up = remove_cv_t<invoke_result_t<_Func, value_type&&>>;
938936 static_assert(!is_array_v<_Up>, "Result of f(std::move(value())) should not be an Array");
939937 static_assert(!is_same_v<_Up, in_place_t>, "Result of f(std::move(value())) should not be std::in_place_t");
......@@ -945,7 +943,7 @@ public:
945943 }
946944
947945 template <class _Func>
948 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto transform(_Func&& __f) const&& {
946 _LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) const&& {
949947 using _Up = remove_cvref_t<invoke_result_t<_Func, const value_type&&>>;
950948 static_assert(!is_array_v<_Up>, "Result of f(std::move(value())) should not be an Array");
951949 static_assert(!is_same_v<_Up, in_place_t>, "Result of f(std::move(value())) should not be std::in_place_t");
......@@ -982,17 +980,17 @@ public:
982980 using __base::reset;
983981};
984982
985# if _LIBCPP_STD_VER >= 17
986983template <class _Tp>
987984optional(_Tp) -> optional<_Tp>;
988# endif
989985
990// Comparisons between optionals
991template <class _Tp, class _Up>
992_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
993 is_convertible_v<decltype(std::declval<const _Tp&>() == std::declval<const _Up&>()), bool>,
994 bool >
995operator==(const optional<_Tp>& __x, const optional<_Up>& __y) {
986// [optional.relops] Relational operators
987
988template <
989 class _Tp,
990 class _Up,
991 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() == std::declval<const _Up&>()), bool>,
992 int> = 0>
993_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, const optional<_Up>& __y) {
996994 if (static_cast<bool>(__x) != static_cast<bool>(__y))
997995 return false;
998996 if (!static_cast<bool>(__x))
......@@ -1000,11 +998,12 @@ operator==(const optional<_Tp>& __x, const optional<_Up>& __y) {
1000998 return *__x == *__y;
1001999}
10021000
1003template <class _Tp, class _Up>
1004_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
1005 is_convertible_v<decltype(std::declval<const _Tp&>() != std::declval<const _Up&>()), bool>,
1006 bool >
1007operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) {
1001template <
1002 class _Tp,
1003 class _Up,
1004 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() != std::declval<const _Up&>()), bool>,
1005 int> = 0>
1006_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) {
10081007 if (static_cast<bool>(__x) != static_cast<bool>(__y))
10091008 return true;
10101009 if (!static_cast<bool>(__x))
......@@ -1012,11 +1011,11 @@ operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) {
10121011 return *__x != *__y;
10131012}
10141013
1015template <class _Tp, class _Up>
1016_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
1017 is_convertible_v<decltype(std::declval<const _Tp&>() < std::declval<const _Up&>()), bool>,
1018 bool >
1019operator<(const optional<_Tp>& __x, const optional<_Up>& __y) {
1014template < class _Tp,
1015 class _Up,
1016 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() < std::declval<const _Up&>()), bool>,
1017 int> = 0>
1018_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const optional<_Tp>& __x, const optional<_Up>& __y) {
10201019 if (!static_cast<bool>(__y))
10211020 return false;
10221021 if (!static_cast<bool>(__x))
......@@ -1024,11 +1023,11 @@ operator<(const optional<_Tp>& __x, const optional<_Up>& __y) {
10241023 return *__x < *__y;
10251024}
10261025
1027template <class _Tp, class _Up>
1028_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
1029 is_convertible_v<decltype(std::declval<const _Tp&>() > std::declval<const _Up&>()), bool>,
1030 bool >
1031operator>(const optional<_Tp>& __x, const optional<_Up>& __y) {
1026template < class _Tp,
1027 class _Up,
1028 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() > std::declval<const _Up&>()), bool>,
1029 int> = 0>
1030_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const optional<_Tp>& __x, const optional<_Up>& __y) {
10321031 if (!static_cast<bool>(__x))
10331032 return false;
10341033 if (!static_cast<bool>(__y))
......@@ -1036,11 +1035,12 @@ operator>(const optional<_Tp>& __x, const optional<_Up>& __y) {
10361035 return *__x > *__y;
10371036}
10381037
1039template <class _Tp, class _Up>
1040_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
1041 is_convertible_v<decltype(std::declval<const _Tp&>() <= std::declval<const _Up&>()), bool>,
1042 bool >
1043operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) {
1038template <
1039 class _Tp,
1040 class _Up,
1041 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() <= std::declval<const _Up&>()), bool>,
1042 int> = 0>
1043_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) {
10441044 if (!static_cast<bool>(__x))
10451045 return true;
10461046 if (!static_cast<bool>(__y))
......@@ -1048,11 +1048,12 @@ operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) {
10481048 return *__x <= *__y;
10491049}
10501050
1051template <class _Tp, class _Up>
1052_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
1053 is_convertible_v<decltype(std::declval<const _Tp&>() >= std::declval<const _Up&>()), bool>,
1054 bool >
1055operator>=(const optional<_Tp>& __x, const optional<_Up>& __y) {
1051template <
1052 class _Tp,
1053 class _Up,
1054 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() >= std::declval<const _Up&>()), bool>,
1055 int> = 0>
1056_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const optional<_Tp>& __x, const optional<_Up>& __y) {
10561057 if (!static_cast<bool>(__y))
10571058 return true;
10581059 if (!static_cast<bool>(__x))
......@@ -1072,7 +1073,8 @@ operator<=>(const optional<_Tp>& __x, const optional<_Up>& __y) {
10721073
10731074# endif // _LIBCPP_STD_VER >= 20
10741075
1075// Comparisons with nullopt
1076// [optional.nullops] Comparison with nullopt
1077
10761078template <class _Tp>
10771079_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, nullopt_t) noexcept {
10781080 return !static_cast<bool>(__x);
......@@ -1144,100 +1146,109 @@ _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const optional<_Tp>&
11441146
11451147# endif // _LIBCPP_STD_VER <= 17
11461148
1147// Comparisons with T
1148template <class _Tp, class _Up>
1149_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
1150 is_convertible_v<decltype(std::declval<const _Tp&>() == std::declval<const _Up&>()), bool>,
1151 bool >
1152operator==(const optional<_Tp>& __x, const _Up& __v) {
1149// [optional.comp.with.t] Comparison with T
1150
1151template <
1152 class _Tp,
1153 class _Up,
1154 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() == std::declval<const _Up&>()), bool>,
1155 int> = 0>
1156_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, const _Up& __v) {
11531157 return static_cast<bool>(__x) ? *__x == __v : false;
11541158}
11551159
1156template <class _Tp, class _Up>
1157_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
1158 is_convertible_v<decltype(std::declval<const _Tp&>() == std::declval<const _Up&>()), bool>,
1159 bool >
1160operator==(const _Tp& __v, const optional<_Up>& __x) {
1160template <
1161 class _Tp,
1162 class _Up,
1163 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() == std::declval<const _Up&>()), bool>,
1164 int> = 0>
1165_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const _Tp& __v, const optional<_Up>& __x) {
11611166 return static_cast<bool>(__x) ? __v == *__x : false;
11621167}
11631168
1164template <class _Tp, class _Up>
1165_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
1166 is_convertible_v<decltype(std::declval<const _Tp&>() != std::declval<const _Up&>()), bool>,
1167 bool >
1168operator!=(const optional<_Tp>& __x, const _Up& __v) {
1169template <
1170 class _Tp,
1171 class _Up,
1172 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() != std::declval<const _Up&>()), bool>,
1173 int> = 0>
1174_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const optional<_Tp>& __x, const _Up& __v) {
11691175 return static_cast<bool>(__x) ? *__x != __v : true;
11701176}
11711177
1172template <class _Tp, class _Up>
1173_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
1174 is_convertible_v<decltype(std::declval<const _Tp&>() != std::declval<const _Up&>()), bool>,
1175 bool >
1176operator!=(const _Tp& __v, const optional<_Up>& __x) {
1178template <
1179 class _Tp,
1180 class _Up,
1181 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() != std::declval<const _Up&>()), bool>,
1182 int> = 0>
1183_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const _Tp& __v, const optional<_Up>& __x) {
11771184 return static_cast<bool>(__x) ? __v != *__x : true;
11781185}
11791186
1180template <class _Tp, class _Up>
1181_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
1182 is_convertible_v<decltype(std::declval<const _Tp&>() < std::declval<const _Up&>()), bool>,
1183 bool >
1184operator<(const optional<_Tp>& __x, const _Up& __v) {
1187template < class _Tp,
1188 class _Up,
1189 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() < std::declval<const _Up&>()), bool>,
1190 int> = 0>
1191_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const optional<_Tp>& __x, const _Up& __v) {
11851192 return static_cast<bool>(__x) ? *__x < __v : true;
11861193}
11871194
1188template <class _Tp, class _Up>
1189_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
1190 is_convertible_v<decltype(std::declval<const _Tp&>() < std::declval<const _Up&>()), bool>,
1191 bool >
1192operator<(const _Tp& __v, const optional<_Up>& __x) {
1195template < class _Tp,
1196 class _Up,
1197 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() < std::declval<const _Up&>()), bool>,
1198 int> = 0>
1199_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const _Tp& __v, const optional<_Up>& __x) {
11931200 return static_cast<bool>(__x) ? __v < *__x : false;
11941201}
11951202
1196template <class _Tp, class _Up>
1197_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
1198 is_convertible_v<decltype(std::declval<const _Tp&>() <= std::declval<const _Up&>()), bool>,
1199 bool >
1200operator<=(const optional<_Tp>& __x, const _Up& __v) {
1203template <
1204 class _Tp,
1205 class _Up,
1206 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() <= std::declval<const _Up&>()), bool>,
1207 int> = 0>
1208_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const optional<_Tp>& __x, const _Up& __v) {
12011209 return static_cast<bool>(__x) ? *__x <= __v : true;
12021210}
12031211
1204template <class _Tp, class _Up>
1205_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
1206 is_convertible_v<decltype(std::declval<const _Tp&>() <= std::declval<const _Up&>()), bool>,
1207 bool >
1208operator<=(const _Tp& __v, const optional<_Up>& __x) {
1212template <
1213 class _Tp,
1214 class _Up,
1215 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() <= std::declval<const _Up&>()), bool>,
1216 int> = 0>
1217_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const _Tp& __v, const optional<_Up>& __x) {
12091218 return static_cast<bool>(__x) ? __v <= *__x : false;
12101219}
12111220
1212template <class _Tp, class _Up>
1213_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
1214 is_convertible_v<decltype(std::declval<const _Tp&>() > std::declval<const _Up&>()), bool>,
1215 bool >
1216operator>(const optional<_Tp>& __x, const _Up& __v) {
1221template < class _Tp,
1222 class _Up,
1223 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() > std::declval<const _Up&>()), bool>,
1224 int> = 0>
1225_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const optional<_Tp>& __x, const _Up& __v) {
12171226 return static_cast<bool>(__x) ? *__x > __v : false;
12181227}
12191228
1220template <class _Tp, class _Up>
1221_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
1222 is_convertible_v<decltype(std::declval<const _Tp&>() > std::declval<const _Up&>()), bool>,
1223 bool >
1224operator>(const _Tp& __v, const optional<_Up>& __x) {
1229template < class _Tp,
1230 class _Up,
1231 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() > std::declval<const _Up&>()), bool>,
1232 int> = 0>
1233_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const _Tp& __v, const optional<_Up>& __x) {
12251234 return static_cast<bool>(__x) ? __v > *__x : true;
12261235}
12271236
1228template <class _Tp, class _Up>
1229_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
1230 is_convertible_v<decltype(std::declval<const _Tp&>() >= std::declval<const _Up&>()), bool>,
1231 bool >
1232operator>=(const optional<_Tp>& __x, const _Up& __v) {
1237template <
1238 class _Tp,
1239 class _Up,
1240 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() >= std::declval<const _Up&>()), bool>,
1241 int> = 0>
1242_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const optional<_Tp>& __x, const _Up& __v) {
12331243 return static_cast<bool>(__x) ? *__x >= __v : false;
12341244}
12351245
1236template <class _Tp, class _Up>
1237_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<
1238 is_convertible_v<decltype(std::declval<const _Tp&>() >= std::declval<const _Up&>()), bool>,
1239 bool >
1240operator>=(const _Tp& __v, const optional<_Up>& __x) {
1246template <
1247 class _Tp,
1248 class _Up,
1249 enable_if_t<__is_core_convertible_v<decltype(std::declval<const _Tp&>() >= std::declval<const _Up&>()), bool>,
1250 int> = 0>
1251_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const _Tp& __v, const optional<_Up>& __x) {
12411252 return static_cast<bool>(__x) ? __v >= *__x : true;
12421253}
12431254
......@@ -1252,9 +1263,8 @@ operator<=>(const optional<_Tp>& __x, const _Up& __v) {
12521263
12531264# endif // _LIBCPP_STD_VER >= 20
12541265
1255template <class _Tp>
1256inline _LIBCPP_HIDE_FROM_ABI
1257_LIBCPP_CONSTEXPR_SINCE_CXX20 enable_if_t< is_move_constructible_v<_Tp> && is_swappable_v<_Tp>, void >
1266template <class _Tp, enable_if_t< is_move_constructible_v<_Tp> && is_swappable_v<_Tp>, int> = 0>
1267inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
12581268swap(optional<_Tp>& __x, optional<_Tp>& __y) noexcept(noexcept(__x.swap(__y))) {
12591269 __x.swap(__y);
12601270}
......@@ -1275,7 +1285,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr optional<_Tp> make_optional(initializer_list<_Up
12751285}
12761286
12771287template <class _Tp>
1278struct _LIBCPP_TEMPLATE_VIS hash< __enable_hash_helper<optional<_Tp>, remove_const_t<_Tp>> > {
1288struct hash< __enable_hash_helper<optional<_Tp>, remove_const_t<_Tp>> > {
12791289# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
12801290 _LIBCPP_DEPRECATED_IN_CXX17 typedef optional<_Tp> argument_type;
12811291 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
lib/libcxx/include/ostream+5
......@@ -205,6 +205,11 @@ void vprint_nonunicode(ostream& os, string_view fmt, format_args args);
205205# include <stdexcept>
206206# include <type_traits>
207207# endif
208
209# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 23
210# include <locale>
211# endif
212
208213#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
209214
210215#endif // _LIBCPP_OSTREAM
lib/libcxx/include/print+2-2
......@@ -34,7 +34,7 @@ namespace std {
3434*/
3535
3636#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
37# include <__cxx03/print>
37# include <__cxx03/__config>
3838#else
3939# include <__assert>
4040# include <__concepts/same_as.h>
......@@ -123,7 +123,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr void __encode(_OutIt& __out_it, char32_t __value
123123 _LIBCPP_ASSERT_UNCATEGORIZED(__is_scalar_value(__value), "an invalid unicode scalar value results in invalid UTF-16");
124124
125125 if (__value < 0x10000) {
126 *__out_it++ = __value;
126 *__out_it++ = static_cast<iter_value_t<_OutIt>>(__value);
127127 return;
128128 }
129129
lib/libcxx/include/queue+88-69
......@@ -299,7 +299,7 @@ template <class _Tp, class _Container>
299299_LIBCPP_HIDE_FROM_ABI bool operator<(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y);
300300
301301template <class _Tp, class _Container /*= deque<_Tp>*/>
302class _LIBCPP_TEMPLATE_VIS queue {
302class queue {
303303public:
304304 typedef _Container container_type;
305305 typedef typename container_type::value_type value_type;
......@@ -428,6 +428,12 @@ public:
428428 template <class _T1, class _OtherContainer>
429429 friend _LIBCPP_HIDE_FROM_ABI bool
430430 operator<(const queue<_T1, _OtherContainer>& __x, const queue<_T1, _OtherContainer>& __y);
431
432# if _LIBCPP_STD_VER >= 20
433 template <class _T1, three_way_comparable _OtherContainer>
434 friend _LIBCPP_HIDE_FROM_ABI compare_three_way_result_t<_OtherContainer>
435 operator<=>(const queue<_T1, _OtherContainer>& __x, const queue<_T1, _OtherContainer>& __y);
436# endif
431437};
432438
433439# if _LIBCPP_STD_VER >= 17
......@@ -452,14 +458,12 @@ template <class _InputIterator,
452458 class _Alloc,
453459 __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0,
454460 __enable_if_t<__is_allocator<_Alloc>::value, int> = 0>
455queue(_InputIterator,
456 _InputIterator,
457 _Alloc) -> queue<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>;
461queue(_InputIterator, _InputIterator, _Alloc)
462 -> queue<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>;
458463
459464template <ranges::input_range _Range, class _Alloc, __enable_if_t<__is_allocator<_Alloc>::value, int> = 0>
460queue(from_range_t,
461 _Range&&,
462 _Alloc) -> queue<ranges::range_value_t<_Range>, deque<ranges::range_value_t<_Range>, _Alloc>>;
465queue(from_range_t, _Range&&, _Alloc)
466 -> queue<ranges::range_value_t<_Range>, deque<ranges::range_value_t<_Range>, _Alloc>>;
463467# endif
464468
465469template <class _Tp, class _Container>
......@@ -497,8 +501,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const queue<_Tp, _Container>& __x,
497501template <class _Tp, three_way_comparable _Container>
498502_LIBCPP_HIDE_FROM_ABI compare_three_way_result_t<_Container>
499503operator<=>(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) {
500 // clang 16 bug: declaring `friend operator<=>` causes "use of overloaded operator '*' is ambiguous" errors
501 return __x.__get_container() <=> __y.__get_container();
504 return __x.c <=> __y.c;
502505}
503506
504507# endif
......@@ -510,11 +513,10 @@ inline _LIBCPP_HIDE_FROM_ABI void swap(queue<_Tp, _Container>& __x, queue<_Tp, _
510513}
511514
512515template <class _Tp, class _Container, class _Alloc>
513struct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc> : public uses_allocator<_Container, _Alloc> {
514};
516struct uses_allocator<queue<_Tp, _Container>, _Alloc> : public uses_allocator<_Container, _Alloc> {};
515517
516518template <class _Tp, class _Container, class _Compare>
517class _LIBCPP_TEMPLATE_VIS priority_queue {
519class priority_queue {
518520public:
519521 typedef _Container container_type;
520522 typedef _Compare value_compare;
......@@ -529,24 +531,25 @@ protected:
529531 value_compare comp;
530532
531533public:
532 _LIBCPP_HIDE_FROM_ABI priority_queue() _NOEXCEPT_(
534 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue() _NOEXCEPT_(
533535 is_nothrow_default_constructible<container_type>::value&& is_nothrow_default_constructible<value_compare>::value)
534536 : c(), comp() {}
535537
536 _LIBCPP_HIDE_FROM_ABI priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
538 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(const priority_queue& __q)
539 : c(__q.c), comp(__q.comp) {}
537540
538 _LIBCPP_HIDE_FROM_ABI priority_queue& operator=(const priority_queue& __q) {
541 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue& operator=(const priority_queue& __q) {
539542 c = __q.c;
540543 comp = __q.comp;
541544 return *this;
542545 }
543546
544547# ifndef _LIBCPP_CXX03_LANG
545 _LIBCPP_HIDE_FROM_ABI priority_queue(priority_queue&& __q) noexcept(
548 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(priority_queue&& __q) noexcept(
546549 is_nothrow_move_constructible<container_type>::value && is_nothrow_move_constructible<value_compare>::value)
547550 : c(std::move(__q.c)), comp(std::move(__q.comp)) {}
548551
549 _LIBCPP_HIDE_FROM_ABI priority_queue& operator=(priority_queue&& __q) noexcept(
552 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue& operator=(priority_queue&& __q) noexcept(
550553 is_nothrow_move_assignable<container_type>::value && is_nothrow_move_assignable<value_compare>::value) {
551554 c = std::move(__q.c);
552555 comp = std::move(__q.comp);
......@@ -554,50 +557,56 @@ public:
554557 }
555558# endif // _LIBCPP_CXX03_LANG
556559
557 _LIBCPP_HIDE_FROM_ABI explicit priority_queue(const value_compare& __comp) : c(), comp(__comp) {}
558 _LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, const container_type& __c);
560 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit priority_queue(const value_compare& __comp)
561 : c(), comp(__comp) {}
562 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
563 priority_queue(const value_compare& __comp, const container_type& __c);
559564# ifndef _LIBCPP_CXX03_LANG
560 _LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, container_type&& __c);
565 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, container_type&& __c);
561566# endif
562567 template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
563 _LIBCPP_HIDE_FROM_ABI priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp = value_compare());
568 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
569 priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp = value_compare());
564570
565571 template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
566 _LIBCPP_HIDE_FROM_ABI
572 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
567573 priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, const container_type& __c);
568574
569575# ifndef _LIBCPP_CXX03_LANG
570576 template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
571 _LIBCPP_HIDE_FROM_ABI
577 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
572578 priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c);
573579# endif // _LIBCPP_CXX03_LANG
574580
575581# if _LIBCPP_STD_VER >= 23
576582 template <_ContainerCompatibleRange<_Tp> _Range>
577 _LIBCPP_HIDE_FROM_ABI priority_queue(from_range_t, _Range&& __range, const value_compare& __comp = value_compare())
583 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
584 priority_queue(from_range_t, _Range&& __range, const value_compare& __comp = value_compare())
578585 : c(from_range, std::forward<_Range>(__range)), comp(__comp) {
579586 std::make_heap(c.begin(), c.end(), comp);
580587 }
581588# endif
582589
583590 template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
584 _LIBCPP_HIDE_FROM_ABI explicit priority_queue(const _Alloc& __a);
591 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit priority_queue(const _Alloc& __a);
585592
586593 template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
587 _LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, const _Alloc& __a);
594 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, const _Alloc& __a);
588595
589596 template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
590 _LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, const container_type& __c, const _Alloc& __a);
597 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
598 priority_queue(const value_compare& __comp, const container_type& __c, const _Alloc& __a);
591599
592600 template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
593 _LIBCPP_HIDE_FROM_ABI priority_queue(const priority_queue& __q, const _Alloc& __a);
601 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(const priority_queue& __q, const _Alloc& __a);
594602
595603# ifndef _LIBCPP_CXX03_LANG
596604 template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
597 _LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, container_type&& __c, const _Alloc& __a);
605 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
606 priority_queue(const value_compare& __comp, container_type&& __c, const _Alloc& __a);
598607
599608 template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
600 _LIBCPP_HIDE_FROM_ABI priority_queue(priority_queue&& __q, const _Alloc& __a);
609 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(priority_queue&& __q, const _Alloc& __a);
601610# endif // _LIBCPP_CXX03_LANG
602611
603612 template <
......@@ -605,21 +614,22 @@ public:
605614 class _Alloc,
606615 __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<container_type, _Alloc>::value,
607616 int> = 0>
608 _LIBCPP_HIDE_FROM_ABI priority_queue(_InputIter __f, _InputIter __l, const _Alloc& __a);
617 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(_InputIter __f, _InputIter __l, const _Alloc& __a);
609618
610619 template <
611620 class _InputIter,
612621 class _Alloc,
613622 __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<container_type, _Alloc>::value,
614623 int> = 0>
615 _LIBCPP_HIDE_FROM_ABI priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, const _Alloc& __a);
624 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
625 priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, const _Alloc& __a);
616626
617627 template <
618628 class _InputIter,
619629 class _Alloc,
620630 __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<container_type, _Alloc>::value,
621631 int> = 0>
622 _LIBCPP_HIDE_FROM_ABI priority_queue(
632 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(
623633 _InputIter __f, _InputIter __l, const value_compare& __comp, const container_type& __c, const _Alloc& __a);
624634
625635# ifndef _LIBCPP_CXX03_LANG
......@@ -628,7 +638,7 @@ public:
628638 class _Alloc,
629639 __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<container_type, _Alloc>::value,
630640 int> = 0>
631 _LIBCPP_HIDE_FROM_ABI
641 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
632642 priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c, const _Alloc& __a);
633643# endif // _LIBCPP_CXX03_LANG
634644
......@@ -637,7 +647,8 @@ public:
637647 template <_ContainerCompatibleRange<_Tp> _Range,
638648 class _Alloc,
639649 class = enable_if_t<uses_allocator<_Container, _Alloc>::value>>
640 _LIBCPP_HIDE_FROM_ABI priority_queue(from_range_t, _Range&& __range, const value_compare& __comp, const _Alloc& __a)
650 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
651 priority_queue(from_range_t, _Range&& __range, const value_compare& __comp, const _Alloc& __a)
641652 : c(from_range, std::forward<_Range>(__range), __a), comp(__comp) {
642653 std::make_heap(c.begin(), c.end(), comp);
643654 }
......@@ -645,24 +656,24 @@ public:
645656 template <_ContainerCompatibleRange<_Tp> _Range,
646657 class _Alloc,
647658 class = enable_if_t<uses_allocator<_Container, _Alloc>::value>>
648 _LIBCPP_HIDE_FROM_ABI priority_queue(from_range_t, _Range&& __range, const _Alloc& __a)
659 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(from_range_t, _Range&& __range, const _Alloc& __a)
649660 : c(from_range, std::forward<_Range>(__range), __a), comp() {
650661 std::make_heap(c.begin(), c.end(), comp);
651662 }
652663
653664# endif
654665
655 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); }
656 _LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); }
657 _LIBCPP_HIDE_FROM_ABI const_reference top() const { return c.front(); }
666 [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); }
667 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); }
668 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_reference top() const { return c.front(); }
658669
659 _LIBCPP_HIDE_FROM_ABI void push(const value_type& __v);
670 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void push(const value_type& __v);
660671# ifndef _LIBCPP_CXX03_LANG
661 _LIBCPP_HIDE_FROM_ABI void push(value_type&& __v);
672 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void push(value_type&& __v);
662673
663674# if _LIBCPP_STD_VER >= 23
664675 template <_ContainerCompatibleRange<_Tp> _Range>
665 _LIBCPP_HIDE_FROM_ABI void push_range(_Range&& __range) {
676 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void push_range(_Range&& __range) {
666677 if constexpr (requires(container_type& __c) { __c.append_range(std::forward<_Range>(__range)); }) {
667678 c.append_range(std::forward<_Range>(__range));
668679 } else {
......@@ -674,14 +685,16 @@ public:
674685# endif
675686
676687 template <class... _Args>
677 _LIBCPP_HIDE_FROM_ABI void emplace(_Args&&... __args);
688 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void emplace(_Args&&... __args);
678689# endif // _LIBCPP_CXX03_LANG
679 _LIBCPP_HIDE_FROM_ABI void pop();
690 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void pop();
680691
681 _LIBCPP_HIDE_FROM_ABI void swap(priority_queue& __q)
692 _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void swap(priority_queue& __q)
682693 _NOEXCEPT_(__is_nothrow_swappable_v<container_type>&& __is_nothrow_swappable_v<value_compare>);
683694
684 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; }
695 [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const {
696 return c;
697 }
685698};
686699
687700# if _LIBCPP_STD_VER >= 17
......@@ -763,7 +776,8 @@ priority_queue(from_range_t, _Range&&, _Alloc)
763776# endif
764777
765778template <class _Tp, class _Container, class _Compare>
766inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp, const container_type& __c)
779_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
780 const _Compare& __comp, const container_type& __c)
767781 : c(__c), comp(__comp) {
768782 std::make_heap(c.begin(), c.end(), comp);
769783}
......@@ -771,7 +785,8 @@ inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare&
771785# ifndef _LIBCPP_CXX03_LANG
772786
773787template <class _Tp, class _Container, class _Compare>
774inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, container_type&& __c)
788_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
789 const value_compare& __comp, container_type&& __c)
775790 : c(std::move(__c)), comp(__comp) {
776791 std::make_heap(c.begin(), c.end(), comp);
777792}
......@@ -780,7 +795,7 @@ inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_com
780795
781796template <class _Tp, class _Container, class _Compare>
782797template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> >
783inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
798_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
784799 _InputIter __f, _InputIter __l, const value_compare& __comp)
785800 : c(__f, __l), comp(__comp) {
786801 std::make_heap(c.begin(), c.end(), comp);
......@@ -788,7 +803,7 @@ inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
788803
789804template <class _Tp, class _Container, class _Compare>
790805template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> >
791inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
806_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
792807 _InputIter __f, _InputIter __l, const value_compare& __comp, const container_type& __c)
793808 : c(__c), comp(__comp) {
794809 c.insert(c.end(), __f, __l);
......@@ -799,7 +814,7 @@ inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
799814
800815template <class _Tp, class _Container, class _Compare>
801816template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> >
802inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
817_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
803818 _InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c)
804819 : c(std::move(__c)), comp(__comp) {
805820 c.insert(c.end(), __f, __l);
......@@ -810,16 +825,18 @@ inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
810825
811826template <class _Tp, class _Container, class _Compare>
812827template <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> >
813inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a) : c(__a) {}
828_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a)
829 : c(__a) {}
814830
815831template <class _Tp, class _Container, class _Compare>
816832template <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> >
817inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, const _Alloc& __a)
833_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
834 const value_compare& __comp, const _Alloc& __a)
818835 : c(__a), comp(__comp) {}
819836
820837template <class _Tp, class _Container, class _Compare>
821838template <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> >
822inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
839_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
823840 const value_compare& __comp, const container_type& __c, const _Alloc& __a)
824841 : c(__c, __a), comp(__comp) {
825842 std::make_heap(c.begin(), c.end(), comp);
......@@ -827,14 +844,15 @@ inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
827844
828845template <class _Tp, class _Container, class _Compare>
829846template <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> >
830inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q, const _Alloc& __a)
847_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
848 const priority_queue& __q, const _Alloc& __a)
831849 : c(__q.c, __a), comp(__q.comp) {}
832850
833851# ifndef _LIBCPP_CXX03_LANG
834852
835853template <class _Tp, class _Container, class _Compare>
836854template <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> >
837inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
855_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
838856 const value_compare& __comp, container_type&& __c, const _Alloc& __a)
839857 : c(std::move(__c), __a), comp(__comp) {
840858 std::make_heap(c.begin(), c.end(), comp);
......@@ -842,7 +860,8 @@ inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
842860
843861template <class _Tp, class _Container, class _Compare>
844862template <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> >
845inline priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q, const _Alloc& __a)
863_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
864 priority_queue&& __q, const _Alloc& __a)
846865 : c(std::move(__q.c), __a), comp(std::move(__q.comp)) {}
847866
848867# endif // _LIBCPP_CXX03_LANG
......@@ -852,7 +871,8 @@ template <
852871 class _InputIter,
853872 class _Alloc,
854873 __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<_Container, _Alloc>::value, int> >
855inline priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l, const _Alloc& __a)
874_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
875 _InputIter __f, _InputIter __l, const _Alloc& __a)
856876 : c(__f, __l, __a), comp() {
857877 std::make_heap(c.begin(), c.end(), comp);
858878}
......@@ -862,7 +882,7 @@ template <
862882 class _InputIter,
863883 class _Alloc,
864884 __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<_Container, _Alloc>::value, int> >
865inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
885_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
866886 _InputIter __f, _InputIter __l, const value_compare& __comp, const _Alloc& __a)
867887 : c(__f, __l, __a), comp(__comp) {
868888 std::make_heap(c.begin(), c.end(), comp);
......@@ -873,7 +893,7 @@ template <
873893 class _InputIter,
874894 class _Alloc,
875895 __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<_Container, _Alloc>::value, int> >
876inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
896_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
877897 _InputIter __f, _InputIter __l, const value_compare& __comp, const container_type& __c, const _Alloc& __a)
878898 : c(__c, __a), comp(__comp) {
879899 c.insert(c.end(), __f, __l);
......@@ -886,7 +906,7 @@ template <
886906 class _InputIter,
887907 class _Alloc,
888908 __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<_Container, _Alloc>::value, int> >
889inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
909_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
890910 _InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c, const _Alloc& __a)
891911 : c(std::move(__c), __a), comp(__comp) {
892912 c.insert(c.end(), __f, __l);
......@@ -895,7 +915,7 @@ inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
895915# endif // _LIBCPP_CXX03_LANG
896916
897917template <class _Tp, class _Container, class _Compare>
898inline void priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v) {
918_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v) {
899919 c.push_back(__v);
900920 std::push_heap(c.begin(), c.end(), comp);
901921}
......@@ -903,14 +923,14 @@ inline void priority_queue<_Tp, _Container, _Compare>::push(const value_type& __
903923# ifndef _LIBCPP_CXX03_LANG
904924
905925template <class _Tp, class _Container, class _Compare>
906inline void priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v) {
926_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v) {
907927 c.push_back(std::move(__v));
908928 std::push_heap(c.begin(), c.end(), comp);
909929}
910930
911931template <class _Tp, class _Container, class _Compare>
912932template <class... _Args>
913inline void priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args) {
933_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args) {
914934 c.emplace_back(std::forward<_Args>(__args)...);
915935 std::push_heap(c.begin(), c.end(), comp);
916936}
......@@ -918,13 +938,13 @@ inline void priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args
918938# endif // _LIBCPP_CXX03_LANG
919939
920940template <class _Tp, class _Container, class _Compare>
921inline void priority_queue<_Tp, _Container, _Compare>::pop() {
941_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void priority_queue<_Tp, _Container, _Compare>::pop() {
922942 std::pop_heap(c.begin(), c.end(), comp);
923943 c.pop_back();
924944}
925945
926946template <class _Tp, class _Container, class _Compare>
927inline void priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
947_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
928948 _NOEXCEPT_(__is_nothrow_swappable_v<container_type>&& __is_nothrow_swappable_v<value_compare>) {
929949 using std::swap;
930950 swap(c, __q.c);
......@@ -935,15 +955,14 @@ template <class _Tp,
935955 class _Container,
936956 class _Compare,
937957 __enable_if_t<__is_swappable_v<_Container> && __is_swappable_v<_Compare>, int> = 0>
938inline _LIBCPP_HIDE_FROM_ABI void
958_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI void
939959swap(priority_queue<_Tp, _Container, _Compare>& __x, priority_queue<_Tp, _Container, _Compare>& __y)
940960 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
941961 __x.swap(__y);
942962}
943963
944964template <class _Tp, class _Container, class _Compare, class _Alloc>
945struct _LIBCPP_TEMPLATE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
946 : public uses_allocator<_Container, _Alloc> {};
965struct uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc> : public uses_allocator<_Container, _Alloc> {};
947966
948967_LIBCPP_END_NAMESPACE_STD
949968
lib/libcxx/include/ranges+11-1
......@@ -285,6 +285,15 @@ namespace std::ranges {
285285 requires view<V> && input_range<range_reference_t<V>>
286286 class join_view;
287287
288 // [range.join.with], join with view
289 template<input_range V, forward_range Pattern>
290 requires view<V> && input_range<range_reference_t<V>>
291 && view<Pattern>
292 && concatable<range_reference_t<V>, Pattern>
293 class join_with_view; // since C++23
294
295 namespace views { inline constexpr unspecified join_with = unspecified; } // since C++23
296
288297 // [range.lazy.split], lazy split view
289298 template<class R>
290299 concept tiny-range = see below; // exposition only
......@@ -381,7 +390,7 @@ namespace std {
381390*/
382391
383392#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
384# include <__cxx03/ranges>
393# include <__cxx03/__config>
385394#else
386395# include <__config>
387396
......@@ -427,6 +436,7 @@ namespace std {
427436# include <__ranges/as_rvalue_view.h>
428437# include <__ranges/chunk_by_view.h>
429438# include <__ranges/from_range.h>
439# include <__ranges/join_with_view.h>
430440# include <__ranges/repeat_view.h>
431441# include <__ranges/to.h>
432442# include <__ranges/zip_view.h>
lib/libcxx/include/ratio+11-11
......@@ -229,7 +229,7 @@ public:
229229};
230230
231231template <intmax_t _Num, intmax_t _Den = 1>
232class _LIBCPP_TEMPLATE_VIS ratio {
232class ratio {
233233 static_assert(__static_abs<_Num> >= 0, "ratio numerator is out of range");
234234 static_assert(_Den != 0, "ratio divide by 0");
235235 static_assert(__static_abs<_Den> > 0, "ratio denominator is out of range");
......@@ -290,7 +290,7 @@ using ratio_multiply = typename __ratio_multiply<_R1, _R2>::type;
290290# else // _LIBCPP_CXX03_LANG
291291
292292template <class _R1, class _R2>
293struct _LIBCPP_TEMPLATE_VIS ratio_multiply : public __ratio_multiply<_R1, _R2>::type {};
293struct ratio_multiply : public __ratio_multiply<_R1, _R2>::type {};
294294
295295# endif // _LIBCPP_CXX03_LANG
296296
......@@ -316,7 +316,7 @@ using ratio_divide = typename __ratio_divide<_R1, _R2>::type;
316316# else // _LIBCPP_CXX03_LANG
317317
318318template <class _R1, class _R2>
319struct _LIBCPP_TEMPLATE_VIS ratio_divide : public __ratio_divide<_R1, _R2>::type {};
319struct ratio_divide : public __ratio_divide<_R1, _R2>::type {};
320320
321321# endif // _LIBCPP_CXX03_LANG
322322
......@@ -345,7 +345,7 @@ using ratio_add = typename __ratio_add<_R1, _R2>::type;
345345# else // _LIBCPP_CXX03_LANG
346346
347347template <class _R1, class _R2>
348struct _LIBCPP_TEMPLATE_VIS ratio_add : public __ratio_add<_R1, _R2>::type {};
348struct ratio_add : public __ratio_add<_R1, _R2>::type {};
349349
350350# endif // _LIBCPP_CXX03_LANG
351351
......@@ -374,20 +374,20 @@ using ratio_subtract = typename __ratio_subtract<_R1, _R2>::type;
374374# else // _LIBCPP_CXX03_LANG
375375
376376template <class _R1, class _R2>
377struct _LIBCPP_TEMPLATE_VIS ratio_subtract : public __ratio_subtract<_R1, _R2>::type {};
377struct ratio_subtract : public __ratio_subtract<_R1, _R2>::type {};
378378
379379# endif // _LIBCPP_CXX03_LANG
380380
381381// ratio_equal
382382
383383template <class _R1, class _R2>
384struct _LIBCPP_TEMPLATE_VIS ratio_equal : _BoolConstant<(_R1::num == _R2::num && _R1::den == _R2::den)> {
384struct ratio_equal : _BoolConstant<(_R1::num == _R2::num && _R1::den == _R2::den)> {
385385 static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
386386 static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
387387};
388388
389389template <class _R1, class _R2>
390struct _LIBCPP_TEMPLATE_VIS ratio_not_equal : _BoolConstant<!ratio_equal<_R1, _R2>::value> {
390struct ratio_not_equal : _BoolConstant<!ratio_equal<_R1, _R2>::value> {
391391 static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
392392 static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
393393};
......@@ -441,25 +441,25 @@ struct __ratio_less<_R1, _R2, -1LL, -1LL> {
441441};
442442
443443template <class _R1, class _R2>
444struct _LIBCPP_TEMPLATE_VIS ratio_less : _BoolConstant<__ratio_less<_R1, _R2>::value> {
444struct ratio_less : _BoolConstant<__ratio_less<_R1, _R2>::value> {
445445 static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
446446 static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
447447};
448448
449449template <class _R1, class _R2>
450struct _LIBCPP_TEMPLATE_VIS ratio_less_equal : _BoolConstant<!ratio_less<_R2, _R1>::value> {
450struct ratio_less_equal : _BoolConstant<!ratio_less<_R2, _R1>::value> {
451451 static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
452452 static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
453453};
454454
455455template <class _R1, class _R2>
456struct _LIBCPP_TEMPLATE_VIS ratio_greater : _BoolConstant<ratio_less<_R2, _R1>::value> {
456struct ratio_greater : _BoolConstant<ratio_less<_R2, _R1>::value> {
457457 static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
458458 static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
459459};
460460
461461template <class _R1, class _R2>
462struct _LIBCPP_TEMPLATE_VIS ratio_greater_equal : _BoolConstant<!ratio_less<_R1, _R2>::value> {
462struct ratio_greater_equal : _BoolConstant<!ratio_less<_R1, _R2>::value> {
463463 static_assert(__is_ratio_v<_R1>, "[ratio.general]/2 requires R1 to be a specialisation of the ratio template");
464464 static_assert(__is_ratio_v<_R2>, "[ratio.general]/2 requires R2 to be a specialisation of the ratio template");
465465};
lib/libcxx/include/regex+248-241
......@@ -792,26 +792,7 @@ typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
792792#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
793793# include <__cxx03/regex>
794794#else
795# include <__algorithm/find.h>
796# include <__algorithm/search.h>
797# include <__assert>
798795# 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>
815796
816797// standard-mandated includes
817798
......@@ -826,14 +807,37 @@ typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
826807# include <compare>
827808# include <initializer_list>
828809
829# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
830# pragma GCC system_header
831# endif
810# if _LIBCPP_HAS_LOCALIZATION
811
812# include <__algorithm/find.h>
813# include <__algorithm/search.h>
814# include <__assert>
815# include <__iterator/back_insert_iterator.h>
816# include <__iterator/default_sentinel.h>
817# include <__iterator/wrap_iter.h>
818# include <__locale>
819# include <__memory/addressof.h>
820# include <__memory/shared_ptr.h>
821# include <__memory_resource/polymorphic_allocator.h>
822# include <__type_traits/is_swappable.h>
823# include <__utility/move.h>
824# include <__utility/pair.h>
825# include <__utility/swap.h>
826# include <__verbose_abort>
827# include <deque>
828# include <stdexcept>
829# include <string>
830# include <vector>
831# include <version>
832
833# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
834# pragma GCC system_header
835# endif
832836
833837_LIBCPP_PUSH_MACROS
834# include <__undef_macros>
838# include <__undef_macros>
835839
836# define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096
840# define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096
837841
838842_LIBCPP_BEGIN_NAMESPACE_STD
839843
......@@ -846,11 +850,11 @@ enum syntax_option_type {
846850 nosubs = 1 << 1,
847851 optimize = 1 << 2,
848852 collate = 1 << 3,
849# ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
853# ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
850854 ECMAScript = 1 << 9,
851# else
855# else
852856 ECMAScript = 0,
853# endif
857# endif
854858 basic = 1 << 4,
855859 extended = 1 << 5,
856860 awk = 1 << 6,
......@@ -861,11 +865,11 @@ enum syntax_option_type {
861865};
862866
863867_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR syntax_option_type __get_grammar(syntax_option_type __g) {
864# ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
868# ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
865869 return static_cast<syntax_option_type>(__g & 0x3F0);
866# else
870# else
867871 return static_cast<syntax_option_type>(__g & 0x1F0);
868# endif
872# endif
869873}
870874
871875inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR syntax_option_type operator~(syntax_option_type __x) {
......@@ -987,20 +991,20 @@ public:
987991
988992template <regex_constants::error_type _Ev>
989993[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_regex_error() {
990# if _LIBCPP_HAS_EXCEPTIONS
994# if _LIBCPP_HAS_EXCEPTIONS
991995 throw regex_error(_Ev);
992# else
996# else
993997 _LIBCPP_VERBOSE_ABORT("regex_error was thrown in -fno-exceptions mode");
994# endif
998# endif
995999}
9961000
9971001template <class _CharT>
998struct _LIBCPP_TEMPLATE_VIS regex_traits {
1002struct regex_traits {
9991003public:
10001004 typedef _CharT char_type;
10011005 typedef basic_string<char_type> string_type;
10021006 typedef locale locale_type;
1003# if defined(__BIONIC__) || defined(_NEWLIB_VERSION)
1007# if defined(__BIONIC__) || defined(_NEWLIB_VERSION)
10041008 // Originally bionic's ctype_base used its own ctype masks because the
10051009 // builtin ctype implementation wasn't in libc++ yet. Bionic's ctype mask
10061010 // was only 8 bits wide and already saturated, so it used a wider type here
......@@ -1015,9 +1019,9 @@ public:
10151019 // often used for space constrained environments, so it makes sense not to
10161020 // duplicate the ctype table.
10171021 typedef uint16_t char_class_type;
1018# else
1022# else
10191023 typedef ctype_base::mask char_class_type;
1020# endif
1024# endif
10211025
10221026 static const char_class_type __regex_word = ctype_base::__regex_word;
10231027
......@@ -1057,30 +1061,30 @@ private:
10571061
10581062 template <class _ForwardIterator>
10591063 string_type __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
1060# if _LIBCPP_HAS_WIDE_CHARACTERS
1064# if _LIBCPP_HAS_WIDE_CHARACTERS
10611065 template <class _ForwardIterator>
10621066 string_type __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1063# endif
1067# endif
10641068 template <class _ForwardIterator>
10651069 string_type __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
1066# if _LIBCPP_HAS_WIDE_CHARACTERS
1070# if _LIBCPP_HAS_WIDE_CHARACTERS
10671071 template <class _ForwardIterator>
10681072 string_type __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1069# endif
1073# endif
10701074 template <class _ForwardIterator>
10711075 char_class_type __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, char) const;
1072# if _LIBCPP_HAS_WIDE_CHARACTERS
1076# if _LIBCPP_HAS_WIDE_CHARACTERS
10731077 template <class _ForwardIterator>
10741078 char_class_type __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, wchar_t) const;
1075# endif
1079# endif
10761080
10771081 static int __regex_traits_value(unsigned char __ch, int __radix);
10781082 _LIBCPP_HIDE_FROM_ABI int __regex_traits_value(char __ch, int __radix) const {
10791083 return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);
10801084 }
1081# if _LIBCPP_HAS_WIDE_CHARACTERS
1085# if _LIBCPP_HAS_WIDE_CHARACTERS
10821086 _LIBCPP_HIDE_FROM_ABI int __regex_traits_value(wchar_t __ch, int __radix) const;
1083# endif
1087# endif
10841088};
10851089
10861090template <class _CharT>
......@@ -1106,8 +1110,8 @@ regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) cons
11061110
11071111template <class _CharT>
11081112void regex_traits<_CharT>::__init() {
1109 __ct_ = &std::use_facet<ctype<char_type> >(__loc_);
1110 __col_ = &std::use_facet<collate<char_type> >(__loc_);
1113 __ct_ = std::addressof(std::use_facet<ctype<char_type> >(__loc_));
1114 __col_ = std::addressof(std::use_facet<collate<char_type> >(__loc_));
11111115}
11121116
11131117template <class _CharT>
......@@ -1139,7 +1143,7 @@ regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, _ForwardIterator
11391143 return __d;
11401144}
11411145
1142# if _LIBCPP_HAS_WIDE_CHARACTERS
1146# if _LIBCPP_HAS_WIDE_CHARACTERS
11431147template <class _CharT>
11441148template <class _ForwardIterator>
11451149typename regex_traits<_CharT>::string_type
......@@ -1158,7 +1162,7 @@ regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, _ForwardIterator
11581162 }
11591163 return __d;
11601164}
1161# endif
1165# endif
11621166
11631167// lookup_collatename is very FreeBSD-specific
11641168
......@@ -1183,7 +1187,7 @@ regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, _ForwardIterato
11831187 return __r;
11841188}
11851189
1186# if _LIBCPP_HAS_WIDE_CHARACTERS
1190# if _LIBCPP_HAS_WIDE_CHARACTERS
11871191template <class _CharT>
11881192template <class _ForwardIterator>
11891193typename regex_traits<_CharT>::string_type
......@@ -1211,7 +1215,7 @@ regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, _ForwardIterato
12111215 }
12121216 return __r;
12131217}
1214# endif // _LIBCPP_HAS_WIDE_CHARACTERS
1218# endif // _LIBCPP_HAS_WIDE_CHARACTERS
12151219
12161220// lookup_classname
12171221
......@@ -1222,17 +1226,17 @@ template <class _ForwardIterator>
12221226typename regex_traits<_CharT>::char_class_type
12231227regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, char) const {
12241228 string_type __s(__f, __l);
1225 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1229 __ct_->tolower(std::addressof(__s[0]), std::addressof(__s[0]) + __s.size());
12261230 return std::__get_classname(__s.c_str(), __icase);
12271231}
12281232
1229# if _LIBCPP_HAS_WIDE_CHARACTERS
1233# if _LIBCPP_HAS_WIDE_CHARACTERS
12301234template <class _CharT>
12311235template <class _ForwardIterator>
12321236typename regex_traits<_CharT>::char_class_type
12331237regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, wchar_t) const {
12341238 string_type __s(__f, __l);
1235 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1239 __ct_->tolower(std::addressof(__s[0]), std::addressof(__s[0]) + __s.size());
12361240 string __n;
12371241 __n.reserve(__s.size());
12381242 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); __i != __e; ++__i) {
......@@ -1242,7 +1246,7 @@ regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, _ForwardIterator
12421246 }
12431247 return __get_classname(__n.c_str(), __icase);
12441248}
1245# endif // _LIBCPP_HAS_WIDE_CHARACTERS
1249# endif // _LIBCPP_HAS_WIDE_CHARACTERS
12461250
12471251template <class _CharT>
12481252bool regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const {
......@@ -1253,28 +1257,28 @@ bool regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const {
12531257
12541258inline _LIBCPP_HIDE_FROM_ABI bool __is_07(unsigned char __c) {
12551259 return (__c & 0xF8u) ==
1256# if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
1260# if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
12571261 0xF0;
1258# else
1262# else
12591263 0x30;
1260# endif
1264# endif
12611265}
12621266
12631267inline _LIBCPP_HIDE_FROM_ABI bool __is_89(unsigned char __c) {
12641268 return (__c & 0xFEu) ==
1265# if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
1269# if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
12661270 0xF8;
1267# else
1271# else
12681272 0x38;
1269# endif
1273# endif
12701274}
12711275
12721276inline _LIBCPP_HIDE_FROM_ABI unsigned char __to_lower(unsigned char __c) {
1273# if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
1277# if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
12741278 return __c & 0xBF;
1275# else
1279# else
12761280 return __c | 0x20;
1277# endif
1281# endif
12781282}
12791283
12801284template <class _CharT>
......@@ -1293,21 +1297,21 @@ int regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix)
12931297 return -1;
12941298}
12951299
1296# if _LIBCPP_HAS_WIDE_CHARACTERS
1300# if _LIBCPP_HAS_WIDE_CHARACTERS
12971301template <class _CharT>
12981302inline int regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const {
12991303 return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
13001304}
1301# endif
1305# endif
13021306
13031307template <class _CharT>
13041308class __node;
13051309
13061310template <class _BidirectionalIterator>
1307class _LIBCPP_TEMPLATE_VIS sub_match;
1311class sub_match;
13081312
13091313template <class _BidirectionalIterator, class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
1310class _LIBCPP_TEMPLATE_VIS match_results;
1314class match_results;
13111315
13121316template <class _CharT>
13131317struct __state {
......@@ -1681,7 +1685,7 @@ public:
16811685template <class _CharT>
16821686void __back_ref<_CharT>::__exec(__state& __s) const {
16831687 if (__mexp_ > __s.__sub_matches_.size())
1684 __throw_regex_error<regex_constants::error_backref>();
1688 std::__throw_regex_error<regex_constants::error_backref>();
16851689 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_ - 1];
16861690 if (__sm.matched) {
16871691 ptrdiff_t __len = __sm.second - __sm.first;
......@@ -1941,10 +1945,10 @@ public:
19411945
19421946template <>
19431947_LIBCPP_EXPORTED_FROM_ABI void __match_any_but_newline<char>::__exec(__state&) const;
1944# if _LIBCPP_HAS_WIDE_CHARACTERS
1948# if _LIBCPP_HAS_WIDE_CHARACTERS
19451949template <>
19461950_LIBCPP_EXPORTED_FROM_ABI void __match_any_but_newline<wchar_t>::__exec(__state&) const;
1947# endif
1951# endif
19481952
19491953// __match_char
19501954
......@@ -2117,7 +2121,7 @@ public:
21172121 std::make_pair(__traits_.transform(__b.begin(), __b.end()), __traits_.transform(__e.begin(), __e.end())));
21182122 } else {
21192123 if (__b.size() != 1 || __e.size() != 1)
2120 __throw_regex_error<regex_constants::error_range>();
2124 std::__throw_regex_error<regex_constants::error_range>();
21212125 if (__icase_) {
21222126 __b[0] = __traits_.translate_nocase(__b[0]);
21232127 __e[0] = __traits_.translate_nocase(__e[0]);
......@@ -2157,7 +2161,7 @@ void __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const {
21572161 __ch2.first = __traits_.translate(__ch2.first);
21582162 __ch2.second = __traits_.translate(__ch2.second);
21592163 }
2160 if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first + 2).empty()) {
2164 if (!__traits_.lookup_collatename(std::addressof(__ch2.first), std::addressof(__ch2.first) + 2).empty()) {
21612165 // __ch2 is a digraph in this locale
21622166 ++__consumed;
21632167 for (size_t __i = 0; __i < __digraphs_.size(); ++__i) {
......@@ -2167,7 +2171,7 @@ void __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const {
21672171 }
21682172 }
21692173 if (__collate_ && !__ranges_.empty()) {
2170 string_type __s2 = __traits_.transform(&__ch2.first, &__ch2.first + 2);
2174 string_type __s2 = __traits_.transform(std::addressof(__ch2.first), std::addressof(__ch2.first) + 2);
21712175 for (size_t __i = 0; __i < __ranges_.size(); ++__i) {
21722176 if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) {
21732177 __found = true;
......@@ -2176,7 +2180,8 @@ void __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const {
21762180 }
21772181 }
21782182 if (!__equivalences_.empty()) {
2179 string_type __s2 = __traits_.transform_primary(&__ch2.first, &__ch2.first + 2);
2183 string_type __s2 =
2184 __traits_.transform_primary(std::addressof(__ch2.first), std::addressof(__ch2.first) + 2);
21802185 for (size_t __i = 0; __i < __equivalences_.size(); ++__i) {
21812186 if (__s2 == __equivalences_[__i]) {
21822187 __found = true;
......@@ -2224,7 +2229,8 @@ void __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const {
22242229 }
22252230 }
22262231 if (!__ranges_.empty()) {
2227 string_type __s2 = __collate_ ? __traits_.transform(&__ch, &__ch + 1) : string_type(1, __ch);
2232 string_type __s2 =
2233 __collate_ ? __traits_.transform(std::addressof(__ch), std::addressof(__ch) + 1) : string_type(1, __ch);
22282234 for (size_t __i = 0; __i < __ranges_.size(); ++__i) {
22292235 if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) {
22302236 __found = true;
......@@ -2233,7 +2239,7 @@ void __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const {
22332239 }
22342240 }
22352241 if (!__equivalences_.empty()) {
2236 string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
2242 string_type __s2 = __traits_.transform_primary(std::addressof(__ch), std::addressof(__ch) + 1);
22372243 for (size_t __i = 0; __i < __equivalences_.size(); ++__i) {
22382244 if (__s2 == __equivalences_[__i]) {
22392245 __found = true;
......@@ -2262,16 +2268,15 @@ template <class _CharT, class _Traits>
22622268class __lookahead;
22632269
22642270template <class _CharT, class _Traits = regex_traits<_CharT> >
2265class _LIBCPP_TEMPLATE_VIS basic_regex;
2271class basic_regex;
22662272
22672273typedef basic_regex<char> regex;
2268# if _LIBCPP_HAS_WIDE_CHARACTERS
2274# if _LIBCPP_HAS_WIDE_CHARACTERS
22692275typedef basic_regex<wchar_t> wregex;
2270# endif
2276# endif
22712277
22722278template <class _CharT, class _Traits>
2273class _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(regex)
2274 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wregex)) basic_regex {
2279class _LIBCPP_PREFERRED_NAME(regex) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wregex)) basic_regex {
22752280public:
22762281 // types:
22772282 typedef _CharT value_type;
......@@ -2338,21 +2343,21 @@ public:
23382343 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
23392344 __init(__first, __last);
23402345 }
2341# ifndef _LIBCPP_CXX03_LANG
2346# ifndef _LIBCPP_CXX03_LANG
23422347 _LIBCPP_HIDE_FROM_ABI basic_regex(initializer_list<value_type> __il, flag_type __f = regex_constants::ECMAScript)
23432348 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
23442349 __init(__il.begin(), __il.end());
23452350 }
2346# endif // _LIBCPP_CXX03_LANG
2351# endif // _LIBCPP_CXX03_LANG
23472352
23482353 // ~basic_regex() = default;
23492354
23502355 // basic_regex& operator=(const basic_regex&) = default;
23512356 // basic_regex& operator=(basic_regex&&) = default;
23522357 _LIBCPP_HIDE_FROM_ABI basic_regex& operator=(const value_type* __p) { return assign(__p); }
2353# ifndef _LIBCPP_CXX03_LANG
2358# ifndef _LIBCPP_CXX03_LANG
23542359 _LIBCPP_HIDE_FROM_ABI basic_regex& operator=(initializer_list<value_type> __il) { return assign(__il); }
2355# endif // _LIBCPP_CXX03_LANG
2360# endif // _LIBCPP_CXX03_LANG
23562361 template <class _ST, class _SA>
23572362 _LIBCPP_HIDE_FROM_ABI basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p) {
23582363 return assign(__p);
......@@ -2360,9 +2365,9 @@ public:
23602365
23612366 // assign:
23622367 _LIBCPP_HIDE_FROM_ABI basic_regex& assign(const basic_regex& __that) { return *this = __that; }
2363# ifndef _LIBCPP_CXX03_LANG
2368# ifndef _LIBCPP_CXX03_LANG
23642369 _LIBCPP_HIDE_FROM_ABI basic_regex& assign(basic_regex&& __that) _NOEXCEPT { return *this = std::move(__that); }
2365# endif
2370# endif
23662371 _LIBCPP_HIDE_FROM_ABI basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript) {
23672372 return assign(__p, __p + __traits_.length(__p), __f);
23682373 }
......@@ -2399,14 +2404,14 @@ public:
23992404 return assign(basic_regex(__first, __last, __f));
24002405 }
24012406
2402# ifndef _LIBCPP_CXX03_LANG
2407# ifndef _LIBCPP_CXX03_LANG
24032408
24042409 _LIBCPP_HIDE_FROM_ABI basic_regex&
24052410 assign(initializer_list<value_type> __il, flag_type __f = regex_constants::ECMAScript) {
24062411 return assign(__il.begin(), __il.end(), __f);
24072412 }
24082413
2409# endif // _LIBCPP_CXX03_LANG
2414# endif // _LIBCPP_CXX03_LANG
24102415
24112416 // const operations:
24122417 _LIBCPP_HIDE_FROM_ABI unsigned mark_count() const { return __marked_count_; }
......@@ -2647,11 +2652,11 @@ private:
26472652 friend class __lookahead;
26482653};
26492654
2650# if _LIBCPP_STD_VER >= 17
2655# if _LIBCPP_STD_VER >= 17
26512656template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
26522657basic_regex(_ForwardIterator, _ForwardIterator, regex_constants::syntax_option_type = regex_constants::ECMAScript)
26532658 -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>;
2654# endif
2659# endif
26552660
26562661template <class _CharT, class _Traits>
26572662const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase;
......@@ -2743,7 +2748,7 @@ void basic_regex<_CharT, _Traits>::__init(_ForwardIterator __first, _ForwardIter
27432748 __flags_ |= regex_constants::ECMAScript;
27442749 _ForwardIterator __temp = __parse(__first, __last);
27452750 if (__temp != __last)
2746 __throw_regex_error<regex_constants::__re_err_parse>();
2751 std::__throw_regex_error<regex_constants::__re_err_parse>();
27472752}
27482753
27492754template <class _CharT, class _Traits>
......@@ -2773,7 +2778,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
27732778 __first = __parse_egrep(__first, __last);
27742779 break;
27752780 default:
2776 __throw_regex_error<regex_constants::__re_err_grammar>();
2781 std::__throw_regex_error<regex_constants::__re_err_grammar>();
27772782 }
27782783 return __first;
27792784}
......@@ -2798,7 +2803,7 @@ basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, _F
27982803 }
27992804 }
28002805 if (__first != __last)
2801 __throw_regex_error<regex_constants::__re_err_empty>();
2806 std::__throw_regex_error<regex_constants::__re_err_empty>();
28022807 }
28032808 return __first;
28042809}
......@@ -2810,13 +2815,13 @@ basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
28102815 __owns_one_state<_CharT>* __sa = __end_;
28112816 _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
28122817 if (__temp == __first)
2813 __throw_regex_error<regex_constants::__re_err_empty>();
2818 std::__throw_regex_error<regex_constants::__re_err_empty>();
28142819 __first = __temp;
28152820 while (__first != __last && *__first == '|') {
28162821 __owns_one_state<_CharT>* __sb = __end_;
28172822 __temp = __parse_ERE_branch(++__first, __last);
28182823 if (__temp == __first)
2819 __throw_regex_error<regex_constants::__re_err_empty>();
2824 std::__throw_regex_error<regex_constants::__re_err_empty>();
28202825 __push_alternation(__sa, __sb);
28212826 __first = __temp;
28222827 }
......@@ -2828,7 +2833,7 @@ template <class _ForwardIterator>
28282833_ForwardIterator basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last) {
28292834 _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
28302835 if (__temp == __first)
2831 __throw_regex_error<regex_constants::__re_err_empty>();
2836 std::__throw_regex_error<regex_constants::__re_err_empty>();
28322837 do {
28332838 __first = __temp;
28342839 __temp = __parse_ERE_expression(__first, __last);
......@@ -2859,7 +2864,7 @@ basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, _
28592864 ++__open_count_;
28602865 __temp = __parse_extended_reg_exp(++__temp, __last);
28612866 if (__temp == __last || *__temp != ')')
2862 __throw_regex_error<regex_constants::error_paren>();
2867 std::__throw_regex_error<regex_constants::error_paren>();
28632868 __push_end_marked_subexpression(__temp_count);
28642869 --__open_count_;
28652870 ++__temp;
......@@ -2911,7 +2916,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterat
29112916 __first = __parse_RE_expression(__temp, __last);
29122917 __temp = __parse_Back_close_paren(__first, __last);
29132918 if (__temp == __first)
2914 __throw_regex_error<regex_constants::error_paren>();
2919 std::__throw_regex_error<regex_constants::error_paren>();
29152920 __push_end_marked_subexpression(__temp_count);
29162921 __first = __temp;
29172922 } else
......@@ -3154,14 +3159,14 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(
31543159 __first = __temp;
31553160 __temp = __parse_DUP_COUNT(__first, __last, __min);
31563161 if (__temp == __first)
3157 __throw_regex_error<regex_constants::error_badbrace>();
3162 std::__throw_regex_error<regex_constants::error_badbrace>();
31583163 __first = __temp;
31593164 if (__first == __last)
3160 __throw_regex_error<regex_constants::error_brace>();
3165 std::__throw_regex_error<regex_constants::error_brace>();
31613166 if (*__first != ',') {
31623167 __temp = __parse_Back_close_brace(__first, __last);
31633168 if (__temp == __first)
3164 __throw_regex_error<regex_constants::error_brace>();
3169 std::__throw_regex_error<regex_constants::error_brace>();
31653170 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, true);
31663171 __first = __temp;
31673172 } else {
......@@ -3170,12 +3175,12 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(
31703175 __first = __parse_DUP_COUNT(__first, __last, __max);
31713176 __temp = __parse_Back_close_brace(__first, __last);
31723177 if (__temp == __first)
3173 __throw_regex_error<regex_constants::error_brace>();
3178 std::__throw_regex_error<regex_constants::error_brace>();
31743179 if (__max == -1)
31753180 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
31763181 else {
31773182 if (__max < __min)
3178 __throw_regex_error<regex_constants::error_badbrace>();
3183 std::__throw_regex_error<regex_constants::error_badbrace>();
31793184 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, true);
31803185 }
31813186 __first = __temp;
......@@ -3225,10 +3230,10 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(
32253230 int __min;
32263231 _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
32273232 if (__temp == __first)
3228 __throw_regex_error<regex_constants::error_badbrace>();
3233 std::__throw_regex_error<regex_constants::error_badbrace>();
32293234 __first = __temp;
32303235 if (__first == __last)
3231 __throw_regex_error<regex_constants::error_brace>();
3236 std::__throw_regex_error<regex_constants::error_brace>();
32323237 switch (*__first) {
32333238 case '}':
32343239 ++__first;
......@@ -3241,7 +3246,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(
32413246 case ',':
32423247 ++__first;
32433248 if (__first == __last)
3244 __throw_regex_error<regex_constants::error_badbrace>();
3249 std::__throw_regex_error<regex_constants::error_badbrace>();
32453250 if (*__first == '}') {
32463251 ++__first;
32473252 if (__grammar == ECMAScript && __first != __last && *__first == '?') {
......@@ -3253,13 +3258,13 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(
32533258 int __max = -1;
32543259 __temp = __parse_DUP_COUNT(__first, __last, __max);
32553260 if (__temp == __first)
3256 __throw_regex_error<regex_constants::error_brace>();
3261 std::__throw_regex_error<regex_constants::error_brace>();
32573262 __first = __temp;
32583263 if (__first == __last || *__first != '}')
3259 __throw_regex_error<regex_constants::error_brace>();
3264 std::__throw_regex_error<regex_constants::error_brace>();
32603265 ++__first;
32613266 if (__max < __min)
3262 __throw_regex_error<regex_constants::error_badbrace>();
3267 std::__throw_regex_error<regex_constants::error_badbrace>();
32633268 if (__grammar == ECMAScript && __first != __last && *__first == '?') {
32643269 ++__first;
32653270 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
......@@ -3268,7 +3273,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(
32683273 }
32693274 break;
32703275 default:
3271 __throw_regex_error<regex_constants::error_badbrace>();
3276 std::__throw_regex_error<regex_constants::error_badbrace>();
32723277 }
32733278 } break;
32743279 }
......@@ -3283,7 +3288,7 @@ basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __firs
32833288 if (__first != __last && *__first == '[') {
32843289 ++__first;
32853290 if (__first == __last)
3286 __throw_regex_error<regex_constants::error_brack>();
3291 std::__throw_regex_error<regex_constants::error_brack>();
32873292 bool __negate = false;
32883293 if (*__first == '^') {
32893294 ++__first;
......@@ -3292,20 +3297,20 @@ basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __firs
32923297 __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
32933298 // __ml owned by *this
32943299 if (__first == __last)
3295 __throw_regex_error<regex_constants::error_brack>();
3300 std::__throw_regex_error<regex_constants::error_brack>();
32963301 if (__get_grammar(__flags_) != ECMAScript && *__first == ']') {
32973302 __ml->__add_char(']');
32983303 ++__first;
32993304 }
33003305 __first = __parse_follow_list(__first, __last, __ml);
33013306 if (__first == __last)
3302 __throw_regex_error<regex_constants::error_brack>();
3307 std::__throw_regex_error<regex_constants::error_brack>();
33033308 if (*__first == '-') {
33043309 __ml->__add_char('-');
33053310 ++__first;
33063311 }
33073312 if (__first == __last || *__first != ']')
3308 __throw_regex_error<regex_constants::error_brack>();
3313 std::__throw_regex_error<regex_constants::error_brack>();
33093314 ++__first;
33103315 }
33113316 return __first;
......@@ -3347,7 +3352,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_expression_term(
33473352 if (__grammar == ECMAScript)
33483353 __first = __parse_class_escape(++__first, __last, __start_range, __ml);
33493354 else
3350 __first = __parse_awk_escape(++__first, __last, &__start_range);
3355 __first = __parse_awk_escape(++__first, __last, std::addressof(__start_range));
33513356 } else {
33523357 __start_range = *__first;
33533358 ++__first;
......@@ -3367,7 +3372,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_expression_term(
33673372 if (__grammar == ECMAScript)
33683373 __first = __parse_class_escape(++__first, __last, __end_range, __ml);
33693374 else
3370 __first = __parse_awk_escape(++__first, __last, &__end_range);
3375 __first = __parse_awk_escape(++__first, __last, std::addressof(__end_range));
33713376 } else {
33723377 __end_range = *__first;
33733378 ++__first;
......@@ -3398,7 +3403,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_class_escape(
33983403 basic_string<_CharT>& __str,
33993404 __bracket_expression<_CharT, _Traits>* __ml) {
34003405 if (__first == __last)
3401 __throw_regex_error<regex_constants::error_escape>();
3406 std::__throw_regex_error<regex_constants::error_escape>();
34023407 switch (*__first) {
34033408 case 0:
34043409 __str = *__first;
......@@ -3427,7 +3432,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_class_escape(
34273432 __ml->__add_neg_char('_');
34283433 return ++__first;
34293434 }
3430 __first = __parse_character_escape(__first, __last, &__str);
3435 __first = __parse_character_escape(__first, __last, std::addressof(__str));
34313436 return __first;
34323437}
34333438
......@@ -3436,7 +3441,7 @@ template <class _ForwardIterator>
34363441_ForwardIterator basic_regex<_CharT, _Traits>::__parse_awk_escape(
34373442 _ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>* __str) {
34383443 if (__first == __last)
3439 __throw_regex_error<regex_constants::error_escape>();
3444 std::__throw_regex_error<regex_constants::error_escape>();
34403445 switch (*__first) {
34413446 case '\\':
34423447 case '"':
......@@ -3501,7 +3506,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_awk_escape(
35013506 else
35023507 __push_char(_CharT(__val));
35033508 } else
3504 __throw_regex_error<regex_constants::error_escape>();
3509 std::__throw_regex_error<regex_constants::error_escape>();
35053510 return __first;
35063511}
35073512
......@@ -3514,11 +3519,11 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_equivalence_class(
35143519 value_type __equal_close[2] = {'=', ']'};
35153520 _ForwardIterator __temp = std::search(__first, __last, __equal_close, __equal_close + 2);
35163521 if (__temp == __last)
3517 __throw_regex_error<regex_constants::error_brack>();
3522 std::__throw_regex_error<regex_constants::error_brack>();
35183523 // [__first, __temp) contains all text in [= ... =]
35193524 string_type __collate_name = __traits_.lookup_collatename(__first, __temp);
35203525 if (__collate_name.empty())
3521 __throw_regex_error<regex_constants::error_collate>();
3526 std::__throw_regex_error<regex_constants::error_collate>();
35223527 string_type __equiv_name = __traits_.transform_primary(__collate_name.begin(), __collate_name.end());
35233528 if (!__equiv_name.empty())
35243529 __ml->__add_equivalence(__equiv_name);
......@@ -3531,7 +3536,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_equivalence_class(
35313536 __ml->__add_digraph(__collate_name[0], __collate_name[1]);
35323537 break;
35333538 default:
3534 __throw_regex_error<regex_constants::error_collate>();
3539 std::__throw_regex_error<regex_constants::error_collate>();
35353540 }
35363541 }
35373542 __first = std::next(__temp, 2);
......@@ -3547,12 +3552,12 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_character_class(
35473552 value_type __colon_close[2] = {':', ']'};
35483553 _ForwardIterator __temp = std::search(__first, __last, __colon_close, __colon_close + 2);
35493554 if (__temp == __last)
3550 __throw_regex_error<regex_constants::error_brack>();
3555 std::__throw_regex_error<regex_constants::error_brack>();
35513556 // [__first, __temp) contains all text in [: ... :]
35523557 typedef typename _Traits::char_class_type char_class_type;
35533558 char_class_type __class_type = __traits_.lookup_classname(__first, __temp, __flags_ & icase);
35543559 if (__class_type == 0)
3555 __throw_regex_error<regex_constants::error_ctype>();
3560 std::__throw_regex_error<regex_constants::error_ctype>();
35563561 __ml->__add_class(__class_type);
35573562 __first = std::next(__temp, 2);
35583563 return __first;
......@@ -3567,7 +3572,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_collating_symbol(
35673572 value_type __dot_close[2] = {'.', ']'};
35683573 _ForwardIterator __temp = std::search(__first, __last, __dot_close, __dot_close + 2);
35693574 if (__temp == __last)
3570 __throw_regex_error<regex_constants::error_brack>();
3575 std::__throw_regex_error<regex_constants::error_brack>();
35713576 // [__first, __temp) contains all text in [. ... .]
35723577 __col_sym = __traits_.lookup_collatename(__first, __temp);
35733578 switch (__col_sym.size()) {
......@@ -3575,7 +3580,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_collating_symbol(
35753580 case 2:
35763581 break;
35773582 default:
3578 __throw_regex_error<regex_constants::error_collate>();
3583 std::__throw_regex_error<regex_constants::error_collate>();
35793584 }
35803585 __first = std::next(__temp, 2);
35813586 return __first;
......@@ -3591,7 +3596,7 @@ basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, _Forwa
35913596 __c = __val;
35923597 for (++__first; __first != __last && (__val = __traits_.value(*__first, 10)) != -1; ++__first) {
35933598 if (__c >= numeric_limits<int>::max() / 10)
3594 __throw_regex_error<regex_constants::error_badbrace>();
3599 std::__throw_regex_error<regex_constants::error_badbrace>();
35953600 __c *= 10;
35963601 __c += __val;
35973602 }
......@@ -3684,7 +3689,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterato
36843689 __push_lookahead(std::move(__exp), false, __marked_count_);
36853690 __marked_count_ += __mexp;
36863691 if (__temp == __last || *__temp != ')')
3687 __throw_regex_error<regex_constants::error_paren>();
3692 std::__throw_regex_error<regex_constants::error_paren>();
36883693 __first = ++__temp;
36893694 } break;
36903695 case '!': {
......@@ -3695,7 +3700,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterato
36953700 __push_lookahead(std::move(__exp), true, __marked_count_);
36963701 __marked_count_ += __mexp;
36973702 if (__temp == __last || *__temp != ')')
3698 __throw_regex_error<regex_constants::error_paren>();
3703 std::__throw_regex_error<regex_constants::error_paren>();
36993704 __first = ++__temp;
37003705 } break;
37013706 }
......@@ -3725,13 +3730,13 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __f
37253730 case '(': {
37263731 ++__first;
37273732 if (__first == __last)
3728 __throw_regex_error<regex_constants::error_paren>();
3733 std::__throw_regex_error<regex_constants::error_paren>();
37293734 _ForwardIterator __temp = std::next(__first);
37303735 if (__temp != __last && *__first == '?' && *__temp == ':') {
37313736 ++__open_count_;
37323737 __first = __parse_ecma_exp(++__temp, __last);
37333738 if (__first == __last || *__first != ')')
3734 __throw_regex_error<regex_constants::error_paren>();
3739 std::__throw_regex_error<regex_constants::error_paren>();
37353740 --__open_count_;
37363741 ++__first;
37373742 } else {
......@@ -3740,7 +3745,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __f
37403745 ++__open_count_;
37413746 __first = __parse_ecma_exp(__first, __last);
37423747 if (__first == __last || *__first != ')')
3743 __throw_regex_error<regex_constants::error_paren>();
3748 std::__throw_regex_error<regex_constants::error_paren>();
37443749 __push_end_marked_subexpression(__temp_count);
37453750 --__open_count_;
37463751 ++__first;
......@@ -3750,7 +3755,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __f
37503755 case '+':
37513756 case '?':
37523757 case '{':
3753 __throw_regex_error<regex_constants::error_badrepeat>();
3758 std::__throw_regex_error<regex_constants::error_badrepeat>();
37543759 break;
37553760 default:
37563761 __first = __parse_pattern_character(__first, __last);
......@@ -3766,7 +3771,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardItera
37663771 if (__first != __last && *__first == '\\') {
37673772 _ForwardIterator __t1 = std::next(__first);
37683773 if (__t1 == __last)
3769 __throw_regex_error<regex_constants::error_escape>();
3774 std::__throw_regex_error<regex_constants::error_escape>();
37703775
37713776 _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
37723777 if (__t2 != __t1)
......@@ -3797,11 +3802,11 @@ basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, _
37973802 unsigned __v = *__first - '0';
37983803 for (++__first; __first != __last && '0' <= *__first && *__first <= '9'; ++__first) {
37993804 if (__v >= numeric_limits<unsigned>::max() / 10)
3800 __throw_regex_error<regex_constants::error_backref>();
3805 std::__throw_regex_error<regex_constants::error_backref>();
38013806 __v = 10 * __v + *__first - '0';
38023807 }
38033808 if (__v == 0 || __v > mark_count())
3804 __throw_regex_error<regex_constants::error_backref>();
3809 std::__throw_regex_error<regex_constants::error_backref>();
38053810 __push_back_ref(__v);
38063811 }
38073812 }
......@@ -3905,40 +3910,40 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_character_escape(
39053910 __push_char(_CharT(*__t % 32));
39063911 __first = ++__t;
39073912 } else
3908 __throw_regex_error<regex_constants::error_escape>();
3913 std::__throw_regex_error<regex_constants::error_escape>();
39093914 } else
3910 __throw_regex_error<regex_constants::error_escape>();
3915 std::__throw_regex_error<regex_constants::error_escape>();
39113916 break;
39123917 case 'u':
39133918 ++__first;
39143919 if (__first == __last)
3915 __throw_regex_error<regex_constants::error_escape>();
3920 std::__throw_regex_error<regex_constants::error_escape>();
39163921 __hd = __traits_.value(*__first, 16);
39173922 if (__hd == -1)
3918 __throw_regex_error<regex_constants::error_escape>();
3923 std::__throw_regex_error<regex_constants::error_escape>();
39193924 __sum = 16 * __sum + static_cast<unsigned>(__hd);
39203925 ++__first;
39213926 if (__first == __last)
3922 __throw_regex_error<regex_constants::error_escape>();
3927 std::__throw_regex_error<regex_constants::error_escape>();
39233928 __hd = __traits_.value(*__first, 16);
39243929 if (__hd == -1)
3925 __throw_regex_error<regex_constants::error_escape>();
3930 std::__throw_regex_error<regex_constants::error_escape>();
39263931 __sum = 16 * __sum + static_cast<unsigned>(__hd);
3927 _LIBCPP_FALLTHROUGH();
3932 [[__fallthrough__]];
39283933 case 'x':
39293934 ++__first;
39303935 if (__first == __last)
3931 __throw_regex_error<regex_constants::error_escape>();
3936 std::__throw_regex_error<regex_constants::error_escape>();
39323937 __hd = __traits_.value(*__first, 16);
39333938 if (__hd == -1)
3934 __throw_regex_error<regex_constants::error_escape>();
3939 std::__throw_regex_error<regex_constants::error_escape>();
39353940 __sum = 16 * __sum + static_cast<unsigned>(__hd);
39363941 ++__first;
39373942 if (__first == __last)
3938 __throw_regex_error<regex_constants::error_escape>();
3943 std::__throw_regex_error<regex_constants::error_escape>();
39393944 __hd = __traits_.value(*__first, 16);
39403945 if (__hd == -1)
3941 __throw_regex_error<regex_constants::error_escape>();
3946 std::__throw_regex_error<regex_constants::error_escape>();
39423947 __sum = 16 * __sum + static_cast<unsigned>(__hd);
39433948 if (__str)
39443949 *__str = _CharT(__sum);
......@@ -3954,14 +3959,14 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_character_escape(
39543959 ++__first;
39553960 break;
39563961 default:
3957 if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) {
3962 if (!__traits_.isctype(*__first, ctype_base::alnum)) {
39583963 if (__str)
39593964 *__str = *__first;
39603965 else
39613966 __push_char(*__first);
39623967 ++__first;
39633968 } else
3964 __throw_regex_error<regex_constants::error_escape>();
3969 std::__throw_regex_error<regex_constants::error_escape>();
39653970 break;
39663971 }
39673972 }
......@@ -4057,7 +4062,7 @@ bool basic_regex<_CharT, _Traits>::__test_back_ref(_CharT __c) {
40574062 unsigned __val = __traits_.value(__c, 10);
40584063 if (__val >= 1 && __val <= 9) {
40594064 if (__val > mark_count())
4060 __throw_regex_error<regex_constants::error_backref>();
4065 std::__throw_regex_error<regex_constants::error_backref>();
40614066 __push_back_ref(__val);
40624067 return true;
40634068 }
......@@ -4184,15 +4189,14 @@ void basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, bo
41844189
41854190typedef sub_match<const char*> csub_match;
41864191typedef sub_match<string::const_iterator> ssub_match;
4187# if _LIBCPP_HAS_WIDE_CHARACTERS
4192# if _LIBCPP_HAS_WIDE_CHARACTERS
41884193typedef sub_match<const wchar_t*> wcsub_match;
41894194typedef sub_match<wstring::const_iterator> wssub_match;
4190# endif
4195# endif
41914196
41924197template <class _BidirectionalIterator>
4193class _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(csub_match)
4194 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcsub_match)) _LIBCPP_PREFERRED_NAME(ssub_match)
4195 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wssub_match)) sub_match
4198class _LIBCPP_PREFERRED_NAME(csub_match) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcsub_match))
4199 _LIBCPP_PREFERRED_NAME(ssub_match) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wssub_match)) sub_match
41964200 : public pair<_BidirectionalIterator, _BidirectionalIterator> {
41974201public:
41984202 typedef _BidirectionalIterator iterator;
......@@ -4227,7 +4231,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator==(const sub_match<_BiIter>& __x, cons
42274231 return __x.compare(__y) == 0;
42284232}
42294233
4230# if _LIBCPP_STD_VER >= 20
4234# if _LIBCPP_STD_VER >= 20
42314235template <class _BiIter>
42324236using __sub_match_cat _LIBCPP_NODEBUG =
42334237 compare_three_way_result_t<basic_string<typename iterator_traits<_BiIter>::value_type>>;
......@@ -4236,7 +4240,7 @@ template <class _BiIter>
42364240_LIBCPP_HIDE_FROM_ABI auto operator<=>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
42374241 return static_cast<__sub_match_cat<_BiIter>>(__x.compare(__y) <=> 0);
42384242}
4239# else // _LIBCPP_STD_VER >= 20
4243# else // _LIBCPP_STD_VER >= 20
42404244template <class _BiIter>
42414245inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
42424246 return !(__x == __y);
......@@ -4303,7 +4307,7 @@ operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST
43034307 const sub_match<_BiIter>& __y) {
43044308 return !(__y < __x);
43054309}
4306# endif // _LIBCPP_STD_VER >= 20
4310# endif // _LIBCPP_STD_VER >= 20
43074311
43084312template <class _BiIter, class _ST, class _SA>
43094313inline _LIBCPP_HIDE_FROM_ABI bool
......@@ -4312,7 +4316,7 @@ operator==(const sub_match<_BiIter>& __x,
43124316 return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0;
43134317}
43144318
4315# if _LIBCPP_STD_VER >= 20
4319# if _LIBCPP_STD_VER >= 20
43164320template <class _BiIter, class _ST, class _SA>
43174321_LIBCPP_HIDE_FROM_ABI auto
43184322operator<=>(const sub_match<_BiIter>& __x,
......@@ -4320,7 +4324,7 @@ operator<=>(const sub_match<_BiIter>& __x,
43204324 return static_cast<__sub_match_cat<_BiIter>>(
43214325 __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) <=> 0);
43224326}
4323# else // _LIBCPP_STD_VER >= 20
4327# else // _LIBCPP_STD_VER >= 20
43244328template <class _BiIter, class _ST, class _SA>
43254329inline _LIBCPP_HIDE_FROM_ABI bool
43264330operator!=(const sub_match<_BiIter>& __x,
......@@ -4391,7 +4395,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool
43914395operator<=(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
43924396 return !(__y < __x);
43934397}
4394# endif // _LIBCPP_STD_VER >= 20
4398# endif // _LIBCPP_STD_VER >= 20
43954399
43964400template <class _BiIter>
43974401inline _LIBCPP_HIDE_FROM_ABI bool
......@@ -4399,13 +4403,13 @@ operator==(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::val
43994403 return __x.compare(__y) == 0;
44004404}
44014405
4402# if _LIBCPP_STD_VER >= 20
4406# if _LIBCPP_STD_VER >= 20
44034407template <class _BiIter>
44044408_LIBCPP_HIDE_FROM_ABI auto
44054409operator<=>(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
44064410 return static_cast<__sub_match_cat<_BiIter>>(__x.compare(__y) <=> 0);
44074411}
4408# else // _LIBCPP_STD_VER >= 20
4412# else // _LIBCPP_STD_VER >= 20
44094413template <class _BiIter>
44104414inline _LIBCPP_HIDE_FROM_ABI bool
44114415operator!=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
......@@ -4473,7 +4477,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool
44734477operator<=(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
44744478 return !(__y < __x);
44754479}
4476# endif // _LIBCPP_STD_VER >= 20
4480# endif // _LIBCPP_STD_VER >= 20
44774481
44784482template <class _BiIter>
44794483inline _LIBCPP_HIDE_FROM_ABI bool
......@@ -4482,14 +4486,14 @@ operator==(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::val
44824486 return __x.compare(string_type(1, __y)) == 0;
44834487}
44844488
4485# if _LIBCPP_STD_VER >= 20
4489# if _LIBCPP_STD_VER >= 20
44864490template <class _BiIter>
44874491_LIBCPP_HIDE_FROM_ABI auto
44884492operator<=>(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
44894493 using string_type = basic_string<typename iterator_traits<_BiIter>::value_type>;
44904494 return static_cast<__sub_match_cat<_BiIter>>(__x.compare(string_type(1, __y)) <=> 0);
44914495}
4492# else // _LIBCPP_STD_VER >= 20
4496# else // _LIBCPP_STD_VER >= 20
44934497template <class _BiIter>
44944498inline _LIBCPP_HIDE_FROM_ABI bool
44954499operator!=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
......@@ -4520,7 +4524,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool
45204524operator<=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
45214525 return !(__y < __x);
45224526}
4523# endif // _LIBCPP_STD_VER >= 20
4527# endif // _LIBCPP_STD_VER >= 20
45244528
45254529template <class _CharT, class _ST, class _BiIter>
45264530inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _ST>&
......@@ -4530,13 +4534,13 @@ operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) {
45304534
45314535typedef match_results<const char*> cmatch;
45324536typedef match_results<string::const_iterator> smatch;
4533# if _LIBCPP_HAS_WIDE_CHARACTERS
4537# if _LIBCPP_HAS_WIDE_CHARACTERS
45344538typedef match_results<const wchar_t*> wcmatch;
45354539typedef match_results<wstring::const_iterator> wsmatch;
4536# endif
4540# endif
45374541
45384542template <class _BidirectionalIterator, class _Allocator>
4539class _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(cmatch) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcmatch))
4543class _LIBCPP_PREFERRED_NAME(cmatch) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcmatch))
45404544 _LIBCPP_PREFERRED_NAME(smatch) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsmatch)) match_results {
45414545public:
45424546 typedef _Allocator allocator_type;
......@@ -4563,12 +4567,12 @@ public:
45634567 typedef basic_string<char_type> string_type;
45644568
45654569 // construct/copy/destroy:
4566# ifndef _LIBCPP_CXX03_LANG
4570# ifndef _LIBCPP_CXX03_LANG
45674571 match_results() : match_results(allocator_type()) {}
45684572 explicit match_results(const allocator_type& __a);
4569# else
4573# else
45704574 explicit match_results(const allocator_type& __a = allocator_type());
4571# endif
4575# endif
45724576
45734577 // match_results(const match_results&) = default;
45744578 // match_results& operator=(const match_results&) = default;
......@@ -4778,7 +4782,7 @@ _OutputIter match_results<_BidirectionalIterator, _Allocator>::format(
47784782 if (__fmt_first + 1 != __fmt_last && '0' <= __fmt_first[1] && __fmt_first[1] <= '9') {
47794783 ++__fmt_first;
47804784 if (__idx >= numeric_limits<size_t>::max() / 10)
4781 __throw_regex_error<regex_constants::error_escape>();
4785 std::__throw_regex_error<regex_constants::error_escape>();
47824786 __idx = 10 * __idx + *__fmt_first - '0';
47834787 }
47844788 __output_iter = std::copy((*this)[__idx].first, (*this)[__idx].second, __output_iter);
......@@ -4818,13 +4822,13 @@ _LIBCPP_HIDE_FROM_ABI bool operator==(const match_results<_BidirectionalIterator
48184822 return __x.__matches_ == __y.__matches_ && __x.__prefix_ == __y.__prefix_ && __x.__suffix_ == __y.__suffix_;
48194823}
48204824
4821# if _LIBCPP_STD_VER < 20
4825# if _LIBCPP_STD_VER < 20
48224826template <class _BidirectionalIterator, class _Allocator>
48234827inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
48244828 const match_results<_BidirectionalIterator, _Allocator>& __y) {
48254829 return !(__x == __y);
48264830}
4827# endif
4831# endif
48284832
48294833template <class _BidirectionalIterator, class _Allocator>
48304834inline _LIBCPP_HIDE_FROM_ABI void
......@@ -4865,7 +4869,7 @@ bool basic_regex<_CharT, _Traits>::__match_at_start_ecma(
48654869 do {
48664870 ++__counter;
48674871 if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
4868 __throw_regex_error<regex_constants::error_complexity>();
4872 std::__throw_regex_error<regex_constants::error_complexity>();
48694873 __state& __s = __states.back();
48704874 if (__s.__node_)
48714875 __s.__node_->__exec(__s);
......@@ -4899,7 +4903,7 @@ bool basic_regex<_CharT, _Traits>::__match_at_start_ecma(
48994903 __states.pop_back();
49004904 break;
49014905 default:
4902 __throw_regex_error<regex_constants::__re_err_unknown>();
4906 std::__throw_regex_error<regex_constants::__re_err_unknown>();
49034907 break;
49044908 }
49054909 } while (!__states.empty());
......@@ -4935,7 +4939,7 @@ bool basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
49354939 do {
49364940 ++__counter;
49374941 if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
4938 __throw_regex_error<regex_constants::error_complexity>();
4942 std::__throw_regex_error<regex_constants::error_complexity>();
49394943 __state& __s = __states.back();
49404944 if (__s.__node_)
49414945 __s.__node_->__exec(__s);
......@@ -4976,7 +4980,7 @@ bool basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
49764980 __states.pop_back();
49774981 break;
49784982 default:
4979 __throw_regex_error<regex_constants::__re_err_unknown>();
4983 std::__throw_regex_error<regex_constants::__re_err_unknown>();
49804984 break;
49814985 }
49824986 } while (!__states.empty());
......@@ -5025,7 +5029,7 @@ bool basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
50255029 do {
50265030 ++__counter;
50275031 if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
5028 __throw_regex_error<regex_constants::error_complexity>();
5032 std::__throw_regex_error<regex_constants::error_complexity>();
50295033 __state& __s = __states.back();
50305034 if (__s.__node_)
50315035 __s.__node_->__exec(__s);
......@@ -5063,7 +5067,7 @@ bool basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
50635067 __states.pop_back();
50645068 break;
50655069 default:
5066 __throw_regex_error<regex_constants::__re_err_unknown>();
5070 std::__throw_regex_error<regex_constants::__re_err_unknown>();
50675071 break;
50685072 }
50695073 } while (!__states.empty());
......@@ -5236,13 +5240,13 @@ regex_search(const basic_string<_CharT, _ST, _SA>& __s,
52365240 return __r;
52375241}
52385242
5239# if _LIBCPP_STD_VER >= 14
5243# if _LIBCPP_STD_VER >= 14
52405244template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
52415245bool regex_search(const basic_string<_Cp, _ST, _SA>&& __s,
52425246 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
52435247 const basic_regex<_Cp, _Tp>& __e,
52445248 regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
5245# endif
5249# endif
52465250
52475251// regex_match
52485252
......@@ -5291,14 +5295,14 @@ regex_match(const basic_string<_CharT, _ST, _SA>& __s,
52915295 return std::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
52925296}
52935297
5294# if _LIBCPP_STD_VER >= 14
5298# if _LIBCPP_STD_VER >= 14
52955299template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
52965300inline _LIBCPP_HIDE_FROM_ABI bool
52975301regex_match(const basic_string<_CharT, _ST, _SA>&& __s,
52985302 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
52995303 const basic_regex<_CharT, _Traits>& __e,
53005304 regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
5301# endif
5305# endif
53025306
53035307template <class _CharT, class _Traits>
53045308inline _LIBCPP_HIDE_FROM_ABI bool
......@@ -5321,18 +5325,18 @@ regex_match(const basic_string<_CharT, _ST, _SA>& __s,
53215325template <class _BidirectionalIterator,
53225326 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
53235327 class _Traits = regex_traits<_CharT> >
5324class _LIBCPP_TEMPLATE_VIS regex_iterator;
5328class regex_iterator;
53255329
53265330typedef regex_iterator<const char*> cregex_iterator;
53275331typedef regex_iterator<string::const_iterator> sregex_iterator;
5328# if _LIBCPP_HAS_WIDE_CHARACTERS
5332# if _LIBCPP_HAS_WIDE_CHARACTERS
53295333typedef regex_iterator<const wchar_t*> wcregex_iterator;
53305334typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
5331# endif
5335# endif
53325336
53335337template <class _BidirectionalIterator, class _CharT, class _Traits>
5334class _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(cregex_iterator)
5335 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_iterator)) _LIBCPP_PREFERRED_NAME(sregex_iterator)
5338class _LIBCPP_PREFERRED_NAME(cregex_iterator) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_iterator))
5339 _LIBCPP_PREFERRED_NAME(sregex_iterator)
53365340 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_iterator)) regex_iterator {
53375341public:
53385342 typedef basic_regex<_CharT, _Traits> regex_type;
......@@ -5341,9 +5345,9 @@ public:
53415345 typedef const value_type* pointer;
53425346 typedef const value_type& reference;
53435347 typedef forward_iterator_tag iterator_category;
5344# if _LIBCPP_STD_VER >= 20
5348# if _LIBCPP_STD_VER >= 20
53455349 typedef input_iterator_tag iterator_concept;
5346# endif
5350# endif
53475351
53485352private:
53495353 _BidirectionalIterator __begin_;
......@@ -5358,20 +5362,20 @@ public:
53585362 _BidirectionalIterator __b,
53595363 const regex_type& __re,
53605364 regex_constants::match_flag_type __m = regex_constants::match_default);
5361# if _LIBCPP_STD_VER >= 14
5365# if _LIBCPP_STD_VER >= 14
53625366 regex_iterator(_BidirectionalIterator __a,
53635367 _BidirectionalIterator __b,
53645368 const regex_type&& __re,
53655369 regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
5366# endif
5370# endif
53675371
53685372 _LIBCPP_HIDE_FROM_ABI bool operator==(const regex_iterator& __x) const;
5369# if _LIBCPP_STD_VER >= 20
5373# if _LIBCPP_STD_VER >= 20
53705374 _LIBCPP_HIDE_FROM_ABI bool operator==(default_sentinel_t) const { return *this == regex_iterator(); }
5371# endif
5372# if _LIBCPP_STD_VER < 20
5375# endif
5376# if _LIBCPP_STD_VER < 20
53735377 _LIBCPP_HIDE_FROM_ABI bool operator!=(const regex_iterator& __x) const { return !(*this == __x); }
5374# endif
5378# endif
53755379
53765380 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __match_; }
53775381 _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return std::addressof(__match_); }
......@@ -5451,17 +5455,17 @@ regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() {
54515455template <class _BidirectionalIterator,
54525456 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
54535457 class _Traits = regex_traits<_CharT> >
5454class _LIBCPP_TEMPLATE_VIS regex_token_iterator;
5458class regex_token_iterator;
54555459
54565460typedef regex_token_iterator<const char*> cregex_token_iterator;
54575461typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
5458# if _LIBCPP_HAS_WIDE_CHARACTERS
5462# if _LIBCPP_HAS_WIDE_CHARACTERS
54595463typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
54605464typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
5461# endif
5465# endif
54625466
54635467template <class _BidirectionalIterator, class _CharT, class _Traits>
5464class _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(cregex_token_iterator)
5468class _LIBCPP_PREFERRED_NAME(cregex_token_iterator)
54655469 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_token_iterator))
54665470 _LIBCPP_PREFERRED_NAME(sregex_token_iterator)
54675471 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_token_iterator)) regex_token_iterator {
......@@ -5472,9 +5476,9 @@ public:
54725476 typedef const value_type* pointer;
54735477 typedef const value_type& reference;
54745478 typedef forward_iterator_tag iterator_category;
5475# if _LIBCPP_STD_VER >= 20
5479# if _LIBCPP_STD_VER >= 20
54765480 typedef input_iterator_tag iterator_concept;
5477# endif
5481# endif
54785482
54795483private:
54805484 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
......@@ -5492,67 +5496,67 @@ public:
54925496 const regex_type& __re,
54935497 int __submatch = 0,
54945498 regex_constants::match_flag_type __m = regex_constants::match_default);
5495# if _LIBCPP_STD_VER >= 14
5499# if _LIBCPP_STD_VER >= 14
54965500 regex_token_iterator(_BidirectionalIterator __a,
54975501 _BidirectionalIterator __b,
54985502 const regex_type&& __re,
54995503 int __submatch = 0,
55005504 regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
5501# endif
5505# endif
55025506
55035507 regex_token_iterator(_BidirectionalIterator __a,
55045508 _BidirectionalIterator __b,
55055509 const regex_type& __re,
55065510 const vector<int>& __submatches,
55075511 regex_constants::match_flag_type __m = regex_constants::match_default);
5508# if _LIBCPP_STD_VER >= 14
5512# if _LIBCPP_STD_VER >= 14
55095513 regex_token_iterator(_BidirectionalIterator __a,
55105514 _BidirectionalIterator __b,
55115515 const regex_type&& __re,
55125516 const vector<int>& __submatches,
55135517 regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
5514# endif
5518# endif
55155519
5516# ifndef _LIBCPP_CXX03_LANG
5520# ifndef _LIBCPP_CXX03_LANG
55175521 regex_token_iterator(_BidirectionalIterator __a,
55185522 _BidirectionalIterator __b,
55195523 const regex_type& __re,
55205524 initializer_list<int> __submatches,
55215525 regex_constants::match_flag_type __m = regex_constants::match_default);
55225526
5523# if _LIBCPP_STD_VER >= 14
5527# if _LIBCPP_STD_VER >= 14
55245528 regex_token_iterator(_BidirectionalIterator __a,
55255529 _BidirectionalIterator __b,
55265530 const regex_type&& __re,
55275531 initializer_list<int> __submatches,
55285532 regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
5529# endif
5530# endif // _LIBCPP_CXX03_LANG
5533# endif
5534# endif // _LIBCPP_CXX03_LANG
55315535 template <size_t _Np>
55325536 regex_token_iterator(_BidirectionalIterator __a,
55335537 _BidirectionalIterator __b,
55345538 const regex_type& __re,
55355539 const int (&__submatches)[_Np],
55365540 regex_constants::match_flag_type __m = regex_constants::match_default);
5537# if _LIBCPP_STD_VER >= 14
5541# if _LIBCPP_STD_VER >= 14
55385542 template <size_t _Np>
55395543 regex_token_iterator(_BidirectionalIterator __a,
55405544 _BidirectionalIterator __b,
55415545 const regex_type&& __re,
55425546 const int (&__submatches)[_Np],
55435547 regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
5544# endif
5548# endif
55455549
55465550 regex_token_iterator(const regex_token_iterator&);
55475551 regex_token_iterator& operator=(const regex_token_iterator&);
55485552
55495553 _LIBCPP_HIDE_FROM_ABI bool operator==(const regex_token_iterator& __x) const;
5550# if _LIBCPP_STD_VER >= 20
5554# if _LIBCPP_STD_VER >= 20
55515555 _LIBCPP_HIDE_FROM_ABI bool operator==(default_sentinel_t) const { return *this == regex_token_iterator(); }
5552# endif
5553# if _LIBCPP_STD_VER < 20
5556# endif
5557# if _LIBCPP_STD_VER < 20
55545558 _LIBCPP_HIDE_FROM_ABI bool operator!=(const regex_token_iterator& __x) const { return !(*this == __x); }
5555# endif
5559# endif
55565560
55575561 _LIBCPP_HIDE_FROM_ABI const value_type& operator*() const { return *__result_; }
55585562 _LIBCPP_HIDE_FROM_ABI const value_type* operator->() const { return __result_; }
......@@ -5568,9 +5572,9 @@ private:
55685572 void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
55695573 void __establish_result() {
55705574 if (__subs_[__n_] == -1)
5571 __result_ = &__position_->prefix();
5575 __result_ = std::addressof(__position_->prefix());
55725576 else
5573 __result_ = &(*__position_)[__subs_[__n_]];
5577 __result_ = std::addressof((*__position_)[__subs_[__n_]]);
55745578 }
55755579};
55765580
......@@ -5587,7 +5591,7 @@ void regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::__init(
55875591 __suffix_.matched = true;
55885592 __suffix_.first = __a;
55895593 __suffix_.second = __b;
5590 __result_ = &__suffix_;
5594 __result_ = std::addressof(__suffix_);
55915595 } else
55925596 __result_ = nullptr;
55935597}
......@@ -5614,7 +5618,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_itera
56145618 __init(__a, __b);
56155619}
56165620
5617# ifndef _LIBCPP_CXX03_LANG
5621# ifndef _LIBCPP_CXX03_LANG
56185622
56195623template <class _BidirectionalIterator, class _CharT, class _Traits>
56205624regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator(
......@@ -5627,7 +5631,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_itera
56275631 __init(__a, __b);
56285632}
56295633
5630# endif // _LIBCPP_CXX03_LANG
5634# endif // _LIBCPP_CXX03_LANG
56315635
56325636template <class _BidirectionalIterator, class _CharT, class _Traits>
56335637template <size_t _Np>
......@@ -5648,8 +5652,8 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_itera
56485652 __suffix_(__x.__suffix_),
56495653 __n_(__x.__n_),
56505654 __subs_(__x.__subs_) {
5651 if (__x.__result_ == &__x.__suffix_)
5652 __result_ = &__suffix_;
5655 if (__x.__result_ == std::addressof(__x.__suffix_))
5656 __result_ = std::addressof(__suffix_);
56535657 else if (__result_ != nullptr)
56545658 __establish_result();
56555659}
......@@ -5657,17 +5661,17 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_itera
56575661template <class _BidirectionalIterator, class _CharT, class _Traits>
56585662regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
56595663regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator=(const regex_token_iterator& __x) {
5660 if (this != &__x) {
5664 if (this != std::addressof(__x)) {
56615665 __position_ = __x.__position_;
5662 if (__x.__result_ == &__x.__suffix_)
5663 __result_ = &__suffix_;
5666 if (__x.__result_ == std::addressof(__x.__suffix_))
5667 __result_ = std::addressof(__suffix_);
56645668 else
56655669 __result_ = __x.__result_;
56665670 __suffix_ = __x.__suffix_;
56675671 __n_ = __x.__n_;
56685672 __subs_ = __x.__subs_;
56695673
5670 if (__result_ != nullptr && __result_ != &__suffix_)
5674 if (__result_ != nullptr && __result_ != std::addressof(__suffix_))
56715675 __establish_result();
56725676 }
56735677 return *this;
......@@ -5677,11 +5681,12 @@ template <class _BidirectionalIterator, class _CharT, class _Traits>
56775681bool regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator==(const regex_token_iterator& __x) const {
56785682 if (__result_ == nullptr && __x.__result_ == nullptr)
56795683 return true;
5680 if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ && __suffix_ == __x.__suffix_)
5684 if (__result_ == std::addressof(__suffix_) && __x.__result_ == std::addressof(__x.__suffix_) &&
5685 __suffix_ == __x.__suffix_)
56815686 return true;
56825687 if (__result_ == nullptr || __x.__result_ == nullptr)
56835688 return false;
5684 if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
5689 if (__result_ == std::addressof(__suffix_) || __x.__result_ == std::addressof(__x.__suffix_))
56855690 return false;
56865691 return __position_ == __x.__position_ && __n_ == __x.__n_ && __subs_ == __x.__subs_;
56875692}
......@@ -5690,7 +5695,7 @@ template <class _BidirectionalIterator, class _CharT, class _Traits>
56905695regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
56915696regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() {
56925697 _Position __prev = __position_;
5693 if (__result_ == &__suffix_)
5698 if (__result_ == std::addressof(__suffix_))
56945699 __result_ = nullptr;
56955700 else if (static_cast<size_t>(__n_ + 1) < __subs_.size()) {
56965701 ++__n_;
......@@ -5705,7 +5710,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() {
57055710 __suffix_.matched = true;
57065711 __suffix_.first = __prev->suffix().first;
57075712 __suffix_.second = __prev->suffix().second;
5708 __result_ = &__suffix_;
5713 __result_ = std::addressof(__suffix_);
57095714 } else
57105715 __result_ = nullptr;
57115716 }
......@@ -5802,7 +5807,7 @@ regex_replace(const _CharT* __s,
58025807
58035808_LIBCPP_END_NAMESPACE_STD
58045809
5805# if _LIBCPP_STD_VER >= 17
5810# if _LIBCPP_STD_VER >= 17
58065811_LIBCPP_BEGIN_NAMESPACE_STD
58075812namespace pmr {
58085813template <class _BidirT>
......@@ -5812,16 +5817,18 @@ using match_results _LIBCPP_AVAILABILITY_PMR =
58125817using cmatch _LIBCPP_AVAILABILITY_PMR = match_results<const char*>;
58135818using smatch _LIBCPP_AVAILABILITY_PMR = match_results<std::pmr::string::const_iterator>;
58145819
5815# if _LIBCPP_HAS_WIDE_CHARACTERS
5820# if _LIBCPP_HAS_WIDE_CHARACTERS
58165821using wcmatch _LIBCPP_AVAILABILITY_PMR = match_results<const wchar_t*>;
58175822using wsmatch _LIBCPP_AVAILABILITY_PMR = match_results<std::pmr::wstring::const_iterator>;
5818# endif
5823# endif
58195824} // namespace pmr
58205825_LIBCPP_END_NAMESPACE_STD
5821# endif
5826# endif
58225827
58235828_LIBCPP_POP_MACROS
58245829
5830# endif // _LIBCPP_HAS_LOCALIZATION
5831
58255832# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
58265833# include <atomic>
58275834# include <concepts>
lib/libcxx/include/scoped_allocator+2-2
......@@ -110,7 +110,7 @@ template <class OuterA1, class OuterA2, class... InnerAllocs>
110110*/
111111
112112#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
113# include <__cxx03/scoped_allocator>
113# include <__cxx03/__config>
114114#else
115115# include <__config>
116116# include <__memory/allocator_traits.h>
......@@ -334,7 +334,7 @@ struct __outermost<_Alloc, true> {
334334};
335335
336336template <class _OuterAlloc, class... _InnerAllocs>
337class _LIBCPP_TEMPLATE_VIS scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>
337class scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>
338338 : public __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> {
339339 typedef __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> _Base;
340340 typedef allocator_traits<_OuterAlloc> _OuterTraits;
lib/libcxx/include/semaphore+1-1
......@@ -46,7 +46,7 @@ using binary_semaphore = counting_semaphore<1>; // since C++20
4646*/
4747
4848#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
49# include <__cxx03/semaphore>
49# include <__cxx03/__config>
5050#else
5151# include <__config>
5252
lib/libcxx/include/set+36-40
......@@ -522,6 +522,7 @@ erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
522522# include <__config>
523523# include <__functional/is_transparent.h>
524524# include <__functional/operations.h>
525# include <__fwd/set.h>
525526# include <__iterator/erase_if_container.h>
526527# include <__iterator/iterator_traits.h>
527528# include <__iterator/ranges_iterator_traits.h>
......@@ -570,10 +571,7 @@ _LIBCPP_PUSH_MACROS
570571_LIBCPP_BEGIN_NAMESPACE_STD
571572
572573template <class _Key, class _Compare, class _Allocator>
573class multiset;
574
575template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
576class _LIBCPP_TEMPLATE_VIS set {
574class set {
577575public:
578576 // types:
579577 typedef _Key key_type;
......@@ -611,9 +609,9 @@ public:
611609# endif
612610
613611 template <class _Key2, class _Compare2, class _Alloc2>
614 friend class _LIBCPP_TEMPLATE_VIS set;
612 friend class set;
615613 template <class _Key2, class _Compare2, class _Alloc2>
616 friend class _LIBCPP_TEMPLATE_VIS multiset;
614 friend class multiset;
617615
618616 _LIBCPP_HIDE_FROM_ABI set() _NOEXCEPT_(
619617 is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_default_constructible<key_compare>::value&&
......@@ -664,14 +662,10 @@ public:
664662
665663 _LIBCPP_HIDE_FROM_ABI set(const set& __s) : __tree_(__s.__tree_) { insert(__s.begin(), __s.end()); }
666664
667 _LIBCPP_HIDE_FROM_ABI set& operator=(const set& __s) {
668 __tree_ = __s.__tree_;
669 return *this;
670 }
665 _LIBCPP_HIDE_FROM_ABI set& operator=(const set& __s) = default;
671666
672667# ifndef _LIBCPP_CXX03_LANG
673 _LIBCPP_HIDE_FROM_ABI set(set&& __s) noexcept(is_nothrow_move_constructible<__base>::value)
674 : __tree_(std::move(__s.__tree_)) {}
668 _LIBCPP_HIDE_FROM_ABI set(set&& __s) noexcept(is_nothrow_move_constructible<__base>::value) = default;
675669# endif // _LIBCPP_CXX03_LANG
676670
677671 _LIBCPP_HIDE_FROM_ABI explicit set(const allocator_type& __a) : __tree_(__a) {}
......@@ -709,7 +703,7 @@ public:
709703 }
710704# endif // _LIBCPP_CXX03_LANG
711705
712 _LIBCPP_HIDE_FROM_ABI ~set() { static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); }
706 _LIBCPP_HIDE_FROM_ABI ~set() { static_assert(sizeof(std::__diagnose_non_const_comparator<_Key, _Compare>()), ""); }
713707
714708 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __tree_.begin(); }
715709 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __tree_.begin(); }
......@@ -742,15 +736,15 @@ public:
742736 }
743737# endif // _LIBCPP_CXX03_LANG
744738
745 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __v) { return __tree_.__insert_unique(__v); }
739 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __v) { return __tree_.__emplace_unique(__v); }
746740 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
747 return __tree_.__insert_unique(__p, __v);
741 return __tree_.__emplace_hint_unique(__p, __v);
748742 }
749743
750744 template <class _InputIterator>
751745 _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __f, _InputIterator __l) {
752746 for (const_iterator __e = cend(); __f != __l; ++__f)
753 __tree_.__insert_unique(__e, *__f);
747 __tree_.__emplace_hint_unique(__e, *__f);
754748 }
755749
756750# if _LIBCPP_STD_VER >= 23
......@@ -758,18 +752,18 @@ public:
758752 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
759753 const_iterator __end = cend();
760754 for (auto&& __element : __range) {
761 __tree_.__insert_unique(__end, std::forward<decltype(__element)>(__element));
755 __tree_.__emplace_hint_unique(__end, std::forward<decltype(__element)>(__element));
762756 }
763757 }
764758# endif
765759
766760# ifndef _LIBCPP_CXX03_LANG
767761 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __v) {
768 return __tree_.__insert_unique(std::move(__v));
762 return __tree_.__emplace_unique(std::move(__v));
769763 }
770764
771765 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
772 return __tree_.__insert_unique(__p, std::move(__v));
766 return __tree_.__emplace_hint_unique(__p, std::move(__v));
773767 }
774768
775769 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
......@@ -1003,9 +997,9 @@ operator<=(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare,
1003997
1004998# else // _LIBCPP_STD_VER <= 17
1005999
1006template <class _Key, class _Allocator>
1000template <class _Key, class _Compare, class _Allocator>
10071001_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Key>
1008operator<=>(const set<_Key, _Allocator>& __x, const set<_Key, _Allocator>& __y) {
1002operator<=>(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare, _Allocator>& __y) {
10091003 return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
10101004}
10111005
......@@ -1032,10 +1026,12 @@ struct __container_traits<set<_Key, _Compare, _Allocator> > {
10321026 // For associative containers, if an exception is thrown by any operation from within
10331027 // an insert or emplace function inserting a single element, the insertion has no effect.
10341028 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
1029
1030 static _LIBCPP_CONSTEXPR const bool __reservable = false;
10351031};
10361032
1037template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
1038class _LIBCPP_TEMPLATE_VIS multiset {
1033template <class _Key, class _Compare, class _Allocator>
1034class multiset {
10391035public:
10401036 // types:
10411037 typedef _Key key_type;
......@@ -1072,9 +1068,9 @@ public:
10721068# endif
10731069
10741070 template <class _Key2, class _Compare2, class _Alloc2>
1075 friend class _LIBCPP_TEMPLATE_VIS set;
1071 friend class set;
10761072 template <class _Key2, class _Compare2, class _Alloc2>
1077 friend class _LIBCPP_TEMPLATE_VIS multiset;
1073 friend class multiset;
10781074
10791075 // construct/copy/destroy:
10801076 _LIBCPP_HIDE_FROM_ABI multiset() _NOEXCEPT_(
......@@ -1129,14 +1125,10 @@ public:
11291125 insert(__s.begin(), __s.end());
11301126 }
11311127
1132 _LIBCPP_HIDE_FROM_ABI multiset& operator=(const multiset& __s) {
1133 __tree_ = __s.__tree_;
1134 return *this;
1135 }
1128 _LIBCPP_HIDE_FROM_ABI multiset& operator=(const multiset& __s) = default;
11361129
11371130# ifndef _LIBCPP_CXX03_LANG
1138 _LIBCPP_HIDE_FROM_ABI multiset(multiset&& __s) noexcept(is_nothrow_move_constructible<__base>::value)
1139 : __tree_(std::move(__s.__tree_)) {}
1131 _LIBCPP_HIDE_FROM_ABI multiset(multiset&& __s) noexcept(is_nothrow_move_constructible<__base>::value) = default;
11401132
11411133 _LIBCPP_HIDE_FROM_ABI multiset(multiset&& __s, const allocator_type& __a);
11421134# endif // _LIBCPP_CXX03_LANG
......@@ -1174,7 +1166,9 @@ public:
11741166 }
11751167# endif // _LIBCPP_CXX03_LANG
11761168
1177 _LIBCPP_HIDE_FROM_ABI ~multiset() { static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); }
1169 _LIBCPP_HIDE_FROM_ABI ~multiset() {
1170 static_assert(sizeof(std::__diagnose_non_const_comparator<_Key, _Compare>()), "");
1171 }
11781172
11791173 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __tree_.begin(); }
11801174 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __tree_.begin(); }
......@@ -1207,15 +1201,15 @@ public:
12071201 }
12081202# endif // _LIBCPP_CXX03_LANG
12091203
1210 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __v) { return __tree_.__insert_multi(__v); }
1204 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __v) { return __tree_.__emplace_multi(__v); }
12111205 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
1212 return __tree_.__insert_multi(__p, __v);
1206 return __tree_.__emplace_hint_multi(__p, __v);
12131207 }
12141208
12151209 template <class _InputIterator>
12161210 _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __f, _InputIterator __l) {
12171211 for (const_iterator __e = cend(); __f != __l; ++__f)
1218 __tree_.__insert_multi(__e, *__f);
1212 __tree_.__emplace_hint_multi(__e, *__f);
12191213 }
12201214
12211215# if _LIBCPP_STD_VER >= 23
......@@ -1223,16 +1217,16 @@ public:
12231217 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
12241218 const_iterator __end = cend();
12251219 for (auto&& __element : __range) {
1226 __tree_.__insert_multi(__end, std::forward<decltype(__element)>(__element));
1220 __tree_.__emplace_hint_multi(__end, std::forward<decltype(__element)>(__element));
12271221 }
12281222 }
12291223# endif
12301224
12311225# ifndef _LIBCPP_CXX03_LANG
1232 _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __v) { return __tree_.__insert_multi(std::move(__v)); }
1226 _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __v) { return __tree_.__emplace_multi(std::move(__v)); }
12331227
12341228 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
1235 return __tree_.__insert_multi(__p, std::move(__v));
1229 return __tree_.__emplace_hint_multi(__p, std::move(__v));
12361230 }
12371231
12381232 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
......@@ -1470,9 +1464,9 @@ operator<=(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key,
14701464
14711465# else // _LIBCPP_STD_VER <= 17
14721466
1473template <class _Key, class _Allocator>
1467template <class _Key, class _Compare, class _Allocator>
14741468_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Key>
1475operator<=>(const multiset<_Key, _Allocator>& __x, const multiset<_Key, _Allocator>& __y) {
1469operator<=>(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key, _Compare, _Allocator>& __y) {
14761470 return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), __synth_three_way);
14771471}
14781472
......@@ -1499,6 +1493,8 @@ struct __container_traits<multiset<_Key, _Compare, _Allocator> > {
14991493 // For associative containers, if an exception is thrown by any operation from within
15001494 // an insert or emplace function inserting a single element, the insertion has no effect.
15011495 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
1496
1497 static _LIBCPP_CONSTEXPR const bool __reservable = false;
15021498};
15031499
15041500_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/shared_mutex+76-91
......@@ -123,7 +123,7 @@ template <class Mutex>
123123*/
124124
125125#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
126# include <__cxx03/shared_mutex>
126# include <__cxx03/__config>
127127#else
128128# include <__config>
129129
......@@ -183,7 +183,7 @@ struct _LIBCPP_EXPORTED_FROM_ABI __shared_mutex_base {
183183};
184184
185185# if _LIBCPP_STD_VER >= 17
186class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_THREAD_SAFETY_ANNOTATION(__capability__("shared_mutex")) shared_mutex {
186class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_CAPABILITY("shared_mutex") shared_mutex {
187187 __shared_mutex_base __base_;
188188
189189public:
......@@ -194,35 +194,23 @@ public:
194194 shared_mutex& operator=(const shared_mutex&) = delete;
195195
196196 // Exclusive ownership
197 _LIBCPP_HIDE_FROM_ABI void lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(__acquire_capability__()) {
198 return __base_.lock();
199 }
200 _LIBCPP_HIDE_FROM_ABI bool try_lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(__try_acquire_capability__(true)) {
201 return __base_.try_lock();
202 }
203 _LIBCPP_HIDE_FROM_ABI void unlock() _LIBCPP_THREAD_SAFETY_ANNOTATION(__release_capability__()) {
204 return __base_.unlock();
205 }
197 _LIBCPP_ACQUIRE_CAPABILITY() _LIBCPP_HIDE_FROM_ABI void lock() { return __base_.lock(); }
198 _LIBCPP_TRY_ACQUIRE_CAPABILITY(true) _LIBCPP_HIDE_FROM_ABI bool try_lock() { return __base_.try_lock(); }
199 _LIBCPP_RELEASE_CAPABILITY _LIBCPP_HIDE_FROM_ABI void unlock() { return __base_.unlock(); }
206200
207201 // Shared ownership
208 _LIBCPP_HIDE_FROM_ABI void lock_shared() _LIBCPP_THREAD_SAFETY_ANNOTATION(__acquire_shared_capability__()) {
209 return __base_.lock_shared();
210 }
211 _LIBCPP_HIDE_FROM_ABI bool try_lock_shared()
212 _LIBCPP_THREAD_SAFETY_ANNOTATION(__try_acquire_shared_capability__(true)) {
202 _LIBCPP_ACQUIRE_SHARED_CAPABILITY _LIBCPP_HIDE_FROM_ABI void lock_shared() { return __base_.lock_shared(); }
203 _LIBCPP_TRY_ACQUIRE_SHARED_CAPABILITY(true) _LIBCPP_HIDE_FROM_ABI bool try_lock_shared() {
213204 return __base_.try_lock_shared();
214205 }
215 _LIBCPP_HIDE_FROM_ABI void unlock_shared() _LIBCPP_THREAD_SAFETY_ANNOTATION(__release_shared_capability__()) {
216 return __base_.unlock_shared();
217 }
206 _LIBCPP_RELEASE_SHARED_CAPABILITY _LIBCPP_HIDE_FROM_ABI void unlock_shared() { return __base_.unlock_shared(); }
218207
219208 // typedef __shared_mutex_base::native_handle_type native_handle_type;
220209 // _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() { return __base::unlock_shared(); }
221210};
222211# endif
223212
224class _LIBCPP_EXPORTED_FROM_ABI
225_LIBCPP_THREAD_SAFETY_ANNOTATION(__capability__("shared_timed_mutex")) shared_timed_mutex {
213class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_CAPABILITY("shared_timed_mutex") shared_timed_mutex {
226214 __shared_mutex_base __base_;
227215
228216public:
......@@ -233,81 +221,77 @@ public:
233221 shared_timed_mutex& operator=(const shared_timed_mutex&) = delete;
234222
235223 // Exclusive ownership
236 void lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(__acquire_capability__());
237 bool try_lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(__try_acquire_capability__(true));
224 void lock() _LIBCPP_ACQUIRE_CAPABILITY();
225 _LIBCPP_TRY_ACQUIRE_CAPABILITY(true) bool try_lock();
238226 template <class _Rep, class _Period>
239 _LIBCPP_HIDE_FROM_ABI bool try_lock_for(const chrono::duration<_Rep, _Period>& __rel_time)
240 _LIBCPP_THREAD_SAFETY_ANNOTATION(__try_acquire_capability__(true)) {
227 _LIBCPP_TRY_ACQUIRE_CAPABILITY(true) _LIBCPP_HIDE_FROM_ABI bool
228 try_lock_for(const chrono::duration<_Rep, _Period>& __rel_time) {
241229 return try_lock_until(chrono::steady_clock::now() + __rel_time);
242230 }
231
243232 template <class _Clock, class _Duration>
244 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool
245 try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time)
246 _LIBCPP_THREAD_SAFETY_ANNOTATION(__try_acquire_capability__(true));
247 void unlock() _LIBCPP_THREAD_SAFETY_ANNOTATION(__release_capability__());
233 _LIBCPP_TRY_ACQUIRE_CAPABILITY(true) _LIBCPP_HIDE_FROM_ABI bool
234 try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time) {
235 unique_lock<mutex> __lk(__base_.__mut_);
236 if (__base_.__state_ & __base_.__write_entered_) {
237 while (true) {
238 cv_status __status = __base_.__gate1_.wait_until(__lk, __abs_time);
239 if ((__base_.__state_ & __base_.__write_entered_) == 0)
240 break;
241 if (__status == cv_status::timeout)
242 return false;
243 }
244 }
245 __base_.__state_ |= __base_.__write_entered_;
246 if (__base_.__state_ & __base_.__n_readers_) {
247 while (true) {
248 cv_status __status = __base_.__gate2_.wait_until(__lk, __abs_time);
249 if ((__base_.__state_ & __base_.__n_readers_) == 0)
250 break;
251 if (__status == cv_status::timeout) {
252 __base_.__state_ &= ~__base_.__write_entered_;
253 __base_.__gate1_.notify_all();
254 return false;
255 }
256 }
257 }
258 return true;
259 }
260
261 _LIBCPP_RELEASE_CAPABILITY void unlock();
248262
249263 // Shared ownership
250 void lock_shared() _LIBCPP_THREAD_SAFETY_ANNOTATION(__acquire_shared_capability__());
251 bool try_lock_shared() _LIBCPP_THREAD_SAFETY_ANNOTATION(__try_acquire_shared_capability__(true));
264 _LIBCPP_ACQUIRE_SHARED_CAPABILITY void lock_shared();
265 _LIBCPP_TRY_ACQUIRE_SHARED_CAPABILITY(true) bool try_lock_shared();
252266 template <class _Rep, class _Period>
253 _LIBCPP_HIDE_FROM_ABI bool try_lock_shared_for(const chrono::duration<_Rep, _Period>& __rel_time)
254 _LIBCPP_THREAD_SAFETY_ANNOTATION(__try_acquire_shared_capability__(true)) {
267 _LIBCPP_TRY_ACQUIRE_SHARED_CAPABILITY(true) _LIBCPP_HIDE_FROM_ABI bool
268 try_lock_shared_for(const chrono::duration<_Rep, _Period>& __rel_time) {
255269 return try_lock_shared_until(chrono::steady_clock::now() + __rel_time);
256270 }
257 template <class _Clock, class _Duration>
258 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool
259 try_lock_shared_until(const chrono::time_point<_Clock, _Duration>& __abs_time)
260 _LIBCPP_THREAD_SAFETY_ANNOTATION(__try_acquire_shared_capability__(true));
261 void unlock_shared() _LIBCPP_THREAD_SAFETY_ANNOTATION(__release_shared_capability__());
262};
263271
264template <class _Clock, class _Duration>
265bool shared_timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time) {
266 unique_lock<mutex> __lk(__base_.__mut_);
267 if (__base_.__state_ & __base_.__write_entered_) {
268 while (true) {
269 cv_status __status = __base_.__gate1_.wait_until(__lk, __abs_time);
270 if ((__base_.__state_ & __base_.__write_entered_) == 0)
271 break;
272 if (__status == cv_status::timeout)
273 return false;
274 }
275 }
276 __base_.__state_ |= __base_.__write_entered_;
277 if (__base_.__state_ & __base_.__n_readers_) {
278 while (true) {
279 cv_status __status = __base_.__gate2_.wait_until(__lk, __abs_time);
280 if ((__base_.__state_ & __base_.__n_readers_) == 0)
281 break;
282 if (__status == cv_status::timeout) {
283 __base_.__state_ &= ~__base_.__write_entered_;
284 __base_.__gate1_.notify_all();
285 return false;
272 template <class _Clock, class _Duration>
273 _LIBCPP_TRY_ACQUIRE_SHARED_CAPABILITY(true) _LIBCPP_HIDE_FROM_ABI bool
274 try_lock_shared_until(const chrono::time_point<_Clock, _Duration>& __abs_time) {
275 unique_lock<mutex> __lk(__base_.__mut_);
276 if ((__base_.__state_ & __base_.__write_entered_) ||
277 (__base_.__state_ & __base_.__n_readers_) == __base_.__n_readers_) {
278 while (true) {
279 cv_status __status = __base_.__gate1_.wait_until(__lk, __abs_time);
280 if ((__base_.__state_ & __base_.__write_entered_) == 0 &&
281 (__base_.__state_ & __base_.__n_readers_) < __base_.__n_readers_)
282 break;
283 if (__status == cv_status::timeout)
284 return false;
286285 }
287286 }
287 unsigned __num_readers = (__base_.__state_ & __base_.__n_readers_) + 1;
288 __base_.__state_ &= ~__base_.__n_readers_;
289 __base_.__state_ |= __num_readers;
290 return true;
288291 }
289 return true;
290}
291292
292template <class _Clock, class _Duration>
293bool shared_timed_mutex::try_lock_shared_until(const chrono::time_point<_Clock, _Duration>& __abs_time) {
294 unique_lock<mutex> __lk(__base_.__mut_);
295 if ((__base_.__state_ & __base_.__write_entered_) ||
296 (__base_.__state_ & __base_.__n_readers_) == __base_.__n_readers_) {
297 while (true) {
298 cv_status __status = __base_.__gate1_.wait_until(__lk, __abs_time);
299 if ((__base_.__state_ & __base_.__write_entered_) == 0 &&
300 (__base_.__state_ & __base_.__n_readers_) < __base_.__n_readers_)
301 break;
302 if (__status == cv_status::timeout)
303 return false;
304 }
305 }
306 unsigned __num_readers = (__base_.__state_ & __base_.__n_readers_) + 1;
307 __base_.__state_ &= ~__base_.__n_readers_;
308 __base_.__state_ |= __num_readers;
309 return true;
310}
293 _LIBCPP_RELEASE_SHARED_CAPABILITY void unlock_shared();
294};
311295
312296template <class _Mutex>
313297class shared_lock {
......@@ -400,9 +384,9 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(shared_lock);
400384template <class _Mutex>
401385void shared_lock<_Mutex>::lock() {
402386 if (__m_ == nullptr)
403 __throw_system_error(EPERM, "shared_lock::lock: references null mutex");
387 std::__throw_system_error(EPERM, "shared_lock::lock: references null mutex");
404388 if (__owns_)
405 __throw_system_error(EDEADLK, "shared_lock::lock: already locked");
389 std::__throw_system_error(EDEADLK, "shared_lock::lock: already locked");
406390 __m_->lock_shared();
407391 __owns_ = true;
408392}
......@@ -410,9 +394,9 @@ void shared_lock<_Mutex>::lock() {
410394template <class _Mutex>
411395bool shared_lock<_Mutex>::try_lock() {
412396 if (__m_ == nullptr)
413 __throw_system_error(EPERM, "shared_lock::try_lock: references null mutex");
397 std::__throw_system_error(EPERM, "shared_lock::try_lock: references null mutex");
414398 if (__owns_)
415 __throw_system_error(EDEADLK, "shared_lock::try_lock: already locked");
399 std::__throw_system_error(EDEADLK, "shared_lock::try_lock: already locked");
416400 __owns_ = __m_->try_lock_shared();
417401 return __owns_;
418402}
......@@ -421,9 +405,9 @@ template <class _Mutex>
421405template <class _Rep, class _Period>
422406bool shared_lock<_Mutex>::try_lock_for(const chrono::duration<_Rep, _Period>& __d) {
423407 if (__m_ == nullptr)
424 __throw_system_error(EPERM, "shared_lock::try_lock_for: references null mutex");
408 std::__throw_system_error(EPERM, "shared_lock::try_lock_for: references null mutex");
425409 if (__owns_)
426 __throw_system_error(EDEADLK, "shared_lock::try_lock_for: already locked");
410 std::__throw_system_error(EDEADLK, "shared_lock::try_lock_for: already locked");
427411 __owns_ = __m_->try_lock_shared_for(__d);
428412 return __owns_;
429413}
......@@ -432,9 +416,9 @@ template <class _Mutex>
432416template <class _Clock, class _Duration>
433417bool shared_lock<_Mutex>::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) {
434418 if (__m_ == nullptr)
435 __throw_system_error(EPERM, "shared_lock::try_lock_until: references null mutex");
419 std::__throw_system_error(EPERM, "shared_lock::try_lock_until: references null mutex");
436420 if (__owns_)
437 __throw_system_error(EDEADLK, "shared_lock::try_lock_until: already locked");
421 std::__throw_system_error(EDEADLK, "shared_lock::try_lock_until: already locked");
438422 __owns_ = __m_->try_lock_shared_until(__t);
439423 return __owns_;
440424}
......@@ -442,7 +426,7 @@ bool shared_lock<_Mutex>::try_lock_until(const chrono::time_point<_Clock, _Durat
442426template <class _Mutex>
443427void shared_lock<_Mutex>::unlock() {
444428 if (!__owns_)
445 __throw_system_error(EPERM, "shared_lock::unlock: not locked");
429 std::__throw_system_error(EPERM, "shared_lock::unlock: not locked");
446430 __m_->unlock_shared();
447431 __owns_ = false;
448432}
......@@ -461,6 +445,7 @@ _LIBCPP_POP_MACROS
461445# endif // _LIBCPP_HAS_THREADS
462446
463447# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
448# include <optional>
464449# include <system_error>
465450# endif
466451#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
lib/libcxx/include/source_location+1-1
......@@ -26,7 +26,7 @@ namespace std {
2626*/
2727
2828#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
29# include <__cxx03/source_location>
29# include <__cxx03/__config>
3030#else
3131# include <__config>
3232# include <cstdint>
lib/libcxx/include/span+3-3
......@@ -145,7 +145,7 @@ template<class R>
145145*/
146146
147147#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
148# include <__cxx03/span>
148# include <__cxx03/__config>
149149#else
150150# include <__assert>
151151# include <__concepts/convertible_to.h>
......@@ -229,7 +229,7 @@ template <class _Sentinel, class _It>
229229concept __span_compatible_sentinel_for = sized_sentinel_for<_Sentinel, _It> && !is_convertible_v<_Sentinel, size_t>;
230230
231231template <typename _Tp, size_t _Extent>
232class _LIBCPP_TEMPLATE_VIS span {
232class span {
233233public:
234234 // constants and types
235235 using element_type = _Tp;
......@@ -412,7 +412,7 @@ private:
412412};
413413
414414template <typename _Tp>
415class _LIBCPP_TEMPLATE_VIS span<_Tp, dynamic_extent> {
415class span<_Tp, dynamic_extent> {
416416public:
417417 // constants and types
418418 using element_type = _Tp;
lib/libcxx/include/sstream+5-5
......@@ -325,7 +325,7 @@ typedef basic_stringstream<wchar_t> wstringstream;
325325# include <__utility/swap.h>
326326# include <ios>
327327# include <istream>
328# include <locale>
328# include <streambuf>
329329# include <string>
330330# include <string_view>
331331# include <version>
......@@ -342,7 +342,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
342342// Class template basic_stringbuf [stringbuf]
343343
344344template <class _CharT, class _Traits, class _Allocator>
345class _LIBCPP_TEMPLATE_VIS basic_stringbuf : public basic_streambuf<_CharT, _Traits> {
345class basic_stringbuf : public basic_streambuf<_CharT, _Traits> {
346346public:
347347 typedef _CharT char_type;
348348 typedef _Traits traits_type;
......@@ -864,7 +864,7 @@ typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type basic_stringbuf<
864864// Class template basic_istringstream [istringstream]
865865
866866template <class _CharT, class _Traits, class _Allocator>
867class _LIBCPP_TEMPLATE_VIS basic_istringstream : public basic_istream<_CharT, _Traits> {
867class basic_istringstream : public basic_istream<_CharT, _Traits> {
868868public:
869869 typedef _CharT char_type;
870870 typedef _Traits traits_type;
......@@ -1000,7 +1000,7 @@ swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x, basic_istringstream<
10001000// Class template basic_ostringstream [ostringstream]
10011001
10021002template <class _CharT, class _Traits, class _Allocator>
1003class _LIBCPP_TEMPLATE_VIS basic_ostringstream : public basic_ostream<_CharT, _Traits> {
1003class basic_ostringstream : public basic_ostream<_CharT, _Traits> {
10041004public:
10051005 typedef _CharT char_type;
10061006 typedef _Traits traits_type;
......@@ -1138,7 +1138,7 @@ swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x, basic_ostringstream<
11381138// Class template basic_stringstream [stringstream]
11391139
11401140template <class _CharT, class _Traits, class _Allocator>
1141class _LIBCPP_TEMPLATE_VIS basic_stringstream : public basic_iostream<_CharT, _Traits> {
1141class basic_stringstream : public basic_iostream<_CharT, _Traits> {
11421142public:
11431143 typedef _CharT char_type;
11441144 typedef _Traits traits_type;
lib/libcxx/include/stack+13-7
......@@ -153,7 +153,7 @@ template <class _Tp, class _Container>
153153_LIBCPP_HIDE_FROM_ABI bool operator<(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y);
154154
155155template <class _Tp, class _Container /*= deque<_Tp>*/>
156class _LIBCPP_TEMPLATE_VIS stack {
156class stack {
157157public:
158158 typedef _Container container_type;
159159 typedef typename container_type::value_type value_type;
......@@ -279,10 +279,18 @@ public:
279279 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; }
280280
281281 template <class _T1, class _OtherContainer>
282 friend bool operator==(const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y);
282 friend _LIBCPP_HIDE_FROM_ABI bool
283 operator==(const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y);
283284
284285 template <class _T1, class _OtherContainer>
285 friend bool operator<(const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y);
286 friend _LIBCPP_HIDE_FROM_ABI bool
287 operator<(const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y);
288
289# if _LIBCPP_STD_VER >= 20
290 template <class _T1, three_way_comparable _OtherContainer>
291 friend _LIBCPP_HIDE_FROM_ABI compare_three_way_result_t<_OtherContainer>
292 operator<=>(const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y);
293# endif
286294};
287295
288296# if _LIBCPP_STD_VER >= 17
......@@ -353,8 +361,7 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const stack<_Tp, _Container>& __x,
353361template <class _Tp, three_way_comparable _Container>
354362_LIBCPP_HIDE_FROM_ABI compare_three_way_result_t<_Container>
355363operator<=>(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) {
356 // clang 16 bug: declaring `friend operator<=>` causes "use of overloaded operator '*' is ambiguous" errors
357 return __x.__get_container() <=> __y.__get_container();
364 return __x.c <=> __y.c;
358365}
359366
360367# endif
......@@ -366,8 +373,7 @@ inline _LIBCPP_HIDE_FROM_ABI void swap(stack<_Tp, _Container>& __x, stack<_Tp, _
366373}
367374
368375template <class _Tp, class _Container, class _Alloc>
369struct _LIBCPP_TEMPLATE_VIS uses_allocator<stack<_Tp, _Container>, _Alloc> : public uses_allocator<_Container, _Alloc> {
370};
376struct uses_allocator<stack<_Tp, _Container>, _Alloc> : public uses_allocator<_Container, _Alloc> {};
371377
372378_LIBCPP_END_NAMESPACE_STD
373379
lib/libcxx/include/stdlib.h+2-17
......@@ -106,23 +106,8 @@ extern "C++" {
106106# undef llabs
107107# endif
108108
109// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
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)
114
115[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float abs(float __lcpp_x) _NOEXCEPT {
116 return __builtin_fabsf(__lcpp_x); // Use builtins to prevent needing math.h
117}
118
119[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double abs(double __lcpp_x) _NOEXCEPT {
120 return __builtin_fabs(__lcpp_x);
121}
122
123[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double abs(long double __lcpp_x) _NOEXCEPT {
124 return __builtin_fabsl(__lcpp_x);
125}
109# include <__math/abs.h>
110using std::__math::abs;
126111
127112// div
128113
lib/libcxx/include/stop_token+1-1
......@@ -32,7 +32,7 @@ namespace std {
3232*/
3333
3434#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
35# include <__cxx03/stop_token>
35# include <__cxx03/__config>
3636#else
3737# include <__config>
3838
lib/libcxx/include/streambuf+38-25
......@@ -134,7 +134,7 @@ _LIBCPP_PUSH_MACROS
134134_LIBCPP_BEGIN_NAMESPACE_STD
135135
136136template <class _CharT, class _Traits>
137class _LIBCPP_TEMPLATE_VIS basic_streambuf {
137class basic_streambuf {
138138public:
139139 // types:
140140 typedef _CharT char_type;
......@@ -178,8 +178,8 @@ public:
178178 // Get and put areas:
179179 // 27.6.2.2.3 Get area:
180180 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 streamsize in_avail() {
181 if (__ninp_ < __einp_)
182 return static_cast<streamsize>(__einp_ - __ninp_);
181 if (gptr() < egptr())
182 return static_cast<streamsize>(egptr() - gptr());
183183 return showmanyc();
184184 }
185185
......@@ -190,37 +190,42 @@ public:
190190 }
191191
192192 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sbumpc() {
193 if (__ninp_ == __einp_)
193 if (gptr() == egptr())
194194 return uflow();
195 return traits_type::to_int_type(*__ninp_++);
195 int_type __c = traits_type::to_int_type(*gptr());
196 this->gbump(1);
197 return __c;
196198 }
197199
198200 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sgetc() {
199 if (__ninp_ == __einp_)
201 if (gptr() == egptr())
200202 return underflow();
201 return traits_type::to_int_type(*__ninp_);
203 return traits_type::to_int_type(*gptr());
202204 }
203205
204206 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 streamsize sgetn(char_type* __s, streamsize __n) { return xsgetn(__s, __n); }
205207
206208 // 27.6.2.2.4 Putback:
207209 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sputbackc(char_type __c) {
208 if (__binp_ == __ninp_ || !traits_type::eq(__c, __ninp_[-1]))
210 if (eback() == gptr() || !traits_type::eq(__c, *(gptr() - 1)))
209211 return pbackfail(traits_type::to_int_type(__c));
210 return traits_type::to_int_type(*--__ninp_);
212 this->gbump(-1);
213 return traits_type::to_int_type(*gptr());
211214 }
212215
213216 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sungetc() {
214 if (__binp_ == __ninp_)
217 if (eback() == gptr())
215218 return pbackfail();
216 return traits_type::to_int_type(*--__ninp_);
219 this->gbump(-1);
220 return traits_type::to_int_type(*gptr());
217221 }
218222
219223 // 27.6.2.2.5 Put area:
220224 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sputc(char_type __c) {
221 if (__nout_ == __eout_)
225 if (pptr() == epptr())
222226 return overflow(traits_type::to_int_type(__c));
223 *__nout_++ = __c;
227 *pptr() = __c;
228 this->pbump(1);
224229 return traits_type::to_int_type(__c);
225230 }
226231
......@@ -267,6 +272,9 @@ protected:
267272
268273 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void gbump(int __n) { __ninp_ += __n; }
269274
275 // gbump takes an int, so it might not be able to represent the offset we want to add.
276 _LIBCPP_HIDE_FROM_ABI void __gbump_ptrdiff(ptrdiff_t __n) { __ninp_ += __n; }
277
270278 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void setg(char_type* __gbeg, char_type* __gnext, char_type* __gend) {
271279 _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__gbeg, __gnext), "[gbeg, gnext) must be a valid range");
272280 _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__gbeg, __gend), "[gbeg, gend) must be a valid range");
......@@ -309,17 +317,16 @@ protected:
309317 virtual streamsize showmanyc() { return 0; }
310318
311319 virtual streamsize xsgetn(char_type* __s, streamsize __n) {
312 const int_type __eof = traits_type::eof();
313320 int_type __c;
314321 streamsize __i = 0;
315322 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);
323 if (gptr() < egptr()) {
324 const streamsize __len = std::min(static_cast<streamsize>(INT_MAX), std::min(egptr() - gptr(), __n - __i));
325 traits_type::copy(__s, gptr(), __len);
319326 __s += __len;
320327 __i += __len;
321328 this->gbump(__len);
322 } else if ((__c = uflow()) != __eof) {
329 } else if ((__c = uflow()) != traits_type::eof()) {
323330 *__s = traits_type::to_char_type(__c);
324331 ++__s;
325332 ++__i;
......@@ -333,7 +340,9 @@ protected:
333340 virtual int_type uflow() {
334341 if (underflow() == traits_type::eof())
335342 return traits_type::eof();
336 return traits_type::to_int_type(*__ninp_++);
343 int_type __c = traits_type::to_int_type(*gptr());
344 this->gbump(1);
345 return __c;
337346 }
338347
339348 // 27.6.2.4.4 Putback:
......@@ -342,17 +351,16 @@ protected:
342351 // 27.6.2.4.5 Put area:
343352 virtual streamsize xsputn(const char_type* __s, streamsize __n) {
344353 streamsize __i = 0;
345 int_type __eof = traits_type::eof();
346354 while (__i < __n) {
347 if (__nout_ >= __eout_) {
348 if (overflow(traits_type::to_int_type(*__s)) == __eof)
355 if (pptr() >= epptr()) {
356 if (overflow(traits_type::to_int_type(*__s)) == traits_type::eof())
349357 break;
350358 ++__s;
351359 ++__i;
352360 } else {
353 streamsize __chunk_size = std::min(__eout_ - __nout_, __n - __i);
354 traits_type::copy(__nout_, __s, __chunk_size);
355 __nout_ += __chunk_size;
361 streamsize __chunk_size = std::min(epptr() - pptr(), __n - __i);
362 traits_type::copy(pptr(), __s, __chunk_size);
363 __pbump(__chunk_size);
356364 __s += __chunk_size;
357365 __i += __chunk_size;
358366 }
......@@ -370,6 +378,10 @@ private:
370378 char_type* __bout_ = nullptr;
371379 char_type* __nout_ = nullptr;
372380 char_type* __eout_ = nullptr;
381
382 template <class _CharT2, class _Traits2, class _Allocator>
383 _LIBCPP_HIDE_FROM_ABI friend basic_istream<_CharT2, _Traits2>&
384 getline(basic_istream<_CharT2, _Traits2>&, basic_string<_CharT2, _Traits2, _Allocator>&, _CharT2);
373385};
374386
375387extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<char>;
......@@ -386,6 +398,7 @@ _LIBCPP_POP_MACROS
386398
387399# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
388400# include <cstdint>
401# include <optional>
389402# endif
390403#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
391404
lib/libcxx/include/string+596-912
......@@ -235,9 +235,9 @@ public:
235235 template <class T>
236236 basic_string& insert(size_type pos1, const T& t); // constexpr since C++20
237237 basic_string& insert(size_type pos1, const basic_string& str,
238 size_type pos2, size_type n); // constexpr since C++20
238 size_type pos2, size_type n2=npos); // constexpr since C++20
239239 template <class T>
240 basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17, constexpr since C++20
240 basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n=npos); // C++17, constexpr since C++20
241241 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); // C++14, constexpr since C++20
242242 basic_string& insert(size_type pos, const value_type* s); // constexpr since C++20
243243 basic_string& insert(size_type pos, size_type n, value_type c); // constexpr since C++20
......@@ -260,7 +260,7 @@ public:
260260 size_type pos2, size_type n2=npos); // C++14, constexpr since C++20
261261 template <class T>
262262 basic_string& replace(size_type pos1, size_type n1, const T& t,
263 size_type pos2, size_type n); // C++17, constexpr since C++20
263 size_type pos2, size_type n2=npos); // C++17, constexpr since C++20
264264 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2); // constexpr since C++20
265265 basic_string& replace(size_type pos, size_type n1, const value_type* s); // constexpr since C++20
266266 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c); // constexpr since C++20
......@@ -516,10 +516,10 @@ basic_istream<charT, traits>&
516516getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
517517
518518template<class charT, class traits, class Allocator, class U>
519typename basic_string<charT, traits, Allocator>::size_type
519constexpr typename basic_string<charT, traits, Allocator>::size_type
520520erase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20
521521template<class charT, class traits, class Allocator, class Predicate>
522typename basic_string<charT, traits, Allocator>::size_type
522constexpr typename basic_string<charT, traits, Allocator>::size_type
523523erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20
524524
525525typedef basic_string<char> string;
......@@ -630,9 +630,11 @@ basic_string<char32_t> operator""s( const char32_t *str, size_t len );
630630# include <__type_traits/is_convertible.h>
631631# include <__type_traits/is_nothrow_assignable.h>
632632# include <__type_traits/is_nothrow_constructible.h>
633# include <__type_traits/is_replaceable.h>
633634# include <__type_traits/is_same.h>
634635# include <__type_traits/is_standard_layout.h>
635# include <__type_traits/is_trivial.h>
636# include <__type_traits/is_trivially_constructible.h>
637# include <__type_traits/is_trivially_copyable.h>
636638# include <__type_traits/is_trivially_relocatable.h>
637639# include <__type_traits/remove_cvref.h>
638640# include <__type_traits/void_t.h>
......@@ -676,7 +678,7 @@ basic_string<char32_t> operator""s( const char32_t *str, size_t len );
676678_LIBCPP_PUSH_MACROS
677679# include <__undef_macros>
678680
679# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
681# if __has_feature(address_sanitizer) && _LIBCPP_INSTRUMENTED_WITH_ASAN
680682# define _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS __attribute__((__no_sanitize__("address")))
681683// This macro disables AddressSanitizer (ASan) instrumentation for a specific function,
682684// allowing memory accesses that would normally trigger ASan errors to proceed without crashing.
......@@ -691,50 +693,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
691693
692694// basic_string
693695
694template <class _CharT, class _Traits, class _Allocator>
695basic_string<_CharT, _Traits, _Allocator> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
696operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const basic_string<_CharT, _Traits, _Allocator>& __y);
697
698template <class _CharT, class _Traits, class _Allocator>
699_LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>
700operator+(const _CharT* __x, const basic_string<_CharT, _Traits, _Allocator>& __y);
701
702template <class _CharT, class _Traits, class _Allocator>
703_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>
704operator+(_CharT __x, const basic_string<_CharT, _Traits, _Allocator>& __y);
705
706template <class _CharT, class _Traits, class _Allocator>
707inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>
708operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
709
710696template <class _CharT, class _Traits, class _Allocator>
711697_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>
712operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
713
714# if _LIBCPP_STD_VER >= 26
715
716template <class _CharT, class _Traits, class _Allocator>
717_LIBCPP_HIDE_FROM_ABI constexpr basic_string<_CharT, _Traits, _Allocator>
718operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
719 type_identity_t<basic_string_view<_CharT, _Traits>> __rhs);
720
721template <class _CharT, class _Traits, class _Allocator>
722_LIBCPP_HIDE_FROM_ABI constexpr basic_string<_CharT, _Traits, _Allocator>
723operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, type_identity_t<basic_string_view<_CharT, _Traits>> __rhs);
724
725template <class _CharT, class _Traits, class _Allocator>
726_LIBCPP_HIDE_FROM_ABI constexpr basic_string<_CharT, _Traits, _Allocator>
727operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs,
728 const basic_string<_CharT, _Traits, _Allocator>& __rhs);
729
730template <class _CharT, class _Traits, class _Allocator>
731_LIBCPP_HIDE_FROM_ABI constexpr basic_string<_CharT, _Traits, _Allocator>
732operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs);
733
734# endif
735
736extern template _LIBCPP_EXPORTED_FROM_ABI string operator+
737 <char, char_traits<char>, allocator<char> >(char const*, string const&);
698__concatenate_strings(const _Allocator& __alloc,
699 __type_identity_t<basic_string_view<_CharT, _Traits> > __str1,
700 __type_identity_t<basic_string_view<_CharT, _Traits> > __str2);
738701
739702template <class _Iter>
740703struct __string_is_trivial_iterator : public false_type {};
......@@ -763,22 +726,19 @@ struct __padding<0> {};
763726
764727template <class _CharT, class _Traits, class _Allocator>
765728class basic_string {
766private:
767 using __default_allocator_type _LIBCPP_NODEBUG = allocator<_CharT>;
768
769729public:
770 typedef basic_string __self;
771 typedef basic_string_view<_CharT, _Traits> __self_view;
772 typedef _Traits traits_type;
773 typedef _CharT value_type;
774 typedef _Allocator allocator_type;
775 typedef allocator_traits<allocator_type> __alloc_traits;
776 typedef typename __alloc_traits::size_type size_type;
777 typedef typename __alloc_traits::difference_type difference_type;
778 typedef value_type& reference;
779 typedef const value_type& const_reference;
780 typedef typename __alloc_traits::pointer pointer;
781 typedef typename __alloc_traits::const_pointer const_pointer;
730 using __self _LIBCPP_NODEBUG = basic_string;
731 using __self_view _LIBCPP_NODEBUG = basic_string_view<_CharT, _Traits>;
732 using traits_type = _Traits;
733 using value_type = _CharT;
734 using allocator_type = _Allocator;
735 using __alloc_traits _LIBCPP_NODEBUG = allocator_traits<allocator_type>;
736 using size_type = typename __alloc_traits::size_type;
737 using difference_type = typename __alloc_traits::difference_type;
738 using reference = value_type&;
739 using const_reference = const value_type&;
740 using pointer = typename __alloc_traits::pointer;
741 using const_pointer = typename __alloc_traits::const_pointer;
782742
783743 // A basic_string contains the following members which may be trivially relocatable:
784744 // - pointer: is currently assumed to be trivially relocatable, but is still checked in case that changes
......@@ -789,13 +749,16 @@ public:
789749 //
790750 // This string implementation doesn't contain any references into itself. It only contains a bit that says whether
791751 // it is in small or large string mode, so the entire structure is trivially relocatable if its members are.
792# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
752# if __has_feature(address_sanitizer) && _LIBCPP_INSTRUMENTED_WITH_ASAN
793753 // When compiling with AddressSanitizer (ASan), basic_string cannot be trivially
794754 // relocatable. Because the object's memory might be poisoned when its content
795755 // is kept inside objects memory (short string optimization), instead of in allocated
796756 // external memory. In such cases, the destructor is responsible for unpoisoning
797757 // the memory to avoid triggering false positives.
798758 // Therefore it's crucial to ensure the destructor is called.
759 //
760 // However, it is replaceable since implementing move-assignment as a destroy + move-construct
761 // will maintain the right ASAN state.
799762 using __trivially_relocatable = void;
800763# else
801764 using __trivially_relocatable _LIBCPP_NODEBUG = __conditional_t<
......@@ -803,8 +766,12 @@ public:
803766 basic_string,
804767 void>;
805768# endif
769 using __replaceable _LIBCPP_NODEBUG =
770 __conditional_t<__is_replaceable_v<pointer> && __container_allocator_is_replaceable<__alloc_traits>::value,
771 basic_string,
772 void>;
806773
807# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
774# if __has_feature(address_sanitizer) && _LIBCPP_INSTRUMENTED_WITH_ASAN
808775 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pointer __asan_volatile_wrapper(pointer const& __ptr) const {
809776 if (__libcpp_is_constant_evaluated())
810777 return __ptr;
......@@ -830,7 +797,9 @@ public:
830797
831798 static_assert(!is_array<value_type>::value, "Character type of basic_string must not be an array");
832799 static_assert(is_standard_layout<value_type>::value, "Character type of basic_string must be standard-layout");
833 static_assert(is_trivial<value_type>::value, "Character type of basic_string must be trivial");
800 static_assert(is_trivially_default_constructible<value_type>::value,
801 "Character type of basic_string must be trivially default constructible");
802 static_assert(is_trivially_copyable<value_type>::value, "Character type of basic_string must be trivially copyable");
834803 static_assert(is_same<_CharT, typename traits_type::char_type>::value,
835804 "traits_type::char_type must be the same type as CharT");
836805 static_assert(is_same<typename allocator_type::value_type, value_type>::value,
......@@ -841,14 +810,14 @@ public:
841810 // Users might provide custom allocators, and prior to C++20 we have no existing way to detect whether the allocator's
842811 // pointer type is contiguous (though it has to be by the Standard). Using the wrapper type ensures the iterator is
843812 // considered contiguous.
844 typedef __bounded_iter<__wrap_iter<pointer> > iterator;
845 typedef __bounded_iter<__wrap_iter<const_pointer> > const_iterator;
813 using iterator = __bounded_iter<__wrap_iter<pointer> >;
814 using const_iterator = __bounded_iter<__wrap_iter<const_pointer> >;
846815# else
847 typedef __wrap_iter<pointer> iterator;
848 typedef __wrap_iter<const_pointer> const_iterator;
816 using iterator = __wrap_iter<pointer>;
817 using const_iterator = __wrap_iter<const_pointer>;
849818# endif
850 typedef std::reverse_iterator<iterator> reverse_iterator;
851 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
819 using reverse_iterator = std::reverse_iterator<iterator>;
820 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
852821
853822private:
854823 static_assert(CHAR_BIT == 8, "This implementation assumes that one byte contains 8 bits");
......@@ -949,7 +918,7 @@ private:
949918 __uninitialized_size_tag, size_type __size, const allocator_type& __a)
950919 : __alloc_(__a) {
951920 if (__size > max_size())
952 __throw_length_error();
921 this->__throw_length_error();
953922 if (__fits_in_sso(__size)) {
954923 __rep_ = __rep();
955924 __set_short_size(__size);
......@@ -1005,7 +974,12 @@ public:
1005974
1006975 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string()
1007976 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
1008 : __rep_() {
977# if _LIBCPP_STD_VER >= 20 // TODO(LLVM 23): Remove this condition; this is a workaround for https://llvm.org/PR154567
978 : __rep_(__short())
979# else
980 : __rep_()
981# endif
982 {
1009983 __annotate_new(0);
1010984 }
1011985
......@@ -1015,7 +989,12 @@ public:
1015989# else
1016990 _NOEXCEPT
1017991# endif
1018 : __rep_(), __alloc_(__a) {
992# if _LIBCPP_STD_VER >= 20 // TODO(LLVM 23): Remove this condition; this is a workaround for https://llvm.org/PR154567
993 : __rep_(__short()),
994# else
995 : __rep_(),
996# endif
997 __alloc_(__a) {
1019998 __annotate_new(0);
1020999 }
10211000
......@@ -1079,13 +1058,14 @@ public:
10791058# endif // _LIBCPP_CXX03_LANG
10801059
10811060 template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0>
1082 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s) {
1061 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __s) {
10831062 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "basic_string(const char*) detected nullptr");
10841063 __init(__s, traits_type::length(__s));
10851064 }
10861065
10871066 template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0>
1088 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, const _Allocator& __a)
1067 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1068 basic_string(const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __s, const _Allocator& __a)
10891069 : __alloc_(__a) {
10901070 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
10911071 __init(__s, traits_type::length(__s));
......@@ -1118,7 +1098,7 @@ public:
11181098 basic_string&& __str, size_type __pos, size_type __n, const _Allocator& __alloc = _Allocator())
11191099 : __alloc_(__alloc) {
11201100 if (__pos > __str.size())
1121 __throw_out_of_range();
1101 this->__throw_out_of_range();
11221102
11231103 auto __len = std::min<size_type>(__n, __str.size() - __pos);
11241104 if (__alloc_traits::is_always_equal::value || __alloc == __str.__alloc_) {
......@@ -1141,7 +1121,7 @@ public:
11411121 : __alloc_(__a) {
11421122 size_type __str_sz = __str.size();
11431123 if (__pos > __str_sz)
1144 __throw_out_of_range();
1124 this->__throw_out_of_range();
11451125 __init(__str.data() + __pos, std::min(__n, __str_sz - __pos));
11461126 }
11471127
......@@ -1150,15 +1130,15 @@ public:
11501130 : __alloc_(__a) {
11511131 size_type __str_sz = __str.size();
11521132 if (__pos > __str_sz)
1153 __throw_out_of_range();
1133 this->__throw_out_of_range();
11541134 __init(__str.data() + __pos, __str_sz - __pos);
11551135 }
11561136
11571137 template <class _Tp,
11581138 __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1159 !__is_same_uncvref<_Tp, basic_string>::value,
1139 !is_same<__remove_cvref_t<_Tp>, basic_string>::value,
11601140 int> = 0>
1161 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
1141 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
11621142 basic_string(const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a = allocator_type())
11631143 : __alloc_(__a) {
11641144 __self_view __sv0 = __t;
......@@ -1168,20 +1148,18 @@ public:
11681148
11691149 template <class _Tp,
11701150 __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1171 !__is_same_uncvref<_Tp, basic_string>::value,
1151 !is_same<__remove_cvref_t<_Tp>, basic_string>::value,
11721152 int> = 0>
1173 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1174 _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const _Tp& __t) {
1153 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const _Tp& __t) {
11751154 __self_view __sv = __t;
11761155 __init(__sv.data(), __sv.size());
11771156 }
11781157
11791158 template <class _Tp,
11801159 __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1181 !__is_same_uncvref<_Tp, basic_string>::value,
1160 !is_same<__remove_cvref_t<_Tp>, basic_string>::value,
11821161 int> = 0>
1183 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1184 _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const _Tp& __t, const allocator_type& __a)
1162 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const _Tp& __t, const allocator_type& __a)
11851163 : __alloc_(__a) {
11861164 __self_view __sv = __t;
11871165 __init(__sv.data(), __sv.size());
......@@ -1238,7 +1216,7 @@ public:
12381216
12391217 template <class _Tp,
12401218 __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1241 !__is_same_uncvref<_Tp, basic_string>::value,
1219 !is_same<__remove_cvref_t<_Tp>, basic_string>::value,
12421220 int> = 0>
12431221 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(const _Tp& __t) {
12441222 __self_view __sv = __t;
......@@ -1256,7 +1234,8 @@ public:
12561234 return assign(__il.begin(), __il.size());
12571235 }
12581236# endif
1259 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(const value_type* __s) {
1237 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1238 operator=(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) {
12601239 return assign(__s);
12611240 }
12621241# if _LIBCPP_STD_VER >= 23
......@@ -1303,12 +1282,20 @@ public:
13031282 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type length() const _NOEXCEPT { return size(); }
13041283
13051284 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT {
1306 size_type __m = __alloc_traits::max_size(__alloc_);
1307 if (__m <= std::numeric_limits<size_type>::max() / 2) {
1308 return __m - __alignment;
1285 if (size_type __m = __alloc_traits::max_size(__alloc_); __m <= std::numeric_limits<size_type>::max() / 2) {
1286 size_type __res = __m - __alignment;
1287
1288 // When the __endian_factor == 2, our string representation assumes that the capacity
1289 // (including the null terminator) is always even, so we have to make sure the lowest bit isn't set when the
1290 // string grows to max_size()
1291 if (__endian_factor == 2)
1292 __res &= ~size_type(1);
1293
1294 // We have to allocate space for the null terminator, but max_size() doesn't include it.
1295 return __res - 1;
13091296 } else {
13101297 bool __uses_lsb = __endian_factor == 2;
1311 return __uses_lsb ? __m - __alignment : (__m / 2) - __alignment;
1298 return __uses_lsb ? __m - __alignment - 1 : (__m / 2) - __alignment - 1;
13121299 }
13131300 }
13141301
......@@ -1366,15 +1353,15 @@ public:
13661353
13671354 template <class _Tp,
13681355 __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1369 !__is_same_uncvref<_Tp, basic_string >::value,
1356 !is_same<__remove_cvref_t<_Tp>, basic_string >::value,
13701357 int> = 0>
1371 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1372 operator+=(const _Tp& __t) {
1358 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator+=(const _Tp& __t) {
13731359 __self_view __sv = __t;
13741360 return append(__sv);
13751361 }
13761362
1377 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator+=(const value_type* __s) {
1363 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1364 operator+=(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) {
13781365 return append(__s);
13791366 }
13801367
......@@ -1395,10 +1382,9 @@ public:
13951382
13961383 template <class _Tp,
13971384 __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1398 !__is_same_uncvref<_Tp, basic_string>::value,
1385 !is_same<__remove_cvref_t<_Tp>, basic_string>::value,
13991386 int> = 0>
1400 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1401 append(const _Tp& __t) {
1387 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const _Tp& __t) {
14021388 __self_view __sv = __t;
14031389 return append(__sv.data(), __sv.size());
14041390 }
......@@ -1407,21 +1393,25 @@ public:
14071393
14081394 template <class _Tp,
14091395 __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1410 !__is_same_uncvref<_Tp, basic_string>::value,
1396 !is_same<__remove_cvref_t<_Tp>, basic_string>::value,
14111397 int> = 0>
1412 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
1413
1414 basic_string&
1415 append(const _Tp& __t, size_type __pos, size_type __n = npos);
1398 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1399 append(const _Tp& __t, size_type __pos, size_type __n = npos) {
1400 __self_view __sv = __t;
1401 size_type __sz = __sv.size();
1402 if (__pos > __sz)
1403 __throw_out_of_range();
1404 return append(__sv.data() + __pos, std::min(__n, __sz - __pos));
1405 }
14161406
14171407 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const value_type* __s, size_type __n);
1418 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const value_type* __s);
1408 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s);
14191409 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(size_type __n, value_type __c);
14201410
14211411 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __append_default_init(size_type __n);
14221412
14231413 template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
1424 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1414 _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
14251415 append(_InputIterator __first, _InputIterator __last) {
14261416 const basic_string __temp(__first, __last, __alloc_);
14271417 append(__temp.data(), __temp.size());
......@@ -1429,8 +1419,26 @@ public:
14291419 }
14301420
14311421 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
1432 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1433 append(_ForwardIterator __first, _ForwardIterator __last);
1422 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1423 append(_ForwardIterator __first, _ForwardIterator __last) {
1424 size_type __sz = size();
1425 size_type __cap = capacity();
1426 size_type __n = static_cast<size_type>(std::distance(__first, __last));
1427 if (__n) {
1428 if (__string_is_trivial_iterator<_ForwardIterator>::value && !__addr_in_range(*__first)) {
1429 if (__cap - __sz < __n)
1430 __grow_by_without_replace(__cap, __sz + __n - __cap, __sz, __sz, 0);
1431 __annotate_increase(__n);
1432 auto __end = __copy_non_overlapping_range(__first, __last, std::__to_address(__get_pointer() + __sz));
1433 traits_type::assign(*__end, value_type());
1434 __set_size(__sz + __n);
1435 } else {
1436 const basic_string __temp(__first, __last, __alloc_);
1437 append(__temp.data(), __temp.size());
1438 }
1439 }
1440 return *this;
1441 }
14341442
14351443# if _LIBCPP_STD_VER >= 23
14361444 template <_ContainerCompatibleRange<_CharT> _Range>
......@@ -1470,8 +1478,7 @@ public:
14701478 }
14711479
14721480 template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1473 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1474 assign(const _Tp& __t) {
1481 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const _Tp& __t) {
14751482 __self_view __sv = __t;
14761483 return assign(__sv.data(), __sv.size());
14771484 }
......@@ -1513,21 +1520,40 @@ public:
15131520
15141521 template <class _Tp,
15151522 __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1516 !__is_same_uncvref<_Tp, basic_string>::value,
1523 !is_same<__remove_cvref_t<_Tp>, basic_string>::value,
15171524 int> = 0>
1518 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1519 assign(const _Tp& __t, size_type __pos, size_type __n = npos);
1525 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1526 assign(const _Tp& __t, size_type __pos, size_type __n = npos) {
1527 __self_view __sv = __t;
1528 size_type __sz = __sv.size();
1529 if (__pos > __sz)
1530 __throw_out_of_range();
1531 return assign(__sv.data() + __pos, std::min(__n, __sz - __pos));
1532 }
15201533
15211534 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const value_type* __s, size_type __n);
15221535 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const value_type* __s);
15231536 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(size_type __n, value_type __c);
1537
15241538 template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
1525 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1526 assign(_InputIterator __first, _InputIterator __last);
1539 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1540 assign(_InputIterator __first, _InputIterator __last) {
1541 __assign_with_sentinel(__first, __last);
1542 return *this;
1543 }
15271544
15281545 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
1529 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1530 assign(_ForwardIterator __first, _ForwardIterator __last);
1546 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1547 assign(_ForwardIterator __first, _ForwardIterator __last) {
1548 if (__string_is_trivial_iterator<_ForwardIterator>::value) {
1549 size_type __n = static_cast<size_type>(std::distance(__first, __last));
1550 __assign_trivial(__first, __last, __n);
1551 } else {
1552 __assign_with_sentinel(__first, __last);
1553 }
1554
1555 return *this;
1556 }
15311557
15321558# if _LIBCPP_STD_VER >= 23
15331559 template <_ContainerCompatibleRange<_CharT> _Range>
......@@ -1557,23 +1583,28 @@ public:
15571583 }
15581584
15591585 template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1560 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1561 insert(size_type __pos1, const _Tp& __t) {
1586 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos1, const _Tp& __t) {
15621587 __self_view __sv = __t;
15631588 return insert(__pos1, __sv.data(), __sv.size());
15641589 }
15651590
15661591 template <class _Tp,
15671592 __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1568 !__is_same_uncvref<_Tp, basic_string>::value,
1593 !is_same<__remove_cvref_t<_Tp>, basic_string>::value,
15691594 int> = 0>
1570 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1571 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n = npos);
1595 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1596 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n = npos) {
1597 __self_view __sv = __t;
1598 size_type __str_sz = __sv.size();
1599 if (__pos2 > __str_sz)
1600 __throw_out_of_range();
1601 return insert(__pos1, __sv.data() + __pos2, std::min(__n, __str_sz - __pos2));
1602 }
15721603
15731604 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
15741605 insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n = npos);
15751606 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1576 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, const value_type* __s);
1607 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s);
15771608 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, size_type __n, value_type __c);
15781609 _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __pos, value_type __c);
15791610
......@@ -1599,12 +1630,18 @@ public:
15991630 }
16001631
16011632 template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
1602 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
1603 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1633 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
1634 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last) {
1635 const basic_string __temp(__first, __last, __alloc_);
1636 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
1637 }
16041638
16051639 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
1606 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
1607 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
1640 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
1641 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last) {
1642 auto __n = static_cast<size_type>(std::distance(__first, __last));
1643 return __insert_with_size(__pos, __first, __last, __n);
1644 }
16081645
16091646# ifndef _LIBCPP_CXX03_LANG
16101647 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
......@@ -1623,7 +1660,7 @@ public:
16231660 }
16241661
16251662 template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1626 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1663 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
16271664 replace(size_type __pos1, size_type __n1, const _Tp& __t) {
16281665 __self_view __sv = __t;
16291666 return replace(__pos1, __n1, __sv.data(), __sv.size());
......@@ -1634,10 +1671,16 @@ public:
16341671
16351672 template <class _Tp,
16361673 __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1637 !__is_same_uncvref<_Tp, basic_string>::value,
1674 !is_same<__remove_cvref_t<_Tp>, basic_string>::value,
16381675 int> = 0>
1639 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1640 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2 = npos);
1676 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1677 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2 = npos) {
1678 __self_view __sv = __t;
1679 size_type __str_sz = __sv.size();
1680 if (__pos2 > __str_sz)
1681 __throw_out_of_range();
1682 return replace(__pos1, __n1, __sv.data() + __pos2, std::min(__n2, __str_sz - __pos2));
1683 }
16411684
16421685 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
16431686 replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
......@@ -1651,7 +1694,7 @@ public:
16511694 }
16521695
16531696 template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1654 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1697 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
16551698 replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) {
16561699 __self_view __sv = __t;
16571700 return replace(__i1 - begin(), __i2 - __i1, __sv);
......@@ -1673,8 +1716,11 @@ public:
16731716 }
16741717
16751718 template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
1676 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1677 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
1719 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1720 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2) {
1721 const basic_string __temp(__j1, __j2, __alloc_);
1722 return replace(__i1, __i2, __temp);
1723 }
16781724
16791725# if _LIBCPP_STD_VER >= 23
16801726 template <_ContainerCompatibleRange<_CharT> _Range>
......@@ -1716,6 +1762,9 @@ public:
17161762 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>);
17171763# endif
17181764
1765 // [string.ops]
1766 // ------------
1767
17191768 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const value_type* c_str() const _NOEXCEPT { return data(); }
17201769 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const value_type* data() const _NOEXCEPT {
17211770 return std::__to_address(__get_pointer());
......@@ -1730,113 +1779,267 @@ public:
17301779 return __alloc_;
17311780 }
17321781
1782 // find
1783
17331784 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1734 find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1785 find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT {
1786 return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __str.data(), __pos, __str.size());
1787 }
17351788
17361789 template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1737 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1738 find(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT;
1790 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1791 find(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT {
1792 __self_view __sv = __t;
1793 return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __sv.data(), __pos, __sv.size());
1794 }
1795
1796 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
1797 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::find(): received nullptr");
1798 return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
1799 }
17391800
1740 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
17411801 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1742 find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1743 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1802 find(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s, size_type __pos = 0) const _NOEXCEPT {
1803 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::find(): received nullptr");
1804 return std::__str_find<value_type, size_type, traits_type, npos>(
1805 data(), size(), __s, __pos, traits_type::length(__s));
1806 }
1807
1808 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT {
1809 return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
1810 }
1811
1812 // rfind
17441813
17451814 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1746 rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1815 rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT {
1816 return std::__str_rfind<value_type, size_type, traits_type, npos>(
1817 data(), size(), __str.data(), __pos, __str.size());
1818 }
17471819
17481820 template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1749 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1750 rfind(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
1821 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1822 rfind(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT {
1823 __self_view __sv = __t;
1824 return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __sv.data(), __pos, __sv.size());
1825 }
1826
1827 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
1828 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
1829 return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
1830 }
17511831
1752 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
17531832 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1754 rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1755 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1833 rfind(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s, size_type __pos = npos) const _NOEXCEPT {
1834 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::rfind(): received nullptr");
1835 return std::__str_rfind<value_type, size_type, traits_type, npos>(
1836 data(), size(), __s, __pos, traits_type::length(__s));
1837 }
1838
1839 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT {
1840 return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
1841 }
1842
1843 // find_first_of
17561844
17571845 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1758 find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1846 find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT {
1847 return std::__str_find_first_of<value_type, size_type, traits_type, npos>(
1848 data(), size(), __str.data(), __pos, __str.size());
1849 }
17591850
17601851 template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1761 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1762 find_first_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT;
1852 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1853 find_first_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT {
1854 __self_view __sv = __t;
1855 return std::__str_find_first_of<value_type, size_type, traits_type, npos>(
1856 data(), size(), __sv.data(), __pos, __sv.size());
1857 }
17631858
17641859 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1765 find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1860 find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
1861 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
1862 return std::__str_find_first_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
1863 }
1864
17661865 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1767 find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1866 find_first_of(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s, size_type __pos = 0) const _NOEXCEPT {
1867 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::find_first_of(): received nullptr");
1868 return std::__str_find_first_of<value_type, size_type, traits_type, npos>(
1869 data(), size(), __s, __pos, traits_type::length(__s));
1870 }
1871
17681872 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1769 find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1873 find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT {
1874 return find(__c, __pos);
1875 }
1876
1877 // find_last_of
17701878
17711879 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1772 find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1880 find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT {
1881 return std::__str_find_last_of<value_type, size_type, traits_type, npos>(
1882 data(), size(), __str.data(), __pos, __str.size());
1883 }
17731884
17741885 template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1775 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1776 find_last_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
1886 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1887 find_last_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT {
1888 __self_view __sv = __t;
1889 return std::__str_find_last_of<value_type, size_type, traits_type, npos>(
1890 data(), size(), __sv.data(), __pos, __sv.size());
1891 }
17771892
17781893 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1779 find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1894 find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
1895 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
1896 return std::__str_find_last_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
1897 }
1898
17801899 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1781 find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1900 find_last_of(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s, size_type __pos = npos) const _NOEXCEPT {
1901 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::find_last_of(): received nullptr");
1902 return std::__str_find_last_of<value_type, size_type, traits_type, npos>(
1903 data(), size(), __s, __pos, traits_type::length(__s));
1904 }
1905
17821906 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1783 find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1907 find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT {
1908 return rfind(__c, __pos);
1909 }
1910
1911 // find_first_not_of
17841912
17851913 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1786 find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1914 find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT {
1915 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(
1916 data(), size(), __str.data(), __pos, __str.size());
1917 }
17871918
17881919 template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1789 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1790 find_first_not_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT;
1920 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1921 find_first_not_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT {
1922 __self_view __sv = __t;
1923 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(
1924 data(), size(), __sv.data(), __pos, __sv.size());
1925 }
17911926
17921927 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1793 find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1928 find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
1929 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
1930 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
1931 }
1932
17941933 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1795 find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1934 find_first_not_of(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s, size_type __pos = 0) const _NOEXCEPT {
1935 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::find_first_not_of(): received nullptr");
1936 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(
1937 data(), size(), __s, __pos, traits_type::length(__s));
1938 }
1939
17961940 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1797 find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1941 find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT {
1942 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
1943 }
1944
1945 // find_last_not_of
17981946
17991947 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1800 find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1948 find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT {
1949 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(
1950 data(), size(), __str.data(), __pos, __str.size());
1951 }
18011952
18021953 template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1803 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1804 find_last_not_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
1954 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1955 find_last_not_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT {
1956 __self_view __sv = __t;
1957 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(
1958 data(), size(), __sv.data(), __pos, __sv.size());
1959 }
18051960
18061961 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1807 find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1962 find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
1963 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
1964 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
1965 }
1966
18081967 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1809 find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1968 find_last_not_of(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s, size_type __pos = npos) const _NOEXCEPT {
1969 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::find_last_not_of(): received nullptr");
1970 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(
1971 data(), size(), __s, __pos, traits_type::length(__s));
1972 }
1973
18101974 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1811 find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1975 find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT {
1976 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
1977 }
18121978
1813 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(const basic_string& __str) const _NOEXCEPT;
1979 // compare
1980
1981 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(const basic_string& __str) const _NOEXCEPT {
1982 return compare(__self_view(__str));
1983 }
18141984
18151985 template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1816 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 int
1817 compare(const _Tp& __t) const _NOEXCEPT;
1986 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(const _Tp& __t) const _NOEXCEPT {
1987 __self_view __sv = __t;
1988 size_t __lhs_sz = size();
1989 size_t __rhs_sz = __sv.size();
1990 int __result = traits_type::compare(data(), __sv.data(), std::min(__lhs_sz, __rhs_sz));
1991 if (__result != 0)
1992 return __result;
1993 if (__lhs_sz < __rhs_sz)
1994 return -1;
1995 if (__lhs_sz > __rhs_sz)
1996 return 1;
1997 return 0;
1998 }
18181999
18192000 template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0>
1820 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 int
1821 compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
2001 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 int
2002 compare(size_type __pos1, size_type __n1, const _Tp& __t) const {
2003 __self_view __sv = __t;
2004 return compare(__pos1, __n1, __sv.data(), __sv.size());
2005 }
18222006
18232007 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 int
1824 compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
2008 compare(size_type __pos1, size_type __n1, const basic_string& __str) const {
2009 return compare(__pos1, __n1, __str.data(), __str.size());
2010 }
2011
18252012 _LIBCPP_CONSTEXPR_SINCE_CXX20 int
1826 compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2 = npos) const;
2013 compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2 = npos) const {
2014 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
2015 }
18272016
18282017 template <class _Tp,
18292018 __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
1830 !__is_same_uncvref<_Tp, basic_string>::value,
2019 !is_same<__remove_cvref_t<_Tp>, basic_string>::value,
18312020 int> = 0>
18322021 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 int
1833 compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2 = npos) const;
2022 compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2 = npos) const {
2023 __self_view __sv = __t;
2024 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
2025 }
2026
2027 _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) const _NOEXCEPT {
2028 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::compare(): received nullptr");
2029 return compare(0, npos, __s, traits_type::length(__s));
2030 }
2031
2032 _LIBCPP_CONSTEXPR_SINCE_CXX20 int
2033 compare(size_type __pos1, size_type __n1, const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) const {
2034 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::compare(): received nullptr");
2035 return compare(__pos1, __n1, __s, traits_type::length(__s));
2036 }
18342037
1835 _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(const value_type* __s) const _NOEXCEPT;
1836 _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
18372038 _LIBCPP_CONSTEXPR_SINCE_CXX20 int
18382039 compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
18392040
2041 // starts_with
2042
18402043# if _LIBCPP_STD_VER >= 20
18412044 constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(__self_view __sv) const noexcept {
18422045 return __self_view(typename __self_view::__assume_valid(), data(), size()).starts_with(__sv);
......@@ -1846,10 +2049,12 @@ public:
18462049 return !empty() && _Traits::eq(front(), __c);
18472050 }
18482051
1849 constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(const value_type* __s) const noexcept {
2052 constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) const noexcept {
18502053 return starts_with(__self_view(__s));
18512054 }
18522055
2056 // ends_with
2057
18532058 constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(__self_view __sv) const noexcept {
18542059 return __self_view(typename __self_view::__assume_valid(), data(), size()).ends_with(__sv);
18552060 }
......@@ -1858,11 +2063,13 @@ public:
18582063 return !empty() && _Traits::eq(back(), __c);
18592064 }
18602065
1861 constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(const value_type* __s) const noexcept {
2066 constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) const noexcept {
18622067 return ends_with(__self_view(__s));
18632068 }
18642069# endif
18652070
2071 // contains
2072
18662073# if _LIBCPP_STD_VER >= 23
18672074 constexpr _LIBCPP_HIDE_FROM_ABI bool contains(__self_view __sv) const noexcept {
18682075 return __self_view(typename __self_view::__assume_valid(), data(), size()).contains(__sv);
......@@ -1872,18 +2079,14 @@ public:
18722079 return __self_view(typename __self_view::__assume_valid(), data(), size()).contains(__c);
18732080 }
18742081
1875 constexpr _LIBCPP_HIDE_FROM_ABI bool contains(const value_type* __s) const {
2082 constexpr _LIBCPP_HIDE_FROM_ABI bool contains(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) const {
18762083 return __self_view(typename __self_view::__assume_valid(), data(), size()).contains(__s);
18772084 }
18782085# endif
18792086
18802087 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const;
18812088
1882 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __clear_and_shrink() _NOEXCEPT;
1883
18842089private:
1885 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __shrink_or_extend(size_type __target_capacity);
1886
18872090 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS bool
18882091 __is_long() const _NOEXCEPT {
18892092 if (__libcpp_is_constant_evaluated() && __builtin_constant_p(__rep_.__l.__is_long_)) {
......@@ -2038,7 +2241,7 @@ private:
20382241 __annotate_contiguous_container(const void* __old_mid, const void* __new_mid) const {
20392242 (void)__old_mid;
20402243 (void)__new_mid;
2041# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
2244# if _LIBCPP_INSTRUMENTED_WITH_ASAN
20422245# if defined(__APPLE__)
20432246 // TODO: remove after addressing issue #96099 (https://github.com/llvm/llvm-project/issues/96099)
20442247 if (!__is_long())
......@@ -2049,36 +2252,36 @@ private:
20492252 }
20502253
20512254 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_new(size_type __current_size) const _NOEXCEPT {
2052 (void)__current_size;
2053# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
2054 if (!__libcpp_is_constant_evaluated())
2055 __annotate_contiguous_container(data() + capacity() + 1, data() + __current_size + 1);
2056# endif
2255 __annotate_contiguous_container(data() + capacity() + 1, data() + __current_size + 1);
20572256 }
20582257
20592258 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_delete() const _NOEXCEPT {
2060# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
2061 if (!__libcpp_is_constant_evaluated())
2062 __annotate_contiguous_container(data() + size() + 1, data() + capacity() + 1);
2063# endif
2259 __annotate_contiguous_container(data() + size() + 1, data() + capacity() + 1);
20642260 }
20652261
20662262 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_increase(size_type __n) const _NOEXCEPT {
2067 (void)__n;
2068# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
2069 if (!__libcpp_is_constant_evaluated())
2070 __annotate_contiguous_container(data() + size() + 1, data() + size() + 1 + __n);
2071# endif
2263 __annotate_contiguous_container(data() + size() + 1, data() + size() + 1 + __n);
20722264 }
20732265
20742266 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __annotate_shrink(size_type __old_size) const _NOEXCEPT {
2075 (void)__old_size;
2076# if _LIBCPP_HAS_ASAN && _LIBCPP_INSTRUMENTED_WITH_ASAN
2077 if (!__libcpp_is_constant_evaluated())
2078 __annotate_contiguous_container(data() + __old_size + 1, data() + size() + 1);
2079# endif
2267 __annotate_contiguous_container(data() + __old_size + 1, data() + size() + 1);
20802268 }
20812269
2270 // Disable ASan annotations and enable them again when going out of scope. It is assumed that the string is in a valid
2271 // state at that point, so `size()` can be called safely.
2272 struct [[__nodiscard__]] __annotation_guard {
2273 __annotation_guard(const __annotation_guard&) = delete;
2274 __annotation_guard& operator=(const __annotation_guard&) = delete;
2275
2276 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __annotation_guard(basic_string& __str) : __str_(__str) {
2277 __str_.__annotate_delete();
2278 }
2279
2280 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__annotation_guard() { __str_.__annotate_new(__str_.size()); }
2281
2282 basic_string& __str_;
2283 };
2284
20822285 template <size_type __a>
20832286 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __align_it(size_type __s) _NOEXCEPT {
20842287 return (__s + (__a - 1)) & ~(__a - 1);
......@@ -2097,7 +2300,6 @@ private:
20972300 return __guess;
20982301 }
20992302
2100 inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void __init(const value_type* __s, size_type __sz, size_type __reserve);
21012303 inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void __init(const value_type* __s, size_type __sz);
21022304 inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void __init(size_type __n, value_type __c);
21032305
......@@ -2176,7 +2378,11 @@ private:
21762378 __alloc_ = __str.__alloc_;
21772379 else {
21782380 if (!__str.__is_long()) {
2179 __clear_and_shrink();
2381 if (__is_long()) {
2382 __annotate_delete();
2383 __alloc_traits::deallocate(__alloc_, __get_long_pointer(), __get_long_cap());
2384 __rep_ = __rep();
2385 }
21802386 __alloc_ = __str.__alloc_;
21812387 } else {
21822388 __annotate_delete();
......@@ -2189,7 +2395,7 @@ private:
21892395 __alloc_ = std::move(__a);
21902396 __set_long_pointer(__allocation.ptr);
21912397 __set_long_cap(__allocation.count);
2192 __set_long_size(__str.size());
2398 __set_long_size(__str.__get_long_size());
21932399 }
21942400 }
21952401 }
......@@ -2231,8 +2437,14 @@ private:
22312437 size_type __old_size = size();
22322438 if (__n > __old_size)
22332439 __annotate_increase(__n - __old_size);
2234 pointer __p =
2235 __is_long() ? (__set_long_size(__n), __get_long_pointer()) : (__set_short_size(__n), __get_short_pointer());
2440 pointer __p;
2441 if (__is_long()) {
2442 __set_long_size(__n);
2443 __p = __get_long_pointer();
2444 } else {
2445 __set_short_size(__n);
2446 __p = __get_short_pointer();
2447 }
22362448 traits_type::move(std::__to_address(__p), __s, __n);
22372449 traits_type::assign(__p[__n], value_type());
22382450 if (__old_size > __n)
......@@ -2265,24 +2477,23 @@ private:
22652477 std::__throw_out_of_range("basic_string");
22662478 }
22672479
2268 friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+ <>(const basic_string&, const basic_string&);
2269 friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+ <>(const value_type*, const basic_string&);
2270 friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+ <>(value_type, const basic_string&);
2271 friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+ <>(const basic_string&, const value_type*);
2272 friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+ <>(const basic_string&, value_type);
2273# if _LIBCPP_STD_VER >= 26
2274 friend constexpr basic_string operator+ <>(const basic_string&, type_identity_t<__self_view>);
2275 friend constexpr basic_string operator+ <>(type_identity_t<__self_view>, const basic_string&);
2276# endif
2480 friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string
2481 __concatenate_strings<>(const _Allocator&, __type_identity_t<__self_view>, __type_identity_t<__self_view>);
22772482
22782483 template <class _CharT2, class _Traits2, class _Allocator2>
22792484 friend inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool
22802485 operator==(const basic_string<_CharT2, _Traits2, _Allocator2>&, const _CharT2*) _NOEXCEPT;
2486
2487 // These functions aren't used anymore but are part of out ABI, so we need to provide them in the dylib for backwards
2488 // compatibility
2489# ifdef _LIBCPP_BUILDING_LIBRARY
2490 void __init(const value_type* __s, size_type __sz, size_type __reserve);
2491# endif
22812492};
22822493
22832494// These declarations must appear before any functions are implicitly used
22842495// so that they have the correct visibility specifier.
2285# define _LIBCPP_DECLARE(...) extern template __VA_ARGS__;
2496# define _LIBCPP_DECLARE(...) extern template _LIBCPP_EXPORTED_FROM_ABI __VA_ARGS__;
22862497# ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
22872498_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char)
22882499# if _LIBCPP_HAS_WIDE_CHARACTERS
......@@ -2309,8 +2520,8 @@ template <class _CharT,
23092520 class _Traits,
23102521 class _Allocator = allocator<_CharT>,
23112522 class = enable_if_t<__is_allocator<_Allocator>::value> >
2312explicit basic_string(basic_string_view<_CharT, _Traits>,
2313 const _Allocator& = _Allocator()) -> basic_string<_CharT, _Traits, _Allocator>;
2523explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
2524 -> basic_string<_CharT, _Traits, _Allocator>;
23142525
23152526template <class _CharT,
23162527 class _Traits,
......@@ -2329,37 +2540,13 @@ basic_string(from_range_t, _Range&&, _Allocator = _Allocator())
23292540 -> basic_string<ranges::range_value_t<_Range>, char_traits<ranges::range_value_t<_Range>>, _Allocator>;
23302541# endif
23312542
2332template <class _CharT, class _Traits, class _Allocator>
2333_LIBCPP_CONSTEXPR_SINCE_CXX20 void
2334basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve) {
2335 if (__libcpp_is_constant_evaluated())
2336 __rep_ = __rep();
2337 if (__reserve > max_size())
2338 __throw_length_error();
2339 pointer __p;
2340 if (__fits_in_sso(__reserve)) {
2341 __set_short_size(__sz);
2342 __p = __get_short_pointer();
2343 } else {
2344 auto __allocation = std::__allocate_at_least(__alloc_, __recommend(__reserve) + 1);
2345 __p = __allocation.ptr;
2346 __begin_lifetime(__p, __allocation.count);
2347 __set_long_pointer(__p);
2348 __set_long_cap(__allocation.count);
2349 __set_long_size(__sz);
2350 }
2351 traits_type::copy(std::__to_address(__p), __s, __sz);
2352 traits_type::assign(__p[__sz], value_type());
2353 __annotate_new(__sz);
2354}
2355
23562543template <class _CharT, class _Traits, class _Allocator>
23572544_LIBCPP_CONSTEXPR_SINCE_CXX20 void
23582545basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz) {
23592546 if (__libcpp_is_constant_evaluated())
23602547 __rep_ = __rep();
23612548 if (__sz > max_size())
2362 __throw_length_error();
2549 this->__throw_length_error();
23632550 pointer __p;
23642551 if (__fits_in_sso(__sz)) {
23652552 __set_short_size(__sz);
......@@ -2389,7 +2576,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(const value
23892576 __set_short_size(__sz);
23902577 } else {
23912578 if (__sz > max_size())
2392 __throw_length_error();
2579 this->__throw_length_error();
23932580 auto __allocation = std::__allocate_at_least(__alloc_, __recommend(__sz) + 1);
23942581 __p = __allocation.ptr;
23952582 __begin_lifetime(__p, __allocation.count);
......@@ -2407,7 +2594,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
24072594 __rep_ = __rep();
24082595
24092596 if (__n > max_size())
2410 __throw_length_error();
2597 this->__throw_length_error();
24112598 pointer __p;
24122599 if (__fits_in_sso(__n)) {
24132600 __set_short_size(__n);
......@@ -2470,7 +2657,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init_with_size(_InputIterator __fir
24702657 __rep_ = __rep();
24712658
24722659 if (__sz > max_size())
2473 __throw_length_error();
2660 this->__throw_length_error();
24742661
24752662 pointer __p;
24762663 if (__fits_in_sso(__sz)) {
......@@ -2511,11 +2698,11 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
25112698 size_type __n_add,
25122699 const value_type* __p_new_stuff) {
25132700 size_type __ms = max_size();
2514 if (__delta_cap > __ms - __old_cap - 1)
2701 if (__delta_cap > __ms - __old_cap)
25152702 __throw_length_error();
25162703 pointer __old_p = __get_pointer();
25172704 size_type __cap =
2518 __old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1;
2705 __old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms;
25192706 __annotate_delete();
25202707 auto __guard = std::__make_scope_guard(__annotate_new_size(*this));
25212708 auto __allocation = std::__allocate_at_least(__alloc_, __cap + 1);
......@@ -2555,10 +2742,10 @@ _LIBCPP_DEPRECATED_("use __grow_by_without_replace") basic_string<_CharT, _Trait
25552742 size_type __n_add) {
25562743 size_type __ms = max_size();
25572744 if (__delta_cap > __ms - __old_cap)
2558 __throw_length_error();
2745 this->__throw_length_error();
25592746 pointer __old_p = __get_pointer();
25602747 size_type __cap =
2561 __old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms - 1;
2748 __old_cap < __ms / 2 - __alignment ? __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : __ms;
25622749 auto __allocation = std::__allocate_at_least(__alloc_, __cap + 1);
25632750 pointer __p = __allocation.ptr;
25642751 __begin_lifetime(__p, __allocation.count);
......@@ -2597,20 +2784,25 @@ template <class _CharT, class _Traits, class _Allocator>
25972784template <bool __is_short>
25982785_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NOINLINE basic_string<_CharT, _Traits, _Allocator>&
25992786basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias(const value_type* __s, size_type __n) {
2600 size_type __cap = __is_short ? static_cast<size_type>(__min_cap) : __get_long_cap();
2787 const auto __cap = __is_short ? static_cast<size_type>(__min_cap) : __get_long_cap();
2788 const auto __size = __is_short ? __get_short_size() : __get_long_size();
26012789 if (__n < __cap) {
2602 size_type __old_size = __is_short ? __get_short_size() : __get_long_size();
2603 if (__n > __old_size)
2604 __annotate_increase(__n - __old_size);
2605 pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer();
2606 __is_short ? __set_short_size(__n) : __set_long_size(__n);
2790 if (__n > __size)
2791 __annotate_increase(__n - __size);
2792 pointer __p;
2793 if (__is_short) {
2794 __p = __get_short_pointer();
2795 __set_short_size(__n);
2796 } else {
2797 __p = __get_long_pointer();
2798 __set_long_size(__n);
2799 }
26072800 traits_type::copy(std::__to_address(__p), __s, __n);
26082801 traits_type::assign(__p[__n], value_type());
2609 if (__old_size > __n)
2610 __annotate_shrink(__old_size);
2802 if (__size > __n)
2803 __annotate_shrink(__size);
26112804 } else {
2612 size_type __sz = __is_short ? __get_short_size() : __get_long_size();
2613 __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s);
2805 __grow_by_and_replace(__cap - 1, __n - __cap + 1, __size, 0, __size, __n, __s);
26142806 }
26152807 return *this;
26162808}
......@@ -2618,17 +2810,16 @@ basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias(const value_type* _
26182810template <class _CharT, class _Traits, class _Allocator>
26192811_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NOINLINE basic_string<_CharT, _Traits, _Allocator>&
26202812basic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s, size_type __n) {
2621 size_type __cap = capacity();
2813 const auto __cap = capacity();
2814 const auto __size = size();
26222815 if (__cap >= __n) {
2623 size_type __old_size = size();
2624 if (__n > __old_size)
2625 __annotate_increase(__n - __old_size);
2816 if (__n > __size)
2817 __annotate_increase(__n - __size);
26262818 value_type* __p = std::__to_address(__get_pointer());
26272819 traits_type::move(__p, __s, __n);
26282820 return __null_terminate_at(__p, __n);
26292821 } else {
2630 size_type __sz = size();
2631 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2822 __grow_by_and_replace(__cap, __n - __cap, __size, 0, __size, __n, __s);
26322823 return *this;
26332824 }
26342825}
......@@ -2646,8 +2837,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
26462837 size_type __cap = capacity();
26472838 size_type __old_size = size();
26482839 if (__cap < __n) {
2649 size_type __sz = size();
2650 __grow_by_without_replace(__cap, __n - __cap, __sz, 0, __sz);
2840 __grow_by_without_replace(__cap, __n - __cap, __old_size, 0, __old_size);
26512841 __annotate_increase(__n);
26522842 } else if (__n > __old_size)
26532843 __annotate_increase(__n - __old_size);
......@@ -2659,10 +2849,10 @@ basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
26592849template <class _CharT, class _Traits, class _Allocator>
26602850_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
26612851basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c) {
2662 pointer __p;
26632852 size_type __old_size = size();
26642853 if (__old_size == 0)
26652854 __annotate_increase(1);
2855 pointer __p;
26662856 if (__is_long()) {
26672857 __p = __get_long_pointer();
26682858 __set_long_size(1);
......@@ -2680,23 +2870,21 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c) {
26802870template <class _CharT, class _Traits, class _Allocator>
26812871_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS basic_string<_CharT, _Traits, _Allocator>&
26822872basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) {
2683 if (this != std::addressof(__str)) {
2684 __copy_assign_alloc(__str);
2685 if (!__is_long()) {
2686 if (!__str.__is_long()) {
2687 size_type __old_size = __get_short_size();
2688 if (__get_short_size() < __str.__get_short_size())
2689 __annotate_increase(__str.__get_short_size() - __get_short_size());
2690 __rep_ = __str.__rep_;
2691 if (__old_size > __get_short_size())
2692 __annotate_shrink(__old_size);
2693 } else {
2694 return __assign_no_alias<true>(__str.data(), __str.size());
2695 }
2696 } else {
2697 return __assign_no_alias<false>(__str.data(), __str.size());
2698 }
2699 }
2873 if (this == std::addressof(__str))
2874 return *this;
2875
2876 __copy_assign_alloc(__str);
2877
2878 if (__is_long())
2879 return __assign_no_alias<false>(__str.data(), __str.size());
2880
2881 if (__str.__is_long())
2882 return __assign_no_alias<true>(__str.data(), __str.size());
2883
2884 __annotate_delete();
2885 auto __guard = std::__make_scope_guard(__annotate_new_size(*this));
2886 __rep_ = __str.__rep_;
2887
27002888 return *this;
27012889}
27022890
......@@ -2760,14 +2948,6 @@ basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, tr
27602948
27612949# endif
27622950
2763template <class _CharT, class _Traits, class _Allocator>
2764template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
2765_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
2766basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last) {
2767 __assign_with_sentinel(__first, __last);
2768 return *this;
2769}
2770
27712951template <class _CharT, class _Traits, class _Allocator>
27722952template <class _InputIterator, class _Sentinel>
27732953_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
......@@ -2776,20 +2956,6 @@ basic_string<_CharT, _Traits, _Allocator>::__assign_with_sentinel(_InputIterator
27762956 assign(__temp.data(), __temp.size());
27772957}
27782958
2779template <class _CharT, class _Traits, class _Allocator>
2780template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
2781_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
2782basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) {
2783 if (__string_is_trivial_iterator<_ForwardIterator>::value) {
2784 size_type __n = static_cast<size_type>(std::distance(__first, __last));
2785 __assign_trivial(__first, __last, __n);
2786 } else {
2787 __assign_with_sentinel(__first, __last);
2788 }
2789
2790 return *this;
2791}
2792
27932959template <class _CharT, class _Traits, class _Allocator>
27942960template <class _Iterator, class _Sentinel>
27952961_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
......@@ -2825,24 +2991,10 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
28252991basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n) {
28262992 size_type __sz = __str.size();
28272993 if (__pos > __sz)
2828 __throw_out_of_range();
2994 this->__throw_out_of_range();
28292995 return assign(__str.data() + __pos, std::min(__n, __sz - __pos));
28302996}
28312997
2832template <class _CharT, class _Traits, class _Allocator>
2833template <class _Tp,
2834 __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
2835 !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
2836 int> >
2837_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
2838basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp& __t, size_type __pos, size_type __n) {
2839 __self_view __sv = __t;
2840 size_type __sz = __sv.size();
2841 if (__pos > __sz)
2842 __throw_out_of_range();
2843 return assign(__sv.data() + __pos, std::min(__n, __sz - __pos));
2844}
2845
28462998template <class _CharT, class _Traits, class _Allocator>
28472999_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_NOINLINE basic_string<_CharT, _Traits, _Allocator>&
28483000basic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s) {
......@@ -2853,10 +3005,9 @@ template <class _CharT, class _Traits, class _Allocator>
28533005_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
28543006basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s) {
28553007 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::assign received nullptr");
2856 return __builtin_constant_p(*__s)
2857 ? (__fits_in_sso(traits_type::length(__s)) ? __assign_short(__s, traits_type::length(__s))
2858 : __assign_external(__s, traits_type::length(__s)))
2859 : __assign_external(__s);
3008 if (auto __len = traits_type::length(__s); __builtin_constant_p(__len) && __fits_in_sso(__len))
3009 return __assign_short(__s, __len);
3010 return __assign_external(__s);
28603011}
28613012// append
28623013
......@@ -2928,11 +3079,10 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::pu
29283079 }
29293080 if (__sz == __cap) {
29303081 __grow_by_without_replace(__cap, 1, __sz, __sz, 0);
2931 __annotate_increase(1);
29323082 __is_short = false; // the string is always long after __grow_by
2933 } else
2934 __annotate_increase(1);
2935 pointer __p = __get_pointer();
3083 }
3084 __annotate_increase(1);
3085 pointer __p;
29363086 if (__is_short) {
29373087 __p = __get_short_pointer() + __sz;
29383088 __set_short_size(__sz + 1);
......@@ -2944,52 +3094,15 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::pu
29443094 traits_type::assign(*++__p, value_type());
29453095}
29463096
2947template <class _CharT, class _Traits, class _Allocator>
2948template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
2949_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
2950basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last) {
2951 size_type __sz = size();
2952 size_type __cap = capacity();
2953 size_type __n = static_cast<size_type>(std::distance(__first, __last));
2954 if (__n) {
2955 if (__string_is_trivial_iterator<_ForwardIterator>::value && !__addr_in_range(*__first)) {
2956 if (__cap - __sz < __n)
2957 __grow_by_without_replace(__cap, __sz + __n - __cap, __sz, __sz, 0);
2958 __annotate_increase(__n);
2959 auto __end = __copy_non_overlapping_range(__first, __last, std::__to_address(__get_pointer() + __sz));
2960 traits_type::assign(*__end, value_type());
2961 __set_size(__sz + __n);
2962 } else {
2963 const basic_string __temp(__first, __last, __alloc_);
2964 append(__temp.data(), __temp.size());
2965 }
2966 }
2967 return *this;
2968}
2969
29703097template <class _CharT, class _Traits, class _Allocator>
29713098_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
29723099basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n) {
29733100 size_type __sz = __str.size();
29743101 if (__pos > __sz)
2975 __throw_out_of_range();
3102 this->__throw_out_of_range();
29763103 return append(__str.data() + __pos, std::min(__n, __sz - __pos));
29773104}
29783105
2979template <class _CharT, class _Traits, class _Allocator>
2980template <class _Tp,
2981 __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
2982 !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
2983 int> >
2984_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
2985basic_string<_CharT, _Traits, _Allocator>::append(const _Tp& __t, size_type __pos, size_type __n) {
2986 __self_view __sv = __t;
2987 size_type __sz = __sv.size();
2988 if (__pos > __sz)
2989 __throw_out_of_range();
2990 return append(__sv.data() + __pos, std::min(__n, __sz - __pos));
2991}
2992
29933106template <class _CharT, class _Traits, class _Allocator>
29943107_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
29953108basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s) {
......@@ -3005,7 +3118,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_t
30053118 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::insert received nullptr");
30063119 size_type __sz = size();
30073120 if (__pos > __sz)
3008 __throw_out_of_range();
3121 this->__throw_out_of_range();
30093122 size_type __cap = capacity();
30103123 if (__cap - __sz >= __n) {
30113124 if (__n) {
......@@ -3032,7 +3145,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
30323145basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c) {
30333146 size_type __sz = size();
30343147 if (__pos > __sz)
3035 __throw_out_of_range();
3148 this->__throw_out_of_range();
30363149 if (__n) {
30373150 size_type __cap = capacity();
30383151 value_type* __p;
......@@ -3054,23 +3167,6 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n
30543167 return *this;
30553168}
30563169
3057template <class _CharT, class _Traits, class _Allocator>
3058template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
3059_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::iterator
3060basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last) {
3061 const basic_string __temp(__first, __last, __alloc_);
3062 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
3063}
3064
3065template <class _CharT, class _Traits, class _Allocator>
3066template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
3067_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::iterator
3068basic_string<_CharT, _Traits, _Allocator>::insert(
3069 const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last) {
3070 auto __n = static_cast<size_type>(std::distance(__first, __last));
3071 return __insert_with_size(__pos, __first, __last, __n);
3072}
3073
30743170template <class _CharT, class _Traits, class _Allocator>
30753171template <class _Iterator, class _Sentinel>
30763172_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::iterator
......@@ -3094,24 +3190,10 @@ basic_string<_CharT, _Traits, _Allocator>::insert(
30943190 size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n) {
30953191 size_type __str_sz = __str.size();
30963192 if (__pos2 > __str_sz)
3097 __throw_out_of_range();
3193 this->__throw_out_of_range();
30983194 return insert(__pos1, __str.data() + __pos2, std::min(__n, __str_sz - __pos2));
30993195}
31003196
3101template <class _CharT, class _Traits, class _Allocator>
3102template <class _Tp,
3103 __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
3104 !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
3105 int> >
3106_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
3107basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n) {
3108 __self_view __sv = __t;
3109 size_type __str_sz = __sv.size();
3110 if (__pos2 > __str_sz)
3111 __throw_out_of_range();
3112 return insert(__pos1, __sv.data() + __pos2, std::min(__n, __str_sz - __pos2));
3113}
3114
31153197template <class _CharT, class _Traits, class _Allocator>
31163198_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
31173199basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s) {
......@@ -3152,7 +3234,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(
31523234 _LIBCPP_ASSERT_NON_NULL(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
31533235 size_type __sz = size();
31543236 if (__pos > __sz)
3155 __throw_out_of_range();
3237 this->__throw_out_of_range();
31563238 __n1 = std::min(__n1, __sz - __pos);
31573239 size_type __cap = capacity();
31583240 if (__cap - __sz + __n1 >= __n2) {
......@@ -3194,7 +3276,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
31943276basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c) {
31953277 size_type __sz = size();
31963278 if (__pos > __sz)
3197 __throw_out_of_range();
3279 this->__throw_out_of_range();
31983280 __n1 = std::min(__n1, __sz - __pos);
31993281 size_type __cap = capacity();
32003282 value_type* __p;
......@@ -3215,40 +3297,16 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
32153297 return __null_terminate_at(__p, __sz - (__n1 - __n2));
32163298}
32173299
3218template <class _CharT, class _Traits, class _Allocator>
3219template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> >
3220_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
3221basic_string<_CharT, _Traits, _Allocator>::replace(
3222 const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2) {
3223 const basic_string __temp(__j1, __j2, __alloc_);
3224 return replace(__i1, __i2, __temp);
3225}
3226
32273300template <class _CharT, class _Traits, class _Allocator>
32283301_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
32293302basic_string<_CharT, _Traits, _Allocator>::replace(
32303303 size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2) {
32313304 size_type __str_sz = __str.size();
32323305 if (__pos2 > __str_sz)
3233 __throw_out_of_range();
3306 this->__throw_out_of_range();
32343307 return replace(__pos1, __n1, __str.data() + __pos2, std::min(__n2, __str_sz - __pos2));
32353308}
32363309
3237template <class _CharT, class _Traits, class _Allocator>
3238template <class _Tp,
3239 __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
3240 !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
3241 int> >
3242_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
3243basic_string<_CharT, _Traits, _Allocator>::replace(
3244 size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2) {
3245 __self_view __sv = __t;
3246 size_type __str_sz = __sv.size();
3247 if (__pos2 > __str_sz)
3248 __throw_out_of_range();
3249 return replace(__pos1, __n1, __sv.data() + __pos2, std::min(__n2, __str_sz - __pos2));
3250}
3251
32523310template <class _CharT, class _Traits, class _Allocator>
32533311_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
32543312basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s) {
......@@ -3278,7 +3336,7 @@ template <class _CharT, class _Traits, class _Allocator>
32783336_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>&
32793337basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n) {
32803338 if (__pos > size())
3281 __throw_out_of_range();
3339 this->__throw_out_of_range();
32823340 if (__n == npos) {
32833341 __erase_to_end(__pos);
32843342 } else {
......@@ -3316,11 +3374,13 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocat
33163374
33173375template <class _CharT, class _Traits, class _Allocator>
33183376inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT {
3319 size_type __old_size = size();
3377 size_type __old_size;
33203378 if (__is_long()) {
3379 __old_size = __get_long_size();
33213380 traits_type::assign(*__get_long_pointer(), value_type());
33223381 __set_long_size(0);
33233382 } else {
3383 __old_size = __get_short_size();
33243384 traits_type::assign(*__get_short_pointer(), value_type());
33253385 __set_short_size(0);
33263386 }
......@@ -3349,7 +3409,7 @@ basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
33493409template <class _CharT, class _Traits, class _Allocator>
33503410_LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity) {
33513411 if (__requested_capacity > max_size())
3352 __throw_length_error();
3412 this->__throw_length_error();
33533413
33543414 // Make sure reserve(n) never shrinks. This is technically only required in C++20
33553415 // and later (since P0966R1), however we provide consistent behavior in all Standard
......@@ -3357,7 +3417,16 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::re
33573417 if (__requested_capacity <= capacity())
33583418 return;
33593419
3360 __shrink_or_extend(__recommend(__requested_capacity));
3420 __annotation_guard __g(*this);
3421 auto __allocation = std::__allocate_at_least(__alloc_, __recommend(__requested_capacity) + 1);
3422 auto __size = size();
3423 __begin_lifetime(__allocation.ptr, __allocation.count);
3424 traits_type::copy(std::__to_address(__allocation.ptr), data(), __size + 1);
3425 if (__is_long())
3426 __alloc_traits::deallocate(__alloc_, __get_long_pointer(), __get_long_cap());
3427 __set_long_cap(__allocation.count);
3428 __set_long_size(__size);
3429 __set_long_pointer(__allocation.ptr);
33613430}
33623431
33633432template <class _CharT, class _Traits, class _Allocator>
......@@ -3366,76 +3435,52 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocat
33663435 if (__target_capacity == capacity())
33673436 return;
33683437
3369 __shrink_or_extend(__target_capacity);
3370}
3438 _LIBCPP_ASSERT_INTERNAL(__is_long(), "Trying to shrink small string");
33713439
3372template <class _CharT, class _Traits, class _Allocator>
3373inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void
3374basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity) {
3375 __annotate_delete();
3376 auto __guard = std::__make_scope_guard(__annotate_new_size(*this));
3377 size_type __cap = capacity();
3378 size_type __sz = size();
3440 // We're a long string and we're shrinking into the small buffer.
3441 const auto __ptr = __get_long_pointer();
3442 const auto __size = __get_long_size();
3443 const auto __cap = __get_long_cap();
33793444
3380 pointer __new_data, __p;
3381 bool __was_long, __now_long;
33823445 if (__fits_in_sso(__target_capacity)) {
3383 __was_long = true;
3384 __now_long = false;
3385 __new_data = __get_short_pointer();
3386 __p = __get_long_pointer();
3387 } else {
3388 if (__target_capacity > __cap) {
3389 // Extend
3390 // - called from reserve should propagate the exception thrown.
3391 auto __allocation = std::__allocate_at_least(__alloc_, __target_capacity + 1);
3392 __new_data = __allocation.ptr;
3393 __target_capacity = __allocation.count - 1;
3394 } else {
3395 // Shrink
3396 // - called from shrink_to_fit should not throw.
3397 // - called from reserve may throw but is not required to.
3446 __annotation_guard __g(*this);
3447 __set_short_size(__size);
3448 traits_type::copy(std::__to_address(__get_short_pointer()), std::__to_address(__ptr), __size + 1);
3449 __alloc_traits::deallocate(__alloc_, __ptr, __cap);
3450 return;
3451 }
3452
33983453# if _LIBCPP_HAS_EXCEPTIONS
3399 try {
3454 try {
34003455# endif // _LIBCPP_HAS_EXCEPTIONS
3401 auto __allocation = std::__allocate_at_least(__alloc_, __target_capacity + 1);
3402
3403 // The Standard mandates shrink_to_fit() does not increase the capacity.
3404 // With equal capacity keep the existing buffer. This avoids extra work
3405 // due to swapping the elements.
3406 if (__allocation.count - 1 > capacity()) {
3407 __alloc_traits::deallocate(__alloc_, __allocation.ptr, __allocation.count);
3408 return;
3409 }
3410 __new_data = __allocation.ptr;
3411 __target_capacity = __allocation.count - 1;
3456 __annotation_guard __g(*this);
3457 auto __allocation = std::__allocate_at_least(__alloc_, __target_capacity + 1);
3458
3459 // The Standard mandates shrink_to_fit() does not increase the capacity.
3460 // With equal capacity keep the existing buffer. This avoids extra work
3461 // due to swapping the elements.
3462 if (__allocation.count - 1 >= capacity()) {
3463 __alloc_traits::deallocate(__alloc_, __allocation.ptr, __allocation.count);
3464 return;
3465 }
3466
3467 __begin_lifetime(__allocation.ptr, __allocation.count);
3468 traits_type::copy(std::__to_address(__allocation.ptr), std::__to_address(__ptr), __size + 1);
3469 __alloc_traits::deallocate(__alloc_, __ptr, __cap);
3470 __set_long_cap(__allocation.count);
3471 __set_long_pointer(__allocation.ptr);
34123472# if _LIBCPP_HAS_EXCEPTIONS
3413 } catch (...) {
3414 return;
3415 }
3473 } catch (...) {
3474 return;
3475 }
34163476# endif // _LIBCPP_HAS_EXCEPTIONS
3417 }
3418 __begin_lifetime(__new_data, __target_capacity + 1);
3419 __now_long = true;
3420 __was_long = __is_long();
3421 __p = __get_pointer();
3422 }
3423 traits_type::copy(std::__to_address(__new_data), std::__to_address(__p), size() + 1);
3424 if (__was_long)
3425 __alloc_traits::deallocate(__alloc_, __p, __cap + 1);
3426 if (__now_long) {
3427 __set_long_cap(__target_capacity + 1);
3428 __set_long_size(__sz);
3429 __set_long_pointer(__new_data);
3430 } else
3431 __set_short_size(__sz);
34323477}
34333478
34343479template <class _CharT, class _Traits, class _Allocator>
34353480_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
34363481basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const {
34373482 if (__n >= size())
3438 __throw_out_of_range();
3483 this->__throw_out_of_range();
34393484 return (*this)[__n];
34403485}
34413486
......@@ -3443,7 +3488,7 @@ template <class _CharT, class _Traits, class _Allocator>
34433488_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::reference
34443489basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) {
34453490 if (__n >= size())
3446 __throw_out_of_range();
3491 this->__throw_out_of_range();
34473492 return (*this)[__n];
34483493}
34493494
......@@ -3452,7 +3497,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>
34523497basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const {
34533498 size_type __sz = size();
34543499 if (__pos > __sz)
3455 __throw_out_of_range();
3500 this->__throw_out_of_range();
34563501 size_type __rlen = std::min(__n, __sz - __pos);
34573502 traits_type::copy(__s, data() + __pos, __rlen);
34583503 return __rlen;
......@@ -3482,274 +3527,15 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocat
34823527 __str.__annotate_new(__str.__get_short_size());
34833528}
34843529
3485// find
3486
3487template <class _CharT, class _Traits, class _Allocator>
3488_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3489basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
3490 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::find(): received nullptr");
3491 return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
3492}
3493
3494template <class _CharT, class _Traits, class _Allocator>
3495inline _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3496basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str, size_type __pos) const _NOEXCEPT {
3497 return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __str.data(), __pos, __str.size());
3498}
3499
3500template <class _CharT, class _Traits, class _Allocator>
3501template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> >
3502_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3503basic_string<_CharT, _Traits, _Allocator>::find(const _Tp& __t, size_type __pos) const _NOEXCEPT {
3504 __self_view __sv = __t;
3505 return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __sv.data(), __pos, __sv.size());
3506}
3507
3508template <class _CharT, class _Traits, class _Allocator>
3509inline _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3510basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, size_type __pos) const _NOEXCEPT {
3511 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::find(): received nullptr");
3512 return std::__str_find<value_type, size_type, traits_type, npos>(
3513 data(), size(), __s, __pos, traits_type::length(__s));
3514}
3515
3516template <class _CharT, class _Traits, class _Allocator>
3517_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3518basic_string<_CharT, _Traits, _Allocator>::find(value_type __c, size_type __pos) const _NOEXCEPT {
3519 return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
3520}
3521
3522// rfind
3523
3524template <class _CharT, class _Traits, class _Allocator>
3525_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3526basic_string<_CharT, _Traits, _Allocator>::rfind(
3527 const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
3528 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
3529 return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
3530}
3531
3532template <class _CharT, class _Traits, class _Allocator>
3533inline _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3534basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str, size_type __pos) const _NOEXCEPT {
3535 return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __str.data(), __pos, __str.size());
3536}
3537
3538template <class _CharT, class _Traits, class _Allocator>
3539template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> >
3540_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3541basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t, size_type __pos) const _NOEXCEPT {
3542 __self_view __sv = __t;
3543 return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __sv.data(), __pos, __sv.size());
3544}
3545
3546template <class _CharT, class _Traits, class _Allocator>
3547inline _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3548basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, size_type __pos) const _NOEXCEPT {
3549 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::rfind(): received nullptr");
3550 return std::__str_rfind<value_type, size_type, traits_type, npos>(
3551 data(), size(), __s, __pos, traits_type::length(__s));
3552}
3553
3554template <class _CharT, class _Traits, class _Allocator>
3555_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3556basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c, size_type __pos) const _NOEXCEPT {
3557 return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
3558}
3559
3560// find_first_of
3561
3562template <class _CharT, class _Traits, class _Allocator>
3563_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3564basic_string<_CharT, _Traits, _Allocator>::find_first_of(
3565 const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
3566 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
3567 return std::__str_find_first_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
3568}
3569
3570template <class _CharT, class _Traits, class _Allocator>
3571inline _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3572basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str, size_type __pos) const _NOEXCEPT {
3573 return std::__str_find_first_of<value_type, size_type, traits_type, npos>(
3574 data(), size(), __str.data(), __pos, __str.size());
3575}
3576
3577template <class _CharT, class _Traits, class _Allocator>
3578template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> >
3579_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3580basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t, size_type __pos) const _NOEXCEPT {
3581 __self_view __sv = __t;
3582 return std::__str_find_first_of<value_type, size_type, traits_type, npos>(
3583 data(), size(), __sv.data(), __pos, __sv.size());
3584}
3585
3586template <class _CharT, class _Traits, class _Allocator>
3587inline _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3588basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, size_type __pos) const _NOEXCEPT {
3589 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::find_first_of(): received nullptr");
3590 return std::__str_find_first_of<value_type, size_type, traits_type, npos>(
3591 data(), size(), __s, __pos, traits_type::length(__s));
3592}
3593
3594template <class _CharT, class _Traits, class _Allocator>
3595inline _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3596basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c, size_type __pos) const _NOEXCEPT {
3597 return find(__c, __pos);
3598}
3599
3600// find_last_of
3601
3602template <class _CharT, class _Traits, class _Allocator>
3603inline _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3604basic_string<_CharT, _Traits, _Allocator>::find_last_of(
3605 const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
3606 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
3607 return std::__str_find_last_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
3608}
3609
3610template <class _CharT, class _Traits, class _Allocator>
3611inline _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3612basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str, size_type __pos) const _NOEXCEPT {
3613 return std::__str_find_last_of<value_type, size_type, traits_type, npos>(
3614 data(), size(), __str.data(), __pos, __str.size());
3615}
3616
3617template <class _CharT, class _Traits, class _Allocator>
3618template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> >
3619_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3620basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t, size_type __pos) const _NOEXCEPT {
3621 __self_view __sv = __t;
3622 return std::__str_find_last_of<value_type, size_type, traits_type, npos>(
3623 data(), size(), __sv.data(), __pos, __sv.size());
3624}
3625
3626template <class _CharT, class _Traits, class _Allocator>
3627inline _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3628basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, size_type __pos) const _NOEXCEPT {
3629 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::find_last_of(): received nullptr");
3630 return std::__str_find_last_of<value_type, size_type, traits_type, npos>(
3631 data(), size(), __s, __pos, traits_type::length(__s));
3632}
3633
3634template <class _CharT, class _Traits, class _Allocator>
3635inline _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3636basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c, size_type __pos) const _NOEXCEPT {
3637 return rfind(__c, __pos);
3638}
3639
3640// find_first_not_of
3641
3642template <class _CharT, class _Traits, class _Allocator>
3643_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3644basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(
3645 const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
3646 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
3647 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
3648}
3649
3650template <class _CharT, class _Traits, class _Allocator>
3651inline _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3652basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(
3653 const basic_string& __str, size_type __pos) const _NOEXCEPT {
3654 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(
3655 data(), size(), __str.data(), __pos, __str.size());
3656}
3657
3658template <class _CharT, class _Traits, class _Allocator>
3659template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> >
3660_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3661basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t, size_type __pos) const _NOEXCEPT {
3662 __self_view __sv = __t;
3663 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(
3664 data(), size(), __sv.data(), __pos, __sv.size());
3665}
3666
3667template <class _CharT, class _Traits, class _Allocator>
3668inline _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3669basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s, size_type __pos) const _NOEXCEPT {
3670 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::find_first_not_of(): received nullptr");
3671 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(
3672 data(), size(), __s, __pos, traits_type::length(__s));
3673}
3674
3675template <class _CharT, class _Traits, class _Allocator>
3676inline _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3677basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c, size_type __pos) const _NOEXCEPT {
3678 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
3679}
3680
3681// find_last_not_of
3682
3683template <class _CharT, class _Traits, class _Allocator>
3684_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3685basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(
3686 const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
3687 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
3688 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
3689}
3690
3691template <class _CharT, class _Traits, class _Allocator>
3692inline _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3693basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(
3694 const basic_string& __str, size_type __pos) const _NOEXCEPT {
3695 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(
3696 data(), size(), __str.data(), __pos, __str.size());
3697}
3698
3699template <class _CharT, class _Traits, class _Allocator>
3700template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> >
3701_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3702basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t, size_type __pos) const _NOEXCEPT {
3703 __self_view __sv = __t;
3704 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(
3705 data(), size(), __sv.data(), __pos, __sv.size());
3706}
3707
3708template <class _CharT, class _Traits, class _Allocator>
3709inline _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3710basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s, size_type __pos) const _NOEXCEPT {
3711 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::find_last_not_of(): received nullptr");
3712 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(
3713 data(), size(), __s, __pos, traits_type::length(__s));
3714}
3715
3716template <class _CharT, class _Traits, class _Allocator>
3717inline _LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3718basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c, size_type __pos) const _NOEXCEPT {
3719 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
3720}
3721
37223530// compare
37233531
3724template <class _CharT, class _Traits, class _Allocator>
3725template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> >
3726_LIBCPP_CONSTEXPR_SINCE_CXX20 int basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const _NOEXCEPT {
3727 __self_view __sv = __t;
3728 size_t __lhs_sz = size();
3729 size_t __rhs_sz = __sv.size();
3730 int __result = traits_type::compare(data(), __sv.data(), std::min(__lhs_sz, __rhs_sz));
3731 if (__result != 0)
3732 return __result;
3733 if (__lhs_sz < __rhs_sz)
3734 return -1;
3735 if (__lhs_sz > __rhs_sz)
3736 return 1;
3737 return 0;
3738}
3739
3740template <class _CharT, class _Traits, class _Allocator>
3741inline _LIBCPP_CONSTEXPR_SINCE_CXX20 int
3742basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT {
3743 return compare(__self_view(__str));
3744}
3745
37463532template <class _CharT, class _Traits, class _Allocator>
37473533inline _LIBCPP_CONSTEXPR_SINCE_CXX20 int basic_string<_CharT, _Traits, _Allocator>::compare(
37483534 size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const {
37493535 _LIBCPP_ASSERT_NON_NULL(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
37503536 size_type __sz = size();
37513537 if (__pos1 > __sz || __n2 == npos)
3752 __throw_out_of_range();
3538 this->__throw_out_of_range();
37533539 size_type __rlen = std::min(__n1, __sz - __pos1);
37543540 int __r = traits_type::compare(data() + __pos1, __s, std::min(__rlen, __n2));
37553541 if (__r == 0) {
......@@ -3761,51 +3547,6 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20 int basic_string<_CharT, _Traits, _Allocato
37613547 return __r;
37623548}
37633549
3764template <class _CharT, class _Traits, class _Allocator>
3765template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> >
3766_LIBCPP_CONSTEXPR_SINCE_CXX20 int
3767basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, size_type __n1, const _Tp& __t) const {
3768 __self_view __sv = __t;
3769 return compare(__pos1, __n1, __sv.data(), __sv.size());
3770}
3771
3772template <class _CharT, class _Traits, class _Allocator>
3773inline _LIBCPP_CONSTEXPR_SINCE_CXX20 int
3774basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, size_type __n1, const basic_string& __str) const {
3775 return compare(__pos1, __n1, __str.data(), __str.size());
3776}
3777
3778template <class _CharT, class _Traits, class _Allocator>
3779template <class _Tp,
3780 __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
3781 !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
3782 int> >
3783_LIBCPP_CONSTEXPR_SINCE_CXX20 int basic_string<_CharT, _Traits, _Allocator>::compare(
3784 size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2) const {
3785 __self_view __sv = __t;
3786 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3787}
3788
3789template <class _CharT, class _Traits, class _Allocator>
3790_LIBCPP_CONSTEXPR_SINCE_CXX20 int basic_string<_CharT, _Traits, _Allocator>::compare(
3791 size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2) const {
3792 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3793}
3794
3795template <class _CharT, class _Traits, class _Allocator>
3796_LIBCPP_CONSTEXPR_SINCE_CXX20 int
3797basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT {
3798 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::compare(): received nullptr");
3799 return compare(0, npos, __s, traits_type::length(__s));
3800}
3801
3802template <class _CharT, class _Traits, class _Allocator>
3803_LIBCPP_CONSTEXPR_SINCE_CXX20 int
3804basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, size_type __n1, const value_type* __s) const {
3805 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::compare(): received nullptr");
3806 return compare(__pos1, __n1, __s, traits_type::length(__s));
3807}
3808
38093550// __invariants
38103551
38113552template <class _CharT, class _Traits, class _Allocator>
......@@ -3821,18 +3562,6 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20 bool basic_string<_CharT, _Traits, _Allocat
38213562 return true;
38223563}
38233564
3824// __clear_and_shrink
3825
3826template <class _CharT, class _Traits, class _Allocator>
3827inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT {
3828 clear();
3829 if (__is_long()) {
3830 __annotate_delete();
3831 __alloc_traits::deallocate(__alloc_, __get_long_pointer(), capacity() + 1);
3832 __rep_ = __rep();
3833 }
3834}
3835
38363565// operator==
38373566
38383567template <class _CharT, class _Traits, class _Allocator>
......@@ -3987,83 +3716,73 @@ operator>=(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>&
39873716
39883717template <class _CharT, class _Traits, class _Allocator>
39893718_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>
3990operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3991 const basic_string<_CharT, _Traits, _Allocator>& __rhs) {
3719__concatenate_strings(const _Allocator& __alloc,
3720 __type_identity_t<basic_string_view<_CharT, _Traits> > __str1,
3721 __type_identity_t<basic_string_view<_CharT, _Traits> > __str2) {
39923722 using _String = basic_string<_CharT, _Traits, _Allocator>;
3993 auto __lhs_sz = __lhs.size();
3994 auto __rhs_sz = __rhs.size();
39953723 _String __r(__uninitialized_size_tag(),
3996 __lhs_sz + __rhs_sz,
3997 _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
3724 __str1.size() + __str2.size(),
3725 _String::__alloc_traits::select_on_container_copy_construction(__alloc));
39983726 auto __ptr = std::__to_address(__r.__get_pointer());
3999 _Traits::copy(__ptr, __lhs.data(), __lhs_sz);
4000 _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz);
4001 _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT());
3727 _Traits::copy(__ptr, __str1.data(), __str1.size());
3728 _Traits::copy(__ptr + __str1.size(), __str2.data(), __str2.size());
3729 _Traits::assign(__ptr[__str1.size() + __str2.size()], _CharT());
40023730 return __r;
40033731}
40043732
3733template <class _CharT, class _Traits, class _Allocator>
3734_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>
3735operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3736 const basic_string<_CharT, _Traits, _Allocator>& __rhs) {
3737 return std::__concatenate_strings<_CharT, _Traits>(__lhs.get_allocator(), __lhs, __rhs);
3738}
3739
40053740template <class _CharT, class _Traits, class _Allocator>
40063741_LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>
40073742operator+(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) {
4008 using _String = basic_string<_CharT, _Traits, _Allocator>;
4009 auto __lhs_sz = _Traits::length(__lhs);
4010 auto __rhs_sz = __rhs.size();
4011 _String __r(__uninitialized_size_tag(),
4012 __lhs_sz + __rhs_sz,
4013 _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator()));
4014 auto __ptr = std::__to_address(__r.__get_pointer());
4015 _Traits::copy(__ptr, __lhs, __lhs_sz);
4016 _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz);
4017 _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT());
4018 return __r;
3743 return std::__concatenate_strings<_CharT, _Traits>(__rhs.get_allocator(), __lhs, __rhs);
40193744}
40203745
3746extern template _LIBCPP_EXPORTED_FROM_ABI string operator+
3747 <char, char_traits<char>, allocator<char> >(char const*, string const&);
3748
40213749template <class _CharT, class _Traits, class _Allocator>
40223750_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>
40233751operator+(_CharT __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) {
4024 using _String = basic_string<_CharT, _Traits, _Allocator>;
4025 typename _String::size_type __rhs_sz = __rhs.size();
4026 _String __r(__uninitialized_size_tag(),
4027 __rhs_sz + 1,
4028 _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator()));
4029 auto __ptr = std::__to_address(__r.__get_pointer());
4030 _Traits::assign(__ptr, 1, __lhs);
4031 _Traits::copy(__ptr + 1, __rhs.data(), __rhs_sz);
4032 _Traits::assign(__ptr + 1 + __rhs_sz, 1, _CharT());
4033 return __r;
3752 return std::__concatenate_strings<_CharT, _Traits>(
3753 __rhs.get_allocator(), basic_string_view<_CharT, _Traits>(std::addressof(__lhs), 1), __rhs);
40343754}
40353755
40363756template <class _CharT, class _Traits, class _Allocator>
4037inline _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>
3757_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>
40383758operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) {
4039 using _String = basic_string<_CharT, _Traits, _Allocator>;
4040 typename _String::size_type __lhs_sz = __lhs.size();
4041 typename _String::size_type __rhs_sz = _Traits::length(__rhs);
4042 _String __r(__uninitialized_size_tag(),
4043 __lhs_sz + __rhs_sz,
4044 _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
4045 auto __ptr = std::__to_address(__r.__get_pointer());
4046 _Traits::copy(__ptr, __lhs.data(), __lhs_sz);
4047 _Traits::copy(__ptr + __lhs_sz, __rhs, __rhs_sz);
4048 _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT());
4049 return __r;
3759 return std::__concatenate_strings<_CharT, _Traits>(__lhs.get_allocator(), __lhs, __rhs);
40503760}
40513761
40523762template <class _CharT, class _Traits, class _Allocator>
40533763_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>
40543764operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs) {
4055 using _String = basic_string<_CharT, _Traits, _Allocator>;
4056 typename _String::size_type __lhs_sz = __lhs.size();
4057 _String __r(__uninitialized_size_tag(),
4058 __lhs_sz + 1,
4059 _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
4060 auto __ptr = std::__to_address(__r.__get_pointer());
4061 _Traits::copy(__ptr, __lhs.data(), __lhs_sz);
4062 _Traits::assign(__ptr + __lhs_sz, 1, __rhs);
4063 _Traits::assign(__ptr + 1 + __lhs_sz, 1, _CharT());
4064 return __r;
3765 return std::__concatenate_strings<_CharT, _Traits>(
3766 __lhs.get_allocator(), __lhs, basic_string_view<_CharT, _Traits>(std::addressof(__rhs), 1));
3767}
3768# if _LIBCPP_STD_VER >= 26
3769
3770template <class _CharT, class _Traits, class _Allocator>
3771_LIBCPP_HIDE_FROM_ABI constexpr basic_string<_CharT, _Traits, _Allocator>
3772operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3773 type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) {
3774 return std::__concatenate_strings<_CharT, _Traits>(__lhs.get_allocator(), __lhs, __rhs);
40653775}
40663776
3777template <class _CharT, class _Traits, class _Allocator>
3778_LIBCPP_HIDE_FROM_ABI constexpr basic_string<_CharT, _Traits, _Allocator>
3779operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs,
3780 const basic_string<_CharT, _Traits, _Allocator>& __rhs) {
3781 return std::__concatenate_strings<_CharT, _Traits>(__rhs.get_allocator(), __lhs, __rhs);
3782}
3783
3784# endif // _LIBCPP_STD_VER >= 26
3785
40673786# ifndef _LIBCPP_CXX03_LANG
40683787
40693788template <class _CharT, class _Traits, class _Allocator>
......@@ -4114,54 +3833,18 @@ operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs) {
41143833
41153834# if _LIBCPP_STD_VER >= 26
41163835
4117template <class _CharT, class _Traits, class _Allocator>
4118_LIBCPP_HIDE_FROM_ABI constexpr basic_string<_CharT, _Traits, _Allocator>
4119operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4120 type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) {
4121 using _String = basic_string<_CharT, _Traits, _Allocator>;
4122 typename _String::size_type __lhs_sz = __lhs.size();
4123 typename _String::size_type __rhs_sz = __rhs.size();
4124 _String __r(__uninitialized_size_tag(),
4125 __lhs_sz + __rhs_sz,
4126 _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
4127 auto __ptr = std::__to_address(__r.__get_pointer());
4128 _Traits::copy(__ptr, __lhs.data(), __lhs_sz);
4129 _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz);
4130 _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT());
4131 return __r;
4132}
4133
41343836template <class _CharT, class _Traits, class _Allocator>
41353837_LIBCPP_HIDE_FROM_ABI constexpr basic_string<_CharT, _Traits, _Allocator>
41363838operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs,
41373839 type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) {
4138 __lhs.append(__rhs);
4139 return std::move(__lhs);
4140}
4141
4142template <class _CharT, class _Traits, class _Allocator>
4143_LIBCPP_HIDE_FROM_ABI constexpr basic_string<_CharT, _Traits, _Allocator>
4144operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs,
4145 const basic_string<_CharT, _Traits, _Allocator>& __rhs) {
4146 using _String = basic_string<_CharT, _Traits, _Allocator>;
4147 typename _String::size_type __lhs_sz = __lhs.size();
4148 typename _String::size_type __rhs_sz = __rhs.size();
4149 _String __r(__uninitialized_size_tag(),
4150 __lhs_sz + __rhs_sz,
4151 _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator()));
4152 auto __ptr = std::__to_address(__r.__get_pointer());
4153 _Traits::copy(__ptr, __lhs.data(), __lhs_sz);
4154 _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz);
4155 _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT());
4156 return __r;
3840 return std::move(__lhs.append(__rhs));
41573841}
41583842
41593843template <class _CharT, class _Traits, class _Allocator>
41603844_LIBCPP_HIDE_FROM_ABI constexpr basic_string<_CharT, _Traits, _Allocator>
41613845operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs,
41623846 basic_string<_CharT, _Traits, _Allocator>&& __rhs) {
4163 __rhs.insert(0, __lhs);
4164 return std::move(__rhs);
3847 return std::move(__rhs.insert(0, __lhs));
41653848}
41663849
41673850# endif // _LIBCPP_STD_VER >= 26
......@@ -4274,7 +3957,7 @@ getline(basic_istream<_CharT, _Traits>&& __is, basic_string<_CharT, _Traits, _Al
42743957
42753958# if _LIBCPP_STD_VER >= 20
42763959template <class _CharT, class _Traits, class _Allocator, class _Up>
4277inline _LIBCPP_HIDE_FROM_ABI typename basic_string<_CharT, _Traits, _Allocator>::size_type
3960inline _LIBCPP_HIDE_FROM_ABI constexpr typename basic_string<_CharT, _Traits, _Allocator>::size_type
42783961erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) {
42793962 auto __old_size = __str.size();
42803963 __str.erase(std::remove(__str.begin(), __str.end(), __v), __str.end());
......@@ -4282,7 +3965,7 @@ erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) {
42823965}
42833966
42843967template <class _CharT, class _Traits, class _Allocator, class _Predicate>
4285inline _LIBCPP_HIDE_FROM_ABI typename basic_string<_CharT, _Traits, _Allocator>::size_type
3968inline _LIBCPP_HIDE_FROM_ABI constexpr typename basic_string<_CharT, _Traits, _Allocator>::size_type
42863969erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, _Predicate __pred) {
42873970 auto __old_size = __str.size();
42883971 __str.erase(std::remove_if(__str.begin(), __str.end(), __pred), __str.end());
......@@ -4345,6 +4028,7 @@ _LIBCPP_POP_MACROS
43454028# include <cstdlib>
43464029# include <iterator>
43474030# include <new>
4031# include <optional>
43484032# include <type_traits>
43494033# include <typeinfo>
43504034# include <utility>
lib/libcxx/include/string_view+8-3
......@@ -235,7 +235,8 @@ namespace std {
235235# include <__type_traits/is_convertible.h>
236236# include <__type_traits/is_same.h>
237237# include <__type_traits/is_standard_layout.h>
238# include <__type_traits/is_trivial.h>
238# include <__type_traits/is_trivially_constructible.h>
239# include <__type_traits/is_trivially_copyable.h>
239240# include <__type_traits/remove_cvref.h>
240241# include <__type_traits/remove_reference.h>
241242# include <__type_traits/type_identity.h>
......@@ -302,7 +303,10 @@ public:
302303
303304 static_assert(!is_array<value_type>::value, "Character type of basic_string_view must not be an array");
304305 static_assert(is_standard_layout<value_type>::value, "Character type of basic_string_view must be standard-layout");
305 static_assert(is_trivial<value_type>::value, "Character type of basic_string_view must be trivial");
306 static_assert(is_trivially_default_constructible<value_type>::value,
307 "Character type of basic_string_view must be trivially default constructible");
308 static_assert(is_trivially_copyable<value_type>::value,
309 "Character type of basic_string_view must be trivially copyable");
306310 static_assert(is_same<_CharT, typename traits_type::char_type>::value,
307311 "traits_type::char_type must be the same type as CharT");
308312
......@@ -447,7 +451,7 @@ public:
447451 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
448452 copy(_CharT* __s, size_type __n, size_type __pos = 0) const {
449453 if (__pos > size())
450 __throw_out_of_range("string_view::copy");
454 std::__throw_out_of_range("string_view::copy");
451455 size_type __rlen = std::min(__n, size() - __pos);
452456 _Traits::copy(__s, data() + __pos, __rlen);
453457 return __rlen;
......@@ -948,6 +952,7 @@ _LIBCPP_POP_MACROS
948952# include <concepts>
949953# include <cstdlib>
950954# include <iterator>
955# include <optional>
951956# include <type_traits>
952957# endif
953958#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
lib/libcxx/include/strstream+31-24
......@@ -133,30 +133,33 @@ private:
133133# include <__cxx03/strstream>
134134#else
135135# include <__config>
136# include <__ostream/basic_ostream.h>
137# include <istream>
138# include <streambuf>
139# include <version>
140136
141# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
142# pragma GCC system_header
143# endif
137# if _LIBCPP_HAS_LOCALIZATION
144138
145# if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM) || defined(_LIBCPP_BUILDING_LIBRARY)
139# include <__ostream/basic_ostream.h>
140# include <istream>
141# include <streambuf>
142# include <version>
143
144# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
145# pragma GCC system_header
146# endif
147
148# if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM) || defined(_LIBCPP_BUILDING_LIBRARY)
146149
147150_LIBCPP_PUSH_MACROS
148# include <__undef_macros>
151# include <__undef_macros>
149152
150153_LIBCPP_BEGIN_NAMESPACE_STD
151154
152155class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI strstreambuf : public streambuf {
153156public:
154# ifndef _LIBCPP_CXX03_LANG
157# ifndef _LIBCPP_CXX03_LANG
155158 _LIBCPP_HIDE_FROM_ABI strstreambuf() : strstreambuf(0) {}
156159 explicit strstreambuf(streamsize __alsize);
157# else
160# else
158161 explicit strstreambuf(streamsize __alsize = 0);
159# endif
162# endif
160163 strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*));
161164 strstreambuf(char* __gnext, streamsize __n, char* __pbeg = nullptr);
162165 strstreambuf(const char* __gnext, streamsize __n);
......@@ -166,10 +169,10 @@ public:
166169 strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg = nullptr);
167170 strstreambuf(const unsigned char* __gnext, streamsize __n);
168171
169# ifndef _LIBCPP_CXX03_LANG
172# ifndef _LIBCPP_CXX03_LANG
170173 _LIBCPP_HIDE_FROM_ABI strstreambuf(strstreambuf&& __rhs);
171174 _LIBCPP_HIDE_FROM_ABI strstreambuf& operator=(strstreambuf&& __rhs);
172# endif // _LIBCPP_CXX03_LANG
175# endif // _LIBCPP_CXX03_LANG
173176
174177 ~strstreambuf() override;
175178
......@@ -203,7 +206,7 @@ private:
203206 void __init(char* __gnext, streamsize __n, char* __pbeg);
204207};
205208
206# ifndef _LIBCPP_CXX03_LANG
209# ifndef _LIBCPP_CXX03_LANG
207210
208211inline _LIBCPP_HIDE_FROM_ABI strstreambuf::strstreambuf(strstreambuf&& __rhs)
209212 : streambuf(__rhs),
......@@ -232,7 +235,7 @@ inline _LIBCPP_HIDE_FROM_ABI strstreambuf& strstreambuf::operator=(strstreambuf&
232235 return *this;
233236}
234237
235# endif // _LIBCPP_CXX03_LANG
238# endif // _LIBCPP_CXX03_LANG
236239
237240class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI istrstream : public istream {
238241public:
......@@ -241,7 +244,7 @@ public:
241244 _LIBCPP_HIDE_FROM_ABI istrstream(const char* __s, streamsize __n) : istream(&__sb_), __sb_(__s, __n) {}
242245 _LIBCPP_HIDE_FROM_ABI istrstream(char* __s, streamsize __n) : istream(&__sb_), __sb_(__s, __n) {}
243246
244# ifndef _LIBCPP_CXX03_LANG
247# ifndef _LIBCPP_CXX03_LANG
245248 _LIBCPP_HIDE_FROM_ABI istrstream(istrstream&& __rhs) // extension
246249 : istream(std::move(static_cast<istream&>(__rhs))), __sb_(std::move(__rhs.__sb_)) {
247250 istream::set_rdbuf(&__sb_);
......@@ -252,7 +255,7 @@ public:
252255 istream::operator=(std::move(__rhs));
253256 return *this;
254257 }
255# endif // _LIBCPP_CXX03_LANG
258# endif // _LIBCPP_CXX03_LANG
256259
257260 ~istrstream() override;
258261
......@@ -274,7 +277,7 @@ public:
274277 _LIBCPP_HIDE_FROM_ABI ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out)
275278 : ostream(&__sb_), __sb_(__s, __n, __s + (__mode & ios::app ? std::strlen(__s) : 0)) {}
276279
277# ifndef _LIBCPP_CXX03_LANG
280# ifndef _LIBCPP_CXX03_LANG
278281 _LIBCPP_HIDE_FROM_ABI ostrstream(ostrstream&& __rhs) // extension
279282 : ostream(std::move(static_cast<ostream&>(__rhs))), __sb_(std::move(__rhs.__sb_)) {
280283 ostream::set_rdbuf(&__sb_);
......@@ -285,7 +288,7 @@ public:
285288 ostream::operator=(std::move(__rhs));
286289 return *this;
287290 }
288# endif // _LIBCPP_CXX03_LANG
291# endif // _LIBCPP_CXX03_LANG
289292
290293 ~ostrstream() override;
291294
......@@ -316,7 +319,7 @@ public:
316319 _LIBCPP_HIDE_FROM_ABI strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out)
317320 : iostream(&__sb_), __sb_(__s, __n, __s + (__mode & ios::app ? std::strlen(__s) : 0)) {}
318321
319# ifndef _LIBCPP_CXX03_LANG
322# ifndef _LIBCPP_CXX03_LANG
320323 _LIBCPP_HIDE_FROM_ABI strstream(strstream&& __rhs) // extension
321324 : iostream(std::move(static_cast<iostream&>(__rhs))), __sb_(std::move(__rhs.__sb_)) {
322325 iostream::set_rdbuf(&__sb_);
......@@ -327,7 +330,7 @@ public:
327330 iostream::operator=(std::move(__rhs));
328331 return *this;
329332 }
330# endif // _LIBCPP_CXX03_LANG
333# endif // _LIBCPP_CXX03_LANG
331334
332335 ~strstream() override;
333336
......@@ -350,7 +353,11 @@ _LIBCPP_END_NAMESPACE_STD
350353
351354_LIBCPP_POP_MACROS
352355
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)
356# endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM) ||
357 // defined(_LIBCPP_BUILDING_LIBRARY)
358
359# endif // _LIBCPP_HAS_LOCALIZATION
360
361#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
355362
356363#endif // _LIBCPP_STRSTREAM
lib/libcxx/include/syncstream+8-9
......@@ -118,10 +118,15 @@ namespace std {
118118*/
119119
120120#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
121# include <__cxx03/syncstream>
121# include <__cxx03/__config>
122122#else
123123# include <__config>
124124
125// standard-mandated includes
126
127// [syncstream.syn]
128# include <ostream>
129
125130# if _LIBCPP_HAS_LOCALIZATION
126131
127132# include <__mutex/lock_guard.h>
......@@ -130,17 +135,11 @@ namespace std {
130135# include <iosfwd> // required for declaration of default arguments
131136# include <streambuf>
132137# include <string>
133
134138# if _LIBCPP_HAS_THREADS
135139# include <map>
136140# include <shared_mutex>
137141# endif
138142
139// standard-mandated includes
140
141// [syncstream.syn]
142# include <ostream>
143
144143# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
145144# pragma GCC system_header
146145# endif
......@@ -248,7 +247,7 @@ private:
248247// Therefore the allocator used in the constructor is passed to the
249248// basic_string. The class does not keep a copy of this allocator.
250249template <class _CharT, class _Traits, class _Allocator>
251class _LIBCPP_TEMPLATE_VIS basic_syncbuf : public basic_streambuf<_CharT, _Traits> {
250class basic_syncbuf : public basic_streambuf<_CharT, _Traits> {
252251public:
253252 using char_type = _CharT;
254253 using traits_type = _Traits;
......@@ -439,7 +438,7 @@ swap(basic_syncbuf<_CharT, _Traits, _Allocator>& __lhs, basic_syncbuf<_CharT, _T
439438// basic_osyncstream
440439
441440template <class _CharT, class _Traits, class _Allocator>
442class _LIBCPP_TEMPLATE_VIS basic_osyncstream : public basic_ostream<_CharT, _Traits> {
441class basic_osyncstream : public basic_ostream<_CharT, _Traits> {
443442public:
444443 using char_type = _CharT;
445444 using traits_type = _Traits;
lib/libcxx/include/system_error+1
......@@ -168,6 +168,7 @@ template <> struct hash<std::error_condition>;
168168# include <cstdint>
169169# include <cstring>
170170# include <limits>
171# include <optional>
171172# include <type_traits>
172173# endif
173174#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
lib/libcxx/include/tuple+24-19
......@@ -211,11 +211,12 @@ template <class... Types>
211211// clang-format on
212212
213213#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
214# include <__cxx03/tuple>
214# include <__cxx03/__config>
215215#else
216216# include <__compare/common_comparison_category.h>
217217# include <__compare/ordering.h>
218218# include <__compare/synth_three_way.h>
219# include <__concepts/boolean_testable.h>
219220# include <__config>
220221# include <__cstddef/size_t.h>
221222# include <__fwd/array.h>
......@@ -250,6 +251,7 @@ template <class... Types>
250251# include <__type_traits/is_nothrow_assignable.h>
251252# include <__type_traits/is_nothrow_constructible.h>
252253# include <__type_traits/is_reference.h>
254# include <__type_traits/is_replaceable.h>
253255# include <__type_traits/is_same.h>
254256# include <__type_traits/is_swappable.h>
255257# include <__type_traits/is_trivially_relocatable.h>
......@@ -257,6 +259,7 @@ template <class... Types>
257259# include <__type_traits/maybe_const.h>
258260# include <__type_traits/nat.h>
259261# include <__type_traits/negation.h>
262# include <__type_traits/reference_constructs_from_temporary.h>
260263# include <__type_traits/remove_cv.h>
261264# include <__type_traits/remove_cvref.h>
262265# include <__type_traits/remove_reference.h>
......@@ -307,15 +310,6 @@ template <size_t _Ip, class _Hp, bool>
307310class __tuple_leaf {
308311 _Hp __value_;
309312
310 template <class _Tp>
311 static _LIBCPP_HIDE_FROM_ABI constexpr bool __can_bind_reference() {
312# if __has_keyword(__reference_binds_to_temporary)
313 return !__reference_binds_to_temporary(_Hp, _Tp);
314# else
315 return true;
316# endif
317 }
318
319313public:
320314 _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_leaf& operator=(const __tuple_leaf&) = delete;
321315
......@@ -345,7 +339,7 @@ public:
345339 _LIBCPP_HIDE_FROM_ABI
346340 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(_Tp&& __t) noexcept(is_nothrow_constructible<_Hp, _Tp>::value)
347341 : __value_(std::forward<_Tp>(__t)) {
348 static_assert(__can_bind_reference<_Tp&&>(),
342 static_assert(!__reference_constructs_from_temporary_v<_Hp, _Tp&&>,
349343 "Attempted construction of reference element binds to a temporary whose lifetime has ended");
350344 }
351345
......@@ -353,7 +347,7 @@ public:
353347 _LIBCPP_HIDE_FROM_ABI
354348 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
355349 : __value_(std::forward<_Tp>(__t)) {
356 static_assert(__can_bind_reference<_Tp&&>(),
350 static_assert(!__reference_constructs_from_temporary_v<_Hp, _Tp&&>,
357351 "Attempted construction of reference element binds to a temporary whose lifetime has ended");
358352 }
359353
......@@ -462,8 +456,8 @@ template <class _Indx, class... _Tp>
462456struct __tuple_impl;
463457
464458template <size_t... _Indx, class... _Tp>
465struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
466 : public __tuple_leaf<_Indx, _Tp>... {
459struct _LIBCPP_DECLSPEC_EMPTY_BASES
460 __tuple_impl<__tuple_indices<_Indx...>, _Tp...> : public __tuple_leaf<_Indx, _Tp>... {
467461 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_impl() noexcept(
468462 __all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
469463
......@@ -535,7 +529,7 @@ __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up
535529}
536530
537531template <class... _Tp>
538class _LIBCPP_TEMPLATE_VIS tuple {
532class _LIBCPP_NO_SPECIALIZATIONS tuple {
539533 typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
540534
541535 _BaseT __base_;
......@@ -555,6 +549,7 @@ class _LIBCPP_TEMPLATE_VIS tuple {
555549public:
556550 using __trivially_relocatable _LIBCPP_NODEBUG =
557551 __conditional_t<_And<__libcpp_is_trivially_relocatable<_Tp>...>::value, tuple, void>;
552 using __replaceable _LIBCPP_NODEBUG = __conditional_t<_And<__is_replaceable<_Tp>...>::value, tuple, void>;
558553
559554 // [tuple.cnstr]
560555
......@@ -1005,8 +1000,12 @@ public:
10051000# endif // _LIBCPP_STD_VER >= 23
10061001};
10071002
1003_LIBCPP_DIAGNOSTIC_PUSH
1004# if __has_warning("-Winvalid-specialization")
1005_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
1006# endif
10081007template <>
1009class _LIBCPP_TEMPLATE_VIS tuple<> {
1008class tuple<> {
10101009public:
10111010 constexpr tuple() _NOEXCEPT = default;
10121011 template <class _Alloc>
......@@ -1022,18 +1021,19 @@ public:
10221021 _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple&) const noexcept {}
10231022# endif
10241023};
1024_LIBCPP_DIAGNOSTIC_POP
10251025
10261026# if _LIBCPP_STD_VER >= 23
10271027template <class... _TTypes, class... _UTypes, template <class> class _TQual, template <class> class _UQual>
10281028 requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; }
10291029struct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> {
1030 using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
1030 using type _LIBCPP_NODEBUG = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>;
10311031};
10321032
10331033template <class... _TTypes, class... _UTypes>
10341034 requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; }
10351035struct common_type<tuple<_TTypes...>, tuple<_UTypes...>> {
1036 using type = tuple<common_type_t<_TTypes, _UTypes>...>;
1036 using type _LIBCPP_NODEBUG = tuple<common_type_t<_TTypes, _UTypes>...>;
10371037};
10381038# endif // _LIBCPP_STD_VER >= 23
10391039
......@@ -1154,6 +1154,11 @@ struct __tuple_equal<0> {
11541154};
11551155
11561156template <class... _Tp, class... _Up>
1157# if _LIBCPP_STD_VER >= 26
1158 requires(__all<requires(const _Tp& __t, const _Up& __u) {
1159 { __t == __u } -> __boolean_testable;
1160 }...>::value && (sizeof...(_Tp) == sizeof...(_Up)))
1161# endif
11571162inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
11581163operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
11591164 static_assert(sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
......@@ -1361,7 +1366,7 @@ tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) {
13611366}
13621367
13631368template <class... _Tp, class _Alloc>
1364struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc> : true_type {};
1369struct uses_allocator<tuple<_Tp...>, _Alloc> : true_type {};
13651370
13661371# if _LIBCPP_STD_VER >= 17
13671372# define _LIBCPP_NOEXCEPT_RETURN(...) \
lib/libcxx/include/type_traits+189-155
......@@ -18,13 +18,11 @@ namespace std
1818
1919 // helper class:
2020 template <class T, T v> struct integral_constant;
21 typedef integral_constant<bool, true> true_type; // C++11
22 typedef integral_constant<bool, false> false_type; // C++11
21 typedef integral_constant<bool, true> true_type; // since C++11
22 typedef integral_constant<bool, false> false_type; // since C++11
2323
24 template <bool B> // C++14
25 using bool_constant = integral_constant<bool, B>; // C++14
26 typedef bool_constant<true> true_type; // C++14
27 typedef bool_constant<false> false_type; // C++14
24 template <bool B>
25 using bool_constant = integral_constant<bool, B>; // since C++17
2826
2927 // helper traits
3028 template <bool, class T = void> struct enable_if;
......@@ -32,7 +30,7 @@ namespace std
3230
3331 // Primary classification traits:
3432 template <class T> struct is_void;
35 template <class T> struct is_null_pointer; // C++14
33 template <class T> struct is_null_pointer; // since C++14
3634 template <class T> struct is_integral;
3735 template <class T> struct is_floating_point;
3836 template <class T> struct is_array;
......@@ -51,7 +49,7 @@ namespace std
5149 template <class T> struct is_arithmetic;
5250 template <class T> struct is_fundamental;
5351 template <class T> struct is_member_pointer;
54 template <class T> struct is_scoped_enum; // C++23
52 template <class T> struct is_scoped_enum; // since C++23
5553 template <class T> struct is_scalar;
5654 template <class T> struct is_object;
5755 template <class T> struct is_compound;
......@@ -75,9 +73,9 @@ namespace std
7573 template <class T> struct remove_pointer;
7674 template <class T> struct add_pointer;
7775
78 template<class T> struct type_identity; // C++20
76 template<class T> struct type_identity; // since C++20
7977 template<class T>
80 using type_identity_t = typename type_identity<T>::type; // C++20
78 using type_identity_t = typename type_identity<T>::type; // since C++20
8179
8280 // Integral properties:
8381 template <class T> struct is_signed;
......@@ -91,20 +89,20 @@ namespace std
9189 template <class T> struct remove_extent;
9290 template <class T> struct remove_all_extents;
9391
94 template <class T> struct is_bounded_array; // C++20
95 template <class T> struct is_unbounded_array; // C++20
92 template <class T> struct is_bounded_array; // since C++20
93 template <class T> struct is_unbounded_array; // since C++20
9694
9795 // Member introspection:
98 template <class T> struct is_pod;
99 template <class T> struct is_trivial;
96 template <class T> struct is_trivial; // deprecated in C++26
97 template <class T> struct is_pod; // deprecated in C++20
10098 template <class T> struct is_trivially_copyable;
10199 template <class T> struct is_standard_layout;
102 template <class T> struct is_literal_type; // Deprecated in C++17; removed in C++20
100 template <class T> struct is_literal_type; // deprecated in C++17; removed in C++20
103101 template <class T> struct is_empty;
104102 template <class T> struct is_polymorphic;
105103 template <class T> struct is_abstract;
106 template <class T> struct is_final; // C++14
107 template <class T> struct is_aggregate; // C++17
104 template <class T> struct is_final; // since C++14
105 template <class T> struct is_aggregate; // since C++17
108106
109107 template <class T, class... Args> struct is_constructible;
110108 template <class T> struct is_default_constructible;
......@@ -113,8 +111,8 @@ namespace std
113111 template <class T, class U> struct is_assignable;
114112 template <class T> struct is_copy_assignable;
115113 template <class T> struct is_move_assignable;
116 template <class T, class U> struct is_swappable_with; // C++17
117 template <class T> struct is_swappable; // C++17
114 template <class T, class U> struct is_swappable_with; // since C++17
115 template <class T> struct is_swappable; // since C++17
118116 template <class T> struct is_destructible;
119117
120118 template <class T, class... Args> struct is_trivially_constructible;
......@@ -133,292 +131,328 @@ namespace std
133131 template <class T, class U> struct is_nothrow_assignable;
134132 template <class T> struct is_nothrow_copy_assignable;
135133 template <class T> struct is_nothrow_move_assignable;
136 template <class T, class U> struct is_nothrow_swappable_with; // C++17
137 template <class T> struct is_nothrow_swappable; // C++17
134 template <class T, class U>
135 struct is_nothrow_swappable_with; // since C++17
136 template <class T>
137 struct is_nothrow_swappable; // since C++17
138138 template <class T> struct is_nothrow_destructible;
139139
140 template<class T> struct is_implicit_lifetime; // Since C++23
140 template <class T> struct is_implicit_lifetime; // since C++23
141141
142142 template <class T> struct has_virtual_destructor;
143143
144 template<class T> struct has_unique_object_representations; // C++17
144 template <class T>
145 struct has_unique_object_representations; // since C++17
146
147 template<class T, class U>
148 struct reference_constructs_from_temporary; // since C++23
149 template<class T, class U>
150 struct reference_converts_from_temporary; // since C++23
145151
146152 // Relationships between types:
147153 template <class T, class U> struct is_same;
148154 template <class Base, class Derived> struct is_base_of;
149 template <class Base, class Derived> struct is_virtual_base_of; // C++26
155 template <class Base, class Derived>
156 struct is_virtual_base_of; // since C++26
150157
151158 template <class From, class To> struct is_convertible;
152 template <typename From, typename To> struct is_nothrow_convertible; // C++20
153 template <typename From, typename To> inline constexpr bool is_nothrow_convertible_v; // C++20
159 template <class From, class To>
160 struct is_nothrow_convertible; // since C++20
154161
155 template <class Fn, class... ArgTypes> struct is_invocable;
156 template <class R, class Fn, class... ArgTypes> struct is_invocable_r;
162 template <class Fn, class... ArgTypes> struct is_invocable; // since C++17
163 template <class R, class Fn, class... ArgTypes>
164 struct is_invocable_r; // since C++17
157165
158 template <class Fn, class... ArgTypes> struct is_nothrow_invocable;
159 template <class R, class Fn, class... ArgTypes> struct is_nothrow_invocable_r;
166 template <class Fn, class... ArgTypes>
167 struct is_nothrow_invocable; // since C++17
168 template <class R, class Fn, class... ArgTypes>
169 struct is_nothrow_invocable_r; // since C++17
160170
161171 // Alignment properties and transformations:
162172 template <class T> struct alignment_of;
163173 template <size_t Len, size_t Align = most_stringent_alignment_requirement>
164 struct aligned_storage; // deprecated in C++23
174 struct aligned_storage; // deprecated in C++23
165175 template <size_t Len, class... Types> struct aligned_union; // deprecated in C++23
166 template <class T> struct remove_cvref; // C++20
176 template <class T> struct remove_cvref; // since C++20
167177
168178 template <class T> struct decay;
169179 template <class... T> struct common_type;
170180 template <class T> struct underlying_type;
171 template <class> class result_of; // undefined; deprecated in C++17; removed in C++20
172 template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>; // deprecated in C++17; removed in C++20
173 template <class Fn, class... ArgTypes> struct invoke_result; // C++17
181 template <class> struct result_of; // undefined; deprecated in C++17; removed in C++20
182 template <class Fn, class... ArgTypes>
183 struct result_of<Fn(ArgTypes...)>; // deprecated in C++17; removed in C++20
184 template <class Fn, class... ArgTypes>
185 struct invoke_result; // since C++17
174186
175187 // const-volatile modifications:
176188 template <class T>
177 using remove_const_t = typename remove_const<T>::type; // C++14
189 using remove_const_t = typename remove_const<T>::type; // since C++14
178190 template <class T>
179 using remove_volatile_t = typename remove_volatile<T>::type; // C++14
191 using remove_volatile_t
192 = typename remove_volatile<T>::type; // since C++14
180193 template <class T>
181 using remove_cv_t = typename remove_cv<T>::type; // C++14
194 using remove_cv_t = typename remove_cv<T>::type; // since C++14
182195 template <class T>
183 using add_const_t = typename add_const<T>::type; // C++14
196 using add_const_t = typename add_const<T>::type; // since C++14
184197 template <class T>
185 using add_volatile_t = typename add_volatile<T>::type; // C++14
198 using add_volatile_t = typename add_volatile<T>::type; // since C++14
186199 template <class T>
187 using add_cv_t = typename add_cv<T>::type; // C++14
200 using add_cv_t = typename add_cv<T>::type; // since C++14
188201
189202 // reference modifications:
190203 template <class T>
191 using remove_reference_t = typename remove_reference<T>::type; // C++14
204 using remove_reference_t
205 = typename remove_reference<T>::type; // since C++14
192206 template <class T>
193 using add_lvalue_reference_t = typename add_lvalue_reference<T>::type; // C++14
207 using add_lvalue_reference_t
208 = typename add_lvalue_reference<T>::type; // since C++14
194209 template <class T>
195 using add_rvalue_reference_t = typename add_rvalue_reference<T>::type; // C++14
210 using add_rvalue_reference_t
211 = typename add_rvalue_reference<T>::type; // since C++14
196212
197213 // sign modifications:
198214 template <class T>
199 using make_signed_t = typename make_signed<T>::type; // C++14
215 using make_signed_t = typename make_signed<T>::type; // since C++14
200216 template <class T>
201 using make_unsigned_t = typename make_unsigned<T>::type; // C++14
217 using make_unsigned_t = typename make_unsigned<T>::type; // since C++14
202218
203219 // array modifications:
204220 template <class T>
205 using remove_extent_t = typename remove_extent<T>::type; // C++14
221 using remove_extent_t
222 = typename remove_extent<T>::type; // since C++14
206223 template <class T>
207 using remove_all_extents_t = typename remove_all_extents<T>::type; // C++14
224 using remove_all_extents_t
225 = typename remove_all_extents<T>::type; // since C++14
208226
209227 template <class T>
210228 inline constexpr bool is_bounded_array_v
211 = is_bounded_array<T>::value; // C++20
229 = is_bounded_array<T>::value; // since C++20
212230 inline constexpr bool is_unbounded_array_v
213 = is_unbounded_array<T>::value; // C++20
231 = is_unbounded_array<T>::value; // since C++20
214232
215233 // pointer modifications:
216234 template <class T>
217 using remove_pointer_t = typename remove_pointer<T>::type; // C++14
235 using remove_pointer_t
236 = typename remove_pointer<T>::type; // since C++14
218237 template <class T>
219 using add_pointer_t = typename add_pointer<T>::type; // C++14
238 using add_pointer_t = typename add_pointer<T>::type; // since C++14
220239
221240 // other transformations:
222241 template <size_t Len, size_t Align=default-alignment>
223 using aligned_storage_t = typename aligned_storage<Len,Align>::type; // C++14
242 using aligned_storage_t
243 = typename aligned_storage<Len,Align>::type; // since C++14
224244 template <size_t Len, class... Types>
225 using aligned_union_t = typename aligned_union<Len,Types...>::type; // C++14
245 using aligned_union_t
246 = typename aligned_union<Len,Types...>::type; // since C++14
226247 template <class T>
227 using remove_cvref_t = typename remove_cvref<T>::type; // C++20
248 using remove_cvref_t
249 = typename remove_cvref<T>::type; // since C++20
228250 template <class T>
229 using decay_t = typename decay<T>::type; // C++14
251 using decay_t = typename decay<T>::type; // since C++14
230252 template <bool b, class T=void>
231 using enable_if_t = typename enable_if<b,T>::type; // C++14
253 using enable_if_t = typename enable_if<b,T>::type; // since C++14
232254 template <bool b, class T, class F>
233 using conditional_t = typename conditional<b,T,F>::type; // C++14
255 using conditional_t
256 = typename conditional<b,T,F>::type; // since C++14
234257 template <class... T>
235 using common_type_t = typename common_type<T...>::type; // C++14
258 using common_type_t
259 = typename common_type<T...>::type; // since C++14
236260 template <class T>
237 using underlying_type_t = typename underlying_type<T>::type; // C++14
261 using underlying_type_t
262 = typename underlying_type<T>::type; // since C++14
238263 template <class T>
239 using result_of_t = typename result_of<T>::type; // C++14; deprecated in C++17; removed in C++20
264 using result_of_t = typename result_of<T>::type; // since C++14; deprecated in C++17; removed in C++20
240265 template <class Fn, class... ArgTypes>
241 using invoke_result_t = typename invoke_result<Fn, ArgTypes...>::type; // C++17
266 using invoke_result_t
267 = typename invoke_result<Fn, ArgTypes...>::type; // since C++17
242268
243269 template <class...>
244 using void_t = void; // C++17
270 using void_t = void; // since C++17
245271
246272 // See C++14 20.10.4.1, primary type categories
247273 template <class T> inline constexpr bool is_void_v
248 = is_void<T>::value; // C++17
274 = is_void<T>::value; // since C++17
249275 template <class T> inline constexpr bool is_null_pointer_v
250 = is_null_pointer<T>::value; // C++17
276 = is_null_pointer<T>::value; // since C++17
251277 template <class T> inline constexpr bool is_integral_v
252 = is_integral<T>::value; // C++17
278 = is_integral<T>::value; // since C++17
253279 template <class T> inline constexpr bool is_floating_point_v
254 = is_floating_point<T>::value; // C++17
280 = is_floating_point<T>::value; // since C++17
255281 template <class T> inline constexpr bool is_array_v
256 = is_array<T>::value; // C++17
282 = is_array<T>::value; // since C++17
257283 template <class T> inline constexpr bool is_pointer_v
258 = is_pointer<T>::value; // C++17
284 = is_pointer<T>::value; // since C++17
259285 template <class T> inline constexpr bool is_lvalue_reference_v
260 = is_lvalue_reference<T>::value; // C++17
286 = is_lvalue_reference<T>::value; // since C++17
261287 template <class T> inline constexpr bool is_rvalue_reference_v
262 = is_rvalue_reference<T>::value; // C++17
288 = is_rvalue_reference<T>::value; // since C++17
263289 template <class T> inline constexpr bool is_member_object_pointer_v
264 = is_member_object_pointer<T>::value; // C++17
290 = is_member_object_pointer<T>::value; // since C++17
265291 template <class T> inline constexpr bool is_member_function_pointer_v
266 = is_member_function_pointer<T>::value; // C++17
292 = is_member_function_pointer<T>::value; // since C++17
267293 template <class T> inline constexpr bool is_enum_v
268 = is_enum<T>::value; // C++17
294 = is_enum<T>::value; // since C++17
269295 template <class T> inline constexpr bool is_union_v
270 = is_union<T>::value; // C++17
296 = is_union<T>::value; // since C++17
271297 template <class T> inline constexpr bool is_class_v
272 = is_class<T>::value; // C++17
298 = is_class<T>::value; // since C++17
273299 template <class T> inline constexpr bool is_function_v
274 = is_function<T>::value; // C++17
300 = is_function<T>::value; // since C++17
275301
276302 // See C++14 20.10.4.2, composite type categories
277303 template <class T> inline constexpr bool is_reference_v
278 = is_reference<T>::value; // C++17
304 = is_reference<T>::value; // since C++17
279305 template <class T> inline constexpr bool is_arithmetic_v
280 = is_arithmetic<T>::value; // C++17
306 = is_arithmetic<T>::value; // since C++17
281307 template <class T> inline constexpr bool is_fundamental_v
282 = is_fundamental<T>::value; // C++17
308 = is_fundamental<T>::value; // since C++17
283309 template <class T> inline constexpr bool is_object_v
284 = is_object<T>::value; // C++17
310 = is_object<T>::value; // since C++17
285311 template <class T> inline constexpr bool is_scalar_v
286 = is_scalar<T>::value; // C++17
312 = is_scalar<T>::value; // since C++17
287313 template <class T> inline constexpr bool is_compound_v
288 = is_compound<T>::value; // C++17
314 = is_compound<T>::value; // since C++17
289315 template <class T> inline constexpr bool is_member_pointer_v
290 = is_member_pointer<T>::value; // C++17
316 = is_member_pointer<T>::value; // since C++17
291317 template <class T> inline constexpr bool is_scoped_enum_v
292 = is_scoped_enum<T>::value; // C++23
318 = is_scoped_enum<T>::value; // since C++23
293319
294320 // See C++14 20.10.4.3, type properties
295321 template <class T> inline constexpr bool is_const_v
296 = is_const<T>::value; // C++17
322 = is_const<T>::value; // since C++17
297323 template <class T> inline constexpr bool is_volatile_v
298 = is_volatile<T>::value; // C++17
324 = is_volatile<T>::value; // since C++17
299325 template <class T> inline constexpr bool is_trivial_v
300 = is_trivial<T>::value; // C++17
326 = is_trivial<T>::value; // since C++17; deprecated in C++26
301327 template <class T> inline constexpr bool is_trivially_copyable_v
302 = is_trivially_copyable<T>::value; // C++17
328 = is_trivially_copyable<T>::value; // since C++17
303329 template <class T> inline constexpr bool is_standard_layout_v
304 = is_standard_layout<T>::value; // C++17
330 = is_standard_layout<T>::value; // since C++17
305331 template <class T> inline constexpr bool is_pod_v
306 = is_pod<T>::value; // C++17
332 = is_pod<T>::value; // since C++17; deprecated in C++20
307333 template <class T> inline constexpr bool is_literal_type_v
308 = is_literal_type<T>::value; // C++17; deprecated in C++17; removed in C++20
334 = is_literal_type<T>::value; // since C++17; deprecated in C++17; removed in C++20
309335 template <class T> inline constexpr bool is_empty_v
310 = is_empty<T>::value; // C++17
336 = is_empty<T>::value; // since C++17
311337 template <class T> inline constexpr bool is_polymorphic_v
312 = is_polymorphic<T>::value; // C++17
338 = is_polymorphic<T>::value; // since C++17
313339 template <class T> inline constexpr bool is_abstract_v
314 = is_abstract<T>::value; // C++17
340 = is_abstract<T>::value; // since C++17
315341 template <class T> inline constexpr bool is_final_v
316 = is_final<T>::value; // C++17
342 = is_final<T>::value; // since C++17
317343 template <class T> inline constexpr bool is_aggregate_v
318 = is_aggregate<T>::value; // C++17
344 = is_aggregate<T>::value; // since C++17
319345 template <class T> inline constexpr bool is_signed_v
320 = is_signed<T>::value; // C++17
346 = is_signed<T>::value; // since C++17
321347 template <class T> inline constexpr bool is_unsigned_v
322 = is_unsigned<T>::value; // C++17
348 = is_unsigned<T>::value; // since C++17
323349 template <class T, class... Args> inline constexpr bool is_constructible_v
324 = is_constructible<T, Args...>::value; // C++17
350 = is_constructible<T, Args...>::value; // since C++17
325351 template <class T> inline constexpr bool is_default_constructible_v
326 = is_default_constructible<T>::value; // C++17
352 = is_default_constructible<T>::value; // since C++17
327353 template <class T> inline constexpr bool is_copy_constructible_v
328 = is_copy_constructible<T>::value; // C++17
354 = is_copy_constructible<T>::value; // since C++17
329355 template <class T> inline constexpr bool is_move_constructible_v
330 = is_move_constructible<T>::value; // C++17
356 = is_move_constructible<T>::value; // since C++17
331357 template <class T, class U> inline constexpr bool is_assignable_v
332 = is_assignable<T, U>::value; // C++17
358 = is_assignable<T, U>::value; // since C++17
333359 template <class T> inline constexpr bool is_copy_assignable_v
334 = is_copy_assignable<T>::value; // C++17
360 = is_copy_assignable<T>::value; // since C++17
335361 template <class T> inline constexpr bool is_move_assignable_v
336 = is_move_assignable<T>::value; // C++17
362 = is_move_assignable<T>::value; // since C++17
337363 template <class T, class U> inline constexpr bool is_swappable_with_v
338 = is_swappable_with<T, U>::value; // C++17
364 = is_swappable_with<T, U>::value; // since C++17
339365 template <class T> inline constexpr bool is_swappable_v
340 = is_swappable<T>::value; // C++17
366 = is_swappable<T>::value; // since C++17
341367 template <class T> inline constexpr bool is_destructible_v
342 = is_destructible<T>::value; // C++17
368 = is_destructible<T>::value; // since C++17
343369 template <class T, class... Args> inline constexpr bool is_trivially_constructible_v
344 = is_trivially_constructible<T, Args...>::value; // C++17
370 = is_trivially_constructible<T, Args...>::value; // since C++17
345371 template <class T> inline constexpr bool is_trivially_default_constructible_v
346 = is_trivially_default_constructible<T>::value; // C++17
372 = is_trivially_default_constructible<T>::value; // since C++17
347373 template <class T> inline constexpr bool is_trivially_copy_constructible_v
348 = is_trivially_copy_constructible<T>::value; // C++17
374 = is_trivially_copy_constructible<T>::value; // since C++17
349375 template <class T> inline constexpr bool is_trivially_move_constructible_v
350 = is_trivially_move_constructible<T>::value; // C++17
376 = is_trivially_move_constructible<T>::value; // since C++17
351377 template <class T, class U> inline constexpr bool is_trivially_assignable_v
352 = is_trivially_assignable<T, U>::value; // C++17
378 = is_trivially_assignable<T, U>::value; // since C++17
353379 template <class T> inline constexpr bool is_trivially_copy_assignable_v
354 = is_trivially_copy_assignable<T>::value; // C++17
380 = is_trivially_copy_assignable<T>::value; // since C++17
355381 template <class T> inline constexpr bool is_trivially_move_assignable_v
356 = is_trivially_move_assignable<T>::value; // C++17
382 = is_trivially_move_assignable<T>::value; // since C++17
357383 template <class T> inline constexpr bool is_trivially_destructible_v
358 = is_trivially_destructible<T>::value; // C++17
384 = is_trivially_destructible<T>::value; // since C++17
359385 template <class T, class... Args> inline constexpr bool is_nothrow_constructible_v
360 = is_nothrow_constructible<T, Args...>::value; // C++17
386 = is_nothrow_constructible<T, Args...>::value; // since C++17
361387 template <class T> inline constexpr bool is_nothrow_default_constructible_v
362 = is_nothrow_default_constructible<T>::value; // C++17
388 = is_nothrow_default_constructible<T>::value; // since C++17
363389 template <class T> inline constexpr bool is_nothrow_copy_constructible_v
364 = is_nothrow_copy_constructible<T>::value; // C++17
390 = is_nothrow_copy_constructible<T>::value; // since C++17
365391 template <class T> inline constexpr bool is_nothrow_move_constructible_v
366 = is_nothrow_move_constructible<T>::value; // C++17
392 = is_nothrow_move_constructible<T>::value; // since C++17
367393 template <class T, class U> inline constexpr bool is_nothrow_assignable_v
368 = is_nothrow_assignable<T, U>::value; // C++17
394 = is_nothrow_assignable<T, U>::value; // since C++17
369395 template <class T> inline constexpr bool is_nothrow_copy_assignable_v
370 = is_nothrow_copy_assignable<T>::value; // C++17
396 = is_nothrow_copy_assignable<T>::value; // since C++17
371397 template <class T> inline constexpr bool is_nothrow_move_assignable_v
372 = is_nothrow_move_assignable<T>::value; // C++17
398 = is_nothrow_move_assignable<T>::value; // since C++17
373399 template <class T, class U> inline constexpr bool is_nothrow_swappable_with_v
374 = is_nothrow_swappable_with<T, U>::value; // C++17
400 = is_nothrow_swappable_with<T, U>::value; // since C++17
375401 template <class T> inline constexpr bool is_nothrow_swappable_v
376 = is_nothrow_swappable<T>::value; // C++17
402 = is_nothrow_swappable<T>::value; // since C++17
377403 template <class T> inline constexpr bool is_nothrow_destructible_v
378 = 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
404 = is_nothrow_destructible<T>::value; // since C++17
405 template <class T> inline constexpr bool is_implicit_lifetime_v
406 = is_implicit_lifetime<T>::value; // since C++23
381407 template <class T> inline constexpr bool has_virtual_destructor_v
382 = has_virtual_destructor<T>::value; // C++17
383 template<class T> inline constexpr bool has_unique_object_representations_v // C++17
384 = has_unique_object_representations<T>::value;
408 = has_virtual_destructor<T>::value; // since C++17
409 template<class T> inline constexpr bool has_unique_object_representations_v
410 = has_unique_object_representations<T>::value; // since C++17
411 template<class T, class U>
412 constexpr bool reference_constructs_from_temporary_v
413 = reference_constructs_from_temporary<T, U>::value; // since C++23
414 template<class T, class U>
415 constexpr bool reference_converts_from_temporary_v
416 = reference_converts_from_temporary<T, U>::value; // since C++23
385417
386418 // See C++14 20.10.5, type property queries
387419 template <class T> inline constexpr size_t alignment_of_v
388 = alignment_of<T>::value; // C++17
420 = alignment_of<T>::value; // since C++17
389421 template <class T> inline constexpr size_t rank_v
390 = rank<T>::value; // C++17
422 = rank<T>::value; // since C++17
391423 template <class T, unsigned I = 0> inline constexpr size_t extent_v
392 = extent<T, I>::value; // C++17
424 = extent<T, I>::value; // since C++17
393425
394426 // See C++14 20.10.6, type relations
395427 template <class T, class U> inline constexpr bool is_same_v
396 = is_same<T, U>::value; // C++17
428 = is_same<T, U>::value; // since C++17
397429 template <class Base, class Derived> inline constexpr bool is_base_of_v
398 = is_base_of<Base, Derived>::value; // C++17
430 = is_base_of<Base, Derived>::value; // since C++17
399431 template <class Base, class Derived> inline constexpr bool is_virtual_base_of_v
400 = is_virtual_base_of<Base, Derived>::value; // C++26
432 = is_virtual_base_of<Base, Derived>::value; // since C++26
401433 template <class From, class To> inline constexpr bool is_convertible_v
402 = is_convertible<From, To>::value; // C++17
434 = is_convertible<From, To>::value; // since C++17
435 template <class From, class To> inline constexpr bool is_nothrow_convertible_v
436 = is_nothrow_convertible<From, To>::value; // since C++20
403437 template <class Fn, class... ArgTypes> inline constexpr bool is_invocable_v
404 = is_invocable<Fn, ArgTypes...>::value; // C++17
438 = is_invocable<Fn, ArgTypes...>::value; // since C++17
405439 template <class R, class Fn, class... ArgTypes> inline constexpr bool is_invocable_r_v
406 = is_invocable_r<R, Fn, ArgTypes...>::value; // C++17
440 = is_invocable_r<R, Fn, ArgTypes...>::value; // since C++17
407441 template <class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_v
408 = is_nothrow_invocable<Fn, ArgTypes...>::value; // C++17
442 = is_nothrow_invocable<Fn, ArgTypes...>::value; // since C++17
409443 template <class R, class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_r_v
410 = is_nothrow_invocable_r<R, Fn, ArgTypes...>::value; // C++17
444 = is_nothrow_invocable_r<R, Fn, ArgTypes...>::value; // since C++17
411445
412446 // [meta.logical], logical operator traits:
413 template<class... B> struct conjunction; // C++17
414 template<class... B>
415 inline constexpr bool conjunction_v = conjunction<B...>::value; // C++17
416 template<class... B> struct disjunction; // C++17
417 template<class... B>
418 inline constexpr bool disjunction_v = disjunction<B...>::value; // C++17
419 template<class B> struct negation; // C++17
420 template<class B>
421 inline constexpr bool negation_v = negation<B>::value; // C++17
447 template<class... B> struct conjunction; // since C++17
448 template<class... B> inline constexpr bool conjunction_v
449 = conjunction<B...>::value; // since C++17
450 template<class... B> struct disjunction; // since C++17
451 template<class... B> inline constexpr bool disjunction_v
452 = disjunction<B...>::value; // since C++17
453 template<class B> struct negation; // since C++17
454 template<class B> inline constexpr bool negation_v
455 = negation<B>::value; // since C++17
422456
423457}
424458
......@@ -429,9 +463,8 @@ namespace std
429463#else
430464# include <__config>
431465# include <__type_traits/add_cv_quals.h>
432# include <__type_traits/add_lvalue_reference.h>
433466# include <__type_traits/add_pointer.h>
434# include <__type_traits/add_rvalue_reference.h>
467# include <__type_traits/add_reference.h>
435468# include <__type_traits/aligned_storage.h>
436469# include <__type_traits/aligned_union.h>
437470# include <__type_traits/alignment_of.h>
......@@ -515,7 +548,6 @@ namespace std
515548# include <__type_traits/common_reference.h>
516549# include <__type_traits/is_bounded_array.h>
517550# include <__type_traits/is_constant_evaluated.h>
518# include <__type_traits/is_nothrow_convertible.h>
519551# include <__type_traits/is_unbounded_array.h>
520552# include <__type_traits/type_identity.h>
521553# include <__type_traits/unwrap_ref.h>
......@@ -523,6 +555,8 @@ namespace std
523555
524556# if _LIBCPP_STD_VER >= 23
525557# include <__type_traits/is_implicit_lifetime.h>
558# include <__type_traits/reference_constructs_from_temporary.h>
559# include <__type_traits/reference_converts_from_temporary.h>
526560# endif
527561
528562# include <version>
lib/libcxx/include/typeindex+3-3
......@@ -62,7 +62,7 @@ struct hash<type_index>
6262
6363_LIBCPP_BEGIN_NAMESPACE_STD
6464
65class _LIBCPP_TEMPLATE_VIS type_index {
65class type_index {
6666 const type_info* __t_;
6767
6868public:
......@@ -91,10 +91,10 @@ public:
9191};
9292
9393template <class _Tp>
94struct _LIBCPP_TEMPLATE_VIS hash;
94struct hash;
9595
9696template <>
97struct _LIBCPP_TEMPLATE_VIS hash<type_index> : public __unary_function<type_index, size_t> {
97struct hash<type_index> : public __unary_function<type_index, size_t> {
9898 _LIBCPP_HIDE_FROM_ABI size_t operator()(type_index __index) const _NOEXCEPT { return __index.hash_code(); }
9999};
100100
lib/libcxx/include/typeinfo+2-2
......@@ -354,7 +354,7 @@ public:
354354
355355# if defined(_LIBCPP_ABI_VCRUNTIME) && _HAS_EXCEPTIONS == 0
356356
357namespace std {
357_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
358358
359359class bad_cast : public exception {
360360public:
......@@ -372,7 +372,7 @@ private:
372372 bad_typeid(const char* const __message) _NOEXCEPT : exception(__message) {}
373373};
374374
375} // namespace std
375_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
376376
377377# endif // defined(_LIBCPP_ABI_VCRUNTIME) && _HAS_EXCEPTIONS == 0
378378
lib/libcxx/include/unordered_map+68-161
......@@ -654,9 +654,7 @@ public:
654654 _LIBCPP_HIDE_FROM_ABI __unordered_map_hasher(const _Hash& __h) _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
655655 : _Hash(__h) {}
656656 _LIBCPP_HIDE_FROM_ABI const _Hash& hash_function() const _NOEXCEPT { return *this; }
657 _LIBCPP_HIDE_FROM_ABI size_t operator()(const _Cp& __x) const {
658 return static_cast<const _Hash&>(*this)(__x.__get_value().first);
659 }
657 _LIBCPP_HIDE_FROM_ABI size_t operator()(const _Cp& __x) const { return static_cast<const _Hash&>(*this)(__x.first); }
660658 _LIBCPP_HIDE_FROM_ABI size_t operator()(const _Key& __x) const { return static_cast<const _Hash&>(*this)(__x); }
661659# if _LIBCPP_STD_VER >= 20
662660 template <typename _K2>
......@@ -680,7 +678,7 @@ public:
680678 _LIBCPP_HIDE_FROM_ABI __unordered_map_hasher(const _Hash& __h) _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
681679 : __hash_(__h) {}
682680 _LIBCPP_HIDE_FROM_ABI const _Hash& hash_function() const _NOEXCEPT { return __hash_; }
683 _LIBCPP_HIDE_FROM_ABI size_t operator()(const _Cp& __x) const { return __hash_(__x.__get_value().first); }
681 _LIBCPP_HIDE_FROM_ABI size_t operator()(const _Cp& __x) const { return __hash_(__x.first); }
684682 _LIBCPP_HIDE_FROM_ABI size_t operator()(const _Key& __x) const { return __hash_(__x); }
685683# if _LIBCPP_STD_VER >= 20
686684 template <typename _K2>
......@@ -713,10 +711,10 @@ public:
713711 : _Pred(__p) {}
714712 _LIBCPP_HIDE_FROM_ABI const _Pred& key_eq() const _NOEXCEPT { return *this; }
715713 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Cp& __x, const _Cp& __y) const {
716 return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y.__get_value().first);
714 return static_cast<const _Pred&>(*this)(__x.first, __y.first);
717715 }
718716 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Cp& __x, const _Key& __y) const {
719 return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);
717 return static_cast<const _Pred&>(*this)(__x.first, __y);
720718 }
721719 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _Cp& __y) const {
722720 return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);
......@@ -724,7 +722,7 @@ public:
724722# if _LIBCPP_STD_VER >= 20
725723 template <typename _K2>
726724 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Cp& __x, const _K2& __y) const {
727 return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);
725 return static_cast<const _Pred&>(*this)(__x.first, __y);
728726 }
729727 template <typename _K2>
730728 _LIBCPP_HIDE_FROM_ABI bool operator()(const _K2& __x, const _Cp& __y) const {
......@@ -755,23 +753,17 @@ public:
755753 _LIBCPP_HIDE_FROM_ABI __unordered_map_equal(const _Pred& __p) _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
756754 : __pred_(__p) {}
757755 _LIBCPP_HIDE_FROM_ABI const _Pred& key_eq() const _NOEXCEPT { return __pred_; }
758 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Cp& __x, const _Cp& __y) const {
759 return __pred_(__x.__get_value().first, __y.__get_value().first);
760 }
761 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Cp& __x, const _Key& __y) const {
762 return __pred_(__x.__get_value().first, __y);
763 }
764 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _Cp& __y) const {
765 return __pred_(__x, __y.__get_value().first);
766 }
756 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Cp& __x, const _Cp& __y) const { return __pred_(__x.first, __y.first); }
757 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Cp& __x, const _Key& __y) const { return __pred_(__x.first, __y); }
758 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _Cp& __y) const { return __pred_(__x, __y.first); }
767759# if _LIBCPP_STD_VER >= 20
768760 template <typename _K2>
769761 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Cp& __x, const _K2& __y) const {
770 return __pred_(__x.__get_value().first, __y);
762 return __pred_(__x.first, __y);
771763 }
772764 template <typename _K2>
773765 _LIBCPP_HIDE_FROM_ABI bool operator()(const _K2& __x, const _Cp& __y) const {
774 return __pred_(__x, __y.__get_value().first);
766 return __pred_(__x, __y.first);
775767 }
776768 template <typename _K2>
777769 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _K2& __y) const {
......@@ -833,99 +825,19 @@ public:
833825
834826 _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT {
835827 if (__second_constructed)
836 __alloc_traits::destroy(__na_, std::addressof(__p->__get_value().__get_value().second));
828 __alloc_traits::destroy(__na_, std::addressof(__p->__get_value().second));
837829 if (__first_constructed)
838 __alloc_traits::destroy(__na_, std::addressof(__p->__get_value().__get_value().first));
830 __alloc_traits::destroy(__na_, std::addressof(__p->__get_value().first));
839831 if (__p)
840832 __alloc_traits::deallocate(__na_, __p, 1);
841833 }
842834};
843835
844# ifndef _LIBCPP_CXX03_LANG
845836template <class _Key, class _Tp>
846struct _LIBCPP_STANDALONE_DEBUG __hash_value_type {
847 typedef _Key key_type;
848 typedef _Tp mapped_type;
849 typedef pair<const key_type, mapped_type> value_type;
850 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
851 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
852
853private:
854 value_type __cc_;
855
856public:
857 _LIBCPP_HIDE_FROM_ABI value_type& __get_value() {
858# if _LIBCPP_STD_VER >= 17
859 return *std::launder(std::addressof(__cc_));
860# else
861 return __cc_;
862# endif
863 }
864
865 _LIBCPP_HIDE_FROM_ABI const value_type& __get_value() const {
866# if _LIBCPP_STD_VER >= 17
867 return *std::launder(std::addressof(__cc_));
868# else
869 return __cc_;
870# endif
871 }
872
873 _LIBCPP_HIDE_FROM_ABI __nc_ref_pair_type __ref() {
874 value_type& __v = __get_value();
875 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
876 }
877
878 _LIBCPP_HIDE_FROM_ABI __nc_rref_pair_type __move() {
879 value_type& __v = __get_value();
880 return __nc_rref_pair_type(std::move(const_cast<key_type&>(__v.first)), std::move(__v.second));
881 }
882
883 _LIBCPP_HIDE_FROM_ABI __hash_value_type& operator=(const __hash_value_type& __v) {
884 __ref() = __v.__get_value();
885 return *this;
886 }
887
888 _LIBCPP_HIDE_FROM_ABI __hash_value_type& operator=(__hash_value_type&& __v) {
889 __ref() = __v.__move();
890 return *this;
891 }
892
893 template <class _ValueTp, __enable_if_t<__is_same_uncvref<_ValueTp, value_type>::value, int> = 0>
894 _LIBCPP_HIDE_FROM_ABI __hash_value_type& operator=(_ValueTp&& __v) {
895 __ref() = std::forward<_ValueTp>(__v);
896 return *this;
897 }
898
899 __hash_value_type(const __hash_value_type& __v) = delete;
900 __hash_value_type(__hash_value_type&& __v) = delete;
901 template <class... _Args>
902 explicit __hash_value_type(_Args&&... __args) = delete;
903
904 ~__hash_value_type() = delete;
905};
906
907# else
908
909template <class _Key, class _Tp>
910struct __hash_value_type {
911 typedef _Key key_type;
912 typedef _Tp mapped_type;
913 typedef pair<const key_type, mapped_type> value_type;
914
915private:
916 value_type __cc_;
917
918public:
919 _LIBCPP_HIDE_FROM_ABI value_type& __get_value() { return __cc_; }
920 _LIBCPP_HIDE_FROM_ABI const value_type& __get_value() const { return __cc_; }
921
922 ~__hash_value_type() = delete;
923};
924
925# endif
837struct __hash_value_type;
926838
927839template <class _HashIterator>
928class _LIBCPP_TEMPLATE_VIS __hash_map_iterator {
840class __hash_map_iterator {
929841 _HashIterator __i_;
930842
931843 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
......@@ -941,8 +853,8 @@ public:
941853
942854 _LIBCPP_HIDE_FROM_ABI __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
943855
944 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __i_->__get_value(); }
945 _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
856 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return *__i_; }
857 _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(*__i_); }
946858
947859 _LIBCPP_HIDE_FROM_ABI __hash_map_iterator& operator++() {
948860 ++__i_;
......@@ -964,19 +876,19 @@ public:
964876# endif
965877
966878 template <class, class, class, class, class>
967 friend class _LIBCPP_TEMPLATE_VIS unordered_map;
879 friend class unordered_map;
968880 template <class, class, class, class, class>
969 friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
881 friend class unordered_multimap;
970882 template <class>
971 friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
883 friend class __hash_const_iterator;
972884 template <class>
973 friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
885 friend class __hash_const_local_iterator;
974886 template <class>
975 friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
887 friend class __hash_map_const_iterator;
976888};
977889
978890template <class _HashIterator>
979class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator {
891class __hash_map_const_iterator {
980892 _HashIterator __i_;
981893
982894 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
......@@ -995,8 +907,8 @@ public:
995907 __hash_map_const_iterator(__hash_map_iterator<typename _HashIterator::__non_const_iterator> __i) _NOEXCEPT
996908 : __i_(__i.__i_) {}
997909
998 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __i_->__get_value(); }
999 _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
910 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return *__i_; }
911 _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(*__i_); }
1000912
1001913 _LIBCPP_HIDE_FROM_ABI __hash_map_const_iterator& operator++() {
1002914 ++__i_;
......@@ -1020,13 +932,13 @@ public:
1020932# endif
1021933
1022934 template <class, class, class, class, class>
1023 friend class _LIBCPP_TEMPLATE_VIS unordered_map;
935 friend class unordered_map;
1024936 template <class, class, class, class, class>
1025 friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
937 friend class unordered_multimap;
1026938 template <class>
1027 friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
939 friend class __hash_const_iterator;
1028940 template <class>
1029 friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
941 friend class __hash_const_local_iterator;
1030942};
1031943
1032944template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -1037,7 +949,7 @@ template <class _Key,
1037949 class _Hash = hash<_Key>,
1038950 class _Pred = equal_to<_Key>,
1039951 class _Alloc = allocator<pair<const _Key, _Tp> > >
1040class _LIBCPP_TEMPLATE_VIS unordered_map {
952class unordered_map {
1041953public:
1042954 // types
1043955 typedef _Key key_type;
......@@ -1053,11 +965,10 @@ public:
1053965
1054966private:
1055967 typedef __hash_value_type<key_type, mapped_type> __value_type;
1056 typedef __unordered_map_hasher<key_type, __value_type, hasher, key_equal> __hasher;
1057 typedef __unordered_map_equal<key_type, __value_type, key_equal, hasher> __key_equal;
1058 typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
968 typedef __unordered_map_hasher<key_type, value_type, hasher, key_equal> __hasher;
969 typedef __unordered_map_equal<key_type, value_type, key_equal, hasher> __key_equal;
1059970
1060 typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table;
971 typedef __hash_table<__value_type, __hasher, __key_equal, allocator_type> __table;
1061972
1062973 __table __table_;
1063974
......@@ -1073,9 +984,6 @@ private:
1073984
1074985 static_assert(__check_valid_allocator<allocator_type>::value, "");
1075986
1076 static_assert(is_same<typename __table::__container_value_type, value_type>::value, "");
1077 static_assert(is_same<typename __table::__node_value_type, __value_type>::value, "");
1078
1079987public:
1080988 typedef typename __alloc_traits::pointer pointer;
1081989 typedef typename __alloc_traits::const_pointer const_pointer;
......@@ -1093,9 +1001,9 @@ public:
10931001# endif
10941002
10951003 template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
1096 friend class _LIBCPP_TEMPLATE_VIS unordered_map;
1004 friend class unordered_map;
10971005 template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
1098 friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
1006 friend class unordered_multimap;
10991007
11001008 _LIBCPP_HIDE_FROM_ABI unordered_map() _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) {}
11011009 explicit _LIBCPP_HIDE_FROM_ABI
......@@ -1227,7 +1135,7 @@ public:
12271135 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return __table_.begin(); }
12281136 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return __table_.end(); }
12291137
1230 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __x) { return __table_.__insert_unique(__x); }
1138 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __x) { return __table_.__emplace_unique(__x); }
12311139
12321140 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x).first; }
12331141
......@@ -1238,7 +1146,7 @@ public:
12381146 template <_ContainerCompatibleRange<value_type> _Range>
12391147 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
12401148 for (auto&& __element : __range) {
1241 __table_.__insert_unique(std::forward<decltype(__element)>(__element));
1149 __table_.__emplace_unique(std::forward<decltype(__element)>(__element));
12421150 }
12431151 }
12441152# endif
......@@ -1247,16 +1155,16 @@ public:
12471155 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
12481156
12491157 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __x) {
1250 return __table_.__insert_unique(std::move(__x));
1158 return __table_.__emplace_unique(std::move(__x));
12511159 }
12521160
12531161 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, value_type&& __x) {
1254 return __table_.__insert_unique(std::move(__x)).first;
1162 return __table_.__emplace_unique(std::move(__x)).first;
12551163 }
12561164
12571165 template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
12581166 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(_Pp&& __x) {
1259 return __table_.__insert_unique(std::forward<_Pp>(__x));
1167 return __table_.__emplace_unique(std::forward<_Pp>(__x));
12601168 }
12611169
12621170 template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
......@@ -1680,9 +1588,8 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(unordered_map&& __
16801588 : __table_(std::move(__u.__table_), typename __table::allocator_type(__a)) {
16811589 if (__a != __u.get_allocator()) {
16821590 iterator __i = __u.begin();
1683 while (__u.size() != 0) {
1684 __table_.__emplace_unique(__u.__table_.remove((__i++).__i_)->__get_value().__move());
1685 }
1591 while (__u.size() != 0)
1592 __table_.__insert_unique_from_orphaned_node(std::move(__u.__table_.remove((__i++).__i_)->__get_value()));
16861593 }
16871594}
16881595
......@@ -1732,7 +1639,7 @@ template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
17321639template <class _InputIterator>
17331640inline void unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
17341641 for (; __first != __last; ++__first)
1735 __table_.__insert_unique(*__first);
1642 __table_.__emplace_unique(*__first);
17361643}
17371644
17381645# ifndef _LIBCPP_CXX03_LANG
......@@ -1741,8 +1648,7 @@ template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
17411648_Tp& unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) {
17421649 return __table_
17431650 .__emplace_unique_key_args(__k, piecewise_construct, std::forward_as_tuple(__k), std::forward_as_tuple())
1744 .first->__get_value()
1745 .second;
1651 .first->second;
17461652}
17471653
17481654template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -1750,8 +1656,7 @@ _Tp& unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
17501656 return __table_
17511657 .__emplace_unique_key_args(
17521658 __k, piecewise_construct, std::forward_as_tuple(std::move(__k)), std::forward_as_tuple())
1753 .first->__get_value()
1754 .second;
1659 .first->second;
17551660}
17561661# else // _LIBCPP_CXX03_LANG
17571662
......@@ -1760,9 +1665,9 @@ typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
17601665unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k) {
17611666 __node_allocator& __na = __table_.__node_alloc();
17621667 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1763 __node_traits::construct(__na, std::addressof(__h->__get_value().__get_value().first), __k);
1668 __node_traits::construct(__na, std::addressof(__h->__get_value().first), __k);
17641669 __h.get_deleter().__first_constructed = true;
1765 __node_traits::construct(__na, std::addressof(__h->__get_value().__get_value().second));
1670 __node_traits::construct(__na, std::addressof(__h->__get_value().second));
17661671 __h.get_deleter().__second_constructed = true;
17671672 return __h;
17681673}
......@@ -1784,7 +1689,7 @@ template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
17841689_Tp& unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) {
17851690 iterator __i = find(__k);
17861691 if (__i == end())
1787 __throw_out_of_range("unordered_map::at: key not found");
1692 std::__throw_out_of_range("unordered_map::at: key not found");
17881693 return __i->second;
17891694}
17901695
......@@ -1792,7 +1697,7 @@ template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
17921697const _Tp& unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const {
17931698 const_iterator __i = find(__k);
17941699 if (__i == end())
1795 __throw_out_of_range("unordered_map::at: key not found");
1700 std::__throw_out_of_range("unordered_map::at: key not found");
17961701 return __i->second;
17971702}
17981703
......@@ -1843,6 +1748,8 @@ struct __container_traits<unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc> > {
18431748 // inserting a single element, the insertion has no effect.
18441749 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
18451750 __is_nothrow_invocable_v<_Hash, const _Key&>;
1751
1752 static _LIBCPP_CONSTEXPR const bool __reservable = true;
18461753};
18471754
18481755template <class _Key,
......@@ -1850,7 +1757,7 @@ template <class _Key,
18501757 class _Hash = hash<_Key>,
18511758 class _Pred = equal_to<_Key>,
18521759 class _Alloc = allocator<pair<const _Key, _Tp> > >
1853class _LIBCPP_TEMPLATE_VIS unordered_multimap {
1760class unordered_multimap {
18541761public:
18551762 // types
18561763 typedef _Key key_type;
......@@ -1867,11 +1774,10 @@ public:
18671774
18681775private:
18691776 typedef __hash_value_type<key_type, mapped_type> __value_type;
1870 typedef __unordered_map_hasher<key_type, __value_type, hasher, key_equal> __hasher;
1871 typedef __unordered_map_equal<key_type, __value_type, key_equal, hasher> __key_equal;
1872 typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
1777 typedef __unordered_map_hasher<key_type, value_type, hasher, key_equal> __hasher;
1778 typedef __unordered_map_equal<key_type, value_type, key_equal, hasher> __key_equal;
18731779
1874 typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table;
1780 typedef __hash_table<__value_type, __hasher, __key_equal, allocator_type> __table;
18751781
18761782 __table __table_;
18771783
......@@ -1901,9 +1807,9 @@ public:
19011807# endif
19021808
19031809 template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
1904 friend class _LIBCPP_TEMPLATE_VIS unordered_map;
1810 friend class unordered_map;
19051811 template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
1906 friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
1812 friend class unordered_multimap;
19071813
19081814 _LIBCPP_HIDE_FROM_ABI unordered_multimap() _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) {}
19091815 explicit _LIBCPP_HIDE_FROM_ABI
......@@ -2036,10 +1942,10 @@ public:
20361942 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return __table_.begin(); }
20371943 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return __table_.end(); }
20381944
2039 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__insert_multi(__x); }
1945 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__emplace_multi(__x); }
20401946
20411947 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __x) {
2042 return __table_.__insert_multi(__p.__i_, __x);
1948 return __table_.__emplace_hint_multi(__p.__i_, __x);
20431949 }
20441950
20451951 template <class _InputIterator>
......@@ -2049,27 +1955,27 @@ public:
20491955 template <_ContainerCompatibleRange<value_type> _Range>
20501956 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
20511957 for (auto&& __element : __range) {
2052 __table_.__insert_multi(std::forward<decltype(__element)>(__element));
1958 __table_.__emplace_multi(std::forward<decltype(__element)>(__element));
20531959 }
20541960 }
20551961# endif
20561962
20571963# ifndef _LIBCPP_CXX03_LANG
20581964 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
2059 _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __x) { return __table_.__insert_multi(std::move(__x)); }
1965 _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __x) { return __table_.__emplace_multi(std::move(__x)); }
20601966
20611967 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __x) {
2062 return __table_.__insert_multi(__p.__i_, std::move(__x));
1968 return __table_.__emplace_hint_multi(__p.__i_, std::move(__x));
20631969 }
20641970
20651971 template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
20661972 _LIBCPP_HIDE_FROM_ABI iterator insert(_Pp&& __x) {
2067 return __table_.__insert_multi(std::forward<_Pp>(__x));
1973 return __table_.__emplace_multi(std::forward<_Pp>(__x));
20681974 }
20691975
20701976 template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
20711977 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, _Pp&& __x) {
2072 return __table_.__insert_multi(__p.__i_, std::forward<_Pp>(__x));
1978 return __table_.__emplace_hint_multi(__p.__i_, std::forward<_Pp>(__x));
20731979 }
20741980
20751981 template <class... _Args>
......@@ -2437,9 +2343,8 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
24372343 : __table_(std::move(__u.__table_), typename __table::allocator_type(__a)) {
24382344 if (__a != __u.get_allocator()) {
24392345 iterator __i = __u.begin();
2440 while (__u.size() != 0) {
2441 __table_.__insert_multi(__u.__table_.remove((__i++).__i_)->__get_value().__move());
2442 }
2346 while (__u.size() != 0)
2347 __table_.__insert_multi_from_orphaned_node(std::move(__u.__table_.remove((__i++).__i_)->__get_value()));
24432348 }
24442349}
24452350
......@@ -2489,7 +2394,7 @@ template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
24892394template <class _InputIterator>
24902395inline void unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
24912396 for (; __first != __last; ++__first)
2492 __table_.__insert_multi(*__first);
2397 __table_.__emplace_multi(*__first);
24932398}
24942399
24952400template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
......@@ -2543,6 +2448,8 @@ struct __container_traits<unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc> >
25432448 // inserting a single element, the insertion has no effect.
25442449 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
25452450 __is_nothrow_invocable_v<_Hash, const _Key&>;
2451
2452 static _LIBCPP_CONSTEXPR const bool __reservable = true;
25462453};
25472454
25482455_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/unordered_set+22-18
......@@ -594,7 +594,7 @@ template <class _Value, class _Hash, class _Pred, class _Alloc>
594594class unordered_multiset;
595595
596596template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, class _Alloc = allocator<_Value> >
597class _LIBCPP_TEMPLATE_VIS unordered_set {
597class unordered_set {
598598public:
599599 // types
600600 typedef _Value key_type;
......@@ -630,9 +630,9 @@ public:
630630# endif
631631
632632 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
633 friend class _LIBCPP_TEMPLATE_VIS unordered_set;
633 friend class unordered_set;
634634 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
635 friend class _LIBCPP_TEMPLATE_VIS unordered_multiset;
635 friend class unordered_multiset;
636636
637637 _LIBCPP_HIDE_FROM_ABI unordered_set() _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) {}
638638 explicit _LIBCPP_HIDE_FROM_ABI
......@@ -769,13 +769,13 @@ public:
769769 }
770770
771771 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __x) {
772 return __table_.__insert_unique(std::move(__x));
772 return __table_.__emplace_unique(std::move(__x));
773773 }
774774 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, value_type&& __x) { return insert(std::move(__x)).first; }
775775
776776 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
777777# endif // _LIBCPP_CXX03_LANG
778 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __x) { return __table_.__insert_unique(__x); }
778 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __x) { return __table_.__emplace_unique(__x); }
779779
780780 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x).first; }
781781 template <class _InputIterator>
......@@ -785,7 +785,7 @@ public:
785785 template <_ContainerCompatibleRange<value_type> _Range>
786786 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
787787 for (auto&& __element : __range) {
788 __table_.__insert_unique(std::forward<decltype(__element)>(__element));
788 __table_.__emplace_unique(std::forward<decltype(__element)>(__element));
789789 }
790790 }
791791# endif
......@@ -1096,7 +1096,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(unordered_set&& __u,
10961096 if (__a != __u.get_allocator()) {
10971097 iterator __i = __u.begin();
10981098 while (__u.size() != 0)
1099 __table_.__insert_unique(std::move(__u.__table_.remove(__i++)->__get_value()));
1099 __table_.__emplace_unique(std::move(__u.__table_.remove(__i++)->__get_value()));
11001100 }
11011101}
11021102
......@@ -1146,7 +1146,7 @@ template <class _Value, class _Hash, class _Pred, class _Alloc>
11461146template <class _InputIterator>
11471147inline void unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
11481148 for (; __first != __last; ++__first)
1149 __table_.__insert_unique(*__first);
1149 __table_.__emplace_unique(*__first);
11501150}
11511151
11521152template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -1196,10 +1196,12 @@ struct __container_traits<unordered_set<_Value, _Hash, _Pred, _Alloc> > {
11961196 // inserting a single element, the insertion has no effect.
11971197 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
11981198 __is_nothrow_invocable_v<_Hash, const _Value&>;
1199
1200 static _LIBCPP_CONSTEXPR const bool __reservable = true;
11991201};
12001202
12011203template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, class _Alloc = allocator<_Value> >
1202class _LIBCPP_TEMPLATE_VIS unordered_multiset {
1204class unordered_multiset {
12031205public:
12041206 // types
12051207 typedef _Value key_type;
......@@ -1233,9 +1235,9 @@ public:
12331235# endif
12341236
12351237 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
1236 friend class _LIBCPP_TEMPLATE_VIS unordered_set;
1238 friend class unordered_set;
12371239 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
1238 friend class _LIBCPP_TEMPLATE_VIS unordered_multiset;
1240 friend class unordered_multiset;
12391241
12401242 _LIBCPP_HIDE_FROM_ABI unordered_multiset() _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) {}
12411243 explicit _LIBCPP_HIDE_FROM_ABI
......@@ -1372,17 +1374,17 @@ public:
13721374 return __table_.__emplace_hint_multi(__p, std::forward<_Args>(__args)...);
13731375 }
13741376
1375 _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __x) { return __table_.__insert_multi(std::move(__x)); }
1377 _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __x) { return __table_.__emplace_multi(std::move(__x)); }
13761378 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __x) {
1377 return __table_.__insert_multi(__p, std::move(__x));
1379 return __table_.__emplace_hint_multi(__p, std::move(__x));
13781380 }
13791381 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
13801382# endif // _LIBCPP_CXX03_LANG
13811383
1382 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__insert_multi(__x); }
1384 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__emplace_multi(__x); }
13831385
13841386 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __x) {
1385 return __table_.__insert_multi(__p, __x);
1387 return __table_.__emplace_hint_multi(__p, __x);
13861388 }
13871389
13881390 template <class _InputIterator>
......@@ -1392,7 +1394,7 @@ public:
13921394 template <_ContainerCompatibleRange<value_type> _Range>
13931395 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
13941396 for (auto&& __element : __range) {
1395 __table_.__insert_multi(std::forward<decltype(__element)>(__element));
1397 __table_.__emplace_multi(std::forward<decltype(__element)>(__element));
13961398 }
13971399 }
13981400# endif
......@@ -1712,7 +1714,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
17121714 if (__a != __u.get_allocator()) {
17131715 iterator __i = __u.begin();
17141716 while (__u.size() != 0)
1715 __table_.__insert_multi(std::move(__u.__table_.remove(__i++)->__get_value()));
1717 __table_.__emplace_multi(std::move(__u.__table_.remove(__i++)->__get_value()));
17161718 }
17171719}
17181720
......@@ -1762,7 +1764,7 @@ template <class _Value, class _Hash, class _Pred, class _Alloc>
17621764template <class _InputIterator>
17631765inline void unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
17641766 for (; __first != __last; ++__first)
1765 __table_.__insert_multi(*__first);
1767 __table_.__emplace_multi(*__first);
17661768}
17671769
17681770template <class _Value, class _Hash, class _Pred, class _Alloc>
......@@ -1816,6 +1818,8 @@ struct __container_traits<unordered_multiset<_Value, _Hash, _Pred, _Alloc> > {
18161818 // inserting a single element, the insertion has no effect.
18171819 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
18181820 __is_nothrow_invocable_v<_Hash, const _Value&>;
1821
1822 static _LIBCPP_CONSTEXPR const bool __reservable = true;
18191823};
18201824
18211825_LIBCPP_END_NAMESPACE_STD
lib/libcxx/include/utility+4
......@@ -279,6 +279,10 @@ template <class T>
279279# include <__utility/unreachable.h>
280280# endif
281281
282# if _LIBCPP_STD_VER >= 26
283# include <__variant/monostate.h>
284# endif
285
282286# include <version>
283287
284288// standard-mandated includes
lib/libcxx/include/valarray+18-18
......@@ -382,9 +382,9 @@ _LIBCPP_PUSH_MACROS
382382_LIBCPP_BEGIN_NAMESPACE_STD
383383
384384template <class _Tp>
385class _LIBCPP_TEMPLATE_VIS valarray;
385class valarray;
386386
387class _LIBCPP_TEMPLATE_VIS slice {
387class slice {
388388 size_t __start_;
389389 size_t __size_;
390390 size_t __stride_;
......@@ -409,14 +409,14 @@ public:
409409};
410410
411411template <class _Tp>
412class _LIBCPP_TEMPLATE_VIS slice_array;
412class slice_array;
413413class _LIBCPP_EXPORTED_FROM_ABI gslice;
414414template <class _Tp>
415class _LIBCPP_TEMPLATE_VIS gslice_array;
415class gslice_array;
416416template <class _Tp>
417class _LIBCPP_TEMPLATE_VIS mask_array;
417class mask_array;
418418template <class _Tp>
419class _LIBCPP_TEMPLATE_VIS indirect_array;
419class indirect_array;
420420
421421template <class _Tp>
422422_LIBCPP_HIDE_FROM_ABI _Tp* begin(valarray<_Tp>& __v);
......@@ -638,7 +638,7 @@ public:
638638 template <class>
639639 friend class __val_expr;
640640 template <class>
641 friend class _LIBCPP_TEMPLATE_VIS valarray;
641 friend class valarray;
642642};
643643
644644template <class _ValExpr>
......@@ -780,7 +780,7 @@ template <class _Tp>
780780struct __val_expr_use_member_functions<indirect_array<_Tp> > : true_type {};
781781
782782template <class _Tp>
783class _LIBCPP_TEMPLATE_VIS valarray {
783class valarray {
784784public:
785785 typedef _Tp value_type;
786786 typedef _Tp __result_type;
......@@ -918,17 +918,17 @@ public:
918918
919919private:
920920 template <class>
921 friend class _LIBCPP_TEMPLATE_VIS valarray;
921 friend class valarray;
922922 template <class>
923 friend class _LIBCPP_TEMPLATE_VIS slice_array;
923 friend class slice_array;
924924 template <class>
925 friend class _LIBCPP_TEMPLATE_VIS gslice_array;
925 friend class gslice_array;
926926 template <class>
927 friend class _LIBCPP_TEMPLATE_VIS mask_array;
927 friend class mask_array;
928928 template <class>
929929 friend class __mask_expr;
930930 template <class>
931 friend class _LIBCPP_TEMPLATE_VIS indirect_array;
931 friend class indirect_array;
932932 template <class>
933933 friend class __indirect_expr;
934934 template <class>
......@@ -1038,7 +1038,7 @@ struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> > {
10381038// slice_array
10391039
10401040template <class _Tp>
1041class _LIBCPP_TEMPLATE_VIS slice_array {
1041class slice_array {
10421042public:
10431043 typedef _Tp value_type;
10441044
......@@ -1268,7 +1268,7 @@ private:
12681268// gslice_array
12691269
12701270template <class _Tp>
1271class _LIBCPP_TEMPLATE_VIS gslice_array {
1271class gslice_array {
12721272public:
12731273 typedef _Tp value_type;
12741274
......@@ -1453,7 +1453,7 @@ inline void gslice_array<_Tp>::operator=(const value_type& __x) const {
14531453// mask_array
14541454
14551455template <class _Tp>
1456class _LIBCPP_TEMPLATE_VIS mask_array {
1456class mask_array {
14571457public:
14581458 typedef _Tp value_type;
14591459
......@@ -1658,7 +1658,7 @@ public:
16581658// indirect_array
16591659
16601660template <class _Tp>
1661class _LIBCPP_TEMPLATE_VIS indirect_array {
1661class indirect_array {
16621662public:
16631663 typedef _Tp value_type;
16641664
......@@ -1860,7 +1860,7 @@ public:
18601860 template <class>
18611861 friend class __val_expr;
18621862 template <class>
1863 friend class _LIBCPP_TEMPLATE_VIS valarray;
1863 friend class valarray;
18641864};
18651865
18661866template <class _ValExpr>
lib/libcxx/include/variant+96-76
......@@ -213,7 +213,7 @@ namespace std {
213213*/
214214
215215#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
216# include <__cxx03/variant>
216# include <__cxx03/__config>
217217#else
218218# include <__compare/common_comparison_category.h>
219219# include <__compare/compare_three_way_result.h>
......@@ -242,10 +242,12 @@ namespace std {
242242# include <__type_traits/is_assignable.h>
243243# include <__type_traits/is_constructible.h>
244244# include <__type_traits/is_convertible.h>
245# include <__type_traits/is_core_convertible.h>
245246# include <__type_traits/is_destructible.h>
246247# include <__type_traits/is_nothrow_assignable.h>
247248# include <__type_traits/is_nothrow_constructible.h>
248249# include <__type_traits/is_reference.h>
250# include <__type_traits/is_replaceable.h>
249251# include <__type_traits/is_same.h>
250252# include <__type_traits/is_swappable.h>
251253# include <__type_traits/is_trivially_assignable.h>
......@@ -283,14 +285,14 @@ namespace std {
283285_LIBCPP_PUSH_MACROS
284286# include <__undef_macros>
285287
286namespace std { // explicitly not using versioning namespace
288_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD
287289
288class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS bad_variant_access : public exception {
290class _LIBCPP_EXPORTED_FROM_ABI bad_variant_access : public exception {
289291public:
290292 const char* what() const _NOEXCEPT override;
291293};
292294
293} // namespace std
295_LIBCPP_END_UNVERSIONED_NAMESPACE_STD
294296
295297_LIBCPP_BEGIN_NAMESPACE_STD
296298
......@@ -306,8 +308,7 @@ struct __farray {
306308 _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& operator[](size_t __n) const noexcept { return __buf_[__n]; }
307309};
308310
309[[noreturn]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS void
310__throw_bad_variant_access() {
311[[noreturn]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_variant_access() {
311312# if _LIBCPP_HAS_EXCEPTIONS
312313 throw bad_variant_access();
313314# else
......@@ -317,31 +318,31 @@ __throw_bad_variant_access() {
317318
318319// variant_size
319320template <class _Tp>
320struct _LIBCPP_TEMPLATE_VIS variant_size<const _Tp> : variant_size<_Tp> {};
321struct variant_size<const _Tp> : variant_size<_Tp> {};
321322
322323template <class _Tp>
323struct _LIBCPP_TEMPLATE_VIS variant_size<volatile _Tp> : variant_size<_Tp> {};
324struct variant_size<volatile _Tp> : variant_size<_Tp> {};
324325
325326template <class _Tp>
326struct _LIBCPP_TEMPLATE_VIS variant_size<const volatile _Tp> : variant_size<_Tp> {};
327struct variant_size<const volatile _Tp> : variant_size<_Tp> {};
327328
328329template <class... _Types>
329struct _LIBCPP_TEMPLATE_VIS variant_size<variant<_Types...>> : integral_constant<size_t, sizeof...(_Types)> {};
330struct variant_size<variant<_Types...>> : integral_constant<size_t, sizeof...(_Types)> {};
330331
331332// variant_alternative
332333template <size_t _Ip, class _Tp>
333struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const _Tp> : add_const<variant_alternative_t<_Ip, _Tp>> {};
334struct variant_alternative<_Ip, const _Tp> : add_const<variant_alternative_t<_Ip, _Tp>> {};
334335
335336template <size_t _Ip, class _Tp>
336struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, volatile _Tp> : add_volatile<variant_alternative_t<_Ip, _Tp>> {};
337struct variant_alternative<_Ip, volatile _Tp> : add_volatile<variant_alternative_t<_Ip, _Tp>> {};
337338
338339template <size_t _Ip, class _Tp>
339struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const volatile _Tp> : add_cv<variant_alternative_t<_Ip, _Tp>> {};
340struct variant_alternative<_Ip, const volatile _Tp> : add_cv<variant_alternative_t<_Ip, _Tp>> {};
340341
341342template <size_t _Ip, class... _Types>
342struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, variant<_Types...>> {
343struct variant_alternative<_Ip, variant<_Types...>> {
343344 static_assert(_Ip < sizeof...(_Types), "Index out of bounds in std::variant_alternative<>");
344 using type = __type_pack_element<_Ip, _Types...>;
345 using type _LIBCPP_NODEBUG = __type_pack_element<_Ip, _Types...>;
345346};
346347
347348template <size_t _NumAlternatives>
......@@ -409,7 +410,8 @@ template <>
409410struct __find_unambiguous_index_sfinae_impl<__ambiguous> {};
410411
411412template <class _Tp, class... _Types>
412struct __find_unambiguous_index_sfinae : __find_unambiguous_index_sfinae_impl<__find_index<_Tp, _Types...>()> {};
413struct __find_unambiguous_index_sfinae
414 : __find_unambiguous_index_sfinae_impl<__find_detail::__find_index<_Tp, _Types...>()> {};
413415
414416} // namespace __find_detail
415417
......@@ -657,7 +659,7 @@ private:
657659# define _LIBCPP_EAT_SEMICOLON static_assert(true, "")
658660
659661template <size_t _Index, class _Tp>
660struct _LIBCPP_TEMPLATE_VIS __alt {
662struct __alt {
661663 using __value_type _LIBCPP_NODEBUG = _Tp;
662664 static constexpr size_t __index = _Index;
663665
......@@ -669,14 +671,14 @@ struct _LIBCPP_TEMPLATE_VIS __alt {
669671};
670672
671673template <_Trait _DestructibleTrait, size_t _Index, class... _Types>
672union _LIBCPP_TEMPLATE_VIS __union;
674union __union;
673675
674676template <_Trait _DestructibleTrait, size_t _Index>
675union _LIBCPP_TEMPLATE_VIS __union<_DestructibleTrait, _Index> {};
677union __union<_DestructibleTrait, _Index> {};
676678
677679# define _LIBCPP_VARIANT_UNION(destructible_trait, destructor_definition) \
678680 template <size_t _Index, class _Tp, class... _Types> \
679 union _LIBCPP_TEMPLATE_VIS __union<destructible_trait, _Index, _Tp, _Types...> { \
681 union __union<destructible_trait, _Index, _Tp, _Types...> { \
680682 public: \
681683 _LIBCPP_HIDE_FROM_ABI explicit constexpr __union(__valueless_t) noexcept : __dummy{} {} \
682684 \
......@@ -711,7 +713,7 @@ _LIBCPP_VARIANT_UNION(_Trait::_Unavailable, _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTE
711713# undef _LIBCPP_VARIANT_UNION
712714
713715template <_Trait _DestructibleTrait, class... _Types>
714class _LIBCPP_TEMPLATE_VIS __base {
716class __base {
715717public:
716718 using __index_t _LIBCPP_NODEBUG = __variant_index_t<sizeof...(_Types)>;
717719
......@@ -747,12 +749,11 @@ protected:
747749};
748750
749751template <class _Traits, _Trait = _Traits::__destructible_trait>
750class _LIBCPP_TEMPLATE_VIS __dtor;
752class __dtor;
751753
752754# define _LIBCPP_VARIANT_DESTRUCTOR(destructible_trait, destructor_definition, destroy) \
753755 template <class... _Types> \
754 class _LIBCPP_TEMPLATE_VIS __dtor<__traits<_Types...>, destructible_trait> \
755 : public __base<destructible_trait, _Types...> { \
756 class __dtor<__traits<_Types...>, destructible_trait> : public __base<destructible_trait, _Types...> { \
756757 using __base_type _LIBCPP_NODEBUG = __base<destructible_trait, _Types...>; \
757758 using __index_t _LIBCPP_NODEBUG = typename __base_type::__index_t; \
758759 \
......@@ -798,7 +799,7 @@ _LIBCPP_VARIANT_DESTRUCTOR(_Trait::_Unavailable,
798799# undef _LIBCPP_VARIANT_DESTRUCTOR
799800
800801template <class _Traits>
801class _LIBCPP_TEMPLATE_VIS __ctor : public __dtor<_Traits> {
802class __ctor : public __dtor<_Traits> {
802803 using __base_type _LIBCPP_NODEBUG = __dtor<_Traits>;
803804
804805public:
......@@ -825,12 +826,11 @@ protected:
825826};
826827
827828template <class _Traits, _Trait = _Traits::__move_constructible_trait>
828class _LIBCPP_TEMPLATE_VIS __move_constructor;
829class __move_constructor;
829830
830831# define _LIBCPP_VARIANT_MOVE_CONSTRUCTOR(move_constructible_trait, move_constructor_definition) \
831832 template <class... _Types> \
832 class _LIBCPP_TEMPLATE_VIS __move_constructor<__traits<_Types...>, move_constructible_trait> \
833 : public __ctor<__traits<_Types...>> { \
833 class __move_constructor<__traits<_Types...>, move_constructible_trait> : public __ctor<__traits<_Types...>> { \
834834 using __base_type _LIBCPP_NODEBUG = __ctor<__traits<_Types...>>; \
835835 \
836836 public: \
......@@ -851,8 +851,7 @@ _LIBCPP_VARIANT_MOVE_CONSTRUCTOR(
851851_LIBCPP_VARIANT_MOVE_CONSTRUCTOR(
852852 _Trait::_Available,
853853 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __move_constructor(__move_constructor&& __that) noexcept(
854 __all<is_nothrow_move_constructible_v<_Types>...>::value)
855 : __move_constructor(__valueless_t{}) {
854 __all<is_nothrow_move_constructible_v<_Types>...>::value) : __move_constructor(__valueless_t{}) {
856855 this->__generic_construct(*this, std::move(__that));
857856 } _LIBCPP_EAT_SEMICOLON);
858857
......@@ -863,11 +862,11 @@ _LIBCPP_VARIANT_MOVE_CONSTRUCTOR(
863862# undef _LIBCPP_VARIANT_MOVE_CONSTRUCTOR
864863
865864template <class _Traits, _Trait = _Traits::__copy_constructible_trait>
866class _LIBCPP_TEMPLATE_VIS __copy_constructor;
865class __copy_constructor;
867866
868867# define _LIBCPP_VARIANT_COPY_CONSTRUCTOR(copy_constructible_trait, copy_constructor_definition) \
869868 template <class... _Types> \
870 class _LIBCPP_TEMPLATE_VIS __copy_constructor<__traits<_Types...>, copy_constructible_trait> \
869 class __copy_constructor<__traits<_Types...>, copy_constructible_trait> \
871870 : public __move_constructor<__traits<_Types...>> { \
872871 using __base_type _LIBCPP_NODEBUG = __move_constructor<__traits<_Types...>>; \
873872 \
......@@ -888,8 +887,9 @@ _LIBCPP_VARIANT_COPY_CONSTRUCTOR(
888887
889888_LIBCPP_VARIANT_COPY_CONSTRUCTOR(
890889 _Trait::_Available,
891 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __copy_constructor(const __copy_constructor& __that)
892 : __copy_constructor(__valueless_t{}) { this->__generic_construct(*this, __that); } _LIBCPP_EAT_SEMICOLON);
890 _LIBCPP_HIDE_FROM_ABI
891 _LIBCPP_CONSTEXPR_SINCE_CXX20 __copy_constructor(const __copy_constructor& __that) : __copy_constructor(
892 __valueless_t{}) { this->__generic_construct(*this, __that); } _LIBCPP_EAT_SEMICOLON);
893893
894894_LIBCPP_VARIANT_COPY_CONSTRUCTOR(
895895 _Trait::_Unavailable,
......@@ -898,7 +898,7 @@ _LIBCPP_VARIANT_COPY_CONSTRUCTOR(
898898# undef _LIBCPP_VARIANT_COPY_CONSTRUCTOR
899899
900900template <class _Traits>
901class _LIBCPP_TEMPLATE_VIS __assignment : public __copy_constructor<_Traits> {
901class __assignment : public __copy_constructor<_Traits> {
902902 using __base_type _LIBCPP_NODEBUG = __copy_constructor<_Traits>;
903903
904904public:
......@@ -952,12 +952,11 @@ protected:
952952};
953953
954954template <class _Traits, _Trait = _Traits::__move_assignable_trait>
955class _LIBCPP_TEMPLATE_VIS __move_assignment;
955class __move_assignment;
956956
957957# define _LIBCPP_VARIANT_MOVE_ASSIGNMENT(move_assignable_trait, move_assignment_definition) \
958958 template <class... _Types> \
959 class _LIBCPP_TEMPLATE_VIS __move_assignment<__traits<_Types...>, move_assignable_trait> \
960 : public __assignment<__traits<_Types...>> { \
959 class __move_assignment<__traits<_Types...>, move_assignable_trait> : public __assignment<__traits<_Types...>> { \
961960 using __base_type _LIBCPP_NODEBUG = __assignment<__traits<_Types...>>; \
962961 \
963962 public: \
......@@ -991,11 +990,11 @@ _LIBCPP_VARIANT_MOVE_ASSIGNMENT(
991990# undef _LIBCPP_VARIANT_MOVE_ASSIGNMENT
992991
993992template <class _Traits, _Trait = _Traits::__copy_assignable_trait>
994class _LIBCPP_TEMPLATE_VIS __copy_assignment;
993class __copy_assignment;
995994
996995# define _LIBCPP_VARIANT_COPY_ASSIGNMENT(copy_assignable_trait, copy_assignment_definition) \
997996 template <class... _Types> \
998 class _LIBCPP_TEMPLATE_VIS __copy_assignment<__traits<_Types...>, copy_assignable_trait> \
997 class __copy_assignment<__traits<_Types...>, copy_assignable_trait> \
999998 : public __move_assignment<__traits<_Types...>> { \
1000999 using __base_type _LIBCPP_NODEBUG = __move_assignment<__traits<_Types...>>; \
10011000 \
......@@ -1029,7 +1028,7 @@ _LIBCPP_VARIANT_COPY_ASSIGNMENT(_Trait::_Unavailable,
10291028# undef _LIBCPP_VARIANT_COPY_ASSIGNMENT
10301029
10311030template <class... _Types>
1032class _LIBCPP_TEMPLATE_VIS __impl : public __copy_assignment<__traits<_Types...>> {
1031class __impl : public __copy_assignment<__traits<_Types...>> {
10331032 using __base_type _LIBCPP_NODEBUG = __copy_assignment<__traits<_Types...>>;
10341033
10351034public:
......@@ -1143,20 +1142,18 @@ using __best_match_t _LIBCPP_NODEBUG = typename invoke_result_t<_MakeOverloads<_
11431142} // namespace __variant_detail
11441143
11451144template <class _Visitor, class... _Vs, typename = void_t<decltype(std::__as_variant(std::declval<_Vs>()))...>>
1146_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr decltype(auto)
1147visit(_Visitor&& __visitor, _Vs&&... __vs);
1145_LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) visit(_Visitor&& __visitor, _Vs&&... __vs);
11481146
11491147# if _LIBCPP_STD_VER >= 20
11501148template <class _Rp,
11511149 class _Visitor,
11521150 class... _Vs,
11531151 typename = void_t<decltype(std::__as_variant(std::declval<_Vs>()))...>>
1154_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Rp
1155visit(_Visitor&& __visitor, _Vs&&... __vs);
1152_LIBCPP_HIDE_FROM_ABI constexpr _Rp visit(_Visitor&& __visitor, _Vs&&... __vs);
11561153# endif
11571154
11581155template <class... _Types>
1159class _LIBCPP_TEMPLATE_VIS _LIBCPP_DECLSPEC_EMPTY_BASES _LIBCPP_NO_SPECIALIZATIONS variant
1156class _LIBCPP_DECLSPEC_EMPTY_BASES _LIBCPP_NO_SPECIALIZATIONS variant
11601157 : private __sfinae_ctor_base< __all<is_copy_constructible_v<_Types>...>::value,
11611158 __all<is_move_constructible_v<_Types>...>::value>,
11621159 private __sfinae_assign_base<
......@@ -1175,6 +1172,7 @@ class _LIBCPP_TEMPLATE_VIS _LIBCPP_DECLSPEC_EMPTY_BASES _LIBCPP_NO_SPECIALIZATIO
11751172public:
11761173 using __trivially_relocatable _LIBCPP_NODEBUG =
11771174 conditional_t<_And<__libcpp_is_trivially_relocatable<_Types>...>::value, variant, void>;
1175 using __replaceable _LIBCPP_NODEBUG = conditional_t<_And<__is_replaceable<_Types>...>::value, variant, void>;
11781176
11791177 template <bool _Dummy = true,
11801178 enable_if_t<__dependent_type<is_default_constructible<__first_type>, _Dummy>::value, int> = 0>
......@@ -1338,35 +1336,30 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool holds_alternative(const variant<_Types...>&
13381336}
13391337
13401338template <size_t _Ip, class _Vp>
1341_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr auto&& __generic_get(_Vp&& __v) {
1339_LIBCPP_HIDE_FROM_ABI constexpr auto&& __generic_get(_Vp&& __v) {
13421340 using __variant_detail::__access::__variant;
13431341 if (!std::__holds_alternative<_Ip>(__v)) {
1344 __throw_bad_variant_access();
1342 std::__throw_bad_variant_access();
13451343 }
13461344 return __variant::__get_alt<_Ip>(std::forward<_Vp>(__v)).__value;
13471345}
13481346
13491347template <size_t _Ip, class... _Types>
1350_LIBCPP_HIDE_FROM_ABI
1351_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr variant_alternative_t<_Ip, variant<_Types...>>&
1352get(variant<_Types...>& __v) {
1348_LIBCPP_HIDE_FROM_ABI constexpr variant_alternative_t<_Ip, variant<_Types...>>& get(variant<_Types...>& __v) {
13531349 static_assert(_Ip < sizeof...(_Types));
13541350 static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
13551351 return std::__generic_get<_Ip>(__v);
13561352}
13571353
13581354template <size_t _Ip, class... _Types>
1359_LIBCPP_HIDE_FROM_ABI
1360_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr variant_alternative_t<_Ip, variant<_Types...>>&&
1361get(variant<_Types...>&& __v) {
1355_LIBCPP_HIDE_FROM_ABI constexpr variant_alternative_t<_Ip, variant<_Types...>>&& get(variant<_Types...>&& __v) {
13621356 static_assert(_Ip < sizeof...(_Types));
13631357 static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
13641358 return std::__generic_get<_Ip>(std::move(__v));
13651359}
13661360
13671361template <size_t _Ip, class... _Types>
1368_LIBCPP_HIDE_FROM_ABI
1369_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const variant_alternative_t<_Ip, variant<_Types...>>&
1362_LIBCPP_HIDE_FROM_ABI constexpr const variant_alternative_t<_Ip, variant<_Types...>>&
13701363get(const variant<_Types...>& __v) {
13711364 static_assert(_Ip < sizeof...(_Types));
13721365 static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
......@@ -1374,8 +1367,7 @@ get(const variant<_Types...>& __v) {
13741367}
13751368
13761369template <size_t _Ip, class... _Types>
1377_LIBCPP_HIDE_FROM_ABI
1378_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const variant_alternative_t<_Ip, variant<_Types...>>&&
1370_LIBCPP_HIDE_FROM_ABI constexpr const variant_alternative_t<_Ip, variant<_Types...>>&&
13791371get(const variant<_Types...>&& __v) {
13801372 static_assert(_Ip < sizeof...(_Types));
13811373 static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
......@@ -1383,27 +1375,25 @@ get(const variant<_Types...>&& __v) {
13831375}
13841376
13851377template <class _Tp, class... _Types>
1386_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Tp& get(variant<_Types...>& __v) {
1378_LIBCPP_HIDE_FROM_ABI constexpr _Tp& get(variant<_Types...>& __v) {
13871379 static_assert(!is_void_v<_Tp>);
13881380 return std::get<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
13891381}
13901382
13911383template <class _Tp, class... _Types>
1392_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Tp&& get(variant<_Types...>&& __v) {
1384_LIBCPP_HIDE_FROM_ABI constexpr _Tp&& get(variant<_Types...>&& __v) {
13931385 static_assert(!is_void_v<_Tp>);
13941386 return std::get<__find_exactly_one_t<_Tp, _Types...>::value>(std::move(__v));
13951387}
13961388
13971389template <class _Tp, class... _Types>
1398_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const _Tp&
1399get(const variant<_Types...>& __v) {
1390_LIBCPP_HIDE_FROM_ABI constexpr const _Tp& get(const variant<_Types...>& __v) {
14001391 static_assert(!is_void_v<_Tp>);
14011392 return std::get<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
14021393}
14031394
14041395template <class _Tp, class... _Types>
1405_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const _Tp&&
1406get(const variant<_Types...>&& __v) {
1396_LIBCPP_HIDE_FROM_ABI constexpr const _Tp&& get(const variant<_Types...>&& __v) {
14071397 static_assert(!is_void_v<_Tp>);
14081398 return std::get<__find_exactly_one_t<_Tp, _Types...>::value>(std::move(__v));
14091399}
......@@ -1453,6 +1443,11 @@ struct __convert_to_bool {
14531443};
14541444
14551445template <class... _Types>
1446# if _LIBCPP_STD_VER >= 26
1447 requires(requires(const _Types& __t) {
1448 { __t == __t } -> __core_convertible_to<bool>;
1449 } && ...)
1450# endif
14561451_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) {
14571452 using __variant_detail::__visitation::__variant;
14581453 if (__lhs.index() != __rhs.index())
......@@ -1485,6 +1480,11 @@ operator<=>(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) {
14851480# endif // _LIBCPP_STD_VER >= 20
14861481
14871482template <class... _Types>
1483# if _LIBCPP_STD_VER >= 26
1484 requires(requires(const _Types& __t) {
1485 { __t != __t } -> __core_convertible_to<bool>;
1486 } && ...)
1487# endif
14881488_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) {
14891489 using __variant_detail::__visitation::__variant;
14901490 if (__lhs.index() != __rhs.index())
......@@ -1495,6 +1495,11 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const variant<_Types...>& __lhs,
14951495}
14961496
14971497template <class... _Types>
1498# if _LIBCPP_STD_VER >= 26
1499 requires(requires(const _Types& __t) {
1500 { __t < __t } -> __core_convertible_to<bool>;
1501 } && ...)
1502# endif
14981503_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) {
14991504 using __variant_detail::__visitation::__variant;
15001505 if (__rhs.valueless_by_exception())
......@@ -1509,6 +1514,11 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const variant<_Types...>& __lhs,
15091514}
15101515
15111516template <class... _Types>
1517# if _LIBCPP_STD_VER >= 26
1518 requires(requires(const _Types& __t) {
1519 { __t > __t } -> __core_convertible_to<bool>;
1520 } && ...)
1521# endif
15121522_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) {
15131523 using __variant_detail::__visitation::__variant;
15141524 if (__lhs.valueless_by_exception())
......@@ -1523,6 +1533,11 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const variant<_Types...>& __lhs,
15231533}
15241534
15251535template <class... _Types>
1536# if _LIBCPP_STD_VER >= 26
1537 requires(requires(const _Types& __t) {
1538 { __t <= __t } -> __core_convertible_to<bool>;
1539 } && ...)
1540# endif
15261541_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) {
15271542 using __variant_detail::__visitation::__variant;
15281543 if (__lhs.valueless_by_exception())
......@@ -1537,6 +1552,11 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const variant<_Types...>& __lhs,
15371552}
15381553
15391554template <class... _Types>
1555# if _LIBCPP_STD_VER >= 26
1556 requires(requires(const _Types& __t) {
1557 { __t >= __t } -> __core_convertible_to<bool>;
1558 } && ...)
1559# endif
15401560_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) {
15411561 using __variant_detail::__visitation::__variant;
15421562 if (__rhs.valueless_by_exception())
......@@ -1551,16 +1571,15 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const variant<_Types...>& __lhs,
15511571}
15521572
15531573template <class... _Vs>
1554_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr void __throw_if_valueless(_Vs&&... __vs) {
1574_LIBCPP_HIDE_FROM_ABI constexpr void __throw_if_valueless(_Vs&&... __vs) {
15551575 const bool __valueless = (... || std::__as_variant(__vs).valueless_by_exception());
15561576 if (__valueless) {
1557 __throw_bad_variant_access();
1577 std::__throw_bad_variant_access();
15581578 }
15591579}
15601580
15611581template < class _Visitor, class... _Vs, typename>
1562_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr decltype(auto)
1563visit(_Visitor&& __visitor, _Vs&&... __vs) {
1582_LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) visit(_Visitor&& __visitor, _Vs&&... __vs) {
15641583 using __variant_detail::__visitation::__variant;
15651584 std::__throw_if_valueless(std::forward<_Vs>(__vs)...);
15661585 return __variant::__visit_value(std::forward<_Visitor>(__visitor), std::forward<_Vs>(__vs)...);
......@@ -1568,8 +1587,7 @@ visit(_Visitor&& __visitor, _Vs&&... __vs) {
15681587
15691588# if _LIBCPP_STD_VER >= 20
15701589template < class _Rp, class _Visitor, class... _Vs, typename>
1571_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Rp
1572visit(_Visitor&& __visitor, _Vs&&... __vs) {
1590_LIBCPP_HIDE_FROM_ABI constexpr _Rp visit(_Visitor&& __visitor, _Vs&&... __vs) {
15731591 using __variant_detail::__visitation::__variant;
15741592 std::__throw_if_valueless(std::forward<_Vs>(__vs)...);
15751593 return __variant::__visit_value<_Rp>(std::forward<_Visitor>(__visitor), std::forward<_Vs>(__vs)...);
......@@ -1578,17 +1596,19 @@ visit(_Visitor&& __visitor, _Vs&&... __vs) {
15781596
15791597template <class... _Types>
15801598_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 auto
1581swap(variant<_Types...>& __lhs,
1582 variant<_Types...>& __rhs) noexcept(noexcept(__lhs.swap(__rhs))) -> decltype(__lhs.swap(__rhs)) {
1599swap(variant<_Types...>& __lhs, variant<_Types...>& __rhs) noexcept(noexcept(__lhs.swap(__rhs)))
1600 -> decltype(__lhs.swap(__rhs)) {
15831601 return __lhs.swap(__rhs);
15841602}
15851603
15861604template <class... _Types>
1587struct _LIBCPP_TEMPLATE_VIS hash< __enable_hash_helper<variant<_Types...>, remove_const_t<_Types>...>> {
1588 using argument_type = variant<_Types...>;
1589 using result_type = size_t;
1605struct hash< __enable_hash_helper<variant<_Types...>, remove_const_t<_Types>...>> {
1606# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1607 using argument_type _LIBCPP_DEPRECATED_IN_CXX17 = variant<_Types...>;
1608 using result_type _LIBCPP_DEPRECATED_IN_CXX17 = size_t;
1609# endif
15901610
1591 _LIBCPP_HIDE_FROM_ABI result_type operator()(const argument_type& __v) const {
1611 _LIBCPP_HIDE_FROM_ABI size_t operator()(const variant<_Types...>& __v) const {
15921612 using __variant_detail::__visitation::__variant;
15931613 size_t __res =
15941614 __v.valueless_by_exception()
lib/libcxx/include/vector+1
......@@ -362,6 +362,7 @@ template<class T, class charT> requires is-vector-bool-reference<T> // Since C++
362362# if _LIBCPP_HAS_LOCALIZATION
363363# include <locale>
364364# endif
365# include <optional>
365366# include <string>
366367# include <string_view>
367368# include <tuple>
lib/libcxx/include/version+24-7
......@@ -16,6 +16,7 @@
1616Macro name Value Headers
1717__cpp_lib_adaptor_iterator_pair_constructor 202106L <queue> <stack>
1818__cpp_lib_addressof_constexpr 201603L <memory>
19__cpp_lib_aligned_accessor 202411L <mdspan>
1920__cpp_lib_allocate_at_least 202302L <memory>
2021__cpp_lib_allocator_traits_is_always_equal 201411L <deque> <forward_list> <list>
2122 <map> <memory> <scoped_allocator>
......@@ -58,28 +59,34 @@ __cpp_lib_char8_t 201907L <atomic> <filesy
5859__cpp_lib_chrono 201611L <chrono>
5960__cpp_lib_chrono_udls 201304L <chrono>
6061__cpp_lib_clamp 201603L <algorithm>
62__cpp_lib_common_reference 202302L <type_traits>
63__cpp_lib_common_reference_wrapper 202302L <functional>
6164__cpp_lib_complex_udls 201309L <complex>
6265__cpp_lib_concepts 202002L <concepts>
63__cpp_lib_constexpr_algorithms 201806L <algorithm> <utility>
66__cpp_lib_constexpr_algorithms 202306L <algorithm> <utility>
67 201806L // C++20
6468__cpp_lib_constexpr_bitset 202207L <bitset>
6569__cpp_lib_constexpr_charconv 202207L <charconv>
6670__cpp_lib_constexpr_cmath 202202L <cmath> <cstdlib>
6771__cpp_lib_constexpr_complex 201711L <complex>
6872__cpp_lib_constexpr_dynamic_alloc 201907L <memory>
73__cpp_lib_constexpr_forward_list 202502L <forward_list>
6974__cpp_lib_constexpr_functional 201907L <functional>
7075__cpp_lib_constexpr_iterator 201811L <iterator>
76__cpp_lib_constexpr_list 202502L <list>
7177__cpp_lib_constexpr_memory 202202L <memory>
7278 201811L // C++20
7379__cpp_lib_constexpr_new 202406L <new>
7480__cpp_lib_constexpr_numeric 201911L <numeric>
81__cpp_lib_constexpr_queue 202502L <queue>
7582__cpp_lib_constexpr_string 201907L <string>
7683__cpp_lib_constexpr_string_view 201811L <string_view>
7784__cpp_lib_constexpr_tuple 201811L <tuple>
7885__cpp_lib_constexpr_typeinfo 202106L <typeinfo>
7986__cpp_lib_constexpr_utility 201811L <utility>
8087__cpp_lib_constexpr_vector 201907L <vector>
81__cpp_lib_constrained_equality 202403L <optional> <tuple> <utility>
82 <variant>
88__cpp_lib_constrained_equality 202411L <expected> <optional> <tuple>
89 <utility> <variant>
8390__cpp_lib_containers_ranges 202202L <deque> <forward_list> <list>
8491 <map> <queue> <set>
8592 <stack> <string> <unordered_map>
......@@ -147,6 +154,7 @@ __cpp_lib_is_nothrow_convertible 201806L <type_traits>
147154__cpp_lib_is_null_pointer 201309L <type_traits>
148155__cpp_lib_is_pointer_interconvertible 201907L <type_traits>
149156__cpp_lib_is_scoped_enum 202011L <type_traits>
157__cpp_lib_is_sufficiently_aligned 202411L <memory>
150158__cpp_lib_is_swappable 201603L <type_traits>
151159__cpp_lib_is_virtual_base_of 202406L <type_traits>
152160__cpp_lib_is_within_lifetime 202306L <type_traits>
......@@ -396,6 +404,8 @@ __cpp_lib_void_t 201411L <type_traits>
396404# if _LIBCPP_HAS_CHAR8_T
397405# define __cpp_lib_char8_t 201907L
398406# endif
407# define __cpp_lib_common_reference 202302L
408# define __cpp_lib_common_reference_wrapper 202302L
399409# define __cpp_lib_concepts 202002L
400410# define __cpp_lib_constexpr_algorithms 201806L
401411# define __cpp_lib_constexpr_complex 201711L
......@@ -485,7 +495,7 @@ __cpp_lib_void_t 201411L <type_traits>
485495# define __cpp_lib_containers_ranges 202202L
486496# define __cpp_lib_expected 202211L
487497# define __cpp_lib_flat_map 202207L
488// # define __cpp_lib_flat_set 202207L
498# define __cpp_lib_flat_set 202207L
489499# define __cpp_lib_format_ranges 202207L
490500// # define __cpp_lib_formatters 202302L
491501# define __cpp_lib_forward_like 202207L
......@@ -512,8 +522,8 @@ __cpp_lib_void_t 201411L <type_traits>
512522# define __cpp_lib_ranges_chunk_by 202202L
513523# define __cpp_lib_ranges_contains 202207L
514524# define __cpp_lib_ranges_find_last 202207L
515// # define __cpp_lib_ranges_iota 202202L
516// # define __cpp_lib_ranges_join_with 202202L
525# define __cpp_lib_ranges_iota 202202L
526# define __cpp_lib_ranges_join_with 202202L
517527# define __cpp_lib_ranges_repeat 202207L
518528// # define __cpp_lib_ranges_slide 202202L
519529# define __cpp_lib_ranges_starts_ends_with 202106L
......@@ -531,15 +541,21 @@ __cpp_lib_void_t 201411L <type_traits>
531541#endif
532542
533543#if _LIBCPP_STD_VER >= 26
544# define __cpp_lib_aligned_accessor 202411L
534545// # define __cpp_lib_associative_heterogeneous_insertion 202306L
535546// # define __cpp_lib_atomic_min_max 202403L
536547# undef __cpp_lib_bind_front
537548# define __cpp_lib_bind_front 202306L
538549# define __cpp_lib_bitset 202306L
550# undef __cpp_lib_constexpr_algorithms
551# define __cpp_lib_constexpr_algorithms 202306L
552# define __cpp_lib_constexpr_forward_list 202502L
553# define __cpp_lib_constexpr_list 202502L
539554# if !defined(_LIBCPP_ABI_VCRUNTIME)
540555# define __cpp_lib_constexpr_new 202406L
541556# endif
542// # define __cpp_lib_constrained_equality 202403L
557# define __cpp_lib_constexpr_queue 202502L
558// # define __cpp_lib_constrained_equality 202411L
543559// # define __cpp_lib_copyable_function 202306L
544560// # define __cpp_lib_debugging 202311L
545561// # define __cpp_lib_default_template_type_for_algorithm_values 202403L
......@@ -559,6 +575,7 @@ __cpp_lib_void_t 201411L <type_traits>
559575// # define __cpp_lib_generate_random 202403L
560576// # define __cpp_lib_hazard_pointer 202306L
561577// # define __cpp_lib_inplace_vector 202406L
578# define __cpp_lib_is_sufficiently_aligned 202411L
562579# if __has_builtin(__builtin_is_virtual_base_of)
563580# define __cpp_lib_is_virtual_base_of 202406L
564581# endif
lib/libcxx/src/any.cpp+1-1
......@@ -18,7 +18,7 @@ const char* bad_any_cast::what() const noexcept { return "bad any cast"; }
1818// Even though it no longer exists in a header file
1919_LIBCPP_BEGIN_NAMESPACE_LFTS
2020
21class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_BAD_ANY_CAST bad_any_cast : public bad_cast {
21class _LIBCPP_EXPORTED_FROM_ABI bad_any_cast : public bad_cast {
2222public:
2323 virtual const char* what() const noexcept;
2424};
lib/libcxx/src/atomic.cpp+5-2
......@@ -151,7 +151,10 @@ __libcpp_contention_monitor_for_wait(__cxx_atomic_contention_t volatile* /*__con
151151static void __libcpp_contention_wait(__cxx_atomic_contention_t volatile* __contention_state,
152152 __cxx_atomic_contention_t const volatile* __platform_state,
153153 __cxx_contention_t __old_value) {
154 __cxx_atomic_fetch_add(__contention_state, __cxx_contention_t(1), memory_order_seq_cst);
154 __cxx_atomic_fetch_add(__contention_state, __cxx_contention_t(1), memory_order_relaxed);
155 // https://github.com/llvm/llvm-project/issues/109290
156 // There are no platform guarantees of a memory barrier in the platform wait implementation
157 __cxx_atomic_thread_fence(memory_order_seq_cst);
155158 // We sleep as long as the monitored value hasn't changed.
156159 __libcpp_platform_wait_on_address(__platform_state, __old_value);
157160 __cxx_atomic_fetch_sub(__contention_state, __cxx_contention_t(1), memory_order_release);
......@@ -163,7 +166,7 @@ static void __libcpp_contention_wait(__cxx_atomic_contention_t volatile* __conte
163166static void __libcpp_atomic_notify(void const volatile* __location) {
164167 auto const __entry = __libcpp_contention_state(__location);
165168 // The value sequence laundering happens on the next line below.
166 __cxx_atomic_fetch_add(&__entry->__platform_state, __cxx_contention_t(1), memory_order_release);
169 __cxx_atomic_fetch_add(&__entry->__platform_state, __cxx_contention_t(1), memory_order_seq_cst);
167170 __libcpp_contention_notify(
168171 &__entry->__contention_state,
169172 &__entry->__platform_state,
lib/libcxx/src/call_once.cpp+1
......@@ -6,6 +6,7 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include <__config>
910#include <__mutex/once_flag.h>
1011#include <__utility/exception_guard.h>
1112
lib/libcxx/src/chrono.cpp+6-6
......@@ -124,7 +124,7 @@ static system_clock::time_point __libcpp_system_clock_now() {
124124static system_clock::time_point __libcpp_system_clock_now() {
125125 struct timespec ts;
126126 if (timespec_get(&ts, TIME_UTC) != TIME_UTC)
127 __throw_system_error(errno, "timespec_get(TIME_UTC) failed");
127 std::__throw_system_error(errno, "timespec_get(TIME_UTC) failed");
128128 return system_clock::time_point(seconds(ts.tv_sec) + microseconds(ts.tv_nsec / 1000));
129129}
130130
......@@ -133,7 +133,7 @@ static system_clock::time_point __libcpp_system_clock_now() {
133133static system_clock::time_point __libcpp_system_clock_now() {
134134 struct timespec tp;
135135 if (0 != clock_gettime(CLOCK_REALTIME, &tp))
136 __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
136 std::__throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
137137 return system_clock::time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000));
138138}
139139
......@@ -180,7 +180,7 @@ system_clock::time_point system_clock::from_time_t(time_t t) noexcept { return s
180180static steady_clock::time_point __libcpp_steady_clock_now() {
181181 struct timespec tp;
182182 if (0 != clock_gettime(CLOCK_MONOTONIC_RAW, &tp))
183 __throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC_RAW) failed");
183 std::__throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC_RAW) failed");
184184 return steady_clock::time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
185185}
186186
......@@ -213,7 +213,7 @@ static steady_clock::time_point __libcpp_steady_clock_now() {
213213static steady_clock::time_point __libcpp_steady_clock_now() {
214214 struct timespec64 ts;
215215 if (0 != gettimeofdayMonotonic(&ts))
216 __throw_system_error(errno, "failed to obtain time of day");
216 std::__throw_system_error(errno, "failed to obtain time of day");
217217
218218 return steady_clock::time_point(seconds(ts.tv_sec) + nanoseconds(ts.tv_nsec));
219219}
......@@ -234,7 +234,7 @@ static steady_clock::time_point __libcpp_steady_clock_now() noexcept {
234234static steady_clock::time_point __libcpp_steady_clock_now() {
235235 struct timespec ts;
236236 if (timespec_get(&ts, TIME_MONOTONIC) != TIME_MONOTONIC)
237 __throw_system_error(errno, "timespec_get(TIME_MONOTONIC) failed");
237 std::__throw_system_error(errno, "timespec_get(TIME_MONOTONIC) failed");
238238 return steady_clock::time_point(seconds(ts.tv_sec) + microseconds(ts.tv_nsec / 1000));
239239}
240240
......@@ -243,7 +243,7 @@ static steady_clock::time_point __libcpp_steady_clock_now() {
243243static steady_clock::time_point __libcpp_steady_clock_now() {
244244 struct timespec tp;
245245 if (0 != clock_gettime(CLOCK_MONOTONIC, &tp))
246 __throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed");
246 std::__throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed");
247247 return steady_clock::time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
248248}
249249
lib/libcxx/src/condition_variable.cpp+10-4
......@@ -7,7 +7,13 @@
77//===----------------------------------------------------------------------===//
88
99#include <condition_variable>
10#include <limits>
11#include <ratio>
1012#include <thread>
13#include <__chrono/duration.h>
14#include <__chrono/system_clock.h>
15#include <__chrono/time_point.h>
16#include <__system_error/throw_system_error.h>
1117
1218#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
1319# pragma comment(lib, "pthread")
......@@ -26,17 +32,17 @@ void condition_variable::notify_all() noexcept { __libcpp_condvar_broadcast(&__c
2632
2733void condition_variable::wait(unique_lock<mutex>& lk) noexcept {
2834 if (!lk.owns_lock())
29 __throw_system_error(EPERM, "condition_variable::wait: mutex not locked");
35 std::__throw_system_error(EPERM, "condition_variable::wait: mutex not locked");
3036 int ec = __libcpp_condvar_wait(&__cv_, lk.mutex()->native_handle());
3137 if (ec)
32 __throw_system_error(ec, "condition_variable wait failed");
38 std::__throw_system_error(ec, "condition_variable wait failed");
3339}
3440
3541void condition_variable::__do_timed_wait(unique_lock<mutex>& lk,
3642 chrono::time_point<chrono::system_clock, chrono::nanoseconds> tp) noexcept {
3743 using namespace chrono;
3844 if (!lk.owns_lock())
39 __throw_system_error(EPERM, "condition_variable::timed wait: mutex not locked");
45 std::__throw_system_error(EPERM, "condition_variable::timed wait: mutex not locked");
4046 nanoseconds d = tp.time_since_epoch();
4147 if (d > nanoseconds(0x59682F000000E941))
4248 d = nanoseconds(0x59682F000000E941);
......@@ -53,7 +59,7 @@ void condition_variable::__do_timed_wait(unique_lock<mutex>& lk,
5359 }
5460 int ec = __libcpp_condvar_timedwait(&__cv_, lk.mutex()->native_handle(), &ts);
5561 if (ec != 0 && ec != ETIMEDOUT)
56 __throw_system_error(ec, "condition_variable timed_wait failed");
62 std::__throw_system_error(ec, "condition_variable timed_wait failed");
5763}
5864
5965void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk) {
lib/libcxx/src/experimental/log_hardening_failure.cpp created+31
......@@ -0,0 +1,31 @@
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 <__log_hardening_failure>
11#include <cstdio>
12
13#ifdef __BIONIC__
14# include <syslog.h>
15#endif // __BIONIC__
16
17_LIBCPP_BEGIN_NAMESPACE_STD
18
19void __log_hardening_failure(const char* message) noexcept {
20 // Always log the message to `stderr` in case the platform-specific system calls fail.
21 std::fputs(message, stderr);
22
23#if defined(__BIONIC__)
24 // Show error in logcat. The latter two arguments are ignored on Android.
25 openlog("libc++", 0, 0);
26 syslog(LOG_CRIT, "%s", message);
27 closelog();
28#endif
29}
30
31_LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/experimental/time_zone.cpp+9
......@@ -29,6 +29,15 @@
2929// These quirks often use a 12h interval; this is the scan interval of zdump,
3030// which implies there are no sys_info objects with a duration of less than 12h.
3131
32// Work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120502
33
34#include <__config>
35
36// TODO(LLVM 23): When upgrading to GCC 16 this can be removed
37#ifdef _LIBCPP_COMPILER_GCC
38# pragma GCC optimize("-O0")
39#endif
40
3241#include <algorithm>
3342#include <cctype>
3443#include <chrono>
lib/libcxx/src/experimental/tzdb.cpp+50-18
......@@ -709,6 +709,39 @@ void __init_tzdb(tzdb& __tzdb, __tz::__rules_storage_type& __rules) {
709709 std::__throw_runtime_error("unknown time zone");
710710}
711711#else // ifdef _WIN32
712
713[[nodiscard]] static string __current_zone_environment() {
714 if (const char* __tz = std::getenv("TZ"))
715 return __tz;
716
717 return {};
718}
719
720[[nodiscard]] static string __current_zone_etc_localtime() {
721 filesystem::path __path = "/etc/localtime";
722 if (!filesystem::exists(__path) || !filesystem::is_symlink(__path))
723 return {};
724
725 filesystem::path __tz = filesystem::read_symlink(__path);
726 // The path may be a relative path, in that case convert it to an absolute
727 // path based on the proper initial directory.
728 if (__tz.is_relative())
729 __tz = filesystem::canonical("/etc" / __tz);
730
731 return filesystem::relative(__tz, "/usr/share/zoneinfo/");
732}
733
734[[nodiscard]] static string __current_zone_etc_timezone() {
735 filesystem::path __path = "/etc/timezone";
736 if (!filesystem::exists(__path))
737 return {};
738
739 ifstream __f(__path);
740 string __name;
741 std::getline(__f, __name);
742 return __name;
743}
744
712745[[nodiscard]] static const time_zone* __current_zone_posix(const tzdb& tzdb) {
713746 // On POSIX systems there are several ways to configure the time zone.
714747 // In order of priority they are:
......@@ -727,30 +760,29 @@ void __init_tzdb(tzdb& __tzdb, __tz::__rules_storage_type& __rules) {
727760 //
728761 // - The time zone name is the target of the symlink /etc/localtime
729762 // relative to /usr/share/zoneinfo/
763 //
764 // - The file /etc/timezone. This text file contains the name of the time
765 // zone.
766 //
767 // On Linux systems it seems /etc/timezone is deprecated and being phased out.
768 // This file is used when /etc/localtime does not exist, or when it exists but
769 // is not a symlink. For more information and links see
770 // https://github.com/llvm/llvm-project/issues/105634
730771
731 // The algorithm is like this:
732 // - If the environment variable TZ is set and points to a valid
733 // record use this value.
734 // - Else use the name based on the `/etc/localtime` symlink.
772 string __name = chrono::__current_zone_environment();
735773
736 if (const char* __tz = getenv("TZ"))
737 if (const time_zone* __result = tzdb.__locate_zone(__tz))
774 // Ignore invalid names in the environment.
775 if (!__name.empty())
776 if (const time_zone* __result = tzdb.__locate_zone(__name))
738777 return __result;
739778
740 filesystem::path __path = "/etc/localtime";
741 if (!filesystem::exists(__path))
742 std::__throw_runtime_error("tzdb: the symlink '/etc/localtime' does not exist");
743
744 if (!filesystem::is_symlink(__path))
745 std::__throw_runtime_error("tzdb: the path '/etc/localtime' is not a symlink");
779 __name = chrono::__current_zone_etc_localtime();
780 if (__name.empty())
781 __name = chrono::__current_zone_etc_timezone();
746782
747 filesystem::path __tz = filesystem::read_symlink(__path);
748 // The path may be a relative path, in that case convert it to an absolute
749 // path based on the proper initial directory.
750 if (__tz.is_relative())
751 __tz = filesystem::canonical("/etc" / __tz);
783 if (__name.empty())
784 std::__throw_runtime_error("tzdb: unable to determine the name of the current time zone");
752785
753 string __name = filesystem::relative(__tz, "/usr/share/zoneinfo/");
754786 if (const time_zone* __result = tzdb.__locate_zone(__name))
755787 return __result;
756788
lib/libcxx/src/filesystem/directory_iterator.cpp+1
......@@ -8,6 +8,7 @@
88
99#include <__assert>
1010#include <__config>
11#include <__memory/shared_ptr.h>
1112#include <errno.h>
1213#include <filesystem>
1314#include <stack>
lib/libcxx/src/filesystem/error.h+7-6
......@@ -10,6 +10,7 @@
1010#define FILESYSTEM_ERROR_H
1111
1212#include <__assert>
13#include <__chrono/time_point.h>
1314#include <__config>
1415#include <cerrno>
1516#include <cstdarg>
......@@ -96,11 +97,11 @@ struct ErrorHandler {
9697 string what = string("in ") + func_name_;
9798 switch (bool(p1_) + bool(p2_)) {
9899 case 0:
99 __throw_filesystem_error(what, ec);
100 filesystem::__throw_filesystem_error(what, ec);
100101 case 1:
101 __throw_filesystem_error(what, *p1_, ec);
102 filesystem::__throw_filesystem_error(what, *p1_, ec);
102103 case 2:
103 __throw_filesystem_error(what, *p1_, *p2_, ec);
104 filesystem::__throw_filesystem_error(what, *p1_, *p2_, ec);
104105 }
105106 __libcpp_unreachable();
106107 }
......@@ -114,11 +115,11 @@ struct ErrorHandler {
114115 string what = string("in ") + func_name_ + ": " + detail::vformat_string(msg, ap);
115116 switch (bool(p1_) + bool(p2_)) {
116117 case 0:
117 __throw_filesystem_error(what, ec);
118 filesystem::__throw_filesystem_error(what, ec);
118119 case 1:
119 __throw_filesystem_error(what, *p1_, ec);
120 filesystem::__throw_filesystem_error(what, *p1_, ec);
120121 case 2:
121 __throw_filesystem_error(what, *p1_, *p2_, ec);
122 filesystem::__throw_filesystem_error(what, *p1_, *p2_, ec);
122123 }
123124 __libcpp_unreachable();
124125 }
lib/libcxx/src/filesystem/filesystem_clock.cpp+4-2
......@@ -8,8 +8,10 @@
88
99#include <__config>
1010#include <__system_error/throw_system_error.h>
11#include <cerrno>
1112#include <chrono>
1213#include <filesystem>
14#include <ratio>
1315#include <time.h>
1416
1517#if defined(_LIBCPP_WIN32API)
......@@ -58,13 +60,13 @@ _FilesystemClock::time_point _FilesystemClock::now() noexcept {
5860 typedef chrono::duration<rep, nano> __nsecs;
5961 struct timespec ts;
6062 if (timespec_get(&ts, TIME_UTC) != TIME_UTC)
61 __throw_system_error(errno, "timespec_get(TIME_UTC) failed");
63 std::__throw_system_error(errno, "timespec_get(TIME_UTC) failed");
6264 return time_point(__secs(ts.tv_sec) + chrono::duration_cast<duration>(__nsecs(ts.tv_nsec)));
6365#elif defined(_LIBCPP_HAS_CLOCK_GETTIME)
6466 typedef chrono::duration<rep, nano> __nsecs;
6567 struct timespec tp;
6668 if (0 != clock_gettime(CLOCK_REALTIME, &tp))
67 __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
69 std::__throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
6870 return time_point(__secs(tp.tv_sec) + chrono::duration_cast<duration>(__nsecs(tp.tv_nsec)));
6971#else
7072 typedef chrono::duration<rep, micro> __microsecs;
lib/libcxx/src/filesystem/filesystem_error.cpp+1
......@@ -7,6 +7,7 @@
77//===----------------------------------------------------------------------===//
88
99#include <__config>
10#include <__memory/shared_ptr.h>
1011#include <__utility/unreachable.h>
1112#include <filesystem>
1213#include <system_error>
lib/libcxx/src/filesystem/operations.cpp+1
......@@ -6,6 +6,7 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include <__algorithm/copy.h>
910#include <__assert>
1011#include <__config>
1112#include <__utility/unreachable.h>
lib/libcxx/src/filesystem/path_parser.h+1-1
......@@ -90,7 +90,7 @@ public:
9090 if (TkEnd)
9191 return makeState(PS_InRootName, Start, TkEnd);
9292 }
93 _LIBCPP_FALLTHROUGH();
93 [[__fallthrough__]];
9494 case PS_InRootName: {
9595 PosPtr TkEnd = consumeAllSeparators(Start, End);
9696 if (TkEnd)
lib/libcxx/src/functional.cpp+4-2
......@@ -12,8 +12,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
1212
1313bad_function_call::~bad_function_call() noexcept {}
1414
15#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
1615const char* bad_function_call::what() const noexcept { return "std::bad_function_call"; }
17#endif
16
17size_t __hash_memory(_LIBCPP_NOESCAPE const void* ptr, size_t size) noexcept {
18 return __murmur2_or_cityhash<size_t>()(ptr, size);
19}
1820
1921_LIBCPP_END_NAMESPACE_STD
lib/libcxx/src/future.cpp+10-10
......@@ -62,7 +62,7 @@ void __assoc_sub_state::__on_zero_shared() noexcept { delete this; }
6262void __assoc_sub_state::set_value() {
6363 unique_lock<mutex> __lk(__mut_);
6464 if (__has_value())
65 __throw_future_error(future_errc::promise_already_satisfied);
65 std::__throw_future_error(future_errc::promise_already_satisfied);
6666 __state_ |= __constructed | ready;
6767 __cv_.notify_all();
6868}
......@@ -70,7 +70,7 @@ void __assoc_sub_state::set_value() {
7070void __assoc_sub_state::set_value_at_thread_exit() {
7171 unique_lock<mutex> __lk(__mut_);
7272 if (__has_value())
73 __throw_future_error(future_errc::promise_already_satisfied);
73 std::__throw_future_error(future_errc::promise_already_satisfied);
7474 __state_ |= __constructed;
7575 __thread_local_data()->__make_ready_at_thread_exit(this);
7676}
......@@ -78,7 +78,7 @@ void __assoc_sub_state::set_value_at_thread_exit() {
7878void __assoc_sub_state::set_exception(exception_ptr __p) {
7979 unique_lock<mutex> __lk(__mut_);
8080 if (__has_value())
81 __throw_future_error(future_errc::promise_already_satisfied);
81 std::__throw_future_error(future_errc::promise_already_satisfied);
8282 __exception_ = __p;
8383 __state_ |= ready;
8484 __cv_.notify_all();
......@@ -87,7 +87,7 @@ void __assoc_sub_state::set_exception(exception_ptr __p) {
8787void __assoc_sub_state::set_exception_at_thread_exit(exception_ptr __p) {
8888 unique_lock<mutex> __lk(__mut_);
8989 if (__has_value())
90 __throw_future_error(future_errc::promise_already_satisfied);
90 std::__throw_future_error(future_errc::promise_already_satisfied);
9191 __exception_ = __p;
9292 __thread_local_data()->__make_ready_at_thread_exit(this);
9393}
......@@ -122,7 +122,7 @@ void __assoc_sub_state::__sub_wait(unique_lock<mutex>& __lk) {
122122 }
123123}
124124
125void __assoc_sub_state::__execute() { __throw_future_error(future_errc::no_state); }
125void __assoc_sub_state::__execute() { std::__throw_future_error(future_errc::no_state); }
126126
127127future<void>::future(__assoc_sub_state* __state) : __state_(__state) { __state_->__attach_future(); }
128128
......@@ -152,31 +152,31 @@ promise<void>::~promise() {
152152
153153future<void> promise<void>::get_future() {
154154 if (__state_ == nullptr)
155 __throw_future_error(future_errc::no_state);
155 std::__throw_future_error(future_errc::no_state);
156156 return future<void>(__state_);
157157}
158158
159159void promise<void>::set_value() {
160160 if (__state_ == nullptr)
161 __throw_future_error(future_errc::no_state);
161 std::__throw_future_error(future_errc::no_state);
162162 __state_->set_value();
163163}
164164
165165void promise<void>::set_exception(exception_ptr __p) {
166166 if (__state_ == nullptr)
167 __throw_future_error(future_errc::no_state);
167 std::__throw_future_error(future_errc::no_state);
168168 __state_->set_exception(__p);
169169}
170170
171171void promise<void>::set_value_at_thread_exit() {
172172 if (__state_ == nullptr)
173 __throw_future_error(future_errc::no_state);
173 std::__throw_future_error(future_errc::no_state);
174174 __state_->set_value_at_thread_exit();
175175}
176176
177177void promise<void>::set_exception_at_thread_exit(exception_ptr __p) {
178178 if (__state_ == nullptr)
179 __throw_future_error(future_errc::no_state);
179 std::__throw_future_error(future_errc::no_state);
180180 __state_->set_exception_at_thread_exit(__p);
181181}
182182
lib/libcxx/src/hash.cpp+8-11
......@@ -9,7 +9,6 @@
99#include <__hash_table>
1010#include <algorithm>
1111#include <stdexcept>
12#include <type_traits>
1312
1413_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wtautological-constant-out-of-range-compare")
1514
......@@ -52,16 +51,14 @@ const unsigned indices[] = {
5251// are fewer potential primes to search, and fewer potential primes to divide
5352// against.
5453
55template <size_t _Sz = sizeof(size_t)>
56inline _LIBCPP_HIDE_FROM_ABI typename enable_if<_Sz == 4, void>::type __check_for_overflow(size_t N) {
57 if (N > 0xFFFFFFFB)
58 __throw_overflow_error("__next_prime overflow");
59}
60
61template <size_t _Sz = sizeof(size_t)>
62inline _LIBCPP_HIDE_FROM_ABI typename enable_if<_Sz == 8, void>::type __check_for_overflow(size_t N) {
63 if (N > 0xFFFFFFFFFFFFFFC5ull)
64 __throw_overflow_error("__next_prime overflow");
54inline void __check_for_overflow(size_t N) {
55 if constexpr (sizeof(size_t) == 4) {
56 if (N > 0xFFFFFFFB)
57 std::__throw_overflow_error("__next_prime overflow");
58 } else {
59 if (N > 0xFFFFFFFFFFFFFFC5ull)
60 std::__throw_overflow_error("__next_prime overflow");
61 }
6562}
6663
6764size_t __next_prime(size_t n) {
lib/libcxx/src/include/overridable_function.h+16-15
......@@ -29,14 +29,14 @@
2929// This is a low-level utility which does not work on all platforms, since it needs
3030// to make assumptions about the object file format in use. Furthermore, it requires
3131// the "base definition" of the function (the one we want to check whether it has been
32// overridden) to be annotated with the _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE macro.
32// overridden) to be defined using the _LIBCPP_OVERRIDABLE_FUNCTION macro.
3333//
3434// This currently works with Mach-O files (used on Darwin) and with ELF files (used on Linux
3535// and others). On platforms where we know how to implement this detection, the macro
3636// _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION is defined to 1, and it is defined to 0 on
37// other platforms. The _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE macro is defined to
38// nothing on unsupported platforms so that it can be used to decorate functions regardless
39// of whether detection is actually supported.
37// other platforms. The _LIBCPP_OVERRIDABLE_FUNCTION macro is defined to perform a normal
38// function definition on unsupported platforms so that it can be used to define functions
39// regardless of whether detection is actually supported.
4040//
4141// How does this work?
4242// -------------------
......@@ -44,7 +44,7 @@
4444// Let's say we want to check whether a weak function `f` has been overridden by the user.
4545// The general mechanism works by placing `f`'s definition (in the libc++ built library)
4646// inside a special section, which we do using the `__section__` attribute via the
47// _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE macro.
47// _LIBCPP_OVERRIDABLE_FUNCTION macro.
4848//
4949// Then, when comes the time to check whether the function has been overridden, we take
5050// the address of the function and we check whether it falls inside the special function
......@@ -66,12 +66,12 @@
6666#if defined(_LIBCPP_OBJECT_FORMAT_MACHO)
6767
6868# define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 1
69# define _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE \
70 __attribute__((__section__("__TEXT,__lcxx_override,regular,pure_instructions")))
69# define _LIBCPP_OVERRIDABLE_FUNCTION(type, name, arglist) \
70 __attribute__((__section__("__TEXT,__lcxx_override,regular,pure_instructions"))) _LIBCPP_WEAK type name arglist
7171
7272_LIBCPP_BEGIN_NAMESPACE_STD
73template <class _Ret, class... _Args>
74_LIBCPP_HIDE_FROM_ABI bool __is_function_overridden(_Ret (*__fptr)(_Args...)) noexcept {
73template <typename T, T* _Func>
74_LIBCPP_HIDE_FROM_ABI inline bool __is_function_overridden() noexcept {
7575 // Declare two dummy bytes and give them these special `__asm` values. These values are
7676 // defined by the linker, which means that referring to `&__lcxx_override_start` will
7777 // effectively refer to the address where the section starts (and same for the end).
......@@ -81,7 +81,7 @@ _LIBCPP_HIDE_FROM_ABI bool __is_function_overridden(_Ret (*__fptr)(_Args...)) no
8181 // Now get a uintptr_t out of these locations, and out of the function pointer.
8282 uintptr_t __start = reinterpret_cast<uintptr_t>(&__lcxx_override_start);
8383 uintptr_t __end = reinterpret_cast<uintptr_t>(&__lcxx_override_end);
84 uintptr_t __ptr = reinterpret_cast<uintptr_t>(__fptr);
84 uintptr_t __ptr = reinterpret_cast<uintptr_t>(_Func);
8585
8686# if __has_feature(ptrauth_calls)
8787 // We must pass a void* to ptrauth_strip since it only accepts a pointer type. Also, in particular,
......@@ -100,7 +100,8 @@ _LIBCPP_END_NAMESPACE_STD
100100#elif defined(_LIBCPP_OBJECT_FORMAT_ELF) && !defined(__NVPTX__)
101101
102102# define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 1
103# define _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE __attribute__((__section__("__lcxx_override")))
103# define _LIBCPP_OVERRIDABLE_FUNCTION(type, name, arglist) \
104 __attribute__((__section__("__lcxx_override"))) _LIBCPP_WEAK type name arglist
104105
105106// This is very similar to what we do for Mach-O above. The ELF linker will implicitly define
106107// variables with those names corresponding to the start and the end of the section.
......@@ -110,11 +111,11 @@ extern char __start___lcxx_override;
110111extern char __stop___lcxx_override;
111112
112113_LIBCPP_BEGIN_NAMESPACE_STD
113template <class _Ret, class... _Args>
114_LIBCPP_HIDE_FROM_ABI bool __is_function_overridden(_Ret (*__fptr)(_Args...)) noexcept {
114template <typename T, T* _Func>
115_LIBCPP_HIDE_FROM_ABI inline bool __is_function_overridden() noexcept {
115116 uintptr_t __start = reinterpret_cast<uintptr_t>(&__start___lcxx_override);
116117 uintptr_t __end = reinterpret_cast<uintptr_t>(&__stop___lcxx_override);
117 uintptr_t __ptr = reinterpret_cast<uintptr_t>(__fptr);
118 uintptr_t __ptr = reinterpret_cast<uintptr_t>(_Func);
118119
119120# if __has_feature(ptrauth_calls)
120121 // We must pass a void* to ptrauth_strip since it only accepts a pointer type. See full explanation above.
......@@ -128,7 +129,7 @@ _LIBCPP_END_NAMESPACE_STD
128129#else
129130
130131# define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 0
131# define _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE /* nothing */
132# define _LIBCPP_OVERRIDABLE_FUNCTION(type, name, arglist) _LIBCPP_WEAK type name arglist
132133
133134#endif
134135
lib/libcxx/src/include/ryu/common.h+1
......@@ -44,6 +44,7 @@
4444
4545#include <__assert>
4646#include <__config>
47#include <cstdint>
4748#include <cstring>
4849
4950_LIBCPP_BEGIN_NAMESPACE_STD
lib/libcxx/src/ios.cpp+5-5
......@@ -217,7 +217,7 @@ void ios_base::clear(iostate state) {
217217 __rdstate_ = state | badbit;
218218
219219 if (((state | (__rdbuf_ ? goodbit : badbit)) & __exceptions_) != 0)
220 __throw_failure("ios_base::clear");
220 std::__throw_failure("ios_base::clear");
221221}
222222
223223// init
......@@ -253,24 +253,24 @@ void ios_base::copyfmt(const ios_base& rhs) {
253253 size_t newesize = sizeof(event_callback) * rhs.__event_size_;
254254 new_callbacks.reset(static_cast<event_callback*>(malloc(newesize)));
255255 if (!new_callbacks)
256 __throw_bad_alloc();
256 std::__throw_bad_alloc();
257257
258258 size_t newisize = sizeof(int) * rhs.__event_size_;
259259 new_ints.reset(static_cast<int*>(malloc(newisize)));
260260 if (!new_ints)
261 __throw_bad_alloc();
261 std::__throw_bad_alloc();
262262 }
263263 if (__iarray_cap_ < rhs.__iarray_size_) {
264264 size_t newsize = sizeof(long) * rhs.__iarray_size_;
265265 new_longs.reset(static_cast<long*>(malloc(newsize)));
266266 if (!new_longs)
267 __throw_bad_alloc();
267 std::__throw_bad_alloc();
268268 }
269269 if (__parray_cap_ < rhs.__parray_size_) {
270270 size_t newsize = sizeof(void*) * rhs.__parray_size_;
271271 new_pointers.reset(static_cast<void**>(malloc(newsize)));
272272 if (!new_pointers)
273 __throw_bad_alloc();
273 std::__throw_bad_alloc();
274274 }
275275 // Got everything we need. Copy everything but __rdstate_, __rdbuf_ and __exceptions_
276276 __fmtflags_ = rhs.__fmtflags_;
lib/libcxx/src/iostream.cpp+66-95
......@@ -7,90 +7,64 @@
77//===----------------------------------------------------------------------===//
88
99#include "std_stream.h"
10#include <__locale>
11#include <new>
12#include <string>
1310
14#define _str(s) #s
15#define str(s) _str(s)
16#define _LIBCPP_ABI_NAMESPACE_STR str(_LIBCPP_ABI_NAMESPACE)
11#include <__memory/construct_at.h>
12#include <__ostream/basic_ostream.h>
13#include <istream>
14
15#define ABI_NAMESPACE_STR _LIBCPP_TOSTRING(_LIBCPP_ABI_NAMESPACE)
1716
1817_LIBCPP_BEGIN_NAMESPACE_STD
1918
20alignas(istream) _LIBCPP_EXPORTED_FROM_ABI char cin[sizeof(istream)]
21#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
22 __asm__("?cin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR
23 "@std@@@12@A")
24#endif
25 ;
26alignas(__stdinbuf<char>) static char __cin[sizeof(__stdinbuf<char>)];
27static mbstate_t mb_cin;
19template <class StreamT, class BufferT>
20union stream_data {
21 constexpr stream_data() {}
22 constexpr ~stream_data() {}
23 struct {
24 // The stream has to be the first element, since that's referenced by the stream declarations in <iostream>
25 StreamT stream;
26 BufferT buffer;
27 mbstate_t mb;
28 };
29
30 void init(FILE* stdstream) {
31 mb = {};
32 std::construct_at(&buffer, stdstream, &mb);
33 std::construct_at(&stream, &buffer);
34 }
35};
2836
29#if _LIBCPP_HAS_WIDE_CHARACTERS
30alignas(wistream) _LIBCPP_EXPORTED_FROM_ABI char wcin[sizeof(wistream)]
31# if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
32 __asm__("?wcin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR
33 "@std@@@12@A")
34# endif
35 ;
36alignas(__stdinbuf<wchar_t>) static char __wcin[sizeof(__stdinbuf<wchar_t>)];
37static mbstate_t mb_wcin;
38#endif // _LIBCPP_HAS_WIDE_CHARACTERS
37#define CHAR_MANGLING_char "D"
38#define CHAR_MANGLING_wchar_t "_W"
39#define CHAR_MANGLING(CharT) CHAR_MANGLING_##CharT
3940
40alignas(ostream) _LIBCPP_EXPORTED_FROM_ABI char cout[sizeof(ostream)]
41#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
42 __asm__("?cout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR
43 "@std@@@12@A")
41#ifdef _LIBCPP_COMPILER_CLANG_BASED
42# define STRING_DATA_CONSTINIT constinit
43#else
44# define STRING_DATA_CONSTINIT
4445#endif
45 ;
46alignas(__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
47static mbstate_t mb_cout;
4846
49#if _LIBCPP_HAS_WIDE_CHARACTERS
50alignas(wostream) _LIBCPP_EXPORTED_FROM_ABI char wcout[sizeof(wostream)]
51# if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
52 __asm__("?wcout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR
53 "@std@@@12@A")
54# endif
55 ;
56alignas(__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
57static mbstate_t mb_wcout;
58#endif // _LIBCPP_HAS_WIDE_CHARACTERS
59
60alignas(ostream) _LIBCPP_EXPORTED_FROM_ABI char cerr[sizeof(ostream)]
61#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
62 __asm__("?cerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR
63 "@std@@@12@A")
47#ifdef _LIBCPP_ABI_MICROSOFT
48# define STREAM(StreamT, BufferT, CharT, var) \
49 STRING_DATA_CONSTINIT stream_data<StreamT<CharT>, BufferT<CharT>> var __asm__( \
50 "?" #var "@" ABI_NAMESPACE_STR "@std@@3V?$" #StreamT \
51 "@" CHAR_MANGLING(CharT) "U?$char_traits@" CHAR_MANGLING(CharT) "@" ABI_NAMESPACE_STR "@std@@@12@A")
52#else
53# define STREAM(StreamT, BufferT, CharT, var) STRING_DATA_CONSTINIT stream_data<StreamT<CharT>, BufferT<CharT>> var
6454#endif
65 ;
66alignas(__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
67static mbstate_t mb_cerr;
68
69#if _LIBCPP_HAS_WIDE_CHARACTERS
70alignas(wostream) _LIBCPP_EXPORTED_FROM_ABI char wcerr[sizeof(wostream)]
71# if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
72 __asm__("?wcerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR
73 "@std@@@12@A")
74# endif
75 ;
76alignas(__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
77static mbstate_t mb_wcerr;
78#endif // _LIBCPP_HAS_WIDE_CHARACTERS
7955
80alignas(ostream) _LIBCPP_EXPORTED_FROM_ABI char clog[sizeof(ostream)]
81#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
82 __asm__("?clog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR
83 "@std@@@12@A")
84#endif
85 ;
56// These definitions and the declarations in <iostream> technically cause ODR violations, since they have different
57// types (stream_data and {i,o}stream respectively). This means that <iostream> should never be included in this TU.
8658
59_LIBCPP_EXPORTED_FROM_ABI STREAM(basic_istream, __stdinbuf, char, cin);
60_LIBCPP_EXPORTED_FROM_ABI STREAM(basic_ostream, __stdoutbuf, char, cout);
61_LIBCPP_EXPORTED_FROM_ABI STREAM(basic_ostream, __stdoutbuf, char, cerr);
62_LIBCPP_EXPORTED_FROM_ABI STREAM(basic_ostream, __stdoutbuf, char, clog);
8763#if _LIBCPP_HAS_WIDE_CHARACTERS
88alignas(wostream) _LIBCPP_EXPORTED_FROM_ABI char wclog[sizeof(wostream)]
89# if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
90 __asm__("?wclog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR
91 "@std@@@12@A")
92# endif
93 ;
64_LIBCPP_EXPORTED_FROM_ABI STREAM(basic_istream, __stdinbuf, wchar_t, wcin);
65_LIBCPP_EXPORTED_FROM_ABI STREAM(basic_ostream, __stdoutbuf, wchar_t, wcout);
66_LIBCPP_EXPORTED_FROM_ABI STREAM(basic_ostream, __stdoutbuf, wchar_t, wcerr);
67_LIBCPP_EXPORTED_FROM_ABI STREAM(basic_ostream, __stdoutbuf, wchar_t, wclog);
9468#endif // _LIBCPP_HAS_WIDE_CHARACTERS
9569
9670// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority
......@@ -124,37 +98,34 @@ public:
12498DoIOSInit::DoIOSInit() {
12599 force_locale_initialization();
126100
127 istream* cin_ptr = ::new (cin) istream(::new (__cin) __stdinbuf<char>(stdin, &mb_cin));
128 ostream* cout_ptr = ::new (cout) ostream(::new (__cout) __stdoutbuf<char>(stdout, &mb_cout));
129 ostream* cerr_ptr = ::new (cerr) ostream(::new (__cerr) __stdoutbuf<char>(stderr, &mb_cerr));
130 ::new (clog) ostream(cerr_ptr->rdbuf());
131 cin_ptr->tie(cout_ptr);
132 std::unitbuf(*cerr_ptr);
133 cerr_ptr->tie(cout_ptr);
101 cin.init(stdin);
102 cout.init(stdout);
103 cerr.init(stderr);
104 clog.init(stderr);
105
106 cin.stream.tie(&cout.stream);
107 std::unitbuf(cerr.stream);
108 cerr.stream.tie(&cout.stream);
134109
135110#if _LIBCPP_HAS_WIDE_CHARACTERS
136 wistream* wcin_ptr = ::new (wcin) wistream(::new (__wcin) __stdinbuf<wchar_t>(stdin, &mb_wcin));
137 wostream* wcout_ptr = ::new (wcout) wostream(::new (__wcout) __stdoutbuf<wchar_t>(stdout, &mb_wcout));
138 wostream* wcerr_ptr = ::new (wcerr) wostream(::new (__wcerr) __stdoutbuf<wchar_t>(stderr, &mb_wcerr));
139 ::new (wclog) wostream(wcerr_ptr->rdbuf());
140
141 wcin_ptr->tie(wcout_ptr);
142 std::unitbuf(*wcerr_ptr);
143 wcerr_ptr->tie(wcout_ptr);
111 wcin.init(stdin);
112 wcout.init(stdout);
113 wcerr.init(stderr);
114 wclog.init(stderr);
115
116 wcin.stream.tie(&wcout.stream);
117 std::unitbuf(wcerr.stream);
118 wcerr.stream.tie(&wcout.stream);
144119#endif
145120}
146121
147122DoIOSInit::~DoIOSInit() {
148 ostream* cout_ptr = reinterpret_cast<ostream*>(cout);
149 cout_ptr->flush();
150 ostream* clog_ptr = reinterpret_cast<ostream*>(clog);
151 clog_ptr->flush();
123 cout.stream.flush();
124 clog.stream.flush();
152125
153126#if _LIBCPP_HAS_WIDE_CHARACTERS
154 wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout);
155 wcout_ptr->flush();
156 wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog);
157 wclog_ptr->flush();
127 wcout.stream.flush();
128 wclog.stream.flush();
158129#endif
159130}
160131
lib/libcxx/src/locale.cpp+67-146
......@@ -34,10 +34,6 @@
3434# define _CTYPE_DISABLE_MACROS
3535#endif
3636
37#if __has_include("<langinfo.h>")
38# include <langinfo.h>
39#endif
40
4137#include "include/atomic_support.h"
4238#include "include/sso_allocator.h"
4339
......@@ -482,7 +478,7 @@ void locale::__imp::install(facet* f, long id) {
482478
483479const locale::facet* locale::__imp::use_facet(long id) const {
484480 if (!has_facet(id))
485 __throw_bad_cast();
481 std::__throw_bad_cast();
486482 return facets_[static_cast<size_t>(id)];
487483}
488484
......@@ -602,7 +598,7 @@ long locale::id::__get() {
602598collate_byname<char>::collate_byname(const char* n, size_t refs)
603599 : collate<char>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, n, 0)) {
604600 if (__l_ == 0)
605 __throw_runtime_error(
601 std::__throw_runtime_error(
606602 ("collate_byname<char>::collate_byname"
607603 " failed to construct for " +
608604 string(n))
......@@ -612,7 +608,7 @@ collate_byname<char>::collate_byname(const char* n, size_t refs)
612608collate_byname<char>::collate_byname(const string& name, size_t refs)
613609 : collate<char>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name.c_str(), 0)) {
614610 if (__l_ == 0)
615 __throw_runtime_error(
611 std::__throw_runtime_error(
616612 ("collate_byname<char>::collate_byname"
617613 " failed to construct for " +
618614 name)
......@@ -646,7 +642,7 @@ collate_byname<char>::string_type collate_byname<char>::do_transform(const char_
646642collate_byname<wchar_t>::collate_byname(const char* n, size_t refs)
647643 : collate<wchar_t>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, n, 0)) {
648644 if (__l_ == 0)
649 __throw_runtime_error(
645 std::__throw_runtime_error(
650646 ("collate_byname<wchar_t>::collate_byname(size_t refs)"
651647 " failed to construct for " +
652648 string(n))
......@@ -656,7 +652,7 @@ collate_byname<wchar_t>::collate_byname(const char* n, size_t refs)
656652collate_byname<wchar_t>::collate_byname(const string& name, size_t refs)
657653 : collate<wchar_t>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name.c_str(), 0)) {
658654 if (__l_ == 0)
659 __throw_runtime_error(
655 std::__throw_runtime_error(
660656 ("collate_byname<wchar_t>::collate_byname(size_t refs)"
661657 " failed to construct for " +
662658 name)
......@@ -701,6 +697,20 @@ const ctype_base::mask ctype_base::graph;
701697
702698// template <> class ctype<wchar_t>;
703699
700template <class CharT>
701static CharT to_upper_impl(CharT c) {
702 if (c < 'a' || c > 'z')
703 return c;
704 return c & ~0x20;
705}
706
707template <class CharT>
708static CharT to_lower_impl(CharT c) {
709 if (c < 'A' || c > 'Z')
710 return c;
711 return c | 0x20;
712}
713
704714#if _LIBCPP_HAS_WIDE_CHARACTERS
705715constinit locale::id ctype<wchar_t>::id;
706716
......@@ -730,48 +740,19 @@ const wchar_t* ctype<wchar_t>::do_scan_not(mask m, const char_type* low, const c
730740 return low;
731741}
732742
733wchar_t ctype<wchar_t>::do_toupper(char_type c) const {
734# ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
735 return std::__libcpp_isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
736# elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__MVS__)
737 return std::__libcpp_isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
738# else
739 return (std::__libcpp_isascii(c) && __locale::__iswlower(c, _LIBCPP_GET_C_LOCALE)) ? c - L'a' + L'A' : c;
740# endif
741}
743wchar_t ctype<wchar_t>::do_toupper(char_type c) const { return to_upper_impl(c); }
742744
743745const wchar_t* ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const {
744746 for (; low != high; ++low)
745# ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
746 *low = std::__libcpp_isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
747# elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__MVS__)
748 *low = std::__libcpp_isascii(*low) ? ctype<char>::__classic_upper_table()[*low] : *low;
749# else
750 *low =
751 (std::__libcpp_isascii(*low) && __locale::__islower(*low, _LIBCPP_GET_C_LOCALE)) ? (*low - L'a' + L'A') : *low;
752# endif
747 *low = to_upper_impl(*low);
753748 return low;
754749}
755750
756wchar_t ctype<wchar_t>::do_tolower(char_type c) const {
757# ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
758 return std::__libcpp_isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
759# elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__MVS__)
760 return std::__libcpp_isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
761# else
762 return (std::__libcpp_isascii(c) && __locale::__isupper(c, _LIBCPP_GET_C_LOCALE)) ? c - L'A' + 'a' : c;
763# endif
764}
751wchar_t ctype<wchar_t>::do_tolower(char_type c) const { return to_lower_impl(c); }
765752
766753const wchar_t* ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const {
767754 for (; low != high; ++low)
768# ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
769 *low = std::__libcpp_isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
770# elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__MVS__)
771 *low = std::__libcpp_isascii(*low) ? ctype<char>::__classic_lower_table()[*low] : *low;
772# else
773 *low = (std::__libcpp_isascii(*low) && __locale::__isupper(*low, _LIBCPP_GET_C_LOCALE)) ? *low - L'A' + L'a' : *low;
774# endif
755 *low = to_lower_impl(*low);
775756 return low;
776757}
777758
......@@ -815,59 +796,19 @@ ctype<char>::~ctype() {
815796 delete[] __tab_;
816797}
817798
818char ctype<char>::do_toupper(char_type c) const {
819#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
820 return std::__libcpp_isascii(c) ? static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
821#elif defined(__NetBSD__)
822 return static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]);
823#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
824 return std::__libcpp_isascii(c) ? static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]) : c;
825#else
826 return (std::__libcpp_isascii(c) && __locale::__islower(c, _LIBCPP_GET_C_LOCALE)) ? c - 'a' + 'A' : c;
827#endif
828}
799char ctype<char>::do_toupper(char_type c) const { return to_upper_impl(c); }
829800
830801const char* ctype<char>::do_toupper(char_type* low, const char_type* high) const {
831802 for (; low != high; ++low)
832#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
833 *low = std::__libcpp_isascii(*low)
834 ? static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)])
835 : *low;
836#elif defined(__NetBSD__)
837 *low = static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(*low)]);
838#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
839 *low = std::__libcpp_isascii(*low) ? static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
840#else
841 *low = (std::__libcpp_isascii(*low) && __locale::__islower(*low, _LIBCPP_GET_C_LOCALE)) ? *low - 'a' + 'A' : *low;
842#endif
803 *low = to_upper_impl(*low);
843804 return low;
844805}
845806
846char ctype<char>::do_tolower(char_type c) const {
847#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
848 return std::__libcpp_isascii(c) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
849#elif defined(__NetBSD__)
850 return static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(c)]);
851#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
852 return std::__libcpp_isascii(c) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
853#else
854 return (std::__libcpp_isascii(c) && __locale::__isupper(c, _LIBCPP_GET_C_LOCALE)) ? c - 'A' + 'a' : c;
855#endif
856}
807char ctype<char>::do_tolower(char_type c) const { return to_lower_impl(c); }
857808
858809const char* ctype<char>::do_tolower(char_type* low, const char_type* high) const {
859810 for (; low != high; ++low)
860#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
861 *low = std::__libcpp_isascii(*low)
862 ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)])
863 : *low;
864#elif defined(__NetBSD__)
865 *low = static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(*low)]);
866#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
867 *low = std::__libcpp_isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
868#else
869 *low = (std::__libcpp_isascii(*low) && __locale::__isupper(*low, _LIBCPP_GET_C_LOCALE)) ? *low - 'A' + 'a' : *low;
870#endif
811 *low = to_lower_impl(*low);
871812 return low;
872813}
873814
......@@ -1014,42 +955,12 @@ const ctype<char>::mask* ctype<char>::classic_table() noexcept {
1014955}
1015956#endif
1016957
1017#if defined(__GLIBC__)
1018const int* ctype<char>::__classic_lower_table() noexcept { return _LIBCPP_GET_C_LOCALE->__ctype_tolower; }
1019
1020const int* ctype<char>::__classic_upper_table() noexcept { return _LIBCPP_GET_C_LOCALE->__ctype_toupper; }
1021#elif defined(__NetBSD__)
1022const short* ctype<char>::__classic_lower_table() noexcept { return _C_tolower_tab_ + 1; }
1023
1024const short* ctype<char>::__classic_upper_table() noexcept { return _C_toupper_tab_ + 1; }
1025
1026#elif defined(__EMSCRIPTEN__)
1027const int* ctype<char>::__classic_lower_table() noexcept { return *__ctype_tolower_loc(); }
1028
1029const int* ctype<char>::__classic_upper_table() noexcept { return *__ctype_toupper_loc(); }
1030#elif defined(__MVS__)
1031const unsigned short* ctype<char>::__classic_lower_table() _NOEXCEPT {
1032# if defined(__NATIVE_ASCII_F)
1033 return const_cast<const unsigned short*>(__OBJ_DATA(__lc_ctype_a)->lower);
1034# else
1035 return const_cast<const unsigned short*>(__ctype + __TOLOWER_INDEX);
1036# endif
1037}
1038const unsigned short* ctype<char>::__classic_upper_table() _NOEXCEPT {
1039# if defined(__NATIVE_ASCII_F)
1040 return const_cast<const unsigned short*>(__OBJ_DATA(__lc_ctype_a)->upper);
1041# else
1042 return const_cast<const unsigned short*>(__ctype + __TOUPPER_INDEX);
1043# endif
1044}
1045#endif // __GLIBC__ || __NETBSD__ || __EMSCRIPTEN__ || __MVS__
1046
1047958// template <> class ctype_byname<char>
1048959
1049960ctype_byname<char>::ctype_byname(const char* name, size_t refs)
1050961 : ctype<char>(0, false, refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name, 0)) {
1051962 if (__l_ == 0)
1052 __throw_runtime_error(
963 std::__throw_runtime_error(
1053964 ("ctype_byname<char>::ctype_byname"
1054965 " failed to construct for " +
1055966 string(name))
......@@ -1059,7 +970,7 @@ ctype_byname<char>::ctype_byname(const char* name, size_t refs)
1059970ctype_byname<char>::ctype_byname(const string& name, size_t refs)
1060971 : ctype<char>(0, false, refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name.c_str(), 0)) {
1061972 if (__l_ == 0)
1062 __throw_runtime_error(
973 std::__throw_runtime_error(
1063974 ("ctype_byname<char>::ctype_byname"
1064975 " failed to construct for " +
1065976 name)
......@@ -1094,7 +1005,7 @@ const char* ctype_byname<char>::do_tolower(char_type* low, const char_type* high
10941005ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)
10951006 : ctype<wchar_t>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name, 0)) {
10961007 if (__l_ == 0)
1097 __throw_runtime_error(
1008 std::__throw_runtime_error(
10981009 ("ctype_byname<wchar_t>::ctype_byname"
10991010 " failed to construct for " +
11001011 string(name))
......@@ -1104,7 +1015,7 @@ ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)
11041015ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs)
11051016 : ctype<wchar_t>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name.c_str(), 0)) {
11061017 if (__l_ == 0)
1107 __throw_runtime_error(
1018 std::__throw_runtime_error(
11081019 ("ctype_byname<wchar_t>::ctype_byname"
11091020 " failed to construct for " +
11101021 name)
......@@ -1344,7 +1255,7 @@ codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs) : locale::facet(refs), _
13441255codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs)
13451256 : locale::facet(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, nm, 0)) {
13461257 if (__l_ == 0)
1347 __throw_runtime_error(
1258 std::__throw_runtime_error(
13481259 ("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname"
13491260 " failed to construct for " +
13501261 string(nm))
......@@ -3957,7 +3868,7 @@ static bool is_narrow_non_breaking_space(const char* ptr) {
39573868}
39583869
39593870static bool is_non_breaking_space(const char* ptr) {
3960 // https://www.fileformat.info/info/unicode/char/0a/index.htm
3871 // https://www.fileformat.info/info/unicode/char/a0/index.htm
39613872 return ptr[0] == '\xc2' && ptr[1] == '\xa0';
39623873}
39633874#endif // _LIBCPP_HAS_WIDE_CHARACTERS
......@@ -4061,7 +3972,7 @@ void numpunct_byname<char>::__init(const char* nm) {
40613972 if (strcmp(nm, "C") != 0) {
40623973 __libcpp_unique_locale loc(nm);
40633974 if (!loc)
4064 __throw_runtime_error(
3975 std::__throw_runtime_error(
40653976 ("numpunct_byname<char>::numpunct_byname"
40663977 " failed to construct for " +
40673978 string(nm))
......@@ -4092,7 +4003,7 @@ void numpunct_byname<wchar_t>::__init(const char* nm) {
40924003 if (strcmp(nm, "C") != 0) {
40934004 __libcpp_unique_locale loc(nm);
40944005 if (!loc)
4095 __throw_runtime_error(
4006 std::__throw_runtime_error(
40964007 ("numpunct_byname<wchar_t>::numpunct_byname"
40974008 " failed to construct for " +
40984009 string(nm))
......@@ -4444,12 +4355,12 @@ const wstring& __time_get_c_storage<wchar_t>::__r() const {
44444355
44454356__time_get::__time_get(const char* nm) : __loc_(__locale::__newlocale(_LIBCPP_ALL_MASK, nm, 0)) {
44464357 if (__loc_ == 0)
4447 __throw_runtime_error(("time_get_byname failed to construct for " + string(nm)).c_str());
4358 std::__throw_runtime_error(("time_get_byname failed to construct for " + string(nm)).c_str());
44484359}
44494360
44504361__time_get::__time_get(const string& nm) : __loc_(__locale::__newlocale(_LIBCPP_ALL_MASK, nm.c_str(), 0)) {
44514362 if (__loc_ == 0)
4452 __throw_runtime_error(("time_get_byname failed to construct for " + nm).c_str());
4363 std::__throw_runtime_error(("time_get_byname failed to construct for " + nm).c_str());
44534364}
44544365
44554366__time_get::~__time_get() { __locale::__freelocale(__loc_); }
......@@ -4610,7 +4521,7 @@ wstring __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& c
46104521 const char* bb = buf;
46114522 size_t j = __locale::__mbsrtowcs(wbb, &bb, countof(wbuf), &mb, __loc_);
46124523 if (j == size_t(-1))
4613 __throw_runtime_error("locale not supported");
4524 std::__throw_runtime_error("locale not supported");
46144525 wchar_t* wbe = wbb + j;
46154526 wstring result;
46164527 while (wbb != wbe) {
......@@ -4771,7 +4682,7 @@ void __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) {
47714682 const char* bb = buf;
47724683 size_t j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);
47734684 if (j == size_t(-1) || j == 0)
4774 __throw_runtime_error("locale not supported");
4685 std::__throw_runtime_error("locale not supported");
47754686 wbe = wbuf + j;
47764687 __weeks_[i].assign(wbuf, wbe);
47774688 __locale::__strftime(buf, countof(buf), "%a", &t, __loc_);
......@@ -4779,7 +4690,7 @@ void __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) {
47794690 bb = buf;
47804691 j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);
47814692 if (j == size_t(-1) || j == 0)
4782 __throw_runtime_error("locale not supported");
4693 std::__throw_runtime_error("locale not supported");
47834694 wbe = wbuf + j;
47844695 __weeks_[i + 7].assign(wbuf, wbe);
47854696 }
......@@ -4791,7 +4702,7 @@ void __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) {
47914702 const char* bb = buf;
47924703 size_t j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);
47934704 if (j == size_t(-1) || j == 0)
4794 __throw_runtime_error("locale not supported");
4705 std::__throw_runtime_error("locale not supported");
47954706 wbe = wbuf + j;
47964707 __months_[i].assign(wbuf, wbe);
47974708 __locale::__strftime(buf, countof(buf), "%b", &t, __loc_);
......@@ -4799,7 +4710,7 @@ void __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) {
47994710 bb = buf;
48004711 j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);
48014712 if (j == size_t(-1) || j == 0)
4802 __throw_runtime_error("locale not supported");
4713 std::__throw_runtime_error("locale not supported");
48034714 wbe = wbuf + j;
48044715 __months_[i + 12].assign(wbuf, wbe);
48054716 }
......@@ -4810,7 +4721,7 @@ void __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) {
48104721 const char* bb = buf;
48114722 size_t j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);
48124723 if (j == size_t(-1))
4813 __throw_runtime_error("locale not supported");
4724 std::__throw_runtime_error("locale not supported");
48144725 wbe = wbuf + j;
48154726 __am_pm_[0].assign(wbuf, wbe);
48164727 t.tm_hour = 13;
......@@ -4819,7 +4730,7 @@ void __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) {
48194730 bb = buf;
48204731 j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);
48214732 if (j == size_t(-1))
4822 __throw_runtime_error("locale not supported");
4733 std::__throw_runtime_error("locale not supported");
48234734 wbe = wbuf + j;
48244735 __am_pm_[1].assign(wbuf, wbe);
48254736 __c_ = __analyze('c', ct);
......@@ -5029,12 +4940,12 @@ time_base::dateorder __time_get_storage<wchar_t>::__do_date_order() const {
50294940
50304941__time_put::__time_put(const char* nm) : __loc_(__locale::__newlocale(_LIBCPP_ALL_MASK, nm, 0)) {
50314942 if (__loc_ == 0)
5032 __throw_runtime_error(("time_put_byname failed to construct for " + string(nm)).c_str());
4943 std::__throw_runtime_error(("time_put_byname failed to construct for " + string(nm)).c_str());
50334944}
50344945
50354946__time_put::__time_put(const string& nm) : __loc_(__locale::__newlocale(_LIBCPP_ALL_MASK, nm.c_str(), 0)) {
50364947 if (__loc_ == 0)
5037 __throw_runtime_error(("time_put_byname failed to construct for " + nm).c_str());
4948 std::__throw_runtime_error(("time_put_byname failed to construct for " + nm).c_str());
50384949}
50394950
50404951__time_put::~__time_put() {
......@@ -5059,7 +4970,7 @@ void __time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm, char __
50594970 const char* __nb = __nar;
50604971 size_t j = __locale::__mbsrtowcs(__wb, &__nb, countof(__wb, __we), &mb, __loc_);
50614972 if (j == size_t(-1))
5062 __throw_runtime_error("locale not supported");
4973 std::__throw_runtime_error("locale not supported");
50634974 __we = __wb + j;
50644975}
50654976#endif // _LIBCPP_HAS_WIDE_CHARACTERS
......@@ -5431,7 +5342,7 @@ void moneypunct_byname<char, false>::init(const char* nm) {
54315342 typedef moneypunct<char, false> base;
54325343 __libcpp_unique_locale loc(nm);
54335344 if (!loc)
5434 __throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());
5345 std::__throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());
54355346
54365347 __locale::__lconv_t* lc = __locale::__localeconv(loc.get());
54375348 if (!checked_string_to_char_convert(__decimal_point_, lc->mon_decimal_point, loc.get()))
......@@ -5466,7 +5377,7 @@ void moneypunct_byname<char, true>::init(const char* nm) {
54665377 typedef moneypunct<char, true> base;
54675378 __libcpp_unique_locale loc(nm);
54685379 if (!loc)
5469 __throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());
5380 std::__throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());
54705381
54715382 __locale::__lconv_t* lc = __locale::__localeconv(loc.get());
54725383 if (!checked_string_to_char_convert(__decimal_point_, lc->mon_decimal_point, loc.get()))
......@@ -5522,7 +5433,7 @@ void moneypunct_byname<wchar_t, false>::init(const char* nm) {
55225433 typedef moneypunct<wchar_t, false> base;
55235434 __libcpp_unique_locale loc(nm);
55245435 if (!loc)
5525 __throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());
5436 std::__throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());
55265437 __locale::__lconv_t* lc = __locale::__localeconv(loc.get());
55275438 if (!checked_string_to_wchar_convert(__decimal_point_, lc->mon_decimal_point, loc.get()))
55285439 __decimal_point_ = base::do_decimal_point();
......@@ -5534,7 +5445,7 @@ void moneypunct_byname<wchar_t, false>::init(const char* nm) {
55345445 const char* bb = lc->currency_symbol;
55355446 size_t j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());
55365447 if (j == size_t(-1))
5537 __throw_runtime_error("locale not supported");
5448 std::__throw_runtime_error("locale not supported");
55385449 wchar_t* wbe = wbuf + j;
55395450 __curr_symbol_.assign(wbuf, wbe);
55405451 if (lc->frac_digits != CHAR_MAX)
......@@ -5548,7 +5459,7 @@ void moneypunct_byname<wchar_t, false>::init(const char* nm) {
55485459 bb = lc->positive_sign;
55495460 j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());
55505461 if (j == size_t(-1))
5551 __throw_runtime_error("locale not supported");
5462 std::__throw_runtime_error("locale not supported");
55525463 wbe = wbuf + j;
55535464 __positive_sign_.assign(wbuf, wbe);
55545465 }
......@@ -5559,7 +5470,7 @@ void moneypunct_byname<wchar_t, false>::init(const char* nm) {
55595470 bb = lc->negative_sign;
55605471 j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());
55615472 if (j == size_t(-1))
5562 __throw_runtime_error("locale not supported");
5473 std::__throw_runtime_error("locale not supported");
55635474 wbe = wbuf + j;
55645475 __negative_sign_.assign(wbuf, wbe);
55655476 }
......@@ -5576,7 +5487,7 @@ void moneypunct_byname<wchar_t, true>::init(const char* nm) {
55765487 typedef moneypunct<wchar_t, true> base;
55775488 __libcpp_unique_locale loc(nm);
55785489 if (!loc)
5579 __throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());
5490 std::__throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());
55805491
55815492 __locale::__lconv_t* lc = __locale::__localeconv(loc.get());
55825493 if (!checked_string_to_wchar_convert(__decimal_point_, lc->mon_decimal_point, loc.get()))
......@@ -5589,7 +5500,7 @@ void moneypunct_byname<wchar_t, true>::init(const char* nm) {
55895500 const char* bb = lc->int_curr_symbol;
55905501 size_t j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());
55915502 if (j == size_t(-1))
5592 __throw_runtime_error("locale not supported");
5503 std::__throw_runtime_error("locale not supported");
55935504 wchar_t* wbe = wbuf + j;
55945505 __curr_symbol_.assign(wbuf, wbe);
55955506 if (lc->int_frac_digits != CHAR_MAX)
......@@ -5607,7 +5518,7 @@ void moneypunct_byname<wchar_t, true>::init(const char* nm) {
56075518 bb = lc->positive_sign;
56085519 j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());
56095520 if (j == size_t(-1))
5610 __throw_runtime_error("locale not supported");
5521 std::__throw_runtime_error("locale not supported");
56115522 wbe = wbuf + j;
56125523 __positive_sign_.assign(wbuf, wbe);
56135524 }
......@@ -5622,7 +5533,7 @@ void moneypunct_byname<wchar_t, true>::init(const char* nm) {
56225533 bb = lc->negative_sign;
56235534 j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());
56245535 if (j == size_t(-1))
5625 __throw_runtime_error("locale not supported");
5536 std::__throw_runtime_error("locale not supported");
56265537 wbe = wbuf + j;
56275538 __negative_sign_.assign(wbuf, wbe);
56285539 }
......@@ -5650,6 +5561,16 @@ void moneypunct_byname<wchar_t, true>::init(const char* nm) {
56505561
56515562void __do_nothing(void*) {}
56525563
5564// Legacy ABI __num_get functions - the new ones are _LIBCPP_HIDE_FROM_ABI
5565template <class _CharT>
5566string __num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep) {
5567 locale __loc = __iob.getloc();
5568 std::use_facet<ctype<_CharT> >(__loc).widen(__src, __src + __int_chr_cnt, __atoms);
5569 const numpunct<_CharT>& __np = std::use_facet<numpunct<_CharT> >(__loc);
5570 __thousands_sep = __np.thousands_sep();
5571 return __np.grouping();
5572}
5573
56535574template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<char>;
56545575_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<wchar_t>;)
56555576
lib/libcxx/src/memory.cpp+2
......@@ -11,7 +11,9 @@
1111# define _LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS
1212#endif
1313
14#include <__functional/hash.h>
1415#include <memory>
16#include <typeinfo>
1517
1618#if _LIBCPP_HAS_THREADS
1719# include <mutex>
lib/libcxx/src/memory_resource.cpp+4-4
......@@ -38,7 +38,7 @@ static bool is_aligned_to(void* ptr, size_t align) {
3838}
3939#endif
4040
41class _LIBCPP_EXPORTED_FROM_ABI __new_delete_memory_resource_imp : public memory_resource {
41class _LIBCPP_HIDDEN __new_delete_memory_resource_imp : public memory_resource {
4242 void* do_allocate(size_t bytes, size_t align) override {
4343#if _LIBCPP_HAS_ALIGNED_ALLOCATION
4444 return std::__libcpp_allocate<std::byte>(__element_count(bytes), align);
......@@ -48,7 +48,7 @@ class _LIBCPP_EXPORTED_FROM_ABI __new_delete_memory_resource_imp : public memory
4848 std::byte* result = std::__libcpp_allocate<std::byte>(__element_count(bytes), align);
4949 if (!is_aligned_to(result, align)) {
5050 std::__libcpp_deallocate<std::byte>(result, __element_count(bytes), align);
51 __throw_bad_alloc();
51 std::__throw_bad_alloc();
5252 }
5353 return result;
5454#endif
......@@ -63,8 +63,8 @@ class _LIBCPP_EXPORTED_FROM_ABI __new_delete_memory_resource_imp : public memory
6363
6464// null_memory_resource()
6565
66class _LIBCPP_EXPORTED_FROM_ABI __null_memory_resource_imp : public memory_resource {
67 void* do_allocate(size_t, size_t) override { __throw_bad_alloc(); }
66class _LIBCPP_HIDDEN __null_memory_resource_imp : public memory_resource {
67 void* do_allocate(size_t, size_t) override { std::__throw_bad_alloc(); }
6868 void do_deallocate(void*, size_t, size_t) override {}
6969 bool do_is_equal(const memory_resource& other) const noexcept override { return &other == this; }
7070};
lib/libcxx/src/mutex.cpp+5-4
......@@ -7,6 +7,7 @@
77//===----------------------------------------------------------------------===//
88
99#include <__assert>
10#include <__system_error/throw_system_error.h>
1011#include <__thread/id.h>
1112#include <__utility/exception_guard.h>
1213#include <limits>
......@@ -28,7 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2829void mutex::lock() {
2930 int ec = __libcpp_mutex_lock(&__m_);
3031 if (ec)
31 __throw_system_error(ec, "mutex lock failed");
32 std::__throw_system_error(ec, "mutex lock failed");
3233}
3334
3435bool mutex::try_lock() noexcept { return __libcpp_mutex_trylock(&__m_); }
......@@ -45,7 +46,7 @@ void mutex::unlock() noexcept {
4546recursive_mutex::recursive_mutex() {
4647 int ec = __libcpp_recursive_mutex_init(&__m_);
4748 if (ec)
48 __throw_system_error(ec, "recursive_mutex constructor failed");
49 std::__throw_system_error(ec, "recursive_mutex constructor failed");
4950}
5051
5152recursive_mutex::~recursive_mutex() {
......@@ -57,7 +58,7 @@ recursive_mutex::~recursive_mutex() {
5758void recursive_mutex::lock() {
5859 int ec = __libcpp_recursive_mutex_lock(&__m_);
5960 if (ec)
60 __throw_system_error(ec, "recursive_mutex lock failed");
61 std::__throw_system_error(ec, "recursive_mutex lock failed");
6162}
6263
6364void recursive_mutex::unlock() noexcept {
......@@ -108,7 +109,7 @@ void recursive_timed_mutex::lock() {
108109 unique_lock<mutex> lk(__m_);
109110 if (id == __id_) {
110111 if (__count_ == numeric_limits<size_t>::max())
111 __throw_system_error(EAGAIN, "recursive_timed_mutex lock limit reached");
112 std::__throw_system_error(EAGAIN, "recursive_timed_mutex lock limit reached");
112113 ++__count_;
113114 return;
114115 }
lib/libcxx/src/new.cpp+9-14
......@@ -43,7 +43,7 @@ static void* operator_new_impl(std::size_t size) {
4343 return p;
4444}
4545
46_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void* operator new(std::size_t size) _THROW_BAD_ALLOC {
46_LIBCPP_OVERRIDABLE_FUNCTION(void*, operator new, (std::size_t size)) _THROW_BAD_ALLOC {
4747 void* p = operator_new_impl(size);
4848 if (p == nullptr)
4949 __throw_bad_alloc_shim();
......@@ -54,7 +54,7 @@ _LIBCPP_WEAK void* operator new(size_t size, const std::nothrow_t&) noexcept {
5454# if !_LIBCPP_HAS_EXCEPTIONS
5555# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
5656 _LIBCPP_ASSERT_SHIM(
57 !std::__is_function_overridden(static_cast<void* (*)(std::size_t)>(&operator new)),
57 (!std::__is_function_overridden < void*(std::size_t), &operator new>()),
5858 "libc++ was configured with exceptions disabled and `operator new(size_t)` has been overridden, "
5959 "but `operator new(size_t, nothrow_t)` has not been overridden. This is problematic because "
6060 "`operator new(size_t, nothrow_t)` must call `operator new(size_t)`, which will terminate in case "
......@@ -74,15 +74,13 @@ _LIBCPP_WEAK void* operator new(size_t size, const std::nothrow_t&) noexcept {
7474# endif
7575}
7676
77_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void* operator new[](size_t size) _THROW_BAD_ALLOC {
78 return ::operator new(size);
79}
77_LIBCPP_OVERRIDABLE_FUNCTION(void*, operator new[], (size_t size)) _THROW_BAD_ALLOC { return ::operator new(size); }
8078
8179_LIBCPP_WEAK void* operator new[](size_t size, const std::nothrow_t&) noexcept {
8280# if !_LIBCPP_HAS_EXCEPTIONS
8381# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
8482 _LIBCPP_ASSERT_SHIM(
85 !std::__is_function_overridden(static_cast<void* (*)(std::size_t)>(&operator new[])),
83 (!std::__is_function_overridden < void*(std::size_t), &operator new[]>()),
8684 "libc++ was configured with exceptions disabled and `operator new[](size_t)` has been overridden, "
8785 "but `operator new[](size_t, nothrow_t)` has not been overridden. This is problematic because "
8886 "`operator new[](size_t, nothrow_t)` must call `operator new[](size_t)`, which will terminate in case "
......@@ -136,8 +134,7 @@ static void* operator_new_aligned_impl(std::size_t size, std::align_val_t alignm
136134 return p;
137135}
138136
139_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void*
140operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
137_LIBCPP_OVERRIDABLE_FUNCTION(void*, operator new, (std::size_t size, std::align_val_t alignment)) _THROW_BAD_ALLOC {
141138 void* p = operator_new_aligned_impl(size, alignment);
142139 if (p == nullptr)
143140 __throw_bad_alloc_shim();
......@@ -148,7 +145,7 @@ _LIBCPP_WEAK void* operator new(size_t size, std::align_val_t alignment, const s
148145# if !_LIBCPP_HAS_EXCEPTIONS
149146# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
150147 _LIBCPP_ASSERT_SHIM(
151 !std::__is_function_overridden(static_cast<void* (*)(std::size_t, std::align_val_t)>(&operator new)),
148 (!std::__is_function_overridden < void*(std::size_t, std::align_val_t), &operator new>()),
152149 "libc++ was configured with exceptions disabled and `operator new(size_t, align_val_t)` has been overridden, "
153150 "but `operator new(size_t, align_val_t, nothrow_t)` has not been overridden. This is problematic because "
154151 "`operator new(size_t, align_val_t, nothrow_t)` must call `operator new(size_t, align_val_t)`, which will "
......@@ -168,8 +165,7 @@ _LIBCPP_WEAK void* operator new(size_t size, std::align_val_t alignment, const s
168165# endif
169166}
170167
171_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void*
172operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
168_LIBCPP_OVERRIDABLE_FUNCTION(void*, operator new[], (size_t size, std::align_val_t alignment)) _THROW_BAD_ALLOC {
173169 return ::operator new(size, alignment);
174170}
175171
......@@ -177,14 +173,13 @@ _LIBCPP_WEAK void* operator new[](size_t size, std::align_val_t alignment, const
177173# if !_LIBCPP_HAS_EXCEPTIONS
178174# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
179175 _LIBCPP_ASSERT_SHIM(
180 !std::__is_function_overridden(static_cast<void* (*)(std::size_t, std::align_val_t)>(&operator new[])),
176 (!std::__is_function_overridden < void*(std::size_t, std::align_val_t), &operator new[]>()),
181177 "libc++ was configured with exceptions disabled and `operator new[](size_t, align_val_t)` has been overridden, "
182178 "but `operator new[](size_t, align_val_t, nothrow_t)` has not been overridden. This is problematic because "
183179 "`operator new[](size_t, align_val_t, nothrow_t)` must call `operator new[](size_t, align_val_t)`, which will "
184180 "terminate in case it fails to allocate, making it impossible for `operator new[](size_t, align_val_t, "
185181 "nothrow_t)` to fulfill its contract (since it should return nullptr upon failure). Please make sure you "
186 "override "
187 "`operator new[](size_t, align_val_t, nothrow_t)` as well.");
182 "override `operator new[](size_t, align_val_t, nothrow_t)` as well.");
188183# endif
189184
190185 return operator_new_aligned_impl(size, alignment);
lib/libcxx/src/optional.cpp+1-1
......@@ -23,7 +23,7 @@ const char* bad_optional_access::what() const noexcept { return "bad_optional_ac
2323// Even though it no longer exists in a header file
2424_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
2525
26class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS bad_optional_access : public std::logic_error {
26class _LIBCPP_EXPORTED_FROM_ABI bad_optional_access : public std::logic_error {
2727public:
2828 bad_optional_access() : std::logic_error("Bad optional Access") {}
2929
lib/libcxx/src/print.cpp+1-1
......@@ -51,7 +51,7 @@ __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::get_last_error(), "failed to write formatted output");
54 std::__throw_system_error(filesystem::detail::get_last_error(), "failed to write formatted output");
5555 }
5656}
5757# endif // _LIBCPP_HAS_WIDE_CHARACTERS
lib/libcxx/src/random.cpp+13-12
......@@ -16,6 +16,7 @@
1616#include <__system_error/throw_system_error.h>
1717#include <limits>
1818#include <random>
19#include <string>
1920
2021#include <errno.h>
2122#include <stdio.h>
......@@ -42,7 +43,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4243
4344random_device::random_device(const string& __token) {
4445 if (__token != "/dev/urandom")
45 __throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
46 std::__throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
4647}
4748
4849random_device::~random_device() {}
......@@ -52,7 +53,7 @@ unsigned random_device::operator()() {
5253 size_t n = sizeof(r);
5354 int err = getentropy(&r, n);
5455 if (err)
55 __throw_system_error(errno, "random_device getentropy failed");
56 std::__throw_system_error(errno, "random_device getentropy failed");
5657 return r;
5758}
5859
......@@ -68,7 +69,7 @@ unsigned random_device::operator()() { return arc4random(); }
6869
6970random_device::random_device(const string& __token) : __f_(open(__token.c_str(), O_RDONLY)) {
7071 if (__f_ < 0)
71 __throw_system_error(errno, ("random_device failed to open " + __token).c_str());
72 std::__throw_system_error(errno, ("random_device failed to open " + __token).c_str());
7273}
7374
7475random_device::~random_device() { close(__f_); }
......@@ -80,10 +81,10 @@ unsigned random_device::operator()() {
8081 while (n > 0) {
8182 ssize_t s = read(__f_, p, n);
8283 if (s == 0)
83 __throw_system_error(ENOMSG, "random_device got EOF");
84 std::__throw_system_error(ENOMSG, "random_device got EOF");
8485 if (s == -1) {
8586 if (errno != EINTR)
86 __throw_system_error(errno, "random_device got an unexpected error");
87 std::__throw_system_error(errno, "random_device got an unexpected error");
8788 continue;
8889 }
8990 n -= static_cast<size_t>(s);
......@@ -96,10 +97,10 @@ unsigned random_device::operator()() {
9697
9798random_device::random_device(const string& __token) {
9899 if (__token != "/dev/urandom")
99 __throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
100 std::__throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
100101 int error = nacl_secure_random_init();
101102 if (error)
102 __throw_system_error(error, ("random device failed to open " + __token).c_str());
103 std::__throw_system_error(error, ("random device failed to open " + __token).c_str());
103104}
104105
105106random_device::~random_device() {}
......@@ -110,9 +111,9 @@ unsigned random_device::operator()() {
110111 size_t bytes_written;
111112 int error = nacl_secure_random(&r, n, &bytes_written);
112113 if (error != 0)
113 __throw_system_error(error, "random_device failed getting bytes");
114 std::__throw_system_error(error, "random_device failed getting bytes");
114115 else if (bytes_written != n)
115 __throw_runtime_error("random_device failed to obtain enough bytes");
116 std::__throw_runtime_error("random_device failed to obtain enough bytes");
116117 return r;
117118}
118119
......@@ -120,7 +121,7 @@ unsigned random_device::operator()() {
120121
121122random_device::random_device(const string& __token) {
122123 if (__token != "/dev/urandom")
123 __throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
124 std::__throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
124125}
125126
126127random_device::~random_device() {}
......@@ -129,7 +130,7 @@ unsigned random_device::operator()() {
129130 unsigned r;
130131 errno_t err = rand_s(&r);
131132 if (err)
132 __throw_system_error(err, "random_device rand_s failed.");
133 std::__throw_system_error(err, "random_device rand_s failed.");
133134 return r;
134135}
135136
......@@ -137,7 +138,7 @@ unsigned random_device::operator()() {
137138
138139random_device::random_device(const string& __token) {
139140 if (__token != "/dev/urandom")
140 __throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
141 std::__throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
141142}
142143
143144random_device::~random_device() {}
lib/libcxx/src/ryu/d2fixed.cpp+1
......@@ -42,6 +42,7 @@
4242#include <__assert>
4343#include <__config>
4444#include <charconv>
45#include <cstddef>
4546#include <cstring>
4647
4748#include "include/ryu/common.h"
lib/libcxx/src/ryu/d2s.cpp+1
......@@ -42,6 +42,7 @@
4242#include <__assert>
4343#include <__config>
4444#include <charconv>
45#include <cstddef>
4546
4647#include "include/ryu/common.h"
4748#include "include/ryu/d2fixed.h"
lib/libcxx/src/ryu/f2s.cpp+2
......@@ -42,6 +42,8 @@
4242#include <__assert>
4343#include <__config>
4444#include <charconv>
45#include <cstdint>
46#include <cstddef>
4547
4648#include "include/ryu/common.h"
4749#include "include/ryu/d2fixed.h"
lib/libcxx/src/std_stream.h+1-1
......@@ -86,7 +86,7 @@ void __stdinbuf<_CharT>::imbue(const locale& __loc) {
8686 __encoding_ = __cv_->encoding();
8787 __always_noconv_ = __cv_->always_noconv();
8888 if (__encoding_ > __limit)
89 __throw_runtime_error("unsupported locale for standard input");
89 std::__throw_runtime_error("unsupported locale for standard input");
9090}
9191
9292template <class _CharT>
lib/libcxx/src/string.cpp+39-1
......@@ -37,7 +37,45 @@ void __basic_string_common<true>::__throw_out_of_range() const { std::__throw_ou
3737
3838#endif // _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
3939
40#define _LIBCPP_EXTERN_TEMPLATE_DEFINE(...) template __VA_ARGS__;
40// Define legacy ABI functions
41// ---------------------------
42
43#ifndef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
44
45template <class _CharT, class _Traits, class _Allocator>
46void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve) {
47 if (__libcpp_is_constant_evaluated())
48 __rep_ = __rep();
49 if (__reserve > max_size())
50 __throw_length_error();
51 pointer __p;
52 if (__fits_in_sso(__reserve)) {
53 __set_short_size(__sz);
54 __p = __get_short_pointer();
55 } else {
56 auto __allocation = std::__allocate_at_least(__alloc_, __recommend(__reserve) + 1);
57 __p = __allocation.ptr;
58 __begin_lifetime(__p, __allocation.count);
59 __set_long_pointer(__p);
60 __set_long_cap(__allocation.count);
61 __set_long_size(__sz);
62 }
63 traits_type::copy(std::__to_address(__p), __s, __sz);
64 traits_type::assign(__p[__sz], value_type());
65 __annotate_new(__sz);
66}
67
68# define STRING_LEGACY_API(CharT) \
69 template _LIBCPP_EXPORTED_FROM_ABI void basic_string<CharT>::__init(const value_type*, size_type, size_type)
70
71STRING_LEGACY_API(char);
72# if _LIBCPP_HAS_WIDE_CHARACTERS
73STRING_LEGACY_API(wchar_t);
74# endif
75
76#endif // _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
77
78#define _LIBCPP_EXTERN_TEMPLATE_DEFINE(...) template _LIBCPP_EXPORTED_FROM_ABI __VA_ARGS__;
4179#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
4280_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
4381# if _LIBCPP_HAS_WIDE_CHARACTERS
lib/libcxx/src/thread.cpp+4-2
......@@ -6,8 +6,10 @@
66//
77//===----------------------------------------------------------------------===//
88
9#include <__system_error/throw_system_error.h>
910#include <__thread/poll_with_backoff.h>
1011#include <__thread/timed_backoff_policy.h>
12#include <__utility/pair.h>
1113#include <exception>
1214#include <future>
1315#include <limits>
......@@ -46,7 +48,7 @@ void thread::join() {
4648 }
4749
4850 if (ec)
49 __throw_system_error(ec, "thread::join failed");
51 std::__throw_system_error(ec, "thread::join failed");
5052}
5153
5254void thread::detach() {
......@@ -58,7 +60,7 @@ void thread::detach() {
5860 }
5961
6062 if (ec)
61 __throw_system_error(ec, "thread::detach failed");
63 std::__throw_system_error(ec, "thread::detach failed");
6264}
6365
6466unsigned thread::hardware_concurrency() noexcept {
lib/libcxx/src/verbose_abort.cpp+1-1
......@@ -23,7 +23,7 @@ extern "C" void android_set_abort_message(const char* msg);
2323
2424_LIBCPP_BEGIN_NAMESPACE_STD
2525
26_LIBCPP_WEAK void __libcpp_verbose_abort(char const* format, ...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT {
26_LIBCPP_WEAK void __libcpp_verbose_abort(char const* format, ...) noexcept {
2727 // Write message to stderr. We do this before formatting into a
2828 // buffer so that we still get some information out if that fails.
2929 {