Skip to content

Commit

Permalink
remove lambda expression in layout stride
Browse files Browse the repository at this point in the history
Replace a lambda expression to allow use in constant expression context
in C++14.
  • Loading branch information
oliverlee committed Feb 1, 2024
1 parent fef0c8a commit f75c20b
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions include/experimental/__p0009_bits/layout_stride.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,21 @@ struct layout_stride {
// Can't use defaulted parameter in the __deduction_workaround template because of a bug in MSVC warning C4348.
using __impl = __deduction_workaround<std::make_index_sequence<Extents::rank()>>;

static constexpr __strides_storage_t strides_storage(std::true_type) {
__strides_storage_t s{};

extents_type e;
index_type stride = 1;
for(int r = static_cast<int>(extents_type::rank() - 1); r >= 0; r--) {
s[r] = stride;
stride *= e.extent(r);
}

return s;
}
static constexpr __strides_storage_t strides_storage(std::false_type) {
return {};
}

//----------------------------------------------------------------------------

Expand All @@ -246,18 +261,8 @@ struct layout_stride {
#else
: __base_t(__base_t{__member_pair_t(
#endif
extents_type(), __strides_storage_t([]() {
__strides_storage_t s{};
if constexpr (extents_type::rank() > 0) {
extents_type e;
index_type stride = 1;
for(int r = static_cast<int>(extents_type::rank() - 1); r >= 0; r--) {
s[r] = stride;
stride *= e.extent(r);
}
}
return s;
}())
extents_type(),
__strides_storage_t(strides_storage(std::integral_constant<bool, (extents_type::rank() > 0)>{}))
#if defined(_MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS)
}
#else
Expand Down

0 comments on commit f75c20b

Please sign in to comment.