@@ -32,71 +32,76 @@ struct array
32
32
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
33
33
34
34
// No explicit construct/copy/destroy for aggregate type
35
- void fill(const T& u);
36
- void swap(array& a) noexcept(is_nothrow_swappable_v<T>);
35
+ void fill(const T& u); // constexpr in C++20
36
+ void swap(array& a) noexcept(is_nothrow_swappable_v<T>); // constexpr in C++20
37
37
38
38
// iterators:
39
- iterator begin() noexcept;
40
- const_iterator begin() const noexcept;
41
- iterator end() noexcept;
42
- const_iterator end() const noexcept;
39
+ iterator begin() noexcept; // constexpr in C++17
40
+ const_iterator begin() const noexcept; // constexpr in C++17
41
+ iterator end() noexcept; // constexpr in C++17
42
+ const_iterator end() const noexcept; // constexpr in C++17
43
43
44
- reverse_iterator rbegin() noexcept;
45
- const_reverse_iterator rbegin() const noexcept;
46
- reverse_iterator rend() noexcept;
47
- const_reverse_iterator rend() const noexcept;
44
+ reverse_iterator rbegin() noexcept; // constexpr in C++17
45
+ const_reverse_iterator rbegin() const noexcept; // constexpr in C++17
46
+ reverse_iterator rend() noexcept; // constexpr in C++17
47
+ const_reverse_iterator rend() const noexcept; // constexpr in C++17
48
48
49
- const_iterator cbegin() const noexcept;
50
- const_iterator cend() const noexcept;
51
- const_reverse_iterator crbegin() const noexcept;
52
- const_reverse_iterator crend() const noexcept;
49
+ const_iterator cbegin() const noexcept; // constexpr in C++17
50
+ const_iterator cend() const noexcept; // constexpr in C++17
51
+ const_reverse_iterator crbegin() const noexcept; // constexpr in C++17
52
+ const_reverse_iterator crend() const noexcept; // constexpr in C++17
53
53
54
54
// capacity:
55
55
constexpr size_type size() const noexcept;
56
56
constexpr size_type max_size() const noexcept;
57
57
constexpr bool empty() const noexcept;
58
58
59
59
// element access:
60
- reference operator[](size_type n);
61
- const_reference operator[](size_type n) const; // constexpr in C++14
62
- const_reference at(size_type n) const; // constexpr in C++14
63
- reference at(size_type n);
64
-
65
- reference front();
66
- const_reference front() const; // constexpr in C++14
67
- reference back();
68
- const_reference back() const; // constexpr in C++14
69
-
70
- T* data() noexcept;
71
- const T* data() const noexcept;
60
+ reference operator[](size_type n); // constexpr in C++17
61
+ const_reference operator[](size_type n) const; // constexpr in C++14
62
+ reference at(size_type n); // constexpr in C++17
63
+ const_reference at(size_type n) const; // constexpr in C++14
64
+
65
+ reference front(); // constexpr in C++17
66
+ const_reference front() const; // constexpr in C++14
67
+ reference back(); // constexpr in C++17
68
+ const_reference back() const; // constexpr in C++14
69
+
70
+ T* data() noexcept; // constexpr in C++17
71
+ const T* data() const noexcept; // constexpr in C++17
72
72
};
73
73
74
- template <class T, class... U>
75
- array(T, U...) -> array<T, 1 + sizeof...(U)>;
74
+ template <class T, class... U>
75
+ array(T, U...) -> array<T, 1 + sizeof...(U)>; // C++17
76
76
77
77
template <class T, size_t N>
78
- bool operator==(const array<T,N>& x, const array<T,N>& y);
78
+ bool operator==(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20
79
79
template <class T, size_t N>
80
- bool operator!=(const array<T,N>& x, const array<T,N>& y);
80
+ bool operator!=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20
81
81
template <class T, size_t N>
82
- bool operator<(const array<T,N>& x, const array<T,N>& y);
82
+ bool operator<(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20
83
83
template <class T, size_t N>
84
- bool operator>(const array<T,N>& x, const array<T,N>& y);
84
+ bool operator>(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20
85
85
template <class T, size_t N>
86
- bool operator<=(const array<T,N>& x, const array<T,N>& y);
86
+ bool operator<=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20
87
87
template <class T, size_t N>
88
- bool operator>=(const array<T,N>& x, const array<T,N>& y);
88
+ bool operator>=(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20
89
89
90
90
template <class T, size_t N >
91
- void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // C++17
91
+ void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20
92
+
93
+ template <class T, size_t N>
94
+ constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]); // C++20
95
+ template <class T, size_t N>
96
+ constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]); // C++20
92
97
93
98
template <class T> struct tuple_size;
94
99
template <size_t I, class T> struct tuple_element;
95
100
template <class T, size_t N> struct tuple_size<array<T, N>>;
96
101
template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>;
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
99
- template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14
102
+ template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14
103
+ template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14
104
+ template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14
100
105
template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14
101
106
102
107
} // std
@@ -143,11 +148,12 @@ struct _LIBCPP_TEMPLATE_VIS array
143
148
_Tp __elems_[_Size];
144
149
145
150
// No explicit construct/copy/destroy for aggregate type
146
- _LIBCPP_INLINE_VISIBILITY void fill (const value_type& __u) {
151
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
152
+ void fill (const value_type& __u) {
147
153
_VSTD::fill_n (__elems_, _Size, __u);
148
154
}
149
155
150
- _LIBCPP_INLINE_VISIBILITY
156
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
151
157
void swap (array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) {
152
158
std::swap_ranges (__elems_, __elems_ + _Size, __a.__elems_ );
153
159
}
@@ -236,50 +242,71 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
236
242
typedef std::reverse_iterator<iterator> reverse_iterator;
237
243
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
238
244
245
+ #ifndef _LIBCPP_CXX03_LANG
246
+ union __wrapper {
247
+ _LIBCPP_CONSTEXPR __wrapper () : __b () { }
248
+ ~__wrapper () = default ;
249
+
250
+ bool __b;
251
+ _Tp __t ;
252
+ } __w;
253
+
254
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
255
+ value_type* data () _NOEXCEPT {return &__w.__t ;}
256
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
257
+ const value_type* data () const _NOEXCEPT {return &__w.__t ;}
258
+ #else // C++03
239
259
typedef typename conditional<is_const<_Tp>::value, const char ,
240
260
char >::type _CharType;
241
261
242
262
struct _ArrayInStructT { _Tp __data_[1 ]; };
243
263
_ALIGNAS_TYPE (_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)];
244
264
265
+ _LIBCPP_INLINE_VISIBILITY
266
+ value_type* data () _NOEXCEPT {return reinterpret_cast <value_type*>(__elems_);}
267
+ _LIBCPP_INLINE_VISIBILITY
268
+ const value_type* data () const _NOEXCEPT {return reinterpret_cast <const value_type*>(__elems_);}
269
+ #endif
270
+
245
271
// No explicit construct/copy/destroy for aggregate type
246
- _LIBCPP_INLINE_VISIBILITY void fill (const value_type&) {
272
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
273
+ void fill (const value_type&) {
247
274
static_assert (!is_const<_Tp>::value,
248
275
" cannot fill zero-sized array of type 'const T'" );
249
276
}
250
277
251
- _LIBCPP_INLINE_VISIBILITY
278
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
252
279
void swap (array&) _NOEXCEPT {
253
280
static_assert (!is_const<_Tp>::value,
254
281
" cannot swap zero-sized array of type 'const T'" );
255
282
}
256
283
257
284
// iterators:
258
- _LIBCPP_INLINE_VISIBILITY
285
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
259
286
iterator begin () _NOEXCEPT {return iterator (data ());}
260
- _LIBCPP_INLINE_VISIBILITY
287
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
261
288
const_iterator begin () const _NOEXCEPT {return const_iterator (data ());}
262
- _LIBCPP_INLINE_VISIBILITY
289
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
263
290
iterator end () _NOEXCEPT {return iterator (data ());}
264
- _LIBCPP_INLINE_VISIBILITY
291
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
265
292
const_iterator end () const _NOEXCEPT {return const_iterator (data ());}
266
293
267
- _LIBCPP_INLINE_VISIBILITY
294
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
268
295
reverse_iterator rbegin () _NOEXCEPT {return reverse_iterator (end ());}
269
- _LIBCPP_INLINE_VISIBILITY
296
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
270
297
const_reverse_iterator rbegin () const _NOEXCEPT {return const_reverse_iterator (end ());}
271
- _LIBCPP_INLINE_VISIBILITY
298
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
272
299
reverse_iterator rend () _NOEXCEPT {return reverse_iterator (begin ());}
273
- _LIBCPP_INLINE_VISIBILITY
300
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
274
301
const_reverse_iterator rend () const _NOEXCEPT {return const_reverse_iterator (begin ());}
275
302
276
- _LIBCPP_INLINE_VISIBILITY
303
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
277
304
const_iterator cbegin () const _NOEXCEPT {return begin ();}
278
- _LIBCPP_INLINE_VISIBILITY
305
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
279
306
const_iterator cend () const _NOEXCEPT {return end ();}
280
- _LIBCPP_INLINE_VISIBILITY
307
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
281
308
const_reverse_iterator crbegin () const _NOEXCEPT {return rbegin ();}
282
- _LIBCPP_INLINE_VISIBILITY
309
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
283
310
const_reverse_iterator crend () const _NOEXCEPT {return rend ();}
284
311
285
312
// capacity:
@@ -291,7 +318,7 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
291
318
_LIBCPP_CONSTEXPR bool empty () const _NOEXCEPT {return true ;}
292
319
293
320
// element access:
294
- _LIBCPP_INLINE_VISIBILITY
321
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
295
322
reference operator [](size_type) _NOEXCEPT {
296
323
_LIBCPP_ASSERT (false , " cannot call array<T, 0>::operator[] on a zero-sized array" );
297
324
_LIBCPP_UNREACHABLE ();
@@ -303,46 +330,41 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
303
330
_LIBCPP_UNREACHABLE ();
304
331
}
305
332
306
- _LIBCPP_INLINE_VISIBILITY
333
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
307
334
reference at (size_type) {
308
335
__throw_out_of_range (" array<T, 0>::at" );
309
336
_LIBCPP_UNREACHABLE ();
310
337
}
311
338
312
- _LIBCPP_INLINE_VISIBILITY
339
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
313
340
const_reference at (size_type) const {
314
341
__throw_out_of_range (" array<T, 0>::at" );
315
342
_LIBCPP_UNREACHABLE ();
316
343
}
317
344
318
- _LIBCPP_INLINE_VISIBILITY
345
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
319
346
reference front () _NOEXCEPT {
320
347
_LIBCPP_ASSERT (false , " cannot call array<T, 0>::front() on a zero-sized array" );
321
348
_LIBCPP_UNREACHABLE ();
322
349
}
323
350
324
- _LIBCPP_INLINE_VISIBILITY
351
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
325
352
const_reference front () const _NOEXCEPT {
326
353
_LIBCPP_ASSERT (false , " cannot call array<T, 0>::front() on a zero-sized array" );
327
354
_LIBCPP_UNREACHABLE ();
328
355
}
329
356
330
- _LIBCPP_INLINE_VISIBILITY
357
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
331
358
reference back () _NOEXCEPT {
332
359
_LIBCPP_ASSERT (false , " cannot call array<T, 0>::back() on a zero-sized array" );
333
360
_LIBCPP_UNREACHABLE ();
334
361
}
335
362
336
- _LIBCPP_INLINE_VISIBILITY
363
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
337
364
const_reference back () const _NOEXCEPT {
338
365
_LIBCPP_ASSERT (false , " cannot call array<T, 0>::back() on a zero-sized array" );
339
366
_LIBCPP_UNREACHABLE ();
340
367
}
341
-
342
- _LIBCPP_INLINE_VISIBILITY
343
- value_type* data () _NOEXCEPT {return reinterpret_cast <value_type*>(__elems_);}
344
- _LIBCPP_INLINE_VISIBILITY
345
- const value_type* data () const _NOEXCEPT {return reinterpret_cast <const value_type*>(__elems_);}
346
368
};
347
369
348
370
@@ -404,7 +426,7 @@ operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
404
426
}
405
427
406
428
template <class _Tp , size_t _Size>
407
- inline _LIBCPP_INLINE_VISIBILITY
429
+ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
408
430
typename enable_if
409
431
<
410
432
_Size == 0 ||
0 commit comments