blob: 165ffad6b8b1bd21b33154b50df1cd3a34fa846a [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- array -----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-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 Hinnantbc8d3f92010-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 Hinnant324bb032010-08-22 00:02:43 +000019template <class T, size_t N >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000020struct array
Howard Hinnant324bb032010-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 Hinnantbc8d3f92010-05-11 19:42:16 +000030 typedef T* pointer;
31 typedef const T* const_pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +000032 typedef std::reverse_iterator<iterator> reverse_iterator;
33 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000034
Howard Hinnant324bb032010-08-22 00:02:43 +000035 // No explicit construct/copy/destroy for aggregate type
36 void fill(const T& u);
Eric Fiselier8f1e73d2016-04-21 23:38:59 +000037 void swap(array& a) noexcept(is_nothrow_swappable_v<T>);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000038
Howard Hinnant324bb032010-08-22 00:02:43 +000039 // iterators:
Howard Hinnantf0562af2011-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 Hinnantbc8d3f92010-05-11 19:42:16 +000044
Howard Hinnantf0562af2011-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 Hinnantbc8d3f92010-05-11 19:42:16 +000049
Howard Hinnantf0562af2011-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 Hinnantbc8d3f92010-05-11 19:42:16 +000054
Howard Hinnant324bb032010-08-22 00:02:43 +000055 // capacity:
Howard Hinnantf0562af2011-05-31 21:06:33 +000056 constexpr size_type size() const noexcept;
57 constexpr size_type max_size() const noexcept;
Howard Hinnant08bce172012-07-20 19:20:49 +000058 constexpr bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000059
Howard Hinnant324bb032010-08-22 00:02:43 +000060 // element access:
61 reference operator[](size_type n);
Marshall Clow8fc4f5a2013-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 Hinnant324bb032010-08-22 00:02:43 +000064 reference at(size_type n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000065
Howard Hinnant324bb032010-08-22 00:02:43 +000066 reference front();
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000067 const_reference front() const; // constexpr in C++14
Howard Hinnant324bb032010-08-22 00:02:43 +000068 reference back();
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000069 const_reference back() const; // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000070
Howard Hinnantf0562af2011-05-31 21:06:33 +000071 T* data() noexcept;
72 const T* data() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000073};
74
Howard Hinnant324bb032010-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 Hinnantbc8d3f92010-05-11 19:42:16 +000087
Howard Hinnant324bb032010-08-22 00:02:43 +000088template <class T, size_t N >
Howard Hinnantf0562af2011-05-31 21:06:33 +000089 void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000090
Howard Hinnant324bb032010-08-22 00:02:43 +000091template <class T> class tuple_size;
Marshall Clowd8717282015-11-19 19:41:04 +000092template <size_t I, class T> class tuple_element;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000093template <class T, size_t N> struct tuple_size<array<T, N>>;
Marshall Clowd8717282015-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 Fiselier199bee02015-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 Hinnantbc8d3f92010-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 Hinnantbc8d3f92010-05-11 19:42:16 +0000111
Howard Hinnant08e17472011-10-17 20:05:10 +0000112#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000113#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000114#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000115
116_LIBCPP_BEGIN_NAMESPACE_STD
117
Howard Hinnant324bb032010-08-22 00:02:43 +0000118template <class _Tp, size_t _Size>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000119struct _LIBCPP_TEMPLATE_VIS array
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120{
121 // types:
122 typedef array __self;
Howard Hinnant324bb032010-08-22 00:02:43 +0000123 typedef _Tp value_type;
124 typedef value_type& reference;
125 typedef const value_type& const_reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000126 typedef value_type* iterator;
127 typedef const value_type* const_iterator;
128 typedef value_type* pointer;
129 typedef const value_type* const_pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +0000130 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 Hinnantbc8d3f92010-05-11 19:42:16 +0000134
135 value_type __elems_[_Size > 0 ? _Size : 1];
136
Howard Hinnant324bb032010-08-22 00:02:43 +0000137 // No explicit construct/copy/destroy for aggregate type
Howard Hinnant333f50d2010-09-21 20:16:37 +0000138 _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000139 {_VSTD::fill_n(__elems_, _Size, __u);}
Howard Hinnantf0562af2011-05-31 21:06:33 +0000140 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8f1e73d2016-04-21 23:38:59 +0000141 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 Hinnantbc8d3f92010-05-11 19:42:16 +0000150
Howard Hinnant324bb032010-08-22 00:02:43 +0000151 // iterators:
Marshall Clowe22af6b2017-01-04 17:58:17 +0000152 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000153 iterator begin() _NOEXCEPT {return iterator(__elems_);}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000154 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000155 const_iterator begin() const _NOEXCEPT {return const_iterator(__elems_);}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000156 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000157 iterator end() _NOEXCEPT {return iterator(__elems_ + _Size);}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000158 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000159 const_iterator end() const _NOEXCEPT {return const_iterator(__elems_ + _Size);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000160
Marshall Clowe22af6b2017-01-04 17:58:17 +0000161 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000162 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000163 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000164 const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000165 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000166 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000167 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000168 const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000169
Marshall Clowe22af6b2017-01-04 17:58:17 +0000170 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000171 const_iterator cbegin() const _NOEXCEPT {return begin();}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000172 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000173 const_iterator cend() const _NOEXCEPT {return end();}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000174 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000175 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000176 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000177 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000178
Howard Hinnant324bb032010-08-22 00:02:43 +0000179 // capacity:
Howard Hinnantf0562af2011-05-31 21:06:33 +0000180 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08bce172012-07-20 19:20:49 +0000181 _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;}
Howard Hinnantf0562af2011-05-31 21:06:33 +0000182 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08bce172012-07-20 19:20:49 +0000183 _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
Howard Hinnantf0562af2011-05-31 21:06:33 +0000184 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08bce172012-07-20 19:20:49 +0000185 _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000186
Howard Hinnant324bb032010-08-22 00:02:43 +0000187 // element access:
Marshall Clowd25c9972017-01-16 03:02:10 +0000188 _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 Clow8fc4f5a2013-07-17 18:25:36 +0000194 _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000195
Marshall Clowd25c9972017-01-16 03:02:10 +0000196 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() {return __elems_[0];}
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000197 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const {return __elems_[0];}
Marshall Clowd25c9972017-01-16 03:02:10 +0000198 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() {return __elems_[_Size > 0 ? _Size-1 : 0];}
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000199 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const {return __elems_[_Size > 0 ? _Size-1 : 0];}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000200
Marshall Clowe22af6b2017-01-04 17:58:17 +0000201 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000202 value_type* data() _NOEXCEPT {return __elems_;}
Marshall Clowe22af6b2017-01-04 17:58:17 +0000203 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantf0562af2011-05-31 21:06:33 +0000204 const value_type* data() const _NOEXCEPT {return __elems_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000205};
206
Howard Hinnant324bb032010-08-22 00:02:43 +0000207template <class _Tp, size_t _Size>
Marshall Clowd25c9972017-01-16 03:02:10 +0000208_LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000209typename array<_Tp, _Size>::reference
210array<_Tp, _Size>::at(size_type __n)
211{
212 if (__n >= _Size)
Marshall Clow14c09a22016-08-25 15:09:01 +0000213 __throw_out_of_range("array::at");
214
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000215 return __elems_[__n];
216}
217
Howard Hinnant324bb032010-08-22 00:02:43 +0000218template <class _Tp, size_t _Size>
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000219_LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000220typename array<_Tp, _Size>::const_reference
221array<_Tp, _Size>::at(size_type __n) const
222{
223 if (__n >= _Size)
Marshall Clow14c09a22016-08-25 15:09:01 +0000224 __throw_out_of_range("array::at");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000225 return __elems_[__n];
226}
227
Howard Hinnant324bb032010-08-22 00:02:43 +0000228template <class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000229inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000230bool
231operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
232{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000233 return _VSTD::equal(__x.__elems_, __x.__elems_ + _Size, __y.__elems_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000234}
235
Howard Hinnant324bb032010-08-22 00:02:43 +0000236template <class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000237inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000238bool
239operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
240{
241 return !(__x == __y);
242}
243
Howard Hinnant324bb032010-08-22 00:02:43 +0000244template <class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000245inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000246bool
247operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
248{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000249 return _VSTD::lexicographical_compare(__x.__elems_, __x.__elems_ + _Size, __y.__elems_, __y.__elems_ + _Size);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000250}
251
Howard Hinnant324bb032010-08-22 00:02:43 +0000252template <class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000253inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000254bool
255operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
256{
257 return __y < __x;
258}
259
Howard Hinnant324bb032010-08-22 00:02:43 +0000260template <class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000261inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000262bool
263operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
264{
265 return !(__y < __x);
266}
267
Howard Hinnant324bb032010-08-22 00:02:43 +0000268template <class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000269inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000270bool
271operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
272{
273 return !(__x < __y);
274}
275
Howard Hinnant324bb032010-08-22 00:02:43 +0000276template <class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000277inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaabf2872011-06-01 19:59:32 +0000278typename enable_if
279<
Eric Fiselier8f1e73d2016-04-21 23:38:59 +0000280 _Size == 0 ||
Howard Hinnantaabf2872011-06-01 19:59:32 +0000281 __is_swappable<_Tp>::value,
282 void
283>::type
Marshall Clow8d48d9b2016-03-07 21:57:10 +0000284swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
Eric Fiselier8f1e73d2016-04-21 23:38:59 +0000285 _NOEXCEPT_(noexcept(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000286{
287 __x.swap(__y);
288}
289
290template <class _Tp, size_t _Size>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000291class _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
Howard Hinnant333f50d2010-09-21 20:16:37 +0000292 : public integral_constant<size_t, _Size> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000293
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000294template <size_t _Ip, class _Tp, size_t _Size>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000295class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000296{
297public:
298 typedef _Tp type;
299};
300
301template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000302inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000303_Tp&
Howard Hinnantf0562af2011-05-31 21:06:33 +0000304get(array<_Tp, _Size>& __a) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000305{
Marshall Clowa46482e2012-12-18 16:46:30 +0000306 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000307 return __a.__elems_[_Ip];
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000308}
309
310template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000311inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000312const _Tp&
Howard Hinnantf0562af2011-05-31 21:06:33 +0000313get(const array<_Tp, _Size>& __a) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000314{
Marshall Clowa46482e2012-12-18 16:46:30 +0000315 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000316 return __a.__elems_[_Ip];
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000317}
318
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000319#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
320
321template <size_t _Ip, class _Tp, size_t _Size>
Howard Hinnant1e564242013-10-04 22:09:00 +0000322inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000323_Tp&&
Howard Hinnantf0562af2011-05-31 21:06:33 +0000324get(array<_Tp, _Size>&& __a) _NOEXCEPT
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000325{
Marshall Clowa46482e2012-12-18 16:46:30 +0000326 static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
Marshall Clow8fc4f5a2013-07-17 18:25:36 +0000327 return _VSTD::move(__a.__elems_[_Ip]);
Howard Hinnantcd2254b2010-11-17 19:52:17 +0000328}
329
Eric Fiselier199bee02015-12-18 00:36:55 +0000330template <size_t _Ip, class _Tp, size_t _Size>
331inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
332const _Tp&&
333get(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 Hinnantcd2254b2010-11-17 19:52:17 +0000339#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
340
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000341_LIBCPP_END_NAMESPACE_STD
342
343#endif // _LIBCPP_ARRAY