Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===---------------------------- array -----------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_ARRAY |
| 12 | #define _LIBCPP_ARRAY |
| 13 | |
| 14 | /* |
| 15 | array synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 19 | template <class T, size_t N > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 20 | struct array |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 21 | { |
| 22 | // types: |
| 23 | typedef T & reference; |
| 24 | typedef const T & const_reference; |
| 25 | typedef implementation defined iterator; |
| 26 | typedef implementation defined const_iterator; |
| 27 | typedef size_t size_type; |
| 28 | typedef ptrdiff_t difference_type; |
| 29 | typedef T value_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 30 | typedef T* pointer; |
| 31 | typedef const T* const_pointer; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 32 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 33 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 34 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 35 | // No explicit construct/copy/destroy for aggregate type |
| 36 | void fill(const T& u); |
Eric Fiselier | 8f1e73d | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 37 | void swap(array& a) noexcept(is_nothrow_swappable_v<T>); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 38 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 39 | // iterators: |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 40 | iterator begin() noexcept; |
| 41 | const_iterator begin() const noexcept; |
| 42 | iterator end() noexcept; |
| 43 | const_iterator end() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 44 | |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 45 | reverse_iterator rbegin() noexcept; |
| 46 | const_reverse_iterator rbegin() const noexcept; |
| 47 | reverse_iterator rend() noexcept; |
| 48 | const_reverse_iterator rend() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 49 | |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 50 | const_iterator cbegin() const noexcept; |
| 51 | const_iterator cend() const noexcept; |
| 52 | const_reverse_iterator crbegin() const noexcept; |
| 53 | const_reverse_iterator crend() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 54 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 55 | // capacity: |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 56 | constexpr size_type size() const noexcept; |
| 57 | constexpr size_type max_size() const noexcept; |
Howard Hinnant | 08bce17 | 2012-07-20 19:20:49 +0000 | [diff] [blame] | 58 | constexpr bool empty() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 59 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 60 | // element access: |
| 61 | reference operator[](size_type n); |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 62 | const_reference operator[](size_type n) const; // constexpr in C++14 |
| 63 | const_reference at(size_type n) const; // constexpr in C++14 |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 64 | reference at(size_type n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 65 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 66 | reference front(); |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 67 | const_reference front() const; // constexpr in C++14 |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 68 | reference back(); |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 69 | const_reference back() const; // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 70 | |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 71 | T* data() noexcept; |
| 72 | const T* data() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 75 | template <class T, size_t N> |
| 76 | bool operator==(const array<T,N>& x, const array<T,N>& y); |
| 77 | template <class T, size_t N> |
| 78 | bool operator!=(const array<T,N>& x, const array<T,N>& y); |
| 79 | template <class T, size_t N> |
| 80 | bool operator<(const array<T,N>& x, const array<T,N>& y); |
| 81 | template <class T, size_t N> |
| 82 | bool operator>(const array<T,N>& x, const array<T,N>& y); |
| 83 | template <class T, size_t N> |
| 84 | bool operator<=(const array<T,N>& x, const array<T,N>& y); |
| 85 | template <class T, size_t N> |
| 86 | bool operator>=(const array<T,N>& x, const array<T,N>& y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 87 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 88 | template <class T, size_t N > |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 89 | void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 90 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 91 | template <class T> class tuple_size; |
Marshall Clow | d871728 | 2015-11-19 19:41:04 +0000 | [diff] [blame] | 92 | template <size_t I, class T> class tuple_element; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 93 | template <class T, size_t N> struct tuple_size<array<T, N>>; |
Marshall Clow | d871728 | 2015-11-19 19:41:04 +0000 | [diff] [blame] | 94 | template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>; |
| 95 | template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14 |
| 96 | template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14 |
| 97 | template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14 |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 98 | template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 99 | |
| 100 | } // std |
| 101 | |
| 102 | */ |
| 103 | |
| 104 | #include <__config> |
| 105 | #include <__tuple> |
| 106 | #include <type_traits> |
| 107 | #include <utility> |
| 108 | #include <iterator> |
| 109 | #include <algorithm> |
| 110 | #include <stdexcept> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 111 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 112 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 113 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 114 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 115 | |
| 116 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 117 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 118 | template <class _Tp, size_t _Size> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 119 | struct _LIBCPP_TEMPLATE_VIS array |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 120 | { |
| 121 | // types: |
| 122 | typedef array __self; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 123 | typedef _Tp value_type; |
| 124 | typedef value_type& reference; |
| 125 | typedef const value_type& const_reference; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 126 | typedef value_type* iterator; |
| 127 | typedef const value_type* const_iterator; |
| 128 | typedef value_type* pointer; |
| 129 | typedef const value_type* const_pointer; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 130 | typedef size_t size_type; |
| 131 | typedef ptrdiff_t difference_type; |
| 132 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 133 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 134 | |
| 135 | value_type __elems_[_Size > 0 ? _Size : 1]; |
| 136 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 137 | // No explicit construct/copy/destroy for aggregate type |
Howard Hinnant | 333f50d | 2010-09-21 20:16:37 +0000 | [diff] [blame] | 138 | _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 139 | {_VSTD::fill_n(__elems_, _Size, __u);} |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 140 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 8f1e73d | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 141 | void swap(array& __a) _NOEXCEPT_(_Size == 0 || __is_nothrow_swappable<_Tp>::value) |
| 142 | { __swap_dispatch((std::integral_constant<bool, _Size == 0>()), __a); } |
| 143 | |
| 144 | _LIBCPP_INLINE_VISIBILITY |
| 145 | void __swap_dispatch(std::true_type, array&) {} |
| 146 | |
| 147 | _LIBCPP_INLINE_VISIBILITY |
| 148 | void __swap_dispatch(std::false_type, array& __a) |
| 149 | { _VSTD::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 150 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 151 | // iterators: |
Marshall Clow | e22af6b | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 152 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 153 | iterator begin() _NOEXCEPT {return iterator(__elems_);} |
Marshall Clow | e22af6b | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 154 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 155 | const_iterator begin() const _NOEXCEPT {return const_iterator(__elems_);} |
Marshall Clow | e22af6b | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 156 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 157 | iterator end() _NOEXCEPT {return iterator(__elems_ + _Size);} |
Marshall Clow | e22af6b | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 158 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 159 | const_iterator end() const _NOEXCEPT {return const_iterator(__elems_ + _Size);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 160 | |
Marshall Clow | e22af6b | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 161 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 162 | reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} |
Marshall Clow | e22af6b | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 163 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 164 | const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} |
Marshall Clow | e22af6b | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 165 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 166 | reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} |
Marshall Clow | e22af6b | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 167 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 168 | const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 169 | |
Marshall Clow | e22af6b | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 170 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 171 | const_iterator cbegin() const _NOEXCEPT {return begin();} |
Marshall Clow | e22af6b | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 172 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 173 | const_iterator cend() const _NOEXCEPT {return end();} |
Marshall Clow | e22af6b | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 174 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 175 | const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} |
Marshall Clow | e22af6b | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 176 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 177 | const_reverse_iterator crend() const _NOEXCEPT {return rend();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 178 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 179 | // capacity: |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 180 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 08bce17 | 2012-07-20 19:20:49 +0000 | [diff] [blame] | 181 | _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;} |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 182 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 08bce17 | 2012-07-20 19:20:49 +0000 | [diff] [blame] | 183 | _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;} |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 184 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 08bce17 | 2012-07-20 19:20:49 +0000 | [diff] [blame] | 185 | _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 186 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 187 | // element access: |
Marshall Clow | d25c997 | 2017-01-16 03:02:10 +0000 | [diff] [blame] | 188 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 189 | reference operator[](size_type __n) {return __elems_[__n];} |
| 190 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 191 | const_reference operator[](size_type __n) const {return __elems_[__n];} |
| 192 | |
| 193 | _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n); |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 194 | _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 195 | |
Marshall Clow | d25c997 | 2017-01-16 03:02:10 +0000 | [diff] [blame] | 196 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() {return __elems_[0];} |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 197 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const {return __elems_[0];} |
Marshall Clow | d25c997 | 2017-01-16 03:02:10 +0000 | [diff] [blame] | 198 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() {return __elems_[_Size > 0 ? _Size-1 : 0];} |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 199 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const {return __elems_[_Size > 0 ? _Size-1 : 0];} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 200 | |
Marshall Clow | e22af6b | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 201 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 202 | value_type* data() _NOEXCEPT {return __elems_;} |
Marshall Clow | e22af6b | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 203 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 204 | const value_type* data() const _NOEXCEPT {return __elems_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 205 | }; |
| 206 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 207 | template <class _Tp, size_t _Size> |
Marshall Clow | d25c997 | 2017-01-16 03:02:10 +0000 | [diff] [blame] | 208 | _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 209 | typename array<_Tp, _Size>::reference |
| 210 | array<_Tp, _Size>::at(size_type __n) |
| 211 | { |
| 212 | if (__n >= _Size) |
Marshall Clow | 14c09a2 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 213 | __throw_out_of_range("array::at"); |
| 214 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 215 | return __elems_[__n]; |
| 216 | } |
| 217 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 218 | template <class _Tp, size_t _Size> |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 219 | _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 220 | typename array<_Tp, _Size>::const_reference |
| 221 | array<_Tp, _Size>::at(size_type __n) const |
| 222 | { |
| 223 | if (__n >= _Size) |
Marshall Clow | 14c09a2 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 224 | __throw_out_of_range("array::at"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 225 | return __elems_[__n]; |
| 226 | } |
| 227 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 228 | template <class _Tp, size_t _Size> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 229 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 230 | bool |
| 231 | operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 232 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 233 | return _VSTD::equal(__x.__elems_, __x.__elems_ + _Size, __y.__elems_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 236 | template <class _Tp, size_t _Size> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 237 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 238 | bool |
| 239 | operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 240 | { |
| 241 | return !(__x == __y); |
| 242 | } |
| 243 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 244 | template <class _Tp, size_t _Size> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 245 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 246 | bool |
| 247 | operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 248 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 249 | return _VSTD::lexicographical_compare(__x.__elems_, __x.__elems_ + _Size, __y.__elems_, __y.__elems_ + _Size); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 252 | template <class _Tp, size_t _Size> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 253 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 254 | bool |
| 255 | operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 256 | { |
| 257 | return __y < __x; |
| 258 | } |
| 259 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 260 | template <class _Tp, size_t _Size> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 261 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 262 | bool |
| 263 | operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 264 | { |
| 265 | return !(__y < __x); |
| 266 | } |
| 267 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 268 | template <class _Tp, size_t _Size> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 269 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 270 | bool |
| 271 | operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) |
| 272 | { |
| 273 | return !(__x < __y); |
| 274 | } |
| 275 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 276 | template <class _Tp, size_t _Size> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 277 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aabf287 | 2011-06-01 19:59:32 +0000 | [diff] [blame] | 278 | typename enable_if |
| 279 | < |
Eric Fiselier | 8f1e73d | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 280 | _Size == 0 || |
Howard Hinnant | aabf287 | 2011-06-01 19:59:32 +0000 | [diff] [blame] | 281 | __is_swappable<_Tp>::value, |
| 282 | void |
| 283 | >::type |
Marshall Clow | 8d48d9b | 2016-03-07 21:57:10 +0000 | [diff] [blame] | 284 | swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y) |
Eric Fiselier | 8f1e73d | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 285 | _NOEXCEPT_(noexcept(__x.swap(__y))) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 286 | { |
| 287 | __x.swap(__y); |
| 288 | } |
| 289 | |
| 290 | template <class _Tp, size_t _Size> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 291 | class _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> > |
Howard Hinnant | 333f50d | 2010-09-21 20:16:37 +0000 | [diff] [blame] | 292 | : public integral_constant<size_t, _Size> {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 293 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 294 | template <size_t _Ip, class _Tp, size_t _Size> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 295 | class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 296 | { |
| 297 | public: |
| 298 | typedef _Tp type; |
| 299 | }; |
| 300 | |
| 301 | template <size_t _Ip, class _Tp, size_t _Size> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 302 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 303 | _Tp& |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 304 | get(array<_Tp, _Size>& __a) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 305 | { |
Marshall Clow | a46482e | 2012-12-18 16:46:30 +0000 | [diff] [blame] | 306 | static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)"); |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 307 | return __a.__elems_[_Ip]; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | template <size_t _Ip, class _Tp, size_t _Size> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 311 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 312 | const _Tp& |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 313 | get(const array<_Tp, _Size>& __a) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 314 | { |
Marshall Clow | a46482e | 2012-12-18 16:46:30 +0000 | [diff] [blame] | 315 | static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)"); |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 316 | return __a.__elems_[_Ip]; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 319 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 320 | |
| 321 | template <size_t _Ip, class _Tp, size_t _Size> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 322 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 323 | _Tp&& |
Howard Hinnant | f0562af | 2011-05-31 21:06:33 +0000 | [diff] [blame] | 324 | get(array<_Tp, _Size>&& __a) _NOEXCEPT |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 325 | { |
Marshall Clow | a46482e | 2012-12-18 16:46:30 +0000 | [diff] [blame] | 326 | static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)"); |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 327 | return _VSTD::move(__a.__elems_[_Ip]); |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 330 | template <size_t _Ip, class _Tp, size_t _Size> |
| 331 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 332 | const _Tp&& |
| 333 | get(const array<_Tp, _Size>&& __a) _NOEXCEPT |
| 334 | { |
| 335 | static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)"); |
| 336 | return _VSTD::move(__a.__elems_[_Ip]); |
| 337 | } |
| 338 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 339 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 340 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 341 | _LIBCPP_END_NAMESPACE_STD |
| 342 | |
| 343 | #endif // _LIBCPP_ARRAY |