124 lines · c
1// -*- C++ -*-2//===----------------------------------------------------------------------===//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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP___RANGES_REND_H11#define _LIBCPP___RANGES_REND_H12 13#include <__concepts/class_or_enum.h>14#include <__concepts/same_as.h>15#include <__config>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>26 27#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)28# pragma GCC system_header29#endif30 31_LIBCPP_BEGIN_NAMESPACE_STD32 33#if _LIBCPP_STD_VER >= 2034 35// [range.access.rend]36 37namespace ranges {38namespace __rend {39template <class _Tp>40concept __member_rend = __can_borrow<_Tp> && requires(_Tp&& __t) {41 ranges::rbegin(__t);42 { _LIBCPP_AUTO_CAST(__t.rend()) } -> sentinel_for<decltype(ranges::rbegin(__t))>;43};44 45void rend() = delete;46 47template <class _Tp>48concept __unqualified_rend =49 !__member_rend<_Tp> && __can_borrow<_Tp> && __class_or_enum<remove_cvref_t<_Tp>> && requires(_Tp&& __t) {50 ranges::rbegin(__t);51 { _LIBCPP_AUTO_CAST(rend(__t)) } -> sentinel_for<decltype(ranges::rbegin(__t))>;52 };53 54template <class _Tp>55concept __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;58};59 60class __fn {61public:62 template <class _Tp>63 requires __member_rend<_Tp>64 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const65 noexcept(noexcept(_LIBCPP_AUTO_CAST(__t.rend()))) {66 return _LIBCPP_AUTO_CAST(__t.rend());67 }68 69 template <class _Tp>70 requires __unqualified_rend<_Tp>71 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const72 noexcept(noexcept(_LIBCPP_AUTO_CAST(rend(__t)))) {73 return _LIBCPP_AUTO_CAST(rend(__t));74 }75 76 template <class _Tp>77 requires __can_reverse<_Tp>78 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const79 noexcept(noexcept(ranges::begin(__t))) {80 return std::make_reverse_iterator(ranges::begin(__t));81 }82 83 void operator()(auto&&) const = delete;84};85} // namespace __rend86 87inline namespace __cpo {88inline constexpr auto rend = __rend::__fn{};89} // namespace __cpo90} // namespace ranges91 92// [range.access.crend]93 94namespace ranges {95namespace __crend {96struct __fn {97 template <class _Tp>98 requires is_lvalue_reference_v<_Tp&&>99 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const100 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));103 }104 105 template <class _Tp>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));110 }111};112} // namespace __crend113 114inline namespace __cpo {115inline constexpr auto crend = __crend::__fn{};116} // namespace __cpo117} // namespace ranges118 119#endif // _LIBCPP_STD_VER >= 20120 121_LIBCPP_END_NAMESPACE_STD122 123#endif // _LIBCPP___RANGES_REND_H124