blob: 4a89ea90d44e95c2e73073869d975fa2cbae85b1 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- array -----------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_ARRAY
12#define _LIBCPP_ARRAY
13
14/*
15 array synopsis
16
17namespace std
18{
Howard Hinnant3b6579a2010-08-22 00:02:43 +000019template <class T, size_t N >
Howard Hinnantc51e1022010-05-11 19:42:16 +000020struct array
Howard Hinnant3b6579a2010-08-22 00:02:43 +000021{
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 Hinnantc51e1022010-05-11 19:42:16 +000030 typedef T* pointer;
31 typedef const T* const_pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +000032 typedef std::reverse_iterator<iterator> reverse_iterator;
33 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +000034
Howard Hinnant3b6579a2010-08-22 00:02:43 +000035 // No explicit construct/copy/destroy for aggregate type
36 void fill(const T& u);
Eric Fiselier6bfed252016-04-21 23:38:59 +000037 void swap(array& a) noexcept(is_nothrow_swappable_v<T>);
Howard Hinnantc51e1022010-05-11 19:42:16 +000038
Howard Hinnant3b6579a2010-08-22 00:02:43 +000039 // iterators:
Howard Hinnant32477e82011-05-31 21:06:33 +000040 iterator begin() noexcept;
41 const_iterator begin() const noexcept;
42 iterator end() noexcept;
43 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000044
Howard Hinnant32477e82011-05-31 21:06:33 +000045 reverse_iterator rbegin() noexcept;
46 const_reverse_iterator rbegin() const noexcept;
47 reverse_iterator rend() noexcept;
48 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000049
Howard Hinnant32477e82011-05-31 21:06:33 +000050 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 Hinnantc51e1022010-05-11 19:42:16 +000054
Howard Hinnant3b6579a2010-08-22 00:02:43 +000055 // capacity:
Howard Hinnant32477e82011-05-31 21:06:33 +000056 constexpr size_type size() const noexcept;
57 constexpr size_type max_size() const noexcept;
Howard Hinnant12ff42f2012-07-20 19:20:49 +000058 constexpr bool empty() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000059
Howard Hinnant3b6579a2010-08-22 00:02:43 +000060 // element access:
61 reference operator[](size_type n);
Marshall Clow0abb1042013-07-17 18:25:36 +000062 const_reference operator[](size_type n) const; // constexpr in C++14
63 const_reference at(size_type n) const; // constexpr in C++14
Howard Hinnant3b6579a2010-08-22 00:02:43 +000064 reference at(size_type n);
Howard Hinnantc51e1022010-05-11 19:42:16 +000065
Howard Hinnant3b6579a2010-08-22 00:02:43 +000066 reference front();
Marshall Clow0abb1042013-07-17 18:25:36 +000067 const_reference front() const; // constexpr in C++14
Howard Hinnant3b6579a2010-08-22 00:02:43 +000068 reference back();
Marshall Clow0abb1042013-07-17 18:25:36 +000069 const_reference back() const; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000070
Howard Hinnant32477e82011-05-31 21:06:33 +000071 T* data() noexcept;
72 const T* data() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000073};
74
Howard Hinnant3b6579a2010-08-22 00:02:43 +000075template <class T, size_t N>
76 bool operator==(const array<T,N>& x, const array<T,N>& y);
77template <class T, size_t N>
78 bool operator!=(const array<T,N>& x, const array<T,N>& y);
79template <class T, size_t N>
80 bool operator<(const array<T,N>& x, const array<T,N>& y);
81template <class T, size_t N>
82 bool operator>(const array<T,N>& x, const array<T,N>& y);
83template <class T, size_t N>
84 bool operator<=(const array<T,N>& x, const array<T,N>& y);
85template <class T, size_t N>
86 bool operator>=(const array<T,N>& x, const array<T,N>& y);
Howard Hinnantc51e1022010-05-11 19:42:16 +000087
Howard Hinnant3b6579a2010-08-22 00:02:43 +000088template <class T, size_t N >
Howard Hinnant32477e82011-05-31 21:06:33 +000089 void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +000090
Howard Hinnant3b6579a2010-08-22 00:02:43 +000091template <class T> class tuple_size;
Marshall Clow291a3512015-11-19 19:41:04 +000092template <size_t I, class T> class tuple_element;
Howard Hinnantc51e1022010-05-11 19:42:16 +000093template <class T, size_t N> struct tuple_size<array<T, N>>;
Marshall Clow291a3512015-11-19 19:41:04 +000094template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>;
95template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14
96template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14
97template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14
Eric Fiselier6dea8092015-12-18 00:36:55 +000098template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000099
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 Hinnantc51e1022010-05-11 19:42:16 +0000111
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000112#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000113#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000114#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000115
Eric Fiselierf4433a32017-05-31 22:07:49 +0000116
117
Howard Hinnantc51e1022010-05-11 19:42:16 +0000118_LIBCPP_BEGIN_NAMESPACE_STD
119
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000120template <class _Tp, size_t _Size>
Eric Fiselier55659e42018-02-04 01:03:08 +0000121struct __array_traits {
122 typedef _Tp _StorageT[_Size];
123
124 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier3bad29c2018-02-04 02:17:02 +0000125 static _LIBCPP_CONSTEXPR_AFTER_CXX14 typename remove_const<_Tp>::type*
126 __data(typename remove_const<_StorageT>::type& __store) {
Eric Fiselier55659e42018-02-04 01:03:08 +0000127 return __store;
128 }
129
130 _LIBCPP_INLINE_VISIBILITY
131 static _LIBCPP_CONSTEXPR_AFTER_CXX14 _Tp const* __data(const _StorageT& __store) {
132 return __store;
133 }
134
135 _LIBCPP_INLINE_VISIBILITY
136 static void __swap(_StorageT& __lhs, _StorageT& __rhs) {
137 std::swap_ranges(__lhs, __lhs + _Size, __rhs);
138 }
139
140 _LIBCPP_INLINE_VISIBILITY
141 static void __fill(_StorageT& __arr, _Tp const& __val) {
142 _VSTD::fill_n(__arr, _Size, __val);
143 }
144};
145
146template <class _Tp>
147struct __array_traits<_Tp, 0> {
Eric Fiselier3bad29c2018-02-04 02:17:02 +0000148 typedef typename aligned_storage<sizeof(_Tp), alignment_of<_Tp>::value>::type
149 _NonConstStorageT;
150 typedef typename conditional<is_const<_Tp>::value, const _NonConstStorageT,
151 _NonConstStorageT>::type _StorageT;
Eric Fiselier55659e42018-02-04 01:03:08 +0000152
Eric Fiselier3bad29c2018-02-04 02:17:02 +0000153 typedef typename remove_const<_Tp>::type _NonConstTp;
Eric Fiselier55659e42018-02-04 01:03:08 +0000154 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier3bad29c2018-02-04 02:17:02 +0000155 static _NonConstTp* __data(_NonConstStorageT& __store) {
Eric Fiselier55659e42018-02-04 01:03:08 +0000156 _StorageT *__ptr = std::addressof(__store);
Eric Fiselier3bad29c2018-02-04 02:17:02 +0000157 return reinterpret_cast<_NonConstTp*>(__ptr);
Eric Fiselier55659e42018-02-04 01:03:08 +0000158 }
159
160 _LIBCPP_INLINE_VISIBILITY
161 static const _Tp* __data(const _StorageT& __store) {
162 const _StorageT *__ptr = std::addressof(__store);
163 return reinterpret_cast<const _Tp*>(__ptr);
164 }
165
166 _LIBCPP_INLINE_VISIBILITY
167 static void __swap(_StorageT&, _StorageT&) {}
168
169 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier3bad29c2018-02-04 02:17:02 +0000170 static void __fill(_StorageT&, _Tp const&) {}
Eric Fiselier55659e42018-02-04 01:03:08 +0000171};
172
173template <class _Tp, size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000174struct _LIBCPP_TEMPLATE_VIS array
Howard Hinnantc51e1022010-05-11 19:42:16 +0000175{
176 // types:
177 typedef array __self;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000178 typedef _Tp value_type;
179 typedef value_type& reference;
180 typedef const value_type& const_reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000181 typedef value_type* iterator;
182 typedef const value_type* const_iterator;
183 typedef value_type* pointer;
184 typedef const value_type* const_pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000185 typedef size_t size_type;
186 typedef ptrdiff_t difference_type;
187 typedef std::reverse_iterator<iterator> reverse_iterator;
188 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000189
Eric Fiselier55659e42018-02-04 01:03:08 +0000190 typedef __array_traits<_Tp, _Size> _Traits;
191 typename _Traits::_StorageT __elems_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000192
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000193 // No explicit construct/copy/destroy for aggregate type
Eric Fiselier3bad29c2018-02-04 02:17:02 +0000194 _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) {
195 static_assert(_Size != 0 || !is_const<_Tp>::value,
196 "cannot fill zero-sized array of type 'const T'");
197 _Traits::__fill(__elems_, __u);
198 }
Eric Fiselier55659e42018-02-04 01:03:08 +0000199
Howard Hinnant32477e82011-05-31 21:06:33 +0000200 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier3bad29c2018-02-04 02:17:02 +0000201 void swap(array& __a)
202 _NOEXCEPT_(_Size == 0 || __is_nothrow_swappable<_Tp>::value) {
203 static_assert(_Size != 0 || !is_const<_Tp>::value,
204 "cannot swap zero-sized array of type 'const T'");
205 _Traits::__swap(__elems_, __a.__elems_);
206 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000207
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000208 // iterators:
Marshall Clow99ba0022017-01-04 17:58:17 +0000209 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier55659e42018-02-04 01:03:08 +0000210 iterator begin() _NOEXCEPT {return iterator(data());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000211 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier55659e42018-02-04 01:03:08 +0000212 const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000213 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier55659e42018-02-04 01:03:08 +0000214 iterator end() _NOEXCEPT {return iterator(data() + _Size);}
Marshall Clow99ba0022017-01-04 17:58:17 +0000215 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier55659e42018-02-04 01:03:08 +0000216 const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000217
Marshall Clow99ba0022017-01-04 17:58:17 +0000218 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000219 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000220 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000221 const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000222 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000223 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000224 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000225 const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000226
Marshall Clow99ba0022017-01-04 17:58:17 +0000227 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000228 const_iterator cbegin() const _NOEXCEPT {return begin();}
Marshall Clow99ba0022017-01-04 17:58:17 +0000229 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000230 const_iterator cend() const _NOEXCEPT {return end();}
Marshall Clow99ba0022017-01-04 17:58:17 +0000231 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000232 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Marshall Clow99ba0022017-01-04 17:58:17 +0000233 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000234 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000235
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000236 // capacity:
Howard Hinnant32477e82011-05-31 21:06:33 +0000237 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant12ff42f2012-07-20 19:20:49 +0000238 _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;}
Howard Hinnant32477e82011-05-31 21:06:33 +0000239 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant12ff42f2012-07-20 19:20:49 +0000240 _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
Marshall Clow425f5752017-11-15 05:51:26 +0000241 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant12ff42f2012-07-20 19:20:49 +0000242 _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000243
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000244 // element access:
Marshall Clowac63f412017-01-16 03:02:10 +0000245 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
246 reference operator[](size_type __n) {return __elems_[__n];}
247 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
248 const_reference operator[](size_type __n) const {return __elems_[__n];}
249
250 _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n);
Marshall Clow0abb1042013-07-17 18:25:36 +0000251 _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000252
Marshall Clowac63f412017-01-16 03:02:10 +0000253 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() {return __elems_[0];}
Marshall Clow0abb1042013-07-17 18:25:36 +0000254 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const {return __elems_[0];}
Marshall Clowac63f412017-01-16 03:02:10 +0000255 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() {return __elems_[_Size > 0 ? _Size-1 : 0];}
Marshall Clow0abb1042013-07-17 18:25:36 +0000256 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const {return __elems_[_Size > 0 ? _Size-1 : 0];}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000257
Marshall Clow99ba0022017-01-04 17:58:17 +0000258 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier55659e42018-02-04 01:03:08 +0000259 value_type* data() _NOEXCEPT {return _Traits::__data(__elems_);}
Marshall Clow99ba0022017-01-04 17:58:17 +0000260 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier55659e42018-02-04 01:03:08 +0000261 const value_type* data() const _NOEXCEPT {return _Traits::__data(__elems_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000262};
263
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000264template <class _Tp, size_t _Size>
Marshall Clowac63f412017-01-16 03:02:10 +0000265_LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000266typename array<_Tp, _Size>::reference
267array<_Tp, _Size>::at(size_type __n)
268{
269 if (__n >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +0000270 __throw_out_of_range("array::at");
271
Howard Hinnantc51e1022010-05-11 19:42:16 +0000272 return __elems_[__n];
273}
274
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000275template <class _Tp, size_t _Size>
Marshall Clow0abb1042013-07-17 18:25:36 +0000276_LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000277typename array<_Tp, _Size>::const_reference
278array<_Tp, _Size>::at(size_type __n) const
279{
280 if (__n >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +0000281 __throw_out_of_range("array::at");
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282 return __elems_[__n];
283}
284
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000285template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000286inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000287bool
288operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
289{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000290 return _VSTD::equal(__x.__elems_, __x.__elems_ + _Size, __y.__elems_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000291}
292
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000293template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000294inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295bool
296operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
297{
298 return !(__x == __y);
299}
300
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000301template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000302inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000303bool
304operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
305{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000306 return _VSTD::lexicographical_compare(__x.__elems_, __x.__elems_ + _Size, __y.__elems_, __y.__elems_ + _Size);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000307}
308
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000309template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000310inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000311bool
312operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
313{
314 return __y < __x;
315}
316
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000317template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000318inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000319bool
320operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
321{
322 return !(__y < __x);
323}
324
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000325template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000326inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327bool
328operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
329{
330 return !(__x < __y);
331}
332
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000333template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000334inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant44267242011-06-01 19:59:32 +0000335typename enable_if
336<
Eric Fiselier6bfed252016-04-21 23:38:59 +0000337 _Size == 0 ||
Howard Hinnant44267242011-06-01 19:59:32 +0000338 __is_swappable<_Tp>::value,
339 void
340>::type
Marshall Clowff1aa3d2016-03-07 21:57:10 +0000341swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
Eric Fiselier6bfed252016-04-21 23:38:59 +0000342 _NOEXCEPT_(noexcept(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000343{
344 __x.swap(__y);
345}
346
347template <class _Tp, size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000348class _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
Howard Hinnant8e29cda2010-09-21 20:16:37 +0000349 : public integral_constant<size_t, _Size> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000350
Howard Hinnantc51e1022010-05-11 19:42:16 +0000351template <size_t _Ip, class _Tp, size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000352class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000353{
Marshall Clow6f77fa12017-06-12 14:41:37 +0000354 static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
Howard Hinnantc51e1022010-05-11 19:42:16 +0000355public:
356 typedef _Tp type;
357};
358
359template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000360inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000361_Tp&
Howard Hinnant32477e82011-05-31 21:06:33 +0000362get(array<_Tp, _Size>& __a) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000363{
Marshall Clow66c49ca2012-12-18 16:46:30 +0000364 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
Marshall Clow0abb1042013-07-17 18:25:36 +0000365 return __a.__elems_[_Ip];
Howard Hinnantc51e1022010-05-11 19:42:16 +0000366}
367
368template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000369inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370const _Tp&
Howard Hinnant32477e82011-05-31 21:06:33 +0000371get(const array<_Tp, _Size>& __a) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000372{
Marshall Clow66c49ca2012-12-18 16:46:30 +0000373 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
Marshall Clow0abb1042013-07-17 18:25:36 +0000374 return __a.__elems_[_Ip];
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375}
376
Eric Fiselier73abed72017-04-16 02:50:40 +0000377#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000378
379template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000380inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant22e97242010-11-17 19:52:17 +0000381_Tp&&
Howard Hinnant32477e82011-05-31 21:06:33 +0000382get(array<_Tp, _Size>&& __a) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +0000383{
Marshall Clow66c49ca2012-12-18 16:46:30 +0000384 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
Marshall Clow0abb1042013-07-17 18:25:36 +0000385 return _VSTD::move(__a.__elems_[_Ip]);
Howard Hinnant22e97242010-11-17 19:52:17 +0000386}
387
Eric Fiselier6dea8092015-12-18 00:36:55 +0000388template <size_t _Ip, class _Tp, size_t _Size>
389inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
390const _Tp&&
391get(const array<_Tp, _Size>&& __a) _NOEXCEPT
392{
393 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
394 return _VSTD::move(__a.__elems_[_Ip]);
395}
396
Eric Fiselier73abed72017-04-16 02:50:40 +0000397#endif // !_LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000398
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399_LIBCPP_END_NAMESPACE_STD
400
401#endif // _LIBCPP_ARRAY