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_BEGIN_NAMESPACE_STD 21 22 template <class _Tp, size_t _Np> begin(_Tp (& __array)[_Np])23_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* begin(_Tp (&__array)[_Np]) _NOEXCEPT { 24 return __array; 25 } 26 27 template <class _Tp, size_t _Np> end(_Tp (& __array)[_Np])28_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* end(_Tp (&__array)[_Np]) _NOEXCEPT { 29 return __array + _Np; 30 } 31 32 #if !defined(_LIBCPP_CXX03_LANG) 33 34 template <class _Cp> 35 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 36 auto 37 begin(_Cp& __c) -> decltype(__c.begin()) 38 { 39 return __c.begin(); 40 } 41 42 template <class _Cp> 43 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 44 auto 45 begin(const _Cp& __c) -> decltype(__c.begin()) 46 { 47 return __c.begin(); 48 } 49 50 template <class _Cp> 51 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 52 auto 53 end(_Cp& __c) -> decltype(__c.end()) 54 { 55 return __c.end(); 56 } 57 58 template <class _Cp> 59 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 60 auto 61 end(const _Cp& __c) -> decltype(__c.end()) 62 { 63 return __c.end(); 64 } 65 66 #if _LIBCPP_STD_VER >= 14 67 68 template <class _Cp> 69 _LIBCPP_HIDE_FROM_ABI constexpr auto cbegin(const _Cp& __c) noexcept(noexcept(std::begin(__c))) 70 -> decltype(std::begin(__c)) { 71 return std::begin(__c); 72 } 73 74 template <class _Cp> 75 _LIBCPP_HIDE_FROM_ABI constexpr auto cend(const _Cp& __c) noexcept(noexcept(std::end(__c))) -> decltype(std::end(__c)) { 76 return std::end(__c); 77 } 78 79 #endif 80 81 82 #else // defined(_LIBCPP_CXX03_LANG) 83 84 template <class _Cp> 85 _LIBCPP_INLINE_VISIBILITY 86 typename _Cp::iterator begin(_Cp & __c)87begin(_Cp& __c) 88 { 89 return __c.begin(); 90 } 91 92 template <class _Cp> 93 _LIBCPP_INLINE_VISIBILITY 94 typename _Cp::const_iterator begin(const _Cp & __c)95begin(const _Cp& __c) 96 { 97 return __c.begin(); 98 } 99 100 template <class _Cp> 101 _LIBCPP_INLINE_VISIBILITY 102 typename _Cp::iterator end(_Cp & __c)103end(_Cp& __c) 104 { 105 return __c.end(); 106 } 107 108 template <class _Cp> 109 _LIBCPP_INLINE_VISIBILITY 110 typename _Cp::const_iterator end(const _Cp & __c)111end(const _Cp& __c) 112 { 113 return __c.end(); 114 } 115 116 #endif // !defined(_LIBCPP_CXX03_LANG) 117 118 _LIBCPP_END_NAMESPACE_STD 119 120 #endif // _LIBCPP___ITERATOR_ACCESS_H 121