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 <__config> 13 #include <__iterator/concepts.h> 14 #include <__iterator/iterator_traits.h> 15 #include <__memory/pointer_traits.h> 16 #include <__ranges/access.h> 17 #include <__utility/forward.h> 18 #include <concepts> 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_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 requires(_Tp&& __t) { 39 { _VSTD::forward<_Tp>(__t) } -> __can_borrow; 40 { __t.data() } -> __ptr_to_object; 41 }; 42 43 template <class _Tp> 44 concept __ranges_begin_invocable = 45 !__member_data<_Tp> && 46 requires(_Tp&& __t) { 47 { _VSTD::forward<_Tp>(__t) } -> __can_borrow; 48 { ranges::begin(_VSTD::forward<_Tp>(__t)) } -> contiguous_iterator; 49 }; 50 51 struct __fn { 52 template <__member_data _Tp> 53 requires __can_borrow<_Tp> 54 _LIBCPP_HIDE_FROM_ABI 55 constexpr __ptr_to_object auto operator()(_Tp&& __t) const 56 noexcept(noexcept(__t.data())) { 57 return __t.data(); 58 } 59 60 template<__ranges_begin_invocable _Tp> 61 requires __can_borrow<_Tp> 62 _LIBCPP_HIDE_FROM_ABI 63 constexpr __ptr_to_object auto operator()(_Tp&& __t) const 64 noexcept(noexcept(_VSTD::to_address(ranges::begin(_VSTD::forward<_Tp>(__t))))) { 65 return _VSTD::to_address(ranges::begin(_VSTD::forward<_Tp>(__t))); 66 } 67 }; 68 } 69 70 inline namespace __cpo { 71 inline constexpr auto data = __data::__fn{}; 72 } // namespace __cpo 73 } // namespace ranges 74 75 #endif // !defined(_LIBCPP_HAS_NO_RANGES) 76 77 _LIBCPP_END_NAMESPACE_STD 78 79 #endif // _LIBCPP___RANGES_DATA_H 80