-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
mdspan
1456 lines (1235 loc) · 65.6 KB
/
mdspan
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
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// mdspan standard header
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef _MDSPAN_
#define _MDSPAN_
#include <yvals.h>
#if _STL_COMPILER_PREPROCESSOR
#if !_HAS_CXX23 || !defined(__cpp_lib_concepts) // TRANSITION, GH-395
_EMIT_STL_WARNING(STL4038, "The contents of <mdspan> are available only with C++23 or later.");
#else // ^^^ not supported / supported language mode vvv
#include <array>
#include <limits>
#include <span>
#include <tuple>
#include <type_traits>
#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
#pragma warning(disable : _STL_DISABLED_WARNINGS)
_STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new
// TRANSITION, non-_Ugly attribute tokens
#pragma push_macro("empty_bases")
#undef empty_bases
_STD_BEGIN
template <class _IndexType, size_t _Size>
struct _Maybe_empty_array {
array<_IndexType, _Size> _Array{};
};
template <class _IndexType>
struct _Maybe_empty_array<_IndexType, 0> {};
template <size_t... _Extents>
inline constexpr size_t _Calculate_rank_dynamic = (static_cast<size_t>(_Extents == dynamic_extent) + ... + 0);
struct _Extents_from_tuple {
explicit _Extents_from_tuple() = default;
};
_EXPORT_STD template <class _IndexType, size_t... _Extents>
class extents : private _Maybe_empty_array<_IndexType, _Calculate_rank_dynamic<_Extents...>> {
public:
using index_type = _IndexType;
using size_type = make_unsigned_t<index_type>;
using rank_type = size_t;
static_assert(_Is_standard_integer<index_type>,
"IndexType must be a signed or unsigned integer type (N4950 [mdspan.extents.overview]/1.1).");
static_assert(((_Extents == dynamic_extent || _STD in_range<index_type>(_Extents)) && ...),
"Each element of Extents must either be equal to dynamic_extent, or be representable as a value of type "
"IndexType (N4950 [mdspan.extents.overview]/1.2).");
static constexpr rank_type _Rank = sizeof...(_Extents);
static constexpr rank_type _Rank_dynamic = _Calculate_rank_dynamic<_Extents...>;
static constexpr array<rank_type, _Rank> _Static_extents = {_Extents...};
static constexpr bool _Multidim_index_space_size_is_always_zero = ((_Extents == 0) || ...);
private:
_NODISCARD static consteval auto _Make_dynamic_indices() noexcept {
array<rank_type, _Rank + 1> _Result{};
rank_type _Counter = 0;
for (rank_type _Idx = 0; _Idx < _Rank; ++_Idx) {
_Result[_Idx] = _Counter;
if (_Static_extents[_Idx] == dynamic_extent) {
++_Counter;
}
}
_Result[_Rank] = _Counter;
return _Result;
}
static constexpr array<rank_type, _Rank + 1> _Dynamic_indices = _Make_dynamic_indices();
_NODISCARD static consteval auto _Make_dynamic_indices_inv() noexcept {
array<rank_type, _Rank_dynamic> _Result{};
rank_type _Counter = 0;
for (rank_type _Idx = 0; _Idx < _Rank; ++_Idx) {
if (_Static_extents[_Idx] == dynamic_extent) {
_Analysis_assume_(_Counter < _Rank_dynamic); // TRANSITION, DevCom-923103
_Result[_Counter] = _Idx;
++_Counter;
}
}
return _Result;
}
static constexpr array<rank_type, _Rank_dynamic> _Dynamic_indices_inv = _Make_dynamic_indices_inv();
using _Base = _Maybe_empty_array<_IndexType, _Rank_dynamic>;
template <class _OtherIndexType, size_t... _OtherExtents, size_t... _Indices>
constexpr explicit extents(
const extents<_OtherIndexType, _OtherExtents...>& _Other, index_sequence<_Indices...>) noexcept
: _Base{static_cast<index_type>(_Other.extent(_Dynamic_indices_inv[_Indices]))...} {
_STL_INTERNAL_STATIC_ASSERT(sizeof...(_OtherExtents) == _Rank);
_STL_INTERNAL_STATIC_ASSERT(
((_OtherExtents == dynamic_extent || _Extents == dynamic_extent || _OtherExtents == _Extents) && ...));
#if _CONTAINER_DEBUG_LEVEL > 0
if constexpr (rank() > 0) {
for (rank_type _Idx = 0; _Idx < _Rank; ++_Idx) {
if constexpr (rank() != rank_dynamic()) {
_STL_VERIFY(_Static_extents[_Idx] == dynamic_extent
|| _STD cmp_equal(_Static_extents[_Idx], _Other.extent(_Idx)),
"Value of other.extent(r) must be equal to extent(r) for each r for which extent(r) is a "
"static extent (N4950 [mdspan.extents.cons]/2.1)");
}
_STL_VERIFY(_STD in_range<index_type>(_Other.extent(_Idx)),
"Value of other.extent(r) must be representable as a value of type index_type for every rank index "
"r (N4950 [mdspan.extents.cons]/2.2)");
}
}
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
template <class _ExtsTuple, size_t... _Indices>
requires (tuple_size_v<_ExtsTuple> == _Rank_dynamic)
constexpr explicit extents(_Extents_from_tuple, _ExtsTuple _Tpl, index_sequence<_Indices...>) noexcept
: _Base{static_cast<index_type>(_STD move(_STD get<_Indices>(_Tpl)))...} {}
template <class _ExtsTuple, size_t... _DynIndices>
requires (tuple_size_v<_ExtsTuple> != _Rank_dynamic)
constexpr explicit extents(_Extents_from_tuple, _ExtsTuple _Tpl, index_sequence<_DynIndices...>) noexcept
: _Base{static_cast<index_type>(_STD move(_STD get<_Dynamic_indices_inv[_DynIndices]>(_Tpl)))...} {
#if _CONTAINER_DEBUG_LEVEL > 0
[&]<size_t... _MixedIndices>(index_sequence<_MixedIndices...>) {
_STL_VERIFY(((_Static_extents[_MixedIndices] == dynamic_extent
|| _STD cmp_equal(_Static_extents[_MixedIndices],
static_cast<index_type>(_STD move(_STD get<_MixedIndices>(_Tpl)))))
&& ...),
"Value of exts_arr[r] must be equal to extent(r) for each r for which extent(r) is a static extent "
"(N4950 [mdspan.extents.cons]/7.1)");
}(make_index_sequence<rank()>{});
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
template <class _OtherIndexType, size_t... _Indices>
constexpr explicit extents(span<_OtherIndexType, _Rank_dynamic> _Dynamic_exts, index_sequence<_Indices...>) noexcept
: _Base{static_cast<index_type>(_STD as_const(_Dynamic_exts[_Indices]))...} {
_STL_INTERNAL_STATIC_ASSERT(is_convertible_v<const _OtherIndexType&, index_type>
&& is_nothrow_constructible_v<index_type, const _OtherIndexType&>);
#if _CONTAINER_DEBUG_LEVEL > 0
if constexpr (_Is_standard_integer<_OtherIndexType> && _Rank_dynamic != 0) {
_STL_VERIFY(((_Dynamic_exts[_Indices] >= 0 && _STD in_range<index_type>(_Dynamic_exts[_Indices])) && ...),
"exts[r] must be representable as a nonnegative value of type index_type for every rank index r "
"(N4950 [mdspan.extents.cons]/10.2)");
}
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
template <class _OtherIndexType, size_t _Size, size_t... _Indices>
constexpr explicit extents(span<_OtherIndexType, _Size> _Mixed_exts, index_sequence<_Indices...>) noexcept
: _Base{static_cast<index_type>(_STD as_const(_Mixed_exts[_Dynamic_indices_inv[_Indices]]))...} {
_STL_INTERNAL_STATIC_ASSERT(_Size != _Rank_dynamic);
_STL_INTERNAL_STATIC_ASSERT(is_convertible_v<const _OtherIndexType&, index_type>
&& is_nothrow_constructible_v<index_type, const _OtherIndexType&>);
#if _CONTAINER_DEBUG_LEVEL > 0
if constexpr (_Is_standard_integer<_OtherIndexType>) {
for (rank_type _Idx = 0; _Idx < _Rank; ++_Idx) {
_STL_VERIFY(
_Static_extents[_Idx] == dynamic_extent || _STD cmp_equal(_Static_extents[_Idx], _Mixed_exts[_Idx]),
"Value of exts[r] must be equal to extent(r) for each r for which extent(r) is a static extent "
"(N4950 [mdspan.extents.cons]/10.1)");
_STL_VERIFY(_Mixed_exts[_Idx] >= 0 && _STD in_range<index_type>(_Mixed_exts[_Idx]),
"exts[r] must be representable as a nonnegative value of type index_type for every rank index r "
"(N4950 [mdspan.extents.cons]/10.2)");
}
}
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
public:
_NODISCARD static constexpr rank_type rank() noexcept {
return _Rank;
}
_NODISCARD static constexpr rank_type rank_dynamic() noexcept {
return _Rank_dynamic;
}
_NODISCARD static constexpr size_t static_extent(const rank_type _Idx) noexcept {
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(_Idx < _Rank, "Index must be less than rank() (N4950 [mdspan.extents.obs]/1)");
#endif // _CONTAINER_DEBUG_LEVEL > 0
return _Static_extents[_Idx];
}
_NODISCARD constexpr index_type extent(const rank_type _Idx) const noexcept {
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(_Idx < _Rank, "Index must be less than rank() (N4950 [mdspan.extents.obs]/3)");
#endif // _CONTAINER_DEBUG_LEVEL > 0
if constexpr (rank_dynamic() == 0) {
return static_cast<index_type>(_Static_extents[_Idx]);
} else if constexpr (rank_dynamic() == rank()) {
return this->_Array[_Idx];
} else {
if (_Static_extents[_Idx] == dynamic_extent) {
return this->_Array[_Dynamic_indices[_Idx]];
} else {
return static_cast<index_type>(_Static_extents[_Idx]);
}
}
}
constexpr extents() noexcept = default;
template <class _OtherIndexType, size_t... _OtherExtents>
requires (sizeof...(_OtherExtents) == rank())
&& ((_OtherExtents == dynamic_extent || _Extents == dynamic_extent || _OtherExtents == _Extents) && ...)
constexpr explicit(((_Extents != dynamic_extent && _OtherExtents == dynamic_extent) || ...)
|| (numeric_limits<index_type>::max)() < (numeric_limits<_OtherIndexType>::max)())
extents(const extents<_OtherIndexType, _OtherExtents...>& _Other) noexcept
: extents(_Other, make_index_sequence<rank_dynamic()>{}) {}
template <class... _OtherIndexTypes>
requires (is_convertible_v<_OtherIndexTypes, index_type> && ...)
&& (is_nothrow_constructible_v<index_type, _OtherIndexTypes> && ...)
&& (sizeof...(_OtherIndexTypes) == rank_dynamic() || sizeof...(_OtherIndexTypes) == rank())
constexpr explicit extents(_OtherIndexTypes... _Exts) noexcept
: extents(_Extents_from_tuple{}, _STD tie(_Exts...), make_index_sequence<rank_dynamic()>{}) {
#if _CONTAINER_DEBUG_LEVEL > 0
auto _Check_extent = []<class _Ty>(const _Ty& _Ext) {
if constexpr (_Is_standard_integer<_Ty>) {
return _Ext >= 0 && _STD in_range<index_type>(_Ext);
} else if constexpr (integral<_Ty> && !same_as<_Ty, bool>) { // NB: character types
const auto _Integer_ext = static_cast<long long>(_Ext);
return _Integer_ext >= 0 && _STD in_range<index_type>(_Integer_ext);
} else {
return true; // NB: We cannot check preconditions
}
};
_STL_VERIFY((_Check_extent(_Exts) && ...), "Each argument must be representable as a nonnegative value of type "
"index_type (N4950 [mdspan.extents.cons]/7.2)");
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
template <class _OtherIndexType, size_t _Size>
requires is_convertible_v<const _OtherIndexType&, index_type>
&& is_nothrow_constructible_v<index_type, const _OtherIndexType&>
&& (_Size == rank_dynamic() || _Size == rank())
constexpr explicit(_Size != rank_dynamic()) extents(span<_OtherIndexType, _Size> _Exts) noexcept
: extents(_Exts, make_index_sequence<rank_dynamic()>{}) {}
template <class _OtherIndexType, size_t _Size>
requires is_convertible_v<const _OtherIndexType&, index_type>
&& is_nothrow_constructible_v<index_type, const _OtherIndexType&>
&& (_Size == rank_dynamic() || _Size == rank())
constexpr explicit(_Size != rank_dynamic()) extents(const array<_OtherIndexType, _Size>& _Exts) noexcept
: extents(span{_Exts}, make_index_sequence<rank_dynamic()>{}) {}
template <class _OtherIndexType, size_t... _OtherExtents>
_NODISCARD_FRIEND constexpr bool operator==(
const extents& _Left, const extents<_OtherIndexType, _OtherExtents...>& _Right) noexcept {
if constexpr (rank() != sizeof...(_OtherExtents)) {
return false;
} else {
for (rank_type _Idx = 0; _Idx < _Rank; ++_Idx) {
if (_STD cmp_not_equal(_Left.extent(_Idx), _Right.extent(_Idx))) {
return false;
}
}
return true;
}
}
_NODISCARD static consteval bool _Is_static_multidim_index_space_size_representable() noexcept {
// Pre: rank_dynamic() == 0
if constexpr (_Multidim_index_space_size_is_always_zero) {
return true;
} else {
index_type _Result{1};
const bool _Overflow = (_Mul_overflow(static_cast<index_type>(_Extents), _Result, _Result) || ...);
return !_Overflow;
}
}
template <integral _Ty = index_type>
_NODISCARD constexpr bool _Is_dynamic_multidim_index_space_size_representable() const noexcept {
// Pre: rank_dynamic() != 0
if constexpr (_Multidim_index_space_size_is_always_zero) {
return true;
} else {
bool _Overflow = false;
_Ty _Result = 1;
for (rank_type _Idx = 0; _Idx < _Rank; ++_Idx) {
const auto _Ext = static_cast<_Ty>(extent(_Idx));
if (_Ext == 0) {
return true;
}
if (!_Overflow) {
_Overflow = _Mul_overflow(_Ext, _Result, _Result);
}
}
return !_Overflow;
}
}
template <size_t... _Seq, class... _IndexTypes>
_NODISCARD constexpr bool _Contains_multidimensional_index(
index_sequence<_Seq...>, _IndexTypes... _Indices) const noexcept {
_STL_INTERNAL_STATIC_ASSERT((same_as<_IndexTypes, index_type> && ...));
if constexpr (unsigned_integral<index_type>) {
return ((_Indices < extent(_Seq)) && ...);
} else {
return ((0 <= _Indices && _Indices < extent(_Seq)) && ...);
}
}
};
template <class>
inline constexpr size_t _Repeat_dynamic_extent = dynamic_extent;
template <class... _Integrals>
requires (is_convertible_v<_Integrals, size_t> && ...)
explicit extents(_Integrals...) -> extents<size_t, _Repeat_dynamic_extent<_Integrals>...>;
template <class _IndexType, class _Indices>
struct _Dextents_impl;
template <class _IndexType, size_t... _Indices>
struct _Dextents_impl<_IndexType, index_sequence<_Indices...>> {
using type = extents<_IndexType, ((void) _Indices, dynamic_extent)...>;
};
_EXPORT_STD template <class _IndexType, size_t _Rank>
using dextents = _Dextents_impl<_IndexType, make_index_sequence<_Rank>>::type;
template <class _Ty>
inline constexpr bool _Is_extents = false;
template <class _IndexType, size_t... _Args>
inline constexpr bool _Is_extents<extents<_IndexType, _Args...>> = true;
template <class _Extents>
class _Fwd_prod_of_extents {
public:
_STL_INTERNAL_STATIC_ASSERT(_Is_extents<_Extents>);
_NODISCARD static constexpr _Extents::index_type _Calculate(const _Extents& _Exts, const size_t _Idx) noexcept {
_STL_INTERNAL_CHECK(_Idx <= _Extents::_Rank);
if constexpr (_Extents::rank() == 0) {
return 1;
} else {
// Use an unsigned type to prevent overflow when called from mdspan::size.
typename _Extents::size_type _Result = 1;
for (size_t _Dim = 0; _Dim < _Idx; ++_Dim) {
_Result *= static_cast<_Extents::size_type>(_Exts.extent(_Dim));
}
return static_cast<_Extents::index_type>(_Result);
}
}
};
template <class _Extents>
requires (_Extents::rank() > 0) && (_Extents::rank_dynamic() == 0)
class _Fwd_prod_of_extents<_Extents> {
private:
_STL_INTERNAL_STATIC_ASSERT(_Is_extents<_Extents>);
_NODISCARD static consteval auto _Make_prods() noexcept {
array<typename _Extents::index_type, _Extents::rank() + 1> _Result;
_Result.front() = 1;
for (size_t _Idx = 1; _Idx < _Extents::_Rank + 1; ++_Idx) {
_Result[_Idx] = static_cast<_Extents::index_type>(_Result[_Idx - 1] * _Extents::_Static_extents[_Idx - 1]);
}
return _Result;
}
static constexpr array<typename _Extents::index_type, _Extents::rank() + 1> _Cache = _Make_prods();
public:
_NODISCARD static constexpr _Extents::index_type _Calculate(const _Extents&, const size_t _Idx) noexcept {
_STL_INTERNAL_CHECK(_Idx <= _Extents::_Rank);
return _Cache[_Idx];
}
};
template <class _Extents>
class _Rev_prod_of_extents {
public:
_STL_INTERNAL_STATIC_ASSERT(_Is_extents<_Extents>);
_STL_INTERNAL_STATIC_ASSERT(_Extents::rank() > 0);
_NODISCARD static constexpr _Extents::index_type _Calculate(const _Extents& _Exts, const size_t _Idx) noexcept {
_STL_INTERNAL_CHECK(_Idx < _Extents::_Rank);
typename _Extents::index_type _Result = 1;
for (size_t _Dim = _Idx + 1; _Dim < _Extents::_Rank; ++_Dim) {
_Result *= _Exts.extent(_Dim);
}
return _Result;
}
};
template <class _Extents>
requires (_Extents::rank_dynamic() == 0)
class _Rev_prod_of_extents<_Extents> {
private:
_STL_INTERNAL_STATIC_ASSERT(_Is_extents<_Extents>);
_STL_INTERNAL_STATIC_ASSERT(_Extents::rank() > 0);
_NODISCARD static consteval auto _Make_prods() noexcept {
array<typename _Extents::index_type, _Extents::rank()> _Result;
_Result.back() = 1;
for (size_t _Idx = _Extents::_Rank; _Idx-- > 1;) {
_Result[_Idx - 1] = static_cast<_Extents::index_type>(_Result[_Idx] * _Extents::_Static_extents[_Idx]);
}
return _Result;
}
static constexpr array<typename _Extents::index_type, _Extents::rank()> _Cache = _Make_prods();
public:
_NODISCARD static constexpr _Extents::index_type _Calculate(const _Extents&, const size_t _Idx) noexcept {
_STL_INTERNAL_CHECK(_Idx < _Extents::_Rank);
return _Cache[_Idx];
}
};
template <class _Layout, class _Mapping>
inline constexpr bool _Is_mapping_of =
is_same_v<typename _Layout::template mapping<typename _Mapping::extents_type>, _Mapping>;
_EXPORT_STD struct layout_left {
template <class _Extents>
class mapping;
};
_EXPORT_STD struct layout_right {
template <class _Extents>
class mapping;
};
_EXPORT_STD struct layout_stride {
template <class _Extents>
class mapping;
};
template <class _Extents>
struct _Maybe_fully_static_extents {
_STL_INTERNAL_STATIC_ASSERT(_Is_extents<_Extents>);
constexpr _Maybe_fully_static_extents() noexcept = default;
template <class _OtherExtents>
constexpr explicit _Maybe_fully_static_extents(const _OtherExtents& _Exts_) : _Exts(_Exts_) {}
_Extents _Exts{};
};
template <class _Extents>
requires (_Extents::rank_dynamic() == 0)
struct _Maybe_fully_static_extents<_Extents> {
_STL_INTERNAL_STATIC_ASSERT(_Is_extents<_Extents>);
constexpr _Maybe_fully_static_extents() noexcept = default;
template <class _OtherExtents>
constexpr explicit _Maybe_fully_static_extents([[maybe_unused]] const _OtherExtents& _Exts_) {
#if _CONTAINER_DEBUG_LEVEL > 0
(void) _Extents{_Exts_}; // NB: temporary created for preconditions check
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
static constexpr _Extents _Exts{};
};
template <class _Extents>
class layout_left::mapping : private _Maybe_fully_static_extents<_Extents> {
public:
using extents_type = _Extents;
using index_type = extents_type::index_type;
using size_type = extents_type::size_type;
using rank_type = extents_type::rank_type;
using layout_type = layout_left;
private:
using _Base = _Maybe_fully_static_extents<extents_type>;
static_assert(_Is_extents<extents_type>,
"Extents must be a specialization of std::extents (N4950 [mdspan.layout.left.overview]/2).");
static_assert(
extents_type::rank_dynamic() != 0 || extents_type::_Is_static_multidim_index_space_size_representable(),
"If Extents::rank_dynamic() == 0 is true, then the size of the multidimensional index space Extents() must be "
"representable as a value of type typename Extents::index_type (N4950 [mdspan.layout.left.overview]/4).");
public:
constexpr mapping() noexcept = default;
constexpr mapping(const mapping&) noexcept = default;
constexpr mapping(const extents_type& _Exts_) noexcept : _Base(_Exts_) {
#if _CONTAINER_DEBUG_LEVEL > 0
if constexpr (extents_type::rank_dynamic() != 0) {
_STL_VERIFY(_Exts_._Is_dynamic_multidim_index_space_size_representable(),
"The size of the multidimensional index space e must be representable as a value of type index_type "
"(N4950 [mdspan.layout.left.cons]/1).");
}
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
template <class _OtherExtents>
requires is_constructible_v<extents_type, _OtherExtents>
constexpr explicit(!is_convertible_v<_OtherExtents, extents_type>)
mapping(const mapping<_OtherExtents>& _Other) noexcept
: _Base(_Other.extents()) {
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(_STD in_range<index_type>(_Other.required_span_size()),
"Value of other.required_span_size() must be representable as a value of type index_type (N4950 "
"[mdspan.layout.left.cons]/4).");
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
template <class _OtherExtents>
requires (extents_type::rank() <= 1) && is_constructible_v<extents_type, _OtherExtents>
constexpr explicit(!is_convertible_v<_OtherExtents, extents_type>)
mapping(const layout_right::mapping<_OtherExtents>& _Other) noexcept
: _Base(_Other.extents()) {
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(_STD in_range<index_type>(_Other.required_span_size()),
"Value of other.required_span_size() must be representable as a value of type index_type (N4950 "
"[mdspan.layout.left.cons]/7).");
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
template <class _OtherExtents>
requires is_constructible_v<extents_type, _OtherExtents>
constexpr explicit(extents_type::rank() > 0)
mapping(const layout_stride::mapping<_OtherExtents>& _Other) noexcept // strengthened
: _Base(_Other.extents()) {
#if _CONTAINER_DEBUG_LEVEL > 0
if constexpr (extents_type::rank() > 0) {
index_type _Prod = 1;
for (size_t _Idx = 0; _Idx < extents_type::_Rank; ++_Idx) {
_STL_VERIFY(_Other.stride(_Idx) == _Prod,
"For all r in the range [0, extents_type::rank()), other.stride(r) must be equal to "
"extents().fwd-prod-of-extents(r) (N4950 [mdspan.layout.left.cons]/10.1).");
_Prod = static_cast<index_type>(_Prod * this->_Exts.extent(_Idx));
}
}
_STL_VERIFY(_STD in_range<index_type>(_Other.required_span_size()),
"Value of other.required_span_size() must be representable as a value of type index_type (N4950 "
"[mdspan.layout.left.cons]/10.2).");
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
constexpr mapping& operator=(const mapping&) noexcept = default;
_NODISCARD constexpr const extents_type& extents() const noexcept {
return this->_Exts;
}
_NODISCARD constexpr index_type required_span_size() const noexcept {
return _Fwd_prod_of_extents<extents_type>::_Calculate(this->_Exts, extents_type::_Rank);
}
template <class... _IndexTypes>
requires (sizeof...(_IndexTypes) == extents_type::rank()) && (is_convertible_v<_IndexTypes, index_type> && ...)
&& (is_nothrow_constructible_v<index_type, _IndexTypes> && ...)
_NODISCARD constexpr index_type operator()(_IndexTypes... _Indices) const noexcept {
return _Index_impl(make_index_sequence<extents_type::rank()>{}, static_cast<index_type>(_Indices)...);
}
_NODISCARD static constexpr bool is_always_unique() noexcept {
return true;
}
_NODISCARD static constexpr bool is_always_exhaustive() noexcept {
return true;
}
_NODISCARD static constexpr bool is_always_strided() noexcept {
return true;
}
_NODISCARD static constexpr bool is_unique() noexcept {
return true;
}
_NODISCARD static constexpr bool is_exhaustive() noexcept {
return true;
}
_NODISCARD static constexpr bool is_strided() noexcept {
return true;
}
_NODISCARD constexpr index_type stride(const rank_type _Idx) const noexcept
requires (extents_type::rank() > 0)
{
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(_Idx < extents_type::_Rank,
"Value of i must be less than extents_type::rank() (N4950 [mdspan.layout.left.obs]/6).");
#endif // _CONTAINER_DEBUG_LEVEL > 0
return _Fwd_prod_of_extents<extents_type>::_Calculate(this->_Exts, _Idx);
}
template <class _OtherExtents>
requires (extents_type::rank() == _OtherExtents::rank())
_NODISCARD_FRIEND constexpr bool operator==(const mapping& _Left, const mapping<_OtherExtents>& _Right) noexcept {
return _Left._Exts == _Right.extents();
}
private:
template <class... _IndexTypes, size_t... _Seq>
_NODISCARD constexpr index_type _Index_impl(
[[maybe_unused]] index_sequence<_Seq...> _Index_seq, _IndexTypes... _Indices) const noexcept {
_STL_INTERNAL_STATIC_ASSERT((same_as<_IndexTypes, index_type> && ...));
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(this->_Exts._Contains_multidimensional_index(_Index_seq, _Indices...),
"Value of extents_type::index-cast(i) must be a multidimensional index in extents_ (N4950 "
"[mdspan.layout.left.obs]/3).");
#endif // _CONTAINER_DEBUG_LEVEL > 0
index_type _Stride = 1;
index_type _Result = 0;
(((_Result += _Indices * _Stride), (_Stride *= this->_Exts.extent(_Seq))), ...);
return _Result;
}
};
template <class _Extents>
class layout_right::mapping : private _Maybe_fully_static_extents<_Extents> {
public:
using extents_type = _Extents;
using index_type = extents_type::index_type;
using size_type = extents_type::size_type;
using rank_type = extents_type::rank_type;
using layout_type = layout_right;
private:
using _Base = _Maybe_fully_static_extents<extents_type>;
static_assert(_Is_extents<extents_type>,
"Extents must be a specialization of std::extents (N4950 [mdspan.layout.right.overview]/2).");
static_assert(
extents_type::rank_dynamic() != 0 || extents_type::_Is_static_multidim_index_space_size_representable(),
"If Extents::rank_dynamic() == 0 is true, then the size of the multidimensional index space Extents() must be "
"representable as a value of type typename Extents::index_type (N4950 [mdspan.layout.right.overview]/4).");
public:
constexpr mapping() noexcept = default;
constexpr mapping(const mapping&) noexcept = default;
constexpr mapping(const extents_type& _Exts_) noexcept : _Base(_Exts_) {
#if _CONTAINER_DEBUG_LEVEL > 0
if constexpr (extents_type::rank_dynamic() != 0) {
_STL_VERIFY(_Exts_._Is_dynamic_multidim_index_space_size_representable(),
"The size of the multidimensional index space e must be representable as a value of type index_type "
"(N4950 [mdspan.layout.right.cons]/1).");
}
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
template <class _OtherExtents>
requires is_constructible_v<extents_type, _OtherExtents>
constexpr explicit(!is_convertible_v<_OtherExtents, extents_type>)
mapping(const mapping<_OtherExtents>& _Other) noexcept
: _Base(_Other.extents()) {
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(_STD in_range<index_type>(_Other.required_span_size()),
"Value of other.required_span_size() must be representable as a value of type index_type (N4950 "
"[mdspan.layout.right.cons]/4).");
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
template <class _OtherExtents>
requires (extents_type::rank() <= 1) && is_constructible_v<extents_type, _OtherExtents>
constexpr explicit(!is_convertible_v<_OtherExtents, extents_type>)
mapping(const layout_left::mapping<_OtherExtents>& _Other) noexcept
: _Base(_Other.extents()) {
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(_STD in_range<index_type>(_Other.required_span_size()),
"Value of other.required_span_size() must be representable as a value of type index_type (N4950 "
"[mdspan.layout.right.cons]/7).");
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
template <class _OtherExtents>
requires is_constructible_v<extents_type, _OtherExtents>
constexpr explicit(extents_type::rank() > 0) mapping(const layout_stride::mapping<_OtherExtents>& _Other) noexcept
: _Base(_Other.extents()) {
#if _CONTAINER_DEBUG_LEVEL > 0
if constexpr (extents_type::rank() > 0) {
index_type _Prod = 1;
for (size_t _Idx = extents_type::_Rank; _Idx-- > 0;) {
_STL_VERIFY(_Prod == _Other.stride(_Idx),
"For all r in the range [0, extents_type::rank()), other.stride(r) must be equal to "
"extents().rev-prod-of-extents(r) (N4950 [mdspan.layout.right.cons]/10.1).");
_Prod = static_cast<index_type>(_Prod * this->_Exts.extent(_Idx));
}
}
_STL_VERIFY(_STD in_range<index_type>(_Other.required_span_size()),
"Value of other.required_span_size() must be representable as a value of type index_type (N4950 "
"[mdspan.layout.right.cons]/10.2).");
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
constexpr mapping& operator=(const mapping&) noexcept = default;
_NODISCARD constexpr const extents_type& extents() const noexcept {
return this->_Exts;
}
_NODISCARD constexpr index_type required_span_size() const noexcept {
return _Fwd_prod_of_extents<extents_type>::_Calculate(this->_Exts, extents_type::_Rank);
}
template <class... _IndexTypes>
requires (sizeof...(_IndexTypes) == extents_type::rank()) && (is_convertible_v<_IndexTypes, index_type> && ...)
&& (is_nothrow_constructible_v<index_type, _IndexTypes> && ...)
_NODISCARD constexpr index_type operator()(_IndexTypes... _Indices) const noexcept {
return _Index_impl(make_index_sequence<extents_type::rank()>{}, static_cast<index_type>(_Indices)...);
}
_NODISCARD static constexpr bool is_always_unique() noexcept {
return true;
}
_NODISCARD static constexpr bool is_always_exhaustive() noexcept {
return true;
}
_NODISCARD static constexpr bool is_always_strided() noexcept {
return true;
}
_NODISCARD static constexpr bool is_unique() noexcept {
return true;
}
_NODISCARD static constexpr bool is_exhaustive() noexcept {
return true;
}
_NODISCARD static constexpr bool is_strided() noexcept {
return true;
}
_NODISCARD constexpr index_type stride(const rank_type _Idx) const noexcept
requires (extents_type::rank() > 0)
{
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(_Idx < extents_type::_Rank,
"Value of i must be less than extents_type::rank() (N4950 [mdspan.layout.right.obs]/6).");
#endif // _CONTAINER_DEBUG_LEVEL > 0
return _Rev_prod_of_extents<extents_type>::_Calculate(this->_Exts, _Idx);
}
template <class _OtherExtents>
requires (extents_type::rank() == _OtherExtents::rank())
_NODISCARD_FRIEND constexpr bool operator==(const mapping& _Left, const mapping<_OtherExtents>& _Right) noexcept {
return _Left._Exts == _Right.extents();
}
private:
template <class... _IndexTypes, size_t... _Seq>
_NODISCARD constexpr index_type _Index_impl(
[[maybe_unused]] index_sequence<_Seq...> _Index_seq, _IndexTypes... _Indices) const noexcept {
_STL_INTERNAL_STATIC_ASSERT((same_as<_IndexTypes, index_type> && ...));
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(this->_Exts._Contains_multidimensional_index(_Index_seq, _Indices...),
"Value of extents_type::index-cast(i) must be a multidimensional index in extents_ (N4950 "
"[mdspan.layout.right.obs]/3).");
#endif // _CONTAINER_DEBUG_LEVEL > 0
index_type _Result = 0;
((_Result = static_cast<index_type>(_Indices + this->_Exts.extent(_Seq) * _Result)), ...);
return _Result;
}
};
template <class _Mp>
concept _Layout_mapping_alike = requires {
requires _Is_extents<typename _Mp::extents_type>;
{ _Mp::is_always_strided() } -> same_as<bool>;
{ _Mp::is_always_exhaustive() } -> same_as<bool>;
{ _Mp::is_always_unique() } -> same_as<bool>;
bool_constant<_Mp::is_always_strided()>::value;
bool_constant<_Mp::is_always_exhaustive()>::value;
bool_constant<_Mp::is_always_unique()>::value;
};
template <class _Extents>
class layout_stride::mapping : private _Maybe_fully_static_extents<_Extents>,
private _Maybe_empty_array<typename _Extents::index_type, _Extents::rank()> {
public:
using extents_type = _Extents;
using index_type = extents_type::index_type;
using size_type = extents_type::size_type;
using rank_type = extents_type::rank_type;
using layout_type = layout_stride;
private:
using _Extents_base = _Maybe_fully_static_extents<extents_type>;
using _Strides_base = _Maybe_empty_array<index_type, _Extents::rank()>;
static_assert(_Is_extents<extents_type>,
"Extents must be a specialization of std::extents (N4950 [mdspan.layout.stride.overview]/2).");
static_assert(
extents_type::rank_dynamic() != 0 || extents_type::_Is_static_multidim_index_space_size_representable(),
"If Extents::rank_dynamic() == 0 is true, then the size of the multidimensional index space Extents() must be "
"representable as a value of type typename Extents::index_type (N4950 [mdspan.layout.stride.overview]/4).");
template <class _OtherIndexType, size_t... _Indices>
constexpr mapping(const extents_type& _Exts_, span<_OtherIndexType, extents_type::rank()> _Strides_,
index_sequence<_Indices...>) noexcept
: _Extents_base(_Exts_), _Strides_base{static_cast<index_type>(_STD as_const(_Strides_[_Indices]))...} {
_STL_INTERNAL_STATIC_ASSERT(is_convertible_v<const _OtherIndexType&, index_type>
&& is_nothrow_constructible_v<index_type, const _OtherIndexType&>);
#if _CONTAINER_DEBUG_LEVEL > 0
if constexpr (extents_type::rank() != 0) {
bool _Found_zero = false;
bool _Overflow = false;
index_type _Req_span_size = 0;
for (rank_type _Idx = 0; _Idx < extents_type::_Rank; ++_Idx) {
const index_type _Stride = this->_Array[_Idx];
_STL_VERIFY(_Stride > 0, "Value of s[i] must be greater than 0 for all i in the range [0, rank_) "
"(N4950 [mdspan.layout.stride.cons]/4.1).");
const index_type _Ext = this->_Exts.extent(_Idx);
if (_Ext == 0) {
_Found_zero = true;
}
if (!_Found_zero && !_Overflow) {
index_type _Prod;
_Overflow = _Mul_overflow(static_cast<index_type>(_Ext - 1), _Stride, _Prod)
|| _Add_overflow(_Req_span_size, _Prod, _Req_span_size);
}
}
_STL_VERIFY(_Found_zero || !_Overflow, "REQUIRED-SPAN-SIZE(e, s) must be representable as a value of type "
"index_type (N4950 [mdspan.layout.stride.cons]/4.2).");
}
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
public:
constexpr mapping() noexcept : _Extents_base(extents_type{}) {
if constexpr (extents_type::rank() != 0) {
this->_Array.back() = 1;
for (rank_type _Idx = extents_type::_Rank - 1; _Idx-- > 0;) {
#if _CONTAINER_DEBUG_LEVEL > 0
const bool _Overflow =
_Mul_overflow(this->_Array[_Idx + 1], this->_Exts.extent(_Idx + 1), this->_Array[_Idx]);
// NB: N4950 requires value of 'layout_right::mapping<extents_type>().required_span_size()' to be
// representable as a value of type 'index_type', but this is not enough. We need to require every
// single stride to be representable as a value of type 'index_type', so we can get desired effects.
_STL_VERIFY(!_Overflow,
"Value of layout_right::mapping<extents_type>().required_span_size() must be "
"representable as a value of type index_type (N4950 [mdspan.layout.stride.cons]/1).");
#else // ^^^ _CONTAINER_DEBUG_LEVEL > 0 / _CONTAINER_DEBUG_LEVEL == 0 vvv
this->_Array[_Idx] = static_cast<index_type>(this->_Array[_Idx + 1] * this->_Exts.extent(_Idx + 1));
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
}
}
constexpr mapping(const mapping&) noexcept = default;
template <class _OtherIndexType>
requires is_convertible_v<const _OtherIndexType&, index_type>
&& is_nothrow_constructible_v<index_type, const _OtherIndexType&>
constexpr mapping(const extents_type& _Exts_, span<_OtherIndexType, extents_type::rank()> _Strides_) noexcept
: mapping(_Exts_, _Strides_, make_index_sequence<extents_type::rank()>{}) {}
template <class _OtherIndexType>
requires is_convertible_v<const _OtherIndexType&, index_type>
&& is_nothrow_constructible_v<index_type, const _OtherIndexType&>
constexpr mapping(
const extents_type& _Exts_, const array<_OtherIndexType, extents_type::rank()>& _Strides_) noexcept
: mapping(_Exts_, span{_Strides_}, make_index_sequence<extents_type::rank()>{}) {}
template <class _StridedLayoutMapping>
requires _Layout_mapping_alike<_StridedLayoutMapping>
&& is_constructible_v<extents_type, typename _StridedLayoutMapping::extents_type>
&& (_StridedLayoutMapping::is_always_unique()) && (_StridedLayoutMapping::is_always_strided())
constexpr explicit(!(
is_convertible_v<typename _StridedLayoutMapping::extents_type, extents_type>
&& (_Is_mapping_of<layout_left, _StridedLayoutMapping> || _Is_mapping_of<layout_right, _StridedLayoutMapping>
|| _Is_mapping_of<layout_stride, _StridedLayoutMapping>) ))
mapping(const _StridedLayoutMapping& _Other) noexcept
: _Extents_base(_Other.extents()) {
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(_STD in_range<index_type>(_Other.required_span_size()),
"Value of other.required_span_size() must be representable as a value of type index_type (N4950 "
"[mdspan.layout.stride.cons]/7.3).");
_STL_VERIFY(
_Offset(_Other) == 0, "Value of OFFSET(other) must be equal to 0 (N4950 [mdspan.layout.stride.cons]/7.4).");
#endif // _CONTAINER_DEBUG_LEVEL > 0
if constexpr (extents_type::_Rank != 0) {
for (rank_type _Idx = 0; _Idx < extents_type::_Rank; ++_Idx) {
const auto _Stride = _Other.stride(_Idx);
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(_Stride > 0, "Value of other.stride(r) must be greater than 0 for every rank index r of "
"extents() (N4950 [mdspan.layout.stride.cons]/7.2).");
#endif // _CONTAINER_DEBUG_LEVEL > 0
this->_Array[_Idx] = static_cast<index_type>(_Stride);
}
}
}
constexpr mapping& operator=(const mapping&) noexcept = default;
_NODISCARD constexpr const extents_type& extents() const noexcept {
return this->_Exts;
}
_NODISCARD constexpr array<index_type, extents_type::rank()> strides() const noexcept {
if constexpr (extents_type::rank() == 0) {
return {};
} else {
return this->_Array;
}
}
_NODISCARD constexpr index_type required_span_size() const noexcept {
if constexpr (extents_type::rank() == 0) {
return 1;
} else {
index_type _Result = 1;
for (rank_type _Idx = 0; _Idx < extents_type::_Rank; ++_Idx) {
const index_type _Ext = this->_Exts.extent(_Idx);
if (_Ext == 0) {
return 0;
}
_Result += (_Ext - 1) * this->_Array[_Idx];
}
return _Result;
}
}
template <class... _IndexTypes>
requires (sizeof...(_IndexTypes) == extents_type::rank()) && (is_convertible_v<_IndexTypes, index_type> && ...)
&& (is_nothrow_constructible_v<index_type, _IndexTypes> && ...)
_NODISCARD constexpr index_type operator()(_IndexTypes... _Indices) const noexcept {
return _Index_impl(make_index_sequence<extents_type::rank()>{}, static_cast<index_type>(_Indices)...);
}
_NODISCARD static constexpr bool is_always_unique() noexcept {
return true;
}
_NODISCARD static constexpr bool is_always_exhaustive() noexcept {
return false;
}
_NODISCARD static constexpr bool is_always_strided() noexcept {
return true;
}
_NODISCARD static constexpr bool is_unique() noexcept {
return true;
}
_NODISCARD constexpr bool is_exhaustive() const noexcept {
if constexpr (extents_type::rank() == 0) {
return true;
} else {
return required_span_size()
== _Fwd_prod_of_extents<extents_type>::_Calculate(this->_Exts, extents_type::_Rank);
}
}
_NODISCARD static constexpr bool is_strided() noexcept {
return true;
}
_NODISCARD constexpr index_type stride(const rank_type _Idx) const noexcept {
if constexpr (extents_type::rank() == 0) {
_STL_VERIFY(false, "The argument to stride must be nonnegative and less than extents_type::rank().");
} else {
return this->_Array[_Idx];
}
}
template <class _OtherMapping>
requires _Layout_mapping_alike<_OtherMapping> && (extents_type::rank() == _OtherMapping::extents_type::rank())
&& (_OtherMapping::is_always_strided())
_NODISCARD_FRIEND constexpr bool operator==(const mapping& _Left, const _OtherMapping& _Right) noexcept {
if constexpr (extents_type::rank() != 0) {
if (_Left.extents() != _Right.extents()) {
return false;
}
for (rank_type _Idx = 0; _Idx < extents_type::_Rank; ++_Idx) {
if (_STD cmp_not_equal(_Left.stride(_Idx), _Right.stride(_Idx))) {
return false;
}
}
}
return _Offset(_Right) == 0;