blob: 8cd3ecdf9e78bfa4a57772202d4d87ff14d6446e [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
125 static _LIBCPP_CONSTEXPR_AFTER_CXX14 _Tp* __data(_StorageT& __store) {
126 return __store;
127 }
128
129 _LIBCPP_INLINE_VISIBILITY
130 static _LIBCPP_CONSTEXPR_AFTER_CXX14 _Tp const* __data(const _StorageT& __store) {
131 return __store;
132 }
133
134 _LIBCPP_INLINE_VISIBILITY
135 static void __swap(_StorageT& __lhs, _StorageT& __rhs) {
136 std::swap_ranges(__lhs, __lhs + _Size, __rhs);
137 }
138
139 _LIBCPP_INLINE_VISIBILITY
140 static void __fill(_StorageT& __arr, _Tp const& __val) {
141 _VSTD::fill_n(__arr, _Size, __val);
142 }
143};
144
145template <class _Tp>
146struct __array_traits<_Tp, 0> {
147 typedef typename aligned_storage<sizeof(_Tp), alignment_of<_Tp>::value>::type _StorageT;
148
149 _LIBCPP_INLINE_VISIBILITY
150 static _Tp* __data(_StorageT& __store) {
151 _StorageT *__ptr = std::addressof(__store);
152 return reinterpret_cast<_Tp*>(__ptr);
153 }
154
155 _LIBCPP_INLINE_VISIBILITY
156 static const _Tp* __data(const _StorageT& __store) {
157 const _StorageT *__ptr = std::addressof(__store);
158 return reinterpret_cast<const _Tp*>(__ptr);
159 }
160
161 _LIBCPP_INLINE_VISIBILITY
162 static void __swap(_StorageT&, _StorageT&) {}
163
164 _LIBCPP_INLINE_VISIBILITY
165 static void __fill(_StorageT&, _Tp const&) {
166 }
167};
168
169template <class _Tp, size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000170struct _LIBCPP_TEMPLATE_VIS array
Howard Hinnantc51e1022010-05-11 19:42:16 +0000171{
172 // types:
173 typedef array __self;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000174 typedef _Tp value_type;
175 typedef value_type& reference;
176 typedef const value_type& const_reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000177 typedef value_type* iterator;
178 typedef const value_type* const_iterator;
179 typedef value_type* pointer;
180 typedef const value_type* const_pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000181 typedef size_t size_type;
182 typedef ptrdiff_t difference_type;
183 typedef std::reverse_iterator<iterator> reverse_iterator;
184 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185
Eric Fiselier55659e42018-02-04 01:03:08 +0000186 typedef __array_traits<_Tp, _Size> _Traits;
187 typename _Traits::_StorageT __elems_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000188
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000189 // No explicit construct/copy/destroy for aggregate type
Howard Hinnant8e29cda2010-09-21 20:16:37 +0000190 _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u)
Eric Fiselier55659e42018-02-04 01:03:08 +0000191 {_Traits::__fill(__elems_, __u);}
192
Howard Hinnant32477e82011-05-31 21:06:33 +0000193 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6bfed252016-04-21 23:38:59 +0000194 void swap(array& __a) _NOEXCEPT_(_Size == 0 || __is_nothrow_swappable<_Tp>::value)
Eric Fiselier55659e42018-02-04 01:03:08 +0000195 { _Traits::__swap(__elems_, __a.__elems_); }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000196
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000197 // iterators:
Marshall Clow99ba0022017-01-04 17:58:17 +0000198 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier55659e42018-02-04 01:03:08 +0000199 iterator begin() _NOEXCEPT {return iterator(data());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000200 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier55659e42018-02-04 01:03:08 +0000201 const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000202 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier55659e42018-02-04 01:03:08 +0000203 iterator end() _NOEXCEPT {return iterator(data() + _Size);}
Marshall Clow99ba0022017-01-04 17:58:17 +0000204 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier55659e42018-02-04 01:03:08 +0000205 const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000206
Marshall Clow99ba0022017-01-04 17:58:17 +0000207 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000208 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000209 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000210 const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000211 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000212 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Marshall Clow99ba0022017-01-04 17:58:17 +0000213 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000214 const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
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 const_iterator cbegin() const _NOEXCEPT {return begin();}
Marshall Clow99ba0022017-01-04 17:58:17 +0000218 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnant32477e82011-05-31 21:06:33 +0000219 const_iterator cend() const _NOEXCEPT {return 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 crbegin() const _NOEXCEPT {return rbegin();}
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 crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000224
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000225 // capacity:
Howard Hinnant32477e82011-05-31 21:06:33 +0000226 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant12ff42f2012-07-20 19:20:49 +0000227 _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;}
Howard Hinnant32477e82011-05-31 21:06:33 +0000228 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant12ff42f2012-07-20 19:20:49 +0000229 _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
Marshall Clow425f5752017-11-15 05:51:26 +0000230 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant12ff42f2012-07-20 19:20:49 +0000231 _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000232
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000233 // element access:
Marshall Clowac63f412017-01-16 03:02:10 +0000234 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
235 reference operator[](size_type __n) {return __elems_[__n];}
236 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
237 const_reference operator[](size_type __n) const {return __elems_[__n];}
238
239 _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n);
Marshall Clow0abb1042013-07-17 18:25:36 +0000240 _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000241
Marshall Clowac63f412017-01-16 03:02:10 +0000242 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() {return __elems_[0];}
Marshall Clow0abb1042013-07-17 18:25:36 +0000243 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const {return __elems_[0];}
Marshall Clowac63f412017-01-16 03:02:10 +0000244 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() {return __elems_[_Size > 0 ? _Size-1 : 0];}
Marshall Clow0abb1042013-07-17 18:25:36 +0000245 _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 +0000246
Marshall Clow99ba0022017-01-04 17:58:17 +0000247 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier55659e42018-02-04 01:03:08 +0000248 value_type* data() _NOEXCEPT {return _Traits::__data(__elems_);}
Marshall Clow99ba0022017-01-04 17:58:17 +0000249 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier55659e42018-02-04 01:03:08 +0000250 const value_type* data() const _NOEXCEPT {return _Traits::__data(__elems_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000251};
252
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000253template <class _Tp, size_t _Size>
Marshall Clowac63f412017-01-16 03:02:10 +0000254_LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000255typename array<_Tp, _Size>::reference
256array<_Tp, _Size>::at(size_type __n)
257{
258 if (__n >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +0000259 __throw_out_of_range("array::at");
260
Howard Hinnantc51e1022010-05-11 19:42:16 +0000261 return __elems_[__n];
262}
263
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000264template <class _Tp, size_t _Size>
Marshall Clow0abb1042013-07-17 18:25:36 +0000265_LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000266typename array<_Tp, _Size>::const_reference
267array<_Tp, _Size>::at(size_type __n) const
268{
269 if (__n >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +0000270 __throw_out_of_range("array::at");
Howard Hinnantc51e1022010-05-11 19:42:16 +0000271 return __elems_[__n];
272}
273
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000274template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000275inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000276bool
277operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
278{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000279 return _VSTD::equal(__x.__elems_, __x.__elems_ + _Size, __y.__elems_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000280}
281
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000282template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000283inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284bool
285operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
286{
287 return !(__x == __y);
288}
289
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000290template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000291inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000292bool
293operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
294{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000295 return _VSTD::lexicographical_compare(__x.__elems_, __x.__elems_ + _Size, __y.__elems_, __y.__elems_ + _Size);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296}
297
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000298template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000299inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000300bool
301operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
302{
303 return __y < __x;
304}
305
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000306template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000307inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000308bool
309operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
310{
311 return !(__y < __x);
312}
313
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000314template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000315inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000316bool
317operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
318{
319 return !(__x < __y);
320}
321
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000322template <class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000323inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant44267242011-06-01 19:59:32 +0000324typename enable_if
325<
Eric Fiselier6bfed252016-04-21 23:38:59 +0000326 _Size == 0 ||
Howard Hinnant44267242011-06-01 19:59:32 +0000327 __is_swappable<_Tp>::value,
328 void
329>::type
Marshall Clowff1aa3d2016-03-07 21:57:10 +0000330swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
Eric Fiselier6bfed252016-04-21 23:38:59 +0000331 _NOEXCEPT_(noexcept(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000332{
333 __x.swap(__y);
334}
335
336template <class _Tp, size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000337class _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
Howard Hinnant8e29cda2010-09-21 20:16:37 +0000338 : public integral_constant<size_t, _Size> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000339
Howard Hinnantc51e1022010-05-11 19:42:16 +0000340template <size_t _Ip, class _Tp, size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000341class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
Howard Hinnantc51e1022010-05-11 19:42:16 +0000342{
Marshall Clow6f77fa12017-06-12 14:41:37 +0000343 static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
Howard Hinnantc51e1022010-05-11 19:42:16 +0000344public:
345 typedef _Tp type;
346};
347
348template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnantb8a8ca22013-10-04 22:09:00 +0000349inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc51e1022010-05-11 19:42:16 +0000350_Tp&
Howard Hinnant32477e82011-05-31 21:06:33 +0000351get(array<_Tp, _Size>& __a) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000352{
Marshall Clow66c49ca2012-12-18 16:46:30 +0000353 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
Marshall Clow0abb1042013-07-17 18:25:36 +0000354 return __a.__elems_[_Ip];
Howard Hinnantc51e1022010-05-11 19:42:16 +0000355}
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 +0000359const _Tp&
Howard Hinnant32477e82011-05-31 21:06:33 +0000360get(const 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<> (const std::array)");
Marshall Clow0abb1042013-07-17 18:25:36 +0000363 return __a.__elems_[_Ip];
Howard Hinnantc51e1022010-05-11 19:42:16 +0000364}
365
Eric Fiselier73abed72017-04-16 02:50:40 +0000366#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000367
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 Hinnant22e97242010-11-17 19:52:17 +0000370_Tp&&
Howard Hinnant32477e82011-05-31 21:06:33 +0000371get(array<_Tp, _Size>&& __a) _NOEXCEPT
Howard Hinnant22e97242010-11-17 19:52:17 +0000372{
Marshall Clow66c49ca2012-12-18 16:46:30 +0000373 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
Marshall Clow0abb1042013-07-17 18:25:36 +0000374 return _VSTD::move(__a.__elems_[_Ip]);
Howard Hinnant22e97242010-11-17 19:52:17 +0000375}
376
Eric Fiselier6dea8092015-12-18 00:36:55 +0000377template <size_t _Ip, class _Tp, size_t _Size>
378inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
379const _Tp&&
380get(const array<_Tp, _Size>&& __a) _NOEXCEPT
381{
382 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
383 return _VSTD::move(__a.__elems_[_Ip]);
384}
385
Eric Fiselier73abed72017-04-16 02:50:40 +0000386#endif // !_LIBCPP_CXX03_LANG
Howard Hinnant22e97242010-11-17 19:52:17 +0000387
Howard Hinnantc51e1022010-05-11 19:42:16 +0000388_LIBCPP_END_NAMESPACE_STD
389
390#endif // _LIBCPP_ARRAY