From f09b24970dfed112c57c3d21cf3b90273c9f7ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Thu, 16 Sep 2021 00:12:11 +0200 Subject: [PATCH] Fix gsl/util for c++20 compilers without (#993) For instance, clang 10 sets __cplusplus >= 202002L yet does not have span, which causes build errors: https://gcc.godbolt.org/z/Yq345zGea --- include/gsl/util | 11 +++++++---- 1 file 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 // for is_signed, integral_constant #include // for exchange, forward -#if defined(__cplusplus) && __cplusplus >= 202002L +#if defined(__has_include) && __has_include() +#include +#if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L #include -#endif // __cplusplus >= 202002L +#endif // __cpp_lib_span >= 202002L +#endif //__has_include() #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 constexpr auto at(std::span sp, const index i) { Expects(i >= 0 && i < narrow_cast(sp.size())); return sp[i]; } -#endif // __cplusplus >= 202002L +#endif // __cpp_lib_span >= 202002L } // namespace gsl #if defined(_MSC_VER) && !defined(__clang__)