forked from gsl-lite/gsl-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsl-lite.hpp
4156 lines (3368 loc) · 127 KB
/
gsl-lite.hpp
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
//
// gsl-lite is based on GSL: Guidelines Support Library.
// For more information see https://github.com/gsl-lite/gsl-lite
//
// Copyright (c) 2015-2018 Martin Moene
// Copyright (c) 2015-2018 Microsoft Corporation. All rights reserved.
//
// This code is licensed under the MIT License (MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef GSL_GSL_LITE_HPP_INCLUDED
#define GSL_GSL_LITE_HPP_INCLUDED
#include <algorithm> // for swap() [pre-C++11], equal(), lexicographical_compare()
#include <exception> // for exception, terminate(), uncaught_exceptions()
#include <iterator> // for data(), size(), reverse_iterator<>, iterator_traits<>
#include <limits>
#include <memory> // for addressof(), unique_ptr<>, shared_ptr<>
#include <iosfwd> // for basic_ostream<>
#include <ios> // for ios_base, streamsize
#include <stdexcept> // for logic_error
#include <string>
#include <utility> // for move(), forward<>(), swap()
#include <cstddef> // for size_t, ptrdiff_t, nullptr_t
#define gsl_lite_MAJOR 0
#define gsl_lite_MINOR 37
#define gsl_lite_PATCH 0
#define gsl_lite_VERSION gsl_STRINGIFY(gsl_lite_MAJOR) "." gsl_STRINGIFY(gsl_lite_MINOR) "." gsl_STRINGIFY(gsl_lite_PATCH)
// gsl-lite backward compatibility:
#if !defined( gsl_CONFIG_DEFAULTS_VERSION )
# define gsl_CONFIG_DEFAULTS_VERSION gsl_lite_MAJOR
#endif
#ifdef gsl_CONFIG_ALLOWS_SPAN_CONTAINER_CTOR
# define gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR gsl_CONFIG_ALLOWS_SPAN_CONTAINER_CTOR
# pragma message ("gsl_CONFIG_ALLOWS_SPAN_CONTAINER_CTOR is deprecated since gsl-lite 0.7; replace with gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR, or consider span(with_container, cont).")
#endif
#if defined( gsl_CONFIG_CONTRACT_LEVEL_ON )
# pragma message ("gsl_CONFIG_CONTRACT_LEVEL_ON is deprecated since gsl-lite 0.36; replace with gsl_CONFIG_CONTRACT_CHECKING_ON.")
# define gsl_CONFIG_CONTRACT_CHECKING_ON
#endif
#if defined( gsl_CONFIG_CONTRACT_LEVEL_OFF )
# pragma message ("gsl_CONFIG_CONTRACT_LEVEL_OFF is deprecated since gsl-lite 0.36; replace with gsl_CONFIG_CONTRACT_CHECKING_OFF.")
# define gsl_CONFIG_CONTRACT_CHECKING_OFF
#endif
#if defined( gsl_CONFIG_CONTRACT_LEVEL_EXPECTS_ONLY )
# pragma message ("gsl_CONFIG_CONTRACT_LEVEL_EXPECTS_ONLY is deprecated since gsl-lite 0.36; replace with gsl_CONFIG_CONTRACT_CHECKING_ENSURES_OFF.")
# define gsl_CONFIG_CONTRACT_CHECKING_ON
# define gsl_CONFIG_CONTRACT_CHECKING_ENSURES_OFF
#elif defined( gsl_CONFIG_CONTRACT_LEVEL_ENSURES_ONLY )
# pragma message ("gsl_CONFIG_CONTRACT_LEVEL_ENSURES_ONLY is deprecated since gsl-lite 0.36; replace with gsl_CONFIG_CONTRACT_CHECKING_EXPECTS_OFF.")
# define gsl_CONFIG_CONTRACT_CHECKING_ON
# define gsl_CONFIG_CONTRACT_CHECKING_EXPECTS_OFF
#endif
// M-GSL compatibility:
#if defined( GSL_THROW_ON_CONTRACT_VIOLATION )
# define gsl_CONFIG_CONTRACT_VIOLATION_THROWS
#endif
#if defined( GSL_TERMINATE_ON_CONTRACT_VIOLATION )
# define gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES
#endif
#if defined( GSL_UNENFORCED_ON_CONTRACT_VIOLATION )
# define gsl_CONFIG_CONTRACT_CHECKING_OFF
#endif
// Configuration: Features
#ifndef gsl_FEATURE_WITH_CONTAINER_TO_STD
# define gsl_FEATURE_WITH_CONTAINER_TO_STD 99
#endif
#ifndef gsl_FEATURE_MAKE_SPAN_TO_STD
# define gsl_FEATURE_MAKE_SPAN_TO_STD 99
#endif
#ifndef gsl_FEATURE_BYTE_SPAN_TO_STD
# define gsl_FEATURE_BYTE_SPAN_TO_STD 99
#endif
#ifndef gsl_FEATURE_IMPLICIT_MACRO
# define gsl_FEATURE_IMPLICIT_MACRO 0
#endif
#ifndef gsl_FEATURE_OWNER_MACRO
# define gsl_FEATURE_OWNER_MACRO (gsl_CONFIG_DEFAULTS_VERSION == 0)
#endif
#ifndef gsl_FEATURE_EXPERIMENTAL_RETURN_GUARD
# define gsl_FEATURE_EXPERIMENTAL_RETURN_GUARD 0
#endif
#ifndef gsl_FEATURE_GSL_LITE_NAMESPACE
# define gsl_FEATURE_GSL_LITE_NAMESPACE (gsl_CONFIG_DEFAULTS_VERSION >= 1)
#endif
// Configuration: Other
#if defined( gsl_CONFIG_TRANSPARENT_NOT_NULL ) && gsl_CONFIG_TRANSPARENT_NOT_NULL && defined( gsl_CONFIG_NOT_NULL_GET_BY_CONST_REF )
# error configuration option gsl_CONFIG_NOT_NULL_GET_BY_CONST_REF is meaningless if gsl_CONFIG_TRANSPARENT_NOT_NULL=1
#endif
#ifndef gsl_CONFIG_DEPRECATE_TO_LEVEL
# if gsl_CONFIG_DEFAULTS_VERSION >= 1
# define gsl_CONFIG_DEPRECATE_TO_LEVEL 6
# else
# define gsl_CONFIG_DEPRECATE_TO_LEVEL 0
# endif
#endif
#ifndef gsl_CONFIG_SPAN_INDEX_TYPE
# define gsl_CONFIG_SPAN_INDEX_TYPE std::size_t
#endif
#ifndef gsl_CONFIG_INDEX_TYPE
# if gsl_CONFIG_DEFAULTS_VERSION >= 1
// p0122r3 uses std::ptrdiff_t
# define gsl_CONFIG_INDEX_TYPE std::ptrdiff_t
# else
# define gsl_CONFIG_INDEX_TYPE gsl_CONFIG_SPAN_INDEX_TYPE
# endif
#endif
#ifndef gsl_CONFIG_NOT_NULL_EXPLICIT_CTOR
# define gsl_CONFIG_NOT_NULL_EXPLICIT_CTOR (gsl_CONFIG_DEFAULTS_VERSION >= 1)
#endif
#ifndef gsl_CONFIG_NOT_NULL_GET_BY_CONST_REF
# define gsl_CONFIG_NOT_NULL_GET_BY_CONST_REF 0
#endif
#ifndef gsl_CONFIG_TRANSPARENT_NOT_NULL
# define gsl_CONFIG_TRANSPARENT_NOT_NULL (gsl_CONFIG_DEFAULTS_VERSION >= 1)
#endif
#ifndef gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS
# define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS 0
#endif
#ifndef gsl_CONFIG_ALLOWS_SPAN_COMPARISON
# define gsl_CONFIG_ALLOWS_SPAN_COMPARISON (gsl_CONFIG_DEFAULTS_VERSION == 0)
#endif
#ifndef gsl_CONFIG_ALLOWS_NONSTRICT_SPAN_COMPARISON
# define gsl_CONFIG_ALLOWS_NONSTRICT_SPAN_COMPARISON 1
#endif
#ifndef gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR
# define gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR 0
#endif
#ifndef gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION
# define gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION (gsl_CONFIG_DEFAULTS_VERSION >= 1)
#endif
#if 1 < defined( gsl_CONFIG_CONTRACT_CHECKING_AUDIT ) + defined( gsl_CONFIG_CONTRACT_CHECKING_ON ) + defined( gsl_CONFIG_CONTRACT_CHECKING_OFF )
# error only one of gsl_CONFIG_CONTRACT_CHECKING_AUDIT, gsl_CONFIG_CONTRACT_CHECKING_ON, and gsl_CONFIG_CONTRACT_CHECKING_OFF may be defined
#endif
#if 1 < defined( gsl_CONFIG_CONTRACT_VIOLATION_THROWS ) + defined( gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES ) + defined( gsl_CONFIG_CONTRACT_VIOLATION_CALLS_HANDLER )
# error only one of gsl_CONFIG_CONTRACT_VIOLATION_THROWS, gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES, and gsl_CONFIG_CONTRACT_VIOLATION_CALLS_HANDLER may be defined
#endif
#if 1 < defined( gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME ) + defined( gsl_CONFIG_UNENFORCED_CONTRACTS_ELIDE )
# error only one of gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME and gsl_CONFIG_UNENFORCED_CONTRACTS_ELIDE may be defined
#endif
// C++ language version detection (C++20 is speculative):
// Note: VC14.0/1900 (VS2015) lacks too much from C++14.
#ifndef gsl_CPLUSPLUS
# if defined(_MSVC_LANG ) && !defined(__clang__)
# define gsl_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG )
# else
# define gsl_CPLUSPLUS __cplusplus
# endif
#endif
#define gsl_CPP98_OR_GREATER ( gsl_CPLUSPLUS >= 199711L )
#define gsl_CPP11_OR_GREATER ( gsl_CPLUSPLUS >= 201103L )
#define gsl_CPP14_OR_GREATER ( gsl_CPLUSPLUS >= 201402L )
#define gsl_CPP17_OR_GREATER ( gsl_CPLUSPLUS >= 201703L )
#define gsl_CPP20_OR_GREATER ( gsl_CPLUSPLUS >= 202000L )
// C++ language version (represent 98 as 3):
#define gsl_CPLUSPLUS_V ( gsl_CPLUSPLUS / 100 - (gsl_CPLUSPLUS > 200000 ? 2000 : 1994) )
// half-open range [lo..hi):
#define gsl_BETWEEN( v, lo, hi ) ( (lo) <= (v) && (v) < (hi) )
// Compiler versions:
// MSVC++ 6.0 _MSC_VER == 1200 gsl_COMPILER_MSVC_VERSION == 60 (Visual Studio 6.0)
// MSVC++ 7.0 _MSC_VER == 1300 gsl_COMPILER_MSVC_VERSION == 70 (Visual Studio .NET 2002)
// MSVC++ 7.1 _MSC_VER == 1310 gsl_COMPILER_MSVC_VERSION == 71 (Visual Studio .NET 2003)
// MSVC++ 8.0 _MSC_VER == 1400 gsl_COMPILER_MSVC_VERSION == 80 (Visual Studio 2005)
// MSVC++ 9.0 _MSC_VER == 1500 gsl_COMPILER_MSVC_VERSION == 90 (Visual Studio 2008)
// MSVC++ 10.0 _MSC_VER == 1600 gsl_COMPILER_MSVC_VERSION == 100 (Visual Studio 2010)
// MSVC++ 11.0 _MSC_VER == 1700 gsl_COMPILER_MSVC_VERSION == 110 (Visual Studio 2012)
// MSVC++ 12.0 _MSC_VER == 1800 gsl_COMPILER_MSVC_VERSION == 120 (Visual Studio 2013)
// MSVC++ 14.0 _MSC_VER == 1900 gsl_COMPILER_MSVC_VERSION == 140 (Visual Studio 2015)
// MSVC++ 14.1 _MSC_VER >= 1910 gsl_COMPILER_MSVC_VERSION == 141 (Visual Studio 2017)
// MSVC++ 14.2 _MSC_VER >= 1920 gsl_COMPILER_MSVC_VERSION == 142 (Visual Studio 2019)
#if defined(_MSC_VER ) && !defined(__clang__)
# define gsl_COMPILER_MSVC_VER (_MSC_VER )
# define gsl_COMPILER_MSVC_VERSION (_MSC_VER / 10 - 10 * ( 5 + (_MSC_VER < 1900 ) ) )
# define gsl_COMPILER_MSVC_VERSION_FULL (_MSC_VER - 100 * ( 5 + (_MSC_VER < 1900 ) ) )
#else
# define gsl_COMPILER_MSVC_VER 0
# define gsl_COMPILER_MSVC_VERSION 0
# define gsl_COMPILER_MSVC_VERSION_FULL 0
#endif
#define gsl_COMPILER_VERSION( major, minor, patch ) ( 10 * ( 10 * (major) + (minor) ) + (patch) )
// AppleClang 7.0.0 __apple_build_version__ == 7000172 gsl_COMPILER_APPLECLANG_VERSION == 700 (Xcode 7.0, 7.0.1) (LLVM 3.7.0)
// AppleClang 7.0.0 __apple_build_version__ == 7000176 gsl_COMPILER_APPLECLANG_VERSION == 700 (Xcode 7.1) (LLVM 3.7.0)
// AppleClang 7.0.2 __apple_build_version__ == 7000181 gsl_COMPILER_APPLECLANG_VERSION == 702 (Xcode 7.2, 7.2.1) (LLVM 3.7.0)
// AppleClang 7.3.0 __apple_build_version__ == 7030029 gsl_COMPILER_APPLECLANG_VERSION == 730 (Xcode 7.3) (LLVM 3.8.0)
// AppleClang 7.3.0 __apple_build_version__ == 7030031 gsl_COMPILER_APPLECLANG_VERSION == 730 (Xcode 7.3.1) (LLVM 3.8.0)
// AppleClang 8.0.0 __apple_build_version__ == 8000038 gsl_COMPILER_APPLECLANG_VERSION == 800 (Xcode 8.0) (LLVM 3.9.0)
// AppleClang 8.0.0 __apple_build_version__ == 8000042 gsl_COMPILER_APPLECLANG_VERSION == 800 (Xcode 8.1, 8.2, 8.2.1) (LLVM 3.9.0)
// AppleClang 8.1.0 __apple_build_version__ == 8020038 gsl_COMPILER_APPLECLANG_VERSION == 810 (Xcode 8.3) (LLVM 3.9.0)
// AppleClang 8.1.0 __apple_build_version__ == 8020041 gsl_COMPILER_APPLECLANG_VERSION == 810 (Xcode 8.3.1) (LLVM 3.9.0)
// AppleClang 8.1.0 __apple_build_version__ == 8020042 gsl_COMPILER_APPLECLANG_VERSION == 810 (Xcode 8.3.2, 8.3.3) (LLVM 3.9.0)
// AppleClang 9.0.0 __apple_build_version__ == 9000037 gsl_COMPILER_APPLECLANG_VERSION == 900 (Xcode 9.0) (LLVM 4.0.0?)
// AppleClang 9.0.0 __apple_build_version__ == 9000038 gsl_COMPILER_APPLECLANG_VERSION == 900 (Xcode 9.1) (LLVM 4.0.0?)
// AppleClang 9.0.0 __apple_build_version__ == 9000039 gsl_COMPILER_APPLECLANG_VERSION == 900 (Xcode 9.2) (LLVM 4.0.0?)
// AppleClang 9.1.0 __apple_build_version__ == 9020039 gsl_COMPILER_APPLECLANG_VERSION == 910 (Xcode 9.3, 9.3.1) (LLVM 5.0.2?)
// AppleClang 9.1.0 __apple_build_version__ == 9020039 gsl_COMPILER_APPLECLANG_VERSION == 910 (Xcode 9.4, 9.4.1) (LLVM 5.0.2?)
// AppleClang 10.0.0 __apple_build_version__ == 10001145 gsl_COMPILER_APPLECLANG_VERSION == 1000 (Xcode 10.0, 10.1) (LLVM 6.0.1?)
// AppleClang 10.0.1 __apple_build_version__ == 10010046 gsl_COMPILER_APPLECLANG_VERSION == 1001 (Xcode 10.2, 10.2.1, 10.3) (LLVM 7.0.0?)
// AppleClang 11.0.0 __apple_build_version__ == 11000033 gsl_COMPILER_APPLECLANG_VERSION == 1100 (Xcode 11.1, 11.2, 11.3) (LLVM 8.0.0?)
#if defined( __apple_build_version__ )
# define gsl_COMPILER_APPLECLANG_VERSION gsl_COMPILER_VERSION( __clang_major__, __clang_minor__, __clang_patchlevel__ )
# define gsl_COMPILER_CLANG_VERSION 0
#elif defined( __clang__ )
# define gsl_COMPILER_APPLECLANG_VERSION 0
# define gsl_COMPILER_CLANG_VERSION gsl_COMPILER_VERSION( __clang_major__, __clang_minor__, __clang_patchlevel__ )
#else
# define gsl_COMPILER_APPLECLANG_VERSION 0
# define gsl_COMPILER_CLANG_VERSION 0
#endif
#if defined(__GNUC__) && !defined(__clang__)
# define gsl_COMPILER_GNUC_VERSION gsl_COMPILER_VERSION( __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ )
#else
# define gsl_COMPILER_GNUC_VERSION 0
#endif
// Compiler non-strict aliasing:
#if defined(__clang__) || defined(__GNUC__)
# define gsl_may_alias __attribute__((__may_alias__))
#else
# define gsl_may_alias
#endif
// Presence of gsl, language and library features:
#define gsl_IN_STD( v ) ( ((v) == 98 ? 3 : (v)) >= gsl_CPLUSPLUS_V )
#define gsl_DEPRECATE_TO_LEVEL( level ) ( level <= gsl_CONFIG_DEPRECATE_TO_LEVEL )
#define gsl_FEATURE_TO_STD( feature ) ( gsl_IN_STD( gsl_FEATURE( feature##_TO_STD ) ) )
#define gsl_FEATURE( feature ) ( gsl_FEATURE_##feature )
#define gsl_CONFIG( feature ) ( gsl_CONFIG_##feature )
#define gsl_HAVE( feature ) ( gsl_HAVE_##feature )
// Presence of wide character support:
#ifdef __DJGPP__
# define gsl_HAVE_WCHAR 0
#else
# define gsl_HAVE_WCHAR 1
#endif
// Presence of language & library features:
#if gsl_BETWEEN(gsl_COMPILER_GNUC_VERSION, 1, 500) || gsl_BETWEEN(gsl_COMPILER_CLANG_VERSION, 1, 360) || gsl_COMPILER_APPLECLANG_VERSION
# ifdef __EXCEPTIONS
# define gsl_HAVE_EXCEPTIONS 1
# else
# define gsl_HAVE_EXCEPTIONS 0
# endif // __EXCEPTIONS
#elif gsl_COMPILER_GNUC_VERSION >= 500 || gsl_COMPILER_CLANG_VERSION >= 500
# ifdef __cpp_exceptions
# define gsl_HAVE_EXCEPTIONS 1
# else
# define gsl_HAVE_EXCEPTIONS 0
# endif // __cpp_exceptions
#elif gsl_COMPILER_MSVC_VERSION
# ifdef _CPPUNWIND
# define gsl_HAVE_EXCEPTIONS 1
# else
# define gsl_HAVE_EXCEPTIONS 0
# endif // _CPPUNWIND
#else
// For all other compilers, assume exceptions are always enabled.
# define gsl_HAVE_EXCEPTIONS 1
#endif
#if defined( gsl_CONFIG_CONTRACT_VIOLATION_THROWS ) && !gsl_HAVE( EXCEPTIONS )
# error Cannot use gsl_CONFIG_CONTRACT_VIOLATION_THROWS if exceptions are disabled.
#endif // defined( gsl_CONFIG_CONTRACT_VIOLATION_THROWS ) && !gsl_HAVE( EXCEPTIONS )
#ifdef _HAS_CPP0X
# define gsl_HAS_CPP0X _HAS_CPP0X
#else
# define gsl_HAS_CPP0X 0
#endif
#define gsl_CPP11_100 (gsl_CPP11_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1600)
#define gsl_CPP11_110 (gsl_CPP11_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1700)
#define gsl_CPP11_120 (gsl_CPP11_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1800)
#define gsl_CPP11_140 (gsl_CPP11_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1900)
#define gsl_CPP14_000 (gsl_CPP14_OR_GREATER)
#define gsl_CPP14_120 (gsl_CPP14_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1800)
#define gsl_CPP14_140 (gsl_CPP14_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1900)
#define gsl_CPP17_000 (gsl_CPP17_OR_GREATER)
#define gsl_CPP17_140 (gsl_CPP17_OR_GREATER || gsl_COMPILER_MSVC_VER >= 1900)
#define gsl_CPP11_140_CPP0X_90 (gsl_CPP11_140 || (gsl_COMPILER_MSVC_VER >= 1500 && gsl_HAS_CPP0X))
#define gsl_CPP11_140_CPP0X_100 (gsl_CPP11_140 || (gsl_COMPILER_MSVC_VER >= 1600 && gsl_HAS_CPP0X))
// Presence of C++11 language features:
#define gsl_HAVE_AUTO gsl_CPP11_100
#define gsl_HAVE_NULLPTR gsl_CPP11_100
#define gsl_HAVE_RVALUE_REFERENCE gsl_CPP11_100
#define gsl_HAVE_FUNCTION_REF_QUALIFIER ( gsl_CPP14_140 && ! gsl_BETWEEN( gsl_COMPILER_GNUC_VERSION, 1, 481 ) )
#define gsl_HAVE_ENUM_CLASS gsl_CPP11_110
#define gsl_HAVE_ALIAS_TEMPLATE gsl_CPP11_120
#define gsl_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG gsl_CPP11_120
#define gsl_HAVE_EXPLICIT gsl_CPP11_120
#define gsl_HAVE_INITIALIZER_LIST gsl_CPP11_120
#define gsl_HAVE_VARIADIC_TEMPLATE gsl_CPP11_120
#define gsl_HAVE_IS_DELETE gsl_CPP11_120
#define gsl_HAVE_CONSTEXPR_11 gsl_CPP11_140
#define gsl_HAVE_IS_DEFAULT gsl_CPP11_140
#define gsl_HAVE_NOEXCEPT gsl_CPP11_140
#define gsl_HAVE_NORETURN ( gsl_CPP11_140 && ! gsl_BETWEEN( gsl_COMPILER_GNUC_VERSION, 1, 480 ) )
#define gsl_HAVE_EXPRESSION_SFINAE gsl_CPP11_140
#if gsl_CPP11_OR_GREATER
// see above
#endif
// Presence of C++14 language features:
#define gsl_HAVE_CONSTEXPR_14 ( gsl_CPP14_000 && ! gsl_BETWEEN( gsl_COMPILER_GNUC_VERSION, 1, 600 ) )
#define gsl_HAVE_DECLTYPE_AUTO gsl_CPP14_140
#define gsl_HAVE_DEPRECATED ( gsl_CPP14_140 && ! gsl_BETWEEN( gsl_COMPILER_MSVC_VERSION, 1, 142 ) )
// Presence of C++17 language features:
// MSVC: template parameter deduction guides since Visual Studio 2017 v15.7
#define gsl_HAVE_ENUM_CLASS_CONSTRUCTION_FROM_UNDERLYING_TYPE gsl_CPP17_000
#define gsl_HAVE_DEDUCTION_GUIDES ( gsl_CPP17_000 && ! gsl_BETWEEN( gsl_COMPILER_MSVC_VERSION_FULL, 1, 1414 ) )
#define gsl_HAVE_NODISCARD gsl_CPP17_000
#define gsl_HAVE_CONSTEXPR_17 gsl_CPP17_OR_GREATER
// Presence of C++20 language features:
#define gsl_HAVE_CONSTEXPR_20 gsl_CPP20_OR_GREATER
// Presence of C++ library features:
#define gsl_HAVE_ADDRESSOF gsl_CPP17_000
#define gsl_HAVE_ARRAY gsl_CPP11_110
#define gsl_HAVE_TYPE_TRAITS gsl_CPP11_110
#define gsl_HAVE_TR1_TYPE_TRAITS gsl_CPP11_110
#define gsl_HAVE_CONTAINER_DATA_METHOD gsl_CPP11_140_CPP0X_90
#define gsl_HAVE_STD_DATA gsl_CPP17_000
#ifdef __cpp_lib_ssize
# define gsl_HAVE_STD_SSIZE 1
#else
# define gsl_HAVE_STD_SSIZE ( gsl_COMPILER_GNUC_VERSION >= 1000 && __cplusplus > 201703L )
#endif
#define gsl_HAVE_SIZED_TYPES gsl_CPP11_140
#define gsl_HAVE_MAKE_SHARED gsl_CPP11_140_CPP0X_100
#define gsl_HAVE_SHARED_PTR gsl_CPP11_140_CPP0X_100
#define gsl_HAVE_UNIQUE_PTR gsl_CPP11_140_CPP0X_100
#define gsl_HAVE_MAKE_UNIQUE gsl_CPP14_120
#define gsl_HAVE_UNCAUGHT_EXCEPTIONS gsl_CPP17_140
#define gsl_HAVE_ADD_CONST gsl_HAVE_TYPE_TRAITS
#define gsl_HAVE_INTEGRAL_CONSTANT gsl_HAVE_TYPE_TRAITS
#define gsl_HAVE_REMOVE_CONST gsl_HAVE_TYPE_TRAITS
#define gsl_HAVE_REMOVE_REFERENCE gsl_HAVE_TYPE_TRAITS
#define gsl_HAVE_REMOVE_CVREF gsl_CPP20_OR_GREATER
#define gsl_HAVE_TR1_ADD_CONST gsl_HAVE_TR1_TYPE_TRAITS
#define gsl_HAVE_TR1_INTEGRAL_CONSTANT gsl_HAVE_TR1_TYPE_TRAITS
#define gsl_HAVE_TR1_REMOVE_CONST gsl_HAVE_TR1_TYPE_TRAITS
#define gsl_HAVE_TR1_REMOVE_REFERENCE gsl_HAVE_TR1_TYPE_TRAITS
// C++ feature usage:
#if gsl_HAVE( ADDRESSOF )
# define gsl_ADDRESSOF(x) std::addressof(x)
#else
# define gsl_ADDRESSOF(x) (&x)
#endif
#if gsl_HAVE( CONSTEXPR_11 )
# define gsl_constexpr constexpr
#else
# define gsl_constexpr /*constexpr*/
#endif
#if gsl_HAVE( CONSTEXPR_14 )
# define gsl_constexpr14 constexpr
#else
# define gsl_constexpr14 /*constexpr*/
#endif
#if gsl_HAVE( CONSTEXPR_17 )
# define gsl_constexpr17 constexpr
#else
# define gsl_constexpr17 /*constexpr*/
#endif
#if gsl_HAVE( CONSTEXPR_20 )
# define gsl_constexpr20 constexpr
#else
# define gsl_constexpr20 /*constexpr*/
#endif
#if gsl_HAVE( EXPLICIT )
# define gsl_explicit explicit
#else
# define gsl_explicit /*explicit*/
#endif
#if gsl_FEATURE( IMPLICIT_MACRO )
# define implicit /*implicit*/
#endif
#if gsl_HAVE( IS_DELETE )
# define gsl_is_delete = delete
#else
# define gsl_is_delete
#endif
#if gsl_HAVE( IS_DELETE )
# define gsl_is_delete_access public
#else
# define gsl_is_delete_access private
#endif
#if !gsl_HAVE( NOEXCEPT ) || defined( gsl_TESTING_ )
# define gsl_noexcept /*noexcept*/
#else
# define gsl_noexcept noexcept
#endif
#if gsl_HAVE( NULLPTR )
# define gsl_nullptr nullptr
#else
# define gsl_nullptr NULL
#endif
#if gsl_HAVE( NODISCARD )
# define gsl_NODISCARD [[nodiscard]]
#else
# define gsl_NODISCARD
#endif
#if gsl_HAVE( NORETURN )
# define gsl_NORETURN [[noreturn]]
#elif defined(_MSC_VER)
# define gsl_NORETURN __declspec(noreturn)
#else
# define gsl_NORETURN
#endif
#if gsl_HAVE( DEPRECATED ) && !defined( gsl_TESTING_ )
# define gsl_DEPRECATED [[deprecated]]
# define gsl_DEPRECATED_MSG( msg ) [[deprecated( msg )]]
#else
# define gsl_DEPRECATED
# define gsl_DEPRECATED_MSG( msg )
#endif
#if gsl_HAVE( TYPE_TRAITS )
#define gsl_DEFINE_ENUM_BITMASK_OPERATORS_( ENUM ) \
gsl_NODISCARD gsl_api inline gsl_constexpr ENUM \
operator~( ENUM val ) gsl_noexcept \
{ \
typedef typename ::gsl::std11::underlying_type<ENUM>::type U; \
return ENUM( ~U( val ) ); \
} \
gsl_NODISCARD gsl_api inline gsl_constexpr ENUM \
operator|( ENUM lhs, ENUM rhs ) gsl_noexcept \
{ \
typedef typename ::gsl::std11::underlying_type<ENUM>::type U; \
return ENUM( U( lhs ) | U( rhs ) ); \
} \
gsl_NODISCARD gsl_api inline gsl_constexpr ENUM \
operator&( ENUM lhs, ENUM rhs ) gsl_noexcept \
{ \
typedef typename ::gsl::std11::underlying_type<ENUM>::type U; \
return ENUM( U( lhs ) & U( rhs ) ); \
} \
gsl_NODISCARD gsl_api inline gsl_constexpr ENUM \
operator^( ENUM lhs, ENUM rhs ) gsl_noexcept \
{ \
typedef typename ::gsl::std11::underlying_type<ENUM>::type U; \
return ENUM( U( lhs ) ^ U( rhs ) ); \
} \
gsl_api inline gsl_constexpr14 ENUM & \
operator|=( ENUM & lhs, ENUM rhs ) gsl_noexcept \
{ \
return lhs = lhs | rhs; \
} \
gsl_api inline gsl_constexpr14 ENUM & \
operator&=( ENUM & lhs, ENUM rhs ) gsl_noexcept \
{ \
return lhs = lhs & rhs; \
} \
gsl_api inline gsl_constexpr14 ENUM & \
operator^=( ENUM & lhs, ENUM rhs ) gsl_noexcept \
{ \
return lhs = lhs ^ rhs; \
}
#define gsl_DEFINE_ENUM_RELATIONAL_OPERATORS_( ENUM ) \
gsl_NODISCARD gsl_api inline gsl_constexpr bool \
operator<( ENUM lhs, ENUM rhs ) gsl_noexcept \
{ \
typedef typename ::gsl::std11::underlying_type<ENUM>::type U; \
return U( lhs ) < U( rhs ); \
} \
gsl_NODISCARD gsl_api inline gsl_constexpr bool \
operator>( ENUM lhs, ENUM rhs ) gsl_noexcept \
{ \
typedef typename ::gsl::std11::underlying_type<ENUM>::type U; \
return U( lhs ) > U( rhs ); \
} \
gsl_NODISCARD gsl_api inline gsl_constexpr bool \
operator<=( ENUM lhs, ENUM rhs ) gsl_noexcept \
{ \
typedef typename ::gsl::std11::underlying_type<ENUM>::type U; \
return U( lhs ) <= U( rhs ); \
} \
gsl_NODISCARD gsl_api inline gsl_constexpr bool \
operator>=( ENUM lhs, ENUM rhs ) gsl_noexcept \
{ \
typedef typename ::gsl::std11::underlying_type<ENUM>::type U; \
return U( lhs ) >= U( rhs ); \
}
//
// Defines bitmask operators `|`, `&`, `^`, `~`, `|=`, `&=`, and `^=` for the given enum type.
//
// enum class Vegetables {
// tomato = 0b001,
// onion = 0b010,
// eggplant = 0b100
// };
// gsl_DEFINE_ENUM_BITMASK_OPERATORS( Vegetables )
//
#define gsl_DEFINE_ENUM_BITMASK_OPERATORS( ENUM ) gsl_DEFINE_ENUM_BITMASK_OPERATORS_( ENUM )
//
// Defines relational operators `<`, `>`, `<=`, `>=` for the given enum type.
//
// enum class OperatorPrecedence {
// additive = 0,
// multiplicative = 1,
// power = 2
// };
// gsl_DEFINE_ENUM_RELATIONAL_OPERATORS( OperatorPrecedence )
//
#define gsl_DEFINE_ENUM_RELATIONAL_OPERATORS( ENUM ) gsl_DEFINE_ENUM_RELATIONAL_OPERATORS_( ENUM )
#endif // gsl_HAVE( TYPE_TRAITS )
#define gsl_DIMENSION_OF( a ) ( sizeof(a) / sizeof(0[a]) )
// Method enabling (C++98, VC120 (VS2013) cannot use __VA_ARGS__)
#if gsl_HAVE( EXPRESSION_SFINAE )
# define gsl_DECLTYPE_(T, EXPR) decltype( EXPR )
#else
# define gsl_DECLTYPE_(T, EXPR) T
#endif
// NOTE: When using SFINAE in gsl-lite, please note that overloads of function templates must always use SFINAE with non-type default arguments
// as explained in https://en.cppreference.com/w/cpp/types/enable_if#Notes. `gsl_ENABLE_IF_()` implements graceful fallback to default
// type arguments (for compilers that don't support non-type default arguments); please verify that this is appropriate in the given
// situation, and add additional checks if necessary.
//
// Also, please note that `gsl_ENABLE_IF_()` doesn't enforce the constraint at all if no compiler/library support is available (i.e. pre-C++11).
#if gsl_HAVE( TYPE_TRAITS ) && gsl_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG )
# if !gsl_BETWEEN( gsl_COMPILER_MSVC_VERSION, 1, 140 ) // VS 2013 seems to have trouble with SFINAE for default non-type arguments
# define gsl_ENABLE_IF_(VA) , typename std::enable_if< ( VA ), int >::type = 0
# else
# define gsl_ENABLE_IF_(VA) , typename = typename std::enable_if< ( VA ), ::gsl::detail::enabler >::type
# endif
#else
# define gsl_ENABLE_IF_(VA)
#endif
// Other features:
#define gsl_HAVE_CONSTRAINED_SPAN_CONTAINER_CTOR \
( gsl_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG && gsl_HAVE_CONTAINER_DATA_METHOD )
// Note: !defined(__NVCC__) doesn't work with nvcc here:
#define gsl_HAVE_UNCONSTRAINED_SPAN_CONTAINER_CTOR \
( gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR && (__NVCC__== 0) )
// GSL API (e.g. for CUDA platform):
// Guidelines for using `gsl_api`:
//
// NVCC imposes the restriction that a function annotated `__host__ __device__` cannot call host-only or device-only functions.
// This makes `gsl_api` inappropriate for generic functions that call unknown code, e.g. the template constructors of `span<>`
// or functions like `finally()` which accept an arbitrary function object.
// It is often preferable to annotate functions only with `gsl_constexpr` or `gsl_constexpr14`. The "extended constexpr" mode
// of NVCC (currently an experimental feature) will implicitly consider constexpr functions `__host__ __device__` functions
// but tolerates calls to host-only or device-only functions.
#ifndef gsl_api
# ifdef __CUDACC__
# define gsl_api __host__ __device__
# else
# define gsl_api /*gsl_api*/
# endif
#endif
// Additional includes:
#if gsl_HAVE( ARRAY )
# include <array>
#endif
#if !gsl_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR ) || !gsl_HAVE( AUTO )
# include <vector>
#endif
#if gsl_HAVE( INITIALIZER_LIST )
# include <initializer_list>
#endif
#if gsl_HAVE( TYPE_TRAITS )
# include <type_traits> // for enable_if<>,
// add_const<>, add_pointer<>, common_type<>, make_signed<>, remove_cv<>, remove_const<>, remove_volatile<>, remove_reference<>, remove_cvref<>, remove_pointer<>, underlying_type<>,
// is_assignable<>, is_constructible<>, is_const<>, is_convertible<>, is_integral<>, is_pointer<>, is_signed<>,
// integral_constant<>, declval()
#elif gsl_HAVE( TR1_TYPE_TRAITS )
# include <tr1/type_traits> // for add_const<>, remove_cv<>, remove_const<>, remove_volatile<>, remove_reference<>, integral_constant<>
#endif
// MSVC warning suppression macros:
#if gsl_COMPILER_MSVC_VERSION >= 140 && !defined(__NVCC__)
# define gsl_SUPPRESS_MSGSL_WARNING(expr) [[gsl::suppress(expr)]]
# define gsl_SUPPRESS_MSVC_WARNING(code, descr) __pragma(warning(suppress: code) )
# define gsl_DISABLE_MSVC_WARNINGS(codes) __pragma(warning(push)) __pragma(warning(disable: codes))
# define gsl_RESTORE_MSVC_WARNINGS() __pragma(warning(pop ))
#else
// TODO: define for Clang
# define gsl_SUPPRESS_MSGSL_WARNING(expr)
# define gsl_SUPPRESS_MSVC_WARNING(code, descr)
# define gsl_DISABLE_MSVC_WARNINGS(codes)
# define gsl_RESTORE_MSVC_WARNINGS()
#endif
// Suppress the following MSVC GSL warnings:
// - C26432: gsl::c.21 : if you define or delete any default operation in the type '...', define or delete them all
// - C26410: gsl::r.32 : the parameter 'ptr' is a reference to const unique pointer, use const T* or const T& instead
// - C26415: gsl::r.30 : smart pointer parameter 'ptr' is used only to access contained pointer. Use T* or T& instead
// - C26418: gsl::r.36 : shared pointer parameter 'ptr' is not copied or moved. Use T* or T& instead
// - C26472: gsl::t.1 : don't use a static_cast for arithmetic conversions;
// use brace initialization, gsl::narrow_cast or gsl::narrow
// - C26439: gsl::f.6 : special function 'function' can be declared 'noexcept'
// - C26440: gsl::f.6 : function 'function' can be declared 'noexcept'
// - C26455: gsl::f.6 : default constructor may not throw. Declare it 'noexcept'
// - C26473: gsl::t.1 : don't cast between pointer types where the source type and the target type are the same
// - C26481: gsl::b.1 : don't use pointer arithmetic. Use span instead
// - C26482: gsl::b.2 : only index into arrays using constant expressions
// - C26446: gdl::b.4 : prefer to use gsl::at() instead of unchecked subscript operator
// - C26490: gsl::t.1 : don't use reinterpret_cast
// - C26487: gsl::l.4 : don't return a pointer '(<some number>'s result)' that may be invalid
gsl_DISABLE_MSVC_WARNINGS( 26432 26410 26415 26418 26472 26439 26440 26455 26473 26481 26482 26446 26490 26487 )
namespace gsl {
// forward declare span<>:
template< class T >
class span;
// C++11 emulation:
namespace std11 {
#if gsl_HAVE( ADD_CONST )
using std::add_const;
#elif gsl_HAVE( TR1_ADD_CONST )
using std::tr1::add_const;
#else
template< class T > struct add_const { typedef const T type; };
#endif // gsl_HAVE( ADD_CONST )
#if gsl_HAVE( REMOVE_CONST )
using std::remove_cv;
using std::remove_const;
using std::remove_volatile;
#elif gsl_HAVE( TR1_REMOVE_CONST )
using std::tr1::remove_cv;
using std::tr1::remove_const;
using std::tr1::remove_volatile;
#else
template< class T > struct remove_const { typedef T type; };
template< class T > struct remove_const<T const> { typedef T type; };
template< class T > struct remove_volatile { typedef T type; };
template< class T > struct remove_volatile<T volatile> { typedef T type; };
template< class T >
struct remove_cv
{
typedef typename remove_volatile<typename remove_const<T>::type>::type type;
};
#endif // gsl_HAVE( REMOVE_CONST )
#if gsl_HAVE( REMOVE_REFERENCE )
using std::remove_reference;
#elif gsl_HAVE( TR1_REMOVE_REFERENCE )
using std::tr1::remove_reference;
#else
template< class T > struct remove_reference { typedef T type; };
template< class T > struct remove_reference<T&> { typedef T type; };
# if gsl_HAVE( RVALUE_REFERENCE )
template< class T > struct remove_reference<T&&> { typedef T type; };
# endif
#endif // gsl_HAVE( REMOVE_REFERENCE )
#if gsl_HAVE( INTEGRAL_CONSTANT )
using std::integral_constant;
using std::true_type;
using std::false_type;
#elif gsl_HAVE( TR1_INTEGRAL_CONSTANT )
using std::tr1::integral_constant;
using std::tr1::true_type;
using std::tr1::false_type;
#else
template< class T, T v > struct integral_constant { enum { value = v }; };
typedef integral_constant< bool, true > true_type;
typedef integral_constant< bool, false > false_type;
#endif
#if gsl_HAVE( TYPE_TRAITS )
using std::underlying_type;
#elif gsl_HAVE( TR1_TYPE_TRAITS )
using std::tr1::underlying_type;
#else
// We could try to define `underlying_type<>` for pre-C++11 here, but let's not until someone actually needs it.
#endif
} // namespace std11
// C++14 emulation:
namespace std14 {
#if gsl_HAVE( UNIQUE_PTR )
# if gsl_HAVE( MAKE_UNIQUE )
using std::make_unique;
# elif gsl_HAVE( VARIADIC_TEMPLATE )
template< class T, class... Args >
std::unique_ptr<T> make_unique( Args &&... args )
{
return std::unique_ptr<T>( new T( std::forward<Args>( args )... ) );
}
# endif // gsl_HAVE( MAKE_UNIQUE ), gsl_HAVE( VARIADIC_TEMPLATE )
#endif // gsl_HAVE( UNIQUE_PTR )
} // namespace std14
namespace detail {
#if gsl_HAVE( VARIADIC_TEMPLATE )
template < bool V0, class T0, class... Ts > struct conjunction_ { using type = T0; };
template < class T0, class T1, class... Ts > struct conjunction_<true, T0, T1, Ts...> : conjunction_<T1::value, T1, Ts...> { };
template < bool V0, class T0, class... Ts > struct disjunction_ { using type = T0; };
template < class T0, class T1, class... Ts > struct disjunction_<false, T0, T1, Ts...> : disjunction_<T1::value, T1, Ts...> { };
#endif
} // namespace detail
// C++17 emulation:
namespace std17 {
template< bool v > struct bool_constant : std11::integral_constant<bool, v>{};
#if gsl_CPP11_120
template < class... Ts > struct conjunction;
template < > struct conjunction< > : std11::true_type { };
template < class T0, class... Ts > struct conjunction<T0, Ts...> : detail::conjunction_<T0::value, T0, Ts...>::type { };
template < class... Ts > struct disjunction;
template < > struct disjunction< > : std11::false_type { };
template < class T0, class... Ts > struct disjunction<T0, Ts...> : detail::disjunction_<T0::value, T0, Ts...>::type { };
template < class T > struct negation : std11::integral_constant<bool, !T::value> { };
# if gsl_CPP14_OR_GREATER
template < class... Ts > constexpr bool conjunction_v = conjunction<Ts...>::value;
template < class... Ts > constexpr bool disjunction_v = disjunction<Ts...>::value;
template < class T > constexpr bool negation_v = negation<T>::value;
# endif // gsl_CPP14_OR_GREATER
template< class... Ts >
struct make_void { typedef void type; };
template< class... Ts >
using void_t = typename make_void< Ts... >::type;
#endif // gsl_CPP11_120
#if gsl_HAVE( STD_DATA )
using std::data;
using std::size;
#elif gsl_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR )
template< class T, size_t N >
gsl_api inline gsl_constexpr auto size( T const(&)[N] ) gsl_noexcept -> size_t
{
return N;
}
template< class C >
inline gsl_constexpr auto size( C const & cont ) -> decltype( cont.size() )
{
return cont.size();
}
template< class T, size_t N >
gsl_api inline gsl_constexpr auto data( T(&arr)[N] ) gsl_noexcept -> T*
{
return &arr[0];
}
template< class C >
inline gsl_constexpr auto data( C & cont ) -> decltype( cont.data() )
{
return cont.data();
}
template< class C >
inline gsl_constexpr auto data( C const & cont ) -> decltype( cont.data() )
{
return cont.data();
}
template< class E >
inline gsl_constexpr auto data( std::initializer_list<E> il ) gsl_noexcept -> E const *
{
return il.begin();
}
#endif // span_HAVE( DATA )
} // namespace std17
// C++20 emulation:
namespace std20 {
#if gsl_CPP11_100
struct identity
{
template < class T >
gsl_constexpr T && operator ()( T && arg ) const gsl_noexcept
{
return std::forward<T>( arg );
}
};
#endif // gsl_CPP11_100
template< class T >
struct type_identity
{
typedef T type;
};
#if gsl_HAVE( ALIAS_TEMPLATE )
template< class T >
using type_identity_t = typename type_identity<T>::type;
#endif // gsl_HAVE( ALIAS_TEMPLATE )
#if gsl_HAVE( STD_SSIZE )
using std::ssize;
#elif gsl_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR )
template < class C >
gsl_constexpr auto ssize( C const & c )
-> typename std::common_type<std::ptrdiff_t, typename std::make_signed<decltype(c.size())>::type>::type
{
using R = typename std::common_type<std::ptrdiff_t, typename std::make_signed<decltype(c.size())>::type>::type;
return static_cast<R>( c.size() );
}
template <class T, std::size_t N>
gsl_constexpr auto ssize( T const(&)[N] ) gsl_noexcept -> std::ptrdiff_t
{
return std::ptrdiff_t( N );
}
#endif // gsl_HAVE( STD_SSIZE )
#if gsl_HAVE( REMOVE_CVREF )
using std::remove_cvref;
#else
template< class T > struct remove_cvref { typedef typename std11::remove_cv< typename std11::remove_reference< T >::type >::type type; };
#endif // gsl_HAVE( REMOVE_CVREF )