blob: 88e9d57ff783e651deb8a922b600ade177586d0e [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- array -----------------------------------===//
3//
Chandler Carruth7c3769d2019-01-19 10:56:40 +00004// 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
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_ARRAY
11#define _LIBCPP_ARRAY
12
13/*
14 array synopsis
15
16namespace std
17{
Howard Hinnant324bb032010-08-22 00:02:43 +000018template <class T, size_t N >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000019struct array
Howard Hinnant324bb032010-08-22 00:02:43 +000020{
21 // types:
22 typedef T & reference;
23 typedef const T & const_reference;
24 typedef implementation defined iterator;
25 typedef implementation defined const_iterator;
26 typedef size_t size_type;
27 typedef ptrdiff_t difference_type;
28 typedef T value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000029 typedef T* pointer;
30 typedef const T* const_pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +000031 typedef std::reverse_iterator<iterator> reverse_iterator;
32 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000033
Howard Hinnant324bb032010-08-22 00:02:43 +000034 // No explicit construct/copy/destroy for aggregate type
35 void fill(const T& u);
Eric Fiselier8f1e73d2016-04-21 23:38:59 +000036 void swap(array& a) noexcept(is_nothrow_swappable_v<T>);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000037
Howard Hinnant324bb032010-08-22 00:02:43 +000038 // iterators:
Howard Hinnantf0562af2011-05-31 21:06:33 +000039 iterator begin() noexcept;
40 const_iterator begin() const noexcept;
41 iterator end() noexcept;
42 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000043
Howard Hinnantf0562af2011-05-31 21:06:33 +000044 reverse_iterator rbegin() noexcept;
45 const_reverse_iterator rbegin() const noexcept;
46 reverse_iterator rend() noexcept;
47 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000048
Howard Hinnantf0562af2011-05-31 21:06:33 +000049 const_iterator cbegin() const noexcept;
50 const_iterator cend() const noexcept;
51 const_reverse_iterator crbegin() const noexcept;
52 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000053
Howard Hinnant324bb032010-08-22 00:02:43 +000054 // capacity:
Howard Hinnantf0562af2011-05-31 21:06:33 +000055 constexpr size_type size() const noexcept;
56 constexpr size_type max_size() const noexcept;
Howard Hinnant08bce172012-07-20 19:20:49 +000057 constexpr bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000058
Howard Hinnant324bb032010-08-22 00:02:43 +000059 // element access:
60 reference operator[](size_type n);
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000061 const_reference operator[](size_type n) const; // constexpr in C++14
62 const_reference at(size_type n) const; // constexpr in C++14
Howard Hinnant324bb032010-08-22 00:02:43 +000063 reference at(size_type n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000064
Howard Hinnant324bb032010-08-22 00:02:43 +000065 reference front();
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000066 const_reference front() const; // constexpr in C++14
Howard Hinnant324bb032010-08-22 00:02:43 +000067 reference back();
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000068 const_reference back() const; // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000069
Howard Hinnantf0562af2011-05-31 21:06:33 +000070 T* data() noexcept;
71 const T* data() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000072};
73
Marshall Clow8a50bbc2018-05-18 21:01:04 +000074 template <class T, class... U>
75 array(T, U...) -> array<T, 1 + sizeof...(U)>;
76
Howard Hinnant324bb032010-08-22 00:02:43 +000077template <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);
87template <class T, size_t N>
88 bool operator>=(const array<T,N>& x, const array<T,N>& y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000089
Howard Hinnant324bb032010-08-22 00:02:43 +000090template <class T, size_t N >
Marshall Clow8a50bbc2018-05-18 21:01:04 +000091 void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000092
Marshall Clow74937312019-01-11 21:57:12 +000093template <class T> struct tuple_size;
Louis Dionneb857e812019-04-01 16:39:34 +000094template <size_t I, class T> struct tuple_element;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000095template <class T, size_t N> struct tuple_size<array<T, N>>;
Marshall Clowd8717282015-11-19 19:41:04 +000096template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>;
97template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14
98template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14
99template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14
Eric Fiselier199bee02015-12-18 00:36:55 +0000100template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000101
102} // std
103
104*/
105
106#include <__config>
107#include <__tuple>
108#include <type_traits>
109#include <utility>
110#include <iterator>
111#include <algorithm>
112#include <stdexcept>
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000113#include <cstdlib> // for _LIBCPP_UNREACHABLE
Marshall Clowe3973fd2018-09-12 19:41:40 +0000114#include <version>
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000115#include <__debug>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000116
Howard Hinnant08e17472011-10-17 20:05:10 +0000117#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000118#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000119#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120
Eric Fiselier018a3d52017-05-31 22:07:49 +0000121
122
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000123_LIBCPP_BEGIN_NAMESPACE_STD
124
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000125
Howard Hinnant324bb032010-08-22 00:02:43 +0000126template <class _Tp, size_t _Size>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000127struct _LIBCPP_TEMPLATE_VIS array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000128{
129 // types:
130 typedef array __self;
Howard Hinnant324bb032010-08-22 00:02:43 +0000131 typedef _Tp value_type;
132 typedef value_type& reference;
133 typedef const value_type& const_reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000134 typedef value_type* iterator;
135 typedef const value_type* const_iterator;
136 typedef value_type* pointer;
137 typedef const value_type* const_pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +0000138 typedef size_t size_type;
139 typedef ptrdiff_t difference_type;
140 typedef std::reverse_iterator<iterator> reverse_iterator;
141 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000142
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000143 _Tp __elems_[_Size];
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000144
Howard Hinnant324bb032010-08-22 00:02:43 +0000145 // No explicit construct/copy/destroy for aggregate type
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000146 _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) {
147 _VSTD::fill_n(__elems_, _Size, __u);
148 }
Eric Fiselierf3224ac2018-02-04 01:03:08 +0000149
Howard Hinnantf0562af2011-05-31 21:06:33 +0000150 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000151 void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) {
152 std::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);
153 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000154
Howard Hinnant324bb032010-08-22 00:02:43 +0000155 // iterators:
Marshall Clowe22af6b2017-01-04 17:58:17 +0000156 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000157 iterator begin() _NOEXCEPT {return iterator(data());}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000158 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000159 const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000160 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000161 iterator end() _NOEXCEPT {return iterator(data() + _Size);}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000162 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000163 const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000164
Marshall Clowe22af6b2017-01-04 17:58:17 +0000165 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000166 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000167 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000168 const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000169 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000170 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000171 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000172 const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000173
Marshall Clowe22af6b2017-01-04 17:58:17 +0000174 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000175 const_iterator cbegin() const _NOEXCEPT {return begin();}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000176 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000177 const_iterator cend() const _NOEXCEPT {return end();}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000178 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000179 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000180 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000181 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000182
Howard Hinnant324bb032010-08-22 00:02:43 +0000183 // capacity:
Howard Hinnantf0562af2011-05-31 21:06:33 +0000184 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08bce172012-07-20 19:20:49 +0000185 _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;}
Howard Hinnantf0562af2011-05-31 21:06:33 +0000186 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08bce172012-07-20 19:20:49 +0000187 _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
Marshall Clow88626bf2017-11-15 05:51:26 +0000188 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000189 _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return false; }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000190
Howard Hinnant324bb032010-08-22 00:02:43 +0000191 // element access:
Marshall Clowd25c9972017-01-16 03:02:10 +0000192 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowfa199b92019-03-14 21:56:57 +0000193 reference operator[](size_type __n) _NOEXCEPT {return __elems_[__n];}
Marshall Clowd25c9972017-01-16 03:02:10 +0000194 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clowfa199b92019-03-14 21:56:57 +0000195 const_reference operator[](size_type __n) const _NOEXCEPT {return __elems_[__n];}
Marshall Clowd25c9972017-01-16 03:02:10 +0000196
197 _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n);
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000198 _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000199
Marshall Clowddb1b052019-03-19 03:30:07 +0000200 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() _NOEXCEPT {return __elems_[0];}
201 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const _NOEXCEPT {return __elems_[0];}
202 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() _NOEXCEPT {return __elems_[_Size - 1];}
203 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const _NOEXCEPT {return __elems_[_Size - 1];}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000204
Marshall Clowe22af6b2017-01-04 17:58:17 +0000205 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Nirav Dave610fc6782018-02-06 03:03:37 +0000206 value_type* data() _NOEXCEPT {return __elems_;}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000207 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Nirav Dave610fc6782018-02-06 03:03:37 +0000208 const value_type* data() const _NOEXCEPT {return __elems_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000209};
210
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000211
Howard Hinnant324bb032010-08-22 00:02:43 +0000212template <class _Tp, size_t _Size>
Marshall Clowd25c9972017-01-16 03:02:10 +0000213_LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000214typename array<_Tp, _Size>::reference
215array<_Tp, _Size>::at(size_type __n)
216{
217 if (__n >= _Size)
Marshall Clow14c09a22016-08-25 15:09:01 +0000218 __throw_out_of_range("array::at");
219
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000220 return __elems_[__n];
221}
222
Howard Hinnant324bb032010-08-22 00:02:43 +0000223template <class _Tp, size_t _Size>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000224_LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000225typename array<_Tp, _Size>::const_reference
226array<_Tp, _Size>::at(size_type __n) const
227{
228 if (__n >= _Size)
Marshall Clow14c09a22016-08-25 15:09:01 +0000229 __throw_out_of_range("array::at");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000230 return __elems_[__n];
231}
232
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000233template <class _Tp>
234struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
235{
236 // types:
237 typedef array __self;
238 typedef _Tp value_type;
239 typedef value_type& reference;
240 typedef const value_type& const_reference;
241 typedef value_type* iterator;
242 typedef const value_type* const_iterator;
243 typedef value_type* pointer;
244 typedef const value_type* const_pointer;
245 typedef size_t size_type;
246 typedef ptrdiff_t difference_type;
247 typedef std::reverse_iterator<iterator> reverse_iterator;
248 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
249
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000250 typedef typename conditional<is_const<_Tp>::value, const char,
251 char>::type _CharType;
Eric Fiselierc0acd342018-02-07 23:50:25 +0000252
253 struct _ArrayInStructT { _Tp __data_[1]; };
254 _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)];
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000255
256 // No explicit construct/copy/destroy for aggregate type
257 _LIBCPP_INLINE_VISIBILITY void fill(const value_type&) {
258 static_assert(!is_const<_Tp>::value,
259 "cannot fill zero-sized array of type 'const T'");
260 }
261
262 _LIBCPP_INLINE_VISIBILITY
263 void swap(array&) _NOEXCEPT {
264 static_assert(!is_const<_Tp>::value,
265 "cannot swap zero-sized array of type 'const T'");
266 }
267
268 // iterators:
269 _LIBCPP_INLINE_VISIBILITY
270 iterator begin() _NOEXCEPT {return iterator(data());}
271 _LIBCPP_INLINE_VISIBILITY
272 const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
273 _LIBCPP_INLINE_VISIBILITY
274 iterator end() _NOEXCEPT {return iterator(data());}
275 _LIBCPP_INLINE_VISIBILITY
276 const_iterator end() const _NOEXCEPT {return const_iterator(data());}
277
278 _LIBCPP_INLINE_VISIBILITY
279 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
280 _LIBCPP_INLINE_VISIBILITY
281 const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
282 _LIBCPP_INLINE_VISIBILITY
283 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
284 _LIBCPP_INLINE_VISIBILITY
285 const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
286
287 _LIBCPP_INLINE_VISIBILITY
288 const_iterator cbegin() const _NOEXCEPT {return begin();}
289 _LIBCPP_INLINE_VISIBILITY
290 const_iterator cend() const _NOEXCEPT {return end();}
291 _LIBCPP_INLINE_VISIBILITY
292 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
293 _LIBCPP_INLINE_VISIBILITY
294 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
295
296 // capacity:
297 _LIBCPP_INLINE_VISIBILITY
298 _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; }
299 _LIBCPP_INLINE_VISIBILITY
300 _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;}
301 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
302 _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;}
303
304 // element access:
305 _LIBCPP_INLINE_VISIBILITY
Marshall Clowfa199b92019-03-14 21:56:57 +0000306 reference operator[](size_type) _NOEXCEPT {
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000307 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
308 _LIBCPP_UNREACHABLE();
309 }
310
311 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clowfa199b92019-03-14 21:56:57 +0000312 const_reference operator[](size_type) const _NOEXCEPT {
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000313 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
314 _LIBCPP_UNREACHABLE();
315 }
316
317 _LIBCPP_INLINE_VISIBILITY
318 reference at(size_type) {
319 __throw_out_of_range("array<T, 0>::at");
320 _LIBCPP_UNREACHABLE();
321 }
322
323 _LIBCPP_INLINE_VISIBILITY
324 const_reference at(size_type) const {
325 __throw_out_of_range("array<T, 0>::at");
326 _LIBCPP_UNREACHABLE();
327 }
328
329 _LIBCPP_INLINE_VISIBILITY
Marshall Clowddb1b052019-03-19 03:30:07 +0000330 reference front() _NOEXCEPT {
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000331 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
332 _LIBCPP_UNREACHABLE();
333 }
334
335 _LIBCPP_INLINE_VISIBILITY
Marshall Clowddb1b052019-03-19 03:30:07 +0000336 const_reference front() const _NOEXCEPT {
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000337 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
338 _LIBCPP_UNREACHABLE();
339 }
340
341 _LIBCPP_INLINE_VISIBILITY
Marshall Clowddb1b052019-03-19 03:30:07 +0000342 reference back() _NOEXCEPT {
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000343 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
344 _LIBCPP_UNREACHABLE();
345 }
346
347 _LIBCPP_INLINE_VISIBILITY
Marshall Clowddb1b052019-03-19 03:30:07 +0000348 const_reference back() const _NOEXCEPT {
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000349 _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
350 _LIBCPP_UNREACHABLE();
351 }
352
353 _LIBCPP_INLINE_VISIBILITY
354 value_type* data() _NOEXCEPT {return reinterpret_cast<value_type*>(__elems_);}
355 _LIBCPP_INLINE_VISIBILITY
356 const value_type* data() const _NOEXCEPT {return reinterpret_cast<const value_type*>(__elems_);}
357};
358
359
Marshall Clow8a50bbc2018-05-18 21:01:04 +0000360#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
361template<class _Tp, class... _Args,
362 class = typename enable_if<(is_same_v<_Tp, _Args> && ...), void>::type
363 >
364array(_Tp, _Args...)
365 -> array<_Tp, 1 + sizeof...(_Args)>;
366#endif
367
Howard Hinnant324bb032010-08-22 00:02:43 +0000368template <class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000369inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow88f5d7a2018-08-02 02:11:06 +0000370_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
372{
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000373 return _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374}
375
Howard Hinnant324bb032010-08-22 00:02:43 +0000376template <class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000377inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow88f5d7a2018-08-02 02:11:06 +0000378_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000379operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
380{
381 return !(__x == __y);
382}
383
Howard Hinnant324bb032010-08-22 00:02:43 +0000384template <class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000385inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow88f5d7a2018-08-02 02:11:06 +0000386_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000387operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
388{
Eric Fiselier6cb35ed2018-02-07 21:06:13 +0000389 return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
390 __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000391}
392
Howard Hinnant324bb032010-08-22 00:02:43 +0000393template <class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000394inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow88f5d7a2018-08-02 02:11:06 +0000395_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000396operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
397{
398 return __y < __x;
399}
400
Howard Hinnant324bb032010-08-22 00:02:43 +0000401template <class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000402inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow88f5d7a2018-08-02 02:11:06 +0000403_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000404operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
405{
406 return !(__y < __x);
407}
408
Howard Hinnant324bb032010-08-22 00:02:43 +0000409template <class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000410inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow88f5d7a2018-08-02 02:11:06 +0000411_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000412operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
413{
414 return !(__x < __y);
415}
416
Howard Hinnant324bb032010-08-22 00:02:43 +0000417template <class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000418inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000419typename enable_if
420<
Eric Fiselier8f1e73d2016-04-21 23:38:59 +0000421 _Size == 0 ||
Howard Hinnantaabf2872011-06-01 19:59:32 +0000422 __is_swappable<_Tp>::value,
423 void
424>::type
Marshall Clow8d48d9b2016-03-07 21:57:10 +0000425swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
Eric Fiselier8f1e73d2016-04-21 23:38:59 +0000426 _NOEXCEPT_(noexcept(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000427{
428 __x.swap(__y);
429}
430
431template <class _Tp, size_t _Size>
Marshall Clow74937312019-01-11 21:57:12 +0000432struct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
Howard Hinnant333f50d2010-09-21 20:16:37 +0000433 : public integral_constant<size_t, _Size> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000434
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000435template <size_t _Ip, class _Tp, size_t _Size>
Louis Dionneb857e812019-04-01 16:39:34 +0000436struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000437{
Marshall Clow568c4812017-06-12 14:41:37 +0000438 static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439 typedef _Tp type;
440};
441
442template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000443inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000444_Tp&
Howard Hinnantf0562af2011-05-31 21:06:33 +0000445get(array<_Tp, _Size>& __a) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000446{
Marshall Clowa46482e2012-12-18 16:46:30 +0000447 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000448 return __a.__elems_[_Ip];
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000449}
450
451template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000452inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000453const _Tp&
Howard Hinnantf0562af2011-05-31 21:06:33 +0000454get(const array<_Tp, _Size>& __a) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000455{
Marshall Clowa46482e2012-12-18 16:46:30 +0000456 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000457 return __a.__elems_[_Ip];
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000458}
459
Eric Fiselier6c26be62017-04-16 02:50:40 +0000460#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000461
462template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000463inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000464_Tp&&
Howard Hinnantf0562af2011-05-31 21:06:33 +0000465get(array<_Tp, _Size>&& __a) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000466{
Marshall Clowa46482e2012-12-18 16:46:30 +0000467 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000468 return _VSTD::move(__a.__elems_[_Ip]);
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000469}
470
Eric Fiselier199bee02015-12-18 00:36:55 +0000471template <size_t _Ip, class _Tp, size_t _Size>
472inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
473const _Tp&&
474get(const array<_Tp, _Size>&& __a) _NOEXCEPT
475{
476 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
477 return _VSTD::move(__a.__elems_[_Ip]);
478}
479
Eric Fiselier6c26be62017-04-16 02:50:40 +0000480#endif // !_LIBCPP_CXX03_LANG
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000481
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000482_LIBCPP_END_NAMESPACE_STD
483
484#endif // _LIBCPP_ARRAY