Skip to content

Commit b43e41f

Browse files
committed
cdata, including tests
drive-by: remove the `__ranges/data.h` header and merge it with `__ranges/access.h` (for `ranges::data`), or `__ranges/const_access.h` (for `ranges::cdata`). I felt comfortable doing this as every use of `__ranges/access.h` included either `__ranges/data.h` itself, or `__ranges/concepts.h` which itself included `__ranges/data.h`.
1 parent 913d2ea commit b43e41f

File tree

14 files changed

+197
-126
lines changed

14 files changed

+197
-126
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,6 @@ set(files
644644
__ranges/container_compatible_range.h
645645
__ranges/counted.h
646646
__ranges/dangling.h
647-
__ranges/data.h
648647
__ranges/drop_view.h
649648
__ranges/drop_while_view.h
650649
__ranges/elements_view.h

libcxx/include/__format/range_default_formatter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#include <__format/formatter.h>
2323
#include <__format/range_formatter.h>
2424
#include <__iterator/back_insert_iterator.h>
25+
#include <__ranges/access.h>
2526
#include <__ranges/concepts.h>
26-
#include <__ranges/data.h>
2727
#include <__ranges/from_range.h>
2828
#include <__ranges/size.h>
2929
#include <__type_traits/conditional.h>

libcxx/include/__format/range_formatter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
#include <__format/formatter_output.h>
2727
#include <__format/parser_std_format_spec.h>
2828
#include <__iterator/back_insert_iterator.h>
29+
#include <__ranges/access.h>
2930
#include <__ranges/concepts.h>
30-
#include <__ranges/data.h>
3131
#include <__ranges/from_range.h>
3232
#include <__ranges/size.h>
3333
#include <__type_traits/remove_cvref.h>

libcxx/include/__ranges/access.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
#include <__config>
1515
#include <__iterator/concepts.h>
1616
#include <__iterator/readable_traits.h>
17+
#include <__memory/pointer_traits.h>
1718
#include <__ranges/enable_borrowed_range.h>
1819
#include <__type_traits/decay.h>
20+
#include <__type_traits/is_pointer.h>
1921
#include <__type_traits/is_reference.h>
2022
#include <__type_traits/remove_cvref.h>
23+
#include <__type_traits/remove_pointer.h>
2124
#include <__type_traits/remove_reference.h>
2225
#include <__utility/auto_cast.h>
2326
#include <__utility/declval.h>
@@ -148,6 +151,42 @@ inline constexpr auto end = __end::__fn{};
148151
} // namespace __cpo
149152
} // namespace ranges
150153

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+
151190
#endif // _LIBCPP_STD_VER >= 20
152191

153192
_LIBCPP_END_NAMESPACE_STD

libcxx/include/__ranges/concepts.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <__iterator/iterator_traits.h>
2222
#include <__iterator/readable_traits.h>
2323
#include <__ranges/access.h>
24-
#include <__ranges/data.h>
2524
#include <__ranges/enable_borrowed_range.h>
2625
#include <__ranges/enable_view.h>
2726
#include <__ranges/size.h>

libcxx/include/__ranges/const_access.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,48 @@ inline constexpr auto crend = __crend::__fn{};
213213
} // namespace __cpo
214214
} // namespace ranges
215215

216+
// [range.prim.cdata]
217+
218+
namespace ranges {
219+
namespace __cdata {
220+
struct __fn {
221+
# if _LIBCPP_STD_VER >= 23
222+
template <class _Tp>
223+
_LIBCPP_HIDE_FROM_ABI constexpr static auto __as_const_pointer(const _Tp* __ptr) noexcept {
224+
return __ptr;
225+
}
226+
227+
template <__const_accessible_range _Rng>
228+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr static auto
229+
operator()(_Rng&& __rng) noexcept(noexcept(__as_const_pointer(ranges::data(ranges::__possibly_const_range(__rng)))))
230+
-> decltype(__as_const_pointer(ranges::data(ranges::__possibly_const_range(__rng)))) {
231+
return __as_const_pointer(ranges::data(ranges::__possibly_const_range(__rng)));
232+
}
233+
234+
# else // ^^^ _LIBCPP_STD_VER >= 23 / _LIBCPP_STD_VER < 23 vvv
235+
template <class _Tp>
236+
requires is_lvalue_reference_v<_Tp&&>
237+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
238+
noexcept(noexcept(ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t))))
239+
-> decltype(ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t))) {
240+
return ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t));
241+
}
242+
243+
template <class _Tp>
244+
requires is_rvalue_reference_v<_Tp&&>
245+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const noexcept(
246+
noexcept(ranges::data(static_cast<const _Tp&&>(__t)))) -> decltype(ranges::data(static_cast<const _Tp&&>(__t))) {
247+
return ranges::data(static_cast<const _Tp&&>(__t));
248+
}
249+
# endif // ^^^ _LIBCPP_STD_VER < 23
250+
};
251+
} // namespace __cdata
252+
253+
inline namespace __cpo {
254+
inline constexpr auto cdata = __cdata::__fn{};
255+
} // namespace __cpo
256+
} // namespace ranges
257+
216258
#endif // _LIBCPP_STD_VER >= 20
217259

218260
_LIBCPP_END_NAMESPACE_STD

libcxx/include/__ranges/data.h

Lines changed: 0 additions & 102 deletions
This file was deleted.

libcxx/include/__ranges/owning_view.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <__config>
1616
#include <__ranges/access.h>
1717
#include <__ranges/concepts.h>
18-
#include <__ranges/data.h>
1918
#include <__ranges/empty.h>
2019
#include <__ranges/enable_borrowed_range.h>
2120
#include <__ranges/size.h>

libcxx/include/__ranges/ref_view.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <__memory/addressof.h>
2020
#include <__ranges/access.h>
2121
#include <__ranges/concepts.h>
22-
#include <__ranges/data.h>
2322
#include <__ranges/empty.h>
2423
#include <__ranges/enable_borrowed_range.h>
2524
#include <__ranges/size.h>

libcxx/include/module.modulemap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,6 @@ module std_private_ranges_counted [system] {
17141714
export std_span
17151715
}
17161716
module std_private_ranges_dangling [system] { header "__ranges/dangling.h" }
1717-
module std_private_ranges_data [system] { header "__ranges/data.h" }
17181717
module std_private_ranges_drop_view [system] { header "__ranges/drop_view.h" }
17191718
module std_private_ranges_drop_while_view [system] { header "__ranges/drop_while_view.h" }
17201719
module std_private_ranges_elements_view [system] { header "__ranges/elements_view.h" }

0 commit comments

Comments
 (0)