aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxx/include/__ranges/rend.h
blob: d2987e9fa8c3009f8481ae81a90dfc5053d07339 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___RANGES_REND_H
#define _LIBCPP___RANGES_REND_H

#include <__concepts/class_or_enum.h>
#include <__concepts/same_as.h>
#include <__config>
#include <__iterator/concepts.h>
#include <__iterator/readable_traits.h>
#include <__iterator/reverse_iterator.h>
#include <__ranges/access.h>
#include <__ranges/rbegin.h>
#include <__utility/auto_cast.h>
#include <type_traits>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#  pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

#if _LIBCPP_STD_VER > 17

// [range.access.rend]

namespace ranges {
namespace __rend {
template <class _Tp>
concept __member_rend =
  __can_borrow<_Tp> &&
  __workaround_52970<_Tp> &&
  requires(_Tp&& __t) {
    ranges::rbegin(__t);
    { _LIBCPP_AUTO_CAST(__t.rend()) } -> sentinel_for<decltype(ranges::rbegin(__t))>;
  };

void rend(auto&) = delete;
void rend(const auto&) = delete;

template <class _Tp>
concept __unqualified_rend =
  !__member_rend<_Tp> &&
  __can_borrow<_Tp> &&
  __class_or_enum<remove_cvref_t<_Tp>> &&
  requires(_Tp&& __t) {
    ranges::rbegin(__t);
    { _LIBCPP_AUTO_CAST(rend(__t)) } -> sentinel_for<decltype(ranges::rbegin(__t))>;
  };

template <class _Tp>
concept __can_reverse =
  __can_borrow<_Tp> &&
  !__member_rend<_Tp> &&
  !__unqualified_rend<_Tp> &&
  requires(_Tp&& __t) {
    { ranges::begin(__t) } -> same_as<decltype(ranges::end(__t))>;
    { ranges::begin(__t) } -> bidirectional_iterator;
  };

class __fn {
public:
  template <class _Tp>
    requires __member_rend<_Tp>
  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
    noexcept(noexcept(_LIBCPP_AUTO_CAST(__t.rend())))
  {
    return _LIBCPP_AUTO_CAST(__t.rend());
  }

  template <class _Tp>
    requires __unqualified_rend<_Tp>
  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
    noexcept(noexcept(_LIBCPP_AUTO_CAST(rend(__t))))
  {
    return _LIBCPP_AUTO_CAST(rend(__t));
  }

  template <class _Tp>
    requires __can_reverse<_Tp>
  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const
    noexcept(noexcept(ranges::begin(__t)))
  {
    return std::make_reverse_iterator(ranges::begin(__t));
  }

  void operator()(auto&&) const = delete;
};
} // namespace __rend

inline namespace __cpo {
  inline constexpr auto rend = __rend::__fn{};
} // namespace __cpo
} // namespace ranges

// [range.access.crend]

namespace ranges {
namespace __crend {
struct __fn {
  template <class _Tp>
    requires is_lvalue_reference_v<_Tp&&>
  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
  constexpr auto operator()(_Tp&& __t) const
    noexcept(noexcept(ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t))))
    -> decltype(      ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t)))
    { return          ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t)); }

  template <class _Tp>
    requires is_rvalue_reference_v<_Tp&&>
  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
  constexpr auto operator()(_Tp&& __t) const
    noexcept(noexcept(ranges::rend(static_cast<const _Tp&&>(__t))))
    -> decltype(      ranges::rend(static_cast<const _Tp&&>(__t)))
    { return          ranges::rend(static_cast<const _Tp&&>(__t)); }
};
} // namespace __crend

inline namespace __cpo {
  inline constexpr auto crend = __crend::__fn{};
} // namespace __cpo
} // namespace ranges

#endif // _LIBCPP_STD_VER > 17

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___RANGES_REND_H