* testsuite/26_numerics/headers/cmath/hypot.cc: XFAIL on AIX.
[official-gcc.git] / libstdc++-v3 / include / bits / range_access.h
blob95c3d52099a07f65765819bd1be0c8c5755b8192
1 // <range_access.h> -*- C++ -*-
3 // Copyright (C) 2010-2016 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file bits/range_access.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{iterator}
30 #ifndef _GLIBCXX_RANGE_ACCESS_H
31 #define _GLIBCXX_RANGE_ACCESS_H 1
33 #pragma GCC system_header
35 #if __cplusplus >= 201103L
36 #include <initializer_list>
37 namespace std _GLIBCXX_VISIBILITY(default)
39 _GLIBCXX_BEGIN_NAMESPACE_VERSION
41 /**
42 * @brief Return an iterator pointing to the first element of
43 * the container.
44 * @param __cont Container.
46 template<typename _Container>
47 inline _GLIBCXX17_CONSTEXPR auto
48 begin(_Container& __cont) -> decltype(__cont.begin())
49 { return __cont.begin(); }
51 /**
52 * @brief Return an iterator pointing to the first element of
53 * the const container.
54 * @param __cont Container.
56 template<typename _Container>
57 inline _GLIBCXX17_CONSTEXPR auto
58 begin(const _Container& __cont) -> decltype(__cont.begin())
59 { return __cont.begin(); }
61 /**
62 * @brief Return an iterator pointing to one past the last element of
63 * the container.
64 * @param __cont Container.
66 template<typename _Container>
67 inline _GLIBCXX17_CONSTEXPR auto
68 end(_Container& __cont) -> decltype(__cont.end())
69 { return __cont.end(); }
71 /**
72 * @brief Return an iterator pointing to one past the last element of
73 * the const container.
74 * @param __cont Container.
76 template<typename _Container>
77 inline _GLIBCXX17_CONSTEXPR auto
78 end(const _Container& __cont) -> decltype(__cont.end())
79 { return __cont.end(); }
81 /**
82 * @brief Return an iterator pointing to the first element of the array.
83 * @param __arr Array.
85 template<typename _Tp, size_t _Nm>
86 inline _GLIBCXX14_CONSTEXPR _Tp*
87 begin(_Tp (&__arr)[_Nm])
88 { return __arr; }
90 /**
91 * @brief Return an iterator pointing to one past the last element
92 * of the array.
93 * @param __arr Array.
95 template<typename _Tp, size_t _Nm>
96 inline _GLIBCXX14_CONSTEXPR _Tp*
97 end(_Tp (&__arr)[_Nm])
98 { return __arr + _Nm; }
100 #if __cplusplus >= 201402L
102 template<typename _Tp> class valarray;
103 // These overloads must be declared for cbegin and cend to use them.
104 template<typename _Tp> _Tp* begin(valarray<_Tp>&);
105 template<typename _Tp> const _Tp* begin(const valarray<_Tp>&);
106 template<typename _Tp> _Tp* end(valarray<_Tp>&);
107 template<typename _Tp> const _Tp* end(const valarray<_Tp>&);
110 * @brief Return an iterator pointing to the first element of
111 * the const container.
112 * @param __cont Container.
114 template<typename _Container>
115 inline constexpr auto
116 cbegin(const _Container& __cont) noexcept(noexcept(std::begin(__cont)))
117 -> decltype(std::begin(__cont))
118 { return std::begin(__cont); }
121 * @brief Return an iterator pointing to one past the last element of
122 * the const container.
123 * @param __cont Container.
125 template<typename _Container>
126 inline constexpr auto
127 cend(const _Container& __cont) noexcept(noexcept(std::end(__cont)))
128 -> decltype(std::end(__cont))
129 { return std::end(__cont); }
132 * @brief Return a reverse iterator pointing to the last element of
133 * the container.
134 * @param __cont Container.
136 template<typename _Container>
137 inline _GLIBCXX17_CONSTEXPR auto
138 rbegin(_Container& __cont) -> decltype(__cont.rbegin())
139 { return __cont.rbegin(); }
142 * @brief Return a reverse iterator pointing to the last element of
143 * the const container.
144 * @param __cont Container.
146 template<typename _Container>
147 inline _GLIBCXX17_CONSTEXPR auto
148 rbegin(const _Container& __cont) -> decltype(__cont.rbegin())
149 { return __cont.rbegin(); }
152 * @brief Return a reverse iterator pointing one past the first element of
153 * the container.
154 * @param __cont Container.
156 template<typename _Container>
157 inline _GLIBCXX17_CONSTEXPR auto
158 rend(_Container& __cont) -> decltype(__cont.rend())
159 { return __cont.rend(); }
162 * @brief Return a reverse iterator pointing one past the first element of
163 * the const container.
164 * @param __cont Container.
166 template<typename _Container>
167 inline _GLIBCXX17_CONSTEXPR auto
168 rend(const _Container& __cont) -> decltype(__cont.rend())
169 { return __cont.rend(); }
172 * @brief Return a reverse iterator pointing to the last element of
173 * the array.
174 * @param __arr Array.
176 template<typename _Tp, size_t _Nm>
177 inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Tp*>
178 rbegin(_Tp (&__arr)[_Nm])
179 { return reverse_iterator<_Tp*>(__arr + _Nm); }
182 * @brief Return a reverse iterator pointing one past the first element of
183 * the array.
184 * @param __arr Array.
186 template<typename _Tp, size_t _Nm>
187 inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Tp*>
188 rend(_Tp (&__arr)[_Nm])
189 { return reverse_iterator<_Tp*>(__arr); }
192 * @brief Return a reverse iterator pointing to the last element of
193 * the initializer_list.
194 * @param __il initializer_list.
196 template<typename _Tp>
197 inline _GLIBCXX17_CONSTEXPR reverse_iterator<const _Tp*>
198 rbegin(initializer_list<_Tp> __il)
199 { return reverse_iterator<const _Tp*>(__il.end()); }
202 * @brief Return a reverse iterator pointing one past the first element of
203 * the initializer_list.
204 * @param __il initializer_list.
206 template<typename _Tp>
207 inline _GLIBCXX17_CONSTEXPR reverse_iterator<const _Tp*>
208 rend(initializer_list<_Tp> __il)
209 { return reverse_iterator<const _Tp*>(__il.begin()); }
212 * @brief Return a reverse iterator pointing to the last element of
213 * the const container.
214 * @param __cont Container.
216 template<typename _Container>
217 inline _GLIBCXX17_CONSTEXPR auto
218 crbegin(const _Container& __cont) -> decltype(std::rbegin(__cont))
219 { return std::rbegin(__cont); }
222 * @brief Return a reverse iterator pointing one past the first element of
223 * the const container.
224 * @param __cont Container.
226 template<typename _Container>
227 inline _GLIBCXX17_CONSTEXPR auto
228 crend(const _Container& __cont) -> decltype(std::rend(__cont))
229 { return std::rend(__cont); }
231 #endif // C++14
233 #if __cplusplus > 201402L
234 #define __cpp_lib_nonmember_container_access 201411
237 * @brief Return the size of a container.
238 * @param __cont Container.
240 template <typename _Container>
241 constexpr auto
242 size(const _Container& __cont) -> decltype(__cont.size())
243 { return __cont.size(); }
246 * @brief Return the size of an array.
247 * @param __array Array.
249 template <typename _Tp, size_t _Nm>
250 constexpr size_t
251 size(const _Tp (&/*__array*/)[_Nm]) noexcept
252 { return _Nm; }
255 * @brief Return whether a container is empty.
256 * @param __cont Container.
258 template <typename _Container>
259 constexpr auto
260 empty(const _Container& __cont) -> decltype(__cont.empty())
261 { return __cont.empty(); }
264 * @brief Return whether an array is empty (always false).
265 * @param __array Container.
267 template <typename _Tp, size_t _Nm>
268 constexpr bool
269 empty(const _Tp (&/*__array*/)[_Nm]) noexcept
270 { return false; }
273 * @brief Return whether an initializer_list is empty.
274 * @param __il Initializer list.
276 template <typename _Tp>
277 constexpr bool
278 empty(initializer_list<_Tp> __il) noexcept
279 { return __il.size() == 0;}
282 * @brief Return the data pointer of a container.
283 * @param __cont Container.
285 template <typename _Container>
286 constexpr auto
287 data(_Container& __cont) -> decltype(__cont.data())
288 { return __cont.data(); }
291 * @brief Return the data pointer of a const container.
292 * @param __cont Container.
294 template <typename _Container>
295 constexpr auto
296 data(const _Container& __cont) -> decltype(__cont.data())
297 { return __cont.data(); }
300 * @brief Return the data pointer of an array.
301 * @param __array Array.
303 template <typename _Tp, size_t _Nm>
304 constexpr _Tp*
305 data(_Tp (&__array)[_Nm]) noexcept
306 { return __array; }
309 * @brief Return the data pointer of an initializer list.
310 * @param __il Initializer list.
312 template <typename _Tp>
313 constexpr const _Tp*
314 data(initializer_list<_Tp> __il) noexcept
315 { return __il.begin(); }
317 #endif // C++17
319 _GLIBCXX_END_NAMESPACE_VERSION
320 } // namespace
322 #endif // C++11
324 #endif // _GLIBCXX_RANGE_ACCESS_H