10b57cec5SDimitry Andric// -*- C++ -*- 2349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_ARRAY 110b57cec5SDimitry Andric#define _LIBCPP_ARRAY 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric array synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry Andricnamespace std 170b57cec5SDimitry Andric{ 180b57cec5SDimitry Andrictemplate <class T, size_t N > 190b57cec5SDimitry Andricstruct array 200b57cec5SDimitry Andric{ 210b57cec5SDimitry Andric // types: 220b57cec5SDimitry Andric typedef T & reference; 230b57cec5SDimitry Andric typedef const T & const_reference; 240b57cec5SDimitry Andric typedef implementation defined iterator; 250b57cec5SDimitry Andric typedef implementation defined const_iterator; 260b57cec5SDimitry Andric typedef size_t size_type; 270b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 280b57cec5SDimitry Andric typedef T value_type; 290b57cec5SDimitry Andric typedef T* pointer; 300b57cec5SDimitry Andric typedef const T* const_pointer; 310b57cec5SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 320b57cec5SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 330b57cec5SDimitry Andric 340b57cec5SDimitry 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 370b57cec5SDimitry Andric 380b57cec5SDimitry 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 430b57cec5SDimitry 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 480b57cec5SDimitry 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 530b57cec5SDimitry Andric 540b57cec5SDimitry Andric // capacity: 550b57cec5SDimitry Andric constexpr size_type size() const noexcept; 560b57cec5SDimitry Andric constexpr size_type max_size() const noexcept; 570b57cec5SDimitry Andric constexpr bool empty() const noexcept; 580b57cec5SDimitry Andric 590b57cec5SDimitry Andric // element access: 605ffd83dbSDimitry Andric reference operator[](size_type n); // constexpr in C++17 610b57cec5SDimitry Andric const_reference operator[](size_type n) const; // constexpr in C++14 625ffd83dbSDimitry Andric reference at(size_type n); // constexpr in C++17 630b57cec5SDimitry Andric const_reference at(size_type n) const; // constexpr in C++14 640b57cec5SDimitry Andric 655ffd83dbSDimitry Andric reference front(); // constexpr in C++17 660b57cec5SDimitry Andric const_reference front() const; // constexpr in C++14 675ffd83dbSDimitry Andric reference back(); // constexpr in C++17 680b57cec5SDimitry Andric const_reference back() const; // constexpr in C++14 690b57cec5SDimitry Andric 705ffd83dbSDimitry Andric T* data() noexcept; // constexpr in C++17 715ffd83dbSDimitry Andric const T* data() const noexcept; // constexpr in C++17 720b57cec5SDimitry Andric}; 730b57cec5SDimitry Andric 740b57cec5SDimitry Andrictemplate <class T, class... U> 755ffd83dbSDimitry Andric array(T, U...) -> array<T, 1 + sizeof...(U)>; // C++17 760b57cec5SDimitry Andric 770b57cec5SDimitry Andrictemplate <class T, size_t N> 785ffd83dbSDimitry Andric bool operator==(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 790b57cec5SDimitry Andrictemplate <class T, size_t N> 805ffd83dbSDimitry Andric bool operator!=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 810b57cec5SDimitry Andrictemplate <class T, size_t N> 825ffd83dbSDimitry Andric bool operator<(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 830b57cec5SDimitry Andrictemplate <class T, size_t N> 845ffd83dbSDimitry Andric bool operator>(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 850b57cec5SDimitry Andrictemplate <class T, size_t N> 865ffd83dbSDimitry Andric bool operator<=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 870b57cec5SDimitry Andrictemplate <class T, size_t N> 885ffd83dbSDimitry Andric bool operator>=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 890b57cec5SDimitry Andric 900b57cec5SDimitry 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 970b57cec5SDimitry Andric 980b57cec5SDimitry Andrictemplate <class T> struct tuple_size; 990b57cec5SDimitry Andrictemplate <size_t I, class T> struct tuple_element; 1000b57cec5SDimitry Andrictemplate <class T, size_t N> struct tuple_size<array<T, N>>; 1010b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>; 1020b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14 1030b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14 1040b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14 1050b57cec5SDimitry Andrictemplate <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14 1060b57cec5SDimitry Andric 1070b57cec5SDimitry Andric} // std 1080b57cec5SDimitry Andric 1090b57cec5SDimitry Andric*/ 1100b57cec5SDimitry Andric 111*81ad6265SDimitry Andric#include <__algorithm/equal.h> 112*81ad6265SDimitry Andric#include <__algorithm/fill_n.h> 113*81ad6265SDimitry Andric#include <__algorithm/lexicographical_compare.h> 114*81ad6265SDimitry Andric#include <__algorithm/swap_ranges.h> 115*81ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler 1160b57cec5SDimitry Andric#include <__config> 117*81ad6265SDimitry Andric#include <__iterator/reverse_iterator.h> 1180b57cec5SDimitry Andric#include <__tuple> 119*81ad6265SDimitry Andric#include <__utility/integer_sequence.h> 120*81ad6265SDimitry Andric#include <__utility/move.h> 121*81ad6265SDimitry Andric#include <__utility/unreachable.h> 122fe6060f1SDimitry Andric#include <stdexcept> 1230b57cec5SDimitry Andric#include <type_traits> 1240b57cec5SDimitry Andric#include <version> 1250b57cec5SDimitry Andric 126*81ad6265SDimitry Andric#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES 127*81ad6265SDimitry Andric# include <algorithm> 128*81ad6265SDimitry Andric# include <iterator> 129*81ad6265SDimitry Andric# include <utility> 130*81ad6265SDimitry Andric#endif 131*81ad6265SDimitry Andric 132*81ad6265SDimitry Andric// standard-mandated includes 133*81ad6265SDimitry Andric 134*81ad6265SDimitry Andric// [iterator.range] 135*81ad6265SDimitry Andric#include <__iterator/access.h> 136*81ad6265SDimitry Andric#include <__iterator/data.h> 137*81ad6265SDimitry Andric#include <__iterator/empty.h> 138*81ad6265SDimitry Andric#include <__iterator/reverse_access.h> 139*81ad6265SDimitry Andric#include <__iterator/size.h> 140*81ad6265SDimitry Andric 141*81ad6265SDimitry Andric// [array.syn] 142*81ad6265SDimitry Andric#include <compare> 143*81ad6265SDimitry Andric#include <initializer_list> 144*81ad6265SDimitry Andric 1450b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1460b57cec5SDimitry Andric# pragma GCC system_header 1470b57cec5SDimitry Andric#endif 1480b57cec5SDimitry Andric 1490b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 1500b57cec5SDimitry Andric 1510b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 1520b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS array 1530b57cec5SDimitry Andric{ 1540b57cec5SDimitry Andric // types: 1550b57cec5SDimitry Andric typedef array __self; 1560b57cec5SDimitry Andric typedef _Tp value_type; 1570b57cec5SDimitry Andric typedef value_type& reference; 1580b57cec5SDimitry Andric typedef const value_type& const_reference; 1590b57cec5SDimitry Andric typedef value_type* iterator; 1600b57cec5SDimitry Andric typedef const value_type* const_iterator; 1610b57cec5SDimitry Andric typedef value_type* pointer; 1620b57cec5SDimitry Andric typedef const value_type* const_pointer; 1630b57cec5SDimitry Andric typedef size_t size_type; 1640b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 165e8d8bef9SDimitry Andric typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 166e8d8bef9SDimitry Andric typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 1670b57cec5SDimitry Andric 1680b57cec5SDimitry Andric _Tp __elems_[_Size]; 1690b57cec5SDimitry Andric 1700b57cec5SDimitry Andric // No explicit construct/copy/destroy for aggregate type 1715ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1725ffd83dbSDimitry Andric void fill(const value_type& __u) { 1735ffd83dbSDimitry Andric _VSTD::fill_n(data(), _Size, __u); 1740b57cec5SDimitry Andric } 1750b57cec5SDimitry Andric 1765ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1770b57cec5SDimitry Andric void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) { 178e8d8bef9SDimitry Andric _VSTD::swap_ranges(data(), data() + _Size, __a.data()); 1790b57cec5SDimitry Andric } 1800b57cec5SDimitry Andric 1810b57cec5SDimitry Andric // iterators: 1820b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1830b57cec5SDimitry Andric iterator begin() _NOEXCEPT {return iterator(data());} 1840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1850b57cec5SDimitry Andric const_iterator begin() const _NOEXCEPT {return const_iterator(data());} 1860b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1870b57cec5SDimitry Andric iterator end() _NOEXCEPT {return iterator(data() + _Size);} 1880b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1890b57cec5SDimitry Andric const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);} 1900b57cec5SDimitry Andric 1910b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1920b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} 1930b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1940b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} 1950b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1960b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} 1970b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1980b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} 1990b57cec5SDimitry Andric 2000b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 2010b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT {return begin();} 2020b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 2030b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT {return end();} 2040b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 2050b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} 2060b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 2070b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT {return rend();} 2080b57cec5SDimitry Andric 2090b57cec5SDimitry Andric // capacity: 2100b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2110b57cec5SDimitry Andric _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;} 2120b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2130b57cec5SDimitry Andric _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;} 2140b57cec5SDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 2155ffd83dbSDimitry Andric _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;} 2160b57cec5SDimitry Andric 2170b57cec5SDimitry Andric // element access: 2180b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 2195ffd83dbSDimitry Andric reference operator[](size_type __n) _NOEXCEPT { 2205ffd83dbSDimitry Andric _LIBCPP_ASSERT(__n < _Size, "out-of-bounds access in std::array<T, N>"); 2215ffd83dbSDimitry Andric return __elems_[__n]; 2225ffd83dbSDimitry Andric } 2230b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 2245ffd83dbSDimitry Andric const_reference operator[](size_type __n) const _NOEXCEPT { 2255ffd83dbSDimitry Andric _LIBCPP_ASSERT(__n < _Size, "out-of-bounds access in std::array<T, N>"); 2265ffd83dbSDimitry Andric return __elems_[__n]; 2275ffd83dbSDimitry Andric } 2280b57cec5SDimitry Andric 2295ffd83dbSDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n) 2305ffd83dbSDimitry Andric { 2315ffd83dbSDimitry Andric if (__n >= _Size) 2325ffd83dbSDimitry Andric __throw_out_of_range("array::at"); 2335ffd83dbSDimitry Andric return __elems_[__n]; 2345ffd83dbSDimitry Andric } 2350b57cec5SDimitry Andric 2365ffd83dbSDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const 2375ffd83dbSDimitry Andric { 2385ffd83dbSDimitry Andric if (__n >= _Size) 2395ffd83dbSDimitry Andric __throw_out_of_range("array::at"); 2405ffd83dbSDimitry Andric return __elems_[__n]; 2415ffd83dbSDimitry Andric } 2425ffd83dbSDimitry Andric 2435ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() _NOEXCEPT {return (*this)[0];} 2445ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const _NOEXCEPT {return (*this)[0];} 2455ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() _NOEXCEPT {return (*this)[_Size - 1];} 2465ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const _NOEXCEPT {return (*this)[_Size - 1];} 2470b57cec5SDimitry Andric 2480b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 2490b57cec5SDimitry Andric value_type* data() _NOEXCEPT {return __elems_;} 2500b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 2510b57cec5SDimitry Andric const value_type* data() const _NOEXCEPT {return __elems_;} 2520b57cec5SDimitry Andric}; 2530b57cec5SDimitry Andric 2540b57cec5SDimitry Andrictemplate <class _Tp> 2550b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> 2560b57cec5SDimitry Andric{ 2570b57cec5SDimitry Andric // types: 2580b57cec5SDimitry Andric typedef array __self; 2590b57cec5SDimitry Andric typedef _Tp value_type; 2600b57cec5SDimitry Andric typedef value_type& reference; 2610b57cec5SDimitry Andric typedef const value_type& const_reference; 2620b57cec5SDimitry Andric typedef value_type* iterator; 2630b57cec5SDimitry Andric typedef const value_type* const_iterator; 2640b57cec5SDimitry Andric typedef value_type* pointer; 2650b57cec5SDimitry Andric typedef const value_type* const_pointer; 2660b57cec5SDimitry Andric typedef size_t size_type; 2670b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 268e8d8bef9SDimitry Andric typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 269e8d8bef9SDimitry Andric typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 2700b57cec5SDimitry Andric 2710b57cec5SDimitry Andric typedef typename conditional<is_const<_Tp>::value, const char, 2720b57cec5SDimitry Andric char>::type _CharType; 2730b57cec5SDimitry Andric 2740b57cec5SDimitry Andric struct _ArrayInStructT { _Tp __data_[1]; }; 2750b57cec5SDimitry Andric _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)]; 2760b57cec5SDimitry Andric 2775ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 2785ffd83dbSDimitry Andric value_type* data() _NOEXCEPT {return nullptr;} 2795ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 2805ffd83dbSDimitry Andric const value_type* data() const _NOEXCEPT {return nullptr;} 2815ffd83dbSDimitry Andric 2820b57cec5SDimitry Andric // No explicit construct/copy/destroy for aggregate type 2835ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 2845ffd83dbSDimitry Andric void fill(const value_type&) { 2850b57cec5SDimitry Andric static_assert(!is_const<_Tp>::value, 2860b57cec5SDimitry Andric "cannot fill zero-sized array of type 'const T'"); 2870b57cec5SDimitry Andric } 2880b57cec5SDimitry Andric 2895ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 2900b57cec5SDimitry Andric void swap(array&) _NOEXCEPT { 2910b57cec5SDimitry Andric static_assert(!is_const<_Tp>::value, 2920b57cec5SDimitry Andric "cannot swap zero-sized array of type 'const T'"); 2930b57cec5SDimitry Andric } 2940b57cec5SDimitry Andric 2950b57cec5SDimitry Andric // iterators: 2965ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 2970b57cec5SDimitry Andric iterator begin() _NOEXCEPT {return iterator(data());} 2985ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 2990b57cec5SDimitry Andric const_iterator begin() const _NOEXCEPT {return const_iterator(data());} 3005ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 3010b57cec5SDimitry Andric iterator end() _NOEXCEPT {return iterator(data());} 3025ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 3030b57cec5SDimitry Andric const_iterator end() const _NOEXCEPT {return const_iterator(data());} 3040b57cec5SDimitry Andric 3055ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 3060b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} 3075ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 3080b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} 3095ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 3100b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} 3115ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 3120b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} 3130b57cec5SDimitry Andric 3145ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 3150b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT {return begin();} 3165ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 3170b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT {return end();} 3185ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 3190b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} 3205ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 3210b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT {return rend();} 3220b57cec5SDimitry Andric 3230b57cec5SDimitry Andric // capacity: 3240b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3250b57cec5SDimitry Andric _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; } 3260b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3270b57cec5SDimitry Andric _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;} 3280b57cec5SDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 3290b57cec5SDimitry Andric _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;} 3300b57cec5SDimitry Andric 3310b57cec5SDimitry Andric // element access: 3325ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 3330b57cec5SDimitry Andric reference operator[](size_type) _NOEXCEPT { 3340b57cec5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array"); 335*81ad6265SDimitry Andric __libcpp_unreachable(); 3360b57cec5SDimitry Andric } 3370b57cec5SDimitry Andric 3380b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 3390b57cec5SDimitry Andric const_reference operator[](size_type) const _NOEXCEPT { 3400b57cec5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array"); 341*81ad6265SDimitry Andric __libcpp_unreachable(); 3420b57cec5SDimitry Andric } 3430b57cec5SDimitry Andric 3445ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 3450b57cec5SDimitry Andric reference at(size_type) { 3460b57cec5SDimitry Andric __throw_out_of_range("array<T, 0>::at"); 347*81ad6265SDimitry Andric __libcpp_unreachable(); 3480b57cec5SDimitry Andric } 3490b57cec5SDimitry Andric 3505ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 3510b57cec5SDimitry Andric const_reference at(size_type) const { 3520b57cec5SDimitry Andric __throw_out_of_range("array<T, 0>::at"); 353*81ad6265SDimitry Andric __libcpp_unreachable(); 3540b57cec5SDimitry Andric } 3550b57cec5SDimitry Andric 3565ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 3570b57cec5SDimitry Andric reference front() _NOEXCEPT { 3580b57cec5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array"); 359*81ad6265SDimitry Andric __libcpp_unreachable(); 3600b57cec5SDimitry Andric } 3610b57cec5SDimitry Andric 3625ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 3630b57cec5SDimitry Andric const_reference front() const _NOEXCEPT { 3640b57cec5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array"); 365*81ad6265SDimitry Andric __libcpp_unreachable(); 3660b57cec5SDimitry Andric } 3670b57cec5SDimitry Andric 3685ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 3690b57cec5SDimitry Andric reference back() _NOEXCEPT { 3700b57cec5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array"); 371*81ad6265SDimitry Andric __libcpp_unreachable(); 3720b57cec5SDimitry Andric } 3730b57cec5SDimitry Andric 3745ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 3750b57cec5SDimitry Andric const_reference back() const _NOEXCEPT { 3760b57cec5SDimitry Andric _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array"); 377*81ad6265SDimitry Andric __libcpp_unreachable(); 3780b57cec5SDimitry Andric } 3790b57cec5SDimitry Andric}; 3800b57cec5SDimitry Andric 3810b57cec5SDimitry Andric 382*81ad6265SDimitry Andric#if _LIBCPP_STD_VER > 14 3830b57cec5SDimitry Andrictemplate<class _Tp, class... _Args, 384349cc55cSDimitry Andric class = enable_if_t<__all<_IsSame<_Tp, _Args>::value...>::value> 3850b57cec5SDimitry Andric > 3860b57cec5SDimitry Andricarray(_Tp, _Args...) 3870b57cec5SDimitry Andric -> array<_Tp, 1 + sizeof...(_Args)>; 3880b57cec5SDimitry Andric#endif 3890b57cec5SDimitry Andric 3900b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 3910b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 3920b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 3930b57cec5SDimitry Andricoperator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 3940b57cec5SDimitry Andric{ 3950b57cec5SDimitry Andric return _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 3960b57cec5SDimitry Andric} 3970b57cec5SDimitry Andric 3980b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 3990b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4000b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 4010b57cec5SDimitry Andricoperator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 4020b57cec5SDimitry Andric{ 4030b57cec5SDimitry Andric return !(__x == __y); 4040b57cec5SDimitry Andric} 4050b57cec5SDimitry Andric 4060b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 4070b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4080b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 4090b57cec5SDimitry Andricoperator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 4100b57cec5SDimitry Andric{ 4110b57cec5SDimitry Andric return _VSTD::lexicographical_compare(__x.begin(), __x.end(), 4120b57cec5SDimitry Andric __y.begin(), __y.end()); 4130b57cec5SDimitry Andric} 4140b57cec5SDimitry Andric 4150b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 4160b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4170b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 4180b57cec5SDimitry Andricoperator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 4190b57cec5SDimitry Andric{ 4200b57cec5SDimitry Andric return __y < __x; 4210b57cec5SDimitry Andric} 4220b57cec5SDimitry Andric 4230b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 4240b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4250b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 4260b57cec5SDimitry Andricoperator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 4270b57cec5SDimitry Andric{ 4280b57cec5SDimitry Andric return !(__y < __x); 4290b57cec5SDimitry Andric} 4300b57cec5SDimitry Andric 4310b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 4320b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4330b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 4340b57cec5SDimitry Andricoperator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) 4350b57cec5SDimitry Andric{ 4360b57cec5SDimitry Andric return !(__x < __y); 4370b57cec5SDimitry Andric} 4380b57cec5SDimitry Andric 4390b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 4405ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 4410b57cec5SDimitry Andrictypename enable_if 4420b57cec5SDimitry Andric< 4430b57cec5SDimitry Andric _Size == 0 || 4440b57cec5SDimitry Andric __is_swappable<_Tp>::value, 4450b57cec5SDimitry Andric void 4460b57cec5SDimitry Andric>::type 4470b57cec5SDimitry Andricswap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y) 4480b57cec5SDimitry Andric _NOEXCEPT_(noexcept(__x.swap(__y))) 4490b57cec5SDimitry Andric{ 4500b57cec5SDimitry Andric __x.swap(__y); 4510b57cec5SDimitry Andric} 4520b57cec5SDimitry Andric 4530b57cec5SDimitry Andrictemplate <class _Tp, size_t _Size> 4540b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> > 4550b57cec5SDimitry Andric : public integral_constant<size_t, _Size> {}; 4560b57cec5SDimitry Andric 4570b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size> 4580b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > 4590b57cec5SDimitry Andric{ 4600b57cec5SDimitry Andric static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)"); 4610b57cec5SDimitry Andric typedef _Tp type; 4620b57cec5SDimitry Andric}; 4630b57cec5SDimitry Andric 4640b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size> 4650b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4660b57cec5SDimitry Andric_Tp& 4670b57cec5SDimitry Andricget(array<_Tp, _Size>& __a) _NOEXCEPT 4680b57cec5SDimitry Andric{ 4690b57cec5SDimitry Andric static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)"); 4700b57cec5SDimitry Andric return __a.__elems_[_Ip]; 4710b57cec5SDimitry Andric} 4720b57cec5SDimitry Andric 4730b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size> 4740b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4750b57cec5SDimitry Andricconst _Tp& 4760b57cec5SDimitry Andricget(const array<_Tp, _Size>& __a) _NOEXCEPT 4770b57cec5SDimitry Andric{ 4780b57cec5SDimitry Andric static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)"); 4790b57cec5SDimitry Andric return __a.__elems_[_Ip]; 4800b57cec5SDimitry Andric} 4810b57cec5SDimitry Andric 4820b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size> 4830b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4840b57cec5SDimitry Andric_Tp&& 4850b57cec5SDimitry Andricget(array<_Tp, _Size>&& __a) _NOEXCEPT 4860b57cec5SDimitry Andric{ 4870b57cec5SDimitry Andric static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)"); 4880b57cec5SDimitry Andric return _VSTD::move(__a.__elems_[_Ip]); 4890b57cec5SDimitry Andric} 4900b57cec5SDimitry Andric 4910b57cec5SDimitry Andrictemplate <size_t _Ip, class _Tp, size_t _Size> 4920b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4930b57cec5SDimitry Andricconst _Tp&& 4940b57cec5SDimitry Andricget(const array<_Tp, _Size>&& __a) _NOEXCEPT 4950b57cec5SDimitry Andric{ 4960b57cec5SDimitry Andric static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)"); 4970b57cec5SDimitry Andric return _VSTD::move(__a.__elems_[_Ip]); 4980b57cec5SDimitry Andric} 4990b57cec5SDimitry Andric 5005ffd83dbSDimitry Andric#if _LIBCPP_STD_VER > 17 5015ffd83dbSDimitry Andric 5025ffd83dbSDimitry Andrictemplate <typename _Tp, size_t _Size, size_t... _Index> 5035ffd83dbSDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> 5045ffd83dbSDimitry Andric__to_array_lvalue_impl(_Tp (&__arr)[_Size], index_sequence<_Index...>) { 5055ffd83dbSDimitry Andric return {{__arr[_Index]...}}; 5065ffd83dbSDimitry Andric} 5075ffd83dbSDimitry Andric 5085ffd83dbSDimitry Andrictemplate <typename _Tp, size_t _Size, size_t... _Index> 5095ffd83dbSDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> 5105ffd83dbSDimitry Andric__to_array_rvalue_impl(_Tp(&&__arr)[_Size], index_sequence<_Index...>) { 5115ffd83dbSDimitry Andric return {{_VSTD::move(__arr[_Index])...}}; 5125ffd83dbSDimitry Andric} 5135ffd83dbSDimitry Andric 5145ffd83dbSDimitry Andrictemplate <typename _Tp, size_t _Size> 5155ffd83dbSDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> 5165ffd83dbSDimitry Andricto_array(_Tp (&__arr)[_Size]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) { 5175ffd83dbSDimitry Andric static_assert( 5185ffd83dbSDimitry Andric !is_array_v<_Tp>, 5195ffd83dbSDimitry Andric "[array.creation]/1: to_array does not accept multidimensional arrays."); 5205ffd83dbSDimitry Andric static_assert( 5215ffd83dbSDimitry Andric is_constructible_v<_Tp, _Tp&>, 5225ffd83dbSDimitry Andric "[array.creation]/1: to_array requires copy constructible elements."); 523e8d8bef9SDimitry Andric return _VSTD::__to_array_lvalue_impl(__arr, make_index_sequence<_Size>()); 5245ffd83dbSDimitry Andric} 5255ffd83dbSDimitry Andric 5265ffd83dbSDimitry Andrictemplate <typename _Tp, size_t _Size> 5275ffd83dbSDimitry Andric_LIBCPP_INLINE_VISIBILITY constexpr array<remove_cv_t<_Tp>, _Size> 5285ffd83dbSDimitry Andricto_array(_Tp(&&__arr)[_Size]) noexcept(is_nothrow_move_constructible_v<_Tp>) { 5295ffd83dbSDimitry Andric static_assert( 5305ffd83dbSDimitry Andric !is_array_v<_Tp>, 5315ffd83dbSDimitry Andric "[array.creation]/4: to_array does not accept multidimensional arrays."); 5325ffd83dbSDimitry Andric static_assert( 5335ffd83dbSDimitry Andric is_move_constructible_v<_Tp>, 5345ffd83dbSDimitry Andric "[array.creation]/4: to_array requires move constructible elements."); 535e8d8bef9SDimitry Andric return _VSTD::__to_array_rvalue_impl(_VSTD::move(__arr), 5365ffd83dbSDimitry Andric make_index_sequence<_Size>()); 5375ffd83dbSDimitry Andric} 5385ffd83dbSDimitry Andric 5395ffd83dbSDimitry Andric#endif // _LIBCPP_STD_VER > 17 5405ffd83dbSDimitry Andric 5410b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 5420b57cec5SDimitry Andric 5430b57cec5SDimitry Andric#endif // _LIBCPP_ARRAY 544