181ad6265SDimitry Andric // -*- C++ -*- 281ad6265SDimitry Andric //===----------------------------------------------------------------------===// 381ad6265SDimitry Andric // 481ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 581ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 681ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 781ad6265SDimitry Andric // 881ad6265SDimitry Andric //===----------------------------------------------------------------------===// 9bdd1243dSDimitry Andric 1081ad6265SDimitry Andric #ifndef _LIBCPP___RANGES_RBEGIN_H 1181ad6265SDimitry Andric #define _LIBCPP___RANGES_RBEGIN_H 1281ad6265SDimitry Andric 1381ad6265SDimitry Andric #include <__concepts/class_or_enum.h> 1481ad6265SDimitry Andric #include <__concepts/same_as.h> 1581ad6265SDimitry Andric #include <__config> 1681ad6265SDimitry Andric #include <__iterator/concepts.h> 1781ad6265SDimitry Andric #include <__iterator/readable_traits.h> 1881ad6265SDimitry Andric #include <__iterator/reverse_iterator.h> 1981ad6265SDimitry Andric #include <__ranges/access.h> 20*06c3fb27SDimitry Andric #include <__type_traits/decay.h> 21*06c3fb27SDimitry Andric #include <__type_traits/is_reference.h> 22*06c3fb27SDimitry Andric #include <__type_traits/remove_cvref.h> 23*06c3fb27SDimitry Andric #include <__type_traits/remove_reference.h> 2481ad6265SDimitry Andric #include <__utility/auto_cast.h> 2581ad6265SDimitry Andric 2681ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 2781ad6265SDimitry Andric # pragma GCC system_header 2881ad6265SDimitry Andric #endif 2981ad6265SDimitry Andric 3081ad6265SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 3181ad6265SDimitry Andric 32*06c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20 3381ad6265SDimitry Andric 3481ad6265SDimitry Andric // [ranges.access.rbegin] 3581ad6265SDimitry Andric 3681ad6265SDimitry Andric namespace ranges { 3781ad6265SDimitry Andric namespace __rbegin { 3881ad6265SDimitry Andric template <class _Tp> 3981ad6265SDimitry Andric concept __member_rbegin = 4081ad6265SDimitry Andric __can_borrow<_Tp> && 4181ad6265SDimitry Andric __workaround_52970<_Tp> && 4281ad6265SDimitry Andric requires(_Tp&& __t) { 4381ad6265SDimitry Andric { _LIBCPP_AUTO_CAST(__t.rbegin()) } -> input_or_output_iterator; 4481ad6265SDimitry Andric }; 4581ad6265SDimitry Andric 4681ad6265SDimitry Andric void rbegin(auto&) = delete; 4781ad6265SDimitry Andric void rbegin(const auto&) = delete; 4881ad6265SDimitry Andric 4981ad6265SDimitry Andric template <class _Tp> 5081ad6265SDimitry Andric concept __unqualified_rbegin = 5181ad6265SDimitry Andric !__member_rbegin<_Tp> && 5281ad6265SDimitry Andric __can_borrow<_Tp> && 5381ad6265SDimitry Andric __class_or_enum<remove_cvref_t<_Tp>> && 5481ad6265SDimitry Andric requires(_Tp&& __t) { 5581ad6265SDimitry Andric { _LIBCPP_AUTO_CAST(rbegin(__t)) } -> input_or_output_iterator; 5681ad6265SDimitry Andric }; 5781ad6265SDimitry Andric 5881ad6265SDimitry Andric template <class _Tp> 5981ad6265SDimitry Andric concept __can_reverse = 6081ad6265SDimitry Andric __can_borrow<_Tp> && 6181ad6265SDimitry Andric !__member_rbegin<_Tp> && 6281ad6265SDimitry Andric !__unqualified_rbegin<_Tp> && 6381ad6265SDimitry Andric requires(_Tp&& __t) { 6481ad6265SDimitry Andric { ranges::begin(__t) } -> same_as<decltype(ranges::end(__t))>; 6581ad6265SDimitry Andric { ranges::begin(__t) } -> bidirectional_iterator; 6681ad6265SDimitry Andric }; 6781ad6265SDimitry Andric 6881ad6265SDimitry Andric struct __fn { 6981ad6265SDimitry Andric template <class _Tp> 7081ad6265SDimitry Andric requires __member_rbegin<_Tp> 7181ad6265SDimitry Andric [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const 7281ad6265SDimitry Andric noexcept(noexcept(_LIBCPP_AUTO_CAST(__t.rbegin()))) 7381ad6265SDimitry Andric { 7481ad6265SDimitry Andric return _LIBCPP_AUTO_CAST(__t.rbegin()); 7581ad6265SDimitry Andric } 7681ad6265SDimitry Andric 7781ad6265SDimitry Andric template <class _Tp> 7881ad6265SDimitry Andric requires __unqualified_rbegin<_Tp> 7981ad6265SDimitry Andric [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const 8081ad6265SDimitry Andric noexcept(noexcept(_LIBCPP_AUTO_CAST(rbegin(__t)))) 8181ad6265SDimitry Andric { 8281ad6265SDimitry Andric return _LIBCPP_AUTO_CAST(rbegin(__t)); 8381ad6265SDimitry Andric } 8481ad6265SDimitry Andric 8581ad6265SDimitry Andric template <class _Tp> 8681ad6265SDimitry Andric requires __can_reverse<_Tp> 8781ad6265SDimitry Andric [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const 8881ad6265SDimitry Andric noexcept(noexcept(ranges::end(__t))) 8981ad6265SDimitry Andric { 9081ad6265SDimitry Andric return std::make_reverse_iterator(ranges::end(__t)); 9181ad6265SDimitry Andric } 9281ad6265SDimitry Andric 9381ad6265SDimitry Andric void operator()(auto&&) const = delete; 9481ad6265SDimitry Andric }; 9581ad6265SDimitry Andric } // namespace __rbegin 9681ad6265SDimitry Andric 9781ad6265SDimitry Andric inline namespace __cpo { 9881ad6265SDimitry Andric inline constexpr auto rbegin = __rbegin::__fn{}; 9981ad6265SDimitry Andric } // namespace __cpo 10081ad6265SDimitry Andric } // namespace ranges 10181ad6265SDimitry Andric 10281ad6265SDimitry Andric // [range.access.crbegin] 10381ad6265SDimitry Andric 10481ad6265SDimitry Andric namespace ranges { 10581ad6265SDimitry Andric namespace __crbegin { 10681ad6265SDimitry Andric struct __fn { 10781ad6265SDimitry Andric template <class _Tp> 10881ad6265SDimitry Andric requires is_lvalue_reference_v<_Tp&&> 10981ad6265SDimitry Andric [[nodiscard]] _LIBCPP_HIDE_FROM_ABI 11081ad6265SDimitry Andric constexpr auto operator()(_Tp&& __t) const 11181ad6265SDimitry Andric noexcept(noexcept(ranges::rbegin(static_cast<const remove_reference_t<_Tp>&>(__t)))) 11281ad6265SDimitry Andric -> decltype( ranges::rbegin(static_cast<const remove_reference_t<_Tp>&>(__t))) 11381ad6265SDimitry Andric { return ranges::rbegin(static_cast<const remove_reference_t<_Tp>&>(__t)); } 11481ad6265SDimitry Andric 11581ad6265SDimitry Andric template <class _Tp> 11681ad6265SDimitry Andric requires is_rvalue_reference_v<_Tp&&> 11781ad6265SDimitry Andric [[nodiscard]] _LIBCPP_HIDE_FROM_ABI 11881ad6265SDimitry Andric constexpr auto operator()(_Tp&& __t) const 11981ad6265SDimitry Andric noexcept(noexcept(ranges::rbegin(static_cast<const _Tp&&>(__t)))) 12081ad6265SDimitry Andric -> decltype( ranges::rbegin(static_cast<const _Tp&&>(__t))) 12181ad6265SDimitry Andric { return ranges::rbegin(static_cast<const _Tp&&>(__t)); } 12281ad6265SDimitry Andric }; 12381ad6265SDimitry Andric } // namespace __crbegin 12481ad6265SDimitry Andric 12581ad6265SDimitry Andric inline namespace __cpo { 12681ad6265SDimitry Andric inline constexpr auto crbegin = __crbegin::__fn{}; 12781ad6265SDimitry Andric } // namespace __cpo 12881ad6265SDimitry Andric } // namespace ranges 12981ad6265SDimitry Andric 130*06c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 20 13181ad6265SDimitry Andric 13281ad6265SDimitry Andric _LIBCPP_END_NAMESPACE_STD 13381ad6265SDimitry Andric 13481ad6265SDimitry Andric #endif // _LIBCPP___RANGES_RBEGIN_H 135