xref: /freebsd/contrib/llvm-project/libcxx/include/__iterator/reverse_access.h (revision 2f9966ff63d65bd474478888c9088eeae3f9c669)
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 
26 template <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 
31 template <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 
36 template <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 
41 template <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 
46 template <class _Cp>
47 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) {
48   return __c.rbegin();
49 }
50 
51 template <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 
56 template <class _Cp>
57 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto rend(_Cp& __c) -> decltype(__c.rend()) {
58   return __c.rend();
59 }
60 
61 template <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 
66 template <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 
71 template <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