|
14 | 14 | #include <__config> |
15 | 15 | #include <__iterator/concepts.h> |
16 | 16 | #include <__iterator/readable_traits.h> |
| 17 | +#include <__memory/pointer_traits.h> |
17 | 18 | #include <__ranges/enable_borrowed_range.h> |
18 | 19 | #include <__type_traits/decay.h> |
| 20 | +#include <__type_traits/is_pointer.h> |
19 | 21 | #include <__type_traits/is_reference.h> |
20 | 22 | #include <__type_traits/remove_cvref.h> |
| 23 | +#include <__type_traits/remove_pointer.h> |
21 | 24 | #include <__type_traits/remove_reference.h> |
22 | 25 | #include <__utility/auto_cast.h> |
23 | 26 | #include <__utility/declval.h> |
@@ -148,6 +151,42 @@ inline constexpr auto end = __end::__fn{}; |
148 | 151 | } // namespace __cpo |
149 | 152 | } // namespace ranges |
150 | 153 |
|
| 154 | +// [range.prim.data] |
| 155 | + |
| 156 | +namespace ranges { |
| 157 | +namespace __data { |
| 158 | +template <class _Tp> |
| 159 | +concept __ptr_to_object = is_pointer_v<_Tp> && is_object_v<remove_pointer_t<_Tp>>; |
| 160 | + |
| 161 | +template <class _Tp> |
| 162 | +concept __member_data = __can_borrow<_Tp> && requires(_Tp&& __t) { |
| 163 | + { _LIBCPP_AUTO_CAST(__t.data()) } -> __ptr_to_object; |
| 164 | +}; |
| 165 | + |
| 166 | +template <class _Tp> |
| 167 | +concept __ranges_begin_invocable = !__member_data<_Tp> && __can_borrow<_Tp> && requires(_Tp&& __t) { |
| 168 | + { ranges::begin(__t) } -> contiguous_iterator; |
| 169 | +}; |
| 170 | + |
| 171 | +struct __fn { |
| 172 | + template <__member_data _Tp> |
| 173 | + _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const noexcept(noexcept(__t.data())) { |
| 174 | + return __t.data(); |
| 175 | + } |
| 176 | + |
| 177 | + template <__ranges_begin_invocable _Tp> |
| 178 | + _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const |
| 179 | + noexcept(noexcept(std::to_address(ranges::begin(__t)))) { |
| 180 | + return std::to_address(ranges::begin(__t)); |
| 181 | + } |
| 182 | +}; |
| 183 | +} // namespace __data |
| 184 | + |
| 185 | +inline namespace __cpo { |
| 186 | +inline constexpr auto data = __data::__fn{}; |
| 187 | +} // namespace __cpo |
| 188 | +} // namespace ranges |
| 189 | + |
151 | 190 | #endif // _LIBCPP_STD_VER >= 20 |
152 | 191 |
|
153 | 192 | _LIBCPP_END_NAMESPACE_STD |
|
0 commit comments