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_CONSTEXPR _Tp* begin(_Tp (&__array)[_Np]) _NOEXCEPT {
24 return __array;
25}
26
27template <class _Tp, size_t _Np>
28[[__nodiscard__]] _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_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_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_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_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__]] 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__]] constexpr auto cend(const _Cp& __c) noexcept(noexcept(std::end(__c))) -> decltype(std::end(__c)) {
73 return std::end(__c);
74}
75
76# endif
77
78#else // defined(_LIBCPP_CXX03_LANG)
79
80template <class _Cp>
81[[__nodiscard__]] typename _Cp::iterator begin(_Cp& __c) {
82 return __c.begin();
83}
84
85template <class _Cp>
86[[__nodiscard__]] typename _Cp::const_iterator begin(const _Cp& __c) {
87 return __c.begin();
88}
89
90template <class _Cp>
91[[__nodiscard__]] typename _Cp::iterator end(_Cp& __c) {
92 return __c.end();
93}
94
95template <class _Cp>
96[[__nodiscard__]] typename _Cp::const_iterator end(const _Cp& __c) {
97 return __c.end();
98}
99
100#endif // !defined(_LIBCPP_CXX03_LANG)
101
102_LIBCPP_END_NAMESPACE_STD
103
104#endif // _LIBCPP___ITERATOR_ACCESS_H
105