2 //===------------------------ __ranges/data.h ------------------------------===//
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
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>
19 #include <type_traits>
21 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22 #pragma GCC system_header
26 #include <__undef_macros>
28 _LIBCPP_BEGIN_NAMESPACE_STD
30 #if !defined(_LIBCPP_HAS_NO_RANGES)
37 concept __ptr_to_object = is_pointer_v<_Tp> && is_object_v<remove_pointer_t<_Tp>>;
40 concept __member_data =
42 { _VSTD::forward<_Tp>(__t) } -> __can_borrow;
43 { __t.data() } -> __ptr_to_object;
47 concept __ranges_begin_invocable =
48 !__member_data<_Tp> &&
50 { _VSTD::forward<_Tp>(__t) } -> __can_borrow;
51 { ranges::begin(_VSTD::forward<_Tp>(__t)) } -> contiguous_iterator;
55 template <__member_data _Tp>
56 requires __can_borrow<_Tp>
58 constexpr __ptr_to_object auto operator()(_Tp&& __t) const
59 noexcept(noexcept(__t.data())) {
63 template<__ranges_begin_invocable _Tp>
64 requires __can_borrow<_Tp>
66 constexpr __ptr_to_object auto operator()(_Tp&& __t) const
67 noexcept(noexcept(_VSTD::to_address(ranges::begin(_VSTD::forward<_Tp>(__t))))) {
68 return _VSTD::to_address(ranges::begin(_VSTD::forward<_Tp>(__t)));
71 } // end namespace __data
73 inline namespace __cpo {
74 inline constexpr const auto data = __data::__fn{};
80 #endif // !defined(_LIBCPP_HAS_NO_RANGES)
82 _LIBCPP_END_NAMESPACE_STD
86 #endif // _LIBCPP___RANGES_DATA_H