1*0b57cec5SDimitry Andric// -*- C++ -*- 2*0b57cec5SDimitry Andric//===---------------------------- array -----------------------------------===// 3*0b57cec5SDimitry Andric// 4*0b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5*0b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 6*0b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7*0b57cec5SDimitry Andric// 8*0b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 9*0b57cec5SDimitry Andric 10*0b57cec5SDimitry Andric#ifndef _LIBCPP_ARRAY 11*0b57cec5SDimitry Andric#define _LIBCPP_ARRAY 12*0b57cec5SDimitry Andric 13*0b57cec5SDimitry Andric/* 14*0b57cec5SDimitry Andric array synopsis 15*0b57cec5SDimitry Andric 16*0b57cec5SDimitry Andricnamespace std 17*0b57cec5SDimitry Andric{ 18*0b57cec5SDimitry Andrictemplate <class T, size_t N > 19*0b57cec5SDimitry Andricstruct array 20*0b57cec5SDimitry Andric{ 21*0b57cec5SDimitry Andric // types: 22*0b57cec5SDimitry Andric typedef T & reference; 23*0b57cec5SDimitry Andric typedef const T & const_reference; 24*0b57cec5SDimitry Andric typedef implementation defined iterator; 25*0b57cec5SDimitry Andric typedef implementation defined const_iterator; 26*0b57cec5SDimitry Andric typedef size_t size_type; 27*0b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 28*0b57cec5SDimitry Andric typedef T value_type; 29*0b57cec5SDimitry Andric typedef T* pointer; 30*0b57cec5SDimitry Andric typedef const T* const_pointer; 31*0b57cec5SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 32*0b57cec5SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 33*0b57cec5SDimitry Andric 34*0b57cec5SDimitry Andric // No explicit construct/copy/destroy for aggregate type 355ffd83dbSDimitry Andric void fill(const T& u); // constexpr in C++20 365ffd83dbSDimitry Andric void swap(array& a) noexcept(is_nothrow_swappable_v<T>); // constexpr in C++20 37*0b57cec5SDimitry Andric 38*0b57cec5SDimitry Andric // iterators: 395ffd83dbSDimitry Andric iterator begin() noexcept; // constexpr in C++17 405ffd83dbSDimitry Andric const_iterator begin() const noexcept; // constexpr in C++17 415ffd83dbSDimitry Andric iterator end() noexcept; // constexpr in C++17 425ffd83dbSDimitry Andric const_iterator end() const noexcept; // constexpr in C++17 43*0b57cec5SDimitry Andric 445ffd83dbSDimitry Andric reverse_iterator rbegin() noexcept; // constexpr in C++17 455ffd83dbSDimitry Andric const_reverse_iterator rbegin() const noexcept; // constexpr in C++17 465ffd83dbSDimitry Andric reverse_iterator rend() noexcept; // constexpr in C++17 475ffd83dbSDimitry Andric const_reverse_iterator rend() const noexcept; // constexpr in C++17 48*0b57cec5SDimitry Andric 495ffd83dbSDimitry Andric const_iterator cbegin() const noexcept; // constexpr in C++17 505ffd83dbSDimitry Andric const_iterator cend() const noexcept; // constexpr in C++17 515ffd83dbSDimitry Andric const_reverse_iterator crbegin() const noexcept; // constexpr in C++17 525ffd83dbSDimitry Andric const_reverse_iterator crend() const noexcept; // constexpr in C++17 53*0b57cec5SDimitry Andric 54*0b57cec5SDimitry Andric // capacity: 55*0b57cec5SDimitry Andric constexpr size_type size() const noexcept; 56*0b57cec5SDimitry Andric constexpr size_type max_size() const noexcept; 57*0b57cec5SDimitry Andric constexpr bool empty() const noexcept; 58*0b57cec5SDimitry Andric 59*0b57cec5SDimitry Andric // element access: 605ffd83dbSDimitry Andric reference operator[](size_type n); // constexpr in C++17 61*0b57cec5SDimitry Andric const_reference operator[](size_type n) const; // constexpr in C++14 625ffd83dbSDimitry Andric reference at(size_type n); // constexpr in C++17 63*0b57cec5SDimitry Andric const_reference at(size_type n) const; // constexpr in C++14 64*0b57cec5SDimitry Andric 655ffd83dbSDimitry Andric reference front(); // constexpr in C++17 66*0b57cec5SDimitry Andric const_reference front() const; // constexpr in C++14 675ffd83dbSDimitry Andric reference back(); // constexpr in C++17 68*0b57cec5SDimitry Andric const_reference back() const; // constexpr in C++14 69*0b57cec5SDimitry Andric 705ffd83dbSDimitry Andric T* data() noexcept; // constexpr in C++17 715ffd83dbSDimitry Andric const T* data() const noexcept; // constexpr in C++17 72*0b57cec5SDimitry Andric}; 73*0b57cec5SDimitry Andric 74*0b57cec5SDimitry Andrictemplate <class T, class... U> 755ffd83dbSDimitry Andric array(T, U...) -> array<T, 1 + sizeof...(U)>; // C++17 76*0b57cec5SDimitry Andric 77*0b57cec5SDimitry Andrictemplate <class T, size_t N> 785ffd83dbSDimitry Andric bool operator==(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 79*0b57cec5SDimitry Andrictemplate <class T, size_t N> 805ffd83dbSDimitry Andric bool operator!=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 81*0b57cec5SDimitry Andrictemplate <class T, size_t N> 825ffd83dbSDimitry Andric bool operator<(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 83*0b57cec5SDimitry Andrictemplate <class T, size_t N> 845ffd83dbSDimitry Andric bool operator>(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 85*0b57cec5SDimitry Andrictemplate <class T, size_t N> 865ffd83dbSDimitry Andric bool operator<=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 87*0b57cec5SDimitry Andrictemplate <class T, size_t N> 885ffd83dbSDimitry Andric bool operator>=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 89*0b57cec5SDimitry Andric 90*0b57cec5SDimitry Andrictemplate <class T, size_t N > 915ffd83dbSDimitry Andric void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20 925ffd83dbSDimitry Andric 935ffd83dbSDimitry Andrictemplate <class T, size_t N> 945ffd83dbSDimitry Andric constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]); // C++20 955ffd83dbSDimitry Andrictemplate <class T, size_t N> 965ffd83dbSDimitry Andric constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]); // C++20 97*0b57cec5SDimitry Andric 98*0b57cec5SDimitry Andrictemplate <class T> struct tuple_size; 99*0b57cec5SDimitry Andrictemplate <size_t I, class T> struct tuple_element; 100*0b57cec5SDimitry Andrictemplate <class T, size_t N> struct tuple_size<array<T, N>>; 101*0b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>; 102*0b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14 103*0b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14 104*0b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14 105*0b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14 106*0b57cec5SDimitry Andric 107*0b57cec5SDimitry Andric} // std 108*0b57cec5SDimitry Andric 109*0b57cec5SDimitry Andric*/ 110*0b57cec5SDimitry Andric 111*0b57cec5SDimitry Andric#include <__config> 112*0b57cec5SDimitry Andric#include <__tuple> 113*0b57cec5SDimitry Andric#include <type_traits> 114*0b57cec5SDimitry Andric#include <utility> 115*0b57cec5SDimitry Andric#include <iterator> 116*0b57cec5SDimitry Andric#include <algorithm> 117*0b57cec5SDimitry Andric#include <stdexcept> 118*0b57cec5SDimitry Andric#include <cstdlib> // for _LIBCPP_UNREACHABLE 119*0b57cec5SDimitry Andric#include <version> 120*0b57cec5SDimitry Andric#include <__debug> 121*0b57cec5SDimitry Andric 122*0b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 123*0b57cec5SDimitry Andric#pragma GCC system_header 124*0b57cec5SDimitry Andric#endif 125*0b57cec5SDimitry Andric 126*0b57cec5SDimitry Andric 127*0b57cec5SDimitry Andric 128*0b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 129*0b57cec5SDimitry Andric 130*0b57cec5SDimitry Andric 131*0b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 132*0b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS array 133*0b57cec5SDimitry Andric{ 134*0b57cec5SDimitry Andric // types: 135*0b57cec5SDimitry Andric typedef array __self; 136*0b57cec5SDimitry Andric typedef _Tp value_type; 137*0b57cec5SDimitry Andric typedef value_type& reference; 138*0b57cec5SDimitry Andric typedef const value_type& const_reference; 139*0b57cec5SDimitry Andric typedef value_type* iterator; 140*0b57cec5SDimitry Andric typedef const value_type* const_iterator; 141*0b57cec5SDimitry Andric typedef value_type* pointer; 142*0b57cec5SDimitry Andric typedef const value_type* const_pointer; 143*0b57cec5SDimitry Andric typedef size_t size_type; 144*0b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 145*0b57cec5SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 146*0b57cec5SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 147*0b57cec5SDimitry Andric 148*0b57cec5SDimitry Andric _Tp __elems_[_Size]; 149*0b57cec5SDimitry Andric 150*0b57cec5SDimitry Andric // No explicit construct/copy/destroy for aggregate type 1515ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1525ffd83dbSDimitry Andric void fill(const value_type& __u) { 1535ffd83dbSDimitry Andric _VSTD::fill_n(data(), _Size, __u); 154*0b57cec5SDimitry Andric } 155*0b57cec5SDimitry Andric 1565ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 157*0b57cec5SDimitry Andric void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) { 1585ffd83dbSDimitry Andric std::swap_ranges(data(), data() + _Size, __a.data()); 159*0b57cec5SDimitry Andric } 160*0b57cec5SDimitry Andric 161*0b57cec5SDimitry Andric // iterators: 162*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 163*0b57cec5SDimitry Andric iterator begin() _NOEXCEPT {return iterator(data());} 164*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 165*0b57cec5SDimitry Andric const_iterator begin() const _NOEXCEPT {return const_iterator(data());} 166*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 167*0b57cec5SDimitry Andric iterator end() _NOEXCEPT {return iterator(data() + _Size);} 168*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 169*0b57cec5SDimitry Andric const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);} 170*0b57cec5SDimitry Andric 171*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 172*0b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} 173*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 174*0b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} 175*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 176*0b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} 177*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 178*0b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} 179*0b57cec5SDimitry Andric 180*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 181*0b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT {return begin();} 182*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 183*0b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT {return end();} 184*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 185*0b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} 186*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 187*0b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT {return rend();} 188*0b57cec5SDimitry Andric 189*0b57cec5SDimitry Andric // capacity: 190*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 191*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;} 192*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 193*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;} 194*0b57cec5SDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 1955ffd83dbSDimitry Andric _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;} 196*0b57cec5SDimitry Andric 197*0b57cec5SDimitry Andric // element access: 198*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1995ffd83dbSDimitry Andric reference operator[](size_type __n) _NOEXCEPT { 2005ffd83dbSDimitry Andric _LIBCPP_ASSERT(__n < _Size, "out-of-bounds access in std::array<T, N>"); 2015ffd83dbSDimitry Andric return __elems_[__n]; 2025ffd83dbSDimitry Andric } 203*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 2045ffd83dbSDimitry Andric const_reference operator[](size_type __n) const _NOEXCEPT { 2055ffd83dbSDimitry Andric _LIBCPP_ASSERT(__n < _Size, "out-of-bounds access in std::array<T, N>"); 2065ffd83dbSDimitry Andric return __elems_[__n]; 2075ffd83dbSDimitry Andric } 208*0b57cec5SDimitry Andric 2095ffd83dbSDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n) 2105ffd83dbSDimitry Andric { 2115ffd83dbSDimitry Andric if (__n >= _Size) 2125ffd83dbSDimitry Andric __throw_out_of_range("array::at"); 2135ffd83dbSDimitry Andric return __elems_[__n]; 2145ffd83dbSDimitry Andric } 215*0b57cec5SDimitry Andric 2165ffd83dbSDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const 2175ffd83dbSDimitry Andric { 2185ffd83dbSDimitry Andric if (__n >= _Size) 2195ffd83dbSDimitry Andric __throw_out_of_range("array::at"); 2205ffd83dbSDimitry Andric return __elems_[__n]; 2215ffd83dbSDimitry Andric } 2225ffd83dbSDimitry Andric 2235ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() _NOEXCEPT {return (*this)[0];} 2245ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const _NOEXCEPT {return (*this)[0];} 2255ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() _NOEXCEPT {return (*this)[_Size - 1];} 2265ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const _NOEXCEPT {return (*this)[_Size - 1];} 227*0b57cec5SDimitry Andric 228*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 229*0b57cec5SDimitry Andric value_type* data() _NOEXCEPT {return __elems_;} 230*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 231*0b57cec5SDimitry Andric const value_type* data() const _NOEXCEPT {return __elems_;} 232*0b57cec5SDimitry Andric}; 233*0b57cec5SDimitry Andric 234*0b57cec5SDimitry Andrictemplate <class _Tp> 235*0b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> 236*0b57cec5SDimitry Andric{ 237*0b57cec5SDimitry Andric // types: 238*0b57cec5SDimitry Andric typedef array __self; 239*0b57cec5SDimitry Andric typedef _Tp value_type; 240*0b57cec5SDimitry Andric typedef value_type& reference; 241*0b57cec5SDimitry Andric typedef const value_type& const_reference; 242*0b57cec5SDimitry Andric typedef value_type* iterator; 243*0b57cec5SDimitry Andric typedef const value_type* const_iterator; 244*0b57cec5SDimitry Andric typedef value_type* pointer; 245*0b57cec5SDimitry Andric typedef const value_type* const_pointer; 246*0b57cec5SDimitry Andric typedef size_t size_type; 247*0b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 248*0b57cec5SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 249*0b57cec5SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 250*0b57cec5SDimitry Andric 251*0b57cec5SDimitry Andric typedef typename conditional<is_const<_Tp>::value, const char, 252*0b57cec5SDimitry Andric char>::type _CharType; 253*0b57cec5SDimitry Andric 254*0b57cec5SDimitry Andric struct _ArrayInStructT { _Tp __data_[1]; }; 255*0b57cec5SDimitry Andric _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)]; 256*0b57cec5SDimitry Andric 2575ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 2585ffd83dbSDimitry Andric value_type* data() _NOEXCEPT {return nullptr;} 2595ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 2605ffd83dbSDimitry Andric const value_type* data() const _NOEXCEPT {return nullptr;} 2615ffd83dbSDimitry Andric 262*0b57cec5SDimitry Andric // No explicit construct/copy/destroy for aggregate type 2635ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 2645ffd83dbSDimitry Andric void fill(const value_type&) { 265*0b57cec5SDimitry Andric static_assert(!is_const<_Tp>::value, 266*0b57cec5SDimitry Andric "cannot fill zero-sized array of type 'const T'"); 267*0b57cec5SDimitry Andric } 268*0b57cec5SDimitry Andric 2695ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 270*0b57cec5SDimitry Andric void swap(array&) _NOEXCEPT { 271*0b57cec5SDimitry Andric static_assert(!is_const<_Tp>::value, 272*0b57cec5SDimitry Andric "cannot swap zero-sized array of type 'const T'"); 273*0b57cec5SDimitry Andric } 274*0b57cec5SDimitry Andric 275*0b57cec5SDimitry Andric // iterators: 2765ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 277*0b57cec5SDimitry Andric iterator begin() _NOEXCEPT {return iterator(data());} 2785ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 279*0b57cec5SDimitry Andric const_iterator begin() const _NOEXCEPT {return const_iterator(data());} 2805ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 281*0b57cec5SDimitry Andric iterator end() _NOEXCEPT {return iterator(data());} 2825ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 283*0b57cec5SDimitry Andric const_iterator end() const _NOEXCEPT {return const_iterator(data());} 284*0b57cec5SDimitry Andric 2855ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 286*0b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} 2875ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 288*0b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} 2895ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 290*0b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} 2915ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 292*0b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} 293*0b57cec5SDimitry Andric 2945ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 295*0b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT {return begin();} 2965ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 297*0b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT {return end();} 2985ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 299*0b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} 3005ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 301*0b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT {return rend();} 302*0b57cec5SDimitry Andric 303*0b57cec5SDimitry Andric // capacity: 304*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 305*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; } 306*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 307*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;} 308*0b57cec5SDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 309*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;} 310*0b57cec5SDimitry Andric 311*0b57cec5SDimitry Andric // element access: 3125ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 313*0b57cec5SDimitry Andric reference operator[](size_type) _NOEXCEPT { 314*0b57cec5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array"); 315*0b57cec5SDimitry Andric _LIBCPP_UNREACHABLE(); 316*0b57cec5SDimitry Andric } 317*0b57cec5SDimitry Andric 318*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 319*0b57cec5SDimitry Andric const_reference operator[](size_type) const _NOEXCEPT { 320*0b57cec5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array"); 321*0b57cec5SDimitry Andric _LIBCPP_UNREACHABLE(); 322*0b57cec5SDimitry Andric } 323*0b57cec5SDimitry Andric 3245ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 325*0b57cec5SDimitry Andric reference at(size_type) { 326*0b57cec5SDimitry Andric __throw_out_of_range("array<T, 0>::at"); 327*0b57cec5SDimitry Andric _LIBCPP_UNREACHABLE(); 328*0b57cec5SDimitry Andric } 329*0b57cec5SDimitry Andric 3305ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 331*0b57cec5SDimitry Andric const_reference at(size_type) const { 332*0b57cec5SDimitry Andric __throw_out_of_range("array<T, 0>::at"); 333*0b57cec5SDimitry Andric _LIBCPP_UNREACHABLE(); 334*0b57cec5SDimitry Andric } 335*0b57cec5SDimitry Andric 3365ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 337*0b57cec5SDimitry Andric reference front() _NOEXCEPT { 338*0b57cec5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array"); 339*0b57cec5SDimitry Andric _LIBCPP_UNREACHABLE(); 340*0b57cec5SDimitry Andric } 341*0b57cec5SDimitry Andric 3425ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 343*0b57cec5SDimitry Andric const_reference front() const _NOEXCEPT { 344*0b57cec5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array"); 345*0b57cec5SDimitry Andric _LIBCPP_UNREACHABLE(); 346*0b57cec5SDimitry Andric } 347*0b57cec5SDimitry Andric 3485ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 349*0b57cec5SDimitry Andric reference back() _NOEXCEPT { 350*0b57cec5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array"); 351*0b57cec5SDimitry Andric _LIBCPP_UNREACHABLE(); 352*0b57cec5SDimitry Andric } 353*0b57cec5SDimitry Andric 3545ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 355*0b57cec5SDimitry Andric const_reference back() const _NOEXCEPT { 356*0b57cec5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array"); 357*0b57cec5SDimitry Andric _LIBCPP_UNREACHABLE(); 358*0b57cec5SDimitry Andric } 359*0b57cec5SDimitry Andric}; 360*0b57cec5SDimitry Andric 361*0b57cec5SDimitry Andric 362*0b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 363*0b57cec5SDimitry Andrictemplate<class _Tp, class... _Args, 36462cfcf62SDimitry Andric class = _EnableIf<__all<_IsSame<_Tp, _Args>::value...>::value> 365*0b57cec5SDimitry Andric > 366*0b57cec5SDimitry Andricarray(_Tp, _Args...) 367*0b57cec5SDimitry Andric -> array<_Tp, 1 + sizeof...(_Args)>; 368*0b57cec5SDimitry Andric#endif 369*0b57cec5SDimitry Andric 370*0b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 371*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 372*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 373*0b57cec5SDimitry Andricoperator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 374*0b57cec5SDimitry Andric{ 375*0b57cec5SDimitry Andric return _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 376*0b57cec5SDimitry Andric} 377*0b57cec5SDimitry Andric 378*0b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 379*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 380*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 381*0b57cec5SDimitry Andricoperator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 382*0b57cec5SDimitry Andric{ 383*0b57cec5SDimitry Andric return !(__x == __y); 384*0b57cec5SDimitry Andric} 385*0b57cec5SDimitry Andric 386*0b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 387*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 388*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 389*0b57cec5SDimitry Andricoperator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 390*0b57cec5SDimitry Andric{ 391*0b57cec5SDimitry Andric return _VSTD::lexicographical_compare(__x.begin(), __x.end(), 392*0b57cec5SDimitry Andric __y.begin(), __y.end()); 393*0b57cec5SDimitry Andric} 394*0b57cec5SDimitry Andric 395*0b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 396*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 397*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 398*0b57cec5SDimitry Andricoperator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 399*0b57cec5SDimitry Andric{ 400*0b57cec5SDimitry Andric return __y < __x; 401*0b57cec5SDimitry Andric} 402*0b57cec5SDimitry Andric 403*0b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 404*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 405*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 406*0b57cec5SDimitry Andricoperator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 407*0b57cec5SDimitry Andric{ 408*0b57cec5SDimitry Andric return !(__y < __x); 409*0b57cec5SDimitry Andric} 410*0b57cec5SDimitry Andric 411*0b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 412*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 413*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 414*0b57cec5SDimitry Andricoperator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 415*0b57cec5SDimitry Andric{ 416*0b57cec5SDimitry Andric return !(__x < __y); 417*0b57cec5SDimitry Andric} 418*0b57cec5SDimitry Andric 419*0b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 4205ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 421*0b57cec5SDimitry Andrictypename enable_if 422*0b57cec5SDimitry Andric< 423*0b57cec5SDimitry Andric _Size == 0 || 424*0b57cec5SDimitry Andric __is_swappable<_Tp>::value, 425*0b57cec5SDimitry Andric void 426*0b57cec5SDimitry Andric>::type 427*0b57cec5SDimitry Andricswap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y) 428*0b57cec5SDimitry Andric _NOEXCEPT_(noexcept(__x.swap(__y))) 429*0b57cec5SDimitry Andric{ 430*0b57cec5SDimitry Andric __x.swap(__y); 431*0b57cec5SDimitry Andric} 432*0b57cec5SDimitry Andric 433*0b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 434*0b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> > 435*0b57cec5SDimitry Andric : public integral_constant<size_t, _Size> {}; 436*0b57cec5SDimitry Andric 437*0b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size> 438*0b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > 439*0b57cec5SDimitry Andric{ 440*0b57cec5SDimitry Andric static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)"); 441*0b57cec5SDimitry Andric typedef _Tp type; 442*0b57cec5SDimitry Andric}; 443*0b57cec5SDimitry Andric 444*0b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size> 445*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 446*0b57cec5SDimitry Andric_Tp& 447*0b57cec5SDimitry Andricget(array<_Tp, _Size>& __a) _NOEXCEPT 448*0b57cec5SDimitry Andric{ 449*0b57cec5SDimitry Andric static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)"); 450*0b57cec5SDimitry Andric return __a.__elems_[_Ip]; 451*0b57cec5SDimitry Andric} 452*0b57cec5SDimitry Andric 453*0b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size> 454*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 455*0b57cec5SDimitry Andricconst _Tp& 456*0b57cec5SDimitry Andricget(const array<_Tp, _Size>& __a) _NOEXCEPT 457*0b57cec5SDimitry Andric{ 458*0b57cec5SDimitry Andric static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)"); 459*0b57cec5SDimitry Andric return __a.__elems_[_Ip]; 460*0b57cec5SDimitry Andric} 461*0b57cec5SDimitry Andric 462*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 463*0b57cec5SDimitry Andric 464*0b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size> 465*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 466*0b57cec5SDimitry Andric_Tp&& 467*0b57cec5SDimitry Andricget(array<_Tp, _Size>&& __a) _NOEXCEPT 468*0b57cec5SDimitry Andric{ 469*0b57cec5SDimitry Andric static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)"); 470*0b57cec5SDimitry Andric return _VSTD::move(__a.__elems_[_Ip]); 471*0b57cec5SDimitry Andric} 472*0b57cec5SDimitry Andric 473*0b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size> 474*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 475*0b57cec5SDimitry Andricconst _Tp&& 476*0b57cec5SDimitry Andricget(const array<_Tp, _Size>&& __a) _NOEXCEPT 477*0b57cec5SDimitry Andric{ 478*0b57cec5SDimitry Andric static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)"); 479*0b57cec5SDimitry Andric return _VSTD::move(__a.__elems_[_Ip]); 480*0b57cec5SDimitry Andric} 481*0b57cec5SDimitry Andric 482*0b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 483*0b57cec5SDimitry Andric 4845ffd83dbSDimitry Andric#if _LIBCPP_STD_VER > 17 4855ffd83dbSDimitry Andric 4865ffd83dbSDimitry Andrictemplate <typename _Tp, size_t _Size, size_t... _Index> 4875ffd83dbSDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> 4885ffd83dbSDimitry Andric__to_array_lvalue_impl(_Tp (&__arr)[_Size], index_sequence<_Index...>) { 4895ffd83dbSDimitry Andric return {{__arr[_Index]...}}; 4905ffd83dbSDimitry Andric} 4915ffd83dbSDimitry Andric 4925ffd83dbSDimitry Andrictemplate <typename _Tp, size_t _Size, size_t... _Index> 4935ffd83dbSDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> 4945ffd83dbSDimitry Andric__to_array_rvalue_impl(_Tp(&&__arr)[_Size], index_sequence<_Index...>) { 4955ffd83dbSDimitry Andric return {{_VSTD::move(__arr[_Index])...}}; 4965ffd83dbSDimitry Andric} 4975ffd83dbSDimitry Andric 4985ffd83dbSDimitry Andrictemplate <typename _Tp, size_t _Size> 4995ffd83dbSDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> 5005ffd83dbSDimitry Andricto_array(_Tp (&__arr)[_Size]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) { 5015ffd83dbSDimitry Andric static_assert( 5025ffd83dbSDimitry Andric !is_array_v<_Tp>, 5035ffd83dbSDimitry Andric "[array.creation]/1: to_array does not accept multidimensional arrays."); 5045ffd83dbSDimitry Andric static_assert( 5055ffd83dbSDimitry Andric is_constructible_v<_Tp, _Tp&>, 5065ffd83dbSDimitry Andric "[array.creation]/1: to_array requires copy constructible elements."); 5075ffd83dbSDimitry Andric return __to_array_lvalue_impl(__arr, make_index_sequence<_Size>()); 5085ffd83dbSDimitry Andric} 5095ffd83dbSDimitry Andric 5105ffd83dbSDimitry Andrictemplate <typename _Tp, size_t _Size> 5115ffd83dbSDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> 5125ffd83dbSDimitry Andricto_array(_Tp(&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) { 5135ffd83dbSDimitry Andric static_assert( 5145ffd83dbSDimitry Andric !is_array_v<_Tp>, 5155ffd83dbSDimitry Andric "[array.creation]/4: to_array does not accept multidimensional arrays."); 5165ffd83dbSDimitry Andric static_assert( 5175ffd83dbSDimitry Andric is_move_constructible_v<_Tp>, 5185ffd83dbSDimitry Andric "[array.creation]/4: to_array requires move constructible elements."); 5195ffd83dbSDimitry Andric return __to_array_rvalue_impl(_VSTD::move(__arr), 5205ffd83dbSDimitry Andric make_index_sequence<_Size>()); 5215ffd83dbSDimitry Andric} 5225ffd83dbSDimitry Andric 5235ffd83dbSDimitry Andric#endif // _LIBCPP_STD_VER > 17 5245ffd83dbSDimitry Andric 525*0b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 526*0b57cec5SDimitry Andric 527*0b57cec5SDimitry Andric#endif // _LIBCPP_ARRAY 528