2 //===---------------------------- array -----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
19 template <class T, size_t N >
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;
31 typedef const T* const_pointer;
32 typedef std::reverse_iterator<iterator> reverse_iterator;
33 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
35 // No explicit construct/copy/destroy for aggregate type
36 void fill(const T& u);
37 void swap(array& a) noexcept(is_nothrow_swappable_v<T>);
40 iterator begin() noexcept;
41 const_iterator begin() const noexcept;
42 iterator end() noexcept;
43 const_iterator end() const noexcept;
45 reverse_iterator rbegin() noexcept;
46 const_reverse_iterator rbegin() const noexcept;
47 reverse_iterator rend() noexcept;
48 const_reverse_iterator rend() const noexcept;
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;
56 constexpr size_type size() const noexcept;
57 constexpr size_type max_size() const noexcept;
58 constexpr bool empty() const noexcept;
61 reference operator[](size_type n);
62 const_reference operator[](size_type n) const; // constexpr in C++14
63 const_reference at(size_type n) const; // constexpr in C++14
64 reference at(size_type n);
67 const_reference front() const; // constexpr in C++14
69 const_reference back() const; // constexpr in C++14
72 const T* data() const noexcept;
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);
88 template <class T, size_t N >
89 void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y)));
91 template <class T> class tuple_size;
92 template <size_t I, class T> class tuple_element;
93 template <class T, size_t N> struct tuple_size<array<T, N>>;
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
98 template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14
106 #include <type_traits>
112 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
113 #pragma GCC system_header
116 _LIBCPP_BEGIN_NAMESPACE_STD
118 template <class _Tp, size_t _Size>
119 struct _LIBCPP_TEMPLATE_VIS array
122 typedef array __self;
123 typedef _Tp value_type;
124 typedef value_type& reference;
125 typedef const value_type& const_reference;
126 typedef value_type* iterator;
127 typedef const value_type* const_iterator;
128 typedef value_type* pointer;
129 typedef const value_type* const_pointer;
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;
135 value_type __elems_[_Size > 0 ? _Size : 1];
137 // No explicit construct/copy/destroy for aggregate type
138 _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u)
139 {_VSTD::fill_n(__elems_, _Size, __u);}
140 _LIBCPP_INLINE_VISIBILITY
141 void swap(array& __a) _NOEXCEPT_(_Size == 0 || __is_nothrow_swappable<_Tp>::value)
142 { __swap_dispatch((std::integral_constant<bool, _Size == 0>()), __a); }
144 _LIBCPP_INLINE_VISIBILITY
145 void __swap_dispatch(std::true_type, array&) {}
147 _LIBCPP_INLINE_VISIBILITY
148 void __swap_dispatch(std::false_type, array& __a)
149 { _VSTD::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);}
152 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
153 iterator begin() _NOEXCEPT {return iterator(__elems_);}
154 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
155 const_iterator begin() const _NOEXCEPT {return const_iterator(__elems_);}
156 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
157 iterator end() _NOEXCEPT {return iterator(__elems_ + _Size);}
158 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
159 const_iterator end() const _NOEXCEPT {return const_iterator(__elems_ + _Size);}
161 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
162 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
163 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
164 const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
165 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
166 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
167 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
168 const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
170 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
171 const_iterator cbegin() const _NOEXCEPT {return begin();}
172 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
173 const_iterator cend() const _NOEXCEPT {return end();}
174 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
175 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
176 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
177 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
180 _LIBCPP_INLINE_VISIBILITY
181 _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;}
182 _LIBCPP_INLINE_VISIBILITY
183 _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
184 _LIBCPP_INLINE_VISIBILITY
185 _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;}
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];}
193 _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n);
194 _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const;
196 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() {return __elems_[0];}
197 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const {return __elems_[0];}
198 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() {return __elems_[_Size > 0 ? _Size-1 : 0];}
199 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const {return __elems_[_Size > 0 ? _Size-1 : 0];}
201 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
202 value_type* data() _NOEXCEPT {return __elems_;}
203 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
204 const value_type* data() const _NOEXCEPT {return __elems_;}
207 template <class _Tp, size_t _Size>
208 _LIBCPP_CONSTEXPR_AFTER_CXX14
209 typename array<_Tp, _Size>::reference
210 array<_Tp, _Size>::at(size_type __n)
213 __throw_out_of_range("array::at");
215 return __elems_[__n];
218 template <class _Tp, size_t _Size>
219 _LIBCPP_CONSTEXPR_AFTER_CXX11
220 typename array<_Tp, _Size>::const_reference
221 array<_Tp, _Size>::at(size_type __n) const
224 __throw_out_of_range("array::at");
225 return __elems_[__n];
228 template <class _Tp, size_t _Size>
229 inline _LIBCPP_INLINE_VISIBILITY
231 operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
233 return _VSTD::equal(__x.__elems_, __x.__elems_ + _Size, __y.__elems_);
236 template <class _Tp, size_t _Size>
237 inline _LIBCPP_INLINE_VISIBILITY
239 operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
241 return !(__x == __y);
244 template <class _Tp, size_t _Size>
245 inline _LIBCPP_INLINE_VISIBILITY
247 operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
249 return _VSTD::lexicographical_compare(__x.__elems_, __x.__elems_ + _Size, __y.__elems_, __y.__elems_ + _Size);
252 template <class _Tp, size_t _Size>
253 inline _LIBCPP_INLINE_VISIBILITY
255 operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
260 template <class _Tp, size_t _Size>
261 inline _LIBCPP_INLINE_VISIBILITY
263 operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
268 template <class _Tp, size_t _Size>
269 inline _LIBCPP_INLINE_VISIBILITY
271 operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
276 template <class _Tp, size_t _Size>
277 inline _LIBCPP_INLINE_VISIBILITY
281 __is_swappable<_Tp>::value,
284 swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
285 _NOEXCEPT_(noexcept(__x.swap(__y)))
290 template <class _Tp, size_t _Size>
291 class _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
292 : public integral_constant<size_t, _Size> {};
294 template <size_t _Ip, class _Tp, size_t _Size>
295 class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
301 template <size_t _Ip, class _Tp, size_t _Size>
302 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
304 get(array<_Tp, _Size>& __a) _NOEXCEPT
306 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
307 return __a.__elems_[_Ip];
310 template <size_t _Ip, class _Tp, size_t _Size>
311 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
313 get(const array<_Tp, _Size>& __a) _NOEXCEPT
315 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
316 return __a.__elems_[_Ip];
319 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
321 template <size_t _Ip, class _Tp, size_t _Size>
322 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
324 get(array<_Tp, _Size>&& __a) _NOEXCEPT
326 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
327 return _VSTD::move(__a.__elems_[_Ip]);
330 template <size_t _Ip, class _Tp, size_t _Size>
331 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
333 get(const array<_Tp, _Size>&& __a) _NOEXCEPT
335 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
336 return _VSTD::move(__a.__elems_[_Ip]);
339 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
341 _LIBCPP_END_NAMESPACE_STD
343 #endif // _LIBCPP_ARRAY