1 1.1 joerg // -*- C++ -*- 2 1.1 joerg //===---------------------------- array -----------------------------------===// 3 1.1 joerg // 4 1.1 joerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 1.1 joerg // See https://llvm.org/LICENSE.txt for license information. 6 1.1 joerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 1.1 joerg // 8 1.1 joerg //===----------------------------------------------------------------------===// 9 1.1 joerg 10 1.1 joerg #ifndef _LIBCPP_ARRAY 11 1.1 joerg #define _LIBCPP_ARRAY 12 1.1 joerg 13 1.1 joerg /* 14 1.1 joerg array synopsis 15 1.1 joerg 16 1.1 joerg namespace std 17 1.1 joerg { 18 1.1 joerg template <class T, size_t N > 19 1.1 joerg struct array 20 1.1 joerg { 21 1.1 joerg // types: 22 1.1 joerg typedef T & reference; 23 1.1 joerg typedef const T & const_reference; 24 1.1 joerg typedef implementation defined iterator; 25 1.1 joerg typedef implementation defined const_iterator; 26 1.1 joerg typedef size_t size_type; 27 1.1 joerg typedef ptrdiff_t difference_type; 28 1.1 joerg typedef T value_type; 29 1.1 joerg typedef T* pointer; 30 1.1 joerg typedef const T* const_pointer; 31 1.1 joerg typedef std::reverse_iterator<iterator> reverse_iterator; 32 1.1 joerg typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 33 1.1 joerg 34 1.1 joerg // No explicit construct/copy/destroy for aggregate type 35 1.1 joerg void fill(const T& u); // constexpr in C++20 36 1.1 joerg void swap(array& a) noexcept(is_nothrow_swappable_v<T>); // constexpr in C++20 37 1.1 joerg 38 1.1 joerg // iterators: 39 1.1 joerg iterator begin() noexcept; // constexpr in C++17 40 1.1 joerg const_iterator begin() const noexcept; // constexpr in C++17 41 1.1 joerg iterator end() noexcept; // constexpr in C++17 42 1.1 joerg const_iterator end() const noexcept; // constexpr in C++17 43 1.1 joerg 44 1.1 joerg reverse_iterator rbegin() noexcept; // constexpr in C++17 45 1.1 joerg const_reverse_iterator rbegin() const noexcept; // constexpr in C++17 46 1.1 joerg reverse_iterator rend() noexcept; // constexpr in C++17 47 1.1 joerg const_reverse_iterator rend() const noexcept; // constexpr in C++17 48 1.1 joerg 49 1.1 joerg const_iterator cbegin() const noexcept; // constexpr in C++17 50 1.1 joerg const_iterator cend() const noexcept; // constexpr in C++17 51 1.1 joerg const_reverse_iterator crbegin() const noexcept; // constexpr in C++17 52 1.1 joerg const_reverse_iterator crend() const noexcept; // constexpr in C++17 53 1.1 joerg 54 1.1 joerg // capacity: 55 1.1 joerg constexpr size_type size() const noexcept; 56 1.1 joerg constexpr size_type max_size() const noexcept; 57 1.1 joerg constexpr bool empty() const noexcept; 58 1.1 joerg 59 1.1 joerg // element access: 60 1.1 joerg reference operator[](size_type n); // constexpr in C++17 61 1.1 joerg const_reference operator[](size_type n) const; // constexpr in C++14 62 1.1 joerg reference at(size_type n); // constexpr in C++17 63 1.1 joerg const_reference at(size_type n) const; // constexpr in C++14 64 1.1 joerg 65 1.1 joerg reference front(); // constexpr in C++17 66 1.1 joerg const_reference front() const; // constexpr in C++14 67 1.1 joerg reference back(); // constexpr in C++17 68 1.1 joerg const_reference back() const; // constexpr in C++14 69 1.1 joerg 70 1.1 joerg T* data() noexcept; // constexpr in C++17 71 1.1 joerg const T* data() const noexcept; // constexpr in C++17 72 1.1 joerg }; 73 1.1 joerg 74 1.1 joerg template <class T, class... U> 75 1.1 joerg array(T, U...) -> array<T, 1 + sizeof...(U)>; // C++17 76 1.1 joerg 77 1.1 joerg template <class T, size_t N> 78 1.1 joerg bool operator==(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 79 1.1 joerg template <class T, size_t N> 80 1.1 joerg bool operator!=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 81 1.1 joerg template <class T, size_t N> 82 1.1 joerg bool operator<(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 83 1.1 joerg template <class T, size_t N> 84 1.1 joerg bool operator>(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 85 1.1 joerg template <class T, size_t N> 86 1.1 joerg bool operator<=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 87 1.1 joerg template <class T, size_t N> 88 1.1 joerg bool operator>=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 89 1.1 joerg 90 1.1 joerg template <class T, size_t N > 91 1.1 joerg void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20 92 1.1 joerg 93 1.1 joerg template <class T, size_t N> 94 1.1 joerg constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]); // C++20 95 1.1 joerg template <class T, size_t N> 96 1.1 joerg constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]); // C++20 97 1.1 joerg 98 1.1 joerg template <class T> struct tuple_size; 99 1.1 joerg template <size_t I, class T> struct tuple_element; 100 1.1 joerg template <class T, size_t N> struct tuple_size<array<T, N>>; 101 1.1 joerg template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>; 102 1.1 joerg template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14 103 1.1 joerg template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14 104 1.1 joerg template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14 105 1.1 joerg template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14 106 1.1 joerg 107 1.1 joerg } // std 108 1.1 joerg 109 1.1 joerg */ 110 1.1 joerg 111 1.1 joerg #include <__config> 112 1.1 joerg #include <__tuple> 113 1.1 joerg #include <type_traits> 114 1.1 joerg #include <utility> 115 1.1 joerg #include <iterator> 116 1.1 joerg #include <algorithm> 117 1.1 joerg #include <stdexcept> 118 1.1 joerg #include <cstdlib> // for _LIBCPP_UNREACHABLE 119 1.1 joerg #include <version> 120 1.1 joerg #include <__debug> 121 1.1 joerg 122 1.1 joerg #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 123 1.1 joerg #pragma GCC system_header 124 1.1 joerg #endif 125 1.1 joerg 126 1.1 joerg 127 1.1 joerg 128 1.1 joerg _LIBCPP_BEGIN_NAMESPACE_STD 129 1.1 joerg 130 1.1 joerg 131 1.1 joerg template <class _Tp, size_t _Size> 132 1.1 joerg struct _LIBCPP_TEMPLATE_VIS array 133 1.1 joerg { 134 1.1 joerg // types: 135 1.1 joerg typedef array __self; 136 1.1 joerg typedef _Tp value_type; 137 1.1 joerg typedef value_type& reference; 138 1.1 joerg typedef const value_type& const_reference; 139 1.1 joerg typedef value_type* iterator; 140 1.1 joerg typedef const value_type* const_iterator; 141 1.1 joerg typedef value_type* pointer; 142 1.1 joerg typedef const value_type* const_pointer; 143 1.1 joerg typedef size_t size_type; 144 1.1 joerg typedef ptrdiff_t difference_type; 145 1.1 joerg typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 146 1.1 joerg typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 147 1.1 joerg 148 1.1 joerg _Tp __elems_[_Size]; 149 1.1 joerg 150 1.1 joerg // No explicit construct/copy/destroy for aggregate type 151 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 152 1.1 joerg void fill(const value_type& __u) { 153 1.1 joerg _VSTD::fill_n(data(), _Size, __u); 154 1.1 joerg } 155 1.1 joerg 156 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 157 1.1 joerg void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) { 158 1.1 joerg _VSTD::swap_ranges(data(), data() + _Size, __a.data()); 159 1.1 joerg } 160 1.1 joerg 161 1.1 joerg // iterators: 162 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 163 1.1 joerg iterator begin() _NOEXCEPT {return iterator(data());} 164 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 165 1.1 joerg const_iterator begin() const _NOEXCEPT {return const_iterator(data());} 166 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 167 1.1 joerg iterator end() _NOEXCEPT {return iterator(data() + _Size);} 168 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 169 1.1 joerg const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);} 170 1.1 joerg 171 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 172 1.1 joerg reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} 173 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 174 1.1 joerg const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} 175 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 176 1.1 joerg reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} 177 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 178 1.1 joerg const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} 179 1.1 joerg 180 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 181 1.1 joerg const_iterator cbegin() const _NOEXCEPT {return begin();} 182 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 183 1.1 joerg const_iterator cend() const _NOEXCEPT {return end();} 184 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 185 1.1 joerg const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} 186 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 187 1.1 joerg const_reverse_iterator crend() const _NOEXCEPT {return rend();} 188 1.1 joerg 189 1.1 joerg // capacity: 190 1.1 joerg _LIBCPP_INLINE_VISIBILITY 191 1.1 joerg _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;} 192 1.1 joerg _LIBCPP_INLINE_VISIBILITY 193 1.1 joerg _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;} 194 1.1 joerg _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 195 1.1 joerg _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;} 196 1.1 joerg 197 1.1 joerg // element access: 198 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 199 1.1 joerg reference operator[](size_type __n) _NOEXCEPT { 200 1.1 joerg _LIBCPP_ASSERT(__n < _Size, "out-of-bounds access in std::array<T, N>"); 201 1.1 joerg return __elems_[__n]; 202 1.1 joerg } 203 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 204 1.1 joerg const_reference operator[](size_type __n) const _NOEXCEPT { 205 1.1 joerg _LIBCPP_ASSERT(__n < _Size, "out-of-bounds access in std::array<T, N>"); 206 1.1 joerg return __elems_[__n]; 207 1.1 joerg } 208 1.1 joerg 209 1.1 joerg _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n) 210 1.1 joerg { 211 1.1 joerg if (__n >= _Size) 212 1.1 joerg __throw_out_of_range("array::at"); 213 1.1 joerg return __elems_[__n]; 214 1.1 joerg } 215 1.1 joerg 216 1.1 joerg _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const 217 1.1 joerg { 218 1.1 joerg if (__n >= _Size) 219 1.1 joerg __throw_out_of_range("array::at"); 220 1.1 joerg return __elems_[__n]; 221 1.1 joerg } 222 1.1 joerg 223 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() _NOEXCEPT {return (*this)[0];} 224 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const _NOEXCEPT {return (*this)[0];} 225 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() _NOEXCEPT {return (*this)[_Size - 1];} 226 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const _NOEXCEPT {return (*this)[_Size - 1];} 227 1.1 joerg 228 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 229 1.1 joerg value_type* data() _NOEXCEPT {return __elems_;} 230 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 231 1.1 joerg const value_type* data() const _NOEXCEPT {return __elems_;} 232 1.1 joerg }; 233 1.1 joerg 234 1.1 joerg template <class _Tp> 235 1.1 joerg struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> 236 1.1 joerg { 237 1.1 joerg // types: 238 1.1 joerg typedef array __self; 239 1.1 joerg typedef _Tp value_type; 240 1.1 joerg typedef value_type& reference; 241 1.1 joerg typedef const value_type& const_reference; 242 1.1 joerg typedef value_type* iterator; 243 1.1 joerg typedef const value_type* const_iterator; 244 1.1 joerg typedef value_type* pointer; 245 1.1 joerg typedef const value_type* const_pointer; 246 1.1 joerg typedef size_t size_type; 247 1.1 joerg typedef ptrdiff_t difference_type; 248 1.1 joerg typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 249 1.1 joerg typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 250 1.1 joerg 251 1.1 joerg typedef typename conditional<is_const<_Tp>::value, const char, 252 1.1 joerg char>::type _CharType; 253 1.1 joerg 254 1.1 joerg struct _ArrayInStructT { _Tp __data_[1]; }; 255 1.1 joerg _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)]; 256 1.1 joerg 257 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 258 1.1 joerg value_type* data() _NOEXCEPT {return nullptr;} 259 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 260 1.1 joerg const value_type* data() const _NOEXCEPT {return nullptr;} 261 1.1 joerg 262 1.1 joerg // No explicit construct/copy/destroy for aggregate type 263 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 264 1.1 joerg void fill(const value_type&) { 265 1.1 joerg static_assert(!is_const<_Tp>::value, 266 1.1 joerg "cannot fill zero-sized array of type 'const T'"); 267 1.1 joerg } 268 1.1 joerg 269 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 270 1.1 joerg void swap(array&) _NOEXCEPT { 271 1.1 joerg static_assert(!is_const<_Tp>::value, 272 1.1 joerg "cannot swap zero-sized array of type 'const T'"); 273 1.1 joerg } 274 1.1 joerg 275 1.1 joerg // iterators: 276 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 277 1.1 joerg iterator begin() _NOEXCEPT {return iterator(data());} 278 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 279 1.1 joerg const_iterator begin() const _NOEXCEPT {return const_iterator(data());} 280 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 281 1.1 joerg iterator end() _NOEXCEPT {return iterator(data());} 282 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 283 1.1 joerg const_iterator end() const _NOEXCEPT {return const_iterator(data());} 284 1.1 joerg 285 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 286 1.1 joerg reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} 287 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 288 1.1 joerg const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} 289 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 290 1.1 joerg reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} 291 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 292 1.1 joerg const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} 293 1.1 joerg 294 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 295 1.1 joerg const_iterator cbegin() const _NOEXCEPT {return begin();} 296 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 297 1.1 joerg const_iterator cend() const _NOEXCEPT {return end();} 298 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 299 1.1 joerg const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} 300 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 301 1.1 joerg const_reverse_iterator crend() const _NOEXCEPT {return rend();} 302 1.1 joerg 303 1.1 joerg // capacity: 304 1.1 joerg _LIBCPP_INLINE_VISIBILITY 305 1.1 joerg _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; } 306 1.1 joerg _LIBCPP_INLINE_VISIBILITY 307 1.1 joerg _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;} 308 1.1 joerg _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 309 1.1 joerg _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;} 310 1.1 joerg 311 1.1 joerg // element access: 312 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 313 1.1 joerg reference operator[](size_type) _NOEXCEPT { 314 1.1 joerg _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array"); 315 1.1 joerg _LIBCPP_UNREACHABLE(); 316 1.1 joerg } 317 1.1 joerg 318 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 319 1.1 joerg const_reference operator[](size_type) const _NOEXCEPT { 320 1.1 joerg _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array"); 321 1.1 joerg _LIBCPP_UNREACHABLE(); 322 1.1 joerg } 323 1.1 joerg 324 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 325 1.1 joerg reference at(size_type) { 326 1.1 joerg __throw_out_of_range("array<T, 0>::at"); 327 1.1 joerg _LIBCPP_UNREACHABLE(); 328 1.1 joerg } 329 1.1 joerg 330 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 331 1.1 joerg const_reference at(size_type) const { 332 1.1 joerg __throw_out_of_range("array<T, 0>::at"); 333 1.1 joerg _LIBCPP_UNREACHABLE(); 334 1.1 joerg } 335 1.1 joerg 336 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 337 1.1 joerg reference front() _NOEXCEPT { 338 1.1 joerg _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array"); 339 1.1 joerg _LIBCPP_UNREACHABLE(); 340 1.1 joerg } 341 1.1 joerg 342 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 343 1.1 joerg const_reference front() const _NOEXCEPT { 344 1.1 joerg _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array"); 345 1.1 joerg _LIBCPP_UNREACHABLE(); 346 1.1 joerg } 347 1.1 joerg 348 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 349 1.1 joerg reference back() _NOEXCEPT { 350 1.1 joerg _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array"); 351 1.1 joerg _LIBCPP_UNREACHABLE(); 352 1.1 joerg } 353 1.1 joerg 354 1.1 joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 355 1.1 joerg const_reference back() const _NOEXCEPT { 356 1.1 joerg _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array"); 357 1.1 joerg _LIBCPP_UNREACHABLE(); 358 1.1 joerg } 359 1.1 joerg }; 360 1.1 joerg 361 1.1 joerg 362 1.1 joerg #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 363 1.1 joerg template<class _Tp, class... _Args, 364 1.1 joerg class = _EnableIf<__all<_IsSame<_Tp, _Args>::value...>::value> 365 1.1 joerg > 366 1.1 joerg array(_Tp, _Args...) 367 1.1 joerg -> array<_Tp, 1 + sizeof...(_Args)>; 368 1.1 joerg #endif 369 1.1 joerg 370 1.1 joerg template <class _Tp, size_t _Size> 371 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY 372 1.1 joerg _LIBCPP_CONSTEXPR_AFTER_CXX17 bool 373 1.1 joerg operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 374 1.1 joerg { 375 1.1 joerg return _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 376 1.1 joerg } 377 1.1 joerg 378 1.1 joerg template <class _Tp, size_t _Size> 379 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY 380 1.1 joerg _LIBCPP_CONSTEXPR_AFTER_CXX17 bool 381 1.1 joerg operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 382 1.1 joerg { 383 1.1 joerg return !(__x == __y); 384 1.1 joerg } 385 1.1 joerg 386 1.1 joerg template <class _Tp, size_t _Size> 387 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY 388 1.1 joerg _LIBCPP_CONSTEXPR_AFTER_CXX17 bool 389 1.1 joerg operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 390 1.1 joerg { 391 1.1 joerg return _VSTD::lexicographical_compare(__x.begin(), __x.end(), 392 1.1 joerg __y.begin(), __y.end()); 393 1.1 joerg } 394 1.1 joerg 395 1.1 joerg template <class _Tp, size_t _Size> 396 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY 397 1.1 joerg _LIBCPP_CONSTEXPR_AFTER_CXX17 bool 398 1.1 joerg operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 399 1.1 joerg { 400 1.1 joerg return __y < __x; 401 1.1 joerg } 402 1.1 joerg 403 1.1 joerg template <class _Tp, size_t _Size> 404 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY 405 1.1 joerg _LIBCPP_CONSTEXPR_AFTER_CXX17 bool 406 1.1 joerg operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 407 1.1 joerg { 408 1.1 joerg return !(__y < __x); 409 1.1 joerg } 410 1.1 joerg 411 1.1 joerg template <class _Tp, size_t _Size> 412 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY 413 1.1 joerg _LIBCPP_CONSTEXPR_AFTER_CXX17 bool 414 1.1 joerg operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 415 1.1 joerg { 416 1.1 joerg return !(__x < __y); 417 1.1 joerg } 418 1.1 joerg 419 1.1 joerg template <class _Tp, size_t _Size> 420 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 421 1.1 joerg typename enable_if 422 1.1 joerg < 423 1.1 joerg _Size == 0 || 424 1.1 joerg __is_swappable<_Tp>::value, 425 1.1 joerg void 426 1.1 joerg >::type 427 1.1 joerg swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y) 428 1.1 joerg _NOEXCEPT_(noexcept(__x.swap(__y))) 429 1.1 joerg { 430 1.1 joerg __x.swap(__y); 431 1.1 joerg } 432 1.1 joerg 433 1.1 joerg template <class _Tp, size_t _Size> 434 1.1 joerg struct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> > 435 1.1 joerg : public integral_constant<size_t, _Size> {}; 436 1.1 joerg 437 1.1 joerg template <size_t _Ip, class _Tp, size_t _Size> 438 1.1 joerg struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > 439 1.1 joerg { 440 1.1 joerg static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)"); 441 1.1 joerg typedef _Tp type; 442 1.1 joerg }; 443 1.1 joerg 444 1.1 joerg template <size_t _Ip, class _Tp, size_t _Size> 445 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 446 1.1 joerg _Tp& 447 1.1 joerg get(array<_Tp, _Size>& __a) _NOEXCEPT 448 1.1 joerg { 449 1.1 joerg static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)"); 450 1.1 joerg return __a.__elems_[_Ip]; 451 1.1 joerg } 452 1.1 joerg 453 1.1 joerg template <size_t _Ip, class _Tp, size_t _Size> 454 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 455 1.1 joerg const _Tp& 456 1.1 joerg get(const array<_Tp, _Size>& __a) _NOEXCEPT 457 1.1 joerg { 458 1.1 joerg static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)"); 459 1.1 joerg return __a.__elems_[_Ip]; 460 1.1 joerg } 461 1.1 joerg 462 1.1 joerg template <size_t _Ip, class _Tp, size_t _Size> 463 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 464 1.1 joerg _Tp&& 465 1.1 joerg get(array<_Tp, _Size>&& __a) _NOEXCEPT 466 1.1 joerg { 467 1.1 joerg static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)"); 468 1.1 joerg return _VSTD::move(__a.__elems_[_Ip]); 469 1.1 joerg } 470 1.1 joerg 471 1.1 joerg template <size_t _Ip, class _Tp, size_t _Size> 472 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 473 1.1 joerg const _Tp&& 474 1.1 joerg get(const array<_Tp, _Size>&& __a) _NOEXCEPT 475 1.1 joerg { 476 1.1 joerg static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)"); 477 1.1 joerg return _VSTD::move(__a.__elems_[_Ip]); 478 1.1 joerg } 479 1.1 joerg 480 1.1 joerg #if _LIBCPP_STD_VER > 17 481 1.1 joerg 482 1.1 joerg template <typename _Tp, size_t _Size, size_t... _Index> 483 1.1 joerg _LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> 484 1.1 joerg __to_array_lvalue_impl(_Tp (&__arr)[_Size], index_sequence<_Index...>) { 485 1.1 joerg return {{__arr[_Index]...}}; 486 1.1 joerg } 487 1.1 joerg 488 1.1 joerg template <typename _Tp, size_t _Size, size_t... _Index> 489 1.1 joerg _LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> 490 1.1 joerg __to_array_rvalue_impl(_Tp(&&__arr)[_Size], index_sequence<_Index...>) { 491 1.1 joerg return {{_VSTD::move(__arr[_Index])...}}; 492 1.1 joerg } 493 1.1 joerg 494 1.1 joerg template <typename _Tp, size_t _Size> 495 1.1 joerg _LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> 496 1.1 joerg to_array(_Tp (&__arr)[_Size]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) { 497 1.1 joerg static_assert( 498 1.1 joerg !is_array_v<_Tp>, 499 1.1 joerg "[array.creation]/1: to_array does not accept multidimensional arrays."); 500 1.1 joerg static_assert( 501 1.1 joerg is_constructible_v<_Tp, _Tp&>, 502 1.1 joerg "[array.creation]/1: to_array requires copy constructible elements."); 503 1.1 joerg return _VSTD::__to_array_lvalue_impl(__arr, make_index_sequence<_Size>()); 504 1.1 joerg } 505 1.1 joerg 506 1.1 joerg template <typename _Tp, size_t _Size> 507 1.1 joerg _LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> 508 1.1 joerg to_array(_Tp(&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) { 509 1.1 joerg static_assert( 510 1.1 joerg !is_array_v<_Tp>, 511 1.1 joerg "[array.creation]/4: to_array does not accept multidimensional arrays."); 512 1.1 joerg static_assert( 513 1.1 joerg is_move_constructible_v<_Tp>, 514 1.1 joerg "[array.creation]/4: to_array requires move constructible elements."); 515 1.1 joerg return _VSTD::__to_array_rvalue_impl(_VSTD::move(__arr), 516 1.1 joerg make_index_sequence<_Size>()); 517 1.1 joerg } 518 1.1 joerg 519 1.1 joerg #endif // _LIBCPP_STD_VER > 17 520 1.1 joerg 521 1.1 joerg _LIBCPP_END_NAMESPACE_STD 522 1.1 joerg 523 1.1 joerg #endif // _LIBCPP_ARRAY 524