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 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___RANGES_DATA_H
10 #define _LIBCPP___RANGES_DATA_H
12 #include <__concepts/class_or_enum.h>
14 #include <__iterator/concepts.h>
15 #include <__iterator/iterator_traits.h>
16 #include <__memory/pointer_traits.h>
17 #include <__ranges/access.h>
18 #include <__utility/auto_cast.h>
19 #include <type_traits>
21 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22 # pragma GCC system_header
25 _LIBCPP_BEGIN_NAMESPACE_STD
27 #if _LIBCPP_STD_VER > 17
34 concept __ptr_to_object = is_pointer_v<_Tp> && is_object_v<remove_pointer_t<_Tp>>;
37 concept __member_data =
39 __workaround_52970<_Tp> &&
41 { _LIBCPP_AUTO_CAST(__t.data()) } -> __ptr_to_object;
45 concept __ranges_begin_invocable =
46 !__member_data<_Tp> &&
49 { ranges::begin(__t) } -> contiguous_iterator;
53 template <__member_data _Tp>
55 constexpr auto operator()(_Tp&& __t) const
56 noexcept(noexcept(__t.data())) {
60 template<__ranges_begin_invocable _Tp>
62 constexpr auto operator()(_Tp&& __t) const
63 noexcept(noexcept(std::to_address(ranges::begin(__t)))) {
64 return std::to_address(ranges::begin(__t));
69 inline namespace __cpo {
70 inline constexpr auto data = __data::__fn{};
80 requires is_lvalue_reference_v<_Tp&&>
81 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
82 constexpr auto operator()(_Tp&& __t) const
83 noexcept(noexcept(ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t))))
84 -> decltype( ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t)))
85 { return ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t)); }
88 requires is_rvalue_reference_v<_Tp&&>
89 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
90 constexpr auto operator()(_Tp&& __t) const
91 noexcept(noexcept(ranges::data(static_cast<const _Tp&&>(__t))))
92 -> decltype( ranges::data(static_cast<const _Tp&&>(__t)))
93 { return ranges::data(static_cast<const _Tp&&>(__t)); }
95 } // namespace __cdata
97 inline namespace __cpo {
98 inline constexpr auto cdata = __cdata::__fn{};
100 } // namespace ranges
102 #endif // _LIBCPP_STD_VER > 17
104 _LIBCPP_END_NAMESPACE_STD
106 #endif // _LIBCPP___RANGES_DATA_H