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_RBEGIN_H
11 #define _LIBCPP___RANGES_RBEGIN_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 <__type_traits/decay.h>
21 #include <__type_traits/is_reference.h>
22 #include <__type_traits/remove_cvref.h>
23 #include <__type_traits/remove_reference.h>
24 #include <__utility/auto_cast.h>
26 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27 # pragma GCC system_header
30 _LIBCPP_BEGIN_NAMESPACE_STD
32 #if _LIBCPP_STD_VER >= 20
34 // [ranges.access.rbegin]
39 concept __member_rbegin
=
41 __workaround_52970
<_Tp
> &&
43 { _LIBCPP_AUTO_CAST(__t
.rbegin()) } -> input_or_output_iterator
;
46 void rbegin(auto&) = delete;
47 void rbegin(const auto&) = delete;
50 concept __unqualified_rbegin
=
51 !__member_rbegin
<_Tp
> &&
53 __class_or_enum
<remove_cvref_t
<_Tp
>> &&
55 { _LIBCPP_AUTO_CAST(rbegin(__t
)) } -> input_or_output_iterator
;
59 concept __can_reverse
=
61 !__member_rbegin
<_Tp
> &&
62 !__unqualified_rbegin
<_Tp
> &&
64 { ranges::begin(__t
) } -> same_as
<decltype(ranges::end(__t
))>;
65 { ranges::begin(__t
) } -> bidirectional_iterator
;
70 requires __member_rbegin
<_Tp
>
71 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp
&& __t
) const
72 noexcept(noexcept(_LIBCPP_AUTO_CAST(__t
.rbegin())))
74 return _LIBCPP_AUTO_CAST(__t
.rbegin());
78 requires __unqualified_rbegin
<_Tp
>
79 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp
&& __t
) const
80 noexcept(noexcept(_LIBCPP_AUTO_CAST(rbegin(__t
))))
82 return _LIBCPP_AUTO_CAST(rbegin(__t
));
86 requires __can_reverse
<_Tp
>
87 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Tp
&& __t
) const
88 noexcept(noexcept(ranges::end(__t
)))
90 return std::make_reverse_iterator(ranges::end(__t
));
93 void operator()(auto&&) const = delete;
95 } // namespace __rbegin
97 inline namespace __cpo
{
98 inline constexpr auto rbegin
= __rbegin::__fn
{};
100 } // namespace ranges
102 // [range.access.crbegin]
105 namespace __crbegin
{
108 requires is_lvalue_reference_v
<_Tp
&&>
109 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
110 constexpr auto operator()(_Tp
&& __t
) const
111 noexcept(noexcept(ranges::rbegin(static_cast<const remove_reference_t
<_Tp
>&>(__t
))))
112 -> decltype( ranges::rbegin(static_cast<const remove_reference_t
<_Tp
>&>(__t
)))
113 { return ranges::rbegin(static_cast<const remove_reference_t
<_Tp
>&>(__t
)); }
116 requires is_rvalue_reference_v
<_Tp
&&>
117 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
118 constexpr auto operator()(_Tp
&& __t
) const
119 noexcept(noexcept(ranges::rbegin(static_cast<const _Tp
&&>(__t
))))
120 -> decltype( ranges::rbegin(static_cast<const _Tp
&&>(__t
)))
121 { return ranges::rbegin(static_cast<const _Tp
&&>(__t
)); }
123 } // namespace __crbegin
125 inline namespace __cpo
{
126 inline constexpr auto crbegin
= __crbegin::__fn
{};
128 } // namespace ranges
130 #endif // _LIBCPP_STD_VER >= 20
132 _LIBCPP_END_NAMESPACE_STD
134 #endif // _LIBCPP___RANGES_RBEGIN_H