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 span_STRINGIFY(span_lite_MAJOR) "." span_STRINGIFY(span_lite_MINOR) "." span_STRINGIFY(span_lite_PATCH) 20 #define span_STRINGIFY( x ) span_STRINGIFY_( x ) 21 #define span_STRINGIFY_( x ) #x 25 #define span_SPAN_DEFAULT 0 26 #define span_SPAN_NONSTD 1 27 #define span_SPAN_STD 2 32 # if __has_include(<nonstd/span.tweak.hpp>) 33 # include <nonstd/span.tweak.hpp> 35 #define span_HAVE_TWEAK_HEADER 1 37 #define span_HAVE_TWEAK_HEADER 0 43 #define span_HAVE( feature ) ( span_HAVE_##feature ) 45 #ifndef span_CONFIG_SELECT_SPAN 46 # define span_CONFIG_SELECT_SPAN ( span_HAVE_STD_SPAN ? span_SPAN_STD : span_SPAN_NONSTD ) 49 #ifndef span_CONFIG_EXTENT_TYPE 50 # define span_CONFIG_EXTENT_TYPE std::size_t 53 #ifndef span_CONFIG_SIZE_TYPE 54 # define span_CONFIG_SIZE_TYPE std::size_t 57 #ifdef span_CONFIG_INDEX_TYPE 58 # error `span_CONFIG_INDEX_TYPE` is deprecated since v0.7.0; it is replaced by `span_CONFIG_SIZE_TYPE`. 63 #ifndef span_FEATURE_WITH_INITIALIZER_LIST_P2447 64 # define span_FEATURE_WITH_INITIALIZER_LIST_P2447 0 67 #ifndef span_FEATURE_WITH_CONTAINER 68 #ifdef span_FEATURE_WITH_CONTAINER_TO_STD 69 # define span_FEATURE_WITH_CONTAINER span_IN_STD( span_FEATURE_WITH_CONTAINER_TO_STD ) 71 # define span_FEATURE_WITH_CONTAINER 0 72 # define span_FEATURE_WITH_CONTAINER_TO_STD 0 76 #ifndef span_FEATURE_CONSTRUCTION_FROM_STDARRAY_ELEMENT_TYPE 77 # define span_FEATURE_CONSTRUCTION_FROM_STDARRAY_ELEMENT_TYPE 0 80 #ifndef span_FEATURE_MEMBER_AT 81 # define span_FEATURE_MEMBER_AT 0 84 #ifndef span_FEATURE_MEMBER_BACK_FRONT 85 # define span_FEATURE_MEMBER_BACK_FRONT 1 88 #ifndef span_FEATURE_MEMBER_CALL_OPERATOR 89 # define span_FEATURE_MEMBER_CALL_OPERATOR 0 92 #ifndef span_FEATURE_MEMBER_SWAP 93 # define span_FEATURE_MEMBER_SWAP 0 96 #ifndef span_FEATURE_NON_MEMBER_FIRST_LAST_SUB 97 # define span_FEATURE_NON_MEMBER_FIRST_LAST_SUB 0 98 #elif span_FEATURE_NON_MEMBER_FIRST_LAST_SUB 99 # define span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_SPAN 1 100 # define span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_CONTAINER 1 103 #ifndef span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_SPAN 104 # define span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_SPAN 0 107 #ifndef span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_CONTAINER 108 # define span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_CONTAINER 0 111 #ifndef span_FEATURE_COMPARISON 112 # define span_FEATURE_COMPARISON 0 // Note: C++20 does not provide comparison 115 #ifndef span_FEATURE_SAME 116 # define span_FEATURE_SAME 0 119 #if span_FEATURE_SAME && !span_FEATURE_COMPARISON 120 # error `span_FEATURE_SAME` requires `span_FEATURE_COMPARISON` 123 #ifndef span_FEATURE_MAKE_SPAN 124 #ifdef span_FEATURE_MAKE_SPAN_TO_STD 125 # define span_FEATURE_MAKE_SPAN span_IN_STD( span_FEATURE_MAKE_SPAN_TO_STD ) 127 # define span_FEATURE_MAKE_SPAN 0 128 # define span_FEATURE_MAKE_SPAN_TO_STD 0 132 #ifndef span_FEATURE_BYTE_SPAN 133 # define span_FEATURE_BYTE_SPAN 0 138 #ifndef span_CONFIG_NO_EXCEPTIONS 139 # if defined(_MSC_VER) 142 # if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || (_HAS_EXCEPTIONS) 143 # define span_CONFIG_NO_EXCEPTIONS 0 145 # define span_CONFIG_NO_EXCEPTIONS 1 146 # undef span_CONFIG_CONTRACT_VIOLATION_THROWS 147 # undef span_CONFIG_CONTRACT_VIOLATION_TERMINATES 148 # define span_CONFIG_CONTRACT_VIOLATION_THROWS 0 149 # define span_CONFIG_CONTRACT_VIOLATION_TERMINATES 1 155 #if defined( span_CONFIG_CONTRACT_LEVEL_ON ) 156 # define span_CONFIG_CONTRACT_LEVEL_MASK 0x11 157 #elif defined( span_CONFIG_CONTRACT_LEVEL_OFF ) 158 # define span_CONFIG_CONTRACT_LEVEL_MASK 0x00 159 #elif defined( span_CONFIG_CONTRACT_LEVEL_EXPECTS_ONLY ) 160 # define span_CONFIG_CONTRACT_LEVEL_MASK 0x01 161 #elif defined( span_CONFIG_CONTRACT_LEVEL_ENSURES_ONLY ) 162 # define span_CONFIG_CONTRACT_LEVEL_MASK 0x10 164 # define span_CONFIG_CONTRACT_LEVEL_MASK 0x11 167 #if defined( span_CONFIG_CONTRACT_VIOLATION_THROWS ) 168 # define span_CONFIG_CONTRACT_VIOLATION_THROWS_V span_CONFIG_CONTRACT_VIOLATION_THROWS 170 # define span_CONFIG_CONTRACT_VIOLATION_THROWS_V 0 173 #if defined( span_CONFIG_CONTRACT_VIOLATION_THROWS ) && span_CONFIG_CONTRACT_VIOLATION_THROWS && \ 174 defined( span_CONFIG_CONTRACT_VIOLATION_TERMINATES ) && 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 ( (span_CONFIG_SELECT_SPAN == span_SPAN_STD) || ((span_CONFIG_SELECT_SPAN == span_SPAN_DEFAULT) && span_HAVE_STD_SPAN) ) 223 #if span_USES_STD_SPAN 240 #else // span_USES_STD_SPAN 258 #if defined(_MSC_VER ) && !defined(__clang__) 259 # define span_COMPILER_MSVC_VER (_MSC_VER ) 260 # define span_COMPILER_MSVC_VERSION (_MSC_VER / 10 - 10 * ( 5 + (_MSC_VER < 1900 ) ) ) 262 # define span_COMPILER_MSVC_VER 0 263 # define span_COMPILER_MSVC_VERSION 0 266 #define span_COMPILER_VERSION( major, minor, patch ) ( 10 * ( 10 * (major) + (minor) ) + (patch) ) 268 #if defined(__clang__) 269 # define span_COMPILER_CLANG_VERSION span_COMPILER_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__) 271 # define span_COMPILER_CLANG_VERSION 0 274 #if defined(__GNUC__) && !defined(__clang__) 275 # define span_COMPILER_GNUC_VERSION span_COMPILER_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) 277 # define span_COMPILER_GNUC_VERSION 0 281 #define span_BETWEEN( v, lo, hi ) ( (lo) <= (v) && (v) < (hi) ) 285 #if defined(__clang__) 286 # pragma clang diagnostic push 287 # pragma clang diagnostic ignored "-Wundef" 288 # pragma clang diagnostic ignored "-Wmismatched-tags" 289 # define span_RESTORE_WARNINGS() _Pragma( "clang diagnostic pop" ) 291 #elif defined __GNUC__ 292 # pragma GCC diagnostic push 293 # pragma GCC diagnostic ignored "-Wundef" 294 # define span_RESTORE_WARNINGS() _Pragma( "GCC diagnostic pop" ) 296 #elif span_COMPILER_MSVC_VER >= 1900 297 # define span_DISABLE_MSVC_WARNINGS(codes) __pragma(warning(push)) __pragma(warning(disable: codes)) 298 # define span_RESTORE_WARNINGS() __pragma(warning(pop )) 309 span_DISABLE_MSVC_WARNINGS( 26439 26440 26472 26473 26481 26490 )
312 # define span_RESTORE_WARNINGS() 318 # define span_HAS_CPP0X _HAS_CPP0X 320 # define span_HAS_CPP0X 0 323 #define span_CPP11_80 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1400) 324 #define span_CPP11_90 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1500) 325 #define span_CPP11_100 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1600) 326 #define span_CPP11_110 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1700) 327 #define span_CPP11_120 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1800) 328 #define span_CPP11_140 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1900) 330 #define span_CPP14_000 (span_CPP14_OR_GREATER) 331 #define span_CPP14_120 (span_CPP14_OR_GREATER || span_COMPILER_MSVC_VER >= 1800) 332 #define span_CPP14_140 (span_CPP14_OR_GREATER || span_COMPILER_MSVC_VER >= 1900) 334 #define span_CPP17_000 (span_CPP17_OR_GREATER) 338 #define span_HAVE_ALIAS_TEMPLATE span_CPP11_140 339 #define span_HAVE_AUTO span_CPP11_100 340 #define span_HAVE_CONSTEXPR_11 span_CPP11_140 341 #define span_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG span_CPP11_120 342 #define span_HAVE_EXPLICIT_CONVERSION span_CPP11_140 343 #define span_HAVE_INITIALIZER_LIST span_CPP11_120 344 #define span_HAVE_IS_DEFAULT span_CPP11_140 345 #define span_HAVE_IS_DELETE span_CPP11_140 346 #define span_HAVE_NOEXCEPT span_CPP11_140 347 #define span_HAVE_NULLPTR span_CPP11_100 348 #define span_HAVE_STATIC_ASSERT span_CPP11_100 352 #define span_HAVE_CONSTEXPR_14 span_CPP14_000 356 #define span_HAVE_DEPRECATED span_CPP17_000 357 #define span_HAVE_NODISCARD span_CPP17_000 358 #define span_HAVE_NORETURN span_CPP17_000 362 #if defined(__cpp_deduction_guides) 363 # define span_HAVE_DEDUCTION_GUIDES 1 365 # define span_HAVE_DEDUCTION_GUIDES (span_CPP17_OR_GREATER && ! span_BETWEEN( span_COMPILER_MSVC_VER, 1, 1913 )) 370 #define span_HAVE_ADDRESSOF span_CPP17_000 371 #define span_HAVE_ARRAY span_CPP11_110 372 #define span_HAVE_BYTE span_CPP17_000 373 #define span_HAVE_CONDITIONAL span_CPP11_120 374 #define span_HAVE_CONTAINER_DATA_METHOD (span_CPP11_140 || ( span_COMPILER_MSVC_VER >= 1500 && span_HAS_CPP0X )) 375 #define span_HAVE_DATA span_CPP17_000 376 #define span_HAVE_LONGLONG span_CPP11_80 377 #define span_HAVE_REMOVE_CONST span_CPP11_110 378 #define span_HAVE_SNPRINTF span_CPP11_140 379 #define span_HAVE_STRUCT_BINDING span_CPP11_120 380 #define span_HAVE_TYPE_TRAITS span_CPP11_90 384 #ifdef NONSTD_BYTE_LITE_HPP 385 # define span_HAVE_NONSTD_BYTE 1 387 # define span_HAVE_NONSTD_BYTE 0 392 #if span_HAVE_ADDRESSOF 393 # define span_ADDRESSOF(x) std::addressof(x) 395 # define span_ADDRESSOF(x) (&x) 398 #if span_HAVE_CONSTEXPR_11 399 # define span_constexpr constexpr 401 # define span_constexpr 404 #if span_HAVE_CONSTEXPR_14 405 # define span_constexpr14 constexpr 407 # define span_constexpr14 410 #if span_HAVE_EXPLICIT_CONVERSION 411 # define span_explicit explicit 413 # define span_explicit 416 #if span_HAVE_IS_DELETE 417 # define span_is_delete = delete 419 # define span_is_delete 422 #if span_HAVE_IS_DELETE 423 # define span_is_delete_access public 425 # define span_is_delete_access private 428 #if span_HAVE_NOEXCEPT && ! span_CONFIG_CONTRACT_VIOLATION_THROWS_V 429 # define span_noexcept noexcept 431 # define span_noexcept 434 #if span_HAVE_NULLPTR 435 # define span_nullptr nullptr 437 # define span_nullptr NULL 440 #if span_HAVE_DEPRECATED 441 # define span_deprecated(msg) [[deprecated(msg)]] 443 # define span_deprecated(msg) 446 #if span_HAVE_NODISCARD 447 # define span_nodiscard [[nodiscard]] 449 # define span_nodiscard 452 #if span_HAVE_NORETURN 453 # define span_noreturn [[noreturn]] 455 # define span_noreturn 460 #define span_HAVE_CONSTRAINED_SPAN_CONTAINER_CTOR span_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG 461 #define span_HAVE_ITERATOR_CTOR span_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG 465 #if span_HAVE( ADDRESSOF ) 469 #if span_HAVE( ARRAY ) 473 #if span_HAVE( BYTE ) 477 #if span_HAVE( DATA ) 481 #if span_HAVE( TYPE_TRAITS ) 482 # include <type_traits> 485 #if ! span_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR ) 489 #if span_FEATURE( MEMBER_AT ) > 1 493 #if ! span_CONFIG( NO_EXCEPTIONS ) 494 # include <stdexcept> 499 #define span_ELIDE_CONTRACT_EXPECTS ( 0 == ( span_CONFIG_CONTRACT_LEVEL_MASK & 0x01 ) ) 500 #define span_ELIDE_CONTRACT_ENSURES ( 0 == ( span_CONFIG_CONTRACT_LEVEL_MASK & 0x10 ) ) 502 #if span_ELIDE_CONTRACT_EXPECTS 503 # define span_constexpr_exp span_constexpr 504 # define span_EXPECTS( cond ) 506 # define span_constexpr_exp span_constexpr14 507 # define span_EXPECTS( cond ) span_CONTRACT_CHECK( "Precondition", cond ) 510 #if span_ELIDE_CONTRACT_ENSURES 511 # define span_constexpr_ens span_constexpr 512 # define span_ENSURES( cond ) 514 # define span_constexpr_ens span_constexpr14 515 # define span_ENSURES( cond ) span_CONTRACT_CHECK( "Postcondition", cond ) 518 #define span_CONTRACT_CHECK( type, cond ) \ 519 cond ? static_cast< void >( 0 ) \ 520 : nonstd::span_lite::detail::report_contract_violation( span_LOCATION( __FILE__, __LINE__ ) ": " type " violation." ) 523 # define span_LOCATION( file, line ) file ":" span_STRINGIFY( line ) 525 # define span_LOCATION( file, line ) file "(" span_STRINGIFY( line ) ")" 530 #if span_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) 532 #define span_REQUIRES_0(VA) \ 533 template< bool B = (VA), typename std::enable_if<B, int>::type = 0 > 535 # if span_BETWEEN( span_COMPILER_MSVC_VERSION, 1, 140 ) 537 # define span_REQUIRES_T(VA) \ 538 , typename = typename std::enable_if< ( VA ), nonstd::span_lite::detail::enabler >::type 540 # define span_REQUIRES_T(VA) \ 541 , typename std::enable_if< (VA), int >::type = 0 544 #define span_REQUIRES_R(R, VA) \ 545 typename std::enable_if< (VA), R>::type 547 #define span_REQUIRES_A(VA) \ 548 , typename std::enable_if< (VA), void*>::type = nullptr 552 # define span_REQUIRES_0(VA) 553 # define span_REQUIRES_T(VA) 554 # define span_REQUIRES_R(R, VA) R 555 # define span_REQUIRES_A(VA) 560 namespace span_lite {
569 template<
class T, extent_t Extent = dynamic_extent >
581 #if span_HAVE( REMOVE_CONST ) 583 using std::remove_cv;
584 using std::remove_const;
585 using std::remove_volatile;
601 #endif // span_HAVE( REMOVE_CONST ) 603 #if span_HAVE( TYPE_TRAITS ) 606 using std::is_signed;
607 using std::integral_constant;
610 using std::remove_reference;
618 template<
class T,
class U >
struct is_same : false_type{};
619 template<
class T >
struct is_same<T, T> : true_type{};
621 template<
typename T >
struct is_signed : false_type {};
622 template<>
struct is_signed<signed char> : true_type {};
623 template<>
struct is_signed<signed int > : true_type {};
624 template<>
struct is_signed<signed long> : true_type {};
643 #if span_HAVE( DATA ) 648 #elif span_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR ) 650 template<
typename T, std::
size_t N >
656 template<
typename C >
662 template<
typename T, std::
size_t N >
668 template<
typename C >
669 inline span_constexpr auto data( C & cont ) -> decltype( cont.data() )
674 template<
typename C >
675 inline span_constexpr auto data( C
const & cont ) -> decltype( cont.data() )
680 template<
typename E >
686 #endif // span_HAVE( DATA ) 688 #if span_HAVE( BYTE ) 690 #elif span_HAVE( NONSTD_BYTE ) 700 #if span_HAVE( DEDUCTION_GUIDES ) 702 using iter_reference_t = decltype( *std::declval<T&>() );
713 template<
typename T >
719 #if span_HAVE( TYPE_TRAITS ) 724 template<
class T, span_CONFIG_EXTENT_TYPE Extent >
728 struct is_span : is_span_oracle< typename std::remove_cv<Q>::type >{};
733 #if span_HAVE( ARRAY ) 735 template<
class T, std::
size_t Extent >
736 struct is_std_array_oracle< std::array<T, Extent> > :
std::true_type{};
741 struct is_std_array : is_std_array_oracle< typename std::remove_cv<Q>::type >{};
749 template<
class T, std::
size_t N >
752 #if span_CPP11_140 && ! span_BETWEEN( span_COMPILER_GNUC_VERSION, 1, 500 ) 754 template<
class,
class =
void >
758 struct has_size_and_data
761 decltype( std17::size(std::declval<C>()) ),
762 decltype( std17::data(std::declval<C>()) ) >
765 template<
class,
class,
class =
void >
768 template<
class C,
class E >
769 struct is_compatible_element
772 decltype( std17::data(std::declval<C>()) ) >
773 > : std::is_convertible< typename std::remove_pointer<decltype( std17::data( std::declval<C&>() ) )>::type(*)[], E(*)[] >{};
778 ! is_span< C >::value
779 && ! is_array< C >::value
780 && ! is_std_array< C >::value
781 && has_size_and_data< C >::value
784 template<
class C,
class E >
787 is_container<C>::value
788 && is_compatible_element<C,E>::value
791 #else // span_CPP11_140 799 && ( std::is_convertible<
typename std::remove_pointer<decltype( std17::data( std::declval<C&>() ) )>::type(*)[], E(*)[] >::
value)
802 ,
class = decltype(
std17::size(std::declval<C>()) )
803 ,
class = decltype( std17::data(std::declval<C>()) )
807 #endif // span_CPP11_140 809 #endif // span_HAVE( TYPE_TRAITS ) 811 #if ! span_CONFIG( NO_EXCEPTIONS ) 812 #if span_FEATURE( MEMBER_AT ) > 1 816 #if defined(__clang__) 817 # pragma clang diagnostic ignored "-Wlong-long" 818 #elif defined __GNUC__ 819 # pragma GCC diagnostic ignored "-Wformat=ll" 820 # pragma GCC diagnostic ignored "-Wlong-long" 825 const char fmt[] =
"span::at(): index '%lli' is out of range [0..%lli)";
826 char buffer[ 2 * 20 +
sizeof fmt ];
827 sprintf( buffer, fmt, static_cast<long long>(idx), static_cast<long long>(size) );
829 throw std::out_of_range( buffer );
834 span_noreturn inline void throw_out_of_range(
size_t ,
size_t )
836 throw std::out_of_range(
"span::at(): index outside span" );
839 #endif // NO_EXCEPTIONS 841 #if span_CONFIG( CONTRACT_VIOLATION_THROWS_V ) 843 struct contract_violation : std::logic_error
845 explicit contract_violation(
char const *
const message )
846 : std::logic_error( message )
852 throw contract_violation( msg );
855 #else // span_CONFIG( CONTRACT_VIOLATION_THROWS_V ) 862 #endif // span_CONFIG( CONTRACT_VIOLATION_THROWS_V ) 868 #define span_sizeof(T) static_cast<extent_t>( sizeof(T) ) 873 return static_cast<size_t>(
size );
879 template<
class T, extent_t Extent >
905 enum { extent = Extent };
911 ( Extent == dynamic_extent )
921 #if span_HAVE( ITERATOR_CTOR ) 931 template<
typename It
933 std::is_convertible<decltype(*std::declval<It&>()), element_type &>::
value 937 : data_( to_address( first ) )
957 #if span_HAVE( ITERATOR_CTOR ) 958 template<
typename It,
typename End
960 std::is_convertible<decltype(&*std::declval<It&>()), element_type *>::
value 965 : data_( to_address( first ) )
966 , size_(
to_size( last - first ) )
975 , size_(
to_size( last - first ) )
985 (Extent == dynamic_extent || Extent == static_cast<extent_t>(N))
986 && std::is_convertible< value_type(*)[], element_type(*)[] >::
value 994 #if span_HAVE( ARRAY ) 998 (Extent == dynamic_extent || Extent == static_cast<extent_t>(N))
999 && std::is_convertible< value_type(*)[], element_type(*)[] >::
value 1002 # if span_FEATURE( CONSTRUCTION_FROM_STDARRAY_ELEMENT_TYPE ) 1007 : data_( arr.data() )
1008 , size_(
to_size( arr.size() ) )
1012 # if span_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) 1014 (Extent == dynamic_extent || Extent == static_cast<extent_t>(N))
1015 && std::is_convertible< value_type(*)[], element_type(*)[] >::
value 1020 : data_( arr.data() )
1021 , size_(
to_size( arr.size() ) )
1024 #endif // span_HAVE( ARRAY ) 1026 #if span_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR ) 1027 template<
class Container
1033 : data_( std17::data( cont ) )
1037 template<
class Container
1044 : data_( std17::data( cont ) )
1048 #endif // span_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR ) 1050 #if span_FEATURE( WITH_CONTAINER ) 1052 template<
class Container >
1055 , size_(
to_size( cont.size() ) )
1058 template<
class Container >
1061 , size_(
to_size( cont.size() ) )
1065 #if span_FEATURE( WITH_INITIALIZER_LIST_P2447 ) && span_HAVE( INITIALIZER_LIST ) 1069 #if !span_BETWEEN( span_COMPILER_MSVC_VERSION, 120, 130 ) 1071 template< extent_t U = Extent
1076 #if span_COMPILER_GNUC_VERSION >= 900 // prevent GCC's "-Winit-list-lifetime" 1084 : data_( il.begin() )
1085 , size_( il.size() )
1089 #endif // MSVC 120 (VS2013) 1091 template< extent_t U = Extent
1096 #if span_COMPILER_GNUC_VERSION >= 900 // prevent GCC's "-Winit-list-lifetime" 1104 : data_( il.begin() )
1105 , size_( il.size() )
1111 #if span_HAVE( IS_DEFAULT ) 1114 ~span() span_noexcept =
default;
1116 span_constexpr14 span & operator=( span
const & other ) span_noexcept =
default;
1119 : data_( other.data_ )
1120 , size_( other.size_ )
1128 data_ = other.data_;
1129 size_ = other.size_;
1135 template<
class OtherElementType, extent_type OtherExtent
1137 (Extent == dynamic_extent || OtherExtent == dynamic_extent || Extent == OtherExtent)
1138 && std::is_convertible<OtherElementType(*)[], element_type(*)[]>::
value 1142 : data_( other.
data() )
1143 , size_( other.
size() )
1150 template< extent_type Count >
1159 template< extent_type Count >
1168 #if span_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) 1169 template<
size_type Offset, extent_type Count = dynamic_extent >
1171 template< size_type Offset, extent_type
Count >
1182 data() + Offset,
Count != dynamic_extent ?
Count : (Extent != dynamic_extent ? Extent - Offset :
size() - Offset) );
1202 subspan( size_type offset, size_type count = static_cast<size_type>(dynamic_extent) )
const 1206 ( count == static_cast<size_type>(dynamic_extent) || (
detail::is_positive( count ) && offset + count <=
size() ) )
1210 data() + offset, count ==
static_cast<size_type
>(
dynamic_extent) ?
size() - offset : count );
1222 return static_cast<std::ptrdiff_t
>( size_ );
1227 return size() *
to_size(
sizeof( element_type ) );
1241 return *( data() + idx );
1244 #if span_FEATURE( MEMBER_CALL_OPERATOR ) 1251 return *( data() + idx );
1255 #if span_FEATURE( MEMBER_AT ) 1258 #if span_CONFIG( NO_EXCEPTIONS ) 1259 return this->operator[]( idx );
1263 detail::throw_out_of_range( idx,
size() );
1265 return *( data() + idx );
1275 #if span_FEATURE( MEMBER_BACK_FRONT ) 1288 return *( data() +
size() - 1 );
1295 #if span_FEATURE( MEMBER_SWAP ) 1300 swap( data_, other.data_ );
1301 swap( size_, other.size_ );
1309 #if span_CPP11_OR_GREATER 1312 return iterator( data() );
1318 #if span_CPP11_OR_GREATER 1319 return { data() +
size() };
1321 return iterator( data() +
size() );
1327 #if span_CPP11_OR_GREATER 1330 return const_iterator( data() );
1336 #if span_CPP11_OR_GREATER 1337 return { data() +
size() };
1339 return const_iterator( data() +
size() );
1345 return reverse_iterator( end() );
1350 return reverse_iterator( begin() );
1355 return const_reverse_iterator ( cend() );
1360 return const_reverse_iterator( cbegin() );
1367 #if span_HAVE( ITERATOR_CTOR ) 1368 static inline span_constexpr pointer to_address( std::nullptr_t ) span_noexcept
1373 template<
typename U >
1374 static inline span_constexpr U * to_address( U * p ) span_noexcept
1379 template<
typename Ptr
1382 static inline span_constexpr pointer to_address( Ptr
const & it ) span_noexcept
1384 return to_address( it.operator->() );
1386 #endif // span_HAVE( ITERATOR_CTOR ) 1395 #if span_HAVE( DEDUCTION_GUIDES ) 1397 template<
class T,
size_t N >
1400 template<
class T,
size_t N >
1403 template<
class T,
size_t N >
1406 #if span_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR ) 1408 template<
class Container >
1411 template<
class Container >
1418 template<
class It,
class EndOrSize >
1421 #endif // span_HAVE( DEDUCTION_GUIDES ) 1425 #if span_FEATURE( COMPARISON ) 1426 #if span_FEATURE( SAME ) 1428 template<
class T1, extent_t E1,
class T2, extent_t E2 >
1433 &&
static_cast<void const*
>( l.
data() ) == r.
data();
1438 template<
class T1, extent_t E1,
class T2, extent_t E2 >
1442 #if span_FEATURE( SAME ) 1448 template<
class T1, extent_t E1,
class T2, extent_t E2 >
1451 return std::lexicographical_compare( l.begin(), l.end(), r.
begin(), r.
end() );
1454 template<
class T1, extent_t E1,
class T2, extent_t E2 >
1460 template<
class T1, extent_t E1,
class T2, extent_t E2 >
1466 template<
class T1, extent_t E1,
class T2, extent_t E2 >
1472 template<
class T1, extent_t E1,
class T2, extent_t E2 >
1478 #endif // span_FEATURE( COMPARISON ) 1482 #if span_HAVE( BYTE ) || span_HAVE( NONSTD_BYTE ) 1486 template<
typename T, extent_t Extent >
1489 #if span_CPP11_OR_GREATER 1496 template<
typename T >
1497 struct BytesExtent< T, dynamic_extent >
1499 #if span_CPP11_OR_GREATER 1500 enum ET : extent_t {
value = dynamic_extent };
1502 enum ET {
value = dynamic_extent };
1506 template<
class T, extent_t Extent >
1511 return {
reinterpret_cast< std17::byte
const *
>( spn.
data() ), spn.
size_bytes() };
1514 reinterpret_cast< std17::byte
const *
>( spn.
data() ), spn.
size_bytes() );
1518 template<
class T, extent_t Extent >
1523 return {
reinterpret_cast< std17::byte *
>( spn.
data() ), spn.
size_bytes() };
1526 reinterpret_cast< std17::byte *
>( spn.
data() ), spn.
size_bytes() );
1530 #endif // span_HAVE( BYTE ) || span_HAVE( NONSTD_BYTE ) 1534 template<
class T, extent_t Extent >
1540 template<
class T, extent_t Extent >
1543 return static_cast<std::ptrdiff_t
>( spn.
size() );
1559 #if span_FEATURE( COMPARISON ) 1560 #if span_FEATURE( SAME ) 1561 using span_lite::same;
1564 using span_lite::operator==;
1565 using span_lite::operator!=;
1566 using span_lite::operator<;
1567 using span_lite::operator<=;
1568 using span_lite::operator>;
1569 using span_lite::operator>=;
1572 #if span_HAVE( BYTE ) 1573 using span_lite::as_bytes;
1574 using span_lite::as_writable_bytes;
1582 #endif // span_USES_STD_SPAN 1586 #if span_FEATURE( MAKE_SPAN ) || span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_SPAN ) || span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_CONTAINER ) 1588 #if span_USES_STD_SPAN 1589 # define span_constexpr constexpr 1590 # define span_noexcept noexcept 1591 # define span_nullptr nullptr 1592 # ifndef span_CONFIG_EXTENT_TYPE 1593 # define span_CONFIG_EXTENT_TYPE std::size_t 1596 #endif // span_USES_STD_SPAN 1599 namespace span_lite {
1603 make_span( T * ptr,
size_t count ) span_noexcept
1610 make_span( T * first, T * last ) span_noexcept
1612 return span<T>( first, last );
1615 template<
class T, std::
size_t N >
1617 make_span( T ( &arr )[ N ] ) span_noexcept
1622 #if span_USES_STD_SPAN || span_HAVE( ARRAY ) 1624 template<
class T, std::
size_t N >
1626 make_span( std::array< T, N > & arr ) span_noexcept
1631 template<
class T, std::
size_t N >
1633 make_span( std::array< T, N >
const & arr ) span_noexcept
1638 #endif // span_HAVE( ARRAY ) 1640 #if span_USES_STD_SPAN || span_HAVE( INITIALIZER_LIST ) 1644 make_span( std::initializer_list<T> il ) span_noexcept
1649 #endif // span_HAVE( INITIALIZER_LIST ) 1651 #if span_USES_STD_SPAN 1653 template<
class Container,
class EP = decltype( std::data(std::declval<Container&>())) >
1660 template<
class Container,
class EP = decltype( std::data(std::declval<Container&>())) >
1667 #elif span_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR ) && span_HAVE( AUTO ) 1669 template<
class Container,
class EP = decltype( std17::data(std::declval<Container&>())) >
1676 template<
class Container,
class EP = decltype( std17::data(std::declval<Container&>())) >
1687 make_span(
span<T> spn ) span_noexcept
1692 template<
class T,
class Allocator >
1694 make_span( std::vector<T, Allocator> & cont ) span_noexcept
1699 template<
class T,
class Allocator >
1701 make_span( std::vector<T, Allocator>
const & cont ) span_noexcept
1706 #endif // span_USES_STD_SPAN || ( ... ) 1708 #if ! span_USES_STD_SPAN && span_FEATURE( WITH_CONTAINER ) 1710 template<
class Container >
1717 template<
class Container >
1724 #endif // ! span_USES_STD_SPAN && span_FEATURE( WITH_CONTAINER ) 1729 #if span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_SPAN ) 1731 template< extent_t Count,
class T, extent_t Extent >
1735 return spn.template first<Count>();
1738 template<
class T, extent_t Extent >
1742 return spn.
first( count );
1745 template< extent_t Count,
class T, extent_t Extent >
1749 return spn.template last<Count>();
1752 template<
class T, extent_t Extent >
1756 return spn.
last( count );
1759 template<
size_t Offset, extent_t Count,
class T, extent_t Extent >
1763 return spn.template subspan<Offset, Count>();
1766 template<
class T, extent_t Extent >
1768 subspan(
span<T, Extent> spn,
size_t offset, extent_t count = dynamic_extent )
1770 return spn.
subspan( offset, count );
1773 #endif // span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_SPAN ) 1775 #if span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_CONTAINER ) && span_CPP11_120 1777 template< extent_t Count,
class T >
1779 first( T & t ) -> decltype( make_span(t).
template first<Count>() )
1781 return make_span( t ).template first<Count>();
1786 first( T & t,
size_t count ) -> decltype( make_span(t).first(count) )
1788 return make_span( t ).first( count );
1791 template< extent_t Count,
class T >
1793 last( T & t ) -> decltype( make_span(t).
template last<Count>() )
1795 return make_span(t).template last<Count>();
1800 last( T & t, extent_t count ) -> decltype( make_span(t).last(count) )
1802 return make_span( t ).last( count );
1805 template<
size_t Offset, extent_t Count = dynamic_extent,
class T >
1807 subspan( T & t ) -> decltype( make_span(t).
template subspan<Offset, Count>() )
1809 return make_span( t ).template subspan<Offset, Count>();
1814 subspan( T & t,
size_t offset, extent_t count = dynamic_extent ) -> decltype( make_span(t).subspan(offset, count) )
1816 return make_span( t ).subspan( offset, count );
1819 #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 ) || ( span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_CONTAINER ) && span_CPP11_120 ) 1831 using span_lite::first;
1832 using span_lite::last;
1833 using span_lite::subspan;
1835 #endif // span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_[SPAN|CONTAINER] ) 1839 #endif // #if span_FEATURE_TO_STD( MAKE_SPAN ) 1841 #if span_CPP11_OR_GREATER && span_FEATURE( BYTE_SPAN ) && ( span_HAVE( BYTE ) || span_HAVE( NONSTD_BYTE ) ) 1844 namespace span_lite {
1866 using span_lite::byte_span;
1869 #endif // span_FEATURE( BYTE_SPAN ) 1871 #if span_HAVE( STRUCT_BINDING ) 1873 #if span_CPP14_OR_GREATER 1875 #elif span_CPP11_OR_GREATER 1878 template< std::
size_t I,
typename T >
1879 using tuple_element_t =
typename tuple_element<I, T>::type;
1883 template<
typename T >
1886 template< std::
size_t I,
typename T >
1887 class tuple_element;
1889 #endif // span_CPP14_OR_GREATER 1897 template<
typename ElementType, nonstd::span_lite::extent_t Extent >
1898 class tuple_size< nonstd::span<ElementType, Extent> > :
public integral_constant<size_t, static_cast<size_t>(Extent)> {};
1902 template<
typename ElementType >
1903 class tuple_size< nonstd::span<ElementType, nonstd::dynamic_extent> >;
1907 template< size_t I, typename ElementType, nonstd::span_lite::extent_t Extent >
1908 class tuple_element< I, nonstd::span<ElementType, Extent> >
1911 #if span_HAVE( STATIC_ASSERT ) 1912 static_assert( Extent !=
nonstd::dynamic_extent && I < Extent,
"tuple_element<I,span>: dynamic extent or index out of range" );
1914 using type = ElementType;
1919 template<
size_t I,
typename ElementType, nonstd::span_lite::extent_t Extent >
1922 #if span_HAVE( STATIC_ASSERT ) 1923 static_assert( Extent !=
nonstd::dynamic_extent && I < Extent,
"get<>(span): dynamic extent or index out of range" );
1928 template<
size_t I,
typename ElementType, nonstd::span_lite::extent_t Extent >
1931 #if span_HAVE( STATIC_ASSERT ) 1932 static_assert( Extent !=
nonstd::dynamic_extent && I < Extent,
"get<>(span): dynamic extent or index out of range" );
1939 #endif // span_HAVE( STRUCT_BINDING ) 1941 #if ! span_USES_STD_SPAN 1943 #endif // span_USES_STD_SPAN 1945 #endif // NONSTD_SPAN_HPP_INCLUDED
std11::remove_volatile< typename std11::remove_const< T >::type >::type type
void swap(any &x, any &y) any_noexcept
span_constexpr_exp span< element_type, dynamic_extent > subspan(size_type offset, size_type count=static_cast< size_type >(dynamic_extent)) const
span_constexpr_exp span(pointer first, pointer last)
const_pointer const_iterator
span_constexpr span(span const &other) span_noexcept
#define span_constexpr_exp
span_constexpr_exp reference operator[](size_type idx) const
span_constexpr iterator begin() const span_noexcept
span_constexpr_exp span(span< OtherElementType, OtherExtent > const &other) span_noexcept
span_CONFIG_SIZE_TYPE size_t
#define span_deprecated(msg)
span_constexpr std::ptrdiff_t ssize(span< T, Extent > const &spn)
std::ptrdiff_t difference_type
T const & const_reference
span_constexpr reverse_iterator rbegin() const span_noexcept
span_constexpr_exp span< element_type, dynamic_extent > last(size_type count) const
span_constexpr size_type size_bytes() const span_noexcept
span_CONFIG_EXTENT_TYPE extent_t
span_constexpr_exp span< element_type, Count > last() const
span_constexpr const_iterator cbegin() const span_noexcept
span_constexpr_exp span< element_type, Count > first() const
const span_constexpr with_container_t with_container
span_constexpr span(element_type(&arr)[N]) span_noexcept
#define span_REQUIRES_T(VA)
#define span_EXPECTS(cond)
span_constexpr const_reverse_iterator crbegin() const span_noexcept
integral_constant< bool, false > false_type
span_constexpr size_t to_size(T size)
span_constexpr pointer data() const span_noexcept
span_noreturn void report_contract_violation(char const *) span_noexcept
#define span_CONFIG_SIZE_TYPE
span_constexpr_exp span< element_type, Count > subspan() const
integral_constant< bool, true > true_type
span_constexpr_exp reference back() const span_noexcept
optional_constexpr bool operator>(optional< T > const &x, optional< U > const &y)
std11::remove_cv< T >::type value_type
std::reverse_iterator< iterator > reverse_iterator
span_constexpr bool is_positive(T x)
span_constexpr_exp span(pointer ptr, size_type count)
#define span_RESTORE_WARNINGS()
bool operator!=(const GlobalRouter::Incidency &a, const GlobalRouter::Incidency &b)
span_constexpr with_container_t() span_noexcept
span_constexpr_exp reference front() const span_noexcept
span_constexpr const extent_t dynamic_extent
span_REQUIRES_0((Extent==0)||(Extent==dynamic_extent)) span_constexpr span() span_noexcept
std::reverse_iterator< const_iterator > const_reverse_iterator
span_constexpr const_iterator cend() const span_noexcept
#define span_ADDRESSOF(x)
span_constexpr std::ptrdiff_t ssize() const span_noexcept
span_constexpr iterator end() const span_noexcept
span_constexpr size_type size() const span_noexcept
span_constexpr std::size_t size(span< T, Extent > const &spn)
span_nodiscard span_constexpr bool empty() const span_noexcept
span_constexpr reverse_iterator rend() const span_noexcept
optional_constexpr bool operator>=(optional< T > const &x, optional< U > const &y)
span_constexpr const_reverse_iterator crend() const span_noexcept
#define span_CONFIG_EXTENT_TYPE
span_constexpr_exp span< element_type, dynamic_extent > first(size_type count) const
bool operator==(const GlobalRouter::Incidency &a, const GlobalRouter::Incidency &b)
span_constexpr14 span & operator=(span const &other) span_noexcept