Skip to content

Commit 5f9d8ff

Browse files
Product code changes
- Add missed `_LIBCPP_NODEBUG`. - Adjust dispatching order for `__as_const::__fn`. - Reuse `__can_borrow`.
1 parent 22f1dac commit 5f9d8ff

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

libcxx/include/__ranges/as_const_view.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,22 @@ inline constexpr bool __is_span_v = false; // true if and only if _Tp is a speci
114114
template <class _Tp, size_t _Extent>
115115
inline constexpr bool __is_span_v<span<_Tp, _Extent>> = true;
116116

117-
template <class _UType>
117+
template <class>
118118
struct __xtype {
119-
using type = void;
119+
using type _LIBCPP_NODEBUG = void;
120120
};
121121
template <class _XType>
122122
struct __xtype<empty_view<_XType>> {
123-
using type = _XType;
123+
using type _LIBCPP_NODEBUG = _XType;
124124
};
125125
template <class _XType, size_t _Extent>
126126
struct __xtype<span<_XType, _Extent>> {
127-
using type = _XType;
127+
using type _LIBCPP_NODEBUG = _XType;
128128
constexpr static size_t __extent = _Extent;
129129
};
130130
template <class _XType>
131131
struct __xtype<ref_view<_XType>> {
132-
using type = _XType;
132+
using type _LIBCPP_NODEBUG = _XType;
133133
};
134134

135135
struct __fn : __range_adaptor_closure<__fn> {
@@ -146,12 +146,10 @@ struct __fn : __range_adaptor_closure<__fn> {
146146

147147
template <class _Type>
148148
static consteval pair<__strategy, bool> __choose_strategy() {
149-
using _UType = std::remove_cvref_t<_Type>;
149+
using _UType = remove_cvref_t<_Type>;
150150
using _XType = __xtype<_UType>::type;
151151

152-
if constexpr (!requires { typename all_t<_Type>; }) {
153-
return {__strategy::__none, false};
154-
} else if constexpr (constant_range<all_t<_Type>>) {
152+
if constexpr (requires { requires constant_range<views::all_t<_Type>>; }) {
155153
return {__strategy::__already_const, noexcept(views::all(std::declval<_Type>()))};
156154
} else if constexpr (__is_specialization_v<_UType, empty_view>) {
157155
return {__strategy::__empty_view, true};
@@ -162,16 +160,18 @@ struct __fn : __range_adaptor_closure<__fn> {
162160
} else if constexpr (is_lvalue_reference_v<_Type> && constant_range<const _UType> && !view<_UType>) {
163161
return {__strategy::__const_is_constant_range,
164162
noexcept(ref_view(static_cast<const _UType&>(std::declval<_Type>())))};
165-
} else {
163+
} else if (requires { as_const_view(std::declval<_Type>()); }) {
166164
return {__strategy::__otherwise, noexcept(as_const_view(std::declval<_Type>()))};
165+
} else {
166+
return {__strategy::__none, false};
167167
}
168168
}
169169

170170
template <class _Type>
171171
requires(__choose_strategy<_Type>().first != __strategy::__none)
172172
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr static auto
173173
operator()(_Type&& __range) noexcept(__choose_strategy<_Type>().second) {
174-
using _UType = std::remove_cvref_t<_Type>;
174+
using _UType = remove_cvref_t<_Type>;
175175
using _XType = __xtype<_UType>::type;
176176

177177
constexpr auto __st = __choose_strategy<_Type>().first;

libcxx/include/__ranges/const_access.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,13 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto& __possibly_const_range(_Rp& __rng) noexcep
4444

4545
// [range.access.cbegin]
4646

47-
template <class _Type>
48-
concept __const_accessible_range = (!is_rvalue_reference_v<_Type&&> || enable_borrowed_range<remove_cv_t<_Type>>);
49-
5047
namespace __cbegin {
5148
struct __fn {
5249
# if _LIBCPP_STD_VER >= 23
5350
template <class _Rng>
5451
using _UType _LIBCPP_NODEBUG = decltype(ranges::begin(ranges::__possibly_const_range(std::declval<_Rng&>())));
5552

56-
template <__const_accessible_range _Rng>
53+
template <__can_borrow _Rng>
5754
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr static auto operator()(_Rng&& __rng) noexcept(
5855
noexcept(const_iterator<_UType<_Rng>>(ranges::begin(ranges::__possibly_const_range(__rng)))))
5956
-> const_iterator<_UType<_Rng>> {
@@ -97,7 +94,7 @@ struct __fn {
9794
template <class _Rng>
9895
using _UType _LIBCPP_NODEBUG = decltype(ranges::end(ranges::__possibly_const_range(std::declval<_Rng&>())));
9996

100-
template <__const_accessible_range _Rng>
97+
template <__can_borrow _Rng>
10198
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr static auto operator()(_Rng&& __rng) noexcept(
10299
noexcept(const_sentinel<_UType<_Rng>>(ranges::end(ranges::__possibly_const_range(__rng)))))
103100
-> const_sentinel<_UType<_Rng>> {
@@ -140,7 +137,7 @@ struct __fn {
140137
template <class _Rng>
141138
using _UType _LIBCPP_NODEBUG = decltype(ranges::rbegin(ranges::__possibly_const_range(std::declval<_Rng&>())));
142139

143-
template <__const_accessible_range _Rng>
140+
template <__can_borrow _Rng>
144141
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr static auto operator()(_Rng&& __rng) noexcept(
145142
noexcept(const_iterator<_UType<_Rng>>(ranges::rbegin(ranges::__possibly_const_range(__rng)))))
146143
-> const_iterator<_UType<_Rng>> {
@@ -177,7 +174,7 @@ struct __fn {
177174
template <class _Rng>
178175
using _UType _LIBCPP_NODEBUG = decltype(ranges::rend(ranges::__possibly_const_range(std::declval<_Rng&>())));
179176

180-
template <__const_accessible_range _Rng>
177+
template <__can_borrow _Rng>
181178
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr static auto operator()(_Rng&& __rng) noexcept(
182179
noexcept(const_sentinel<_UType<_Rng>>(ranges::rend(ranges::__possibly_const_range(__rng)))))
183180
-> const_sentinel<_UType<_Rng>> {
@@ -217,7 +214,7 @@ struct __fn {
217214
return __ptr;
218215
}
219216

220-
template <__const_accessible_range _Rng>
217+
template <__can_borrow _Rng>
221218
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr static auto
222219
operator()(_Rng&& __rng) noexcept(noexcept(__as_const_pointer(ranges::data(ranges::__possibly_const_range(__rng)))))
223220
-> decltype(__as_const_pointer(ranges::data(ranges::__possibly_const_range(__rng)))) {

0 commit comments

Comments
 (0)