2 //===----------------------------------------------------------------------===//
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 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___RANGES_REND_H
11 #define _LIBCPP___RANGES_REND_H
13 #include <__concepts/class_or_enum.h>
14 #include <__concepts/same_as.h>
16 #include <__iterator/concepts.h>
17 #include <__iterator/readable_traits.h>
18 #include <__iterator/reverse_iterator.h>
19 #include <__ranges/access.h>
20 #include <__ranges/rbegin.h>
21 #include <__type_traits/decay.h>
22 #include <__type_traits/is_reference.h>
23 #include <__type_traits/remove_cvref.h>
24 #include <__type_traits/remove_reference.h>
25 #include <__utility/auto_cast.h>
27 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28 # pragma GCC system_header
31 _LIBCPP_BEGIN_NAMESPACE_STD
33 #if _LIBCPP_STD_VER >= 20
35 // [range.access.rend]
40 concept __member_rend
=
42 __workaround_52970
<_Tp
> &&
45 { _LIBCPP_AUTO_CAST(__t
.rend()) } -> sentinel_for
<decltype(ranges::rbegin(__t
))>;
48 void rend(auto&) = delete;
49 void rend(const auto&) = delete;
52 concept __unqualified_rend
=
53 !__member_rend
<_Tp
> &&
55 __class_or_enum
<remove_cvref_t
<_Tp
>> &&
58 { _LIBCPP_AUTO_CAST(rend(__t
)) } -> sentinel_for
<decltype(ranges::rbegin(__t
))>;
62 concept __can_reverse
=
64 !__member_rend
<_Tp
> &&
65 !__unqualified_rend
<_Tp
> &&
67 { ranges::begin(__t
) } -> same_as
<decltype(ranges::end(__t
))>;
68 { ranges::begin(__t
) } -> bidirectional_iterator
;
74 requires __member_rend
<_Tp
>
75 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp
&& __t
) const
76 noexcept(noexcept(_LIBCPP_AUTO_CAST(__t
.rend())))
78 return _LIBCPP_AUTO_CAST(__t
.rend());
82 requires __unqualified_rend
<_Tp
>
83 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp
&& __t
) const
84 noexcept(noexcept(_LIBCPP_AUTO_CAST(rend(__t
))))
86 return _LIBCPP_AUTO_CAST(rend(__t
));
90 requires __can_reverse
<_Tp
>
91 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp
&& __t
) const
92 noexcept(noexcept(ranges::begin(__t
)))
94 return std::make_reverse_iterator(ranges::begin(__t
));
97 void operator()(auto&&) const = delete;
101 inline namespace __cpo
{
102 inline constexpr auto rend
= __rend::__fn
{};
104 } // namespace ranges
106 // [range.access.crend]
112 requires is_lvalue_reference_v
<_Tp
&&>
113 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
114 constexpr auto operator()(_Tp
&& __t
) const
115 noexcept(noexcept(ranges::rend(static_cast<const remove_reference_t
<_Tp
>&>(__t
))))
116 -> decltype( ranges::rend(static_cast<const remove_reference_t
<_Tp
>&>(__t
)))
117 { return ranges::rend(static_cast<const remove_reference_t
<_Tp
>&>(__t
)); }
120 requires is_rvalue_reference_v
<_Tp
&&>
121 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
122 constexpr auto operator()(_Tp
&& __t
) const
123 noexcept(noexcept(ranges::rend(static_cast<const _Tp
&&>(__t
))))
124 -> decltype( ranges::rend(static_cast<const _Tp
&&>(__t
)))
125 { return ranges::rend(static_cast<const _Tp
&&>(__t
)); }
127 } // namespace __crend
129 inline namespace __cpo
{
130 inline constexpr auto crend
= __crend::__fn
{};
132 } // namespace ranges
134 #endif // _LIBCPP_STD_VER >= 20
136 _LIBCPP_END_NAMESPACE_STD
138 #endif // _LIBCPP___RANGES_REND_H