xref: /freebsd/contrib/llvm-project/libcxx/include/__iterator/access.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1fe6060f1SDimitry Andric // -*- C++ -*-
2fe6060f1SDimitry Andric //===----------------------------------------------------------------------===//
3fe6060f1SDimitry Andric //
4fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
6fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7fe6060f1SDimitry Andric //
8fe6060f1SDimitry Andric //===----------------------------------------------------------------------===//
9fe6060f1SDimitry Andric 
10fe6060f1SDimitry Andric #ifndef _LIBCPP___ITERATOR_ACCESS_H
11fe6060f1SDimitry Andric #define _LIBCPP___ITERATOR_ACCESS_H
12fe6060f1SDimitry Andric 
13fe6060f1SDimitry Andric #include <__config>
14fe6060f1SDimitry Andric #include <cstddef>
15fe6060f1SDimitry Andric 
16fe6060f1SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17fe6060f1SDimitry Andric #  pragma GCC system_header
18fe6060f1SDimitry Andric #endif
19fe6060f1SDimitry Andric 
20fe6060f1SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
21fe6060f1SDimitry Andric 
22fe6060f1SDimitry Andric template <class _Tp, size_t _Np>
begin(_Tp (& __array)[_Np])235f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* begin(_Tp (&__array)[_Np]) _NOEXCEPT {
24fe6060f1SDimitry Andric   return __array;
25fe6060f1SDimitry Andric }
26fe6060f1SDimitry Andric 
27fe6060f1SDimitry Andric template <class _Tp, size_t _Np>
end(_Tp (& __array)[_Np])285f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* end(_Tp (&__array)[_Np]) _NOEXCEPT {
29fe6060f1SDimitry Andric   return __array + _Np;
30fe6060f1SDimitry Andric }
31fe6060f1SDimitry Andric 
32fe6060f1SDimitry Andric #if !defined(_LIBCPP_CXX03_LANG)
33fe6060f1SDimitry Andric 
34fe6060f1SDimitry Andric template <class _Cp>
35cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto begin(_Cp& __c) -> decltype(__c.begin()) {
36fe6060f1SDimitry Andric   return __c.begin();
37fe6060f1SDimitry Andric }
38fe6060f1SDimitry Andric 
39fe6060f1SDimitry Andric template <class _Cp>
40cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto begin(const _Cp& __c) -> decltype(__c.begin()) {
41fe6060f1SDimitry Andric   return __c.begin();
42fe6060f1SDimitry Andric }
43fe6060f1SDimitry Andric 
44fe6060f1SDimitry Andric template <class _Cp>
45cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto end(_Cp& __c) -> decltype(__c.end()) {
46fe6060f1SDimitry Andric   return __c.end();
47fe6060f1SDimitry Andric }
48fe6060f1SDimitry Andric 
49fe6060f1SDimitry Andric template <class _Cp>
50cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 auto end(const _Cp& __c) -> decltype(__c.end()) {
51fe6060f1SDimitry Andric   return __c.end();
52fe6060f1SDimitry Andric }
53fe6060f1SDimitry Andric 
5406c3fb27SDimitry Andric #  if _LIBCPP_STD_VER >= 14
55fe6060f1SDimitry Andric 
56fe6060f1SDimitry Andric template <class _Cp>
57*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr auto
58*0fca6ea1SDimitry Andric cbegin(const _Cp& __c) noexcept(noexcept(std::begin(__c))) -> decltype(std::begin(__c)) {
595f757f3fSDimitry Andric   return std::begin(__c);
60fe6060f1SDimitry Andric }
61fe6060f1SDimitry Andric 
62fe6060f1SDimitry Andric template <class _Cp>
635f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr auto cend(const _Cp& __c) noexcept(noexcept(std::end(__c))) -> decltype(std::end(__c)) {
645f757f3fSDimitry Andric   return std::end(__c);
65fe6060f1SDimitry Andric }
66fe6060f1SDimitry Andric 
67fe6060f1SDimitry Andric #  endif
68fe6060f1SDimitry Andric 
69fe6060f1SDimitry Andric #else // defined(_LIBCPP_CXX03_LANG)
70fe6060f1SDimitry Andric 
71fe6060f1SDimitry Andric template <class _Cp>
begin(_Cp & __c)72cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI typename _Cp::iterator begin(_Cp& __c) {
73fe6060f1SDimitry Andric   return __c.begin();
74fe6060f1SDimitry Andric }
75fe6060f1SDimitry Andric 
76fe6060f1SDimitry Andric template <class _Cp>
begin(const _Cp & __c)77cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI typename _Cp::const_iterator begin(const _Cp& __c) {
78fe6060f1SDimitry Andric   return __c.begin();
79fe6060f1SDimitry Andric }
80fe6060f1SDimitry Andric 
81fe6060f1SDimitry Andric template <class _Cp>
end(_Cp & __c)82cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI typename _Cp::iterator end(_Cp& __c) {
83fe6060f1SDimitry Andric   return __c.end();
84fe6060f1SDimitry Andric }
85fe6060f1SDimitry Andric 
86fe6060f1SDimitry Andric template <class _Cp>
end(const _Cp & __c)87cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI typename _Cp::const_iterator end(const _Cp& __c) {
88fe6060f1SDimitry Andric   return __c.end();
89fe6060f1SDimitry Andric }
90fe6060f1SDimitry Andric 
91fe6060f1SDimitry Andric #endif // !defined(_LIBCPP_CXX03_LANG)
92fe6060f1SDimitry Andric 
93fe6060f1SDimitry Andric _LIBCPP_END_NAMESPACE_STD
94fe6060f1SDimitry Andric 
95fe6060f1SDimitry Andric #endif // _LIBCPP___ITERATOR_ACCESS_H
96