blob: fdb1f9dae5306b0b1b7eb8198792518d25e90b7b [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- array -----------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_ARRAY
12#define _LIBCPP_ARRAY
13
14/*
15 array synopsis
16
17namespace std
18{
Howard Hinnant3b6579a2010-08-22 00:02:43 +000019template <class T, size_t N >
Howard Hinnantc51e1022010-05-11 19:42:16 +000020struct array
Howard Hinnant3b6579a2010-08-22 00:02:43 +000021{
22 // types:
23 typedef T & reference;
24 typedef const T & const_reference;
25 typedef implementation defined iterator;
26 typedef implementation defined const_iterator;
27 typedef size_t size_type;
28 typedef ptrdiff_t difference_type;
29 typedef T value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +000030 typedef T* pointer;
31 typedef const T* const_pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +000032 typedef std::reverse_iterator<iterator> reverse_iterator;
33 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +000034
Howard Hinnant3b6579a2010-08-22 00:02:43 +000035 // No explicit construct/copy/destroy for aggregate type
36 void fill(const T& u);
Eric Fiselier6bfed252016-04-21 23:38:59 +000037 void swap(array& a) noexcept(is_nothrow_swappable_v<T>);
Howard Hinnantc51e1022010-05-11 19:42:16 +000038
Howard Hinnant3b6579a2010-08-22 00:02:43 +000039 // iterators:
Howard Hinnant32477e82011-05-31 21:06:33 +000040 iterator begin() noexcept;
41 const_iterator begin() const noexcept;
42 iterator end() noexcept;
43 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000044
Howard Hinnant32477e82011-05-31 21:06:33 +000045 reverse_iterator rbegin() noexcept;
46 const_reverse_iterator rbegin() const noexcept;
47 reverse_iterator rend() noexcept;
48 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000049
Howard Hinnant32477e82011-05-31 21:06:33 +000050 const_iterator cbegin() const noexcept;
51 const_iterator cend() const noexcept;
52 const_reverse_iterator crbegin() const noexcept;
53 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000054
Howard Hinnant3b6579a2010-08-22 00:02:43 +000055 // capacity:
Howard Hinnant32477e82011-05-31 21:06:33 +000056 constexpr size_type size() const noexcept;
57 constexpr size_type max_size() const noexcept;
Howard Hinnant12ff42f2012-07-20 19:20:49 +000058 constexpr bool empty() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000059
Howard Hinnant3b6579a2010-08-22 00:02:43 +000060 // element access:
61 reference operator[](size_type n);
Marshall Clow0abb1042013-07-17 18:25:36 +000062 const_reference operator[](size_type n) const; // constexpr in C++14
63 const_reference at(size_type n) const; // constexpr in C++14
Howard Hinnant3b6579a2010-08-22 00:02:43 +000064 reference at(size_type n);
Howard Hinnantc51e1022010-05-11 19:42:16 +000065
Howard Hinnant3b6579a2010-08-22 00:02:43 +000066 reference front();
Marshall Clow0abb1042013-07-17 18:25:36 +000067 const_reference front() const; // constexpr in C++14
Howard Hinnant3b6579a2010-08-22 00:02:43 +000068 reference back();
Marshall Clow0abb1042013-07-17 18:25:36 +000069 const_reference back() const; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000070
Howard Hinnant32477e82011-05-31 21:06:33 +000071 T* data() noexcept;
72 const T* data() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000073};
74
Howard Hinnant3b6579a2010-08-22 00:02:43 +000075template <class T, size_t N>
76 bool operator==(const array<T,N>& x, const array<T,N>& y);
77template <class T, size_t N>
78 bool operator!=(const array<T,N>& x, const array<T,N>& y);
79template <class T, size_t N>
80 bool operator<(const array<T,N>& x, const array<T,N>& y);
81template <class T, size_t N>
82 bool operator>(const array<T,N>& x, const array<T,N>& y);
83template <class T, size_t N>
84 bool operator<=(const array<T,N>& x, const array<T,N>& y);
85template <class T, size_t N>
86 bool operator>=(const array<T,N>& x, const array<T,N>& y);
Howard Hinnantc51e1022010-05-11 19:42:16 +000087
Howard Hinnant3b6579a2010-08-22 00:02:43 +000088template <class T, size_t N >
Howard Hinnant32477e82011-05-31 21:06:33 +000089 void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +000090
Howard Hinnant3b6579a2010-08-22 00:02:43 +000091template <class T> class tuple_size;
Marshall Clow291a3512015-11-19 19:41:04 +000092template <size_t I, class T> class tuple_element;
Howard Hinnantc51e1022010-05-11 19:42:16 +000093template <class T, size_t N> struct tuple_size<array<T, N>>;
Marshall Clow291a3512015-11-19 19:41:04 +000094template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>;
95template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14
96template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14
97template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +000098template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000099
100} // std
101
102*/
103
104#include <__config>
105#include <__tuple>
106#include <type_traits>
107#include <utility>
108#include <iterator>
109#include <algorithm>
110#include <stdexcept>
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000111#include <cstdlib> // for _LIBCPP_UNREACHABLE
112#include <__debug>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000113
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000114#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000115#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000116#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000117
Eric Fiselierf4433a32017-05-31 22:07:49 +0000118
119
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120_LIBCPP_BEGIN_NAMESPACE_STD
121
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000122
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000123template <class _Tp, size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000124struct _LIBCPP_TEMPLATE_VIS array
Howard Hinnantc51e1022010-05-11 19:42:16 +0000125{
126 // types:
127 typedef array __self;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000128 typedef _Tp value_type;
129 typedef value_type& reference;
130 typedef const value_type& const_reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000131 typedef value_type* iterator;
132 typedef const value_type* const_iterator;
133 typedef value_type* pointer;
134 typedef const value_type* const_pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000135 typedef size_t size_type;
136 typedef ptrdiff_t difference_type;
137 typedef std::reverse_iterator<iterator> reverse_iterator;
138 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000139
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000140 _Tp __elems_[_Size];
Howard Hinnantc51e1022010-05-11 19:42:16 +0000141
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000142 // No explicit construct/copy/destroy for aggregate type
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000143 _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) {
144 _VSTD::fill_n(__elems_, _Size, __u);
145 }
Eric Fiselier55659e42018-02-04 01:03:08 +0000146
Howard Hinnant32477e82011-05-31 21:06:33 +0000147 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000148 void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) {
149 std::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);
150 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000151
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000152 // iterators:
Marshall Clow99ba0022017-01-04 17:58:17 +0000153 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000154 iterator begin() _NOEXCEPT {return iterator(data());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000155 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000156 const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000157 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000158 iterator end() _NOEXCEPT {return iterator(data() + _Size);}
Marshall Clow99ba0022017-01-04 17:58:17 +0000159 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000160 const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000161
Marshall Clow99ba0022017-01-04 17:58:17 +0000162 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000163 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000164 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000165 const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000166 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000167 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000168 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000169 const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000170
Marshall Clow99ba0022017-01-04 17:58:17 +0000171 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000172 const_iterator cbegin() const _NOEXCEPT {return begin();}
Marshall Clow99ba0022017-01-04 17:58:17 +0000173 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000174 const_iterator cend() const _NOEXCEPT {return end();}
Marshall Clow99ba0022017-01-04 17:58:17 +0000175 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000176 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Marshall Clow99ba0022017-01-04 17:58:17 +0000177 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000178 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000179
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000180 // capacity:
Howard Hinnant32477e82011-05-31 21:06:33 +0000181 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant12ff42f2012-07-20 19:20:49 +0000182 _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;}
Howard Hinnant32477e82011-05-31 21:06:33 +0000183 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant12ff42f2012-07-20 19:20:49 +0000184 _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
Marshall Clow425f5752017-11-15 05:51:26 +0000185 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000186 _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return false; }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000187
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000188 // element access:
Marshall Clowac63f412017-01-16 03:02:10 +0000189 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
190 reference operator[](size_type __n) {return __elems_[__n];}
191 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
192 const_reference operator[](size_type __n) const {return __elems_[__n];}
193
194 _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n);
Marshall Clow0abb1042013-07-17 18:25:36 +0000195 _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000196
Marshall Clowac63f412017-01-16 03:02:10 +0000197 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() {return __elems_[0];}
Marshall Clow0abb1042013-07-17 18:25:36 +0000198 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const {return __elems_[0];}
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000199 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() {return __elems_[_Size - 1];}
200 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const {return __elems_[_Size - 1];}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000201
Marshall Clow99ba0022017-01-04 17:58:17 +0000202 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Nirav Dave129fb5c2018-02-06 03:03:37 +0000203 value_type* data() _NOEXCEPT {return __elems_;}
Marshall Clow99ba0022017-01-04 17:58:17 +0000204 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Nirav Dave129fb5c2018-02-06 03:03:37 +0000205 const value_type* data() const _NOEXCEPT {return __elems_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000206};
207
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000208
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000209template <class _Tp, size_t _Size>
Marshall Clowac63f412017-01-16 03:02:10 +0000210_LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000211typename array<_Tp, _Size>::reference
212array<_Tp, _Size>::at(size_type __n)
213{
214 if (__n >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +0000215 __throw_out_of_range("array::at");
216
Howard Hinnantc51e1022010-05-11 19:42:16 +0000217 return __elems_[__n];
218}
219
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000220template <class _Tp, size_t _Size>
Marshall Clow0abb1042013-07-17 18:25:36 +0000221_LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000222typename array<_Tp, _Size>::const_reference
223array<_Tp, _Size>::at(size_type __n) const
224{
225 if (__n >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +0000226 __throw_out_of_range("array::at");
Howard Hinnantc51e1022010-05-11 19:42:16 +0000227 return __elems_[__n];
228}
229
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000230template <class _Tp>
231struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
232{
233 // types:
234 typedef array __self;
235 typedef _Tp value_type;
236 typedef value_type& reference;
237 typedef const value_type& const_reference;
238 typedef value_type* iterator;
239 typedef const value_type* const_iterator;
240 typedef value_type* pointer;
241 typedef const value_type* const_pointer;
242 typedef size_t size_type;
243 typedef ptrdiff_t difference_type;
244 typedef std::reverse_iterator<iterator> reverse_iterator;
245 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
246
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000247 typedef typename conditional<is_const<_Tp>::value, const char,
248 char>::type _CharType;
Eric Fiselier6a537582018-02-07 23:50:25 +0000249
250 struct _ArrayInStructT { _Tp __data_[1]; };
251 _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)];
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000252
253 // No explicit construct/copy/destroy for aggregate type
254 _LIBCPP_INLINE_VISIBILITY void fill(const value_type&) {
255 static_assert(!is_const<_Tp>::value,
256 "cannot fill zero-sized array of type 'const T'");
257 }
258
259 _LIBCPP_INLINE_VISIBILITY
260 void swap(array&) _NOEXCEPT {
261 static_assert(!is_const<_Tp>::value,
262 "cannot swap zero-sized array of type 'const T'");
263 }
264
265 // iterators:
266 _LIBCPP_INLINE_VISIBILITY
267 iterator begin() _NOEXCEPT {return iterator(data());}
268 _LIBCPP_INLINE_VISIBILITY
269 const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
270 _LIBCPP_INLINE_VISIBILITY
271 iterator end() _NOEXCEPT {return iterator(data());}
272 _LIBCPP_INLINE_VISIBILITY
273 const_iterator end() const _NOEXCEPT {return const_iterator(data());}
274
275 _LIBCPP_INLINE_VISIBILITY
276 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
277 _LIBCPP_INLINE_VISIBILITY
278 const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
279 _LIBCPP_INLINE_VISIBILITY
280 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
281 _LIBCPP_INLINE_VISIBILITY
282 const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
283
284 _LIBCPP_INLINE_VISIBILITY
285 const_iterator cbegin() const _NOEXCEPT {return begin();}
286 _LIBCPP_INLINE_VISIBILITY
287 const_iterator cend() const _NOEXCEPT {return end();}
288 _LIBCPP_INLINE_VISIBILITY
289 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
290 _LIBCPP_INLINE_VISIBILITY
291 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
292
293 // capacity:
294 _LIBCPP_INLINE_VISIBILITY
295 _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; }
296 _LIBCPP_INLINE_VISIBILITY
297 _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;}
298 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
299 _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;}
300
301 // element access:
302 _LIBCPP_INLINE_VISIBILITY
303 reference operator[](size_type) {
304 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
305 _LIBCPP_UNREACHABLE();
306 }
307
308 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
309 const_reference operator[](size_type) const {
310 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
311 _LIBCPP_UNREACHABLE();
312 }
313
314 _LIBCPP_INLINE_VISIBILITY
315 reference at(size_type) {
316 __throw_out_of_range("array<T, 0>::at");
317 _LIBCPP_UNREACHABLE();
318 }
319
320 _LIBCPP_INLINE_VISIBILITY
321 const_reference at(size_type) const {
322 __throw_out_of_range("array<T, 0>::at");
323 _LIBCPP_UNREACHABLE();
324 }
325
326 _LIBCPP_INLINE_VISIBILITY
327 reference front() {
328 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
329 _LIBCPP_UNREACHABLE();
330 }
331
332 _LIBCPP_INLINE_VISIBILITY
333 const_reference front() const {
334 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
335 _LIBCPP_UNREACHABLE();
336 }
337
338 _LIBCPP_INLINE_VISIBILITY
339 reference back() {
340 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
341 _LIBCPP_UNREACHABLE();
342 }
343
344 _LIBCPP_INLINE_VISIBILITY
345 const_reference back() const {
346 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
347 _LIBCPP_UNREACHABLE();
348 }
349
350 _LIBCPP_INLINE_VISIBILITY
351 value_type* data() _NOEXCEPT {return reinterpret_cast<value_type*>(__elems_);}
352 _LIBCPP_INLINE_VISIBILITY
353 const value_type* data() const _NOEXCEPT {return reinterpret_cast<const value_type*>(__elems_);}
354};
355
356
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000357template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000358inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000359bool
360operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
361{
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000362 return _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000363}
364
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000365template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000366inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000367bool
368operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
369{
370 return !(__x == __y);
371}
372
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000373template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000374inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375bool
376operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
377{
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000378 return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
379 __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000380}
381
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000382template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000383inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000384bool
385operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
386{
387 return __y < __x;
388}
389
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000390template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000391inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392bool
393operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
394{
395 return !(__y < __x);
396}
397
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000398template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000399inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000400bool
401operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
402{
403 return !(__x < __y);
404}
405
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000406template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000407inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant44267242011-06-01 19:59:32 +0000408typename enable_if
409<
Eric Fiselier6bfed252016-04-21 23:38:59 +0000410 _Size == 0 ||
Howard Hinnant44267242011-06-01 19:59:32 +0000411 __is_swappable<_Tp>::value,
412 void
413>::type
Marshall Clowff1aa3d2016-03-07 21:57:10 +0000414swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
Eric Fiselier6bfed252016-04-21 23:38:59 +0000415 _NOEXCEPT_(noexcept(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416{
417 __x.swap(__y);
418}
419
420template <class _Tp, size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000421class _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
Howard Hinnant8e29cda2010-09-21 20:16:37 +0000422 : public integral_constant<size_t, _Size> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423
Howard Hinnantc51e1022010-05-11 19:42:16 +0000424template <size_t _Ip, class _Tp, size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000425class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000426{
Marshall Clow6f77fa12017-06-12 14:41:37 +0000427 static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428public:
429 typedef _Tp type;
430};
431
432template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000433inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000434_Tp&
Howard Hinnant32477e82011-05-31 21:06:33 +0000435get(array<_Tp, _Size>& __a) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000436{
Marshall Clow66c49ca2012-12-18 16:46:30 +0000437 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
Marshall Clow0abb1042013-07-17 18:25:36 +0000438 return __a.__elems_[_Ip];
Howard Hinnantc51e1022010-05-11 19:42:16 +0000439}
440
441template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000442inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000443const _Tp&
Howard Hinnant32477e82011-05-31 21:06:33 +0000444get(const array<_Tp, _Size>& __a) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445{
Marshall Clow66c49ca2012-12-18 16:46:30 +0000446 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
Marshall Clow0abb1042013-07-17 18:25:36 +0000447 return __a.__elems_[_Ip];
Howard Hinnantc51e1022010-05-11 19:42:16 +0000448}
449
Eric Fiselier73abed72017-04-16 02:50:40 +0000450#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000451
452template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000453inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant22e97242010-11-17 19:52:17 +0000454_Tp&&
Howard Hinnant32477e82011-05-31 21:06:33 +0000455get(array<_Tp, _Size>&& __a) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +0000456{
Marshall Clow66c49ca2012-12-18 16:46:30 +0000457 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
Marshall Clow0abb1042013-07-17 18:25:36 +0000458 return _VSTD::move(__a.__elems_[_Ip]);
Howard Hinnant22e97242010-11-17 19:52:17 +0000459}
460
Eric Fiselier6dea8092015-12-18 00:36:55 +0000461template <size_t _Ip, class _Tp, size_t _Size>
462inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
463const _Tp&&
464get(const array<_Tp, _Size>&& __a) _NOEXCEPT
465{
466 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
467 return _VSTD::move(__a.__elems_[_Ip]);
468}
469
Eric Fiselier73abed72017-04-16 02:50:40 +0000470#endif // !_LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000471
Howard Hinnantc51e1022010-05-11 19:42:16 +0000472_LIBCPP_END_NAMESPACE_STD
473
474#endif // _LIBCPP_ARRAY