Skip to content

Commit

Permalink
Add _MDSPAN_USE_IF_CONSTEXPR_17 macro
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanlachnit committed Nov 18, 2024
1 parent efea5cb commit 0ed2570
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 7 additions & 0 deletions include/experimental/__p0009_bits/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions include/experimental/__p0009_bits/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,3 +697,9 @@ struct __bools;

// </editor-fold> 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
5 changes: 3 additions & 2 deletions include/experimental/__p0009_bits/mdspan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 */ (
Expand All @@ -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<index_type>) {
if _MDSPAN_IF_CONSTEXPR_17 (_MDSPAN_TRAIT(std::is_signed, index_type)) {
if (static_cast<index_type>(index) < 0) {
return true;
}
Expand Down

0 comments on commit 0ed2570

Please sign in to comment.