diff --git a/src/Domain/Creators/TimeDependentOptions/ShapeMap.cpp b/src/Domain/Creators/TimeDependentOptions/ShapeMap.cpp index 382c0d91cfcd..4819adcf7f9a 100644 --- a/src/Domain/Creators/TimeDependentOptions/ShapeMap.cpp +++ b/src/Domain/Creators/TimeDependentOptions/ShapeMap.cpp @@ -64,8 +64,8 @@ FromVolumeFileShapeSize::FromVolumeFileShapeSize( std::string subfile_name) : FromVolumeFile(std::move(h5_filename), std::move(subfile_name)), transition_ends_at_cube(transition_ends_at_cube_in) { - const auto shape_fot_map = - retrieve_function_of_time({"Shape" + name(Object)}, std::nullopt); + const auto shape_fot_map = retrieve_function_of_time( + {std::string{"Shape" + name(Object)}}, std::nullopt); const auto& shape_fot = shape_fot_map.at("Shape" + name(Object)); const double initial_time = shape_fot->time_bounds()[0]; diff --git a/src/Utilities/StaticCache.hpp b/src/Utilities/StaticCache.hpp index 6ca7bc013357..77efc21bd6df 100644 --- a/src/Utilities/StaticCache.hpp +++ b/src/Utilities/StaticCache.hpp @@ -158,11 +158,10 @@ class StaticCache { std::tuple> parameter0) const { // note that the act of assigning to the specified function pointer type // fixes the template arguments that need to be inferred. - static const std::array::*)() - const, + static const std::array - cache{{&StaticCache::unwrap_cache_combined< - IntegralConstantValues..., IntegralConstants>...}}; + cache{{&StaticCache::unwrap_cache_combined...}}; // The array `cache` holds pointers to member functions, so we dereference // the pointer and invoke it on `this`. return (this->*gsl::at(cache, std::get<0>(parameter0)))(); @@ -173,41 +172,39 @@ class StaticCache { const T& unwrap_cache_combined( std::tuple> parameter0, std::tuple> parameter1) const { + constexpr size_t num0 = sizeof...(IntegralConstants0); + constexpr size_t num1 = sizeof...(IntegralConstants1); + constexpr size_t total_size = num0 * num1; // note that the act of assigning to the specified function pointer type // fixes the template arguments that need to be inferred. - static const std::array< - const T& (StaticCache::*)() const, - sizeof...(IntegralConstants0) * sizeof...(IntegralConstants1)> + static const std::array cache = []() { - std::array::*)() const, - sizeof...(IntegralConstants0) * - sizeof...(IntegralConstants1)> - result; + std::array result; size_t counter1 = 0; - const auto helper = [&counter1, - &result]() { + const auto helper1 = [&counter1, + &result]() { size_t counter0 = 0; - // Note: Left-to-right ordering is guaranteed by the comma - // operator, otherwise we'd need to use another - // EXPAND_PACK_LEFT_TO_RIGHT - (((result[counter0 + sizeof...(IntegralConstants0) * counter1] = - &StaticCache::unwrap_cache_combined< - IntegralConstantValues..., IntegralConstants0, - IntegralConstant1>), - ++counter0), - ...); + const auto helper0 = [&counter0, &counter1, + &result]() { + result[counter0 + num0 * counter1] = + &StaticCache::unwrap_cache_combined; + ++counter0; + }; + EXPAND_PACK_LEFT_TO_RIGHT( + helper0.template operator()()); ++counter1; }; EXPAND_PACK_LEFT_TO_RIGHT( - helper.template operator()()); + helper1.template operator()()); return result; }(); // The array `cache` holds pointers to member functions, so we dereference // the pointer and invoke it on `this`. return (this->*gsl::at(cache, std::get<0>(parameter0) + - sizeof...(IntegralConstants0) * - std::get<0>(parameter1)))(); + num0 * std::get<0>(parameter1)))(); } template > parameter0, std::tuple> parameter1, std::tuple> parameter2) const { + constexpr size_t num0 = sizeof...(IntegralConstants0); + constexpr size_t num1 = sizeof...(IntegralConstants1); + constexpr size_t num2 = sizeof...(IntegralConstants2); + constexpr size_t total_size = num0 * num1 * num2; // note that the act of assigning to the specified function pointer type // fixes the template arguments that need to be inferred. - static const std::array< - const T& (StaticCache::*)() const, - sizeof...(IntegralConstants0) * sizeof...(IntegralConstants1) * - sizeof...(IntegralConstants2)> + static const std::array cache = []() { - std::array::*)() const, - sizeof...(IntegralConstants0) * - sizeof...(IntegralConstants1) * - sizeof...(IntegralConstants2)> - result; + std::array result; size_t counter2 = 0; const auto helper2 = [&counter2, &result]() { size_t counter1 = 0; - const auto helper = [&counter1, &counter2, - &result]() { + const auto helper1 = [&counter1, &counter2, + &result]() { size_t counter0 = 0; - // Note: Left-to-right ordering is guaranteed by the comma - // operator, otherwise we'd need to use another - // EXPAND_PACK_LEFT_TO_RIGHT - (((result[counter0 + - sizeof...(IntegralConstants0) * - (counter1 + - sizeof...(IntegralConstants1) * counter2)] = - &StaticCache:: - unwrap_cache_combined< - IntegralConstantValues..., IntegralConstants0, - IntegralConstant1, IntegralConstant2>), - ++counter0), - ...); + const auto helper0 = [&counter0, &counter1, &counter2, + &result]() { + result[counter0 + num0 * (counter1 + num1 * counter2)] = + &StaticCache::unwrap_cache_combined< + IntegralConstantValues..., IntegralConstant0, + IntegralConstant1, IntegralConstant2>; + ++counter0; + }; + EXPAND_PACK_LEFT_TO_RIGHT( + helper0.template operator()()); ++counter1; }; EXPAND_PACK_LEFT_TO_RIGHT( - helper.template operator()()); + helper1.template operator()()); ++counter2; }; EXPAND_PACK_LEFT_TO_RIGHT( @@ -261,11 +252,10 @@ class StaticCache { // The array `cache` holds pointers to member functions, so we dereference // the pointer and invoke it on `this`. - return (this->*gsl::at(cache, std::get<0>(parameter0) + - sizeof...(IntegralConstants0) * - (std::get<0>(parameter1) + - sizeof...(IntegralConstants1) * - std::get<0>(parameter2))))(); + return ( + this->*gsl::at(cache, std::get<0>(parameter0) + + num0 * (std::get<0>(parameter1) + + num1 * std::get<0>(parameter2))))(); } template > parameter1, std::tuple> parameter2, std::tuple> parameter3) const { + constexpr size_t num0 = sizeof...(IntegralConstants0); + constexpr size_t num1 = sizeof...(IntegralConstants1); + constexpr size_t num2 = sizeof...(IntegralConstants2); + constexpr size_t num3 = sizeof...(IntegralConstants3); + constexpr size_t total_size = num0 * num1 * num2 * num3; // note that the act of assigning to the specified function pointer type // fixes the template arguments that need to be inferred. - static const std::array< - const T& (StaticCache::*)() const, - sizeof...(IntegralConstants0) * sizeof...(IntegralConstants1) * - sizeof...(IntegralConstants2) * sizeof...(IntegralConstants3)> + static const std::array cache = []() { - std::array< - const T& (StaticCache::*)() const, - sizeof...(IntegralConstants0) * sizeof...(IntegralConstants1) * - sizeof...(IntegralConstants2) * sizeof...(IntegralConstants3)> - result; + std::array result; size_t counter3 = 0; const auto helper3 = [&counter3, &result]() { @@ -295,29 +283,27 @@ class StaticCache { const auto helper2 = [&counter2, &counter3, &result]() { size_t counter1 = 0; - const auto helper = [&counter1, &counter2, &counter3, - &result]() { + const auto helper1 = [&counter1, &counter2, &counter3, + &result]() { size_t counter0 = 0; - // Note: Left-to-right ordering is guaranteed by the comma - // operator, otherwise we'd need to use another - // EXPAND_PACK_LEFT_TO_RIGHT - (((result[counter0 + - sizeof...(IntegralConstants0) * - (counter1 + - sizeof...(IntegralConstants1) * - (counter2 + sizeof...(IntegralConstants2) * - counter3))] = - &StaticCache:: - unwrap_cache_combined< - IntegralConstantValues..., IntegralConstants0, - IntegralConstant1, IntegralConstant2, - IntegralConstant3>), - ++counter0), - ...); + const auto helper0 = [&counter0, &counter1, &counter2, + &counter3, + &result]() { + result[counter0 + + num0 * + (counter1 + num1 * (counter2 + num2 * counter3))] = + &StaticCache::unwrap_cache_combined< + IntegralConstantValues..., IntegralConstant0, + IntegralConstant1, IntegralConstant2, + IntegralConstant3>; + ++counter0; + }; + EXPAND_PACK_LEFT_TO_RIGHT( + helper0.template operator()()); ++counter1; }; EXPAND_PACK_LEFT_TO_RIGHT( - helper.template operator()()); + helper1.template operator()()); ++counter2; }; EXPAND_PACK_LEFT_TO_RIGHT( @@ -329,16 +315,14 @@ class StaticCache { return result; }(); - // The array `cache` holds pointers to member functions, so we dereference - // the pointer and invoke it on `this`. + // The array `cache` holds pointers to member functions, so we + // dereference the pointer and invoke it on `this`. return ( - this->*gsl::at(cache, std::get<0>(parameter0) + - sizeof...(IntegralConstants0) * - (std::get<0>(parameter1) + - sizeof...(IntegralConstants1) * - (std::get<0>(parameter2) + - sizeof...(IntegralConstants2) * - std::get<0>(parameter3)))))(); + this->*gsl::at(cache, + std::get<0>(parameter0) + + num0 * (std::get<0>(parameter1) + + num1 * (std::get<0>(parameter2) + + num2 * std::get<0>(parameter3)))))(); } template > parameter3, std::tuple> parameter4, const Args&... parameters) const { + constexpr size_t num0 = sizeof...(IntegralConstants0); + constexpr size_t num1 = sizeof...(IntegralConstants1); + constexpr size_t num2 = sizeof...(IntegralConstants2); + constexpr size_t num3 = sizeof...(IntegralConstants3); + constexpr size_t num4 = sizeof...(IntegralConstants4); + constexpr size_t total_size = num0 * num1 * num2 * num3 * num4; // note that the act of assigning to the specified function pointer type // fixes the template arguments that need to be inferred. - static const std::array< - const T& (StaticCache::*)(Args...) const, - sizeof...(IntegralConstants0) * sizeof...(IntegralConstants1) * - sizeof...(IntegralConstants2) * sizeof...(IntegralConstants3) * - sizeof...(IntegralConstants3)> + static const std::array cache = []() { - std::array< - const T& (StaticCache::*)(Args...) const, - sizeof...(IntegralConstants0) * sizeof...(IntegralConstants1) * - sizeof...(IntegralConstants2) * - sizeof...(IntegralConstants3) * sizeof...(IntegralConstants3)> + std::array result; size_t counter4 = 0; const auto helper4 = [&counter4, @@ -376,32 +359,30 @@ class StaticCache { const auto helper2 = [&counter2, &counter3, &counter4, &result]() { size_t counter1 = 0; - const auto helper = [&counter1, &counter2, &counter3, &counter4, - &result]() { + const auto helper1 = [&counter1, &counter2, &counter3, + &counter4, + &result]() { size_t counter0 = 0; - // Note: Left-to-right ordering is guaranteed by the comma - // operator, otherwise we'd need to use another - // EXPAND_PACK_LEFT_TO_RIGHT - (((result[counter0 + - sizeof...(IntegralConstants0) * - (counter1 + - sizeof...(IntegralConstants1) * - (counter2 + - sizeof...(IntegralConstants2) * - (counter3 + - sizeof...(IntegralConstants3) * - counter4)))] = - &StaticCache:: - unwrap_cache_combined< - IntegralConstantValues..., IntegralConstants0, - IntegralConstant1, IntegralConstant2, - IntegralConstant3, IntegralConstant4>), - ++counter0), - ...); + const auto helper0 = [&counter0, &counter1, &counter2, + &counter3, &counter4, + &result]() { + result[counter0 + + num0 * + (counter1 + + num1 * (counter2 + + num2 * (counter3 + num3 * counter4)))] = + &StaticCache::unwrap_cache_combined< + IntegralConstantValues..., IntegralConstant0, + IntegralConstant1, IntegralConstant2, + IntegralConstant3, IntegralConstant4>; + ++counter0; + }; + EXPAND_PACK_LEFT_TO_RIGHT( + helper0.template operator()()); ++counter1; }; EXPAND_PACK_LEFT_TO_RIGHT( - helper.template operator()()); + helper1.template operator()()); ++counter2; }; EXPAND_PACK_LEFT_TO_RIGHT( @@ -419,16 +400,15 @@ class StaticCache { // The array `cache` holds pointers to member functions, so we dereference // the pointer and invoke it on `this`. - return (this->*gsl::at(cache, - std::get<0>(parameter0) + - sizeof...(IntegralConstants0) * - (std::get<0>(parameter1) + - sizeof...(IntegralConstants1) * - (std::get<0>(parameter2) + - sizeof...(IntegralConstants2) * - (std::get<0>(parameter3) + - sizeof...(IntegralConstants3) * - std::get<0>(parameter4))))))( + return ( + this->*gsl::at( + cache, + std::get<0>(parameter0) + + num0 * + (std::get<0>(parameter1) + + num1 * (std::get<0>(parameter2) + + num2 * (std::get<0>(parameter3) + + num3 * std::get<0>(parameter4))))))( parameters...); } #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ > 10 && __GNUC__ < 14