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-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___ITERATOR_REVERSE_ACCESS_H
11#define _LIBCPP___ITERATOR_REVERSE_ACCESS_H
12
13#include <__config>
14#include <__iterator/reverse_iterator.h>
15#include <cstddef>
16#include <initializer_list>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#  pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24#if _LIBCPP_STD_VER >= 14
25
26template <class _Tp, size_t _Np>
27_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) {
28  return reverse_iterator<_Tp*>(__array + _Np);
29}
30
31template <class _Tp, size_t _Np>
32_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) {
33  return reverse_iterator<_Tp*>(__array);
34}
35
36template <class _Ep>
37_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il) {
38  return reverse_iterator<const _Ep*>(__il.end());
39}
40
41template <class _Ep>
42_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il) {
43  return reverse_iterator<const _Ep*>(__il.begin());
44}
45
46template <class _Cp>
47_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) {
48  return __c.rbegin();
49}
50
51template <class _Cp>
52_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) {
53  return __c.rbegin();
54}
55
56template <class _Cp>
57_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rend(_Cp& __c) -> decltype(__c.rend()) {
58  return __c.rend();
59}
60
61template <class _Cp>
62_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rend(const _Cp& __c) -> decltype(__c.rend()) {
63  return __c.rend();
64}
65
66template <class _Cp>
67_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto crbegin(const _Cp& __c) -> decltype(std::rbegin(__c)) {
68  return std::rbegin(__c);
69}
70
71template <class _Cp>
72_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto crend(const _Cp& __c) -> decltype(std::rend(__c)) {
73  return std::rend(__c);
74}
75
76#endif // _LIBCPP_STD_VER >= 14
77
78_LIBCPP_END_NAMESPACE_STD
79
80#endif // _LIBCPP___ITERATOR_REVERSE_ACCESS_H
81