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/size_t.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22template <class _Tp, size_t _Np>
23[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* begin(_Tp (&__array)[_Np]) _NOEXCEPT {
24 return __array;
25}
26
27template <class _Tp, size_t _Np>
28[[__nodiscard__]] _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
34template <class _Cp>
35[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto begin(_Cp& __c) -> decltype(__c.begin()) {
36 return __c.begin();
37}
38
39template <class _Cp>
40[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto begin(const _Cp& __c)
41 -> decltype(__c.begin()) {
42 return __c.begin();
43}
44
45template <class _Cp>
46[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto end(_Cp& __c) -> decltype(__c.end()) {
47 return __c.end();
48}
49
50template <class _Cp>
51[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto end(const _Cp& __c) -> decltype(__c.end()) {
52 return __c.end();
53}
54
55# if _LIBCPP_STD_VER >= 14
56
57template <class _Cp>
58[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr auto cbegin(const _Cp& __c) noexcept(noexcept(std::begin(__c)))
59 -> decltype(std::begin(__c)) {
60 return std::begin(__c);
61}
62
63template <class _Cp>
64[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr auto cend(const _Cp& __c) noexcept(noexcept(std::end(__c)))
65 -> decltype(std::end(__c)) {
66 return std::end(__c);
67}
68
69# endif
70
71#else // defined(_LIBCPP_CXX03_LANG)
72
73template <class _Cp>
74[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI typename _Cp::iterator begin(_Cp& __c) {
75 return __c.begin();
76}
77
78template <class _Cp>
79[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI typename _Cp::const_iterator begin(const _Cp& __c) {
80 return __c.begin();
81}
82
83template <class _Cp>
84[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI typename _Cp::iterator end(_Cp& __c) {
85 return __c.end();
86}
87
88template <class _Cp>
89[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI typename _Cp::const_iterator end(const _Cp& __c) {
90 return __c.end();
91}
92
93#endif // !defined(_LIBCPP_CXX03_LANG)
94
95_LIBCPP_END_NAMESPACE_STD
96
97#endif // _LIBCPP___ITERATOR_ACCESS_H
98