1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 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 7 // 8 //===----------------------------------------------------------------------===// 9 #ifndef _LIBCPP___RANGES_DATA_H 10 #define _LIBCPP___RANGES_DATA_H 11 12 #include <__concepts/class_or_enum.h> 13 #include <__config> 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> 20 21 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 22 #pragma GCC system_header 23 #endif 24 25 _LIBCPP_BEGIN_NAMESPACE_STD 26 27 #if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 28 29 // [range.prim.data] 30 31 namespace ranges { 32 namespace __data { 33 template <class _Tp> 34 concept __ptr_to_object = is_pointer_v<_Tp> && is_object_v<remove_pointer_t<_Tp>>; 35 36 template <class _Tp> 37 concept __member_data = 38 __can_borrow<_Tp> && 39 __workaround_52970<_Tp> && 40 requires(_Tp&& __t) { 41 { _LIBCPP_AUTO_CAST(__t.data()) } -> __ptr_to_object; 42 }; 43 44 template <class _Tp> 45 concept __ranges_begin_invocable = 46 !__member_data<_Tp> && 47 __can_borrow<_Tp> && 48 requires(_Tp&& __t) { 49 { ranges::begin(__t) } -> contiguous_iterator; 50 }; 51 52 struct __fn { 53 template <__member_data _Tp> 54 _LIBCPP_HIDE_FROM_ABI 55 constexpr auto operator()(_Tp&& __t) const 56 noexcept(noexcept(__t.data())) { 57 return __t.data(); 58 } 59 60 template<__ranges_begin_invocable _Tp> 61 _LIBCPP_HIDE_FROM_ABI 62 constexpr auto operator()(_Tp&& __t) const 63 noexcept(noexcept(_VSTD::to_address(ranges::begin(__t)))) { 64 return _VSTD::to_address(ranges::begin(__t)); 65 } 66 }; 67 } // namespace __data 68 69 inline namespace __cpo { 70 inline constexpr auto data = __data::__fn{}; 71 } // namespace __cpo 72 } // namespace ranges 73 74 // [range.prim.cdata] 75 76 namespace ranges { 77 namespace __cdata { 78 struct __fn { 79 template <class _Tp> 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)); } 86 87 template <class _Tp> 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)); } 94 }; 95 } // namespace __cdata 96 97 inline namespace __cpo { 98 inline constexpr auto cdata = __cdata::__fn{}; 99 } // namespace __cpo 100 } // namespace ranges 101 102 #endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 103 104 _LIBCPP_END_NAMESPACE_STD 105 106 #endif // _LIBCPP___RANGES_DATA_H 107