From 0ed25707efdfaf5646aff315f80dd8fd5f4afeef Mon Sep 17 00:00:00 2001 From: Stephan Lachnit Date: Mon, 18 Nov 2024 13:23:50 +0100 Subject: [PATCH] Add _MDSPAN_USE_IF_CONSTEXPR_17 macro --- include/experimental/__p0009_bits/config.hpp | 7 +++++++ include/experimental/__p0009_bits/macros.hpp | 6 ++++++ include/experimental/__p0009_bits/mdspan.hpp | 5 +++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/experimental/__p0009_bits/config.hpp b/include/experimental/__p0009_bits/config.hpp index e8cacf40..ce2e6f20 100644 --- a/include/experimental/__p0009_bits/config.hpp +++ b/include/experimental/__p0009_bits/config.hpp @@ -176,6 +176,13 @@ static_assert(_MDSPAN_CPLUSPLUS >= MDSPAN_CXX_STD_14, "mdspan requires C++14 or # endif #endif +#ifndef _MDSPAN_USE_IF_CONSTEXPR_17 +# if (defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606) \ + || (!defined(__cpp_constexpr) && MDSPAN_HAS_CXX_17) +# define _MDSPAN_USE_IF_CONSTEXPR_17 1 +# endif +#endif + #ifndef _MDSPAN_USE_INTEGER_SEQUENCE # if defined(_MDSPAN_COMPILER_MSVC) # if (defined(__cpp_lib_integer_sequence) && __cpp_lib_integer_sequence >= 201304) diff --git a/include/experimental/__p0009_bits/macros.hpp b/include/experimental/__p0009_bits/macros.hpp index b60c4261..91c7817e 100644 --- a/include/experimental/__p0009_bits/macros.hpp +++ b/include/experimental/__p0009_bits/macros.hpp @@ -697,3 +697,9 @@ struct __bools; // end Pre-C++14 constexpr }}}1 //============================================================================== + +#if _MDSPAN_USE_IF_CONSTEXPR_17 +# define _MDSPAN_IF_CONSTEXPR_17 constexpr +#else +# define _MDSPAN_IF_CONSTEXPR_17 +#endif diff --git a/include/experimental/__p0009_bits/mdspan.hpp b/include/experimental/__p0009_bits/mdspan.hpp index 2100492a..9acd4b0f 100644 --- a/include/experimental/__p0009_bits/mdspan.hpp +++ b/include/experimental/__p0009_bits/mdspan.hpp @@ -18,6 +18,7 @@ #include "default_accessor.hpp" #include "layout_right.hpp" +#include "macros.hpp" #include "extents.hpp" #include "trait_backports.hpp" #include "compressed_pair.hpp" @@ -442,7 +443,7 @@ class mdspan MDSPAN_FORCE_INLINE_FUNCTION constexpr mapping_type const& __mapping_ref() const noexcept { return __members.__second().__first(); } MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 accessor_type& __accessor_ref() noexcept { return __members.__second().__second(); } MDSPAN_FORCE_INLINE_FUNCTION constexpr accessor_type const& __accessor_ref() const noexcept { return __members.__second().__second(); } - + MDSPAN_TEMPLATE_REQUIRES( class SizeType, /* requires */ ( @@ -452,7 +453,7 @@ class mdspan ) MDSPAN_FORCE_INLINE_FUNCTION constexpr bool __is_index_oor(SizeType index, index_type extent) const noexcept { // Check for negative indices - if constexpr (std::is_signed_v) { + if _MDSPAN_IF_CONSTEXPR_17 (_MDSPAN_TRAIT(std::is_signed, index_type)) { if (static_cast(index) < 0) { return true; }