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) //
36 noexcept(noexcept(__c.begin())) //
37 -> decltype(/*-*/ __c.begin()) {
38 return /*--------*/ __c.begin();
39}
40
41template <class _Cp>
42[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto begin(const _Cp& __c)
43 //
44 noexcept(noexcept(__c.begin())) //
45 -> decltype(/*-*/ __c.begin()) {
46 return /*--------*/ __c.begin();
47}
48
49template <class _Cp>
50[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto end(_Cp& __c) //
51 noexcept(noexcept(__c.end())) //
52 -> decltype(/*-*/ __c.end()) {
53 return /*--------*/ __c.end();
54}
55
56template <class _Cp>
57[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto end(const _Cp& __c) //
58 noexcept(noexcept(__c.end())) //
59 -> decltype(/*-*/ __c.end()) {
60 return /*--------*/ __c.end();
61}
62
63# if _LIBCPP_STD_VER >= 14
64
65template <class _Cp>
66[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr auto cbegin(const _Cp& __c) noexcept(noexcept(std::begin(__c)))
67 -> decltype(std::begin(__c)) {
68 return std::begin(__c);
69}
70
71template <class _Cp>
72[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr auto cend(const _Cp& __c) noexcept(noexcept(std::end(__c)))
73 -> decltype(std::end(__c)) {
74 return std::end(__c);
75}
76
77# endif
78
79#else // defined(_LIBCPP_CXX03_LANG)
80
81template <class _Cp>
82[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI typename _Cp::iterator begin(_Cp& __c) {
83 return __c.begin();
84}
85
86template <class _Cp>
87[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI typename _Cp::const_iterator begin(const _Cp& __c) {
88 return __c.begin();
89}
90
91template <class _Cp>
92[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI typename _Cp::iterator end(_Cp& __c) {
93 return __c.end();
94}
95
96template <class _Cp>
97[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI typename _Cp::const_iterator end(const _Cp& __c) {
98 return __c.end();
99}
100
101#endif // !defined(_LIBCPP_CXX03_LANG)
102
103_LIBCPP_END_NAMESPACE_STD
104
105#endif // _LIBCPP___ITERATOR_ACCESS_H
106