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
= __can_borrow
<_Tp
> && requires(_Tp
&& __t
) {
42 { _LIBCPP_AUTO_CAST(__t
.rend()) } -> sentinel_for
<decltype(ranges::rbegin(__t
))>;
48 concept __unqualified_rend
=
49 !__member_rend
<_Tp
> && __can_borrow
<_Tp
> && __class_or_enum
<remove_cvref_t
<_Tp
>> && requires(_Tp
&& __t
) {
51 { _LIBCPP_AUTO_CAST(rend(__t
)) } -> sentinel_for
<decltype(ranges::rbegin(__t
))>;
55 concept __can_reverse
= __can_borrow
<_Tp
> && !__member_rend
<_Tp
> && !__unqualified_rend
<_Tp
> && requires(_Tp
&& __t
) {
56 { ranges::begin(__t
) } -> same_as
<decltype(ranges::end(__t
))>;
57 { ranges::begin(__t
) } -> bidirectional_iterator
;
63 requires __member_rend
<_Tp
>
64 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp
&& __t
) const
65 noexcept(noexcept(_LIBCPP_AUTO_CAST(__t
.rend()))) {
66 return _LIBCPP_AUTO_CAST(__t
.rend());
70 requires __unqualified_rend
<_Tp
>
71 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp
&& __t
) const
72 noexcept(noexcept(_LIBCPP_AUTO_CAST(rend(__t
)))) {
73 return _LIBCPP_AUTO_CAST(rend(__t
));
77 requires __can_reverse
<_Tp
>
78 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp
&& __t
) const
79 noexcept(noexcept(ranges::begin(__t
))) {
80 return std::make_reverse_iterator(ranges::begin(__t
));
83 void operator()(auto&&) const = delete;
87 inline namespace __cpo
{
88 inline constexpr auto rend
= __rend::__fn
{};
92 // [range.access.crend]
98 requires is_lvalue_reference_v
<_Tp
&&>
99 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp
&& __t
) const
100 noexcept(noexcept(ranges::rend(static_cast<const remove_reference_t
<_Tp
>&>(__t
))))
101 -> decltype(ranges::rend(static_cast<const remove_reference_t
<_Tp
>&>(__t
))) {
102 return ranges::rend(static_cast<const remove_reference_t
<_Tp
>&>(__t
));
106 requires is_rvalue_reference_v
<_Tp
&&>
107 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp
&& __t
) const noexcept(
108 noexcept(ranges::rend(static_cast<const _Tp
&&>(__t
)))) -> decltype(ranges::rend(static_cast<const _Tp
&&>(__t
))) {
109 return ranges::rend(static_cast<const _Tp
&&>(__t
));
112 } // namespace __crend
114 inline namespace __cpo
{
115 inline constexpr auto crend
= __crend::__fn
{};
117 } // namespace ranges
119 #endif // _LIBCPP_STD_VER >= 20
121 _LIBCPP_END_NAMESPACE_STD
123 #endif // _LIBCPP___RANGES_REND_H