2 //===----------------------------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___RANGES_DATA_H
11 #define _LIBCPP___RANGES_DATA_H
13 #include <__concepts/class_or_enum.h>
15 #include <__iterator/concepts.h>
16 #include <__iterator/iterator_traits.h>
17 #include <__memory/pointer_traits.h>
18 #include <__ranges/access.h>
19 #include <__type_traits/decay.h>
20 #include <__type_traits/is_object.h>
21 #include <__type_traits/is_pointer.h>
22 #include <__type_traits/is_reference.h>
23 #include <__type_traits/remove_pointer.h>
24 #include <__type_traits/remove_reference.h>
25 #include <__utility/auto_cast.h>
27 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28 # pragma GCC system_header
31 _LIBCPP_BEGIN_NAMESPACE_STD
33 #if _LIBCPP_STD_VER >= 20
40 concept __ptr_to_object
= is_pointer_v
<_Tp
> && is_object_v
<remove_pointer_t
<_Tp
>>;
43 concept __member_data
=
45 __workaround_52970
<_Tp
> &&
47 { _LIBCPP_AUTO_CAST(__t
.data()) } -> __ptr_to_object
;
51 concept __ranges_begin_invocable
=
52 !__member_data
<_Tp
> &&
55 { ranges::begin(__t
) } -> contiguous_iterator
;
59 template <__member_data _Tp
>
61 constexpr auto operator()(_Tp
&& __t
) const
62 noexcept(noexcept(__t
.data())) {
66 template<__ranges_begin_invocable _Tp
>
68 constexpr auto operator()(_Tp
&& __t
) const
69 noexcept(noexcept(std::to_address(ranges::begin(__t
)))) {
70 return std::to_address(ranges::begin(__t
));
75 inline namespace __cpo
{
76 inline constexpr auto data
= __data::__fn
{};
86 requires is_lvalue_reference_v
<_Tp
&&>
87 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
88 constexpr auto operator()(_Tp
&& __t
) const
89 noexcept(noexcept(ranges::data(static_cast<const remove_reference_t
<_Tp
>&>(__t
))))
90 -> decltype( ranges::data(static_cast<const remove_reference_t
<_Tp
>&>(__t
)))
91 { return ranges::data(static_cast<const remove_reference_t
<_Tp
>&>(__t
)); }
94 requires is_rvalue_reference_v
<_Tp
&&>
95 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
96 constexpr auto operator()(_Tp
&& __t
) const
97 noexcept(noexcept(ranges::data(static_cast<const _Tp
&&>(__t
))))
98 -> decltype( ranges::data(static_cast<const _Tp
&&>(__t
)))
99 { return ranges::data(static_cast<const _Tp
&&>(__t
)); }
101 } // namespace __cdata
103 inline namespace __cpo
{
104 inline constexpr auto cdata
= __cdata::__fn
{};
106 } // namespace ranges
108 #endif // _LIBCPP_STD_VER >= 20
110 _LIBCPP_END_NAMESPACE_STD
112 #endif // _LIBCPP___RANGES_DATA_H