11 #ifndef NONSTD_SPAN_HPP_INCLUDED
12 #define NONSTD_SPAN_HPP_INCLUDED
14 #define span_lite_MAJOR 0
15 #define span_lite_MINOR 10
16 #define span_lite_PATCH 3
18 #define span_lite_VERSION \
19 span_STRINGIFY(span_lite_MAJOR) "." span_STRINGIFY( \
20 span_lite_MINOR) "." span_STRINGIFY(span_lite_PATCH)
22 #define span_STRINGIFY(x) span_STRINGIFY_(x)
23 #define span_STRINGIFY_(x) #x
27 #define span_SPAN_DEFAULT 0
28 #define span_SPAN_NONSTD 1
29 #define span_SPAN_STD 2
34 #if __has_include(<nonstd/span.tweak.hpp>)
35 #include <nonstd/span.tweak.hpp>
37 #define span_HAVE_TWEAK_HEADER 1
39 #define span_HAVE_TWEAK_HEADER 0
45 #define span_HAVE(feature) (span_HAVE_##feature)
47 #ifndef span_CONFIG_SELECT_SPAN
48 #define span_CONFIG_SELECT_SPAN (span_HAVE_STD_SPAN ? span_SPAN_STD : span_SPAN_NONSTD)
51 #ifndef span_CONFIG_EXTENT_TYPE
52 #define span_CONFIG_EXTENT_TYPE std::size_t
55 #ifndef span_CONFIG_SIZE_TYPE
56 #define span_CONFIG_SIZE_TYPE std::size_t
59 #ifdef span_CONFIG_INDEX_TYPE
60 # error `span_CONFIG_INDEX_TYPE` is deprecated since v0.7.0; it is replaced by `span_CONFIG_SIZE_TYPE`.
65 #ifndef span_FEATURE_WITH_CONTAINER
66 #ifdef span_FEATURE_WITH_CONTAINER_TO_STD
67 #define span_FEATURE_WITH_CONTAINER span_IN_STD(span_FEATURE_WITH_CONTAINER_TO_STD)
69 #define span_FEATURE_WITH_CONTAINER 0
70 #define span_FEATURE_WITH_CONTAINER_TO_STD 0
74 #ifndef span_FEATURE_CONSTRUCTION_FROM_STDARRAY_ELEMENT_TYPE
75 #define span_FEATURE_CONSTRUCTION_FROM_STDARRAY_ELEMENT_TYPE 0
78 #ifndef span_FEATURE_MEMBER_AT
79 #define span_FEATURE_MEMBER_AT 0
82 #ifndef span_FEATURE_MEMBER_BACK_FRONT
83 #define span_FEATURE_MEMBER_BACK_FRONT 1
86 #ifndef span_FEATURE_MEMBER_CALL_OPERATOR
87 #define span_FEATURE_MEMBER_CALL_OPERATOR 0
90 #ifndef span_FEATURE_MEMBER_SWAP
91 #define span_FEATURE_MEMBER_SWAP 0
94 #ifndef span_FEATURE_NON_MEMBER_FIRST_LAST_SUB
95 #define span_FEATURE_NON_MEMBER_FIRST_LAST_SUB 0
96 #elif span_FEATURE_NON_MEMBER_FIRST_LAST_SUB
97 #define span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_SPAN 1
98 #define span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_CONTAINER 1
101 #ifndef span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_SPAN
102 #define span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_SPAN 0
105 #ifndef span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_CONTAINER
106 #define span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_CONTAINER 0
109 #ifndef span_FEATURE_COMPARISON
110 #define span_FEATURE_COMPARISON 0 // Note: C++20 does not provide comparison
113 #ifndef span_FEATURE_SAME
114 #define span_FEATURE_SAME 0
117 #if span_FEATURE_SAME && !span_FEATURE_COMPARISON
118 #error `span_FEATURE_SAME` requires `span_FEATURE_COMPARISON`
121 #ifndef span_FEATURE_MAKE_SPAN
122 #ifdef span_FEATURE_MAKE_SPAN_TO_STD
123 #define span_FEATURE_MAKE_SPAN span_IN_STD(span_FEATURE_MAKE_SPAN_TO_STD)
125 #define span_FEATURE_MAKE_SPAN 0
126 #define span_FEATURE_MAKE_SPAN_TO_STD 0
130 #ifndef span_FEATURE_BYTE_SPAN
131 #define span_FEATURE_BYTE_SPAN 0
136 #ifndef span_CONFIG_NO_EXCEPTIONS
137 #if defined(_MSC_VER)
140 #if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || (_HAS_EXCEPTIONS)
141 #define span_CONFIG_NO_EXCEPTIONS 0
143 #define span_CONFIG_NO_EXCEPTIONS 1
144 #undef span_CONFIG_CONTRACT_VIOLATION_THROWS
145 #undef span_CONFIG_CONTRACT_VIOLATION_TERMINATES
146 #define span_CONFIG_CONTRACT_VIOLATION_THROWS 0
147 #define span_CONFIG_CONTRACT_VIOLATION_TERMINATES 1
153 #if defined(span_CONFIG_CONTRACT_LEVEL_ON)
154 #define span_CONFIG_CONTRACT_LEVEL_MASK 0x11
155 #elif defined(span_CONFIG_CONTRACT_LEVEL_OFF)
156 #define span_CONFIG_CONTRACT_LEVEL_MASK 0x00
157 #elif defined(span_CONFIG_CONTRACT_LEVEL_EXPECTS_ONLY)
158 #define span_CONFIG_CONTRACT_LEVEL_MASK 0x01
159 #elif defined(span_CONFIG_CONTRACT_LEVEL_ENSURES_ONLY)
160 #define span_CONFIG_CONTRACT_LEVEL_MASK 0x10
162 #define span_CONFIG_CONTRACT_LEVEL_MASK 0x11
165 #if defined(span_CONFIG_CONTRACT_VIOLATION_THROWS)
166 #define span_CONFIG_CONTRACT_VIOLATION_THROWS_V span_CONFIG_CONTRACT_VIOLATION_THROWS
168 #define span_CONFIG_CONTRACT_VIOLATION_THROWS_V 0
171 #if defined(span_CONFIG_CONTRACT_VIOLATION_THROWS) && \
172 span_CONFIG_CONTRACT_VIOLATION_THROWS && \
173 defined(span_CONFIG_CONTRACT_VIOLATION_TERMINATES) && \
174 span_CONFIG_CONTRACT_VIOLATION_TERMINATES
175 # error Please define none or one of span_CONFIG_CONTRACT_VIOLATION_THROWS and span_CONFIG_CONTRACT_VIOLATION_TERMINATES to 1, but not both.
181 #ifndef span_CPLUSPLUS
182 #if defined(_MSVC_LANG) && !defined(__clang__)
183 #define span_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG)
185 #define span_CPLUSPLUS __cplusplus
189 #define span_CPP98_OR_GREATER (span_CPLUSPLUS >= 199711L)
190 #define span_CPP11_OR_GREATER (span_CPLUSPLUS >= 201103L)
191 #define span_CPP14_OR_GREATER (span_CPLUSPLUS >= 201402L)
192 #define span_CPP17_OR_GREATER (span_CPLUSPLUS >= 201703L)
193 #define span_CPP20_OR_GREATER (span_CPLUSPLUS >= 202000L)
197 #define span_CPLUSPLUS_V (span_CPLUSPLUS / 100 - (span_CPLUSPLUS > 200000 ? 2000 : 1994))
199 #define span_IN_STD(v) (((v) == 98 ? 3 : (v)) >= span_CPLUSPLUS_V)
201 #define span_CONFIG(feature) (span_CONFIG_##feature)
202 #define span_FEATURE(feature) (span_FEATURE_##feature)
203 #define span_FEATURE_TO_STD(feature) (span_IN_STD(span_FEATURE(feature##_TO_STD)))
207 #if span_CPP20_OR_GREATER && defined(__has_include)
208 #if __has_include(<span> )
209 #define span_HAVE_STD_SPAN 1
211 #define span_HAVE_STD_SPAN 0
214 #define span_HAVE_STD_SPAN 0
217 #define span_USES_STD_SPAN \
218 ((span_CONFIG_SELECT_SPAN == span_SPAN_STD) || \
219 ((span_CONFIG_SELECT_SPAN == span_SPAN_DEFAULT) && span_HAVE_STD_SPAN))
225 #if span_USES_STD_SPAN
243 #else // span_USES_STD_SPAN
262 #if defined(_MSC_VER) && !defined(__clang__)
263 #define span_COMPILER_MSVC_VER (_MSC_VER)
264 #define span_COMPILER_MSVC_VERSION (_MSC_VER / 10 - 10 * (5 + (_MSC_VER < 1900)))
266 #define span_COMPILER_MSVC_VER 0
267 #define span_COMPILER_MSVC_VERSION 0
270 #define span_COMPILER_VERSION(major, minor, patch) \
271 (10 * (10 * (major) + (minor)) + (patch))
273 #if defined(__clang__)
274 #define span_COMPILER_CLANG_VERSION \
275 span_COMPILER_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__)
277 #define span_COMPILER_CLANG_VERSION 0
280 #if defined(__GNUC__) && !defined(__clang__)
281 #define span_COMPILER_GNUC_VERSION \
282 span_COMPILER_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
284 #define span_COMPILER_GNUC_VERSION 0
288 #define span_BETWEEN(v, lo, hi) ((lo) <= (v) && (v) < (hi))
292 #if defined(__clang__)
293 #pragma clang diagnostic push
294 #pragma clang diagnostic ignored "-Wundef"
295 #pragma clang diagnostic ignored "-Wmismatched-tags"
296 #define span_RESTORE_WARNINGS() _Pragma("clang diagnostic pop")
298 #elif defined __GNUC__
299 #pragma GCC diagnostic push
300 #pragma GCC diagnostic ignored "-Wundef"
301 #define span_RESTORE_WARNINGS() _Pragma("GCC diagnostic pop")
303 #elif span_COMPILER_MSVC_VER >= 1900
304 #define span_DISABLE_MSVC_WARNINGS(codes) \
305 __pragma(warning(push)) __pragma(warning(disable : codes))
306 #define span_RESTORE_WARNINGS() __pragma(warning(pop))
318 span_DISABLE_MSVC_WARNINGS(26439 26440 26472 26473 26481 26490)
321 #define span_RESTORE_WARNINGS()
327 #define span_HAS_CPP0X _HAS_CPP0X
329 #define span_HAS_CPP0X 0
332 #define span_CPP11_80 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1400)
333 #define span_CPP11_90 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1500)
334 #define span_CPP11_100 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1600)
335 #define span_CPP11_110 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1700)
336 #define span_CPP11_120 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1800)
337 #define span_CPP11_140 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1900)
339 #define span_CPP14_000 (span_CPP14_OR_GREATER)
340 #define span_CPP14_120 (span_CPP14_OR_GREATER || span_COMPILER_MSVC_VER >= 1800)
341 #define span_CPP14_140 (span_CPP14_OR_GREATER || span_COMPILER_MSVC_VER >= 1900)
343 #define span_CPP17_000 (span_CPP17_OR_GREATER)
347 #define span_HAVE_ALIAS_TEMPLATE span_CPP11_140
348 #define span_HAVE_AUTO span_CPP11_100
349 #define span_HAVE_CONSTEXPR_11 span_CPP11_140
350 #define span_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG span_CPP11_120
351 #define span_HAVE_EXPLICIT_CONVERSION span_CPP11_140
352 #define span_HAVE_INITIALIZER_LIST span_CPP11_120
353 #define span_HAVE_IS_DEFAULT span_CPP11_140
354 #define span_HAVE_IS_DELETE span_CPP11_140
355 #define span_HAVE_NOEXCEPT span_CPP11_140
356 #define span_HAVE_NULLPTR span_CPP11_100
357 #define span_HAVE_STATIC_ASSERT span_CPP11_100
361 #define span_HAVE_CONSTEXPR_14 span_CPP14_000
365 #define span_HAVE_DEPRECATED span_CPP17_000
366 #define span_HAVE_NODISCARD span_CPP17_000
367 #define span_HAVE_NORETURN span_CPP17_000
371 #if defined(__cpp_deduction_guides)
372 #define span_HAVE_DEDUCTION_GUIDES 1
374 #define span_HAVE_DEDUCTION_GUIDES \
375 (span_CPP17_OR_GREATER && !span_BETWEEN(span_COMPILER_MSVC_VER, 1, 1913))
380 #define span_HAVE_ADDRESSOF span_CPP17_000
381 #define span_HAVE_ARRAY span_CPP11_110
382 #define span_HAVE_BYTE span_CPP17_000
383 #define span_HAVE_CONDITIONAL span_CPP11_120
384 #define span_HAVE_CONTAINER_DATA_METHOD \
385 (span_CPP11_140 || (span_COMPILER_MSVC_VER >= 1500 && span_HAS_CPP0X))
386 #define span_HAVE_DATA span_CPP17_000
387 #define span_HAVE_LONGLONG span_CPP11_80
388 #define span_HAVE_REMOVE_CONST span_CPP11_110
389 #define span_HAVE_SNPRINTF span_CPP11_140
390 #define span_HAVE_STRUCT_BINDING span_CPP11_120
391 #define span_HAVE_TYPE_TRAITS span_CPP11_90
395 #ifdef NONSTD_BYTE_LITE_HPP
396 #define span_HAVE_NONSTD_BYTE 1
398 #define span_HAVE_NONSTD_BYTE 0
403 #if span_HAVE_ADDRESSOF
404 #define span_ADDRESSOF(x) std::addressof(x)
406 #define span_ADDRESSOF(x) (&x)
409 #if span_HAVE_CONSTEXPR_11
410 #define span_constexpr constexpr
412 #define span_constexpr
415 #if span_HAVE_CONSTEXPR_14
416 #define span_constexpr14 constexpr
418 #define span_constexpr14
421 #if span_HAVE_EXPLICIT_CONVERSION
422 #define span_explicit explicit
424 #define span_explicit
427 #if span_HAVE_IS_DELETE
428 #define span_is_delete = delete
430 #define span_is_delete
433 #if span_HAVE_IS_DELETE
434 #define span_is_delete_access public
436 #define span_is_delete_access private
439 #if span_HAVE_NOEXCEPT && !span_CONFIG_CONTRACT_VIOLATION_THROWS_V
440 #define span_noexcept noexcept
442 #define span_noexcept
445 #if span_HAVE_NULLPTR
446 #define span_nullptr nullptr
448 #define span_nullptr NULL
451 #if span_HAVE_DEPRECATED
452 #define span_deprecated(msg) [[deprecated(msg)]]
454 #define span_deprecated(msg)
457 #if span_HAVE_NODISCARD
458 #define span_nodiscard [[nodiscard]]
460 #define span_nodiscard
463 #if span_HAVE_NORETURN
464 #define span_noreturn [[noreturn]]
466 #define span_noreturn
471 #define span_HAVE_CONSTRAINED_SPAN_CONTAINER_CTOR span_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG
472 #define span_HAVE_ITERATOR_CTOR span_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG
476 #if span_HAVE(ADDRESSOF)
492 #if span_HAVE(TYPE_TRAITS)
493 #include <type_traits>
496 #if !span_HAVE(CONSTRAINED_SPAN_CONTAINER_CTOR)
500 #if span_FEATURE(MEMBER_AT) > 1
504 #if !span_CONFIG(NO_EXCEPTIONS)
510 #define span_ELIDE_CONTRACT_EXPECTS (0 == (span_CONFIG_CONTRACT_LEVEL_MASK & 0x01))
511 #define span_ELIDE_CONTRACT_ENSURES (0 == (span_CONFIG_CONTRACT_LEVEL_MASK & 0x10))
513 #if span_ELIDE_CONTRACT_EXPECTS
514 #define span_constexpr_exp span_constexpr
515 #define span_EXPECTS(cond)
517 #define span_constexpr_exp span_constexpr14
518 #define span_EXPECTS(cond) span_CONTRACT_CHECK("Precondition", cond)
521 #if span_ELIDE_CONTRACT_ENSURES
522 #define span_constexpr_ens span_constexpr
523 #define span_ENSURES(cond)
525 #define span_constexpr_ens span_constexpr14
526 #define span_ENSURES(cond) span_CONTRACT_CHECK("Postcondition", cond)
529 #define span_CONTRACT_CHECK(type, cond) \
530 cond ? static_cast<void>(0) : \
531 nonstd::span_lite::detail::report_contract_violation( \
532 span_LOCATION(__FILE__, __LINE__) ": " type " violation.")
535 #define span_LOCATION(file, line) file ":" span_STRINGIFY(line)
537 #define span_LOCATION(file, line) file "(" span_STRINGIFY(line) ")"
542 #if span_HAVE(DEFAULT_FUNCTION_TEMPLATE_ARG)
544 #define span_REQUIRES_0(VA) \
545 template <bool B = (VA), typename std::enable_if<B, int>::type = 0>
547 #if span_BETWEEN(span_COMPILER_MSVC_VERSION, 1, 140)
549 #define span_REQUIRES_T(VA) \
550 , typename = typename std::enable_if<(VA), nonstd::span_lite::detail::enabler>::type
552 #define span_REQUIRES_T(VA) , typename std::enable_if<(VA), int>::type = 0
555 #define span_REQUIRES_R(R, VA) typename std::enable_if<(VA), R>::type
557 #define span_REQUIRES_A(VA) , typename std::enable_if<(VA), void*>::type = nullptr
561 #define span_REQUIRES_0(VA)
562 #define span_REQUIRES_T(VA)
563 #define span_REQUIRES_R(R, VA) R
564 #define span_REQUIRES_A(VA)
580 template <
class T, extent_t Extent = dynamic_extent>
598 #if span_HAVE(REMOVE_CONST)
600 using std::remove_const;
601 using std::remove_cv;
602 using std::remove_volatile;
635 #endif // span_HAVE( REMOVE_CONST )
637 #if span_HAVE(TYPE_TRAITS)
640 using std::integral_constant;
643 using std::remove_reference;
648 template <
class T, T v>
659 template <
class T,
class U>
668 template <
typename T>
711 #elif span_HAVE(CONSTRAINED_SPAN_CONTAINER_CTOR)
713 template <
typename T, std::
size_t N>
719 template <
typename C>
725 template <
typename T, std::
size_t N>
731 template <
typename C>
737 template <
typename C>
743 template <
typename E>
749 #endif // span_HAVE( DATA )
753 #elif span_HAVE(NONSTD_BYTE)
764 #if span_HAVE(DEDUCTION_GUIDES)
766 using iter_reference_t = decltype(*std::declval<T&>());
780 template <
typename T>
786 #if span_HAVE(TYPE_TRAITS)
793 template <
class T, span_CONFIG_EXTENT_TYPE Extent>
799 struct is_span : is_span_oracle<typename std::remove_cv<Q>::type>
810 template <
class T, std::
size_t Extent>
818 struct is_std_array : is_std_array_oracle<typename std::remove_cv<Q>::type>
832 template <
class T, std::
size_t N>
837 #if span_CPP11_140 && !span_BETWEEN(span_COMPILER_GNUC_VERSION, 1, 500)
839 template <
class,
class =
void>
845 struct has_size_and_data<
C, std17::
void_t<decltype(std17::size(std::declval<C>())),
846 decltype(std17::data(std::declval<C>()))> >
851 template <
class,
class,
class =
void>
856 template <
class C,
class E>
857 struct is_compatible_element<
C, E,
858 std17::
void_t<decltype(std17::data(std::declval<C>()))> >
859 : std::is_convertible<typename std::remove_pointer<decltype(std17::data(
860 std::declval<C&>()))>::type (*)[],
868 !is_std_array<C>::value && has_size_and_data<C>::value>
872 template <
class C,
class E>
873 struct is_compatible_container
878 #else // span_CPP11_140
882 (!is_span<C>::value && !is_array<C>::value && !is_std_array<C>::value &&
883 (std::is_convertible<
typename std::remove_pointer<decltype(
std17::data(
884 std::declval<C&>()))>::type (*)[],
894 #endif // span_CPP11_140
896 #endif // span_HAVE( TYPE_TRAITS )
898 #if !span_CONFIG(NO_EXCEPTIONS)
899 #if span_FEATURE(MEMBER_AT) > 1
903 #if defined(__clang__)
904 #pragma clang diagnostic ignored "-Wlong-long"
905 #elif defined __GNUC__
906 #pragma GCC diagnostic ignored "-Wformat=ll"
907 #pragma GCC diagnostic ignored "-Wlong-long"
912 const char fmt[] =
"span::at(): index '%lli' is out of range [0..%lli)";
913 char buffer[2 * 20 +
sizeof fmt];
914 sprintf(buffer, fmt,
static_cast<long long>(idx),
static_cast<long long>(
size));
916 throw std::out_of_range(buffer);
921 span_noreturn inline void throw_out_of_range(
size_t ,
size_t )
923 throw std::out_of_range(
"span::at(): index outside span");
926 #endif // NO_EXCEPTIONS
928 #if span_CONFIG(CONTRACT_VIOLATION_THROWS_V)
930 struct contract_violation : std::logic_error
932 explicit contract_violation(
char const*
const message) :
std::logic_error(message)
939 throw contract_violation(
msg);
942 #else // span_CONFIG( CONTRACT_VIOLATION_THROWS_V )
949 #endif // span_CONFIG( CONTRACT_VIOLATION_THROWS_V )
955 #define span_sizeof(T) static_cast<extent_t>(sizeof(T))
960 return static_cast<size_t>(
size);
966 template <
class T,
extent_t Extent >
1007 #if span_HAVE(ITERATOR_CTOR)
1017 (std::is_convertible<decltype(*std::declval<It&>()),
element_type&>::value))>
1032 #if span_HAVE(ITERATOR_CTOR)
1034 (std::is_convertible<decltype(&*std::declval<It&>()),
1036 !std::is_convertible<End, std::size_t>::value))>
1059 #if span_HAVE(ARRAY)
1064 #if span_FEATURE(CONSTRUCTION_FROM_STDARRAY_ELEMENT_TYPE)
1069 :
data_(arr.data()),
1075 #if span_HAVE(DEFAULT_FUNCTION_TEMPLATE_ARG)
1082 :
data_(arr.data()),
1087 #endif // span_HAVE( ARRAY )
1089 #if span_HAVE(CONSTRAINED_SPAN_CONTAINER_CTOR)
1091 (detail::is_compatible_container<Container, element_type>::value))>
1098 (std::is_const<element_type>::value &&
1099 detail::is_compatible_container<Container, element_type>::value))>
1105 #endif // span_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR )
1107 #if span_FEATURE(WITH_CONTAINER)
1109 template <
class Container>
1116 template <
class Container>
1125 #if span_HAVE(IS_DEFAULT)
1143 data_ = other.data_;
1144 size_ = other.size_;
1150 template <
class OtherElementType,
1153 Extent == OtherExtent) &&
1154 std::is_convertible<OtherElementType (*)[],
element_type (*)[]>::value))>
1156 :
data_(other.data()),
1164 template <extent_type Count>
1172 template <extent_type Count>
1180 #if span_HAVE(DEFAULT_FUNCTION_TEMPLATE_ARG)
1181 template <
size_type Offset, extent_type Count = dynamic_extent>
1233 return static_cast<std::ptrdiff_t
>(
size_);
1252 return *(
data() + idx);
1255 #if span_FEATURE(MEMBER_CALL_OPERATOR)
1263 return *(
data() + idx);
1267 #if span_FEATURE(MEMBER_AT)
1270 #if span_CONFIG(NO_EXCEPTIONS)
1275 detail::throw_out_of_range(idx,
size());
1277 return *(
data() + idx);
1287 #if span_FEATURE(MEMBER_BACK_FRONT)
1307 #if span_FEATURE(MEMBER_SWAP)
1321 #if span_CPP11_OR_GREATER
1330 #if span_CPP11_OR_GREATER
1339 #if span_CPP11_OR_GREATER
1348 #if span_CPP11_OR_GREATER
1378 #if span_HAVE(ITERATOR_CTOR)
1384 template <
typename U>
1390 template <
typename Ptr span_REQUIRES_T((!std::is_po
inter<Ptr>::value))>
1393 return to_address(it.operator->());
1395 #endif // span_HAVE( ITERATOR_CTOR )
1404 #if span_HAVE(DEDUCTION_GUIDES)
1406 template <
class T,
size_t N>
1409 template <
class T,
size_t N>
1412 template <
class T,
size_t N>
1415 #if span_HAVE(CONSTRAINED_SPAN_CONTAINER_CTOR)
1417 template <
class Container>
1420 template <
class Container>
1427 template <
class It,
class EndOrSize>
1429 typename std11::remove_reference<typename std20::iter_reference_t<It> >::type>;
1431 #endif // span_HAVE( DEDUCTION_GUIDES )
1435 #if span_FEATURE(COMPARISON)
1436 #if span_FEATURE(SAME)
1438 template <
class T1, extent_t E1,
class T2, extent_t E2>
1443 static_cast<void const*
>(l.data()) == r.data();
1448 template <
class T1, extent_t E1,
class T2, extent_t E2>
1452 #if span_FEATURE(SAME)
1458 template <
class T1, extent_t E1,
class T2, extent_t E2>
1461 return std::lexicographical_compare(l.begin(), l.end(), r.begin(), r.end());
1464 template <
class T1, extent_t E1,
class T2, extent_t E2>
1470 template <
class T1, extent_t E1,
class T2, extent_t E2>
1476 template <
class T1, extent_t E1,
class T2, extent_t E2>
1482 template <
class T1, extent_t E1,
class T2, extent_t E2>
1488 #endif // span_FEATURE( COMPARISON )
1492 #if span_HAVE(BYTE) || span_HAVE(NONSTD_BYTE)
1496 template <
typename T, extent_t Extent>
1499 #if span_CPP11_OR_GREATER
1512 template <
typename T>
1515 #if span_CPP11_OR_GREATER
1525 template <
class T, extent_t Extent>
1526 inline span_constexpr span<const std17::byte, BytesExtent<T, Extent>::value>
1530 return {
reinterpret_cast< std17::byte
const *
>( spn.data() ), spn.size_bytes() };
1532 return span<const std17::byte, BytesExtent<T, Extent>::value>(
1533 reinterpret_cast<std17::byte const*
>(spn.data()), spn.size_bytes());
1537 template <
class T, extent_t Extent>
1538 inline span_constexpr span<std17::byte, BytesExtent<T, Extent>::value>
1542 return {
reinterpret_cast< std17::byte *
>( spn.data() ), spn.size_bytes() };
1544 return span<std17::byte, BytesExtent<T, Extent>::value>(
1545 reinterpret_cast<std17::byte*
>(spn.data()), spn.size_bytes());
1549 #endif // span_HAVE( BYTE ) || span_HAVE( NONSTD_BYTE )
1553 template <
class T,
extent_t Extent >
1559 template <
class T,
extent_t Extent >
1562 return static_cast<std::ptrdiff_t
>(spn.
size());
1575 using span_lite::span;
1579 #if span_FEATURE(COMPARISON)
1580 #if span_FEATURE(SAME)
1581 using span_lite::same;
1584 using span_lite::operator==;
1585 using span_lite::operator!=;
1586 using span_lite::operator<;
1587 using span_lite::operator<=;
1588 using span_lite::operator>;
1589 using span_lite::operator>=;
1593 using span_lite::as_bytes;
1594 using span_lite::as_writable_bytes;
1602 #endif // span_USES_STD_SPAN
1606 #if span_FEATURE(MAKE_SPAN) || span_FEATURE(NON_MEMBER_FIRST_LAST_SUB_SPAN) || \
1607 span_FEATURE(NON_MEMBER_FIRST_LAST_SUB_CONTAINER)
1609 #if span_USES_STD_SPAN
1610 #define span_constexpr constexpr
1611 #define span_noexcept noexcept
1612 #define span_nullptr nullptr
1613 #ifndef span_CONFIG_EXTENT_TYPE
1614 #define span_CONFIG_EXTENT_TYPE std::size_t
1617 #endif // span_USES_STD_SPAN
1627 return span<T>(
ptr, count);
1633 return span<T>(
first, last);
1636 template <
class T, std::
size_t N>
1640 return span<T, static_cast<extent_t>(N)>(&arr[0], N);
1643 #if span_USES_STD_SPAN || span_HAVE(ARRAY)
1645 template <
class T, std::
size_t N>
1649 return span<T, static_cast<extent_t>(N)>(arr);
1652 template <
class T, std::
size_t N>
1656 return span<const T, static_cast<extent_t>(N)>(arr);
1659 #endif // span_HAVE( ARRAY )
1661 #if span_USES_STD_SPAN
1663 template <class Container, class EP = decltype(std::data(std::declval<Container&>()))>
1670 template <class Container, class EP = decltype(std::data(std::declval<Container&>()))>
1677 #elif span_HAVE(CONSTRAINED_SPAN_CONTAINER_CTOR) && span_HAVE(AUTO)
1679 template <class Container, class EP = decltype(std17::data(std::declval<Container&>()))>
1686 template <class Container, class EP = decltype(std17::data(std::declval<Container&>()))>
1701 template <
class T,
class Allocator>
1707 template <
class T,
class Allocator>
1709 make_span(std::vector<T, Allocator>
const& cont)
span_noexcept
1714 #endif // span_USES_STD_SPAN || ( ... )
1716 #if !span_USES_STD_SPAN && span_FEATURE(WITH_CONTAINER)
1718 template <
class Container>
1722 return span<typename Container::value_type>(
with_container, cont);
1725 template <
class Container>
1727 make_span(with_container_t, Container
const& cont)
span_noexcept
1729 return span<const typename Container::value_type>(
with_container, cont);
1732 #endif // ! span_USES_STD_SPAN && span_FEATURE( WITH_CONTAINER )
1737 #if span_FEATURE(NON_MEMBER_FIRST_LAST_SUB_SPAN)
1739 template <extent_t Count,
class T, extent_t Extent>
1742 return spn.template first<Count>();
1745 template <
class T, extent_t Extent>
1748 return spn.first(count);
1751 template <extent_t Count,
class T, extent_t Extent>
1754 return spn.template last<Count>();
1757 template <
class T, extent_t Extent>
1760 return spn.last(count);
1763 template <
size_t Offset, extent_t Count,
class T, extent_t Extent>
1766 return spn.template subspan<Offset, Count>();
1769 template <
class T, extent_t Extent>
1770 span_constexpr span<T> subspan(span<T, Extent> spn,
size_t offset,
1773 return spn.subspan(offset, count);
1776 #endif // span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_SPAN )
1778 #if span_FEATURE(NON_MEMBER_FIRST_LAST_SUB_CONTAINER) && span_CPP11_120
1780 template <extent_t Count,
class T>
1783 return make_span(t).template first<Count>();
1789 return make_span(t).first(count);
1792 template <extent_t Count,
class T>
1793 span_constexpr auto last(T& t) -> decltype(make_span(t).
template last<Count>())
1795 return make_span(t).template last<Count>();
1801 return make_span(t).last(count);
1804 template <
size_t Offset, extent_t Count = dynamic_extent,
class T>
1806 -> decltype(make_span(t).
template subspan<Offset, Count>())
1808 return make_span(t).template subspan<Offset, Count>();
1813 -> decltype(make_span(t).subspan(offset, count))
1815 return make_span(t).subspan(offset, count);
1818 #endif // span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_CONTAINER )
1827 using span_lite::make_span;
1829 #if span_FEATURE(NON_MEMBER_FIRST_LAST_SUB_SPAN) || \
1830 (span_FEATURE(NON_MEMBER_FIRST_LAST_SUB_CONTAINER) && span_CPP11_120)
1833 using span_lite::last;
1834 using span_lite::subspan;
1836 #endif // span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_[SPAN|CONTAINER] )
1840 #endif // #if span_FEATURE_TO_STD( MAKE_SPAN )
1842 #if span_CPP11_OR_GREATER && span_FEATURE(BYTE_SPAN) && \
1843 (span_HAVE(BYTE) || span_HAVE(NONSTD_BYTE))
1854 return span<std17::byte, span_sizeof(t)>(
reinterpret_cast<std17::byte*
>(&t),
1862 return span<const std17::byte, span_sizeof(t)>(
reinterpret_cast<std17::byte const*
>(&t),
1873 using span_lite::byte_span;
1876 #endif // span_FEATURE( BYTE_SPAN )
1878 #if span_HAVE(STRUCT_BINDING)
1880 #if span_CPP14_OR_GREATER
1882 #elif span_CPP11_OR_GREATER
1886 template <std::
size_t I,
typename T>
1892 template <
typename T>
1895 template <std::
size_t I,
typename T>
1898 #endif // span_CPP14_OR_GREATER
1907 template <
typename ElementType, nonstd::span_lite::extent_t Extent>
1908 class tuple_size<
nonstd::span<ElementType, Extent> >
1909 :
public integral_constant<size_t, static_cast<size_t>(Extent)>
1915 template <
typename ElementType>
1916 class tuple_size<
nonstd::span<ElementType, nonstd::dynamic_extent> >;
1920 template <size_t I, typename ElementType, nonstd::span_lite::extent_t Extent>
1924 #if span_HAVE(STATIC_ASSERT)
1926 "dynamic extent or index "
1929 using type = ElementType;
1934 template <
size_t I,
typename ElementType, nonstd::span_lite::extent_t Extent>
1937 #if span_HAVE(STATIC_ASSERT)
1939 "extent or index out of "
1945 template <
size_t I,
typename ElementType, nonstd::span_lite::extent_t Extent>
1949 #if span_HAVE(STATIC_ASSERT)
1951 "extent or index out of "
1959 #endif // span_HAVE( STRUCT_BINDING )
1961 #if !span_USES_STD_SPAN
1963 #endif // span_USES_STD_SPAN
1965 #endif // NONSTD_SPAN_HPP_INCLUDED