blob: 8f4e111acbb4a712ab1faa25568685e6a791396d [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
Marshall Clow8847d032018-05-18 21:01:04 +000075 template <class T, class... U>
76 array(T, U...) -> array<T, 1 + sizeof...(U)>;
77
Howard Hinnant3b6579a2010-08-22 00:02:43 +000078template <class T, size_t N>
79 bool operator==(const array<T,N>& x, const array<T,N>& y);
80template <class T, size_t N>
81 bool operator!=(const array<T,N>& x, const array<T,N>& y);
82template <class T, size_t N>
83 bool operator<(const array<T,N>& x, const array<T,N>& y);
84template <class T, size_t N>
85 bool operator>(const array<T,N>& x, const array<T,N>& y);
86template <class T, size_t N>
87 bool operator<=(const array<T,N>& x, const array<T,N>& y);
88template <class T, size_t N>
89 bool operator>=(const array<T,N>& x, const array<T,N>& y);
Howard Hinnantc51e1022010-05-11 19:42:16 +000090
Howard Hinnant3b6579a2010-08-22 00:02:43 +000091template <class T, size_t N >
Marshall Clow8847d032018-05-18 21:01:04 +000092 void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +000093
Howard Hinnant3b6579a2010-08-22 00:02:43 +000094template <class T> class tuple_size;
Marshall Clow291a3512015-11-19 19:41:04 +000095template <size_t I, class T> class tuple_element;
Howard Hinnantc51e1022010-05-11 19:42:16 +000096template <class T, size_t N> struct tuple_size<array<T, N>>;
Marshall Clow291a3512015-11-19 19:41:04 +000097template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>;
98template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14
99template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14
100template <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 +0000101template <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 +0000102
103} // std
104
105*/
106
107#include <__config>
108#include <__tuple>
109#include <type_traits>
110#include <utility>
111#include <iterator>
112#include <algorithm>
113#include <stdexcept>
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000114#include <cstdlib> // for _LIBCPP_UNREACHABLE
Marshall Clow0a1e7502018-09-12 19:41:40 +0000115#include <version>
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000116#include <__debug>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000117
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000118#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000119#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000120#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000121
Eric Fiselierf4433a32017-05-31 22:07:49 +0000122
123
Howard Hinnantc51e1022010-05-11 19:42:16 +0000124_LIBCPP_BEGIN_NAMESPACE_STD
125
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000126
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000127template <class _Tp, size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000128struct _LIBCPP_TEMPLATE_VIS array
Howard Hinnantc51e1022010-05-11 19:42:16 +0000129{
130 // types:
131 typedef array __self;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000132 typedef _Tp value_type;
133 typedef value_type& reference;
134 typedef const value_type& const_reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000135 typedef value_type* iterator;
136 typedef const value_type* const_iterator;
137 typedef value_type* pointer;
138 typedef const value_type* const_pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000139 typedef size_t size_type;
140 typedef ptrdiff_t difference_type;
141 typedef std::reverse_iterator<iterator> reverse_iterator;
142 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000143
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000144 _Tp __elems_[_Size];
Howard Hinnantc51e1022010-05-11 19:42:16 +0000145
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000146 // No explicit construct/copy/destroy for aggregate type
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000147 _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) {
148 _VSTD::fill_n(__elems_, _Size, __u);
149 }
Eric Fiselier55659e42018-02-04 01:03:08 +0000150
Howard Hinnant32477e82011-05-31 21:06:33 +0000151 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000152 void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) {
153 std::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);
154 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000155
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000156 // iterators:
Marshall Clow99ba0022017-01-04 17:58:17 +0000157 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000158 iterator begin() _NOEXCEPT {return iterator(data());}
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 begin() const _NOEXCEPT {return const_iterator(data());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000161 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000162 iterator end() _NOEXCEPT {return iterator(data() + _Size);}
Marshall Clow99ba0022017-01-04 17:58:17 +0000163 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000164 const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000165
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 rbegin() _NOEXCEPT {return reverse_iterator(end());}
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 rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000170 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000171 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000172 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000173 const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000174
Marshall Clow99ba0022017-01-04 17:58:17 +0000175 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000176 const_iterator cbegin() const _NOEXCEPT {return begin();}
Marshall Clow99ba0022017-01-04 17:58:17 +0000177 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000178 const_iterator cend() const _NOEXCEPT {return end();}
Marshall Clow99ba0022017-01-04 17:58:17 +0000179 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000180 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Marshall Clow99ba0022017-01-04 17:58:17 +0000181 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000182 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000183
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000184 // capacity:
Howard Hinnant32477e82011-05-31 21:06:33 +0000185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant12ff42f2012-07-20 19:20:49 +0000186 _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;}
Howard Hinnant32477e82011-05-31 21:06:33 +0000187 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant12ff42f2012-07-20 19:20:49 +0000188 _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
Marshall Clow425f5752017-11-15 05:51:26 +0000189 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000190 _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return false; }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000191
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000192 // element access:
Marshall Clowac63f412017-01-16 03:02:10 +0000193 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
194 reference operator[](size_type __n) {return __elems_[__n];}
195 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
196 const_reference operator[](size_type __n) const {return __elems_[__n];}
197
198 _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n);
Marshall Clow0abb1042013-07-17 18:25:36 +0000199 _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000200
Marshall Clowac63f412017-01-16 03:02:10 +0000201 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() {return __elems_[0];}
Marshall Clow0abb1042013-07-17 18:25:36 +0000202 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const {return __elems_[0];}
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000203 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() {return __elems_[_Size - 1];}
204 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const {return __elems_[_Size - 1];}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000205
Marshall Clow99ba0022017-01-04 17:58:17 +0000206 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Nirav Dave129fb5c2018-02-06 03:03:37 +0000207 value_type* data() _NOEXCEPT {return __elems_;}
Marshall Clow99ba0022017-01-04 17:58:17 +0000208 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Nirav Dave129fb5c2018-02-06 03:03:37 +0000209 const value_type* data() const _NOEXCEPT {return __elems_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000210};
211
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000212
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000213template <class _Tp, size_t _Size>
Marshall Clowac63f412017-01-16 03:02:10 +0000214_LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000215typename array<_Tp, _Size>::reference
216array<_Tp, _Size>::at(size_type __n)
217{
218 if (__n >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +0000219 __throw_out_of_range("array::at");
220
Howard Hinnantc51e1022010-05-11 19:42:16 +0000221 return __elems_[__n];
222}
223
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000224template <class _Tp, size_t _Size>
Marshall Clow0abb1042013-07-17 18:25:36 +0000225_LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000226typename array<_Tp, _Size>::const_reference
227array<_Tp, _Size>::at(size_type __n) const
228{
229 if (__n >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +0000230 __throw_out_of_range("array::at");
Howard Hinnantc51e1022010-05-11 19:42:16 +0000231 return __elems_[__n];
232}
233
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000234template <class _Tp>
235struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
236{
237 // types:
238 typedef array __self;
239 typedef _Tp value_type;
240 typedef value_type& reference;
241 typedef const value_type& const_reference;
242 typedef value_type* iterator;
243 typedef const value_type* const_iterator;
244 typedef value_type* pointer;
245 typedef const value_type* const_pointer;
246 typedef size_t size_type;
247 typedef ptrdiff_t difference_type;
248 typedef std::reverse_iterator<iterator> reverse_iterator;
249 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
250
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000251 typedef typename conditional<is_const<_Tp>::value, const char,
252 char>::type _CharType;
Eric Fiselier6a537582018-02-07 23:50:25 +0000253
254 struct _ArrayInStructT { _Tp __data_[1]; };
255 _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)];
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000256
257 // No explicit construct/copy/destroy for aggregate type
258 _LIBCPP_INLINE_VISIBILITY void fill(const value_type&) {
259 static_assert(!is_const<_Tp>::value,
260 "cannot fill zero-sized array of type 'const T'");
261 }
262
263 _LIBCPP_INLINE_VISIBILITY
264 void swap(array&) _NOEXCEPT {
265 static_assert(!is_const<_Tp>::value,
266 "cannot swap zero-sized array of type 'const T'");
267 }
268
269 // iterators:
270 _LIBCPP_INLINE_VISIBILITY
271 iterator begin() _NOEXCEPT {return iterator(data());}
272 _LIBCPP_INLINE_VISIBILITY
273 const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
274 _LIBCPP_INLINE_VISIBILITY
275 iterator end() _NOEXCEPT {return iterator(data());}
276 _LIBCPP_INLINE_VISIBILITY
277 const_iterator end() const _NOEXCEPT {return const_iterator(data());}
278
279 _LIBCPP_INLINE_VISIBILITY
280 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
281 _LIBCPP_INLINE_VISIBILITY
282 const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
283 _LIBCPP_INLINE_VISIBILITY
284 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
285 _LIBCPP_INLINE_VISIBILITY
286 const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
287
288 _LIBCPP_INLINE_VISIBILITY
289 const_iterator cbegin() const _NOEXCEPT {return begin();}
290 _LIBCPP_INLINE_VISIBILITY
291 const_iterator cend() const _NOEXCEPT {return end();}
292 _LIBCPP_INLINE_VISIBILITY
293 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
294 _LIBCPP_INLINE_VISIBILITY
295 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
296
297 // capacity:
298 _LIBCPP_INLINE_VISIBILITY
299 _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; }
300 _LIBCPP_INLINE_VISIBILITY
301 _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;}
302 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
303 _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;}
304
305 // element access:
306 _LIBCPP_INLINE_VISIBILITY
307 reference operator[](size_type) {
308 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
309 _LIBCPP_UNREACHABLE();
310 }
311
312 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
313 const_reference operator[](size_type) const {
314 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
315 _LIBCPP_UNREACHABLE();
316 }
317
318 _LIBCPP_INLINE_VISIBILITY
319 reference at(size_type) {
320 __throw_out_of_range("array<T, 0>::at");
321 _LIBCPP_UNREACHABLE();
322 }
323
324 _LIBCPP_INLINE_VISIBILITY
325 const_reference at(size_type) const {
326 __throw_out_of_range("array<T, 0>::at");
327 _LIBCPP_UNREACHABLE();
328 }
329
330 _LIBCPP_INLINE_VISIBILITY
331 reference front() {
332 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
333 _LIBCPP_UNREACHABLE();
334 }
335
336 _LIBCPP_INLINE_VISIBILITY
337 const_reference front() const {
338 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
339 _LIBCPP_UNREACHABLE();
340 }
341
342 _LIBCPP_INLINE_VISIBILITY
343 reference back() {
344 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
345 _LIBCPP_UNREACHABLE();
346 }
347
348 _LIBCPP_INLINE_VISIBILITY
349 const_reference back() const {
350 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
351 _LIBCPP_UNREACHABLE();
352 }
353
354 _LIBCPP_INLINE_VISIBILITY
355 value_type* data() _NOEXCEPT {return reinterpret_cast<value_type*>(__elems_);}
356 _LIBCPP_INLINE_VISIBILITY
357 const value_type* data() const _NOEXCEPT {return reinterpret_cast<const value_type*>(__elems_);}
358};
359
360
Marshall Clow8847d032018-05-18 21:01:04 +0000361#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
362template<class _Tp, class... _Args,
363 class = typename enable_if<(is_same_v<_Tp, _Args> && ...), void>::type
364 >
365array(_Tp, _Args...)
366 -> array<_Tp, 1 + sizeof...(_Args)>;
367#endif
368
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000369template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000370inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow35a45042018-08-02 02:11:06 +0000371_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
Howard Hinnantc51e1022010-05-11 19:42:16 +0000372operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
373{
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000374 return _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375}
376
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000377template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000378inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow35a45042018-08-02 02:11:06 +0000379_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
Howard Hinnantc51e1022010-05-11 19:42:16 +0000380operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
381{
382 return !(__x == __y);
383}
384
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000385template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000386inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow35a45042018-08-02 02:11:06 +0000387_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
Howard Hinnantc51e1022010-05-11 19:42:16 +0000388operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
389{
Eric Fiselier5037a3b2018-02-07 21:06:13 +0000390 return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
391 __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392}
393
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000394template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000395inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow35a45042018-08-02 02:11:06 +0000396_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
398{
399 return __y < __x;
400}
401
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000402template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000403inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow35a45042018-08-02 02:11:06 +0000404_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
Howard Hinnantc51e1022010-05-11 19:42:16 +0000405operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
406{
407 return !(__y < __x);
408}
409
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000410template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000411inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow35a45042018-08-02 02:11:06 +0000412_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
414{
415 return !(__x < __y);
416}
417
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000418template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000419inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant44267242011-06-01 19:59:32 +0000420typename enable_if
421<
Eric Fiselier6bfed252016-04-21 23:38:59 +0000422 _Size == 0 ||
Howard Hinnant44267242011-06-01 19:59:32 +0000423 __is_swappable<_Tp>::value,
424 void
425>::type
Marshall Clowff1aa3d2016-03-07 21:57:10 +0000426swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
Eric Fiselier6bfed252016-04-21 23:38:59 +0000427 _NOEXCEPT_(noexcept(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428{
429 __x.swap(__y);
430}
431
432template <class _Tp, size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000433class _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
Howard Hinnant8e29cda2010-09-21 20:16:37 +0000434 : public integral_constant<size_t, _Size> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000435
Howard Hinnantc51e1022010-05-11 19:42:16 +0000436template <size_t _Ip, class _Tp, size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000437class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000438{
Marshall Clow6f77fa12017-06-12 14:41:37 +0000439 static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
Howard Hinnantc51e1022010-05-11 19:42:16 +0000440public:
441 typedef _Tp type;
442};
443
444template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000445inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446_Tp&
Howard Hinnant32477e82011-05-31 21:06:33 +0000447get(array<_Tp, _Size>& __a) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000448{
Marshall Clow66c49ca2012-12-18 16:46:30 +0000449 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
Marshall Clow0abb1042013-07-17 18:25:36 +0000450 return __a.__elems_[_Ip];
Howard Hinnantc51e1022010-05-11 19:42:16 +0000451}
452
453template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000454inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000455const _Tp&
Howard Hinnant32477e82011-05-31 21:06:33 +0000456get(const array<_Tp, _Size>& __a) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000457{
Marshall Clow66c49ca2012-12-18 16:46:30 +0000458 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
Marshall Clow0abb1042013-07-17 18:25:36 +0000459 return __a.__elems_[_Ip];
Howard Hinnantc51e1022010-05-11 19:42:16 +0000460}
461
Eric Fiselier73abed72017-04-16 02:50:40 +0000462#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000463
464template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000465inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant22e97242010-11-17 19:52:17 +0000466_Tp&&
Howard Hinnant32477e82011-05-31 21:06:33 +0000467get(array<_Tp, _Size>&& __a) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +0000468{
Marshall Clow66c49ca2012-12-18 16:46:30 +0000469 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
Marshall Clow0abb1042013-07-17 18:25:36 +0000470 return _VSTD::move(__a.__elems_[_Ip]);
Howard Hinnant22e97242010-11-17 19:52:17 +0000471}
472
Eric Fiselier6dea8092015-12-18 00:36:55 +0000473template <size_t _Ip, class _Tp, size_t _Size>
474inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
475const _Tp&&
476get(const array<_Tp, _Size>&& __a) _NOEXCEPT
477{
478 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
479 return _VSTD::move(__a.__elems_[_Ip]);
480}
481
Eric Fiselier73abed72017-04-16 02:50:40 +0000482#endif // !_LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000483
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484_LIBCPP_END_NAMESPACE_STD
485
486#endif // _LIBCPP_ARRAY