diff options
author | Jean-Michaƫl Celerier <jeanmichael.celerier+github@gmail.com> | 2021-09-16 01:12:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-16 01:12:11 +0300 |
commit | f09b24970dfed112c57c3d21cf3b90273c9f7ff2 (patch) | |
tree | 60b2aae784cc1c287236f1564d013f272f8a7e11 | |
parent | 8a4b9ed0bf643726ce625678a17b1fc40d90870c (diff) |
Fix gsl/util for c++20 compilers without <span> (#993)
For instance, clang 10 sets __cplusplus >= 202002L yet does not have span, which causes build errors:
https://gcc.godbolt.org/z/Yq345zGea
-rw-r--r-- | include/gsl/util | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/include/gsl/util b/include/gsl/util index db66aae..330b996 100644 --- a/include/gsl/util +++ b/include/gsl/util @@ -25,9 +25,12 @@ #include <type_traits> // for is_signed, integral_constant #include <utility> // for exchange, forward -#if defined(__cplusplus) && __cplusplus >= 202002L +#if defined(__has_include) && __has_include(<version>) +#include <version> +#if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L #include <span> -#endif // __cplusplus >= 202002L +#endif // __cpp_lib_span >= 202002L +#endif //__has_include(<version>) #if defined(_MSC_VER) && !defined(__clang__) @@ -138,14 +141,14 @@ GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute return *(cont.begin() + i); } -#if defined(__cplusplus) && __cplusplus >= 202002L +#if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L template <class T, size_t extent = std::dynamic_extent> constexpr auto at(std::span<T, extent> sp, const index i) { Expects(i >= 0 && i < narrow_cast<i>(sp.size())); return sp[i]; } -#endif // __cplusplus >= 202002L +#endif // __cpp_lib_span >= 202002L } // namespace gsl #if defined(_MSC_VER) && !defined(__clang__) |