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_PUSH_MACROS
23 #include <__undef_macros>
24 
25 _LIBCPP_BEGIN_NAMESPACE_STD
26 
27 #if !defined(_LIBCPP_CXX03_LANG)
28 
29 #if _LIBCPP_STD_VER > 11
30 
31 template <class _Tp, size_t _Np>
32 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
33 reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
34 {
35     return reverse_iterator<_Tp*>(__array + _Np);
36 }
37 
38 template <class _Tp, size_t _Np>
39 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
40 reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
41 {
42     return reverse_iterator<_Tp*>(__array);
43 }
44 
45 template <class _Ep>
46 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
47 reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
48 {
49     return reverse_iterator<const _Ep*>(__il.end());
50 }
51 
52 template <class _Ep>
53 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
54 reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
55 {
56     return reverse_iterator<const _Ep*>(__il.begin());
57 }
58 
59 template <class _Cp>
60 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
61 auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
62 {
63     return __c.rbegin();
64 }
65 
66 template <class _Cp>
67 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
68 auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
69 {
70     return __c.rbegin();
71 }
72 
73 template <class _Cp>
74 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
75 auto rend(_Cp& __c) -> decltype(__c.rend())
76 {
77     return __c.rend();
78 }
79 
80 template <class _Cp>
81 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
82 auto rend(const _Cp& __c) -> decltype(__c.rend())
83 {
84     return __c.rend();
85 }
86 
87 template <class _Cp>
88 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
89 auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
90 {
91     return _VSTD::rbegin(__c);
92 }
93 
94 template <class _Cp>
95 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
96 auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
97 {
98     return _VSTD::rend(__c);
99 }
100 
101 #endif
102 
103 #endif // !defined(_LIBCPP_CXX03_LANG)
104 
105 _LIBCPP_END_NAMESPACE_STD
106 
107 _LIBCPP_POP_MACROS
108 
109 #endif // _LIBCPP___ITERATOR_REVERSE_ACCESS_H
110