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_ACCESS_H
11 #define _LIBCPP___ITERATOR_ACCESS_H
12 
13 #include <__config>
14 #include <cstddef>
15 
16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17 #pragma GCC system_header
18 #endif
19 
20 _LIBCPP_PUSH_MACROS
21 #include <__undef_macros>
22 
23 _LIBCPP_BEGIN_NAMESPACE_STD
24 
25 template <class _Tp, size_t _Np>
26 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
27 _Tp*
begin(_Tp (& __array)[_Np])28 begin(_Tp (&__array)[_Np])
29 {
30     return __array;
31 }
32 
33 template <class _Tp, size_t _Np>
34 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
35 _Tp*
end(_Tp (& __array)[_Np])36 end(_Tp (&__array)[_Np])
37 {
38     return __array + _Np;
39 }
40 
41 #if !defined(_LIBCPP_CXX03_LANG)
42 
43 template <class _Cp>
44 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
45 auto
46 begin(_Cp& __c) -> decltype(__c.begin())
47 {
48     return __c.begin();
49 }
50 
51 template <class _Cp>
52 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
53 auto
54 begin(const _Cp& __c) -> decltype(__c.begin())
55 {
56     return __c.begin();
57 }
58 
59 template <class _Cp>
60 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
61 auto
62 end(_Cp& __c) -> decltype(__c.end())
63 {
64     return __c.end();
65 }
66 
67 template <class _Cp>
68 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
69 auto
70 end(const _Cp& __c) -> decltype(__c.end())
71 {
72     return __c.end();
73 }
74 
75 #if _LIBCPP_STD_VER > 11
76 
77 template <class _Cp>
78 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
79 auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
80 {
81     return _VSTD::begin(__c);
82 }
83 
84 template <class _Cp>
85 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
86 auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
87 {
88     return _VSTD::end(__c);
89 }
90 
91 #endif
92 
93 
94 #else  // defined(_LIBCPP_CXX03_LANG)
95 
96 template <class _Cp>
97 _LIBCPP_INLINE_VISIBILITY
98 typename _Cp::iterator
begin(_Cp & __c)99 begin(_Cp& __c)
100 {
101     return __c.begin();
102 }
103 
104 template <class _Cp>
105 _LIBCPP_INLINE_VISIBILITY
106 typename _Cp::const_iterator
begin(const _Cp & __c)107 begin(const _Cp& __c)
108 {
109     return __c.begin();
110 }
111 
112 template <class _Cp>
113 _LIBCPP_INLINE_VISIBILITY
114 typename _Cp::iterator
end(_Cp & __c)115 end(_Cp& __c)
116 {
117     return __c.end();
118 }
119 
120 template <class _Cp>
121 _LIBCPP_INLINE_VISIBILITY
122 typename _Cp::const_iterator
end(const _Cp & __c)123 end(const _Cp& __c)
124 {
125     return __c.end();
126 }
127 
128 #endif // !defined(_LIBCPP_CXX03_LANG)
129 
130 _LIBCPP_END_NAMESPACE_STD
131 
132 _LIBCPP_POP_MACROS
133 
134 #endif // _LIBCPP___ITERATOR_ACCESS_H
135