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