File indexing completed on 2026-05-03 08:13:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___CXX03___RANGES_ACCESS_H
0011 #define _LIBCPP___CXX03___RANGES_ACCESS_H
0012
0013 #include <__cxx03/__concepts/class_or_enum.h>
0014 #include <__cxx03/__config>
0015 #include <__cxx03/__iterator/concepts.h>
0016 #include <__cxx03/__iterator/readable_traits.h>
0017 #include <__cxx03/__ranges/enable_borrowed_range.h>
0018 #include <__cxx03/__type_traits/decay.h>
0019 #include <__cxx03/__type_traits/is_reference.h>
0020 #include <__cxx03/__type_traits/remove_cvref.h>
0021 #include <__cxx03/__type_traits/remove_reference.h>
0022 #include <__cxx03/__utility/auto_cast.h>
0023 #include <__cxx03/__utility/declval.h>
0024 #include <__cxx03/cstddef>
0025
0026 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0027 # pragma GCC system_header
0028 #endif
0029
0030 _LIBCPP_BEGIN_NAMESPACE_STD
0031
0032 #if _LIBCPP_STD_VER >= 20
0033
0034 namespace ranges {
0035 template <class _Tp>
0036 concept __can_borrow = is_lvalue_reference_v<_Tp> || enable_borrowed_range<remove_cvref_t<_Tp>>;
0037 }
0038
0039
0040
0041 namespace ranges {
0042 namespace __begin {
0043 template <class _Tp>
0044 concept __member_begin = __can_borrow<_Tp> && requires(_Tp&& __t) {
0045 { _LIBCPP_AUTO_CAST(__t.begin()) } -> input_or_output_iterator;
0046 };
0047
0048 void begin() = delete;
0049
0050 template <class _Tp>
0051 concept __unqualified_begin =
0052 !__member_begin<_Tp> && __can_borrow<_Tp> && __class_or_enum<remove_cvref_t<_Tp>> && requires(_Tp&& __t) {
0053 { _LIBCPP_AUTO_CAST(begin(__t)) } -> input_or_output_iterator;
0054 };
0055
0056 struct __fn {
0057 template <class _Tp>
0058 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp (&__t)[]) const noexcept
0059 requires(sizeof(_Tp) >= 0)
0060 {
0061 return __t + 0;
0062 }
0063
0064 template <class _Tp, size_t _Np>
0065 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp (&__t)[_Np]) const noexcept
0066 requires(sizeof(_Tp) >= 0)
0067 {
0068 return __t + 0;
0069 }
0070
0071 template <class _Tp>
0072 requires __member_begin<_Tp>
0073 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
0074 noexcept(noexcept(_LIBCPP_AUTO_CAST(__t.begin()))) {
0075 return _LIBCPP_AUTO_CAST(__t.begin());
0076 }
0077
0078 template <class _Tp>
0079 requires __unqualified_begin<_Tp>
0080 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
0081 noexcept(noexcept(_LIBCPP_AUTO_CAST(begin(__t)))) {
0082 return _LIBCPP_AUTO_CAST(begin(__t));
0083 }
0084
0085 void operator()(auto&&) const = delete;
0086 };
0087 }
0088
0089 inline namespace __cpo {
0090 inline constexpr auto begin = __begin::__fn{};
0091 }
0092 }
0093
0094
0095
0096 namespace ranges {
0097 template <class _Tp>
0098 using iterator_t = decltype(ranges::begin(std::declval<_Tp&>()));
0099 }
0100
0101
0102
0103 namespace ranges {
0104 namespace __end {
0105 template <class _Tp>
0106 concept __member_end = __can_borrow<_Tp> && requires(_Tp&& __t) {
0107 typename iterator_t<_Tp>;
0108 { _LIBCPP_AUTO_CAST(__t.end()) } -> sentinel_for<iterator_t<_Tp>>;
0109 };
0110
0111 void end() = delete;
0112
0113 template <class _Tp>
0114 concept __unqualified_end =
0115 !__member_end<_Tp> && __can_borrow<_Tp> && __class_or_enum<remove_cvref_t<_Tp>> && requires(_Tp&& __t) {
0116 typename iterator_t<_Tp>;
0117 { _LIBCPP_AUTO_CAST(end(__t)) } -> sentinel_for<iterator_t<_Tp>>;
0118 };
0119
0120 struct __fn {
0121 template <class _Tp, size_t _Np>
0122 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp (&__t)[_Np]) const noexcept
0123 requires(sizeof(_Tp) >= 0)
0124 {
0125 return __t + _Np;
0126 }
0127
0128 template <class _Tp>
0129 requires __member_end<_Tp>
0130 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
0131 noexcept(noexcept(_LIBCPP_AUTO_CAST(__t.end()))) {
0132 return _LIBCPP_AUTO_CAST(__t.end());
0133 }
0134
0135 template <class _Tp>
0136 requires __unqualified_end<_Tp>
0137 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
0138 noexcept(noexcept(_LIBCPP_AUTO_CAST(end(__t)))) {
0139 return _LIBCPP_AUTO_CAST(end(__t));
0140 }
0141
0142 void operator()(auto&&) const = delete;
0143 };
0144 }
0145
0146 inline namespace __cpo {
0147 inline constexpr auto end = __end::__fn{};
0148 }
0149 }
0150
0151
0152
0153 namespace ranges {
0154 namespace __cbegin {
0155 struct __fn {
0156 template <class _Tp>
0157 requires is_lvalue_reference_v<_Tp&&>
0158 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
0159 noexcept(noexcept(ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t))))
0160 -> decltype(ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t))) {
0161 return ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t));
0162 }
0163
0164 template <class _Tp>
0165 requires is_rvalue_reference_v<_Tp&&>
0166 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
0167 noexcept(noexcept(ranges::begin(static_cast<const _Tp&&>(__t))))
0168 -> decltype(ranges::begin(static_cast<const _Tp&&>(__t))) {
0169 return ranges::begin(static_cast<const _Tp&&>(__t));
0170 }
0171 };
0172 }
0173
0174 inline namespace __cpo {
0175 inline constexpr auto cbegin = __cbegin::__fn{};
0176 }
0177 }
0178
0179
0180
0181 namespace ranges {
0182 namespace __cend {
0183 struct __fn {
0184 template <class _Tp>
0185 requires is_lvalue_reference_v<_Tp&&>
0186 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
0187 noexcept(noexcept(ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t))))
0188 -> decltype(ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t))) {
0189 return ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t));
0190 }
0191
0192 template <class _Tp>
0193 requires is_rvalue_reference_v<_Tp&&>
0194 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const noexcept(
0195 noexcept(ranges::end(static_cast<const _Tp&&>(__t)))) -> decltype(ranges::end(static_cast<const _Tp&&>(__t))) {
0196 return ranges::end(static_cast<const _Tp&&>(__t));
0197 }
0198 };
0199 }
0200
0201 inline namespace __cpo {
0202 inline constexpr auto cend = __cend::__fn{};
0203 }
0204 }
0205
0206 #endif
0207
0208 _LIBCPP_END_NAMESPACE_STD
0209
0210 #endif