From f75c20bb0625b1343e237c4049871e5edf051b64 Mon Sep 17 00:00:00 2001 From: Oliver Lee Date: Thu, 1 Feb 2024 11:06:39 -0800 Subject: [PATCH] remove lambda expression in layout stride Replace a lambda expression to allow use in constant expression context in C++14. --- .../__p0009_bits/layout_stride.hpp | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/include/experimental/__p0009_bits/layout_stride.hpp b/include/experimental/__p0009_bits/layout_stride.hpp index 9318495e..773efec3 100644 --- a/include/experimental/__p0009_bits/layout_stride.hpp +++ b/include/experimental/__p0009_bits/layout_stride.hpp @@ -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>; + 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(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 {}; + } //---------------------------------------------------------------------------- @@ -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(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 0)>{})) #if defined(_MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS) } #else