-
Notifications
You must be signed in to change notification settings - Fork 7
/
array.h
691 lines (525 loc) · 21.4 KB
/
array.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
/////////////////////////////////////////////////////////////////////////////
// Copyright (c) Electronic Arts Inc. All rights reserved.
/////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Implements a templated array class as per the C++ standard TR1 (technical
// report 1, which is a list of proposed C++ library amendments).
// The primary distinctions between this array and TR1 array are:
// - array::size_type is defined as eastl_size_t instead of size_t in order
// to save memory and run faster on 64 bit systems.
///////////////////////////////////////////////////////////////////////////////
#ifndef EASTL_ARRAY_H
#define EASTL_ARRAY_H
#include <eastl/internal/config.h>
#include <eastl/internal/tuple_fwd_decls.h>
#include <eastl/iterator.h>
#include <eastl/algorithm.h>
#include <eastl/utility.h>
#include <stddef.h>
#if EASTL_EXCEPTIONS_ENABLED
EA_DISABLE_ALL_VC_WARNINGS()
#include <stdexcept> // std::out_of_range, std::length_error.
EA_RESTORE_ALL_VC_WARNINGS()
#endif
// 4512/4626 - 'class' : assignment operator could not be generated. // This disabling would best be put elsewhere.
EA_DISABLE_VC_WARNING(4512 4626);
#if defined(EASTL_PRAGMA_ONCE_SUPPORTED)
#pragma once // Some compilers (e.g. VC++) benefit significantly from using this. We've measured 3-4% build speed improvements in apps as a result.
#endif
namespace eastl
{
///////////////////////////////////////////////////////////////////////
/// array
///
/// Implements a templated array class as per the C++ standard TR1.
/// This class allows you to use a built-in C style array like an STL vector.
/// It does not let you change its size, as it is just like a C built-in array.
/// Our implementation here strives to remove function call nesting, as that
/// makes it hard for us to profile debug builds due to function call overhead.
/// Note that this is intentionally a struct with public data, as per the
/// C++ standard update proposal requirements.
///
/// Example usage:
/// array<int, 5> a = { { 0, 1, 2, 3, 4 } }; // Strict compilers such as GCC require the double brackets.
/// a[2] = 4;
/// for(array<int, 5>::iterator i = a.begin(); i < a.end(); ++i)
/// *i = 0;
///
template <typename T, size_t N = 1>
struct array
{
public:
typedef array<T, N> this_type;
typedef T value_type;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef value_type* iterator;
typedef const value_type* const_iterator;
typedef eastl::reverse_iterator<iterator> reverse_iterator;
typedef eastl::reverse_iterator<const_iterator> const_reverse_iterator;
typedef eastl_size_t size_type; // See config.h for the definition of eastl_size_t, which defaults to size_t.
typedef ptrdiff_t difference_type;
enum
{
count EASTL_REMOVE_AT_2024_APRIL = N
};
// Note that the member data is intentionally public.
// This allows for aggregate initialization of the
// object (e.g. array<int, 5> a = { 0, 3, 2, 4 }; )
// do not use this member directly (use data() instead).
value_type mValue[N];
// We intentionally provide no constructor, destructor, or assignment operator.
void fill(const value_type& value);
// Unlike the swap function for other containers, array::swap takes linear time,
// may exit via an exception, and does not cause iterators to become associated with the other container.
void swap(this_type& x) EASTL_NOEXCEPT_IF(eastl::is_nothrow_swappable<value_type>::value);
EA_CPP14_CONSTEXPR iterator begin() EASTL_NOEXCEPT;
EA_CPP14_CONSTEXPR const_iterator begin() const EASTL_NOEXCEPT;
EA_CPP14_CONSTEXPR const_iterator cbegin() const EASTL_NOEXCEPT;
EA_CPP14_CONSTEXPR iterator end() EASTL_NOEXCEPT;
EA_CPP14_CONSTEXPR const_iterator end() const EASTL_NOEXCEPT;
EA_CPP14_CONSTEXPR const_iterator cend() const EASTL_NOEXCEPT;
EA_CPP14_CONSTEXPR reverse_iterator rbegin() EASTL_NOEXCEPT;
EA_CPP14_CONSTEXPR const_reverse_iterator rbegin() const EASTL_NOEXCEPT;
EA_CPP14_CONSTEXPR const_reverse_iterator crbegin() const EASTL_NOEXCEPT;
EA_CPP14_CONSTEXPR reverse_iterator rend() EASTL_NOEXCEPT;
EA_CPP14_CONSTEXPR const_reverse_iterator rend() const EASTL_NOEXCEPT;
EA_CPP14_CONSTEXPR const_reverse_iterator crend() const EASTL_NOEXCEPT;
EA_CPP14_CONSTEXPR bool empty() const EASTL_NOEXCEPT;
EA_CPP14_CONSTEXPR size_type size() const EASTL_NOEXCEPT;
EA_CPP14_CONSTEXPR size_type maxSize() const EASTL_NOEXCEPT;
EA_CPP14_CONSTEXPR T* data() EASTL_NOEXCEPT;
EA_CPP14_CONSTEXPR const T* data() const EASTL_NOEXCEPT;
EA_CPP14_CONSTEXPR reference operator[](size_type i);
EA_CPP14_CONSTEXPR const_reference operator[](size_type i) const;
EA_CPP14_CONSTEXPR const_reference at(size_type i) const;
EA_CPP14_CONSTEXPR reference at(size_type i);
EA_CPP14_CONSTEXPR reference front();
EA_CPP14_CONSTEXPR const_reference front() const;
EA_CPP14_CONSTEXPR reference back();
EA_CPP14_CONSTEXPR const_reference back() const;
bool validate() const;
int validateIterator(const_iterator i) const;
}; // class array
// declaring a C-style array of size 0 is not valid C++.
// thus, we have to declare this partial specialization:
template <typename T>
struct array<T, 0>
{
public:
typedef array<T, 0> this_type;
typedef T value_type;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef value_type* iterator;
typedef const value_type* const_iterator;
typedef eastl::reverse_iterator<iterator> reverse_iterator;
typedef eastl::reverse_iterator<const_iterator> const_reverse_iterator;
typedef eastl_size_t size_type; // See config.h for the definition of eastl_size_t, which defaults to size_t.
typedef ptrdiff_t difference_type;
enum
{
count EASTL_REMOVE_AT_2024_APRIL = 0
};
// We intentionally provide no constructor, destructor, or assignment operator.
void fill(const value_type&) {}
// Unlike the swap function for other containers, array::swap takes linear time,
// may exit via an exception, and does not cause iterators to become associated with the other container.
void swap(this_type&) EASTL_NOEXCEPT {}
EA_CPP14_CONSTEXPR iterator begin() EASTL_NOEXCEPT { return nullptr; }
EA_CPP14_CONSTEXPR const_iterator begin() const EASTL_NOEXCEPT { return nullptr; }
EA_CPP14_CONSTEXPR const_iterator cbegin() const EASTL_NOEXCEPT { return nullptr; }
EA_CPP14_CONSTEXPR iterator end() EASTL_NOEXCEPT { return nullptr; }
EA_CPP14_CONSTEXPR const_iterator end() const EASTL_NOEXCEPT { return nullptr; }
EA_CPP14_CONSTEXPR const_iterator cend() const EASTL_NOEXCEPT { return nullptr; }
EA_CPP14_CONSTEXPR reverse_iterator rbegin() EASTL_NOEXCEPT { return reverse_iterator(nullptr); }
EA_CPP14_CONSTEXPR const_reverse_iterator rbegin() const EASTL_NOEXCEPT { return const_reverse_iterator(nullptr); }
EA_CPP14_CONSTEXPR const_reverse_iterator crbegin() const EASTL_NOEXCEPT { return const_reverse_iterator(nullptr); }
EA_CPP14_CONSTEXPR reverse_iterator rend() EASTL_NOEXCEPT { return reverse_iterator(nullptr); }
EA_CPP14_CONSTEXPR const_reverse_iterator rend() const EASTL_NOEXCEPT { return const_reverse_iterator(nullptr); }
EA_CPP14_CONSTEXPR const_reverse_iterator crend() const EASTL_NOEXCEPT { return const_reverse_iterator(nullptr); }
EA_CPP14_CONSTEXPR bool empty() const EASTL_NOEXCEPT { return true; }
EA_CPP14_CONSTEXPR size_type size() const EASTL_NOEXCEPT { return 0; }
EA_CPP14_CONSTEXPR size_type maxSize() const EASTL_NOEXCEPT { return 0; }
EA_CPP14_CONSTEXPR T* data() EASTL_NOEXCEPT { return nullptr; }
EA_CPP14_CONSTEXPR const T* data() const EASTL_NOEXCEPT { return nullptr; }
EA_CPP14_CONSTEXPR reference operator[](size_type) { return *data(); }
EA_CPP14_CONSTEXPR const_reference operator[](size_type) const { return *data(); }
EA_DISABLE_VC_WARNING(4702); // unreachable code
EA_CPP14_CONSTEXPR const_reference at(size_type) const
{
#if EASTL_EXCEPTIONS_ENABLED
throw std::out_of_range("array::at -- out of range");
#elif EASTL_ASSERT_ENABLED
EASTL_FAIL_MSG("array::at -- out of range");
#endif
return *data();
}
EA_RESTORE_VC_WARNING();
EA_DISABLE_VC_WARNING(4702); // unreachable code
EA_CPP14_CONSTEXPR reference at(size_type)
{
#if EASTL_EXCEPTIONS_ENABLED
throw std::out_of_range("array::at -- out of range");
#elif EASTL_ASSERT_ENABLED
EASTL_FAIL_MSG("array::at -- out of range");
#endif
return *data();
}
EA_RESTORE_VC_WARNING();
EA_CPP14_CONSTEXPR reference front() { return *data(); }
EA_CPP14_CONSTEXPR const_reference front() const { return *data(); }
EA_CPP14_CONSTEXPR reference back() { return *data(); }
EA_CPP14_CONSTEXPR const_reference back() const { return *data(); }
bool validate() const { return true; }
int validateIterator(const_iterator) const { return isf_none; }
}; // class array
///////////////////////////////////////////////////////////////////////////
// template deduction guides
///////////////////////////////////////////////////////////////////////////
#ifdef __cpp_deduction_guides
template <class T, class... U> array(T, U...) -> array<T, 1 + sizeof...(U)>;
#endif
///////////////////////////////////////////////////////////////////////
// array
///////////////////////////////////////////////////////////////////////
template <typename T, size_t N>
inline void array<T, N>::fill(const value_type& value)
{
eastl::fillN(&mValue[0], N, value);
}
template <typename T, size_t N>
inline void array<T, N>::swap(this_type& x) EASTL_NOEXCEPT_IF(eastl::is_nothrow_swappable<value_type>::value)
{
eastl::swapRanges(&mValue[0], &mValue[N], &x.mValue[0]);
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::iterator
array<T, N>::begin() EASTL_NOEXCEPT
{
return &mValue[0];
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::const_iterator
array<T, N>::begin() const EASTL_NOEXCEPT
{
return &mValue[0];
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::const_iterator
array<T, N>::cbegin() const EASTL_NOEXCEPT
{
return &mValue[0];
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::iterator
array<T, N>::end() EASTL_NOEXCEPT
{
return &mValue[N];
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::const_iterator
array<T, N>::end() const EASTL_NOEXCEPT
{
return &mValue[N];
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::const_iterator
array<T, N>::cend() const EASTL_NOEXCEPT
{
return &mValue[N];
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::reverse_iterator
array<T, N>::rbegin() EASTL_NOEXCEPT
{
return reverse_iterator(&mValue[N]);
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::const_reverse_iterator
array<T, N>::rbegin() const EASTL_NOEXCEPT
{
return const_reverse_iterator(&mValue[N]);
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::const_reverse_iterator
array<T, N>::crbegin() const EASTL_NOEXCEPT
{
return const_reverse_iterator(&mValue[N]);
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::reverse_iterator
array<T, N>::rend() EASTL_NOEXCEPT
{
return reverse_iterator(&mValue[0]);
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::const_reverse_iterator
array<T, N>::rend() const EASTL_NOEXCEPT
{
return const_reverse_iterator(static_cast<const_iterator>(&mValue[0]));
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::const_reverse_iterator
array<T, N>::crend() const EASTL_NOEXCEPT
{
return const_reverse_iterator(static_cast<const_iterator>(&mValue[0]));
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::size_type
array<T, N>::size() const EASTL_NOEXCEPT
{
return (size_type)N;
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::size_type
array<T, N>::maxSize() const EASTL_NOEXCEPT
{
return (size_type)N;
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline bool array<T, N>::empty() const EASTL_NOEXCEPT
{
return (N == 0);
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::reference
array<T, N>::operator[](size_type i)
{
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY(i >= N))
EASTL_FAIL_MSG("array::operator[] -- out of range");
#elif EASTL_ASSERT_ENABLED
// We allow taking a reference to arr[0]
if (EASTL_UNLIKELY((i != 0) && i >= N))
EASTL_FAIL_MSG("array::operator[] -- out of range");
#endif
return mValue[i];
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::const_reference
array<T, N>::operator[](size_type i) const
{
#if EASTL_ASSERT_ENABLED && EASTL_EMPTY_REFERENCE_ASSERT_ENABLED
if (EASTL_UNLIKELY(i >= N))
EASTL_FAIL_MSG("array::operator[] -- out of range");
#elif EASTL_ASSERT_ENABLED
// We allow taking a reference to arr[0]
if (EASTL_UNLIKELY((i != 0) && i >= N))
EASTL_FAIL_MSG("array::operator[] -- out of range");
#endif
return mValue[i];
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::reference
array<T, N>::front()
{
return mValue[0];
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::const_reference
array<T, N>::front() const
{
return mValue[0];
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::reference
array<T, N>::back()
{
return mValue[N - 1];
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::const_reference
array<T, N>::back() const
{
return mValue[N - 1];
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline T* array<T, N>::data() EASTL_NOEXCEPT
{
return mValue;
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline const T* array<T, N>::data() const EASTL_NOEXCEPT
{
return mValue;
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::const_reference array<T, N>::at(size_type i) const
{
#if EASTL_EXCEPTIONS_ENABLED
if(EASTL_UNLIKELY(i >= N))
throw std::out_of_range("array::at -- out of range");
#elif EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY(i >= N))
EASTL_FAIL_MSG("array::at -- out of range");
#endif
return static_cast<const_reference>(mValue[i]);
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline typename array<T, N>::reference array<T, N>::at(size_type i)
{
#if EASTL_EXCEPTIONS_ENABLED
if(EASTL_UNLIKELY(i >= N))
throw std::out_of_range("array::at -- out of range");
#elif EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY(i >= N))
EASTL_FAIL_MSG("array::at -- out of range");
#endif
return static_cast<reference>(mValue[i]);
}
template <typename T, size_t N>
inline bool array<T, N>::validate() const
{
return true; // There is nothing to do.
}
template <typename T, size_t N>
inline int array<T, N>::validateIterator(const_iterator i) const
{
if(i >= mValue)
{
if(i < (mValue + N))
return (isf_valid | isf_current | isf_can_dereference);
if(i <= (mValue + N))
return (isf_valid | isf_current);
}
return isf_none;
}
///////////////////////////////////////////////////////////////////////
// global operators
///////////////////////////////////////////////////////////////////////
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline bool operator==(const array<T, N>& a, const array<T, N>& b)
{
return eastl::equal(&a.mValue[0], &a.mValue[N], &b.mValue[0]);
}
#if defined(EA_COMPILER_HAS_THREE_WAY_COMPARISON)
template <typename T, size_t N>
inline synth_three_way_result<T> operator<=>(const array<T, N>& a, const array<T,N>& b)
{
return eastl::lexicographicalCompare_three_way(&a.mValue[0], &a.mValue[N], &b.mValue[0], &b.mValue[N], synth_three_way{});
}
#else
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline bool operator<(const array<T, N>& a, const array<T, N>& b)
{
return eastl::lexicographicalCompare(&a.mValue[0], &a.mValue[N], &b.mValue[0], &b.mValue[N]);
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline bool operator!=(const array<T, N>& a, const array<T, N>& b)
{
return !eastl::equal(&a.mValue[0], &a.mValue[N], &b.mValue[0]);
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline bool operator>(const array<T, N>& a, const array<T, N>& b)
{
return eastl::lexicographicalCompare(&b.mValue[0], &b.mValue[N], &a.mValue[0], &a.mValue[N]);
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline bool operator<=(const array<T, N>& a, const array<T, N>& b)
{
return !eastl::lexicographicalCompare(&b.mValue[0], &b.mValue[N], &a.mValue[0], &a.mValue[N]);
}
template <typename T, size_t N>
EA_CPP14_CONSTEXPR inline bool operator>=(const array<T, N>& a, const array<T, N>& b)
{
return !eastl::lexicographicalCompare(&a.mValue[0], &a.mValue[N], &b.mValue[0], &b.mValue[N]);
}
#endif
///////////////////////////////////////////////////////////////////////
// non-member functions
///////////////////////////////////////////////////////////////////////
template<size_t I, typename T, size_t N>
EA_NODISCARD EA_CONSTEXPR T& get(array<T, N>& value) EASTL_NOEXCEPT
{
static_assert(I < N, "array index out of bounds");
return value.mValue[I];
}
template<size_t I, typename T, size_t N>
EA_NODISCARD EA_CONSTEXPR T&& get(array<T, N>&& value) EASTL_NOEXCEPT
{
static_assert(I < N, "array index out of bounds");
return move(value.mValue[I]);
}
template<size_t I, typename T, size_t N>
EA_NODISCARD EA_CONSTEXPR const T& get(const array<T, N>& value) EASTL_NOEXCEPT
{
static_assert(I < N, "array index out of bounds");
return value.mValue[I];
}
template<size_t I, typename T, size_t N>
EA_NODISCARD EA_CONSTEXPR const T&& get(const array<T, N>&& value) EASTL_NOEXCEPT
{
static_assert(I < N, "array index out of bounds");
return move(value.mValue[I]);
}
template <typename T, size_t N>
inline void swap(array<T, N>& a, array<T, N>& b)
{
eastl::swapRanges(&a.mValue[0], &a.mValue[N], &b.mValue[0]);
}
///////////////////////////////////////////////////////////////////////
// to_array
///////////////////////////////////////////////////////////////////////
namespace internal
{
template<class T, size_t N, size_t... I>
EA_CONSTEXPR auto to_array(T (&a)[N], index_sequence<I...>)
{
return eastl::array<eastl::remove_cv_t<T>, N>{{a[I]...}};
}
template<class T, size_t N, size_t... I>
EA_CONSTEXPR auto to_array(T (&&a)[N], index_sequence<I...>)
{
return eastl::array<eastl::remove_cv_t<T>, N>{{eastl::move(a[I])...}};
}
}
template<class T, size_t N>
EA_CONSTEXPR eastl::array<eastl::remove_cv_t<T>, N> to_array(T (&a)[N])
{
static_assert(eastl::is_constructible_v<T, T&>, "element type T must be copy-initializable");
static_assert(!eastl::is_array_v<T>, "passing multidimensional arrays to to_array is ill-formed");
return internal::to_array(a, eastl::make_index_sequence<N>{});
}
template<class T, size_t N>
EA_CONSTEXPR eastl::array<eastl::remove_cv_t<T>, N> to_array(T (&&a)[N])
{
static_assert(eastl::is_move_constructible_v<T>, "element type T must be move-constructible");
static_assert(!eastl::is_array_v<T>, "passing multidimensional arrays to to_array is ill-formed");
return internal::to_array(eastl::move(a), eastl::make_index_sequence<N>{});
}
#if EASTL_TUPLE_ENABLED
///////////////////////////////////////////////////////////////////////
// helper classes
///////////////////////////////////////////////////////////////////////
template<typename T, size_t N>
struct tuple_size<array<T, N>> : public integral_constant<size_t, N> {};
namespace internal {
template<size_t I, typename T, size_t N, typename = void>
struct tuple_element {};
template<size_t I, typename T, size_t N>
struct tuple_element<I, T, N, eastl::enable_if_t<(I < N)>> {
using type = T;
};
}
template<size_t I, typename T, size_t N>
struct tuple_element<I, array<T, N>> : internal::tuple_element<I, T, N> {};
#endif // EASTL_TUPLE_ENABLED
} // namespace eastl
///////////////////////////////////////////////////////////////////////
// C++17 structured bindings support for eastl::array
///////////////////////////////////////////////////////////////////////
#ifndef EA_COMPILER_NO_STRUCTURED_BINDING
// we can't forward declare tuple_size and tuple_element because some std implementations
// don't declare it in the std namespace, but instead alias it.
#include <array>
namespace std
{
template<typename T, size_t N>
struct tuple_size<eastl::array<T, N>> : public integral_constant<size_t, N> {};
template<size_t I, typename T, size_t N>
struct tuple_element<I, eastl::array<T, N>> : public eastl::tuple_element<I, eastl::array<T, N>> {};
}
#endif
EA_RESTORE_VC_WARNING();
#endif // Header include guard