| 1 |
// |
| 2 |
// span for C++98 and later. |
| 3 |
// Based on http://wg21.link/p0122r7 |
| 4 |
// For more information see https://github.com/martinmoene/span-lite |
| 5 |
// |
| 6 |
// Copyright 2018-2021 Martin Moene |
| 7 |
// |
| 8 |
// Distributed under the Boost Software License, Version 1.0. |
| 9 |
// (See accompanying file LICENSE.txt or copy at https://www.boost.org/LICENSE_1_0.txt) |
| 10 |
|
| 11 |
#ifndef NONSTD_SPAN_HPP_INCLUDED |
| 12 |
#define NONSTD_SPAN_HPP_INCLUDED |
| 13 |
|
| 14 |
#define span_lite_MAJOR 0 |
| 15 |
#define span_lite_MINOR 11 |
| 16 |
#define span_lite_PATCH 0 |
| 17 |
|
| 18 |
#define span_lite_VERSION span_STRINGIFY(span_lite_MAJOR) "." span_STRINGIFY(span_lite_MINOR) "." span_STRINGIFY(span_lite_PATCH) |
| 19 |
|
| 20 |
#define span_STRINGIFY( x ) span_STRINGIFY_( x ) |
| 21 |
#define span_STRINGIFY_( x ) #x |
| 22 |
|
| 23 |
// span configuration: |
| 24 |
|
| 25 |
#define span_SPAN_DEFAULT 0 |
| 26 |
#define span_SPAN_NONSTD 1 |
| 27 |
#define span_SPAN_STD 2 |
| 28 |
|
| 29 |
// tweak header support: |
| 30 |
|
| 31 |
#ifdef __has_include |
| 32 |
# if __has_include(<nonstd/span.tweak.hpp>) |
| 33 |
# include <nonstd/span.tweak.hpp> |
| 34 |
# endif |
| 35 |
#define span_HAVE_TWEAK_HEADER 1 |
| 36 |
#else |
| 37 |
#define span_HAVE_TWEAK_HEADER 0 |
| 38 |
//# pragma message("span.hpp: Note: Tweak header not supported.") |
| 39 |
#endif |
| 40 |
|
| 41 |
// span selection and configuration: |
| 42 |
|
| 43 |
#define span_HAVE( feature ) ( span_HAVE_##feature ) |
| 44 |
|
| 45 |
#ifndef span_CONFIG_SELECT_SPAN |
| 46 |
# define span_CONFIG_SELECT_SPAN ( span_HAVE_STD_SPAN ? span_SPAN_STD : span_SPAN_NONSTD ) |
| 47 |
#endif |
| 48 |
|
| 49 |
#ifndef span_CONFIG_CONTRACT_LEVEL_ON |
| 50 |
# define span_CONFIG_CONTRACT_LEVEL_ON 1 |
| 51 |
#endif |
| 52 |
|
| 53 |
#ifndef span_CONFIG_CONTRACT_VIOLATION_THROWS |
| 54 |
# define span_CONFIG_CONTRACT_VIOLATION_THROWS 0 |
| 55 |
#endif |
| 56 |
|
| 57 |
#ifndef span_CONFIG_CONTRACT_VIOLATION_TERMINATES |
| 58 |
# if span_CONFIG_CONTRACT_VIOLATION_THROWS |
| 59 |
# define span_CONFIG_CONTRACT_VIOLATION_TERMINATES 0 |
| 60 |
# else |
| 61 |
# define span_CONFIG_CONTRACT_VIOLATION_TERMINATES 1 |
| 62 |
# endif |
| 63 |
#endif |
| 64 |
|
| 65 |
#ifndef span_CONFIG_EXTENT_TYPE |
| 66 |
# define span_CONFIG_EXTENT_TYPE std::size_t |
| 67 |
#endif |
| 68 |
|
| 69 |
#ifndef span_CONFIG_SIZE_TYPE |
| 70 |
# define span_CONFIG_SIZE_TYPE std::size_t |
| 71 |
#endif |
| 72 |
|
| 73 |
#ifdef span_CONFIG_INDEX_TYPE |
| 74 |
# error `span_CONFIG_INDEX_TYPE` is deprecated since v0.7.0; it is replaced by `span_CONFIG_SIZE_TYPE`. |
| 75 |
#endif |
| 76 |
|
| 77 |
// span configuration (features): |
| 78 |
|
| 79 |
#ifndef span_FEATURE_WITH_INITIALIZER_LIST_P2447 |
| 80 |
# define span_FEATURE_WITH_INITIALIZER_LIST_P2447 0 |
| 81 |
#endif |
| 82 |
|
| 83 |
#ifndef span_FEATURE_WITH_CONTAINER |
| 84 |
#ifdef span_FEATURE_WITH_CONTAINER_TO_STD |
| 85 |
# define span_FEATURE_WITH_CONTAINER span_IN_STD( span_FEATURE_WITH_CONTAINER_TO_STD ) |
| 86 |
#else |
| 87 |
# define span_FEATURE_WITH_CONTAINER 0 |
| 88 |
# define span_FEATURE_WITH_CONTAINER_TO_STD 0 |
| 89 |
#endif |
| 90 |
#endif |
| 91 |
|
| 92 |
#ifndef span_FEATURE_CONSTRUCTION_FROM_STDARRAY_ELEMENT_TYPE |
| 93 |
# define span_FEATURE_CONSTRUCTION_FROM_STDARRAY_ELEMENT_TYPE 0 |
| 94 |
#endif |
| 95 |
|
| 96 |
#ifndef span_FEATURE_MEMBER_AT |
| 97 |
# define span_FEATURE_MEMBER_AT 0 |
| 98 |
#endif |
| 99 |
|
| 100 |
#ifndef span_FEATURE_MEMBER_BACK_FRONT |
| 101 |
# define span_FEATURE_MEMBER_BACK_FRONT 1 |
| 102 |
#endif |
| 103 |
|
| 104 |
#ifndef span_FEATURE_MEMBER_CALL_OPERATOR |
| 105 |
# define span_FEATURE_MEMBER_CALL_OPERATOR 0 |
| 106 |
#endif |
| 107 |
|
| 108 |
#ifndef span_FEATURE_MEMBER_SWAP |
| 109 |
# define span_FEATURE_MEMBER_SWAP 0 |
| 110 |
#endif |
| 111 |
|
| 112 |
#ifndef span_FEATURE_NON_MEMBER_FIRST_LAST_SUB |
| 113 |
# define span_FEATURE_NON_MEMBER_FIRST_LAST_SUB 0 |
| 114 |
#elif span_FEATURE_NON_MEMBER_FIRST_LAST_SUB |
| 115 |
# define span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_SPAN 1 |
| 116 |
# define span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_CONTAINER 1 |
| 117 |
#endif |
| 118 |
|
| 119 |
#ifndef span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_SPAN |
| 120 |
# define span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_SPAN 0 |
| 121 |
#endif |
| 122 |
|
| 123 |
#ifndef span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_CONTAINER |
| 124 |
# define span_FEATURE_NON_MEMBER_FIRST_LAST_SUB_CONTAINER 0 |
| 125 |
#endif |
| 126 |
|
| 127 |
#ifndef span_FEATURE_COMPARISON |
| 128 |
# define span_FEATURE_COMPARISON 0 // Note: C++20 does not provide comparison |
| 129 |
#endif |
| 130 |
|
| 131 |
#ifndef span_FEATURE_SAME |
| 132 |
# define span_FEATURE_SAME 0 |
| 133 |
#endif |
| 134 |
|
| 135 |
#if span_FEATURE_SAME && !span_FEATURE_COMPARISON |
| 136 |
# error `span_FEATURE_SAME` requires `span_FEATURE_COMPARISON` |
| 137 |
#endif |
| 138 |
|
| 139 |
#ifndef span_FEATURE_MAKE_SPAN |
| 140 |
#ifdef span_FEATURE_MAKE_SPAN_TO_STD |
| 141 |
# define span_FEATURE_MAKE_SPAN span_IN_STD( span_FEATURE_MAKE_SPAN_TO_STD ) |
| 142 |
#else |
| 143 |
# define span_FEATURE_MAKE_SPAN 0 |
| 144 |
# define span_FEATURE_MAKE_SPAN_TO_STD 0 |
| 145 |
#endif |
| 146 |
#endif |
| 147 |
|
| 148 |
#ifndef span_FEATURE_BYTE_SPAN |
| 149 |
# define span_FEATURE_BYTE_SPAN 0 |
| 150 |
#endif |
| 151 |
|
| 152 |
// Control presence of exception handling (try and auto discover): |
| 153 |
|
| 154 |
#ifndef span_CONFIG_NO_EXCEPTIONS |
| 155 |
# if defined(_MSC_VER) |
| 156 |
# include <cstddef> // for _HAS_EXCEPTIONS |
| 157 |
# endif |
| 158 |
# if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || (_HAS_EXCEPTIONS) |
| 159 |
# define span_CONFIG_NO_EXCEPTIONS 0 |
| 160 |
# else |
| 161 |
# define span_CONFIG_NO_EXCEPTIONS 1 |
| 162 |
# undef span_CONFIG_CONTRACT_VIOLATION_THROWS |
| 163 |
# undef span_CONFIG_CONTRACT_VIOLATION_TERMINATES |
| 164 |
# define span_CONFIG_CONTRACT_VIOLATION_THROWS 0 |
| 165 |
# define span_CONFIG_CONTRACT_VIOLATION_TERMINATES 1 |
| 166 |
# endif |
| 167 |
#endif |
| 168 |
|
| 169 |
// Control pre- and postcondition violation behaviour: |
| 170 |
|
| 171 |
#if defined( span_CONFIG_CONTRACT_LEVEL_ON ) |
| 172 |
# define span_CONFIG_CONTRACT_LEVEL_MASK 0x11 |
| 173 |
#elif defined( span_CONFIG_CONTRACT_LEVEL_OFF ) |
| 174 |
# define span_CONFIG_CONTRACT_LEVEL_MASK 0x00 |
| 175 |
#elif defined( span_CONFIG_CONTRACT_LEVEL_EXPECTS_ONLY ) |
| 176 |
# define span_CONFIG_CONTRACT_LEVEL_MASK 0x01 |
| 177 |
#elif defined( span_CONFIG_CONTRACT_LEVEL_ENSURES_ONLY ) |
| 178 |
# define span_CONFIG_CONTRACT_LEVEL_MASK 0x10 |
| 179 |
#else |
| 180 |
# define span_CONFIG_CONTRACT_LEVEL_MASK 0x11 |
| 181 |
#endif |
| 182 |
|
| 183 |
#if defined( span_CONFIG_CONTRACT_VIOLATION_THROWS ) |
| 184 |
# define span_CONFIG_CONTRACT_VIOLATION_THROWS_V span_CONFIG_CONTRACT_VIOLATION_THROWS |
| 185 |
#else |
| 186 |
# define span_CONFIG_CONTRACT_VIOLATION_THROWS_V 0 |
| 187 |
#endif |
| 188 |
|
| 189 |
#if span_CONFIG_CONTRACT_VIOLATION_THROWS && \ |
| 190 |
span_CONFIG_CONTRACT_VIOLATION_TERMINATES |
| 191 |
# error Please define none or one of span_CONFIG_CONTRACT_VIOLATION_THROWS and span_CONFIG_CONTRACT_VIOLATION_TERMINATES to 1, but not both. |
| 192 |
#endif |
| 193 |
|
| 194 |
// C++ language version detection (C++23 is speculative): |
| 195 |
// Note: VC14.0/1900 (VS2015) lacks too much from C++14. |
| 196 |
|
| 197 |
#ifndef span_CPLUSPLUS |
| 198 |
# if defined(_MSVC_LANG ) && !defined(__clang__) |
| 199 |
# define span_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG ) |
| 200 |
# else |
| 201 |
# define span_CPLUSPLUS __cplusplus |
| 202 |
# endif |
| 203 |
#endif |
| 204 |
|
| 205 |
#define span_CPP98_OR_GREATER ( span_CPLUSPLUS >= 199711L ) |
| 206 |
#define span_CPP11_OR_GREATER ( span_CPLUSPLUS >= 201103L ) |
| 207 |
#define span_CPP14_OR_GREATER ( span_CPLUSPLUS >= 201402L ) |
| 208 |
#define span_CPP17_OR_GREATER ( span_CPLUSPLUS >= 201703L ) |
| 209 |
#define span_CPP20_OR_GREATER ( span_CPLUSPLUS >= 202002L ) |
| 210 |
#define span_CPP23_OR_GREATER ( span_CPLUSPLUS >= 202300L ) |
| 211 |
|
| 212 |
// C++ language version (represent 98 as 3): |
| 213 |
|
| 214 |
#define span_CPLUSPLUS_V ( span_CPLUSPLUS / 100 - (span_CPLUSPLUS > 200000 ? 2000 : 1994) ) |
| 215 |
|
| 216 |
#define span_IN_STD( v ) ( ((v) == 98 ? 3 : (v)) >= span_CPLUSPLUS_V ) |
| 217 |
|
| 218 |
#define span_CONFIG( feature ) ( span_CONFIG_##feature ) |
| 219 |
#define span_FEATURE( feature ) ( span_FEATURE_##feature ) |
| 220 |
#define span_FEATURE_TO_STD( feature ) ( span_IN_STD( span_FEATURE( feature##_TO_STD ) ) ) |
| 221 |
|
| 222 |
// Use C++20 std::span if available and requested: |
| 223 |
|
| 224 |
#if span_CPP20_OR_GREATER && defined(__has_include ) |
| 225 |
# if __has_include( <span> ) |
| 226 |
# define span_HAVE_STD_SPAN 1 |
| 227 |
# else |
| 228 |
# define span_HAVE_STD_SPAN 0 |
| 229 |
# endif |
| 230 |
#else |
| 231 |
# define span_HAVE_STD_SPAN 0 |
| 232 |
#endif |
| 233 |
|
| 234 |
#define span_USES_STD_SPAN ( (span_CONFIG_SELECT_SPAN == span_SPAN_STD) || ((span_CONFIG_SELECT_SPAN == span_SPAN_DEFAULT) && span_HAVE_STD_SPAN) ) |
| 235 |
|
| 236 |
// |
| 237 |
// Use C++20 std::span: |
| 238 |
// |
| 239 |
|
| 240 |
#if span_USES_STD_SPAN |
| 241 |
|
| 242 |
#include <span> |
| 243 |
|
| 244 |
namespace nonstd { |
| 245 |
|
| 246 |
using std::span; |
| 247 |
using std::dynamic_extent; |
| 248 |
|
| 249 |
// Note: C++20 does not provide comparison |
| 250 |
// using std::operator==; |
| 251 |
// using std::operator!=; |
| 252 |
// using std::operator<; |
| 253 |
// using std::operator<=; |
| 254 |
// using std::operator>; |
| 255 |
// using std::operator>=; |
| 256 |
} // namespace nonstd |
| 257 |
|
| 258 |
#else // span_USES_STD_SPAN |
| 259 |
|
| 260 |
#include <algorithm> |
| 261 |
|
| 262 |
// Compiler versions: |
| 263 |
// |
| 264 |
// MSVC++ 6.0 _MSC_VER == 1200 span_COMPILER_MSVC_VERSION == 60 (Visual Studio 6.0) |
| 265 |
// MSVC++ 7.0 _MSC_VER == 1300 span_COMPILER_MSVC_VERSION == 70 (Visual Studio .NET 2002) |
| 266 |
// MSVC++ 7.1 _MSC_VER == 1310 span_COMPILER_MSVC_VERSION == 71 (Visual Studio .NET 2003) |
| 267 |
// MSVC++ 8.0 _MSC_VER == 1400 span_COMPILER_MSVC_VERSION == 80 (Visual Studio 2005) |
| 268 |
// MSVC++ 9.0 _MSC_VER == 1500 span_COMPILER_MSVC_VERSION == 90 (Visual Studio 2008) |
| 269 |
// MSVC++ 10.0 _MSC_VER == 1600 span_COMPILER_MSVC_VERSION == 100 (Visual Studio 2010) |
| 270 |
// MSVC++ 11.0 _MSC_VER == 1700 span_COMPILER_MSVC_VERSION == 110 (Visual Studio 2012) |
| 271 |
// MSVC++ 12.0 _MSC_VER == 1800 span_COMPILER_MSVC_VERSION == 120 (Visual Studio 2013) |
| 272 |
// MSVC++ 14.0 _MSC_VER == 1900 span_COMPILER_MSVC_VERSION == 140 (Visual Studio 2015) |
| 273 |
// MSVC++ 14.1 _MSC_VER >= 1910 span_COMPILER_MSVC_VERSION == 141 (Visual Studio 2017) |
| 274 |
// MSVC++ 14.2 _MSC_VER >= 1920 span_COMPILER_MSVC_VERSION == 142 (Visual Studio 2019) |
| 275 |
|
| 276 |
#if defined(_MSC_VER ) && !defined(__clang__) |
| 277 |
# define span_COMPILER_MSVC_VER (_MSC_VER ) |
| 278 |
# define span_COMPILER_MSVC_VERSION (_MSC_VER / 10 - 10 * ( 5 + (_MSC_VER < 1900 ) ) ) |
| 279 |
#else |
| 280 |
# define span_COMPILER_MSVC_VER 0 |
| 281 |
# define span_COMPILER_MSVC_VERSION 0 |
| 282 |
#endif |
| 283 |
|
| 284 |
#define span_COMPILER_VERSION( major, minor, patch ) ( 10 * ( 10 * (major) + (minor) ) + (patch) ) |
| 285 |
|
| 286 |
#if defined(__clang__) |
| 287 |
# define span_COMPILER_CLANG_VERSION span_COMPILER_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__) |
| 288 |
#else |
| 289 |
# define span_COMPILER_CLANG_VERSION 0 |
| 290 |
#endif |
| 291 |
|
| 292 |
#if defined(__GNUC__) && !defined(__clang__) |
| 293 |
# define span_COMPILER_GNUC_VERSION span_COMPILER_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) |
| 294 |
#else |
| 295 |
# define span_COMPILER_GNUC_VERSION 0 |
| 296 |
#endif |
| 297 |
|
| 298 |
// half-open range [lo..hi): |
| 299 |
#define span_BETWEEN( v, lo, hi ) ( (lo) <= (v) && (v) < (hi) ) |
| 300 |
|
| 301 |
// Compiler warning suppression: |
| 302 |
|
| 303 |
#if defined(__clang__) |
| 304 |
# pragma clang diagnostic push |
| 305 |
# pragma clang diagnostic ignored "-Wundef" |
| 306 |
# pragma clang diagnostic ignored "-Wmismatched-tags" |
| 307 |
# define span_RESTORE_WARNINGS() _Pragma( "clang diagnostic pop" ) |
| 308 |
|
| 309 |
#elif defined __GNUC__ |
| 310 |
# pragma GCC diagnostic push |
| 311 |
# pragma GCC diagnostic ignored "-Wundef" |
| 312 |
# define span_RESTORE_WARNINGS() _Pragma( "GCC diagnostic pop" ) |
| 313 |
|
| 314 |
#elif span_COMPILER_MSVC_VER >= 1900 |
| 315 |
# define span_DISABLE_MSVC_WARNINGS(codes) __pragma(warning(push)) __pragma(warning(disable: codes)) |
| 316 |
# define span_RESTORE_WARNINGS() __pragma(warning(pop )) |
| 317 |
|
| 318 |
// Suppress the following MSVC GSL warnings: |
| 319 |
// - C26439, gsl::f.6 : special function 'function' can be declared 'noexcept' |
| 320 |
// - C26440, gsl::f.6 : function 'function' can be declared 'noexcept' |
| 321 |
// - C26472, gsl::t.1 : don't use a static_cast for arithmetic conversions; |
| 322 |
// use brace initialization, gsl::narrow_cast or gsl::narrow |
| 323 |
// - C26473: gsl::t.1 : don't cast between pointer types where the source type and the target type are the same |
| 324 |
// - C26481: gsl::b.1 : don't use pointer arithmetic. Use span instead |
| 325 |
// - C26490: gsl::t.1 : don't use reinterpret_cast |
| 326 |
|
| 327 |
span_DISABLE_MSVC_WARNINGS( 26439 26440 26472 26473 26481 26490 ) |
| 328 |
|
| 329 |
#else |
| 330 |
# define span_RESTORE_WARNINGS() /*empty*/ |
| 331 |
#endif |
| 332 |
|
| 333 |
// Presence of language and library features: |
| 334 |
|
| 335 |
#ifdef _HAS_CPP0X |
| 336 |
# define span_HAS_CPP0X _HAS_CPP0X |
| 337 |
#else |
| 338 |
# define span_HAS_CPP0X 0 |
| 339 |
#endif |
| 340 |
|
| 341 |
#define span_CPP11_80 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1400) |
| 342 |
#define span_CPP11_90 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1500) |
| 343 |
#define span_CPP11_100 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1600) |
| 344 |
#define span_CPP11_110 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1700) |
| 345 |
#define span_CPP11_120 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1800) |
| 346 |
#define span_CPP11_140 (span_CPP11_OR_GREATER || span_COMPILER_MSVC_VER >= 1900) |
| 347 |
|
| 348 |
#define span_CPP14_000 (span_CPP14_OR_GREATER) |
| 349 |
#define span_CPP14_120 (span_CPP14_OR_GREATER || span_COMPILER_MSVC_VER >= 1800) |
| 350 |
#define span_CPP14_140 (span_CPP14_OR_GREATER || span_COMPILER_MSVC_VER >= 1900) |
| 351 |
|
| 352 |
#define span_CPP17_000 (span_CPP17_OR_GREATER) |
| 353 |
|
| 354 |
// Presence of C++11 language features: |
| 355 |
|
| 356 |
#define span_HAVE_ALIAS_TEMPLATE span_CPP11_140 |
| 357 |
#define span_HAVE_AUTO span_CPP11_100 |
| 358 |
#define span_HAVE_CONSTEXPR_11 span_CPP11_140 |
| 359 |
#define span_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG span_CPP11_120 |
| 360 |
#define span_HAVE_EXPLICIT_CONVERSION span_CPP11_140 |
| 361 |
#define span_HAVE_INITIALIZER_LIST span_CPP11_120 |
| 362 |
#define span_HAVE_IS_DEFAULT span_CPP11_140 |
| 363 |
#define span_HAVE_IS_DELETE span_CPP11_140 |
| 364 |
#define span_HAVE_NOEXCEPT span_CPP11_140 |
| 365 |
#define span_HAVE_NORETURN ( span_CPP11_140 && ! span_BETWEEN( span_COMPILER_GNUC_VERSION, 1, 480 ) ) |
| 366 |
#define span_HAVE_NULLPTR span_CPP11_100 |
| 367 |
#define span_HAVE_STATIC_ASSERT span_CPP11_100 |
| 368 |
|
| 369 |
// Presence of C++14 language features: |
| 370 |
|
| 371 |
#define span_HAVE_CONSTEXPR_14 span_CPP14_000 |
| 372 |
|
| 373 |
// Presence of C++17 language features: |
| 374 |
|
| 375 |
#define span_HAVE_DEPRECATED span_CPP17_000 |
| 376 |
#define span_HAVE_NODISCARD span_CPP17_000 |
| 377 |
|
| 378 |
// MSVC: template parameter deduction guides since Visual Studio 2017 v15.7 |
| 379 |
|
| 380 |
#if defined(__cpp_deduction_guides) |
| 381 |
# define span_HAVE_DEDUCTION_GUIDES 1 |
| 382 |
#else |
| 383 |
# define span_HAVE_DEDUCTION_GUIDES (span_CPP17_OR_GREATER && ! span_BETWEEN( span_COMPILER_MSVC_VER, 1, 1913 )) |
| 384 |
#endif |
| 385 |
|
| 386 |
// Presence of C++ library features: |
| 387 |
|
| 388 |
#define span_HAVE_ADDRESSOF span_CPP17_000 |
| 389 |
#define span_HAVE_ARRAY span_CPP11_110 |
| 390 |
#define span_HAVE_BYTE span_CPP17_000 |
| 391 |
#define span_HAVE_CONDITIONAL span_CPP11_120 |
| 392 |
#define span_HAVE_CONTAINER_DATA_METHOD (span_CPP11_140 || ( span_COMPILER_MSVC_VER >= 1500 && span_HAS_CPP0X )) |
| 393 |
#define span_HAVE_DATA span_CPP17_000 |
| 394 |
#define span_HAVE_LONGLONG span_CPP11_80 |
| 395 |
#define span_HAVE_REMOVE_CONST span_CPP11_110 |
| 396 |
#define span_HAVE_SNPRINTF span_CPP11_140 |
| 397 |
#define span_HAVE_STRUCT_BINDING span_CPP11_120 |
| 398 |
#define span_HAVE_TYPE_TRAITS span_CPP11_90 |
| 399 |
|
| 400 |
// Presence of byte-lite: |
| 401 |
|
| 402 |
#ifdef NONSTD_BYTE_LITE_HPP |
| 403 |
# define span_HAVE_NONSTD_BYTE 1 |
| 404 |
#else |
| 405 |
# define span_HAVE_NONSTD_BYTE 0 |
| 406 |
#endif |
| 407 |
|
| 408 |
// C++ feature usage: |
| 409 |
|
| 410 |
#if span_HAVE_ADDRESSOF |
| 411 |
# define span_ADDRESSOF(x) std::addressof(x) |
| 412 |
#else |
| 413 |
# define span_ADDRESSOF(x) (&x) |
| 414 |
#endif |
| 415 |
|
| 416 |
#if span_HAVE_CONSTEXPR_11 |
| 417 |
# define span_constexpr constexpr |
| 418 |
#else |
| 419 |
# define span_constexpr /*span_constexpr*/ |
| 420 |
#endif |
| 421 |
|
| 422 |
#if span_HAVE_CONSTEXPR_14 |
| 423 |
# define span_constexpr14 constexpr |
| 424 |
#else |
| 425 |
# define span_constexpr14 /*span_constexpr*/ |
| 426 |
#endif |
| 427 |
|
| 428 |
#if span_HAVE_EXPLICIT_CONVERSION |
| 429 |
# define span_explicit explicit |
| 430 |
#else |
| 431 |
# define span_explicit /*explicit*/ |
| 432 |
#endif |
| 433 |
|
| 434 |
#if span_HAVE_IS_DELETE |
| 435 |
# define span_is_delete = delete |
| 436 |
#else |
| 437 |
# define span_is_delete |
| 438 |
#endif |
| 439 |
|
| 440 |
#if span_HAVE_IS_DELETE |
| 441 |
# define span_is_delete_access public |
| 442 |
#else |
| 443 |
# define span_is_delete_access private |
| 444 |
#endif |
| 445 |
|
| 446 |
#if span_HAVE_NOEXCEPT && ! span_CONFIG_CONTRACT_VIOLATION_THROWS_V |
| 447 |
# define span_noexcept noexcept |
| 448 |
#else |
| 449 |
# define span_noexcept /*noexcept*/ |
| 450 |
#endif |
| 451 |
|
| 452 |
#if span_HAVE_NULLPTR |
| 453 |
# define span_nullptr nullptr |
| 454 |
#else |
| 455 |
# define span_nullptr NULL |
| 456 |
#endif |
| 457 |
|
| 458 |
#if span_HAVE_DEPRECATED |
| 459 |
# define span_deprecated(msg) [[deprecated(msg)]] |
| 460 |
#else |
| 461 |
# define span_deprecated(msg) /*[[deprecated]]*/ |
| 462 |
#endif |
| 463 |
|
| 464 |
#if span_HAVE_NODISCARD |
| 465 |
# define span_nodiscard [[nodiscard]] |
| 466 |
#else |
| 467 |
# define span_nodiscard /*[[nodiscard]]*/ |
| 468 |
#endif |
| 469 |
|
| 470 |
#if span_HAVE_NORETURN |
| 471 |
# define span_noreturn [[noreturn]] |
| 472 |
#else |
| 473 |
# define span_noreturn /*[[noreturn]]*/ |
| 474 |
#endif |
| 475 |
|
| 476 |
// Other features: |
| 477 |
|
| 478 |
#define span_HAVE_CONSTRAINED_SPAN_CONTAINER_CTOR span_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG |
| 479 |
#define span_HAVE_ITERATOR_CTOR span_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG |
| 480 |
|
| 481 |
// Additional includes: |
| 482 |
|
| 483 |
#if span_HAVE( ADDRESSOF ) |
| 484 |
# include <memory> |
| 485 |
#endif |
| 486 |
|
| 487 |
#if span_HAVE( ARRAY ) |
| 488 |
# include <array> |
| 489 |
#endif |
| 490 |
|
| 491 |
#if span_HAVE( BYTE ) |
| 492 |
# include <cstddef> |
| 493 |
#endif |
| 494 |
|
| 495 |
#if span_HAVE( DATA ) |
| 496 |
# include <iterator> // for std::data(), std::size() |
| 497 |
#endif |
| 498 |
|
| 499 |
#if span_HAVE( TYPE_TRAITS ) |
| 500 |
# include <type_traits> |
| 501 |
#endif |
| 502 |
|
| 503 |
#if ! span_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR ) |
| 504 |
# include <vector> |
| 505 |
#endif |
| 506 |
|
| 507 |
#if span_FEATURE( MEMBER_AT ) > 1 |
| 508 |
# include <cstdio> |
| 509 |
#endif |
| 510 |
|
| 511 |
#if ! span_CONFIG( NO_EXCEPTIONS ) |
| 512 |
# include <stdexcept> |
| 513 |
#endif |
| 514 |
|
| 515 |
#if span_CONFIG( CONTRACT_VIOLATION_TERMINATES ) |
| 516 |
# include <exception> |
| 517 |
#endif |
| 518 |
|
| 519 |
// Contract violation |
| 520 |
|
| 521 |
#define span_ELIDE_CONTRACT_EXPECTS ( 0 == ( span_CONFIG_CONTRACT_LEVEL_MASK & 0x01 ) ) |
| 522 |
#define span_ELIDE_CONTRACT_ENSURES ( 0 == ( span_CONFIG_CONTRACT_LEVEL_MASK & 0x10 ) ) |
| 523 |
|
| 524 |
#if span_ELIDE_CONTRACT_EXPECTS |
| 525 |
# define span_constexpr_exp span_constexpr |
| 526 |
# define span_EXPECTS( cond ) /* Expect elided */ |
| 527 |
#else |
| 528 |
# define span_constexpr_exp span_constexpr14 |
| 529 |
# define span_EXPECTS( cond ) span_CONTRACT_CHECK( "Precondition", cond ) |
| 530 |
#endif |
| 531 |
|
| 532 |
#if span_ELIDE_CONTRACT_ENSURES |
| 533 |
# define span_constexpr_ens span_constexpr |
| 534 |
# define span_ENSURES( cond ) /* Ensures elided */ |
| 535 |
#else |
| 536 |
# define span_constexpr_ens span_constexpr14 |
| 537 |
# define span_ENSURES( cond ) span_CONTRACT_CHECK( "Postcondition", cond ) |
| 538 |
#endif |
| 539 |
|
| 540 |
#define span_CONTRACT_CHECK( type, cond ) \ |
| 541 |
cond ? static_cast< void >( 0 ) \ |
| 542 |
: nonstd::span_lite::detail::report_contract_violation( span_LOCATION( __FILE__, __LINE__ ) ": " type " violation." ) |
| 543 |
|
| 544 |
#ifdef __GNUG__ |
| 545 |
# define span_LOCATION( file, line ) file ":" span_STRINGIFY( line ) |
| 546 |
#else |
| 547 |
# define span_LOCATION( file, line ) file "(" span_STRINGIFY( line ) ")" |
| 548 |
#endif |
| 549 |
|
| 550 |
// Method enabling |
| 551 |
|
| 552 |
#if span_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) |
| 553 |
|
| 554 |
#define span_REQUIRES_0(VA) \ |
| 555 |
template< bool B = (VA), typename std::enable_if<B, int>::type = 0 > |
| 556 |
|
| 557 |
# if span_BETWEEN( span_COMPILER_MSVC_VERSION, 1, 140 ) |
| 558 |
// VS 2013 and earlier seem to have trouble with SFINAE for default non-type arguments |
| 559 |
# define span_REQUIRES_T(VA) \ |
| 560 |
, typename = typename std::enable_if< ( VA ), nonstd::span_lite::detail::enabler >::type |
| 561 |
# else |
| 562 |
# define span_REQUIRES_T(VA) \ |
| 563 |
, typename std::enable_if< (VA), int >::type = 0 |
| 564 |
# endif |
| 565 |
|
| 566 |
#define span_REQUIRES_R(R, VA) \ |
| 567 |
typename std::enable_if< (VA), R>::type |
| 568 |
|
| 569 |
#define span_REQUIRES_A(VA) \ |
| 570 |
, typename std::enable_if< (VA), void*>::type = nullptr |
| 571 |
|
| 572 |
#else |
| 573 |
|
| 574 |
# define span_REQUIRES_0(VA) /*empty*/ |
| 575 |
# define span_REQUIRES_T(VA) /*empty*/ |
| 576 |
# define span_REQUIRES_R(R, VA) R |
| 577 |
# define span_REQUIRES_A(VA) /*empty*/ |
| 578 |
|
| 579 |
#endif |
| 580 |
|
| 581 |
namespace nonstd { |
| 582 |
namespace span_lite { |
| 583 |
|
| 584 |
// [views.constants], constants |
| 585 |
|
| 586 |
typedef span_CONFIG_EXTENT_TYPE extent_t; |
| 587 |
typedef span_CONFIG_SIZE_TYPE size_t; |
| 588 |
|
| 589 |
span_constexpr const extent_t dynamic_extent = static_cast<extent_t>( -1 ); |
| 590 |
|
| 591 |
template< class T, extent_t Extent = dynamic_extent > |
| 592 |
class span; |
| 593 |
|
| 594 |
// Tag to select span constructor taking a container (prevent ms-gsl warning C26426): |
| 595 |
|
| 596 |
struct with_container_t { span_constexpr with_container_t() span_noexcept {} }; |
| 597 |
const span_constexpr with_container_t with_container; |
| 598 |
|
| 599 |
// C++11 emulation: |
| 600 |
|
| 601 |
namespace std11 { |
| 602 |
|
| 603 |
#if span_HAVE( REMOVE_CONST ) |
| 604 |
|
| 605 |
using std::remove_cv; |
| 606 |
using std::remove_const; |
| 607 |
using std::remove_volatile; |
| 608 |
|
| 609 |
#else |
| 610 |
|
| 611 |
template< class T > struct remove_const { typedef T type; }; |
| 612 |
template< class T > struct remove_const< T const > { typedef T type; }; |
| 613 |
|
| 614 |
template< class T > struct remove_volatile { typedef T type; }; |
| 615 |
template< class T > struct remove_volatile< T volatile > { typedef T type; }; |
| 616 |
|
| 617 |
template< class T > |
| 618 |
struct remove_cv |
| 619 |
{ |
| 620 |
typedef typename std11::remove_volatile< typename std11::remove_const< T >::type >::type type; |
| 621 |
}; |
| 622 |
|
| 623 |
#endif // span_HAVE( REMOVE_CONST ) |
| 624 |
|
| 625 |
#if span_HAVE( TYPE_TRAITS ) |
| 626 |
|
| 627 |
using std::is_same; |
| 628 |
using std::is_signed; |
| 629 |
using std::integral_constant; |
| 630 |
using std::true_type; |
| 631 |
using std::false_type; |
| 632 |
using std::remove_reference; |
| 633 |
|
| 634 |
#else |
| 635 |
|
| 636 |
template< class T, T v > struct integral_constant { enum { value = v }; }; |
| 637 |
typedef integral_constant< bool, true > true_type; |
| 638 |
typedef integral_constant< bool, false > false_type; |
| 639 |
|
| 640 |
template< class T, class U > struct is_same : false_type{}; |
| 641 |
template< class T > struct is_same<T, T> : true_type{}; |
| 642 |
|
| 643 |
template< typename T > struct is_signed : false_type {}; |
| 644 |
template<> struct is_signed<signed char> : true_type {}; |
| 645 |
template<> struct is_signed<signed int > : true_type {}; |
| 646 |
template<> struct is_signed<signed long> : true_type {}; |
| 647 |
|
| 648 |
#endif |
| 649 |
|
| 650 |
} // namespace std11 |
| 651 |
|
| 652 |
// C++17 emulation: |
| 653 |
|
| 654 |
namespace std17 { |
| 655 |
|
| 656 |
template< bool v > struct bool_constant : std11::integral_constant<bool, v>{}; |
| 657 |
|
| 658 |
#if span_CPP11_120 |
| 659 |
|
| 660 |
template< class...> |
| 661 |
using void_t = void; |
| 662 |
|
| 663 |
#endif |
| 664 |
|
| 665 |
#if span_HAVE( DATA ) |
| 666 |
|
| 667 |
using std::data; |
| 668 |
using std::size; |
| 669 |
|
| 670 |
#elif span_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR ) |
| 671 |
|
| 672 |
template< typename T, std::size_t N > |
| 673 |
inline span_constexpr auto size( const T(&)[N] ) span_noexcept -> size_t |
| 674 |
{ |
| 675 |
return N; |
| 676 |
} |
| 677 |
|
| 678 |
template< typename C > |
| 679 |
inline span_constexpr auto size( C const & cont ) -> decltype( cont.size() ) |
| 680 |
{ |
| 681 |
return cont.size(); |
| 682 |
} |
| 683 |
|
| 684 |
template< typename T, std::size_t N > |
| 685 |
inline span_constexpr auto data( T(&arr)[N] ) span_noexcept -> T* |
| 686 |
{ |
| 687 |
return &arr[0]; |
| 688 |
} |
| 689 |
|
| 690 |
template< typename C > |
| 691 |
inline span_constexpr auto data( C & cont ) -> decltype( cont.data() ) |
| 692 |
{ |
| 693 |
return cont.data(); |
| 694 |
} |
| 695 |
|
| 696 |
template< typename C > |
| 697 |
inline span_constexpr auto data( C const & cont ) -> decltype( cont.data() ) |
| 698 |
{ |
| 699 |
return cont.data(); |
| 700 |
} |
| 701 |
|
| 702 |
template< typename E > |
| 703 |
inline span_constexpr auto data( std::initializer_list<E> il ) span_noexcept -> E const * |
| 704 |
{ |
| 705 |
return il.begin(); |
| 706 |
} |
| 707 |
|
| 708 |
#endif // span_HAVE( DATA ) |
| 709 |
|
| 710 |
#if span_HAVE( BYTE ) |
| 711 |
using std::byte; |
| 712 |
#elif span_HAVE( NONSTD_BYTE ) |
| 713 |
using nonstd::byte; |
| 714 |
#endif |
| 715 |
|
| 716 |
} // namespace std17 |
| 717 |
|
| 718 |
// C++20 emulation: |
| 719 |
|
| 720 |
namespace std20 { |
| 721 |
|
| 722 |
#if span_HAVE( DEDUCTION_GUIDES ) |
| 723 |
template< class T > |
| 724 |
using iter_reference_t = decltype( *std::declval<T&>() ); |
| 725 |
#endif |
| 726 |
|
| 727 |
} // namespace std20 |
| 728 |
|
| 729 |
// Implementation details: |
| 730 |
|
| 731 |
namespace detail { |
| 732 |
|
| 733 |
/*enum*/ struct enabler{}; |
| 734 |
|
| 735 |
template< typename T > |
| 736 |
span_constexpr bool is_positive( T x ) |
| 737 |
{ |
| 738 |
return std11::is_signed<T>::value ? x >= 0 : true; |
| 739 |
} |
| 740 |
|
| 741 |
#if span_HAVE( TYPE_TRAITS ) |
| 742 |
|
| 743 |
template< class Q > |
| 744 |
struct is_span_oracle : std::false_type{}; |
| 745 |
|
| 746 |
template< class T, span_CONFIG_EXTENT_TYPE Extent > |
| 747 |
struct is_span_oracle< span<T, Extent> > : std::true_type{}; |
| 748 |
|
| 749 |
template< class Q > |
| 750 |
struct is_span : is_span_oracle< typename std::remove_cv<Q>::type >{}; |
| 751 |
|
| 752 |
template< class Q > |
| 753 |
struct is_std_array_oracle : std::false_type{}; |
| 754 |
|
| 755 |
#if span_HAVE( ARRAY ) |
| 756 |
|
| 757 |
template< class T, std::size_t Extent > |
| 758 |
struct is_std_array_oracle< std::array<T, Extent> > : std::true_type{}; |
| 759 |
|
| 760 |
#endif |
| 761 |
|
| 762 |
template< class Q > |
| 763 |
struct is_std_array : is_std_array_oracle< typename std::remove_cv<Q>::type >{}; |
| 764 |
|
| 765 |
template< class Q > |
| 766 |
struct is_array : std::false_type {}; |
| 767 |
|
| 768 |
template< class T > |
| 769 |
struct is_array<T[]> : std::true_type {}; |
| 770 |
|
| 771 |
template< class T, std::size_t N > |
| 772 |
struct is_array<T[N]> : std::true_type {}; |
| 773 |
|
| 774 |
#if span_CPP11_140 && ! span_BETWEEN( span_COMPILER_GNUC_VERSION, 1, 500 ) |
| 775 |
|
| 776 |
template< class, class = void > |
| 777 |
struct has_size_and_data : std::false_type{}; |
| 778 |
|
| 779 |
template< class C > |
| 780 |
struct has_size_and_data |
| 781 |
< |
| 782 |
C, std17::void_t< |
| 783 |
decltype( std17::size(std::declval<C>()) ), |
| 784 |
decltype( std17::data(std::declval<C>()) ) > |
| 785 |
> : std::true_type{}; |
| 786 |
|
| 787 |
template< class, class, class = void > |
| 788 |
struct is_compatible_element : std::false_type {}; |
| 789 |
|
| 790 |
template< class C, class E > |
| 791 |
struct is_compatible_element |
| 792 |
< |
| 793 |
C, E, std17::void_t< |
| 794 |
decltype( std17::data(std::declval<C>()) ) > |
| 795 |
> : std::is_convertible< typename std::remove_pointer<decltype( std17::data( std::declval<C&>() ) )>::type(*)[], E(*)[] >{}; |
| 796 |
|
| 797 |
template< class C > |
| 798 |
struct is_container : std17::bool_constant |
| 799 |
< |
| 800 |
! is_span< C >::value |
| 801 |
&& ! is_array< C >::value |
| 802 |
&& ! is_std_array< C >::value |
| 803 |
&& has_size_and_data< C >::value |
| 804 |
>{}; |
| 805 |
|
| 806 |
template< class C, class E > |
| 807 |
struct is_compatible_container : std17::bool_constant |
| 808 |
< |
| 809 |
is_container<C>::value |
| 810 |
&& is_compatible_element<C,E>::value |
| 811 |
>{}; |
| 812 |
|
| 813 |
#else // span_CPP11_140 |
| 814 |
|
| 815 |
template< |
| 816 |
class C, class E |
| 817 |
span_REQUIRES_T(( |
| 818 |
! is_span< C >::value |
| 819 |
&& ! is_array< C >::value |
| 820 |
&& ! is_std_array< C >::value |
| 821 |
&& ( std::is_convertible< typename std::remove_pointer<decltype( std17::data( std::declval<C&>() ) )>::type(*)[], E(*)[] >::value) |
| 822 |
// && has_size_and_data< C >::value |
| 823 |
)) |
| 824 |
, class = decltype( std17::size(std::declval<C>()) ) |
| 825 |
, class = decltype( std17::data(std::declval<C>()) ) |
| 826 |
> |
| 827 |
struct is_compatible_container : std::true_type{}; |
| 828 |
|
| 829 |
#endif // span_CPP11_140 |
| 830 |
|
| 831 |
#endif // span_HAVE( TYPE_TRAITS ) |
| 832 |
|
| 833 |
#if ! span_CONFIG( NO_EXCEPTIONS ) |
| 834 |
#if span_FEATURE( MEMBER_AT ) > 1 |
| 835 |
|
| 836 |
// format index and size: |
| 837 |
|
| 838 |
#if defined(__clang__) |
| 839 |
# pragma clang diagnostic ignored "-Wlong-long" |
| 840 |
#elif defined __GNUC__ |
| 841 |
# pragma GCC diagnostic ignored "-Wformat=ll" |
| 842 |
# pragma GCC diagnostic ignored "-Wlong-long" |
| 843 |
#endif |
| 844 |
|
| 845 |
span_noreturn inline void throw_out_of_range( size_t idx, size_t size ) |
| 846 |
{ |
| 847 |
const char fmt[] = "span::at(): index '%lli' is out of range [0..%lli)"; |
| 848 |
char buffer[ 2 * 20 + sizeof fmt ]; |
| 849 |
sprintf( buffer, fmt, static_cast<long long>(idx), static_cast<long long>(size) ); |
| 850 |
|
| 851 |
throw std::out_of_range( buffer ); |
| 852 |
} |
| 853 |
|
| 854 |
#else // MEMBER_AT |
| 855 |
|
| 856 |
span_noreturn inline void throw_out_of_range( size_t /*idx*/, size_t /*size*/ ) |
| 857 |
{ |
| 858 |
throw std::out_of_range( "span::at(): index outside span" ); |
| 859 |
} |
| 860 |
#endif // MEMBER_AT |
| 861 |
#endif // NO_EXCEPTIONS |
| 862 |
|
| 863 |
#if span_CONFIG( CONTRACT_VIOLATION_THROWS_V ) |
| 864 |
|
| 865 |
struct contract_violation : std::logic_error |
| 866 |
{ |
| 867 |
explicit contract_violation( char const * const message ) |
| 868 |
: std::logic_error( message ) |
| 869 |
{} |
| 870 |
}; |
| 871 |
|
| 872 |
inline void report_contract_violation( char const * msg ) |
| 873 |
{ |
| 874 |
throw contract_violation( msg ); |
| 875 |
} |
| 876 |
|
| 877 |
#else // span_CONFIG( CONTRACT_VIOLATION_THROWS_V ) |
| 878 |
|
| 879 |
span_noreturn inline void report_contract_violation( char const * /*msg*/ ) span_noexcept |
| 880 |
{ |
| 881 |
std::terminate(); |
| 882 |
} |
| 883 |
|
| 884 |
#endif // span_CONFIG( CONTRACT_VIOLATION_THROWS_V ) |
| 885 |
|
| 886 |
} // namespace detail |
| 887 |
|
| 888 |
// Prevent signed-unsigned mismatch: |
| 889 |
|
| 890 |
#define span_sizeof(T) static_cast<extent_t>( sizeof(T) ) |
| 891 |
|
| 892 |
template< class T > |
| 893 |
inline span_constexpr size_t to_size( T size ) |
| 894 |
{ |
| 895 |
return static_cast<size_t>( size ); |
| 896 |
} |
| 897 |
|
| 898 |
// |
| 899 |
// [views.span] - A view over a contiguous, single-dimension sequence of objects |
| 900 |
// |
| 901 |
template< class T, extent_t Extent /*= dynamic_extent*/ > |
| 902 |
class span |
| 903 |
{ |
| 904 |
public: |
| 905 |
// constants and types |
| 906 |
|
| 907 |
typedef T element_type; |
| 908 |
typedef typename std11::remove_cv< T >::type value_type; |
| 909 |
|
| 910 |
typedef T & reference; |
| 911 |
typedef T * pointer; |
| 912 |
typedef T const * const_pointer; |
| 913 |
typedef T const & const_reference; |
| 914 |
|
| 915 |
typedef size_t size_type; |
| 916 |
typedef extent_t extent_type; |
| 917 |
|
| 918 |
typedef pointer iterator; |
| 919 |
typedef const_pointer const_iterator; |
| 920 |
|
| 921 |
typedef std::ptrdiff_t difference_type; |
| 922 |
|
| 923 |
typedef std::reverse_iterator< iterator > reverse_iterator; |
| 924 |
typedef std::reverse_iterator< const_iterator > const_reverse_iterator; |
| 925 |
|
| 926 |
// static constexpr extent_type extent = Extent; |
| 927 |
enum { extent = Extent }; |
| 928 |
|
| 929 |
// 26.7.3.2 Constructors, copy, and assignment [span.cons] |
| 930 |
|
| 931 |
span_REQUIRES_0( |
| 932 |
( Extent == 0 ) || |
| 933 |
( Extent == dynamic_extent ) |
| 934 |
) |
| 935 |
span_constexpr span() span_noexcept |
| 936 |
: data_( span_nullptr ) |
| 937 |
, size_( 0 ) |
| 938 |
{ |
| 939 |
// span_EXPECTS( data() == span_nullptr ); |
| 940 |
// span_EXPECTS( size() == 0 ); |
| 941 |
} |
| 942 |
|
| 943 |
#if span_HAVE( ITERATOR_CTOR ) |
| 944 |
// Didn't yet succeed in combining the next two constructors: |
| 945 |
|
| 946 |
span_constexpr_exp span( std::nullptr_t, size_type count ) |
| 947 |
: data_( span_nullptr ) |
| 948 |
, size_( count ) |
| 949 |
{ |
| 950 |
span_EXPECTS( data_ == span_nullptr && count == 0 ); |
| 951 |
} |
| 952 |
|
| 953 |
template< typename It |
| 954 |
span_REQUIRES_T(( |
| 955 |
std::is_convertible<decltype(*std::declval<It&>()), element_type &>::value |
| 956 |
)) |
| 957 |
> |
| 958 |
span_constexpr_exp span( It first, size_type count ) |
| 959 |
: data_( to_address( first ) ) |
| 960 |
, size_( count ) |
| 961 |
{ |
| 962 |
span_EXPECTS( |
| 963 |
( data_ == span_nullptr && count == 0 ) || |
| 964 |
( data_ != span_nullptr && detail::is_positive( count ) ) |
| 965 |
); |
| 966 |
} |
| 967 |
#else |
| 968 |
span_constexpr_exp span( pointer ptr, size_type count ) |
| 969 |
: data_( ptr ) |
| 970 |
, size_( count ) |
| 971 |
{ |
| 972 |
span_EXPECTS( |
| 973 |
( ptr == span_nullptr && count == 0 ) || |
| 974 |
( ptr != span_nullptr && detail::is_positive( count ) ) |
| 975 |
); |
| 976 |
} |
| 977 |
#endif |
| 978 |
|
| 979 |
#if span_HAVE( ITERATOR_CTOR ) |
| 980 |
template< typename It, typename End |
| 981 |
span_REQUIRES_T(( |
| 982 |
std::is_convertible<decltype(&*std::declval<It&>()), element_type *>::value |
| 983 |
&& ! std::is_convertible<End, std::size_t>::value |
| 984 |
)) |
| 985 |
> |
| 986 |
span_constexpr_exp span( It first, End last ) |
| 987 |
: data_( to_address( first ) ) |
| 988 |
, size_( to_size( last - first ) ) |
| 989 |
{ |
| 990 |
span_EXPECTS( |
| 991 |
last - first >= 0 |
| 992 |
); |
| 993 |
} |
| 994 |
#else |
| 995 |
span_constexpr_exp span( pointer first, pointer last ) |
| 996 |
: data_( first ) |
| 997 |
, size_( to_size( last - first ) ) |
| 998 |
{ |
| 999 |
span_EXPECTS( |
| 1000 |
last - first >= 0 |
| 1001 |
); |
| 1002 |
} |
| 1003 |
#endif |
| 1004 |
|
| 1005 |
template< std::size_t N |
| 1006 |
span_REQUIRES_T(( |
| 1007 |
(Extent == dynamic_extent || Extent == static_cast<extent_t>(N)) |
| 1008 |
&& std::is_convertible< value_type(*)[], element_type(*)[] >::value |
| 1009 |
)) |
| 1010 |
> |
| 1011 |
span_constexpr span( element_type ( &arr )[ N ] ) span_noexcept |
| 1012 |
: data_( span_ADDRESSOF( arr[0] ) ) |
| 1013 |
, size_( N ) |
| 1014 |
{} |
| 1015 |
|
| 1016 |
#if span_HAVE( ARRAY ) |
| 1017 |
|
| 1018 |
template< std::size_t N |
| 1019 |
span_REQUIRES_T(( |
| 1020 |
(Extent == dynamic_extent || Extent == static_cast<extent_t>(N)) |
| 1021 |
&& std::is_convertible< value_type(*)[], element_type(*)[] >::value |
| 1022 |
)) |
| 1023 |
> |
| 1024 |
# if span_FEATURE( CONSTRUCTION_FROM_STDARRAY_ELEMENT_TYPE ) |
| 1025 |
span_constexpr span( std::array< element_type, N > & arr ) span_noexcept |
| 1026 |
# else |
| 1027 |
span_constexpr span( std::array< value_type, N > & arr ) span_noexcept |
| 1028 |
# endif |
| 1029 |
: data_( arr.data() ) |
| 1030 |
, size_( to_size( arr.size() ) ) |
| 1031 |
{} |
| 1032 |
|
| 1033 |
template< std::size_t N |
| 1034 |
# if span_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) |
| 1035 |
span_REQUIRES_T(( |
| 1036 |
(Extent == dynamic_extent || Extent == static_cast<extent_t>(N)) |
| 1037 |
&& std::is_convertible< value_type(*)[], element_type(*)[] >::value |
| 1038 |
)) |
| 1039 |
# endif |
| 1040 |
> |
| 1041 |
span_constexpr span( std::array< value_type, N> const & arr ) span_noexcept |
| 1042 |
: data_( arr.data() ) |
| 1043 |
, size_( to_size( arr.size() ) ) |
| 1044 |
{} |
| 1045 |
|
| 1046 |
#endif // span_HAVE( ARRAY ) |
| 1047 |
|
| 1048 |
#if span_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR ) |
| 1049 |
template< class Container |
| 1050 |
span_REQUIRES_T(( |
| 1051 |
detail::is_compatible_container< Container, element_type >::value |
| 1052 |
)) |
| 1053 |
> |
| 1054 |
span_constexpr span( Container & cont ) |
| 1055 |
: data_( std17::data( cont ) ) |
| 1056 |
, size_( to_size( std17::size( cont ) ) ) |
| 1057 |
{} |
| 1058 |
|
| 1059 |
template< class Container |
| 1060 |
span_REQUIRES_T(( |
| 1061 |
std::is_const< element_type >::value |
| 1062 |
&& detail::is_compatible_container< Container, element_type >::value |
| 1063 |
)) |
| 1064 |
> |
| 1065 |
span_constexpr span( Container const & cont ) |
| 1066 |
: data_( std17::data( cont ) ) |
| 1067 |
, size_( to_size( std17::size( cont ) ) ) |
| 1068 |
{} |
| 1069 |
|
| 1070 |
#endif // span_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR ) |
| 1071 |
|
| 1072 |
#if span_FEATURE( WITH_CONTAINER ) |
| 1073 |
|
| 1074 |
template< class Container > |
| 1075 |
span_constexpr span( with_container_t, Container & cont ) |
| 1076 |
: data_( cont.size() == 0 ? span_nullptr : span_ADDRESSOF( cont[0] ) ) |
| 1077 |
, size_( to_size( cont.size() ) ) |
| 1078 |
{} |
| 1079 |
|
| 1080 |
template< class Container > |
| 1081 |
span_constexpr span( with_container_t, Container const & cont ) |
| 1082 |
: data_( cont.size() == 0 ? span_nullptr : const_cast<pointer>( span_ADDRESSOF( cont[0] ) ) ) |
| 1083 |
, size_( to_size( cont.size() ) ) |
| 1084 |
{} |
| 1085 |
#endif |
| 1086 |
|
| 1087 |
#if span_FEATURE( WITH_INITIALIZER_LIST_P2447 ) && span_HAVE( INITIALIZER_LIST ) |
| 1088 |
|
| 1089 |
// constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il) noexcept; |
| 1090 |
|
| 1091 |
#if !span_BETWEEN( span_COMPILER_MSVC_VERSION, 120, 130 ) |
| 1092 |
|
| 1093 |
template< extent_t U = Extent |
| 1094 |
span_REQUIRES_T(( |
| 1095 |
U != dynamic_extent |
| 1096 |
)) |
| 1097 |
> |
| 1098 |
#if span_COMPILER_GNUC_VERSION >= 900 // prevent GCC's "-Winit-list-lifetime" |
| 1099 |
span_constexpr14 explicit span( std::initializer_list<value_type> il ) span_noexcept |
| 1100 |
{ |
| 1101 |
data_ = il.begin(); |
| 1102 |
size_ = il.size(); |
| 1103 |
} |
| 1104 |
#else |
| 1105 |
span_constexpr explicit span( std::initializer_list<value_type> il ) span_noexcept |
| 1106 |
: data_( il.begin() ) |
| 1107 |
, size_( il.size() ) |
| 1108 |
{} |
| 1109 |
#endif |
| 1110 |
|
| 1111 |
#endif // MSVC 120 (VS2013) |
| 1112 |
|
| 1113 |
template< extent_t U = Extent |
| 1114 |
span_REQUIRES_T(( |
| 1115 |
U == dynamic_extent |
| 1116 |
)) |
| 1117 |
> |
| 1118 |
#if span_COMPILER_GNUC_VERSION >= 900 // prevent GCC's "-Winit-list-lifetime" |
| 1119 |
span_constexpr14 /*explicit*/ span( std::initializer_list<value_type> il ) span_noexcept |
| 1120 |
{ |
| 1121 |
data_ = il.begin(); |
| 1122 |
size_ = il.size(); |
| 1123 |
} |
| 1124 |
#else |
| 1125 |
span_constexpr /*explicit*/ span( std::initializer_list<value_type> il ) span_noexcept |
| 1126 |
: data_( il.begin() ) |
| 1127 |
, size_( il.size() ) |
| 1128 |
{} |
| 1129 |
#endif |
| 1130 |
|
| 1131 |
#endif // P2447 |
| 1132 |
|
| 1133 |
#if span_HAVE( IS_DEFAULT ) |
| 1134 |
span_constexpr span( span const & other ) span_noexcept = default; |
| 1135 |
|
| 1136 |
~span() span_noexcept = default; |
| 1137 |
|
| 1138 |
span_constexpr14 span & operator=( span const & other ) span_noexcept = default; |
| 1139 |
#else |
| 1140 |
span_constexpr span( span const & other ) span_noexcept |
| 1141 |
: data_( other.data_ ) |
| 1142 |
, size_( other.size_ ) |
| 1143 |
{} |
| 1144 |
|
| 1145 |
~span() span_noexcept |
| 1146 |
{} |
| 1147 |
|
| 1148 |
span_constexpr14 span & operator=( span const & other ) span_noexcept |
| 1149 |
{ |
| 1150 |
data_ = other.data_; |
| 1151 |
size_ = other.size_; |
| 1152 |
|
| 1153 |
return *this; |
| 1154 |
} |
| 1155 |
#endif |
| 1156 |
|
| 1157 |
template< class OtherElementType, extent_type OtherExtent |
| 1158 |
span_REQUIRES_T(( |
| 1159 |
(Extent == dynamic_extent || OtherExtent == dynamic_extent || Extent == OtherExtent) |
| 1160 |
&& std::is_convertible<OtherElementType(*)[], element_type(*)[]>::value |
| 1161 |
)) |
| 1162 |
> |
| 1163 |
span_constexpr_exp span( span<OtherElementType, OtherExtent> const & other ) span_noexcept |
| 1164 |
: data_( other.data() ) |
| 1165 |
, size_( other.size() ) |
| 1166 |
{ |
| 1167 |
span_EXPECTS( (Extent == dynamic_extent) || (Extent != dynamic_extent && other.size() == to_size(Extent)) ); |
| 1168 |
} |
| 1169 |
|
| 1170 |
// 26.7.3.3 Subviews [span.sub] |
| 1171 |
|
| 1172 |
template< extent_type Count > |
| 1173 |
span_constexpr_exp span< element_type, Count > |
| 1174 |
first() const |
| 1175 |
{ |
| 1176 |
span_EXPECTS( detail::is_positive( Count ) && Count <= size() ); |
| 1177 |
|
| 1178 |
return span< element_type, Count >( data(), Count ); |
| 1179 |
} |
| 1180 |
|
| 1181 |
template< extent_type Count > |
| 1182 |
span_constexpr_exp span< element_type, Count > |
| 1183 |
last() const |
| 1184 |
{ |
| 1185 |
span_EXPECTS( detail::is_positive( Count ) && Count <= size() ); |
| 1186 |
|
| 1187 |
return span< element_type, Count >( data() + (size() - Count), Count ); |
| 1188 |
} |
| 1189 |
|
| 1190 |
#if span_HAVE( DEFAULT_FUNCTION_TEMPLATE_ARG ) |
| 1191 |
template< size_type Offset, extent_type Count = dynamic_extent > |
| 1192 |
#else |
| 1193 |
template< size_type Offset, extent_type Count /*= dynamic_extent*/ > |
| 1194 |
#endif |
| 1195 |
span_constexpr_exp span< element_type, Count > |
| 1196 |
subspan() const |
| 1197 |
{ |
| 1198 |
span_EXPECTS( |
| 1199 |
( detail::is_positive( Offset ) && Offset <= size() ) && |
| 1200 |
( Count == dynamic_extent || (detail::is_positive( Count ) && Count + Offset <= size()) ) |
| 1201 |
); |
| 1202 |
|
| 1203 |
return span< element_type, Count >( |
| 1204 |
data() + Offset, Count != dynamic_extent ? Count : (Extent != dynamic_extent ? Extent - Offset : size() - Offset) ); |
| 1205 |
} |
| 1206 |
|
| 1207 |
span_constexpr_exp span< element_type, dynamic_extent > |
| 1208 |
first( size_type count ) const |
| 1209 |
{ |
| 1210 |
span_EXPECTS( detail::is_positive( count ) && count <= size() ); |
| 1211 |
|
| 1212 |
return span< element_type, dynamic_extent >( data(), count ); |
| 1213 |
} |
| 1214 |
|
| 1215 |
span_constexpr_exp span< element_type, dynamic_extent > |
| 1216 |
last( size_type count ) const |
| 1217 |
{ |
| 1218 |
span_EXPECTS( detail::is_positive( count ) && count <= size() ); |
| 1219 |
|
| 1220 |
return span< element_type, dynamic_extent >( data() + ( size() - count ), count ); |
| 1221 |
} |
| 1222 |
|
| 1223 |
span_constexpr_exp span< element_type, dynamic_extent > |
| 1224 |
subspan( size_type offset, size_type count = static_cast<size_type>(dynamic_extent) ) const |
| 1225 |
{ |
| 1226 |
span_EXPECTS( |
| 1227 |
( ( detail::is_positive( offset ) && offset <= size() ) ) && |
| 1228 |
( count == static_cast<size_type>(dynamic_extent) || ( detail::is_positive( count ) && offset + count <= size() ) ) |
| 1229 |
); |
| 1230 |
|
| 1231 |
return span< element_type, dynamic_extent >( |
| 1232 |
data() + offset, count == static_cast<size_type>(dynamic_extent) ? size() - offset : count ); |
| 1233 |
} |
| 1234 |
|
| 1235 |
// 26.7.3.4 Observers [span.obs] |
| 1236 |
|
| 1237 |
span_constexpr size_type size() const span_noexcept |
| 1238 |
{ |
| 1239 |
return size_; |
| 1240 |
} |
| 1241 |
|
| 1242 |
span_constexpr std::ptrdiff_t ssize() const span_noexcept |
| 1243 |
{ |
| 1244 |
return static_cast<std::ptrdiff_t>( size_ ); |
| 1245 |
} |
| 1246 |
|
| 1247 |
span_constexpr size_type size_bytes() const span_noexcept |
| 1248 |
{ |
| 1249 |
return size() * to_size( sizeof( element_type ) ); |
| 1250 |
} |
| 1251 |
|
| 1252 |
span_nodiscard span_constexpr bool empty() const span_noexcept |
| 1253 |
{ |
| 1254 |
return size() == 0; |
| 1255 |
} |
| 1256 |
|
| 1257 |
// 26.7.3.5 Element access [span.elem] |
| 1258 |
|
| 1259 |
span_constexpr_exp reference operator[]( size_type idx ) const |
| 1260 |
{ |
| 1261 |
span_EXPECTS( detail::is_positive( idx ) && idx < size() ); |
| 1262 |
|
| 1263 |
return *( data() + idx ); |
| 1264 |
} |
| 1265 |
|
| 1266 |
#if span_FEATURE( MEMBER_CALL_OPERATOR ) |
| 1267 |
span_deprecated("replace operator() with operator[]") |
| 1268 |
|
| 1269 |
span_constexpr_exp reference operator()( size_type idx ) const |
| 1270 |
{ |
| 1271 |
span_EXPECTS( detail::is_positive( idx ) && idx < size() ); |
| 1272 |
|
| 1273 |
return *( data() + idx ); |
| 1274 |
} |
| 1275 |
#endif |
| 1276 |
|
| 1277 |
#if span_FEATURE( MEMBER_AT ) |
| 1278 |
span_constexpr14 reference at( size_type idx ) const |
| 1279 |
{ |
| 1280 |
#if span_CONFIG( NO_EXCEPTIONS ) |
| 1281 |
return this->operator[]( idx ); |
| 1282 |
#else |
| 1283 |
if ( !detail::is_positive( idx ) || size() <= idx ) |
| 1284 |
{ |
| 1285 |
detail::throw_out_of_range( idx, size() ); |
| 1286 |
} |
| 1287 |
return *( data() + idx ); |
| 1288 |
#endif |
| 1289 |
} |
| 1290 |
#endif |
| 1291 |
|
| 1292 |
span_constexpr pointer data() const span_noexcept |
| 1293 |
{ |
| 1294 |
return data_; |
| 1295 |
} |
| 1296 |
|
| 1297 |
#if span_FEATURE( MEMBER_BACK_FRONT ) |
| 1298 |
|
| 1299 |
span_constexpr_exp reference front() const span_noexcept |
| 1300 |
{ |
| 1301 |
span_EXPECTS( ! empty() ); |
| 1302 |
|
| 1303 |
return *data(); |
| 1304 |
} |
| 1305 |
|
| 1306 |
span_constexpr_exp reference back() const span_noexcept |
| 1307 |
{ |
| 1308 |
span_EXPECTS( ! empty() ); |
| 1309 |
|
| 1310 |
return *( data() + size() - 1 ); |
| 1311 |
} |
| 1312 |
|
| 1313 |
#endif |
| 1314 |
|
| 1315 |
// xx.x.x.x Modifiers [span.modifiers] |
| 1316 |
|
| 1317 |
#if span_FEATURE( MEMBER_SWAP ) |
| 1318 |
|
| 1319 |
span_constexpr14 void swap( span & other ) span_noexcept |
| 1320 |
{ |
| 1321 |
using std::swap; |
| 1322 |
swap( data_, other.data_ ); |
| 1323 |
swap( size_, other.size_ ); |
| 1324 |
} |
| 1325 |
#endif |
| 1326 |
|
| 1327 |
// 26.7.3.6 Iterator support [span.iterators] |
| 1328 |
|
| 1329 |
span_constexpr iterator begin() const span_noexcept |
| 1330 |
{ |
| 1331 |
#if span_CPP11_OR_GREATER |
| 1332 |
return { data() }; |
| 1333 |
#else |
| 1334 |
return iterator( data() ); |
| 1335 |
#endif |
| 1336 |
} |
| 1337 |
|
| 1338 |
span_constexpr iterator end() const span_noexcept |
| 1339 |
{ |
| 1340 |
#if span_CPP11_OR_GREATER |
| 1341 |
return { data() + size() }; |
| 1342 |
#else |
| 1343 |
return iterator( data() + size() ); |
| 1344 |
#endif |
| 1345 |
} |
| 1346 |
|
| 1347 |
span_constexpr const_iterator cbegin() const span_noexcept |
| 1348 |
{ |
| 1349 |
#if span_CPP11_OR_GREATER |
| 1350 |
return { data() }; |
| 1351 |
#else |
| 1352 |
return const_iterator( data() ); |
| 1353 |
#endif |
| 1354 |
} |
| 1355 |
|
| 1356 |
span_constexpr const_iterator cend() const span_noexcept |
| 1357 |
{ |
| 1358 |
#if span_CPP11_OR_GREATER |
| 1359 |
return { data() + size() }; |
| 1360 |
#else |
| 1361 |
return const_iterator( data() + size() ); |
| 1362 |
#endif |
| 1363 |
} |
| 1364 |
|
| 1365 |
span_constexpr reverse_iterator rbegin() const span_noexcept |
| 1366 |
{ |
| 1367 |
return reverse_iterator( end() ); |
| 1368 |
} |
| 1369 |
|
| 1370 |
span_constexpr reverse_iterator rend() const span_noexcept |
| 1371 |
{ |
| 1372 |
return reverse_iterator( begin() ); |
| 1373 |
} |
| 1374 |
|
| 1375 |
span_constexpr const_reverse_iterator crbegin() const span_noexcept |
| 1376 |
{ |
| 1377 |
return const_reverse_iterator ( cend() ); |
| 1378 |
} |
| 1379 |
|
| 1380 |
span_constexpr const_reverse_iterator crend() const span_noexcept |
| 1381 |
{ |
| 1382 |
return const_reverse_iterator( cbegin() ); |
| 1383 |
} |
| 1384 |
|
| 1385 |
private: |
| 1386 |
|
| 1387 |
// Note: C++20 has std::pointer_traits<Ptr>::to_address( it ); |
| 1388 |
|
| 1389 |
#if span_HAVE( ITERATOR_CTOR ) |
| 1390 |
static inline span_constexpr pointer to_address( std::nullptr_t ) span_noexcept |
| 1391 |
{ |
| 1392 |
return nullptr; |
| 1393 |
} |
| 1394 |
|
| 1395 |
template< typename U > |
| 1396 |
static inline span_constexpr U * to_address( U * p ) span_noexcept |
| 1397 |
{ |
| 1398 |
return p; |
| 1399 |
} |
| 1400 |
|
| 1401 |
template< typename Ptr |
| 1402 |
span_REQUIRES_T(( ! std::is_pointer<Ptr>::value )) |
| 1403 |
> |
| 1404 |
static inline span_constexpr pointer to_address( Ptr const & it ) span_noexcept |
| 1405 |
{ |
| 1406 |
return to_address( it.operator->() ); |
| 1407 |
} |
| 1408 |
#endif // span_HAVE( ITERATOR_CTOR ) |
| 1409 |
|
| 1410 |
private: |
| 1411 |
pointer data_; |
| 1412 |
size_type size_; |
| 1413 |
}; |
| 1414 |
|
| 1415 |
// class template argument deduction guides: |
| 1416 |
|
| 1417 |
#if span_HAVE( DEDUCTION_GUIDES ) |
| 1418 |
|
| 1419 |
template< class T, size_t N > |
| 1420 |
span( T (&)[N] ) -> span<T, static_cast<extent_t>(N)>; |
| 1421 |
|
| 1422 |
template< class T, size_t N > |
| 1423 |
span( std::array<T, N> & ) -> span<T, static_cast<extent_t>(N)>; |
| 1424 |
|
| 1425 |
template< class T, size_t N > |
| 1426 |
span( std::array<T, N> const & ) -> span<const T, static_cast<extent_t>(N)>; |
| 1427 |
|
| 1428 |
#if span_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR ) |
| 1429 |
|
| 1430 |
template< class Container > |
| 1431 |
span( Container& ) -> span<typename Container::value_type>; |
| 1432 |
|
| 1433 |
template< class Container > |
| 1434 |
span( Container const & ) -> span<const typename Container::value_type>; |
| 1435 |
|
| 1436 |
#endif |
| 1437 |
|
| 1438 |
// iterator: constraints: It satisfies contiguous_Âiterator. |
| 1439 |
|
| 1440 |
template< class It, class EndOrSize > |
| 1441 |
span( It, EndOrSize ) -> span< typename std11::remove_reference< typename std20::iter_reference_t<It> >::type >; |
| 1442 |
|
| 1443 |
#endif // span_HAVE( DEDUCTION_GUIDES ) |
| 1444 |
|
| 1445 |
// 26.7.3.7 Comparison operators [span.comparison] |
| 1446 |
|
| 1447 |
#if span_FEATURE( COMPARISON ) |
| 1448 |
#if span_FEATURE( SAME ) |
| 1449 |
|
| 1450 |
template< class T1, extent_t E1, class T2, extent_t E2 > |
| 1451 |
inline span_constexpr bool same( span<T1,E1> const & l, span<T2,E2> const & r ) span_noexcept |
| 1452 |
{ |
| 1453 |
return std11::is_same<T1, T2>::value |
| 1454 |
&& l.size() == r.size() |
| 1455 |
&& static_cast<void const*>( l.data() ) == r.data(); |
| 1456 |
} |
| 1457 |
|
| 1458 |
#endif |
| 1459 |
|
| 1460 |
template< class T1, extent_t E1, class T2, extent_t E2 > |
| 1461 |
inline span_constexpr bool operator==( span<T1,E1> const & l, span<T2,E2> const & r ) |
| 1462 |
{ |
| 1463 |
return |
| 1464 |
#if span_FEATURE( SAME ) |
| 1465 |
same( l, r ) || |
| 1466 |
#endif |
| 1467 |
( l.size() == r.size() && std::equal( l.begin(), l.end(), r.begin() ) ); |
| 1468 |
} |
| 1469 |
|
| 1470 |
template< class T1, extent_t E1, class T2, extent_t E2 > |
| 1471 |
inline span_constexpr bool operator<( span<T1,E1> const & l, span<T2,E2> const & r ) |
| 1472 |
{ |
| 1473 |
return std::lexicographical_compare( l.begin(), l.end(), r.begin(), r.end() ); |
| 1474 |
} |
| 1475 |
|
| 1476 |
template< class T1, extent_t E1, class T2, extent_t E2 > |
| 1477 |
inline span_constexpr bool operator!=( span<T1,E1> const & l, span<T2,E2> const & r ) |
| 1478 |
{ |
| 1479 |
return !( l == r ); |
| 1480 |
} |
| 1481 |
|
| 1482 |
template< class T1, extent_t E1, class T2, extent_t E2 > |
| 1483 |
inline span_constexpr bool operator<=( span<T1,E1> const & l, span<T2,E2> const & r ) |
| 1484 |
{ |
| 1485 |
return !( r < l ); |
| 1486 |
} |
| 1487 |
|
| 1488 |
template< class T1, extent_t E1, class T2, extent_t E2 > |
| 1489 |
inline span_constexpr bool operator>( span<T1,E1> const & l, span<T2,E2> const & r ) |
| 1490 |
{ |
| 1491 |
return ( r < l ); |
| 1492 |
} |
| 1493 |
|
| 1494 |
template< class T1, extent_t E1, class T2, extent_t E2 > |
| 1495 |
inline span_constexpr bool operator>=( span<T1,E1> const & l, span<T2,E2> const & r ) |
| 1496 |
{ |
| 1497 |
return !( l < r ); |
| 1498 |
} |
| 1499 |
|
| 1500 |
#endif // span_FEATURE( COMPARISON ) |
| 1501 |
|
| 1502 |
// 26.7.2.6 views of object representation [span.objectrep] |
| 1503 |
|
| 1504 |
#if span_HAVE( BYTE ) || span_HAVE( NONSTD_BYTE ) |
| 1505 |
|
| 1506 |
// Avoid MSVC 14.1 (1910), VS 2017: warning C4307: '*': integral constant overflow: |
| 1507 |
|
| 1508 |
template< typename T, extent_t Extent > |
| 1509 |
struct BytesExtent |
| 1510 |
{ |
| 1511 |
#if span_CPP11_OR_GREATER |
| 1512 |
enum ET : extent_t { value = span_sizeof(T) * Extent }; |
| 1513 |
#else |
| 1514 |
enum ET { value = span_sizeof(T) * Extent }; |
| 1515 |
#endif |
| 1516 |
}; |
| 1517 |
|
| 1518 |
template< typename T > |
| 1519 |
struct BytesExtent< T, dynamic_extent > |
| 1520 |
{ |
| 1521 |
#if span_CPP11_OR_GREATER |
| 1522 |
enum ET : extent_t { value = dynamic_extent }; |
| 1523 |
#else |
| 1524 |
enum ET { value = dynamic_extent }; |
| 1525 |
#endif |
| 1526 |
}; |
| 1527 |
|
| 1528 |
template< class T, extent_t Extent > |
| 1529 |
inline span_constexpr span< const std17::byte, BytesExtent<T, Extent>::value > |
| 1530 |
as_bytes( span<T,Extent> spn ) span_noexcept |
| 1531 |
{ |
| 1532 |
#if 0 |
| 1533 |
return { reinterpret_cast< std17::byte const * >( spn.data() ), spn.size_bytes() }; |
| 1534 |
#else |
| 1535 |
return span< const std17::byte, BytesExtent<T, Extent>::value >( |
| 1536 |
reinterpret_cast< std17::byte const * >( spn.data() ), spn.size_bytes() ); // NOLINT |
| 1537 |
#endif |
| 1538 |
} |
| 1539 |
|
| 1540 |
template< class T, extent_t Extent > |
| 1541 |
inline span_constexpr span< std17::byte, BytesExtent<T, Extent>::value > |
| 1542 |
as_writable_bytes( span<T,Extent> spn ) span_noexcept |
| 1543 |
{ |
| 1544 |
#if 0 |
| 1545 |
return { reinterpret_cast< std17::byte * >( spn.data() ), spn.size_bytes() }; |
| 1546 |
#else |
| 1547 |
return span< std17::byte, BytesExtent<T, Extent>::value >( |
| 1548 |
reinterpret_cast< std17::byte * >( spn.data() ), spn.size_bytes() ); // NOLINT |
| 1549 |
#endif |
| 1550 |
} |
| 1551 |
|
| 1552 |
#endif // span_HAVE( BYTE ) || span_HAVE( NONSTD_BYTE ) |
| 1553 |
|
| 1554 |
// 27.8 Container and view access [iterator.container] |
| 1555 |
|
| 1556 |
template< class T, extent_t Extent /*= dynamic_extent*/ > |
| 1557 |
span_constexpr std::size_t size( span<T,Extent> const & spn ) |
| 1558 |
{ |
| 1559 |
return static_cast<std::size_t>( spn.size() ); |
| 1560 |
} |
| 1561 |
|
| 1562 |
template< class T, extent_t Extent /*= dynamic_extent*/ > |
| 1563 |
span_constexpr std::ptrdiff_t ssize( span<T,Extent> const & spn ) |
| 1564 |
{ |
| 1565 |
return static_cast<std::ptrdiff_t>( spn.size() ); |
| 1566 |
} |
| 1567 |
|
| 1568 |
} // namespace span_lite |
| 1569 |
} // namespace nonstd |
| 1570 |
|
| 1571 |
// make available in nonstd: |
| 1572 |
|
| 1573 |
namespace nonstd { |
| 1574 |
|
| 1575 |
using span_lite::dynamic_extent; |
| 1576 |
|
| 1577 |
using span_lite::span; |
| 1578 |
|
| 1579 |
using span_lite::with_container; |
| 1580 |
|
| 1581 |
#if span_FEATURE( COMPARISON ) |
| 1582 |
#if span_FEATURE( SAME ) |
| 1583 |
using span_lite::same; |
| 1584 |
#endif |
| 1585 |
|
| 1586 |
using span_lite::operator==; |
| 1587 |
using span_lite::operator!=; |
| 1588 |
using span_lite::operator<; |
| 1589 |
using span_lite::operator<=; |
| 1590 |
using span_lite::operator>; |
| 1591 |
using span_lite::operator>=; |
| 1592 |
#endif |
| 1593 |
|
| 1594 |
#if span_HAVE( BYTE ) |
| 1595 |
using span_lite::as_bytes; |
| 1596 |
using span_lite::as_writable_bytes; |
| 1597 |
#endif |
| 1598 |
|
| 1599 |
using span_lite::size; |
| 1600 |
using span_lite::ssize; |
| 1601 |
|
| 1602 |
} // namespace nonstd |
| 1603 |
|
| 1604 |
#endif // span_USES_STD_SPAN |
| 1605 |
|
| 1606 |
// make_span() [span-lite extension]: |
| 1607 |
|
| 1608 |
#if span_FEATURE( MAKE_SPAN ) || span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_SPAN ) || span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_CONTAINER ) |
| 1609 |
|
| 1610 |
#if span_USES_STD_SPAN |
| 1611 |
# define span_constexpr constexpr |
| 1612 |
# define span_noexcept noexcept |
| 1613 |
# define span_nullptr nullptr |
| 1614 |
# ifndef span_CONFIG_EXTENT_TYPE |
| 1615 |
# define span_CONFIG_EXTENT_TYPE std::size_t |
| 1616 |
# endif |
| 1617 |
using extent_t = span_CONFIG_EXTENT_TYPE; |
| 1618 |
#endif // span_USES_STD_SPAN |
| 1619 |
|
| 1620 |
namespace nonstd { |
| 1621 |
namespace span_lite { |
| 1622 |
|
| 1623 |
template< class T > |
| 1624 |
inline span_constexpr span<T> |
| 1625 |
make_span( T * ptr, size_t count ) span_noexcept |
| 1626 |
{ |
| 1627 |
return span<T>( ptr, count ); |
| 1628 |
} |
| 1629 |
|
| 1630 |
template< class T > |
| 1631 |
inline span_constexpr span<T> |
| 1632 |
make_span( T * first, T * last ) span_noexcept |
| 1633 |
{ |
| 1634 |
return span<T>( first, last ); |
| 1635 |
} |
| 1636 |
|
| 1637 |
template< class T, std::size_t N > |
| 1638 |
inline span_constexpr span<T, static_cast<extent_t>(N)> |
| 1639 |
make_span( T ( &arr )[ N ] ) span_noexcept |
| 1640 |
{ |
| 1641 |
return span<T, static_cast<extent_t>(N)>( &arr[ 0 ], N ); |
| 1642 |
} |
| 1643 |
|
| 1644 |
#if span_USES_STD_SPAN || span_HAVE( ARRAY ) |
| 1645 |
|
| 1646 |
template< class T, std::size_t N > |
| 1647 |
inline span_constexpr span<T, static_cast<extent_t>(N)> |
| 1648 |
make_span( std::array< T, N > & arr ) span_noexcept |
| 1649 |
{ |
| 1650 |
return span<T, static_cast<extent_t>(N)>( arr ); |
| 1651 |
} |
| 1652 |
|
| 1653 |
template< class T, std::size_t N > |
| 1654 |
inline span_constexpr span< const T, static_cast<extent_t>(N) > |
| 1655 |
make_span( std::array< T, N > const & arr ) span_noexcept |
| 1656 |
{ |
| 1657 |
return span<const T, static_cast<extent_t>(N)>( arr ); |
| 1658 |
} |
| 1659 |
|
| 1660 |
#endif // span_HAVE( ARRAY ) |
| 1661 |
|
| 1662 |
#if span_USES_STD_SPAN || span_HAVE( INITIALIZER_LIST ) |
| 1663 |
|
| 1664 |
template< class T > |
| 1665 |
inline span_constexpr span< const T > |
| 1666 |
make_span( std::initializer_list<T> il ) span_noexcept |
| 1667 |
{ |
| 1668 |
return span<const T>( il.begin(), il.size() ); |
| 1669 |
} |
| 1670 |
|
| 1671 |
#endif // span_HAVE( INITIALIZER_LIST ) |
| 1672 |
|
| 1673 |
#if span_USES_STD_SPAN |
| 1674 |
|
| 1675 |
template< class Container, class EP = decltype( std::data(std::declval<Container&>())) > |
| 1676 |
inline span_constexpr auto |
| 1677 |
make_span( Container & cont ) span_noexcept -> span< typename std::remove_pointer<EP>::type > |
| 1678 |
{ |
| 1679 |
return span< typename std::remove_pointer<EP>::type >( cont ); |
| 1680 |
} |
| 1681 |
|
| 1682 |
template< class Container, class EP = decltype( std::data(std::declval<Container&>())) > |
| 1683 |
inline span_constexpr auto |
| 1684 |
make_span( Container const & cont ) span_noexcept -> span< const typename std::remove_pointer<EP>::type > |
| 1685 |
{ |
| 1686 |
return span< const typename std::remove_pointer<EP>::type >( cont ); |
| 1687 |
} |
| 1688 |
|
| 1689 |
#elif span_HAVE( CONSTRAINED_SPAN_CONTAINER_CTOR ) && span_HAVE( AUTO ) |
| 1690 |
|
| 1691 |
template< class Container, class EP = decltype( std17::data(std::declval<Container&>())) > |
| 1692 |
inline span_constexpr auto |
| 1693 |
make_span( Container & cont ) span_noexcept -> span< typename std::remove_pointer<EP>::type > |
| 1694 |
{ |
| 1695 |
return span< typename std::remove_pointer<EP>::type >( cont ); |
| 1696 |
} |
| 1697 |
|
| 1698 |
template< class Container, class EP = decltype( std17::data(std::declval<Container&>())) > |
| 1699 |
inline span_constexpr auto |
| 1700 |
make_span( Container const & cont ) span_noexcept -> span< const typename std::remove_pointer<EP>::type > |
| 1701 |
{ |
| 1702 |
return span< const typename std::remove_pointer<EP>::type >( cont ); |
| 1703 |
} |
| 1704 |
|
| 1705 |
#else |
| 1706 |
|
| 1707 |
template< class T > |
| 1708 |
inline span_constexpr span<T> |
| 1709 |
make_span( span<T> spn ) span_noexcept |
| 1710 |
{ |
| 1711 |
return spn; |
| 1712 |
} |
| 1713 |
|
| 1714 |
template< class T, class Allocator > |
| 1715 |
inline span_constexpr span<T> |
| 1716 |
make_span( std::vector<T, Allocator> & cont ) span_noexcept |
| 1717 |
{ |
| 1718 |
return span<T>( with_container, cont ); |
| 1719 |
} |
| 1720 |
|
| 1721 |
template< class T, class Allocator > |
| 1722 |
inline span_constexpr span<const T> |
| 1723 |
make_span( std::vector<T, Allocator> const & cont ) span_noexcept |
| 1724 |
{ |
| 1725 |
return span<const T>( with_container, cont ); |
| 1726 |
} |
| 1727 |
|
| 1728 |
#endif // span_USES_STD_SPAN || ( ... ) |
| 1729 |
|
| 1730 |
#if ! span_USES_STD_SPAN && span_FEATURE( WITH_CONTAINER ) |
| 1731 |
|
| 1732 |
template< class Container > |
| 1733 |
inline span_constexpr span<typename Container::value_type> |
| 1734 |
make_span( with_container_t, Container & cont ) span_noexcept |
| 1735 |
{ |
| 1736 |
return span< typename Container::value_type >( with_container, cont ); |
| 1737 |
} |
| 1738 |
|
| 1739 |
template< class Container > |
| 1740 |
inline span_constexpr span<const typename Container::value_type> |
| 1741 |
make_span( with_container_t, Container const & cont ) span_noexcept |
| 1742 |
{ |
| 1743 |
return span< const typename Container::value_type >( with_container, cont ); |
| 1744 |
} |
| 1745 |
|
| 1746 |
#endif // ! span_USES_STD_SPAN && span_FEATURE( WITH_CONTAINER ) |
| 1747 |
|
| 1748 |
// extensions: non-member views: |
| 1749 |
// this feature implies the presence of make_span() |
| 1750 |
|
| 1751 |
#if span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_SPAN ) |
| 1752 |
|
| 1753 |
template< extent_t Count, class T, extent_t Extent > |
| 1754 |
span_constexpr span<T, Count> |
| 1755 |
first( span<T, Extent> spn ) |
| 1756 |
{ |
| 1757 |
return spn.template first<Count>(); |
| 1758 |
} |
| 1759 |
|
| 1760 |
template< class T, extent_t Extent > |
| 1761 |
span_constexpr span<T> |
| 1762 |
first( span<T, Extent> spn, size_t count ) |
| 1763 |
{ |
| 1764 |
return spn.first( count ); |
| 1765 |
} |
| 1766 |
|
| 1767 |
template< extent_t Count, class T, extent_t Extent > |
| 1768 |
span_constexpr span<T, Count> |
| 1769 |
last( span<T, Extent> spn ) |
| 1770 |
{ |
| 1771 |
return spn.template last<Count>(); |
| 1772 |
} |
| 1773 |
|
| 1774 |
template< class T, extent_t Extent > |
| 1775 |
span_constexpr span<T> |
| 1776 |
last( span<T, Extent> spn, size_t count ) |
| 1777 |
{ |
| 1778 |
return spn.last( count ); |
| 1779 |
} |
| 1780 |
|
| 1781 |
template< size_t Offset, extent_t Count, class T, extent_t Extent > |
| 1782 |
span_constexpr span<T, Count> |
| 1783 |
subspan( span<T, Extent> spn ) |
| 1784 |
{ |
| 1785 |
return spn.template subspan<Offset, Count>(); |
| 1786 |
} |
| 1787 |
|
| 1788 |
template< class T, extent_t Extent > |
| 1789 |
span_constexpr span<T> |
| 1790 |
subspan( span<T, Extent> spn, size_t offset, extent_t count = dynamic_extent ) |
| 1791 |
{ |
| 1792 |
return spn.subspan( offset, count ); |
| 1793 |
} |
| 1794 |
|
| 1795 |
#endif // span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_SPAN ) |
| 1796 |
|
| 1797 |
#if span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_CONTAINER ) && span_CPP11_120 |
| 1798 |
|
| 1799 |
template< extent_t Count, class T > |
| 1800 |
span_constexpr auto |
| 1801 |
first( T & t ) -> decltype( make_span(t).template first<Count>() ) |
| 1802 |
{ |
| 1803 |
return make_span( t ).template first<Count>(); |
| 1804 |
} |
| 1805 |
|
| 1806 |
template< class T > |
| 1807 |
span_constexpr auto |
| 1808 |
first( T & t, size_t count ) -> decltype( make_span(t).first(count) ) |
| 1809 |
{ |
| 1810 |
return make_span( t ).first( count ); |
| 1811 |
} |
| 1812 |
|
| 1813 |
template< extent_t Count, class T > |
| 1814 |
span_constexpr auto |
| 1815 |
last( T & t ) -> decltype( make_span(t).template last<Count>() ) |
| 1816 |
{ |
| 1817 |
return make_span(t).template last<Count>(); |
| 1818 |
} |
| 1819 |
|
| 1820 |
template< class T > |
| 1821 |
span_constexpr auto |
| 1822 |
last( T & t, extent_t count ) -> decltype( make_span(t).last(count) ) |
| 1823 |
{ |
| 1824 |
return make_span( t ).last( count ); |
| 1825 |
} |
| 1826 |
|
| 1827 |
template< size_t Offset, extent_t Count = dynamic_extent, class T > |
| 1828 |
span_constexpr auto |
| 1829 |
subspan( T & t ) -> decltype( make_span(t).template subspan<Offset, Count>() ) |
| 1830 |
{ |
| 1831 |
return make_span( t ).template subspan<Offset, Count>(); |
| 1832 |
} |
| 1833 |
|
| 1834 |
template< class T > |
| 1835 |
span_constexpr auto |
| 1836 |
subspan( T & t, size_t offset, extent_t count = dynamic_extent ) -> decltype( make_span(t).subspan(offset, count) ) |
| 1837 |
{ |
| 1838 |
return make_span( t ).subspan( offset, count ); |
| 1839 |
} |
| 1840 |
|
| 1841 |
#endif // span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_CONTAINER ) |
| 1842 |
|
| 1843 |
} // namespace span_lite |
| 1844 |
} // namespace nonstd |
| 1845 |
|
| 1846 |
// make available in nonstd: |
| 1847 |
|
| 1848 |
namespace nonstd { |
| 1849 |
using span_lite::make_span; |
| 1850 |
|
| 1851 |
#if span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_SPAN ) || ( span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_CONTAINER ) && span_CPP11_120 ) |
| 1852 |
|
| 1853 |
using span_lite::first; |
| 1854 |
using span_lite::last; |
| 1855 |
using span_lite::subspan; |
| 1856 |
|
| 1857 |
#endif // span_FEATURE( NON_MEMBER_FIRST_LAST_SUB_[SPAN|CONTAINER] ) |
| 1858 |
|
| 1859 |
} // namespace nonstd |
| 1860 |
|
| 1861 |
#endif // #if span_FEATURE_TO_STD( MAKE_SPAN ) |
| 1862 |
|
| 1863 |
#if span_CPP11_OR_GREATER && span_FEATURE( BYTE_SPAN ) && ( span_HAVE( BYTE ) || span_HAVE( NONSTD_BYTE ) ) |
| 1864 |
|
| 1865 |
namespace nonstd { |
| 1866 |
namespace span_lite { |
| 1867 |
|
| 1868 |
template< class T > |
| 1869 |
inline span_constexpr auto |
| 1870 |
byte_span( T & t ) span_noexcept -> span< std17::byte, span_sizeof(T) > |
| 1871 |
{ |
| 1872 |
return span< std17::byte, span_sizeof(t) >( reinterpret_cast< std17::byte * >( &t ), span_sizeof(T) ); |
| 1873 |
} |
| 1874 |
|
| 1875 |
template< class T > |
| 1876 |
inline span_constexpr auto |
| 1877 |
byte_span( T const & t ) span_noexcept -> span< const std17::byte, span_sizeof(T) > |
| 1878 |
{ |
| 1879 |
return span< const std17::byte, span_sizeof(t) >( reinterpret_cast< std17::byte const * >( &t ), span_sizeof(T) ); |
| 1880 |
} |
| 1881 |
|
| 1882 |
} // namespace span_lite |
| 1883 |
} // namespace nonstd |
| 1884 |
|
| 1885 |
// make available in nonstd: |
| 1886 |
|
| 1887 |
namespace nonstd { |
| 1888 |
using span_lite::byte_span; |
| 1889 |
} // namespace nonstd |
| 1890 |
|
| 1891 |
#endif // span_FEATURE( BYTE_SPAN ) |
| 1892 |
|
| 1893 |
#if !span_USES_STD_SPAN && span_HAVE( STRUCT_BINDING ) |
| 1894 |
|
| 1895 |
#if span_CPP14_OR_GREATER |
| 1896 |
# include <tuple> |
| 1897 |
#elif span_CPP11_OR_GREATER |
| 1898 |
# include <tuple> |
| 1899 |
namespace std { |
| 1900 |
template< std::size_t I, typename T > |
| 1901 |
using tuple_element_t = typename tuple_element<I, T>::type; |
| 1902 |
} |
| 1903 |
#else |
| 1904 |
namespace std { |
| 1905 |
template< typename T > |
| 1906 |
class tuple_size; /*undefined*/ |
| 1907 |
|
| 1908 |
template< std::size_t I, typename T > |
| 1909 |
class tuple_element; /* undefined */ |
| 1910 |
} |
| 1911 |
#endif // span_CPP14_OR_GREATER |
| 1912 |
|
| 1913 |
namespace std { |
| 1914 |
|
| 1915 |
// 26.7.X Tuple interface |
| 1916 |
|
| 1917 |
// std::tuple_size<>: |
| 1918 |
|
| 1919 |
template< typename ElementType, nonstd::span_lite::extent_t Extent > |
| 1920 |
class tuple_size< nonstd::span<ElementType, Extent> > : public integral_constant<size_t, static_cast<size_t>(Extent)> {}; |
| 1921 |
|
| 1922 |
// std::tuple_size<>: Leave undefined for dynamic extent: |
| 1923 |
|
| 1924 |
template< typename ElementType > |
| 1925 |
class tuple_size< nonstd::span<ElementType, nonstd::dynamic_extent> >; |
| 1926 |
|
| 1927 |
// std::tuple_element<>: |
| 1928 |
|
| 1929 |
template< size_t I, typename ElementType, nonstd::span_lite::extent_t Extent > |
| 1930 |
class tuple_element< I, nonstd::span<ElementType, Extent> > |
| 1931 |
{ |
| 1932 |
public: |
| 1933 |
#if span_HAVE( STATIC_ASSERT ) |
| 1934 |
static_assert( Extent != nonstd::dynamic_extent && I < Extent, "tuple_element<I,span>: dynamic extent or index out of range" ); |
| 1935 |
#endif |
| 1936 |
using type = ElementType; |
| 1937 |
}; |
| 1938 |
|
| 1939 |
// std::get<>(), 2 variants: |
| 1940 |
|
| 1941 |
template< size_t I, typename ElementType, nonstd::span_lite::extent_t Extent > |
| 1942 |
span_constexpr ElementType & get( nonstd::span<ElementType, Extent> & spn ) span_noexcept |
| 1943 |
{ |
| 1944 |
#if span_HAVE( STATIC_ASSERT ) |
| 1945 |
static_assert( Extent != nonstd::dynamic_extent && I < Extent, "get<>(span): dynamic extent or index out of range" ); |
| 1946 |
#endif |
| 1947 |
return spn[I]; |
| 1948 |
} |
| 1949 |
|
| 1950 |
template< size_t I, typename ElementType, nonstd::span_lite::extent_t Extent > |
| 1951 |
span_constexpr ElementType const & get( nonstd::span<ElementType, Extent> const & spn ) span_noexcept |
| 1952 |
{ |
| 1953 |
#if span_HAVE( STATIC_ASSERT ) |
| 1954 |
static_assert( Extent != nonstd::dynamic_extent && I < Extent, "get<>(span): dynamic extent or index out of range" ); |
| 1955 |
#endif |
| 1956 |
return spn[I]; |
| 1957 |
} |
| 1958 |
|
| 1959 |
} // end namespace std |
| 1960 |
|
| 1961 |
#endif // !span_USES_STD_SPAN && span_HAVE( STRUCT_BINDING ) |
| 1962 |
|
| 1963 |
#if ! span_USES_STD_SPAN |
| 1964 |
span_RESTORE_WARNINGS() |
| 1965 |
#endif // span_USES_STD_SPAN |
| 1966 |
|
| 1967 |
#endif // NONSTD_SPAN_HPP_INCLUDED |