xref: /netbsd-src/external/apache2/llvm/dist/libcxx/include/__ranges/data.h (revision 4d6fc14bc9b0c5bf3e30be318c143ee82cadd108)
1 // -*- C++ -*-
2 //===------------------------ __ranges/data.h ------------------------------===//
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 <__ranges/access.h>
16 #include <concepts>
17 #include <type_traits>
18 
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 #pragma GCC system_header
21 #endif
22 
23 _LIBCPP_PUSH_MACROS
24 #include <__undef_macros>
25 
26 _LIBCPP_BEGIN_NAMESPACE_STD
27 
28 #if !defined(_LIBCPP_HAS_NO_RANGES)
29 
30 // clang-format off
31 namespace ranges {
32 // [range.prim.data]
33 namespace __data {
34   template <class _Tp>
35   concept __ptr_to_object = is_pointer_v<_Tp> && is_object_v<remove_pointer_t<_Tp>>;
36 
37   template <class _Tp>
38   concept __member_data =
requires(_Tp && __t)39     requires(_Tp&& __t) {
40       { _VSTD::forward<_Tp>(__t) } -> __can_borrow;
41       { __t.data() } -> __ptr_to_object;
42     };
43 
44   template <class _Tp>
45   concept __ranges_begin_invocable =
46     !__member_data<_Tp> &&
47     requires(_Tp&& __t) {
48       { _VSTD::forward<_Tp>(__t) } -> __can_borrow;
49       { ranges::begin(_VSTD::forward<_Tp>(__t)) } -> contiguous_iterator;
50     };
51 
52   struct __fn {
53     template <__member_data _Tp>
54       requires __can_borrow<_Tp>
operator__fn55     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>
operator__fn62     constexpr __ptr_to_object auto operator()(_Tp&& __t) const
63         noexcept(noexcept(_VSTD::to_address(ranges::begin(_VSTD::forward<_Tp>(__t))))) {
64       return _VSTD::to_address(ranges::begin(_VSTD::forward<_Tp>(__t)));
65     }
66   };
67 } // end namespace __data
68 
69 inline namespace __cpo {
70   inline constexpr const auto data = __data::__fn{};
71 } // namespace __cpo
72 } // namespace ranges
73 
74 // clang-format off
75 
76 #endif // !defined(_LIBCPP_HAS_NO_RANGES)
77 
78 _LIBCPP_END_NAMESPACE_STD
79 
80 _LIBCPP_POP_MACROS
81 
82 #endif // _LIBCPP___RANGES_DATA_H
83