17a984708SDavid Chisnall// -*- C++ -*- 27a984708SDavid Chisnall//===---------------------------- array -----------------------------------===// 37a984708SDavid Chisnall// 47a984708SDavid Chisnall// The LLVM Compiler Infrastructure 57a984708SDavid Chisnall// 67a984708SDavid Chisnall// This file is dual licensed under the MIT and the University of Illinois Open 77a984708SDavid Chisnall// Source Licenses. See LICENSE.TXT for details. 87a984708SDavid Chisnall// 97a984708SDavid Chisnall//===----------------------------------------------------------------------===// 107a984708SDavid Chisnall 117a984708SDavid Chisnall#ifndef _LIBCPP_ARRAY 127a984708SDavid Chisnall#define _LIBCPP_ARRAY 137a984708SDavid Chisnall 147a984708SDavid Chisnall/* 157a984708SDavid Chisnall array synopsis 167a984708SDavid Chisnall 177a984708SDavid Chisnallnamespace std 187a984708SDavid Chisnall{ 197a984708SDavid Chisnalltemplate <class T, size_t N > 207a984708SDavid Chisnallstruct array 217a984708SDavid Chisnall{ 227a984708SDavid Chisnall // types: 237a984708SDavid Chisnall typedef T & reference; 247a984708SDavid Chisnall typedef const T & const_reference; 257a984708SDavid Chisnall typedef implementation defined iterator; 267a984708SDavid Chisnall typedef implementation defined const_iterator; 277a984708SDavid Chisnall typedef size_t size_type; 287a984708SDavid Chisnall typedef ptrdiff_t difference_type; 297a984708SDavid Chisnall typedef T value_type; 307a984708SDavid Chisnall typedef T* pointer; 317a984708SDavid Chisnall typedef const T* const_pointer; 327a984708SDavid Chisnall typedef std::reverse_iterator<iterator> reverse_iterator; 337a984708SDavid Chisnall typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 347a984708SDavid Chisnall 357a984708SDavid Chisnall // No explicit construct/copy/destroy for aggregate type 367a984708SDavid Chisnall void fill(const T& u); 377c82a1ecSDimitry Andric void swap(array& a) noexcept(is_nothrow_swappable_v<T>); 387a984708SDavid Chisnall 397a984708SDavid Chisnall // iterators: 407a984708SDavid Chisnall iterator begin() noexcept; 417a984708SDavid Chisnall const_iterator begin() const noexcept; 427a984708SDavid Chisnall iterator end() noexcept; 437a984708SDavid Chisnall const_iterator end() const noexcept; 447a984708SDavid Chisnall 457a984708SDavid Chisnall reverse_iterator rbegin() noexcept; 467a984708SDavid Chisnall const_reverse_iterator rbegin() const noexcept; 477a984708SDavid Chisnall reverse_iterator rend() noexcept; 487a984708SDavid Chisnall const_reverse_iterator rend() const noexcept; 497a984708SDavid Chisnall 507a984708SDavid Chisnall const_iterator cbegin() const noexcept; 517a984708SDavid Chisnall const_iterator cend() const noexcept; 527a984708SDavid Chisnall const_reverse_iterator crbegin() const noexcept; 537a984708SDavid Chisnall const_reverse_iterator crend() const noexcept; 547a984708SDavid Chisnall 557a984708SDavid Chisnall // capacity: 567a984708SDavid Chisnall constexpr size_type size() const noexcept; 577a984708SDavid Chisnall constexpr size_type max_size() const noexcept; 58936e9439SDimitry Andric constexpr bool empty() const noexcept; 597a984708SDavid Chisnall 607a984708SDavid Chisnall // element access: 617a984708SDavid Chisnall reference operator[](size_type n); 624f7ab58eSDimitry Andric const_reference operator[](size_type n) const; // constexpr in C++14 634f7ab58eSDimitry Andric const_reference at(size_type n) const; // constexpr in C++14 647a984708SDavid Chisnall reference at(size_type n); 657a984708SDavid Chisnall 667a984708SDavid Chisnall reference front(); 674f7ab58eSDimitry Andric const_reference front() const; // constexpr in C++14 687a984708SDavid Chisnall reference back(); 694f7ab58eSDimitry Andric const_reference back() const; // constexpr in C++14 707a984708SDavid Chisnall 717a984708SDavid Chisnall T* data() noexcept; 727a984708SDavid Chisnall const T* data() const noexcept; 737a984708SDavid Chisnall}; 747a984708SDavid Chisnall 754ba319b5SDimitry Andric template <class T, class... U> 764ba319b5SDimitry Andric array(T, U...) -> array<T, 1 + sizeof...(U)>; 774ba319b5SDimitry Andric 787a984708SDavid Chisnalltemplate <class T, size_t N> 797a984708SDavid Chisnall bool operator==(const array<T,N>& x, const array<T,N>& y); 807a984708SDavid Chisnalltemplate <class T, size_t N> 817a984708SDavid Chisnall bool operator!=(const array<T,N>& x, const array<T,N>& y); 827a984708SDavid Chisnalltemplate <class T, size_t N> 837a984708SDavid Chisnall bool operator<(const array<T,N>& x, const array<T,N>& y); 847a984708SDavid Chisnalltemplate <class T, size_t N> 857a984708SDavid Chisnall bool operator>(const array<T,N>& x, const array<T,N>& y); 867a984708SDavid Chisnalltemplate <class T, size_t N> 877a984708SDavid Chisnall bool operator<=(const array<T,N>& x, const array<T,N>& y); 887a984708SDavid Chisnalltemplate <class T, size_t N> 897a984708SDavid Chisnall bool operator>=(const array<T,N>& x, const array<T,N>& y); 907a984708SDavid Chisnall 917a984708SDavid Chisnalltemplate <class T, size_t N > 924ba319b5SDimitry Andric void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // C++17 937a984708SDavid Chisnall 94*b5893f02SDimitry Andrictemplate <class T> struct tuple_size; 959729cf09SDimitry Andrictemplate <size_t I, class T> class tuple_element; 967a984708SDavid Chisnalltemplate <class T, size_t N> struct tuple_size<array<T, N>>; 979729cf09SDimitry Andrictemplate <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>; 989729cf09SDimitry Andrictemplate <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14 999729cf09SDimitry Andrictemplate <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14 1009729cf09SDimitry Andrictemplate <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14 1019729cf09SDimitry Andrictemplate <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14 1027a984708SDavid Chisnall 1037a984708SDavid Chisnall} // std 1047a984708SDavid Chisnall 1057a984708SDavid Chisnall*/ 1067a984708SDavid Chisnall 1077a984708SDavid Chisnall#include <__config> 1087a984708SDavid Chisnall#include <__tuple> 1097a984708SDavid Chisnall#include <type_traits> 1107a984708SDavid Chisnall#include <utility> 1117a984708SDavid Chisnall#include <iterator> 1127a984708SDavid Chisnall#include <algorithm> 1137a984708SDavid Chisnall#include <stdexcept> 1144ba319b5SDimitry Andric#include <cstdlib> // for _LIBCPP_UNREACHABLE 115*b5893f02SDimitry Andric#include <version> 1164ba319b5SDimitry Andric#include <__debug> 1177a984708SDavid Chisnall 1187a984708SDavid Chisnall#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1197a984708SDavid Chisnall#pragma GCC system_header 1207a984708SDavid Chisnall#endif 1217a984708SDavid Chisnall 122f9448bf3SDimitry Andric 123f9448bf3SDimitry Andric 1247a984708SDavid Chisnall_LIBCPP_BEGIN_NAMESPACE_STD 1257a984708SDavid Chisnall 1264ba319b5SDimitry Andric 1277a984708SDavid Chisnalltemplate <class _Tp, size_t _Size> 128aed8d94eSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS array 1297a984708SDavid Chisnall{ 1307a984708SDavid Chisnall // types: 1317a984708SDavid Chisnall typedef array __self; 1327a984708SDavid Chisnall typedef _Tp value_type; 1337a984708SDavid Chisnall typedef value_type& reference; 1347a984708SDavid Chisnall typedef const value_type& const_reference; 1357a984708SDavid Chisnall typedef value_type* iterator; 1367a984708SDavid Chisnall typedef const value_type* const_iterator; 1377a984708SDavid Chisnall typedef value_type* pointer; 1387a984708SDavid Chisnall typedef const value_type* const_pointer; 1397a984708SDavid Chisnall typedef size_t size_type; 1407a984708SDavid Chisnall typedef ptrdiff_t difference_type; 1417a984708SDavid Chisnall typedef std::reverse_iterator<iterator> reverse_iterator; 1427a984708SDavid Chisnall typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 1437a984708SDavid Chisnall 1444ba319b5SDimitry Andric _Tp __elems_[_Size]; 1457a984708SDavid Chisnall 1467a984708SDavid Chisnall // No explicit construct/copy/destroy for aggregate type 1474ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) { 1484ba319b5SDimitry Andric _VSTD::fill_n(__elems_, _Size, __u); 1494ba319b5SDimitry Andric } 1507c82a1ecSDimitry Andric 1517c82a1ecSDimitry Andric _LIBCPP_INLINE_VISIBILITY 1524ba319b5SDimitry Andric void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) { 1534ba319b5SDimitry Andric std::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_); 1544ba319b5SDimitry Andric } 1557a984708SDavid Chisnall 1567a984708SDavid Chisnall // iterators: 157aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1584ba319b5SDimitry Andric iterator begin() _NOEXCEPT {return iterator(data());} 159aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1604ba319b5SDimitry Andric const_iterator begin() const _NOEXCEPT {return const_iterator(data());} 161aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1624ba319b5SDimitry Andric iterator end() _NOEXCEPT {return iterator(data() + _Size);} 163aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1644ba319b5SDimitry Andric const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);} 1657a984708SDavid Chisnall 166aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1677a984708SDavid Chisnall reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} 168aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1697a984708SDavid Chisnall const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} 170aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1717a984708SDavid Chisnall reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} 172aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1737a984708SDavid Chisnall const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} 1747a984708SDavid Chisnall 175aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1767a984708SDavid Chisnall const_iterator cbegin() const _NOEXCEPT {return begin();} 177aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1787a984708SDavid Chisnall const_iterator cend() const _NOEXCEPT {return end();} 179aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1807a984708SDavid Chisnall const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} 181aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1827a984708SDavid Chisnall const_reverse_iterator crend() const _NOEXCEPT {return rend();} 1837a984708SDavid Chisnall 1847a984708SDavid Chisnall // capacity: 1857a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 186936e9439SDimitry Andric _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;} 1877a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 188936e9439SDimitry Andric _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;} 189b2c7081bSDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 1904ba319b5SDimitry Andric _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return false; } 1917a984708SDavid Chisnall 1927a984708SDavid Chisnall // element access: 193daf78e69SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 194daf78e69SDimitry Andric reference operator[](size_type __n) {return __elems_[__n];} 195daf78e69SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 196daf78e69SDimitry Andric const_reference operator[](size_type __n) const {return __elems_[__n];} 197daf78e69SDimitry Andric 198daf78e69SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n); 1994f7ab58eSDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const; 2007a984708SDavid Chisnall 201daf78e69SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() {return __elems_[0];} 2024f7ab58eSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const {return __elems_[0];} 2034ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() {return __elems_[_Size - 1];} 2044ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const {return __elems_[_Size - 1];} 2057a984708SDavid Chisnall 206aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 2077a984708SDavid Chisnall value_type* data() _NOEXCEPT {return __elems_;} 208aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 2097a984708SDavid Chisnall const value_type* data() const _NOEXCEPT {return __elems_;} 2107a984708SDavid Chisnall}; 2117a984708SDavid Chisnall 2124ba319b5SDimitry Andric 2137a984708SDavid Chisnalltemplate <class _Tp, size_t _Size> 214daf78e69SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX14 2157a984708SDavid Chisnalltypename array<_Tp, _Size>::reference 2167a984708SDavid Chisnallarray<_Tp, _Size>::at(size_type __n) 2177a984708SDavid Chisnall{ 2187a984708SDavid Chisnall if (__n >= _Size) 219aed8d94eSDimitry Andric __throw_out_of_range("array::at"); 220aed8d94eSDimitry Andric 2217a984708SDavid Chisnall return __elems_[__n]; 2227a984708SDavid Chisnall} 2237a984708SDavid Chisnall 2247a984708SDavid Chisnalltemplate <class _Tp, size_t _Size> 2254f7ab58eSDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 2267a984708SDavid Chisnalltypename array<_Tp, _Size>::const_reference 2277a984708SDavid Chisnallarray<_Tp, _Size>::at(size_type __n) const 2287a984708SDavid Chisnall{ 2297a984708SDavid Chisnall if (__n >= _Size) 230aed8d94eSDimitry Andric __throw_out_of_range("array::at"); 2317a984708SDavid Chisnall return __elems_[__n]; 2327a984708SDavid Chisnall} 2337a984708SDavid Chisnall 2344ba319b5SDimitry Andrictemplate <class _Tp> 2354ba319b5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> 2364ba319b5SDimitry Andric{ 2374ba319b5SDimitry Andric // types: 2384ba319b5SDimitry Andric typedef array __self; 2394ba319b5SDimitry Andric typedef _Tp value_type; 2404ba319b5SDimitry Andric typedef value_type& reference; 2414ba319b5SDimitry Andric typedef const value_type& const_reference; 2424ba319b5SDimitry Andric typedef value_type* iterator; 2434ba319b5SDimitry Andric typedef const value_type* const_iterator; 2444ba319b5SDimitry Andric typedef value_type* pointer; 2454ba319b5SDimitry Andric typedef const value_type* const_pointer; 2464ba319b5SDimitry Andric typedef size_t size_type; 2474ba319b5SDimitry Andric typedef ptrdiff_t difference_type; 2484ba319b5SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 2494ba319b5SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 2504ba319b5SDimitry Andric 2514ba319b5SDimitry Andric typedef typename conditional<is_const<_Tp>::value, const char, 2524ba319b5SDimitry Andric char>::type _CharType; 2534ba319b5SDimitry Andric 2544ba319b5SDimitry Andric struct _ArrayInStructT { _Tp __data_[1]; }; 2554ba319b5SDimitry Andric _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)]; 2564ba319b5SDimitry Andric 2574ba319b5SDimitry Andric // No explicit construct/copy/destroy for aggregate type 2584ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void fill(const value_type&) { 2594ba319b5SDimitry Andric static_assert(!is_const<_Tp>::value, 2604ba319b5SDimitry Andric "cannot fill zero-sized array of type 'const T'"); 2614ba319b5SDimitry Andric } 2624ba319b5SDimitry Andric 2634ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2644ba319b5SDimitry Andric void swap(array&) _NOEXCEPT { 2654ba319b5SDimitry Andric static_assert(!is_const<_Tp>::value, 2664ba319b5SDimitry Andric "cannot swap zero-sized array of type 'const T'"); 2674ba319b5SDimitry Andric } 2684ba319b5SDimitry Andric 2694ba319b5SDimitry Andric // iterators: 2704ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2714ba319b5SDimitry Andric iterator begin() _NOEXCEPT {return iterator(data());} 2724ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2734ba319b5SDimitry Andric const_iterator begin() const _NOEXCEPT {return const_iterator(data());} 2744ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2754ba319b5SDimitry Andric iterator end() _NOEXCEPT {return iterator(data());} 2764ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2774ba319b5SDimitry Andric const_iterator end() const _NOEXCEPT {return const_iterator(data());} 2784ba319b5SDimitry Andric 2794ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2804ba319b5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} 2814ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2824ba319b5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} 2834ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2844ba319b5SDimitry Andric reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} 2854ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2864ba319b5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} 2874ba319b5SDimitry Andric 2884ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2894ba319b5SDimitry Andric const_iterator cbegin() const _NOEXCEPT {return begin();} 2904ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2914ba319b5SDimitry Andric const_iterator cend() const _NOEXCEPT {return end();} 2924ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2934ba319b5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} 2944ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2954ba319b5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT {return rend();} 2964ba319b5SDimitry Andric 2974ba319b5SDimitry Andric // capacity: 2984ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2994ba319b5SDimitry Andric _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; } 3004ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3014ba319b5SDimitry Andric _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;} 3024ba319b5SDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 3034ba319b5SDimitry Andric _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;} 3044ba319b5SDimitry Andric 3054ba319b5SDimitry Andric // element access: 3064ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3074ba319b5SDimitry Andric reference operator[](size_type) { 3084ba319b5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array"); 3094ba319b5SDimitry Andric _LIBCPP_UNREACHABLE(); 3104ba319b5SDimitry Andric } 3114ba319b5SDimitry Andric 3124ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 3134ba319b5SDimitry Andric const_reference operator[](size_type) const { 3144ba319b5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array"); 3154ba319b5SDimitry Andric _LIBCPP_UNREACHABLE(); 3164ba319b5SDimitry Andric } 3174ba319b5SDimitry Andric 3184ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3194ba319b5SDimitry Andric reference at(size_type) { 3204ba319b5SDimitry Andric __throw_out_of_range("array<T, 0>::at"); 3214ba319b5SDimitry Andric _LIBCPP_UNREACHABLE(); 3224ba319b5SDimitry Andric } 3234ba319b5SDimitry Andric 3244ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3254ba319b5SDimitry Andric const_reference at(size_type) const { 3264ba319b5SDimitry Andric __throw_out_of_range("array<T, 0>::at"); 3274ba319b5SDimitry Andric _LIBCPP_UNREACHABLE(); 3284ba319b5SDimitry Andric } 3294ba319b5SDimitry Andric 3304ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3314ba319b5SDimitry Andric reference front() { 3324ba319b5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array"); 3334ba319b5SDimitry Andric _LIBCPP_UNREACHABLE(); 3344ba319b5SDimitry Andric } 3354ba319b5SDimitry Andric 3364ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3374ba319b5SDimitry Andric const_reference front() const { 3384ba319b5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array"); 3394ba319b5SDimitry Andric _LIBCPP_UNREACHABLE(); 3404ba319b5SDimitry Andric } 3414ba319b5SDimitry Andric 3424ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3434ba319b5SDimitry Andric reference back() { 3444ba319b5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array"); 3454ba319b5SDimitry Andric _LIBCPP_UNREACHABLE(); 3464ba319b5SDimitry Andric } 3474ba319b5SDimitry Andric 3484ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3494ba319b5SDimitry Andric const_reference back() const { 3504ba319b5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array"); 3514ba319b5SDimitry Andric _LIBCPP_UNREACHABLE(); 3524ba319b5SDimitry Andric } 3534ba319b5SDimitry Andric 3544ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3554ba319b5SDimitry Andric value_type* data() _NOEXCEPT {return reinterpret_cast<value_type*>(__elems_);} 3564ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3574ba319b5SDimitry Andric const value_type* data() const _NOEXCEPT {return reinterpret_cast<const value_type*>(__elems_);} 3584ba319b5SDimitry Andric}; 3594ba319b5SDimitry Andric 3604ba319b5SDimitry Andric 3614ba319b5SDimitry Andric#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 3624ba319b5SDimitry Andrictemplate<class _Tp, class... _Args, 3634ba319b5SDimitry Andric class = typename enable_if<(is_same_v<_Tp, _Args> && ...), void>::type 3644ba319b5SDimitry Andric > 3654ba319b5SDimitry Andricarray(_Tp, _Args...) 3664ba319b5SDimitry Andric -> array<_Tp, 1 + sizeof...(_Args)>; 3674ba319b5SDimitry Andric#endif 3684ba319b5SDimitry Andric 3697a984708SDavid Chisnalltemplate <class _Tp, size_t _Size> 3704f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 371*b5893f02SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 3727a984708SDavid Chisnalloperator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 3737a984708SDavid Chisnall{ 3744ba319b5SDimitry Andric return _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 3757a984708SDavid Chisnall} 3767a984708SDavid Chisnall 3777a984708SDavid Chisnalltemplate <class _Tp, size_t _Size> 3784f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 379*b5893f02SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 3807a984708SDavid Chisnalloperator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 3817a984708SDavid Chisnall{ 3827a984708SDavid Chisnall return !(__x == __y); 3837a984708SDavid Chisnall} 3847a984708SDavid Chisnall 3857a984708SDavid Chisnalltemplate <class _Tp, size_t _Size> 3864f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 387*b5893f02SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 3887a984708SDavid Chisnalloperator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 3897a984708SDavid Chisnall{ 3904ba319b5SDimitry Andric return _VSTD::lexicographical_compare(__x.begin(), __x.end(), 3914ba319b5SDimitry Andric __y.begin(), __y.end()); 3927a984708SDavid Chisnall} 3937a984708SDavid Chisnall 3947a984708SDavid Chisnalltemplate <class _Tp, size_t _Size> 3954f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 396*b5893f02SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 3977a984708SDavid Chisnalloperator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 3987a984708SDavid Chisnall{ 3997a984708SDavid Chisnall return __y < __x; 4007a984708SDavid Chisnall} 4017a984708SDavid Chisnall 4027a984708SDavid Chisnalltemplate <class _Tp, size_t _Size> 4034f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 404*b5893f02SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 4057a984708SDavid Chisnalloperator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 4067a984708SDavid Chisnall{ 4077a984708SDavid Chisnall return !(__y < __x); 4087a984708SDavid Chisnall} 4097a984708SDavid Chisnall 4107a984708SDavid Chisnalltemplate <class _Tp, size_t _Size> 4114f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 412*b5893f02SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 4137a984708SDavid Chisnalloperator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 4147a984708SDavid Chisnall{ 4157a984708SDavid Chisnall return !(__x < __y); 4167a984708SDavid Chisnall} 4177a984708SDavid Chisnall 4187a984708SDavid Chisnalltemplate <class _Tp, size_t _Size> 4194f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4207a984708SDavid Chisnalltypename enable_if 4217a984708SDavid Chisnall< 4227c82a1ecSDimitry Andric _Size == 0 || 4237a984708SDavid Chisnall __is_swappable<_Tp>::value, 4247a984708SDavid Chisnall void 4257a984708SDavid Chisnall>::type 4267c82a1ecSDimitry Andricswap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y) 4277c82a1ecSDimitry Andric _NOEXCEPT_(noexcept(__x.swap(__y))) 4287a984708SDavid Chisnall{ 4297a984708SDavid Chisnall __x.swap(__y); 4307a984708SDavid Chisnall} 4317a984708SDavid Chisnall 4327a984708SDavid Chisnalltemplate <class _Tp, size_t _Size> 433*b5893f02SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> > 4347a984708SDavid Chisnall : public integral_constant<size_t, _Size> {}; 4357a984708SDavid Chisnall 4367a984708SDavid Chisnalltemplate <size_t _Ip, class _Tp, size_t _Size> 437aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > 4387a984708SDavid Chisnall{ 43924d58133SDimitry Andric static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)"); 4407a984708SDavid Chisnallpublic: 4417a984708SDavid Chisnall typedef _Tp type; 4427a984708SDavid Chisnall}; 4437a984708SDavid Chisnall 4447a984708SDavid Chisnalltemplate <size_t _Ip, class _Tp, size_t _Size> 4454f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4467a984708SDavid Chisnall_Tp& 4477a984708SDavid Chisnallget(array<_Tp, _Size>& __a) _NOEXCEPT 4487a984708SDavid Chisnall{ 449cfdf2879SDavid Chisnall static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)"); 4504f7ab58eSDimitry Andric return __a.__elems_[_Ip]; 4517a984708SDavid Chisnall} 4527a984708SDavid Chisnall 4537a984708SDavid Chisnalltemplate <size_t _Ip, class _Tp, size_t _Size> 4544f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4557a984708SDavid Chisnallconst _Tp& 4567a984708SDavid Chisnallget(const array<_Tp, _Size>& __a) _NOEXCEPT 4577a984708SDavid Chisnall{ 458cfdf2879SDavid Chisnall static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)"); 4594f7ab58eSDimitry Andric return __a.__elems_[_Ip]; 4607a984708SDavid Chisnall} 4617a984708SDavid Chisnall 462540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 4637a984708SDavid Chisnall 4647a984708SDavid Chisnalltemplate <size_t _Ip, class _Tp, size_t _Size> 4654f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4667a984708SDavid Chisnall_Tp&& 4677a984708SDavid Chisnallget(array<_Tp, _Size>&& __a) _NOEXCEPT 4687a984708SDavid Chisnall{ 469cfdf2879SDavid Chisnall static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)"); 4704f7ab58eSDimitry Andric return _VSTD::move(__a.__elems_[_Ip]); 4717a984708SDavid Chisnall} 4727a984708SDavid Chisnall 4739729cf09SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size> 4749729cf09SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4759729cf09SDimitry Andricconst _Tp&& 4769729cf09SDimitry Andricget(const array<_Tp, _Size>&& __a) _NOEXCEPT 4779729cf09SDimitry Andric{ 4789729cf09SDimitry Andric static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)"); 4799729cf09SDimitry Andric return _VSTD::move(__a.__elems_[_Ip]); 4809729cf09SDimitry Andric} 4819729cf09SDimitry Andric 482540d2a8bSDimitry Andric#endif // !_LIBCPP_CXX03_LANG 4837a984708SDavid Chisnall 4847a984708SDavid Chisnall_LIBCPP_END_NAMESPACE_STD 4857a984708SDavid Chisnall 4867a984708SDavid Chisnall#endif // _LIBCPP_ARRAY 487