blob: 068ab506a337ebe45058934a4aa2cdac63e97b91 [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
Eric Fiselier9c21a342018-02-04 08:02:35 +0000149 _NonConstStorageT[1];
Eric Fiselier3bad29c2018-02-04 02:17:02 +0000150 typedef typename conditional<is_const<_Tp>::value, const _NonConstStorageT,
151 _NonConstStorageT>::type _StorageT;
Eric Fiselier3bad29c2018-02-04 02:17:02 +0000152 typedef typename remove_const<_Tp>::type _NonConstTp;
Eric Fiselier9c21a342018-02-04 08:02:35 +0000153
Eric Fiselier55659e42018-02-04 01:03:08 +0000154 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier9c21a342018-02-04 08:02:35 +0000155 static _NonConstTp* __data(_NonConstStorageT &__store) {
156 return reinterpret_cast<_NonConstTp*>(__store);
Eric Fiselier55659e42018-02-04 01:03:08 +0000157 }
158
159 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier9c21a342018-02-04 08:02:35 +0000160 static const _Tp* __data(const _StorageT &__store) {
161 return reinterpret_cast<const _Tp*>(__store);
Eric Fiselier55659e42018-02-04 01:03:08 +0000162 }
163
164 _LIBCPP_INLINE_VISIBILITY
165 static void __swap(_StorageT&, _StorageT&) {}
166
167 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier3bad29c2018-02-04 02:17:02 +0000168 static void __fill(_StorageT&, _Tp const&) {}
Eric Fiselier55659e42018-02-04 01:03:08 +0000169};
170
171template <class _Tp, size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000172struct _LIBCPP_TEMPLATE_VIS array
Howard Hinnantc51e1022010-05-11 19:42:16 +0000173{
174 // types:
175 typedef array __self;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000176 typedef _Tp value_type;
177 typedef value_type& reference;
178 typedef const value_type& const_reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000179 typedef value_type* iterator;
180 typedef const value_type* const_iterator;
181 typedef value_type* pointer;
182 typedef const value_type* const_pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000183 typedef size_t size_type;
184 typedef ptrdiff_t difference_type;
185 typedef std::reverse_iterator<iterator> reverse_iterator;
186 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000187
Eric Fiselier55659e42018-02-04 01:03:08 +0000188 typedef __array_traits<_Tp, _Size> _Traits;
189 typename _Traits::_StorageT __elems_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000190
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000191 // No explicit construct/copy/destroy for aggregate type
Eric Fiselier3bad29c2018-02-04 02:17:02 +0000192 _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) {
193 static_assert(_Size != 0 || !is_const<_Tp>::value,
194 "cannot fill zero-sized array of type 'const T'");
195 _Traits::__fill(__elems_, __u);
196 }
Eric Fiselier55659e42018-02-04 01:03:08 +0000197
Howard Hinnant32477e82011-05-31 21:06:33 +0000198 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier3bad29c2018-02-04 02:17:02 +0000199 void swap(array& __a)
200 _NOEXCEPT_(_Size == 0 || __is_nothrow_swappable<_Tp>::value) {
201 static_assert(_Size != 0 || !is_const<_Tp>::value,
202 "cannot swap zero-sized array of type 'const T'");
203 _Traits::__swap(__elems_, __a.__elems_);
204 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000205
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000206 // iterators:
Marshall Clow99ba0022017-01-04 17:58:17 +0000207 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier55659e42018-02-04 01:03:08 +0000208 iterator begin() _NOEXCEPT {return iterator(data());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000209 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier55659e42018-02-04 01:03:08 +0000210 const_iterator begin() const _NOEXCEPT {return const_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 iterator end() _NOEXCEPT {return iterator(data() + _Size);}
Marshall Clow99ba0022017-01-04 17:58:17 +0000213 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier55659e42018-02-04 01:03:08 +0000214 const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000215
Marshall Clow99ba0022017-01-04 17:58:17 +0000216 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000217 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000218 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000219 const_reverse_iterator rbegin() const _NOEXCEPT {return const_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 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000222 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000223 const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000224
Marshall Clow99ba0022017-01-04 17:58:17 +0000225 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000226 const_iterator cbegin() const _NOEXCEPT {return begin();}
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 cend() const _NOEXCEPT {return end();}
Marshall Clow99ba0022017-01-04 17:58:17 +0000229 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000230 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
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 crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000233
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000234 // capacity:
Howard Hinnant32477e82011-05-31 21:06:33 +0000235 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant12ff42f2012-07-20 19:20:49 +0000236 _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;}
Howard Hinnant32477e82011-05-31 21:06:33 +0000237 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant12ff42f2012-07-20 19:20:49 +0000238 _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
Marshall Clow425f5752017-11-15 05:51:26 +0000239 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant12ff42f2012-07-20 19:20:49 +0000240 _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000241
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000242 // element access:
Marshall Clowac63f412017-01-16 03:02:10 +0000243 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
244 reference operator[](size_type __n) {return __elems_[__n];}
245 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
246 const_reference operator[](size_type __n) const {return __elems_[__n];}
247
248 _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n);
Marshall Clow0abb1042013-07-17 18:25:36 +0000249 _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000250
Marshall Clowac63f412017-01-16 03:02:10 +0000251 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() {return __elems_[0];}
Marshall Clow0abb1042013-07-17 18:25:36 +0000252 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const {return __elems_[0];}
Marshall Clowac63f412017-01-16 03:02:10 +0000253 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() {return __elems_[_Size > 0 ? _Size-1 : 0];}
Marshall Clow0abb1042013-07-17 18:25:36 +0000254 _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 +0000255
Marshall Clow99ba0022017-01-04 17:58:17 +0000256 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier55659e42018-02-04 01:03:08 +0000257 value_type* data() _NOEXCEPT {return _Traits::__data(__elems_);}
Marshall Clow99ba0022017-01-04 17:58:17 +0000258 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier55659e42018-02-04 01:03:08 +0000259 const value_type* data() const _NOEXCEPT {return _Traits::__data(__elems_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000260};
261
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000262template <class _Tp, size_t _Size>
Marshall Clowac63f412017-01-16 03:02:10 +0000263_LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264typename array<_Tp, _Size>::reference
265array<_Tp, _Size>::at(size_type __n)
266{
267 if (__n >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +0000268 __throw_out_of_range("array::at");
269
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270 return __elems_[__n];
271}
272
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000273template <class _Tp, size_t _Size>
Marshall Clow0abb1042013-07-17 18:25:36 +0000274_LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275typename array<_Tp, _Size>::const_reference
276array<_Tp, _Size>::at(size_type __n) const
277{
278 if (__n >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +0000279 __throw_out_of_range("array::at");
Howard Hinnantc51e1022010-05-11 19:42:16 +0000280 return __elems_[__n];
281}
282
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000283template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000284inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000285bool
286operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
287{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000288 return _VSTD::equal(__x.__elems_, __x.__elems_ + _Size, __y.__elems_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289}
290
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000291template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000292inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000293bool
294operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
295{
296 return !(__x == __y);
297}
298
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000299template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000300inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000301bool
302operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
303{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000304 return _VSTD::lexicographical_compare(__x.__elems_, __x.__elems_ + _Size, __y.__elems_, __y.__elems_ + _Size);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000305}
306
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000307template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000308inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000309bool
310operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
311{
312 return __y < __x;
313}
314
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000315template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000316inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000317bool
318operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
319{
320 return !(__y < __x);
321}
322
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000323template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000324inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000325bool
326operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
327{
328 return !(__x < __y);
329}
330
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000331template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000332inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant44267242011-06-01 19:59:32 +0000333typename enable_if
334<
Eric Fiselier6bfed252016-04-21 23:38:59 +0000335 _Size == 0 ||
Howard Hinnant44267242011-06-01 19:59:32 +0000336 __is_swappable<_Tp>::value,
337 void
338>::type
Marshall Clowff1aa3d2016-03-07 21:57:10 +0000339swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
Eric Fiselier6bfed252016-04-21 23:38:59 +0000340 _NOEXCEPT_(noexcept(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000341{
342 __x.swap(__y);
343}
344
345template <class _Tp, size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000346class _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
Howard Hinnant8e29cda2010-09-21 20:16:37 +0000347 : public integral_constant<size_t, _Size> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348
Howard Hinnantc51e1022010-05-11 19:42:16 +0000349template <size_t _Ip, class _Tp, size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000350class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000351{
Marshall Clow6f77fa12017-06-12 14:41:37 +0000352 static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
Howard Hinnantc51e1022010-05-11 19:42:16 +0000353public:
354 typedef _Tp type;
355};
356
357template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000358inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000359_Tp&
Howard Hinnant32477e82011-05-31 21:06:33 +0000360get(array<_Tp, _Size>& __a) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000361{
Marshall Clow66c49ca2012-12-18 16:46:30 +0000362 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
Marshall Clow0abb1042013-07-17 18:25:36 +0000363 return __a.__elems_[_Ip];
Howard Hinnantc51e1022010-05-11 19:42:16 +0000364}
365
366template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000367inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000368const _Tp&
Howard Hinnant32477e82011-05-31 21:06:33 +0000369get(const array<_Tp, _Size>& __a) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370{
Marshall Clow66c49ca2012-12-18 16:46:30 +0000371 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
Marshall Clow0abb1042013-07-17 18:25:36 +0000372 return __a.__elems_[_Ip];
Howard Hinnantc51e1022010-05-11 19:42:16 +0000373}
374
Eric Fiselier73abed72017-04-16 02:50:40 +0000375#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000376
377template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000378inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant22e97242010-11-17 19:52:17 +0000379_Tp&&
Howard Hinnant32477e82011-05-31 21:06:33 +0000380get(array<_Tp, _Size>&& __a) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +0000381{
Marshall Clow66c49ca2012-12-18 16:46:30 +0000382 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
Marshall Clow0abb1042013-07-17 18:25:36 +0000383 return _VSTD::move(__a.__elems_[_Ip]);
Howard Hinnant22e97242010-11-17 19:52:17 +0000384}
385
Eric Fiselier6dea8092015-12-18 00:36:55 +0000386template <size_t _Ip, class _Tp, size_t _Size>
387inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
388const _Tp&&
389get(const array<_Tp, _Size>&& __a) _NOEXCEPT
390{
391 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
392 return _VSTD::move(__a.__elems_[_Ip]);
393}
394
Eric Fiselier73abed72017-04-16 02:50:40 +0000395#endif // !_LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000396
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397_LIBCPP_END_NAMESPACE_STD
398
399#endif // _LIBCPP_ARRAY