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___CXX03___RANGES_DATA_H
11 #define _LIBCPP___CXX03___RANGES_DATA_H
13 #include <__cxx03/__concepts/class_or_enum.h>
14 #include <__cxx03/__config>
15 #include <__cxx03/__iterator/concepts.h>
16 #include <__cxx03/__iterator/iterator_traits.h>
17 #include <__cxx03/__memory/pointer_traits.h>
18 #include <__cxx03/__ranges/access.h>
19 #include <__cxx03/__type_traits/decay.h>
20 #include <__cxx03/__type_traits/is_object.h>
21 #include <__cxx03/__type_traits/is_pointer.h>
22 #include <__cxx03/__type_traits/is_reference.h>
23 #include <__cxx03/__type_traits/remove_pointer.h>
24 #include <__cxx03/__type_traits/remove_reference.h>
25 #include <__cxx03/__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
= __can_borrow
<_Tp
> && requires(_Tp
&& __t
) {
44 { _LIBCPP_AUTO_CAST(__t
.data()) } -> __ptr_to_object
;
48 concept __ranges_begin_invocable
= !__member_data
<_Tp
> && __can_borrow
<_Tp
> && requires(_Tp
&& __t
) {
49 { ranges::begin(__t
) } -> contiguous_iterator
;
53 template <__member_data _Tp
>
54 _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp
&& __t
) const noexcept(noexcept(__t
.data())) {
58 template <__ranges_begin_invocable _Tp
>
59 _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp
&& __t
) const
60 noexcept(noexcept(std::to_address(ranges::begin(__t
)))) {
61 return std::to_address(ranges::begin(__t
));
66 inline namespace __cpo
{
67 inline constexpr auto data
= __data::__fn
{};
77 requires is_lvalue_reference_v
<_Tp
&&>
78 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp
&& __t
) const
79 noexcept(noexcept(ranges::data(static_cast<const remove_reference_t
<_Tp
>&>(__t
))))
80 -> decltype(ranges::data(static_cast<const remove_reference_t
<_Tp
>&>(__t
))) {
81 return ranges::data(static_cast<const remove_reference_t
<_Tp
>&>(__t
));
85 requires is_rvalue_reference_v
<_Tp
&&>
86 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp
&& __t
) const noexcept(
87 noexcept(ranges::data(static_cast<const _Tp
&&>(__t
)))) -> decltype(ranges::data(static_cast<const _Tp
&&>(__t
))) {
88 return ranges::data(static_cast<const _Tp
&&>(__t
));
91 } // namespace __cdata
93 inline namespace __cpo
{
94 inline constexpr auto cdata
= __cdata::__fn
{};
98 #endif // _LIBCPP_STD_VER >= 20
100 _LIBCPP_END_NAMESPACE_STD
102 #endif // _LIBCPP___CXX03___RANGES_DATA_H